Esempio n. 1
0
def test_maxabsscaler_minimum_operation_success():
    params = {
        MaxAbsScalerOperation.ATTRIBUTE_PARAM: ['col'],
    }

    n_in = {'input data': 'input_1'}
    n_out = {'output data': 'output_1'}
    in1 = n_in['input data']
    out = n_out['output data']

    instance = MaxAbsScalerOperation(params,
                                     named_inputs=n_in,
                                     named_outputs=n_out)

    code = instance.generate_code()

    expected_code = dedent("""
        output_1 = input_1
        from sklearn.preprocessing import MaxAbsScaler
        scaler = MaxAbsScaler()
        X_train = input_1['col'].values.tolist()
        output_1['col_norm'] = scaler.fit_transform(X_train).tolist()
        """)

    result, msg = compare_ast(ast.parse(code), ast.parse(expected_code))

    assert result, msg + format_code_comparison(code, expected_code)
Esempio n. 2
0
def test_max_abs_scaler_success():
    df = util.iris(['sepalwidth', 'petalwidth'], size=10)
    test_df = df.copy()

    arguments = {
        'parameters': {
            'attribute': ['sepalwidth', 'petalwidth'],
            'multiplicity': {
                'input data': 0
            }
        },
        'named_inputs': {
            'input data': 'df',
        },
        'named_outputs': {
            'output data': 'out'
        }
    }
    instance = MaxAbsScalerOperation(**arguments)
    result = util.execute(instance.generate_code(), {'df': df})
    data = {'scaled_1': scaler(df, ['sepalwidth', 'petalwidth'])}
    data = pd.DataFrame(data)

    assert test_df.max()['sepalwidth'] == 3.9
    assert test_df.max()['petalwidth'] == 0.4
    assert result['out'].loc[:, 'scaled_1'].equals(data.loc[:, 'scaled_1'])
Esempio n. 3
0
def test_max_abs_scaler_missing_input_implies_no_code_success():
    arguments = {
        'parameters': {
            'attribute': ['sepalwidth', 'petalwidth'],
            'multiplicity': {
                'input data': 0
            }
        },
        'named_inputs': {},
        'named_outputs': {
            'output data': 'out'
        }
    }
    instance = MaxAbsScalerOperation(**arguments)
    assert instance.generate_code() is None
Esempio n. 4
0
def test_max_abs_scaler_alias_param_success():
    df = util.iris(['sepalwidth', 'petalwidth'], size=10)
    arguments = {
        'parameters': {
            'attribute': ['sepalwidth', 'petalwidth'],
            'multiplicity': {
                'input data': 0
            },
            'alias': 'test_pass'
        },
        'named_inputs': {
            'input data': 'df',
        },
        'named_outputs': {
            'output data': 'out'
        }
    }
    instance = MaxAbsScalerOperation(**arguments)
    result = util.execute(instance.generate_code(), {'df': df})
    assert result['out'].iloc[:, 2].name == 'test_pass'
Esempio n. 5
0
def test_max_abs_scaler_missing_attributes_param_fail():
    arguments = {
        'parameters': {
            'multiplicity': {
                'input data': 0
            }
        },
        'named_inputs': {
            'input data': 'df',
        },
        'named_outputs': {
            'output data': 'out'
        }
    }
    with pytest.raises(ValueError) as val_err:
        MaxAbsScalerOperation(**arguments)
    assert "Parameters 'attribute' must be informed for task" in str(
        val_err.value)
Esempio n. 6
0
def test_maxabsscaler_operation_failure():
    params = {MaxAbsScalerOperation.ALIAS_PARAM: 'c'}
    with pytest.raises(ValueError):
        n_in = {'input data': 'input_1'}
        n_out = {'output data': 'output_1'}
        MaxAbsScalerOperation(params, named_inputs=n_in, named_outputs=n_out)