-
Notifications
You must be signed in to change notification settings - Fork 325
/
Copy pathensemble_regression.py
37 lines (31 loc) · 1.34 KB
/
ensemble_regression.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
import numpy as np
from modAL.disagreement import max_std_sampling
from modAL.models import ActiveLearner, CommitteeRegressor
from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels import RBF, WhiteKernel
np.random.seed(0)
# generating the data
X = np.concatenate((np.random.rand(100)-1, np.random.rand(100)))
y = np.abs(X) + np.random.normal(scale=0.2, size=X.shape)
# initializing the regressors
n_initial = 10
kernel = RBF(length_scale=1.0, length_scale_bounds=(1e-2, 1e3)) \
+ WhiteKernel(noise_level=1, noise_level_bounds=(1e-10, 1e+1))
initial_idx = list()
initial_idx.append(np.random.choice(range(100), size=n_initial, replace=False))
initial_idx.append(np.random.choice(range(100, 200), size=n_initial, replace=False))
learner_list = [ActiveLearner(
estimator=GaussianProcessRegressor(kernel),
X_training=X[idx].reshape(-1, 1), y_training=y[idx].reshape(-1, 1)
)
for idx in initial_idx]
# initializing the Committee
committee = CommitteeRegressor(
learner_list=learner_list,
query_strategy=max_std_sampling
)
# active regression
n_queries = 10
for idx in range(n_queries):
query_idx, query_instance = committee.query(X.reshape(-1, 1))
committee.teach(X[query_idx].reshape(-1, 1), y[query_idx].reshape(-1, 1))