import pandas as pd
from sklearn import preprocessing
hmeq = pd.read_csv('hmeq_small.csv')
# Standardize the data
standardized = hmeq.StandardScaler()
# Output the standardized data as a data frame
hmeqStand = standardized(as_frame=True)
# Normalize the data
normalized = hmeq.normalize()
# Output the normalized data as a data frame
hmeqNorm = normalized(as_frame=True)
# Print the means and standard deviations of hmeqStand and hmeqNorm
print("The means of hmeqStand are ", hmeqStand.mean())
print("The standard deviations of hmeqStand are ", hmeqStand.stdev())
print("The means of hmeqNorm are ", hmeqNorm.mean())
print("The standard deviations of hmeqNorm are ", hmeqNorm.stdev())
我试着运行.StandardScaler()
和.normalize()
函数,但不断出现错误。
1条答案
按热度按时间3xiyfsfu1#
StandardScaler和Normalizer来自预处理包,在使用它们之前需要初始化它们。
然后,您可以调整和转换数据