MCPcopy Create free account
hub / github.com/modAL-python/modAL / CommitteeRegressor

Class CommitteeRegressor

modAL/models/learners.py:632–714  ·  view source on GitHub ↗

This class is an abstract model of a committee-based active learning regression. Args: learner_list: A list of ActiveLearners forming the CommitteeRegressor. query_strategy: Query strategy function. on_transformed: Whether to transform samples with the pipeline defin

Source from the content-addressed store, hash-verified

630
631
632class CommitteeRegressor(BaseCommittee):
633 """
634 This class is an abstract model of a committee-based active learning regression.
635 Args:
636 learner_list: A list of ActiveLearners forming the CommitteeRegressor.
637 query_strategy: Query strategy function.
638 on_transformed: Whether to transform samples with the pipeline defined by each learner's estimator
639 when applying the query strategy.
640 Examples:
641 >>> import numpy as np
642 >>> import matplotlib.pyplot as plt
643 >>> from sklearn.gaussian_process import GaussianProcessRegressor
644 >>> from sklearn.gaussian_process.kernels import WhiteKernel, RBF
645 >>> from modAL.models import ActiveLearner, CommitteeRegressor
646 >>>
647 >>> # generating the data
648 >>> X = np.concatenate((np.random.rand(100)-1, np.random.rand(100)))
649 >>> y = np.abs(X) + np.random.normal(scale=0.2, size=X.shape)
650 >>>
651 >>> # initializing the regressors
652 >>> n_initial = 10
653 >>> kernel = RBF(length_scale=1.0, length_scale_bounds=(1e-2, 1e3)) + WhiteKernel(noise_level=1, noise_level_bounds=(1e-10, 1e+1))
654 >>>
655 >>> initial_idx = list()
656 >>> initial_idx.append(np.random.choice(range(100), size=n_initial, replace=False))
657 >>> initial_idx.append(np.random.choice(range(100, 200), size=n_initial, replace=False))
658 >>> learner_list = [ActiveLearner(
659 ... estimator=GaussianProcessRegressor(kernel),
660 ... X_training=X[idx].reshape(-1, 1), y_training=y[idx].reshape(-1, 1)
661 ... )
662 ... for idx in initial_idx]
663 >>>
664 >>> # query strategy for regression
665 >>> def ensemble_regression_std(regressor, X):
666 ... _, std = regressor.predict(X, return_std=True)
667 ... return np.argmax(std)
668 >>>
669 >>> # initializing the CommitteeRegressor
670 >>> committee = CommitteeRegressor(
671 ... learner_list=learner_list,
672 ... query_strategy=ensemble_regression_std
673 ... )
674 >>>
675 >>> # active regression
676 >>> n_queries = 10
677 >>> for idx in range(n_queries):
678 ... query_idx, query_instance = committee.query(X.reshape(-1, 1))
679 ... committee.teach(X[query_idx].reshape(-1, 1), y[query_idx].reshape(-1, 1))
680 """
681 def __init__(self, learner_list: List[ActiveLearner], query_strategy: Callable = max_std_sampling,
682 on_transformed: bool = False) -> None:
683 super().__init__(learner_list, query_strategy, on_transformed)
684
685 def predict(self, X: modALinput, return_std: bool = False, **predict_kwargs) -> Any:
686 """
687 Predicts the values of the samples by averaging the prediction of each regressor.
688 Args:
689 X: The samples to be predicted.

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…