标签: confusion-matrix

图形绘制matlab中的混淆矩阵

我有一个像这样的混淆矩阵:

[1   0   0   0   0 ]
[0  0.9  0  0.1  0 ]
[0   0   1   0   0 ]
[0   0   0   1   0 ]
[0.1 0  0.2  0  0.7]
Run Code Online (Sandbox Code Playgroud)

行表示真实的基础,列表示分类结果.我想在网格中以图形方式绘制它.我试过surface但它只显示了一个4x4的数字,而我的矩阵有5x5的大小.我怎样才能做到这一点?

matlab confusion-matrix

1
推荐指数
1
解决办法
8624
查看次数

无法使用混淆矩阵显示灵敏度/特异性

我有一个我想使用以下表格进行分析confusionMatrix

value<-cbind(c(rnorm(100,500,90),rnorm(100,800,120)))
genotype<-cbind(c(rep("A",100),rep("B",100)))
df<-cbind(value,genotype)
df<-as.data.frame(df)
colnames(df)<-c("value","genotype")
df$value<-as.numeric(as.character(df$value))
table(value>600,genotype)
Run Code Online (Sandbox Code Playgroud)

我想分析输出的敏感性和特异性,confusionMatrix但它不起作用:

confusionMatrix(table(value>600,genotype))
Run Code Online (Sandbox Code Playgroud)

如果我做错了什么有什么想法吗?

r confusion-matrix

1
推荐指数
1
解决办法
2827
查看次数

是否有可能从R中的混淆矩阵中检索假阳性和假阴性?

我使用R生成了一个混淆矩阵,如下所示.

是否可以从该矩阵中检索出假负值61并分配给R中的变量?$ byClass似乎不适合这种情况.谢谢.

Confusion Matrix and Statistics

              Reference
    Prediction   no  yes
           no  9889   61
           yes    6   44

               Accuracy : 0.9933          
                 95% CI : (0.9915, 0.9948)
    No Information Rate : 0.9895          
    P-Value [Acc > NIR] : 4.444e-05       

                  Kappa : 0.5648          
 Mcnemar's Test P-Value : 4.191e-11       

            Sensitivity : 0.9994          
            Specificity : 0.4190          
         Pos Pred Value : 0.9939          
         Neg Pred Value : 0.8800          
             Prevalence : 0.9895          
         Detection Rate : 0.9889          
   Detection Prevalence : 0.9950          
      Balanced Accuracy : 0.7092          

       'Positive' Class : no     
Run Code Online (Sandbox Code Playgroud)

r confusion-matrix r-caret

1
推荐指数
1
解决办法
1787
查看次数

R中逻辑回归的混淆矩阵

我想使用我的训练数据和测试数据为我的逻辑回归计算两个混淆矩阵:

logitMod <- glm(LoanStatus_B ~ ., data=train, family=binomial(link="logit"))
Run Code Online (Sandbox Code Playgroud)

我将预测概率的阈值设置为 0.5:

confusionMatrix(table(predict(logitMod, type="response") >= 0.5,
                      train$LoanStatus_B == 1))
Run Code Online (Sandbox Code Playgroud)

下面的代码适用于我的训练集。但是,当我使用测试集时:

confusionMatrix(table(predict(logitMod, type="response") >= 0.5,
                      test$LoanStatus_B == 1))
Run Code Online (Sandbox Code Playgroud)

它给了我一个错误

Error in table(predict(logitMod, type = "response") >= 0.5, test$LoanStatus_B == : all arguments must have the same length
Run Code Online (Sandbox Code Playgroud)

为什么是这样?我怎样才能解决这个问题?谢谢!

validation r confusion-matrix logistic-regression

1
推荐指数
1
解决办法
3万
查看次数

从熊猫混乱矩阵的散景热图

如何将大熊猫DataFrame展示为散景热图?

https://bokeh.pydata.org/en/latest/docs/user_guide/categorical.html#heat-maps显示了一些示例,但尝试修改始终只给出了一个空图.

示例混淆矩阵:

df = pd.DataFrame([[10, 0, 1], [1, 10, 0], [1, 1, 9]], 
                  columns=['A', 'B', 'C'], 
                  index=['A', 'B', 'C'])
df.index.name = 'Treatment'
df.columns.name = 'Prediction'
Run Code Online (Sandbox Code Playgroud)

python pandas confusion-matrix bokeh

1
推荐指数
1
解决办法
2960
查看次数

张量流 - tf.confusion_matrix() 抛出错误 ValueError: Shape (2, 2048, 2) 必须具有等级 2

我尝试使用谷歌张量流确定用Python编写的神经网络模型的confusion_matrix。通过使用这段代码:

cm = tf.zeros(shape=[2,2], dtype=tf.int32)

for i in range(0, validation_data.shape[0], batch_size_validation):
    batched_val_data = np.array(validation_data[i:i+batch_size_validation, :, :], dtype='float')
    batched_val_labels = np.array(validation_labels[i:i+batch_size_validation, :], dtype='float')

    batched_val_data = batched_val_data.reshape((-1, n_chunks, chunk_size))            

    _acc, _c, _p = sess.run([accuracy, correct, pred], feed_dict=({x:batched_val_data, y:batched_val_labels}))

    #batched_val_labels.shape ==> (2048, 2)
    #_p.shape                 ==> (2048, 2)
    #this piece of code throws the error!
    cm = tf.confusion_matrix(labels=batched_val_labels, predictions=_p)
Run Code Online (Sandbox Code Playgroud)

我收到以下错误: ValueError: Shape (2, 2048, 2) 必须具有等级 2

至少您应该知道验证标签的数组batched_val_labels是一个单热数组。有人可以帮我吗?提前致谢!

python python-3.x confusion-matrix tensorflow

1
推荐指数
1
解决办法
1157
查看次数

如何用 Keras 制作混淆矩阵?

我已经使用 keras 训练了 CNN 模型(多类分类),现在我想在我的测试图像集上评估该模型。有没有办法创建混淆矩阵?

python machine-learning confusion-matrix keras tensorflow

1
推荐指数
1
解决办法
2万
查看次数

python制表混淆矩阵

在我的 sklearn 逻辑回归模型中,我使用metrics.confusion_matrix命令获得了一个混淆矩阵。数组看起来像这样

array([[51,  0],
   [26,  0]])
Run Code Online (Sandbox Code Playgroud)

忽略模型做得很糟糕的事实,我试图了解以漂亮的方式制表此矩阵的最佳方法是什么

我正在尝试使用tabulate 包,此代码部分适用于我

print tabulate(cm,headers=['Pred True', 'Pred False']) 
Run Code Online (Sandbox Code Playgroud)

因为它给出了输出

  Pred True    Pred False
-----------  ------------
     51             0
     26             0
Run Code Online (Sandbox Code Playgroud)

编辑

要插入行名称,我意识到插入元素而不是 zip 会有所帮助

cm_list=cm.tolist()
cm_list[0].insert(0,'Real True')
cm_list[1].insert(0,'Real False')
print tabulate(cm_list,headers=['Real/Pred','Pred True', 'Pred False'])
Run Code Online (Sandbox Code Playgroud)

因为它给

Real/Pred      Pred True    Pred False
-----------  -----------  ------------
Real True             51             0
Real False            26             0
Run Code Online (Sandbox Code Playgroud)

但是,仍然想知道是否有更快或替代的美化混淆矩阵的方法。(我在网上找到了一些绘图示例,但我不需要那个)

谢谢,

python tabular confusion-matrix scikit-learn

0
推荐指数
1
解决办法
3267
查看次数

如何为数据框构建混淆矩阵

我有以下数据框:

v1  v2  v3  v4  v5
0   t   1   12  N/A
1   t   0   34  N/A
2   t   1   45  N/A
5   f   0   76  N/A
12  f   0   98  N/A
45  t   1   45  M
Run Code Online (Sandbox Code Playgroud)

我希望能够在 v2 和 v3 两列上构造以下混淆矩阵:

    t  |  f
 0  1     2
 1  3     0
Run Code Online (Sandbox Code Playgroud)

在 R 中执行此操作的最优雅方法是什么

r confusion-matrix

0
推荐指数
1
解决办法
2034
查看次数

如何计算具有多列的多个 Pandas 数据框的准确度

我有多个熊猫数据框如下:

data1 = {'1':[4], '2':[2], '3':[6]}
baseline = pd.DataFrame(data1)

 # baseline output  
   1  2  3
0  4  2  6

data2 = {'1':[3], '2':[5], '5':[5]}
forecast1 = pd.DataFrame(data2)

# forecast1 output
   1  2  5
0  3  5  5

data3 = {'1':[2], '3':[4], '5':[5], '6':[2]}
forecast2 = pd.DataFrame(data3)

# forecast2 output
   1  3  5  6
0  2  4  5  2
Run Code Online (Sandbox Code Playgroud)

基线数据框(即基线 vs 预测 1 和基线 vs 预测 2)相比,我如何计算预测 1预测 2(分别)的准确性(或混淆矩阵)?

另请注意,与基线数据框相比,预测 1 和预测 2 可能有一些额外的列。因此,精度计算需要考虑可用列的数量并处理额外的列。有没有办法处理这种情况?

这些数据帧是我正在做的数据清理的结果,这就是为什么其中一些数据帧几乎没有基线数据帧中不可用的额外列。 …

python pandas confusion-matrix forecast

0
推荐指数
1
解决办法
2629
查看次数

Keras 模型的混淆矩阵:一个问题,也许有人知道如何为该模型创建混淆矩阵?

我目前正在研究分类问题,但我不知道如何为这个模型制作混淆矩阵,我将其发送到下面的代码。我在协作中使用 Keras 库,因为我的本地环境与 tf.keras.preprocessing.image_dataset_from_directory 不兼容,我获得了很好的准确率和良好的预测,但在做矩阵时我迷失了。预先感谢社区

image_size = (180, 180)
batch_size = 32

train_ds = tf.keras.preprocessing.image_dataset_from_directory(
    "/content/gdrive/MyDrive/Collab Notebooks/LungCells/seg_train",
    validation_split=0.2,
    subset="training",
    seed=42,
    image_size=image_size,
    batch_size=batch_size,
)
val_ds = tf.keras.preprocessing.image_dataset_from_directory(
    "/content/gdrive/MyDrive/Collab Notebooks/LungCells/seg_train",
    validation_split=0.2,
    subset="validation",
    #seed=1337,
    seed=42,
    image_size=image_size,
    batch_size=batch_size,
)

data_augmentation = keras.Sequential(
    [
        layers.experimental.preprocessing.RandomFlip("horizontal"),
        layers.experimental.preprocessing.RandomRotation(0.1),
    ]
)

def make_model(input_shape, num_classes):
    inputs = keras.Input(shape=input_shape)
    # Image augmentation block
    x = data_augmentation(inputs)

    # Entry block
    x = layers.experimental.preprocessing.Rescaling(1.0 / 255)(x)
    x = layers.Conv2D(32, 3, strides=2, padding="same")(x)
    x = layers.BatchNormalization()(x)
    x = layers.Activation("relu")(x)

    x = layers.Conv2D(64, 3, …
Run Code Online (Sandbox Code Playgroud)

python matrix confusion-matrix keras tensorflow

0
推荐指数
1
解决办法
5032
查看次数

ConfusionMatrixDisplay(confusion_matrix).plot() 不显示任何内容

我有以下代码:

from sklearn.metrics import classification_report, confusion_matrix, ConfusionMatrixDisplay

...

confusion_matrix = confusion_matrix(validation_generator.classes, y_pred, normalize='all')

print(confusion_matrix)

display = ConfusionMatrixDisplay(confusion_matrix).plot()
Run Code Online (Sandbox Code Playgroud)

哪个输出:

[[0.013 0.487]
 [0.001 0.499]]
Run Code Online (Sandbox Code Playgroud)

问题是.plot()执行时没有显示混淆矩阵图。

我在我的 venv 中执行pip freeze > requirements.txt,这些是我的requirements.txt中的包版本

absl-py==0.11.0
astunparse==1.6.3
autopep8==1.5.5
cachetools==4.2.1
certifi==2020.12.5
chardet==4.0.0
cycler==0.10.0
flatbuffers==1.12
gast==0.3.3
google-auth==1.27.1
google-auth-oauthlib==0.4.3
google-pasta==0.2.0
grpcio==1.32.0
h5py==2.10.0
idna==2.10
joblib==1.0.1
Keras-Preprocessing==1.1.2
kiwisolver==1.3.1
Markdown==3.3.4
matplotlib==3.2.0
numpy==1.19.5
oauthlib==3.1.0
opt-einsum==3.3.0
pandas==1.2.3
Pillow==8.1.2
protobuf==3.15.5
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycodestyle==2.6.0
pydot==1.4.2
pyparsing==2.4.7
python-dateutil==2.8.1
pytz==2021.1
requests==2.25.1
requests-oauthlib==1.3.0
rsa==4.7.2
scikit-learn==0.24.1
scipy==1.6.1
seaborn==0.11.1
six==1.15.0
sklearn==0.0
tensorboard==2.4.1
tensorboard-plugin-wit==1.8.0
tensorflow==2.4.1
tensorflow-estimator==2.4.0
termcolor==1.1.0
threadpoolctl==2.1.0 …
Run Code Online (Sandbox Code Playgroud)

python confusion-matrix scikit-learn

0
推荐指数
1
解决办法
5234
查看次数