예제 #1
0
    def test_preproc(self):
        """
        As a domain expert, I have a particular pre-processing that I believe
        reveals important patterns in my data.  I would like to know how good
        a classifier can be built on top of my preprocessing algorithm.
        """

        # -- for testing purpose, suppose that the RBM is our "domain-specific
        #    pre-processing"

        algo = SklearnClassifier(
            partial(
                hyperopt_estimator,
                preprocessing=hp.choice('pp',
                    [
                        # -- VQ (alone)
                        [
                            hpc.colkmeans('vq0',
                                n_init=1),
                        ],
                        # -- VQ -> RBM
                        [
                            hpc.colkmeans('vq1',
                                n_clusters=scope.int(
                                    hp.quniform(
                                        'vq1.n_clusters', 1, 5, q=1)),
                                n_init=1),
                            hpc.rbm(name='rbm:alone',
                                verbose=0)
                        ],
                        # -- VQ -> RBM -> PCA
                        [
                            hpc.colkmeans('vq2',
                                n_clusters=scope.int(
                                    hp.quniform(
                                        'vq2.n_clusters', 1, 5, q=1)),
                                n_init=1),
                            hpc.rbm(name='rbm:pre-pca',
                                verbose=0),
                            hpc.pca('pca')
                        ],
                    ]),
                classifier=hpc.any_classifier('classif'),
                algo=tpe.suggest,
                max_evals=10,
                ))
        mean_test_error = self.view.protocol(algo)
        print('mean test error:', mean_test_error)
예제 #2
0
    def test_preproc(self):
        """
        As a domain expert, I have a particular pre-processing that I believe
        reveals important patterns in my data.  I would like to know how good
        a classifier can be built on top of my preprocessing algorithm.
        """

        # -- for testing purpose, suppose that the RBM is our "domain-specific
        #    pre-processing"

        algo = LearningAlgo(
            partial(
                hyperopt_estimator,
                preprocessing=hp.choice(
                    'pp',
                    [
                        # -- VQ (alone)
                        [
                            hpc.colkmeans(
                                'vq0',
                                n_clusters=scope.int(
                                    hp.quniform(
                                        'vq0.n_clusters', 1.5, 5.5, q=1)),
                                n_init=1,
                                max_iter=100),
                        ],
                        # -- VQ -> RBM
                        [
                            hpc.colkmeans(
                                'vq1',
                                n_clusters=scope.int(
                                    hp.quniform(
                                        'vq1.n_clusters', 1.5, 5.5, q=1)),
                                n_init=1,
                                max_iter=100),
                            hpc.rbm(name='rbm:alone',
                                    n_components=scope.int(
                                        hp.qloguniform('rbm1.n_components',
                                                       np.log(4.5),
                                                       np.log(20.5), 1)),
                                    n_iter=100,
                                    verbose=0)
                        ],
                        # -- VQ -> RBM -> PCA
                        [
                            hpc.colkmeans('vq2',
                                          n_clusters=scope.int(
                                              hp.quniform('vq2.n_clusters',
                                                          1.5,
                                                          5.5,
                                                          q=1)),
                                          n_init=1,
                                          max_iter=100),
                            hpc.rbm(name='rbm:pre-pca',
                                    n_components=scope.int(
                                        hp.qloguniform('rbm2.n_components',
                                                       np.log(4.5),
                                                       np.log(20.5), 1)),
                                    n_iter=100,
                                    verbose=0),
                            hpc.pca('pca')
                        ],
                    ]),
                classifier=hpc.any_classifier('classif'),
                algo=tpe.suggest,
                #trial_timeout=5.0,  # seconds
                verbose=1,
                max_evals=10,
            ))
        mean_test_error = self.view.protocol(algo)
        print('\n====Iris: VQ + RBM + PCA + any classifier====',
              file=sys.stderr)
        print('mean test error:', mean_test_error, file=sys.stderr)
        print('====End optimization====')