### ソースコード
import
1import numpy as np 2from sklearn.preprocessing import MinMaxScaler 3df=pandas.read_csv( 'http://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-red.csv ',sep=';') 4array=df.values 5x=array[:,0:8] 6y=array[:,8] 7scaler=MinMaxScaler(feature_range=(0,1)) 8rescaledX=scaler.fit_transform(x) 9np.set_printoptions(precision=3) 10rescaledX[0:5,:] 11 12import matplotlib.pyplot as plt 13from mpl_toolkits.mplot3d import Axes3D 14from sklearn import decomposition 15from sklearn import datasets 16 17np.random.seed(5) 18 19centers = [[1, 1], [-1, -1], [1, -1]] 20 21X = rescaledX 22 23fig = plt.figure(1, figsize=(4, 3)) 24plt.clf() 25ax = Axes3D(fig, rect=[0, 0, .95, 1], elev=48, azim=134) 26 27plt.cla() 28pca = decomposition.PCA(n_components=2) 29pca.fit(X) 30X = pca.transform(X) 31 32for name, label in [('a', 0), ('b', 1)]: 33 ax.text3D(X[y == label, 0].mean(), 34 X[y == label, 1].mean() + 1.5, 35 X[y == label, 2].mean(), name, 36 horizontalalignment='center', 37 bbox=dict(alpha=.5, edgecolor='w', facecolor='w')) 38 39y = np.choose(y, [1, 2, 0]).astype(np.float) 40ax.scatter(X[:, 0], X[:, 1], X[:, 2], c=y, cmap=plt.cm.nipy_spectral, 41 edgecolor='k') 42 43ax.w_xaxis.set_ticklabels([]) 44ax.w_yaxis.set_ticklabels([]) 45ax.w_zaxis.set_ticklabels([]) 46 47plt.show()
エラー内容
IndexError Traceback (most recent call last)
<ipython-input-4-8333174d1e05> in <module>
22 ax.text3D(X[y == label, 0].mean(),
23 X[y == label, 1].mean() + 1.5,
---> 24 X[y == label, 2].mean(), name,
25 horizontalalignment='center',
26 bbox=dict(alpha=.5, edgecolor='w', facecolor='w'))
IndexError: index 2 is out of bounds for axis 1 with size 2