【问题标题】:What does y_p :::python do in this (or any) script?y_p :::python 在这个(或任何)脚本中做了什么?
【发布时间】:2016-02-13 03:51:57
【问题描述】:

我正在尝试完成 Sebastian Raschka 关于特征缩放的教程,但我无法运行下面的代码,因为它在第三行(以“python”结尾的行)抛出错误。

from matplotlib import pyplot as plt

fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(nrows=2, ncols=2, figsize=(10,5))

y_p    :::python
    # Standardization

    x = [1,4,5,6,6,2,3]
    mean = sum(x)/len(x)
    std_dev = (1/len(x) * sum([ (x_i - mean)**2 for x_i in x]))**0.5

    z_scores = [(x_i - mean)/std_dev for x_i in x]

    # Min-Max scaling

    minmax = [(x_i - min(x)) / (min(x) - max(x)) for x_i in x]os = [0 for i in range(len(x))]

ax1.scatter(z_scores, y_pos, color='g')
ax1.set_title('Python standardization', color='g')

ax2.scatter(minmax, y_pos, color='g')
ax2.set_title('Python Min-Max scaling', color='g')

ax3.scatter(z_scores_np, y_pos, color='b')
ax3.set_title('Python NumPy standardization', color='b')
The-effect-of-standardization
ax4.scatter(np_minmax, y_pos, color='b')
ax4.set_title('Python NumPy Min-Max scaling', color='b')

plt.tight_layout()

for ax in (ax1, ax2, ax3, ax4):
    ax.get_yaxis().set_visible(False)
    ax.grid()

plt.show()

那么,y_p :::python 做了什么?

【问题讨论】:

    标签: python python-2.7 numpy matplotlib


    【解决方案1】:

    答案是它不是有效的 Python 代码。

    您应该查看 ipython 笔记本,我相信您从中获得了该代码的某些部分。

    http://nbviewer.jupyter.org/github/rasbt/pattern_classification/blob/master/preprocessing/about_standardization_normalization.ipynb

    相关的sn-p是

    from matplotlib import pyplot as plt
    
    fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(nrows=2, ncols=2, figsize=(10,5))
    
    y_pos = [0 for i in range(len(x))]
    
    ax1.scatter(z_scores, y_pos, color='g')
    ax1.set_title('Python standardization', color='g')
    

    【讨论】:

    • 这很有趣。实际上,我使用的代码来自网站:sebastianraschka.com/Articles/2014_about_feature_scaling.html,但您链接到的笔记本要干净得多。也许它可以将网站转换为笔记本或其他东西?无论如何,感谢您为我解决这个问题。我很感激。
    • 显然 HTML 导出搞砸了
    猜你喜欢
    • 2014-01-14
    • 2022-01-10
    • 1970-01-01
    • 2011-08-26
    • 2013-07-10
    • 2012-04-05
    • 2022-08-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多