<jupyter_start><jupyter_text>Model<jupyter_code>params = {
#     'C':[0.05,0.5,0.8,1,1.5]
}
clf = LogisticRegression(fit_intercept=True,random_state=123,max_iter=1000)
model = GridSearchCV(clf,param_grid=params)
model = model.fit(X_train,y_train)
model.score(X_train,y_train)
# model.score(X_test,y_test)
f1_score(y_test,model.predict(X_test))
f1_score(y_train,model.predict(X_train))
import matplotlib.pyplot as plt
from pdpbox import pdp, get_dataset, info_plots

# Create the data that we will plot
pdp_goals = pdp.pdp_isolate(model=model, dataset=val_X, model_features=feature_names, feature='Goal Scored')

# plot it
pdp.pdp_plot(pdp_goals, 'Goal Scored')
plt.show()
params= {
    "n_estimators" : [20,50,100,150],
    "max_depth" : [2,3,5,6],
}
clf_forest = RandomForestClassifier()
model_forest = GridSearchCV(clf_forest,param_grid=params,cv=4)
model_forest.fit(X_train,y_train)
f1_score(y_train,model_forest.predict(X_train))
f1_score(y_test,model_forest.predict(X_test))
model_forest.best_estimator_
#0.8746, 0.877256
#test train
# 0.87 0.86     property_area, credit_history, totalincome
# 
pd.DataFrame(zip(X_train.columns,model_forest.best_estimator_.feature_importances_)).sort_values(by=[1],ascending=False).rename(columns = {0:"Feature",1:"Score"})
from sklearn.inspection import permutation_importance
r = permutation_importance(model_forest, X_test, y_test,
                           n_repeats=30,
                           random_state=0)
for i in r.importances_mean.argsort()[::-1]:
    if r.importances_mean[i] - 2 * r.importances_std[i] > 0:
        print(f"{X_train.columns[i]:<8}"+"  "
              f"{r.importances_mean[i]:.3f}"
              f" +/- {r.importances_std[i]:.3f}")
r = permutation_importance(model, X_train, y_train,
                           n_repeats=30,
                           random_state=0)
for i in r.importances_mean.argsort()[::-1]:
    if r.importances_mean[i] - 2 * r.importances_std[i] > 0:
        print(f"{X_train.columns[i]:<8}"+"  "
              f"{r.importances_mean[i]:.3f}"
              f" +/- {r.importances_std[i]:.3f}")<jupyter_output>Credit_History_1.0  0.060 +/- 0.012
Credit_History_0.0  0.060 +/- 0.012
Property_Area_Rural  0.004 +/- 0.002
{'fraction_non_alphanumeric': 0.14737793851717904, 'fraction_numerical': 0.04656419529837252, 'mean_word_length': 4.1465116279069765, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '643317', 'license': 'MIT', 'n_tokens_mistral': 947, 'n_tokens_neox': 875, 'n_words': 115, 'path': 'notebooks/4_Modelling.ipynb', 'repo_name': 'vamsidhar-reddy-rajula/loan-approval', 'size': '2212'}