Ejemplo n.º 1
0
def test_main_empty(mock_save_results, mock_fetch_data):
    mock_fetch_data.return_value = t.inputs_regression(include_nominal=True,
                                                       limit_to=0)
    main()
    output = json.loads(mock_save_results.call_args[0][0])

    assert output == {}
Ejemplo n.º 2
0
def test_aggregate(mock_save_results, mock_get_results, mock_fetch_data):
    # run partial jobs
    inputs_1 = t.inputs_regression(limit_from=0,
                                   limit_to=8,
                                   include_nominal=True)
    mock_fetch_data.return_value = inputs_1
    intermediate()
    output_1 = mock_save_results.call_args[0][0]

    inputs_2 = t.inputs_regression(limit_from=8,
                                   limit_to=20,
                                   include_nominal=True)
    mock_fetch_data.return_value = inputs_2
    intermediate()
    output_2 = mock_save_results.call_args[0][0]

    mock_get_results.side_effect = [
        mock.MagicMock(data=output_1, error=''),
        mock.MagicMock(data=output_2, error=''),
    ]

    # run computations
    aggregate(['1', '2'])
    output_agg = json.loads(mock_save_results.call_args[0][0])
    beta_agg = {k: v['coef'] for k, v in output_agg.items()}

    # calculate coefficients from single-node regression
    mock_fetch_data.return_value = t.inputs_regression(limit_to=20,
                                                       include_nominal=True)
    main()
    output_single = json.loads(mock_save_results.call_args[0][0])
    beta_single = {k: v['coef'] for k, v in output_single.items()}

    assert t.round_dict(beta_agg) == t.round_dict(beta_single)
Ejemplo n.º 3
0
def test_main_logistic(mock_save_results, mock_fetch_data):
    mock_fetch_data.return_value = t.inputs_classification(
        limit_to=50, include_nominal=True)
    main()
    output = json.loads(mock_save_results.call_args[0][0])

    assert t.round_dict(fx.output_classification()) == t.round_dict(output)
Ejemplo n.º 4
0
def test_main_logistic_single_category(mock_exit, mock_save_error,
                                       mock_fetch_data):
    data = t.inputs_classification(limit_to=5, include_nominal=True)
    # single output
    data['data']['dependent'][0]['series'] = len(
        data['data']['dependent'][0]['series']) * ['AD']

    mock_fetch_data.return_value = data
    main()
    assert mock_save_error.call_args[0] == (
        'Not enough data to apply logistic regression.', )
Ejemplo n.º 5
0
def main():
    '''
    knn model
    由于模型训练参数速度较慢,大约2个小时,这里可以选择是否选择重新跑参数,默认为加载原有的参数
    predict_from_params = False  则表示重新跑参数
    '''
    # knn.main(predict_from_params=False)
    linear_regression.main()
    '''
    sarimax 时间序列模型
    需要三个小时跑模型
    '''
    sarimax_run.main()
    '''
    两个模型结果融合
    '''

    linear_sarimax_ensemble.linear_sarimax_ensemble()
Ejemplo n.º 6
0
def test_aggregate_single(mock_save_results, mock_get_results,
                          mock_fetch_data):
    """Aggregation on single node should give same results as ordinary linear regression."""
    # run partial jobs
    inputs = t.inputs_regression(limit_from=0, limit_to=20)
    mock_fetch_data.return_value = inputs
    intermediate()
    output = mock_save_results.call_args[0][0]

    mock_get_results.side_effect = [
        mock.MagicMock(data=output, error=''),
    ]

    # run computations
    aggregate(['1'])
    output_agg = json.loads(mock_save_results.call_args[0][0])

    # calculate coefficients from single-node regression
    mock_fetch_data.return_value = t.inputs_regression(limit_to=20)
    main()
    output_single = json.loads(mock_save_results.call_args[0][0])

    assert t.round_dict(output_agg) == t.round_dict(output_single)
 def test_linear_regression(self):
   linear_regression.main([None, "--train_steps=1"])
Ejemplo n.º 8
0
import logistic_regression as lo
import linear_regression as lg
import neural_network as nn

lg.main()
print("\n")
lo.main()
print("\n")
nn.main()
print("\n")
Ejemplo n.º 9
0
def train_linear_reg(X, y, tscv):
    import linear_regression as lin_reg
    lin_reg.main(X, y, tscv.split(X))
Ejemplo n.º 10
0
def test_main(mock_save_results, mock_fetch_data):
    mock_fetch_data.return_value = t.inputs_regression(include_nominal=True)
    main()
    output = json.loads(mock_save_results.call_args[0][0])

    assert t.round_dict(fx.output_regression()) == t.round_dict(output)
Ejemplo n.º 11
0
def test_main(mock_save_results, mock_fetch_data):
    mock_fetch_data.return_value = fx.inputs
    main()
    output = json.loads(mock_save_results.call_args[0][0])

    assert _round_dict(fx.outputs) == _round_dict(output)
Ejemplo n.º 12
0
 def test_linear_regression(self):
   linear_regression.main([None, "--train_steps=1"])
Ejemplo n.º 13
0
def main(datafile="datafile.csv"):
    wine_data, wine_features = import_data.import_data(datafile)
    linear_regression.main(wine_data, wine_features)
    knn_regression.main(wine_data)
    polynomial_model.main(wine_data)
    polynomial_model_bayesian.main(wine_data)