print展示例子
积累了一些很好的数据分析方法,
print
真的很美。持续更新中。
%.4f结果保留4位小数
- Example1
print("C=%.2f" % C)
print("{:<40} {:.2f}%".format("Sparsity with L1 penalty:", sparsity_l1_LR))
print("{:<40} {:.2f}%".format("Sparsity with Elastic-Net penalty:", sparsity_en_LR))
print("{:<40} {:.2f}%".format("Sparsity with L2 penalty:", sparsity_l2_LR))
print("{:<40} {:.2f}".format("Score with L1 penalty:", clf_l1_LR.score(X, y)))
print(
"{:<40} {:.2f}".format("Score with Elastic-Net penalty:", clf_en_LR.score(X, y))
)
print("{:<40} {:.2f}".format("Score with L2 penalty:", clf_l2_LR.score(X, y)))
其结果为:
- Example2
print("Sparsity with L1 penalty: %.2f%%" % sparsity)
print("Test score with L1 penalty: %.4f" % score)
print("Example run in %.3f s" % run_time)
print('训练集均方误差根: %.3f, 测试集均方误差根: %.3f' % (mean_squared_error(y_train, y_train_pred)**0.5,\
mean_squared_error(y_test, y_test_pred)**0.5))
print('训练集拟合优度: %.3f, 测试集拟合优度: %.3f' %(r2_score(y_train, y_train_pred),r2_score(y_test, y_test_pred)))
其结果为:
To be continue