xmoai.problems package
Submodules
xmoai.problems.objectives module
Created on Sat Jul 11 23:58:52 2020
@author: wmonteiro92
- xmoai.problems.objectives.convert_one_hot_to_label_encoded(x, x_original, categorical_columns_one_hot_encoder, cat_features=None)
- xmoai.problems.objectives.convert_single_one_hot_feature_to_label_encoded(x, x_original, col)
- xmoai.problems.objectives.get_difference_attributes(x, x_original, ranges, categorical_columns_label_encoder, categorical_columns_one_hot_encoder)
Calculates the objective 2 (f2), where it attempts to minimize the difference between the modified and original values through the Gower distance.
- Parameters
x (numpy.array) – the individual (or individuals) to be evaluated
x_original (numpy.array) – the original individual
categorical_columns_label_encoder (dict) – dictionary containing the label-encoded categorical columns and their allowed values. The keys are the i-th position of the indexes and the values are the allowed categories. The minimum and maximum categories must respect the values in lower_bounds and upper_bounds since this variable is called after it in code.
categorical_columns_one_hot_encoder (numpy.array) – list of lists containing the one-hot encoded categorical columns. Each list inside this list contains the i-th positions of a given one-hot encoded column. Example: if a column was encoded into three columns, the i-th positions of these columns are encoded into a list.
- Returns
the Gower distance between x and x_original
- Return type
np.array
- xmoai.problems.objectives.get_difference_target_classification_proba(model, x, class_column, method='predict_proba')
Calculates the objective 1 (f1), where it attempts to maximize the probability of the desired class. Valid only for classification problems with methods returning the probability estimates for each class.
- Parameters
model – a machine learning model
x (numpy.array) – the individual (or individuals) to be evaluated
class_column (Integer) – the column index of the prediction class targeted
method (string, defaults to predict_proba) – the method responsible of determining the prediction
- Returns
two objects. The first are the objective 1 (f1) values and the second are the predicted values related to x and found by model using method
- Return type
np.array (first object) and np.array (second object)
- xmoai.problems.objectives.get_difference_target_classification_simple(model, x, y_desired, method='predict')
Calculates the objective 1 (f1), where it assigns 1 if the predicted class differs from the desired class and 0 otherwise. Valid only for classification problems with methods returning the predicted class.
- Parameters
model – a machine learning model
x (numpy.array) – the individual (or individuals) to be evaluated
y_desired (object) – the class targeted
method (string, defaults to predict) – the method responsible of determining the prediction
- Returns
two objects. The first are the objective 1 (f1) values and the second are the predicted values related to x and found by model using method
- Return type
np.array (first object) and np.array (second object)
- xmoai.problems.objectives.get_difference_target_regression(model, x, y_desired, method='predict')
Calculates the objective 1 (f1), where it attempts to minimize the unsigned difference between y_desired and the value found by the prediction found for the proposed x - i.e. between the target and the value found by the subject. Valid only for regression problems.
- Parameters
model (Object) – a machine learning model
x (numpy.array) – the individual (or individuals) to be evaluated
y_desired (numpy.array) – the prediction result targeted
method (string, defaults to predict) – the method responsible of determining the prediction
- Returns
two objects. The first are the objective 1 (f1) values and the second are the predicted values related to x and found by model using method
- Return type
np.array (first object) and np.array (second object)
- xmoai.problems.objectives.get_modified_attributes(x, x_original, categorical_columns_one_hot_encoder)
Calculates the objective 3 (f3), where it attempts to minimize the number of modified attributes (columns).
- Parameters
x (numpy.array) – the individual (or individuals) to be evaluated
x_original (numpy.array) – the original individual
categorical_columns_one_hot_encoder (numpy.array) – list of lists containing the one-hot encoded categorical columns. Each list inside this list contains the i-th positions of a given one-hot encoded column. Example: if a column was encoded into three columns, the i-th positions of these columns are encoded into a list.
- Returns
the number of modified attributes for each one of the solutions (rows) provided in x and compared against x_original
- Return type
np.array
xmoai.problems.restrictions module
Created on Sun Jul 12 00:06:08 2020
@author: wmonteiro92
- xmoai.problems.restrictions.get_changed_vars_threshold(current_changed_vars, max_changed_vars)
Calculates the constraint 1 (g1), where the number of variables (columns) changed must be less than or equal to the limit defined by max_changed_vars.
- Parameters
current_changed_vars (numpy.array) – the number of variables changed per individual
max_changed_vars (Integer) – the maximum allowed number of changed variables
- Returns
an array containing the result of the constraint comparison. Each element represents the results for an individual
- Return type
np.array
- xmoai.problems.restrictions.is_prediction_in_threshold_classification_proba(y_acceptable_range, prediction, prob_column)
Calculates the constraints 2 (g2) and 3 (g3). Constraint 2 determines if the predicted value is greater than or equal the minimum acceptable value for the output. Constraint 3 determines if the predicted value is lesser than or equal the maximum acceptable value for the output. Valid only for classification problems with methods returning the probability estimates for each class.
- Parameters
y_acceptable_range (numpy.array) – the lower (first value) and upper (second value) limits allowed for the probability output
prediction (numpy.array) – the predicted probabilities
prob_column (Integer) – the i-th column to be observed in the prediction parameter
- Returns
two objects. The first are the constraint 2 (g2) values and the second are the constraint 3 (g3) values. Each element of both objects represents the results for an individual.
- Return type
np.array (first object) and np.array (second object)
- xmoai.problems.restrictions.is_prediction_in_threshold_classification_simple(prediction, y_desired)
Calculates the constraint 2 (g2). Constraint 2 determines if the predicted value is different from the expected output. Valid only for classification problems with methods returning the predicted class.
- Parameters
y_desired (object) – the targeted value
prediction (numpy.array) – the predicted values
- Returns
an array containing the result of the constraint comparison. Each element represents the results for an individual
- Return type
np.array
- xmoai.problems.restrictions.is_prediction_in_threshold_regression(y_acceptable_range, prediction)
Calculates the constraints 2 (g2) and 3 (g3). Constraint 2 determines if the predicted value is greater than or equal the minimum acceptable value for the output. Constraint 3 determines if the predicted value is lesser than or equal the maximum acceptable value for the output. Valid only for regression problems.
- Parameters
y_acceptable_range (numpy.array) – the lower (first value) and upper (second value) limits allowed for the prediction
prediction (numpy.array) – the predicted values
- Returns
two objects. The first are the constraint 2 (g2) values and the second are the constraint 3 (g3) values. Each element of both objects represents the results for an individual.
- Return type
np.array (first object) and np.array (second object)
xmoai.problems.xMOAIProblem module
xmoai.problems.xMOAIRepair module
Created on Thu Jul 2 21:36:28 2020
@author: wmonteiro92
- class xmoai.problems.xMOAIRepair.xMOAIRepair(X_current, max_changed_vars, categorical_columns_label_encoder, categorical_columns_one_hot_encoder, integer_columns, immutable_column_indexes)
Bases:
Repair
Module contents
Created on Thu Jul 2 21:44:12 2020
@author: wmont