Skip to content
This repository was archived by the owner on Nov 23, 2023. It is now read-only.

modified model and api path #32

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# Load our model into memory.
# Please update this path to reflect your own trained model.
static_model = load_model(
path_to_model='assets/trained-models/load_shortfall_simple_lm_regression.pkl')
path_to_model='assets/trained-models/model_RF.pkl')

print ('-'*40)
print ('Model successfully loaded')
Expand Down
Binary file added assets/trained-models/model_RF.pkl
Binary file not shown.
60 changes: 59 additions & 1 deletion model.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,67 @@ def _preprocess_data(data):
# receive marks for submitting this code in an unchanged state.
# ---------------------------------------------------------------

# ----------- Replace this code with your own preprocessing steps --------
feature_vector_df['time'] = pd.to_datetime(feature_vector_df['time'])
feature_vector_df['Year'] = feature_vector_df['time'].dt.year
feature_vector_df['Month'] = feature_vector_df['time'].dt.month
feature_vector_df['Day'] = feature_vector_df['time'].dt.day
feature_vector_df['Hour'] = feature_vector_df['time'].dt.hour

cat_features_test = feature_vector_df[list(feature_vector_df.select_dtypes(include=['object']).columns)]


############# creating features based on data type
features_test = feature_vector_df.select_dtypes(include=['float64', 'int64']).columns

id_features_test = [var for var in features_test if var[-2:] == 'id']

#Droping columns
feature_vector_df = feature_vector_df.drop(columns='Unnamed: 0')
feature_vector_df = feature_vector_df.drop(columns=id_features_test)


valencia_wind_test = []
for i in feature_vector_df['Valencia_wind_deg']:
value = i.split('_')[-1:]
valencia_wind_test = valencia_wind_test + value
valencia_wind_test = list(map(int, valencia_wind_test))

wind_deg_test = pd.DataFrame({'Level': valencia_wind_test})

seville_pressure_test = []
for i in feature_vector_df['Seville_pressure']:
value = i.split('p')[-1:]
seville_pressure_test = seville_pressure_test + value
seville_pressure_test = list(map(int, seville_pressure_test))

pressure_df_test = pd.DataFrame({'SP (Static Pressure)': seville_pressure_test})

feature_vector_df['Valencia_wind_deg'] = wind_deg_test
feature_vector_df['Seville_pressure'] = pressure_df_test
feature_vector_df['Valencia_pressure'].fillna(1013.148351, inplace=True) #Manually added mean #Manually added mean

predict_vector = feature_vector_df[['Madrid_wind_speed', 'Valencia_wind_deg', 'Bilbao_rain_1h',
'Valencia_wind_speed', 'Seville_humidity', 'Madrid_humidity',
'Bilbao_clouds_all', 'Bilbao_wind_speed', 'Seville_clouds_all',
'Bilbao_wind_deg', 'Barcelona_wind_speed', 'Barcelona_wind_deg',
'Madrid_clouds_all', 'Seville_wind_speed', 'Barcelona_rain_1h',
'Seville_pressure', 'Seville_rain_1h', 'Bilbao_snow_3h',
'Barcelona_pressure', 'Seville_rain_3h', 'Madrid_rain_1h',
'Barcelona_rain_3h', 'Valencia_snow_3h', 'Bilbao_pressure',
'Valencia_pressure', 'Seville_temp_max', 'Madrid_pressure',
'Valencia_temp_max', 'Valencia_temp', 'Seville_temp',
'Valencia_humidity', 'Valencia_temp_min', 'Barcelona_temp_max',
'Madrid_temp_max', 'Barcelona_temp', 'Bilbao_temp_min', 'Bilbao_temp',
'Barcelona_temp_min', 'Bilbao_temp_max', 'Seville_temp_min',
'Madrid_temp', 'Madrid_temp_min', 'Year', 'Month', 'Day', 'Hour']]


# ----------- Replace this code with your own preprocessing steps --------
predict_vector = feature_vector_df[['Madrid_wind_speed','Bilbao_rain_1h','Valencia_wind_speed']]
#predict_vector = feature_vector_df[['Madrid_wind_speed','Bilbao_rain_1h','Valencia_wind_speed']]
# ------------------------------------------------------------------------



return predict_vector

Expand Down
2 changes: 1 addition & 1 deletion utils/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
# replace the URL below with its public IP:

# url = 'http://{public-ip-address-of-remote-machine}:5000/api_v0.1'
url = 'http://127.0.0.1:5000/api_v0.1'
url = 'http://52.49.203.132:5000/api_v0.1'

# Perform the POST request.
print(f"Sending POST request to web server API at: {url}")
Expand Down