Przejdź do treści
Biblioteka skilli
Dane i analityka · Analiza

feature-selection

/feature-selection

Wybiera najważniejsze opóźnienia, cechy okienne i zmienne zewnętrzne za pomocą selektorów z sklearn.

Repozytorium
skforecast ↗
Licencja
BSD-3-Clause
Ostatnia zmiana repozytorium
11.11.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 11.11.2026, bez odwołań do wycofanych modeli i API.

Licencja

BSD-3-Clause, otwarta.

Co robi i kiedy

Wybiera najważniejsze opóźnienia, cechy okienne i zmienne zewnętrzne za pomocą selektorów z sklearn.

Oryginalny opis (EN)

Selects the most relevant lags, window features, and exogenous variables using sklearn feature selectors (RFECV, SelectFromModel). Covers single-series and multi-series selection with force inclusion and subsampling. Use when the user has many features and wants to identify the most important ones.

Jak działa

  1. When to Use
  2. Single Series
  3. Multi-Series
  4. Force Inclusion
  5. Select Only Specific Feature Types
  6. Common Mistakes
Sekcje z nagłówków SKILL.md, w oryginale · 157 linii, 711 słów
Podgląd SKILL.md
---
name: feature-selection
description: >
  Selects the most relevant lags, window features, and exogenous variables
  using sklearn feature selectors (RFECV, SelectFromModel). Covers single-series
  and multi-series selection with force inclusion and subsampling.
  Use when the user has many features and wants to identify the most
  important ones.
---

# Feature Selection

## When to Use

Feature selection is an **optional refinement**, not a step on the critical path.
It is usually run once a forecaster is already trained and tuned, to trim the
feature set and reduce model complexity, rather than to improve accuracy. It is
also the slowest step in the pipeline, since the selector refits the estimator
many times.

Use feature selection when:
- You have many lags or exogenous variables and want to reduce overfitting
- You want to identify which features matter most
- You need to speed up inference or training by removing irrelevant features

After a large reduction, re-run `hyperparameter-optimization`: the best
parameters for the full feature set are not necessarily best for the trimmed one.

### Related skills

- **Prerequisite**: `autocorrelation-and-lag-selection` (generate an informed candidate set of lags before running the selector)
- **Prerequisite**: `feature-engineering` (create the rolling, calendar, and exogenous features that the selector will rank)
- **Next**: `hyperparameter-optimization` (re-tune the estimator on the reduced feature set)

## Single Series

`select_features` works with `ForecasterRecursive` and `ForecasterDirect`.

```python
from sklearn.feature_selection import RFECV
from sklearn.ensemble import RandomForestRegressor
from skforecast.recursive import ForecasterRecursive
from skforecast.preprocessing import RollingFeatures
from skforecast.feature_selection import select_features

# Create forecaster with many candidate features
rolling = RollingFeatures(stats=['mean', 'std', 'min', 'max'], window_sizes=[7, 14])

forecaster = ForecasterRecursive(
    estimator=RandomForestRegressor(n_estimators=100, random_state=123),
    lags=48,  # Many lags — feature selection will reduce
    window_features=rolling,
)

# Run feature selection
selected_lags, selected_window_features, selected_exog, selected_calendar_features = select_features(
    forecaster=forecaster,
    selector=RFECV(
        estimator=RandomForestRegressor(n_estimators=50, random_state=123),
        step=1,
        cv=3,                  # Records reach the selector in random order: random folds
    ),
    y=y_train,
    exog=exog_train,
    select_only=None,          # 'autoreg' (lags+window), 'exog', 'calendar', a list of them, or None (all)
    force_inclusion=None,      # Features to always keep (list or regex string)
    subsample=0.5,             # Use 50% of the records (without replacement, in random order)
    random_state=123,
    verbose=True,
)

# Apply selected lags to the same forecaster (simplest approach)
forecaster.set_lags(selected_lags)

# selected_window_features is a list of names (strings), not the RollingFeatures
# object. Use the names to verify which window features were selected.
print(f'Selected window features: {selected_window_features}')
print(f'Selected exog variables: {selected_exog}')
```

## Multi-Series

`select_features_multiseries` works with `ForecasterRecursiveMultiSeries` and `ForecasterDirectMultiVariate`.

> **Note:** When used with `ForecasterDirectMultiVariate`, `selected_lags` is returned as a `dict` (one entry per series) instead of a `list`.

```python
from skforecast.recursive import ForecasterRecursiveMultiSeries
from skforecast.feature_selection import select_features_multiseries

forecaster = ForecasterRecursiveMultiSeries(
    estimator=RandomForestRegressor(n_estimators=100, random_state=123),
    lags=48,
    encoding='ordinal',
)

selected_lags, selected_window_features, selected_exog, selected_calendar_features = select_features_multiseries(
    forecaster=forecaster,
    selector=RFECV(
        estimator=RandomForestRegressor(n_estimators=50, random_state=123),
        step=1,
        cv=3,
    ),
    series=series_df,
    exog=exog_df,
    select_only=None,
    force_inclusion=None,
    subsample=0.5,
    random_state=123,
    verbose=True,
)
```

## Force Inclusion

```python
# Always keep specific features regardless of selection
selected_lags, selected_wf, selected_exog, selected_cal = select_features(
    forecaster=forecaster,
    selector=selector,
    y=y_train,
    exog=exog_train,
    force_inclusion=['temperature', 'holiday'],  # Always keep these exog columns
)

# Regex pattern to force include
selected_lags, selected_wf, selected_exog, selected_cal = select_features(
    forecaster=forecaster,
    selector=selector,
    y=y_train,
    exog=exog_train,
    force_inclusion='^lag_',  # Keep all lag features
)
```

## Select Only Specific Feature Types

```python
# Only select among exogenous variables (keep all lags)
selected_lags, selected_wf, selected_exog, selected_cal = select_features(
    forecaster=forecaster,
    selector=selector,
    y=y_train,
    exog=exog_train,
    select_only='exog',  # Only select exog, keep all autoregressive features
)

# Only select among autoregressive features (keep all exog)
selected_lags, selected_wf, selected_exog, selected_cal = select_features(
    forecaster=forecaster,
    selector=selector,
    y=y_train,
    exog=exog_train,
    select_only='autoreg',  # Only select lags+window features, keep all exog
)
```

## Common Mistakes

1. **Using the wrong selector**: RFECV works best for recursive feature elimination. For faster selection, use `SelectFromModel`.
2. **Too small subsample**: If `subsample` is too small, selection may be unreliable. Use at least 0.3.
3. **Not updating forecaster**: After selection, update the forecaster with `forecaster.set_lags(selected_lags)` — the original is not modified in place by `select_features`.
4. **Running on full dataset**: Always run on training data only (`y_train`, `exog_train`).
5. **Confusing `selected_window_features` with `RollingFeatures`**: The returned `selected_window_features` is a list of **feature name strings** (e.g. `['roll_mean_7', 'roll_std_14']`), not the `RollingFeatures` object itself. Create a new `RollingFeatures` with only the selected statistics and window sizes (e.g. `RollingFeatures(stats=['mean', 'std'], window_sizes=[7, 14])`). If none was selected, set `window_features=None`: `RollingFeatures(stats=[])` raises a `ValueError`.
6. **Using `TimeSeriesSplit` as the `cv` of the selector**: The records are sampled without replacement and passed to the selector in random order, so its folds are random (an integer `cv` gives the same folds as `KFold(shuffle=True)`, with the records of every series spread over the folds in multi-series). A `TimeSeriesSplit` gives no temporal validation and raises a warning. Validate the selection with backtesting.

Wersje

RepozytoriumWynikLicencja
Ta strona · skforecast/skforecast100BSD-3-Clause
skforecast/skforecast-ai100Apache-2.0

Migawka bazy z 13.11.2026 · wersja paczki 7ec6509fc42a (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100sklearn-pipeline-builder
    Prawdopodobnie pomaga budować pipeline'y scikit-learn w trenowaniu modeli ML i wyzwala się automatycznie na hasła związane z sklearn pipeline builder.
  • 100feature-engineering
    Tworzy cechy do prognozowania szeregów czasowych w skforecast: cechy kalendarzowe, odległość od świąt, statystyki kroczące, różnicowanie i zmienne egzogeniczne kategoryczne.
  • 100feature-engineering
    Projektuje i implementuje cechy z surowych danych dla modeli uczenia maszynowego: kodowanie kategorii, skośność, interakcje, opóźnienia oraz cechy z tekstu i dat.
  • 90feature-engineering
    Tworzy, wyodrębnia i wybiera cechy wejściowe modelu, od PCA i embeddingów po kodowanie dat, opóźnienia i selekcję cech.
  • 90python-sklearn-workflow
    Projektuje poprawne ewaluacje scikit-learn: podziały bez wycieku danych, walidację krzyżową, wyszukiwanie, Pipeline i diagnostykę modelu.
  • 100autocorrelation-and-lag-selection
    Analizuje dynamikę szeregów czasowych funkcjami skforecast.stats acf, pacf i calculate_lag_autocorrelation: odczyt wzorców ACF i PACF, rzędy AR i MA, sezonowość i dobór opóźnień dla forecasterów.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.