25 lines
		
	
	
		
			539 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			25 lines
		
	
	
		
			539 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
var data = [
 | 
						|
  {a:0, b:0, c:0, y:'A'}, 
 | 
						|
  {a:0, b:1, c:1, y:'A'}, 
 | 
						|
  {a:1, b:1, c:0, y:'B'}, 
 | 
						|
  {a:2, b:2, c:2, y:'B'}, 
 | 
						|
  {a:1, b:2, c:2, y:'C'}, 
 | 
						|
  {a:2, b:1, c:2, y:'C'}
 | 
						|
  ];
 | 
						|
var model = ml.learn({
 | 
						|
  algorithm:ml.ML.DT,
 | 
						|
  data:data, 
 | 
						|
  target:'y',
 | 
						|
  features:['a','b','c'],
 | 
						|
  eps:0.2
 | 
						|
});
 | 
						|
print(toJSON(model).length+' Bytes')
 | 
						|
 | 
						|
var test_data =[{a:0, b:1.2, c:0},
 | 
						|
                {a:2.1, b:2, c:3},
 | 
						|
                {a:2.1, b:1.1, c:2.0}];
 | 
						|
 | 
						|
print(ml.print(model))
 | 
						|
print(ml.classify(model,test_data))
 | 
						|
print(ml.classify(model,{a:1,b:2,c:3}))
 |