<jupyter_start><jupyter_text>I'd like to remove the null values for LoanAmount. As the plot shows, the distribution has a long tail. I think that the mean might be biases because of that.In that sense, I think that the median would be a better guess<jupyter_code>df['LoanAmount'].fillna(df['LoanAmount'].median(), inplace=True)
df['has_Credit_History'].hist()
plt.show()
df['has_Credit_History'].fillna(1, inplace=True)
df['Property_Area'].unique()
df = pd.get_dummies(df, columns=['Property_Area'])
# from matplotlib.colors import 
# my_cmap = [cores]
# my_cmap = ListedColormap(sns.color_palette(my_cmap).as_hex())
# sns.heatmap(df.corr(), cmap=my_cmap)
plt.figure(figsize=[17, 10])
sns.heatmap(df.corr().abs(), annot=True, cmap="Reds")
plt.show()
df["TotalIncome"] = df['ApplicantIncome'] + df['CoapplicantIncome']
df['ApplicantIncome'] = np.log(df['ApplicantIncome'])
df.loc[df['CoapplicantIncome'] == 0, 'CoapplicantIncome'] = 1
df['CoapplicantIncome'] = np.log(df['CoapplicantIncome'])
df['TotalIncome'] = np.log(df['TotalIncome'])<jupyter_output><empty_output><jupyter_text>Begining training<jupyter_code>X = df.drop("Loan_Status", axis=1)
y = df['Loan_Status']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)<jupyter_output><empty_output><jupyter_text>Logistic Regression<jupyter_code>lr = LogisticRegression()
lr.fit(X_train, y_train)
print("Score in train set: {0:.2%}".format(lr.score(X_train, y_train)))
print("Score in test set: {0:.2%}".format(lr.score(X_test, y_test)))<jupyter_output>Score in train set: 80.20%
Score in test set: 82.18%<jupyter_text>Decision Tree<jupyter_code>dt = DecisionTreeClassifier()
dt.fit(X_train, y_train, )

print("Score in train set: {0:.2%}".format(dt.score(X_train, y_train)))
print("Score in test set: {0:.2%}".format(dt.score(X_test, y_test)))<jupyter_output>Score in train set: 100.00%
Score in test set: 71.78%<jupyter_text>Clearly overfitted. Lets limit depth to avoid this problem<jupyter_code>dt = DecisionTreeClassifier(max_depth=4)
dt.fit(X_train, y_train)

print("Score in train set: {0:.2%}".format(dt.score(X_train, y_train)))
print("Score in test set: {0:.2%}".format(dt.score(X_test, y_test)))<jupyter_output>Score in train set: 82.64%
Score in test set: 83.17%<jupyter_text>Random Forest<jupyter_code>rf = RandomForestClassifier(n_estimators = 100, random_state=42)
rf.fit(X_train, y_train)

print("Score in train set: {0:.2%}".format(dt.score(X_train, y_train)))
print("Score in test set: {0:.2%}".format(dt.score(X_test, y_test)))<jupyter_output>Score in train set: 82.64%
Score in test set: 83.17%<jupyter_text>Best one was decision tree.<jupyter_code>X_test['Loan_Status'] = dt.predict(X_test)
X_test.head()
X_test.to_csv("clientes_previstos.csv", index=False)<jupyter_output><empty_output><jupyter_text>Exporting model to file<jupyter_code>import pickle
pickle.dump(dt, open('modelo.sav', 'wb'))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16359918200409, 'fraction_numerical': 0.023176550783912748, 'mean_word_length': 8.347133757961783, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '336063', 'license': 'MIT', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1151, 'n_words': 216, 'path': 'projeto_emprestimo/Loan Prediction.ipynb', 'repo_name': 'semaraugusto/Projetos-Data-Science', 'size': '2934'}