コード例 #1
0
def project_cnn_feature_combined_rf_lda_analysis_with_highest(
        feature_matrix, y_vector, logger=None, rf_estimator=50):
    if logger is None:
        logger = setup_logger('')
    feature_matrix = np.squeeze(feature_matrix)
    num_instance, num_attribute, num_map = feature_matrix.shape
    predict = True
    skip_count = 0
    rf_time = 0
    lda_time = 0
    keep_avg_acc = -1
    map_attr_imp_matrix = []
    success_count = 0
    for i in range(0, num_map):
        map_feature_matrix = feature_matrix[:, :, i]
        if np.any(map_feature_matrix) is False:
            skip_count = skip_count + 1
            continue
        rf_lda_avg_acc = 0
        #feature_value_vector = []

        start_time = 0
        rf_feature_value_vector, rf_model, rf_f1_value, rf_run_time = rf_feature_extraction(
            map_feature_matrix, y_vector, predict, logger, rf_estimator)
        rf_time = rf_time + time.time() - start_time
        if rf_model is not None:
            rf_lda_avg_acc = rf_feature_value_vector
            feature_value_vector = rf_feature_value_vector * rf_f1_value
        start_time = 0
        lda_feature_vector, lda_model, lad_averaged_acc, lad_run_time = lda_feature_extraction(
            map_feature_matrix, y_vector, predict, logger)
        lda_time = lda_time + time.time() - start_time

        if lda_model is not None:
            rf_lda_avg_acc = rf_lda_avg_acc + lda_feature_vector
        success_count = success_count + 1
        #rf_lda_avg_acc = rf_f1_value + lad_averaged_acc
        if keep_avg_acc < rf_lda_avg_acc:
            keep_avg_acc = rf_lda_avg_acc
            feature_value_vector = feature_value_vector + lda_feature_vector * lad_averaged_acc
            map_attr_imp_matrix = [feature_value_vector]
        elif keep_avg_acc == rf_lda_avg_acc:
            map_attr_imp_matrix.append(feature_value_vector)
    map_attr_imp_matrix = np.array(map_attr_imp_matrix)
    logger.info("success count: " + str(success_count))
    logger.info("highest acc:" + str(keep_avg_acc))
    return map_attr_imp_matrix, rf_time + lda_time
コード例 #2
0
def project_cnn_feature_combined_lda_analysis(feature_matrix,
                                              y_vector,
                                              logger=None,
                                              rf_estimator=50):
    if logger is None:
        logger = setup_logger('')
    feature_matrix = np.squeeze(feature_matrix)
    num_instance, num_attribute, num_map = feature_matrix.shape
    predict = True
    skip_count = 0
    rf_time = 0
    lda_time = 0
    map_attr_imp_matrix = []
    success_count = 0

    feature_matrix_2d = feature_matrix.reshape(num_instance,
                                               num_attribute * num_map)
    start_time = 0
    lda_feature_value_vector, lda_model, lda_f1_value, lda_run_time = lda_feature_extraction(
        feature_matrix_2d, y_vector, predict, logger)
    lda_time = time.time() - start_time

    lda_feature_value_vector = lda_feature_value_vector.reshape(
        num_attribute, num_map)
    lda_feature_value_vector = np.sum(lda_feature_value_vector, axis=1)
    sum_value = sum(lda_feature_value_vector)
    lda_feature_value_vector = lda_feature_value_vector / float(sum_value)
    lda_class_attr_list = map_attr_imp_analysis(lda_feature_value_vector,
                                                logger)

    logger.info("lda feature value: " + str(lda_feature_value_vector.shape))
    logger.info("lda f1 value: " + str(lda_f1_value))
    logger.info("lda only attr:" + str(lda_class_attr_list))

    feature_value_vector = lda_feature_value_vector
    return feature_value_vector, rf_time + lda_time
コード例 #3
0
def project_cnn_feature_combined_rf_lda_analysis(feature_matrix,
                                                 y_vector,
                                                 logger=None,
                                                 rf_estimator=50):
    if logger is None:
        logger = setup_logger('')
    #feature_matrix = np.squeeze(feature_matrix)
    num_instance, num_attribute, num_map = feature_matrix.shape
    predict = True
    skip_count = 0
    rf_time = 0
    lda_time = 0
    map_attr_imp_matrix = []
    success_count = 0

    feature_matrix_2d = feature_matrix.reshape(num_instance,
                                               num_attribute * num_map)
    start_time = 0
    rf_feature_value_vector, rf_model, rf_f1_value, rf_run_time = rf_feature_extraction(
        feature_matrix_2d, y_vector, predict, logger, rf_estimator)
    rf_time = rf_time + time.time() - start_time
    start_time = 0
    lda_feature_value_vector, lda_model, lda_f1_value, lda_run_time = lda_feature_extraction(
        feature_matrix_2d, y_vector, predict, logger)
    lda_time = time.time() - start_time
    #print rf_feature_value_vector
    #print np.sum(rf_feature_value_vector)
    #print lda_feature_value_vector
    #print np.sum(lda_feature_value_vector)

    rf_feature_value_vector = rf_feature_value_vector.reshape(
        num_attribute, num_map)
    rf_feature_value_vector = np.sum(rf_feature_value_vector, axis=1)
    sum_value = sum(rf_feature_value_vector)
    rf_feature_value_vector = rf_feature_value_vector / float(sum_value)
    rf_feature_value_vector = rf_feature_value_vector * rf_f1_value
    rf_class_attr_list = map_attr_imp_analysis(rf_feature_value_vector, logger)

    logger.info("rf feature value: " + str(rf_feature_value_vector))
    logger.info("rf f1 value: " + str(rf_f1_value))
    logger.info("rf only attr:" + str(rf_class_attr_list))

    feature_value_vector = rf_feature_value_vector
    if lda_feature_value_vector is not None:
        lda_feature_value_vector = lda_feature_value_vector.reshape(
            num_attribute, num_map)
        lda_feature_value_vector = np.sum(lda_feature_value_vector, axis=1)
        sum_value = sum(lda_feature_value_vector)
        lda_feature_value_vector = lda_feature_value_vector / float(sum_value)
        lda_feature_value_vector = lda_feature_value_vector * lda_f1_value
        lda_class_attr_list = map_attr_imp_analysis(lda_feature_value_vector,
                                                    logger)
        lda_max = max(lda_feature_value_vector)
        logger.info("lda only attr:" + str(lda_class_attr_list))
        logger.info("lda feature value: " + str(lda_feature_value_vector))
        logger.info("lda f1 value: " + str(lda_f1_value))
        logger.info("max lda value: " + str(lda_max))
        if lda_max < 0.9:
            feature_value_vector = feature_value_vector + lda_feature_value_vector

    #if rf_f1_value > lda_f1_value:
    #    feature_value_vector = rf_feature_value_vector
    #elif rf_f1_value < lda_f1_value:
    #    feature_value_vector = lda_feature_value_vector
    #else:
    #    feature_value_vector = rf_feature_value_vector + lda_feature_value_vector

    sum_value = sum(feature_value_vector)
    feature_value_vector = feature_value_vector / float(sum_value)
    class_attr_list = map_attr_imp_analysis(feature_value_vector, logger)
    logger.info("overall rf and lda feature value: " +
                str(feature_value_vector))
    logger.info("rf and lda attr:" + str(class_attr_list))
    return feature_value_vector, rf_time + lda_time