Skip to content

Commit Live PR #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified __pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q01_outlier_removal/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q01_outlier_removal/__pycache__/build.cpython-36.pyc
Binary file not shown.
10 changes: 9 additions & 1 deletion q01_outlier_removal/build.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# %load q01_outlier_removal/build.py
# Default imports
import pandas as pd
import numpy as np

loan_data = pd.read_csv('data/loan_prediction_uncleaned.csv')
loan_data = loan_data.drop('Loan_ID', 1)

def outlier_removal(loan_data):
df= loan_data.quantile(.95)
loan_data = loan_data.drop(loan_data [loan_data['ApplicantIncome'] > df['ApplicantIncome']].index)
loan_data = loan_data.drop(loan_data [loan_data['CoapplicantIncome'] > df['CoapplicantIncome']].index)
loan_data = loan_data.drop(loan_data [loan_data['LoanAmount'] > df['LoanAmount']].index)
return loan_data


# Write your Solution here:
Binary file modified q01_outlier_removal/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
20 changes: 19 additions & 1 deletion q02_data_cleaning_all/build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# %load q02_data_cleaning_all/build.py
# Default Imports
import sys, os
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname('__file__'))))
Expand All @@ -9,6 +10,23 @@
loan_data = pd.read_csv('data/loan_prediction_uncleaned.csv')
loan_data = loan_data.drop('Loan_ID', 1)
loan_data = outlier_removal(loan_data)
loan_data.columns
def data_cleaning (housing_data):
missinglist = list(housing_data.columns[housing_data.isnull().any()])
cate=[]
num=[]
for k in missinglist :
if (str(housing_data[k].dtypes) == 'object' ):
housing_data[k].fillna(housing_data[k].mode()[0], inplace =True)
cate.append(k)
else:
housing_data[k].fillna(housing_data[k].mean(), inplace =True)
num.append(k)
X=housing_data.drop('Loan_Status',1)
y=housing_data['Loan_Status']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=9)
return X ,y, X_train, X_test, y_train, y_test
data_cleaning(loan_data)



# Write your solution here :
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
21 changes: 20 additions & 1 deletion q02_data_cleaning_all_2/build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# %load q02_data_cleaning_all_2/build.py
# Default Imports
import pandas as pd
import numpy as np
Expand All @@ -8,6 +9,24 @@
loan_data = loan_data.drop('Loan_ID', 1)
loan_data = outlier_removal(loan_data)
X, y, X_train, X_test, y_train, y_test = data_cleaning(loan_data)
def data_cleaning_2(X_train, X_test, y_train, y_test):
col=['Gender', 'Married', 'Dependents', 'Education', 'Self_Employed', 'Property_Area']
allcolumn = X_train.columns.values

df=pd.get_dummies(X_train , columns=col )
X_train = pd.concat([X_train,df], axis=1)
X_train = X_train.drop(col,axis=1)
X_train = X_train.drop(allcolumn,axis=1)
X_train = X_train.drop('Dependents_3+',axis=1)

df1=pd.get_dummies(X_test , columns=col )
X_test = pd.concat([X_test,df1], axis=1)
X_test = X_test.drop(col,axis=1)
X_test = X_test.drop(allcolumn,axis=1)
X_test = X_test.drop('Dependents_3+',axis=1)

return X_train ,X_test,y_train,y_test




# Write your solution here :
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
18 changes: 17 additions & 1 deletion q03_logistic_regression/build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# %load q03_logistic_regression/build.py
# Default Imports
import pandas as pd
from sklearn.preprocessing import StandardScaler
Expand All @@ -11,8 +12,23 @@
loan_data = loan_data.drop('Loan_ID', 1)
loan_data = outlier_removal(loan_data)
X, y, X_train, X_test, y_train, y_test = data_cleaning(loan_data)


X_train, X_test, y_train, y_test = data_cleaning_2(X_train, X_test, y_train, y_test)
def logistic_regression(X_train, X_test, y_train, y_test ):
scaler = StandardScaler()
li= ['ApplicantIncome','CoapplicantIncome','LoanAmount']
X_train[li] = scaler.fit_transform(X_train[li])
X_test[li] = scaler.fit_transform(X_test[li])
lr= LogisticRegression(random_state=9)
lr.fit(X_train,y_train)
y_pred= lr.predict(X_test)
cnf_matrix = confusion_matrix(y_test, y_pred)
return cnf_matrix






# Write your solution code here:

Binary file not shown.
Binary file not shown.