0

我有三个回归模型:

  • 线性回归:使用 ols_regressor = sm.OLS()
  • 随机森林:使用 rf = RandomForestRegressor()
  • 人工神经网络:使用 tensorflow 和 keras

我想为这三个模型绘制一个预测误差图,我遇到了看起来非常简单的Yellowbrick库。

在他们的文档中,他们有两种应用其功能的方法:

# Method 1:
from yellowbrick.regressor import PredictionError

# Instantiate the linear model and visualizer
model = Lasso()
visualizer = PredictionError(model)

visualizer.fit(X_train, y_train)  # Fit the training data to the visualizer
visualizer.score(X_test, y_test)  # Evaluate the model on the test data
visualizer.show()                 # Finalize and render the figure

# Method 2:
from yellowbrick.regressor import prediction_error

# Instantiate the linear model and visualizer
model = Lasso()
visualizer = prediction_error(model, X_train, y_train, X_test, y_test)

在尝试任何一种方法时,线性回归和 NN 模型都会出现以下错误:

YellowbrickTypeError: This estimator is not a regressor; try a classifier or clustering score visualizer instead!

它为随机森林绘制得很好。

它们是回归量,我的数据中没有任何分类变量。为什么会这样?我可以使用什么替代方案或我应该添加什么?

来源:https ://www.scikit-yb.org/en/latest/api/regressor/peplot.html

4

0 回答 0