Skip to content
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

Commit Live PR #71

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.
9 changes: 9 additions & 0 deletions q01_outlier_removal/build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# %load q01_outlier_removal/build.py
# Default imports
import pandas as pd

Expand All @@ -6,3 +7,11 @@


# Write your Solution here:
def outlier_removal(loan_data):
loan = loan_data[['ApplicantIncome','CoapplicantIncome','LoanAmount']]
q = loan_data.quantile(0.95)
for l in loan:
loan_data = loan_data.drop(loan_data[loan_data[l] > q[l]].index)
return loan_data
outlier_removal(loan_data).shape

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.
27 changes: 26 additions & 1 deletion q02_data_cleaning_all/build.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
# %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 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)

np.random.seed(9)

# Write your solution here :
def data_cleaning(loan_data):
#Computing mean of the numerical variable
impu_mean = Imputer(missing_values = 'NaN', strategy='mean')
impu_mean.fit(loan_data[['LoanAmount']])
loan_data[['LoanAmount']] = impu_mean.transform(loan_data[['LoanAmount']])

#Computing mode of the categorical variable
cate_col = ['Gender', 'Married', 'Dependents', 'Self_Employed', 'Loan_Amount_Term', 'Credit_History']
for col in cate_col:
loan_data['LoanAmount'].fillna(loan_data[col].mode(), inplace = True)

#seperate the features and target variable
X = loan_data.iloc[:,:-1]
y = loan_data.iloc[:,-1]

#train test split
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)




Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 11 additions & 0 deletions 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 @@ -11,3 +12,13 @@


# Write your solution here :
def data_cleaning_2(X_train,X_test,y_train,y_test):
cols=X_train.select_dtypes(include=['object']).columns.tolist()
X_train['ApplicantIncome'] = np.sqrt(X_train['ApplicantIncome'])
X_test['ApplicantIncome']= np.sqrt(X_test['ApplicantIncome'])
X_train=pd.get_dummies(X_train,columns=cols,drop_first=True)
X_test=pd.get_dummies(X_test,columns=cols,drop_first=True)
return X_train,X_test,y_train,y_test
data_cleaning_2(X_train,X_test,y_train,y_test)


Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
12 changes: 12 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
Expand All @@ -15,4 +16,15 @@


# Write your solution code here:
def logistic_regression(X_train,X_test,y_train,y_test):
scalar=StandardScaler()
scalar.fit(X_train[['ApplicantIncome','CoapplicantIncome','LoanAmount']])
modl = LogisticRegression(random_state=9)
modl.fit(X_train,y_train)
y_pred=modl.predict(X_test)
cm = confusion_matrix(y_test,y_pred)
return cm
logistic_regression(X_train,X_test,y_train,y_test)



Binary file not shown.
Binary file not shown.