filtro

Tidy tools to apply filter-based supervised feature selection methods

https://github.com/tidymodels/filtro

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (17.9%) to scientific vocabulary
Last synced: 11 months ago · JSON representation

Repository

Tidy tools to apply filter-based supervised feature selection methods

Basic Info
Statistics
  • Stars: 5
  • Watchers: 1
  • Forks: 0
  • Open Issues: 24
  • Releases: 2
Created about 1 year ago · Last pushed 11 months ago
Metadata Files
Readme Changelog License

README.Rmd

---
output: github_document
---



```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
```

# filtro 


[![R-CMD-check](https://github.com/tidymodels/filtro/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/tidymodels/filtro/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/tidymodels/filtro/graph/badge.svg)](https://app.codecov.io/gh/tidymodels/filtro)
[![CRAN status](https://www.r-pkg.org/badges/version/filtro)](https://CRAN.R-project.org/package=filtro)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)


> ⚠️ **filtro is under active development; breaking changes may occur.**

## Overview

filtro is tidy tools to apply filter-based supervised feature
selection methods. These methods score and rank feature relevance
using metrics such as p-values, correlation, feature importance, information gain, 
and more.

The package provides functions to rank and select a top proportion or number 
of features using built-in methods and the
[desirability2](https://desirability2.tidymodels.org) package, and 
supports streamlined preprocessing, either standalone or within tidymodels
workflows such as the [recipes](https://recipes.tidymodels.org) package. 

For a detailed introduction, please see [vignette("filtro")](https://filtro.tidymodels.org/dev/articles/filtro.html). 

## Installation

Install the released version of filtro from [CRAN](https://CRAN.R-project.org) with:

``` r
install.packages("filtro")
```

Install the development version from GitHub with:

``` r
# install.packages("pak")
pak::pak("tidymodels/filtro")
```

## Feature selection methods

Currently, the implemented filters include:

1. ANOVA F-test 

2. Correlation

3. Random forest feature importance 

4. Information gain

5. Area under the ROC curve 

6. Cross tabulation (Chi-squared test and Fisher's exact test) 

## Scoring examples

```{r}
#| label: start
#| include: false
library(filtro)
library(desirability2)
library(dplyr)
library(modeldata)
```

```{r}
library(filtro)
library(desirability2)
library(dplyr)
library(modeldata)
```

```{r}
ames_subset <- modeldata::ames |>
  # Use a subset of data for demonstration
  dplyr::select(
    Sale_Price,
    MS_SubClass,
    MS_Zoning,
    Lot_Frontage,
    Lot_Area,
    Street
  )
ames_subset <- ames_subset |>
  dplyr::mutate(Sale_Price = log10(Sale_Price))
```

```{r}
# ANOVA p-value
ames_aov_pval_res <-
  score_aov_pval |>
  fit(Sale_Price ~ ., data = ames_subset)
ames_aov_pval_res@results
```

```{r}
# Pearson correlation
ames_cor_pearson_res <-
  score_cor_pearson |>
  fit(Sale_Price ~ ., data = ames_subset)
ames_cor_pearson_res@results
```

```{r}
# Forest importance
ames_imp_rf_reg_res <-
  score_imp_rf |>
  fit(Sale_Price ~ ., data = ames_subset, seed = 42)
ames_imp_rf_reg_res@results
```

```{r}
# Information gain
ames_info_gain_reg_res <-
  score_info_gain |>
  fit(Sale_Price ~ ., data = ames_subset)
ames_info_gain_reg_res@results
```

## Filtering exmples for score *singular* 

```{r}
ames_aov_pval_res@results
```

```{r}
# Show best score, based on proportion of predictors
ames_aov_pval_res |> show_best_score_prop(prop_terms = 0.2)
```

```{r}
# Fill safe value, then show best score 
ames_aov_pval_res <- ames_aov_pval_res |> fill_safe_value()
ames_aov_pval_res |> show_best_score_prop(prop_terms = 0.2)
```

## Filtering examples for scores *plural* 

```{r}
# Create a list
class_score_list <- list(
  ames_cor_pearson_res,
  ames_imp_rf_reg_res,
  ames_info_gain_reg_res
)
```

```{r}
# Fill safe values
ames_scores_results <- class_score_list |>
  fill_safe_values() |>
  # Remove outcome
  dplyr::select(-outcome)
ames_scores_results
```

```{r}
# Single and multi-parameter optimization using desirability functions
# Optimize correlation alone
ames_scores_results |>
  show_best_desirability_prop(
    maximize(cor_pearson, low = 0, high = 1)
  )

# Optimize correlation and forest importance
ames_scores_results |>
  show_best_desirability_prop(
    maximize(cor_pearson, low = 0, high = 1),
    maximize(imp_rf)
  )

# Optimize correlation, forest importance and information gain
ames_scores_results |>
  show_best_desirability_prop(
    maximize(cor_pearson, low = 0, high = 1),
    maximize(imp_rf),
    maximize(infogain)
  )

# Same as above, but retain only a proportion of predictors
ames_scores_results |>
  show_best_desirability_prop(
    maximize(cor_pearson, low = 0, high = 1),
    maximize(imp_rf),
    maximize(infogain),
    prop_terms = 0.2
  )

# Optimize toward a target
ames_scores_results |>
  show_best_desirability_prop(
    target(cor_pearson, low = 0.2, target = 0.255, high = 0.9)
  )

# Optimize with box constraints
ames_scores_results |>
  show_best_desirability_prop(
    constrain(cor_pearson, low = 0.2, high = 1)
  )
```

## Contributing

Please note that the filtro project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.

- For questions and discussions about tidymodels packages, modeling, and machine learning, please [post on Posit Community](https://forum.posit.co/new-topic?category_id=15&tags=tidymodels,question).

- If you think you have encountered a bug, please [submit an issue](https://github.com/tidymodels/filtro/issues).

- Either way, learn how to create and share a [reprex](https://reprex.tidyverse.org/articles/articles/learn-reprex.html) (a minimal, reproducible example), to clearly communicate about your code.

- Check out further details on [contributing guidelines for tidymodels packages](https://www.tidymodels.org/contribute/) and [how to get help](https://www.tidymodels.org/help/).

Owner

  • Name: tidymodels
  • Login: tidymodels
  • Kind: organization

GitHub Events

Total
  • Create event: 52
  • Release event: 3
  • Issues event: 56
  • Watch event: 4
  • Delete event: 50
  • Issue comment event: 34
  • Push event: 207
  • Pull request review event: 41
  • Pull request review comment event: 35
  • Pull request event: 88
Last Year
  • Create event: 52
  • Release event: 3
  • Issues event: 56
  • Watch event: 4
  • Delete event: 50
  • Issue comment event: 34
  • Push event: 207
  • Pull request review event: 41
  • Pull request review comment event: 35
  • Pull request event: 88

Committers

Last synced: about 1 year ago

All Time
  • Total Commits: 44
  • Total Committers: 2
  • Avg Commits per committer: 22.0
  • Development Distribution Score (DDS): 0.045
Past Year
  • Commits: 44
  • Committers: 2
  • Avg Commits per committer: 22.0
  • Development Distribution Score (DDS): 0.045
Top Committers
Name Email Commits
Frances Lin f****c@g****m 42
Emil Hvitfeldt e****t@g****m 2

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 46
  • Total pull requests: 59
  • Average time to close issues: 11 days
  • Average time to close pull requests: 1 day
  • Total issue authors: 3
  • Total pull request authors: 3
  • Average comments per issue: 0.09
  • Average comments per pull request: 0.24
  • Merged pull requests: 39
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 46
  • Pull requests: 59
  • Average time to close issues: 11 days
  • Average time to close pull requests: 1 day
  • Issue authors: 3
  • Pull request authors: 3
  • Average comments per issue: 0.09
  • Average comments per pull request: 0.24
  • Merged pull requests: 39
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • franceslinyc (41)
  • topepo (4)
  • EmilHvitfeldt (1)
Pull Request Authors
  • franceslinyc (48)
  • topepo (8)
  • EmilHvitfeldt (3)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cran 253 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 2
  • Total maintainers: 1
cran.r-project.org: filtro

Feature Selection Using Supervised Filter-Based Methods

  • Versions: 2
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 253 Last month
Rankings
Dependent packages count: 25.9%
Dependent repos count: 31.8%
Average: 47.8%
Downloads: 85.6%
Maintainers (1)
Last synced: 11 months ago

Dependencies

.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v4 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pkgdown.yaml actions
  • JamesIves/github-pages-deploy-action v4.5.0 composite
  • actions/checkout v4 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pr-commands.yaml actions
  • actions/checkout v4 composite
  • r-lib/actions/pr-fetch v2 composite
  • r-lib/actions/pr-push v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/test-coverage.yaml actions
  • actions/checkout v4 composite
  • actions/upload-artifact v4 composite
  • codecov/codecov-action v5 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
DESCRIPTION cran
  • scales * depends
  • aorsf * imports
  • cli * imports
  • dplyr * imports
  • glue * imports
  • pROC * imports
  • partykit * imports
  • purrr * imports
  • ranger * imports
  • stats * imports
  • tibble * imports
  • modeldata * suggests
  • testthat >= 3.0.0 suggests
  • titanic * suggests