Question
in the following R program, the plot is not fully satisfactory. Find a way to shade the red region, say, rather than show it as
in the following R program, the plot is not fully satisfactory.
Find a way to shade the red region, say, rather than show it as red crosses.
Then there will be no need to show the green region - it will just be white.
Try making other improvements as they occur to you, such as including a legend or distinguishing data points which were misclassified!
NewProbeKnnBig =
function (TrialX, ProbeX, TrialY, k)
{
library(class)
ProbeYhat = knn(TrialX,ProbeX,TrialY,k)
MinX = min(TrialX)
MaxX = max(TrialX)
ProbeColor = c(cbind(ProbeYhat)+1)
plot(ProbeX[,1],ProbeX[,2],
main=c("knn Classification Space", k),
xlab="X1",ylab="X2",
cex=2, pch=3,
col=ProbeColor,
xlim=c(MinX,MaxX),
ylim=c(MinX,MaxX))
par(new=TRUE)
plot(TrialX[,1],TrialX[,2],
ann=FALSE,
pch=".",
col=c(cbind(TrialY)+17),
xlim=c(MinX,MaxX),
ylim=c(MinX,MaxX),
cex=2)
return()
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started