From 4562685cc71be17ea2d3b25eef1fdb20366ad70e Mon Sep 17 00:00:00 2001 From: Bronwyn Krige Date: Tue, 15 Nov 2022 22:23:53 +0200 Subject: [PATCH 1/8] updated port to 5001 --- api.py | 2 +- assets/trained-models/mlr_model.pkl | Bin 0 -> 65 bytes utils/request.py | 4 ++-- 3 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 assets/trained-models/mlr_model.pkl diff --git a/api.py b/api.py index f822fbe2..9554c151 100644 --- a/api.py +++ b/api.py @@ -62,4 +62,4 @@ def model_prediction(): # This will allow Flask to automatically restart itself everytime you # update your API code. if __name__ == '__main__': - app.run(host='0.0.0.0', port=5000, debug=False) + app.run(host='0.0.0.0', port=5001, debug=False) diff --git a/assets/trained-models/mlr_model.pkl b/assets/trained-models/mlr_model.pkl new file mode 100644 index 0000000000000000000000000000000000000000..57271d0ecac1225ee7881fd33213ede6c268bad2 GIT binary patch literal 65 zcmZo*nQF!W0X-7M**U3+MR|IudBv%@Nja%{@oD)*sl_EzdPIW~^HTD2-N4+S)O4U| LaemR1$y4+IoRt?V literal 0 HcmV?d00001 diff --git a/utils/request.py b/utils/request.py index 99ab68da..a52e5a35 100644 --- a/utils/request.py +++ b/utils/request.py @@ -37,8 +37,8 @@ # 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://127.0.0.1:5000/api_v0.1' +url = 'http://172.31.34.86:5000' # Perform the POST request. print(f"Sending POST request to web server API at: {url}") print("") From 0d44d0528ca8bb6ed3c3111eeed2d76dc8b6c252 Mon Sep 17 00:00:00 2001 From: Bronwyn Krige Date: Tue, 15 Nov 2022 22:49:47 +0200 Subject: [PATCH 2/8] changed port back to 5000 --- api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api.py b/api.py index 9554c151..f822fbe2 100644 --- a/api.py +++ b/api.py @@ -62,4 +62,4 @@ def model_prediction(): # This will allow Flask to automatically restart itself everytime you # update your API code. if __name__ == '__main__': - app.run(host='0.0.0.0', port=5001, debug=False) + app.run(host='0.0.0.0', port=5000, debug=False) From 5e9e48514f4e160ac52a2f26fb23fc49fa7d4d43 Mon Sep 17 00:00:00 2001 From: Bronwyn Krige Date: Tue, 15 Nov 2022 22:59:21 +0200 Subject: [PATCH 3/8] updated url --- utils/request.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/request.py b/utils/request.py index a52e5a35..c7d505de 100644 --- a/utils/request.py +++ b/utils/request.py @@ -38,7 +38,7 @@ # url = 'http://{public-ip-address-of-remote-machine}:5000/api_v0.1' # url = 'http://127.0.0.1:5000/api_v0.1' -url = 'http://172.31.34.86:5000' +url = 'http://172.31.34.86:5000/api_v0.1' # Perform the POST request. print(f"Sending POST request to web server API at: {url}") print("") From d7527c52a10005416188ace2a2ca1d2eb93411b8 Mon Sep 17 00:00:00 2001 From: Bronwyn Krige Date: Tue, 15 Nov 2022 23:40:55 +0200 Subject: [PATCH 4/8] changed to ec2 url --- utils/request.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/request.py b/utils/request.py index c7d505de..853039f4 100644 --- a/utils/request.py +++ b/utils/request.py @@ -37,8 +37,8 @@ # 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://172.31.34.86:5000/api_v0.1' +url = 'http://127.0.0.1:5000/api_v0.1' +# url = 'http://54.229.191.145:5000/api_v0.1' # Perform the POST request. print(f"Sending POST request to web server API at: {url}") print("") From 6d7b82d529237cc10632188fb25b7b13ba9d3c79 Mon Sep 17 00:00:00 2001 From: Bronwynkrige <112427529+Bronwynkrige@users.noreply.github.com> Date: Fri, 18 Nov 2022 02:22:35 +0200 Subject: [PATCH 5/8] Update api.py Updated the path to reference our trined model --- api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api.py b/api.py index f822fbe2..0c14df38 100644 --- a/api.py +++ b/api.py @@ -30,7 +30,8 @@ # 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/load_shortfall_simple_lm_regression.pkl') + path_to_model='assets/trained-models/mlr_model.pkl') print ('-'*40) print ('Model successfully loaded') From 94c952adc1958416d168cf2d2ea8b237112942f0 Mon Sep 17 00:00:00 2001 From: Bronwynkrige <112427529+Bronwynkrige@users.noreply.github.com> Date: Fri, 18 Nov 2022 02:25:49 +0200 Subject: [PATCH 6/8] Update model.py implemented the preprocessing to work with our model --- model.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 10 deletions(-) diff --git a/model.py b/model.py index 42f73063..1668bf9f 100644 --- a/model.py +++ b/model.py @@ -26,6 +26,7 @@ import pandas as pd import pickle import json +from datetime import datetime, timedelta def _preprocess_data(data): """Private helper function to preprocess data for model prediction. @@ -49,16 +50,52 @@ def _preprocess_data(data): # Load the dictionary as a Pandas DataFrame. feature_vector_df = pd.DataFrame.from_dict([feature_vector_dict]) - # --------------------------------------------------------------- - # NOTE: You will need to swap the lines below for your own data - # preprocessing methods. - # - # The code below is for demonstration purposes only. You will not - # receive marks for submitting this code in an unchanged state. - # --------------------------------------------------------------- - - # ----------- Replace this code with your own preprocessing steps -------- - predict_vector = feature_vector_df[['Madrid_wind_speed','Bilbao_rain_1h','Valencia_wind_speed']] + feature_vector_df['time'] = pd.to_datetime(feature_vector_df['time']) + + # day + feature_vector_df['day'] = feature_vector_df['time'].dt.day + # month + feature_vector_df['month'] = feature_vector_df['time'].dt.month + # year + feature_vector_df['year'] = feature_vector_df['time'].dt.year + # hour + feature_vector_df['hour'] = feature_vector_df['time'].dt.hour + # minute + feature_vector_df['minute'] = feature_vector_df['time'].dt.minute + # second + feature_vector_df['second'] = feature_vector_df['time'].dt.second + + + + feature_vector_df = feature_vector_df.loc[:, ['time','day', 'month', 'year', 'hour', 'minute', + 'second', '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', 'Madrid_weather_id', + 'Barcelona_weather_id', 'Bilbao_pressure', 'Seville_weather_id', + 'Valencia_pressure', 'Seville_temp_max', 'Madrid_pressure', + 'Valencia_temp_max', 'Valencia_temp', 'Bilbao_weather_id', + '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']] + # # ,'load_shortfall_3h']] + + feature_vector_df= feature_vector_df.drop(['time'], axis = 1) + feature_vector_df['Valencia_wind_deg'] = feature_vector_df['Valencia_wind_deg'].str.extract('(\d+)') + feature_vector_df['Valencia_wind_deg'] = pd.to_numeric(feature_vector_df['Valencia_wind_deg']) + + feature_vector_df['Seville_pressure'] = feature_vector_df['Seville_pressure'].str.extract('(\d+)') + feature_vector_df['Seville_pressure'] = pd.to_numeric(feature_vector_df['Seville_pressure']) + + feature_vector_df['Valencia_pressure'] = feature_vector_df['Valencia_pressure'].fillna(1015.0) + # # ----------- Replace this code with your own preprocessing steps -------- + predict_vector = feature_vector_df.copy() + # predict_vector = feature_vector_df[['Madrid_wind_speed','Bilbao_rain_1h','Valencia_wind_speed']] # ------------------------------------------------------------------------ return predict_vector @@ -104,7 +141,13 @@ def make_prediction(data, model): """ # Data preprocessing. prep_data = _preprocess_data(data) + + # Perform prediction with model and preprocessed data. prediction = model.predict(prep_data) + + print(prediction) + + # Format as list for output standardisation. return prediction[0].tolist() From 55f077b715a9faeb0e852b5b9bc658840f98532e Mon Sep 17 00:00:00 2001 From: Bronwynkrige <112427529+Bronwynkrige@users.noreply.github.com> Date: Fri, 18 Nov 2022 02:35:31 +0200 Subject: [PATCH 7/8] Delete mlr_model.pkl updated --- assets/trained-models/mlr_model.pkl | Bin 65 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 assets/trained-models/mlr_model.pkl diff --git a/assets/trained-models/mlr_model.pkl b/assets/trained-models/mlr_model.pkl deleted file mode 100644 index 57271d0ecac1225ee7881fd33213ede6c268bad2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 65 zcmZo*nQF!W0X-7M**U3+MR|IudBv%@Nja%{@oD)*sl_EzdPIW~^HTD2-N4+S)O4U| LaemR1$y4+IoRt?V From 62a07d48fb1502f28b55fbc0e610310197257112 Mon Sep 17 00:00:00 2001 From: Bronwynkrige <112427529+Bronwynkrige@users.noreply.github.com> Date: Fri, 18 Nov 2022 02:36:42 +0200 Subject: [PATCH 8/8] Add files via upload Added trianed model --- assets/trained-models/mlr_model.pkl | Bin 0 -> 2636 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 assets/trained-models/mlr_model.pkl diff --git a/assets/trained-models/mlr_model.pkl b/assets/trained-models/mlr_model.pkl new file mode 100644 index 0000000000000000000000000000000000000000..4cb59b7d55031706d189b4b517fbbfd9519b3f36 GIT binary patch literal 2636 zcmZuzdvp_38lO^&C2f(H^da3MLN}$5KEOVdHrIw%8)$174PQbqu?_gNFjxy5{t689iOsrL8C5dwg8X&T~5Yq_5 zv}6)N5OthPae~Z>7S<_4Y%@6m2L*@7({^qx3lEVRJZ4y@$XaNbWgw0mjsq5l(@l{u zyjdLyRK3G2!NZkgJf3qpBu?g5vk>1xj>h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