diff --git a/api.py b/api.py index a206495..89bf4c6 100644 --- a/api.py +++ b/api.py @@ -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/apples_simple_lm_regression.pkl') + path_to_model='assets/trained-models/mlr_model.pkl') print ('-'*40) print ('Model succesfully loaded') diff --git a/assets/trained-models/mlr_model.pkl b/assets/trained-models/mlr_model.pkl new file mode 100644 index 0000000..49209e6 Binary files /dev/null and b/assets/trained-models/mlr_model.pkl differ diff --git a/model.py b/model.py index d72c14b..391f98b 100644 --- a/model.py +++ b/model.py @@ -48,7 +48,7 @@ def _preprocess_data(data): # Convert the json string to a python dictionary object feature_vector_dict = json.loads(data) # Load the dictionary as a Pandas DataFrame. - feature_vector_df = pd.DataFrame.from_dict([feature_vector_dict]) + df_train = pd.DataFrame.from_dict([feature_vector_dict]) # --------------------------------------------------------------- # NOTE: You will need to swap the lines below for your own data @@ -60,13 +60,25 @@ def _preprocess_data(data): # ----------- Replace this code with your own preprocessing steps -------- - - feature_vector_df = feature_vector_df[(feature_vector_df['Commodities'] == 'APPLE GOLDEN DELICIOUS')] - predict_vector = feature_vector_df[['Total_Qty_Sold','Stock_On_Hand']] + #Filtering Commodities for APPLE GOLDEN DELICIOUS + df_train = df_train[df_train['Commodities']=='APPLE GOLDEN DELICIOUS'] + + #Removing negative values + df_train = df_train._get_numeric_data() + df_train[df_train < 0] = 0 + + #Removing all infinity and 'not a number' values + df_train = df_train.replace([np.inf, -np.inf, 0], np.nan).dropna(axis=0) + + #Creating data sets + train = df_train[['Weight_Kg','Low_Price', 'High_Price', 'Sales_Total', 'Total_Qty_Sold','Total_Kg_Sold']] + + #feature_vector_df = feature_vector_df[(feature_vector_df['Commodities'] == 'APPLE GOLDEN DELICIOUS')] + #predict_vector = feature_vector_df[['Total_Qty_Sold','Stock_On_Hand']] # ------------------------------------------------------------------------ - return predict_vector + return train def load_model(path_to_model:str): """Adapter function to load our pretrained model into memory. diff --git a/utils/request.py b/utils/request.py index 79cfe84..0d9773f 100644 --- a/utils/request.py +++ b/utils/request.py @@ -36,7 +36,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://34.245.158.7:5000/api_v0.1' # Perform the POST request. print(f"Sending POST request to web server API at: {url}")