forked from the-aerospace-corporation/brainblocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsklearn_style_classifier.py
More file actions
42 lines (34 loc) · 1.31 KB
/
sklearn_style_classifier.py
File metadata and controls
42 lines (34 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# ==============================================================================
# sklearn_style_classifier.py
# ==============================================================================
from brainblocks.tools import BBClassifier
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
import time
import numpy as np
h = .02 # step size in the mesh
num_samples = 500
rand_seed = 42
noise = 0.1
clf = BBClassifier(num_epochs=3, random_state=rand_seed)
X, y = make_classification(n_samples=num_samples, n_features=2, n_redundant=0, n_informative=2,
random_state=rand_seed, n_clusters_per_class=1, n_classes=2)
rng = np.random.RandomState(rand_seed)
X += 2 * rng.uniform(low=0.0, high=noise, size=X.shape)
# scale the data
X = MinMaxScaler().fit_transform(X)
# split data into train and test sets
X_train, X_test, y_train, y_test = \
train_test_split(X, y, test_size=.2, random_state=rand_seed)
print("Training")
t0 = time.time()
clf.fit(X_train, y_train)
t1 = time.time()
print("Time %fs with size %d" % ((t1 - t0), y_train.shape[0]))
print("Predicting")
t0 = time.time()
score = clf.score(X_test, y_test)
t1 = time.time()
print("Time %fs with size %d" % ((t1 - t0), y_test.shape[0]))
print("Score:", score)