Google Colaboratoryを使用し、以下のコードを非線形のものにする。線形、非線形のことを理解しておらず、どのように手を施していいか分かりません。以下のコードの結果は図のようになりました。カーネルSVMを識別の実装を行うことが必要となっていますが、理解できていません。
Python
1import keras 2from keras.datasets import mnist 3import matplotlib.pyplot as plt 4 5# Read MNIST data 6(X_train, y_train), (X_test, y_test) = mnist.load_data() 7 8# display images 9for i in range(0, 32): 10 plt.subplot(4, 8, i+1) 11 plt.imshow(X_train[i], cmap='gray') 12 13plt.show() 14
以下のコードをCIFAR10データセットを用いた場合を実行したいのですが、どのようにすれば実行できるのでしょうか。画像サイズを変える必要があるとのことですがGoogle Colaboratoryを利用してどのようにやるかができていません。情報不足ではありますが、分かる範囲のことを教えて頂きたいです。
Python
1import keras 2from keras.datasets import mnist 3from sklearn import svm 4from sklearn.metrics import accuracy_score, confusion_matrix 5 6# input/output size 7in_size = 28 * 28 8out_size = 10 9 10# read MNIST data 11(X_train, y_train), (X_test, y_test) = mnist.load_data() 12 13# 28*28 -> 784 14X_train = X_train.reshape(-1, 784).astype('float32') / 255 15X_test = X_test.reshape(-1, 784).astype('float32') / 255 16 17# train 18print('Training...') 19classifier = svm.LinearSVC() 20classifier.fit(X_train, y_train) 21 22# test 23print('Testing...') 24predicted = classifier.predict(X_test) 25 26print('target : ' + str(y_test)) 27print('predicted: ' + str(predicted)) 28 29print('accuracy = %.4f\n' % accuracy_score(y_test, predicted)) 30print('confusion matrix:') 31print(confusion_matrix(y_test, predicted)) 32 33実行結果 34Training... 35Testing... 36target : [7 2 1 ... 4 5 6] 37predicted: [7 2 1 ... 4 5 6] 38accuracy = 0.9187 39 40confusion matrix: 41[[ 962 0 2 1 1 4 5 3 1 1] 42 [ 0 1112 3 2 0 1 5 1 11 0] 43 [ 11 11 914 18 10 4 13 12 36 3] 44 [ 4 0 19 918 2 22 5 12 20 8] 45 [ 1 4 5 4 913 0 9 3 6 37] 46 [ 9 2 0 38 12 770 17 7 29 8] 47 [ 7 4 7 2 5 21 909 1 2 0] 48 [ 2 8 23 5 7 1 1 948 5 28] 49 [ 11 12 8 20 14 31 8 13 845 12] 50 [ 7 8 2 15 31 12 0 26 12 896]] 51/usr/local/lib/python3.6/dist-packages/sklearn/svm/_base.py:947: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations. 52 "the number of iterations.", ConvergenceWarning)
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。