我正在尝试进行标准化(z-score标准化(
x = data[['BALANCE', 'BALANCE_FREQUENCY', 'PURCHASES']]
std_scale = preprocessing.StandardScaler().fit(x)
df_std = std_scale.transform(x)
print('Mean after standardization:nBALANCE={:.2f}, BALANCE_FREQUENCY={:.2f}, PURCHASES={:.2f}'.format(df_std[:,0].mean(), df_std[:,1].mean, df_std[:,2].mean()))
print('nStandard deviation after standardization:nBALANCE={:.2f}, BALANCE_FREQUENCY={:.2f}, PURCHASES={:.2f}'.format(df_std[:,0].std(), df_std[:,1].std, df_std[:,2].std()))
我得到了这个错误:
---> 10 .format(df_std[:,0].mean(), df_std[:,1].mean, df_std[:,2].mean()))
TypeError: unsupported format string passed to builtin_function_or_method.__format__
mean
和std
的函数调用中缺少括号。
print('Mean after standardization:nBALANCE={:.2f}, BALANCE_FREQUENCY={:.2f}, PURCHASES={:.2f}'.format(df_std[:,0].mean(), df_std[:,1].mean(), df_std[:,2].mean()))
print('nStandard deviation after standardization:nBALANCE={:.2f}, BALANCE_FREQUENCY={:.2f}, PURCHASES={:.2f}'.format(df_std[:,0].std(), df_std[:,1].std(), df_std[:,2].std()))