sanjana commited on
Commit
79ccab8
·
1 Parent(s): fa07661

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -62
app.py CHANGED
@@ -14,23 +14,6 @@ from array import *
14
 
15
  df_train = pd.read_csv("train_ctrUa4K.csv") #Reading the dataset in a dataframe using Pandas
16
 
17
- df_train.head()
18
-
19
- df_train.describe()
20
-
21
- df_train.shape
22
-
23
- df_train.info()
24
-
25
- df_train.isnull().sum()
26
-
27
- print(df_train['Gender'].value_counts())
28
- print(df_train['Married'].value_counts())
29
- print(df_train['Dependents'].value_counts())
30
- print(df_train['Self_Employed'].value_counts())
31
- print(df_train['Credit_History'].value_counts())
32
- print(df_train['Property_Area'].value_counts())
33
-
34
  df_train['Gender'].fillna("Male", inplace = True)
35
  df_train['Married'].fillna("Yes", inplace = True)
36
  df_train['Dependents'].fillna("0", inplace = True)
@@ -38,17 +21,6 @@ df_train['Self_Employed'].fillna("No", inplace = True)
38
  df_train['Credit_History'].fillna(1.0, inplace = True)
39
  df_train.isnull().sum()
40
 
41
- duplicate=df_train.duplicated()
42
- print(duplicate.sum())
43
- df_train[duplicate]
44
-
45
- fig, ax = plt.subplots(3, 2, figsize = (10, 7))
46
- sns.boxplot(x= df_train["ApplicantIncome"], ax = ax[0,0])
47
- sns.distplot(df_train['ApplicantIncome'], ax = ax[0,1])
48
- sns.boxplot(x= df_train["CoapplicantIncome"], ax = ax[1,0])
49
- sns.distplot(df_train['CoapplicantIncome'], ax = ax[1,1])
50
- sns.boxplot(x= df_train["Loan_Amount_Term"], ax = ax[2,0])
51
- sns.distplot(df_train['Loan_Amount_Term'], ax = ax[2,1])
52
 
53
  def remove_outlier(col):
54
  sorted(col)
@@ -70,21 +42,11 @@ low_LAT, high_LAT=remove_outlier(df_train['Loan_Amount_Term'])
70
  df_train['Loan_Amount_Term']=np.where(df_train['Loan_Amount_Term']>high_LAT, high_LAT, df_train['Loan_Amount_Term'])
71
  df_train['Loan_Amount_Term']=np.where(df_train['Loan_Amount_Term']<low_LAT, low_LAT, df_train['Loan_Amount_Term'])
72
 
73
- df_train.boxplot(column=['ApplicantIncome'])
74
- plt.show()
75
-
76
- df_train.boxplot(column=['CoapplicantIncome'])
77
- plt.show()
78
-
79
- df_train.boxplot(column=['Loan_Amount_Term'])
80
- plt.show()
81
-
82
- df_train.isnull().sum()
83
 
84
  df_train['Loan_Amount_Term'].fillna(360, inplace = True)
85
 
86
  table = df_train.pivot_table(values='LoanAmount', index='Self_Employed' ,columns='Education', aggfunc=np.median)
87
- table
88
 
89
  def val(x):
90
  return table.loc[x['Self_Employed'],x['Education']]
@@ -100,8 +62,6 @@ df=df_train
100
  label_encoder = preprocessing.LabelEncoder()
101
  df['Gender']= label_encoder.fit_transform(df['Gender'])
102
 
103
- df
104
-
105
  df['Married']= label_encoder.fit_transform(df['Married'])
106
  df['Education']= label_encoder.fit_transform(df['Education'])
107
  df['Self_Employed']= label_encoder.fit_transform(df['Self_Employed'])
@@ -169,26 +129,6 @@ g=GridSearchCV(LR, parametersLR)
169
  g.fit(x_train, y_train)
170
 
171
  ypred = g.predict(x_test)
172
- ypred
173
-
174
- print (classification_report(y_test, ypred))
175
-
176
- l = {'Gender': [1],
177
- 'Married': [0],
178
- 'Dependents':[0],
179
- 'Education':[0],
180
- 'Self_Employed':[0],
181
- 'LoanAmount':[130],
182
- 'Loan_Amount_Term':[360],
183
- 'Credit_History':[1],
184
- 'Property_Area':[2],
185
- 'Total_income':[5849]
186
- }
187
- df=pd.DataFrame(l)
188
- ans = g.predict(df)
189
- ans2 = ans.tolist()
190
- ans2[0]
191
- df
192
 
193
  def pred(Gender, Marital_Status, Dependents, Education, Self_Employed, Loan_Amount, Credit_History, Property_Area, Total_Income):
194
  if Gender == "Male":
@@ -243,6 +183,6 @@ def pred(Gender, Marital_Status, Dependents, Education, Self_Employed, Loan_Amou
243
 
244
  iface = gr.Interface(
245
  fn=pred,
246
- inputs=[gr.inputs.Radio(["Male", "Female"]), gr.inputs.Radio(["Married", "Unmarried"]),gr.inputs.Radio(["0", "1","2", "3+"]), gr.inputs.Radio(["Educated", "Uneducated"]), gr.inputs.Radio(["Yes", "No"]), "text", gr.inputs.Radio(["1", "0"]), gr.inputs.Radio(["0", "1", "2"]), "text"],
247
  outputs="text")
248
  iface.launch(inline=False)
 
14
 
15
  df_train = pd.read_csv("train_ctrUa4K.csv") #Reading the dataset in a dataframe using Pandas
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  df_train['Gender'].fillna("Male", inplace = True)
18
  df_train['Married'].fillna("Yes", inplace = True)
19
  df_train['Dependents'].fillna("0", inplace = True)
 
21
  df_train['Credit_History'].fillna(1.0, inplace = True)
22
  df_train.isnull().sum()
23
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  def remove_outlier(col):
26
  sorted(col)
 
42
  df_train['Loan_Amount_Term']=np.where(df_train['Loan_Amount_Term']>high_LAT, high_LAT, df_train['Loan_Amount_Term'])
43
  df_train['Loan_Amount_Term']=np.where(df_train['Loan_Amount_Term']<low_LAT, low_LAT, df_train['Loan_Amount_Term'])
44
 
 
 
 
 
 
 
 
 
 
 
45
 
46
  df_train['Loan_Amount_Term'].fillna(360, inplace = True)
47
 
48
  table = df_train.pivot_table(values='LoanAmount', index='Self_Employed' ,columns='Education', aggfunc=np.median)
49
+
50
 
51
  def val(x):
52
  return table.loc[x['Self_Employed'],x['Education']]
 
62
  label_encoder = preprocessing.LabelEncoder()
63
  df['Gender']= label_encoder.fit_transform(df['Gender'])
64
 
 
 
65
  df['Married']= label_encoder.fit_transform(df['Married'])
66
  df['Education']= label_encoder.fit_transform(df['Education'])
67
  df['Self_Employed']= label_encoder.fit_transform(df['Self_Employed'])
 
129
  g.fit(x_train, y_train)
130
 
131
  ypred = g.predict(x_test)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133
  def pred(Gender, Marital_Status, Dependents, Education, Self_Employed, Loan_Amount, Credit_History, Property_Area, Total_Income):
134
  if Gender == "Male":
 
183
 
184
  iface = gr.Interface(
185
  fn=pred,
186
+ inputs=[gr.inputs.Radio(["Male", "Female"]), gr.inputs.Radio(["Married", "Unmarried"]),gr.inputs.Radio(["0", "1","2", "3+"]), gr.inputs.Radio(["Educated", "Uneducated"]), gr.inputs.Radio(["Yes", "No"]), "text", gr.inputs.Radio(["1", "0"]), gr.inputs.Radio(["Urban", "Semi Urban", "Rural"]), "text"],
187
  outputs="text")
188
  iface.launch(inline=False)