docs/test_smoother.html
<div class="highlight"><pre><span></span><span class="sd">"""Test smoother."""</span>
<span class="kn">import</span> <span class="nn">altair_recipes</span> <span class="kn">as</span> <span class="nn">ar</span>
<span class="kn">from</span> <span class="nn">altair_recipes.common</span> <span class="kn">import</span> <span class="n">viz_reg_test</span>
<span class="kn">from</span> <span class="nn">altair_recipes.display_pweave</span> <span class="kn">import</span> <span class="n">show_test</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="kn">as</span> <span class="nn">pd</span>
</pre></div>
<h2>Smoother</h2>
<div class="highlight"><pre><span></span><span class="nd">@viz_reg_test</span>
<span class="k">def</span> <span class="nf">test_smoother</span><span class="p">():</span>
<span class="n">x</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">uniform</span><span class="p">(</span><span class="n">size</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="nb">dict</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">x</span><span class="p">,</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">uniform</span><span class="p">(</span><span class="n">size</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span> <span class="o">+</span> <span class="mi">10</span> <span class="o">*</span> <span class="n">x</span><span class="p">))</span>
<span class="k">return</span> <span class="n">ar</span><span class="o">.</span><span class="n">smoother</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="o">*</span><span class="nb">list</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">columns</span><span class="p">))</span>
<span class="n">show_test</span><span class="p">(</span><span class="n">test_smoother</span><span class="p">)</span>
</pre></div>
<script src="https://cdn.jsdelivr.net/npm/vega@3"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-lite@2"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@3"></script>
<div id="A604a066ea180633f4a2d9f91ce6ba8f977a0f88baa17c34cc87c0ecdb01af83c"></div>
<script type="text/javascript">
var spec = {
"$schema": "https://vega.github.io/schema/vega-lite/v4.0.0.json",
"config": {
"view": {
"continuousHeight": 300,
"continuousWidth": 400
}
},
"data": {
"name": "data-23786d09348bf1b8e690bc291077eedd"
},
"datasets": {
"data-23786d09348bf1b8e690bc291077eedd": [
{
"median": null,
"q1": null,
"q3": null,
"x": null,
"y": 0.48137138748359143
},
{
"median": null,
"q1": null,
"q3": null,
"x": null,
"y": 0.7578629150648163
},
{
"median": null,
"q1": null,
"q3": null,
"x": null,
"y": 0.45543194364532846
},
{
"median": null,
"q1": null,
"q3": null,
"x": null,
"y": 1.0832871715144188
},
{
"median": null,
"q1": null,
"q3": null,
"x": null,
"y": 0.6158026106035869
},
{
"median": null,
"q1": null,
"q3": null,
"x": null,
"y": 1.4941780713083705
},
{
"median": null,
"q1": null,
"q3": null,
"x": null,
"y": 1.2187035520920113
},
{
"median": null,
"q1": null,
"q3": null,
"x": null,
"y": 1.5241584016813468
},
{
"median": null,
"q1": null,
"q3": null,
"x": null,
"y": 1.2677987378623916
},
{
"median": null,
"q1": null,
"q3": null,
"x": null,
"y": 1.5293150839389877
},
{
"median": null,
"q1": null,
"q3": null,
"x": null,
"y": 1.1326137562010712
},
{
"median": null,
"q1": null,
"q3": null,
"x": null,
"y": 1.3309908224089766
},
{
"median": null,
"q1": null,
"q3": null,
"x": null,
"y": 1.636007671764125
},
{
"median": null,
"q1": null,
"q3": null,
"x": null,
"y": 1.5572940943211202
},
{
"median": null,
"q1": null,
"q3": null,
"x": null,
"y": 1.606599307247512
},
{
"median": null,
"q1": null,
"q3": null,
"x": null,
"y": 1.2191161190737483
},
{
"median": null,
"q1": null,
"q3": null,
"x": null,
"y": 2.13004690559728
},
{
"median": null,
"q1": null,
"q3": null,
"x": null,
"y": 2.2087455902932067
},
{
"median": null,
"q1": null,
"q3": null,
"x": null,
"y": 1.504171629924258
},
{
"median": null,
"q1": null,
"q3": null,
"x": null,
"y": 2.2482118394147674
},
{
"median": null,
"q1": null,
"q3": null,
"x": null,
"y": 1.4527260723997975
},
{
"median": null,
"q1": null,
"q3": null,
"x": null,
"y": 2.287124609599761
},
{
"median": null,
"q1": null,
"q3": null,
"x": null,
"y": 2.461103408172197
},
{
"median": null,
"q1": null,
"q3": null,
"x": null,
"y": 2.3223724286887353
},
{
"median": 1.504171629924258,
"q1": 1.2187035520920113,
"q3": 2.13004690559728,
"x": 0.10204481074802807,
"y": 2.941345121803421
},
{
"median": 1.5241584016813468,
"q1": 1.2191161190737483,
"q3": 2.2087455902932067,
"x": 0.11037514116430513,
"y": 2.2125875437977887
},
{
"median": 1.5293150839389877,
"q1": 1.2677987378623916,
"q3": 2.2087455902932067,
"x": 0.11827442586893322,
"y": 2.20405249805071
},
{
"median": 1.5572940943211202,
"q1": 1.3309908224089766,
"q3": 2.2125875437977887,
"x": 0.11872771895424405,
"y": 2.5134229154711654
},
{
"median": 1.606599307247512,
"q1": 1.4527260723997975,
"q3": 2.2482118394147674,
"x": 0.1201965612131689,
"y": 3.102016764012414
},
{
"median": 1.636007671764125,
"q1": 1.4941780713083705,
"q3": 2.287124609599761,
"x": 0.1289262976548533,
"y": 3.2635715500451115
},
{
"median": 2.13004690559728,
"q1": 1.504171629924258,
"q3": 2.3223724286887353,
"x": 0.13179786240439217,
"y": 3.2678608653603503
},
{
"median": 2.20405249805071,
"q1": 1.5241584016813468,
"q3": 2.461103408172197,
"x": 0.1381829513486138,
"y": 3.1734213064609986
},
{
"median": 2.2087455902932067,
"q1": 1.5293150839389877,
"q3": 2.5134229154711654,
"x": 0.1433532874090464,
"y": 3.6336117245212987
},
{
"median": 2.2125875437977887,
"q1": 1.5572940943211202,
"q3": 2.941345121803421,
"x": 0.15896958364551972,
"y": 3.6658163771449823
},
{
"median": 2.2482118394147674,
"q1": 1.606599307247512,
"q3": 3.102016764012414,
"x": 0.16130951788499626,
"y": 3.8685248087909496
},
{
"median": 2.287124609599761,
"q1": 1.636007671764125,
"q3": 3.1734213064609986,
"x": 0.18319136200711683,
"y": 3.344525950437673
},
{
"median": 2.3223724286887353,
"q1": 2.13004690559728,
"q3": 3.2635715500451115,
"x": 0.1965823616800535,
"y": 3.583910586729328
},
{
"median": 2.461103408172197,
"q1": 2.20405249805071,
"q3": 3.2678608653603503,
"x": 0.2088767560948347,
"y": 4.4916256015889235
},
{
"median": 2.5134229154711654,
"q1": 2.2087455902932067,
"q3": 3.344525950437673,
"x": 0.2103825610738409,
"y": 4.635954715994092
},
{
"median": 2.941345121803421,
"q1": 2.2125875437977887,
"q3": 3.583910586729328,
"x": 0.24442559200160274,
"y": 4.543055049002252
},
{
"median": 3.102016764012414,
"q1": 2.2482118394147674,
"q3": 3.6336117245212987,
"x": 0.2532916025397821,
"y": 4.787164199774763
},
{
"median": 3.1734213064609986,
"q1": 2.287124609599761,
"q3": 3.6658163771449823,
"x": 0.26455561210462697,
"y": 4.764108346646464
},
{
"median": 3.2635715500451115,
"q1": 2.3223724286887353,
"q3": 3.8685248087909496,
"x": 0.2653894909394454,
"y": 4.436697007115679
},
{
"median": 3.2678608653603503,
"q1": 2.461103408172197,
"q3": 4.436697007115679,
"x": 0.2828069625764096,
"y": 4.485301136909006
},
{
"median": 3.344525950437673,
"q1": 2.5134229154711654,
"q3": 4.485301136909006,
"x": 0.2894060929472011,
"y": 4.737881408041311
},
{
"median": 3.583910586729328,
"q1": 2.941345121803421,
"q3": 4.4916256015889235,
"x": 0.29614019752214493,
"y": 4.967914043898764
},
{
"median": 3.6336117245212987,
"q1": 3.102016764012414,
"q3": 4.543055049002252,
"x": 0.31542835092418386,
"y": 5.254141191991418
},
{
"median": 3.6658163771449823,
"q1": 3.1734213064609986,
"q3": 4.635954715994092,
"x": 0.317983179393976,
"y": 4.696977386387935
},
{
"median": 3.8685248087909496,
"q1": 3.2635715500451115,
"q3": 4.696977386387935,
"x": 0.31856895245132366,
"y": 5.570877257252542
},
{
"median": 4.436697007115679,
"q1": 3.2678608653603503,
"q3": 4.737881408041311,
"x": 0.359507900573786,
"y": 5.0702910257890625
},
{
"median": 4.485301136909006,
"q1": 3.344525950437673,
"q3": 4.740850004816269,
"x": 0.3637107709426226,
"y": 4.740850004816269
},
{
"median": 4.4916256015889235,
"q1": 3.583910586729328,
"q3": 4.764108346646464,
"x": 0.3687251706609641,
"y": 5.878656754993402
},
{
"median": 4.543055049002252,
"q1": 3.6336117245212987,
"q3": 4.787164199774763,
"x": 0.3834415188257777,
"y": 5.768113337691955
},
{
"median": 4.635954715994092,
"q1": 3.6658163771449823,
"q3": 4.967914043898764,
"x": 0.41426299451466997,
"y": 6.135357870000172
},
{
"median": 4.696977386387935,
"q1": 3.8685248087909496,
"q3": 5.0702910257890625,
"x": 0.4146619399905236,
"y": 6.411020375086407
},
{
"median": 4.737881408041311,
"q1": 4.436697007115679,
"q3": 5.254141191991418,
"x": 0.4236547993389047,
"y": 6.165951576069478
},
{
"median": 4.740850004816269,
"q1": 4.485301136909006,
"q3": 5.570877257252542,
"x": 0.43703195379934145,
"y": 6.600228539990545
},
{
"median": 4.764108346646464,
"q1": 4.4916256015889235,
"q3": 5.768113337691955,
"x": 0.4375872112626925,
"y": 6.379924886256827
},
{
"median": 4.787164199774763,
"q1": 4.543055049002252,
"q3": 5.878656754993402,
"x": 0.43860151346232035,
"y": 5.982621814642515
},
{
"median": 4.967914043898764,
"q1": 4.635954715994092,
"q3": 5.878656754993402,
"x": 0.45615033221654855,
"y": 5.85141600883679
},
{
"median": 5.0702910257890625,
"q1": 4.696977386387935,
"q3": 5.982621814642515,
"x": 0.46147936225293185,
"y": 6.489586985078562
},
{
"median": 5.254141191991418,
"q1": 4.737881408041311,
"q3": 6.092543976074155,
"x": 0.4663107728563063,
"y": 6.092543976074155
},
{
"median": 5.570877257252542,
"q1": 4.740850004816269,
"q3": 6.135357870000172,
"x": 0.4686512016477016,
"y": 6.762827782839034
},
{
"median": 5.768113337691955,
"q1": 4.764108346646464,
"q3": 6.135357870000172,
"x": 0.5218483217500717,
"y": 6.0669769919110745
},
{
"median": 5.85141600883679,
"q1": 4.787164199774763,
"q3": 6.165951576069478,
"x": 0.5232480534666997,
"y": 6.6952824760737935
},
{
"median": 5.878656754993402,
"q1": 4.967914043898764,
"q3": 6.379924886256827,
"x": 0.5288949197529045,
"y": 6.8225407886047025
},
{
"median": 5.982621814642515,
"q1": 5.0702910257890625,
"q3": 6.411020375086407,
"x": 0.5448831829968969,
"y": 6.767227732006944
},
{
"median": 6.0669769919110745,
"q1": 5.254141191991418,
"q3": 6.489586985078562,
"x": 0.5488135039273248,
"y": 7.005603427403162
},
{
"median": 6.092543976074155,
"q1": 5.570877257252542,
"q3": 6.600228539990545,
"x": 0.5666014542065752,
"y": 7.035098465084398
},
{
"median": 6.135357870000172,
"q1": 5.768113337691955,
"q3": 6.6952824760737935,
"x": 0.5680445610939323,
"y": 7.338402213378995
},
{
"median": 6.165951576069478,
"q1": 5.85141600883679,
"q3": 6.762827782839034,
"x": 0.5684339488686485,
"y": 7.285351494123082
},
{
"median": 6.379924886256827,
"q1": 5.878656754993402,
"q3": 6.767227732006944,
"x": 0.5701967704178796,
"y": 7.473861143502762
},
{
"median": 6.411020375086407,
"q1": 5.982621814642515,
"q3": 6.8225407886047025,
"x": 0.5759464955561793,
"y": 6.883947548611939
},
{
"median": 6.489586985078562,
"q1": 6.0669769919110745,
"q3": 6.883947548611939,
"x": 0.5865129348100832,
"y": 7.41026727972196
},
{
"median": 6.600228539990545,
"q1": 6.092543976074155,
"q3": 7.005603427403162,
"x": 0.6027633760716439,
"y": 7.249621426468808
},
{
"median": 6.6952824760737935,
"q1": 6.135357870000172,
"q3": 7.035098465084398,
"x": 0.604845519745046,
"y": 7.162614015074707
},
{
"median": 6.762827782839034,
"q1": 6.165951576069478,
"q3": 7.162614015074707,
"x": 0.6120957227224214,
"y": 7.412176884538276
},
{
"median": 6.767227732006944,
"q1": 6.379924886256827,
"q3": 7.249621426468808,
"x": 0.6169339968747569,
"y": 7.42190163691636
},
{
"median": 6.8225407886047025,
"q1": 6.411020375086407,
"q3": 7.285351494123082,
"x": 0.6176354970758771,
"y": 8.10764443116959
},
{
"median": 6.883947548611939,
"q1": 6.489586985078562,
"q3": 7.338402213378995,
"x": 0.6399210213275238,
"y": 8.186333497340437
},
{
"median": 7.005603427403162,
"q1": 6.600228539990545,
"q3": 7.41026727972196,
"x": 0.6458941130666561,
"y": 8.171105595287933
},
{
"median": 7.035098465084398,
"q1": 6.6952824760737935,
"q3": 7.412176884538276,
"x": 0.6531083254653984,
"y": 8.663302871353357
},
{
"median": 7.162614015074707,
"q1": 6.762827782839034,
"q3": 7.42190163691636,
"x": 0.6563295894652734,
"y": 8.449281962094192
},
{
"median": 7.249621426468808,
"q1": 6.767227732006944,
"q3": 7.473861143502762,
"x": 0.6667667154456677,
"y": 8.364375759444274
},
{
"median": 7.285351494123082,
"q1": 6.8225407886047025,
"q3": 8.10764443116959,
"x": 0.6674103799636817,
"y": 8.492910024093938
},
{
"median": 7.338402213378995,
"q1": 6.883947548611939,
"q3": 8.171105595287933,
"x": 0.6706378696181594,
"y": 8.221646382664353
},
{
"median": 7.41026727972196,
"q1": 7.005603427403162,
"q3": 8.186333497340437,
"x": 0.6818202991034834,
"y": 8.347429452497508
},
{
"median": 7.412176884538276,
"q1": 7.035098465084398,
"q3": 8.221646382664353,
"x": 0.6924721193700198,
"y": 8.90747132811524
},
{
"median": 7.42190163691636,
"q1": 7.162614015074707,
"q3": 8.347429452497508,
"x": 0.6976311959272649,
"y": 9.109439637412097
},
{
"median": 7.473861143502762,
"q1": 7.249621426468808,
"q3": 8.364375759444274,
"x": 0.7151893663724195,
"y": 9.392653072545956
},
{
"median": 8.10764443116959,
"q1": 7.285351494123082,
"q3": 8.449281962094192,
"x": 0.7163272041185655,
"y": 9.48998191361167
},
{
"median": 8.171105595287933,
"q1": 7.338402213378995,
"q3": 8.492910024093938,
"x": 0.7392635793983017,
"y": 9.553403333781745
},
{
"median": 8.186333497340437,
"q1": 7.41026727972196,
"q3": 8.663302871353357,
"x": 0.7742336894342167,
"y": 9.604906971241743
},
{
"median": 8.221646382664353,
"q1": 7.412176884538276,
"q3": 8.90747132811524,
"x": 0.7781567509498505,
"y": 10.089584055147931
},
{
"median": 8.347429452497508,
"q1": 7.42190163691636,
"q3": 9.109439637412097,
"x": 0.7805291762864555,
"y": 9.748263987170388
},
{
"median": 8.364375759444274,
"q1": 7.473861143502762,
"q3": 9.392653072545956,
"x": 0.7917250380826646,
"y": 9.859709237650911
},
{
"median": 8.449281962094192,
"q1": 8.10764443116959,
"q3": 9.48998191361167,
"x": 0.7991585642167236,
"y": 10.285631256338087
},
{
"median": 8.492910024093938,
"q1": 8.171105595287933,
"q3": 9.553403333781745,
"x": 0.8209932298479351,
"y": 9.967607406799772
},
{
"median": 8.663302871353357,
"q1": 8.186333497340437,
"q3": 9.604906971241743,
"x": 0.8289400292173631,
"y": 10.511437702147282
},
{
"median": 8.90747132811524,
"q1": 8.221646382664353,
"q3": 9.748263987170388,
"x": 0.832619845547938,
"y": 10.046231315268638
}
]
},
"layer": [
{
"encoding": {
"x": {
"field": "x",
"type": "quantitative"
},
"y": {
"field": "median",
"type": "quantitative"
}
},
"height": 600,
"mark": "line",
"width": 800
},
{
"encoding": {
"x": {
"field": "x",
"type": "quantitative"
},
"y": {
"field": "q1",
"title": "y",
"type": "quantitative"
},
"y2": {
"field": "q3"
}
},
"height": 600,
"mark": {
"opacity": 0.2,
"type": "area"
},
"width": 800
}
]
};
var opt = {"renderer": "canvas", "actions": false};
vegaEmbed("#A604a066ea180633f4a2d9f91ce6ba8f977a0f88baa17c34cc87c0ecdb01af83c", spec, opt);
</script>