.. image:: https://github.com/skorch-dev/skorch/blob/master/assets/skorch_bordered.svg
:width: 30%
------------
|build| |coverage| |docs| |huggingface| |powered|
A scikit-learn compatible neural network library that wraps PyTorch.
.. |build| image:: https://github.com/skorch-dev/skorch/workflows/tests/badge.svg
:alt: Test Status
.. |coverage| image:: https://github.com/skorch-dev/skorch/blob/master/assets/coverage.svg
:alt: Test Coverage
.. |docs| image:: https://readthedocs.org/projects/skorch/badge/?version=latest
:alt: Documentation Status
:target: https://skorch.readthedocs.io/en/latest/?badge=latest
.. |huggingface| image:: https://github.com/skorch-dev/skorch/actions/workflows/test-hf-integration.yml/badge.svg
:alt: Hugging Face Integration
:target: https://github.com/skorch-dev/skorch/actions/workflows/test-hf-integration.yml
.. |powered| image:: https://github.com/skorch-dev/skorch/blob/master/assets/powered.svg
:alt: Powered by
:target: https://github.com/ottogroup/
=========
Resources
=========
- `Documentation <https://skorch.readthedocs.io/en/latest/?badge=latest>`_
- `Source Code <https://github.com/skorch-dev/skorch/>`_
- `Installation <https://github.com/skorch-dev/skorch#installation>`_
========
Examples
========
To see more elaborate examples, look `here
<https://github.com/skorch-dev/skorch/tree/master/notebooks/README.md>`__.
.. code:: python
import numpy as np
from sklearn.datasets import make_classification
from torch import nn
from skorch import NeuralNetClassifier
X, y = make_classification(1000, 20, n_informative=10, random_state=0)
X = X.astype(np.float32)
y = y.astype(np.int64)
class MyModule(nn.Module):
def __init__(self, num_units=10, nonlin=nn.ReLU()):
super().__init__()
self.dense0 = nn.Linear(20, num_units)
self.nonlin = nonlin
self.dropout = nn.Dropout(0.5)
self.dense1 = nn.Linear(num_units, num_units)
self.output = nn.Linear(num_units, 2)
self.softmax = nn.Softmax(dim=-1)
def forward(self, X, **kwargs):
X = self.nonlin(self.dense0(X))
X = self.dropout(X)
X = self.nonlin(self.dense1(X))
X = self.softmax(self.output(X))
return X
net = NeuralNetClassifier(
MyModule,
max_epochs=10,
lr=0.1,
# Shuffle training data on each epoch
iterator_train__shuffle=True,
)
net.fit(X, y)
y_proba = net.predict_proba(X)
In an `sklearn Pipeline <https://scikit-learn.org/stable/modules/generated/sklearn.pipeline.Pipeline.html>`_:
.. code:: python
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
pipe = Pipeline([
('scale', StandardScaler()),
('net', net),
])
pipe.fit(X, y)
y_proba = pipe.predict_proba(X)
With `grid search <https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.GridSearchCV.html>`_:
.. code:: python
from sklearn.model_selection import GridSearchCV
# deactivate skorch-internal train-valid split and verbose logging
net.set_params(train_split=False, verbose=0)
params = {
'lr': [0.01, 0.02],
'max_epochs': [10, 20],
'module__num_units': [10, 20],
}
gs = GridSearchCV(net, params, refit=False, cv=3, scoring='accuracy', verbose=2)
gs.fit(X, y)
print("best score: {:.3f}, best params: {}".format(gs.best_score_, gs.best_params_))
skorch also provides many convenient features, among others:
- `Learning rate schedulers <https://skorch.readthedocs.io/en/stable/callbacks.html#skorch.callbacks.LRScheduler>`_ (Warm restarts, cyclic LR and many more)
- `Scoring using sklearn (and custom) scoring functions <https://skorch.readthedocs.io/en/stable/callbacks.html#skorch.callbacks.EpochScoring>`_
- `Early stopping <https://skorch.readthedocs.io/en/stable/callbacks.html#skorch.callbacks.EarlyStopping>`_
- `Checkpointing <https://skorch.readthedocs.io/en/stable/callbacks.html#skorch.callbacks.Checkpoint>`_
- `Parameter freezing/unfreezing <https://skorch.readthedocs.io/en/stable/callbacks.html#skorch.callbacks.Freezer>`_
- `Progress bar <https://skorch.readthedocs.io/en/stable/callbacks.html#skorch.callbacks.ProgressBar>`_ (for CLI as well as jupyter)
- `Automatic inference of CLI parameters <https://github.com/skorch-dev/skorch/tree/master/examples/cli>`_
- `Integration with GPyTorch for Gaussian Processes <https://skorch.readthedocs.io/en/latest/user/probabilistic.html>`_
- `Integration with Hugging Face 🤗 <https://skorch.readthedocs.io/en/stable/user/huggingface.html>`_
============
Installation
============
skorch requires Python 3.9 or higher.
conda installation
==================
You need a working conda installation. Get the correct miniconda for
your system from `here <https://conda.io/miniconda.html>`__.
To install skorch, you need to use the conda-forge channel:
.. code:: bash
conda install -c conda-forge skorch
We recommend to use a `conda virtual environment <https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html>`_.
**Note**: The conda channel is *not* managed by the skorch
maintainers. More information is available `here
<https://github.com/conda-forge/skorch-feedstock>`__.
pip installation
================
To install with pip, run:
.. code:: bash
python -m pip install -U skorch
Again, we recommend to use a `virtual environment
<https://docs.python.org/3/tutorial/venv.html>`_ for this.
From source
===========
If you would like to use the most recent additions to skorch or
help development, you should install skorch from source.
Using conda
-----------
To install skorch from source using conda, proceed as follows:
.. code:: bash
git clone https://github.com/skorch-dev/skorch.git
cd skorch
conda create -n skorch-env python=3.10
conda activate skorch-env
conda install -c pytorch pytorch
python -m pip install -r requirements.txt
python -m pip install .
If you want to help developing, run:
.. code:: bash
git clone https://github.com/skorch-dev/skorch.git
cd skorch
conda create -n skorch-env python=3.10
conda activate skorch-env
conda install -c pytorch pytorch
python -m pip install -r requirements.txt
python -m pip install -r requirements-dev.txt
python -m pip install -e .
py.test # unit tests
pylint skorch # static code checks
You may adjust the Python version to any of the supported Python versions.
Using pip
---------
For pip, follow these instructions instead:
.. code:: bash
git clone https://github.com/skorch-dev/skorch.git
cd skorch
# create and activate a virtual environment
python -m pip install -r requirements.txt
# install pytorch version for your system (see below)
python -m pip install .
If you want to help developing, run:
.. code:: bash
git clone https://github.com/skorch-dev/skorch.git
cd skorch
# create and activate a virtual environment
python -m pip install -r requirements.txt
# install pytorch version for your system (see below)
python -m pip install -r requirements-dev.txt
python -m pip install -e .
py.test # unit tests
pylint skorch # static code checks
PyTorch
=======
PyTorch is not covered by the dependencies, since the PyTorch version
you need is dependent on your OS and device. For installation
instructions for PyTorch, visit the `PyTorch website
<http://pytorch.org/>`__. skorch officially supports the last four
minor PyTorch versions, which currently are:
- 2.2.2
- 2.3.1
- 2.4.1
- 2.5.1
However, that doesn't mean that older versions don't work, just that
they aren't tested. Since skorch mostly relies on the stable part of
the PyTorch API, older PyTorch versions should work fine.
In general, running this to install PyTorch should work:
.. code:: bash
# using conda:
conda install pytorch pytorch-cuda -c pytorch
# using pip
python -m pip install torch
==================
External resources
==================
- @jakubczakon: `blog post
<https://neptune.ai/blog/model-training-libraries-pytorch-ecosystem>`_
"8 Creators and Core Contributors Talk About Their Model Training
Libraries From PyTorch Ecosystem" 2020
- @BenjaminBossan: `talk 1
<https://www.youtube.com/watch?v=Qbu_DCBjVEk>`_ "skorch: A
scikit-learn compatible neural network library" at PyCon/PyData 2019
- @githubnemo: `poster <https://github.com/githubnemo/skorch-poster>`_
for the PyTorch developer conference 2019
- @thomasjpfan: `talk 2 <https://www.youtube.com/watch?v=0J7FaLk0bmQ>`_
"Skorch: A Union of Scikit learn and PyTorch" at SciPy 2019
- @thomasjpfan: `talk 3 <https://www.youtube.com/watch?v=yAXsxf2CQ8M>`_
"Skorch - A Union of Scikit-learn and PyTorch" at PyData 2018
- @BenjaminBossan: `talk 4 <https://youtu.be/y_n7BjDCS-M>`_ "Extend your
scikit-learn workflow with Hugging Face and skorch" at PyData Amsterdam 2023
(`slides 4 <https://github.com/BenjaminBossan/presentations/blob/main/2023-09-14-pydata/presentation.org>`_)
=============
Communication
=============
- `GitHub discussions <https://github.com/skorch-dev/skorch/discussions>`_:
user questions, thoughts, install issues, general discussions.
- `GitHub issues <https://github.com/skorch-dev/skorch/issues>`_: bug
reports, feature requests, RFCs, etc.
- Slack: We run the #skorch channel on the `PyTorch Slack server
<https://pytorch.slack.com/>`_, for which you can `request access
here <https://bit.ly/ptslack>`_.
Raw data
{
"_id": null,
"home_page": "https://github.com/skorch-dev/skorch",
"name": "skorch",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/6d/fe/b59c04446b5d2af8617ac0df04f6cd3a2757d9d8c1f093af8bb4d2eaec2e/skorch-1.1.0.tar.gz",
"platform": null,
"description": ".. image:: https://github.com/skorch-dev/skorch/blob/master/assets/skorch_bordered.svg\n :width: 30%\n\n------------\n\n|build| |coverage| |docs| |huggingface| |powered|\n\nA scikit-learn compatible neural network library that wraps PyTorch.\n\n.. |build| image:: https://github.com/skorch-dev/skorch/workflows/tests/badge.svg\n :alt: Test Status\n\n.. |coverage| image:: https://github.com/skorch-dev/skorch/blob/master/assets/coverage.svg\n :alt: Test Coverage\n\n.. |docs| image:: https://readthedocs.org/projects/skorch/badge/?version=latest\n :alt: Documentation Status\n :target: https://skorch.readthedocs.io/en/latest/?badge=latest\n\n.. |huggingface| image:: https://github.com/skorch-dev/skorch/actions/workflows/test-hf-integration.yml/badge.svg\n :alt: Hugging Face Integration\n :target: https://github.com/skorch-dev/skorch/actions/workflows/test-hf-integration.yml\n\n.. |powered| image:: https://github.com/skorch-dev/skorch/blob/master/assets/powered.svg\n :alt: Powered by\n :target: https://github.com/ottogroup/\n\n=========\nResources\n=========\n\n- `Documentation <https://skorch.readthedocs.io/en/latest/?badge=latest>`_\n- `Source Code <https://github.com/skorch-dev/skorch/>`_\n- `Installation <https://github.com/skorch-dev/skorch#installation>`_\n\n========\nExamples\n========\n\nTo see more elaborate examples, look `here\n<https://github.com/skorch-dev/skorch/tree/master/notebooks/README.md>`__.\n\n.. code:: python\n\n import numpy as np\n from sklearn.datasets import make_classification\n from torch import nn\n from skorch import NeuralNetClassifier\n\n X, y = make_classification(1000, 20, n_informative=10, random_state=0)\n X = X.astype(np.float32)\n y = y.astype(np.int64)\n\n class MyModule(nn.Module):\n def __init__(self, num_units=10, nonlin=nn.ReLU()):\n super().__init__()\n\n self.dense0 = nn.Linear(20, num_units)\n self.nonlin = nonlin\n self.dropout = nn.Dropout(0.5)\n self.dense1 = nn.Linear(num_units, num_units)\n self.output = nn.Linear(num_units, 2)\n self.softmax = nn.Softmax(dim=-1)\n\n def forward(self, X, **kwargs):\n X = self.nonlin(self.dense0(X))\n X = self.dropout(X)\n X = self.nonlin(self.dense1(X))\n X = self.softmax(self.output(X))\n return X\n\n net = NeuralNetClassifier(\n MyModule,\n max_epochs=10,\n lr=0.1,\n # Shuffle training data on each epoch\n iterator_train__shuffle=True,\n )\n\n net.fit(X, y)\n y_proba = net.predict_proba(X)\n\nIn an `sklearn Pipeline <https://scikit-learn.org/stable/modules/generated/sklearn.pipeline.Pipeline.html>`_:\n\n.. code:: python\n\n from sklearn.pipeline import Pipeline\n from sklearn.preprocessing import StandardScaler\n\n pipe = Pipeline([\n ('scale', StandardScaler()),\n ('net', net),\n ])\n\n pipe.fit(X, y)\n y_proba = pipe.predict_proba(X)\n\nWith `grid search <https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.GridSearchCV.html>`_:\n\n.. code:: python\n\n from sklearn.model_selection import GridSearchCV\n\n # deactivate skorch-internal train-valid split and verbose logging\n net.set_params(train_split=False, verbose=0)\n params = {\n 'lr': [0.01, 0.02],\n 'max_epochs': [10, 20],\n 'module__num_units': [10, 20],\n }\n gs = GridSearchCV(net, params, refit=False, cv=3, scoring='accuracy', verbose=2)\n\n gs.fit(X, y)\n print(\"best score: {:.3f}, best params: {}\".format(gs.best_score_, gs.best_params_))\n\n\nskorch also provides many convenient features, among others:\n\n- `Learning rate schedulers <https://skorch.readthedocs.io/en/stable/callbacks.html#skorch.callbacks.LRScheduler>`_ (Warm restarts, cyclic LR and many more)\n- `Scoring using sklearn (and custom) scoring functions <https://skorch.readthedocs.io/en/stable/callbacks.html#skorch.callbacks.EpochScoring>`_\n- `Early stopping <https://skorch.readthedocs.io/en/stable/callbacks.html#skorch.callbacks.EarlyStopping>`_\n- `Checkpointing <https://skorch.readthedocs.io/en/stable/callbacks.html#skorch.callbacks.Checkpoint>`_\n- `Parameter freezing/unfreezing <https://skorch.readthedocs.io/en/stable/callbacks.html#skorch.callbacks.Freezer>`_\n- `Progress bar <https://skorch.readthedocs.io/en/stable/callbacks.html#skorch.callbacks.ProgressBar>`_ (for CLI as well as jupyter)\n- `Automatic inference of CLI parameters <https://github.com/skorch-dev/skorch/tree/master/examples/cli>`_\n- `Integration with GPyTorch for Gaussian Processes <https://skorch.readthedocs.io/en/latest/user/probabilistic.html>`_\n- `Integration with Hugging Face \ud83e\udd17 <https://skorch.readthedocs.io/en/stable/user/huggingface.html>`_\n\n============\nInstallation\n============\n\nskorch requires Python 3.9 or higher.\n\nconda installation\n==================\n\nYou need a working conda installation. Get the correct miniconda for\nyour system from `here <https://conda.io/miniconda.html>`__.\n\nTo install skorch, you need to use the conda-forge channel:\n\n.. code:: bash\n\n conda install -c conda-forge skorch\n\nWe recommend to use a `conda virtual environment <https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html>`_.\n\n**Note**: The conda channel is *not* managed by the skorch\nmaintainers. More information is available `here\n<https://github.com/conda-forge/skorch-feedstock>`__.\n\npip installation\n================\n\nTo install with pip, run:\n\n.. code:: bash\n\n python -m pip install -U skorch\n\nAgain, we recommend to use a `virtual environment\n<https://docs.python.org/3/tutorial/venv.html>`_ for this.\n\nFrom source\n===========\n\nIf you would like to use the most recent additions to skorch or\nhelp development, you should install skorch from source.\n\nUsing conda\n-----------\n\nTo install skorch from source using conda, proceed as follows:\n\n.. code:: bash\n\n git clone https://github.com/skorch-dev/skorch.git\n cd skorch\n conda create -n skorch-env python=3.10\n conda activate skorch-env\n conda install -c pytorch pytorch\n python -m pip install -r requirements.txt\n python -m pip install .\n\nIf you want to help developing, run:\n\n.. code:: bash\n\n git clone https://github.com/skorch-dev/skorch.git\n cd skorch\n conda create -n skorch-env python=3.10\n conda activate skorch-env\n conda install -c pytorch pytorch\n python -m pip install -r requirements.txt\n python -m pip install -r requirements-dev.txt\n python -m pip install -e .\n\n py.test # unit tests\n pylint skorch # static code checks\n\nYou may adjust the Python version to any of the supported Python versions.\n\nUsing pip\n---------\n\nFor pip, follow these instructions instead:\n\n.. code:: bash\n\n git clone https://github.com/skorch-dev/skorch.git\n cd skorch\n # create and activate a virtual environment\n python -m pip install -r requirements.txt\n # install pytorch version for your system (see below)\n python -m pip install .\n\nIf you want to help developing, run:\n\n.. code:: bash\n\n git clone https://github.com/skorch-dev/skorch.git\n cd skorch\n # create and activate a virtual environment\n python -m pip install -r requirements.txt\n # install pytorch version for your system (see below)\n python -m pip install -r requirements-dev.txt\n python -m pip install -e .\n\n py.test # unit tests\n pylint skorch # static code checks\n\nPyTorch\n=======\n\nPyTorch is not covered by the dependencies, since the PyTorch version\nyou need is dependent on your OS and device. For installation\ninstructions for PyTorch, visit the `PyTorch website\n<http://pytorch.org/>`__. skorch officially supports the last four\nminor PyTorch versions, which currently are:\n\n- 2.2.2\n- 2.3.1\n- 2.4.1\n- 2.5.1\n\nHowever, that doesn't mean that older versions don't work, just that\nthey aren't tested. Since skorch mostly relies on the stable part of\nthe PyTorch API, older PyTorch versions should work fine.\n\nIn general, running this to install PyTorch should work:\n\n.. code:: bash\n\n # using conda:\n conda install pytorch pytorch-cuda -c pytorch\n # using pip\n python -m pip install torch\n\n==================\nExternal resources\n==================\n\n- @jakubczakon: `blog post\n <https://neptune.ai/blog/model-training-libraries-pytorch-ecosystem>`_\n \"8 Creators and Core Contributors Talk About Their Model Training\n Libraries From PyTorch Ecosystem\" 2020\n- @BenjaminBossan: `talk 1\n <https://www.youtube.com/watch?v=Qbu_DCBjVEk>`_ \"skorch: A\n scikit-learn compatible neural network library\" at PyCon/PyData 2019\n- @githubnemo: `poster <https://github.com/githubnemo/skorch-poster>`_\n for the PyTorch developer conference 2019\n- @thomasjpfan: `talk 2 <https://www.youtube.com/watch?v=0J7FaLk0bmQ>`_\n \"Skorch: A Union of Scikit learn and PyTorch\" at SciPy 2019\n- @thomasjpfan: `talk 3 <https://www.youtube.com/watch?v=yAXsxf2CQ8M>`_\n \"Skorch - A Union of Scikit-learn and PyTorch\" at PyData 2018\n- @BenjaminBossan: `talk 4 <https://youtu.be/y_n7BjDCS-M>`_ \"Extend your\n scikit-learn workflow with Hugging Face and skorch\" at PyData Amsterdam 2023\n (`slides 4 <https://github.com/BenjaminBossan/presentations/blob/main/2023-09-14-pydata/presentation.org>`_)\n\n=============\nCommunication\n=============\n\n- `GitHub discussions <https://github.com/skorch-dev/skorch/discussions>`_: \n user questions, thoughts, install issues, general discussions.\n\n- `GitHub issues <https://github.com/skorch-dev/skorch/issues>`_: bug\n reports, feature requests, RFCs, etc.\n\n- Slack: We run the #skorch channel on the `PyTorch Slack server\n <https://pytorch.slack.com/>`_, for which you can `request access\n here <https://bit.ly/ptslack>`_.\n",
"bugtrack_url": null,
"license": "new BSD 3-Clause",
"summary": "scikit-learn compatible neural network library for pytorch",
"version": "1.1.0",
"project_urls": {
"Homepage": "https://github.com/skorch-dev/skorch"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "546fa53502b4e4d94294d48fb30610c5547bd1bd87297c6a84ad8ceacaa2217c",
"md5": "c30a69c908e042788f449bbcbe31dafe",
"sha256": "2a444993bc34d31f3582d6ba7198fcd0e7b8df27bd9d0b853c6da6b85ffd5f41"
},
"downloads": -1,
"filename": "skorch-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c30a69c908e042788f449bbcbe31dafe",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 228911,
"upload_time": "2025-01-10T13:01:10",
"upload_time_iso_8601": "2025-01-10T13:01:10.997224Z",
"url": "https://files.pythonhosted.org/packages/54/6f/a53502b4e4d94294d48fb30610c5547bd1bd87297c6a84ad8ceacaa2217c/skorch-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "6dfeb59c04446b5d2af8617ac0df04f6cd3a2757d9d8c1f093af8bb4d2eaec2e",
"md5": "5e312ff82ff5ea65120d99c79ad7146a",
"sha256": "020b8c848fcc3b80cd7b17b96b35445cec3b95a4d104dd1e7055bcd6aaa1d2b6"
},
"downloads": -1,
"filename": "skorch-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "5e312ff82ff5ea65120d99c79ad7146a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 211808,
"upload_time": "2025-01-10T13:01:13",
"upload_time_iso_8601": "2025-01-10T13:01:13.231083Z",
"url": "https://files.pythonhosted.org/packages/6d/fe/b59c04446b5d2af8617ac0df04f6cd3a2757d9d8c1f093af8bb4d2eaec2e/skorch-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-10 13:01:13",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "skorch-dev",
"github_project": "skorch",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"requirements": [
{
"name": "numpy",
"specs": [
[
">=",
"1.13.3"
]
]
},
{
"name": "scikit-learn",
"specs": [
[
">=",
"0.22.0"
]
]
},
{
"name": "scipy",
"specs": [
[
">=",
"1.1.0"
]
]
},
{
"name": "tabulate",
"specs": [
[
">=",
"0.7.7"
]
]
},
{
"name": "tqdm",
"specs": [
[
">=",
"4.14.0"
]
]
}
],
"lcname": "skorch"
}