def test_ale(self) -> None: project = Project("test") # we load the dataset dataset = load_dataset(project) # we select an algorithm from the set of algorithms algo = get_algorithm(project, 'linear-regression') # we train the algorithm with the dataset to obtain a model model = algo.fit(dataset) # we initialize a ALE test ale = ALE() columns = ['windspeed', 'hum', 'atemp', 'season'] # we run the ALE test on the model and dataset result = ale.run(dataset, model, columns=columns, max_datapoints=200, n_intervals=10) # we make sure that we obtain a reasonable result assert isinstance(result, DatasetModelResult)
def test_shap(self) -> None: from algoneer.methods.blackbox.shap import SHAP, SHAPDatapointResult, SHAPModelResult project = Project("test") # we load the dataset dataset = load_dataset(project) # we select an algorithm from the set of algorithms algo = get_algorithm(project, 'linear-regression') # we train the algorithm with the dataset to obtain a model model = algo.fit(dataset) # we initialize a SHAP test shap = SHAP() # we run the SHAP test on the model and dataset result = shap.run(dataset, model, max_datapoints=10) # we make sure that we obtain a reasonable result assert isinstance(result, DatasetModelResult) assert 'expected_value' in result.data
def test_objects(self) -> None: project = Project("test") # we load the dataset dataset = load_dataset(project) # we select an algorithm from the set of algorithms algo = get_algorithm(project, 'linear-regression') # we train the algorithm with the dataset to obtain a model model = algo.fit(dataset) assert isinstance(algo, Object) assert isinstance(model, Object) assert isinstance(dataset, Object) client: Union[Client, TestClient] token = os.environ.get("ALGONAUT_TOKEN") if token: client = Client(token) else: client = TestClient() session = Session(client) for Test in dataset_model_tests: # we initialize the test test = Test() # we run the test on the model and dataset result = test.run(dataset, model, max_datapoints=10, max_values=10) session.add(result) api_model = session.add(model) api_dataset = session.add(dataset) api_algo = session.add(algo) assert model in session assert dataset in session assert algo in session session.sync()
def test_predictions(self) -> None: project = Project("test") # we load the dataset dataset = load_dataset(project) # we select an algorithm from the set of algorithms algo = get_algorithm(project, 'random-forest') # we train the algorithm with the dataset to obtain a model model = algo.fit(dataset) # we initialize a predictions test predictions = Predictions() # we run the predictions test on the model and dataset result = predictions.run(dataset, model, max_datapoints=110) # we make sure that we obtain a reasonable result assert isinstance(result, DatasetModelResult)