Beispiel #1
0
def fit_and_predict(config, experiment_name, test_set, model_name):
    """Runs:
    - train
    - model_selection_df
    - predict
    - analyze
    """
    run_name = "fit_and_predict:{}:{}:{}".format(
        experiment_name, test_set, model_name)

    config = C.Config.load(config)
    print(utils.colored("Running {} end-to-end.".format(run_name)))

    timer = utils.TimerHolder()
    timer.start(run_name)
    logger.debug("Running model={} with experiment_name={} at {}"
                 .format(model_name, experiment_name,
                         timer.get_start(run_name)))
    driver = hcnn.driver.Driver(config,
                                model_name=model_name,
                                experiment_name=experiment_name,
                                load_features=True)
    result = driver.fit_and_predict_one(test_set)
    print("{} - {} complted in duration {}".format(
        run_name, utils.result_colored(result), timer.end(run_name)))
    return result
Beispiel #2
0
def handle_arguments(arguments):
    config = CONFIG_PATH
    logger.debug(arguments)

    # Run modes
    if arguments['run']:
        model = arguments['<model>']
        skip_training = arguments['--skip_training']
        skip_features = arguments['--skip_features']

        logger.info("Run Mode; model={}".format(model))
        if model:
            result = run_experiment(model, config,
                                    skip_features=skip_features,
                                    skip_training=skip_training)
        else:
            result = run_all_experiments(config,
                                         skip_features=skip_features,
                                         skip_training=skip_training)

    elif arguments['extract_features']:
        logger.info('Extracting features.')
        result = extract_features(config)

    # Basic Experiment modes
    elif arguments['experiment']:
        if arguments['fit_and_predict']:
            mode = 'fit_and_predict'
        elif arguments['train']:
            mode = 'train'
        elif arguments['predict']:
            mode = 'predict'
        elif arguments['analyze']:
            mode = 'analyze'
        else:
            # docopt should not allow us to get here.
            raise ValueError("No valid experiment mode set.")

        experiment_name = arguments['<experiment_name>']
        test_set = arguments['<test_set>']
        model = arguments['<model>']

        logger.info("Running experiment '{}' with test_set '{}' "
                    "using model '{}'".format(
                        experiment_name, test_set, model))

        # Use the 'mode' to select the function to call.
        result = globals().get(mode)(config, experiment_name, test_set, model)

    # Test modes
    elif arguments['test']:
        test_type = 'all'
        if arguments['data']:
            test_type = 'data'
        elif arguments['model']:
            test_type = 'model'
        elif arguments['unit']:
            test_type = 'unit'

        logger.info('Running {} tests'.format(test_type))

        result = run_tests(test_type)

    elif arguments['collect_results']:
        experiment_name = arguments.get('<experiment_name>', None)
        destination = arguments['<results_destination>']
        integration_mode = arguments['--integration']

        result = collect_results(config, destination, experiment_name,
                                 use_integration=integration_mode)

    return result