1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
-
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
-
- import matplotlib.pyplot as plt
- from sklearn.neural_network import MLPClassifier
- from sklearn.model_selection import train_test_split
- from sklearn.model_selection import KFold
- from sklearn.metrics import precision_score
- from sklearn.metrics import confusion_matrix
- from sklearn.svm import SVC
- import random
- import time
-
- """
- from sklearn.datasets import fetch_openml
- mnist = fetch_openml('mnist_784')
- """
-
- """
- images = mnist.data.values.reshape((-1, 28, 28))
- plt.imshow(images[0],cmap=plt.cm.gray_r,interpolation="nearest")
- plt.show()
-
- print(mnist.target[0])
- """
-
- """
- indices = [i for i in range(len(mnist.data))]
- random.shuffle(indices)
- indices = indices[:15000]
-
- data = [mnist.data.values[i] for i in indices]
- target = [mnist.target[i] for i in indices]
- """
-
- xtrain, xtest, ytrain, ytest = train_test_split(data, target, train_size=0.7)
-
- clf = SVC()
- clf.fit(xtrain, ytrain)
- ypred = clf.predict(xtest)
- print(confusion_matrix(ytest, ypred))
- """
- print(target[4])
- print(clf.predict(data[4].reshape(1,-1)))
- plt.imshow(data[4].reshape(28, 28), cmap=plt.cm.gray_r, interpolation="nearest")
- plt.show()
- """
-
-
- """
- kernels = ["linear", "poly", "rbf", "sigmoid"]
- for k in kernels:
- print(k + ":")
- start_time = time.time()
- clf = SVC(kernel = k)
- clf.fit(xtrain, ytrain)
- print(f"training time = {time.time() - start_time}, score = {clf.score(xtest, ytest)}")
- """
-
- """
- scores = []
- times = []
- tolerance=[i*0.1 for i in range(1,10,2)]
- for C in tolerance:
- print(f"C = {C} :")
- start_time = time.time()
- clf = SVC(C = C)
- clf.fit(xtrain, ytrain)
- training_time = time.time() - start_time
- score = clf.score(xtest, ytest)
- times += [training_time]
- scores += [score]
-
- plt.plot(tolerance, scores)
- plt.show()
- plt.plot(tolerance, times)
- """
|