Tue 27 Aug 00:14:56 CEST 2024
This commit is contained in:
		
							parent
							
								
									a241b621ad
								
							
						
					
					
						commit
						eeb5cab5ef
					
				
							
								
								
									
										65
									
								
								test/test-c45.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								test/test-c45.js
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,65 @@
 | 
				
			||||||
 | 
					// Test 1
 | 
				
			||||||
 | 
					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.C45,
 | 
				
			||||||
 | 
					 data:training_data,
 | 
				
			||||||
 | 
					 target:target,
 | 
				
			||||||
 | 
					 features:features
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					print(ml.print(model))
 | 
				
			||||||
 | 
					print(toJSON(model).length+' Bytes')
 | 
				
			||||||
 | 
					print(ml.classify(model,test_data))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Test 2
 | 
				
			||||||
 | 
					var A='A',B='B',C='C',False=false,True=true,CLASS1='CLASS1',CLASS2='CLASS2';
 | 
				
			||||||
 | 
					training_data = [
 | 
				
			||||||
 | 
					[A,70,True,CLASS1],
 | 
				
			||||||
 | 
					[A,90,True,CLASS2],
 | 
				
			||||||
 | 
					[A,85,False,CLASS2],
 | 
				
			||||||
 | 
					[A,95,False,CLASS2],
 | 
				
			||||||
 | 
					[A,70,False,CLASS1],
 | 
				
			||||||
 | 
					[B,90,True,CLASS1],
 | 
				
			||||||
 | 
					[B,78,False,CLASS1],
 | 
				
			||||||
 | 
					[B,65,True,CLASS1],
 | 
				
			||||||
 | 
					[B,75,False,CLASS1],
 | 
				
			||||||
 | 
					[C,80,True,CLASS2],
 | 
				
			||||||
 | 
					[C,70,True,CLASS2],
 | 
				
			||||||
 | 
					[C,80,False,CLASS1],
 | 
				
			||||||
 | 
					[C,80,False,CLASS1],
 | 
				
			||||||
 | 
					[C,96,False,CLASS1],
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					test_data = [
 | 
				
			||||||
 | 
					  [B,71,False],
 | 
				
			||||||
 | 
					  [C,70,True],
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					model = ml.learn({
 | 
				
			||||||
 | 
					 algorithm:ml.ML.C45,
 | 
				
			||||||
 | 
					 data:training_data
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					print(ml.print(model))
 | 
				
			||||||
 | 
					print(ml.classify(model,test_data))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user