/usr/share/doc/python-mlpy-doc/html/classification.html is in python-mlpy-doc 2.2.0~dfsg1-3build3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Supervised Classification — mlpy 2.2.0 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '2.2.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</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>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Regression" href="regression.html" />
<link rel="prev" title="Kernels" href="kernel.html" />
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
</head>
<body role="document">
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="supervised-classification">
<h1>Supervised Classification<a class="headerlink" href="#supervised-classification" title="Permalink to this headline">¶</a></h1>
<p>Every classifier must be initialized with a specific set of
parameters. Two distinct methods are deployed for the <em>training</em>
(<code class="xref py py-meth docutils literal"><span class="pre">compute()</span></code>) and the <em>testing</em> (<code class="xref py py-meth docutils literal"><span class="pre">predict()</span></code>)
phases. Whenever possible, the real valued prediction is stored in the
<em>realpred</em> variable.</p>
<div class="section" id="support-vector-machines-svms">
<h2>Support Vector Machines (SVMs)<a class="headerlink" href="#support-vector-machines-svms" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="mlpy.Svm">
<em class="property">class </em><code class="descclassname">mlpy.</code><code class="descname">Svm</code><span class="sig-paren">(</span><em>kernel='linear'</em>, <em>kp=0.1</em>, <em>C=1.0</em>, <em>tol=0.001</em>, <em>eps=0.001</em>, <em>maxloops=1000</em>, <em>cost=0.0</em>, <em>alpha_tversky=1.0</em>, <em>beta_tversky=1.0</em>, <em>opt_offset=True</em><span class="sig-paren">)</span><a class="headerlink" href="#mlpy.Svm" title="Permalink to this definition">¶</a></dt>
<dd><p>Support Vector Machines (SVM).</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">Example:</th><td class="field-body"></td>
</tr>
</tbody>
</table>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">mlpy</span>
<span class="gp">>>> </span><span class="n">xtr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">,</span> <span class="mf">3.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">],</span> <span class="c1"># first sample</span>
<span class="gp">... </span> <span class="p">[</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">,</span> <span class="mf">3.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">],</span> <span class="c1"># second sample</span>
<span class="gp">... </span> <span class="p">[</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">,</span> <span class="mf">3.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">]])</span> <span class="c1"># third sample</span>
<span class="gp">>>> </span><span class="n">ytr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span> <span class="c1"># classes</span>
<span class="gp">>>> </span><span class="n">mysvm</span> <span class="o">=</span> <span class="n">mlpy</span><span class="o">.</span><span class="n">Svm</span><span class="p">()</span> <span class="c1"># initialize Svm class</span>
<span class="gp">>>> </span><span class="n">mysvm</span><span class="o">.</span><span class="n">compute</span><span class="p">(</span><span class="n">xtr</span><span class="p">,</span> <span class="n">ytr</span><span class="p">)</span> <span class="c1"># compute SVM</span>
<span class="go">1</span>
<span class="gp">>>> </span><span class="n">mysvm</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">xtr</span><span class="p">)</span> <span class="c1"># predict SVM model on training data</span>
<span class="go">array([ 1, -1, 1])</span>
<span class="gp">>>> </span><span class="n">xts</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">4.0</span><span class="p">,</span> <span class="mf">5.0</span><span class="p">,</span> <span class="mf">6.0</span><span class="p">,</span> <span class="mf">7.0</span><span class="p">])</span> <span class="c1"># test point</span>
<span class="gp">>>> </span><span class="n">mysvm</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">xts</span><span class="p">)</span> <span class="c1"># predict SVM model on test point</span>
<span class="go">-1</span>
<span class="gp">>>> </span><span class="n">mysvm</span><span class="o">.</span><span class="n">realpred</span> <span class="c1"># real-valued prediction</span>
<span class="go">-5.5</span>
<span class="gp">>>> </span><span class="n">mysvm</span><span class="o">.</span><span class="n">weights</span><span class="p">(</span><span class="n">xtr</span><span class="p">,</span> <span class="n">ytr</span><span class="p">)</span> <span class="c1"># compute weights on training data</span>
<span class="go">array([ 0., 0., 0., 1.])</span>
</pre></div>
</div>
<p>Initialize the Svm class</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"><dl class="first last docutils">
<dt>kernel <span class="classifier-delimiter">:</span> <span class="classifier">string [‘linear’, ‘gaussian’, ‘polynomial’, ‘tr’, ‘tversky’]</span></dt>
<dd><p class="first last">kernel</p>
</dd>
<dt>kp <span class="classifier-delimiter">:</span> <span class="classifier">float</span></dt>
<dd><p class="first last">kernel parameter (two sigma squared) for gaussian and polynomial kernel</p>
</dd>
<dt>C <span class="classifier-delimiter">:</span> <span class="classifier">float</span></dt>
<dd><p class="first last">regularization parameter</p>
</dd>
<dt>tol <span class="classifier-delimiter">:</span> <span class="classifier">float</span></dt>
<dd><p class="first last">tolerance for testing KKT conditions</p>
</dd>
<dt>eps <span class="classifier-delimiter">:</span> <span class="classifier">float</span></dt>
<dd><p class="first last">convergence parameter</p>
</dd>
<dt>maxloops <span class="classifier-delimiter">:</span> <span class="classifier">integer</span></dt>
<dd><p class="first last">maximum number of optimization loops</p>
</dd>
<dt>cost <span class="classifier-delimiter">:</span> <span class="classifier">float [-1.0, ..., 1.0]</span></dt>
<dd><p class="first last">for cost-sensitive classification</p>
</dd>
<dt>alpha_tversky <span class="classifier-delimiter">:</span> <span class="classifier">float</span></dt>
<dd><p class="first last">positive multiplicative parameter for the norm of the first vector</p>
</dd>
<dt>beta_tversky <span class="classifier-delimiter">:</span> <span class="classifier">float</span></dt>
<dd><p class="first last">positive multiplicative parameter for the norm of the second vector</p>
</dd>
<dt>opt_offset <span class="classifier-delimiter">:</span> <span class="classifier">bool</span></dt>
<dd><p class="first last">compute the optimal offset</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="mlpy.Svm.compute">
<code class="descname">compute</code><span class="sig-paren">(</span><em>x</em>, <em>y</em><span class="sig-paren">)</span><a class="headerlink" href="#mlpy.Svm.compute" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute SVM model</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"><dl class="first docutils">
<dt>x <span class="classifier-delimiter">:</span> <span class="classifier">2d ndarray float (samples x feats)</span></dt>
<dd><p class="first last">training data</p>
</dd>
<dt>y <span class="classifier-delimiter">:</span> <span class="classifier">1d ndarray integer (-1 or 1)</span></dt>
<dd><p class="first last">classes</p>
</dd>
</dl>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><dl class="first last docutils">
<dt>conv <span class="classifier-delimiter">:</span> <span class="classifier">integer</span></dt>
<dd><p class="first last">svm convergence (0: false, 1: true)</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mlpy.Svm.predict">
<code class="descname">predict</code><span class="sig-paren">(</span><em>p</em><span class="sig-paren">)</span><a class="headerlink" href="#mlpy.Svm.predict" title="Permalink to this definition">¶</a></dt>
<dd><p>Predict svm model on a test point(s)</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"><dl class="first docutils">
<dt>p <span class="classifier-delimiter">:</span> <span class="classifier">1d or 2d ndarray float (samples x feats)</span></dt>
<dd><p class="first last">test point(s)training dataInput</p>
</dd>
</dl>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><dl class="first docutils">
<dt>cl <span class="classifier-delimiter">:</span> <span class="classifier">integer or 1d ndarray integer</span></dt>
<dd><p class="first last">class(es) predicted</p>
</dd>
</dl>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Attributes:</th><td class="field-body"><dl class="first last docutils">
<dt>Svm.realpred <span class="classifier-delimiter">:</span> <span class="classifier">float or 1d ndarray float</span></dt>
<dd><p class="first last">real valued prediction</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mlpy.Svm.weights">
<code class="descname">weights</code><span class="sig-paren">(</span><em>x</em>, <em>y</em><span class="sig-paren">)</span><a class="headerlink" href="#mlpy.Svm.weights" title="Permalink to this definition">¶</a></dt>
<dd><p>Return feature weights</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"><dl class="first docutils">
<dt>x <span class="classifier-delimiter">:</span> <span class="classifier">2d ndarray float (samples x feats)</span></dt>
<dd><p class="first last">training data</p>
</dd>
<dt>y <span class="classifier-delimiter">:</span> <span class="classifier">1d ndarray integer (-1 or 1)</span></dt>
<dd><p class="first last">classes</p>
</dd>
</dl>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><dl class="first last docutils">
<dt>fw <span class="classifier-delimiter">:</span> <span class="classifier">1d ndarray float</span></dt>
<dd><p class="first last">feature weights</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">For <em>tr</em> kernel (Terminated Ramp Kernel) see <a class="reference internal" href="#merler06" id="id1">[Merler06]</a>.</p>
</div>
</div>
<div class="section" id="k-nearest-neighbor-knn">
<h2>K Nearest Neighbor (KNN)<a class="headerlink" href="#k-nearest-neighbor-knn" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="mlpy.Knn">
<em class="property">class </em><code class="descclassname">mlpy.</code><code class="descname">Knn</code><span class="sig-paren">(</span><em>k</em>, <em>dist='se'</em><span class="sig-paren">)</span><a class="headerlink" href="#mlpy.Knn" title="Permalink to this definition">¶</a></dt>
<dd><p>k-Nearest Neighbor (KNN).</p>
<p>Example:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">mlpy</span>
<span class="gp">>>> </span><span class="n">xtr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">,</span> <span class="mf">3.1</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">],</span> <span class="c1"># first sample</span>
<span class="gp">... </span> <span class="p">[</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">,</span> <span class="mf">3.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">],</span> <span class="c1"># second sample</span>
<span class="gp">... </span> <span class="p">[</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">,</span> <span class="mf">3.1</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">]])</span> <span class="c1"># third sample</span>
<span class="gp">>>> </span><span class="n">ytr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span> <span class="c1"># classes</span>
<span class="gp">>>> </span><span class="n">myknn</span> <span class="o">=</span> <span class="n">mlpy</span><span class="o">.</span><span class="n">Knn</span><span class="p">(</span><span class="n">k</span> <span class="o">=</span> <span class="mi">1</span><span class="p">)</span> <span class="c1"># initialize knn class</span>
<span class="gp">>>> </span><span class="n">myknn</span><span class="o">.</span><span class="n">compute</span><span class="p">(</span><span class="n">xtr</span><span class="p">,</span> <span class="n">ytr</span><span class="p">)</span> <span class="c1"># compute knn</span>
<span class="go">1</span>
<span class="gp">>>> </span><span class="n">myknn</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">xtr</span><span class="p">)</span> <span class="c1"># predict knn model on training data</span>
<span class="go">array([ 1, -1, 1])</span>
<span class="gp">>>> </span><span class="n">xts</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">4.0</span><span class="p">,</span> <span class="mf">5.0</span><span class="p">,</span> <span class="mf">6.0</span><span class="p">,</span> <span class="mf">7.0</span><span class="p">])</span> <span class="c1"># test point</span>
<span class="gp">>>> </span><span class="n">myknn</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">xts</span><span class="p">)</span> <span class="c1"># predict knn model on test point</span>
<span class="go">-1</span>
<span class="gp">>>> </span><span class="n">myknn</span><span class="o">.</span><span class="n">realpred</span> <span class="c1"># real-valued prediction</span>
<span class="go">0.0</span>
</pre></div>
</div>
<p>Initialize the Knn class.</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"><dl class="first last docutils">
<dt>k <span class="classifier-delimiter">:</span> <span class="classifier">int (odd > = 1)</span></dt>
<dd><p class="first last">number of NN</p>
</dd>
<dt>dist <span class="classifier-delimiter">:</span> <span class="classifier">string (‘se’ = SQUARED EUCLIDEAN, ‘e’ = EUCLIDEAN)</span></dt>
<dd><p class="first last">adopted distance</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="mlpy.Knn.compute">
<code class="descname">compute</code><span class="sig-paren">(</span><em>x</em>, <em>y</em><span class="sig-paren">)</span><a class="headerlink" href="#mlpy.Knn.compute" title="Permalink to this definition">¶</a></dt>
<dd><p>Store x and y data.</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"><dl class="first docutils">
<dt>x <span class="classifier-delimiter">:</span> <span class="classifier">2d ndarray float (samples x feats)</span></dt>
<dd><p class="first last">training data</p>
</dd>
<dt>y <span class="classifier-delimiter">:</span> <span class="classifier">1d ndarray integer (-1 or 1 for binary classification)</span></dt>
<dd><p class="first last">: 1d ndarray integer (1, ..., nclasses for multiclass classificatio)
classes</p>
</dd>
</dl>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">1</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Raises:</th><td class="field-body"><dl class="first last docutils">
<dt>ValueError</dt>
<dd><p class="first last">if not (1 <= k <= #samples)</p>
</dd>
<dt>ValueError</dt>
<dd><p class="first last">if there aren’e at least 2 classes</p>
</dd>
<dt>ValueError</dt>
<dd><p class="first last">if, in case of 2-classes problems, the lables are not 1 and -1</p>
</dd>
<dt>ValueError</dt>
<dd><p class="first last">if, in case of n-classes problems, the lables are not int from 1 to n</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mlpy.Knn.predict">
<code class="descname">predict</code><span class="sig-paren">(</span><em>p</em><span class="sig-paren">)</span><a class="headerlink" href="#mlpy.Knn.predict" title="Permalink to this definition">¶</a></dt>
<dd><p>Predict knn model on a test point(s).</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"><dl class="first docutils">
<dt>p <span class="classifier-delimiter">:</span> <span class="classifier">1d or 2d ndarray float (sample(s) x feats)</span></dt>
<dd><p class="first last">test sample(s)</p>
</dd>
</dl>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">the predicted value(s) on success:
integer or 1d numpy array integer (-1 or 1) for binary classification
integer or 1d numpy array integer (1, ..., nclasses) for multiclass classification
0 on succes with non unique classification
-2 otherwise</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Raises:</th><td class="field-body"><dl class="first last docutils">
<dt>StandardError</dt>
<dd><p class="first last">if no Knn method computed</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="fisher-discriminant-analysis-fda">
<h2>Fisher Discriminant Analysis (FDA)<a class="headerlink" href="#fisher-discriminant-analysis-fda" title="Permalink to this headline">¶</a></h2>
<p>Described in <a class="reference internal" href="#mika01" id="id2">[Mika01]</a>.</p>
<dl class="class">
<dt id="mlpy.Fda">
<em class="property">class </em><code class="descclassname">mlpy.</code><code class="descname">Fda</code><span class="sig-paren">(</span><em>C=1</em><span class="sig-paren">)</span><a class="headerlink" href="#mlpy.Fda" title="Permalink to this definition">¶</a></dt>
<dd><p>Fisher Discriminant Analysis.</p>
<p>Example:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">mlpy</span>
<span class="gp">>>> </span><span class="n">xtr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">,</span> <span class="mf">3.1</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">],</span> <span class="c1"># first sample</span>
<span class="gp">... </span> <span class="p">[</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">,</span> <span class="mf">3.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">],</span> <span class="c1"># second sample</span>
<span class="gp">... </span> <span class="p">[</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">,</span> <span class="mf">3.1</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">]])</span> <span class="c1"># third sample</span>
<span class="gp">>>> </span><span class="n">ytr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span> <span class="c1"># classes</span>
<span class="gp">>>> </span><span class="n">myfda</span> <span class="o">=</span> <span class="n">mlpy</span><span class="o">.</span><span class="n">Fda</span><span class="p">()</span> <span class="c1"># initialize fda class</span>
<span class="gp">>>> </span><span class="n">myfda</span><span class="o">.</span><span class="n">compute</span><span class="p">(</span><span class="n">xtr</span><span class="p">,</span> <span class="n">ytr</span><span class="p">)</span> <span class="c1"># compute fda</span>
<span class="go">1</span>
<span class="gp">>>> </span><span class="n">myfda</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">xtr</span><span class="p">)</span> <span class="c1"># predict fda model on training data</span>
<span class="go">array([ 1, -1, 1])</span>
<span class="gp">>>> </span><span class="n">xts</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">4.0</span><span class="p">,</span> <span class="mf">5.0</span><span class="p">,</span> <span class="mf">6.0</span><span class="p">,</span> <span class="mf">7.0</span><span class="p">])</span> <span class="c1"># test point</span>
<span class="gp">>>> </span><span class="n">myfda</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">xts</span><span class="p">)</span> <span class="c1"># predict fda model on test point</span>
<span class="go">-1</span>
<span class="gp">>>> </span><span class="n">myfda</span><span class="o">.</span><span class="n">realpred</span> <span class="c1"># real-valued prediction</span>
<span class="go">-42.51475717037367</span>
<span class="gp">>>> </span><span class="n">myfda</span><span class="o">.</span><span class="n">weights</span><span class="p">(</span><span class="n">xtr</span><span class="p">,</span> <span class="n">ytr</span><span class="p">)</span> <span class="c1"># compute weights on training data</span>
<span class="go">array([ 9.60629896, 9.77148463, 9.82027615, 11.58765243])</span>
</pre></div>
</div>
<p>Initialize Fda class.</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"><dl class="first last docutils">
<dt>C <span class="classifier-delimiter">:</span> <span class="classifier">float</span></dt>
<dd><p class="first last">regularization parameter</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="mlpy.Fda.compute">
<code class="descname">compute</code><span class="sig-paren">(</span><em>x</em>, <em>y</em><span class="sig-paren">)</span><a class="headerlink" href="#mlpy.Fda.compute" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute fda model.</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"><dl class="first docutils">
<dt>x <span class="classifier-delimiter">:</span> <span class="classifier">2d numpy array float (sample x feature)</span></dt>
<dd><p class="first last">training data</p>
</dd>
<dt>y <span class="classifier-delimiter">:</span> <span class="classifier">1d numpy array integer (two classes, 1 or -1)</span></dt>
<dd><p class="first last">classes</p>
</dd>
</dl>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">1</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mlpy.Fda.predict">
<code class="descname">predict</code><span class="sig-paren">(</span><em>p</em><span class="sig-paren">)</span><a class="headerlink" href="#mlpy.Fda.predict" title="Permalink to this definition">¶</a></dt>
<dd><p>Predict fda model on test point(s).</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"><dl class="first docutils">
<dt>p <span class="classifier-delimiter">:</span> <span class="classifier">1d or 2d ndarray float (sample(s) x feats)</span></dt>
<dd><p class="first last">test sample(s)</p>
</dd>
</dl>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><dl class="first docutils">
<dt>cl <span class="classifier-delimiter">:</span> <span class="classifier">integer or 1d numpy array integer</span></dt>
<dd><p class="first last">class(es) predicted</p>
</dd>
</dl>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Attributes:</th><td class="field-body"><dl class="first last docutils">
<dt>self.realpred <span class="classifier-delimiter">:</span> <span class="classifier">float or 1d numpy array float</span></dt>
<dd><p class="first last">real valued prediction</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mlpy.Fda.weights">
<code class="descname">weights</code><span class="sig-paren">(</span><em>x</em>, <em>y</em><span class="sig-paren">)</span><a class="headerlink" href="#mlpy.Fda.weights" title="Permalink to this definition">¶</a></dt>
<dd><p>Return feature weights.</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"><dl class="first docutils">
<dt>x <span class="classifier-delimiter">:</span> <span class="classifier">2d ndarray float (samples x feats)</span></dt>
<dd><p class="first last">training data</p>
</dd>
<dt>y <span class="classifier-delimiter">:</span> <span class="classifier">1d ndarray integer (-1 or 1)</span></dt>
<dd><p class="first last">classes</p>
</dd>
</dl>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><dl class="first last docutils">
<dt>fw <span class="classifier-delimiter">:</span> <span class="classifier">1d ndarray float</span></dt>
<dd><p class="first last">feature weights</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="spectral-regression-discriminant-analysis-srda">
<h2>Spectral Regression Discriminant Analysis (SRDA)<a class="headerlink" href="#spectral-regression-discriminant-analysis-srda" title="Permalink to this headline">¶</a></h2>
<p>Described in <a class="reference internal" href="#cai08" id="id3">[Cai08]</a>.</p>
<dl class="class">
<dt id="mlpy.Srda">
<em class="property">class </em><code class="descclassname">mlpy.</code><code class="descname">Srda</code><span class="sig-paren">(</span><em>alpha=1.0</em><span class="sig-paren">)</span><a class="headerlink" href="#mlpy.Srda" title="Permalink to this definition">¶</a></dt>
<dd><p>Spectral Regression Discriminant Analysis (SRDA).</p>
<p>Example:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">mlpy</span>
<span class="gp">>>> </span><span class="n">xtr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">,</span> <span class="mf">3.1</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">],</span> <span class="c1"># first sample</span>
<span class="gp">... </span> <span class="p">[</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">,</span> <span class="mf">3.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">],</span> <span class="c1"># second sample</span>
<span class="gp">... </span> <span class="p">[</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">,</span> <span class="mf">3.1</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">]])</span> <span class="c1"># third sample</span>
<span class="gp">>>> </span><span class="n">ytr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span> <span class="c1"># classes</span>
<span class="gp">>>> </span><span class="n">mysrda</span> <span class="o">=</span> <span class="n">mlpy</span><span class="o">.</span><span class="n">Srda</span><span class="p">()</span> <span class="c1"># initialize srda class</span>
<span class="gp">>>> </span><span class="n">mysrda</span><span class="o">.</span><span class="n">compute</span><span class="p">(</span><span class="n">xtr</span><span class="p">,</span> <span class="n">ytr</span><span class="p">)</span> <span class="c1"># compute srda</span>
<span class="go">1</span>
<span class="gp">>>> </span><span class="n">mysrda</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">xtr</span><span class="p">)</span> <span class="c1"># predict srda model on training data</span>
<span class="go">array([ 1, -1, 1])</span>
<span class="gp">>>> </span><span class="n">xts</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">4.0</span><span class="p">,</span> <span class="mf">5.0</span><span class="p">,</span> <span class="mf">6.0</span><span class="p">,</span> <span class="mf">7.0</span><span class="p">])</span> <span class="c1"># test point</span>
<span class="gp">>>> </span><span class="n">mysrda</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">xts</span><span class="p">)</span> <span class="c1"># predict srda model on test point</span>
<span class="go">-1</span>
<span class="gp">>>> </span><span class="n">mysrda</span><span class="o">.</span><span class="n">realpred</span> <span class="c1"># real-valued prediction</span>
<span class="go">-6.8283034257748758</span>
<span class="gp">>>> </span><span class="n">mysrda</span><span class="o">.</span><span class="n">weights</span><span class="p">(</span><span class="n">xtr</span><span class="p">,</span> <span class="n">ytr</span><span class="p">)</span> <span class="c1"># compute weights on training data</span>
<span class="go">array([ 0.10766721, 0.21533442, 0.51386623, 1.69331158])</span>
</pre></div>
</div>
<p>Initialize the Srda class.</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"><dl class="first last docutils">
<dt>alpha <span class="classifier-delimiter">:</span> <span class="classifier">float(>=0.0)</span></dt>
<dd><p class="first last">regularization parameter</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="mlpy.Srda.compute">
<code class="descname">compute</code><span class="sig-paren">(</span><em>x</em>, <em>y</em><span class="sig-paren">)</span><a class="headerlink" href="#mlpy.Srda.compute" title="Permalink to this definition">¶</a></dt>
<dd><dl class="docutils">
<dt>Compute Srda model.</dt>
<dd>Initialize array of alphas a.</dd>
</dl>
<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"><dl class="first docutils">
<dt>x <span class="classifier-delimiter">:</span> <span class="classifier">2d ndarray float (samples x feats)</span></dt>
<dd><p class="first last">training data</p>
</dd>
<dt>y <span class="classifier-delimiter">:</span> <span class="classifier">1d ndarray integer (-1 or 1)</span></dt>
<dd><p class="first last">classes</p>
</dd>
</dl>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">1</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Raises:</th><td class="field-body"><dl class="first last docutils">
<dt>LinAlgError</dt>
<dd><p class="first last">if x is singular matrix in __PenRegrModel</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mlpy.Srda.predict">
<code class="descname">predict</code><span class="sig-paren">(</span><em>p</em><span class="sig-paren">)</span><a class="headerlink" href="#mlpy.Srda.predict" title="Permalink to this definition">¶</a></dt>
<dd><p>Predict Srda model on test point(s).</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"><dl class="first docutils">
<dt>p <span class="classifier-delimiter">:</span> <span class="classifier">1d or 2d ndarray float (sample(s) x feats)</span></dt>
<dd><p class="first last">test sample(s)</p>
</dd>
</dl>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><dl class="first docutils">
<dt>cl <span class="classifier-delimiter">:</span> <span class="classifier">integer or 1d numpy array integer</span></dt>
<dd><p class="first last">class(es) predicted</p>
</dd>
</dl>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Attributes:</th><td class="field-body"><dl class="first last docutils">
<dt>self.realpred <span class="classifier-delimiter">:</span> <span class="classifier">float or 1d numpy array float</span></dt>
<dd><p class="first last">real valued prediction</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mlpy.Srda.weights">
<code class="descname">weights</code><span class="sig-paren">(</span><em>x</em>, <em>y</em><span class="sig-paren">)</span><a class="headerlink" href="#mlpy.Srda.weights" title="Permalink to this definition">¶</a></dt>
<dd><p>Return feature weights.</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"><dl class="first docutils">
<dt>x <span class="classifier-delimiter">:</span> <span class="classifier">2d ndarray float (samples x feats)</span></dt>
<dd><p class="first last">training data</p>
</dd>
<dt>y <span class="classifier-delimiter">:</span> <span class="classifier">1d ndarray integer (-1 or 1)</span></dt>
<dd><p class="first last">classes</p>
</dd>
</dl>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><dl class="first last docutils">
<dt>fw <span class="classifier-delimiter">:</span> <span class="classifier">1d ndarray float</span></dt>
<dd><p class="first last">feature weights</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="penalized-discriminant-analysis-pda">
<h2>Penalized Discriminant Analysis (PDA)<a class="headerlink" href="#penalized-discriminant-analysis-pda" title="Permalink to this headline">¶</a></h2>
<p>Described in <a class="reference internal" href="#ghosh03" id="id4">[Ghosh03]</a>.</p>
<dl class="class">
<dt id="mlpy.Pda">
<em class="property">class </em><code class="descclassname">mlpy.</code><code class="descname">Pda</code><span class="sig-paren">(</span><em>Nreg=3</em><span class="sig-paren">)</span><a class="headerlink" href="#mlpy.Pda" title="Permalink to this definition">¶</a></dt>
<dd><p>Penalized Discriminant Analysis (PDA).</p>
<p>Example:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">mlpy</span>
<span class="gp">>>> </span><span class="n">xtr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">,</span> <span class="mf">3.1</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">],</span> <span class="c1"># first sample</span>
<span class="gp">... </span> <span class="p">[</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">,</span> <span class="mf">3.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">],</span> <span class="c1"># second sample</span>
<span class="gp">... </span> <span class="p">[</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">,</span> <span class="mf">3.1</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">]])</span> <span class="c1"># third sample</span>
<span class="gp">>>> </span><span class="n">ytr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span> <span class="c1"># classes</span>
<span class="gp">>>> </span><span class="n">mypda</span> <span class="o">=</span> <span class="n">mlpy</span><span class="o">.</span><span class="n">Pda</span><span class="p">()</span> <span class="c1"># initialize pda class</span>
<span class="gp">>>> </span><span class="n">mypda</span><span class="o">.</span><span class="n">compute</span><span class="p">(</span><span class="n">xtr</span><span class="p">,</span> <span class="n">ytr</span><span class="p">)</span> <span class="c1"># compute pda</span>
<span class="go">1</span>
<span class="gp">>>> </span><span class="n">mypda</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">xtr</span><span class="p">)</span> <span class="c1"># predict pda model on training data</span>
<span class="go">array([ 1, -1, 1])</span>
<span class="gp">>>> </span><span class="n">xts</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">4.0</span><span class="p">,</span> <span class="mf">5.0</span><span class="p">,</span> <span class="mf">6.0</span><span class="p">,</span> <span class="mf">7.0</span><span class="p">])</span> <span class="c1"># test point</span>
<span class="gp">>>> </span><span class="n">mypda</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">xts</span><span class="p">)</span> <span class="c1"># predict pda model on test point</span>
<span class="go">-1</span>
<span class="gp">>>> </span><span class="n">mypda</span><span class="o">.</span><span class="n">realpred</span> <span class="c1"># real-valued prediction</span>
<span class="go">-7.6106885609535624</span>
<span class="gp">>>> </span><span class="n">mypda</span><span class="o">.</span><span class="n">weights</span><span class="p">(</span><span class="n">xtr</span><span class="p">,</span> <span class="n">ytr</span><span class="p">)</span> <span class="c1"># compute weights on training data</span>
<span class="go">array([ 4.0468174 , 8.0936348 , 18.79228266, 58.42466988])</span>
</pre></div>
</div>
<p>Initialize Pda class.</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"><dl class="first last docutils">
<dt>Nreg <span class="classifier-delimiter">:</span> <span class="classifier">int</span></dt>
<dd><p class="first last">number of regressions</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="mlpy.Pda.compute">
<code class="descname">compute</code><span class="sig-paren">(</span><em>x</em>, <em>y</em><span class="sig-paren">)</span><a class="headerlink" href="#mlpy.Pda.compute" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute Pda model.</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"><dl class="first docutils">
<dt>x <span class="classifier-delimiter">:</span> <span class="classifier">2d ndarray float (samples x feats)</span></dt>
<dd><p class="first last">training data</p>
</dd>
<dt>y <span class="classifier-delimiter">:</span> <span class="classifier">1d ndarray integer (-1 or 1)</span></dt>
<dd><p class="first last">classes</p>
</dd>
</dl>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">1</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Raises:</th><td class="field-body"><dl class="first last docutils">
<dt>LinAlgError</dt>
<dd><p class="first last">if x is singular matrix in __PenRegrModel</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mlpy.Pda.predict">
<code class="descname">predict</code><span class="sig-paren">(</span><em>p</em><span class="sig-paren">)</span><a class="headerlink" href="#mlpy.Pda.predict" title="Permalink to this definition">¶</a></dt>
<dd><p>Predict Pda model on test point(s).</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"><dl class="first docutils">
<dt>p <span class="classifier-delimiter">:</span> <span class="classifier">1d or 2d ndarray float (sample(s) x feats)</span></dt>
<dd><p class="first last">test sample(s)</p>
</dd>
</dl>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><dl class="first docutils">
<dt>cl <span class="classifier-delimiter">:</span> <span class="classifier">integer or 1d numpy array integer</span></dt>
<dd><p class="first last">class(es) predicted</p>
</dd>
</dl>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Attributes:</th><td class="field-body"><dl class="first last docutils">
<dt>self.realpred <span class="classifier-delimiter">:</span> <span class="classifier">float or 1d numpy array float</span></dt>
<dd><p class="first last">real valued prediction</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mlpy.Pda.weights">
<code class="descname">weights</code><span class="sig-paren">(</span><em>x</em>, <em>y</em><span class="sig-paren">)</span><a class="headerlink" href="#mlpy.Pda.weights" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute feature weights.</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"><dl class="first docutils">
<dt>x <span class="classifier-delimiter">:</span> <span class="classifier">2d ndarray float (samples x feats)</span></dt>
<dd><p class="first last">training data</p>
</dd>
<dt>y <span class="classifier-delimiter">:</span> <span class="classifier">1d ndarray integer (-1 or 1)</span></dt>
<dd><p class="first last">classes</p>
</dd>
</dl>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><dl class="first last docutils">
<dt>fw <span class="classifier-delimiter">:</span> <span class="classifier">1d ndarray float</span></dt>
<dd><p class="first last">feature weights</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="diagonal-linear-discriminant-analysis-dlda">
<h2>Diagonal Linear Discriminant Analysis (DLDA)<a class="headerlink" href="#diagonal-linear-discriminant-analysis-dlda" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="mlpy.Dlda">
<em class="property">class </em><code class="descclassname">mlpy.</code><code class="descname">Dlda</code><span class="sig-paren">(</span><em>nf=0</em>, <em>tol=10</em>, <em>overview=False</em>, <em>bal=False</em><span class="sig-paren">)</span><a class="headerlink" href="#mlpy.Dlda" title="Permalink to this definition">¶</a></dt>
<dd><p>Diagonal Linear Discriminant Analysis.</p>
<p>Example:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">numpy</span> <span class="k">import</span> <span class="o">*</span>
<span class="gp">>>> </span><span class="kn">from</span> <span class="nn">mlpy</span> <span class="k">import</span> <span class="o">*</span>
<span class="gp">>>> </span><span class="n">xtr</span> <span class="o">=</span> <span class="n">array</span><span class="p">([[</span><span class="mf">1.1</span><span class="p">,</span> <span class="mf">2.4</span><span class="p">,</span> <span class="mf">3.1</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">],</span> <span class="c1"># first sample</span>
<span class="gp">... </span> <span class="p">[</span><span class="mf">1.2</span><span class="p">,</span> <span class="mf">2.3</span><span class="p">,</span> <span class="mf">3.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">],</span> <span class="c1"># second sample</span>
<span class="gp">... </span> <span class="p">[</span><span class="mf">1.3</span><span class="p">,</span> <span class="mf">2.2</span><span class="p">,</span> <span class="mf">3.5</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">],</span> <span class="c1"># third sample</span>
<span class="gp">... </span> <span class="p">[</span><span class="mf">1.4</span><span class="p">,</span> <span class="mf">2.1</span><span class="p">,</span> <span class="mf">3.2</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">]])</span> <span class="c1"># fourth sample</span>
<span class="gp">>>> </span><span class="n">ytr</span> <span class="o">=</span> <span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">])</span> <span class="c1"># classes</span>
<span class="gp">>>> </span><span class="n">mydlda</span> <span class="o">=</span> <span class="n">Dlda</span><span class="p">(</span><span class="n">nf</span> <span class="o">=</span> <span class="mi">2</span><span class="p">)</span> <span class="c1"># initialize dlda class</span>
<span class="gp">>>> </span><span class="n">mydlda</span><span class="o">.</span><span class="n">compute</span><span class="p">(</span><span class="n">xtr</span><span class="p">,</span> <span class="n">ytr</span><span class="p">)</span> <span class="c1"># compute dlda</span>
<span class="go">1</span>
<span class="gp">>>> </span><span class="n">mydlda</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">xtr</span><span class="p">)</span> <span class="c1"># predict dlda model on training data</span>
<span class="go">array([ 1, -1, 1, -1])</span>
<span class="gp">>>> </span><span class="n">xts</span> <span class="o">=</span> <span class="n">array</span><span class="p">([</span><span class="mf">4.0</span><span class="p">,</span> <span class="mf">5.0</span><span class="p">,</span> <span class="mf">6.0</span><span class="p">,</span> <span class="mf">7.0</span><span class="p">])</span> <span class="c1"># test point</span>
<span class="gp">>>> </span><span class="n">mydlda</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">xts</span><span class="p">)</span> <span class="c1"># predict dlda model on test point</span>
<span class="go">-1</span>
<span class="gp">>>> </span><span class="n">mydlda</span><span class="o">.</span><span class="n">realpred</span> <span class="c1"># real-valued prediction</span>
<span class="go">-21.999999999999954</span>
<span class="gp">>>> </span><span class="n">mydlda</span><span class="o">.</span><span class="n">weights</span><span class="p">(</span><span class="n">xtr</span><span class="p">,</span> <span class="n">ytr</span><span class="p">)</span> <span class="c1"># compute weights on training data</span>
<span class="go">array([ 2.13162821e-14, 0.00000000e+00, 0.00000000e+00, 4.00000000e+00])</span>
</pre></div>
</div>
<p>Initialize Dlda class.</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"><dl class="first last docutils">
<dt>nf <span class="classifier-delimiter">:</span> <span class="classifier">int (1 <= nf >= #features)</span></dt>
<dd><p class="first last">the number of the best features that you want to use in
the model. If nf = 0 the system stops at a number of features
corresponding to a peak of accuracy</p>
</dd>
<dt>tol <span class="classifier-delimiter">:</span> <span class="classifier">int</span></dt>
<dd><p class="first last">in case of nf = 0 it’s the number of steps
of classification to be calculated after the peak to avoid a
local maximum</p>
</dd>
<dt>overview <span class="classifier-delimiter">:</span> <span class="classifier">bool</span></dt>
<dd><p class="first last">set True to print informations about the
accuracy of the classifier at every step of the compute</p>
</dd>
<dt>bal <span class="classifier-delimiter">:</span> <span class="classifier">bool</span></dt>
<dd><p class="first last">set True if it’s reasonable to consider the
unbalancement of the test set similar to the one of the
training set</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="mlpy.Dlda.compute">
<code class="descname">compute</code><span class="sig-paren">(</span><em>x</em>, <em>y</em>, <em>mf=0</em><span class="sig-paren">)</span><a class="headerlink" href="#mlpy.Dlda.compute" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute Dlda model.</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"><dl class="first docutils">
<dt>x <span class="classifier-delimiter">:</span> <span class="classifier">2d ndarray float (samples x feats)</span></dt>
<dd><p class="first last">training data</p>
</dd>
<dt>y <span class="classifier-delimiter">:</span> <span class="classifier">1d ndarray integer (-1 or 1)</span></dt>
<dd><p class="first last">classes</p>
</dd>
<dt>mf <span class="classifier-delimiter">:</span> <span class="classifier">int</span></dt>
<dd><p class="first last">number of classification steps to be calculated
more on a model already computed</p>
</dd>
</dl>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">1</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Raises:</th><td class="field-body"><dl class="first last docutils">
<dt>LinAlgError</dt>
<dd><p class="first last">if x is singular matrix</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mlpy.Dlda.predict">
<code class="descname">predict</code><span class="sig-paren">(</span><em>p</em><span class="sig-paren">)</span><a class="headerlink" href="#mlpy.Dlda.predict" title="Permalink to this definition">¶</a></dt>
<dd><p>Predict Dlda model on test point(s).</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"><dl class="first docutils">
<dt>p <span class="classifier-delimiter">:</span> <span class="classifier">1d or 2d ndarray float (sample(s) x feats)</span></dt>
<dd><p class="first last">test sample(s)</p>
</dd>
</dl>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><dl class="first docutils">
<dt>cl <span class="classifier-delimiter">:</span> <span class="classifier">integer or 1d numpy array integer</span></dt>
<dd><p class="first last">class(es) predicted</p>
</dd>
</dl>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Attributes:</th><td class="field-body"><dl class="first last docutils">
<dt>self.realpred <span class="classifier-delimiter">:</span> <span class="classifier">float or 1d numpy array float</span></dt>
<dd><p class="first last">real valued prediction</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="mlpy.Dlda.weights">
<code class="descname">weights</code><span class="sig-paren">(</span><em>x</em>, <em>y</em><span class="sig-paren">)</span><a class="headerlink" href="#mlpy.Dlda.weights" title="Permalink to this definition">¶</a></dt>
<dd><p>Return feature weights.</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"><dl class="first docutils">
<dt>x <span class="classifier-delimiter">:</span> <span class="classifier">2d ndarray float (samples x feats)</span></dt>
<dd><p class="first last">training data</p>
</dd>
<dt>y <span class="classifier-delimiter">:</span> <span class="classifier">1d ndarray integer (-1 or 1)</span></dt>
<dd><p class="first last">classes</p>
</dd>
</dl>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><dl class="first last docutils">
<dt>fw <span class="classifier-delimiter">:</span> <span class="classifier">1d ndarray float</span></dt>
<dd><p class="first last">feature weights, they are going to be
> 0 for the features chosen for the classification and = 0 for
all the others</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<table class="docutils citation" frame="void" id="vapnik95" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label">[Vapnik95]</td><td>V Vapnik. The Nature of Statistical Learning Theory. Springer-Verlag, 1995.</td></tr>
</tbody>
</table>
<table class="docutils citation" frame="void" id="cristianini" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label">[Cristianini]</td><td>N Cristianini and J Shawe-Taylor. An introduction to support vector machines. Cambridge University Press.</td></tr>
</tbody>
</table>
<table class="docutils citation" frame="void" id="merler06" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id1">[Merler06]</a></td><td>S Merler and G Jurman. Terminated Ramp - Support Vector Machine: a nonparametric data dependent kernel. Neural Network, 19:1597-1611, 2006.</td></tr>
</tbody>
</table>
<table class="docutils citation" frame="void" id="nasr09" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label">[Nasr09]</td><td><ol class="first last upperalpha simple" start="18">
<li>Nasr, S. Swamidass, and P. Baldi. Large scale study of multiplemolecule queries. Journal of Cheminformatics, vol. 1, no. 1, p. 7, 2009.</li>
</ol>
</td></tr>
</tbody>
</table>
<table class="docutils citation" frame="void" id="mika01" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id2">[Mika01]</a></td><td>S Mika and A Smola and B Scholkopf. An improved training algorithm for kernel fisher discriminants. Proceedings AISTATS 2001, 2001.</td></tr>
</tbody>
</table>
<table class="docutils citation" frame="void" id="cristianini02" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label">[Cristianini02]</td><td>N Cristianini, J Shawe-Taylor and A Elisseeff. On Kernel-Target Alignment. Advances in Neural Information Processing Systems, Volume 14, 2002.</td></tr>
</tbody>
</table>
<table class="docutils citation" frame="void" id="cai08" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id3">[Cai08]</a></td><td>D Cai, X He, J Han. SRDA: An Efficient Algorithm for Large-Scale Discriminant Analysis. Knowledge and Data Engineering, IEEE Transactions on Volume 20, Issue 1, Jan. 2008 Page(s):1 - 12.</td></tr>
</tbody>
</table>
<table class="docutils citation" frame="void" id="ghosh03" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id4">[Ghosh03]</a></td><td>D Ghosh. Penalized discriminant methods for the classification of tumors from gene expression data. Biometrics on Volume 59, Dec. 2003 Page(s):992 - 1000(9).</td></tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="index.html">
<img class="logo" src="_static/mlpy_logo.png" alt="Logo"/>
</a></p>
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Supervised Classification</a><ul>
<li><a class="reference internal" href="#support-vector-machines-svms">Support Vector Machines (SVMs)</a></li>
<li><a class="reference internal" href="#k-nearest-neighbor-knn">K Nearest Neighbor (KNN)</a></li>
<li><a class="reference internal" href="#fisher-discriminant-analysis-fda">Fisher Discriminant Analysis (FDA)</a></li>
<li><a class="reference internal" href="#spectral-regression-discriminant-analysis-srda">Spectral Regression Discriminant Analysis (SRDA)</a></li>
<li><a class="reference internal" href="#penalized-discriminant-analysis-pda">Penalized Discriminant Analysis (PDA)</a></li>
<li><a class="reference internal" href="#diagonal-linear-discriminant-analysis-dlda">Diagonal Linear Discriminant Analysis (DLDA)</a></li>
</ul>
</li>
</ul>
<div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="index.html">Documentation overview</a><ul>
<li>Previous: <a href="kernel.html" title="previous chapter">Kernels</a></li>
<li>Next: <a href="regression.html" title="next chapter">Regression</a></li>
</ul></li>
</ul>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/classification.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
©2017, mlpy Developers.
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 1.5.6</a>
& <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.8</a>
|
<a href="_sources/classification.txt"
rel="nofollow">Page source</a>
</div>
</body>
</html>
|