I have a question about two different methods from different libraries which seems doing same job. I am trying to make linear regression model.
Here is the code which I using statsmodel library with OLS :
X_train, X_test, y_train, y_test = cross_validation.train_test_split(x, y, test_size=0.3, random_state=1)
x_train = sm.add_constant(X_train)
model = sm.OLS(y_train, x_train)
results = model.fit()
print "GFT + Wiki / GT R-squared", results.rsquared
This print out GFT + Wiki / GT R-squared 0.981434611923
and the second one is scikit learn library Linear model method:
model = LinearRegression()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
print 'GFT + Wiki / GT R-squared: %.4f' % model.score(X_test, y_test)
This print out GFT + Wiki / GT R-squared: 0.8543
So my question is the both method prints our R^2 result but one is print out 0.98 and the other one is 0.85.
From my understanding, OLS works with training dataset. So my questions,
- Is there a way that work with test data set with OLS ?
- Is the traning data set score gives us any meaning(In OLS we didn't use test data set)? From my past knowledge we have to work with test data.
- What is the difference between OLS and scikit linear regression. Which one we use for calculating the score of the model ?
Thanks for any help.