【问题标题】:find the misclassified data in a confusion matrix在混淆矩阵中找到错误分类的数据
【发布时间】:2017-01-13 17:06:48
【问题描述】:

我使用这个函数来评估我的模型

def stratified_cv(X, y, clf_class, shuffle=True, n_folds=10, **kwargs):

     X = X.as_matrix().astype(np.float)
     y = y.as_matrix().astype(np.int)
     y_pred = y.copy()
     stratified_k_fold = cross_validation.StratifiedKFold(y, n_folds=n_folds, shuffle=shuffle)  
     y_pred = y.copy()
     for ii, jj in stratified_k_fold:
           X_train, X_test =  X[ii],  X[jj]
           y_train,y_test = y[ii],y[jj]
           clf = clf_class(**kwargs)
           clf.fit(X_train,y_train)
           y_pred[jj] = clf.predict(X_test)
      return y_pred  

并给出混淆矩阵的例子

pass_agg_conf_matrix = metrics.confusion_matrix(y,       stratified_cv(X, y, linear_model.PassiveAggressiveClassifier))

现在我想识别错误分类的条目

【问题讨论】:

  • 只需在每个示例 x 上使用您的预测器 clf 并找到 y_pred 不等于 y 的那些。这不应该那么难!

标签: python pandas machine-learning confusion-matrix


【解决方案1】:

您可以从混淆矩阵本身中找出错误分类的预测。右上角的框给出了预测为 0 但不为零的预测数量。左下角的方框显示那些预测的 1 但不是 1。 如果混淆矩阵是根据正确的约定构建的,则上述单元格被称为真阴性和假阳性。

【讨论】:

    猜你喜欢
    • 2019-01-05
    • 2020-09-10
    • 2021-07-02
    • 2019-10-15
    • 2015-09-18
    • 2021-12-24
    • 2019-03-01
    • 2020-06-17
    • 2011-02-23
    相关资源
    最近更新 更多