from sklearn.kernel_approximation import RBFSampler
from sklearn.feature_selection import SelectKBest
from sklearn.gaussian_process import GaussianProcessClassifier
from sklearn.gaussian_process.kernels import RBF
from sklearn import tree
from sklearn.ensemble import RandomForestClassifier
from sklearn.ensemble import VotingClassifier
# import matplotlib.pyplot as plt
from preprocess import read_and_preprocess

pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)

# # Read data
kFolds = 4
X, y = read_and_preprocess(True)

X.drop(labels="playerID", axis=1, inplace=True)

# Models
# KNN classifier
model = KNeighborsClassifier()

# Grid Search
start = time.perf_counter()
X = preprocessing.StandardScaler().fit_transform(X)

parameters = {'n_neighbors': [3, 5, 7, 9]}
print(model)
gridSearch = GridSearchCV(model, parameters, cv=kFolds, n_jobs=kFolds).fit(X, y)
results = pd.DataFrame(gridSearch.cv_results_)
Exemple #2
0
import time

import pandas as pd
from sklearn import preprocessing
from sklearn import svm
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import GridSearchCV

from preprocess import read_and_preprocess

pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)

# # Read data
X, y = read_and_preprocess(False)
kFolds = 4

### Model ###
# SVM
model = svm.SVC()

### Grid Search ###
start = time.perf_counter()
X = preprocessing.StandardScaler().fit_transform(X)
parameters = {'kernel': ['rbf', 'poly'], 'gamma': [0.5, 0.75, 1, 1.25, 1.5]}

gridSearch = GridSearchCV(model, parameters, cv=kFolds,
                          n_jobs=kFolds).fit(X, y)
results = pd.DataFrame(gridSearch.cv_results_)
results = results.drop(labels=["std_fit_time", "std_score_time", "params"],
from sklearn import svm
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
import preprocess

# get features and labels
X, Y = preprocess.read_and_preprocess()
X_train, X_test, Y_train, Y_test = train_test_split(X,
                                                    Y,
                                                    test_size=0.1,
                                                    random_state=100)

clf = svm.SVC()
clf = clf.fit(X_train, Y_train)

Y_pred = clf.predict(X_test)

print "SVM successfully trained"
print "prediction vector : ", Y_pred

acc_score = accuracy_score(Y_test, Y_pred)
print "Accuracy score : {}".format(acc_score)