24 lines
		
	
	
		
			628 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
		
		
			
		
	
	
			24 lines
		
	
	
		
			628 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| 
								 | 
							
								var data = load('test-data-iris.json')
							 | 
						||
| 
								 | 
							
								var datac = ml.preprocess(data,'xmy',{features:['length','width','petal_length','petal_width'],
							 | 
						||
| 
								 | 
							
								                                      target:'species'});
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								var x = datac.x;
							 | 
						||
| 
								 | 
							
								var y = datac.y;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								var t0=time()
							 | 
						||
| 
								 | 
							
								var model = ml.learn({
							 | 
						||
| 
								 | 
							
								  algorithm:ml.ML.ICE,
							 | 
						||
| 
								 | 
							
								  x:x, 
							 | 
						||
| 
								 | 
							
								  y:y,
							 | 
						||
| 
								 | 
							
								  eps:0.2
							 | 
						||
| 
								 | 
							
								});
							 | 
						||
| 
								 | 
							
								var t1=time()
							 | 
						||
| 
								 | 
							
								var result = ml.classify(model,x).map(function (r,i) { r.y=y[i]; return r } )
							 | 
						||
| 
								 | 
							
								var t2=time()
							 | 
						||
| 
								 | 
							
								print(result)
							 | 
						||
| 
								 | 
							
								var correct=0,wrong=0;
							 | 
						||
| 
								 | 
							
								result.forEach(function (r) { if (r.value==r.y) correct++; else wrong++ });
							 | 
						||
| 
								 | 
							
								print('Correct='+correct+', wrong='+wrong);
							 | 
						||
| 
								 | 
							
								print(toJSON(model).length)
							 | 
						||
| 
								 | 
							
								print(t1-t0,t2-t1)
							 |