Skip to content

Instantly share code, notes, and snippets.

@koshian2
Created May 29, 2018 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koshian2/09c1c21dc08fbb769eaaf836c5d9940a to your computer and use it in GitHub Desktop.
Save koshian2/09c1c21dc08fbb769eaaf836c5d9940a to your computer and use it in GitHub Desktop.
CIFAR-10
import numpy as np
import matplotlib.pyplot as plt
from keras.datasets import cifar10
from sklearn.svm import LinearSVC
import time
start_time = time.time()
# データの読み込み
(x_train, y_train), (x_test, y_test) = cifar10.load_data()
# 小数化
x_train = x_train / 255
x_test = x_test / 255
# データ数
m_train, m_test = x_train.shape[0], x_test.shape[0]
# ベクトル化
x_train, x_test = x_train.reshape(m_train, -1), x_test.reshape(m_test, -1)
# ノルムで標準化
x_train = x_train / np.linalg.norm(x_train, ord=2, axis=1, keepdims=True)
x_test = x_test / np.linalg.norm(x_test, ord=2, axis=1, keepdims=True)
# サポートベクトルマシン
svc = LinearSVC()
svc.fit(x_train, y_train)
print("Elapsed[s] : ", time.time() - start_time)
print("Train :", svc.score(x_train, y_train))
print("Test :", svc.score(x_test, y_test))
#Elapsed[s] : 275.0674293041229
#Train : 0.45122
#Test : 0.4062
#ちなみにノルムで標準化を切ると
#Elapsed[s] : 3692.342868089676
#Train : 0.4203
#Test : 0.3093
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment