Ejemplo n.º 1
0
                load_sample_from_dataset(y_desired_index, dataset)

        # Training a ML model
        for algorithm in algorithms:
            if verbose:
                print(f'Training using {algorithm}.')

            model = train_ml_model(X, y, algorithm)

            if verbose:
                print(f'Starting counterfactual generation.')

            pareto_front, pareto_set, pareto_algorithms = \
                generate_counterfactuals_classification_simple(model, X_current, \
                    y_desired, immutable_column_indexes, upper_bounds, \
                    lower_bounds, categorical_columns, integer_columns, \
                    n_gen=100, pop_size=100, max_changed_vars=10, \
                    verbose=verbose, seed=0)

            trained_models.append([
                dataset, algorithm, pareto_front, pareto_set, pareto_algorithms
            ])

    return trained_models


results_proba = train_classification_proba(verbose=True)
results_simple = train_classification_simple(verbose=True)

view_results(results_proba)
view_results(results_simple)
        upper_bounds = np.max(X, axis=0)
        lower_bounds = np.min(X, axis=0)

        # Training a ML model
        for algorithm in algorithms:
            if verbose:
                print(f'Training using {algorithm}')

            model = train_ml_model(X, y, algorithm)

            if verbose:
                print(f'Starting counterfactual generation.')

            pareto_front, pareto_set, pareto_algorithms = \
                generate_counterfactuals_regression(model, \
                    scaler.transform(X_current.reshape(1, -1)), \
                    y_desired, immutable_column_indexes, \
                    y_acceptable_range, upper_bounds, lower_bounds, \
                    categorical_columns, integer_columns, n_gen=50, \
                    pop_size=300, max_changed_vars=10, verbose=verbose, seed=0)

            trained_models.append([
                dataset, algorithm, pareto_front, pareto_set, pareto_algorithms
            ])

    return np.array(trained_models)


results = train_regression(verbose=True)
view_results(results)
            upper_bounds, lower_bounds, y_acceptable_range, \
            categorical_columns, integer_columns = \
                load_sample_from_dataset(y_desired_index, dataset)

        # Training a ML model
        for algorithm in algorithms:
            if verbose:
                print(f'Training using {algorithm}.')

            model = train_ml_model(X, y, algorithm)

            if verbose:
                print(f'Starting counterfactual generation.')

            pareto_front, pareto_set, pareto_algorithms = \
                generate_counterfactuals_classification_proba(model, \
                    X_current, y_desired, immutable_column_indexes, \
                    y_acceptable_range, upper_bounds, lower_bounds, \
                    categorical_columns, integer_columns, n_gen=50, \
                    pop_size=100, max_changed_vars=5, verbose=verbose, seed=0)

            trained_models.append([
                dataset, algorithm, pareto_front, pareto_set, pareto_algorithms
            ])

    return np.array(trained_models)


results_proba = train_classification_proba(verbose=True)
view_results(results_proba)