我正在尝试在 XGBoost 拟合模型上使用 sklearn plot_partial_dependence 函数,即在调用 .fit 之后。但我不断收到错误消息:
NotFittedError:此 XGBRegressor 实例尚未安装。在使用此估计器之前,使用适当的参数调用 'fit'。
以下是我使用虚拟数据集采取的步骤。
带有虚拟数据的完整示例:
import numpy as np
# dummy dataset
from sklearn.datasets import make_regression
X_train, y_train = make_regression(n_samples = 1000, n_features = 10)
# Import xgboost
import xgboost as xgb
# Initialize the model
model_xgb_1 = xgb.XGBRegressor(max_depth = 5,
learning_rate = 0.01,
n_estimators = 100,
objective = 'reg:squarederror',
booster = 'gbtree')
# Fit the model
# Not assigning to a new variable
model_xgb_1.fit(X_train, y_train)
# Just to check …Run Code Online (Sandbox Code Playgroud)