<jupyter_start><jupyter_text><jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

bank = pd.read_csv("bank.csv")
bank.head()
bank.info()
bank.dtypes
bank.describe().transpose()
bank.describe().transpose()
bank.apply(lambda x : sum(x.isnull()) )
bank.apply(lambda x: len(x.unique()))
bank[bank <0] =0
import math
median_Experience = math.floor(bank.Experience.median())
median_Experience
bank.Experience = bank.Experience.fillna(median_Experience)
bank.head()
corr = bank.corr()
corr
sns.set_context("notebook", font_scale=1.0, rc={"lines.linewidth": 2.5})
plt.figure(figsize=(15,7))
mask = np.zeros_like(corr)
mask[np.triu_indices_from(mask, 1)] = True
a = sns.heatmap(corr,mask=mask, annot=True, fmt='.2f')
rotx = a.set_xticklabels(a.get_xticklabels(), rotation=90)
roty = a.set_yticklabels(a.get_yticklabels(), rotation=30)
plt.figure(figsize=(15,5))

sns.distplot(bank.Age  ,color="r")

plt.figure(figsize=(20,6))
sns.lineplot(x="Age" , y="Personal Loan" , hue="Family" ,data=bank  )

plt.figure(figsize=(20,6))
sns.lineplot(x="Age" , y="Mortgage" , hue="Family" ,data=bank  )

variant = bank[["Experience","Income","Mortgage"]].groupby(bank.Age).sum()
variant.plot(kind='line', fontsize = 14, figsize=(18,5))
plt.figure(figsize=(17,5))
sns.lineplot(x="Age" , y="Income" ,hue="Family" ,data=bank)
sns.factorplot('Age','Income',data=bank,
                   hue='Family',
                   size=15,
                   aspect=0.7,
                   palette='Blues',
                   join=False,
              )
bank.drop(["ID"],axis=1,inplace=True)
bank.head()
X = bank.drop("Personal Loan",axis=1)
y = bank["Personal Loan"]
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4, random_state=0)
from sklearn.linear_model import LogisticRegression
logmodel = LogisticRegression()
logmodel.fit(X_train,y_train)
y_prediction = logmodel.predict(X_test)
y_prediction
from sklearn.metrics import classification_report
classification_report(y_test,y_prediction)
from sklearn.metrics import confusion_matrix
confusion_matrix(y_test,y_prediction)
from sklearn.tree import DecisionTreeClassifier
loan_entropy = DecisionTreeClassifier(criterion="entropy" , random_state=2000 , max_depth=5 , min_samples_leaf=5 )
loan_entropy.fit(X_train,y_train)
loan_classifier = DecisionTreeClassifier(max_leaf_nodes=5,random_state=2000)
loan_classifier.fit(X_train,y_train)
y_pre = loan_classifier.predict(X_test)
Y_predi = loan_entropy.predict(X_test)
Y_predi
y_pre
from sklearn.metrics import accuracy_score
accuracy_score(y_test,y_pre)
accuracy_score(y_test,Y_predi)
confusion_matrix(y_test,y_pre)
confusion_matrix(y_test,Y_predi)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14332129963898918, 'fraction_numerical': 0.018772563176895306, 'mean_word_length': 6.330687830687831, 'pattern_counts': {'":': 1, '<': 6, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '87850', 'license': 'MIT', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1023, 'n_words': 161, 'path': 'bank_loan_prediction.ipynb', 'repo_name': 'sahilmerai/ml_basic', 'size': '2770'}