application_vnd.jupyter.stderr_output_1.png
from sklearn.linear_model import LogisticRegression

from sklearn.preprocessing import OneHotEncoder, MinMaxScaler

import numpy

import pandas

train = pandas.read_csv('/kaggle/input/loan-status-binary-classification/train.csv')
test = pandas.read_csv('/kaggle/input/loan-status-binary-classification/test.csv')

train['Total_Income'] = train['Applicant_Income'] + train['Coapplicant_Income']
test['Total_Income'] = test['Applicant_Income'] + test['Coapplicant_Income']
train['Applicant_Proportion'] = train['Applicant_Income'] / train['Total_Income']
test['Applicant_Proportion'] = test['Applicant_Income'] / test['Total_Income']
train['Loan_Income_Ratio'] = train['Loan_Amount'] / train['Total_Income']
test['Loan_Income_Ratio'] = test['Loan_Amount'] / test['Total_Income']
train['Loan_Term_Ratio'] = train['Loan_Amount'] / train['Term']
test['Loan_Term_Ratio'] = test['Loan_Amount'] / test['Term']
train['Income_Term_Product'] = train['Total_Income'] * train['Term']
test['Income_Term_Product'] = test['Total_Income'] * test['Term']
def Education_Area_Interaction(dataFrame):
    Eduction_Encode = pandas.get_dummies(dataFrame['Education'], prefix='Education')
    Area_Encode = pandas.get_dummies(dataFrame['Area'], prefix='Area')
    for Education_Column in Eduction_Encode.columns:
        for Area_Column in Area_Encode.columns:
            dataFrame[f'{Education_Column}_X_{Area_Column}'] = Eduction_Encode[Education_Column] * Area_Encode[Area_Column]
    return dataFrame
train = Education_Area_Interaction(train)
test = Education_Area_Interaction(test)
def Dependents_Education_Interaction(dataFrame):
    Dependents_Encode = pandas.get_dummies(dataFrame['Dependents'], prefix='Dependents')
    Education_Encode = pandas.get_dummies(dataFrame['Education'], prefix='Education')
    for Dependents_Column in Dependents_Encode.columns:
        for Education_Column in Education_Encode.columns:
            dataFrame[f'{Dependents_Column}_X_{Education_Column}'] = Dependents_Encode[Dependents_Column] * Education_Encode[Education_Column]
    return dataFrame
train = Dependents_Education_Interaction(train)
test = Dependents_Education_Interaction(test)

categorical_variables = ['Gender', 'Married', 'Dependents', 'Education', 'Self_Employed', 'Credit_History', 'Area'] + [column for column in train.columns if '_X_' in column]
encoder = OneHotEncoder()
all_data = pandas.concat([train, test], axis=0)
all_data_encoded = encoder.fit_transform(all_data[categorical_variables])
train_encoded = all_data_encoded[:train.shape[0]]
test_encoded = all_data_encoded[train.shape[0]:]

numerical_variables = ['Applicant_Income', 'Coapplicant_Income', 'Loan_Amount', 'Term', 'Total_Income', 'Applicant_Proportion', 'Loan_Income_Ratio', 'Loan_Term_Ratio', 'Income_Term_Product']
scaler = MinMaxScaler()
all_data_scaled = scaler.fit_transform(all_data[numerical_variables])
train_scaled = all_data_scaled[:train.shape[0]]
test_scaled = all_data_scaled[train.shape[0]:]

train_processed = numpy.hstack((train_encoded.toarray(), train_scaled))
test_processed = numpy.hstack((test_encoded.toarray(), test_scaled))

model = LogisticRegression()
model.fit(train_processed, train['Status'])
print(model.score(train_processed, train['Status']))
predictions = model.predict(test_processed)
submission = pandas.DataFrame({'id': test['id'], 'Status': predictions})
submission.to_csv('/kaggle/working/submission.csv', index=False)