コード例 #1
0
    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
コード例 #2
0
ファイル: test_ale.py プロジェクト: prototypefund/algoneer
    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)
コード例 #3
0
    def test_sklean(self):

        project = Project("test")

        # we load the dataset
        dataset = load_dataset(project)

        assert isinstance(dataset, Dataset)

        hash = dataset.hash

        assert hash == b'\x01\x00\x00\x00\xb9\x96\xdb_\xdc\xe6\x98\x05\xe0\xe5\xec`HQ\x82\x14\xde[o5\n\xff\xd2\xb1\xe2K\x06>\xd1:M\xf9'

        datapoint = dataset.datapoint(0)
        dp_hash = datapoint.hash
        assert dp_hash == b'\x01\x00\x00\x00E/\xbdy\xbe#\x19g\xf3\xafV\x1a\xe3\x84\xeel{:\xde)\xa0\x89e\xc1\xbf\xd9\xc6\x94\x8a\x90G\xde'
コード例 #4
0
    def test_sklean(self):

        from algoneer.algorithm.sklearn import SklearnAlgorithm
        from sklearn.ensemble import RandomForestRegressor

        project = Project("test")

        # we load the dataset
        dataset = load_dataset(project)

        algo = SklearnAlgorithm(project, RandomForestRegressor, n_estimators=100)

        assert isinstance(algo, Algorithm)

        assert 'kwargs' in algo.data and algo.data['kwargs'] == {"n_estimators" : 100, "random_state" : 0}

        model = algo.fit(dataset)

        assert isinstance(model, Model)
コード例 #5
0
    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()
コード例 #6
0
    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)