Skip to main content

Easy to use package of the DNNR regression.

Project description

DNNR: Differential Nearest Neighbors Regression

Build Status

[Paper] [Documentation]

The Python package of differential nearest neighbors regression (DNNR): Raising KNN-regression to levels of gradient boosting methods.

Whereas KNN regression only uses the averaged value, DNNR also uses the gradient or even higher-order derivatives:

KNN and DNNR Overview Image

Our implementation uses numpy, sklearn, and the annoy approximate nearest neighbor index. Using annoy is optional, as you can also use sklearn's KDTree as index. We support Python 3.7 to 3.10.

🚀 Quickstart

To install this project, run:

pip install dnnr

🎉 Example

import numpy as np
from dnnr import DNNR

X = np.array([[0], [1], [2], [3]])
y = np.array([0, 0, 1, 1])

model = DNNR(n_neighbors=1, n_derivative_neighbors=3)
model.fit(X, y)
model.predict([[1.5]])
# Will output: 0.25

Also check out our Jupiter Notebook on how to use DNNR. Open In Colab

📊 Hyperparameters

DNNR has three main hyperparameters:

  • n_neighbors: number of nearest neighbors to use. The default value of 3 is usually a good choice.
  • n_derivative_neighbors: number of neighbors used in approximating the derivatives. As a default value, we choose 3 * dim, where dim is the input dimension.
  • order: Taylor approximation order, one of 1, 2, 2diag, 3diag. The preferable option here is 1. Sometimes 2diag can deliver small improvements. 2 and 3diag are implemented but usually do not yield significant improvements.

We recommend a hyperparameter search over the n_derivative_neighbors variable to archive the best performance.

For all options, see the documentation of the DNNR class.

🛠 Development Installation

python3 -m venv venv      # create a virtual environment
source venv/bin/activate  # and load it
git clone https://github.com/younader/dnnr.git
cd dnnr
pip install -U pip wheel poetry
poetry install
make test                 # to run the tests

📄 Citation

If you use this library for a scientific publication, please use the following BibTex entry to cite our work:

@InProceedings{pmlr-v162-nader22a,
  title = 	 {{DNNR}: Differential Nearest Neighbors Regression},
  author =       {Nader, Youssef and Sixt, Leon and Landgraf, Tim},
  booktitle = 	 {Proceedings of the 39th International Conference on Machine Learning},
  pages = 	 {16296--16317},
  year = 	 {2022},
  editor = 	 {Chaudhuri, Kamalika and Jegelka, Stefanie and Song, Le and Szepesvari, Csaba and Niu, Gang and Sabato, Sivan},
  volume = 	 {162},
  series = 	 {Proceedings of Machine Learning Research},
  month = 	 {17--23 Jul},
  publisher =    {PMLR},
  pdf = 	 {https://proceedings.mlr.press/v162/nader22a/nader22a.pdf},
  url = 	 {https://proceedings.mlr.press/v162/nader22a.html},
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dnnr-0.1.2.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dnnr-0.1.2-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file dnnr-0.1.2.tar.gz.

File metadata

  • Download URL: dnnr-0.1.2.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for dnnr-0.1.2.tar.gz
Algorithm Hash digest
SHA256 aad60dccbdcb9287fd1644aceb118cb517d1fa1d37adeade97271af62afe6bac
MD5 a0de3d453b89ba8ae30c3d6fd9fe1977
BLAKE2b-256 95a20291d74f60908d43fa2312dafc1cf1f2ea269015b7b86a3ced2650b40f8c

See more details on using hashes here.

File details

Details for the file dnnr-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: dnnr-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for dnnr-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dbaee1ce75b99f047aa188ad94e8e90c3c1e1e9fdfae19e09969652d0e9c76fb
MD5 ed12bd2f08b3c7fb29e6fc0083587b1b
BLAKE2b-256 c36876f23eb4f6cf23be0a59baff77547936b4ee53ec028f56882c0e43532885

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page