Any demo for statsmodels regression model when setting up cross validation?

I want to find out several linear regression models for my dataframe. Below is a sample code. All over the internet I only found code like this where the target variable can be found out using other variables, but in the full dataset. I did not specifically find that k-fold cross validation is set to preferably a direct function as a parameter to the ols method.

However, I found a cross-selection setup in the regression method from the scikit-learn library, but I'm wondering why not using statsmodels.

import statsmodels.formula.api as sm
import pandas

      

Assuming the data was in .csv format and read using pandas (therefore in dataframe format).

mod = sm.ols(formula='Target_Var ~ var_1 + var_2 + var_3', data=df)
res = mod.fit()
print res.summary()

      

+3


source to share





All Articles