Feature Extraction from Grouped Data

An R6 implementation for calculating features from grouped data. The output will be one row for each group. This functionality is often needed in the feature extraction process of machine learning problems. Very large datasets are supported, since data is only read into RAM when needed. Calculation can be done in parallel and the process can be monitored. Global error handling is supported. Results are available in one final dataframe.


BuildStatus codecov AppVeyor BuildStatus

Feature extraction is a crucial step for tackling machine learning problems. Many machine learning problems start with complex (often timestamped) raw data with many grouped variables (e.g. heart rate measurements of many patients, gps data for analysis of movements of many participants of a study, etc.). Often times, this raw data cannot directly be used for machine learning algorithms. User-defined features must be extracted for this purpose. Examples could be the heart rate variability of a patient, or the maximum distance traveled by a participant of a gps study. Since there are many different machine learning applications and therefore many inherently different raw datasets and features which need to be calculated, we do not supply any automated features. fxtract assists you in the feature extraction process by helping with the data wrangling needed, but still allows you to extract your own defined features.

The user only needs to define functions which have a dataset as input and named vector (or list) with the desired features as output. The whole data wrangling (calculating the features for each ID and collecting the results in one final dataframe) is handled by fxtract. This package works with very large datasets and many different IDs and the main functionality is written in R6. Parallelization is available via future.

See the tutorial on how to use this package.

Installation

For the development version, use devtools:

devtools::install_github("QuayAu/fxtract")

Why don’t just use dplyr or other packages?

At first glance it looks like we just rewrote the summarize() functionality of dplyr. Another similar functionality is covered by the aggregate()-function from the base stats package. For small datasets and few (easy to calculate) features, using fxtract may indeed be a little overkill (and slower too).

However, this package was especially designed for projects with large datasets, many IDs, and many different feature functions. fxtract streamlines the process of loading datasets and adding feature functions. Once your dataset (with all IDs) becomes too big for memory, or if some feature functions fail on some IDs, using our package can save you many lines of code.

Usage

library(fxtract)
 
# user-defined function:
fun = function(data) {
  c(mean_sepal_length = mean(data$Sepal.Length),
    sd_sepal_length = sd(data$Sepal.Length))
}
 
# R6 object:
xtractor = Xtractor$new("xtractor")
xtractor$add_data(iris, group_by = "Species")
xtractor$add_feature(fun)
xtractor$calc_features()
xtractor$results
##       Species mean_sepal_length sd_sepal_length
## 1:     setosa             5.006       0.3524897
## 2: versicolor             5.936       0.5161711
## 3:  virginica             6.588       0.6358796

Features

  • Unit-tested functions.
  • Extracting features from raw data of many different IDs with the R6 Class Xtractor:
    • No more code bloat thanks to R6.
    • Very large datasets are supported, since data is only read into RAM when needed. Minimum requirement: Individual datasets for each ID must be small enough to be read into memory.
    • Features will be calculated for each ID individually and can be parallelized with the future-package.
    • If one feature on one ID throws an error, this will not stop the whole process (like in a traditional R script). The remaining features will still be calculated.
    • Individual features can be deleted or updated easily.
    • Calculation of features can be done in parallel and the process can be monitored. It is also possible to stop and return the calculation at a later time.
    • Results can be easily retrieved in one final dataframe.

News

fxtract 0.9.1

  • Initial release to CRAN

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("fxtract")

0.9.1 by Quay Au, 4 months ago


https://github.com/QuayAu/fxtract


Report a bug at https://github.com/QuayAu/fxtract/issues


Browse source code at https://github.com/cran/fxtract


Authors: Quay Au [aut, cre] , Clemens Stachl [ctb] , Ramona Schoedel [ctb] , Theresa Ullmann [ctb] , Andreas Hofheinz [ctb]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports dplyr, magrittr, checkmate, utils, data.table, future, future.apply, R6

Suggests testthat, knitr, covr, pkgdown


See at CRAN