-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuncertainty.py
More file actions
67 lines (58 loc) · 3.42 KB
/
uncertainty.py
File metadata and controls
67 lines (58 loc) · 3.42 KB
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
# https://github.com/catboost/catboost/blob/master/catboost/tutorials/uncertainty/uncertainty_regression.ipynb
from catboost import Pool, CatBoostRegressor
import pathlib
path = pathlib.Path(__file__).parent.resolve()
# Initialize data
# fmt: off
train = [
[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8],
[1, 0], [1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8],
[2, 0], [2, 1], [2, 3], [2, 4], [2, 5], [2, 7], [2, 8],
[3, 0], [3, 4], [3, 8],
[4, 0], [4, 1], [4, 7], [4, 8],
[5, 0], [5, 1], [5, 2], [5, 6], [5, 7], [5, 8],
[6, 0], [6, 1], [6, 2], [6, 3], [6, 5], [6, 6], [6, 7], [6, 8],
[7, 0], [7, 1], [7, 2], [7, 3], [7, 4], [7, 5], [7, 6], [7, 7], [7, 8],
[8, 0], [8, 1], [8, 2], [8, 3], [8, 4], [8, 5], [8, 6], [8, 7], [8, 8],
]
target = [
0.72521874, 0.81306316, 0.78951918, 0.63989202, 0.41333291, 0.66029847, 0.51369098, 0.93615932, 1.11307067,
0.41474829, 0.53642606, 0.70178216, 0.79502002, 0.93017249, 0.22431398, 0.11811878, -0.06856018, 0.79782863,
0.90118582, 0.79254678, 0.58944797, 0.29085234, 0.67859874, 0.38936195, -0.0180365, 0.7655756, 0.67207266,
0.61199905, 0.61874744, 0.49006958, -0.07426662, 0.58545209, 0.68838048, 0.04736273, -0.05253338, 0.58441963,
1.10231391, 0.14227897, 0.12179704, 0.13015426, 0.53659334, 0.34642409, 0.54207603, 0.27684754, 0.00329988,
0.61601189, 0.15901045, 0.232219, 0.36977517, 0.83368444, 0.47373142, 0.71089641, -0.02121393, 0.93509757,
0.6609454, 1.16351698, 0.51872295, 0.71246324, 0.13391299, 0.3442149, 0.15783911, 0.32596401, 0.04927093,
0.27446782,
]
val_target = [
0.5888292247640471, 0.9392786862925653, 0.5050355880840027, 0.5297474621671271, 0.46471464953274194, 0.7913214637629536,
0.44975471291197533, 0.9251404335195065, 0.9431469341244492, 0.29803194489560525, 0.8570868976267007, 0.3804619156716161,
0.4226079936340558, 0.9068782532900777, 0.21797193518791544, 0.16276180362197543, -0.177861249382067, 0.848254742458336,
0.8983947358282917, 0.809551598131752, 0.5151549767809285, 0.6565569017761108, 0.6929143159642182, 0.7954190924939059,
0.12207925938764953, 1.0220494166214362, 0.5381072526097342, 0.7033018711819606, 0.6423429124963995, 0.5443857636773293,
-0.01168516067883843, 0.4941384552125, 0.6304597759973332, 0.25666078662641834, 0.1393153768140811, 0.46439809561380246,
0.8648912560238609, 0.03356380165399675, 0.15099178961839316, 0.1669260521079708, 0.7431909741608171, -0.05395713471566266,
0.6236034272077193, 0.14097710006428463, 0.2158203138574188, 0.7785740965035162, 0.2358468549969851, 0.26723967849924835,
0.5473122200515477, 0.8611921661924052, -0.17245053643542801, 0.934884578314605, 0.2904605264588923, 0.90171398386932,
0.616702680791144, 1.0673655540178757, 0.7958520150549493, 0.8195092189779412, 0.023686782945237253, 0.37502762973306225,
0.010256482154749447, 0.42877878719084794, 0.10376426492147697, 0.5029095522419103,
]
# fmt: on
train_pool = Pool(train, target, cat_features=[0, 1])
val_pool = Pool(train, val_target, cat_features=[0, 1])
# Initialize CatBoostRegressor
model = CatBoostRegressor(
iterations=1000,
learning_rate=0.2,
loss_function="RMSEWithUncertainty",
verbose=False,
random_seed=0,
)
# Fit model
model.fit(train_pool, eval_set=val_pool)
# Get predicted Class
preds = model.predict([[0, 0]])
print(f"Preds `RMSEWithUncertainty`: {preds}")
# Save model
model.save_model(f"{path}/uncertainty.cbm")