最大值最小值归一化

 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()

结果:

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

转载于:https://www.cnblogs.com/yszd/p/9606284.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值