歸一化 Z-Score
這里簡單記錄一下歸一化的公式以及python實現歸一化的代碼。
公式:

介紹:其中x為數組中某一個具體元素,u是數組的平均數,σ是數組的標准差。
下面附上python代碼:
import math def get_average(records): return sum(records) / len(records) def get_variance(records): average = get_average(records) return sum([(x - average) ** 2 for x in records]) / len(records) def get_standard_deviation(records): variance = get_variance(records) return math.sqrt(variance) def get_z_score(records): avg = get_average(records) stan = get_standard_deviation(records) scores = [(i-avg)/stan for i in records] return scores
函數功能介紹:
get_average:求數組平均數
get_variance:求數組方差
get_standard_deviation:求數組標准差
get_z_score:求數組的z-score歸一化最后的結果