| | import pandas as pd |
| | import numpy as np |
| | import sklearn as sn |
| | from datasets import Dataset |
| |
|
| | df=pd.read_csv("https://huggingface.co/spaces/Ralmao/Cart/raw/main/cart2_data.csv", on_bad_lines='skip') |
| | dataset= Dataset.from_pandas(df) |
| | |
| | X = df.drop(['Cart_Abandoned'], axis = 1) |
| | y = df['Cart_Abandoned'] |
| |
|
| |
|
| | |
| | from sklearn.model_selection import train_test_split |
| |
|
| | |
| | X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.50, random_state=42) |
| |
|
| | |
| | from sklearn.ensemble import RandomForestClassifier |
| |
|
| | |
| | random_forest = RandomForestClassifier(n_estimators=10) |
| |
|
| | |
| | random_forest.fit(X_train,y_train) |
| |
|
| | import gradio as gr |
| |
|
| | def predict_customer_segment_type(No_Checkout_Confirmed,No_Checkout_Initiated,No_Customer_Login,Session_Activity_Count): |
| | x = np.array([No_Checkout_Confirmed,No_Checkout_Initiated,No_Customer_Login,Session_Activity_Count]) |
| | pred = random_forest.predict(x.reshape(1, -1)) |
| | return pred[0] |
| |
|
| |
|
| | No_Checkout_Confirmed = gr.Number(label='No_Checkout_Confirmed') |
| | No_Checkout_Initiated = gr.Number(label='No_Checkout_Initiated ') |
| | No_Customer_Login = gr.Number(label='No_Customer_Login') |
| | Session_Activity_Count = gr.Number(label='Session_Activity_Count') |
| | output = gr.Textbox(label='Cart_Abandoned') |
| |
|
| | app = gr.Interface(predict_customer_segment_type, inputs=[No_Checkout_Confirmed,No_Checkout_Initiated,No_Customer_Login,Session_Activity_Count], outputs=output, description= 'This is customer segmented predict') |
| | app.launch() |