with open(os.path.join("data/out", "train.pkl"), "rb") as f:
    train = pickle.load(f)

# trainer = pycrfsuite.Trainer(verbose=True)

# trainer.set_params({'c1': 0.1,   # coefficient for L1 penalty
#                     'c2': 0.1,  # coefficient for L2 penalty
#                     'max_iterations': 250,  # stop earlier
#                     'feature.possible_transitions': False,
#                     'feature.possible_states': False
#                    })

# trainer = pycrfsuite.Trainer(algorithm = 'ap',verbose=True)
trainer = pycrfsuite.Trainer(algorithm = 'pa',verbose=True)
#rainer = pycrfsuite.Trainer(algorithm = 'arow',verbose=True)
trainer.set_params({
                    'type':3,
                     'c': 0.1, # coefficient for L1 penalty
#                     'c2': 0.01,  # coefficient for L2 penalty
                    'max_iterations': 2000,
                    'feature.possible_transitions': False,
                    'feature.possible_states': False
                   })

for i, data in enumerate(train):
    temp = prepare_data(data)
    for features, ylabel in temp:
        trainer.append(features, ylabel)
    trainer.train("exp_{}".format(i))
    print("Model {} Trained".format(i))
Exemple #2
0
        elif f['is_ball']:
            p = "I-ball"
        elif f['is_face']:
            p = "I-face"
        elif f['is_key']:
            p = "I-key"
        pred.append(p)
    return pred


support_threshold = 0
stats = StatsManager(support_threshold)

for i, data in enumerate(validation):
    y_pred = []
    y_true = []
    for features, ylabel in prepare_data(data):
        y_pred.append(ftag(features))
        y_true.append(ylabel)
# print(y_true[0][0:50])
# print("predict:", y_pred[0][0:50])
    stats.append_report(y_true, y_pred)

print("Multi-class Classification Report Mean(Std)")
report, summary = stats.summarize()
# pretty_print_report(report)

# print("Run-length Report")
# rl_report = stats.runlength_report()
# pretty_rl_table(rl_report)