-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
conformal_preds.py
80 lines (71 loc) · 2.75 KB
/
conformal_preds.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import os
import nnetsauce as ns
import numpy as np
from sklearn.datasets import load_diabetes, fetch_california_housing
from sklearn.model_selection import train_test_split
from sklearn.linear_model import Ridge
from sklearn.ensemble import ExtraTreesRegressor, RandomForestRegressor
from time import time
print(f"\n ----- Running: {os.path.basename(__file__)}... ----- \n")
print(f"\n ----- fetch_california_housing ----- \n")
data = fetch_california_housing()
X = data.data
y= data.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = .3, random_state = 213)
print(f"X_train.shape(): {X_train.shape}")
print(f"X_test.shape(): {X_test.shape}")
regr = ns.PredictionInterval(obj=ExtraTreesRegressor(),
type_pi="bootstrap",
replications=100,
level=95,
seed=312)
start = time()
regr.fit(X_train, y_train)
print(f"Elapsed: {time() - start}s")
preds = regr.predict(X_test)
print(preds)
print(f"coverage_rate: {np.mean((preds[2]<=y_test)*(preds[3]>=y_test))}")
regr2 = ns.PredictionInterval(obj=ExtraTreesRegressor(),
type_pi="kde",
replications=100,
level=95,
seed=312)
start = time()
regr2.fit(X_train, y_train)
print(f"Elapsed: {time() - start}s")
preds2 = regr2.predict(X_test)
print(preds2)
print(f"coverage_rate: {np.mean((preds2[2]<=y_test)*(preds2[3]>=y_test))}")
regr = ns.PredictionInterval(obj=RandomForestRegressor(),
type_pi="bootstrap",
replications=100,
level=95,
seed=312)
start = time()
regr.fit(X_train, y_train)
print(f"Elapsed: {time() - start}s")
preds = regr.predict(X_test)
print(preds)
print(f"coverage_rate: {np.mean((preds[2]<=y_test)*(preds[3]>=y_test))}")
regr2 = ns.PredictionInterval(obj=RandomForestRegressor(),
type_pi="kde",
replications=100,
level=95,
seed=312)
start = time()
regr2.fit(X_train, y_train)
print(f"Elapsed: {time() - start}s")
preds2 = regr2.predict(X_test)
print(preds2)
print(f"coverage_rate: {np.mean((preds2[2]<=y_test)*(preds2[3]>=y_test))}")
regr2 = ns.PredictionInterval(obj=Ridge(),
type_pi="kde",
replications=100,
level=95,
seed=312)
start = time()
regr2.fit(X_train, y_train)
print(f"Elapsed: {time() - start}s")
preds2 = regr2.predict(X_test)
print(preds2)
print(f"coverage_rate: {np.mean((preds2[2]<=y_test)*(preds2[3]>=y_test))}")