scikit-fda: Functional Data Analysis in Python

repository·develop·Indexed 43 days ago

https://github.com/gaa-uam/scikit-fda

A Python library for Functional Data Analysis (FDA) providing tools for the representation, preprocessing, exploratory analysis, and statistical modeling of data depending on a continuous parameter. It includes modules for functional data objects (FData), depth measures, outlier detection (BoxplotOutlierDetector, MSPlotOutlierDetector), location and dispersion statistics, and specialized visualization tools like Magnitude-Shape plots and Outliergrams.

Tokens
10.9K
Snippets
31
Records
87
Agent score
56%

What's inside scikit-fda

  1. Overview of scikit-fda capabilities

    develop

    scikit-fda is a Python package for Functional Data Analysis (FDA), which involves analyzing data that depends on a continuous parameter.

    Key features include:

    • Functional Data Representation: Tools to work with functional data and its representations.
    • Exploratory Analysis: Utilities for inspecting functional data.
    • Preprocessing: Methods for preparing functional data.
    • Statistical Tasks: Support for inference, classification, regression, and clustering of functional data.
  2. Preprocessing functional data in scikit-fda

    develop

    scikit-fda provides several preprocessing modules to prepare functional data for analysis. Depending on the nature of your data, you can use the following categories of preprocessing:

    • Missing data: Reconstruct invalid or missing information in observations.
    • Smoothing: Reduce noise in functional data to better represent the underlying true functions.
    • Registration: Align misaligned functional data to eliminate phase variation.
    • Dimensionality Reduction: Reduce the number of features while preserving relevant information to improve clarity in analysis.
    • Feature construction: Create new features from curves to serve as explicit characteristics for machine learning algorithms.
  3. Use operators in skfda.misc

    develop

    The skfda.misc module provides several operators that can be applied to functional data and, in some cases, multivariate data. Linear operators within this module can also be utilized in the context of regularization tasks.

    Key operators available include:

    • Identity: An operator that returns the input unchanged.
    • LinearDifferentialOperator: An operator representing a linear differential operation.
    • SRSF: Square Root Stochastic Flow operator.
  4. Perform exploratory analysis of functional data

    develop

    The scikit-fda exploratory analysis package provides tools to summarize, interpret, and visualize functional data. It is organized into several specialized modules:

    • Depth: Techniques for measuring the centrality of functional data.
    • Outliers: Methods for detecting anomalous functional observations.
    • Stats: Statistical tools for functional data analysis.
    • Visualization: Tools for plotting and interpreting functional data structures.
  5. Explore scikit-fda miscellaneous submodules

    develop

    The skfda.misc package is organized into several specialized submodules for functional data tasks:

    • skfda.misc.covariances: Covariance functions (useful with skfda.datasets.make_gaussian_process).
    • skfda.misc.metrics: Functional data metrics designed for use with metric-based machine learning tools.
    • skfda.misc.operators: Operators, defined as functions that act upon other functions.
    • skfda.misc.regularization: Regularization functions used in contexts like LinearRegression, FPCA (Functional Principal Component Analysis), or BasisSmoother.
    • skfda.misc.hat_matrix: (Available in the module structure).
    • skfda.misc.scoring: (Available in the module structure).
  6. Use scikit-fda for Machine Learning tasks

    develop

    The scikit-fda machine learning module provides classes and utilities designed to solve machine learning problems using functional data. All classes in this module are compatible with scikit-learn estimators and utilities.

    The module is organized into three specialized sub-modules:

    • Classification: For functional classification tasks.
    • Clustering: For functional clustering tasks.
    • Regression: For functional regression tasks.
  7. What is a Hat Matrix in scikit-fda?

    develop

    In scikit-fda, a Hat Matrix is an object used to define how weights are calculated during kernel smoothing (skfda.preprocessing.smoothing.KernelSmoother) and kernel regression (skfda.ml.regression.KernelRegression).

    These algorithms estimate target values as a weighted mean of the training data. The specific type of Hat Matrix determines the mathematical logic used to compute those weights.

  8. Understand the FData base class

    develop
    All functional objects in the package are instances of FData. FData is an abstract base class that defines the common attributes and methods used across all representations (Grid, Basis, Irregular). Because it does not specify a concrete representation, it cannot be instantiated directly. Most package functionalities accept FData objects as arguments.
  9. Basic representation of functional data

    develop

    Functional data can be visualized directly as function graphs. If the domain dimension is 1, the data is represented as curves; if the domain dimension is 2, it is represented as surfaces. Each codomain dimension is plotted separately. For discretized data, discretization points can be visualized using a scatter plot.

    You can use the following classes for these representations:

    • skfda.exploratory.visualization.representation.GraphPlot: For curves or surfaces.
    • skfda.exploratory.visualization.representation.ScatterPlot: For discretized data points.

    Note that calling the .plot() method on skfda.representation.FData or skfda.representation.grid.FDataGrid objects will automatically instantiate and use one of these classes.

  10. Understand Domain and Codomain concepts

    develop

    Functional data analysis relies on defining the input and output spaces of functions:

    • Domain: The set of possible input values of a function.
    • Domain Range: The valid range where a function can be evaluated. In scikit-fda, this is a Python sequence containing a tuple of (minimum, maximum) values for each dimension of the domain. This is used for plotting and as the domain of integration.
    • Codomain: The set of allowed output values of a function.
    • Image: The set of actual output values that a function takes (a subset of the codomain).
    • Curve / Trajectory: A specific type of functional data object where both the domain and codomain are the set of real numbers ($\mathbb{R}$), meaning both dim_domain and dim_codomain attributes are 1.
  11. Use covariance functions in Gaussian processes

    develop

    The skfda.misc.covariances module provides several common covariance functions used in Gaussian processes. These functions can be passed as the covariance argument to skfda.preprocessing.make_gaussian_process to define the kernel of the process.

    Available covariance functions include:

    • Brownian
    • Covariance
    • Exponential
    • Gaussian
    • Linear
    • Polynomial
    • Matern
    • WhiteNoise