Skip to content

Commit Live PR #79

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.
19 changes: 18 additions & 1 deletion q01_outlier_removal/build.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@

# Default imports
import pandas as pd

loan_data = pd.read_csv('data/loan_prediction_uncleaned.csv')
loan_data = loan_data.drop('Loan_ID', 1)
loan_data_numerical = loan_data[['ApplicantIncome', 'CoapplicantIncome', 'LoanAmount']]

def outlier_removal(data):
df = data
qlt = df.quantile(q=0.95)

df = df.drop(df[(df['ApplicantIncome']>qlt[0])].index)
df = df.drop(df[(df['CoapplicantIncome']>qlt[1])].index)
df = df.drop(df[(df['LoanAmount']>qlt[2])].index)

return df

outlier_removal(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.
21 changes: 20 additions & 1 deletion q02_data_cleaning_all/build.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
# %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.preprocessing import Imputer
from sklearn.model_selection import train_test_split
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)

def data_cleaning(data):
df = data
imputer_mean = Imputer(missing_values='NaN', strategy='mean')
imputer_mean.fit(df[['LoanAmount']])
df['LoanAmount'] = imputer_mean.transform(df[['LoanAmount']])
cat_features = ['Gender', 'Married', 'Dependents', 'Self_Employed', 'Loan_Amount_Term', 'Credit_History']
for feature in cat_features:
df[feature] = df[feature].fillna(df[feature].mode()[0])
X = df.iloc[:,:-1]
y = df.iloc[:,-1]

np.random.seed(9)
X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.25, train_size=0.75)
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.
23 changes: 22 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 @@ -9,5 +10,25 @@
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):

numeric_feature = ['ApplicantIncome', 'CoapplicantIncome', 'LoanAmount', 'Loan_Amount_Term','Credit_History']
cat_features = ['Gender', 'Married', 'Dependents', 'Education', 'Self_Employed', 'Property_Area']

for feature in numeric_feature:
X_train[feature] = np.sqrt(X_train[feature])
X_test[feature] = np.sqrt(X_test[feature])

X_train_dummy = pd.get_dummies(X_train[cat_features], drop_first=True)
X_test_dummy = pd.get_dummies(X_test[cat_features], drop_first=True)
X_train = X_train[numeric_feature].join(X_train_dummy)
X_test = X_test[numeric_feature].join(X_test_dummy)
y_train, y_test = y_train, y_test

return X_train, X_test, y_train, y_test

data_cleaning_2(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.
22 changes: 21 additions & 1 deletion q03_logistic_regression/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# %load q03_logistic_regression/build.py
# Default Imports
import pandas as pd
import numpy as np
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import confusion_matrix
Expand All @@ -13,6 +15,24 @@
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):
column_transform = ['ApplicantIncome', 'CoapplicantIncome', 'LoanAmount']

stand_scale = StandardScaler()
X_train.loc[:, column_transform] = stand_scale.fit_transform(X_train.loc[:, column_transform])
X_test.loc[:, column_transform] = stand_scale.fit_transform(X_test.loc[:, column_transform])

lr = LogisticRegression(random_state=9)
lr.fit(X_train, y_train)

y_pred = lr.predict(X_test)
cm = confusion_matrix(y_test,y_pred)

return cm






# Write your solution code here:

Binary file not shown.
Binary file not shown.