示例#1
0
    def setUpClass(cls):
        """Set up model to test."""
        cls = cls._prep_data(cls, reg=True)
        cls.mod = Incremental(
            StreamingEXTR(n_estimators_per_chunk=1,
                          max_n_estimators=39,
                          verbose=1))

        # Set expected number of estimators
        # This should be set manually depending on data.
        cls.expected_n_estimators = 10

        # Set helper values
        super().setUpClass()
示例#2
0
    def setUpClass(cls):
        """Set up model to test."""
        cls.n_samples = 1000
        cls.x, cls.y = sklearn.datasets.make_regression(n_samples=int(2e4),
                                                        random_state=0,
                                                        n_features=400)

        cls.mod = StreamingEXTR(n_estimators_per_chunk=1, max_n_estimators=39)

        # Set expected number of estimators
        cls.expected_n_estimators = 39

        # Set helper values
        super().setUpClass()
示例#3
0
    def setUpClass(cls):
        """Set up model to test."""
        cls = cls._prep_data(cls, reg=True)
        cls.mod = Incremental(
            StreamingEXTR(n_estimators_per_chunk=4,
                          n_jobs=-1,
                          max_n_estimators=np.inf,
                          verbose=1))

        # Set expected number of estimators
        cls.expected_n_estimators = 40

        # Set helper values
        super().setUpClass()
示例#4
0
    def setUpClass(cls):
        """Set up model to test."""
        cls.spf_n_fits = 10
        cls.spf_sample_prop = 0.1
        cls.dask_feeding = False
        cls.n_estimators_per_sample = 10

        cls.mod = StreamingEXTR(
            verbose=1,
            n_estimators_per_chunk=cls.n_estimators_per_sample,
            max_n_estimators=np.inf,
            dask_feeding=cls.dask_feeding,
            spf_sample_prop=cls.spf_sample_prop,
            spf_n_fits=cls.spf_n_fits)

        super().setUpClass()
示例#5
0
def bunch_of_examples():
    from sklearn.datasets import make_blobs, make_regression

    x, y = make_regression(n_samples=int(2e5),
                           random_state=0,
                           n_features=40)

    srfr = StreamingRFR(n_estimators_per_chunk=5,
                        spf_n_fits=10,
                        dask_feeding=False,
                        verbose=0,
                        n_jobs=2)

    srfr.fit(x, y)

    # Fit 10 regressors
    for _ in range(10):
        x, y = make_regression(n_samples=int(2e5),
                               random_state=0,
                               n_features=40)

        srfr = StreamingRFR(n_estimators_per_chunk=5,
                            max_n_estimators=100,
                            verbose=0,
                            n_jobs=5)

        chunk_size = int(2e3)
        for _ in range(20):
            sample_idx = np.random.randint(0, x.shape[0], chunk_size)
            srfr.partial_fit(x[sample_idx], y[sample_idx],
                             classes=np.unique(y))

        print(f"SRFR: {srfr.score(x, y)}")

        sext = StreamingEXTR(n_estimators_per_chunk=5,
                             max_n_estimators=100,
                             verbose=0,
                             n_jobs=5)

        for _ in range(20):
            sample_idx = np.random.randint(0, x.shape[0], chunk_size)
            sext.partial_fit(x[sample_idx], y[sample_idx],
                             classes=np.unique(y))

        print(f"SEXTR: {sext.score(x, y)}")

    # Fit 10 classifiers
    for _ in range(10):
        x, y = make_blobs(n_samples=int(2e5),
                          random_state=0,
                          n_features=40,
                          centers=2,
                          cluster_std=100)

        srfc = StreamingRFC(n_estimators_per_chunk=5,
                            max_n_estimators=100,
                            verbose=0,
                            n_jobs=5)

        chunk_size = int(2e3)
        for _ in range(20):
            sample_idx = np.random.randint(0, x.shape[0], chunk_size)
            srfc.partial_fit(x[sample_idx], y[sample_idx],
                             classes=np.unique(y))

        print(f"SRFC: {srfc.score(x, y)}")

        sext = StreamingEXTC(n_estimators_per_chunk=5,
                             max_n_estimators=100,
                             verbose=0,
                             n_jobs=5)

        for _ in range(20):
            sample_idx = np.random.randint(0, x.shape[0], chunk_size)
            sext.partial_fit(x[sample_idx], y[sample_idx],
                             classes=np.unique(y))

        print(f"SEXTC: {sext.score(x, y)}")