def _calculate_metafeatures_encoded(data_feat_type, basename, x_train, y_train, watcher, task, logger): EXCLUDE_META_FEATURES = EXCLUDE_META_FEATURES_CLASSIFICATION \ if task in CLASSIFICATION_TASKS else EXCLUDE_META_FEATURES_REGRESSION task_name = 'CalculateMetafeaturesEncoded' watcher.start_task(task_name) categorical = [ True if feat_type.lower() in ['categorical'] else False for feat_type in data_feat_type ] result = calculate_all_metafeatures_encoded_labels( x_train, y_train, categorical=categorical, dataset_name=basename, dont_calculate=EXCLUDE_META_FEATURES) for key in list(result.metafeature_values.keys()): if result.metafeature_values[key].type_ != 'METAFEATURE': del result.metafeature_values[key] watcher.stop_task(task_name) logger.info('Calculating Metafeatures (encoded attributes) took %5.2fsec', watcher.wall_elapsed(task_name)) return result
def _calculate_metafeatures_encoded(data_feat_type, basename, x_train, y_train, watcher, task, logger_): with warnings.catch_warnings(): warnings.showwarning = get_send_warnings_to_logger(logger_) EXCLUDE_META_FEATURES = EXCLUDE_META_FEATURES_CLASSIFICATION \ if task in CLASSIFICATION_TASKS else EXCLUDE_META_FEATURES_REGRESSION task_name = 'CalculateMetafeaturesEncoded' watcher.start_task(task_name) categorical = { col: True if feat_type.lower() == 'categorical' else False for col, feat_type in data_feat_type.items() } result = calculate_all_metafeatures_encoded_labels( x_train, y_train, categorical=categorical, dataset_name=basename, dont_calculate=EXCLUDE_META_FEATURES, logger=logger_) for key in list(result.metafeature_values.keys()): if result.metafeature_values[key].type_ != 'METAFEATURE': del result.metafeature_values[key] watcher.stop_task(task_name) logger_.info( 'Calculating Metafeatures (encoded attributes) took %5.2fsec', watcher.wall_elapsed(task_name)) return result
def calc_meta_features_encoded(X_train, Y_train, categorical, dataset_name): """ Calculate meta features with encoded labels :param X_train: :param Y_train: :param categorical: :param dataset_name: :return: """ if np.sum(categorical) != 0: raise ValueError("Training matrix doesn't look OneHotEncoded!") return calculate_all_metafeatures_encoded_labels( X_train, Y_train, categorical, dataset_name + SENTINEL, dont_calculate=EXCLUDE_META_FUTURES)
def _calculate_metafeatures_encoded__(basename, x_train, y_train): EXCLUDE_META_FEATURES = EXCLUDE_META_FEATURES_CLASSIFICATION \ if task in CLASSIFICATION_TASKS else EXCLUDE_META_FEATURES_REGRESSION task_name = 'CalculateMetafeaturesEncoded' result = calculate_all_metafeatures_encoded_labels( x_train, y_train, categorical=[False] * x_train.shape[1], dataset_name=basename, dont_calculate=EXCLUDE_META_FEATURES) for key in list(result.metafeature_values.keys()): if result.metafeature_values[key].type_ != 'METAFEATURE': del result.metafeature_values[key] return result
def _calculate_metafeatures_encoded(basename, x_train, y_train, watcher, task, logger): EXCLUDE_META_FEATURES = EXCLUDE_META_FEATURES_CLASSIFICATION \ if task in CLASSIFICATION_TASKS else EXCLUDE_META_FEATURES_REGRESSION task_name = 'CalculateMetafeaturesEncoded' watcher.start_task(task_name) result = calculate_all_metafeatures_encoded_labels( x_train, y_train, categorical=[False] * x_train.shape[1], dataset_name=basename, dont_calculate=EXCLUDE_META_FEATURES) for key in list(result.metafeature_values.keys()): if result.metafeature_values[key].type_ != 'METAFEATURE': del result.metafeature_values[key] watcher.stop_task(task_name) logger.info( 'Calculating Metafeatures (encoded attributes) took %5.2fsec', watcher.wall_elapsed(task_name)) return result
print(type(res)) print(len(res)) from autosklearn.metalearning.metafeatures.metafeatures import \ calculate_all_metafeatures_with_labels, \ calculate_all_metafeatures_encoded_labels, subsets X_train, Y_train, X_test, Y_test = get_dataset(dataset_name) print(Y_train) categorical = [False] * X_train.shape[1] meta_features_label = calculate_all_metafeatures_with_labels( X_train, Y_train, categorical, dataset_name) print(meta_features_label) meta_features_encoded_label = calculate_all_metafeatures_encoded_labels( X_train, Y_train, categorical, dataset_name) print(meta_features_encoded_label) #configuration_space = get_configuration_space( # { # 'metric': metric, # 'task': task, # 'is_sparse': False # }, #include_preprocessors=['no_preprocessing']) #X_train, Y_train, X_test, Y_test = get_dataset(dataset_name) #categorical = [False] * X_train.shape[1] #categorical = [False] * X_train.shape[1] #meta_features_label = calc_meta_features(X_train, y_train, categorical, 'a', REGRESSION) #meta_features_encoded_label = calc_meta_features_encoded(X_train, y_train, categorical, 'b', task)