You are on page 1of 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