New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dsTypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe'' #15188
Comments
Hey! Have fun :D |
Thanks @filip-stolinski for your solution |
@filip-stolinski Thank you very much for your solution. It definitely Works |
Closing. Please reopen or open a new issue if needed. |
Thanks @filip-stolinski |
thanks |
@filip-stolinski thank you that works for me <3 |
Thanks so much!! |
I am running a program on Python and I try to generate statistics outputs from an array.
The code line:
regressor_OLS = sm.OLS(y,X_opt).fit()
is given an elaborate error.
This is the code
Multiple Linear Regression
Importing Libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
#importing the dataset
dataset = pd.read_csv('50_Startups.csv')
#Getting the independent variables
X = dataset.iloc[:,:-1].values
y = dataset.iloc[:,4].values
print (dataset)
Encoding categorical data
Encoding the Independent Variable
from sklearn.preprocessing import OneHotEncoder
from sklearn.compose import ColumnTransformer
ct = ColumnTransformer([("Country", OneHotEncoder(), [3])], remainder = 'passthrough')
X = ct.fit_transform(X)
Avoiding the Dummy Variable Trap
X = X[:, 1:]
Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state =0)
Fitting Multiple Linear Regression Model to the Training Set
from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(X_train, y_train)
Predicting the Test set results
y_pred = regressor.predict(X_test)
#Building the Optimal Model using Backward Elimination
import statsmodels.api as sm
#Add columns of 1
X= np.append(arr = np.ones((50,1)).astype(int), values = X, axis =1)
X_opt = X[:,[0,1,2,3,4,5]]
#Multiple Linear Regression Model --- OLS
regressor_OLS = sm.OLS(y,X_opt).fit()
regressor_OLS.summary()
Reproducing code example:
The text was updated successfully, but these errors were encountered: