コード例 #1
0
def test_main_classification(mock_parameters, mock_save_results,
                             mock_get_results, mock_fetch_data, method, name):
    # create mock objects from database
    mock_parameters.return_value = {'type': method}
    mock_fetch_data.return_value = fx.inputs_classification(
        include_categorical=True)
    mock_get_results.return_value = None

    main(job_id=None, generate_pfa=True)

    pfa = mock_save_results.call_args[0][0]
    pfa_dict = json.loads(pfa)

    # NOTE: this does not work due to bug in jsonpickle
    # deserialize model
    # estimator = deserialize_sklearn_estimator(pfa_dict['metadata']['estimator'])
    # assert estimator.__class__.__name__ == name

    # make some prediction with PFA
    from titus.genpy import PFAEngine
    engine, = PFAEngine.fromJson(pfa_dict)
    engine.action({
        'stress_before_test1': 10.,
        'iq': 10.,
        'agegroup': '50-59y'
    })
コード例 #2
0
def test_main_partial(mock_parameters, mock_save_results, mock_get_results, mock_fetch_data, method, name):
    # create mock objects from database
    mock_parameters.return_value = {'type': method}
    mock_fetch_data.return_value = fx.inputs_regression()
    mock_get_results.return_value = None

    main(job_id=None, generate_pfa=False)

    js = json.loads(mock_save_results.call_args[0][0])
    estimator = deserialize_sklearn_estimator(js['estimator'])
    assert estimator.__class__.__name__ == name
コード例 #3
0
def test_main_classification_empty(
    mock_exit, mock_parameters, mock_save_error, mock_save_results, mock_get_results, mock_fetch_data, method, name
):
    # create mock objects from database
    mock_parameters.return_value = {'type': method}

    # one column has all NULL values
    data = fx.inputs_classification(include_categorical=True)
    data['data']['independent'][0]['series'] = [None] * len(data['data']['independent'][0]['series'])

    mock_fetch_data.return_value = data
    mock_get_results.return_value = None

    main(job_id=None, generate_pfa=True)

    mock_exit.assert_called_once_with(1)
    assert mock_save_error.call_args[0] == ('Model was not fitted on any data, cannot generate PFA.', )
コード例 #4
0
def test_main_distributed(mock_parameters, mock_save_results, mock_get_results, mock_fetch_data, method, name):
    mock_parameters.return_value = {'type': method}
    mock_fetch_data.return_value = fx.inputs_regression()
    mock_get_results.return_value = None

    # run intermediate job
    main(job_id=None, generate_pfa=False)

    mock_get_results.return_value = mock.MagicMock(data=mock_save_results.call_args[0][0])

    # generate PFA
    main(job_id='1', generate_pfa=True)

    pfa = mock_save_results.call_args_list[1][0][0]
    pfa_dict = json.loads(pfa)

    # make some prediction with PFA
    from titus.genpy import PFAEngine
    engine, = PFAEngine.fromJson(pfa_dict)
    engine.action({'stress_before_test1': 10., 'iq': 10., 'agegroup': '-50y'})