Example #1
0
 def test_cohort_filter_greater(self):
     X_train, X_test, y_train, y_test, feature_names = create_iris_pandas()
     filters = [{'arg': [2.8], 'column': SEPAL_WIDTH, 'method': 'greater'}]
     validation_data = create_validation_data(X_test, y_test)
     validation_data = validation_data.loc[X_test[SEPAL_WIDTH] > 2.8]
     model_task = ModelTask.CLASSIFICATION
     model = create_sklearn_svm_classifier(X_train, y_train)
     categorical_features = []
     run_rai_insights(validation_data,
                      model,
                      X_train,
                      y_train,
                      X_test,
                      y_test,
                      feature_names,
                      categorical_features,
                      model_task,
                      filters=filters)
Example #2
0
 def test_cohort_filter_index(self):
     X_train, X_test, y_train, y_test, feature_names = create_iris_pandas()
     # filter on index, which can be done from the RAI dashboard
     filters = [{
         'arg': [40],
         'column': ROW_INDEX,
         'method': 'less and equal'
     }]
     validation_data = create_validation_data(X_test, y_test)
     validation_data = validation_data.loc[validation_data[ROW_INDEX] <= 40]
     model_task = ModelTask.CLASSIFICATION
     model = create_sklearn_svm_classifier(X_train, y_train)
     categorical_features = []
     model_task = ModelTask.CLASSIFICATION
     run_rai_insights(validation_data,
                      model,
                      X_train,
                      y_train,
                      X_test,
                      y_test,
                      feature_names,
                      categorical_features,
                      model_task,
                      filters=filters)
Example #3
0
    def test_cohort_filter_multiclass_classification_outcome(
            self, arg, correct_prediction):
        X_train, X_test, y_train, y_test, feature_names = create_iris_pandas()
        model = create_sklearn_svm_classifier(X_train, y_train)
        model_task = ModelTask.CLASSIFICATION
        categorical_features = []

        # the index 1, corresponds to incorrect prediction
        # the index 0 correspond to correct prediction
        filters = [{
            'arg': arg,
            'column': CLASSIFICATION_OUTCOME,
            'method': 'includes'
        }]
        pred_y = model.predict(X_test)
        validation_data = create_validation_data(X_test, y_test, pred_y)
        if correct_prediction:
            validation_filter = validation_data[PRED_Y] == validation_data[
                TRUE_Y]
        else:
            validation_filter = validation_data[PRED_Y] != validation_data[
                TRUE_Y]
        validation_data = validation_data.loc[validation_filter]
        validation_data = validation_data.drop(columns=PRED_Y)
        model_task = ModelTask.CLASSIFICATION
        run_rai_insights(validation_data,
                         model,
                         X_train,
                         y_train,
                         X_test,
                         y_test,
                         feature_names,
                         categorical_features,
                         model_task,
                         filters=filters,
                         is_empty_validation_data=(not correct_prediction))