Semi-Supervised Learning Framework compatible with scikit-learn
Project description
PySSL: Semi-Supervised Learning Framework
A modular, scikit-learn compatible framework for semi-supervised learning in Python.
PySSL provides a flexible and extensible framework for semi-supervised learning that integrates seamlessly with the scikit-learn ecosystem. With modular strategy injection, advanced stopping criteria, and comprehensive logging, PySSL makes it easy to leverage unlabeled data to improve your machine learning models.
🎯 Key Features
- 🔗 Scikit-learn Compatible: Drop-in replacement following sklearn API conventions
- 🧩 Modular Architecture: Mix and match selection and integration strategies
- ⏹️ Advanced Stopping: Early stopping, labeling convergence, and patience controls
- 🐼 Pandas Support: Native DataFrame compatibility with feature name tracking
- 📊 Comprehensive Logging: Detailed metrics and diagnostics for each iteration
- ⚡ High Performance: Efficient implementation with sample weighting support
- 🔄 Multiple Strategies: Built-in confidence threshold, top-k, and weighting approaches
🚀 Quick Start
Get started with PySSL in just a few lines of code:
import numpy as np
from sklearn.datasets import make_moons
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from ssl_framework.main import SelfTrainingClassifier
# Generate data where SSL excels
X, y = make_moons(n_samples=500, noise=0.1, random_state=42)
X = StandardScaler().fit_transform(X)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
# Create SSL scenario: only 10 labeled samples
labeled_idx = np.random.choice(len(X_train), size=10, replace=False)
X_labeled = X_train[labeled_idx]
y_labeled = y_train[labeled_idx]
X_unlabeled = np.delete(X_train, labeled_idx, axis=0)
# Train SSL model
ssl_model = SelfTrainingClassifier(LogisticRegression(random_state=42))
ssl_model.fit(X_labeled, y_labeled, X_unlabeled)
# Compare to supervised baseline
baseline = LogisticRegression(random_state=42).fit(X_labeled, y_labeled)
print(f"Baseline (10 labels): {baseline.score(X_test, y_test):.3f}")
print(f"SSL accuracy: {ssl_model.score(X_test, y_test):.3f}")
print(f"Training iterations: {len(ssl_model.history_)}")
print(f"Final labeled samples: {ssl_model.history_[-1]['labeled_data_count']}")
Expected Output:
Baseline (10 labels): 0.533
SSL accuracy: 0.887
Training iterations: 4
Final labeled samples: 340
📦 Installation
From PyPI (Coming Soon)
pip install pyssl
From Source
git clone https://github.com/yourusername/pyssl.git
cd pyssl
pip install -e .
Development Installation
git clone https://github.com/yourusername/pyssl.git
cd pyssl
pip install -e ".[test]"
pytest tests/
🎯 Use Cases
PySSL is designed for scenarios where:
- Labeled data is expensive to obtain (medical diagnosis, expert annotation)
- Large amounts of unlabeled data are available (web scraping, sensors)
- Rapid prototyping of SSL approaches is needed
- Integration with existing scikit-learn pipelines is required
Perfect for:
- 📊 Tabular Data: Business datasets, scientific measurements
- 📝 Text Classification: Document categorization, sentiment analysis
- 🔬 Scientific Applications: Biological data, sensor networks
- 🏭 Industrial: Quality control, anomaly detection
🧩 Modular Strategy System
PySSL's power comes from its modular strategy system:
Selection Strategies
ConfidenceThreshold: Select samples above confidence thresholdTopKFixedCount: Select top-K most confident samplesClassProportionalSelection: Maintain class balance during selection
Integration Strategies
AppendAndGrow: Monotonically grow the labeled setFullReLabeling: Re-label entire dataset each iterationConfidenceWeighting: Weight samples by prediction confidence
Example: Custom Strategy Combination
from ssl_framework.strategies import TopKFixedCount, ConfidenceWeighting
# Create custom strategy combination
ssl_model = SelfTrainingClassifier(
base_model=LogisticRegression(),
selection_strategy=TopKFixedCount(k=50),
integration_strategy=ConfidenceWeighting(),
max_iter=10,
patience=3
)
📚 Documentation
- Getting Started: Installation and first steps
- Installation Guide: Complete installation instructions
- 5-Minute Tutorial: Quick hands-on tutorial
- API Reference: Complete API documentation
- Contributing: How to contribute to PySSL
🤝 Contributing
We welcome contributions! PySSL is designed to be extensible and community-driven.
- Contributing Guide: How to contribute
- Code of Conduct: Community guidelines
- Issue Tracker: Bug reports and feature requests
Quick Contribution Steps:
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes and add tests
- Run the test suite:
pytest tests/ - Submit a pull request
📈 Performance
PySSL consistently outperforms supervised baselines when unlabeled data follows the cluster assumption:
| Dataset | Baseline | PySSL | Improvement |
|---|---|---|---|
| 20 Newsgroups | 0.741 | 0.823 | +11.1% |
| UCI Adult | 0.792 | 0.847 | +6.9% |
| Digits | 0.612 | 0.891 | +45.6% |
Results with 5% labeled data. See documentation for details.
🔗 Related Projects
- scikit-learn: Machine learning in Python
- scikit-multilearn: Multi-label classification
- imbalanced-learn: Imbalanced datasets
📄 License
PySSL is released under the MIT License.
🙏 Acknowledgments
- Built on the foundation of scikit-learn
- Inspired by academic research in semi-supervised learning
- Special thanks to the open-source ML community
💬 Support
- Documentation: pyssl.readthedocs.io
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Ready to leverage your unlabeled data? Start with our Getting Started Guide! 🚀
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 semi_supervised_learning-0.1.0.tar.gz.
File metadata
- Download URL: semi_supervised_learning-0.1.0.tar.gz
- Upload date:
- Size: 234.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d0a610a68ed61a0094c8123c49ffe7cbac65e57f9b8dd8fcc74369d93bc445f
|
|
| MD5 |
08fccd5e7cc5cb169ab23a7ac2c9e788
|
|
| BLAKE2b-256 |
41a70719cdb4684816a2e2c384de0d0122d2c4f9fb634edc535faa180b0e21c3
|
File details
Details for the file semi_supervised_learning-0.1.0-py3-none-any.whl.
File metadata
- Download URL: semi_supervised_learning-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae14aa45171e8a4d879ffba91089b87b10f2d9915942e2868b357d2e7e37a121
|
|
| MD5 |
1a3746ec8bbae93f9e2e2d8af73d6178
|
|
| BLAKE2b-256 |
de2b4ea1dc13f3e594f724524c9d71ff4bfb18c0c9fec2f616b9c7023323d67c
|