import numpy as np

np.random.seed(1337)  # for reproducibility
from sklearn.datasets import load_boston
from sklearn.cross_validation import train_test_split
from sklearn.metrics.regression import r2_score, mean_squared_error
from sklearn.preprocessing import MinMaxScaler
import pandas as pd
from dbn.tensorflow import SupervisedDBNRegression


# Loading dataset
stats = pd.read_csv('/Users/yash/Documents/machine learning/Tutorial/Deep_Learning_A_Z/Volume 2 - Unsupervised Deep Learning/Part 5 - Boltzmann Machines (BM)/RBMtime/Stats/dataset_n.csv')
X  = stats.iloc[:,2:].values
Y = stats.iloc[:,1].values
X = np.array(X)
Y  = np.array(Y)
# 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)))