Skip to content

Documentation for DRFSC

Distributed Randomised Feature Selection for Classification (DRFSC)

__init__(n_vbins=1, n_hbins=1, n_runs=1, redistribute_features=False, feature_sharing='all', k=0, output='single', metric='roc_auc', verbose=False, polynomial=1, preprocess=True, max_processes=None)

Constructor for DRFSC class. Initialises the DRFSC class with the given parameters.

Parameters:

Name Type Description Default
n_vbins int, optional

Number of vertical partitions to create for the data. Defaults to 1.

1
n_hbins int, optional

Number of horizontal partitions to create for the data. If output = 'ensemble', each hbin will converge to its own best model. Defaults to 1.

1
n_runs int, optional

Number of feature-sharing iterations to perform. Larger numbers may yield better results, but also take longer. Defaults to 1.

1
redistribute_features bool, optional

If True, the base features included in each bin will be shuffled at each feature-sharing iteration. Does not affect feature sharing. Defaults to False.

False
feature_sharing str, optional

The method used to share features. Defaults to 'all'. Options (str): 'all', 'latest', 'top_k'. If feature_sharing = 'all', the entire history of best features from all sub-processes will be shared. If feature)sharing = 'latest', features from all sub-processes at the current iteration will be shared. If feature_sharing = 'top_k', the best k features will be shared.

'all'
k int, optional

Number of best features to share. Only used if feature_sharing = 'top_k'. Defaults to 0.

0
output str, optional

Output type desired. Options (str): 'single', 'ensemble'. If output = 'single', the best model from all sub-processes will be returned. If output = 'ensemble', the best model from each horizontal partition will be returned. If output = 'ensemb;e'. no features between different horizontal partitions will be created. Defaults to 'single'.

'single'
metric str, optional

Evaluation metric used in the optimisation process. Options (str) : ['acc', 'roc_auc', 'weighted', 'avg_prec', 'f1', 'auprc']. Defaults to 'roc_auc'. For more information on the metrics, see the documentation for the sklearn.metrics module.

'roc_auc'
verbose bool, optional

if True, prints extra information. Defaults to False.

False
polynomial int, optional

degree of polynomial features to use. Defaults to 1.

1
preprocess bool, optional

If True, will scale-data, create dummies for categorical variables, and create polynomial features based on passed polynomial parameter. If False, will only convert data to numpy arrays. Defaults to True.

True
max_processes int, optional

Enforces maximum number of processes that can be generated. If None, will use all available cores. Defaults to None.

None

set_initial_mu(mu_init, _type='name')

Setter for initial mu values for RFSC.

If type(mu_init) == float, will set all mu values to that float.

If type(mu_init) == dict, will set the mu values for the given features to the given values.

If dict is passed, _type must be set to 'name' or 'index'. If 'name', the keys of the dictionary must be the names of the features. If 'index', the keys of the dictionary must be the indices of the features.

Parameters:

Name Type Description Default
mu_init Union[dict, float]

Initial mu values for RFSC. Can be a dictionary or float.

required
_type str, optional

Only required if type(mu_init) == dict. Type of keys in mu_init.

'name'

get_rfsc_params()

Getter for RFSC parameters. Returns a dictionary of the current RFSC parameters

set_rfsc_params(params)

Setter for RFSC parameters. Updates the RFSC parameters with the given dictionary. Dictionary must be in the form of {parameter_name: parameter_value}.

To view available parameters, see help(RFSC_base.init)

load_data(X_train, X_val, Y_train, Y_val, X_test=None, Y_test=None, polynomial=1, preprocess=True)

Preprocesses the data in the required way for the DRFSC model. Can be used to load data into the model if it has not been loaded yet. Scales the data to [0,1] and creates polynomial expansion based on the passed 'polynomial' parameter.

Parameters:

Name Type Description Default
X_train np.ndarray or pd.DataFrame

Train set data

required
X_val np.ndarray or pd.DataFrame

Validation set data

required
Y_train np.ndarray or pd.DataFrame

Train set labels

required
Y_val np.ndarray or pd.DataFrame

Validation set labels

required
X_test np.ndarray or pd.DataFrame, optional

Test set data. Only required if postprocessing is required. Defaults to None.

None
Y_test np.ndarray or pd.DataFrame optional

Test set labels. Only required if postprocessing is required. Defaults to None.

None
polynomial int, optional

degree of polynomial features to use. Defaults to 1.

1
preprocess bool, optional

If True, will scale-data, create dummies for categorical variables, and create polynomial features based on passed polynomial parameter. If False, will only convert data to numpy arrays. Defaults to True.

True

Returns

X_train, X_val, Y_train, Y_val, X_test, Y_test : np.ndarray Preprocessed data and labels

fit(X_train, X_val, Y_train, Y_val)

The main function for fitting the model. Returns the a single final model if output == 'single', else returns a model ensemble based on the number of horizontal partitions (n_hbins).

Parameters:

Name Type Description Default
X_train np.ndarray or pd.DataFrame

Train set data

required
X_val np.ndarray or pd.DataFrame

Validation set data

required
Y_train np.ndarray or pd.DataFrame

Train set labels

required
Y_val np.ndarray or pd.DataFrame

Validation set labels

required

score(X_test, Y_test, metric=None)

Used to evaluate the final model on the test set.

Parameters:

Name Type Description Default
X_test np.ndarray or pd.DataFrame

Test set data

required
Y_test np.ndarray or pd.DataFrame or pd.Series

Test set labels

required
metric str, optional

Metric to use for evaluation. By default uses the metric specified in the constructor. Other options: ('acc', 'roc_auc', 'weighted', 'avg_prec', 'f1', 'auprc').

None

Returns:

Name Type Description
evaluation dict

returns the score of the model based on the metric specified.

feature_importance()

Creates a bar plot of the features of the model and their contribution to the final prediction.

Returns

Returns:

Name Type Description
figure matplotlib figure

hisogram of feature coefficients for features of the final model.

pos_neg_prediction(data_index=0, X_test=None)

Creates a plot of the positive and negative parts of the prediction. Returned figure shows, for a given sample (indexed by data_index), the value of the coefficients and multiplies them by the feature values. These components of the prediction are then plotted.

Parameters:

Name Type Description Default
data_index int

Index of the data observation to be plotted. If X_test is not provided, then the index is relative to the provided training/validation data. If X_test is provided, then the index is relative to the provided test data. Default is 0.

0
X_test np.array or pd.DataFrame

Test data to be used for prediction. If provided, then the index is relative to the provided test data. Default is None.

None

Returns:

Name Type Description
figure matplotlib.pyplot.figure

output figure

single_prediction(data_index=0, X_test=None)

Creates a plot of the single prediction of the final model. Figure shows for a given sample (indexed by data_index) the coefficients of the final model, weighted by the feature values for the indexed observation.

Parameters:

Name Type Description Default
data_index int

Index of the data observation to be plotted. If X_test is not provided, then the index is relative to the provided training/validation data. If X_test is provided, then the index is relative to the provided test data. Default is 0.

0
X_test np.array or pd.DataFrame

Test data to be used for prediction. If provided, then the index is relative to the provided test data. Default is None.

None

Returns:

Name Type Description
figure matplotlib.pyplot.figure

output figure