handy-nn


Namehandy-nn JSON
Version 0.0.3 PyPI version JSON
download
home_pageNone
SummaryDelightful and useful neural networks models, including OrdinalRegressionLoss, etc.
upload_time2024-12-09 03:56:04
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseCopyright (c) 2013 kaelzhang <>, contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords neural-networks pytorch machine-learning ordinal-regression models
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![](https://github.com/kaelzhang/handy-nn/actions/workflows/python.yml/badge.svg)](https://github.com/kaelzhang/handy-nn/actions/workflows/python.yml)
[![](https://codecov.io/gh/kaelzhang/handy-nn/branch/main/graph/badge.svg)](https://codecov.io/gh/kaelzhang/handy-nn)
[![](https://img.shields.io/pypi/v/handy-nn.svg)](https://pypi.org/project/handy-nn/)
[![](https://img.shields.io/pypi/l/handy-nn.svg)](https://github.com/kaelzhang/handy-nn)

# handy-nn

Delightful and useful neural networks models, including OrdinalRegressionLoss, etc.

## Install

```sh
$ pip install handy-nn
```

## Usage

```py
from handy_nn import OrdinalRegressionLoss

# Initialize the loss function
num_classes = 5
criterion = OrdinalRegressionLoss(num_classes)

# For training
logits = model(inputs)  # Shape: (batch_size, 1)
loss = criterion(logits, targets)
loss.backward()  # shape: torch.Size([])

# To get class probabilities
probas = criterion.predict_probas(logits)  # Shape: (batch_size, num_classes)
```

# APIs

## OrdinalRegressionLoss(num_classes, learn_thresholds, init_scale)

- **num_classes** `int`: Number of ordinal classes (ranks)
- **learn_thresholds** `bool=True`: Whether to learn threshold parameters or use fixed ones, defaults to `True`.
- **init_scale** `float=2.0`: Scale for initializing thresholds, defaults to `2.0`

Creates the loss function for ordinal regression.

The goal of [ordinal regression](https://en.wikipedia.org/wiki/Ordinal_regression) is to model the relationship between one or more independent variables and an ordinal dependent variable. It predicts the probability that an observation falls into a specific ordinal category or a category higher than a certain threshold. This is particularly useful in fields like social sciences, medicine, and customer surveys where outcomes are often ordinal.

## License

[MIT](LICENSE)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "handy-nn",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "neural-networks, pytorch, machine-learning, ordinal-regression, models",
    "author": null,
    "author_email": "Kael Zhang <i+pypi@kael.me>",
    "download_url": "https://files.pythonhosted.org/packages/25/53/7767d21fd0d6e6b6c76ceb94d740a258c9bd2034a678f8b27a058c4a51b5/handy_nn-0.0.3.tar.gz",
    "platform": null,
    "description": "[![](https://github.com/kaelzhang/handy-nn/actions/workflows/python.yml/badge.svg)](https://github.com/kaelzhang/handy-nn/actions/workflows/python.yml)\n[![](https://codecov.io/gh/kaelzhang/handy-nn/branch/main/graph/badge.svg)](https://codecov.io/gh/kaelzhang/handy-nn)\n[![](https://img.shields.io/pypi/v/handy-nn.svg)](https://pypi.org/project/handy-nn/)\n[![](https://img.shields.io/pypi/l/handy-nn.svg)](https://github.com/kaelzhang/handy-nn)\n\n# handy-nn\n\nDelightful and useful neural networks models, including OrdinalRegressionLoss, etc.\n\n## Install\n\n```sh\n$ pip install handy-nn\n```\n\n## Usage\n\n```py\nfrom handy_nn import OrdinalRegressionLoss\n\n# Initialize the loss function\nnum_classes = 5\ncriterion = OrdinalRegressionLoss(num_classes)\n\n# For training\nlogits = model(inputs)  # Shape: (batch_size, 1)\nloss = criterion(logits, targets)\nloss.backward()  # shape: torch.Size([])\n\n# To get class probabilities\nprobas = criterion.predict_probas(logits)  # Shape: (batch_size, num_classes)\n```\n\n# APIs\n\n## OrdinalRegressionLoss(num_classes, learn_thresholds, init_scale)\n\n- **num_classes** `int`: Number of ordinal classes (ranks)\n- **learn_thresholds** `bool=True`: Whether to learn threshold parameters or use fixed ones, defaults to `True`.\n- **init_scale** `float=2.0`: Scale for initializing thresholds, defaults to `2.0`\n\nCreates the loss function for ordinal regression.\n\nThe goal of [ordinal regression](https://en.wikipedia.org/wiki/Ordinal_regression) is to model the relationship between one or more independent variables and an ordinal dependent variable. It predicts the probability that an observation falls into a specific ordinal category or a category higher than a certain threshold. This is particularly useful in fields like social sciences, medicine, and customer surveys where outcomes are often ordinal.\n\n## License\n\n[MIT](LICENSE)\n",
    "bugtrack_url": null,
    "license": "Copyright (c) 2013 kaelzhang <>, contributors  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Delightful and useful neural networks models, including OrdinalRegressionLoss, etc.",
    "version": "0.0.3",
    "project_urls": {
        "Homepage": "https://github.com/kaelzhang/handy-nn"
    },
    "split_keywords": [
        "neural-networks",
        " pytorch",
        " machine-learning",
        " ordinal-regression",
        " models"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4a4ab9a41136203446b08f8dde6de8d8d5cd029d3d532eab9b019caf10a11d9b",
                "md5": "4a0b7d63256bde92d8e9dc366c9bdbf3",
                "sha256": "1be83f5e33dab5c9c7f913a11d419a3a8e2628d2ba8fbfe39c97a2f367b8a287"
            },
            "downloads": -1,
            "filename": "handy_nn-0.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4a0b7d63256bde92d8e9dc366c9bdbf3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 5221,
            "upload_time": "2024-12-09T03:56:03",
            "upload_time_iso_8601": "2024-12-09T03:56:03.594351Z",
            "url": "https://files.pythonhosted.org/packages/4a/4a/b9a41136203446b08f8dde6de8d8d5cd029d3d532eab9b019caf10a11d9b/handy_nn-0.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "25537767d21fd0d6e6b6c76ceb94d740a258c9bd2034a678f8b27a058c4a51b5",
                "md5": "13903186c0ca9e5fdb1009ef57bcea88",
                "sha256": "b3a8b55dccd5c184f7900a904fad8630ddc17536ea630a4f3a345b3cb372f551"
            },
            "downloads": -1,
            "filename": "handy_nn-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "13903186c0ca9e5fdb1009ef57bcea88",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 4711,
            "upload_time": "2024-12-09T03:56:04",
            "upload_time_iso_8601": "2024-12-09T03:56:04.732475Z",
            "url": "https://files.pythonhosted.org/packages/25/53/7767d21fd0d6e6b6c76ceb94d740a258c9bd2034a678f8b27a058c4a51b5/handy_nn-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-09 03:56:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kaelzhang",
    "github_project": "handy-nn",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "handy-nn"
}
        
Elapsed time: 0.98910s