Exemple #1
0
def get_feature_pipelines(sort_by=FeaturePipeline.start_time,
                          response_type="json",
                          **kwargs):
    assert_response_type(response_type)
    q = session.query(FeaturePipeline)
    q = sort_and_filter(q, sort_by=sort_by, **kwargs)
    return build_response(q.all(), response_type)
Exemple #2
0
def get_predictor_details(predictor_id=None, response_type="json"):
    assert_response_type(response_type)
    predictor_id = predictor_id or request.args.get('predictor', type=int)
    predictor = Predictor.load(id=predictor_id)
    if response_type == 'object':
        return predictor
    else:
        return build_response(cohort.as_dict(), response_type)
Exemple #3
0
def get_predictors(sort_by=Predictor.created_at,
                   response_type="json",
                   **kwargs):
    assert_response_type(response_type)
    q = session.query(Predictor)
    q = sort_and_filter(q, sort_by=sort_by, **kwargs)
    if response_type == 'object':
        return q.all()
    else:
        return build_response(q.all(), response_type)
Exemple #4
0
def get_training_configuration(
    pipeline_id=None,
    response_type="json",
    config=None
):
    assert_response_type(response_type)
    pipeline_id = pipeline_id or request.args.get('pipeline', type=int)
    config = config or request.args
    tc = TrainingConfiguration.load_by_config(pipeline_id, config)
    return build_response(tc, response_type)
Exemple #5
0
def predict_outcome(predictor_id=None,
                    features=[],
                    patient_id=None,
                    response_type="json"):
    """
    Load predictor and predict outcome for patient
    """
    assert_response_type(response_type)
    predictor_id = predictor_id or request.args.get('predictor', type=int)
    predictor = Predictor.load(id=predictor_id)
    if not features:
        if patient_id is None:
            # special case, because patient_id could be 0 (evaluates False)
            patient_id = request.args.get('patient', type=int)
        df = predictor.get_data()
        del df[predictor.training_configuration.target]
        features = list(df.iloc[patient_id])

    prediction = {
        'predicted_label': predictor.clf.predict([features])[0],
        'class_probabilities':
        predictor.clf.predict_proba([features])[0].tolist()
    }
    return build_response(prediction, response_type)
Exemple #6
0
def get_training_results(
    pipeline_id=None,
    columns=DEFAULT_COLUMNS,
    metrics=DEFAULT_METRICS,
    response_type="json",
    **kwargs
):
    assert_response_type(response_type)
    pipeline_id = pipeline_id or request.args.get('pipeline', type=int)
    assert pipeline_id is not None
    q = session.query(
        TrainingResult
    ).join(
        TrainingConfiguration,
        TrainingResult.training_configuration_id == TrainingConfiguration.id
    ).filter(
        TrainingConfiguration.training_pipeline_id == pipeline_id
    ).with_entities(
        *columns,
        *metrics
    )
    q = sort_and_filter(q, **kwargs)
    results = [row._asdict() for row in q]
    return build_response(results, response_type)
Exemple #7
0
def get_cohort_details(cohort_id=None, response_type="json"):
    assert_response_type(response_type)
    cohort_id = cohort_id or request.args.get('cohort', type=int)
    assert cohort_id is not None
    cohort = Cohort.load(id=cohort_id)
    return build_response(cohort.as_dict(), response_type)
Exemple #8
0
def get_cohorts(sort_by=Cohort.created_at, response_type="json", **kwargs):
    assert_response_type(response_type)
    q = session.query(Cohort)
    q = sort_and_filter(q, sort_by=sort_by, **kwargs)
    return build_response(q.all(), response_type)