0

I am trying to fit my data with the stats model OLS method. While following from a tutorial, imported all the necessary libraries;

from scipy import stats
import statsmodels.formula.api as sm
import numpy
import pandas
import matplotlib.pyplot as plt
import statsmodels.api as sm

Then defined all the variable names from the X_train data;

variable_names = [
 'Block', 
 'Acreage', 
'dist_Kyanuuna_TC', 
'dist_Busunju_TC', 
'dist_Namungo_TC', 
'dist_Kitalya_TC',
'dist_Kabindula_TC', 
'dist_Namayumba_HC', 
'dist_BlueStarJr_Sch', 
'dist_Kyanuuna_HS',
'dist_Busunju_Col',
'Central_P',
'years',
'Use_Agric_Farm',
'Use_Res',
'Use_Res_Agric']

Then included the neighborhood variable to the formular, for which binary dummy varaibles are to be created and fitted without an intercept.

f = 'Value ~ ' + ' + '.join(variable_names) + ' + neighborhood - 1'

And finally fitted the data as below;

model2 = sm.OLS(f, data=X_train).fit()
print(m3.summary2())

However, this raises the;

ValueError: unrecognized data structures: <class 'str'> / <class 'NoneType'>

But I have failed to figure out what could be the issue. Any clues on how to approach this would be very much appreciated. Thank you.

1 Answer 1

0

As written in the document here, it is ols instead of OLS

Update: In your import section, you use both sm for two different packages. Removing the first one should work.

Sign up to request clarification or add additional context in comments.

3 Comments

Well, i had used ols initially and raised the error "AttributeError: module 'statsmodels.api' has no attribute 'ols" So i changed it to OLS.
Which version of statsmodels are you using?
lowercase models like ols are in statsmodesl.formula.api. or use OLS.from_formula method. (convention is to use smf as abbreviation for formula.api

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.