Skip to content

Commit Live PR #77

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.
13 changes: 12 additions & 1 deletion q01_outlier_removal/build.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
# %load q01_outlier_removal/build.py
# Default imports
from greyatomlib.logistic_regression_project.q01_outlier_removal.build import outlier_removal
import pandas as pd

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

def outlier_removal(df):
qv = 0.95
numeric_features = ['ApplicantIncome', 'CoapplicantIncome', 'LoanAmount']
df_qv = df.quantile(q=qv, axis=0, numeric_only=True, interpolation='linear')
for feature in numeric_features:
df = df.drop(df[df[feature] > df_qv[feature]].index)
return df




# 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.
18 changes: 16 additions & 2 deletions q02_data_cleaning_all/build.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
# %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 greyatomlib.logistic_regression_project.q01_outlier_removal.build import outlier_removal

from sklearn.preprocessing import Imputer
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(df):
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])
y = df.iloc[:,-1]
X = 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



# Write your solution here :
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
17 changes: 16 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,19 @@
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):
numerical_features = ['ApplicantIncome', 'CoapplicantIncome', 'LoanAmount', 'Loan_Amount_Term','Credit_History']
categorical_features = ['Gender', 'Married', 'Dependents', 'Education', 'Self_Employed', 'Property_Area']
for feature in numerical_features:
X_train[feature] = np.sqrt(X_train[feature])
X_test[feature] = np.sqrt(X_test[feature])
X_train_dummy = pd.get_dummies(X_train[categorical_features], drop_first=True)
X_test_dummy = pd.get_dummies(X_test[categorical_features], drop_first=True)
X_train = X_train[numerical_features].join(X_train_dummy)
X_test = X_test[numerical_features].join(X_test_dummy)
y_train, y_test = y_train, y_test
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.
19 changes: 17 additions & 2 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 @@ -6,13 +7,27 @@
from greyatomlib.logistic_regression_project.q01_outlier_removal.build import outlier_removal
from greyatomlib.logistic_regression_project.q02_data_cleaning_all.build import data_cleaning
from greyatomlib.logistic_regression_project.q02_data_cleaning_all_2.build import data_cleaning_2

from sklearn.metrics import mean_squared_error, r2_score, accuracy_score, confusion_matrix, f1_score, log_loss
from sklearn.linear_model import LinearRegression, Lasso, Ridge, ElasticNet, LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import PolynomialFeatures, StandardScaler, LabelEncoder
loan_data = pd.read_csv('data/loan_prediction_uncleaned.csv')
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)


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



Binary file not shown.
Binary file not shown.