Example #1
0
def demo():
    """ _test_stream_speed
    
    This demo tests the sample generation speed of the file stream.
    
    """
    # Setup the stream
    # stream = FileStream("../datasets/covtype.csv", -1, 1)
    stream = RandomRBFGeneratorDrift()
    stream.prepare_for_use()

    # Test with RandomTreeGenerator
    # opt_list = [['-c', '2'], ['-o', '0'], ['-u', '5'], ['-v', '4']]
    # stream = RandomTreeGenerator(opt_list)
    # stream.prepare_for_use()

    # Setup the evaluator
    evaluator = EvaluateStreamGenerationSpeed(100000, float("inf"), None, 5)

    # Evaluate
    evaluator.eval(stream)
def demo():
    """ _test_streams
    
    This demo tests if the streams are correctly generating samples.
    
    :return: 
    """
    opt = FileOption('FILE', 'OPT_NAME', '../datasets/covtype.csv', 'csv',
                     False)
    stream = FileStream(opt, -1, 1)
    stream.prepare_for_use()
    rbf_drift = RandomRBFGeneratorDrift(change_speed=41.00,
                                        num_centroids=50,
                                        model_seed=32523423,
                                        instance_seed=5435,
                                        num_classes=2,
                                        num_att=10,
                                        num_drift_centroids=50)
    rbf_drift.prepare_for_use()

    sea = SEAGenerator()

    print('1 instance:\n')

    X, y = stream.next_instance()
    print(X)
    print(y)

    X, y = sea.next_instance()
    print(X)
    print(y)

    print('\n\n10 instances:\n')
    X, y = stream.next_instance(10)
    print(X)
    print(y)

    X, y = sea.next_instance(10)
    print(X)
    print(y)
def test_random_rbf_generator_drift(test_path):
    stream = RandomRBFGeneratorDrift(model_seed=99,
                                     instance_seed=50,
                                     num_classes=4,
                                     num_att=10,
                                     num_centroids=50,
                                     change_speed=0.87,
                                     num_drift_centroids=50)
    stream.prepare_for_use()

    assert stream.estimated_remaining_instances() == -1

    expected_header = [
        'att_num_0', 'att_num_1', 'att_num_2', 'att_num_3', 'att_num_4',
        'att_num_5', 'att_num_6', 'att_num_7', 'att_num_8', 'att_num_9'
    ]
    assert stream.get_attributes_header() == expected_header

    expected_classes = [0, 1, 2, 3]
    assert stream.get_classes() == expected_classes

    assert stream.get_classes_header() == ['class']

    assert stream.get_num_attributes() == 10

    assert stream.get_num_nominal_attributes() == 0

    assert stream.get_num_numerical_attributes() == 10

    assert stream.get_num_targets() == 4

    assert stream.get_num_values_per_nominal_attribute() == 0

    assert stream.get_plot_name(
    ) == 'Random RBF Generator with drift - 4 class labels'

    assert stream.has_more_instances() is True

    assert stream.is_restartable() is True

    # Load test data corresponding to first 10 instances
    test_file = os.path.join(test_path, 'random_rbf_drift_stream.npz')
    data = np.load(test_file)
    X_expected = data['X']
    y_expected = data['y']

    X, y = stream.next_instance()
    assert np.alltrue(X[0] == X_expected[0])
    assert np.alltrue(y[0] == y_expected[0])

    X, y = stream.get_last_instance()
    assert np.alltrue(X[0] == X_expected[0])
    assert np.alltrue(y[0] == y_expected[0])

    stream.restart()
    X, y = stream.next_instance(10)
    assert np.alltrue(X == X_expected)
    assert np.alltrue(y == y_expected)
Example #4
0
def test_random_rbf_generator_drift(test_path):
    stream = RandomRBFGeneratorDrift(model_random_state=99,
                                     sample_random_state=50,
                                     n_classes=4,
                                     n_features=10,
                                     n_centroids=50,
                                     change_speed=0.87,
                                     num_drift_centroids=50)
    stream.prepare_for_use()

    assert stream.n_remaining_samples() == -1

    expected_names = [
        'att_num_0', 'att_num_1', 'att_num_2', 'att_num_3', 'att_num_4',
        'att_num_5', 'att_num_6', 'att_num_7', 'att_num_8', 'att_num_9'
    ]
    assert stream.feature_names == expected_names

    expected_targets = [0, 1, 2, 3]
    assert stream.target_values == expected_targets

    assert stream.target_names == ['target_0']

    assert stream.n_features == 10

    assert stream.n_cat_features == 0

    assert stream.n_num_features == 10

    assert stream.n_targets == 1

    assert stream.get_data_info(
    ) == 'Random RBF Generator with drift - 1 targets, 4 classes, 10 features'

    assert stream.has_more_samples() is True

    assert stream.is_restartable() is True

    # Load test data corresponding to first 10 instances
    test_file = os.path.join(test_path, 'random_rbf_drift_stream.npz')
    data = np.load(test_file)
    X_expected = data['X']
    y_expected = data['y']

    X, y = stream.next_sample()
    assert np.alltrue(X[0] == X_expected[0])
    assert np.alltrue(y[0] == y_expected[0])

    X, y = stream.last_sample()
    assert np.alltrue(X[0] == X_expected[0])
    assert np.alltrue(y[0] == y_expected[0])

    stream.restart()
    X, y = stream.next_sample(10)
    assert np.alltrue(X == X_expected)
    assert np.alltrue(y == y_expected)

    assert stream.n_targets == np.array(y).ndim

    assert stream.n_features == X.shape[1]