
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
wink-regression-tree
Advanced tools
Decision Tree to predict the value of a continuous target variable
Decision Tree to predict the value of a continuous target variable
Predict the value of a continuous variable such as price, turn around time, or mileage using wink-regression-tree
. It is a part of wink — a growing family of high quality packages for Statistical Analysis, Natural Language Processing and Machine Learning in NodeJS.
Use npm to install:
npm install wink-regression-tree --save
Here is an example of predicting car’s mileage (miles per gallon - mpg) from attributes like displacement, horsepower, acceleration, country of origin, and few more. The data set used in this example has been quantized for a quick start.
// Load wink-regression-tree.
var regressionTree = require( 'wink-regression-tree' );
// Load cars training data set.
// In practice an async mechanism may be used to
// read data asynchronously and call `ingest()` on
// every row of data read.
var cars = require( 'wink-regression-tree/sample-data/cars.json' );
// Create a sample data to test prediction for
// Ford Gran Torino, having "mpg of 14.5", very
// large displacement, extremely high power, very
// high weight, slow, and with origin as US.
var input = {
model: 'Ford Gran Torino',
weight: 'very high weight',
displacement: 'very large displacement',
horsepower: 'extremely high power',
origin: 'US',
acceleration: 'slow'
};
// Above record is not the part of training data.
// Create an instance of the regression tree.
var rt = regressionTree();
// Specify columns of the training data.
var columns = [
{ name: 'model', categorical: true, exclude: true },
{ name: 'mpg', categorical: false, target: true },
{ name: 'cylinders', categorical: true, exclude: false },
{ name: 'displacement', categorical: true, exclude: false },
{ name: 'horsepower', categorical: true, exclude: false },
{ name: 'weight', categorical: true, exclude: false },
{ name: 'acceleration', categorical: true, exclude: false },
{ name: 'year', categorical: true, exclude: true },
{ name: 'origin', categorical: true, exclude: false }
];
// Specify configuration for learning.
var treeParams = {
minPercentVarianceReduction: 0.5,
minLeafNodeItems: 10,
minSplitCandidateItems: 30,
minAvgChildrenItems: 2
};
// Define the regression tree configuration using
// `columns` and `treeParams`.
rt.defineConfig( columns, treeParams );
// Ingest the data.
cars.forEach( function ( row ) {
rt.ingest( row );
} );
// Data ingested! Now time to learn from data!!
console.log( rt.learn() );
// -> 16 (Number of Rules Learned)
// Predict the **mean** value.
var mean = rt.predict( input );
console.log( +mean.toFixed( 1 ) );
// -> 14.3 ( compare with actual mpg of 14.5 )
// In practice one may like to compute a range
// or upper limit using the `modifier` function
// during prediction. Note `size`, `mean`, and `stdev`
// values, passed to this function, can be used
// for computing the range or the upper limit.
Try experimenting with this example on Runkit in the browser.
For detailed API docs, check out https://winkjs.github.io/wink-regression-tree/ URL!
If you spot a bug and the same has not yet been reported, raise a new issue or consider fixing it and sending a pull request.
wink-regression-tree is copyright 2017 GRAYPE Systems Private Limited.
It is licensed under the under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License.
FAQs
Decision Tree to predict the value of a continuous target variable
The npm package wink-regression-tree receives a total of 34 weekly downloads. As such, wink-regression-tree popularity was classified as not popular.
We found that wink-regression-tree demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.