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
# Loading pandas | |
import pandas as pd | |
# Loading date wrangling package | |
from datetime import datetime | |
# Reading the input data | |
d = pd.read_csv('input/DAYTON_hourly.csv') | |
# Formating to datetime |
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 numpy as np | |
def create_X_Y(ts: list, lag: int) -> tuple: | |
""" | |
A method to create X and Y matrix from a time series list for the training of | |
deep learning models | |
""" | |
X, Y = [], [] | |
if len(ts) - lag <= 0: |
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
# Deep learning packages | |
from keras.models import Sequential | |
from keras.layers import LSTM, Dense | |
# Defining the number of neurons in the LSTM layer | |
n_layer = 50 | |
# Defining how many lags will be used in the time series | |
n_lag = 3 |
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
# Data wrangling | |
import pandas as pd | |
import numpy as np | |
# Deep learning: | |
from keras.models import Sequential | |
from keras.layers import LSTM, Dense | |
class DeepModelTS(): |
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 re | |
def clean_text( | |
string: str, | |
punctuations=r'''!()-[]{};:'"\,<>./?@#$%^&*_~''', | |
stop_words=['the', 'a', 'and', 'is', 'be', 'will']) -> str: | |
""" | |
A method to clean text | |
""" | |
# Cleaning the urls |
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
# Defining the window for context | |
window = 2 | |
# Creating a placeholder for the scanning of the word list | |
word_lists = [] | |
all_text = [] | |
for text in texts: | |
# Cleaning the text |
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
def create_unique_word_dict(text:list) -> dict: | |
""" | |
A method that creates a dictionary where the keys are unique words | |
and key values are indices | |
""" | |
# Getting all the unique words from our text and sorting them alphabetically | |
words = list(set(text)) | |
words.sort() | |
# Creating the dictionary for the unique words |
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
from scipy import sparse | |
import numpy as np | |
# Defining the number of features (unique words) | |
n_words = len(unique_word_dict) | |
# Getting all the unique words | |
words = list(unique_word_dict.keys()) | |
# Creating the X and Y matrices using one hot encoding |
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
# Deep learning: | |
from keras.models import Input, Model | |
from keras.layers import Dense | |
# Defining the size of the embedding | |
embed_size = 2 | |
# Defining the neural network | |
inp = Input(shape=(X.shape[1],)) | |
x = Dense(units=embed_size, activation='linear')(inp) |
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
# Deep learning: | |
from keras.models import Input, Model | |
from keras.layers import Dense | |
# Defining the size of the embedding | |
embed_size = 2 | |
# Defining the neural network | |
inp = Input(shape=(X.shape[1],)) | |
x = Dense(units=embed_size, activation='linear')(inp) |
OlderNewer