训练集
trainSample <- cbind(data[1:980,1], data[1:980,2]) cl <-
factor(c(data[1:980,3]))
Run Code Online (Sandbox Code Playgroud)
测试集
testSample <- data(data[981:1485,1], data[981:1485,2])
cl.test <- clknn
Run Code Online (Sandbox Code Playgroud)
预测
k <- knn(trainSample, testSample, cl, k = 5)
Run Code Online (Sandbox Code Playgroud)
产量
< k
[1] 2 2 1 1 1 1 2 1 2 1 1 2 2 2 2 2 1 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 1 1 2 2 1 1 2 2 2 2 1 2 2 2 2 2 2 1 2 …Run Code Online (Sandbox Code Playgroud) 这是我的data.frame的一个小样本
naiveBayesPrediction knnPred5 knnPred10 dectreePrediction logressionPrediction correctClass
1 non-bob 2 2 non-bob 0.687969711847463 1
2 non-bob 2 2 non-bob 0.85851872253358 1
3 non-bob 1 1 non-bob 0.500470892627383 1
4 non-bob 1 1 non-bob 0.77762739066215 1
5 non-bob 1 2 non-bob 0.556431439357365 1
6 non-bob 1 2 non-bob 0.604868385598237 1
7 non-bob 2 2 non-bob 0.554624186182919 1
Run Code Online (Sandbox Code Playgroud)
我考虑了一切
'data.frame': 505 obs. of 6 variables:
$ naiveBayesPrediction: Factor w/ 2 levels "bob","non-bob": 2 2 2 2 2 2 2 2 2 2 …Run Code Online (Sandbox Code Playgroud) 作为一般惯例,静态方法是否应该从具有实例方法的类中分离为另一个类?
你的理由还有一个例子吗?