最大值最小值归一化

复制代码
 1 # -*- coding: utf-8 -*-
 2 """
 3 Created on Fri Sep  7 16:28:20 2018
 4 
 5 @author: zhen
 6 """
 7 # 最大值最小值归一化:(X-Xmin)/(Xmax-Xmin)
 8 import numpy as np
 9 import matplotlib.pyplot as plt
10 
11 x = np.random.rand(100)
12 x = x.reshape(-1, 1)
13 
14 rand = np.random.rand(100) * np.random.randint(10)
15 rand = rand.reshape(-1, 1)
16 # 获取Xmax,Xmin
17 x_max = np.max(rand)
18 x_min = np.min(rand)
19 
20 result = []
21 # 查找数组的索引:np.where(rand == i)
22 for i in rand:
23     result.append((float(i[0]) - x_min)/(x_max - x_min))
24     
25 result = np.array(result, dtype = float)
26 result = result.reshape(-1, 1)
27 # 可视化
28 plt.plot(x, rand, "r.", label="native")
29 plt.plot(x, result, "b.", linewidth=2, label="normalized")
30 
31 plt.legend(loc="upper left")
32 plt.grid()
33 plt.show()
复制代码

结果:

分析:可知,数据的离散性大大降低,数据之间的内聚性增加,数据更加密集!

posted @   云山之巅  阅读(6214)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示