Python Machine Learning学习笔记

2.1 通过降维压缩数据

  • 主特征分析(PCA),压缩非监督学习数据
  • 线性判别分析(PDA),降维监督学习数据
  • 核心主特征分析(KPCA),降维非线性数据 ### Sklearn PCA

In [5]:



---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-5-8b857522d61f> in <module>()
     34 X_test_pca = pca.transform(X_test_std)
     35 lr.fit(X_train_pca, y_train)
---> 36 plot_decision_regions(X_train_pca, y_train, classifier=lr)
     37 plt.xlabel('PC1')
     38 plt.ylabel('PC2')

<ipython-input-5-8b857522d61f> in plot_decision_regions(X, y, classifier, resolution)
      9     markers = ('s', 'x', 'o', '^', 'v')
     10     colors = ('red', 'blue', 'lightgreen', 'gray', 'cyan')
---> 11     cmap = ListedColormap(colors[:len(np.unique(y))])
     12     # plot the decision surface
     13     x1_min, x1_max = X[:, 0].min() - 1, X[:, 0].max() + 1

NameError: global name 'np' is not defined

In [ ]: