Jayabalambika commited on
Commit
783a1d4
Β·
1 Parent(s): 303f2f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -40
app.py CHANGED
@@ -6,6 +6,7 @@ from sklearn.ensemble import IsolationForest
6
  import numpy as np
7
  from sklearn.model_selection import train_test_split
8
  import gradio as gr
 
9
 
10
 
11
  #Data preparation
@@ -23,48 +24,27 @@ y = np.concatenate(
23
 
24
  #Visualize the data as a scatter plot
25
 
 
 
 
 
 
 
 
 
 
26
 
 
27
 
28
- # def predict_survival(passenger_class, is_male, age, company, fare, embark_point):
29
- # if passenger_class is None or embark_point is None:
30
- # return None
31
- # df = pd.DataFrame.from_dict(
32
- # {
33
- # "Pclass": [passenger_class + 1],
34
- # "Sex": [0 if is_male else 1],
35
- # "Age": [age],
36
- # "Fare": [fare],
37
- # "Embarked": [embark_point + 1],
38
- # "Company": [
39
- # (1 if "Sibling" in company else 0) + (2 if "Child" in company else 0)
40
- # ]
41
- # }
42
- # )
43
- # df = encode_age(df)
44
- # df = encode_fare(df)
45
- # pred = clf.predict_proba(df)[0]
46
- # return {"Perishes": float(pred[0]), "Survives": float(pred[1])}
47
 
 
48
 
49
- # demo = gr.Interface(
50
- # predict_survival,
51
- # [
52
- # gr.Dropdown(["first", "second", "third"], type="index"),
53
- # "checkbox",
54
- # gr.Slider(0, 80, value=25),
55
- # gr.CheckboxGroup(["Sibling", "Child"], label="Travelling with (select all)"),
56
- # gr.Number(value=20),
57
- # gr.Radio(["S", "C", "Q"], type="index"),
58
- # ],
59
- # "label",
60
- # examples=[
61
- # ["first", True, 30, [], 50, "S"],
62
- # ["second", False, 40, ["Sibling", "Child"], 10, "Q"],
63
- # ["third", True, 30, ["Child"], 20, "S"],
64
- # ],
65
- # interpretation="default",
66
- # live=True,
67
- # )
68
 
69
- # if __name__ == "__main__":
70
- # demo.launch()
 
 
 
 
6
  import numpy as np
7
  from sklearn.model_selection import train_test_split
8
  import gradio as gr
9
+ import matplotlib.pyplot as plt
10
 
11
 
12
  #Data preparation
 
24
 
25
  #Visualize the data as a scatter plot
26
 
27
+ def visualize_input_data():
28
+ fig = plt.figure(1, facecolor="w", figsize=(5, 5))
29
+ scatter = plt.scatter(X[:, 0], X[:, 1], c=y, s=20, edgecolor="k")
30
+ handles, labels = scatter.legend_elements()
31
+ plt.axis("square")
32
+ plt.legend(handles=handles, labels=["outliers", "inliers"], title="true class")
33
+ plt.title("Gaussian inliers with \nuniformly distributed outliers")
34
+ # plt.show()
35
+ return fig
36
 
37
+ title = " An example using IsolationForest for anomaly detection."
38
 
39
+ with gr.Blocks(title=title) as demo:
40
+ gr.Markdown(f"# {title}")
41
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
+ gr.Markdown(" **https://scikit-learn.org/stable/auto_examples/ensemble/plot_isolation_forest.html#sphx-glr-auto-examples-ensemble-plot-isolation-forest-py**")
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
+
47
+ btn = gr.Button(value="Visualize input dataset")
48
+ btn.click(visualize_input_data, outputs= gr.Plot(label='Visualizing input dataset') )
49
+ gr.Markdown( f"## In progress")
50
+ demo.launch()