def get_roc_metrics(data_table: pd.DataFrame, model):
    """Get fpr, tpr and threshold"""

    X_train, X_test, y_train, y_test = get_train_and_test_data(data_table)

    trained_model = train_model(X_train, y_train, model)

    y_prob = get_y_probabilities(X_test, trained_model)
    y_pos_prob = y_prob[:, 1]

    return roc_curve(y_test, y_pos_prob, pos_label=Values.Y_LABEL_MORE.value)
예제 #2
0
def test_train_random_forest_model(input_data_features: pd.DataFrame):
    """Tests that random forest model training works"""
    X_train, X_test, y_train, y_test = get_train_and_test_data(
        input_data_features)

    model = Models.RANDOM_FOREST.value

    try:

        trained_model = train_model(X_train, y_train, model)

    except Exception as exception:
        pytest.fail('Failed to train model: {}'.format(exception))
예제 #3
0
        open('val_loss_' + args.exp_name + '.csv', 'a') as csv_val,    \
        open('indv_loss_' + args.exp_name + '.csv', 'a') as csv_indv:
    train_writer = csv.writer(csv_train)
    test_writer = csv.writer(csv_test)
    val_writer = csv.writer(csv_val)
    indv_writer = csv.writer(csv_indv)

    for epoch in range(args.epochs_start, args.epochs_end):
        if args.train:
            avg_loss_train = train_model(TileNet,
                                         cuda,
                                         train_dataloader,
                                         optimizer,
                                         epoch + 1,
                                         args.species,
                                         args.alpha,
                                         train_writer,
                                         indv_writer,
                                         margin=margin,
                                         l2=l2,
                                         print_every=print_every,
                                         t0=t0)
            train_loss.append(avg_loss_train)
            writer.add_scalar('loss/train', avg_loss_train, epoch)

        if args.test:
            avg_loss_test = validate_model(TileNet,
                                           cuda,
                                           test_dataloader,
                                           optimizer,
                                           epoch + 1,
예제 #4
0
mse_list = {'big': {}, 'small': {}}
save_dir = paths.model_dir + args.name + '/'

t0 = time()

with open(save_dir + 'command.p', 'wb') as f:
    pickle.dump(args, f)

# Train
for epoch in range(args.epochs_start, args.epochs_end):
    if args.train:
        avg_loss_train = train_model(TileNet,
                                     cuda,
                                     train_dataloader,
                                     optimizer,
                                     epoch + 1,
                                     criterion,
                                     margin=margin,
                                     l2=l2,
                                     print_every=print_every,
                                     t0=t0)
        train_loss.append(avg_loss_train)
        writer.add_scalar('loss/train', avg_loss_train, epoch)

    if args.test:
        avg_loss_test = validate_model(TileNet,
                                       cuda,
                                       test_dataloader,
                                       optimizer,
                                       epoch + 1,
                                       criterion,
                                       margin=margin,
예제 #5
0
    parser.add_argument("--wsd_data_dir", required=True, help="Directory where wsd training and"
                                                              " evaluation data are located, typically ./wsd_data/")
    parser.add_argument("--do_eval", help="If set, the model performs the evaluation step only. "
                                          "Otherwise, it will perform both training and evaluation.",
                        action="store_true")

    parser.add_argument("--epochs", help="Number of training epochs.", type=int, default=40)

    args = parser.parse_args()

    if args.starting_from_checkpoint:
        print("Starting training from epoch {} checkpoint".format(args.starting_epoch))
        config = config_class.ConfigAllWords(args.inventory_name, args.model_name, args.starting_epoch, args.data_dir,
                                             args.data_out, args.wsd_data_dir, args.starting_from_checkpoint)

    else:
        config = config_class.ConfigAllWords(args.inventory_name, args.model_name, args.starting_epoch, args.data_dir,
                                             args.data_out, args.wsd_data_dir)

    print('\n\nUsing {} as sense inventory'.format(config.inventory))

    print('Output files will be saved to {}'.format(config.experiment_folder))

    if not args.do_eval:
        utils.define_folders(config)
        prepare_data(config)
        training.train_model(config, args.epochs)

    best_epoch = utils.pick_epoch(config.experiment_folder)
    test.test(config, best_epoch)
예제 #6
0
from src.model_1 import Model1
from src.model_2 import Model2
from src.training import train_model

if __name__ == "__main__":

    model1 = Model1()
    model2 = Model2()

    train_model(model1)
    train_model(model2)
예제 #7
0
from src.training import train_model

if __name__ == "__main__":
    train_model()