擅长:python、mysql、java
<p>为避免此错误,请不要影响变量的拟合模型</p>
<pre><code># Import xgboost
import xgboost as xgb
# Initialize the model
model_xgb_1 = xgb.XGBRegressor(max_depth = max_depth,
learning_rate = shrinkage,
n_estimators = nTrees,
objective = 'reg:squarederror',
booster = 'gbtree')
# Fit the model
model_xgb_1.fit(X_train, y_train)
# Just to check that .predict can be called and works
# without error
model_xgb_1.predict(X_train)
# the above works ok and prints the output
#This next step throws an error:
from sklearn.inspection import plot_partial_dependence
plot_partial_dependence(model_xgb_1, X_train, [0])
</code></pre>