Created
May 29, 2018 21:18
-
-
Save koshian2/a5b8f904b371b7425b9cbaa54cdcad9d to your computer and use it in GitHub Desktop.
CIFAR-10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from keras.datasets import cifar10 | |
from sklearn.linear_model import LogisticRegression | |
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) | |
# ロジスティック回帰 | |
logr = LogisticRegression() | |
logr.fit(x_train, y_train) | |
print("Elapsed[s] : ", time.time() - start_time) | |
print("Train :", logr.score(x_train, y_train)) | |
print("Test :", logr.score(x_test, y_test)) | |
#Elapsed[s] : 329.31931829452515 | |
#Train : 0.41996 | |
#Test : 0.4072 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment