Exemplo n.º 1
0
    def test_gpx_regression(self):

        INSTANCE: int = 13
        reg = RandomForestRegressor()
        x, y = load_boston(return_X_y=True)
        x_train, x_test, y_train, y_test = train_test_split(x,
                                                            y,
                                                            train_size=.8,
                                                            test_size=.2,
                                                            random_state=42)
        reg.fit(x_train, y_train)

        gpx = Gpx(predict=reg.predict,
                  x_train=x_train,
                  y_train=y_train,
                  problem='regression',
                  random_state=42)
        gpx.explaining(x_test[INSTANCE, :])
        y_hat = reg.predict(x_test)
        mse = mean_squared_error(y_test, y_hat)

        d = gpx.features_distribution()

        # self.assertEqual(max(list(d.values())), d['x_2'])

        self.assertLess(
            gpx.understand(metric='mse'), mse,
            '{} mse greater than understand (local mse)'.format(
                self.test_gpx_regression.__name__))
Exemplo n.º 2
0
    def test_features_distribution(self):
        x_varied, y_varied = make_moons(n_samples=500, random_state=170)
        model = MLPClassifier()
        model.fit(x_varied, y_varied)
        my_predict = model.predict_proba

        gpx = Gpx(my_predict,
                  x_train=x_varied,
                  y_train=y_varied,
                  random_state=42,
                  num_samples=250)

        gpx.explaining(x_varied[13, :])
        d = gpx.features_distribution()

        gpx.logger.info('distribution-> program:{} / x_0: {} / x_1: {}'.format(
            gpx.gp_model._program, d['x_0'], d['x_1']))
        self.assertLess(
            d['x_0'], d['x_1'],
            'Method features_distributions() output unexpected, x_0 greater than x_1!'
        )