Python You can import any data you want. Using default hyperparameters: 1. Construct Naive Bayes (NB) models on the training set.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Python

You can import any data you want.

Using default hyperparameters:

1. Construct Naive Bayes (NB) models on the training set.

2. Calculate the confusion matrix and report the following performance metrics on the training set: Accuracy, F1 Score, AUC, Sensitivity, Specificity, and Precision.

You can use the function p1_metrics for this purpose.

3. Calculate the same metrics by applying the trained model to the validation set. Compare and contrast the errors each model makes in terms of each class.

 

#peformance metric functions

from sklearn.metrics import confusion_matrix, roc_auc_score, f1_score

import numpy as np

 

#A list of keys for the dictionary returned by p1_metrics

metric_keys = ['auc','f1','accuracy','sensitivity','specificity', 'precision']

 

def p1_metrics(y_true,y_pred,include_cm=True):

cm = confusion_matrix(y_true,y_pred)

tn, fp, fn, tp = cm.ravel()

if include_cm:

return {

'auc': roc_auc_score(y_true,y_pred),

'f1': f1_score(y_true,y_pred),

'accuracy': (tp+tn)/np.sum(cm),

'sensitivity': tp/(tp+fn),

'specificity': tn/(tn+fp),

'precision': tp/(tp+fp),

'confusion_matrix': cm}

else:

return {

'auc': roc_auc_score(y_true,y_pred),

'f1': f1_score(y_true,y_pred),

'accuracy': (tp+tn)/np.sum(cm),

'sensitivity': tp/(tp+fn),

'specificity': tn/(tn+fp),

'precision': tp/(tp+fp)}

 

#This wrapper can be used to return multiple performance metrics during cross-validation

def p1_metrics_scorer(clf,X,y_true):

y_pred=clf.predict(X)

return p1_metrics(y_true,y_pred,include_cm=False)

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Computational Systems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY