<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_train,y_train)
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 0.131 seconds
Test score with 3NN is: 0.9150
Test time 0.990 seconds
Test score with 3NN is: 0.9150<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_train,y_train)
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>Training time 0.140 seconds
Test score with 5NN is: 0.9200
Test time 0.957 seconds
Test score with 5NN is: 0.9200<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_train,y_train)
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>Training time 0.161 seconds
Test score with 1NN is: 0.9300
Test time 0.952 seconds
Test score with 1NN is: 0.9300<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:10200]
y_train, y_test = y[:10000], y[10000:10200]
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_train,y_train)
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.30454215
Iteration 2, loss = 2.30125955
Iteration 3, loss = 2.30120262
Iteration 4, loss = 2.30058722
Iteration 5, loss = 2.30042938
Iteration 6, loss = 2.29943975
Iteration 7, loss = 2.29867319
Iteration 8, loss = 2.29834305
Iteration 9, loss = 2.29773144
Iteration 10, loss = 2.29659269
Iteration 11, loss = 2.29551009
Iteration 12, loss = 2.29415868
Iteration 13, loss = 2.29271219
Iteration 14, loss = 2.29080467
Iteration 15, loss = 2.28815967
Iteration 16, loss = 2.28567883
Iteration 17, loss = 2.28233864
Iteration 18, loss = 2.27804437
Iteration 19, loss = 2.27350144
Iteration 20, loss = 2.26689236
Iteration 21, loss = 2.25943889
Iteration 22, loss = 2.25020769
Iteration 23, loss = 2.23991498
Iteration 24, loss = 2.22809553
Iteration 25, loss = 2.21294113
Iteration 26, loss = 2.19509497
Iteration 27, loss = 2.17492325
Iteration 28, loss = 2.15165413
Iteration 29, loss = 2.12602172
Iteration 30, loss = 2.09749275
Iteration 31, loss = 2.06691795
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_train,y_train)
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.30800662
Iteration 2, loss = 2.30288661
Iteration 3, loss = 2.30179307
Iteration 4, loss = 2.30179997
Iteration 5, loss = 2.30213552
Iteration 6, loss = 2.30119653
Iteration 7, loss = 2.30092266
Iteration 8, loss = 2.30070933
Iteration 9, loss = 2.29981106
Iteration 10, loss = 2.30022172
Iteration 11, loss = 2.29862128
Iteration 12, loss = 2.29712283
Iteration 13, loss = 2.29611147
Iteration 14, loss = 2.29387955
Iteration 15, loss = 2.28984783
Iteration 16, loss = 2.28109478
Iteration 17, loss = 2.26712063
Iteration 18, loss = 2.24307923
Iteration 19, loss = 2.25598550
Iteration 20, loss = 2.27592082
Iteration 21, loss = 2.22471399
Iteration 22, loss = 2.25716824
Iteration 23, loss = 2.21686140
Iteration 24, loss = 2.27704808
Iteration 25, loss = 2.25683880
Iteration 26, loss = 2.21989608
Training loss did not improve more than tol=0.000100 for two consecutive epochs. Stopping.
Training time of Double hidden layer perceptron is: 10.984 seconds
Test score with Dou[...]<jupyter_text>Linear function SVM<jupyter_code># Import datasets, classifiers and performance metrics
from sklearn import datasets, svm, metrics
import time
start_time = time.time()
#Classifier Declaration
## Linear
clf = svm.SVC(kernel = 'linear', C = 1)
##
#Train the classifier
clf.fit(X_train,y_train)
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 = clf.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>Training time of linear function SVM is: 1.704 seconds
Test score with linear function SVM is: 0.9200
Test time of of linear function SVM is: 0.198 seconds<jupyter_text>Polynormial function SVM<jupyter_code>import time
start_time = time.time()
#Classifier Declaration
## Linear
clf = svm.SVC(kernel = 'poly',degree = 3, C = 1)
##
#Train the classifier
clf.fit(X_train,y_train)
train_time = time.time() - start_time
start_time = time.time()
print("Training time of polynormial function SVM is: %.3f seconds" % train_time)
#Evaluate the result
score = clf.score(X_test,y_test)
print("Test score with polynormila function SVM is: %.4f" % score)
test_time = time.time() - start_time
print("Test time of polynormial function SVM is: %.3f seconds" % test_time)<jupyter_output>Training time of polynormial function SVM is: 7.816 seconds
Test score with polynormila function SVM is: 0.1100
Test time of polynormial function SVM is: 0.528 seconds<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_train,y_train)
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 = clf.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>Training time of radial basis function SVM is: 8.571 seconds
Test score with radial basis function SVM is: 0.1850
Test time of ofradial basis function SVM is: 0.577 seconds
{'fraction_non_alphanumeric': 0.10158872230924144, 'fraction_numerical': 0.09275005594092638, 'mean_word_length': 5.143642611683849, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '586756', 'license': 'MIT', 'n_tokens_mistral': 3732, 'n_tokens_neox': 3086, 'n_words': 980, 'path': 'lab7/lab7 partB.ipynb', 'repo_name': 'wwwbxy123/Computer-Vision-Explore', 'size': '8938'}