Jayabalambika commited on
Commit
303f2f6
Β·
1 Parent(s): 55f8ab7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -0
app.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import pandas as pd
4
+ from sklearn.ensemble import IsolationForest
5
+
6
+ import numpy as np
7
+ from sklearn.model_selection import train_test_split
8
+ import gradio as gr
9
+
10
+
11
+ #Data preparation
12
+ n_samples, n_outliers = 120, 40
13
+ rng = np.random.RandomState(0)
14
+ covariance = np.array([[0.5, -0.1], [0.7, 0.4]])
15
+ cluster_1 = 0.4 * rng.randn(n_samples, 2) @ covariance + np.array([2, 2]) # general deformed cluster
16
+ cluster_2 = 0.3 * rng.randn(n_samples, 2) + np.array([-2, -2]) # spherical cluster
17
+ outliers = rng.uniform(low=-4, high=4, size=(n_outliers, 2))
18
+
19
+ X = np.concatenate([cluster_1, cluster_2, outliers]) #120+120+40 = 280 with 2D
20
+ y = np.concatenate(
21
+ [np.ones((2 * n_samples), dtype=int), -np.ones((n_outliers), dtype=int)]
22
+ )
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()