blob: 00f68ff1da508f9445993e05c14da4ce705b6c7d [file] [log] [blame]
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Algorithms &mdash; SystemDS 2.0.0 documentation</title>
<link rel="stylesheet" href="../../static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../static/pygments.css" type="text/css" />
<!--[if lt IE 9]>
<script src="../../static/js/html5shiv.min.js"></script>
<![endif]-->
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../static/documentation_options.js"></script>
<script src="../../static/jquery.js"></script>
<script src="../../static/underscore.js"></script>
<script src="../../static/doctools.js"></script>
<script src="../../static/language_data.js"></script>
<script type="text/javascript" src="../../static/js/theme.js"></script>
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
<link rel="next" title="SystemDSContext" href="../context/systemds_context.html" />
<link rel="prev" title="Design" href="../../onnx_systemds/onnx_systemds_design.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home" alt="Documentation Home"> SystemDS
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<p class="caption"><span class="caption-text">Getting Started:</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../getting_started/install.html">Install SystemDS</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../getting_started/simple_examples.html">QuickStart</a></li>
</ul>
<p class="caption"><span class="caption-text">Guides</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../guide/federated.html">Federated Environment</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../guide/algorithms_basics.html">Built-in Algorithms</a></li>
</ul>
<p class="caption"><span class="caption-text">Onnx SystemDS</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../onnx_systemds/onnx_systemds.html">QuickStart Onnx</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../onnx_systemds/onnx_systemds_design.html">Design</a></li>
</ul>
<p class="caption"><span class="caption-text">API</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="current reference internal" href="#">Algorithms</a></li>
<li class="toctree-l1"><a class="reference internal" href="../context/systemds_context.html">SystemDSContext</a></li>
<li class="toctree-l1"><a class="reference internal" href="../matrix/data_gen.html">Data Generators</a></li>
<li class="toctree-l1"><a class="reference internal" href="../matrix/matrix.html">Matrix</a></li>
<li class="toctree-l1"><a class="reference internal" href="../matrix/federated.html">Federated</a></li>
<li class="toctree-l1"><a class="reference internal" href="operation_node.html">Operation Node</a></li>
<li class="toctree-l1"><a class="reference internal" href="../onnx_systemds/convert.html">Convert</a></li>
<li class="toctree-l1"><a class="reference internal" href="../onnx_systemds/onnx_helper.html">Onnx Helper</a></li>
<li class="toctree-l1"><a class="reference internal" href="../onnx_systemds/operator_gen.html">Operator Gen</a></li>
<li class="toctree-l1"><a class="reference internal" href="../onnx_systemds/render.html">Render</a></li>
<li class="toctree-l1"><a class="reference internal" href="../onnx_systemds/util.html">Util</a></li>
</ul>
<p class="caption"><span class="caption-text">Internals API</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../script_building/dag.html">Dag</a></li>
<li class="toctree-l1"><a class="reference internal" href="../script_building/script.html">Script</a></li>
<li class="toctree-l1"><a class="reference internal" href="../utils/converters.html">Converters</a></li>
<li class="toctree-l1"><a class="reference internal" href="../utils/helpers.html">Helpers</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">SystemDS</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html" class="icon icon-home"></a> &raquo;</li>
<li>Algorithms</li>
<li class="wy-breadcrumbs-aside">
<a href="../../sources/api/operator/algorithms.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="algorithms">
<h1>Algorithms<a class="headerlink" href="#algorithms" title="Permalink to this headline"></a></h1>
<p>SystemDS support different Machine learning algorithms out of the box.</p>
<p>As an example the lm algorithm can be used as follows:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># Import numpy and SystemDS matrix</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">systemds.context</span> <span class="kn">import</span> <span class="n">SystemDSContext</span>
<span class="kn">from</span> <span class="nn">systemds.matrix</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="kn">from</span> <span class="nn">systemds.operator.algorithm</span> <span class="kn">import</span> <span class="n">lm</span>
<span class="c1"># Set a seed</span>
<span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">seed</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="c1"># Generate matrix of feature vectors</span>
<span class="n">features</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">15</span><span class="p">)</span>
<span class="c1"># Generate a 1-column matrix of response values</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="c1"># compute the weights</span>
<span class="k">with</span> <span class="n">SystemDSContext</span><span class="p">()</span> <span class="k">as</span> <span class="n">sds</span><span class="p">:</span>
<span class="n">weights</span> <span class="o">=</span> <span class="n">lm</span><span class="p">(</span><span class="n">Matrix</span><span class="p">(</span><span class="n">sds</span><span class="p">,</span> <span class="n">features</span><span class="p">),</span> <span class="n">Matrix</span><span class="p">(</span><span class="n">sds</span><span class="p">,</span> <span class="n">y</span><span class="p">))</span><span class="o">.</span><span class="n">compute</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="n">weights</span><span class="p">)</span>
</pre></div>
</div>
<p>The output should be similar to:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">[[</span><span class="o">-</span><span class="mf">0.11538199</span><span class="p">]</span>
<span class="p">[</span><span class="o">-</span><span class="mf">0.20386541</span><span class="p">]</span>
<span class="p">[</span><span class="o">-</span><span class="mf">0.39956035</span><span class="p">]</span>
<span class="p">[</span> <span class="mf">1.04078623</span><span class="p">]</span>
<span class="p">[</span> <span class="mf">0.4327084</span> <span class="p">]</span>
<span class="p">[</span> <span class="mf">0.18954599</span><span class="p">]</span>
<span class="p">[</span> <span class="mf">0.49858968</span><span class="p">]</span>
<span class="p">[</span><span class="o">-</span><span class="mf">0.26812763</span><span class="p">]</span>
<span class="p">[</span> <span class="mf">0.09961844</span><span class="p">]</span>
<span class="p">[</span><span class="o">-</span><span class="mf">0.57000751</span><span class="p">]</span>
<span class="p">[</span><span class="o">-</span><span class="mf">0.43386048</span><span class="p">]</span>
<span class="p">[</span> <span class="mf">0.55358873</span><span class="p">]</span>
<span class="p">[</span><span class="o">-</span><span class="mf">0.54638565</span><span class="p">]</span>
<span class="p">[</span> <span class="mf">0.2205885</span> <span class="p">]</span>
<span class="p">[</span> <span class="mf">0.37957689</span><span class="p">]]</span>
</pre></div>
</div>
<span class="target" id="module-systemds.operator.algorithm"></span><dl class="py function">
<dt id="systemds.operator.algorithm.kmeans">
<code class="sig-prename descclassname">systemds.operator.algorithm.</code><code class="sig-name descname">kmeans</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span><span class="p">:</span> <span class="n">systemds.operator.operation_node.OperationNode</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span><span class="p">:</span> <span class="n">Dict<span class="p">[</span>str<span class="p">, </span>Union<span class="p">[</span>DAGNode<span class="p">, </span>str<span class="p">, </span>int<span class="p">, </span>float<span class="p">, </span>bool<span class="p">]</span><span class="p">]</span></span></em><span class="sig-paren">)</span> &#x2192; systemds.operator.operation_node.OperationNode<a class="headerlink" href="#systemds.operator.algorithm.kmeans" title="Permalink to this definition"></a></dt>
<dd><p>Performs KMeans on matrix input.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x</strong> – Input dataset to perform K-Means on.</p></li>
<li><p><strong>k</strong> – The number of centroids to use for the algorithm.</p></li>
<li><p><strong>runs</strong> – The number of concurrent instances of K-Means to run (with different initial centroids).</p></li>
<li><p><strong>max_iter</strong> – The maximum number of iterations to run the K-Means algorithm for.</p></li>
<li><p><strong>eps</strong> – Tolerance for the algorithm to declare convergence using WCSS change ratio.</p></li>
<li><p><strong>is_verbose</strong> – Boolean flag if the algorithm should be run in a verbose manner.</p></li>
<li><p><strong>avg_sample_size_per_centroid</strong> – The average number of records per centroid in the data samples.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><cite>OperationNode</cite> List containing two outputs 1. the clusters, 2 the cluster ID associated with each row in x.</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="systemds.operator.algorithm.l2svm">
<code class="sig-prename descclassname">systemds.operator.algorithm.</code><code class="sig-name descname">l2svm</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span><span class="p">:</span> <span class="n">systemds.operator.operation_node.OperationNode</span></em>, <em class="sig-param"><span class="n">y</span><span class="p">:</span> <span class="n">systemds.operator.operation_node.OperationNode</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span><span class="p">:</span> <span class="n">Dict<span class="p">[</span>str<span class="p">, </span>Union<span class="p">[</span>DAGNode<span class="p">, </span>str<span class="p">, </span>int<span class="p">, </span>float<span class="p">, </span>bool<span class="p">]</span><span class="p">]</span></span></em><span class="sig-paren">)</span> &#x2192; systemds.operator.operation_node.OperationNode<a class="headerlink" href="#systemds.operator.algorithm.l2svm" title="Permalink to this definition"></a></dt>
<dd><p>Perform L2SVM on matrix with labels given.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x</strong> – Input dataset</p></li>
<li><p><strong>y</strong> – Input labels in shape of one column</p></li>
<li><p><strong>kwargs</strong> – Dictionary of extra arguments</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><cite>OperationNode</cite> containing the model fit.</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="systemds.operator.algorithm.lm">
<code class="sig-prename descclassname">systemds.operator.algorithm.</code><code class="sig-name descname">lm</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span><span class="p">:</span> <span class="n">systemds.operator.operation_node.OperationNode</span></em>, <em class="sig-param"><span class="n">y</span><span class="p">:</span> <span class="n">systemds.operator.operation_node.OperationNode</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span><span class="p">:</span> <span class="n">Dict<span class="p">[</span>str<span class="p">, </span>Union<span class="p">[</span>DAGNode<span class="p">, </span>str<span class="p">, </span>int<span class="p">, </span>float<span class="p">, </span>bool<span class="p">]</span><span class="p">]</span></span></em><span class="sig-paren">)</span> &#x2192; systemds.operator.operation_node.OperationNode<a class="headerlink" href="#systemds.operator.algorithm.lm" title="Permalink to this definition"></a></dt>
<dd><p>Performs LM on matrix with labels given.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x</strong> – Input dataset</p></li>
<li><p><strong>y</strong> – Input labels in shape of one column</p></li>
<li><p><strong>kwargs</strong> – Dictionary of extra arguments</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><cite>OperationNode</cite> containing the model fit.</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="systemds.operator.algorithm.multiLogReg">
<code class="sig-prename descclassname">systemds.operator.algorithm.</code><code class="sig-name descname">multiLogReg</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span><span class="p">:</span> <span class="n">systemds.operator.operation_node.OperationNode</span></em>, <em class="sig-param"><span class="n">y</span><span class="p">:</span> <span class="n">systemds.operator.operation_node.OperationNode</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span><span class="p">:</span> <span class="n">Dict<span class="p">[</span>str<span class="p">, </span>Union<span class="p">[</span>DAGNode<span class="p">, </span>str<span class="p">, </span>int<span class="p">, </span>float<span class="p">, </span>bool<span class="p">]</span><span class="p">]</span></span></em><span class="sig-paren">)</span> &#x2192; systemds.operator.operation_node.OperationNode<a class="headerlink" href="#systemds.operator.algorithm.multiLogReg" title="Permalink to this definition"></a></dt>
<dd><p>Performs Multiclass Logistic Regression on the matrix input
using Trust Region method.</p>
<p>See: Trust Region Newton Method for Logistic Regression, Lin, Weng and Keerthi, JMLR 9 (2008) 627-650)</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x</strong> – Input dataset to perform logstic regression on</p></li>
<li><p><strong>y</strong> – Labels rowaligned with the input dataset</p></li>
<li><p><strong>icpt</strong> – Intercept, default 2, Intercept presence, shifting and rescaling X columns:
0 = no intercept, no shifting, no rescaling;
1 = add intercept, but neither shift nor rescale X;
2 = add intercept, shift &amp; rescale X columns to mean = 0, variance = 1</p></li>
<li><p><strong>tol</strong> – float tolerance for the algorithm.</p></li>
<li><p><strong>reg</strong> – Regularization parameter (lambda = 1/C); intercept settings are not regularized.</p></li>
<li><p><strong>maxi</strong> – Maximum outer iterations of the algorithm</p></li>
<li><p><strong>maxii</strong> – Maximum inner iterations of the algorithm
:return: <cite>OperationNode</cite> of a matrix containing the regression parameters trained.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="systemds.operator.algorithm.multiLogRegPredict">
<code class="sig-prename descclassname">systemds.operator.algorithm.</code><code class="sig-name descname">multiLogRegPredict</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span><span class="p">:</span> <span class="n">systemds.operator.operation_node.OperationNode</span></em>, <em class="sig-param"><span class="n">b</span><span class="p">:</span> <span class="n">systemds.operator.operation_node.OperationNode</span></em>, <em class="sig-param"><span class="n">y</span><span class="p">:</span> <span class="n">systemds.operator.operation_node.OperationNode</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span><span class="p">:</span> <span class="n">Dict<span class="p">[</span>str<span class="p">, </span>Union<span class="p">[</span>DAGNode<span class="p">, </span>str<span class="p">, </span>int<span class="p">, </span>float<span class="p">, </span>bool<span class="p">]</span><span class="p">]</span></span></em><span class="sig-paren">)</span> &#x2192; systemds.operator.operation_node.OperationNode<a class="headerlink" href="#systemds.operator.algorithm.multiLogRegPredict" title="Permalink to this definition"></a></dt>
<dd><p>Performs prediction on input data x using the model trained, b.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x</strong> – The data to perform classification on.</p></li>
<li><p><strong>b</strong> – The regression parameters trained from multiLogReg.</p></li>
<li><p><strong>y</strong> – The Labels expected to be contained in the X dataset, to calculate accuracy.</p></li>
<li><p><strong>verbose</strong> – Boolean specifying if the prediction should be verbose.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><cite>OperationNode</cite> List containing three outputs.
1. The predicted means / probabilities
2. The predicted response vector
3. The scalar value of accuracy</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="systemds.operator.algorithm.pca">
<code class="sig-prename descclassname">systemds.operator.algorithm.</code><code class="sig-name descname">pca</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x</span><span class="p">:</span> <span class="n">systemds.operator.operation_node.OperationNode</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span><span class="p">:</span> <span class="n">Dict<span class="p">[</span>str<span class="p">, </span>Union<span class="p">[</span>DAGNode<span class="p">, </span>str<span class="p">, </span>int<span class="p">, </span>float<span class="p">, </span>bool<span class="p">]</span><span class="p">]</span></span></em><span class="sig-paren">)</span> &#x2192; systemds.operator.operation_node.OperationNode<a class="headerlink" href="#systemds.operator.algorithm.pca" title="Permalink to this definition"></a></dt>
<dd><p>Performs PCA on the matrix input</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x</strong> – Input dataset to perform Principal Componenet Analysis (PCA) on.</p></li>
<li><p><strong>K</strong> – The number of reduced dimensions.</p></li>
<li><p><strong>center</strong> – Boolean specifying if the input values should be centered.</p></li>
<li><p><strong>scale</strong> – Boolean specifying if the input values should be scaled.
:return: <cite>OperationNode</cite> List containing two outputs 1. The dimensionality reduced X input, 2. A matrix to reduce dimensionality similarly on unseen data.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="../context/systemds_context.html" class="btn btn-neutral float-right" title="SystemDSContext" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="../../onnx_systemds/onnx_systemds_design.html" class="btn btn-neutral float-left" title="Design" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2020, Apache SystemDS
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>