<jupyter_start><jupyter_text>KNN neighbor = 3<jupyter_code>import time
start_time = time.time()
#Classifier Declaration
KNN = neighbors.KNeighborsClassifier(n_neighbors=3)
#Train the classifier
KNN.fit(X,y)
train_time = time.time() - start_time
start_time = time.time()
print("Training time %.3f seconds" % train_time)
#Evaluate the result
score = KNN.score(X_test,y_test)
print("Test score with 3NN is: %.4f" % score)
test_time = time.time() - start_time
print("Test time %.3f seconds" % test_time)
print("Test score with 3NN is: %.4f" % score)<jupyter_output>Training time 163.337 seconds<jupyter_text>KNN neighbor=5<jupyter_code>import time
start_time = time.time()
#Classifier Declaration
KNN = neighbors.KNeighborsClassifier(n_neighbors=5)
#Train the classifier
KNN.fit(X,y)
train_time = time.time() - start_time
start_time = time.time()
print("Training time %.3f seconds" % train_time)
#Evaluate the result
score = KNN.score(X_test,y_test)
print("Test score with 5NN is: %.4f" % score)
test_time = time.time() - start_time
print("Test time %.3f seconds" % test_time)
print("Test score with 5NN is: %.4f" % score)<jupyter_output><empty_output><jupyter_text>KNN neighbor=1<jupyter_code>import time
start_time = time.time()
#Classifier Declaration
KNN = neighbors.KNeighborsClassifier(n_neighbors=1)
#Train the classifier
KNN.fit(X,y)
train_time = time.time() - start_time
start_time = time.time()
print("Training time %.3f seconds" % train_time)
#Evaluate the result
score = KNN.score(X_test,y_test)
print("Test score with 1NN is: %.4f" % score)
test_time = time.time() - start_time
print("Test time %.3f seconds" % test_time)
print("Test score with 1NN is: %.4f" % score)<jupyter_output><empty_output><jupyter_text>single hidden layer perceptron<jupyter_code># Standard scientific Python import
import time
import io
import matplotlib.pyplot as plt
import numpy as np
from scipy.io.arff import loadarff

from sklearn.neural_network import MLPClassifier
from sklearn.datasets import get_data_home
from sklearn.externals.joblib import Memory
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.utils import check_random_state
from urllib.request import urlopen
# rescale the data, use the traditional train/test split

X = X / 255.

###### NEW  Refromat the the labels to be integers rather than byte arrays
y_trans = []
for i in range(len(y)):
    y_trans.append(int(y[i]))
y = np.asarray(y_trans)

X_train, X_test = X[:10000], X[10000:]
y_train, y_test = y[:10000], y[10000:]
import time
start_time = time.time()
#Classifier Declaration
# Single hidden layer
mlp = MLPClassifier(hidden_layer_sizes=(50,), max_iter=40, alpha=1e-4,
                    solver='sgd', verbose=10, tol=1e-4, random_state=1,
                    learning_rate_init=.1)
# Note, the iteration limit will be reached! 
#Train the classifier
mlp.fit(X,y)
train_time = time.time() - start_time
start_time = time.time()
print("Training time of Single hidden layer perceptron is: %.3f seconds" % train_time)
#Evaluate the result
score = mlp.score(X_test,y_test)
print("Test score with Single hidden layer perceptron is: %.4f" % score)
test_time = time.time() - start_time
print("Test time of of Single hidden layer perceptron is: %.3f seconds" % test_time)<jupyter_output>Iteration 1, loss = 2.30177414
Iteration 2, loss = 2.29640579
Iteration 3, loss = 2.28079607
Iteration 4, loss = 2.22430802
Iteration 5, loss = 2.06978627
Iteration 6, loss = 1.87692259
Iteration 7, loss = 1.73030194
Iteration 8, loss = 1.57107123
Iteration 9, loss = 1.48629060
Iteration 10, loss = 1.32709638
Iteration 11, loss = 1.20931433
Iteration 12, loss = 1.14219911
Iteration 13, loss = 1.01709561
Iteration 14, loss = 0.91444504
Iteration 15, loss = 0.85380360
Iteration 16, loss = 0.79627242
Iteration 17, loss = 0.75783681
Iteration 18, loss = 0.69868661
Iteration 19, loss = 0.68157973
Iteration 20, loss = 0.66439737
Iteration 21, loss = 0.64161187
Iteration 22, loss = 0.62998200
Iteration 23, loss = 0.59340712
Iteration 24, loss = 0.59331972
Iteration 25, loss = 0.58458257
Iteration 26, loss = 0.55399646
Iteration 27, loss = 0.55201760
Iteration 28, loss = 0.53965429
Iteration 29, loss = 0.51772597
Iteration 30, loss = 0.51751486
Iteration 31, loss = 0.50862867
Iteration 32, los[...]<jupyter_text>Double hidden layer perceptron<jupyter_code>import time
start_time = time.time()
#Classifier Declaration
# Two hidden layers
mlp_2 = MLPClassifier(hidden_layer_sizes=(50,50), max_iter=40, alpha=1e-4,
                    solver='sgd', verbose=10, tol=1e-4, random_state=1,
                    learning_rate_init=.1)
#
#Train the classifier
mlp_2.fit(X,y)
train_time = time.time() - start_time
start_time = time.time()
print("Training time of Double hidden layer perceptron is: %.3f seconds" % train_time)
#Evaluate the result
score = mlp_2.score(X_test,y_test)
print("Test score with Double hidden layer perceptron is: %.4f" % score)
test_time = time.time() - start_time
print("Test time of of Double hidden layer perceptron is: %.3f seconds" % test_time)<jupyter_output>Iteration 1, loss = 2.30276770
Iteration 2, loss = 2.29844983
Iteration 3, loss = 2.25937831
Iteration 4, loss = 2.25532811
Iteration 5, loss = 2.20611945
Iteration 6, loss = 2.16756758
Iteration 7, loss = 2.13828029
Iteration 8, loss = 2.12182886
Iteration 9, loss = 2.06342671
Iteration 10, loss = 2.01456683
Iteration 11, loss = 1.94533658
Iteration 12, loss = 1.96352857
Iteration 13, loss = 1.98564846
Iteration 14, loss = 1.94674204
Training loss did not improve more than tol=0.000100 for two consecutive epochs. Stopping.
Training time of Double hidden layer perceptron is: 35.302 seconds
Test score with Double hidden layer perceptron is: 0.2749
Test time of of Double hidden layer perceptron is: 9.492 seconds<jupyter_text>Linear function SVM<jupyter_code># Standard scientific Python imports
import time
import io
import matplotlib.pyplot as plt
import numpy as np

# Import datasets, classifiers and performance metrics
from sklearn import datasets, svm, metrics
from scipy.io.arff import loadarff
from sklearn.datasets import get_data_home
from sklearn.externals.joblib import Memory
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.utils import check_random_state
from urllib.request import urlopen

import time
start_time = time.time()
#Classifier Declaration
## Linear
clf = svm.SVC(kernel = 'linear', C = 1)
##
#Train the classifier
clf.fit(X,y)
train_time = time.time() - start_time
start_time = time.time()
print("Training time of linear function SVM is: %.3f seconds" % train_time)
#Evaluate the result
score = mlp_2.score(X_test,y_test)
print("Test score with linear function SVM is: %.4f" % score)
test_time = time.time() - start_time
print("Test time of of linear function SVM is: %.3f seconds" % test_time)<jupyter_output><empty_output><jupyter_text>Polynormial function SVM<jupyter_code>import time
start_time = time.time()
#Classifier Declaration
## cubic polynomial
clf = svm.SVC(kernel = 'poly',degree = 3, C = 1)
##
#Train the classifier
clf.fit(X,y)
train_time = time.time() - start_time
start_time = time.time()
print("Training time of poly function SVM is: %.3f seconds" % train_time)
#Evaluate the result
score = mlp_2.score(X_test,y_test)
print("Test score with poly function SVM is: %.4f" % score)
test_time = time.time() - start_time
print("Test time of of poly function SVM is: %.3f seconds" % test_time)<jupyter_output><empty_output><jupyter_text>radial basis function SVM<jupyter_code>import time
start_time = time.time()
#Classifier Declaration
## Radial basis functions
clf = svm.SVC(kernel = 'rbf', C = 1, gamma = 0.5)

#Train the classifier
clf.fit(X,y)
train_time = time.time() - start_time
start_time = time.time()
print("Training time of radial basis function SVM is: %.3f seconds" % train_time)
#Evaluate the result
score = mlp_2.score(X_test,y_test)
print("Test score with radial basis function SVM is: %.4f" % score)
test_time = time.time() - start_time
print("Test time of ofradial basis function SVM is: %.3f seconds" % test_time)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10364822420874607, 'fraction_numerical': 0.07320608842715631, 'mean_word_length': 5.324675324675325, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '341998', 'license': 'MIT', 'n_tokens_mistral': 3316, 'n_tokens_neox': 2838, 'n_words': 865, 'path': 'lab7/.ipynb_checkpoints/lab7 partB-checkpoint.ipynb', 'repo_name': 'wwwbxy123/Computer-Vision-Explore', 'size': '8278'}