<jupyter_start><jupyter_text>DATA VISUALIZATION<jupyter_code>sns.countplot(x="Loan_Status", data=train)
sns.set(style="whitegrid")
plt.show()
sns.countplot(x="Gender",hue="Loan_Status",data=train)
sns.set(style="whitegrid")
plt.show()
sns.countplot(x="Married",hue="Loan_Status",data=train)
sns.set(style="whitegrid")
plt.show()
sns.countplot(x="Dependents",data=train)
sns.set(style="whitegrid")
plt.show()
sns.countplot(x="Self_Employed",data=train)
sns.set(style="whitegrid")
plt.show()
sns.countplot(x="Education",data=train)
sns.set(style="whitegrid")
plt.show()
sns.violinplot(x="ApplicantIncome",data=train)
sns.set(style="whitegrid")
plt.show()
sns.violinplot(x="CoapplicantIncome",data=train)
sns.set(style="whitegrid")
plt.show()
sns.violinplot(x="LoanAmount",data=train)
sns.set(style="whitegrid")
plt.show()
sns.countplot(x="Credit_History",data=train)
plt.show()
sns.countplot(x="Loan_Amount_Term",data=train)
plt.show()
sns.countplot(x="Property_Area",data=train)
plt.show()
train=train.fillna(train.mean())
train["Gender"].fillna( method ='ffill', inplace = True)
train["Married"].fillna( method ='ffill', inplace = True)
train["Dependents"].fillna( method ='ffill', inplace = True)
train["Self_Employed"].fillna( method ='ffill', inplace = True)
#train=train.dropna()
train.isnull().sum()<jupyter_output><empty_output><jupyter_text>DROPPING "Loan_Id" COLUMN AS IT IS UNIQUE AND DOESN'T DEPEND ON TARGET VARIABLE<jupyter_code>train=train.drop(['Loan_ID'],axis=1)<jupyter_output><empty_output><jupyter_text>DUMMIFYING THE CHARACTER CONTAINING COLUMNS AS THE ALOGIRTHM DOESN'T UNDERSTAND STRINGS ANS IT'S DEPENDENCY ON TARGET VARIABLE<jupyter_code>sex=pd.get_dummies(train['Gender'],drop_first=True)
marriage_status=pd.get_dummies(train['Married'],drop_first=True)
education_bg=pd.get_dummies(train['Education'],drop_first=True)
employee_st=pd.get_dummies(train['Self_Employed'],drop_first=True)
area=pd.get_dummies(train['Property_Area'],drop_first=True)
loan_st=pd.get_dummies(train['Loan_Status'],drop_first=True)
dep=pd.get_dummies(train['Dependents'],drop_first=True)<jupyter_output><empty_output><jupyter_text>JOINING THE DUMMIFIED VALUES TO OUR TRAIN DATA AND REMOVING THE ORIGINAL<jupyter_code>train=pd.concat([train,sex,marriage_status,education_bg,employee_st,area,loan_st,dep],axis=1)
train.head()
train.drop(['Gender','Married','Education','Self_Employed','Property_Area','Loan_Status','Dependents'],axis=1,inplace=True)
train.head()
x=train.drop("Y",axis=1)
y=train["Y"]<jupyter_output><empty_output><jupyter_text>IMPORTING THE REQUIRED LIBARARIES FOR LOGISTIC REGRESSION<jupyter_code>from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
from sklearn.metrics import accuracy_score
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.3,random_state=0)#spliting the data into train and test 30% of data for test
logmodel=LogisticRegression()
logmodel.fit(x_train,y_train)
predictions=logmodel.predict(x_test)
classification_report=(y_test,predictions)
print(accuracy_score(y_test,predictions)*100)
print(confusion_matrix(y_test,predictions))<jupyter_output>83.24324324324324
[[ 22  29]
 [  2 132]]<jupyter_text>AS ACCURACY IS 77.7 SO STANDARDIZING AND CHECKING THE ACCURACY<jupyter_code>from sklearn.preprocessing import StandardScaler
sc=StandardScaler()
x_train=sc.fit_transform(x_train)
x_test=sc.fit_transform(x_test)
logmodel=LogisticRegression()
logmodel.fit(x_train,y_train)
pred_sc=logmodel.predict(x_test)
classification_report=(y_test,predictions)
accuracy_score(y_test,pred_sc)*100<jupyter_output>C:\Users\AISHWARYA\Anaconda3\lib\site-packages\sklearn\linear_model\logistic.py:433: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)<jupyter_text>READING THE TEST DATASET AND PERFORMING THE PREPROCESSING AS DONE FOR THE TRAIN DATASET<jupyter_code>test=pd.read_csv("test.csv",header=0)
test.head()
print(test.shape)
test.isnull().sum()
test=test.fillna(test.mean())
test["Gender"].fillna( method ='ffill', inplace = True)
test["Married"].fillna( method ='ffill', inplace = True)
test["Dependents"].fillna( method ='ffill', inplace = True)
test["Self_Employed"].fillna( method ='ffill', inplace = True)
test.isnull().sum()
loan_test=test.iloc[:,[0]].values
loan_test=pd.DataFrame(loan_test)
loan_test.head()#storing only loan id<jupyter_output><empty_output><jupyter_text>GIVING A SERIES OF NUMBER IN COLUMN SO THAT AFTER PREDICTION WE REQUIRE A COMMON COLUMN TO MERGE THE PREDICTED WITH RESPECTIVE LOAN ID<jupyter_code>loan_test['ld_no']=pd.Series(range(0,367))
loan_test.columns= ['Loan_ID','id_no']
loan_test.tail()
sex_t=pd.get_dummies(test['Gender'],drop_first=True)
marriage_test=pd.get_dummies(test['Married'],drop_first=True)
education_test=pd.get_dummies(test['Education'],drop_first=True)
employee_test=pd.get_dummies(test['Self_Employed'],drop_first=True)
areat=pd.get_dummies(test['Property_Area'],drop_first=True)
dept=pd.get_dummies(test['Dependents'],drop_first=True)
test=pd.concat([test,sex_t,marriage_test,education_test,employee_test,areat,dept],axis=1)
test.drop(['Loan_ID','Gender','Married','Education','Self_Employed','Property_Area','Dependents'],axis=1,inplace=True)
test.head()
print(test.shape)
test=sc.fit_transform(test)
test_pred=logmodel.predict(test)#predicting for test datset and storing in test_pred
test_pred=pd.DataFrame(test_pred)#converting into dataframe
test_pred.columns= ['loan_status']
test_pred['Loan_Status']='null'<jupyter_output><empty_output><jupyter_text>CONVERTING DUMMIFIED LOAN STATUS TO NORMAL BY IF CONDITION<jupyter_code>for i in range (0,367):
    if (test_pred['loan_status'][i]==1):
        test_pred['Loan_Status'][i]="Y"
    else:
        test_pred['Loan_Status'][i]="N"
test_pred.head()
test_pred=test_pred.drop(['loan_status'],axis=1)#dropping the column of 0 and 1
test_pred['id_no']= pd.Series(range(0,368))#creating a column so that we can merge based on common column 
test_pred=pd.merge(loan_test,test_pred,how="outer",on="id_no")
test_pred=test_pred.drop(['id_no'],axis=1)#dropping the column as we have merged
test_pred.head()
test_pred.iloc[:,[0,1]].to_csv('sample_submission.csv',index = False)#writing the predicted into a csv file<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14752305047663697, 'fraction_numerical': 0.011251758087201125, 'mean_word_length': 11.524461839530332, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '538708', 'license': 'Apache-2.0', 'n_tokens_mistral': 2526, 'n_tokens_neox': 2418, 'n_words': 343, 'path': 'loan-checkpoint.ipynb', 'repo_name': 'BOLLOJUAISHWARYA/Loan-status-prediction', 'size': '6399'}