Louis VAUBOURDOLLE commited on
Commit
34ccbbc
·
1 Parent(s): 2ad3396

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -0
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import pandas as pd
4
+ from sklearn.model_selection import train_test_split
5
+ from sklearn.preprocessing import StandardScaler
6
+ from sklearn.linear_model import LogisticRegression
7
+ from sklearn.pipeline import Pipeline
8
+ from sklearn.metrics import accuracy_score
9
+ import time
10
+ import paho.mqtt.client as mqtt
11
+
12
+ df = pd.read_csv("./Churn_Modelling.csv")
13
+ df.drop(["RowNumber","CustomerId","Surname"], axis=1, inplace=True)
14
+ df.head()
15
+
16
+ df.Balance.plot(kind="hist", figsize=(10,6))
17
+ df.Balance = np.where(df.Balance==0, 0, 1)
18
+ df.Balance.value_counts()
19
+ df.Age.plot(kind="hist", figsize=(10,6))
20
+
21
+ X = df.drop(["Exited","Geography","Gender"], axis=1)
22
+ y = df["Exited"]
23
+ X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)
24
+
25
+ pl = Pipeline([
26
+ ("scale", StandardScaler()),
27
+ ("logreg", LogisticRegression())
28
+ ])
29
+ pl.fit(X_train, y_train)
30
+ y_train_pred = pl.predict(X_train)
31
+ y_test_pred = pl.predict(X_test)
32
+
33
+ def sentence_builder(credit, age, tenure, balance, nb_prods, has_card, active, est_salary):
34
+ data = [{
35
+ "CreditScore": credit,
36
+ "Age": age,
37
+ "Tenure": tenure,
38
+ "Balance": balance,
39
+ "NumOfProducts": nb_prods,
40
+ "HasCrCard": has_card,
41
+ "IsActiveMember": active,
42
+ "EstimatedSalary": est_salary,
43
+ }]
44
+ df = pd.json_normalize(data)
45
+ return bool(pl.predict(df)[0])
46
+
47
+ iface = gr.Interface(
48
+ sentence_builder,
49
+ [
50
+ gr.inputs.Slider(0, 10000, label='credit'),
51
+ gr.inputs.Slider(0, 100, label='age'),
52
+ gr.inputs.Slider(0, 10, label='tenure'),
53
+ gr.inputs.Slider(0, 10000, label='balance'),
54
+ gr.inputs.Slider(0, 10, label='number of products'),
55
+ gr.inputs.Checkbox(label="credit card"),
56
+ gr.inputs.Checkbox(label="active"),
57
+ gr.inputs.Slider(0, 200000, label='estimated salary'),
58
+ ],
59
+ "text",
60
+ examples=[
61
+ [619, 42, 2, 0, 1, 1, 1, 101348], # Returns False 0
62
+ [608, 41, 1, 83807, 1, 0, 1, 112542], # Returns True 1
63
+ ],
64
+ )
65
+ iface.launch()