image_output_1.png
from sklearn.ensemble import RandomForestClassifier

from sklearn.linear_model import LogisticRegression

from sklearn.metrics import plot_confusion_matrix

import matplotlib.pyplot as plt

import pandas as pd

df = pd.read_csv('../input/kasco-dataset-russian/Задача 1/Прогнозирование пролонгации/Данные для задачи.txt', sep=';')

logmodel = LogisticRegression(fit_intercept=True)
logmodel.max_iter = 1000
logit_result = logmodel.fit(X_train, Y_train)
ylm_predicted = logit_result.predict(X_test)

rf_clf = RandomForestClassifier(bootstrap=False)
result_clf = rf_clf.fit(X_train, Y_train)
yrf_predicted = rf_clf.predict(X_test)

imp = pd.DataFrame(rf_clf.feature_importances_, index=X_test.columns, columns=['POLICY_PRICE_CHANGE'])
imp.sort_values('POLICY_PRICE_CHANGE').plot(kind='barh', figsize=(12, 8))

titles_options = [('Normalized cm in log regression', 'true')]
for title, normalize in titles_options:
    disp = plot_confusion_matrix(logmodel, X_test, Y_test, cmap=plt.cm.Blues, normalize=normalize)
    disp.ax_.set_title(title)
    print(title)
    print(disp.confusion_matrix)
plt.show()