| @@ 15-33 (lines=19) @@ | ||
| 12 | logger = logging.getLogger(__file__) |
|
| 13 | ||
| 14 | ||
| 15 | def training_and_test(token, train_data, test_data, num_classes, result): |
|
| 16 | """Train and test |
|
| 17 | ||
| 18 | Args: |
|
| 19 | token (:obj:`str`): token representing this run |
|
| 20 | train_data (:obj:`tuple` of :obj:`numpy.array`): Tuple of training feature and label |
|
| 21 | test_data (:obj:`tuple` of :obj:`numpy.array`): Tuple of testing feature and label |
|
| 22 | num_classes (:obj:`int`): Number of classes |
|
| 23 | result (:obj:`pyActLearn.performance.record.LearningResult`): LearningResult object to hold learning result |
|
| 24 | """ |
|
| 25 | decision_tree = DecisionTree(train_data[0].shape[1], num_classes, log_level=logging.WARNING) |
|
| 26 | decision_tree.build(train_data[0], train_data[1].flatten()) |
|
| 27 | # Test |
|
| 28 | predicted_y = decision_tree.classify(test_data[0]) |
|
| 29 | # Evaluate the Test and Store Result |
|
| 30 | confusion_matrix = get_confusion_matrix(num_classes=num_classes, |
|
| 31 | label=test_data[1].flatten(), predicted=predicted_y) |
|
| 32 | result.add_record(decision_tree.export_to_dict(), key=token, confusion_matrix=confusion_matrix) |
|
| 33 | return predicted_y |
|
| 34 | ||
| 35 | ||
| 36 | def load_and_test(token, test_data, num_classes, result): |
|
| @@ 15-33 (lines=19) @@ | ||
| 12 | logger = logging.getLogger(__file__) |
|
| 13 | ||
| 14 | ||
| 15 | def training_and_test(token, train_data, test_data, num_classes, result): |
|
| 16 | """Train and test |
|
| 17 | ||
| 18 | Args: |
|
| 19 | token (:obj:`str`): token representing this run |
|
| 20 | train_data (:obj:`tuple` of :obj:`numpy.array`): Tuple of training feature and label |
|
| 21 | test_data (:obj:`tuple` of :obj:`numpy.array`): Tuple of testing feature and label |
|
| 22 | num_classes (:obj:`int`): Number of classes |
|
| 23 | result (:obj:`pyActLearn.performance.record.LearningResult`): LearningResult object to hold learning result |
|
| 24 | """ |
|
| 25 | svm_model = sklearn.svm.SVC(kernel='rbf') |
|
| 26 | svm_model.fit(train_data[0], train_data[1].flatten()) |
|
| 27 | # Test |
|
| 28 | predicted_y = svm_model.predict(test_data[0]) |
|
| 29 | # Evaluate the Test and Store Result |
|
| 30 | confusion_matrix = get_confusion_matrix(num_classes=num_classes, |
|
| 31 | label=test_data[1].flatten(), predicted=predicted_y) |
|
| 32 | result.add_record(svm_model, key=token, confusion_matrix=confusion_matrix) |
|
| 33 | return predicted_y |
|
| 34 | ||
| 35 | ||
| 36 | def load_and_test(token, test_data, num_classes, result): |
|