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 #80

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.
13 changes: 13 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,15 @@


# Write your Solution here:
def outlier_removal(df):
q_vals = df.select_dtypes(include = ['int64', 'float64']).quantile(0.95)
num_feats = ['ApplicantIncome', 'CoapplicantIncome', 'LoanAmount']
for i in num_feats:
df = df.drop(df[df[i] > q_vals[i]].index)
print(df.shape)
return df
q_vals.index.values.tolist()
outlier_removal(loan_data)



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.
14 changes: 14 additions & 0 deletions 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 @@ -12,3 +13,16 @@


# Write your solution here :
def data_cleaning(df):
X = df.iloc[:,:-1]
y = df.iloc[:,-1]
X['LoanAmount'] = X['LoanAmount'].fillna(X['LoanAmount'].mean())
cols = ['Gender','Married', 'Dependents', 'Self_Employed', 'Loan_Amount_Term', 'Credit_History']
for col in cols:
X[col] = X[col].fillna(X[col].mode()[0])
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

loan_data.head()


Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
13 changes: 13 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,15 @@


# Write your solution here :
def data_cleaning_2(X_train, X_test, y_train, y_test):
num_col = X_train.select_dtypes(include=['int','float'])
for col in num_col.columns.values:
X_train.loc[:,col] = np.sqrt(X_train[col])
X_test.loc[:,col] = np.sqrt(X_test[col])

cols = ['Gender', 'Married', 'Dependents', 'Education', 'Self_Employed', 'Property_Area']
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


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):
scale = StandardScaler()
cols = ['ApplicantIncome', 'CoapplicantIncome', 'LoanAmount']
X_train.loc[:,cols] = scale.fit_transform(X_train.loc[:,cols])
X_test.loc[:,cols] = scale.fit_transform(X_test.loc[:,cols])
log_reg = LogisticRegression(random_state=9)
log_reg.fit(X_train,y_train)
y_pred = log_reg.predict(X_test)
cm = confusion_matrix(y_test,y_pred)
return cm


Binary file not shown.
Binary file not shown.