UNPKG

qminer

Version:

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

563 lines (559 loc) 23.3 kB
<!doctype html> <html> <head> <meta name="generator" content="JSDoc 3"> <meta charset="utf-8"> <title>Class: RecLinReg</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">RecLinReg</span></h1> <p class="source-link">Source: <a href="analyticsdoc.js.html#source-line-956">analyticsdoc.<wbr>js:956</a></p> <div class="symbol-classdesc"> <p>Holds the Recursive Linear Regression model.</p> </div> <dl class="dl-compact"> </dl> </header> <section id="summary"> <div class="summary-callout"> <h2 class="summary-callout-heading">Properties</h2> <div class="summary-content"> <div class="summary-column"> <dl class="dl-summary-callout"> <dt><a href="module-analytics.RecLinReg.html#dim">dim</a></dt> <dd> </dd> </dl> </div> <div class="summary-column"> <dl class="dl-summary-callout"> <dt><a href="module-analytics.RecLinReg.html#weights">weights</a></dt> <dd> </dd> </dl> </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.RecLinReg.html#fit">fit(mat, vec)</a></dt> <dd> </dd> <dt><a href="module-analytics.RecLinReg.html#getModel">getModel()</a></dt> <dd> </dd> <dt><a href="module-analytics.RecLinReg.html#getParams">getParams()</a></dt> <dd> </dd> </dl> </div> <div class="summary-column"> <dl class="dl-summary-callout"> <dt><a href="module-analytics.RecLinReg.html#partialFit">partialFit(vec, num)</a></dt> <dd> </dd> <dt><a href="module-analytics.RecLinReg.html#predict">predict(vec)</a></dt> <dd> </dd> <dt><a href="module-analytics.RecLinReg.html#save">save(fout)</a></dt> <dd> </dd> </dl> </div> <div class="summary-column"> <dl class="dl-summary-callout"> <dt><a href="module-analytics.RecLinReg.html#setParams">setParams(params)</a></dt> <dd> </dd> </dl> </div> </div> </div> </section> <section> <h2 id="RecLinReg">new&nbsp;<span class="symbol-name">RecLinReg</span><span class="signature"><span class="signature-params">(arg)</span></span></h2> <p>Recursive Linear Regression</p> <section> <h3> Example </h3> <div> <pre class="prettyprint"><code>// import analytics module var analytics &#x3D; require(&#x27;qminer&#x27;).analytics; // create the recursive linear regression model holder var linreg &#x3D; new analytics.RecLinReg({ dim: 10, regFact: 1.0, forgetFact: 1.0 });</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#~recLinRegParam">module:analytics~recLinRegParam</a> or <a href="module-fs.FIn.html">module:fs.FIn</a>)</p> </td> <td> <p>&nbsp;</p> </td> <td> <p>Construction arguments. There are two ways of constructing: <br>1. Using the <a href="module-analytics.html#~detectorParam">module:analytics~detectorParam</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>Properties</h2> <section> <h3 id="dim"><span class="symbol-name">dim</span></h3> <p>Gets the dimensionality of the model. Type <code>number</code>.</p> <section> <h4> Example </h4> <div> <pre class="prettyprint"><code>// import analytics module var analytics &#x3D; require(&#x27;qminer&#x27;).analytics; // create a new Recursive Linear Regression model var linreg &#x3D; new analytics.RecLinReg({ dim: 10 }); // get the dimensionality of the model var dim &#x3D; linreg.dim;</code></pre> </div> </section> <dl class="dl-compact"> </dl> <h3 id="weights"><span class="symbol-name">weights</span></h3> <p>Gives the weights of the model. Type <a href="module-la.Vector.html">module:la.Vector</a>.</p> <section> <h4> Example </h4> <div> <pre class="prettyprint"><code>// import analytics module var analytics &#x3D; require(&#x27;qminer&#x27;).analytics; var la &#x3D; require(&#x27;qminer&#x27;).la; // create a new Recursive Linear Regression model var linreg &#x3D; new analytics.RecLinReg({ dim: 2 }); // create a new dense matrix and target vector var mat &#x3D; new la.Matrix([[1, 2], [1, -1]]); var vec &#x3D; new la.Vector([3, 3]); // fit the model with the matrix linreg.fit(mat, vec); // get the weights of the model var weights &#x3D; linreg.weights;</code></pre> </div> </section> <dl class="dl-compact"> </dl> </section> <h2>Methods</h2> <section> <h3 id="fit"><span class="symbol-name">fit</span><span class="signature"><span class="signature-params">(mat, vec)</span>&nbsp;&rarr; <span class="signature-returns"> <a href="module-analytics.RecLinReg.html">module:analytics.RecLinReg</a></span></span></h3> <p>Creates/updates the internal model.</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 the Recursive Linear Regression model var linreg &#x3D; new analytics.RecLinReg({ dim: 2.0 }); // create a new dense matrix and target vector var mat &#x3D; new la.Matrix([[1, 2, 3], [3, 4, 5]]); var vec &#x3D; new la.Vector([3, 5, -1]); // fit the model with the matrix linreg.fit(mat, vec);</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>mat</p> </td> <td> <p><a href="module-la.Matrix.html">module:la.Matrix</a></p> </td> <td> <p>&nbsp;</p> </td> <td> <p>The input matrix.</p> </td> </tr> <tr> <td> <p>vec</p> </td> <td> <p><a href="module-la.Vector.html">module:la.Vector</a></p> </td> <td> <p>&nbsp;</p> </td> <td> <p>The target numbers, where the i-th number in vector is the target number for the i-th column of the <code>mat</code>.</p> </td> </tr> </tbody> </table> </section> <dl class="dl-compact"> <dt>Returns</dt> <dd> <p><code><a href="module-analytics.RecLinReg.html">module:analytics.RecLinReg</a></code>B Self. The internal model is updated.</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 Recursive Linear Regression model var linreg &#x3D; new analytics.RecLinReg({ dim: 10 }); // get the model var model &#x3D; linreg.getModel(); // returns { weights: new require(&#x27;qminer&#x27;).la.Vector(); }</code></pre> </div> </section> <dl class="dl-compact"> <dt>Returns</dt> <dd> <p><code>Object</code>B The <code>recLinRegModel</code> object containing the property: <br> 1. <code>recLinRegModel.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"> <a href="module-analytics.html#~recLinRegParam">module:analytics~recLinRegParam</a></span></span></h3> <p>Returns 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 Recursive Linear Regression model var linreg &#x3D; new analytics.RecLinReg({ dim: 10 }); // get the parameters of the model var params &#x3D; linreg.getParams(); // returns { dim: 10, recFact: 1.0, forgetFact: 1.0 }</code></pre> </div> </section> <dl class="dl-compact"> <dt>Returns</dt> <dd> <p><code><a href="module-analytics.html#~recLinRegParam">module:analytics~recLinRegParam</a></code>B The parameters of the model.</p> </dd> </dl> <h3 id="partialFit"><span class="symbol-name">partialFit</span><span class="signature"><span class="signature-params">(vec, num)</span>&nbsp;&rarr; <span class="signature-returns"> <a href="module-analytics.RecLinReg.html">module:analytics.RecLinReg</a></span></span></h3> <p>Updates the internal model.</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 the Recursive Linear Regression model var linreg &#x3D; new analytics.RecLinReg({ dim: 3.0 }); // create a new dense vector var vec &#x3D; new la.Vector([1, 2, 3]); // fit the model with the vector linreg.partialFit(vec, 6);</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>vec</p> </td> <td> <p><a href="module-la.Vector.html">module:la.Vector</a></p> </td> <td> <p>&nbsp;</p> </td> <td> <p>The input vector.</p> </td> </tr> <tr> <td> <p>num</p> </td> <td> <p>number</p> </td> <td> <p>&nbsp;</p> </td> <td> <p>The target number for the vector.</p> </td> </tr> </tbody> </table> </section> <dl class="dl-compact"> <dt>Returns</dt> <dd> <p><code><a href="module-analytics.RecLinReg.html">module:analytics.RecLinReg</a></code>B Self. The internal model is updated.</p> </dd> </dl> <h3 id="predict"><span class="symbol-name">predict</span><span class="signature"><span class="signature-params">(vec)</span>&nbsp;&rarr; <span class="signature-returns"> number</span></span></h3> <p>Puts the vector through the model and returns the prediction as a real number.</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 the Recursive Linear Regression model var linreg &#x3D; new analytics.RecLinReg({ dim: 2.0, recFact: 1e-10 }); // create a new dense matrix and target vector var mat &#x3D; new la.Matrix([[1, 2], [1, -1]]); var vec &#x3D; new la.Vector([3, 3]); // fit the model with the matrix linreg.fit(mat, vec); // create the vector to be predicted var pred &#x3D; new la.Vector([1, 1]); // predict the value of the vector var prediction &#x3D; linreg.predict(pred); // returns something close to 3.0</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>vec</p> </td> <td> <p><a href="module-la.Vector.html">module:la.Vector</a></p> </td> <td> <p>&nbsp;</p> </td> <td> <p>The prediction vector.</p> </td> </tr> </tbody> </table> </section> <dl class="dl-compact"> <dt>Returns</dt> <dd> <p><code>number</code>B The prediction.</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>Save model to provided 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 the Recursive Linear Regression model var linreg &#x3D; new analytics.RecLinReg({ dim: 2.0, recFact: 1e-10 }); // create a new dense matrix and target vector var mat &#x3D; new la.Matrix([[1, 2], [1, -1]]); var vec &#x3D; new la.Vector([3, 3]); // fit the model with the matrix linreg.fit(mat, vec); // create an output stream object and save the model var fout &#x3D; fs.openWrite(&#x27;linreg_example.bin&#x27;); linreg.save(fout); fout.close(); // create a new Nearest Neighbor Anomaly model by loading the model var fin &#x3D; fs.openRead(&#x27;linreg_example.bin&#x27;); var linreg2 &#x3D; new analytics.RecLinReg(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>The 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">(params)</span>&nbsp;&rarr; <span class="signature-returns"> <a href="module-analytics.RecLinReg.html">module:analytics.RecLinReg</a></span></span></h3> <p>Sets the parameters of the model.</p> <section> <h4> Example </h4> <div> <pre class="prettyprint"><code>// import analytics module var analytics &#x3D; require(&#x27;qminer&#x27;).analytics; // create a new Recursive Linear Regression model var linreg &#x3D; new analytics.RecLinReg({ dim: 10 }); // set the parameters of the model linreg.setParams({ dim: 3, recFact: 1e2, forgetFact: 0.5 });</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>params</p> </td> <td> <p><a href="module-analytics.html#~recLinRegParam">module:analytics~recLinRegParam</a></p> </td> <td> <p>&nbsp;</p> </td> <td> <p>The new parameters of the model.</p> </td> </tr> </tbody> </table> </section> <dl class="dl-compact"> <dt>Returns</dt> <dd> <p><code><a href="module-analytics.RecLinReg.html">module:analytics.RecLinReg</a></code>B Self. The parameters are updated. Any previous model is set to default.</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>