最大值最小值歸一化


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

結果:

分析:可知,數據的離散性大大降低,數據之間的內聚性增加,數據更加密集!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM