Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,8 +7,7 @@ from sklearn.impute import KNNImputer
|
|
7 |
from sklearn.decomposition import PCA
|
8 |
import pickle
|
9 |
|
10 |
-
|
11 |
-
# model = joblib.load("ann_model.joblib")
|
12 |
|
13 |
# # Define the prediction function
|
14 |
def predict(age, workclass, education, marital_status, occupation, relationship, race, gender, capital_gain, capital_loss, hours_per_week, native_country):
|
@@ -19,14 +18,13 @@ def predict(age, workclass, education, marital_status, occupation, relationship,
|
|
19 |
"hours-per-week":[hours_per_week], "native-country":[native_country]}
|
20 |
df = pd.DataFrame(data=columns)
|
21 |
fixed_features = cleaning_features(df)
|
22 |
-
|
|
|
|
|
23 |
# prediction = 1
|
24 |
-
|
25 |
-
return print(fixed_features)
|
26 |
|
27 |
def cleaning_features(data):
|
28 |
-
# with open('race_onehot_encoder.pkl', 'rb') as enc_file:
|
29 |
-
# encoder = pickle.load(enc_file)
|
30 |
|
31 |
with open('label_encoder_work.pkl', 'rb') as le_file:
|
32 |
le_work = pickle.load(le_file)
|
@@ -69,7 +67,7 @@ def cleaning_features(data):
|
|
69 |
|
70 |
data[numeric_cols] = scaler.transform(data[numeric_cols])
|
71 |
|
72 |
-
|
73 |
return data
|
74 |
|
75 |
# def pca(data):
|
@@ -155,7 +153,7 @@ interface = gr.Interface(
|
|
155 |
["Male", "Female"],
|
156 |
label="Gender"
|
157 |
),
|
158 |
-
gr.Slider(1,
|
159 |
gr.Slider(0, 100000, step=100, label="Capital Gain"),
|
160 |
gr.Slider(0, 5000, step=50, label="Capital Loss"),
|
161 |
gr.Dropdown(
|
|
|
7 |
from sklearn.decomposition import PCA
|
8 |
import pickle
|
9 |
|
10 |
+
|
|
|
11 |
|
12 |
# # Define the prediction function
|
13 |
def predict(age, workclass, education, marital_status, occupation, relationship, race, gender, capital_gain, capital_loss, hours_per_week, native_country):
|
|
|
18 |
"hours-per-week":[hours_per_week], "native-country":[native_country]}
|
19 |
df = pd.DataFrame(data=columns)
|
20 |
fixed_features = cleaning_features(df)
|
21 |
+
with open('ann_model.pkl', 'rb') as ann_model_file:
|
22 |
+
ann_model = pickle.load(ann_model_file)
|
23 |
+
prediction = ann_model.predict(fixed_features)
|
24 |
# prediction = 1
|
25 |
+
return "Income >50K" if prediction == 1 else "Income <=50K"
|
|
|
26 |
|
27 |
def cleaning_features(data):
|
|
|
|
|
28 |
|
29 |
with open('label_encoder_work.pkl', 'rb') as le_file:
|
30 |
le_work = pickle.load(le_file)
|
|
|
67 |
|
68 |
data[numeric_cols] = scaler.transform(data[numeric_cols])
|
69 |
|
70 |
+
data = pca(data)
|
71 |
return data
|
72 |
|
73 |
# def pca(data):
|
|
|
153 |
["Male", "Female"],
|
154 |
label="Gender"
|
155 |
),
|
156 |
+
gr.Slider(1, 60, step=1, label="Hours Per Week"),
|
157 |
gr.Slider(0, 100000, step=100, label="Capital Gain"),
|
158 |
gr.Slider(0, 5000, step=50, label="Capital Loss"),
|
159 |
gr.Dropdown(
|