【发布时间】:2021-12-10 19:41:54
【问题描述】:
raise NotFittedError(msg % {'name': type(estimator).name}) sklearn.exceptions.NotFittedError:此套索实例未安装 然而。在使用它之前使用适当的参数调用“fit” 估算器。
from sklearn import datasets
from sklearn.linear_model import Lasso
from sklearn.model_selection import train_test_split
#
# Load the Boston Data Set
#
bh = datasets.load_boston()
X = bh.data
y = bh.target
#
# Create training and test split
#
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
#
# Create an instance of Lasso Regression implementation
#
lasso = Lasso(alpha=1.0)
#
# Fit the Lasso model
#
lasso.fit(X_test, y_test)
#
# Create the model score
#
#lasso.score(X_test, y_test), lasso.score(X_train, y_train)
lasso_reg = Lasso(normalize=True)
y_pred_lass =lasso_reg.predict(X_test)
print(y_pred_lass)
【问题讨论】:
-
您在运行
lasso.fit之后创建了一个新的Lasso对象,因此旧的套索对象及其拟合结果将丢失。 -
旧的套索对象实际上并没有丢失,它只是存储在不同的变量中。
标签: python scikit-learn data-science lasso-regression