我正在尝试使用mlpy绘制一个精彩的PCA,而c
的{{1}}参数会导致异常。
数据集:http://mlpy.sourceforge.net/docs/3.5/_downloads/iris.csv
plt.scatter
我有以下错误:
import mlpy
from matplotlib.mlab import PCA
import matplotlib.pyplot as plt
def classification():
# x: (observations x attributes) matrix
x = np.array(iris)[:, :4]
# y: classes (1: setosa, 2: versicolor, 3: virginica)
outputs_file="/Users/vasques/Desktop/classification.csv"
y = np.loadtxt(outputs_file, delimiter=',')[:, 4].astype(np.int)
pca = mlpy.PCA() # new PCA instance
pca.learn(x) # learn from data
z = pca.transform(x, k=2) # embed x into the k=2 dimensional subspace
plt.set_cmap(plt.cm.Paired)
fig1 = plt.figure(1)
title = plt.title("PCA")
plot = plt.scatter(z[:, 0], z[:, 1], c=y)
labx = plt.xlabel("First component")
laby = plt.ylabel("Second component")
plt.show()
当我在Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/matplotlib/artist.py", line 59, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/Library/Python/2.7/site-packages/matplotlib/figure.py", line 1050, in draw
func(*args)
File "/Library/Python/2.7/site-packages/matplotlib/artist.py", line 59, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/Library/Python/2.7/site-packages/matplotlib/axes/_base.py", line 2075, in draw
a.draw(renderer)
File "/Library/Python/2.7/site-packages/matplotlib/collections.py", line 729, in draw
Collection.draw(self, renderer)
File "/Library/Python/2.7/site-packages/matplotlib/artist.py", line 59, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/Library/Python/2.7/site-packages/matplotlib/collections.py", line 301, in draw
self._offset_position)
File "/Library/Python/2.7/site-packages/matplotlib/backends/backend_macosx.py", line 79, in draw_path_collection
all_transforms = [t.get_matrix() for t in all_transforms]
AttributeError: 'numpy.ndarray' object has no attribute 'get_matrix'
中删除c=y
时,它会运行,但我只有一种颜色,不允许我识别这些群组。