@@ -1353,3 +1353,92 @@ Legendre Feature Transform
1353
1353
>> > avg_errors = cross_validator.excute()
1354
1354
1355
1355
>> > best_model = cross_validator.get_best_model()
1356
+
1357
+ Uniform Blending for Classification
1358
+ ============
1359
+
1360
+ .. code-block :: py
1361
+
1362
+ >> > input_train_data_file = os.path.join(os.path.join(os.getcwd(), os.path.dirname(__file__ )), ' FukuML/dataset/pocket_pla_binary_train.dat' )
1363
+
1364
+ >> > input_test_data_file = os.path.join(os.path.join(os.getcwd(), os.path.dirname(__file__ )), ' FukuML/dataset/pocket_pla_binary_test.dat' )
1365
+
1366
+ >> > uniform_blending_classifier = utility.UniformBlendingClassifier()
1367
+
1368
+ >> > pla_bc = pla.BinaryClassifier()
1369
+
1370
+ >> > pla_bc.load_train_data(input_train_data_file)
1371
+
1372
+ >> > pla_bc.load_test_data(input_test_data_file)
1373
+
1374
+ >> > pla_bc.set_param()
1375
+
1376
+ >> > pla_bc.init_W()
1377
+
1378
+ >> > pla_bc.train()
1379
+
1380
+ >> > print (" PLA 平均錯誤值(Eout):" )
1381
+
1382
+ >> > print (pla_bc.calculate_avg_error(pla_bc.test_X, pla_bc.test_Y, pla_bc.W))
1383
+
1384
+ >> > pocket_bc = pocket.BinaryClassifier()
1385
+
1386
+ >> > pocket_bc.load_train_data(input_train_data_file)
1387
+
1388
+ >> > pocket_bc.load_test_data(input_test_data_file)
1389
+
1390
+ >> > pocket_bc.set_param()
1391
+
1392
+ >> > pocket_bc.init_W()
1393
+
1394
+ >> > pocket_bc.train()
1395
+
1396
+ >> > print (" Pocket 平均錯誤值(Eout):" )
1397
+
1398
+ >> > print (pocket_bc.calculate_avg_error(pocket_bc.test_X, pocket_bc.test_Y, pocket_bc.W))
1399
+
1400
+ >> > linear_bc = linear_regression.BinaryClassifier()
1401
+
1402
+ >> > linear_bc.load_train_data(input_train_data_file)
1403
+
1404
+ >> > linear_bc.load_test_data(input_test_data_file)
1405
+
1406
+ >> > linear_bc.set_param()
1407
+
1408
+ >> > linear_bc.init_W()
1409
+
1410
+ >> > linear_bc.train()
1411
+
1412
+ >> > print (" Linear 平均錯誤值(Eout):" )
1413
+
1414
+ >> > print (linear_bc.calculate_avg_error(linear_bc.test_X, linear_bc.test_Y, linear_bc.W))
1415
+
1416
+ >> > uniform_blending_classifier.add_model(pla_bc)
1417
+
1418
+ >> > uniform_blending_classifier.add_model(pocket_bc)
1419
+
1420
+ >> > uniform_blending_classifier.add_model(linear_bc)
1421
+
1422
+ >> > test_data = ' 0.32368 0.61439 0.42097 0.025626 -1'
1423
+
1424
+ >> > prediction = uniform_blending_classifier.prediction(test_data)
1425
+
1426
+ >> > print (" 測試資料 x:" )
1427
+
1428
+ >> > print (prediction[' input_data_x' ])
1429
+
1430
+ >> > print (" 測試資料 y:" )
1431
+
1432
+ >> > print (prediction[' input_data_y' ])
1433
+
1434
+ >> > print (" 預測結果:" )
1435
+
1436
+ >> > print (prediction[' prediction' ])
1437
+
1438
+ >> > print (" 平均錯誤率(Ein):" )
1439
+
1440
+ >> > print (uniform_blending_classifier.calculate_avg_error(input_train_data_file))
1441
+
1442
+ >> > print (" 平均錯誤率(Eout):" )
1443
+
1444
+ >> > print (uniform_blending_classifier.calculate_avg_error(input_test_data_file))
0 commit comments