{ "info": { "author": "Sigvald Marholm", "author_email": "marholm@marebakken.com", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "localreg\n=========\n\n.. image:: https://travis-ci.com/sigvaldm/localreg.svg?branch=master\n :target: https://travis-ci.com/sigvaldm/localreg\n\n.. image:: https://coveralls.io/repos/github/sigvaldm/localreg/badge.svg?branch=master\n :target: https://coveralls.io/github/sigvaldm/localreg?branch=master\n\n.. image:: https://img.shields.io/pypi/pyversions/localreg.svg\n :target: https://pypi.org/project/localreg\n\nSmoothing of noisy data series through *local polynomial regression* (including LOESS/LOWESS).\n\nInstallation\n------------\nInstall from PyPI using ``pip`` (preferred method)::\n\n pip install localreg\n\nOr download the GitHub repository https://github.com/sigvaldm/localreg.git and run::\n\n python setup.py install\n\nIntroduction\n------------\nLocal polynomial regression is performed using the function::\n\n localreg(x, y, x0=None, degree=2, kernel=epanechnikov, width=1, frac=None)\n\nwhere ``x`` and ``y`` are the x and y-values of the data to smooth, respectively.\n``x0`` is the x-values at which to compute smoothed values. By default this is the same as ``x``, but beware that the run time is proportional to the size of ``x0``, so if you have many datapoints, it may be worthwhile to specify a smaller ``x0`` yourself.\n\nLocal polynomial regression works by fitting a polynomial of degree ``degree`` to the datapoints in vicinity of where you wish to compute a smoothed value (``x0``), and then evaluating that polynomial at ``x0``. For ``degree=0`` it reduces to a weighted moving average. A weighting function or kernel ``kernel`` is used to assign a higher weight to datapoints near ``x0``. The argument to ``kernel`` is a pure function of one argument so it is possible to define custom kernels. The following kernels are already implemented:\n\n- ``rectangular``\n- ``triangular``\n- ``epanechnikov``\n- ``biweight``\n- ``triweight``\n- ``tricube``\n- ``gaussian`` (non-compact)\n- ``cosine``\n- ``logistic`` (non-compact)\n- ``sigmoid`` (non-compact)\n- ``silverman`` (non-compact)\n\nHaving a kernel wich tapers off toward the edges, i.e., not a rectangular kernel, results in a smooth output.\n\nThe width of the kernel can be scaled by the parameter ``width``, which is actually half of the kernel-width for kernels with compact support. For kernels with non-compact support, like the Gaussian kernel, it is simply a scaling parameter, akin to the standard deviation. Having a wider kernel and including more datapoints lowers the noise (variance) but increases the bias as the regression will not be able to capture variations on a scale much narrower than the kernel window.\n\nFor unevenly spaced datapoints, having a fixed width means that a variable number of datapoints are included in the window, and hence the noise/variance is variable too. However, the bias is fixed. Using a width that varies such that a fixed number of datapoints is included leads instead to constant noise/variance but fixed bias. This can be acheived by specifying ``frac`` which overrules ``width`` and specifies the fraction of all datapoints to be included in the width of the kernel.\n\nExample Usage\n-------------\nThe below example exhibits several interesting features::\n\n import numpy as np\n import matplotlib.pyplot as plt\n from localreg import *\n\n np.random.seed(1234)\n x = np.linspace(1.5, 5, 2000)\n yf = np.sin(x*x)\n y = yf + 0.5*np.random.randn(*x.shape)\n\n y0 = localreg(x, y, degree=0, kernel=tricube, width=0.3)\n y1 = localreg(x, y, degree=1, kernel=tricube, width=0.3)\n y2 = localreg(x, y, degree=2, kernel=tricube, width=0.3)\n\n plt.plot(x, y, '+', markersize=0.6, color='gray')\n plt.plot(x, yf, label='Ground truth ($\\sin(x^2)$)')\n plt.plot(x, y0, label='Moving average')\n plt.plot(x, y1, label='Local linear regression')\n plt.plot(x, y2, label='Local quadratic regression')\n plt.legend()\n plt.show()\n\n.. image:: examples/basic.png\n\nIf there's a slope in the data near an edge, a simple moving average will fail to take into account the slope, as seen in the figure, since most of the datapoints will be to the right (or left) of ``x0``. A local linear (or higher order regression) is able to compensate for this. We also see that as the frequency of the oscillations increases, the local linear regression is not able to keep up, because the variations become too small compared to the window. A smaller window would help, at the cost of more noise in the regression. Another option is to increase the degree to 2. The quadratic regression is better at filling the valleys and the hills. For too rapid changes compared to the kernel, however, quadratic polynomials will also start failing.\n\nIt is also worth noting that a higher degree also comes with an increase in variance, which can show up as small spurious oscillations. It is therefore not very common to go higher than 2, although localreg supports arbitrary degree.\n\n.. [Hastie] T. Hastie, R. Tibshirani and J. Friedman *The Elements of Statistical Learing -- Data Mining, Inference, and Prediction*, Second Edition, Springer, 2017.\n.. [Cleveland] W. Cleveland *Robust Locally Weighted Regression and Smoothing Scatterplots*, Journal of the Americal Statistical Associations, 74, 1979.", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/sigvaldm/localreg.git", "keywords": "", "license": "LGPL", "maintainer": "", "maintainer_email": "", "name": "localreg", "package_url": "https://pypi.org/project/localreg/", "platform": "", "project_url": "https://pypi.org/project/localreg/", "project_urls": { "Homepage": "https://github.com/sigvaldm/localreg.git" }, "release_url": "https://pypi.org/project/localreg/0.2.1/", "requires_dist": null, "requires_python": "", "summary": "Local Polynomial Regression", "version": "0.2.1" }, "last_serial": 5322421, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "aa0c49d595082b4abbf3053b723081a9", "sha256": "1014b524405efbba64a370a30feec190d282ab9b9426cbb1401c449edb8c0705" }, "downloads": -1, "filename": "localreg-0.1.0.tar.gz", "has_sig": false, "md5_digest": "aa0c49d595082b4abbf3053b723081a9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2881, "upload_time": "2019-05-09T10:04:41", "url": "https://files.pythonhosted.org/packages/f1/b2/6a19c0021557a64b830ca73b962dfdbff61c28b97865c3ee6b3d928b07fd/localreg-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "ce0de9b1f145d16d49ed7bbbea51f0e2", "sha256": "0eb47360a0d6780cc91b7b693ffb86e7b4ae90c2036284cb661015cc89f76896" }, "downloads": -1, "filename": "localreg-0.2.0.tar.gz", "has_sig": false, "md5_digest": "ce0de9b1f145d16d49ed7bbbea51f0e2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6561, "upload_time": "2019-05-20T18:04:42", "url": "https://files.pythonhosted.org/packages/4b/75/0f9482e9befcde90162893ac55872cc5abcd5f9422822a390799e1763b6c/localreg-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "47d81746093195b06ba8c0527e2506c2", "sha256": "c8a2c88ded1a8b536733931af97a89c9fba1f6baa1428f60011c7f4cab6f5242" }, "downloads": -1, "filename": "localreg-0.2.1.tar.gz", "has_sig": false, "md5_digest": "47d81746093195b06ba8c0527e2506c2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6566, "upload_time": "2019-05-27T13:50:34", "url": "https://files.pythonhosted.org/packages/af/13/def3f42370e0d9782ed70e6e58eddd3f193711ac8c08b5732120dc66dcf4/localreg-0.2.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "47d81746093195b06ba8c0527e2506c2", "sha256": "c8a2c88ded1a8b536733931af97a89c9fba1f6baa1428f60011c7f4cab6f5242" }, "downloads": -1, "filename": "localreg-0.2.1.tar.gz", "has_sig": false, "md5_digest": "47d81746093195b06ba8c0527e2506c2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6566, "upload_time": "2019-05-27T13:50:34", "url": "https://files.pythonhosted.org/packages/af/13/def3f42370e0d9782ed70e6e58eddd3f193711ac8c08b5732120dc66dcf4/localreg-0.2.1.tar.gz" } ] }