Feature selection with Optuna optimization
Project description
OptunaFS
OptunaFS is a Python library that enhances feature selection in machine learning workflows by leveraging Optuna's optimization framework. It provides an intelligent way to identify and select the most impactful features for your models.
Key Features
- Automated feature selection through Optuna's hyperparameter optimization
- Supports any scikit-learn compatible estimator
- Built-in cross-validation for robust feature evaluation
- Support for feature grouping and early stopping
- Detailed feature importance analysis
- Type-safe implementation with comprehensive error handling
Installation
pip install optunafs
Usage Example
from optunafs import FeatureSelector
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import make_classification
# Create example dataset
X, y = make_classification(
n_samples=1000,
n_features=25,
n_informative=10,
random_state=42
)
# Initialize model
model = RandomForestClassifier(random_state=42)
# Create feature selector
selector = FeatureSelector(
model=model,
X=X,
y=y,
scoring='roc_auc',
cv=4,
optimization_direction='maximize'
)
# Run optimization
result = selector.optimize(n_trials=100)
# Get selected features
print(f"Selected features: {result.selected_features}")
print(f"Best score: {result.best_score:.4f}")
# Transform data using selected features
X_transformed = selector.transform(X)
Useful Features
Feature Groups
You can define groups of features that should be selected together:
feature_groups = {
'group1': ['feature1', 'feature2', 'feature3'],
'group2': ['feature4', 'feature5']
}
selector = FeatureSelector(
model=model,
X=X,
y=y,
scoring='accuracy',
feature_groups=feature_groups
)
Early Stopping
Enable early stopping to automatically halt optimization when no improvement is seen:
selector = FeatureSelector(
model=model,
X=X,
y=y,
scoring='accuracy',
early_stopping_rounds=10
)
Feature Importance Analysis
Get detailed insights into feature selection patterns:
importance_df = selector.get_feature_importance()
print(importance_df.sort_values('selection_frequency', ascending=False))
Development
# Clone the repository
git clone https://github.com/yourusername/optunafs.git
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest tests/
License
This project is licensed under the terms of the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file optunafs-0.1.0.post1.tar.gz.
File metadata
- Download URL: optunafs-0.1.0.post1.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
689dc9e678cb5f24b86f9df5f78995f57879d12581201e0c5ca3b89a9ca3c2e4
|
|
| MD5 |
ec00c775214b5ca9ff27f03e51ae2d03
|
|
| BLAKE2b-256 |
c76c1a3ca63abab9e14d789d9473b68804d918bef5a5e4d6e3c2dd4466533dad
|
File details
Details for the file optunafs-0.1.0.post1-py3-none-any.whl.
File metadata
- Download URL: optunafs-0.1.0.post1-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c09c3f28fb8797e75e73b176016a13badc31cf17d854e57e8d031e01dc959cb1
|
|
| MD5 |
aef53053d3433f66758fee0d86deb3d2
|
|
| BLAKE2b-256 |
636df6ffaeb41cb2d25ec1e3d0c3d6ec91df02eca37177056cd59bd852734725
|