forked from nagizeroiw/prpr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluate.py
54 lines (40 loc) · 1.66 KB
/
evaluate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#from __future__ import print_function
# Authors: Yann N. Dauphin, Vlad Niculae, Gabriel Synnaeve
# License: BSD
import numpy as np
import matplotlib.pyplot as plt
from scipy.ndimage import convolve
from sklearn import linear_model, datasets, metrics
from sklearn.model_selection import train_test_split
from sklearn.neural_network import BernoulliRBM
from sklearn.pipeline import Pipeline
import data_engine
def load_data():
engine = data_engine.data_engine()
engine.load()
return [engine.train_x.reshape([-1, 32 * 32]), engine.train_y, engine.test_x.reshape([-1, 32 * 32]), engine.test_y]
def get_prediction(X_train, Y_train, X_test, Y_test):
logistic = linear_model.LogisticRegression()
rbm = BernoulliRBM(random_state=0, verbose=True)
classifier = Pipeline(steps=[('rbm', rbm), ('logistic', logistic)])
rbm.learning_rate = 0.005
rbm.n_iter = 100
# More components tend to give better prediction performance, but larger
# fitting time
rbm.n_components = 64
logistic.C = 6000.0
# Training RBM-Logistic Pipeline
classifier.fit(X_train, Y_train)
# Training Logistic regression
logistic_classifier = linear_model.LogisticRegression(C=100.0)
logistic_classifier.fit(X_train, Y_train)
print("Logistic regression using RBM features:\n%s\n" % (
metrics.classification_report(
Y_test,
classifier.predict(X_test))))
print("Logistic regression using raw pixel features:\n%s\n" % (
metrics.classification_report(
Y_test,
logistic_classifier.predict(X_test))))
X_train, Y_train, X_test, Y_test = load_data()
get_prediction(X_train, Y_train, X_test, Y_test)