0% found this document useful (0 votes)
43 views2 pages

Lab6 Writeup

This document describes an experiment using the Wisconsin Breast Cancer dataset to measure the performance of a k-nearest neighbors (KNN) classifier. The data is split into training and testing sets, normalized, and a KNN model with k=3 is applied. The accuracy, sensitivity, specificity, and precision of the KNN classifier are then calculated and printed. The accuracy of the classifier is reported to be around 76%.

Uploaded by

Saurabh Jadhav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views2 pages

Lab6 Writeup

This document describes an experiment using the Wisconsin Breast Cancer dataset to measure the performance of a k-nearest neighbors (KNN) classifier. The data is split into training and testing sets, normalized, and a KNN model with k=3 is applied. The accuracy, sensitivity, specificity, and precision of the KNN classifier are then calculated and printed. The accuracy of the classifier is reported to be around 76%.

Uploaded by

Saurabh Jadhav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Bansilal RamnathAgarwal Charitable Trust’s

VISHWAKARMA INSTITUTE OF TECHNOLOGY – PUNE


Department of SY Common

MD2201: Data Science


Name of the student: Saurabh Jadhav Roll No. 27

Div: B Batch: B2

Date of performance: 17-12-2021

Experiment No.7

Title: Classifier Performance

Aim: To measure the different performance parameters of a classifier.

Software used: Programming language R.

Code Statement:

Apply KNN to the Wisconsin Breast Cancer data set . Split the data into training and testing
samples. Scale the data and find the following
1. Accuracy
2. Sensitivity
3. Specificity
4. Precision

Code: (Write code for above statements here)

# K-NN
library(class)
wbc = read.csv("wbc_csv.csv")
wbc$diagnosis = as.factor(wbc$diagnosis)
set.seed(123)
wbc = wbc[order(runif(569)),]

# normalize
wbc_mod = wbc[,3:32]
n2 = function(b){
(b-min(b)) / (max(b) - min(b))
}
wbc_new = as.data.frame (lapply(wbc_mod,n2))

# K-NN function
wbc_train = wbc_new[1:469,]
wbc_test = wbc_new[470:569,]
Bansilal RamnathAgarwal Charitable Trust’s
VISHWAKARMA INSTITUTE OF TECHNOLOGY – PUNE
Department of SY Common

wbc_train_label = wbc[1:469,2]
wbc_test_label = wbc[470:569,2] #actual
p = knn(wbc_train,wbc_test,wbc_train_label,k=3)
t = table(actual = wbc_test_label, predicted = p)
print(t)

ac1 = sum(diag(t)) / sum(t)


cat("\nAccuracy of classifier is :", ac1)
re = t[2,2] / sum(t[2,])
cat("\nRecall of classifier is :", re)
spe = t[1,1] / sum(t[1,])
cat("\nSpecificity of classifier is :", spe)
pre = t[2,2] / sum(t[,2])
cat("\nPrecision of classifier is :",pre)
sen = t[2,2] / sum(t[2,])
cat("\nSensitivity of classifier is :",sen)

Results: Display the output obtained on R console for all the cases.

Conclusion: (Write the conclusion in your words. Write the values you obtained for all metrics).

In this experiment we studied to measure the different performance parameters of a classifier


using the inbuilt functions in R on the Wisconsin Breast Cancer data set and calculated
Accuracy, Recall, Specificity, Precision and Sensitivity of the classifier.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy