【问题标题】:TypeError: plot_confusion_matrix() got an unexpected keyword argument 'title'TypeError: plot_confusion_matrix() 得到了一个意外的关键字参数“标题”
【发布时间】:2021-09-29 21:00:55
【问题描述】:
`import matplotlib.pyplot as plt  
 from sklearn.datasets import make_classification
 from sklearn.metrics import plot_confusion_matrix
 from sklearn.model_selection import train_test_split
 from sklearn.svm import SVC
 cm_plot_labels = ['Normal', 'Tuberculosis']
 cm_plot_title =['Confusion Matrix']
 plot_confusion_matrix(cm, cm_plot_labels, title='Confusion Matrix')

TypeError: plot_confusion_matrix() 得到了一个意外的关键字参数“标题” 请告诉我如何解决错误

【问题讨论】:

  • plot_confusion_matrix 没有 title 参数。删除它。
  • 我正在投票关闭这个由错字/不可复制引起的问题

标签: python matplotlib scikit-learn sklearn-pandas matplotlib-animation


【解决方案1】:

根据docs,没有像title这样的关键字参数。这就是导致此错误的原因。尝试删除它。

【讨论】:

    【解决方案2】:

    使用plot_confusion_matrix时可以添加标题,如下:

    clf = SVC(random_state=0)
    clf.fit(X_train, y_train)
    cm = plot_confusion_matrix(clf, X_test, y_test)
    cm.ax_.set_title('Confusion Matrix')
    

    【讨论】:

      猜你喜欢
      • 2022-09-23
      • 2021-05-13
      • 2016-09-17
      • 2022-01-14
      • 1970-01-01
      • 2012-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多