• Register
Welcome to Kodlogs, programming questions and answer website.
0 votes

when using following code:

test= sm.OLS(y, X).fit()

I am getting error it says:

valueerror: pandas data cast to numpy dtype of object. check input data with np.asarray(data).

Please help to solve this issue.

by (720 points)  
edited by

1 Answer

0 votes


Try to convert X to float by using .astype this should solve your issue.

test= sm.OLS(y, X.astype(float)).fit()

Or you can cast both variables like this example:

test=sm.OLS(y.astype(float), X.astype(float)).fit()

by (4k points)