-
Notifications
You must be signed in to change notification settings - Fork 0
/
KNC_Testing.java
48 lines (41 loc) · 1.22 KB
/
KNC_Testing.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
##################################
# Weight | Texture | Label #
# 150g | Bumpy (0) | Orange (1)#
# 170g | Bumpy (0) | Orange (1)#
# 140g | Smooth (1)| Apple (0) #
# 130g | smooth (1)| Apple (0) #
##################################
*/
import java.util.Scanner;
public class KNC_Testing {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
//int features[][] = new int[4][2];
int features[][] = {
{150, 0},
{170, 0},
{140, 1},
{130, 1}
};
int labels[] = {1, 1, 0, 0};
int testFeatures[] = new int[2];
System.out.print("Enter mass: ");
testFeatures[0] = s.nextInt();
System.out.print("Enter texture: ");
String tex = s.next();
if(tex.equals("bumpy"))
testFeatures[1] = 0;
else if(tex.equals("smooth"))
testFeatures[1] = 1;
//It takes only two lines to train the classifier//
KNeighboursClassifier clf = new KNeighboursClassifier(4, 2);
clf.fit(features, labels);
//It takes only two lines to train the classifier//
if(clf.predict(testFeatures) == 0)
System.out.println("Its an orange.");
else
System.out.println("Its an apple.");
}
}