application_vnd.jupyter.stderr_output_1.png
from sklearn.cross_validation import train_test_split

from sklearn.decomposition import PCA

from sklearn.ensemble import AdaBoostClassifier

from sklearn.neighbors import KNeighborsClassifier

from sklearn.preprocessing import Normalizer

from sklearn.svm import SVC

from sklearn.tree import DecisionTreeClassifier

from time import time

import numpy as np

import pandas as pd

start = time()
train_data = pd.read_csv('train.csv')
test_data = pd.read_csv('test.csv')
trainData = train_data.drop('label', 1)
trainLabel = train_data[['label']]
header = trainData.columns
X_train, X_test, y_train, y_test = train_test_split(trainData, trainLabel, test_size=0.3, random_state=1)
norm = Normalizer().fit(X_train)
X_train = norm.transform(X_train)
X_test = norm.transform(X_test)
testData = norm.transform(test_data)
X_train = pd.DataFrame(X_train, columns=header)
X_test = pd.DataFrame(X_test, columns=header)
testData = pd.DataFrame(testData, columns=header)
y_train = y_train.as_matrix()
y_test = y_test.as_matrix()
end = time()

start = time()
component = 30
pca = PCA(n_components=component).fit(X_train)
X_train = pca.transform(X_train)
X_test = pca.transform(X_test)
testData = pca.transform(testData)
X_train = pd.DataFrame(X_train)
X_test = pd.DataFrame(X_test)
testData = pd.DataFrame(testData)
print('PCA - component : {}'.format(component))
neighbors = 5
CLF1 = KNeighborsClassifier(n_neighbors=neighbors).fit(X_train, np.ravel(y_train))
print('CLF | KNN-neighbors : {}'.format(neighbors))
penalty_C = 10.0
CLF2 = SVC(C=penalty_C, gamma=0.1, kernel='rbf').fit(X_train, np.ravel(y_train))
print('CLF | SVM-penalty_C : {}'.format(penalty_C))
max_depth = 15
CLF3 = AdaBoostClassifier(DecisionTreeClassifier(max_depth=max_depth), n_estimators=1000, learning_rate=1.0, algorithm='SAMME.R').fit(X_train, np.ravel(y_train))
print('CLF | Adaboost-max_depth : {}'.format(max_depth))
print('\n---CLF1---')
print('ACC: %f.4' % CLF1.score(X_test, y_test))
print('\n---CLF2---')
print('ACC: %f.4' % CLF2.score(X_test, y_test))
print('\n---CLF3---')
print('ACC: %f.4' % CLF3.score(X_test, y_test))
end = time()
print('\n***Training Done: %.2f ***\n' % (end - start))