def viterbi_test(test_path, features, weights, beam=10): viterbi = Viterbi(features, weights, beam=beam) list_of_sentences, real_list_of_tags = evaluation.prepare_test_data( test_path) pred_list_of_tags = viterbi.predict_tags(list_of_sentences) # for i in range(len(pred_list_of_tags)): # print("SENTENCE", i) # print(list_of_sentences[i]) # for word, t1, t2 in zip(list_of_sentences[i].split(' '), real_list_of_tags[i], pred_list_of_tags[i]): # if t1 != t2: # print(word, t1, t2) accuracy, accuracies, confusion_matrix = evaluation.calculate_accuracy( real_list_of_tags, pred_list_of_tags) return accuracy, accuracies, confusion_matrix
Xts = np.array([[1,4,5],[7,3,2]]) yts = np.array([1,2]) yts = np.reshape(yts,(2,1)) # Build Model DTCmodel = DTC() DTCmodel.fit(X_train = Xtr, y_train = ytr) # Predict outputs yh = DTCmodel.predict(X_test = Xts) # calculate accuracy acc = evaluation.calculate_accuracy(yts,yh) print('Accuracy: ' + str(acc)) # Verify Nodes node = DTCmodel.node_list[0] print('Verify Node:') print('Node Depth: ' + str(node.depth)) print('Node Data Indexes: ' + str(node.data_indexes)) print('Node sons: ' + str(node.sonList)) print('Node attribute: ' + str(node.attribute)) print('Node threshold: ' + str(node.threshold)) print('Node is leaf: ' + str(node.is_leaf)) print('Node Label: ' + str(node.label)) ###################################################
if args['--output-dir'] is not None: os.environ["OUT_DIR"] = args['--output-dir'] else: assert "OUT_DIR" in os.environ if args['--config'] is not None: config = load_config_from_file(args['--config']) else: from seq2seq import config print("Using configuration", config.__file__) if args['--test'] is True: test_file = config.filename_test eval_type = 'test' elif args['--dev'] is True: test_file = config.filename_dev eval_type = 'dev' else: raise ValueError('Specify --dev or --test.') config_holder = ConfigHolder(config) model = Model(config_holder) df = evaluation.predict(model, config_holder, test_file) acc_dict = evaluation.calculate_accuracy(df) acc_verbose = evaluation.accuracy_to_string_verbose(acc_dict) evaluation.save_results(df, acc_dict, acc_verbose, "Et-morf-yh", eval_type, config.out_dir)
def evaluate(model, config_holder, test_file, lang_key, eval_type, out_dir): df = evaluation.predict(model, config_holder, test_file) acc_dict = evaluation.calculate_accuracy(df) acc_verbose = evaluation.accuracy_to_string_verbose(acc_dict) evaluation.save_results(df, acc_dict, acc_verbose, lang_key, eval_type, out_dir)
mean_acc_mdc = 0 for i in range(N): # Split data between train and test Xtr, Ytr, Xts, Yts = hold_out.leave_one_out(X, Y, i) # Build Model MDClassifier = MDC() MDClassifier.fit(Xtr, Ytr) # Predict outputs Yh = MDClassifier.predict(Xts) # Calculate and Accumulate accuracy acc_mdc = evaluation.calculate_accuracy(Yts, Yh) mean_acc_mdc = mean_acc_mdc + acc_mdc # Mean Accuracy mean_acc_mdc = mean_acc_mdc / N print( 'Mean Accuracy of MD Classifier, with Iris Dataset and Leave-one-out Method:' ) print(mean_acc_mdc) # ########################## Experiment 2 - Wine, KNN, Random Subsampling # Load DataSet X, Y = data_loader.load_wine()