ClassificationProgressiveLearner¶
- class proglearn.ClassificationProgressiveLearner(default_transformer_class=None, default_transformer_kwargs=None, default_voter_class=None, default_voter_kwargs=None, default_decider_class=None, default_decider_kwargs=None)[source]¶
A (mostly) internal class for progressive learning in the classification setting. Most users who desire to utilize ProgLearn should use the classes defined in {network, forest}.py instead of this class.
Methods Summary
Adds a task to the progressive learner. |
|
Adds a transformer to the progressive learner and trains the voters and deciders from this new transformer to the specified backward_task_ids. |
|
predicts labels under task_id for each example in input data X using the given transformer_ids. |
|
predicts posteriors under task_id for each example in input data X using the given transformer_ids. |
|
- ClassificationProgressiveLearner.add_task(X, y, task_id=None, transformer_voter_decider_split=[0.67, 0.33, 0], num_transformers=1, transformer_class=None, transformer_kwargs=None, voter_class=None, voter_kwargs=None, decider_class=None, decider_kwargs=None, backward_task_ids=None, forward_transformer_ids=None)¶
Adds a task to the progressive learner. Optionally trains one or more transformer from the input data (if num_transformers > 0), adds voters and deciders from this/these new transformer(s) to the tasks specified in backward_task_ids, and adds voters and deciders from the transformers specified in forward_transformer_ids (and from the newly added transformer(s) corresponding to the input task_id if num_transformers > 0) to the new task_id.
- Parameters
X : ndarray
Input data matrix.
y : ndarray
Output (response) data matrix.
task_id : obj, default=None
The id corresponding to the task being added.
transformer_voter_decider_split : ndarray, default=[0.67, 0.33, 0]
A 1d array of length 3. The 0th index indicates the proportions of the input data used to train the (optional) newly added transformer(s) corresponding to the task_id provided in this function call. The 1st index indicates the proportion of the data set aside to train the voter(s) from these (optional) newly added transformer(s) to the task_id provided in this function call. For all other tasks, the aggregate transformer and voter data pairs from those tasks are used to train the voter(s) from these (optional) newly added transformer(s) to those tasks; for all other transformers, the aggregate transformer and voter data provided in this function call is used to train the voter(s) from those transformers to the task_id provided in this function call. The 2nd index indicates the proportion of the data set aside to train the decider - these indices are saved internally and will be used to train all further deciders corresponding to this task for all function calls.
num_transformers : int, default=1
The number of transformers to add corresponding to the given inputs.
transformer_class : BaseTransformer, default=None
The class of the transformer(s) being added.
transformer_kwargs : dict, default=None
A dictionary with keys of type string and values of type obj corresponding to the given string kwarg. This determines the kwargs of the transformer(s) being added.
voter_class : BaseVoter, default=None
The class of the voter(s) being added.
voter_kwargs : dict, default=None
A dictionary with keys of type string and values of type obj corresponding to the given string kwarg. This determines the kwargs of the voter(s) being added.
decider_class : BaseDecider, default=None
The class of the decider(s) being added.
decider_kwargs : dict, default=None
A dictionary with keys of type string and values of type obj corresponding to the given string kwarg. This determines the kwargs of the decider(s) being added.
backward_task_ids : ndarray, default=None
A 1d array of type obj used to specify to which existing task voters and deciders will be trained from the transformer(s) being added.
foward_transformer_ids : ndarray, default=None
A 1d array of type obj used to specify from which existing transformer(s) voters and deciders will be trained to the new task. If num_transformers > 0, the input task_id corresponding to the task being added is automatically appended to this 1d array.
- Returns
self : ProgressiveLearner
The object itself.
- ClassificationProgressiveLearner.add_transformer(X, y, transformer_data_proportion=1.0, transformer_voter_data_idx=None, transformer_id=None, num_transformers=1, transformer_class=None, transformer_kwargs=None, backward_task_ids=None)¶
Adds a transformer to the progressive learner and trains the voters and deciders from this new transformer to the specified backward_task_ids.
- Parameters
X : ndarray
Input data matrix.
y : ndarray
Output (response) data matrix.
transformer_data_proportion : float, default=1.0
The proportion of the data set aside to train the transformer. The remainder of the data is used to train voters. This is used in the case that you are using a bagging algorithm and want the various components in that bagging ensemble to train on disjoint subsets of the data. This parameter is mostly for internal use.
transformer_voter_data_idx : ndarray, default=None
A 1d array of type int used to specify the aggregate indices of the input data used to train the transformers and voters. This is used in the case that X and/or y contain data that you do not want to use to train transformers or voters (e.g. X and/or y contains decider training data disjoint from the transformer/voter data). This parameter is mostly for internal use.
transformer_id : obj, default=None
The id corresponding to the transformer being added.
num_transformers : int, default=1
The number of transformers to add corresponding to the given inputs.
transformer_class : BaseTransformer, default=None
The class of the transformer(s) being added.
transformer_kwargs : dict, default=None
A dictionary with keys of type string and values of type obj corresponding to the given string kwarg. This determines the kwargs of the transformer(s) being added.
backward_task_ids : ndarray, default=None
A 1d array of type obj used to specify to which existing task voters and deciders will be trained from the transformer(s) being added.
- Returns
self : ProgressiveLearner
The object itself.
- ClassificationProgressiveLearner.get_task_ids()¶
- ClassificationProgressiveLearner.get_transformer_ids()¶
- ClassificationProgressiveLearner.predict(X, task_id, transformer_ids=None)¶
predicts labels under task_id for each example in input data X using the given transformer_ids.
- Parameters
X : ndarray
The input data matrix.
task_id : obj
The id corresponding to the task being mapped to.
transformer_ids : list, default=None
The list of transformer_ids through which a user would like to send X (which will be pipelined with their corresponding voters) to make an inference prediction.
- Returns
y_hat : ndarray of shape [n_samples]
predicted class label per example
- ClassificationProgressiveLearner.predict_proba(X, task_id, transformer_ids=None)[source]¶
predicts posteriors under task_id for each example in input data X using the given transformer_ids.
- Parameters
X : ndarray
The input data matrix.
task_id : obj
The id corresponding to the task being mapped to.
transformer_ids : list, default=None
The list of transformer_ids through which a user would like to send X (which will be pipelined with their corresponding voters) to estimate posteriors.
- Returns
y_proba_hat : ndarray of shape [n_samples, n_classes]
posteriors per example
- ClassificationProgressiveLearner.set_decider(task_id, transformer_ids, decider_class=None, decider_kwargs=None)¶
- ClassificationProgressiveLearner.set_transformer(transformer_id=None, transformer=None, transformer_data_idx=None, transformer_class=None, transformer_kwargs=None)¶
- ClassificationProgressiveLearner.set_voter(transformer_id, task_id=None, voter_class=None, voter_kwargs=None, bag_id=None)¶