Statsmodels Raises Typeerror: Ufunc 'isfinite' Not Supported For The Input Types
I am applying backward elimination using statsmodels.api and the code gives this error `TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be s
Solution 1:
U need to change the datatype of the readX to int or float64 using numpy. astype( ) function before optimisedX is initialize. Also change endog to readY
readX.astype('float64')
optimisedX = readX[:,[0,1,2,3,4,5]]
ols = smf.OLS(endog=readY, exog=optimisedX).fit()
print(ols.summary())
Solution 2:
just add this line,
X_opt = X[:, [0, 1, 2, 3, 4, 5]]
X_opt = np.array(X_opt, dtype=float) # <-- this line
convert it to the array and change the datatype.
Solution 3:
Today I received the same error.
The root cause is converting numpy dtype
object
to float64
and assigning to it a new variable and using this variable in a function.
X[1:3]
#array([[1, 0.0, 0.0, 162597.7, 151377.59, 443898.53],# [1, 1.0, 0.0, 153441.51, 101145.55, 407934.54]], dtype=object)
X.dtype
#dtype('O')
X1= X.astype(np.float64)
X1[1:2]
#array([[1.0000000e+00, 0.0000000e+00, 0.0000000e+00, 1.625977e+05, 1.5137759e+05, 4.4389853e+05]])
X1.dtype
#dtype('float64')
Post a Comment for "Statsmodels Raises Typeerror: Ufunc 'isfinite' Not Supported For The Input Types"