1

我正在尝试将DiscriminationthresholdVisualizer 用于我的拟合模型;它们都是二元分类器(逻辑回归、lightgbm 和 xgbclassifier)但是,根据文档,我很难在已经拟合的模型上生成图。我的代码如下

# test is a logistic regression model 
from yellowbrick.classifier import DiscriminationThreshold
visualizer = DiscriminationThreshold(test, is_fitted = True)
visualizer.show()

其输出如下:Empty DiscriminationThreshold 视觉图像

有人可以帮助我了解如何在拟合模型上正确使用歧视阈值。我尝试了其他 lgbm 和 xgb 并得到了一个空的情节。

4

1 回答 1

1

DiscriminationThreshold可视化器充当模型的评估器,需要评估数据集。这意味着无论您的模型是否已安装,您都需要安装可视化器。您似乎省略了这一步,因为您的模型已经安装好了。

尝试这样的事情:

from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split

from yellowbrick.classifier import DiscriminationThreshold
from yellowbrick.datasets import load_spam

# Load a binary classification dataset and split
X, y = load_spam()
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)

# Instantiate and fit the LogisticRegression model
model = LogisticRegression(multi_class="auto", solver="liblinear")
model.fit(X_train, y_train)

visualizer = DiscriminationThreshold(model, is_fitted=True)
visualizer.fit(X_test, y_test)  # Fit the test data to the visualizer
visualizer.show()

在此处输入图像描述

于 2021-12-21T01:22:09.450 回答