Skip to content

Commit

Permalink
Merge branch 'master' of github.com:rpmcruz/machine-learning
Browse files Browse the repository at this point in the history
  • Loading branch information
rpmcruz committed Feb 17, 2017
2 parents 55b4848 + 5d0e0d1 commit 00090be
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions timeseries/delay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# introduce delay in the target variable

import numpy as np

def shift(y, delay):
X = np.asarray([np.roll(y, d) for d in range(1, delay+1)]).T
X = X[delay:]
y = y[delay:]
t = np.arange(delay, len(y)+delay, dtype=int)
return t, X, y
12 changes: 12 additions & 0 deletions timeseries/growing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import numpy as np

class GrowingWindow:
def __init__(self, n_splits=3, test_size=1):
self.n_splits = n_splits
self.test_size = test_size

def split(self, X, y=None):
train_size = len(X)-self.test_size
train_blocks = np.linspace(0, train_size, self.n_splits+1, dtype=int)
for j in train_blocks[1:]:
yield np.arange(0, j), np.arange(j, j+self.test_size)
14 changes: 14 additions & 0 deletions timeseries/sliding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import numpy as np

class SlidingWindow:
def __init__(self, n_splits=3, test_size=1):
self.n_splits = n_splits
self.test_size = test_size

def split(self, X, y=None):
train_size = len(X)-self.test_size
train_blocks = np.linspace(0, train_size, self.n_splits+1, dtype=int)
train_i = train_blocks[:-1]
train_j = train_blocks[1:]
for i, j in zip(train_blocks[:-1], train_blocks[1:]):
yield np.arange(i, j), np.arange(j, j+self.test_size)

0 comments on commit 00090be

Please sign in to comment.