culebra.solution.feature_selection.Species
class¶
- class Species(num_feats: int, min_feat: int | None = None, min_size: int | None = None, max_feat: int | None = None, max_size: int | None = None)¶
Create a new species.
- Parameters:
num_feats (
int
) – Number of input features considered in the feature selection problemmin_feat (
int
, optional) – Smallest feature index considered in this species. Must be in the interval [0, num_feats). If omitted, the minimum value (0) will be used. Defaults toNone
min_size (
int
, optional) – Minimum size of solutions (minimum number of features selected by solutions in the species). Must be in the interval [0, max_feat - min_feat + 1]. If omitted, the minimum value (0) will be used. Defaults toNone
max_feat (
int
, optional) – Largest feature index considered in this species. Must be in the interval [min_feat, num_feats). If omitted, the maximum possible feature index (num_feats - 1) will be used. Defaults toNone
max_size (
int
, optional) – Maximum size of solutions. Must be in the interval [min_size, max_feat - min_feat + 1]. If omitted, the maximum possible size is used. Defaults toNone
- Raises:
TypeError – If any argument is not of the appropriate type
ValueError – If any argument has an incorrect value
Properties¶
Class methods¶
- classmethod Species.load_pickle(filename: str) Base ¶
Load a pickled object from a file.
- Parameters:
filename (
str
) – The file name.- Raises:
TypeError – If filename is not a valid file name
ValueError – If the filename extension is not
PICKLE_FILE_EXTENSION
- classmethod Species.from_proportion(num_feats: int, prop: float = 0.15) Species ¶
Create a parametrized species for testing purposes.
Fix min_feat, max_feat, min_size and max_size proportionally to the number of features, according to prop, in this way:
min_feat = num_feats * prop
max_feat = num_feats - min_feat - 1
min_size = min_feat
max_size = max_feat - (2 * min_feat) + 1
Here are some examples for num_feats = 1000
prop
min_feat
max_feat
min_size
max_size
0.00
0
999
0
1000
0.05
50
949
50
850
0.10
100
899
100
700
0.15
150
849
150
550
0.20
200
799
200
400
0.25
250
749
250
250
The maximum value for prop is
MAX_PROP
.- Parameters:
num_feats (
int
) – Number of input features considered in the feature selection problemprop (
float
, optional) – Proportion of the number of features used to fix the species parameters. Defaults toDEFAULT_PROP
. The maximum allowed value isMAX_PROP
.
- Raises:
TypeError – If any argument is not of the appropriate type
ValueError – If any argument has an incorrect value
- Returns:
A Species object
- Return type:
Methods¶
- Species.save_pickle(filename: str) None ¶
Pickle this object and save it to a file.
- Parameters:
filename (
str
) – The file name.- Raises:
TypeError – If filename is not a valid file name
ValueError – If the filename extension is not
PICKLE_FILE_EXTENSION