qminer
Version:
A C++ based data analytics platform for processing large-scale real-time streams containing structured and unstructured data
406 lines (402 loc) • 18.8 kB
HTML
<html>
<head>
<meta name="generator" content="JSDoc 3">
<meta charset="utf-8">
<title>Class: OneVsAll</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> <span class="label label-static">static</span></div>
<h1><small><a href="module-analytics.html">analytics</a>.<wbr></small><span class="symbol-name">OneVsAll</span></h1>
<p class="source-link">Source: <a href="analyticsdoc.js.html#source-line-3082">analyticsdoc.<wbr>js:3082</a></p>
<div class="symbol-classdesc">
<p>One vs All model for multiclass prediction. Builds binary model
for each category and predicts the one with the highest score. Binary model is
provided as part of the constructor.</p>
</div>
<dl class="dl-compact">
</dl>
</header>
<section id="summary">
<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.OneVsAll.html#decisionFunction">decisionFunction(X)</a></dt>
<dd>
</dd>
<dt><a href="module-analytics.OneVsAll.html#fit">fit(X, y)</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-analytics.OneVsAll.html#getParams">getParams()</a></dt>
<dd>
</dd>
<dt><a href="module-analytics.OneVsAll.html#predict">predict(X)</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-analytics.OneVsAll.html#setParams">setParams(params)</a></dt>
<dd>
</dd>
</dl>
</div>
</div>
</div>
</section>
<section>
<h2 id="OneVsAll">new <span class="symbol-name">OneVsAll</span><span class="signature"><span class="signature-params">([arg])</span></span></h2>
<section>
<h3>
Example
</h3>
<div>
<pre class="prettyprint"><code>// import analytics module
var analytics = require('qminer').analytics;
// create a new OneVsAll object with the model analytics.SVC
var onevsall = new analytics.OneVsAll({ model: analytics.SVC, modelParam: { c: 10, maxTime: 1000 }, cats: 2 });</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#~oneVsAllParam">module:analytics~oneVsAllParam</a></p>
</td>
<td>
<p>Yes</p>
</td>
<td>
<p>Construction arguments.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
</dl>
</section>
<section>
<h2>Methods</h2>
<section>
<h3 id="decisionFunction"><span class="symbol-name">decisionFunction</span><span class="signature"><span class="signature-params">(X)</span> → <span class="signature-returns"> (<a href="module-la.Vector.html">module:la.Vector</a> or <a href="module-la.Matrix.html">module:la.Matrix</a>)</span></span></h3>
<p>Apply all models to the given vector and returns a vector of scores, one for each category.
Semantic of scores depend on the provided binary model.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create a new OneVsAll object with the model analytics.SVC
var onevsall = new analytics.OneVsAll({ model: analytics.SVC, modelParam: { c: 10, maxTime: 1000 }, cats: 2 });
// create the data (matrix and vector) used to fit the model
var matrix = new la.Matrix([[1, 2, 1, 1], [2, 1, -3, -4]]);
var vector = new la.Vector([0, 0, 1, 1]);
// fit the model
onevsall.fit(matrix, vector);
// create the vector for the decisionFunction
var test = new la.Vector([1, 2]);
// give the vector to the decision function
var prediction = onevsall.decisionFunction(test); // returns the vector of scores</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>, <a href="module-la.SparseVector.html">module:la.SparseVector</a>, <a href="module-la.Matrix.html">module:la.Matrix</a>, or <a href="module-la.SparseMatrix.html">module:la.SparseMatrix</a>)</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Feature vector or matrix with feature vectors as columns.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>(<a href="module-la.Vector.html">module:la.Vector</a> or <a href="module-la.Matrix.html">module:la.Matrix</a>)</code>B The score and label of the input <code>X</code>:
<br>1. <a href="module-la.Vector.html">module:la.Vector</a> of scores, if <code>X</code> is of type <a href="module-la.Vector.html">module:la.Vector</a> or <a href="module-la.SparseVector.html">module:la.SparseVector</a>.
<br>2. <a href="module-la.Matrix.html">module:la.Matrix</a> with columns corresponding to instances, and rows corresponding to labels, if <code>X</code> is of type <a href="module-la.Matrix.html">module:la.Matrix</a> or <a href="module-la.SparseMatrix.html">module:la.SparseMatrix</a>.
</p>
</dd>
</dl>
<h3 id="fit"><span class="symbol-name">fit</span><span class="signature"><span class="signature-params">(X, y)</span> → <span class="signature-returns"> <a href="module-analytics.OneVsAll.html">module:analytics.OneVsAll</a></span></span></h3>
<p>Apply all models to the given vector and returns category with the highest score.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create a new OneVsAll object with the model analytics.SVC
var onevsall = new analytics.OneVsAll({ model: analytics.SVC, modelParam: { c: 10, maxTime: 1000 }, cats: 2 });
// create the data (matrix and vector) used to fit the model
var matrix = new la.Matrix([[1, 2, 1, 1], [2, 1, -3, -4]]);
var vector = new la.Vector([0, 0, 1, 1]);
// fit the model
onevsall.fit(matrix, vector);</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> or <a href="module-la.SparseMatrix.html">module:la.SparseMatrix</a>)</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>training instance 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> </p>
</td>
<td>
<p>target category for each training instance. Categories must
be integer numbers between <code>0</code> and <code>oneVsAllParam.categories-1</code>.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-analytics.OneVsAll.html">module:analytics.OneVsAll</a></code>B Self. The models have been fitted.</p>
</dd>
</dl>
<h3 id="getParams"><span class="symbol-name">getParams</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> <a href="module-analytics.html#~oneVsAllParam">module:analytics~oneVsAllParam</a></span></span></h3>
<p>Gets the parameters.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import analytics module
var analytics = require('qminer').analytics;
// create a new OneVsAll object with the model analytics.SVC
var onevsall = new analytics.OneVsAll({ model: analytics.SVC, modelParam: { c: 10, maxTime: 1000 }, cats: 2 });
// get the parameters
// returns the JSon object
// { model: analytics.SVC, modelParam: { c: 10, maxTime: 1000 }, cats: 2, models: [] }
var params = onevsall.getParams();</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-analytics.html#~oneVsAllParam">module:analytics~oneVsAllParam</a></code>B The constructor parameters.</p>
</dd>
</dl>
<h3 id="predict"><span class="symbol-name">predict</span><span class="signature"><span class="signature-params">(X)</span> → <span class="signature-returns"> (number or <a href="module-la.IntVector.html">module:la.IntVector</a>)</span></span></h3>
<p>Apply all models to the given vector and returns category with the highest score.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create a new OneVsAll object with the model analytics.SVC
var onevsall = new analytics.OneVsAll({ model: analytics.SVC, modelParam: { c: 10, maxTime: 1000 }, cats: 2 });
// create the data (matrix and vector) used to fit the model
var matrix = new la.Matrix([[1, 2, 1, 1], [2, 1, -3, -4]]);
var vector = new la.Vector([0, 0, 1, 1]);
// fit the model
onevsall.fit(matrix, vector);
// create the vector for the prediction
var test = new la.Vector([1, 2]);
// get the prediction of the vector
var prediction = onevsall.predict(test); // returns 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>X</p>
</td>
<td>
<p>(<a href="module-la.Vector.html">module:la.Vector</a>, <a href="module-la.SparseVector.html">module:la.SparseVector</a>, <a href="module-la.Matrix.html">module:la.Matrix</a>, or <a href="module-la.SparseMatrix.html">module:la.SparseMatrix</a>)</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Feature vector or matrix with feature vectors as columns.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>(number or <a href="module-la.IntVector.html">module:la.IntVector</a>)</code>B <br>1. number of the category with the higher score, if <code>X</code> is <a href="module-la.Vector.html">module:la.Vector</a> or <a href="module-la.SparseVector.html">module:la.SparseVector</a>.
<br>2. <a href="module-la.IntVector.html">module:la.IntVector</a> of categories with the higher score for each column of <code>X</code>, if <code>X</code> is <a href="module-la.Matrix.html">module:la.Matrix</a> or <a href="module-la.SparseMatrix.html">module:la.SparseMatrix</a>.
</p>
</dd>
</dl>
<h3 id="setParams"><span class="symbol-name">setParams</span><span class="signature"><span class="signature-params">(params)</span> → <span class="signature-returns"> <a href="module-analytics.OneVsAll.html">module:analytics.OneVsAll</a></span></span></h3>
<p>Sets the parameters.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import analytics module
var analytics = require('qminer').analytics;
// create a new OneVsAll object with the model analytics.SVC
var onevsall = new analytics.OneVsAll({ model: analytics.SVC, modelParam: { c: 10, maxTime: 1000 }, cats: 2 });
// set the parameters
var params = onevsall.setParams({ model: analytics.SVR, modelParam: { c: 12, maxTime: 10000}, cats: 3, verbose: true });</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>module:analytics~OneVsAllParam</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The constructor parameters.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-analytics.OneVsAll.html">module:analytics.OneVsAll</a></code>B Self. The parameters are changed.</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>