Documentation for RFSC
Bases: RFSC_base
Implements RFSC algorithm based on parameters inherited from RFSC_base.
__init__(*args)
Inherits parameters from RFSC_base. See help(RFSC_base.init) for more information.
set_attr(params)
Setter for RFSC attributes. Used to update RFSC parameters for DRFSC model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params |
dict
|
Dictionary of parameters to update. |
required |
load_data_rfsc(X_train, X_val, Y_train, Y_val, feature_partition=None, sample_partition=None, drfsc_index=None, mu_init=None, M=None)
Loads the data passed from DRFSC into the RFSC object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X_train |
np.ndarray
|
Training set data |
required |
X_val |
np.ndarray
|
Validation set data |
required |
Y_train |
np.ndarray
|
Training set labels |
required |
Y_val |
np.ndarray
|
Validation set labels |
required |
feature_partition |
list
|
list of features indices for corresponding drfsc index |
None
|
sample_partition |
list
|
list of sample indices for corresponding drfsc index |
None
|
drfsc_index |
tuple
|
index of DRFSC bin of the form (r,i,j), where r is the drfsc iteration number, i is the vertical partition index, and j is the horizontal partition index |
None
|
mu_init |
dict
|
dictionary containing user-assigned RIPs. If None, RIPs are initialised to 1/n_features. |
None
|
M |
dict
|
dictionary containing relevant previous information for feature sharing |
None
|
rfsc_main(X_train, X_val, Y_train, Y_val, drfsc_index=None)
This is the main section of the RFSC algorithm called by DRFSC. It extracts the model populations and evaluates them on the validation set, and updates the feature inclusion probabilities accordingly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X_train |
np.ndarray
|
Training set data |
required |
X_val |
np.ndarray
|
Validation set data |
required |
Y_train |
np.ndarray
|
Training set labels |
required |
Y_val |
np.ndarray
|
Validation set labels |
required |
drfsc_index |
tuple, optional
|
index of DRFSC bin of the form (r,i,j), where r is the drfsc iteration number, i is the vertical partition index, and j is the horizontal partition index |
None
|
generate_models(X_train, Y_train, X_val, Y_val, mu)
Generates random models and for each model evaluates the significance of each feature. Statistically significant features are retained and resultant model is regressed again and its performance on validation partition is evaluated and stored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X_train |
np.ndarray
|
Training data. |
required |
Y_train |
np.ndarray
|
Training labels |
required |
X_val |
np.ndarray
|
Validation data |
required |
Y_val |
np.ndarray
|
Validation labels |
required |
mu |
np.ndarray
|
Array of regressor inclusion probabilities of each feature. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
mask_mtx |
np.ndarray
|
Matrix containing 1 in row i at column j if feature j was included in model i, else 0. |
performance_vector |
np.ndarray
|
Array containing performance of each model. |
size_vector |
np.ndarray
|
Array containing number of features in each model. |
update_feature_probability(mask, performance, mu)
Updates the feature probability vector mu based on the performance of the models generated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask |
np.ndarray
|
Matrix of shape (n_models, n_features) containing the mask of the models generated. |
required |
performance |
np.ndarray
|
Performance evaluation for each model. |
required |
mu |
np.ndarray
|
Current feature probability vector. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
mu_update |
np.ndarray
|
Updated feature probability vector. |
tol_check
Checks if maximum difference between mu vectors is below tolerance threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu_update |
np.ndarray
|
mu at iteration t+1 |
required |
mu |
np.ndarray
|
mu at iteration t |
required |
tol |
float
|
tolerance condition |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True max difference below tolerance, else False. |
select_model
Selects final model based on features that are above the regressor inclusion probability (rip) threshold
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu |
np.ndarray
|
current feature probability vector |
required |
rip_cutoff |
float
|
regressor inclusion probability threshold |
required |
Returns:
| Name | Type | Description |
|---|---|---|
model_feats |
list
|
list of features that are above the rip threshold |
gamma_update
Scale the update of the feature probability vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
performance |
np.ndarray
|
performance evaluation for each model. |
required |
tuning |
float, optional
|
tuning parameter to adjust convergence rate, default=10 |
10
|
Returns:
| Name | Type | Description |
|---|---|---|
gamma |
float
|
Scaling factor for the update of the feature probability vector |
generate_model
Takes a vector of probabilities and returns a random model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu |
np.ndarray
|
array of probabilities for each feature |
required |
Returns:
| Name | Type | Description |
|---|---|---|
index |
np.ndarray
|
randomly generated numbers corresponding to features ids based on probabilities. |
prune_model
Tests whether features are signifincant at selected signifincance level. Returns index of significant features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model |
object
|
logistic regression model object. See statsmodels.api.Logit |
required |
feature_ids |
list
|
feature ids included in the model. |
required |
alpha |
float
|
(0,1) significance level. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
sig_feature_ids |
list
|
list of features above the significance level. |