私はデータセットを持っています。最初の 10 の数字は私の特徴 (1、2、...、10) で、最後の列は私の目標です (MID と HIGH を含む 2 つの目標しかありません)。データは、次のような txt 形式 (data.txt) で保存されます。
200000,400000,5000000,100000,5000000,50000,50000,300000,3333,1333,MID
200000,100000,500000,100000,5000000,5000,50000,300000,2000,1333,MID
100000,400000,5000000,100000,5000000,5000,50000,300000,2000,3333,MID
400000,200000,50000000,100000,5000000,5000,50000,300000,3333,3333,MID
200000,200000,5000000,100000,5000000,5000,50000,300000,3333,1333,HIGH
200000,100000,500000,10000000,5000000,50000,50000,300000,3333,3333,HIGH
100000,200000,500000,100000,5000000,50000,50000,300000,3333,666,HIGH
200000,100000,500000,1000000,5000000,50000,50000,300000,3333,666,HIGH
200000,100000,5000000,1000000,5000000,50000,5000,300000,3333,1333,HIGH
利用可能なチュートリアルに基づいて LDA 分析を実装しようとしました。また、列9と10の単位が最初の 8 列とは異なるため、正規化にはStandardScalerを使用しました。これが私が試したものです:
import pandas as pd
from matplotlib import pyplot as plt
import numpy as np
import math
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.preprocessing import StandardScaler
df = pd.read_csv('data.txt', header=None)
df.columns=['one','two','three','four','five','six','seven','eight','nine','ten','class']
X = df.ix[:,0:10].values
y = df.ix[:,10].values
X_std = StandardScaler().fit_transform(X)
lda = LinearDiscriminantAnalysis(n_components=2)
X_r2 = lda.fit_transform(X_std,y)
with plt.style.context('seaborn-whitegrid'):
plt.figure(figsize=(8, 6))
for lab, col in zip(('MID', 'HIGH'),
('blue', 'red')):
plt.scatter(X_r2[y==lab, 0],
X_r2[y==lab, 1],
label=lab,s=100,
c=col)
plt.xlabel('LDA 1')
plt.ylabel('LDA 2')
plt.legend(loc='lower right')
plt.tight_layout()
plt.savefig('Results.png', format='png', dpi=1200)
plt.show()
このエラーが発生しています:
line 32, in <module>X_r2[y==lab, 1],
IndexError: index 1 is out of bounds for axis 1 with size 1
この問題を解決する方法を知っている人はいますか? よろしくお願いします。