def test_load_iris(): """ Tests :func:`fatf.utils.data.datasets.load_iris`. """ # Check the first, middle and last entry in the dataset. n_samples = 150 n_features = 4 check_ind = np.array([0, 75, 149]) true_data = np.array([[5.1, 3.5, 1.4, 0.2], [6.6, 3.0, 4.4, 1.4], [5.9, 3.0, 5.1, 1.8]]) # yapf: disable true_target = np.array([0, 1, 2]) target_names = np.array(['setosa', 'versicolor', 'virginica']) feature_names = np.array([ 'sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)' ]) iris_data = fudd.load_iris() assert not fuav.is_structured_array(iris_data['data']) assert iris_data['data'].shape == (n_samples, n_features) assert iris_data['target'].shape == (n_samples, ) assert np.array_equal(iris_data['target_names'], target_names) assert np.array_equal(iris_data['feature_names'], feature_names) assert np.isclose(iris_data['data'][check_ind, :], true_data).all() assert np.isclose(iris_data['target'][check_ind], true_target).all()
""" # Author: Kacper Sokol <*****@*****.**> # License: new BSD from pprint import pprint import numpy as np import fatf.utils.data.datasets as fatf_datasets import fatf.utils.models as fatf_models import fatf.transparency.predictions.counterfactuals as fatf_cf print(__doc__) # Load data iris_data_dict = fatf_datasets.load_iris() iris_X = iris_data_dict['data'] iris_y = iris_data_dict['target'].astype(int) iris_feature_names = iris_data_dict['feature_names'] iris_class_names = iris_data_dict['target_names'] # Train a model clf = fatf_models.KNN() clf.fit(iris_X, iris_y) # Create a Counterfactual Explainer cf_explainer = fatf_cf.CounterfactualExplainer( model=clf, dataset=iris_X, categorical_indices=[], default_numerical_step_size=0.1)