Skip to content
This repository was archived by the owner on Nov 23, 2023. It is now read-only.
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/apples_simple_lm_regression.pkl')
path_to_model='assets/trained-models/mlr_model.pkl')

print ('-'*40)
print ('Model succesfully loaded')
Expand Down
Binary file added assets/trained-models/mlr_model.pkl
Binary file not shown.
22 changes: 17 additions & 5 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion utils/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down