Skip to main content

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},
}

Metadata

Release files for dnnr 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dnnr 0.1.2
File Size Uploaded
dnnr-0.1.2.tar.gz 18.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dnnr 0.1.2
File Interpreter ABI Platform
dnnr-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 32.4 kB

Release files / dnnr-0.1.2.tar.gz

Download URL dnnr-0.1.2.tar.gz
Size 18.4 kB
Tags Source
SHA-256 checksum
How to use checksums
aad60dccbdcb9287fd1644aceb118cb517d1fa1d37adeade97271af62afe6bac
BLAKE2b-256 checksum
How to use checksums
95a20291d74f60908d43fa2312dafc1cf1f2ea269015b7b86a3ced2650b40f8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / dnnr-0.1.2-py3-none-any.whl

Download URL dnnr-0.1.2-py3-none-any.whl
Size 13.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dbaee1ce75b99f047aa188ad94e8e90c3c1e1e9fdfae19e09969652d0e9c76fb
BLAKE2b-256 checksum
How to use checksums
c36876f23eb4f6cf23be0a59baff77547936b4ee53ec028f56882c0e43532885
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page