def test_cross_validate_without_loading_data(): k_fold = 5 mlf.select_classifier("Decision Tree") ret_val = mlf.cross_validate(k_fold) assert isinstance(ret_val, str)
def test_invalid_input_select_classifier(): invalid_input = 37246 print(mlf.CLASSIFIER) mlf.select_classifier(invalid_input) print(mlf.CLASSIFIER) assert mlf.CLASSIFIER is None
def test_load_classifier(): mlf.select_classifier("Decision Tree") classifier_before_saving = mlf.CLASSIFIER mlf.save_classifier() mlf.load_classifier() assert classifier_before_saving == mlf.CLASSIFIER
def test_save_classifier(): mlf.select_classifier("Decision Tree") existing_classifiers = os.listdir("Classifiers") pickle_path = os.path.split(mlf.save_classifier())[1] # Check if a file was created and if is is unique assert (os.path.isfile(pickle_path) and (pickle_path not in existing_classifiers))
def test_cross_validate_with_invalid_k_fold(): k_fold = "invalid!" malware_rate = 0.33 mlf.load_json_data(malware_rate) mlf.select_classifier("Decision Tree") ret_val = mlf.cross_validate(k_fold) assert isinstance(ret_val, str)
def test_cross_validate_with_classifier(): k_fold = 5 malware_rate = 0.33 mlf.load_json_data(malware_rate) # TODO: value error mlf.select_classifier("Decision Tree") ret_val = mlf.cross_validate(k_fold) assert isinstance(ret_val, numpy.ndarray)
def test_train_classifier_with_classifier(): malware_rate = 0.45 partition_size = 0.92 mlf.load_json_data(malware_rate) mlf.partition_data(partition_size) mlf.select_classifier("Decision Tree") mlf.train_classifier()
def test_valid_input_select_classifier(): valid_input = "Decision Tree" ret_val = mlf.select_classifier(valid_input) assert (isinstance(ret_val, str) and mlf.CLASSIFIER is not None)
def test_calculate_classifier_accuracy_with_classifier(): malware_rate = 0.33 partition_size = 0.33 mlf.load_json_data(malware_rate) mlf.partition_data(partition_size) mlf.select_classifier("Decision Tree") mlf.train_classifier() ret_val = mlf.calculate_classifier_accuracy() assert isinstance(ret_val, float)
def test_classify_new_data_with_classifier(): malware_rate = 0.33 partition_size = 0.33 mlf.load_json_data(malware_rate) mlf.partition_data(partition_size) mlf.select_classifier("Decision Tree") mlf.train_classifier() ret_val = mlf.classify_new_data() assert isinstance(ret_val, numpy.ndarray)
def test_display_confusion_matrix_pass(): malware_rate = 0.33 partition_size = 0.33 mlf.REPORT.create_new_report_directory() mlf.load_json_data(malware_rate) mlf.partition_data(partition_size) mlf.select_classifier("Decision Tree") mlf.train_classifier() mlf.classify_new_data() mlf.display_confusion_matrix()
def classifier_selection_menu(): global CLASSIFIER_NAME if CLASSIFIER_NAME: classifier_functionalities_menu() else: click.echo("\nClassifier Selection Menu\n") user_opt = prompt_user_with_menu(mlf.CLASSIFIER_DICT, "Select a classifier") if user_opt: CLASSIFIER_NAME = mlf.select_classifier(user_opt) classifier_functionalities_menu()