数字热力图

 

静态单图

import numpy as np
import matplotlib.pyplot as plt


# 号码热力图
pre = 49
a = np.random.randint(49, size=pre) + 1 # 模拟前期数据(这里不妨取49)

import collections
c = collections.Counter(a).most_common() # 统计次数

d = np.zeros(49)
for i, x in c:
    d[i-1] = x

image = d.reshape(7,7) # 构造成一个图像

plt.imshow(image, cmap=plt.cm.hot) # 画热力图
plt.colorbar()

#plt.imshow(image, cmap=plt.cm.hot, interpolation="nearest")
#plt.colorbar()

# 为了方便,把号码也对应显示
xx, yy = np.meshgrid(np.arange(7), np.arange(7))
for i, (x, y) in enumerate(zip(xx.flatten(), yy.flatten())):
    c = str(i+1)
    plt.text(x, y, c, va='center', ha='center')
    
plt.show()

 

 

另一个动态的热力图

import numpy as np
import matplotlib.pyplot as plt

import collections

'''动态号码热力图'''

#plt.imshow(image, cmap=plt.cm.hot, interpolation="nearest")
#plt.colorbar()

# 为了方便,把号码也对应显示
xx, yy = np.meshgrid(np.arange(7), np.arange(7))
for i, (x, y) in enumerate(zip(xx.flatten(), yy.flatten())):
    c = str(i+1)
    plt.text(x, y, c, va='center', ha='center')
    
    
# 根据前面历史数据,构造成一个图像
def build_image(a_list):
    c = collections.Counter(a_list).most_common() # 统计次数

    d = np.zeros(49)
    for i, x in c:
        d[i-1] = x
    
    image = d.reshape(7,7) # 构造成一个图像
    
    return image

    
    
for i in range(100):
    if i == 0:
        # 号码热力图
        pre = 49
        a_list = np.random.randint(49, size=pre) + 1 # 模拟前期数据(这里不妨取49)
        image = build_image(a_list)

        im = plt.imshow(image, cmap=plt.cm.hot) # 画热力图
        plt.colorbar()
    else:
        a_list = np.hstack((a_list[1:], np.random.randint(49)+1))
        image = build_image(a_list)
        
        im.set_data(image)
        
    plt.pause(0.1)
    

 

转载于:https://www.cnblogs.com/hhh5460/p/5400865.html

### 数字识别中的热力使用方法及应用场景 在数字识别领域,热力是一种重要的可视化工具,用于展示模型预测的结果及其准确性。以下是关于如何在数字识别中使用热力的方法以及其主要的应用场景。 #### 方法概述 为了绘制混淆矩阵热力并应用于数字识别任务,通常会采用 Python 的 `matplotlib` 和 `seaborn` 库来实现这一功能[^1]。具体来说: - **数据准备**:首先需要构建一个混淆矩阵(Confusion Matrix),该矩阵记录了分类器对于每类标签的真实值与预测值之间的匹配情况。 - **绘函数**:利用 `sns.heatmap()` 函数可以轻松创建热力,并通过参数调整颜色映射、字体大小以及其他样式属性以增强可读性和美观度。 ```python import seaborn as sns import matplotlib.pyplot as plt from sklearn.metrics import confusion_matrix def plot_confusion_matrix(y_true, y_pred, labels): cm = confusion_matrix(y_true, y_pred) fig, ax = plt.subplots(figsize=(8, 6)) sns.heatmap(cm, annot=True, fmt='d', cmap="Blues", xticklabels=labels, yticklabels=labels, ax=ax) ax.set_title('Confusion Matrix Heatmap') ax.set_xlabel('Predicted Labels') ax.set_ylabel('True Labels') plt.show() ``` 上述代码片段展示了如何基于真实标签 (`y_true`) 和预测标签 (`y_pred`) 绘制混淆矩阵热力。 #### 主要应用场景 1. **错误模式分析**:通过对混淆矩阵的观察,研究者能够快速定位哪些类别容易被误判为其他特定类别,进而采取措施改善这些薄弱环节。 2. **模型表现评估**:除了传统的精确率、召回率指标外,热力为用户提供了一种更加直观的方式去理解整个系统的整体性能分布状况。 3. **特征重要性解释**:某些高级技术还可以结合 SHAP 或 LIME 等方法生成局部区域内的贡献程度表示形式——即所谓的“显著性地”,这有助于揭示输入样本内部结构对最终决策的影响机制。 4. **跨域迁移验证**:当尝试将在某一领域训练好的神经网络迁移到另一个新环境中时,比较两者之间产生的差异可以帮助我们判断是否存在过拟合现象或者适应能力不足等问题存在风险。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值