src/03_modelling/011_modelling.py
def evaluate_model(model, X_train=X_train, X_test=X_valid,
                       y_train=y_train, y_test=y_valid, verbose=True):
        """
        This function prints train and test accuracies,
        classification report, and confusion matrix.
        """
        model.fit(X_train, y_train)
        train_acc = model.score(X_train, y_train)
        test_acc = model.score(X_test, y_test)

        if verbose:
            print("Train Accuracy:", train_acc)
            print("Validation Accuracy", test_acc, "\n")

            print(classification_report(y_test, model.predict(X_test)))
            print(plot_confusion_matrix(model, X_test, y_test,
                                        display_labels=[0, 1],
                                        cmap=plt.cm.Blues,
                                        values_format='d'))
        else:
            report = {}
            f1 = f1_score(y_test, model.predict(X_test))
            recall = recall_score(y_test, model.predict(X_test))
            precision = precision_score(y_test, model.predict(X_test))
            report['renewed'] = [f1, recall, precision]

            f1 = f1_score(y_test, model.predict(X_test), pos_label=0)
            recall = recall_score(y_test, model.predict(X_test), pos_label=0)
            precision = precision_score(
                y_test, model.predict(X_test), pos_label=0)
            report['not_renewed'] = [f1, recall, precision]

            report['accuracy'] = [train_acc, test_acc]

            return report

        This function prints train and test accuracies,
        classification report, and confusion matrix.
        
This function prints train and test accuracies,
classification report, and confusion matrix.
This function prints train and test accuracies classification report and confusion matrix .
def evaluate_model(model, X_train=X_train, X_test=X_valid,
                       y_train=y_train, y_test=y_valid, verbose=True):
        model.fit(X_train, y_train)
        train_acc = model.score(X_train, y_train)
        test_acc = model.score(X_test, y_test)
        if verbose:
            print("Train Accuracy:", train_acc)
            print("Validation Accuracy", test_acc, "\n")
            print(classification_report(y_test, model.predict(X_test)))
            print(plot_confusion_matrix(model, X_test, y_test,
                                        display_labels=[0, 1],
                                        cmap=plt.cm.Blues,
                                        values_format='d'))
        else:
            report = {}
            f1 = f1_score(y_test, model.predict(X_test))
            recall = recall_score(y_test, model.predict(X_test))
            precision = precision_score(y_test, model.predict(X_test))
            report['renewed'] = [f1, recall, precision]
            f1 = f1_score(y_test, model.predict(X_test), pos_label=0)
            recall = recall_score(y_test, model.predict(X_test), pos_label=0)
            precision = precision_score(
                y_test, model.predict(X_test), pos_label=0)
            report['not_renewed'] = [f1, recall, precision]
            report['accuracy'] = [train_acc, test_acc]
            return report
def evaluate_model ( model , X_train = X_train , X_test = X_valid , y_train = y_train , y_test = y_valid , verbose = True ) : model . fit ( X_train , y_train ) train_acc = model . score ( X_train , y_train ) test_acc = model . score ( X_test , y_test ) if verbose : print ( "Train Accuracy:" , train_acc ) print ( "Validation Accuracy" , test_acc , "\n" ) print ( classification_report ( y_test , model . predict ( X_test ) ) ) print ( plot_confusion_matrix ( model , X_test , y_test , display_labels = [ 0 , 1 ] , cmap = plt . cm . Blues , values_format = 'd' ) ) else : report = { } f1 = f1_score ( y_test , model . predict ( X_test ) ) recall = recall_score ( y_test , model . predict ( X_test ) ) precision = precision_score ( y_test , model . predict ( X_test ) ) report [ 'renewed' ] = [ f1 , recall , precision ] f1 = f1_score ( y_test , model . predict ( X_test ) , pos_label = 0 ) recall = recall_score ( y_test , model . predict ( X_test ) , pos_label = 0 ) precision = precision_score ( y_test , model . predict ( X_test ) , pos_label = 0 ) report [ 'not_renewed' ] = [ f1 , recall , precision ] report [ 'accuracy' ] = [ train_acc , test_acc ] return report
This function prints train and test accuracies,
classification report, and confusion matrix.
This function prints train and test accuracies classification report and confusion matrix .
"""
        This function prints train and test accuracies,
        classification report, and confusion matrix.
        """
model
X_train
X_test
y_train
y_test
verbose