-
Notifications
You must be signed in to change notification settings - Fork 212
/
example_regression.py
36 lines (28 loc) · 1.22 KB
/
example_regression.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
import numpy as np
np.random.seed(1337) # for reproducibility
from sklearn.datasets import load_boston
from sklearn.model_selection import train_test_split
from sklearn.metrics.regression import r2_score, mean_squared_error
from sklearn.preprocessing import MinMaxScaler
from dbn.tensorflow import SupervisedDBNRegression
# Loading dataset
boston = load_boston()
X, Y = boston.data, boston.target
# Splitting data
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, random_state=1337)
# Data scaling
min_max_scaler = MinMaxScaler()
X_train = min_max_scaler.fit_transform(X_train)
# Training
regressor = SupervisedDBNRegression(hidden_layers_structure=[100],
learning_rate_rbm=0.01,
learning_rate=0.01,
n_epochs_rbm=20,
n_iter_backprop=200,
batch_size=16,
activation_function='relu')
regressor.fit(X_train, Y_train)
# Test
X_test = min_max_scaler.transform(X_test)
Y_pred = regressor.predict(X_test)
print('Done.\nR-squared: %f\nMSE: %f' % (r2_score(Y_test, Y_pred), mean_squared_error(Y_test, Y_pred)))