File size: 1,617 Bytes
0117a59
 
 
 
 
6eaa5ab
0117a59
d8f3da6
cff1eb0
 
0117a59
d8f3da6
0117a59
 
 
 
 
 
 
 
 
 
d8f3da6
0117a59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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)
# Select features (columns) for X
X = df.drop(['Cart_Abandoned'], axis = 1)
y = df['Cart_Abandoned']


#Importamos las librerias necesarias para la creacion del modelo
from sklearn.model_selection import train_test_split

#50% para test y 50% para train
X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.50, random_state=42)

#Arbol de decision
from sklearn.ensemble import RandomForestClassifier

#Creacion del modelo
random_forest = RandomForestClassifier(n_estimators=10)

#Entrenamiento
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()