UNPKG

qminer

Version:

A C++ based data analytics platform for processing large-scale real-time streams containing structured and unstructured data

555 lines (551 loc) 22.2 kB
<!doctype html> <html> <head> <meta name="generator" content="JSDoc 3"> <meta charset="utf-8"> <title>Class: RidgeReg</title> <link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css"> <link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css"> <link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css"> <link href="css/baseline.css" rel="stylesheet"> </head> <body onload="prettyPrint()"> <nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar"> <div id="jsdoc-navbar-container"> <div id="jsdoc-navbar-content"> <a href="index.html" class="jsdoc-navbar-package-name">QMiner JavaScript API v9.4.0</a> </div> </div> </nav> <div id="jsdoc-body-container"> <div id="jsdoc-content"> <div id="jsdoc-content-container"> <div id="jsdoc-main" role="main"> <header class="page-header"> <div class="symbol-detail-labels"><span class="label label-kind">class</span>&nbsp;<span class="label label-static">static</span></div> <h1><small><a href="module-analytics.html">analytics</a>.<wbr></small><span class="symbol-name">RidgeReg</span></h1> <p class="source-link">Source: <a href="analyticsdoc.js.html#source-line-431">analyticsdoc.<wbr>js:431</a></p> <div class="symbol-classdesc"> <p>Ridge regression minimizes the value <code>||A' x - b||^2 + ||gamma x||^2</code>. Uses <a href="http://en.wikipedia.org/wiki/Tikhonov_regularization">Tikhonov regularization</a>.</p> </div> <dl class="dl-compact"> </dl> </header> <section id="summary"> <div class="summary-callout"> <h2 class="summary-callout-heading">Property</h2> <div class="summary-content"> <div class="summary-column"> <dl class="dl-summary-callout"> <dt><a href="module-analytics.RidgeReg.html#weights">weights</a></dt> <dd> </dd> </dl> </div> <div class="summary-column"> </div> <div class="summary-column"> </div> </div> </div> <div class="summary-callout"> <h2 class="summary-callout-heading">Methods</h2> <div class="summary-content"> <div class="summary-column"> <dl class="dl-summary-callout"> <dt><a href="module-analytics.RidgeReg.html#decisionFunction">decisionFunction(x)</a></dt> <dd> </dd> <dt><a href="module-analytics.RidgeReg.html#fit">fit(X, y)</a></dt> <dd> </dd> <dt><a href="module-analytics.RidgeReg.html#getModel">getModel()</a></dt> <dd> </dd> </dl> </div> <div class="summary-column"> <dl class="dl-summary-callout"> <dt><a href="module-analytics.RidgeReg.html#getParams">getParams()</a></dt> <dd> </dd> <dt><a href="module-analytics.RidgeReg.html#predict">predict(x)</a></dt> <dd> </dd> <dt><a href="module-analytics.RidgeReg.html#save">save(fout)</a></dt> <dd> </dd> </dl> </div> <div class="summary-column"> <dl class="dl-summary-callout"> <dt><a href="module-analytics.RidgeReg.html#setParams">setParams(gamma)</a></dt> <dd> </dd> </dl> </div> </div> </div> </section> <section> <h2 id="RidgeReg">new&nbsp;<span class="symbol-name">RidgeReg</span><span class="signature"><span class="signature-params">([arg])</span></span></h2> <p>Ridge Regression</p> <section> <h3> Example </h3> <div> <pre class="prettyprint"><code>// import modules analytics &#x3D; require(&#x27;qminer&#x27;).analytics; la &#x3D; require(&#x27;qminer&#x27;).la; // create a new model with gamma equal to 1.0 var regmod &#x3D; new analytics.RidgeReg({ gamma: 1.0 }); // generate a random feature matrix var A &#x3D; la.randn(10, 100); // generate a random model var w &#x3D; la.randn(10); // generate noise var n &#x3D; la.randn(100).multiply(0.01); // generate responses (model&#x27;*data + noise) var b &#x3D; A.transpose().multiply(w).plus(n); // fit model regmod.fit(A, b); // compare the true with the trained model // true model w.print(); // trained model; regmod.weights.print(); // cosine between the true and the estimated model should be close to 1 if the fit succeeded var cos &#x3D; regmod.weights.cosine(w);</code></pre> </div> </section> <section> <h3>Parameter</h3> <table class="jsdoc-details-table"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Optional</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td> <p>arg</p> </td> <td> <p>(<a href="module-analytics.html#~ridgeRegParam">module:analytics~ridgeRegParam</a> or <a href="module-fs.FIn.html">module:fs.FIn</a>)</p> </td> <td> <p>Yes</p> </td> <td> <p>Construction arguments. There are two ways of constructing: <br>1. Using the <a href="module-analytics.html#~ridgeRegParam">module:analytics~ridgeRegParam</a> object, <br>2. using the file input stream <a href="module-fs.FIn.html">module:fs.FIn</a>. </p> </td> </tr> </tbody> </table> </section> <dl class="dl-compact"> </dl> </section> <section> <h2>Property</h2> <section> <h3 id="weights"><span class="symbol-name">weights</span></h3> <p>Vector of coefficients for linear regression. Type <a href="module-la.Vector.html">module:la.Vector</a>.</p> <section> <h4> Example </h4> <div> <pre class="prettyprint"><code>// import modules var analytics &#x3D; require(&#x27;qminer&#x27;).analytics; var la &#x3D; require(&#x27;qminer&#x27;).la; // create a new Ridge Regression object var regmod &#x3D; new analytics.RidgeReg(); // create the test matrix and vector var X &#x3D; new la.Matrix([[1, 2], [1, -1]]); var y &#x3D; new la.Vector([3, 3]); // fit the model with X and y regmod.fit(X, y); // get the weights var weights &#x3D; regmod.weights;</code></pre> </div> </section> <dl class="dl-compact"> </dl> </section> <h2>Methods</h2> <section> <h3 id="decisionFunction"><span class="symbol-name">decisionFunction</span><span class="signature"><span class="signature-params">(x)</span>&nbsp;&rarr; <span class="signature-returns"> number</span></span></h3> <p>Returns the expected response for the provided feature vector.</p> <section> <h4> Example </h4> <div> <pre class="prettyprint"><code>// import modules var analytics &#x3D; require(&#x27;qminer&#x27;).analytics; var la &#x3D; require(&#x27;qminer&#x27;).la; // create a new Ridge Regression object var regmod &#x3D; new analytics.RidgeReg(); // create the test matrix and vector var X &#x3D; new la.Matrix([[1, 2], [1, -1]]); var y &#x3D; new la.Vector([3, 3]); // fit the model with X and y regmod.fit(X, y); // create a new vector for the prediction var vec &#x3D; new la.Vector([3, 4]); // create the prediction // returns the value 10 var prediction &#x3D; regmod.decisionFunction(vec);</code></pre> </div> </section> <section> <h4>Parameter</h4> <table class="jsdoc-details-table"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Optional</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td> <p>x</p> </td> <td> <p><a href="module-la.Vector.html">module:la.Vector</a></p> </td> <td> <p>&nbsp;</p> </td> <td> <p>Feature vector.</p> </td> </tr> </tbody> </table> </section> <dl class="dl-compact"> <dt>Returns</dt> <dd> <p><code>number</code>B Predicted response.</p> </dd> </dl> <h3 id="fit"><span class="symbol-name">fit</span><span class="signature"><span class="signature-params">(X, y)</span>&nbsp;&rarr; <span class="signature-returns"> <a href="module-analytics.RidgeReg.html">module:analytics.RidgeReg</a></span></span></h3> <p>Fits a column matrix of feature vectors <code>X</code> onto the response variable <code>y</code>.</p> <section> <h4> Example </h4> <div> <pre class="prettyprint"><code>// import modules var analytics &#x3D; require(&#x27;qminer&#x27;).analytics; var la &#x3D; require(&#x27;qminer&#x27;).la; // create a new Ridge Regression object var regmod &#x3D; new analytics.RidgeReg(); // create the test matrix and vector var X &#x3D; new la.Matrix([[1, 2], [1, -1]]); var y &#x3D; new la.Vector([3, 3]); // fit the model with X and y // the weights of the model are 2, 1 regmod.fit(X, y);</code></pre> </div> </section> <section> <h4>Parameters</h4> <table class="jsdoc-details-table"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Optional</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td> <p>X</p> </td> <td> <p><a href="module-la.Matrix.html">module:la.Matrix</a></p> </td> <td> <p>&nbsp;</p> </td> <td> <p>Column matrix which stores the feature vectors.</p> </td> </tr> <tr> <td> <p>y</p> </td> <td> <p><a href="module-la.Vector.html">module:la.Vector</a></p> </td> <td> <p>&nbsp;</p> </td> <td> <p>Response variable.</p> </td> </tr> </tbody> </table> </section> <dl class="dl-compact"> <dt>Returns</dt> <dd> <p><code><a href="module-analytics.RidgeReg.html">module:analytics.RidgeReg</a></code>B Self. The model is fitted by <code>X</code> and <code>y</code>.</p> </dd> </dl> <h3 id="getModel"><span class="symbol-name">getModel</span><span class="signature"><span class="signature-params">()</span>&nbsp;&rarr; <span class="signature-returns"> Object</span></span></h3> <p>Gets the model.</p> <section> <h4> Example </h4> <div> <pre class="prettyprint"><code>// import analytics module var analytics &#x3D; require(&#x27;qminer&#x27;).analytics; // create the Ridge Regression model var regmod &#x3D; new analytics.RidgeReg(); // get the model var model &#x3D; regmod.getModel();</code></pre> </div> </section> <dl class="dl-compact"> <dt>Returns</dt> <dd> <p><code>Object</code>B The <code>ridgeRegModel</code> object containing the property: <br> 1. <code>ridgeRegModel.weights</code> - The weights of the model. Type <a href="module-la.Vector.html">module:la.Vector</a>. </p> </dd> </dl> <h3 id="getParams"><span class="symbol-name">getParams</span><span class="signature"><span class="signature-params">()</span>&nbsp;&rarr; <span class="signature-returns"> model:analytics~RidgeRegParam</span></span></h3> <p>Gets the parameters.</p> <section> <h4> Example </h4> <div> <pre class="prettyprint"><code>// import analytics module var analytics &#x3D; require(&#x27;qminer&#x27;).analytics; // create a new Ridge Regression object var regmod &#x3D; new analytics.RidgeReg({ gamma: 5 }); // get the parameters // returns a json object { gamma: 5 } var param &#x3D; regmod.getParams();</code></pre> </div> </section> <dl class="dl-compact"> <dt>Returns</dt> <dd> <p><code>model:analytics~RidgeRegParam</code>B The object containing the parameters.</p> </dd> </dl> <h3 id="predict"><span class="symbol-name">predict</span><span class="signature"><span class="signature-params">(x)</span>&nbsp;&rarr; <span class="signature-returns"> number</span></span></h3> <p>Returns the expected response for the provided feature vector.</p> <section> <h4> Example </h4> <div> <pre class="prettyprint"><code>// import modules var analytics &#x3D; require(&#x27;qminer&#x27;).analytics; var la &#x3D; require(&#x27;qminer&#x27;).la; // create a new Ridge Regression object var regmod &#x3D; new analytics.RidgeReg(); // create the test matrix and vector var X &#x3D; new la.Matrix([[1, 2], [1, -1]]); var y &#x3D; new la.Vector([3, 3]); // fit the model with X and y regmod.fit(X, y); // create a new vector for the prediction var vec &#x3D; new la.Vector([3, 4]); // create the prediction // returns the value 10 var prediction &#x3D; regmod.predict(vec);</code></pre> </div> </section> <section> <h4>Parameter</h4> <table class="jsdoc-details-table"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Optional</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td> <p>x</p> </td> <td> <p><a href="module-la.Vector.html">module:la.Vector</a></p> </td> <td> <p>&nbsp;</p> </td> <td> <p>Feature vector.</p> </td> </tr> </tbody> </table> </section> <dl class="dl-compact"> <dt>Returns</dt> <dd> <p><code>number</code>B Predicted response.</p> </dd> </dl> <h3 id="save"><span class="symbol-name">save</span><span class="signature"><span class="signature-params">(fout)</span>&nbsp;&rarr; <span class="signature-returns"> <a href="module-fs.FOut.html">module:fs.FOut</a></span></span></h3> <p>Saves the model into the output stream.</p> <section> <h4> Example </h4> <div> <pre class="prettyprint"><code>// import modules var analytics &#x3D; require(&#x27;qminer&#x27;).analytics; var la &#x3D; require(&#x27;qminer&#x27;).la; var fs &#x3D; require(&#x27;qminer&#x27;).fs; // create a new Ridge Regression object var regmod &#x3D; new analytics.RidgeReg(); // create the test matrix and vector var X &#x3D; new la.Matrix([[1, 2], [1, -1]]); var y &#x3D; new la.Vector([3, 3]); // fit the model with X and y regmod.fit(X, y); // create an output stream object and save the model var fout &#x3D; fs.openWrite(&#x27;regmod_example.bin&#x27;); regmod.save(fout); fout.close(); // create a new Ridge Regression model by loading the model var fin &#x3D; fs.openRead(&#x27;regmod_example.bin&#x27;); var regmod2 &#x3D; new analytics.RidgeReg(fin);</code></pre> </div> </section> <section> <h4>Parameter</h4> <table class="jsdoc-details-table"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Optional</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td> <p>fout</p> </td> <td> <p><a href="module-fs.FOut.html">module:fs.FOut</a></p> </td> <td> <p>&nbsp;</p> </td> <td> <p>Output stream.</p> </td> </tr> </tbody> </table> </section> <dl class="dl-compact"> <dt>Returns</dt> <dd> <p><code><a href="module-fs.FOut.html">module:fs.FOut</a></code>B The output stream <code>fout</code>.</p> </dd> </dl> <h3 id="setParams"><span class="symbol-name">setParams</span><span class="signature"><span class="signature-params">(gamma)</span>&nbsp;&rarr; <span class="signature-returns"> <a href="module-analytics.RidgeReg.html">module:analytics.RidgeReg</a></span></span></h3> <p>Set the parameters.</p> <section> <h4> Example </h4> <div> <pre class="prettyprint"><code>// import analytics module var analytics &#x3D; require(&#x27;qminer&#x27;).analytics; // create a new Ridge Regression object var regmod &#x3D; new analytics.RidgeReg({ gamma: 5 }); // set the parameters of the object var param &#x3D; regmod.setParams({ gamma: 10 });</code></pre> </div> </section> <section> <h4>Parameter</h4> <table class="jsdoc-details-table"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Optional</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td> <p>gamma</p> </td> <td> <p>(number or model:analytics~RidgeRegParam)</p> </td> <td> <p>&nbsp;</p> </td> <td> <p>The new parameter for the model, given as a number or as an object.</p> </td> </tr> </tbody> </table> </section> <dl class="dl-compact"> <dt>Returns</dt> <dd> <p><code><a href="module-analytics.RidgeReg.html">module:analytics.RidgeReg</a></code>B Self. The parameter is set to <code>gamma</code>.</p> </dd> </dl> </section> </section> </div> </div> <nav id="jsdoc-toc-nav" role="navigation"></nav> </div> </div> <footer id="jsdoc-footer" class="jsdoc-footer"> <div id="jsdoc-footer-container"> <p> </p> </div> </footer> <script src="scripts/jquery.min.js"></script> <script src="scripts/tree.jquery.js"></script> <script src="scripts/prettify.js"></script> <script src="scripts/jsdoc-toc.js"></script> <script src="scripts/linenumber.js"></script> <script src="scripts/scrollanchor.js"></script> </body> </html>