Example #1
0
def test_prediction_to_csv_class():
    """Test util.prediction_to_csv"""
    with create_test_project() as p, create_test_dataset(p) as ds,\
         create_test_featureset(p) as fs,\
         create_test_model(fs, model_type='LinearSGDClassifier') as m,\
         create_test_prediction(ds, m) as pred:
        pred = featureset.from_netcdf(pred.file.uri)
        assert util.prediction_to_csv(pred) ==\
            [['ts_name', 'true_target', 'prediction'],
             ['0', 'Mira', 'Mira'],
             ['1', 'Classical_Cepheid', 'Classical_Cepheid'],
             ['2', 'Mira', 'Mira'],
             ['3', 'Classical_Cepheid', 'Classical_Cepheid'],
             ['4', 'Mira', 'Mira']]
Example #2
0
def test_pred_results_table_rfc(driver):
    driver.get('/')
    with create_test_project() as p, create_test_dataset(p) as ds,\
         create_test_featureset(p) as fs, create_test_model(fs) as m,\
         create_test_prediction(ds, m):
        _click_prediction_row(p.id, driver)
        try:
            rows = _grab_pred_results_table_rows(driver, 'Mira')
            for row in rows:
                probs = [
                    float(v.text)
                    for v in row.find_elements_by_tag_name('td')[3::2]
                ]
                assert sorted(probs, reverse=True) == probs
            driver.find_element_by_xpath(
                "//th[contains(text(),'Time Series')]")
        except:
            driver.save_screenshot("/tmp/pred_click_tr_fail.png")
            raise
Example #3
0
def test_prediction_to_csv_regr():
    """Test util.prediction_to_csv"""
    with create_test_project() as p, create_test_dataset(p, label_type='regr') as ds,\
         create_test_featureset(p, label_type='regr') as fs,\
         create_test_model(fs, model_type='LinearRegressor') as m,\
         create_test_prediction(ds, m) as pred:

        pred = featureset.from_netcdf(pred.file.uri)
        results = util.prediction_to_csv(pred)

        assert results[0] == ['ts_name', 'true_target', 'prediction']

        npt.assert_array_almost_equal(
            [[float(e) for e in row] for row in results[1:]],
            [[0, 2.2, 2.2],
             [1, 3.4, 3.4],
             [2, 4.4, 4.4],
             [3, 2.2, 2.2],
             [4, 3.1, 3.1]])
Example #4
0
def test_download_prediction_csv_class(driver):
    driver.get('/')
    with create_test_project() as p, create_test_dataset(p) as ds,\
         create_test_featureset(p) as fs,\
         create_test_model(fs, model_type='LinearSGDClassifier') as m,\
         create_test_prediction(ds, m):
        _click_download(p.id, driver)
        assert os.path.exists('/tmp/cesium_prediction_results.csv')
        try:
            npt.assert_equal(
                np.genfromtxt('/tmp/cesium_prediction_results.csv',
                              dtype='str'),
                [
                    'ts_name,true_target,prediction', '0,Mira,Mira',
                    '1,Classical_Cepheid,Classical_Cepheid', '2,Mira,Mira',
                    '3,Classical_Cepheid,Classical_Cepheid', '4,Mira,Mira'
                ])
        finally:
            os.remove('/tmp/cesium_prediction_results.csv')
Example #5
0
def test_download_prediction_csv_regr(driver):
    driver.get('/')
    with create_test_project() as p, create_test_dataset(p, label_type='regr') as ds,\
         create_test_featureset(p, label_type='regr') as fs,\
         create_test_model(fs, model_type='LinearRegressor') as m,\
         create_test_prediction(ds, m):
        _click_download(p.id, driver)
        assert os.path.exists('/tmp/cesium_prediction_results.csv')
        try:
            results = np.genfromtxt('/tmp/cesium_prediction_results.csv',
                                    dtype='str',
                                    delimiter=',')
            npt.assert_equal(results[0],
                             ['ts_name', 'true_target', 'prediction'])
            npt.assert_array_almost_equal(
                [[float(e) for e in row] for row in results[1:]],
                [[0, 2.2, 2.2], [1, 3.4, 3.4], [2, 4.4, 4.4], [3, 2.2, 2.2],
                 [4, 3.1, 3.1]])
        finally:
            os.remove('/tmp/cesium_prediction_results.csv')
Example #6
0
def test_add_prediction_lsgdc(driver):
    driver.get('/')
    with create_test_project() as p, create_test_dataset(p) as ds,\
         create_test_featureset(p) as fs,\
         create_test_model(fs, model_type='LinearSGDClassifier') as m:
        _add_prediction(p.id, driver)
Example #7
0
def test_add_prediction_rfc(driver):
    driver.get('/')
    with create_test_project() as p, create_test_dataset(p) as ds,\
         create_test_featureset(p) as fs, create_test_model(fs) as m:
        _add_prediction(p.id, driver)
Example #8
0
def test_add_prediction_rfr(driver):
    driver.get('/')
    with create_test_project() as p, create_test_dataset(p, label_type='regr') as ds,\
         create_test_featureset(p, label_type='regr') as fs,\
         create_test_model(fs, model_type='RandomForestRegressor') as m:
        _add_prediction(p.id, driver)