Ejemplo n.º 1
0
 def test_stat_aibolit_pipeline(self):
     model = self.__load_mock_model()
     test_df = generate_fake_dataset()
     table = Stats.aibolit_stat(test_df, model)
     test_csv = Path(self.cur_file_dir, 'results_test.csv')
     results_df = pd.read_csv(test_csv, index_col=0)
     all_elements_compared: pd.DataFrame = table.eq(results_df)
     bool_eq_elems = np.ravel(all_elements_compared.values)
     are_equal_arrays = np.logical_and.reduce(bool_eq_elems, axis=0)
     self.assertTrue(are_equal_arrays)
Ejemplo n.º 2
0
def test_train_with_selected_features():
    cur_file_dir = Path(os.path.realpath(__file__)).parent
    model = PatternRankingModel()
    selected_patterns = ['P18', 'P9', 'M2', 'M5']
    train_df = generate_fake_dataset()
    print('Features for the whole dataset: {}'.format(list(train_df.columns)))
    target = train_df.pop('M4')
    start = time()
    print('Start training...')
    model.fit_regressor(train_df, target, selected_patterns)
    end = time()
    print('End training. Elapsed time: {:.2f} secs'.format(end - start))
    # this folder is created by catboost library, impossible to get rid of it
    catboost_folder = Path(cur_file_dir, 'catboost_info')
    if catboost_folder.exists():
        shutil.rmtree(catboost_folder)
    print('Model features: {}'.format(model.features_conf['features_order']))
Ejemplo n.º 3
0
def test_model_training():
    cur_file_dir = Path(os.path.realpath(__file__)).parent
    config = Config.get_patterns_config()
    model = PatternRankingModel()
    patterns = [x['code'] for x in config['patterns']]
    train_df = generate_fake_dataset()
    model.features_conf = {'features_order': patterns}
    scaled_df = scale_dataset(train_df, model.features_conf)
    start = time()
    print('Start training...')
    model.fit_regressor(scaled_df[patterns], scaled_df['M4'])
    end = time()
    print('End training. Elapsed time: {:.2f} secs'.format(end - start))
    # this folder is created by catboost library, impossible to get rid of it
    catboost_folder = Path(cur_file_dir, 'catboost_info')
    if catboost_folder.exists():
        shutil.rmtree(catboost_folder)