Reputation: 1
I need help in running my code, it is showing ERROR: - "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''"
I found few solutions (statsmodels raises TypeError: ufunc 'isfinite' not supported for the input types changing the datatype to float or int still it is not working. Can anyone please let me know what I am doing wrong in this code is below :
import statsmodels.api as sm
X = np.append(arr = np.ones((50,1)).astype(int),values=X,axis=1)
X.astype('float64')
X_opt = X[:,[0,1,2,3,4,5]]
regressor_ols = sm.OLS(endog=y,exog=X_opt).fit()
OR
import statsmodels.regression.linear_model as lm
X = np.append(arr = np.ones((50,1)).astype(int),values=X,axis=1)
X.astype('float64')
X_opt = X[:,[0,1,2,3,4,5]]
regressor_ols = lm.OLS(endog=y,exog=X_opt).fit()
regressor_ols = lm.OLS(endog=y,exog=X_opt).fit()
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\hp\PycharmProjects\DataScientist\venv\lib\site-packages\statsmodels\regression\linear_model.py", line 858, in __init__
super(OLS, self).__init__(endog, exog, missing=missing,
File "C:\Users\hp\PycharmProjects\DataScientist\venv\lib\site-packages\statsmodels\regression\linear_model.py", line 701, in __init__
super(WLS, self).__init__(endog, exog, missing=missing,
File "C:\Users\hp\PycharmProjects\DataScientist\venv\lib\site-packages\statsmodels\regression\linear_model.py", line 190, in __init__
super(RegressionModel, self).__init__(endog, exog, **kwargs)
File "C:\Users\hp\PycharmProjects\DataScientist\venv\lib\site-packages\statsmodels\base\model.py", line 236, in __init__
super(LikelihoodModel, self).__init__(endog, exog, **kwargs)
File "C:\Users\hp\PycharmProjects\DataScientist\venv\lib\site-packages\statsmodels\base\model.py", line 76, in __init__
self.data = self._handle_data(endog, exog, missing, hasconst,
File "C:\Users\hp\PycharmProjects\DataScientist\venv\lib\site-packages\statsmodels\base\model.py", line 100, in _handle_data
data = handle_data(endog, exog, missing, hasconst, **kwargs)
File "C:\Users\hp\PycharmProjects\DataScientist\venv\lib\site-packages\statsmodels\base\data.py", line 671, in handle_data
return klass(endog, exog=exog, missing=missing, hasconst=hasconst,
File "C:\Users\hp\PycharmProjects\DataScientist\venv\lib\site-packages\statsmodels\base\data.py", line 87, in __init__
self._handle_constant(hasconst)
File "C:\Users\hp\PycharmProjects\DataScientist\venv\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''
Upvotes: 0
Views: 4180
Reputation: 1552
This:
X = np.append(arr = np.ones((50,1)).astype(int),values=X,axis=1)
creates an array of dtype int
, but your classifier expects floating point values. It looks like you are tying to correct this with that:
X.astype('float64')
but this does nothing, because you never assign to it (correct would be X = X.astype('float64')
).
I suggest you just remove the astype(int)
from your array creation:
X = np.append(arr=np.ones((50,1)), values=X, axis=1)
Upvotes: 2