Esempio n. 1
0
    def test_reoccuring(self):
        s1 = MIXEDGenerator(classification_function = 1, random_state= 112, balance_classes = False)
        s2 = MIXEDGenerator(classification_function = 0, random_state= 112, balance_classes = False)
        stream = ReoccuringDriftStream(stream=s1,
                                drift_stream=s2,
                                random_state=None,
                                alpha=90.0, # angle of change grade 0 - 90
                                position=2000,
                                width=500)
        stream.prepare_for_use()
        evaluator = EvaluatePrequential(show_plot=False,batch_size=10,
                                        max_samples=1000,
                                        metrics=['accuracy', 'kappa_t', 'kappa_m', 'kappa'],    
                                        output_file=None)
        eval = evaluator.evaluate(stream=stream, model=OzaBaggingAdwin(base_estimator=KNN()))
        

        measurements = np.asarray(evaluator.get_measurements()[0])[0]
        
        self.assertIsNotNone(eval)
        self.assertTrue(measurements.get_accuracy() >= 0.6,
                        msg='Accuracy was {} but has to be greater than 0.6'.
                        format(measurements.get_accuracy()))
Esempio n. 2
0
 def test_alpha(self):
     with self.assertRaises(ValueError):
         ReoccuringDriftStream(alpha=-1)
     with self.assertRaises(ValueError):
         ReoccuringDriftStream(alpha=91)
     ReoccuringDriftStream(alpha=1)
Esempio n. 3
0
 def test_pause(self):
     with self.assertRaises(ValueError):
         ReoccuringDriftStream(pause=-1)
     ReoccuringDriftStream(pause=1)
Esempio n. 4
0
 def test_width(self):
     with self.assertRaises(ValueError):
         ReoccuringDriftStream(width=-1)
     ReoccuringDriftStream(width=1)
def test_missing_streams():
    grid = {
        "sigma": np.append(1, np.arange(2, 11, 2)),
        "prototypes_per_class": np.append(1, np.arange(2, 11, 2)),
        "gamma": np.array([0.7, 0.9, 0.999]),
        "confidence": np.array([0.01, 0.001]),
        "window_size": np.array([800])
    }
    clf = ARSLVQ()
    led_a = ConceptDriftStream(
        stream=LEDGeneratorDrift(has_noise=False,
                                 noise_percentage=0.0,
                                 n_drift_features=3),
        drift_stream=LEDGeneratorDrift(has_noise=False,
                                       noise_percentage=0.0,
                                       n_drift_features=7),
        random_state=None,
        alpha=90.0,  # angle of change grade 0 - 90
        position=250000,
        width=1)

    led_a.name = "led_a"
    led_g = ConceptDriftStream(stream=LEDGeneratorDrift(has_noise=False,
                                                        noise_percentage=0.0,
                                                        n_drift_features=3),
                               drift_stream=LEDGeneratorDrift(
                                   has_noise=False,
                                   noise_percentage=0.0,
                                   n_drift_features=7),
                               random_state=None,
                               position=250000,
                               width=50000)
    led_g.name = "led_g"
    led_fa = ReoccuringDriftStream(
        stream=LEDGeneratorDrift(has_noise=False,
                                 noise_percentage=0.0,
                                 n_drift_features=3),
        drift_stream=LEDGeneratorDrift(has_noise=False,
                                       noise_percentage=0.0,
                                       n_drift_features=7),
        random_state=None,
        alpha=90.0,  # angle of change grade 0 - 90
        position=2000,
        width=1)

    led_fg = ReoccuringDriftStream(
        stream=LEDGeneratorDrift(has_noise=False,
                                 noise_percentage=0.0,
                                 n_drift_features=3),
        drift_stream=LEDGeneratorDrift(has_noise=False,
                                       noise_percentage=0.0,
                                       n_drift_features=7),
        random_state=None,
        position=2000,
        width=1000)
    covertype = FileStream(os.path.realpath('covtype.csv'))  # Label failure
    covertype.name = "covertype"
    poker = FileStream(os.path.realpath('poker.csv'))  # label failure
    poker.name = "poker"
    airlines = FileStream(os.path.realpath('airlines.csv'))
    airlines.name = "airport"
    gs = GridSearch(clf=clf, grid=grid, max_samples=50000)

    gs.streams = [led_a, led_g, led_fa, led_fg, covertype, poker, airlines]
    gs.search()
    gs.save_summary()
def test_led():
    led_a = ConceptDriftStream(
        stream=LEDGeneratorDrift(has_noise=False,
                                 noise_percentage=0.0,
                                 n_drift_features=3),
        drift_stream=LEDGeneratorDrift(has_noise=False,
                                       noise_percentage=0.0,
                                       n_drift_features=7),
        random_state=None,
        alpha=90.0,  # angle of change grade 0 - 90
        position=250000,
        width=1)

    led_a.name = "led_a"
    led_g = ConceptDriftStream(stream=LEDGeneratorDrift(has_noise=False,
                                                        noise_percentage=0.0,
                                                        n_drift_features=3),
                               drift_stream=LEDGeneratorDrift(
                                   has_noise=False,
                                   noise_percentage=0.0,
                                   n_drift_features=7),
                               random_state=None,
                               position=250000,
                               width=50000)
    led_g.name = "led_g"
    led_fa = ReoccuringDriftStream(
        stream=LEDGeneratorDrift(has_noise=False,
                                 noise_percentage=0.0,
                                 n_drift_features=3),
        drift_stream=LEDGeneratorDrift(has_noise=False,
                                       noise_percentage=0.0,
                                       n_drift_features=7),
        random_state=None,
        alpha=90.0,  # angle of change grade 0 - 90
        position=2000,
        width=1)

    led_fg = ReoccuringDriftStream(
        stream=LEDGeneratorDrift(has_noise=False,
                                 noise_percentage=0.0,
                                 n_drift_features=3),
        drift_stream=LEDGeneratorDrift(has_noise=False,
                                       noise_percentage=0.0,
                                       n_drift_features=7),
        random_state=None,
        position=2000,
        width=1000)

    np = 2
    sigma = 3
    clfs = [
        ARSLVQ(prototypes_per_class=np,
               sigma=sigma,
               confidence=0.0001,
               window_size=1500),
        OzaBaggingAdwin(),
        AdaptiveRandomForest(),
        HAT(),
        RSLVQ(prototypes_per_class=np, sigma=sigma),
        SAMKNN()
    ]

    cv = CrossValidation(clfs=clfs, parallel=1)
    cv.streams = [led_a, led_g, led_fa, led_fg]
    cv.search()
    cv.save_summary()
Esempio n. 7
0
from skmultiflow.data import SEAGenerator
from bix.data.reoccuringdriftstream import ReoccuringDriftStream
import numpy as np
from bix.detectors.kswin import KSWIN
from sklearn.random_projection import SparseRandomProjection
"""Look into if a CD Detector detects the same drifts in high and in low dim space"""

n_samples = 20000

drift_detected_high = []
drift_detected_low = []

stream = ReoccuringDriftStream(SEAGenerator(classification_function=0),
                               SEAGenerator(classification_function=2),
                               position=2000,
                               width=1000,
                               pause=1000)

stream.prepare_for_use()

stream.next_sample()
"""Init KSWIN for every dimension"""
kswin_high = [
    KSWIN(alpha=1e-5, w_size=300, stat_size=30, data=None)
    for i in range(10000)
]
kswin_low = [
    KSWIN(alpha=1e-5, w_size=300, stat_size=30, data=None) for i in range(1000)
]
"""Calc amount of random features we need"""
Esempio n. 8
0
from skmultiflow.drift_detection import ADWIN, EDDM, DDM
from bix.detectors.kswin import KSWIN
from bix.data.reoccuringdriftstream import ReoccuringDriftStream
#from mebwin import MEBWIN
from sw_mebwin import SWMEBWIN
from kernel_swmebwin import Kernel_SWMEBWIN
import time
import numpy as np
import typing
from skmultiflow.bayes import NaiveBayes

streams = []

"""CD at 2000 and then every 1000"""
# MIXED
stream = ReoccuringDriftStream(stream=MIXEDGenerator(classification_function=0), drift_stream=MIXEDGenerator(classification_function=1), width=1, alpha=90, pause=1000, position=2000)

stream.name = 'MIXED Abrupt Reoccuring'
streams.append(stream)

# SEA
stream = ReoccuringDriftStream(stream=SEAGenerator(classification_function=0), drift_stream=SEAGenerator(classification_function=1), width=1, alpha=90, pause=1000, position=2000)

stream.name = 'SEA Abrupt Reoccuring'
streams.append(stream)

# SINE
stream = ReoccuringDriftStream(stream=SineGenerator(classification_function=0), drift_stream=SineGenerator(classification_function=1), width=1, alpha=90, pause=1000, position=2000)

stream.name = 'Sine Abrupt Reoccuring'
streams.append(stream)