-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_answers.py
52 lines (39 loc) · 1.69 KB
/
my_answers.py
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
43
44
45
46
47
48
49
50
51
52
import numpy as np
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
import keras
# TODO: fill out the function below that transforms the input series
# and window-size into a set of input/output pairs for use with our RNN model
def window_transform_series(series,window_size):
# containers for input/output pairs
X = [series[i:i+window_size] for i in range(len(series) - window_size)]
y = series[window_size:]
# reshape each
X = np.asarray(X)
X.shape = (np.shape(X)[0:2])
y = np.asarray(y)
y.shape = (len(y),1)
return X,y
# TODO: build an RNN to perform regression on our time series input/output data
def build_part1_RNN(step_size, window_size):
model = Sequential()
model.add(Dense(128, activation='softmax', input_shape = (7,1)))
model.add(LSTM(128))
model.add(Dropout(0.5))
model.add(Dense(1, activation='softmax'))
model.summary()
### TODO: list all unique characters in the text and remove any non-english ones
def clean_text(text):
# find all unique characters in the text
for punc in string.punctuation:
if punc == ',' or punc == '.':
continue
text = text.replace(punc, ' ')
# remove as many non-english characters and character sequences as you can
### TODO: fill out the function below that transforms the input text and window-size into a set of input/output pairs for use with our RNN model
def window_transform_text(text,window_size,step_size):
# containers for input/output pairs
inputs = [text[i:i+window_size] for i in range(len(text) - window_size)[::step_size]]
outputs = text[window_size::step_size]
return inputs,outputs