text_plain_output_1.png
from sklearn.metrics import ConfusionMatrixDisplay, confusion_matrix, classification_report

from sklearn.metrics import roc_auc_score

from sklearn.tree import DecisionTreeClassifier

from sklearn.tree import DecisionTreeClassifier

import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

train = pd.read_csv('/kaggle/input/e-commerce-shoppers-behaviour-understanding/train_data_v2.csv')
test = pd.read_csv('/kaggle/input/e-commerce-shoppers-behaviour-understanding/test_data_v2.csv')

train.shape

train.columns

train.isna().sum()

var = train.corr()

from sklearn.metrics import roc_auc_score
from sklearn.metrics import ConfusionMatrixDisplay, confusion_matrix, classification_report
def get_metrics(classifier, Xvalid, yvalid):
    """Function to Get the metrics of the given Classifier"""
    y_train_pred = classifier.predict_proba(X_train)[:, 1]
    y_valid_pred = classifier.predict_proba(Xvalid)[:, 1]
    y_valid_predict = classifier.predict(Xvalid)
    cm = confusion_matrix(yvalid, y_valid_predict)
    dist = ConfusionMatrixDisplay(cm)

from sklearn.tree import DecisionTreeClassifier
dc = DecisionTreeClassifier()
dc.fit(X_train, y_train)
get_metrics(dc, X_valid, y_valid)

from sklearn.tree import DecisionTreeClassifier
dc = DecisionTreeClassifier(max_depth=4, criterion='gini', min_samples_split=2, min_samples_leaf=4)
dc.fit(X_train, y_train)
get_metrics(dc, X_valid, y_valid)