-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDemo_LR.py
More file actions
37 lines (27 loc) · 705 Bytes
/
Demo_LR.py
File metadata and controls
37 lines (27 loc) · 705 Bytes
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
import numpy as np
# change this to switch algorithm & types of validation (jho, jkfold, jloo)
from MLR.lr import jkfold
import matplotlib.pyplot as plt
from sklearn import datasets
# load data
X, Y = datasets.load_diabetes(return_X_y=True)
feat = X[:, np.newaxis, 2]
label = Y
# parameters
kfold = 10
opts = {'kfold':kfold}
# LR with k-fold
mdl = jkfold(feat, label, opts)
# overall mse
mse = mdl['mse']
# overall r2 score
r2 = mdl['r2']
# Plot outputs
xtest = mdl['xtest']
ytest = mdl['ytest']
ypred = mdl['ypred']
plt.scatter(xtest, ytest, color='black')
plt.plot(xtest, ypred, color='blue', linewidth=3)
plt.xticks(())
plt.yticks(())
plt.show()