Tue 27 Aug 00:14:56 CEST 2024
This commit is contained in:
		
							parent
							
								
									f2464e6e16
								
							
						
					
					
						commit
						5b883273cd
					
				
							
								
								
									
										31
									
								
								test/test-id3.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								test/test-id3.js
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,31 @@
 | 
				
			||||||
 | 
					var training_data = [
 | 
				
			||||||
 | 
					  	{"color":"blue", "shape":"square", "liked":false},
 | 
				
			||||||
 | 
					  	{"color":"red", "shape":"square", "liked":false},
 | 
				
			||||||
 | 
					  	{"color":"blue", "shape":"circle", "liked":true},
 | 
				
			||||||
 | 
					  	{"color":"red", "shape":"circle", "liked":true},
 | 
				
			||||||
 | 
					  	{"color":"blue", "shape":"hexagon", "liked":false},
 | 
				
			||||||
 | 
					  	{"color":"red", "shape":"hexagon", "liked":false},
 | 
				
			||||||
 | 
					  	{"color":"yellow", "shape":"hexagon", "liked":true},
 | 
				
			||||||
 | 
					  	{"color":"yellow", "shape":"circle", "liked":true}
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var test_data = [
 | 
				
			||||||
 | 
					  	{"color":"blue", "shape":"hexagon", "liked":false},
 | 
				
			||||||
 | 
					  	{"color":"red", "shape":"hexagon", "liked":false},
 | 
				
			||||||
 | 
					  	{"color":"yellow", "shape":"hexagon", "liked":true},
 | 
				
			||||||
 | 
					  	{"color":"yellow", "shape":"circle", "liked":true}
 | 
				
			||||||
 | 
					  ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var target = "liked";
 | 
				
			||||||
 | 
					var features = ["color", "shape"];
 | 
				
			||||||
 | 
					var model = ml.learn({
 | 
				
			||||||
 | 
					 algorithm:ml.ML.ID3,
 | 
				
			||||||
 | 
					 data:training_data,
 | 
				
			||||||
 | 
					 target:target,
 | 
				
			||||||
 | 
					 features:features
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					print(ml.print(model))
 | 
				
			||||||
 | 
					print(toJSON(model).length+' Bytes')
 | 
				
			||||||
 | 
					print(ml.classify(model,test_data))
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user