Created
December 6, 2021 02:37
-
-
Save maheshs11/f6272d710da1217c8ee61d05e6bca157 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
window_length = 5 | |
stride = None | |
horizon=1 | |
df = pd.read_csv("trainbins.csv") | |
print(df) | |
X, y = SlidingWindow(window_length, stride=stride, horizon=horizon)(df) | |
X = X.astype('float') | |
splits = get_splits(y, valid_size=.2, stratify=True, random_state=23, shuffle=False) | |
print(splits) | |
tfms = [None, [Categorize()]] | |
dsets = TSDatasets(X, y, tfms=tfms, splits=splits) | |
dls = TSDataLoaders.from_dsets(dsets.train, dsets.valid, bs=50) | |
model = TST(dls.vars, dls.c, dls.len, fc_dropout=0.9) | |
learn = Learner(dls, model, loss_func=CrossEntropyLossFlat(), | |
metrics=[accuracy], cbs=ShowGraphCallback2()) | |
learn.fit_one_cycle(250, 1e-4) | |
learn.export("models/clf.pkl") # make sure you set the path to a folder that already exists | |
from tsai.inference import load_learner | |
learn = load_learner("models/clf.pkl") | |
probas, target, preds = learn.get_X_preds(X[splits[0]], y[splits[0]]) | |
probas, target, preds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment