【问题标题】:Attempting to see the Discrimination Threshold Plot for Fitted models尝试查看拟合模型的判别阈值图
【发布时间】:2022-01-22 11:21:53
【问题描述】:

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

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

输出如下:

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

【问题讨论】:

  • DiscriminationThreshold required 参数应该是一个估计器,我认为您正在尝试传递数据集。检查docs
  • 嘿! test 是一个模型对象 :) 我只是把它叫做 test 因为我试图让函数工作
  • 能否提供一些样本数据进行复现?

标签: machine-learning scikit-learn classification data-science yellowbrick


【解决方案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()

【讨论】:

  • 我没有意识到它仍然需要数据,那么阈值图会基于测试集的评估吗?如果这对我有用,将更新
  • 实际上是的。它将提供的数据集拆分为多个较小的集并评估给定的模型。您在此处看到的波段显示了这些较小集合的性能变化,实线是平均值。
猜你喜欢
  • 2020-08-10
  • 2021-01-23
  • 2022-07-21
  • 2019-10-27
  • 1970-01-01
  • 1970-01-01
  • 2020-01-25
  • 1970-01-01
  • 2021-10-06
相关资源
最近更新 更多