blob: 2c317bce396e0afba8b84bd49e9983b6ee57b7d2 [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta content="IE=edge" http-equiv="X-UA-Compatible"/>
<meta content="width=device-width, initial-scale=1" name="viewport"/>
<title>Evaluation Metric API — mxnet documentation</title>
<link crossorigin="anonymous" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="../../_static/basic.css" rel="stylesheet" type="text/css">
<link href="../../_static/pygments.css" rel="stylesheet" type="text/css">
<link href="../../_static/mxnet.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../../',
VERSION: '',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: ''
};
</script>
<script src="../../_static/jquery-1.11.1.js" type="text/javascript"></script>
<script src="../../_static/underscore.js" type="text/javascript"></script>
<script src="../../_static/searchtools_custom.js" type="text/javascript"></script>
<script src="../../_static/doctools.js" type="text/javascript"></script>
<script src="../../_static/selectlang.js" type="text/javascript"></script>
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script>
<script type="text/javascript"> jQuery(function() { Search.loadIndex("/searchindex.js"); Search.init();}); </script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new
Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-96378503-1', 'auto');
ga('send', 'pageview');
</script>
<!-- -->
<!-- <script type="text/javascript" src="../../_static/jquery.js"></script> -->
<!-- -->
<!-- <script type="text/javascript" src="../../_static/underscore.js"></script> -->
<!-- -->
<!-- <script type="text/javascript" src="../../_static/doctools.js"></script> -->
<!-- -->
<!-- <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> -->
<!-- -->
<link href="index.html" rel="up" title="MXNet - Python API">
<link href="../r/index.html" rel="next" title="MXNet - R API"/>
<link href="callback.html" rel="prev" title="Callback API"/>
<link href="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/mxnet-icon.png" rel="icon" type="image/png"/>
</link></link></link></head>
<body role="document"><!-- Previous Navbar Layout
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="../../" class="navbar-brand">
<img src="http://data.mxnet.io/theme/mxnet.png">
</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul id="navbar" class="navbar navbar-left">
<li> <a href="../../get_started/index.html">Get Started</a> </li>
<li> <a href="../../tutorials/index.html">Tutorials</a> </li>
<li> <a href="../../how_to/index.html">How To</a> </li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true">Packages <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="../../packages/python/index.html">
Python
</a></li>
<li><a href="../../packages/r/index.html">
R
</a></li>
<li><a href="../../packages/julia/index.html">
Julia
</a></li>
<li><a href="../../packages/c++/index.html">
C++
</a></li>
<li><a href="../../packages/scala/index.html">
Scala
</a></li>
<li><a href="../../packages/perl/index.html">
Perl
</a></li>
</ul>
</li>
<li> <a href="../../system/index.html">System</a> </li>
<li>
<form class="" role="search" action="../../search.html" method="get" autocomplete="off">
<div class="form-group inner-addon left-addon">
<i class="glyphicon glyphicon-search"></i>
<input type="text" name="q" class="form-control" placeholder="Search">
</div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form> </li>
</ul>
<ul id="navbar" class="navbar navbar-right">
<li> <a href="../../index.html"><span class="flag-icon flag-icon-us"></span></a> </li>
<li> <a href="../..//zh/index.html"><span class="flag-icon flag-icon-cn"></span></a> </li>
</ul>
</div>
</div>
</div>
Previous Navbar Layout End -->
<div class="navbar navbar-fixed-top">
<div class="container" id="navContainer">
<div class="innder" id="header-inner">
<h1 id="logo-wrap">
<a href="../../" id="logo"><img src="http://data.mxnet.io/theme/mxnet.png"/></a>
</h1>
<nav class="nav-bar" id="main-nav">
<a class="main-nav-link" href="../../get_started/install.html">Install</a>
<a class="main-nav-link" href="../../tutorials/index.html">Tutorials</a>
<a class="main-nav-link" href="../../how_to/index.html">How To</a>
<span id="dropdown-menu-position-anchor">
<a aria-expanded="true" aria-haspopup="true" class="main-nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button">API <span class="caret"></span></a>
<ul class="dropdown-menu" id="package-dropdown-menu">
<li><a class="main-nav-link" href="../../api/python/index.html">Python</a></li>
<li><a class="main-nav-link" href="../../api/scala/index.html">Scala</a></li>
<li><a class="main-nav-link" href="../../api/r/index.html">R</a></li>
<li><a class="main-nav-link" href="../../api/julia/index.html">Julia</a></li>
<li><a class="main-nav-link" href="../../api/c++/index.html">C++</a></li>
<li><a class="main-nav-link" href="../../api/perl/index.html">Perl</a></li>
</ul>
</span>
<a class="main-nav-link" href="../../architecture/index.html">Architecture</a>
<!-- <a class="main-nav-link" href="../../community/index.html">Community</a> -->
<a class="main-nav-link" href="https://github.com/dmlc/mxnet">Github</a>
<span id="dropdown-menu-position-anchor-version" style="position: relative"><a href="#" class="main-nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true">Versions(master)<span class="caret"></span></a><ul id="package-dropdown-menu" class="dropdown-menu"><li><a class="main-nav-link" href=http://mxnet.incubator.apache.org/test/>v0.10.14</a></li><li><a class="main-nav-link" href=http://mxnet.incubator.apache.org/test/versions/0.10/index.html>0.10</a></li><li><a class="main-nav-link" href=http://mxnet.incubator.apache.org/test/versions/master/index.html>master</a></li></ul></span></nav>
<script> function getRootPath(){ return "../../" } </script>
<div class="burgerIcon dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button"></a>
<ul class="dropdown-menu dropdown-menu-right" id="burgerMenu">
<li><a href="../../get_started/install.html">Install</a></li>
<li><a href="../../tutorials/index.html">Tutorials</a></li>
<li><a href="../../how_to/index.html">How To</a></li>
<li class="dropdown-submenu">
<a href="#" tabindex="-1">API</a>
<ul class="dropdown-menu">
<li><a href="../../api/python/index.html" tabindex="-1">Python</a>
</li>
<li><a href="../../api/scala/index.html" tabindex="-1">Scala</a>
</li>
<li><a href="../../api/r/index.html" tabindex="-1">R</a>
</li>
<li><a href="../../api/julia/index.html" tabindex="-1">Julia</a>
</li>
<li><a href="../../api/c++/index.html" tabindex="-1">C++</a>
</li>
<li><a href="../../api/perl/index.html" tabindex="-1">Perl</a>
</li>
</ul>
</li>
<li><a href="../../architecture/index.html">Architecture</a></li>
<li><a class="main-nav-link" href="https://github.com/dmlc/mxnet">Github</a></li>
<li id="dropdown-menu-position-anchor-version-mobile" class="dropdown-submenu" style="position: relative"><a href="#" tabindex="-1">Versions(master)</a><ul class="dropdown-menu"><li><a tabindex="-1" href=http://mxnet.incubator.apache.org/test/>v0.10.14</a></li><li><a tabindex="-1" href=http://mxnet.incubator.apache.org/test/versions/0.10/index.html>0.10</a></li><li><a tabindex="-1" href=http://mxnet.incubator.apache.org/test/versions/master/index.html>master</a></li></ul></li></ul>
</div>
<div class="plusIcon dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button"><span aria-hidden="true" class="glyphicon glyphicon-plus"></span></a>
<ul class="dropdown-menu dropdown-menu-right" id="plusMenu"></ul>
</div>
<div id="search-input-wrap">
<form action="../../search.html" autocomplete="off" class="" method="get" role="search">
<div class="form-group inner-addon left-addon">
<i class="glyphicon glyphicon-search"></i>
<input class="form-control" name="q" placeholder="Search" type="text"/>
</div>
<input name="check_keywords" type="hidden" value="yes">
<input name="area" type="hidden" value="default"/>
</input></form>
<div id="search-preview"></div>
</div>
<div id="searchIcon">
<span aria-hidden="true" class="glyphicon glyphicon-search"></span>
</div>
<!-- <div id="lang-select-wrap"> -->
<!-- <label id="lang-select-label"> -->
<!-- <\!-- <i class="fa fa-globe"></i> -\-> -->
<!-- <span></span> -->
<!-- </label> -->
<!-- <select id="lang-select"> -->
<!-- <option value="en">Eng</option> -->
<!-- <option value="zh">中文</option> -->
<!-- </select> -->
<!-- </div> -->
<!-- <a id="mobile-nav-toggle">
<span class="mobile-nav-toggle-bar"></span>
<span class="mobile-nav-toggle-bar"></span>
<span class="mobile-nav-toggle-bar"></span>
</a> -->
</div>
</div>
</div>
<div class="container">
<div class="row">
<div aria-label="main navigation" class="sphinxsidebar leftsidebar" role="navigation">
<div class="sphinxsidebarwrapper">
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="index.html">Python Documents</a><ul class="current">
<li class="toctree-l2 current"><a class="reference internal" href="index.html#table-of-contents">Table of contents</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="ndarray.html">NDArray API</a></li>
<li class="toctree-l3"><a class="reference internal" href="symbol.html">Symbol API</a></li>
<li class="toctree-l3"><a class="reference internal" href="module.html">Module API</a></li>
<li class="toctree-l3"><a class="reference internal" href="rnn.html">RNN Cell API</a></li>
<li class="toctree-l3"><a class="reference internal" href="kvstore.html">KVStore API</a></li>
<li class="toctree-l3"><a class="reference internal" href="io.html">Data Loading API</a></li>
<li class="toctree-l3"><a class="reference internal" href="optimization.html">Optimization: initialize and update weights</a></li>
<li class="toctree-l3"><a class="reference internal" href="callback.html">Callback API</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="">Evaluation Metric API</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#overview">Overview</a></li>
<li class="toctree-l4"><a class="reference internal" href="#api-reference">API Reference</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../r/index.html">R Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../julia/index.html">Julia Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../c++/index.html">C++ Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../scala/index.html">Scala Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../perl/index.html">Perl Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../how_to/index.html">HowTo Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../architecture/index.html">System Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../tutorials/index.html">Tutorials</a></li>
</ul>
</div>
</div>
<div class="content">
<div class="section" id="evaluation-metric-api">
<span id="evaluation-metric-api"></span><h1>Evaluation Metric API<a class="headerlink" href="#evaluation-metric-api" title="Permalink to this headline"></a></h1>
<div class="section" id="overview">
<span id="overview"></span><h2>Overview<a class="headerlink" href="#overview" title="Permalink to this headline"></a></h2>
<p>This document lists all the evaluation metrics available to evaluate
the performance of a learned model.</p>
<table border="1" class="longtable docutils">
<colgroup>
<col width="10%"/>
<col width="90%"/>
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><a class="reference internal" href="model.html#module-mxnet.metric" title="mxnet.metric"><code class="xref py py-obj docutils literal"><span class="pre">mxnet.metric</span></code></a></td>
<td>Online evaluation metric module.</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="api-reference">
<span id="api-reference"></span><h2>API Reference<a class="headerlink" href="#api-reference" title="Permalink to this headline"></a></h2>
<script src="../../_static/js/auto_module_index.js" type="text/javascript"></script><span class="target" id="module-mxnet.metric"></span><p>Online evaluation metric module.</p>
<dl class="class">
<dt id="mxnet.metric.EvalMetric">
<em class="property">class </em><code class="descclassname">mxnet.metric.</code><code class="descname">EvalMetric</code><span class="sig-paren">(</span><em>name</em>, <em>output_names=None</em>, <em>label_names=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.EvalMetric" title="Permalink to this definition"></a></dt>
<dd><p>Base class for all evaluation metrics.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This is a base class that provides common metric interfaces.
One should not use this class directly, but instead create new metric
classes that extend it.</p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>name</strong> (<em>str</em>) – Name of this metric instance for display.</li>
<li><strong>output_names</strong> (<em>list of str, or None</em>) – Name of predictions that should be used when updating with update_dict.
By default include all predictions.</li>
<li><strong>label_names</strong> (<em>list of str, or None</em>) – Name of labels that should be used when updating with update_dict.
By default include all labels.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="mxnet.metric.EvalMetric.get_config">
<code class="descname">get_config</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.EvalMetric.get_config" title="Permalink to this definition"></a></dt>
<dd><p>Save configurations of metric. Can be recreated
from configs with metric.create(<a href="#id1"><span class="problematic" id="id2">**</span></a>config)</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.metric.EvalMetric.update_dict">
<code class="descname">update_dict</code><span class="sig-paren">(</span><em>label</em>, <em>pred</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.EvalMetric.update_dict" title="Permalink to this definition"></a></dt>
<dd><p>Update the internal evaluation with named label and pred</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>labels</strong> (<em>OrderedDict of str -> NDArray</em>) – name to array mapping for labels.</li>
<li><strong>preds</strong> (<em>list of NDArray</em>) – name to array mapping of predicted outputs.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.metric.EvalMetric.update">
<code class="descname">update</code><span class="sig-paren">(</span><em>labels</em>, <em>preds</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.EvalMetric.update" title="Permalink to this definition"></a></dt>
<dd><p>Updates the internal evaluation result.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>labels</strong> (list of <cite>NDArray</cite>) – The labels of the data.</li>
<li><strong>preds</strong> (list of <cite>NDArray</cite>) – Predicted values.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.metric.EvalMetric.reset">
<code class="descname">reset</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.EvalMetric.reset" title="Permalink to this definition"></a></dt>
<dd><p>Resets the internal evaluation result to initial state.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.metric.EvalMetric.get">
<code class="descname">get</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.EvalMetric.get" title="Permalink to this definition"></a></dt>
<dd><p>Gets the current evaluation result.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><ul class="simple">
<li><strong>names</strong> (<em>list of str</em>) –
Name of the metrics.</li>
<li><strong>values</strong> (<em>list of float</em>) –
Value of the evaluations.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.metric.EvalMetric.get_name_value">
<code class="descname">get_name_value</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.EvalMetric.get_name_value" title="Permalink to this definition"></a></dt>
<dd><p>Returns zipped name and value pairs.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">A (name, value) tuple list.</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">list of tuples</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="function">
<dt id="mxnet.metric.create">
<code class="descclassname">mxnet.metric.</code><code class="descname">create</code><span class="sig-paren">(</span><em>metric</em>, <em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.create" title="Permalink to this definition"></a></dt>
<dd><p>Creates evaluation metric from metric names or instances of EvalMetric
or a custom metric function.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>metric</strong> (<em>str or callable</em>) – <p>Specifies the metric to create.
This argument must be one of the below:</p>
<ul>
<li>Name of a metric.</li>
<li>An instance of <cite>EvalMetric</cite>.</li>
<li>A list, each element of which is a metric or a metric name.</li>
<li>An evaluation function that computes custom metric for a given batch of
labels and predictions.</li>
</ul>
</li>
<li><strong>*args</strong><p>Additional arguments to metric constructor.
Only used when metric is str.</p>
</li>
<li><strong>**kwargs</strong><p>Additional arguments to metric constructor.
Only used when metric is str</p>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">def</span> <span class="nf">custom_metric</span><span class="p">(</span><span class="n">label</span><span class="p">,</span> <span class="n">pred</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">label</span> <span class="o">-</span> <span class="n">pred</span><span class="p">))</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">metric1</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">metric</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="s1">'acc'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">metric2</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">metric</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">custom_metric</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">metric3</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">metric</span><span class="o">.</span><span class="n">create</span><span class="p">([</span><span class="n">metric1</span><span class="p">,</span> <span class="n">metric2</span><span class="p">,</span> <span class="s1">'rmse'</span><span class="p">])</span>
</pre></div>
</div>
</dd></dl>
<dl class="class">
<dt id="mxnet.metric.CompositeEvalMetric">
<em class="property">class </em><code class="descclassname">mxnet.metric.</code><code class="descname">CompositeEvalMetric</code><span class="sig-paren">(</span><em>metrics=None</em>, <em>name='composite'</em>, <em>output_names=None</em>, <em>label_names=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.CompositeEvalMetric" title="Permalink to this definition"></a></dt>
<dd><p>Manages multiple evaluation metrics.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>metrics</strong> (<em>list of EvalMetric</em>) – List of child metrics.</li>
<li><strong>name</strong> (<em>str</em>) – Name of this metric instance for display.</li>
<li><strong>output_names</strong> (<em>list of str, or None</em>) – Name of predictions that should be used when updating with update_dict.
By default include all predictions.</li>
<li><strong>label_names</strong> (<em>list of str, or None</em>) – Name of labels that should be used when updating with update_dict.
By default include all labels.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">predicts</span> <span class="o">=</span> <span class="p">[</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mf">0.3</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mf">1.</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">]])]</span>
<span class="gp">>>> </span><span class="n">labels</span> <span class="o">=</span> <span class="p">[</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">])]</span>
<span class="gp">>>> </span><span class="n">eval_metrics_1</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">metric</span><span class="o">.</span><span class="n">Accuracy</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">eval_metrics_2</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">metric</span><span class="o">.</span><span class="n">F1</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">eval_metrics</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">metric</span><span class="o">.</span><span class="n">CompositeEvalMetric</span><span class="p">()</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">child_metric</span> <span class="ow">in</span> <span class="p">[</span><span class="n">eval_metrics_1</span><span class="p">,</span> <span class="n">eval_metrics_2</span><span class="p">]:</span>
<span class="gp">>>> </span> <span class="n">eval_metrics</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">child_metric</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">eval_metrics</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">labels</span> <span class="o">=</span> <span class="n">labels</span><span class="p">,</span> <span class="n">preds</span> <span class="o">=</span> <span class="n">predicts</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">print</span> <span class="n">eval_metrics</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<span class="go">(['accuracy', 'f1'], [0.6666666666666666, 0.8])</span>
</pre></div>
</div>
<dl class="method">
<dt id="mxnet.metric.CompositeEvalMetric.add">
<code class="descname">add</code><span class="sig-paren">(</span><em>metric</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.CompositeEvalMetric.add" title="Permalink to this definition"></a></dt>
<dd><p>Adds a child metric.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>metric</strong> – A metric instance.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.metric.CompositeEvalMetric.get_metric">
<code class="descname">get_metric</code><span class="sig-paren">(</span><em>index</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.CompositeEvalMetric.get_metric" title="Permalink to this definition"></a></dt>
<dd><p>Returns a child metric.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>index</strong> (<em>int</em>) – Index of child metric in the list of metrics.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.metric.CompositeEvalMetric.update">
<code class="descname">update</code><span class="sig-paren">(</span><em>labels</em>, <em>preds</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.CompositeEvalMetric.update" title="Permalink to this definition"></a></dt>
<dd><p>Updates the internal evaluation result.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>labels</strong> (list of <cite>NDArray</cite>) – The labels of the data.</li>
<li><strong>preds</strong> (list of <cite>NDArray</cite>) – Predicted values.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.metric.CompositeEvalMetric.reset">
<code class="descname">reset</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.CompositeEvalMetric.reset" title="Permalink to this definition"></a></dt>
<dd><p>Resets the internal evaluation result to initial state.</p>
</dd></dl>
<dl class="method">
<dt id="mxnet.metric.CompositeEvalMetric.get">
<code class="descname">get</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.CompositeEvalMetric.get" title="Permalink to this definition"></a></dt>
<dd><p>Returns the current evaluation result.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><ul class="simple">
<li><strong>names</strong> (<em>list of str</em>) –
Name of the metrics.</li>
<li><strong>values</strong> (<em>list of float</em>) –
Value of the evaluations.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="mxnet.metric.Accuracy">
<em class="property">class </em><code class="descclassname">mxnet.metric.</code><code class="descname">Accuracy</code><span class="sig-paren">(</span><em>axis=1</em>, <em>name='accuracy'</em>, <em>output_names=None</em>, <em>label_names=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.Accuracy" title="Permalink to this definition"></a></dt>
<dd><p>Computes accuracy classification score.</p>
<p>The accuracy score is defined as</p>
<div class="math">
\[\text{accuracy}(y, \hat{y}) = \frac{1}{n} \sum_{i=0}^{n-1}
\text{1}(\hat{y_i} == y_i)\]</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>axis</strong> (<em>int, default=1</em>) – The axis that represents classes</li>
<li><strong>name</strong> (<em>str</em>) – Name of this metric instance for display.</li>
<li><strong>output_names</strong> (<em>list of str, or None</em>) – Name of predictions that should be used when updating with update_dict.
By default include all predictions.</li>
<li><strong>label_names</strong> (<em>list of str, or None</em>) – Name of labels that should be used when updating with update_dict.
By default include all labels.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">predicts</span> <span class="o">=</span> <span class="p">[</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mf">0.3</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mf">1.</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">]])]</span>
<span class="gp">>>> </span><span class="n">labels</span> <span class="o">=</span> <span class="p">[</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">])]</span>
<span class="gp">>>> </span><span class="n">acc</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">metric</span><span class="o">.</span><span class="n">Accuracy</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">acc</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">preds</span> <span class="o">=</span> <span class="n">predicts</span><span class="p">,</span> <span class="n">labels</span> <span class="o">=</span> <span class="n">labels</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">print</span> <span class="n">acc</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<span class="go">('accuracy', 0.6666666666666666)</span>
</pre></div>
</div>
<dl class="method">
<dt id="mxnet.metric.Accuracy.update">
<code class="descname">update</code><span class="sig-paren">(</span><em>labels</em>, <em>preds</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.Accuracy.update" title="Permalink to this definition"></a></dt>
<dd><p>Updates the internal evaluation result.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>labels</strong> (list of <cite>NDArray</cite>) – The labels of the data.</li>
<li><strong>preds</strong> (list of <cite>NDArray</cite>) – Predicted values.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="mxnet.metric.TopKAccuracy">
<em class="property">class </em><code class="descclassname">mxnet.metric.</code><code class="descname">TopKAccuracy</code><span class="sig-paren">(</span><em>top_k=1</em>, <em>name='top_k_accuracy'</em>, <em>output_names=None</em>, <em>label_names=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.TopKAccuracy" title="Permalink to this definition"></a></dt>
<dd><p>Computes top k predictions accuracy.</p>
<p><cite>TopKAccuracy</cite> differs from Accuracy in that it considers the prediction
to be <code class="docutils literal"><span class="pre">True</span></code> as long as the ground truth label is in the top K
predicated labels.</p>
<p>If <cite>top_k</cite> = <code class="docutils literal"><span class="pre">1</span></code>, then <cite>TopKAccuracy</cite> is identical to <cite>Accuracy</cite>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>top_k</strong> (<em>int</em>) – Whether targets are in top k predictions.</li>
<li><strong>name</strong> (<em>str</em>) – Name of this metric instance for display.</li>
<li><strong>output_names</strong> (<em>list of str, or None</em>) – Name of predictions that should be used when updating with update_dict.
By default include all predictions.</li>
<li><strong>label_names</strong> (<em>list of str, or None</em>) – Name of labels that should be used when updating with update_dict.
By default include all labels.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </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">999</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">top_k</span> <span class="o">=</span> <span class="mi">3</span>
<span class="gp">>>> </span><span class="n">labels</span> <span class="o">=</span> <span class="p">[</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">2</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">9</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">9</span><span class="p">,</span> <span class="mi">6</span><span class="p">])]</span>
<span class="gp">>>> </span><span class="n">predicts</span> <span class="o">=</span> <span class="p">[</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">(</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">10</span><span class="p">))]</span>
<span class="gp">>>> </span><span class="n">acc</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">metric</span><span class="o">.</span><span class="n">TopKAccuracy</span><span class="p">(</span><span class="n">top_k</span><span class="o">=</span><span class="n">top_k</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">acc</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">labels</span><span class="p">,</span> <span class="n">predicts</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">print</span> <span class="n">acc</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<span class="go">('top_k_accuracy', 0.3)</span>
</pre></div>
</div>
<dl class="method">
<dt id="mxnet.metric.TopKAccuracy.update">
<code class="descname">update</code><span class="sig-paren">(</span><em>labels</em>, <em>preds</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.TopKAccuracy.update" title="Permalink to this definition"></a></dt>
<dd><p>Updates the internal evaluation result.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>labels</strong> (list of <cite>NDArray</cite>) – The labels of the data.</li>
<li><strong>preds</strong> (list of <cite>NDArray</cite>) – Predicted values.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="mxnet.metric.F1">
<em class="property">class </em><code class="descclassname">mxnet.metric.</code><code class="descname">F1</code><span class="sig-paren">(</span><em>name='f1'</em>, <em>output_names=None</em>, <em>label_names=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.F1" title="Permalink to this definition"></a></dt>
<dd><p>Computes the F1 score of a binary classification problem.</p>
<p>The F1 score is equivalent to weighted average of the precision and recall,
where the best value is 1.0 and the worst value is 0.0. The formula for F1 score is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">F1</span> <span class="o">=</span> <span class="mi">2</span> <span class="o">*</span> <span class="p">(</span><span class="n">precision</span> <span class="o">*</span> <span class="n">recall</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">precision</span> <span class="o">+</span> <span class="n">recall</span><span class="p">)</span>
</pre></div>
</div>
<p>The formula for precision and recall is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">precision</span> <span class="o">=</span> <span class="n">true_positives</span> <span class="o">/</span> <span class="p">(</span><span class="n">true_positives</span> <span class="o">+</span> <span class="n">false_positives</span><span class="p">)</span>
<span class="n">recall</span> <span class="o">=</span> <span class="n">true_positives</span> <span class="o">/</span> <span class="p">(</span><span class="n">true_positives</span> <span class="o">+</span> <span class="n">false_negatives</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This F1 score only supports binary classification.</p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>name</strong> (<em>str</em>) – Name of this metric instance for display.</li>
<li><strong>output_names</strong> (<em>list of str, or None</em>) – Name of predictions that should be used when updating with update_dict.
By default include all predictions.</li>
<li><strong>label_names</strong> (<em>list of str, or None</em>) – Name of labels that should be used when updating with update_dict.
By default include all labels.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">predicts</span> <span class="o">=</span> <span class="p">[</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mf">0.3</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.</span><span class="p">,</span> <span class="mf">1.</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">]])]</span>
<span class="gp">>>> </span><span class="n">labels</span> <span class="o">=</span> <span class="p">[</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.</span><span class="p">,</span> <span class="mf">1.</span><span class="p">,</span> <span class="mf">1.</span><span class="p">])]</span>
<span class="gp">>>> </span><span class="n">acc</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">metric</span><span class="o">.</span><span class="n">F1</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">acc</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">preds</span> <span class="o">=</span> <span class="n">predicts</span><span class="p">,</span> <span class="n">labels</span> <span class="o">=</span> <span class="n">labels</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">print</span> <span class="n">acc</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<span class="go">('f1', 0.8)</span>
</pre></div>
</div>
<dl class="method">
<dt id="mxnet.metric.F1.update">
<code class="descname">update</code><span class="sig-paren">(</span><em>labels</em>, <em>preds</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.F1.update" title="Permalink to this definition"></a></dt>
<dd><p>Updates the internal evaluation result.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>labels</strong> (list of <cite>NDArray</cite>) – The labels of the data.</li>
<li><strong>preds</strong> (list of <cite>NDArray</cite>) – Predicted values.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="mxnet.metric.Perplexity">
<em class="property">class </em><code class="descclassname">mxnet.metric.</code><code class="descname">Perplexity</code><span class="sig-paren">(</span><em>ignore_label</em>, <em>axis=-1</em>, <em>name='perplexity'</em>, <em>output_names=None</em>, <em>label_names=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.Perplexity" title="Permalink to this definition"></a></dt>
<dd><p>Computes perplexity.</p>
<p>Perplexity is a measurement of how well a probability distribution
or model predicts a sample. A low perplexity indicates the model
is good at predicting the sample.</p>
<p>The perplexity of a model q is defined as</p>
<div class="math">
\[b^{\big(-\frac{1}{N} \sum_{i=1}^N \log_b q(x_i) \big)}
= \exp \big(-\frac{1}{N} \sum_{i=1}^N \log q(x_i)\big)\]</div>
<p>where we let <cite>b = e</cite>.</p>
<p><span class="math">\(q(x_i)\)</span> is the predicted value of its ground truth
label on sample <span class="math">\(x_i\)</span>.</p>
<p>For example, we have three samples <span class="math">\(x_1, x_2, x_3\)</span> and their labels
are <span class="math">\([0, 1, 1]\)</span>.
Suppose our model predicts <span class="math">\(q(x_1) = p(y_1 = 0 | x_1) = 0.3\)</span>
and <span class="math">\(q(x_2) = 1.0\)</span>,
<span class="math">\(q(x_3) = 0.6\)</span>. The perplexity of model q is
<span class="math">\(exp\big(-(\log 0.3 + \log 1.0 + \log 0.6) / 3\big) = 1.77109762852\)</span>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>ignore_label</strong> (<em>int or None</em>) – Index of invalid label to ignore when
counting. By default, sets to -1.
If set to <cite>None</cite>, it will include all entries.</li>
<li><strong>axis</strong> (<em>int (default -1)</em>) – The axis from prediction that was used to
compute softmax. By default use the last
axis.</li>
<li><strong>name</strong> (<em>str</em>) – Name of this metric instance for display.</li>
<li><strong>output_names</strong> (<em>list of str, or None</em>) – Name of predictions that should be used when updating with update_dict.
By default include all predictions.</li>
<li><strong>label_names</strong> (<em>list of str, or None</em>) – Name of labels that should be used when updating with update_dict.
By default include all labels.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">predicts</span> <span class="o">=</span> <span class="p">[</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mf">0.3</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mf">1.</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">]])]</span>
<span class="gp">>>> </span><span class="n">labels</span> <span class="o">=</span> <span class="p">[</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">])]</span>
<span class="gp">>>> </span><span class="n">perp</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">metric</span><span class="o">.</span><span class="n">Perplexity</span><span class="p">(</span><span class="n">ignore_label</span><span class="o">=</span><span class="bp">None</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">perp</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">labels</span><span class="p">,</span> <span class="n">predicts</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">print</span> <span class="n">perp</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<span class="go">('Perplexity', 1.7710976285155853)</span>
</pre></div>
</div>
<dl class="method">
<dt id="mxnet.metric.Perplexity.update">
<code class="descname">update</code><span class="sig-paren">(</span><em>labels</em>, <em>preds</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.Perplexity.update" title="Permalink to this definition"></a></dt>
<dd><p>Updates the internal evaluation result.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>labels</strong> (list of <cite>NDArray</cite>) – The labels of the data.</li>
<li><strong>preds</strong> (list of <cite>NDArray</cite>) – Predicted values.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mxnet.metric.Perplexity.get">
<code class="descname">get</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.Perplexity.get" title="Permalink to this definition"></a></dt>
<dd><p>Returns the current evaluation result.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Representing name of the metric and evaluation result.</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">Tuple of (str, float)</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="mxnet.metric.MAE">
<em class="property">class </em><code class="descclassname">mxnet.metric.</code><code class="descname">MAE</code><span class="sig-paren">(</span><em>name='mae'</em>, <em>output_names=None</em>, <em>label_names=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.MAE" title="Permalink to this definition"></a></dt>
<dd><p>Computes Mean Absolute Error (MAE) loss.</p>
<p>The mean absolute error is given by</p>
<div class="math">
\[\frac{\sum_i^n |y_i - \hat{y}_i|}{n}\]</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>name</strong> (<em>str</em>) – Name of this metric instance for display.</li>
<li><strong>output_names</strong> (<em>list of str, or None</em>) – Name of predictions that should be used when updating with update_dict.
By default include all predictions.</li>
<li><strong>label_names</strong> (<em>list of str, or None</em>) – Name of labels that should be used when updating with update_dict.
By default include all labels.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">predicts</span> <span class="o">=</span> <span class="p">[</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.5</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">7</span><span class="p">])</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span><span class="mi">1</span><span class="p">))]</span>
<span class="gp">>>> </span><span class="n">labels</span> <span class="o">=</span> <span class="p">[</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">2.5</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">8</span><span class="p">])</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span><span class="mi">1</span><span class="p">))]</span>
<span class="gp">>>> </span><span class="n">mean_absolute_error</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">metric</span><span class="o">.</span><span class="n">MAE</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">mean_absolute_error</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">labels</span> <span class="o">=</span> <span class="n">labels</span><span class="p">,</span> <span class="n">preds</span> <span class="o">=</span> <span class="n">predicts</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">print</span> <span class="n">mean_absolute_error</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<span class="go">('mae', 0.5)</span>
</pre></div>
</div>
<dl class="method">
<dt id="mxnet.metric.MAE.update">
<code class="descname">update</code><span class="sig-paren">(</span><em>labels</em>, <em>preds</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.MAE.update" title="Permalink to this definition"></a></dt>
<dd><p>Updates the internal evaluation result.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>labels</strong> (list of <cite>NDArray</cite>) – The labels of the data.</li>
<li><strong>preds</strong> (list of <cite>NDArray</cite>) – Predicted values.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="mxnet.metric.MSE">
<em class="property">class </em><code class="descclassname">mxnet.metric.</code><code class="descname">MSE</code><span class="sig-paren">(</span><em>name='mse'</em>, <em>output_names=None</em>, <em>label_names=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.MSE" title="Permalink to this definition"></a></dt>
<dd><p>Computes Mean Squared Error (MSE) loss.</p>
<p>The mean squared error is given by</p>
<div class="math">
\[\frac{\sum_i^n (y_i - \hat{y}_i)^2}{n}\]</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>name</strong> (<em>str</em>) – Name of this metric instance for display.</li>
<li><strong>output_names</strong> (<em>list of str, or None</em>) – Name of predictions that should be used when updating with update_dict.
By default include all predictions.</li>
<li><strong>label_names</strong> (<em>list of str, or None</em>) – Name of labels that should be used when updating with update_dict.
By default include all labels.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">predicts</span> <span class="o">=</span> <span class="p">[</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.5</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">7</span><span class="p">])</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span><span class="mi">1</span><span class="p">))]</span>
<span class="gp">>>> </span><span class="n">labels</span> <span class="o">=</span> <span class="p">[</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">2.5</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">8</span><span class="p">])</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span><span class="mi">1</span><span class="p">))]</span>
<span class="gp">>>> </span><span class="n">mean_squared_error</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">metric</span><span class="o">.</span><span class="n">MSE</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">mean_squared_error</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">labels</span> <span class="o">=</span> <span class="n">labels</span><span class="p">,</span> <span class="n">preds</span> <span class="o">=</span> <span class="n">predicts</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">print</span> <span class="n">mean_squared_error</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<span class="go">('mse', 0.375)</span>
</pre></div>
</div>
<dl class="method">
<dt id="mxnet.metric.MSE.update">
<code class="descname">update</code><span class="sig-paren">(</span><em>labels</em>, <em>preds</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.MSE.update" title="Permalink to this definition"></a></dt>
<dd><p>Updates the internal evaluation result.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>labels</strong> (list of <cite>NDArray</cite>) – The labels of the data.</li>
<li><strong>preds</strong> (list of <cite>NDArray</cite>) – Predicted values.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="mxnet.metric.RMSE">
<em class="property">class </em><code class="descclassname">mxnet.metric.</code><code class="descname">RMSE</code><span class="sig-paren">(</span><em>name='rmse'</em>, <em>output_names=None</em>, <em>label_names=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.RMSE" title="Permalink to this definition"></a></dt>
<dd><p>Computes Root Mean Squred Error (RMSE) loss.</p>
<p>The root mean squared error is given by</p>
<div class="math">
\[\sqrt{\frac{\sum_i^n (y_i - \hat{y}_i)^2}{n}}\]</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>name</strong> (<em>str</em>) – Name of this metric instance for display.</li>
<li><strong>output_names</strong> (<em>list of str, or None</em>) – Name of predictions that should be used when updating with update_dict.
By default include all predictions.</li>
<li><strong>label_names</strong> (<em>list of str, or None</em>) – Name of labels that should be used when updating with update_dict.
By default include all labels.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">predicts</span> <span class="o">=</span> <span class="p">[</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.5</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">7</span><span class="p">])</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span><span class="mi">1</span><span class="p">))]</span>
<span class="gp">>>> </span><span class="n">labels</span> <span class="o">=</span> <span class="p">[</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">2.5</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">8</span><span class="p">])</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span><span class="mi">1</span><span class="p">))]</span>
<span class="gp">>>> </span><span class="n">root_mean_squared_error</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">metric</span><span class="o">.</span><span class="n">RMSE</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">root_mean_squared_error</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">labels</span> <span class="o">=</span> <span class="n">labels</span><span class="p">,</span> <span class="n">preds</span> <span class="o">=</span> <span class="n">predicts</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">print</span> <span class="n">root_mean_squared_error</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<span class="go">('rmse', 0.612372457981)</span>
</pre></div>
</div>
<dl class="method">
<dt id="mxnet.metric.RMSE.update">
<code class="descname">update</code><span class="sig-paren">(</span><em>labels</em>, <em>preds</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.RMSE.update" title="Permalink to this definition"></a></dt>
<dd><p>Updates the internal evaluation result.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>labels</strong> (list of <cite>NDArray</cite>) – The labels of the data.</li>
<li><strong>preds</strong> (list of <cite>NDArray</cite>) – Predicted values.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="mxnet.metric.CrossEntropy">
<em class="property">class </em><code class="descclassname">mxnet.metric.</code><code class="descname">CrossEntropy</code><span class="sig-paren">(</span><em>eps=1e-08</em>, <em>name='cross-entropy'</em>, <em>output_names=None</em>, <em>label_names=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.CrossEntropy" title="Permalink to this definition"></a></dt>
<dd><p>Computes Cross Entropy loss.</p>
<p>The cross entropy is given by</p>
<div class="math">
\[-y\log \hat{y} + (1-y)\log (1-\hat{y})\]</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>eps</strong> (<em>float</em>) – Cross Entropy loss is undefined for predicted value is 0 or 1,
so predicted values are added with the small constant.</li>
<li><strong>name</strong> (<em>str</em>) – Name of this metric instance for display.</li>
<li><strong>output_names</strong> (<em>list of str, or None</em>) – Name of predictions that should be used when updating with update_dict.
By default include all predictions.</li>
<li><strong>label_names</strong> (<em>list of str, or None</em>) – Name of labels that should be used when updating with update_dict.
By default include all labels.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">predicts</span> <span class="o">=</span> <span class="p">[</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mf">0.3</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mf">1.</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">]])]</span>
<span class="gp">>>> </span><span class="n">labels</span> <span class="o">=</span> <span class="p">[</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">])]</span>
<span class="gp">>>> </span><span class="n">ce</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">metric</span><span class="o">.</span><span class="n">CrossEntropy</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">ce</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">labels</span><span class="p">,</span> <span class="n">predicts</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">print</span> <span class="n">ce</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<span class="go">('cross-entropy', 0.57159948348999023)</span>
</pre></div>
</div>
<dl class="method">
<dt id="mxnet.metric.CrossEntropy.update">
<code class="descname">update</code><span class="sig-paren">(</span><em>labels</em>, <em>preds</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.CrossEntropy.update" title="Permalink to this definition"></a></dt>
<dd><p>Updates the internal evaluation result.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>labels</strong> (list of <cite>NDArray</cite>) – The labels of the data.</li>
<li><strong>preds</strong> (list of <cite>NDArray</cite>) – Predicted values.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="mxnet.metric.Loss">
<em class="property">class </em><code class="descclassname">mxnet.metric.</code><code class="descname">Loss</code><span class="sig-paren">(</span><em>name='loss'</em>, <em>output_names=None</em>, <em>label_names=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.Loss" title="Permalink to this definition"></a></dt>
<dd><p>Dummy metric for directly printing loss.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>name</strong> (<em>str</em>) – Name of this metric instance for display.</li>
<li><strong>output_names</strong> (<em>list of str, or None</em>) – Name of predictions that should be used when updating with update_dict.
By default include all predictions.</li>
<li><strong>label_names</strong> (<em>list of str, or None</em>) – Name of labels that should be used when updating with update_dict.
By default include all labels.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="class">
<dt id="mxnet.metric.Torch">
<em class="property">class </em><code class="descclassname">mxnet.metric.</code><code class="descname">Torch</code><span class="sig-paren">(</span><em>name='torch'</em>, <em>output_names=None</em>, <em>label_names=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.Torch" title="Permalink to this definition"></a></dt>
<dd><p>Dummy metric for torch criterions.</p>
</dd></dl>
<dl class="class">
<dt id="mxnet.metric.Caffe">
<em class="property">class </em><code class="descclassname">mxnet.metric.</code><code class="descname">Caffe</code><span class="sig-paren">(</span><em>name='caffe'</em>, <em>output_names=None</em>, <em>label_names=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.Caffe" title="Permalink to this definition"></a></dt>
<dd><p>Dummy metric for caffe criterions.</p>
</dd></dl>
<dl class="class">
<dt id="mxnet.metric.CustomMetric">
<em class="property">class </em><code class="descclassname">mxnet.metric.</code><code class="descname">CustomMetric</code><span class="sig-paren">(</span><em>feval</em>, <em>name=None</em>, <em>allow_extra_outputs=False</em>, <em>output_names=None</em>, <em>label_names=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.CustomMetric" title="Permalink to this definition"></a></dt>
<dd><p>Computes a customized evaluation metric.</p>
<p>The <cite>feval</cite> function can return a <cite>tuple</cite> of (sum_metric, num_inst) or return
an <cite>int</cite> sum_metric.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>feval</strong> (<em>callable(label, pred)</em>) – Customized evaluation function.</li>
<li><strong>name</strong> (<em>str</em>) – The name of the metric. (the default is None).</li>
<li><strong>allow_extra_outputs</strong> (<em>bool, optional</em>) – If true, the prediction outputs can have extra outputs.
This is useful in RNN, where the states are also produced
in outputs for forwarding. (the default is False).</li>
<li><strong>name</strong> – Name of this metric instance for display.</li>
<li><strong>output_names</strong> (<em>list of str, or None</em>) – Name of predictions that should be used when updating with update_dict.
By default include all predictions.</li>
<li><strong>label_names</strong> (<em>list of str, or None</em>) – Name of labels that should be used when updating with update_dict.
By default include all labels.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">predicts</span> <span class="o">=</span> <span class="p">[</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.5</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">7</span><span class="p">])</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span><span class="mi">1</span><span class="p">))]</span>
<span class="gp">>>> </span><span class="n">labels</span> <span class="o">=</span> <span class="p">[</span><span class="n">mx</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">2.5</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">8</span><span class="p">])</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span><span class="mi">1</span><span class="p">))]</span>
<span class="gp">>>> </span><span class="n">feval</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="p">:</span> <span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">mean</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">eval_metrics</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">metric</span><span class="o">.</span><span class="n">CustomMetric</span><span class="p">(</span><span class="n">feval</span><span class="o">=</span><span class="n">feval</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">eval_metrics</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">labels</span><span class="p">,</span> <span class="n">predicts</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">print</span> <span class="n">eval_metrics</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<span class="go">('custom(<lambda>)', 6.0)</span>
</pre></div>
</div>
<dl class="method">
<dt id="mxnet.metric.CustomMetric.update">
<code class="descname">update</code><span class="sig-paren">(</span><em>labels</em>, <em>preds</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.CustomMetric.update" title="Permalink to this definition"></a></dt>
<dd><p>Updates the internal evaluation result.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>labels</strong> (list of <cite>NDArray</cite>) – The labels of the data.</li>
<li><strong>preds</strong> (list of <cite>NDArray</cite>) – Predicted values.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="function">
<dt id="mxnet.metric.np">
<code class="descclassname">mxnet.metric.</code><code class="descname">np</code><span class="sig-paren">(</span><em>numpy_feval</em>, <em>name=None</em>, <em>allow_extra_outputs=False</em><span class="sig-paren">)</span><a class="headerlink" href="#mxnet.metric.np" title="Permalink to this definition"></a></dt>
<dd><p>Creates a custom evaluation metric that receives its inputs as numpy arrays.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name"/>
<col class="field-body"/>
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>numpy_feval</strong> (<em>callable(label, pred)</em>) – Custom evaluation function that receives labels and predictions for a minibatch
as numpy arrays and returns the corresponding custom metric as a floating point number.</li>
<li><strong>name</strong> (<em>str, optional</em>) – Name of the custom metric.</li>
<li><strong>allow_extra_outputs</strong> (<em>bool, optional</em>) – Whether prediction output is allowed to have extra outputs. This is useful in cases
like RNN where states are also part of output which can then be fed back to the RNN
in the next step. By default, extra outputs are not allowed.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Custom metric corresponding to the provided labels and predictions.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">float</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Example</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">def</span> <span class="nf">custom_metric</span><span class="p">(</span><span class="n">label</span><span class="p">,</span> <span class="n">pred</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">label</span><span class="o">-</span><span class="n">pred</span><span class="p">))</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">metric</span> <span class="o">=</span> <span class="n">mx</span><span class="o">.</span><span class="n">metric</span><span class="o">.</span><span class="n">np</span><span class="p">(</span><span class="n">custom_metric</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
<script>auto_index("api-reference");</script></div>
</div>
<div class="container">
<div class="footer">
<p> © 2015-2017 DMLC. All rights reserved. </p>
</div>
</div>
</div>
<div aria-label="main navigation" class="sphinxsidebar rightsidebar" role="navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../../index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Evaluation Metric API</a><ul>
<li><a class="reference internal" href="#overview">Overview</a></li>
<li><a class="reference internal" href="#api-reference">API Reference</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- pagename != index -->
<script crossorigin="anonymous" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="../../_static/js/sidebar.js" type="text/javascript"></script>
<script src="../../_static/js/search.js" type="text/javascript"></script>
<script src="../../_static/js/navbar.js" type="text/javascript"></script>
<script src="../../_static/js/clipboard.min.js" type="text/javascript"></script>
<script src="../../_static/js/copycode.js" type="text/javascript"></script>
<script type="text/javascript">
$('body').ready(function () {
$('body').css('visibility', 'visible');
});
</script>
</div></body>
</html>