![](/img/trans.png)
[英]How to resolve an issue with TypeError: unsupported format string passed to numpy.ndarray.__format__
[英]how to resolve issue with an unsupported format string passed to builtin_function_or_method.__format__
我正在尝试进行标准化(z-score normalization)
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
的 function 调用中缺少括号。
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()))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.