Expt 5
Expt 5
Div: C Batch: 2
Experiment No.5
Title: Classifier.
Code Statement:
Consider 18 points data set referred in theory class. Consider test sample P(3,2). Apply following
algorithms to find the class of this test point.
i. NN
ii. KNN with K=5 and K=7.
iii. R-NN Radius based algorithm with radius as 1.45 units.
iv. MKNN with K=5
Code:
data = read.csv("knn1_csv.csv")
f1 = cbind(data,eucld)
sortedData = f1[order(f1$eucld),]
df5 = sortedData[1:5,]
l1 = sum(df5$class == 1)
l2 = sum(df5$class == 2)
l3 = sum(df5$class == 3)
Bansilal RamnathAgarwal Charitable Trust’s
VISHWAKARMA INSTITUTE OF TECHNOLOGY – PUNE
Department of SY Common
df = sortedData[1:7,]
l1 = sum(df$class == 1)
l2 = sum(df$class == 2)
l3 = sum(df$class == 3)
#Rnn
#MKNN
d5 = max(df5$eucld)
Bansilal RamnathAgarwal Charitable Trust’s
VISHWAKARMA INSTITUTE OF TECHNOLOGY – PUNE
d1 = min(df5$eucld) Department of SY Common
w = (d5 - df5$eucld)/(d5-d1)
dfw = cbind(df5,w)
w1 = sum(dfw$w[dfw$class == 1])
w2 = sum(dfw$w[dfw$class == 2])
w3 = sum(dfw$w[dfw$class == 3])
Results:
Conclusion: