2016-02-13 46 views
-1

我想通过Sebastian Raschka在功能缩放上的教程,我无法得到下面的代码运行,因为它引发和第三行错误,以'python'结束。y_p ::: 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是做什么的?

回答

1

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

你应该看看ipython笔记本,我相信你从那里得到了一些代码的一部分。

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

相关的片段是

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') 
+0

这很有趣。其实我使用的代码来自网站:http://sebastianraschka.com/Articles/2014_about_feature_scaling.html但你链接到的笔记本更清洁。也许它是在那里将网站转换为笔记本电脑或其他东西?无论如何,谢谢你为我清理那个。我很感激。 – user3426752

+0

显然,HTML导出已经搞砸了 –