src.FeatureSelectionMethods.TemplateMethod

 1# ************************************************************************************************************************* #
 2#   UTC Header                                                                                                              #
 3#                                                         ::::::::::::::::::::       :::    ::: :::::::::::  ::::::::       #
 4#      TemplateMethod.py                                  ::::::::::::::::::::       :+:    :+:     :+:     :+:    :+:      #
 5#                                                         ::::::::::::::+++#####+++  +:+    +:+     +:+     +:+             #
 6#      By: branlyst and ismailkad < >                     ::+++##############+++     +:+    +:+     +:+     +:+             #
 7#                                                     +++##############+++::::       +#+    +:+     +#+     +#+             #
 8#                                                       +++##+++::::::::::::::       +#+    +:+     +#+     +#+             #
 9#                                                         ::::::::::::::::::::       +#+    +#+     +#+     +#+             #
10#                                                         ::::::::::::::::::::       #+#    #+#     #+#     #+#    #+#      #
11#      Update: 2022/06/16 17:39:34 by branlyst and ismai  ::::::::::::::::::::        ########      ###      ######## .fr   #
12#                                                                                                                           #
13# ************************************************************************************************************************* #
14
15
16class TemplateMethod:
17    """
18    The class TemplateMethod provide a Template which can be implemented or extended to implement methods for Feature Selection.
19
20    Args:
21        method_name (str) : the name of the implemented method, name used to find the right instance
22
23    Attributes:
24        _score (DataFrame) : Dataframe which contains len(target_columns) columns and len(features) lines representing the score result of the feature selection
25        _method_name (str) : variable which stores the method name
26        _selected_features (dict(str[])) : Dictionnary with `target_columns` as keys. Each value corresponds to an Array of the selected features to keep according to the feature selection method for the key target_column.
27    """
28
29    _score = None
30    _method_name = None
31    _selected_features = None
32
33    def __init__(self, method_name):
34        self._method_name = method_name
35
36    def select(self, dataframe, target_columns, number_of_target_to_keep=1):
37        """
38        Select abstract method. Must be implemented.
39
40        Args:
41            dataframe (DataFrame) : dataframe which contains the data used to apply the feature selection. 1 column by feature and 1 line by entry
42            target_columns (str[]) : array of the target column names used to apply the feature selection
43            number_of_target_to_keep (int | None) : number of target to keep to select features. If None, algorithm will try to find the best compromise
44        """
45        raise NotImplementedError
46
47    def get_feature_importances(self):
48        """
49        Accessor to the _score variable
50        """
51        return self._score
52
53    def get_method_name(self):
54        """
55        Accessor to the _method_name variable
56        """
57        return self._method_name
58
59    def get_selected_features(self):
60        """
61        Accessor to the _selected_features variable
62        """
63        return self._selected_features
class TemplateMethod:
17class TemplateMethod:
18    """
19    The class TemplateMethod provide a Template which can be implemented or extended to implement methods for Feature Selection.
20
21    Args:
22        method_name (str) : the name of the implemented method, name used to find the right instance
23
24    Attributes:
25        _score (DataFrame) : Dataframe which contains len(target_columns) columns and len(features) lines representing the score result of the feature selection
26        _method_name (str) : variable which stores the method name
27        _selected_features (dict(str[])) : Dictionnary with `target_columns` as keys. Each value corresponds to an Array of the selected features to keep according to the feature selection method for the key target_column.
28    """
29
30    _score = None
31    _method_name = None
32    _selected_features = None
33
34    def __init__(self, method_name):
35        self._method_name = method_name
36
37    def select(self, dataframe, target_columns, number_of_target_to_keep=1):
38        """
39        Select abstract method. Must be implemented.
40
41        Args:
42            dataframe (DataFrame) : dataframe which contains the data used to apply the feature selection. 1 column by feature and 1 line by entry
43            target_columns (str[]) : array of the target column names used to apply the feature selection
44            number_of_target_to_keep (int | None) : number of target to keep to select features. If None, algorithm will try to find the best compromise
45        """
46        raise NotImplementedError
47
48    def get_feature_importances(self):
49        """
50        Accessor to the _score variable
51        """
52        return self._score
53
54    def get_method_name(self):
55        """
56        Accessor to the _method_name variable
57        """
58        return self._method_name
59
60    def get_selected_features(self):
61        """
62        Accessor to the _selected_features variable
63        """
64        return self._selected_features

The class TemplateMethod provide a Template which can be implemented or extended to implement methods for Feature Selection.

Args
  • method_name (str) : the name of the implemented method, name used to find the right instance
Attributes
  • _score (DataFrame) : Dataframe which contains len(target_columns) columns and len(features) lines representing the score result of the feature selection
  • _method_name (str) : variable which stores the method name
  • _selected_features (dict(str[])) : Dictionnary with target_columns as keys. Each value corresponds to an Array of the selected features to keep according to the feature selection method for the key target_column.
TemplateMethod(method_name)
34    def __init__(self, method_name):
35        self._method_name = method_name
def select(self, dataframe, target_columns, number_of_target_to_keep=1)
37    def select(self, dataframe, target_columns, number_of_target_to_keep=1):
38        """
39        Select abstract method. Must be implemented.
40
41        Args:
42            dataframe (DataFrame) : dataframe which contains the data used to apply the feature selection. 1 column by feature and 1 line by entry
43            target_columns (str[]) : array of the target column names used to apply the feature selection
44            number_of_target_to_keep (int | None) : number of target to keep to select features. If None, algorithm will try to find the best compromise
45        """
46        raise NotImplementedError

Select abstract method. Must be implemented.

Args
  • dataframe (DataFrame) : dataframe which contains the data used to apply the feature selection. 1 column by feature and 1 line by entry
  • target_columns (str[]) : array of the target column names used to apply the feature selection
  • number_of_target_to_keep (int | None) : number of target to keep to select features. If None, algorithm will try to find the best compromise
def get_feature_importances(self)
48    def get_feature_importances(self):
49        """
50        Accessor to the _score variable
51        """
52        return self._score

Accessor to the _score variable

def get_method_name(self)
54    def get_method_name(self):
55        """
56        Accessor to the _method_name variable
57        """
58        return self._method_name

Accessor to the _method_name variable

def get_selected_features(self)
60    def get_selected_features(self):
61        """
62        Accessor to the _selected_features variable
63        """
64        return self._selected_features

Accessor to the _selected_features variable