
Security News
pnpm 10.12 Introduces Global Virtual Store and Expanded Version Catalogs
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.
JavaScript implementation of the Locally-Weighted Regression package originally written in C by Cleveland, Grosse and Shyu (1992)
JavaScript implementation of the Locally-Weighted Regression package originally written in C by Cleveland, Grosse and Shyu (1992)
First install the package:
npm install loess --save
Load in your data:
var data = require('./myData.json')
Instantiate a LOESS model with the data:
var Loess = require('loess')
var options = {span: 0.5, band: 0.8, degree: 1}
var model = new Loess(data, option)
Fit model by calling the .predict( ) method on the model object:
var fit = model.predict()
console.log(fit.fitted)
// do something else with fit.fitted
To fit model on a new set of points, pass a data object into .predict( )
var newData = {
x: [1, 2, 3, 4, 5],
x2: [6, 7, 8, 9, 10]
}
fit = model.predict(newData)
var upperLimit = fit.fitted.map((yhat, idx) => yhat + fit.halfwidth[idx])
var lowerLimit = fit.fitted.map((yhat, idx) => yhat - fit.halfwidth[idx])
// plot upperLimit and lowerLimit
Alternatively, use .grid( ) method to generate a grid of equally spaced points:
newData = model.grid([20, 20])
fit = model.predict(newData)
class Loess {
constructor (data: object, options: object) {
// arguments
data /*required*/ = {
y: [number],
x: [number],
x2: [number], // optional
w: [number] // optional
}
options /*optional*/ = {
span: number, // 0 to inf, default 0.75
band: number, // 0 to 1, default 0
degree: [0, 1, 2] || ['constant', 'linear', 'quadratic'] // default 2
normalize: boolean, // default true if degree > 1, false otherwise
robust: boolean, // default false
iterations: integer //default 4 if robust = true, 1 otherwise
}
// return a LOESS model object with the following properties
this.y = data.y
this.x = [data.x, data.x2] // predictor matrix
this.n = this.y.length // number of data points
this.d = this.x.length // dimension of predictors
this.bandwidth = options.span * this.n // number of data points used in local regression
this.options = options
}
predict (data: object) {
// arguments
data /*optional*/ = {
x: [number],
x2: [number]
} // default this.x
return {
fitted: [number], // fitted values for the specified data points
halfwidth: [number] // fitted +- halfwidth is the uncertainty band
}
}
grid (cuts: [integer]) {
return {
x_cut: [number], // equally-spaced data points
x_cut2: [number],
x: [number], // all combination of x_cut and x_cut2, forming a grid
x2: [number]
}
}
}
William S. Cleveland, Susan J. Devlin
Locally Weighted Regression: An Approach to Regression Analysis by Local Fitting
Journal of the American Statistical Association, Vol. 83, No. 403. (Sep., 1988), pp. 596-610.
William S. Cleveland, Eric Grosse, Ming-Jen Shyu
A Package of C and Fortran Routines for Fitting Local Regression Models (20 August 1992)
Source code available at http://www.netlib.org/a/dloess
FAQs
JavaScript implementation of the Locally-Weighted Regression package originally written in C by Cleveland, Grosse and Shyu (1992)
The npm package loess receives a total of 513 weekly downloads. As such, loess popularity was classified as not popular.
We found that loess demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.
Security News
Amaro 1.0 lays the groundwork for stable TypeScript support in Node.js, bringing official .ts loading closer to reality.
Research
A deceptive PyPI package posing as an Instagram growth tool collects user credentials and sends them to third-party bot services.