Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-perseus committed Dec 2, 2023
1 parent 1674917 commit dd1b650
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 31 deletions.
1 change: 0 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import urllib.request
from flask import Flask, jsonify, request
from flask_cors import CORS
Expand Down
12 changes: 3 additions & 9 deletions data/preprocessing/preprocess_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@


class PreprocessFeatures:
# def __init__(self, df, labels_df):
def __init__(self, df):
self.df = df
# self.labels_df = labels_df

def get_features_for_model(self):
self.append_time_features()
# self.get_lagged_features()

pd.set_option('display.max_columns', None)
print(self.df.head())

return self.df[feature_columns], len(feature_columns)

def append_time_features(self):
Expand Down Expand Up @@ -53,7 +48,6 @@ def append_time_features(self):
self.df['sin_month'] = np.sin(2 * np.pi * self.df['month'] / month_in_year)
self.df['cos_month'] = np.cos(2 * np.pi * self.df['month'] / month_in_year)

def get_lagged_features(self, period=24):
for label in parking_data_labels:
pass
# self.df[label + '_lagged_' + str(period)] = self.labels_df[label].shift(periods=period)
# def get_lagged_features(self, period=24):
# for label in parking_data_labels:
# self.df[label + '_lagged_' + str(period)] = self.labels_df[label].shift(periods=period)
30 changes: 15 additions & 15 deletions data/preprocessing/single_prediction_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ def get_weather_forecast(self, timestamp):
daily_dataframe = pd.DataFrame(data=daily_data)
return daily_dataframe

def get_parking_data_df(self):
df_parking_data = pd.read_csv("temp-for-lagged.csv", sep=";")
df_parking_data["datetime"] = pd.to_datetime(df_parking_data["datetime"], format='%d.%m.%Y %H:%M')

df_parking_data.set_index("datetime", inplace=True)

# df = pd.merge(df, df_parking_data, on="datetime", how="outer")

print("df_parking_data")
print(df_parking_data.head())

return df_parking_data
# def get_parking_data_df(self):
# df_parking_data = pd.read_csv("temp-for-lagged.csv", sep=";")
# df_parking_data["datetime"] = pd.to_datetime(df_parking_data["datetime"], format='%d.%m.%Y %H:%M')
#
# df_parking_data.set_index("datetime", inplace=True)
#
# # df = pd.merge(df, df_parking_data, on="datetime", how="outer")
#
# print("df_parking_data")
# print(df_parking_data.head())
#
# return df_parking_data

def build_dataframe(self, input_date):
timestamp = datetime.strptime(input_date, '%Y-%m-%d %H:%M')
Expand All @@ -72,7 +72,7 @@ def build_dataframe(self, input_date):
# Merge Weather with other Features
df = pd.merge(df_weather, self.calendar_features, on="date", how="left")
df["datetime"] = timestamp
#df["datetime"] = pd.to_datetime(timestamp, format='%d.%m.%Y %H:%M')
# df["datetime"] = pd.to_datetime(timestamp, format='%d.%m.%Y %H:%M')

# parking_df = self.get_parking_data_df()

Expand All @@ -84,8 +84,8 @@ def build_dataframe(self, input_date):
date_today = date.today()
date_tomorrow = date_today + timedelta(days=1)
single_prediction_features = SinglePredictionFeatures("raw_features_2024.csv")
print(date_tomorrow.strftime("%Y-%m-%d %H:%M"))
print(date_today.strftime("%Y-%m-%d %H:%M"))
# print(date_tomorrow.strftime("%Y-%m-%d %H:%M"))
# print(date_today.strftime("%Y-%m-%d %H:%M"))
df_demo, features_length = single_prediction_features.build_dataframe(date_tomorrow.strftime("%Y-%m-%d %H:%M"))
print(df_demo.head())
print(df_demo.columns)
Expand Down
2 changes: 0 additions & 2 deletions data/preprocessing/temp-for-lagged.csv

This file was deleted.

5 changes: 3 additions & 2 deletions model/W&B_PPSG_LSTM.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"outputs": [],
"source": [
"# See also https://towardsdatascience.com/choosing-the-right-hyperparameters-for-a-simple-lstm-using-keras-f8e9ed76f046\n",
"# Runs are here: https://wandb.ai/parcaster/pp-sg-lstm\n",
"\n",
"sweep_config = {\n",
" 'method': 'bayes',\n",
Expand All @@ -97,7 +98,7 @@
" },\n",
" 'parameters': {\n",
" 'model': {\n",
" 'values': ['lstm', 'rnn']\n",
" 'value': 'lstm'\n",
" },\n",
" 'scaler': {\n",
" 'values': ['standard', 'minmax', 'robust', 'maxabs']\n",
Expand Down Expand Up @@ -515,7 +516,7 @@
},
"outputs": [],
"source": [
"wandb.agent(sweep_id, train, count=1)"
"wandb.agent(sweep_id, train, count=20)"
]
},
{
Expand Down
2 changes: 0 additions & 2 deletions model/scaler.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import joblib
from sklearn.preprocessing import StandardScaler


class Scaler:
def __init__(self, scaler):
# self.scaler = StandardScaler()
self.scaler = scaler

def scale(self, X_train, X_val, X_test, y_train, y_val, y_test):
Expand Down

0 comments on commit dd1b650

Please sign in to comment.