def test_glm(cas_session, boston_dataset):
    target = {
        'tool': 'SAS Visual Analytics',
        'targetVariable': 'Price',
        'scoreCodeType': 'ds2MultiType',
        'function': 'prediction',
        'algorithm': 'Linear regression'
    }

    cas_session.loadactionset('regression')
    cas_session.loadactionset('astore')

    tbl = cas_session.upload(boston_dataset).casTable

    tbl.regression.glm(target='Price',
                       inputs=list(boston_dataset.columns[:-1]),
                       savestate='astore')

    desc = cas_session.astore.describe(rstore='astore', epcode=True)
    props = _get_model_properties(desc)

    # Verify properties are set
    for k, v in six.iteritems(target):
        assert props[k] == v

    files = create_files_from_astore(cas_session.CASTable('astore'))
    check_input_variables(files, BOSTON_INPUT_VARS)
def test_logistic(cas_session, iris_dataset):
    target = {
        'tool': 'SAS Visual Analytics',
        'targetVariable': 'Species',
        'scoreCodeType': 'ds2MultiType',
        'function': 'classification',
        'algorithm': 'Logistic regression'
    }

    cas_session.loadactionset('regression')
    cas_session.loadactionset('astore')

    tbl = cas_session.upload(iris_dataset).casTable

    tbl.regression.logistic(target='Species',
                                inputs=list(iris_dataset.columns[:-1]),
                                savestate='astore')

    desc = cas_session.astore.describe(rstore='astore', epcode=True)
    props = _get_model_properties(desc)

    for k, v in six.iteritems(target):
        assert props[k] == v

    files = create_files_from_astore(cas_session.CASTable('astore'))
    check_input_variables(files, IRIS_INPUT_VARS)
def test_bayesnet_classification(cas_session, iris_dataset):
    target = {
        'tool': 'SAS Visual Data Mining and Machine Learning',
        'targetVariable': 'Species',
        'scoreCodeType': 'ds2MultiType',
        'function': 'classification',
        'algorithm': 'Bayesian network'
    }

    cas_session.loadactionset('bayesianNetClassifier')
    cas_session.loadactionset('astore')

    tbl = cas_session.upload(iris_dataset).casTable

    tbl.bayesianNetClassifier.bnet(target='Species',
                                inputs=list(iris_dataset.columns[:-1]),
                                savestate='astore')

    desc = cas_session.astore.describe(rstore='astore', epcode=True)
    props = _get_model_properties(desc)

    for k, v in six.iteritems(target):
        assert props[k] == v

    files = create_files_from_astore(cas_session.CASTable('astore'))
    check_input_variables(files, IRIS_INPUT_VARS)
def test_svm_regression(cas_session, boston_dataset):
    target = {
        'tool': 'SAS Visual Data Mining and Machine Learning',
        'targetVariable': 'Price',
        'scoreCodeType': 'ds2MultiType',
        'function': 'prediction',
        'algorithm': 'Support vector machine'
    }

    cas_session.loadactionset('svm')
    cas_session.loadactionset('astore')

    tbl = cas_session.upload(boston_dataset).casTable

    tbl.svm.svmTrain(target='Price',
                     inputs=list(boston_dataset.columns[:-1]),
                     saveState='astore')

    desc = cas_session.astore.describe(rstore='astore', epcode=True)
    props = _get_model_properties(desc)

    for k, v in six.iteritems(target):
        assert props[k] == v

    files = create_files_from_astore(cas_session.CASTable('astore'))
    check_input_variables(files, BOSTON_INPUT_VARS)
def test_neuralnet_regression(cas_session, boston_dataset):
    target = {
        'tool': 'SAS Visual Data Mining and Machine Learning',
        'targetVariable': 'Price',
        'scoreCodeType': 'ds2MultiType',
        'function': 'prediction',
        'algorithm': 'Neural network'
    }

    cas_session.loadactionset('neuralnet')
    cas_session.loadactionset('astore')

    tbl = cas_session.upload(boston_dataset).casTable

    tbl.neuralNet.annTrain(target='Price',
                           inputs=list(boston_dataset.columns[:-1]),
                           # modelTable='network',
                           arch='MLP',
                           hiddens=[2],
                           combs=['linear'],
                           casout='network')
                           # savestate='astore')

    pytest.skip('Implement.  How to get an astore?')
    desc = cas_session.astore.describe(rstore='astore', epcode=True)
    props = _get_model_properties(desc)

    for k, v in six.iteritems(target):
        assert props[k] == v

    files = create_files_from_astore(cas_session.CASTable('astore'))
    check_input_variables(files, BOSTON_INPUT_VARS)
def test_gradboost_binary_classification(cas_session, cancer_dataset):
    target = {
        'tool': 'SAS Visual Data Mining and Machine Learning',
        'targetVariable': 'Type',
        'scoreCodeType': 'ds2MultiType',
        'function': 'classification',
        'algorithm': 'Gradient boosting',
        'targetLevel': 'binary'
    }

    cas_session.loadactionset('decisiontree')
    cas_session.loadactionset('astore')

    tbl = cas_session.upload(cancer_dataset).casTable

    tbl.decisiontree.gbtreetrain(target='Type',
                                 inputs=list(cancer_dataset.columns[:-1]),
                                 savestate='astore')

    desc = cas_session.astore.describe(rstore='astore', epcode=True)
    props = _get_model_properties(desc)

    for k, v in six.iteritems(target):
        assert props[k] == v

    files = create_files_from_astore(cas_session.CASTable('astore'))
    check_input_variables(files, CANCER_INPUT_VARS)
def test_dtree_regression(cas_session, boston_dataset):
    target = {
        'tool': 'SAS Visual Analytics',
        'targetVariable': 'Price',
        'scoreCodeType': 'ds2MultiType',
        'function': 'prediction',
        'algorithm': 'Decision tree'
    }

    cas_session.loadactionset('decisiontree')
    cas_session.loadactionset('astore')

    tbl = cas_session.upload(boston_dataset).casTable

    tbl.decisiontree.dtreetrain(target='Price',
                                inputs=list(boston_dataset.columns[:-1]),
                                casout='tree')

    pytest.skip('Implement.  How to get an astore?')

    cas_session.decisiontree.dtreeExportModel(modelTable='tree',
                                         casout='astore')

    desc = cas_session.astore.describe(rstore='astore', epcode=True)
    props = _get_model_properties(desc)

    for k, v in six.iteritems(target):
        assert props[k] == v

    files = create_files_from_astore(cas_session.CASTable('astore'))
    check_input_variables(files, BOSTON_INPUT_VARS)