# %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)
# Write your solution here :

def data_cleaning(data):

    X = data.iloc[:,:-1]
    y = data.Loan_Status

    categorical = ['Gender','Married','Dependents','Self_Employed','Loan_Amount_Term','Credit_History']
    cat_pd = pd.DataFrame()
    for name in categorical:
        mode = X[name].mode()
        X[name].fillna(mode[0],inplace = True)

    mean = X['LoanAmount'].mean()
    X['LoanAmount'].fillna(mean,inplace = True)

    np.random.seed(9)
    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


