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.