0
import pandas as pd
import numpy as np

from sklearn.model_selection import train_test_split, cross_val_score
from sklearn.linear_model import LinearRegression


boston = pd.read_csv('boston.csv')

x = boston.drop('medv', axis=1).values
y = boston['medv'].values


reg = LinearRegression()

cross_val_score(reg, x, y, cv=5)

reg.predict(x)

In the above code, I calculate the 5 - fold cross-validation score for my Linear Regression regressor. But when I try using the predict() method, I get an error saying:

This LinearRegression instance is not fitted yet. Call 'fit' with 
appropriate arguments before using this estimator.

I thought the regressor is fit while performing cross-validation.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
NKUwakwe
  • 7
  • 2

1 Answers1

0

You need to fit your data first:

reg = LinearRegression()
reg.fit(x,y)
alphaBetaGamma
  • 653
  • 6
  • 19