Commit b71629ce authored by Ard Kastrati's avatar Ard Kastrati
Browse files

Prepared the experiment for kNN

parent 3c25aa75
...@@ -27,7 +27,7 @@ from config import config ...@@ -27,7 +27,7 @@ from config import config
def cross_validate_kNN(X, y): def cross_validate_kNN(X, y):
logging.info("Cross-validation KNN...") logging.info("Cross-validation KNN...")
classifier = KNeighborsClassifier(weights='uniform', algorithm='auto', n_jobs=-1) classifier = KNeighborsClassifier(weights='uniform', algorithm='auto', n_jobs=-1)
parameters_KNN = {'n_neighbors': [5, 10, 50], 'leaf_size': [10, 30]} parameters_KNN = {'n_neighbors': [5, 25, 100], 'leaf_size': [10, 50]}
cross_validate(classifier=classifier, parameters=parameters_KNN, X=X, y=y) cross_validate(classifier=classifier, parameters=parameters_KNN, X=X, y=y)
def cross_validate_SVC(X, y): def cross_validate_SVC(X, y):
...@@ -44,7 +44,7 @@ def cross_validate_RFC(X, y): ...@@ -44,7 +44,7 @@ def cross_validate_RFC(X, y):
def cross_validate(classifier, parameters, X, y): def cross_validate(classifier, parameters, X, y):
X = X.reshape((36223, 500 * 129)) X = X.reshape((36223, 500 * 129))
clf = GridSearchCV(classifier, parameters, scoring='accuracy', n_jobs=-1, verbose=3) clf = GridSearchCV(classifier, parameters, scoring='accuracy', n_jobs=-1, verbose=3, cv=2)
clf.fit(X, y.ravel()) clf.fit(X, y.ravel())
export_dict(clf.cv_results_['mean_fit_time'], clf.cv_results_['std_fit_time'], clf.cv_results_['mean_score_time'], export_dict(clf.cv_results_['mean_fit_time'], clf.cv_results_['std_fit_time'], clf.cv_results_['mean_score_time'],
...@@ -60,17 +60,17 @@ def try_sklearn_classifiers(X, y): ...@@ -60,17 +60,17 @@ def try_sklearn_classifiers(X, y):
logging.info("Training the simple classifiers: kNN, Linear SVM, Random Forest and Naive Bayes.") logging.info("Training the simple classifiers: kNN, Linear SVM, Random Forest and Naive Bayes.")
names = [# "Nearest Neighbors", names = [# "Nearest Neighbors",
# "Linear SVM", # "Linear SVM",
"Random Forest", # "Random Forest",
"Naive Bayes", # "Naive Bayes",
"Linear SVM" "Linear SVM"
] ]
classifiers = [ classifiers = [
# KNeighborsClassifier(n_neighbors=5, weights='uniform', algorithm='auto', leaf_size=30, n_jobs=-1), # KNeighborsClassifier(n_neighbors=5, weights='uniform', algorithm='auto', leaf_size=30, n_jobs=-1),
# LinearSVC(tol=1e-5, C=1, random_state=42, max_iter=1000), # LinearSVC(tol=1e-5, C=1, random_state=42, max_iter=1000),
RandomForestClassifier(n_estimators=30, max_depth=20, max_features='auto', random_state=42, n_jobs=-1), # RandomForestClassifier(n_estimators=30, max_depth=20, max_features='auto', random_state=42, n_jobs=-1),
GaussianNB(), # GaussianNB(),
LinearSVC(tol=1e-3, C=5, random_state=42, max_iter=500) LinearSVC(tol=1e-3, C=20, random_state=42, max_iter=500)
] ]
X = X.reshape((36223, 500 * 129)) X = X.reshape((36223, 500 * 129))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment