

<!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>sPlot &mdash; hep_ml 0.7.0 documentation</title>
  

  
  <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="_static/css/theme.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 data-url_root="./" id="documentation_options" 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 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="Code Examples" href="notebooks.html" />
    <link rel="prev" title="Fast predictions" href="speedup.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"> hep_ml
          

          
          </a>

          
            
            
              <div class="version">
                0.7.0
              </div>
            
          

          
<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">
          
            
            
              
            
            
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="index.html">hep_ml documentation</a></li>
<li class="toctree-l1"><a class="reference internal" href="gb.html">Gradient boosting</a></li>
<li class="toctree-l1"><a class="reference internal" href="losses.html">Losses for Gradient Boosting</a></li>
<li class="toctree-l1"><a class="reference internal" href="uboost.html">uBoost</a></li>
<li class="toctree-l1"><a class="reference internal" href="metrics.html">Metric functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="nnet.html">Neural networks</a></li>
<li class="toctree-l1"><a class="reference internal" href="preprocessing.html">Preprocessing data</a></li>
<li class="toctree-l1"><a class="reference internal" href="reweight.html">Reweighting algorithms</a></li>
<li class="toctree-l1"><a class="reference internal" href="speedup.html">Fast predictions</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">sPlot</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#example">Example</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="notebooks.html">Code Examples</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">hep_ml</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>sPlot</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="_sources/splot.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="module-hep_ml.splot">
<span id="splot"></span><h1>sPlot<a class="headerlink" href="#module-hep_ml.splot" title="Permalink to this headline">¶</a></h1>
<p><strong>sPlot</strong> is reweighting technique frequently used in HEP to reconstruct the distributions of features in mixture.
Initial information used is the probabilities obtained after fitting.</p>
<p><strong>hep_ml.splot</strong> contains standalone python implementation of this technique.
This implementation is brilliantly simple and clear - just as it should be.</p>
<div class="section" id="example">
<h2>Example<a class="headerlink" href="#example" title="Permalink to this headline">¶</a></h2>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">hep_ml.splot</span> <span class="kn">import</span> <span class="n">compute_sweights</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">pandas</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span><span class="s1">&#39;signal&#39;</span><span class="p">:</span> <span class="n">p_signal</span><span class="p">,</span> <span class="s1">&#39;bkg&#39;</span><span class="p">,</span> <span class="n">b_bkg</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sWeights</span> <span class="o">=</span> <span class="n">compute_sweights</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># plotting reconstructed distribution of some other variable</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">hist</span><span class="p">(</span><span class="n">other_var</span><span class="p">,</span> <span class="n">weights</span><span class="o">=</span><span class="n">sWeights</span><span class="o">.</span><span class="n">signal</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">plt</span><span class="o">.</span><span class="n">hist</span><span class="p">(</span><span class="n">other_var</span><span class="p">,</span> <span class="n">weights</span><span class="o">=</span><span class="n">sWeights</span><span class="o">.</span><span class="n">bkg</span><span class="p">)</span>
</pre></div>
</div>
<p>For more examples and explanations, see notebooks/Splot in repository.</p>
<dl class="py function">
<dt class="sig sig-object py" id="hep_ml.splot.compute_sweights">
<span class="sig-prename descclassname"><span class="pre">hep_ml.splot.</span></span><span class="sig-name descname"><span class="pre">compute_sweights</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">probabilities</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sample_weight</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/hep_ml/splot.html#compute_sweights"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#hep_ml.splot.compute_sweights" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes sWeights based on probabilities obtained from distribution fit.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>probabilities</strong> – pandas.DataFrame with probabilities of shape [n_samples, n_classes].
These probabilities are obtained after fit (typically, mass fit).
Pay attention, that for each sample sum of probabilities should be equal to 1.</p></li>
<li><p><strong>sample_weight</strong> – optionally you can pass weights of events, numpy.array of shape [n_samples]</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>pandas.DataFrame with sWeights of shape [n_samples, n_classes]</p>
</dd>
</dl>
</dd></dl>

</div>
</div>


           </div>
           
          </div>
          <footer>
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
        <a href="notebooks.html" class="btn btn-neutral float-right" title="Code Examples" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
        <a href="speedup.html" class="btn btn-neutral float-left" title="Fast predictions" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2015-2017, Yandex; Alex Rogozhnikov and contributors.

    </p>
  </div>
    
    
    
    Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    
    <a href="https://github.com/readthedocs/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>