RNN Classification Models¶
This example shows the application of RNN models in river-torch with and without usage of an incremental class adaption strategy.
In [1]:
Copied!
from deep_river.classification import RollingClassifier
from river import metrics, compose, preprocessing, datasets
import torch
from tqdm import tqdm
from deep_river.classification import RollingClassifier
from river import metrics, compose, preprocessing, datasets
import torch
from tqdm import tqdm
RNN Model¶
In [2]:
Copied!
class RnnModule(torch.nn.Module):
def __init__(self, n_features, hidden_size=1):
super().__init__()
self.n_features = n_features
self.rnn = torch.nn.RNN(
input_size=n_features, hidden_size=hidden_size, num_layers=1
)
self.softmax = torch.nn.Softmax(dim=-1)
def forward(self, X, **kwargs):
out, hn = self.rnn(X) # lstm with input, hidden, and internal state
hn = hn.view(-1, self.rnn.hidden_size)
return self.softmax(hn)
class RnnModule(torch.nn.Module):
def __init__(self, n_features, hidden_size=1):
super().__init__()
self.n_features = n_features
self.rnn = torch.nn.RNN(
input_size=n_features, hidden_size=hidden_size, num_layers=1
)
self.softmax = torch.nn.Softmax(dim=-1)
def forward(self, X, **kwargs):
out, hn = self.rnn(X) # lstm with input, hidden, and internal state
hn = hn.view(-1, self.rnn.hidden_size)
return self.softmax(hn)
Classification without incremental class adapation strategy¶
In [3]:
Copied!
dataset = datasets.Keystroke()
metric = metrics.Accuracy()
optimizer_fn = torch.optim.SGD
model_pipeline = preprocessing.StandardScaler()
model_pipeline |= RollingClassifier(
module=RnnModule,
loss_fn="binary_cross_entropy",
optimizer_fn=torch.optim.SGD,
window_size=20,
lr=1e-2,
append_predict=True,
is_class_incremental=False,
)
model_pipeline
dataset = datasets.Keystroke()
metric = metrics.Accuracy()
optimizer_fn = torch.optim.SGD
model_pipeline = preprocessing.StandardScaler()
model_pipeline |= RollingClassifier(
module=RnnModule,
loss_fn="binary_cross_entropy",
optimizer_fn=torch.optim.SGD,
window_size=20,
lr=1e-2,
append_predict=True,
is_class_incremental=False,
)
model_pipeline
Out[3]:
StandardScaler
StandardScaler (
with_std=True
)
RollingClassifier
RollingClassifier (
module=None
loss_fn="binary_cross_entropy"
optimizer_fn=<class 'torch.optim.sgd.SGD'>
lr=0.01
output_is_logit=True
is_class_incremental=False
is_feature_incremental=False
device="cpu"
seed=42
window_size=20
append_predict=True
)
In [4]:
Copied!
for x, y in tqdm(dataset):
y_pred = model_pipeline.predict_one(x) # make a prediction
metric.update(y, y_pred) # update the metric
model_pipeline.learn_one(x, y) # make the model learn
print(f"Accuracy: {metric.get():.2f}")
for x, y in tqdm(dataset):
y_pred = model_pipeline.predict_one(x) # make a prediction
metric.update(y, y_pred) # update the metric
model_pipeline.learn_one(x, y) # make the model learn
print(f"Accuracy: {metric.get():.2f}")
0it [00:00, ?it/s]
41it [00:00, 408.88it/s]
95it [00:00, 483.29it/s]
161it [00:00, 562.61it/s]
226it [00:00, 596.24it/s]
291it [00:00, 612.34it/s]
357it [00:00, 625.66it/s]
422it [00:00, 631.70it/s]
488it [00:00, 639.38it/s]
556it [00:00, 649.65it/s]
621it [00:01, 643.08it/s]
686it [00:01, 644.80it/s]
751it [00:01, 621.36it/s]
816it [00:01, 629.20it/s]
882it [00:01, 636.47it/s]
946it [00:01, 624.35it/s]
1009it [00:01, 625.61it/s]
1073it [00:01, 628.75it/s]
1137it [00:01, 631.68it/s]
1205it [00:01, 643.98it/s]
1271it [00:02, 646.62it/s]
1336it [00:02, 646.97it/s]
1401it [00:02, 627.89it/s]
1467it [00:02, 634.70it/s]
1533it [00:02, 640.11it/s]
1598it [00:02, 642.17it/s]
1665it [00:02, 648.58it/s]
1730it [00:02, 640.08it/s]
1797it [00:02, 648.46it/s]
1862it [00:02, 647.08it/s]
1927it [00:03, 644.39it/s]
1992it [00:03, 641.85it/s]
2057it [00:03, 616.41it/s]
2123it [00:03, 627.48it/s]
2189it [00:03, 636.68it/s]
2253it [00:03, 632.65it/s]
2320it [00:03, 641.70it/s]
2385it [00:03, 635.01it/s]
2450it [00:03, 636.53it/s]
2517it [00:03, 645.09it/s]
2583it [00:04, 646.50it/s]
2648it [00:04, 641.16it/s]
2713it [00:04, 614.64it/s]
2779it [00:04, 626.45it/s]
2844it [00:04, 632.74it/s]
2912it [00:04, 645.61it/s]
2977it [00:04, 644.70it/s]
3042it [00:04, 629.49it/s]
3106it [00:04, 621.49it/s]
3173it [00:05, 634.69it/s]
3239it [00:05, 639.61it/s]
3304it [00:05, 610.90it/s]
3366it [00:05, 534.43it/s]
3427it [00:05, 553.05it/s]
3489it [00:05, 571.17it/s]
3556it [00:05, 597.31it/s]
3618it [00:05, 601.51it/s]
3683it [00:05, 612.43it/s]
3749it [00:06, 624.32it/s]
3817it [00:06, 638.59it/s]
3882it [00:06, 636.91it/s]
3946it [00:06, 611.49it/s]
4012it [00:06, 623.04it/s]
4075it [00:06, 615.63it/s]
4141it [00:06, 626.21it/s]
4209it [00:06, 641.09it/s]
4274it [00:06, 636.95it/s]
4339it [00:06, 638.74it/s]
4406it [00:07, 646.27it/s]
4471it [00:07, 638.48it/s]
4536it [00:07, 640.03it/s]
4601it [00:07, 622.94it/s]
4667it [00:07, 632.70it/s]
4731it [00:07, 626.40it/s]
4797it [00:07, 633.64it/s]
4863it [00:07, 640.43it/s]
4928it [00:07, 622.86it/s]
4993it [00:07, 628.39it/s]
5060it [00:08, 637.99it/s]
5124it [00:08, 632.06it/s]
5190it [00:08, 638.55it/s]
5254it [00:08, 602.03it/s]
5319it [00:08, 613.37it/s]
5385it [00:08, 624.05it/s]
5448it [00:08, 586.11it/s]
5515it [00:08, 608.50it/s]
5578it [00:08, 608.88it/s]
5641it [00:09, 613.89it/s]
5706it [00:09, 624.16it/s]
5770it [00:09, 626.14it/s]
5833it [00:09, 626.44it/s]
5897it [00:09, 628.92it/s]
5960it [00:09, 626.50it/s]
6026it [00:09, 634.91it/s]
6092it [00:09, 642.19it/s]
6157it [00:09, 640.99it/s]
6222it [00:09, 630.35it/s]
6288it [00:10, 637.28it/s]
6353it [00:10, 639.50it/s]
6419it [00:10, 644.47it/s]
6484it [00:10, 636.75it/s]
6548it [00:10, 635.99it/s]
6613it [00:10, 637.11it/s]
6679it [00:10, 643.43it/s]
6746it [00:10, 649.92it/s]
6812it [00:10, 646.35it/s]
6877it [00:10, 638.54it/s]
6942it [00:11, 640.45it/s]
7007it [00:11, 638.15it/s]
7074it [00:11, 645.44it/s]
7139it [00:11, 629.12it/s]
7203it [00:11, 612.93it/s]
7265it [00:11, 609.92it/s]
7332it [00:11, 625.59it/s]
7399it [00:11, 637.33it/s]
7464it [00:11, 639.25it/s]
7528it [00:11, 634.26it/s]
7595it [00:12, 642.34it/s]
7660it [00:12, 642.55it/s]
7725it [00:12, 634.96it/s]
7789it [00:12, 631.12it/s]
7853it [00:12, 631.76it/s]
7920it [00:12, 636.72it/s]
7984it [00:12, 631.99it/s]
8050it [00:12, 637.70it/s]
8114it [00:12, 634.79it/s]
8178it [00:13, 619.48it/s]
8244it [00:13, 629.75it/s]
8308it [00:13, 625.28it/s]
8374it [00:13, 634.27it/s]
8438it [00:13, 633.26it/s]
8502it [00:13, 616.84it/s]
8566it [00:13, 623.09it/s]
8632it [00:13, 633.21it/s]
8696it [00:13, 634.39it/s]
8762it [00:13, 640.83it/s]
8827it [00:14, 636.94it/s]
8891it [00:14, 636.94it/s]
8957it [00:14, 642.75it/s]
9022it [00:14, 638.38it/s]
9086it [00:14, 637.33it/s]
9150it [00:14, 618.58it/s]
9212it [00:14, 614.31it/s]
9274it [00:14, 609.50it/s]
9336it [00:14, 605.51it/s]
9400it [00:14, 615.14it/s]
9464it [00:15, 621.63it/s]
9527it [00:15, 623.05it/s]
9594it [00:15, 635.24it/s]
9658it [00:15, 634.68it/s]
9723it [00:15, 637.71it/s]
9787it [00:15, 622.74it/s]
9854it [00:15, 635.00it/s]
9919it [00:15, 639.13it/s]
9985it [00:15, 643.33it/s]
10051it [00:15, 648.07it/s]
10116it [00:16, 638.49it/s]
10181it [00:16, 640.26it/s]
10248it [00:16, 645.86it/s]
10313it [00:16, 639.67it/s]
10378it [00:16, 641.90it/s]
10443it [00:16, 632.54it/s]
10507it [00:16, 626.53it/s]
10574it [00:16, 637.18it/s]
10640it [00:16, 639.83it/s]
10705it [00:17, 634.47it/s]
10769it [00:17, 633.75it/s]
10833it [00:17, 628.07it/s]
10899it [00:17, 636.08it/s]
10963it [00:17, 632.53it/s]
11027it [00:17, 632.67it/s]
11091it [00:17, 628.98it/s]
11158it [00:17, 639.98it/s]
11225it [00:17, 646.12it/s]
11290it [00:17, 644.40it/s]
11355it [00:18, 645.64it/s]
11420it [00:18, 639.19it/s]
11484it [00:18, 634.59it/s]
11548it [00:18, 627.76it/s]
11611it [00:18, 615.69it/s]
11676it [00:18, 624.44it/s]
11739it [00:18, 614.45it/s]
11802it [00:18, 618.69it/s]
11868it [00:18, 627.98it/s]
11932it [00:18, 631.42it/s]
11997it [00:19, 634.21it/s]
12061it [00:19, 616.33it/s]
12125it [00:19, 621.49it/s]
12191it [00:19, 632.39it/s]
12255it [00:19, 625.04it/s]
12318it [00:19, 625.31it/s]
12382it [00:19, 626.84it/s]
12445it [00:19, 625.94it/s]
12511it [00:19, 633.33it/s]
12577it [00:19, 638.61it/s]
12643it [00:20, 643.92it/s]
12708it [00:20, 628.70it/s]
12774it [00:20, 637.71it/s]
12838it [00:20, 633.87it/s]
12902it [00:20, 629.48it/s]
12969it [00:20, 640.98it/s]
13034it [00:20, 635.23it/s]
13098it [00:20, 631.37it/s]
13164it [00:20, 638.94it/s]
13230it [00:21, 644.33it/s]
13296it [00:21, 646.61it/s]
13361it [00:21, 624.46it/s]
13426it [00:21, 629.99it/s]
13492it [00:21, 636.31it/s]
13556it [00:21, 619.06it/s]
13623it [00:21, 632.13it/s]
13687it [00:21, 634.26it/s]
13754it [00:21, 644.51it/s]
13819it [00:21, 642.49it/s]
13884it [00:22, 636.58it/s]
13948it [00:22, 631.49it/s]
14012it [00:22, 627.12it/s]
14077it [00:22, 631.34it/s]
14141it [00:22, 624.07it/s]
14204it [00:22, 624.40it/s]
14268it [00:22, 627.09it/s]
14332it [00:22, 629.47it/s]
14396it [00:22, 632.44it/s]
14463it [00:22, 642.37it/s]
14530it [00:23, 649.05it/s]
14595it [00:23, 649.10it/s]
14660it [00:23, 623.62it/s]
14724it [00:23, 626.38it/s]
14787it [00:23, 624.06it/s]
14850it [00:23, 621.86it/s]
14916it [00:23, 632.15it/s]
14980it [00:23, 627.70it/s]
15044it [00:23, 628.58it/s]
15107it [00:23, 628.59it/s]
15174it [00:24, 640.51it/s]
15239it [00:24, 642.65it/s]
15304it [00:24, 627.95it/s]
15368it [00:24, 631.03it/s]
15432it [00:24, 623.05it/s]
15498it [00:24, 632.74it/s]
15562it [00:24, 632.56it/s]
15626it [00:24, 627.15it/s]
15689it [00:24, 607.82it/s]
15753it [00:25, 614.07it/s]
15818it [00:25, 623.91it/s]
15881it [00:25, 624.06it/s]
15946it [00:25, 631.20it/s]
16012it [00:25, 637.79it/s]
16076it [00:25, 616.14it/s]
16138it [00:25, 617.10it/s]
16203it [00:25, 626.38it/s]
16267it [00:25, 629.86it/s]
16331it [00:25, 632.38it/s]
16397it [00:26, 638.74it/s]
16461it [00:26, 637.60it/s]
16527it [00:26, 643.00it/s]
16592it [00:26, 640.85it/s]
16657it [00:26, 633.00it/s]
16721it [00:26, 619.63it/s]
16787it [00:26, 630.13it/s]
16852it [00:26, 635.21it/s]
16916it [00:26, 634.17it/s]
16980it [00:26, 628.55it/s]
17044it [00:27, 628.93it/s]
17109it [00:27, 634.50it/s]
17174it [00:27, 637.67it/s]
17240it [00:27, 642.08it/s]
17305it [00:27, 642.29it/s]
17370it [00:27, 628.91it/s]
17436it [00:27, 637.62it/s]
17502it [00:27, 643.12it/s]
17567it [00:27, 636.50it/s]
17631it [00:27, 627.95it/s]
17696it [00:28, 633.83it/s]
17760it [00:28, 629.02it/s]
17825it [00:28, 634.85it/s]
17889it [00:28, 593.75it/s]
17949it [00:28, 586.63it/s]
18013it [00:28, 601.31it/s]
18074it [00:28, 589.51it/s]
18138it [00:28, 602.30it/s]
18201it [00:28, 608.50it/s]
18266it [00:29, 620.22it/s]
18333it [00:29, 634.03it/s]
18397it [00:29, 626.12it/s]
18461it [00:29, 630.04it/s]
18525it [00:29, 623.09it/s]
18588it [00:29, 606.12it/s]
18655it [00:29, 622.08it/s]
18721it [00:29, 630.61it/s]
18787it [00:29, 638.35it/s]
18851it [00:29, 619.82it/s]
18916it [00:30, 626.43it/s]
18981it [00:30, 630.78it/s]
19047it [00:30, 637.27it/s]
19112it [00:30, 640.29it/s]
19177it [00:30, 637.91it/s]
19241it [00:30, 629.73it/s]
19307it [00:30, 636.31it/s]
19373it [00:30, 641.88it/s]
19440it [00:30, 646.83it/s]
19505it [00:30, 638.54it/s]
19569it [00:31, 630.20it/s]
19635it [00:31, 636.70it/s]
19700it [00:31, 639.50it/s]
19765it [00:31, 642.50it/s]
19830it [00:31, 630.36it/s]
19894it [00:31, 610.86it/s]
19959it [00:31, 621.14it/s]
20025it [00:31, 630.56it/s]
20090it [00:31, 633.65it/s]
20154it [00:32, 599.96it/s]
20215it [00:32, 602.08it/s]
20281it [00:32, 617.53it/s]
20348it [00:32, 631.91it/s]
20400it [00:32, 629.27it/s]
Accuracy: 0.02
Classification with incremental class adaption strategy¶
In [5]:
Copied!
dataset = datasets.Keystroke()
metric = metrics.Accuracy()
optimizer_fn = torch.optim.SGD
model_pipeline = preprocessing.StandardScaler()
model_pipeline |= RollingClassifier(
module=RnnModule,
loss_fn="binary_cross_entropy",
optimizer_fn=torch.optim.SGD,
window_size=20,
lr=1e-2,
append_predict=True,
is_class_incremental=True,
)
model_pipeline
dataset = datasets.Keystroke()
metric = metrics.Accuracy()
optimizer_fn = torch.optim.SGD
model_pipeline = preprocessing.StandardScaler()
model_pipeline |= RollingClassifier(
module=RnnModule,
loss_fn="binary_cross_entropy",
optimizer_fn=torch.optim.SGD,
window_size=20,
lr=1e-2,
append_predict=True,
is_class_incremental=True,
)
model_pipeline
Out[5]:
StandardScaler
StandardScaler (
with_std=True
)
RollingClassifier
RollingClassifier (
module=None
loss_fn="binary_cross_entropy"
optimizer_fn=<class 'torch.optim.sgd.SGD'>
lr=0.01
output_is_logit=True
is_class_incremental=True
is_feature_incremental=False
device="cpu"
seed=42
window_size=20
append_predict=True
)
In [6]:
Copied!
for x, y in tqdm(dataset):
y_pred = model_pipeline.predict_one(x) # make a prediction
metric.update(y, y_pred) # update the metric
model_pipeline.learn_one(x, y) # make the model learn
print(f"Accuracy: {metric.get():.2f}")
for x, y in tqdm(dataset):
y_pred = model_pipeline.predict_one(x) # make a prediction
metric.update(y, y_pred) # update the metric
model_pipeline.learn_one(x, y) # make the model learn
print(f"Accuracy: {metric.get():.2f}")
0it [00:00, ?it/s]
/Users/cedrickulbach/Documents/Projects/deep-river/deep_river/base.py:231: UserWarning: The model will not be able to adapt its output to new classes since no supported output layer was found. warnings.warn(
69it [00:00, 684.00it/s]
138it [00:00, 651.33it/s]
204it [00:00, 646.26it/s]
270it [00:00, 648.99it/s]
335it [00:00, 647.15it/s]
400it [00:00, 646.63it/s]
465it [00:00, 642.35it/s]
530it [00:00, 635.89it/s]
596it [00:00, 640.13it/s]
661it [00:01, 640.32it/s]
726it [00:01, 619.35it/s]
789it [00:01, 617.77it/s]
851it [00:01, 614.48it/s]
915it [00:01, 621.90it/s]
979it [00:01, 626.47it/s]
1042it [00:01, 620.07it/s]
1105it [00:01, 619.02it/s]
1167it [00:01, 618.79it/s]
1234it [00:01, 633.74it/s]
1300it [00:02, 639.51it/s]
1364it [00:02, 628.78it/s]
1429it [00:02, 632.47it/s]
1493it [00:02, 633.93it/s]
1557it [00:02, 615.71it/s]
1622it [00:02, 624.96it/s]
1685it [00:02, 623.92it/s]
1748it [00:02, 623.24it/s]
1814it [00:02, 631.82it/s]
1879it [00:02, 636.62it/s]
1943it [00:03, 624.11it/s]
2006it [00:03, 601.55it/s]
2072it [00:03, 615.65it/s]
2139it [00:03, 629.25it/s]
2203it [00:03, 589.19it/s]
2264it [00:03, 594.60it/s]
2324it [00:03, 585.81it/s]
2388it [00:03, 599.18it/s]
2454it [00:03, 615.18it/s]
2520it [00:04, 626.84it/s]
2583it [00:04, 627.40it/s]
2646it [00:04, 604.47it/s]
2709it [00:04, 610.52it/s]
2775it [00:04, 622.89it/s]
2841it [00:04, 633.19it/s]
2906it [00:04, 638.08it/s]
2970it [00:04, 617.72it/s]
3034it [00:04, 623.91it/s]
3100it [00:04, 632.80it/s]
3164it [00:05, 625.77it/s]
3227it [00:05, 615.02it/s]
3289it [00:05, 615.26it/s]
3356it [00:05, 631.10it/s]
3422it [00:05, 639.45it/s]
3487it [00:05, 641.47it/s]
3554it [00:05, 649.57it/s]
3619it [00:05, 628.66it/s]
3685it [00:05, 635.34it/s]
3749it [00:05, 626.92it/s]
3812it [00:06, 618.94it/s]
3874it [00:06, 617.02it/s]
3936it [00:06, 590.99it/s]
4000it [00:06, 603.65it/s]
4065it [00:06, 616.57it/s]
4131it [00:06, 627.14it/s]
4196it [00:06, 632.09it/s]
4260it [00:06, 618.73it/s]
4325it [00:06, 626.86it/s]
4390it [00:07, 631.76it/s]
4454it [00:07, 626.10it/s]
4517it [00:07, 625.77it/s]
4580it [00:07, 623.48it/s]
4647it [00:07, 637.17it/s]
4711it [00:07, 630.06it/s]
4777it [00:07, 638.03it/s]
4842it [00:07, 640.61it/s]
4907it [00:07, 637.94it/s]
4974it [00:07, 645.11it/s]
5039it [00:08, 643.57it/s]
5106it [00:08, 650.73it/s]
5172it [00:08, 644.68it/s]
5237it [00:08, 630.67it/s]
5305it [00:08, 642.57it/s]
5370it [00:08, 631.17it/s]
5434it [00:08, 606.20it/s]
5495it [00:08, 606.60it/s]
5556it [00:08, 605.27it/s]
5622it [00:08, 620.17it/s]
5686it [00:09, 625.58it/s]
5749it [00:09, 621.03it/s]
5812it [00:09, 618.88it/s]
5876it [00:09, 623.90it/s]
5940it [00:09, 626.15it/s]
6005it [00:09, 631.12it/s]
6072it [00:09, 639.18it/s]
6138it [00:09, 644.51it/s]
6203it [00:09, 633.41it/s]
6268it [00:10, 636.11it/s]
6333it [00:10, 639.26it/s]
6400it [00:10, 647.27it/s]
6465it [00:10, 638.95it/s]
6529it [00:10, 626.50it/s]
6595it [00:10, 634.64it/s]
6661it [00:10, 640.91it/s]
6726it [00:10, 640.98it/s]
6792it [00:10, 644.01it/s]
6857it [00:10, 626.37it/s]
6921it [00:11, 629.80it/s]
6985it [00:11, 627.32it/s]
7051it [00:11, 636.85it/s]
7115it [00:11, 610.99it/s]
7177it [00:11, 590.98it/s]
7240it [00:11, 600.56it/s]
7306it [00:11, 616.69it/s]
7369it [00:11, 618.90it/s]
7435it [00:11, 629.39it/s]
7499it [00:11, 621.29it/s]
7563it [00:12, 625.97it/s]
7626it [00:12, 626.01it/s]
7689it [00:12, 621.90it/s]
7753it [00:12, 627.18it/s]
7816it [00:12, 586.52it/s]
7880it [00:12, 599.99it/s]
7945it [00:12, 612.79it/s]
8012it [00:12, 626.48it/s]
8077it [00:12, 631.01it/s]
8141it [00:13, 633.06it/s]
8205it [00:13, 626.13it/s]
8271it [00:13, 633.29it/s]
8335it [00:13, 627.38it/s]
8400it [00:13, 631.73it/s]
8464it [00:13, 623.97it/s]
8531it [00:13, 634.72it/s]
8597it [00:13, 640.05it/s]
8664it [00:13, 646.60it/s]
8729it [00:13, 630.04it/s]
8793it [00:14, 267.00it/s]
8841it [00:14, 270.87it/s]
8883it [00:15, 100.61it/s]
8914it [00:16, 107.97it/s]
8940it [00:16, 118.12it/s]
8964it [00:16, 126.22it/s]
8986it [00:16, 138.43it/s]
9009it [00:16, 152.06it/s]
9041it [00:16, 182.23it/s]
9066it [00:16, 191.97it/s]
9091it [00:16, 197.76it/s]
9115it [00:17, 186.71it/s]
9137it [00:17, 181.55it/s]
9158it [00:17, 187.69it/s]
9184it [00:17, 205.58it/s]
9212it [00:17, 225.00it/s]
9238it [00:17, 234.07it/s]
9263it [00:17, 233.26it/s]
9288it [00:17, 235.52it/s]
9313it [00:17, 221.52it/s]
9336it [00:18, 171.20it/s]
9356it [00:18, 167.90it/s]
9375it [00:18, 138.91it/s]
9395it [00:18, 151.04it/s]
9412it [00:18, 151.02it/s]
9430it [00:18, 156.10it/s]
9449it [00:18, 164.25it/s]
9486it [00:19, 218.97it/s]
9514it [00:19, 234.14it/s]
9556it [00:19, 285.14it/s]
9589it [00:19, 296.86it/s]
9625it [00:19, 314.38it/s]
9667it [00:19, 343.85it/s]
9702it [00:19, 325.76it/s]
9749it [00:19, 366.15it/s]
9792it [00:19, 382.75it/s]
9838it [00:19, 402.24it/s]
9885it [00:20, 420.55it/s]
9928it [00:20, 399.22it/s]
9971it [00:20, 407.50it/s]
10013it [00:20, 405.73it/s]
10054it [00:20, 402.42it/s]
10095it [00:20, 375.73it/s]
10143it [00:20, 403.82it/s]
10198it [00:20, 441.22it/s]
10249it [00:20, 458.59it/s]
10296it [00:21, 460.94it/s]
10343it [00:21, 461.60it/s]
10399it [00:21, 488.91it/s]
10456it [00:21, 511.13it/s]
10512it [00:21, 523.94it/s]
10565it [00:21, 514.27it/s]
10619it [00:21, 519.89it/s]
10675it [00:21, 529.89it/s]
10731it [00:21, 536.97it/s]
10789it [00:21, 549.11it/s]
10844it [00:22, 492.14it/s]
10895it [00:22, 451.14it/s]
10942it [00:22, 425.82it/s]
10986it [00:22, 423.51it/s]
11035it [00:22, 440.93it/s]
11081it [00:22, 445.95it/s]
11134it [00:22, 468.48it/s]
11188it [00:22, 487.92it/s]
11238it [00:22, 467.66it/s]
11286it [00:23, 451.41it/s]
11332it [00:23, 435.43it/s]
11379it [00:23, 444.71it/s]
11434it [00:23, 473.85it/s]
11482it [00:23, 457.05it/s]
11529it [00:23, 440.37it/s]
11574it [00:23, 438.94it/s]
11624it [00:23, 454.79it/s]
11680it [00:23, 483.73it/s]
11738it [00:24, 511.29it/s]
11799it [00:24, 539.07it/s]
11854it [00:24, 525.95it/s]
11910it [00:24, 533.19it/s]
11969it [00:24, 546.63it/s]
12029it [00:24, 561.62it/s]
12091it [00:24, 578.10it/s]
12149it [00:24, 570.01it/s]
12211it [00:24, 584.15it/s]
12271it [00:24, 585.62it/s]
12330it [00:25, 577.50it/s]
12388it [00:25, 564.67it/s]
12445it [00:25, 565.54it/s]
12504it [00:25, 571.74it/s]
12563it [00:25, 576.90it/s]
12622it [00:25, 578.20it/s]
12682it [00:25, 584.65it/s]
12741it [00:25, 561.54it/s]
12800it [00:25, 569.65it/s]
12858it [00:26, 566.61it/s]
12915it [00:26, 538.37it/s]
12975it [00:26, 554.02it/s]
13031it [00:26, 553.65it/s]
13094it [00:26, 574.09it/s]
13152it [00:26, 571.82it/s]
13214it [00:26, 583.54it/s]
13275it [00:26, 589.33it/s]
13335it [00:26, 573.92it/s]
13393it [00:26, 569.07it/s]
13454it [00:27, 579.40it/s]
13516it [00:27, 588.91it/s]
13581it [00:27, 606.84it/s]
13645it [00:27, 615.14it/s]
13711it [00:27, 628.15it/s]
13774it [00:27, 616.87it/s]
13839it [00:27, 624.07it/s]
13902it [00:27, 619.55it/s]
13965it [00:27, 575.89it/s]
14029it [00:28, 593.70it/s]
14094it [00:28, 607.48it/s]
14157it [00:28, 612.75it/s]
14219it [00:28, 609.33it/s]
14285it [00:28, 622.25it/s]
14351it [00:28, 630.28it/s]
14415it [00:28, 612.51it/s]
14479it [00:28, 618.53it/s]
14544it [00:28, 626.24it/s]
14607it [00:28, 618.92it/s]
14670it [00:29, 618.28it/s]
14732it [00:29, 612.86it/s]
14797it [00:29, 622.85it/s]
14860it [00:29, 620.39it/s]
14923it [00:29, 614.79it/s]
14986it [00:29, 618.98it/s]
15049it [00:29, 621.36it/s]
15112it [00:29, 623.00it/s]
15176it [00:29, 626.20it/s]
15239it [00:29, 614.59it/s]
15304it [00:30, 622.29it/s]
15370it [00:30, 631.81it/s]
15436it [00:30, 640.05it/s]
15502it [00:30, 643.26it/s]
15567it [00:30, 643.23it/s]
15632it [00:30, 638.91it/s]
15696it [00:30, 638.11it/s]
15760it [00:30, 634.23it/s]
15825it [00:30, 636.11it/s]
15889it [00:30, 627.78it/s]
15952it [00:31, 621.19it/s]
16015it [00:31, 601.15it/s]
16081it [00:31, 615.84it/s]
16143it [00:31, 616.45it/s]
16205it [00:31, 581.90it/s]
16264it [00:31, 573.73it/s]
16324it [00:31, 578.06it/s]
16386it [00:31, 588.46it/s]
16449it [00:31, 596.50it/s]
16509it [00:32, 589.95it/s]
16574it [00:32, 607.32it/s]
16640it [00:32, 622.07it/s]
16703it [00:32, 622.74it/s]
16766it [00:32, 598.72it/s]
16827it [00:32, 585.45it/s]
16887it [00:32, 589.37it/s]
16950it [00:32, 598.79it/s]
17015it [00:32, 613.73it/s]
17078it [00:32, 617.35it/s]
17140it [00:33, 615.94it/s]
17202it [00:33, 612.54it/s]
17268it [00:33, 623.91it/s]
17333it [00:33, 630.17it/s]
17397it [00:33, 631.74it/s]
17461it [00:33, 622.47it/s]
17524it [00:33, 615.59it/s]
17586it [00:33, 615.76it/s]
17649it [00:33, 618.64it/s]
17713it [00:33, 623.21it/s]
17776it [00:34, 608.70it/s]
17837it [00:34, 604.52it/s]
17903it [00:34, 618.18it/s]
17965it [00:34, 617.87it/s]
18027it [00:34, 610.24it/s]
18089it [00:34, 594.16it/s]
18152it [00:34, 602.34it/s]
18218it [00:34, 618.17it/s]
18284it [00:34, 629.13it/s]
18348it [00:35, 620.64it/s]
18411it [00:35, 603.90it/s]
18476it [00:35, 614.85it/s]
18543it [00:35, 629.01it/s]
18609it [00:35, 637.38it/s]
18673it [00:35, 632.90it/s]
18737it [00:35, 612.96it/s]
18799it [00:35, 603.78it/s]
18860it [00:35, 599.95it/s]
18922it [00:35, 605.02it/s]
18983it [00:36, 605.80it/s]
19044it [00:36, 534.86it/s]
19099it [00:36, 524.54it/s]
19161it [00:36, 550.36it/s]
19227it [00:36, 579.32it/s]
19289it [00:36, 588.91it/s]
19349it [00:36, 586.94it/s]
19411it [00:36, 595.76it/s]
19472it [00:36, 598.99it/s]
19536it [00:37, 609.59it/s]
19598it [00:37, 595.27it/s]
19662it [00:37, 607.81it/s]
19728it [00:37, 620.98it/s]
19794it [00:37, 631.64it/s]
19859it [00:37, 636.06it/s]
19923it [00:37, 612.23it/s]
19985it [00:37, 613.74it/s]
20050it [00:37, 623.87it/s]
20116it [00:37, 632.11it/s]
20181it [00:38, 635.51it/s]
20245it [00:38, 624.27it/s]
20312it [00:38, 635.99it/s]
20378it [00:38, 642.27it/s]
20400it [00:38, 531.22it/s]
Accuracy: 0.02
LSTM Model¶
In [7]:
Copied!
class LstmModule(torch.nn.Module):
def __init__(self, n_features, hidden_size=1):
super().__init__()
self.n_features = n_features
self.lstm = torch.nn.LSTM(
input_size=n_features, hidden_size=hidden_size, num_layers=1
)
self.softmax = torch.nn.Softmax(dim=-1)
def forward(self, X, **kwargs):
output, (hn, cn) = self.lstm(
X
) # lstm with input, hidden, and internal state
hn = hn.view(-1, self.lstm.hidden_size)
return self.softmax(hn)
class LstmModule(torch.nn.Module):
def __init__(self, n_features, hidden_size=1):
super().__init__()
self.n_features = n_features
self.lstm = torch.nn.LSTM(
input_size=n_features, hidden_size=hidden_size, num_layers=1
)
self.softmax = torch.nn.Softmax(dim=-1)
def forward(self, X, **kwargs):
output, (hn, cn) = self.lstm(
X
) # lstm with input, hidden, and internal state
hn = hn.view(-1, self.lstm.hidden_size)
return self.softmax(hn)
Classifcation without incremental class adaption strategy¶
In [8]:
Copied!
dataset = datasets.Keystroke()
metric = metrics.Accuracy()
optimizer_fn = torch.optim.SGD
model_pipeline = preprocessing.StandardScaler()
model_pipeline |= RollingClassifier(
module=LstmModule,
loss_fn="binary_cross_entropy",
optimizer_fn=torch.optim.SGD,
window_size=20,
lr=1e-2,
append_predict=True,
)
model_pipeline
dataset = datasets.Keystroke()
metric = metrics.Accuracy()
optimizer_fn = torch.optim.SGD
model_pipeline = preprocessing.StandardScaler()
model_pipeline |= RollingClassifier(
module=LstmModule,
loss_fn="binary_cross_entropy",
optimizer_fn=torch.optim.SGD,
window_size=20,
lr=1e-2,
append_predict=True,
)
model_pipeline
Out[8]:
StandardScaler
StandardScaler (
with_std=True
)
RollingClassifier
RollingClassifier (
module=None
loss_fn="binary_cross_entropy"
optimizer_fn=<class 'torch.optim.sgd.SGD'>
lr=0.01
output_is_logit=True
is_class_incremental=False
is_feature_incremental=False
device="cpu"
seed=42
window_size=20
append_predict=True
)
In [9]:
Copied!
for x, y in tqdm(dataset):
y_pred = model_pipeline.predict_one(x) # make a prediction
metric.update(y, y_pred) # update the metric
model_pipeline.learn_one(x, y) # make the model learn
print(f"Accuracy: {metric.get():.2f}")
for x, y in tqdm(dataset):
y_pred = model_pipeline.predict_one(x) # make a prediction
metric.update(y, y_pred) # update the metric
model_pipeline.learn_one(x, y) # make the model learn
print(f"Accuracy: {metric.get():.2f}")
0it [00:00, ?it/s]
32it [00:00, 319.38it/s]
88it [00:00, 460.14it/s]
154it [00:00, 550.66it/s]
221it [00:00, 595.18it/s]
288it [00:00, 618.97it/s]
354it [00:00, 629.76it/s]
417it [00:00, 623.94it/s]
484it [00:00, 636.24it/s]
551it [00:00, 645.65it/s]
618it [00:01, 652.79it/s]
685it [00:01, 656.93it/s]
751it [00:01, 638.66it/s]
818it [00:01, 646.37it/s]
886it [00:01, 653.71it/s]
953it [00:01, 657.55it/s]
1020it [00:01, 659.39it/s]
1086it [00:01, 642.11it/s]
1152it [00:01, 644.49it/s]
1217it [00:01, 645.30it/s]
1282it [00:02, 645.78it/s]
1347it [00:02, 646.24it/s]
1412it [00:02, 629.05it/s]
1478it [00:02, 637.83it/s]
1546it [00:02, 647.31it/s]
1613it [00:02, 652.41it/s]
1679it [00:02, 653.10it/s]
1745it [00:02, 652.19it/s]
1812it [00:02, 655.56it/s]
1880it [00:02, 660.13it/s]
1947it [00:03, 663.03it/s]
2014it [00:03, 665.00it/s]
2081it [00:03, 642.76it/s]
2148it [00:03, 650.67it/s]
2216it [00:03, 657.66it/s]
2285it [00:03, 664.64it/s]
2352it [00:03, 663.51it/s]
2419it [00:03, 651.38it/s]
2485it [00:03, 649.73it/s]
2551it [00:03, 640.86it/s]
2616it [00:04, 638.89it/s]
2683it [00:04, 647.52it/s]
2748it [00:04, 636.96it/s]
2815it [00:04, 645.03it/s]
2882it [00:04, 652.22it/s]
2950it [00:04, 659.76it/s]
3017it [00:04, 662.00it/s]
3084it [00:04, 647.16it/s]
3151it [00:04, 652.81it/s]
3218it [00:05, 657.79it/s]
3285it [00:05, 659.23it/s]
3352it [00:05, 659.39it/s]
3418it [00:05, 645.02it/s]
3486it [00:05, 652.81it/s]
3553it [00:05, 656.49it/s]
3620it [00:05, 660.44it/s]
3688it [00:05, 664.15it/s]
3755it [00:05, 650.68it/s]
3821it [00:05, 652.18it/s]
3887it [00:06, 654.12it/s]
3954it [00:06, 658.14it/s]
4020it [00:06, 656.14it/s]
4086it [00:06, 649.05it/s]
4151it [00:06, 648.39it/s]
4218it [00:06, 653.93it/s]
4284it [00:06, 654.03it/s]
4351it [00:06, 656.26it/s]
4417it [00:06, 652.64it/s]
4484it [00:06, 654.95it/s]
4551it [00:07, 658.09it/s]
4617it [00:07, 655.20it/s]
4683it [00:07, 653.40it/s]
4750it [00:07, 655.76it/s]
4817it [00:07, 657.77it/s]
4884it [00:07, 661.08it/s]
4951it [00:07, 661.11it/s]
5018it [00:07, 624.39it/s]
5081it [00:07, 611.30it/s]
5148it [00:07, 625.75it/s]
5215it [00:08, 637.19it/s]
5283it [00:08, 648.10it/s]
5349it [00:08, 651.24it/s]
5415it [00:08, 648.26it/s]
5480it [00:08, 640.29it/s]
5547it [00:08, 647.57it/s]
5614it [00:08, 651.71it/s]
5681it [00:08, 654.67it/s]
5747it [00:08, 654.14it/s]
5813it [00:08, 650.04it/s]
5879it [00:09, 649.33it/s]
5946it [00:09, 653.78it/s]
6012it [00:09, 655.57it/s]
6078it [00:09, 656.16it/s]
6144it [00:09, 653.35it/s]
6211it [00:09, 657.25it/s]
6278it [00:09, 660.83it/s]
6345it [00:09, 661.18it/s]
6412it [00:09, 662.44it/s]
6479it [00:10, 653.75it/s]
6546it [00:10, 657.16it/s]
6613it [00:10, 658.48it/s]
6679it [00:10, 656.50it/s]
6746it [00:10, 660.44it/s]
6813it [00:10, 646.13it/s]
6878it [00:10, 644.34it/s]
6946it [00:10, 652.13it/s]
7013it [00:10, 655.14it/s]
7080it [00:10, 656.61it/s]
7146it [00:11, 639.23it/s]
7211it [00:11, 638.18it/s]
7275it [00:11, 636.85it/s]
7339it [00:11, 635.13it/s]
7403it [00:11, 634.66it/s]
7467it [00:11, 626.55it/s]
7534it [00:11, 639.21it/s]
7599it [00:11, 642.32it/s]
7666it [00:11, 649.54it/s]
7733it [00:11, 653.10it/s]
7799it [00:12, 645.65it/s]
7866it [00:12, 652.51it/s]
7933it [00:12, 656.95it/s]
8000it [00:12, 660.06it/s]
8067it [00:12, 662.36it/s]
8134it [00:12, 654.74it/s]
8200it [00:12, 655.85it/s]
8266it [00:12, 655.14it/s]
8332it [00:12, 653.33it/s]
8399it [00:12, 655.85it/s]
8465it [00:13, 637.72it/s]
8532it [00:13, 646.49it/s]
8597it [00:13, 646.54it/s]
8662it [00:13, 646.56it/s]
8728it [00:13, 650.44it/s]
8794it [00:13, 637.31it/s]
8860it [00:13, 642.42it/s]
8928it [00:13, 651.86it/s]
8994it [00:13, 648.50it/s]
9059it [00:13, 635.80it/s]
9123it [00:14, 631.46it/s]
9190it [00:14, 640.88it/s]
9255it [00:14, 637.08it/s]
9322it [00:14, 645.34it/s]
9389it [00:14, 651.00it/s]
9455it [00:14, 640.30it/s]
9521it [00:14, 643.90it/s]
9588it [00:14, 650.09it/s]
9655it [00:14, 653.59it/s]
9721it [00:15, 653.40it/s]
9787it [00:15, 630.58it/s]
9852it [00:15, 634.41it/s]
9917it [00:15, 638.20it/s]
9984it [00:15, 647.46it/s]
10050it [00:15, 650.15it/s]
10116it [00:15, 643.49it/s]
10183it [00:15, 649.87it/s]
10250it [00:15, 653.18it/s]
10317it [00:15, 655.06it/s]
10383it [00:16, 651.46it/s]
10449it [00:16, 640.67it/s]
10515it [00:16, 645.10it/s]
10580it [00:16, 646.33it/s]
10647it [00:16, 651.57it/s]
10713it [00:16, 653.01it/s]
10779it [00:16, 637.34it/s]
10843it [00:16, 635.35it/s]
10910it [00:16, 643.73it/s]
10976it [00:16, 648.05it/s]
11042it [00:17, 650.47it/s]
11108it [00:17, 633.19it/s]
11173it [00:17, 637.08it/s]
11239it [00:17, 642.69it/s]
11306it [00:17, 648.79it/s]
11371it [00:17, 646.86it/s]
11436it [00:17, 643.13it/s]
11501it [00:17, 622.62it/s]
11567it [00:17, 632.17it/s]
11633it [00:17, 637.88it/s]
11700it [00:18, 644.61it/s]
11765it [00:18, 638.26it/s]
11829it [00:18, 637.68it/s]
11894it [00:18, 640.32it/s]
11959it [00:18, 642.14it/s]
12024it [00:18, 639.14it/s]
12088it [00:18, 461.09it/s]
12146it [00:18, 488.33it/s]
12203it [00:19, 508.49it/s]
12262it [00:19, 528.99it/s]
12319it [00:19, 527.78it/s]
12381it [00:19, 551.72it/s]
12443it [00:19, 570.71it/s]
12502it [00:19, 570.15it/s]
12565it [00:19, 586.04it/s]
12627it [00:19, 594.37it/s]
12694it [00:19, 615.30it/s]
12759it [00:19, 624.11it/s]
12824it [00:20, 630.20it/s]
12890it [00:20, 636.57it/s]
12954it [00:20, 631.15it/s]
13018it [00:20, 631.73it/s]
13084it [00:20, 638.53it/s]
13148it [00:20, 637.25it/s]
13212it [00:20, 633.64it/s]
13276it [00:20, 629.94it/s]
13341it [00:20, 633.50it/s]
13407it [00:20, 640.74it/s]
13472it [00:21, 635.16it/s]
13538it [00:21, 641.80it/s]
13603it [00:21, 630.60it/s]
13667it [00:21, 629.74it/s]
13733it [00:21, 637.44it/s]
13799it [00:21, 643.22it/s]
13865it [00:21, 647.64it/s]
13930it [00:21, 638.30it/s]
13995it [00:21, 640.63it/s]
14060it [00:21, 642.46it/s]
14125it [00:22, 644.37it/s]
14191it [00:22, 647.91it/s]
14256it [00:22, 638.98it/s]
14320it [00:22, 631.93it/s]
14386it [00:22, 638.53it/s]
14452it [00:22, 641.99it/s]
14517it [00:22, 636.05it/s]
14581it [00:22, 611.59it/s]
14645it [00:22, 618.91it/s]
14711it [00:23, 629.80it/s]
14777it [00:23, 637.13it/s]
14842it [00:23, 639.53it/s]
14907it [00:23, 633.76it/s]
14971it [00:23, 628.85it/s]
15037it [00:23, 636.12it/s]
15103it [00:23, 642.73it/s]
15169it [00:23, 647.81it/s]
15234it [00:23, 640.91it/s]
15300it [00:23, 643.95it/s]
15365it [00:24, 631.44it/s]
15430it [00:24, 636.73it/s]
15494it [00:24, 635.00it/s]
15559it [00:24, 639.27it/s]
15623it [00:24, 634.02it/s]
15689it [00:24, 640.46it/s]
15754it [00:24, 637.15it/s]
15820it [00:24, 642.66it/s]
15885it [00:24, 643.17it/s]
15950it [00:24, 636.00it/s]
16016it [00:25, 641.38it/s]
16082it [00:25, 643.96it/s]
16148it [00:25, 646.10it/s]
16214it [00:25, 648.73it/s]
16279it [00:25, 633.26it/s]
16345it [00:25, 639.48it/s]
16411it [00:25, 643.52it/s]
16478it [00:25, 648.52it/s]
16544it [00:25, 649.28it/s]
16609it [00:25, 644.95it/s]
16675it [00:26, 647.88it/s]
16742it [00:26, 651.65it/s]
16808it [00:26, 653.18it/s]
16875it [00:26, 654.99it/s]
16941it [00:26, 644.08it/s]
17007it [00:26, 647.18it/s]
17072it [00:26, 644.26it/s]
17138it [00:26, 646.61it/s]
17203it [00:26, 643.41it/s]
17268it [00:27, 630.78it/s]
17335it [00:27, 639.98it/s]
17402it [00:27, 646.08it/s]
17467it [00:27, 645.15it/s]
17533it [00:27, 649.25it/s]
17598it [00:27, 635.25it/s]
17662it [00:27, 634.33it/s]
17728it [00:27, 640.59it/s]
17793it [00:27, 622.55it/s]
17858it [00:27, 630.28it/s]
17922it [00:28, 625.77it/s]
17988it [00:28, 633.60it/s]
18053it [00:28, 636.20it/s]
18119it [00:28, 641.70it/s]
18185it [00:28, 644.50it/s]
18250it [00:28, 639.82it/s]
18315it [00:28, 642.51it/s]
18381it [00:28, 646.73it/s]
18447it [00:28, 650.08it/s]
18515it [00:28, 657.97it/s]
18581it [00:29, 649.60it/s]
18647it [00:29, 651.10it/s]
18713it [00:29, 650.47it/s]
18780it [00:29, 655.97it/s]
18846it [00:29, 649.24it/s]
18911it [00:29, 635.62it/s]
18977it [00:29, 640.61it/s]
19043it [00:29, 644.53it/s]
19109it [00:29, 648.14it/s]
19175it [00:29, 651.49it/s]
19241it [00:30, 640.53it/s]
19307it [00:30, 645.24it/s]
19372it [00:30, 604.31it/s]
19433it [00:30, 594.97it/s]
19498it [00:30, 608.56it/s]
19560it [00:30, 604.45it/s]
19625it [00:30, 616.65it/s]
19691it [00:30, 629.09it/s]
19755it [00:30, 615.84it/s]
19817it [00:31, 590.62it/s]
19877it [00:31, 586.99it/s]
19943it [00:31, 606.20it/s]
20009it [00:31, 619.78it/s]
20074it [00:31, 628.38it/s]
20137it [00:31, 624.54it/s]
20202it [00:31, 629.43it/s]
20268it [00:31, 638.18it/s]
20334it [00:31, 642.53it/s]
20399it [00:31, 643.96it/s]
20400it [00:31, 638.51it/s]
Accuracy: 0.02
Classifcation with incremental class adaption strategy¶
In [10]:
Copied!
dataset = datasets.Keystroke()
metric = metrics.Accuracy()
optimizer_fn = torch.optim.SGD
model_pipeline = preprocessing.StandardScaler()
model_pipeline |= RollingClassifier(
module=LstmModule,
loss_fn="binary_cross_entropy",
optimizer_fn=torch.optim.SGD,
window_size=20,
lr=1e-2,
append_predict=True,
is_class_incremental=True,
)
model_pipeline
dataset = datasets.Keystroke()
metric = metrics.Accuracy()
optimizer_fn = torch.optim.SGD
model_pipeline = preprocessing.StandardScaler()
model_pipeline |= RollingClassifier(
module=LstmModule,
loss_fn="binary_cross_entropy",
optimizer_fn=torch.optim.SGD,
window_size=20,
lr=1e-2,
append_predict=True,
is_class_incremental=True,
)
model_pipeline
Out[10]:
StandardScaler
StandardScaler (
with_std=True
)
RollingClassifier
RollingClassifier (
module=None
loss_fn="binary_cross_entropy"
optimizer_fn=<class 'torch.optim.sgd.SGD'>
lr=0.01
output_is_logit=True
is_class_incremental=True
is_feature_incremental=False
device="cpu"
seed=42
window_size=20
append_predict=True
)
In [11]:
Copied!
for x, y in tqdm(dataset):
y_pred = model_pipeline.predict_one(x) # make a prediction
metric.update(y, y_pred) # update the metric
model_pipeline.learn_one(x, y) # make the model learn
print(f"Accuracy: {metric.get()}:.2f")
for x, y in tqdm(dataset):
y_pred = model_pipeline.predict_one(x) # make a prediction
metric.update(y, y_pred) # update the metric
model_pipeline.learn_one(x, y) # make the model learn
print(f"Accuracy: {metric.get()}:.2f")
0it [00:00, ?it/s]
59it [00:00, 584.72it/s]
121it [00:00, 601.33it/s]
186it [00:00, 620.76it/s]
251it [00:00, 628.55it/s]
316it [00:00, 634.75it/s]
380it [00:00, 633.92it/s]
444it [00:00, 623.37it/s]
508it [00:00, 626.79it/s]
574it [00:00, 635.01it/s]
641it [00:01, 643.18it/s]
706it [00:01, 639.77it/s]
770it [00:01, 633.24it/s]
834it [00:01, 604.76it/s]
900it [00:01, 618.13it/s]
963it [00:01, 610.45it/s]
1025it [00:01, 608.91it/s]
1090it [00:01, 620.85it/s]
1155it [00:01, 628.87it/s]
1218it [00:01, 623.76it/s]
1281it [00:02, 607.23it/s]
1342it [00:02, 607.61it/s]
1403it [00:02, 595.57it/s]
1467it [00:02, 607.47it/s]
1533it [00:02, 620.64it/s]
1598it [00:02, 627.01it/s]
1661it [00:02, 607.92it/s]
1722it [00:02, 608.49it/s]
1786it [00:02, 616.48it/s]
1852it [00:02, 626.71it/s]
1917it [00:03, 630.84it/s]
1981it [00:03, 623.19it/s]
2044it [00:03, 616.52it/s]
2108it [00:03, 622.26it/s]
2173it [00:03, 629.11it/s]
2236it [00:03, 622.83it/s]
2300it [00:03, 626.47it/s]
2364it [00:03, 630.25it/s]
2428it [00:03, 619.36it/s]
2491it [00:04, 622.09it/s]
2556it [00:04, 627.96it/s]
2619it [00:04, 620.29it/s]
2682it [00:04, 617.89it/s]
2746it [00:04, 623.69it/s]
2809it [00:04, 622.43it/s]
2872it [00:04, 620.97it/s]
2936it [00:04, 625.28it/s]
2999it [00:04, 619.06it/s]
3064it [00:04, 625.58it/s]
3127it [00:05, 621.64it/s]
3191it [00:05, 624.11it/s]
3254it [00:05, 598.81it/s]
3317it [00:05, 607.62it/s]
3383it [00:05, 621.14it/s]
3448it [00:05, 626.34it/s]
3514it [00:05, 634.68it/s]
3578it [00:05, 635.30it/s]
3642it [00:05, 615.75it/s]
3708it [00:05, 627.01it/s]
3772it [00:06, 629.62it/s]
3838it [00:06, 633.87it/s]
3902it [00:06, 630.84it/s]
3968it [00:06, 636.72it/s]
4032it [00:06, 631.99it/s]
4096it [00:06, 631.09it/s]
4160it [00:06, 629.61it/s]
4223it [00:06, 614.77it/s]
4287it [00:06, 621.22it/s]
4353it [00:06, 629.80it/s]
4417it [00:07, 624.04it/s]
4482it [00:07, 631.07it/s]
4546it [00:07, 620.17it/s]
4609it [00:07, 622.34it/s]
4674it [00:07, 628.05it/s]
4738it [00:07, 629.50it/s]
4801it [00:07, 625.31it/s]
4864it [00:07, 613.88it/s]
4928it [00:07, 620.21it/s]
4991it [00:08, 613.44it/s]
5055it [00:08, 619.48it/s]
5119it [00:08, 624.37it/s]
5182it [00:08, 621.10it/s]
5245it [00:08, 612.28it/s]
5310it [00:08, 621.43it/s]
5373it [00:08, 616.89it/s]
5436it [00:08, 619.35it/s]
5498it [00:08, 616.33it/s]
5561it [00:08, 619.69it/s]
5624it [00:09, 621.31it/s]
5688it [00:09, 623.58it/s]
5751it [00:09, 624.27it/s]
5814it [00:09, 619.48it/s]
5877it [00:09, 620.59it/s]
5941it [00:09, 624.07it/s]
6004it [00:09, 613.50it/s]
6071it [00:09, 627.55it/s]
6136it [00:09, 632.04it/s]
6200it [00:09, 628.00it/s]
6266it [00:10, 636.07it/s]
6334it [00:10, 647.57it/s]
6401it [00:10, 650.06it/s]
6467it [00:10, 633.60it/s]
6531it [00:10, 629.86it/s]
6595it [00:10, 629.22it/s]
6658it [00:10, 622.69it/s]
6721it [00:10, 622.39it/s]
6784it [00:10, 618.41it/s]
6846it [00:10, 607.89it/s]
6909it [00:11, 612.24it/s]
6972it [00:11, 616.54it/s]
7035it [00:11, 619.15it/s]
7097it [00:11, 531.50it/s]
7157it [00:11, 549.24it/s]
7218it [00:11, 564.61it/s]
7283it [00:11, 586.15it/s]
7347it [00:11, 600.29it/s]
7411it [00:11, 609.59it/s]
7473it [00:12, 587.69it/s]
7537it [00:12, 601.53it/s]
7601it [00:12, 610.71it/s]
7664it [00:12, 613.73it/s]
7727it [00:12, 618.37it/s]
7790it [00:12, 607.52it/s]
7852it [00:12, 609.89it/s]
7916it [00:12, 616.31it/s]
7978it [00:12, 614.89it/s]
8040it [00:12, 605.38it/s]
8101it [00:13, 597.94it/s]
8163it [00:13, 603.48it/s]
8226it [00:13, 609.09it/s]
8289it [00:13, 613.20it/s]
8351it [00:13, 614.26it/s]
8413it [00:13, 601.32it/s]
8474it [00:13, 602.81it/s]
8538it [00:13, 611.27it/s]
8602it [00:13, 618.49it/s]
8665it [00:14, 619.01it/s]
8727it [00:14, 610.53it/s]
8789it [00:14, 611.46it/s]
8851it [00:14, 605.41it/s]
8912it [00:14, 606.45it/s]
8973it [00:14, 600.05it/s]
9034it [00:14, 581.68it/s]
9093it [00:14, 564.73it/s]
9151it [00:14, 567.67it/s]
9211it [00:14, 575.91it/s]
9270it [00:15, 578.51it/s]
9328it [00:15, 571.28it/s]
9389it [00:15, 581.24it/s]
9449it [00:15, 585.73it/s]
9511it [00:15, 593.46it/s]
9574it [00:15, 602.57it/s]
9635it [00:15, 588.20it/s]
9697it [00:15, 595.53it/s]
9757it [00:15, 580.60it/s]
9820it [00:15, 593.72it/s]
9881it [00:16, 598.08it/s]
9944it [00:16, 604.59it/s]
10005it [00:16, 606.15it/s]
10066it [00:16, 606.92it/s]
10128it [00:16, 610.43it/s]
10190it [00:16, 611.85it/s]
10252it [00:16, 599.99it/s]
10314it [00:16, 604.06it/s]
10376it [00:16, 606.84it/s]
10437it [00:17, 606.98it/s]
10498it [00:17, 606.80it/s]
10559it [00:17, 596.14it/s]
10620it [00:17, 597.81it/s]
10681it [00:17, 600.96it/s]
10743it [00:17, 604.72it/s]
10804it [00:17, 595.18it/s]
10864it [00:17, 578.92it/s]
10925it [00:17, 586.32it/s]
10986it [00:17, 593.17it/s]
11049it [00:18, 603.14it/s]
11110it [00:18, 603.31it/s]
11171it [00:18, 603.04it/s]
11232it [00:18, 598.75it/s]
11293it [00:18, 599.45it/s]
11353it [00:18, 599.01it/s]
11413it [00:18, 598.61it/s]
11473it [00:18, 587.40it/s]
11534it [00:18, 591.87it/s]
11596it [00:18, 597.75it/s]
11656it [00:19, 594.35it/s]
11717it [00:19, 596.50it/s]
11777it [00:19, 583.94it/s]
11838it [00:19, 589.78it/s]
11898it [00:19, 592.21it/s]
11958it [00:19, 593.83it/s]
12018it [00:19, 586.20it/s]
12077it [00:19, 561.19it/s]
12138it [00:19, 573.49it/s]
12199it [00:19, 581.63it/s]
12260it [00:20, 588.00it/s]
12321it [00:20, 591.56it/s]
12381it [00:20, 583.44it/s]
12442it [00:20, 589.37it/s]
12506it [00:20, 602.67it/s]
12567it [00:20, 585.71it/s]
12626it [00:20, 582.78it/s]
12685it [00:20, 577.88it/s]
12746it [00:20, 584.67it/s]
12806it [00:21, 588.52it/s]
12866it [00:21, 591.32it/s]
12926it [00:21, 589.92it/s]
12986it [00:21, 551.15it/s]
13042it [00:21, 550.36it/s]
13098it [00:21, 544.95it/s]
13153it [00:21, 466.61it/s]
13202it [00:21, 428.47it/s]
13248it [00:21, 434.95it/s]
13293it [00:22, 412.42it/s]
13336it [00:22, 334.84it/s]
13373it [00:22, 295.12it/s]
13405it [00:22, 293.18it/s]
13444it [00:22, 315.14it/s]
13491it [00:22, 352.03it/s]
13537it [00:22, 378.82it/s]
13590it [00:22, 419.65it/s]
13641it [00:23, 444.07it/s]
13692it [00:23, 462.81it/s]
13747it [00:23, 487.97it/s]
13802it [00:23, 504.35it/s]
13859it [00:23, 521.27it/s]
13916it [00:23, 535.22it/s]
13972it [00:23, 541.84it/s]
14027it [00:23, 524.32it/s]
14081it [00:23, 527.63it/s]
14134it [00:23, 520.60it/s]
14187it [00:24, 508.65it/s]
14242it [00:24, 520.56it/s]
14295it [00:24, 446.88it/s]
14342it [00:24, 439.01it/s]
14388it [00:24, 435.00it/s]
14433it [00:24, 385.04it/s]
14473it [00:24, 379.27it/s]
14515it [00:24, 389.40it/s]
14561it [00:25, 405.22it/s]
14603it [00:25, 408.77it/s]
14647it [00:25, 416.28it/s]
14692it [00:25, 423.50it/s]
14737it [00:25, 428.69it/s]
14783it [00:25, 435.78it/s]
14830it [00:25, 443.53it/s]
14880it [00:25, 458.08it/s]
14926it [00:25, 435.75it/s]
14970it [00:25, 421.20it/s]
15018it [00:26, 436.63it/s]
15062it [00:26, 428.30it/s]
15107it [00:26, 432.54it/s]
15154it [00:26, 443.21it/s]
15200it [00:26, 447.70it/s]
15245it [00:26, 427.44it/s]
15288it [00:26, 425.83it/s]
15340it [00:26, 452.64it/s]
15393it [00:26, 475.17it/s]
15447it [00:27, 491.99it/s]
15500it [00:27, 502.16it/s]
15551it [00:27, 503.19it/s]
15602it [00:27, 494.41it/s]
15657it [00:27, 508.16it/s]
15712it [00:27, 519.29it/s]
15767it [00:27, 526.09it/s]
15824it [00:27, 536.72it/s]
15880it [00:27, 542.30it/s]
15939it [00:27, 556.03it/s]
15998it [00:28, 564.05it/s]
16055it [00:28, 554.19it/s]
16111it [00:28, 544.74it/s]
16166it [00:28, 539.15it/s]
16221it [00:28, 541.73it/s]
16276it [00:28, 538.44it/s]
16330it [00:28, 531.76it/s]
16386it [00:28, 539.61it/s]
16440it [00:28, 521.77it/s]
16493it [00:28, 517.38it/s]
16547it [00:29, 523.89it/s]
16604it [00:29, 537.22it/s]
16663it [00:29, 552.56it/s]
16722it [00:29, 562.78it/s]
16779it [00:29, 564.64it/s]
16836it [00:29, 561.79it/s]
16893it [00:29, 563.34it/s]
16951it [00:29, 567.06it/s]
17008it [00:29, 567.20it/s]
17066it [00:29, 568.88it/s]
17126it [00:30, 575.51it/s]
17185it [00:30, 578.49it/s]
17243it [00:30, 574.29it/s]
17301it [00:30, 574.95it/s]
17360it [00:30, 579.11it/s]
17418it [00:30, 576.67it/s]
17476it [00:30, 575.79it/s]
17535it [00:30, 578.80it/s]
17593it [00:30, 578.71it/s]
17651it [00:30, 556.03it/s]
17707it [00:31, 555.43it/s]
17764it [00:31, 557.24it/s]
17821it [00:31, 559.40it/s]
17878it [00:31, 561.44it/s]
17935it [00:31, 558.65it/s]
17991it [00:31, 558.36it/s]
18047it [00:31, 555.84it/s]
18103it [00:31, 554.65it/s]
18159it [00:31, 549.03it/s]
18215it [00:32, 550.14it/s]
18271it [00:32, 543.49it/s]
18327it [00:32, 547.70it/s]
18383it [00:32, 549.41it/s]
18438it [00:32, 545.65it/s]
18495it [00:32, 550.02it/s]
18551it [00:32, 551.59it/s]
18607it [00:32, 552.98it/s]
18663it [00:32, 552.56it/s]
18719it [00:32, 516.92it/s]
18772it [00:33, 514.85it/s]
18828it [00:33, 527.59it/s]
18882it [00:33, 488.70it/s]
18937it [00:33, 505.35it/s]
18992it [00:33, 517.65it/s]
19046it [00:33, 521.57it/s]
19103it [00:33, 534.81it/s]
19162it [00:33, 549.69it/s]
19218it [00:33, 541.95it/s]
19276it [00:33, 551.31it/s]
19333it [00:34, 555.77it/s]
19389it [00:34, 551.28it/s]
19445it [00:34, 552.66it/s]
19504it [00:34, 560.85it/s]
19561it [00:34, 514.07it/s]
19614it [00:34, 504.87it/s]
19666it [00:34, 506.20it/s]
19718it [00:34, 503.13it/s]
19769it [00:34, 489.85it/s]
19819it [00:35, 477.26it/s]
19867it [00:35, 450.50it/s]
19913it [00:35, 439.33it/s]
19961it [00:35, 450.18it/s]
20017it [00:35, 479.87it/s]
20073it [00:35, 501.83it/s]
20130it [00:35, 519.89it/s]
20186it [00:35, 528.45it/s]
20240it [00:35, 481.21it/s]
20290it [00:36, 472.13it/s]
20342it [00:36, 482.98it/s]
20394it [00:36, 492.93it/s]
20400it [00:36, 562.37it/s]
Accuracy: 0.05965686274509804:.2f