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

ndarray.argmax, argmin

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 用在求解混淆矩阵用的更多相关文章

  1. 机器学习 - 案例 - 样本不均衡数据分析 - 信用卡诈骗 ( 标准化处理, 数据不均处理, 交叉验证, 评估, Recall值, 混淆矩阵, 阈值 )

    案例背景 银行评判用户的信用考量规避信用卡诈骗 ▒ 数据 数据共有 31 个特征, 为了安全起见数据已经向了模糊化处理无法读出真实信息目标 其中数据中的 class 特征标识为是否正常用户 (0 代表 ...

  2. 【机器学习】--模型评估指标之混淆矩阵,ROC曲线和AUC面积

    一.前述 怎么样对训练出来的模型进行评估是有一定指标的,本文就相关指标做一个总结. 二.具体 1.混淆矩阵 混淆矩阵如图:  第一个参数true,false是指预测的正确性.  第二个参数true,p ...

  3. 利用sklearn对MNIST手写数据集开始一个简单的二分类判别器项目(在这个过程中学习关于模型性能的评价指标,如accuracy,precision,recall,混淆矩阵)

    .caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { border: 1px so ...

  4. confusion_matrix(混淆矩阵)

    作者:十岁的小男孩 凡心所向,素履可往 目录 监督学习—混淆矩阵 是什么?有什么用?怎么用? 非监督学习—匹配矩阵 混淆矩阵 矩阵每一列代表预测值,每一行代表的是实际的类别.这个名字来源于它可以非常容 ...

  5. Python绘制混淆矩阵,汉字显示label

    1. 在计算出混淆矩阵之后,想自己绘制图形(并且在图形上显示汉字),可用 #coding=utf-8 import matplotlib.pyplot as plt import numpy as n ...

  6. mIoU混淆矩阵生成函数代码详解

    代码参考博客原文: https://blog.csdn.net/jiongnima/article/details/84750819 在原文和原文的引用里,找到了关于mIoU详尽的解释.这里重点解析  ...

  7. 分类问题(三)混淆矩阵,Precision与Recall

    混淆矩阵 衡量一个分类器性能的更好的办法是混淆矩阵.它基于的思想是:计算类别A被分类为类别B的次数.例如在查看分类器将图片5分类成图片3时,我们会看混淆矩阵的第5行以及第3列. 为了计算一个混淆矩阵, ...

  8. [机器学习]-分类问题常用评价指标、混淆矩阵及ROC曲线绘制方法

    分类问题 分类问题是人工智能领域中最常见的一类问题之一,掌握合适的评价指标,对模型进行恰当的评价,是至关重要的. 同样地,分割问题是像素级别的分类,除了mAcc.mIoU之外,也可以采用分类问题的一些 ...

  9. 10. 混淆矩阵、总体分类精度、Kappa系数

    一.前言 表征分类精度的指标有很多,其中最常用的就是利用混淆矩阵.总体分类精度以及Kappa系数. 其中混淆矩阵能够很清楚的看到每个地物正确分类的个数以及被错分的类别和个数.但是,混淆矩阵并不能一眼就 ...

随机推荐

  1. Ubuntu 16.04安装Wine版的迅雷+QQ(完美方案,终极解决方法)

    安装前先备份好系统! 继上一篇安装QQ的方法http://www.cnblogs.com/EasonJim/p/7425978.html,这一篇的QQ采用的是Wine模式安装.完美解决消息记录中文乱码 ...

  2. 第四章——SQLServer2008-2012资源及性能监控(1)专家

    http://blog.csdn.net/dba_huangzj/article/details/8614817

  3. U-boot for Tiny4412

    我的开发板型号: Tiny4412ADK + S700 4GB Flash 1. Build uboot a) 安装好toolchain (arm-linux-gcc-4.5.1-v6-vfp-201 ...

  4. 邁向IT專家成功之路的三十則鐵律 鐵律十二:IT人養生之道-德行

    所謂的「養生」在中國古代裡所指的是針對內在精神層面修為的提升,到了近代中醫所謂的養生,則除了包含最根本的內在精神層面之外,還涵蓋了外在身體的養護.在現今各行各業的人士當中,嚴格來說都應該要有一套專屬的 ...

  5. 【spring cloud】spring cloud服务发现注解之@EnableDiscoveryClient与@EnableEurekaClient

    spring cloud服务发现注解之@EnableDiscoveryClient与@EnableEurekaClient的区别

  6. BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第12章节--SP 2013中远程Event Receivers 远程Event Receivers App级别生命周期

    BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第12章节--SP 2013中远程Event Receivers  远程Event Receivers App级别生命周期 ...

  7. 转:Json 语法 格式

    转自: http://www.cnblogs.com/chencidi/archive/2011/03/24/1993450.html 评注: json 官网如下: http://json.org/j ...

  8. AngularJS的ng-repeat显示表格

    代码下载:https://files.cnblogs.com/files/xiandedanteng/angualrJSngRepeatTable.rar 代码: <!DOCTYPE HTML ...

  9. ArcGIS 10.1系列产品 升级安装至 ArcGIS 10.2

    概要 分享ArcGIS10.1系列产品(包括desktop.engine.server)升级到ArcGIS10.2的过程,并提供安装ArcGIS10.2安装的详细文档下载链接和crack需要的文件: ...

  10. C语言-回溯例3

    排列问题 1.实现排列A(n,m)对指定的正整数m,n(约定1<m<=n),具体实现排列A(n,m).2. 回溯算法设计设置一维数组a,a(i)(i=1,2,…,m)在1—n中取值.首先从 ...