aboutsummaryrefslogtreecommitdiff
path: root/feast.py
diff options
context:
space:
mode:
Diffstat (limited to 'feast.py')
-rw-r--r--feast.py219
1 files changed, 218 insertions, 1 deletions
diff --git a/feast.py b/feast.py
index 0d2fee6..9cf5725 100644
--- a/feast.py
+++ b/feast.py
@@ -43,6 +43,11 @@ def BetaGamma(data, labels, n_select, beta=1.0, gamma=1.0):
weight attached to the redundant mutual and conditional
mutual information, respectively.
+ The return type is none if there is an error with the
+ dimensions of the data and/or labels. All data are
+ automatically cast as doubles before calling the feature
+ selection tool.
+
Input
:data - data in a Numpy array such that len(data) =
n_observations, and len(data.transpose()) = n_features
@@ -59,6 +64,11 @@ def BetaGamma(data, labels, n_select, beta=1.0, gamma=1.0):
:selected_features - returns a list containing the features
in the order they were selected.
'''
+ data, labels = check_data(data, labels)
+ if data == None or labels == None:
+ return None
+
+
# python values
n_observations, n_features = data.shape
output = np.zeros(n_select)
@@ -93,6 +103,39 @@ def BetaGamma(data, labels, n_select, beta=1.0, gamma=1.0):
+def CIFE(data, labels, n_select):
+ '''
+ CIFE(data, labels, n_select)
+
+ This function implements the Condred feature selection algorithm.
+ beta = 1; gamma = 1;
+
+ The return type is none if there is an error with the
+ dimensions of the data and/or labels. All data are
+ automatically cast as doubles before calling the feature
+ selection tool.
+
+ Input
+ :data - data in a Numpy array such that len(data) =
+ n_observations, and len(data.transpose()) = n_features
+ (REQUIRED)
+ :labels - labels represented in a numpy list with
+ n_observations as the number of elements. That is
+ len(labels) = len(data) = n_observations.
+ (REQUIRED)
+ :n_select - number of features to select. (REQUIRED)
+ Output
+ :selected_features - returns a list containing the features
+ in the order they were selected.
+ '''
+ data, labels = check_data(data, labels)
+ if data == None or labels == None:
+ return None
+ return BetaGamma(data, labels, n_select, beta=1.0, gamma=1.0)
+
+
+
+
def CMIM(data, labels, n_select):
'''
CMIM(data, labels, n_select)
@@ -100,7 +143,12 @@ def CMIM(data, labels, n_select):
This function implements the conditional mutual information
maximization feature selection algorithm. Note that this
implementation does not allow for the weighting of the
- redundancy terms that BetaGamma will allow you to do.
+ redundancy terms that BetaGamma will allow you to do.
+
+ The return type is none if there is an error with the
+ dimensions of the data and/or labels. All data are
+ automatically cast as doubles before calling the feature
+ selection tool.
Input
:data - data in a Numpy array such that len(data) =
@@ -115,6 +163,9 @@ def CMIM(data, labels, n_select):
:selected_features - returns a list containing the features
in the order they were selected.
'''
+ data, labels = check_data(data, labels)
+ if data == None or labels == None:
+ return None
# python values
n_observations, n_features = data.shape
@@ -154,6 +205,11 @@ def CondMI(data, labels, n_select):
This function implements the conditional mutual information
maximization feature selection algorithm.
+ The return type is none if there is an error with the
+ dimensions of the data and/or labels. All data are
+ automatically cast as doubles before calling the feature
+ selection tool.
+
Input
:data - data in a Numpy array such that len(data) =
n_observations, and len(data.transpose()) = n_features
@@ -167,6 +223,10 @@ def CondMI(data, labels, n_select):
:selected_features - returns a list containing the features
in the order they were selected.
'''
+ data, labels = check_data(data, labels)
+ if data == None or labels == None:
+ return None
+
# python values
n_observations, n_features = data.shape
output = np.zeros(n_select)
@@ -197,7 +257,36 @@ def CondMI(data, labels, n_select):
return selected_features
+def Condred(data, labels, n_select):
+ '''
+ Condred(data, labels, n_select)
+
+ This function implements the Condred feature selection algorithm.
+ beta = 0; gamma = 1;
+
+ The return type is none if there is an error with the
+ dimensions of the data and/or labels. All data are
+ automatically cast as doubles before calling the feature
+ selection tool.
+
+ Input
+ :data - data in a Numpy array such that len(data) =
+ n_observations, and len(data.transpose()) = n_features
+ (REQUIRED)
+ :labels - labels represented in a numpy list with
+ n_observations as the number of elements. That is
+ len(labels) = len(data) = n_observations.
+ (REQUIRED)
+ :n_select - number of features to select. (REQUIRED)
+ Output
+ :selected_features - returns a list containing the features
+ in the order they were selected.
+ '''
+ data, labels = check_data(data, labels)
+ if data == None or labels == None:
+ return None
+ return BetaGamma(data, labels, n_select, beta=0.0, gamma=1.0)
@@ -208,6 +297,11 @@ def DISR(data, labels, n_select):
This function implements the double input symmetrical relevance
feature selection algorithm.
+ The return type is none if there is an error with the
+ dimensions of the data and/or labels. All data are
+ automatically cast as doubles before calling the feature
+ selection tool.
+
Input
:data - data in a Numpy array such that len(data) =
n_observations, and len(data.transpose()) = n_features
@@ -221,6 +315,10 @@ def DISR(data, labels, n_select):
:selected_features - returns a list containing the features
in the order they were selected.
'''
+ data, labels = check_data(data, labels)
+ if data == None or labels == None:
+ return None
+
# python values
n_observations, n_features = data.shape
output = np.zeros(n_select)
@@ -260,6 +358,11 @@ def ICAP(data, labels, n_select):
This function implements the interaction capping feature
selection algorithm.
+ The return type is none if there is an error with the
+ dimensions of the data and/or labels. All data are
+ automatically cast as doubles before calling the feature
+ selection tool.
+
Input
:data - data in a Numpy array such that len(data) =
n_observations, and len(data.transpose()) = n_features
@@ -273,6 +376,10 @@ def ICAP(data, labels, n_select):
:selected_features - returns a list containing the features
in the order they were selected.
'''
+ data, labels = check_data(data, labels)
+ if data == None or labels == None:
+ return None
+
# python values
n_observations, n_features = data.shape
output = np.zeros(n_select)
@@ -313,6 +420,11 @@ def JMI(data, labels, n_select):
This function implements the joint mutual information feature
selection algorithm.
+ The return type is none if there is an error with the
+ dimensions of the data and/or labels. All data are
+ automatically cast as doubles before calling the feature
+ selection tool.
+
Input
:data - data in a Numpy array such that len(data) =
n_observations, and len(data.transpose()) = n_features
@@ -326,6 +438,9 @@ def JMI(data, labels, n_select):
:selected_features - returns a list containing the features
in the order they were selected.
'''
+ data, labels = check_data(data, labels)
+ if data == None or labels == None:
+ return None
# python values
n_observations, n_features = data.shape
@@ -356,6 +471,73 @@ def JMI(data, labels, n_select):
return selected_features
+
+
+def MIFS(data, labels, n_select):
+ '''
+ MIFS(data, labels, n_select)
+
+ This function implements the MIFS algorithm.
+ beta = 1; gamma = 0;
+
+ The return type is none if there is an error with the
+ dimensions of the data and/or labels. All data are
+ automatically cast as doubles before calling the feature
+ selection tool.
+
+ Input
+ :data - data in a Numpy array such that len(data) =
+ n_observations, and len(data.transpose()) = n_features
+ (REQUIRED)
+ :labels - labels represented in a numpy list with
+ n_observations as the number of elements. That is
+ len(labels) = len(data) = n_observations.
+ (REQUIRED)
+ :n_select - number of features to select. (REQUIRED)
+ Output
+ :selected_features - returns a list containing the features
+ in the order they were selected.
+ '''
+ data, labels = check_data(data, labels)
+ if data == None or labels == None:
+ return None
+
+ return BetaGamma(data, labels, n_select, beta=0.0, gamma=0.0)
+
+
+def MIM(data, labels, n_select):
+ '''
+ MIM(data, labels, n_select)
+
+ This function implements the MIM algorithm.
+ beta = 0; gamma = 0;
+
+ The return type is none if there is an error with the
+ dimensions of the data and/or labels. All data are
+ automatically cast as doubles before calling the feature
+ selection tool.
+
+ Input
+ :data - data in a Numpy array such that len(data) =
+ n_observations, and len(data.transpose()) = n_features
+ (REQUIRED)
+ :labels - labels represented in a numpy list with
+ n_observations as the number of elements. That is
+ len(labels) = len(data) = n_observations.
+ (REQUIRED)
+ :n_select - number of features to select. (REQUIRED)
+ Output
+ :selected_features - returns a list containing the features
+ in the order they were selected.
+ '''
+ data, labels = check_data(data, labels)
+ if data == None or labels == None:
+ return None
+
+ return BetaGamma(data, labels, n_select, beta=0.0, gamma=0.0)
+
+
+
def mRMR(data, labels, n_select):
'''
mRMR(data, labels, n_select)
@@ -363,6 +545,11 @@ def mRMR(data, labels, n_select):
This funciton implements the max-relevance min-redundancy feature
selection algorithm.
+ The return type is none if there is an error with the
+ dimensions of the data and/or labels. All data are
+ automatically cast as doubles before calling the feature
+ selection tool.
+
Input
:data - data in a Numpy array such that len(data) =
n_observations, and len(data.transpose()) = n_features
@@ -376,6 +563,10 @@ def mRMR(data, labels, n_select):
:selected_features - returns a list containing the features
in the order they were selected.
'''
+ data, labels = check_data(data, labels)
+ if data == None or labels == None:
+ return None
+
# python values
n_observations, n_features = data.shape
@@ -410,3 +601,29 @@ def mRMR(data, labels, n_select):
+
+
+
+def check_data(data, labels):
+ '''
+ check_data(data, labels)
+
+ The return type is none if there is an error with the
+ dimensions of the data and/or labels. All data are
+ automatically cast as doubles before calling the feature
+ selection tool.
+
+ Input
+ :data
+ :labels
+ Output
+ :data
+ :labels
+ '''
+ if len(data) != len(labels):
+ return None, None
+
+ return 1.0*data, 1.0*labels
+
+
+