Completed
Push — develop ( c05ce8...24fc91 )
by Arkadiusz
02:58
created

SupportVectorMachine::train()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
declare (strict_types = 1);
4
5
namespace Phpml\Classification;
6
7
use Phpml\Classification\Traits\Predictable;
8
use Phpml\Classification\Traits\Trainable;
9
use Phpml\Math\Kernel;
10
11
class SupportVectorMachine implements Classifier
12
{
13
    use Trainable, Predictable;
14
15
    /**
16
     * @var Kernel
17
     */
18
    private $kernel;
19
20
    /**
21
     * @var float
22
     */
23
    private $C;
24
25
    /**
26
     * @var float
27
     */
28
    private $tolerance;
29
30
    /**
31
     * @var int
32
     */
33
    private $upperBound;
34
35
    /**
36
     * @var string
37
     */
38
    private $binPath;
0 ignored issues
show
Unused Code introduced by
The property $binPath is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
39
40
    /**
41
     * @param Kernel $kernel
42
     * @param float  $C
43
     * @param float  $tolerance
44
     * @param int    $upperBound
45
     */
46
    public function __construct(Kernel $kernel = null, float $C = 1.0, float $tolerance = .001, int $upperBound = 100)
47
    {
48
        if (null === $kernel) {
49
            $kernel = new Kernel\RBF($gamma = .001);
50
        }
51
52
        $this->kernel = $kernel;
53
        $this->C = $C;
54
        $this->tolerance = $tolerance;
55
        $this->upperBound = $upperBound;
56
    }
57
58
    /**
59
     * @param array $samples
60
     * @param array $labels
61
     */
62
    public function train(array $samples, array $labels)
63
    {
64
        $this->samples = $samples;
65
        $this->labels = $labels;
66
    }
67
68
    /**
69
     * @param array $sample
70
     *
71
     * @return mixed
72
     */
73
    protected function predictSample(array $sample)
0 ignored issues
show
Unused Code introduced by
The parameter $sample is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
74
    {
75
    }
76
}
77