@main.command()
@_classifier_path
@_data_path
@_output_path
@_label_col
@_class_prior
@_overwrite
@_verbose
def predict(classifier_path, data_path, output_path, label_col, class_prior, overwrite, verbose):
    'predict labels for data'
    LOGGER.log_args()
    LOGGER.log_versions(['sklearn', 'numpy'])
    (classifier, feature_params, scaler) = load_classifier(classifier_path)
    class_label = get_classifier_label(classifier)
    if ((class_prior is not None) and (class_label == 'lr')):
        class_labels = list(class_prior)
        encoded = transform_response(class_labels)
        ordered = sorted(zip(encoded, class_labels))
        if ('e' in ordered[0]):
            adj = log((class_prior['g'] / class_prior['e']))
        else:
            adj = log((class_prior['e'] / class_prior['g']))
        classifier.intercept_ += adj
    basename_class = get_basename(classifier_path)
    basename_data = get_basename(data_path)
    basename = f'{basename_class}-{basename_data}'
    outpath = os.path.join(output_path, f'{basename}-predicted-{class_label}.json.gz')
    os.makedirs(output_path, exist_ok=True)
    logfile_path = os.path.join(output_path, f'logs/{basename}-predict-{class_label}.log')
    if (os.path.exists(outpath) and (not overwrite)):
        if (verbose > 1):
            click.secho(f'Skipping. {outpath} exists. use overwrite to force.', fg='green')
        return
    LOGGER.log_file_path = logfile_path
    LOGGER.input_file(classifier_path)
    LOGGER.input_file(data_path)
    start_time = time.time()
    if (class_label in ('nb', 'xgb')):
        classifier.decision_function = classifier.predict_proba
    fulldata = pandas.read_csv(data_path, sep='\t')
    result = {}
    result['feature_params'] = feature_params
    result['classifier_label'] = class_label
    result['classifier_path'] = classifier_path
    result['predictions'] = defaultdict(list)
    total = (fulldata.shape[0] // 2000)
    pbar = tqdm(iter_indices(fulldata.shape[0], block_size=2000), ncols=80, total=total)
    for indices in pbar:
        data = fulldata.iloc[indices]
        (ids, resp, feat, n_dims, names) = data_to_numeric(data, label_col=label_col, **feature_params)
        if scaler:
            feat = scaler.transform(feat)
        (predictions, scores) = predict_origin(classifier, feat)
        if (class_label in ('nb', 'xgb')):
            scores = scores[:, 1].tolist()
        elif (class_label == 'ocs'):
            scores = scores[:, 0].tolist()
        predictions = inverse_transform_response(predictions)
        result['predictions']['varid'].extend(list(ids))
        result['predictions']['predicted'].extend(list(predictions))
        result['predictions']['scores'].extend(list(scores))
    dump_json(outpath, result)
    LOGGER.output_file(outpath)
    duration = (time.time() - start_time)
    LOGGER.log_message(('%.2f' % (duration / 60.0)), label='run duration (minutes)')
    LOGGER.shutdown()
predict labels for data
@main.command()
@_classifier_path
@_data_path
@_output_path
@_label_col
@_class_prior
@_overwrite
@_verbose
def predict(classifier_path, data_path, output_path, label_col, class_prior, overwrite, verbose):
    
    LOGGER.log_args()
    LOGGER.log_versions(['sklearn', 'numpy'])
    (classifier, feature_params, scaler) = load_classifier(classifier_path)
    class_label = get_classifier_label(classifier)
    if ((class_prior is not None) and (class_label == 'lr')):
        class_labels = list(class_prior)
        encoded = transform_response(class_labels)
        ordered = sorted(zip(encoded, class_labels))
        if ('e' in ordered[0]):
            adj = log((class_prior['g'] / class_prior['e']))
        else:
            adj = log((class_prior['e'] / class_prior['g']))
        classifier.intercept_ += adj
    basename_class = get_basename(classifier_path)
    basename_data = get_basename(data_path)
    basename = f'{basename_class}-{basename_data}'
    outpath = os.path.join(output_path, f'{basename}-predicted-{class_label}.json.gz')
    os.makedirs(output_path, exist_ok=True)
    logfile_path = os.path.join(output_path, f'logs/{basename}-predict-{class_label}.log')
    if (os.path.exists(outpath) and (not overwrite)):
        if (verbose > 1):
            click.secho(f'Skipping. {outpath} exists. use overwrite to force.', fg='green')
        return
    LOGGER.log_file_path = logfile_path
    LOGGER.input_file(classifier_path)
    LOGGER.input_file(data_path)
    start_time = time.time()
    if (class_label in ('nb', 'xgb')):
        classifier.decision_function = classifier.predict_proba
    fulldata = pandas.read_csv(data_path, sep='\t')
    result = {}
    result['feature_params'] = feature_params
    result['classifier_label'] = class_label
    result['classifier_path'] = classifier_path
    result['predictions'] = defaultdict(list)
    total = (fulldata.shape[0] // 2000)
    pbar = tqdm(iter_indices(fulldata.shape[0], block_size=2000), ncols=80, total=total)
    for indices in pbar:
        data = fulldata.iloc[indices]
        (ids, resp, feat, n_dims, names) = data_to_numeric(data, label_col=label_col, **feature_params)
        if scaler:
            feat = scaler.transform(feat)
        (predictions, scores) = predict_origin(classifier, feat)
        if (class_label in ('nb', 'xgb')):
            scores = scores[:, 1].tolist()
        elif (class_label == 'ocs'):
            scores = scores[:, 0].tolist()
        predictions = inverse_transform_response(predictions)
        result['predictions']['varid'].extend(list(ids))
        result['predictions']['predicted'].extend(list(predictions))
        result['predictions']['scores'].extend(list(scores))
    dump_json(outpath, result)
    LOGGER.output_file(outpath)
    duration = (time.time() - start_time)
    LOGGER.log_message(('%.2f' % (duration / 60.0)), label='run duration (minutes)')
    LOGGER.shutdown()