predict.sknn: Simple k Nearest Neighbours Classification

Description Usage Arguments Value Author(s) See Also Examples

View source: R/sknn.R

Description

Classifies new observations using the sknn learned by the sknn-function.

Usage

1
2
## S3 method for class 'sknn'
predict(object, newdata,...)

Arguments

object

Object of class sknn.

newdata

Data frame (or matrix) of cases to be classified.

...

...

Value

A list with elements ‘class’ and ‘posterior’.

Author(s)

Karsten Luebke, karsten.luebke@fom.de

See Also

sknn, knn

Examples

1
2
3
4
5
data(iris)
x <- sknn(Species ~ ., data = iris)
predict(x, iris)
x <- sknn(Species ~ ., gamma = 10, kn = 10, data = iris)
predict(x, iris)

Example output

Loading required package: MASS
$posterior
    setosa versicolor virginica
1        1  0.0000000 0.0000000
2        1  0.0000000 0.0000000
3        1  0.0000000 0.0000000
4        1  0.0000000 0.0000000
5        1  0.0000000 0.0000000
6        1  0.0000000 0.0000000
7        1  0.0000000 0.0000000
8        1  0.0000000 0.0000000
9        1  0.0000000 0.0000000
10       1  0.0000000 0.0000000
11       1  0.0000000 0.0000000
12       1  0.0000000 0.0000000
13       1  0.0000000 0.0000000
14       1  0.0000000 0.0000000
15       1  0.0000000 0.0000000
16       1  0.0000000 0.0000000
17       1  0.0000000 0.0000000
18       1  0.0000000 0.0000000
19       1  0.0000000 0.0000000
20       1  0.0000000 0.0000000
21       1  0.0000000 0.0000000
22       1  0.0000000 0.0000000
23       1  0.0000000 0.0000000
24       1  0.0000000 0.0000000
25       1  0.0000000 0.0000000
26       1  0.0000000 0.0000000
27       1  0.0000000 0.0000000
28       1  0.0000000 0.0000000
29       1  0.0000000 0.0000000
30       1  0.0000000 0.0000000
31       1  0.0000000 0.0000000
32       1  0.0000000 0.0000000
33       1  0.0000000 0.0000000
34       1  0.0000000 0.0000000
35       1  0.0000000 0.0000000
36       1  0.0000000 0.0000000
37       1  0.0000000 0.0000000
38       1  0.0000000 0.0000000
39       1  0.0000000 0.0000000
40       1  0.0000000 0.0000000
41       1  0.0000000 0.0000000
42       1  0.0000000 0.0000000
43       1  0.0000000 0.0000000
44       1  0.0000000 0.0000000
45       1  0.0000000 0.0000000
46       1  0.0000000 0.0000000
47       1  0.0000000 0.0000000
48       1  0.0000000 0.0000000
49       1  0.0000000 0.0000000
50       1  0.0000000 0.0000000
51       0  1.0000000 0.0000000
52       0  1.0000000 0.0000000
53       0  1.0000000 0.0000000
54       0  1.0000000 0.0000000
55       0  1.0000000 0.0000000
56       0  1.0000000 0.0000000
57       0  1.0000000 0.0000000
58       0  1.0000000 0.0000000
59       0  1.0000000 0.0000000
60       0  1.0000000 0.0000000
61       0  1.0000000 0.0000000
62       0  1.0000000 0.0000000
63       0  1.0000000 0.0000000
64       0  1.0000000 0.0000000
65       0  1.0000000 0.0000000
66       0  1.0000000 0.0000000
67       0  1.0000000 0.0000000
68       0  1.0000000 0.0000000
69       0  1.0000000 0.0000000
70       0  1.0000000 0.0000000
71       0  0.3333333 0.6666667
72       0  1.0000000 0.0000000
73       0  0.3333333 0.6666667
74       0  1.0000000 0.0000000
75       0  1.0000000 0.0000000
76       0  1.0000000 0.0000000
77       0  1.0000000 0.0000000
78       0  1.0000000 0.0000000
79       0  1.0000000 0.0000000
80       0  1.0000000 0.0000000
81       0  1.0000000 0.0000000
82       0  1.0000000 0.0000000
83       0  1.0000000 0.0000000
84       0  0.3333333 0.6666667
85       0  1.0000000 0.0000000
86       0  1.0000000 0.0000000
87       0  1.0000000 0.0000000
88       0  1.0000000 0.0000000
89       0  1.0000000 0.0000000
90       0  1.0000000 0.0000000
91       0  1.0000000 0.0000000
92       0  1.0000000 0.0000000
93       0  1.0000000 0.0000000
94       0  1.0000000 0.0000000
95       0  1.0000000 0.0000000
96       0  1.0000000 0.0000000
97       0  1.0000000 0.0000000
98       0  1.0000000 0.0000000
99       0  1.0000000 0.0000000
100      0  1.0000000 0.0000000
101      0  0.0000000 1.0000000
102      0  0.0000000 1.0000000
103      0  0.0000000 1.0000000
104      0  0.0000000 1.0000000
105      0  0.0000000 1.0000000
106      0  0.0000000 1.0000000
107      0  0.6666667 0.3333333
108      0  0.0000000 1.0000000
109      0  0.0000000 1.0000000
110      0  0.0000000 1.0000000
111      0  0.0000000 1.0000000
112      0  0.0000000 1.0000000
113      0  0.0000000 1.0000000
114      0  0.0000000 1.0000000
115      0  0.0000000 1.0000000
116      0  0.0000000 1.0000000
117      0  0.0000000 1.0000000
118      0  0.0000000 1.0000000
119      0  0.0000000 1.0000000
120      0  0.6666667 0.3333333
121      0  0.0000000 1.0000000
122      0  0.0000000 1.0000000
123      0  0.0000000 1.0000000
124      0  0.0000000 1.0000000
125      0  0.0000000 1.0000000
126      0  0.0000000 1.0000000
127      0  0.0000000 1.0000000
128      0  0.0000000 1.0000000
129      0  0.0000000 1.0000000
130      0  0.0000000 1.0000000
131      0  0.0000000 1.0000000
132      0  0.0000000 1.0000000
133      0  0.0000000 1.0000000
134      0  0.6666667 0.3333333
135      0  0.3333333 0.6666667
136      0  0.0000000 1.0000000
137      0  0.0000000 1.0000000
138      0  0.0000000 1.0000000
139      0  0.3333333 0.6666667
140      0  0.0000000 1.0000000
141      0  0.0000000 1.0000000
142      0  0.0000000 1.0000000
143      0  0.0000000 1.0000000
144      0  0.0000000 1.0000000
145      0  0.0000000 1.0000000
146      0  0.0000000 1.0000000
147      0  0.0000000 1.0000000
148      0  0.0000000 1.0000000
149      0  0.0000000 1.0000000
150      0  0.0000000 1.0000000

$class
  [1] setosa     setosa     setosa     setosa     setosa     setosa    
  [7] setosa     setosa     setosa     setosa     setosa     setosa    
 [13] setosa     setosa     setosa     setosa     setosa     setosa    
 [19] setosa     setosa     setosa     setosa     setosa     setosa    
 [25] setosa     setosa     setosa     setosa     setosa     setosa    
 [31] setosa     setosa     setosa     setosa     setosa     setosa    
 [37] setosa     setosa     setosa     setosa     setosa     setosa    
 [43] setosa     setosa     setosa     setosa     setosa     setosa    
 [49] setosa     setosa     versicolor versicolor versicolor versicolor
 [55] versicolor versicolor versicolor versicolor versicolor versicolor
 [61] versicolor versicolor versicolor versicolor versicolor versicolor
 [67] versicolor versicolor versicolor versicolor virginica  versicolor
 [73] virginica  versicolor versicolor versicolor versicolor versicolor
 [79] versicolor versicolor versicolor versicolor versicolor virginica 
 [85] versicolor versicolor versicolor versicolor versicolor versicolor
 [91] versicolor versicolor versicolor versicolor versicolor versicolor
 [97] versicolor versicolor versicolor versicolor virginica  virginica 
[103] virginica  virginica  virginica  virginica  versicolor virginica 
[109] virginica  virginica  virginica  virginica  virginica  virginica 
[115] virginica  virginica  virginica  virginica  virginica  versicolor
[121] virginica  virginica  virginica  virginica  virginica  virginica 
[127] virginica  virginica  virginica  virginica  virginica  virginica 
[133] virginica  versicolor virginica  virginica  virginica  virginica 
[139] virginica  virginica  virginica  virginica  virginica  virginica 
[145] virginica  virginica  virginica  virginica  virginica  virginica 
Levels: setosa versicolor virginica

$posterior
    setosa  versicolor  virginica
1        1 0.000000000 0.00000000
2        1 0.000000000 0.00000000
3        1 0.000000000 0.00000000
4        1 0.000000000 0.00000000
5        1 0.000000000 0.00000000
6        1 0.000000000 0.00000000
7        1 0.000000000 0.00000000
8        1 0.000000000 0.00000000
9        1 0.000000000 0.00000000
10       1 0.000000000 0.00000000
11       1 0.000000000 0.00000000
12       1 0.000000000 0.00000000
13       1 0.000000000 0.00000000
14       1 0.000000000 0.00000000
15       1 0.000000000 0.00000000
16       1 0.000000000 0.00000000
17       1 0.000000000 0.00000000
18       1 0.000000000 0.00000000
19       1 0.000000000 0.00000000
20       1 0.000000000 0.00000000
21       1 0.000000000 0.00000000
22       1 0.000000000 0.00000000
23       1 0.000000000 0.00000000
24       1 0.000000000 0.00000000
25       1 0.000000000 0.00000000
26       1 0.000000000 0.00000000
27       1 0.000000000 0.00000000
28       1 0.000000000 0.00000000
29       1 0.000000000 0.00000000
30       1 0.000000000 0.00000000
31       1 0.000000000 0.00000000
32       1 0.000000000 0.00000000
33       1 0.000000000 0.00000000
34       1 0.000000000 0.00000000
35       1 0.000000000 0.00000000
36       1 0.000000000 0.00000000
37       1 0.000000000 0.00000000
38       1 0.000000000 0.00000000
39       1 0.000000000 0.00000000
40       1 0.000000000 0.00000000
41       1 0.000000000 0.00000000
42       1 0.000000000 0.00000000
43       1 0.000000000 0.00000000
44       1 0.000000000 0.00000000
45       1 0.000000000 0.00000000
46       1 0.000000000 0.00000000
47       1 0.000000000 0.00000000
48       1 0.000000000 0.00000000
49       1 0.000000000 0.00000000
50       1 0.000000000 0.00000000
51       0 1.000000000 0.00000000
52       0 1.000000000 0.00000000
53       0 1.000000000 0.00000000
54       0 1.000000000 0.00000000
55       0 1.000000000 0.00000000
56       0 1.000000000 0.00000000
57       0 0.911090325 0.08890968
58       0 1.000000000 0.00000000
59       0 1.000000000 0.00000000
60       0 1.000000000 0.00000000
61       0 1.000000000 0.00000000
62       0 1.000000000 0.00000000
63       0 1.000000000 0.00000000
64       0 0.889673791 0.11032621
65       0 1.000000000 0.00000000
66       0 1.000000000 0.00000000
67       0 1.000000000 0.00000000
68       0 1.000000000 0.00000000
69       0 0.956900725 0.04309928
70       0 1.000000000 0.00000000
71       0 0.514171530 0.48582847
72       0 1.000000000 0.00000000
73       0 0.585846716 0.41415328
74       0 1.000000000 0.00000000
75       0 1.000000000 0.00000000
76       0 1.000000000 0.00000000
77       0 0.988814993 0.01118501
78       0 0.770878873 0.22912113
79       0 0.960284271 0.03971573
80       0 1.000000000 0.00000000
81       0 1.000000000 0.00000000
82       0 1.000000000 0.00000000
83       0 1.000000000 0.00000000
84       0 0.399908335 0.60009167
85       0 1.000000000 0.00000000
86       0 0.971220874 0.02877913
87       0 1.000000000 0.00000000
88       0 1.000000000 0.00000000
89       0 1.000000000 0.00000000
90       0 1.000000000 0.00000000
91       0 1.000000000 0.00000000
92       0 0.969119486 0.03088051
93       0 1.000000000 0.00000000
94       0 1.000000000 0.00000000
95       0 1.000000000 0.00000000
96       0 1.000000000 0.00000000
97       0 1.000000000 0.00000000
98       0 1.000000000 0.00000000
99       0 1.000000000 0.00000000
100      0 1.000000000 0.00000000
101      0 0.000000000 1.00000000
102      0 0.071495668 0.92850433
103      0 0.000000000 1.00000000
104      0 0.000000000 1.00000000
105      0 0.000000000 1.00000000
106      0 0.000000000 1.00000000
107      0 0.010968272 0.98903173
108      0 0.000000000 1.00000000
109      0 0.000000000 1.00000000
110      0 0.000000000 1.00000000
111      0 0.063882748 0.93611725
112      0 0.000000000 1.00000000
113      0 0.000000000 1.00000000
114      0 0.019669958 0.98033004
115      0 0.000000000 1.00000000
116      0 0.000000000 1.00000000
117      0 0.000000000 1.00000000
118      0 0.000000000 1.00000000
119      0 0.000000000 1.00000000
120      0 0.199678914 0.80032109
121      0 0.000000000 1.00000000
122      0 0.030101848 0.96989815
123      0 0.000000000 1.00000000
124      0 0.150980979 0.84901902
125      0 0.000000000 1.00000000
126      0 0.000000000 1.00000000
127      0 0.122582095 0.87741791
128      0 0.202743657 0.79725634
129      0 0.000000000 1.00000000
130      0 0.000000000 1.00000000
131      0 0.000000000 1.00000000
132      0 0.000000000 1.00000000
133      0 0.000000000 1.00000000
134      0 0.319062468 0.68093753
135      0 0.041952968 0.95804703
136      0 0.000000000 1.00000000
137      0 0.000000000 1.00000000
138      0 0.000000000 1.00000000
139      0 0.290214364 0.70978564
140      0 0.000000000 1.00000000
141      0 0.000000000 1.00000000
142      0 0.006776379 0.99322362
143      0 0.071495668 0.92850433
144      0 0.000000000 1.00000000
145      0 0.000000000 1.00000000
146      0 0.000000000 1.00000000
147      0 0.112261876 0.88773812
148      0 0.054661231 0.94533877
149      0 0.000000000 1.00000000
150      0 0.157772529 0.84222747

$class
  [1] setosa     setosa     setosa     setosa     setosa     setosa    
  [7] setosa     setosa     setosa     setosa     setosa     setosa    
 [13] setosa     setosa     setosa     setosa     setosa     setosa    
 [19] setosa     setosa     setosa     setosa     setosa     setosa    
 [25] setosa     setosa     setosa     setosa     setosa     setosa    
 [31] setosa     setosa     setosa     setosa     setosa     setosa    
 [37] setosa     setosa     setosa     setosa     setosa     setosa    
 [43] setosa     setosa     setosa     setosa     setosa     setosa    
 [49] setosa     setosa     versicolor versicolor versicolor versicolor
 [55] versicolor versicolor versicolor versicolor versicolor versicolor
 [61] versicolor versicolor versicolor versicolor versicolor versicolor
 [67] versicolor versicolor versicolor versicolor versicolor versicolor
 [73] versicolor versicolor versicolor versicolor versicolor versicolor
 [79] versicolor versicolor versicolor versicolor versicolor virginica 
 [85] versicolor versicolor versicolor versicolor versicolor versicolor
 [91] versicolor versicolor versicolor versicolor versicolor versicolor
 [97] versicolor versicolor versicolor versicolor virginica  virginica 
[103] virginica  virginica  virginica  virginica  virginica  virginica 
[109] virginica  virginica  virginica  virginica  virginica  virginica 
[115] virginica  virginica  virginica  virginica  virginica  virginica 
[121] virginica  virginica  virginica  virginica  virginica  virginica 
[127] virginica  virginica  virginica  virginica  virginica  virginica 
[133] virginica  virginica  virginica  virginica  virginica  virginica 
[139] virginica  virginica  virginica  virginica  virginica  virginica 
[145] virginica  virginica  virginica  virginica  virginica  virginica 
Levels: setosa versicolor virginica

klaR documentation built on March 26, 2020, 5:50 p.m.

Related to predict.sknn in klaR...