import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
dataset=pd.read_csv('50_Startups.csv')
x=dataset.iloc[:,:-1].values
y=dataset.iloc[:,4].values
from sklearn.preprocessing import LabelEncoder ,OneHotEncoder
from sklearn.compose import ColumnTransformer
labelencoder_x=LabelEncoder()
x[:,3]=labelencoder_x.fit_transform(x[:,3])
columntransformer = ColumnTransformer([("Country", OneHotEncoder(), [3])], remainder = 'passthrough')
x = columntransformer.fit_transform(x)
x=x[:,1:]
from sklearn.model_selection import train_test_split
xtrain,xtest,ytrain,ytest=train_test_split(x,y,test_size=1/3,random_state=0)
from sklearn.linear_model import LinearRegression
regressor=LinearRegression()
regressor.fit(xtrain, ytrain)
ypred=regressor.predict(xtest)
import statsmodels.api as sm
x=np.append(arr=np.ones((50,1)).astype(float),values=x,axis=1)
xopt=x[:,[0,1,2,3,4,5]]
regressorols=sm.OLS(endog = y,exog = xopt).fit()
regressorols.summary()
and the output is
*runcell(0, 'C:/Users/patil/Downloads/P14-Machine-Learning-AZ-Template-Folder/Machine Learning A-Z Template Folder/Part 2 - Regression/Section 5 - Multiple Linear Regression/untitled0.py') Traceback (most recent call last):
File "C:\Users\patil\Downloads\P14-Machine-Learning-AZ-Template-Folder\Machine Learning A-Z Template Folder\Part 2 - Regression\Section 5 - Multiple Linear Regression\untitled0.py", line 36, in regressorols=sm.OLS(endog = y,exog = xopt).fit()
File "C:\Users\patil\anaconda3\lib\site-packages\statsmodels\regression\linear_model.py", line 859, in init hasconst=hasconst, **kwargs)
File "C:\Users\patil\anaconda3\lib\site-packages\statsmodels\regression\linear_model.py", line 702, in init weights=weights, hasconst=hasconst, **kwargs)
File "C:\Users\patil\anaconda3\lib\site-packages\statsmodels\regression\linear_model.py", line 190, in init super(RegressionModel, self).init(endog, exog, **kwargs)
File "C:\Users\patil\anaconda3\lib\site-packages\statsmodels\base\model.py", line 236, in init super(LikelihoodModel, self).init(endog, exog, **kwargs)
File "C:\Users\patil\anaconda3\lib\site-packages\statsmodels\base\model.py", line 77, in init **kwargs)
File "C:\Users\patil\anaconda3\lib\site-packages\statsmodels\base\model.py", line 100, in _handle_data data = handle_data(endog, exog, missing, hasconst, **kwargs)
File "C:\Users\patil\anaconda3\lib\site-packages\statsmodels\base\data.py", line 672, in handle_data **kwargs)
File "C:\Users\patil\anaconda3\lib\site-packages\statsmodels\base\data.py", line 87, in init self._handle_constant(hasconst)
File "C:\Users\patil\anaconda3\lib\site-packages\statsmodels\base\data.py", line 132, in _handle_constant if not np.isfinite(exog_max).all():
TypeError: 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''*