-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_boston.py
41 lines (29 loc) · 910 Bytes
/
run_boston.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
import numpy as np
import tensorflow as tf
import pickle
import matplotlib.pyplot as plt
from varlinreg import VarLinReg
from varlinregtf import VarLinRegTf
# load data
with open('boston.pkl', 'rb') as f:
data = pickle.load(f, encoding='latin1')
X=data["X"]
y=data["y"]
N = X.shape[0] # num data points
# Shuffle the data
idx = np.random.permutation(X.shape[0])
# determine the training set size
Ntr = np.int(N*0.9)
# Split the data into train and test
Xtr = X[idx[0:Ntr],:] # train input
Xts = X[idx[Ntr:],:] # test input
ytr = y[idx[0:Ntr]] # train output
yts = y[idx[Ntr:]] # test output
# Create model instance
model = VarLinRegTf()
# Train and predict
model.train(Xtr, ytr)
ypred = model.predict(Xts)
ypred_mean = ypred[0] # get the predictive mean
rmse = np.sqrt(np.mean((ypred_mean - yts)**2))
print("Root mean squared error is", rmse)