Skip to content

Instantly share code, notes, and snippets.

@koshian2
Created May 29, 2018 21:51
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/ce491e1149203530ede91c5b5bad2365 to your computer and use it in GitHub Desktop.
Save koshian2/ce491e1149203530ede91c5b5bad2365 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.ensemble import RandomForestClassifier
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)
# ランダムフォレストは標準化いらない
# ランダムフォレスト
rf = RandomForestClassifier(max_depth=8)
rf.fit(x_train, y_train)
print("Elapsed[s] : ", time.time() - start_time)
print("Train :", rf.score(x_train, y_train))
print("Test :", rf.score(x_test, y_test))
# デフォルト→Overfitting
#Elapsed[s] : 30.51237440109253
#Train : 0.99394
#Test : 0.3576
# max_depth=8
#Elapsed[s] : 18.324826955795288
#Train : 0.434
#Test : 0.3717#Test : 0.3747
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment