numpy.argmax 用在求解混淆矩阵用
numpy.argmax
numpy.
argmax
(a, axis=None, out=None)[source]-
Returns the indices of the maximum values along an axis.
Parameters: a : array_like
Input array.
axis : int, optional
By default, the index is into the flattened array, otherwise along the specified axis.
out : array, optional
If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype.
Returns: index_array : ndarray of ints
Array of indices into the array. It has the same shape as a.shape with the dimension along axis removed.
See also
amax
- The maximum value along a given axis.
unravel_index
- Convert a flat index into an index tuple.
Notes
In case of multiple occurrences of the maximum values, the indices corresponding to the first occurrence are returned.
Examples
>>> a = np.arange(6).reshape(2,3)
>>> a
array([[0, 1, 2],
[3, 4, 5]])
>>> np.argmax(a)
5
>>> np.argmax(a, axis=0)
array([1, 1, 1])
>>> np.argmax(a, axis=1)
array([2, 2])>>> b = np.arange(6)
>>> b[1] = 5
>>> b
array([0, 5, 2, 3, 4, 5])
>>> np.argmax(b) # Only the first occurrence is returned.
1 在多分类模型训练中,我的使用:org_labels = [0,1,2,....max_label] 从0开始的标记类别if __name__ == "__main__":
width, height = 32, 32
X, Y, org_labels = load_data(dirname="data", resize_pics=(width, height))
trainX, testX, trainY, testY = train_test_split(X, Y, test_size=0.2, random_state=666)
print("sample data:")
print(trainX[0])
print(trainY[0])
print(testX[-1])
print(testY[-1]) model = get_model(width, height, classes=100) filename = 'cnn_handwrite-acc0.8.tflearn'
# try to load model and resume training
#try:
# model.load(filename)
# print("Model loaded OK. Resume training!")
#except:
# pass # Initialize our callback with desired accuracy threshold.
early_stopping_cb = EarlyStoppingCallback(val_acc_thresh=0.6)
try:
model.fit(trainX, trainY, validation_set=(testX, testY), n_epoch=500, shuffle=True,
snapshot_epoch=True, # Snapshot (save & evaluate) model every epoch.
show_metric=True, batch_size=32, callbacks=early_stopping_cb, run_id='cnn_handwrite')
except StopIteration as e:
print("OK, stop iterate!Good!") model.save(filename) # predict all data and calculate confusion_matrix
model.load(filename) pro_arr =model.predict(X)
predict_labels = np.argmax(pro_arr, axis=1)
print(classification_report(org_labels, predict_labels))
print(confusion_matrix(org_labels, predict_labels))
numpy.argmax 用在求解混淆矩阵用的更多相关文章
- 机器学习 - 案例 - 样本不均衡数据分析 - 信用卡诈骗 ( 标准化处理, 数据不均处理, 交叉验证, 评估, Recall值, 混淆矩阵, 阈值 )
案例背景 银行评判用户的信用考量规避信用卡诈骗 ▒ 数据 数据共有 31 个特征, 为了安全起见数据已经向了模糊化处理无法读出真实信息目标 其中数据中的 class 特征标识为是否正常用户 (0 代表 ...
- 【机器学习】--模型评估指标之混淆矩阵,ROC曲线和AUC面积
一.前述 怎么样对训练出来的模型进行评估是有一定指标的,本文就相关指标做一个总结. 二.具体 1.混淆矩阵 混淆矩阵如图: 第一个参数true,false是指预测的正确性. 第二个参数true,p ...
- 利用sklearn对MNIST手写数据集开始一个简单的二分类判别器项目(在这个过程中学习关于模型性能的评价指标,如accuracy,precision,recall,混淆矩阵)
.caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { border: 1px so ...
- confusion_matrix(混淆矩阵)
作者:十岁的小男孩 凡心所向,素履可往 目录 监督学习—混淆矩阵 是什么?有什么用?怎么用? 非监督学习—匹配矩阵 混淆矩阵 矩阵每一列代表预测值,每一行代表的是实际的类别.这个名字来源于它可以非常容 ...
- Python绘制混淆矩阵,汉字显示label
1. 在计算出混淆矩阵之后,想自己绘制图形(并且在图形上显示汉字),可用 #coding=utf-8 import matplotlib.pyplot as plt import numpy as n ...
- mIoU混淆矩阵生成函数代码详解
代码参考博客原文: https://blog.csdn.net/jiongnima/article/details/84750819 在原文和原文的引用里,找到了关于mIoU详尽的解释.这里重点解析 ...
- 分类问题(三)混淆矩阵,Precision与Recall
混淆矩阵 衡量一个分类器性能的更好的办法是混淆矩阵.它基于的思想是:计算类别A被分类为类别B的次数.例如在查看分类器将图片5分类成图片3时,我们会看混淆矩阵的第5行以及第3列. 为了计算一个混淆矩阵, ...
- [机器学习]-分类问题常用评价指标、混淆矩阵及ROC曲线绘制方法
分类问题 分类问题是人工智能领域中最常见的一类问题之一,掌握合适的评价指标,对模型进行恰当的评价,是至关重要的. 同样地,分割问题是像素级别的分类,除了mAcc.mIoU之外,也可以采用分类问题的一些 ...
- 10. 混淆矩阵、总体分类精度、Kappa系数
一.前言 表征分类精度的指标有很多,其中最常用的就是利用混淆矩阵.总体分类精度以及Kappa系数. 其中混淆矩阵能够很清楚的看到每个地物正确分类的个数以及被错分的类别和个数.但是,混淆矩阵并不能一眼就 ...
随机推荐
- Java创建和解析Json数据方法(五)——Google Gson包的使用
(五)Google Gson包的使用 1.简介 Gson包中,使用最多的是Gson类的toJson()和fromJson()方法: ①toJson():将java对象转化为json数据 ...
- javascript --- 移除DOM节点
在IE中移除容器类节点,会引起内存泄露,最好是创建一个新的节点,比如div,然后将要删除的节点放入这个div中,再将div的innerHTML清空.其它的直接removeChild就可以了. var ...
- NSThread学习
使用多线程可以防止主线程阻塞.同时也可以将一个大的任务分成若干个小的任务去做. 常用方法一: 1, 首先使用 detachNewThreadSelector:toTarget:withObject: ...
- 第六讲_图像分割Image Segmentation
第六讲_图像分割Image Segmentation 语义分割(semantic segmentation) 常用神经网络介绍对比-FCN SegNet U-net DeconvNet 目录 +三大数 ...
- window.open 打开子窗体,关闭全部的子窗体
需求:通过window.open方法打开了子窗体,当关闭主窗体时.子窗体应当也关闭. 实现思路: 1.打开子窗体函数window.open(url,winName)的第二个參数winName能够唯一标 ...
- Android开发——进程间通信之AIDL(二)
0. 前言 不论是Android还是其它操作系统.都会有自己的IPC机制.所谓IPC(Inter-Process Communication)即进程间通信.首先线程和进程是非常不同的概念,线程是CP ...
- VC++的窗口句柄和窗口ID
原文地址:VC++的窗口句柄和窗口ID作者:放放 句柄是窗口资源的标识,它标识资源在系统中所占用的内存块,应用程序通过窗口句柄对窗口进行操作.除了窗口句柄之外,任何一种资源都有它自己的句柄,比如光标句 ...
- Flex4_Tree组件2(添加多选框、修改树图标)
1.新建AS类,用于为Tree生成复选框,及一些选择事件. package com.th.myUtils { import flash.events.Event; import flash.event ...
- C# 利用ICSharpCode.SharpZipLib实现在线加密压缩和解密解压缩 C# 文件压缩加解密
C# 利用ICSharpCode.SharpZipLib实现在线加密压缩和解密解压缩 这里我们选用ICSharpCode.SharpZipLib这个类库来实现我们的需求. 下载地址:http:// ...
- 读《疯狂Java讲义》笔记总结三
1.初始化块 实际上初始化块是一个假象,使用javac命令编译Java类后,该Java类中的初始化块会消失--初始化块中代码会被 "还原" 到每一个构造器中,且位于构造器全部代码的 ...