Louis VAUBOURDOLLE
commited on
Commit
·
661a0f2
1
Parent(s):
4489a5b
[ADD] prediction
Browse files
app.py
CHANGED
|
@@ -1,25 +1,65 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
iface = gr.Interface(
|
| 8 |
sentence_builder,
|
| 9 |
[
|
| 10 |
-
gr.inputs.Slider(
|
| 11 |
-
gr.inputs.
|
| 12 |
-
gr.inputs.
|
| 13 |
-
gr.inputs.
|
| 14 |
-
gr.inputs.
|
|
|
|
|
|
|
|
|
|
| 15 |
],
|
| 16 |
"text",
|
| 17 |
examples=[
|
| 18 |
-
[2,
|
| 19 |
-
[
|
| 20 |
-
[10, "bird", "road", ["ran"], False],
|
| 21 |
-
[8, "cat", "zoo", ["ate"], True],
|
| 22 |
],
|
| 23 |
)
|
| 24 |
-
|
| 25 |
-
iface.launch()
|
|
|
|
| 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("/content/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 pl.predict(df)
|
| 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()
|
|
|