python 可视化

来源:互联网 发布:太阳黑子与气候数据 编辑:程序博客网 时间:2024/05/16 14:22

1,绘制散点图:

# k_to_accuracies: A dictionary holding the accuracies for different values of k that we find when running cross-validation with int key and list value.for k in k_choices:    accuracies = k_to_accuracies[k]    plt.scatter([k] * len(accuracies), accuracies)# plot the trend line with error bars that correspond to standard deviationaccuracies_mean = np.array([np.mean(v) for k,v in sorted(k_to_accuracies.items())])accuracies_std = np.array([np.std(v) for k,v in sorted(k_to_accuracies.items())])plt.errorbar(k_choices, accuracies_mean, yerr=accuracies_std)plt.title('Cross-validation on k')plt.xlabel('k')plt.ylabel('Cross-validation accuracy')plt.show()

原创粉丝点击