Skip to content

Commit Live PR #66

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
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.
24 changes: 23 additions & 1 deletion q01_outlier_removal/build.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
# %load q01_outlier_removal/build.py
# Default imports
import pandas as pd

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


# Write your Solution here:

#num_feature_data = loan_data[['ApplicantIncome', 'CoapplicantIncome', 'LoanAmount']]

# Write your code here:
def outlier_removal(loan_data):
#df = num_feature_data
#df = df.drop(df[(df['ApplicantIncome']>df['ApplicantIncome'].quantile(0.95)) | (df['CoapplicantIncome']>df['CoapplicantIncome'].quantile(0.95)) | (df['LoanAmount']>df['LoanAmount'].quantile(0.95))].index)

loan_data = loan_data.drop(loan_data[(loan_data['ApplicantIncome']>loan_data['ApplicantIncome'].quantile(0.95)) | (loan_data['CoapplicantIncome']>loan_data['CoapplicantIncome'].quantile(0.95)) | (loan_data['LoanAmount']>loan_data['LoanAmount'].quantile(0.95))].index)

#loan_data.head()

#print (df)

return loan_data


outlier_removal(loan_data)

loan_data.head()


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.
38 changes: 36 additions & 2 deletions q02_data_cleaning_all/build.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,48 @@
# %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__'))))
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import Imputer
from sklearn.model_selection import train_test_split as tts
from greyatomlib.logistic_regression_project.q01_outlier_removal.build import outlier_removal

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


# Write your solution here :

def data_cleaning(loan_data):

imp_mean = Imputer(missing_values = float('NaN'), strategy='mean')
#imp_mean.fit(loan_data[['LoanAmount']])
#loan_data['LoanAmount'] = imp_mean.transform(loan_data[['LoanAmount']])
loan_data['LoanAmount'] = imp_mean.fit_transform(loan_data[['LoanAmount']]).ravel()

loan_data['Gender'] = loan_data['Gender'].fillna(loan_data['Gender'].mode()[0])
loan_data['Married'] = loan_data['Married'].fillna(loan_data['Married'].mode()[0])
loan_data['Dependents'] = loan_data['Dependents'].fillna(loan_data['Dependents'].mode()[0])
loan_data['Self_Employed'] = loan_data['Self_Employed'].fillna(loan_data['Self_Employed'].mode()[0])
loan_data['Loan_Amount_Term'] = loan_data['Loan_Amount_Term'].fillna(loan_data['Loan_Amount_Term'].mode()[0])
loan_data['Credit_History'] = loan_data['Credit_History'].fillna(loan_data['Credit_History'].mode()[0])

#np.random.seed(9)
X=loan_data.drop(['LoanAmount'],axis=1)
y=loan_data['LoanAmount']

X_train, X_test, y_train, y_test = tts(X, y, test_size = 0.25, random_state = 9)


#return loan_data.head()

return (X,y,X_train, X_test, y_train, y_test)

data_cleaning(loan_data)






Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
27 changes: 26 additions & 1 deletion q02_data_cleaning_all_2/build.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# %load q02_data_cleaning_all_2/build.py
# Default Imports
import pandas as pd
import numpy as np
from math import sqrt
from sklearn import preprocessing
from sklearn.preprocessing import LabelEncoder

from greyatomlib.logistic_regression_project.q02_data_cleaning_all.build import data_cleaning
from greyatomlib.logistic_regression_project.q01_outlier_removal.build import outlier_removal

@@ -9,5 +14,25 @@
loan_data = outlier_removal(loan_data)
X, y, X_train, X_test, y_train, y_test = data_cleaning(loan_data)


# Write your solution here :
def data_cleaning_2(X_train,X_test,y_train,y_test):
for x in ['CoapplicantIncome','LoanAmount','Loan_Amount_Term','Credit_History']:

X_train[x] = np.sqrt(X_train[x])
X_test[x]= np.sqrt(X_test[x])

X_train1 = pd.get_dummies(X_train)
X_test1 = pd.get_dummies(X_test)

X_train1=X_train1.drop(['Dependents_0','Gender_Female','Education_Graduate','Self_Employed_No','Married_No','Property_Area_Rural'],axis=1)

X_test1=X_test1.drop(['Dependents_0','Gender_Female','Education_Graduate','Self_Employed_No','Married_No','Property_Area_Rural'],axis=1)

return X_train1,X_test1,y_train,y_test

data_cleaning_2(X_train, X_test, y_train, y_test)


y_train


Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
17 changes: 17 additions & 0 deletions 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
@@ -15,4 +16,20 @@


# Write your solution code here:
def logistic_regression(X_train,X_test,y_train,y_test):

scale = StandardScaler()
scale.fit(X_train[['ApplicantIncome','CoapplicantIncome','LoanAmount']])
log_reg = LogisticRegression()
log_reg.fit(X_train,y_train)

y_pred = log_reg.predict(X_test)
conf_matrix = confusion_matrix(y_test,y_pred)

# print (y_pred, conf_matrix)

return conf_matrix

logistic_regression(X_train,X_test,y_train,y_test)


Binary file not shown.
Binary file not shown.