import pandas as pd
import numpy as np
data = pd.read_excel(‘F:/result/dangdang.xls’)
data2 = data.T
comment = data2.values[2]
price = data2.values[3]
print(price.max())
离差标准化(最小-最大标准化)——消除量纲(单位)影响以及变异大小因素的影响
x1 = (x-min)/(max-min)
comment1 = (comment-comment.min())/(comment.max()-comment.min())
price1 = (price-price.min())/(price.max()-price.min())
print(comment1)
print(price1)
标准差标准化(零-均值标准化)——消除单位影响以及变量自身变异影响。
x1 = (x-平均数)/标准差 所得数据平均数为0,标准差为1
comment2 = (comment1-comment1.mean())/comment.std()
#print(comment2)
小数定标规范化——消除单位影响
x1 = x/10**(k) 、k=lg(x的绝对值的最大值)
z = comment.abs().max() # .abs() 取绝对值
k = np.ceil(np.log10(z)) # np.ceil:进1取整
comment3 = comment/10**k
print(comment3)
print(np.ceil(4.1))
离散化
等宽离散化(0-50,50-10。。。)
等频率离散化(将相同频率的数据归在一起)
一维聚类离散化
等宽
comment4 = comment.copy()
comment5 = comment4.T
comment6 = comment5
print(comment6)
k = 610
k = [0,50,100,300,396]
p1 = pd.cut(price,k,labels=[“很便宜”,“便宜”,“适中”,“小贵”,“很贵”])
print(p1)