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 sklearn.model_selection import train_test_split | |
def feature_label_split(df, target_col): | |
y = df[[target_col]] | |
X = df.drop(columns=[target_col]) | |
return X, y | |
def train_val_test_split(df, target_col, test_ratio): | |
val_ratio = test_ratio / (1 - test_ratio) | |
X, y = feature_label_split(df, target_col) |
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 generate_time_lags(df, n_lags): | |
df_n = df.copy() | |
for n in range(1, n_lags + 1): | |
df_n[f"lag{n}"] = df_n["value"].shift(n) | |
df_n = df_n.iloc[n_lags:] | |
return df_n | |
input_dim = 100 | |
df_generated = generate_time_lags(df, input_dim) |
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 | |
df = pd.read_csv('<YOUR_FILE_DIR>/PJME_hourly.csv') | |
df = df.set_index(['Datetime']) | |
df.index = pd.to_datetime(df.index) | |
if not df.index.is_monotonic: | |
df = df.sort_index() | |
df = df.rename(columns={'PJME_MW': 'value'}) |
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 plotly.graph_objs as go | |
from plotly.offline import iplot | |
def plot_dataset(df, title): | |
data = [] | |
value = go.Scatter( | |
x=df.index, | |
y=df.value, | |
mode="lines", | |
name="values", |
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
#========================================================================# | |
# file_collector.py # | |
#========================================================================# | |
#========================================================================# | |
# usage: file_collector.py [-h] [-f FILE] [-o OUTPUT_FOLDER] # | |
#========================================================================# | |
# optional arguments: | |
# -h, --help show this help message and exit | |
# -f FILE, --file FILE the xlsx file that contains all the files to be | |
# collected |
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
#=======================================================================# | |
# extract_data.py # | |
#=======================================================================# | |
# usage: extract_data.py [-h] [-i INPUT_DIR] [-o OUTPUT_DIR] | |
# | |
# This program extracts provision numbers from a set of documents. | |
# | |
# optional arguments: | |
# -h, --help show this help message and exit | |
# -i INPUT_DIR, --input_dir INPUT_DIR |
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
#=======================================================================# | |
# pdf_utils.py # | |
#=======================================================================# | |
# usage: pdf_utils.py [-h] [-i INPUT_DIR] [-o OUTPUT_DIR] [-m METHOD] | |
# | |
# This program contains some utility functions for pdf files. | |
# | |
# optional arguments: | |
# -h, --help show this help message and exit | |
# -i INPUT_DIR, --input_dir INPUT_DIR |
NewerOlder