diff --git a/src/Phpml/Exception/PreprocessorException.php b/src/Phpml/Exception/PreprocessorException.php new file mode 100644 index 0000000..15e3975 --- /dev/null +++ b/src/Phpml/Exception/PreprocessorException.php @@ -0,0 +1,17 @@ +fit($samples); + } + } + + /** + * @param array $samples + */ + public function fit(array $samples) { $this->countTokensFrequency($samples); @@ -24,7 +34,13 @@ class TfIdfTransformer implements Transformer foreach ($this->idf as &$value) { $value = log($count / $value, 10); } + } + /** + * @param array $samples + */ + public function transform(array &$samples) + { foreach ($samples as &$sample) { foreach ($sample as $index => &$feature) { $feature = $feature * $this->idf[$index]; diff --git a/src/Phpml/FeatureExtraction/TokenCountVectorizer.php b/src/Phpml/FeatureExtraction/TokenCountVectorizer.php index f823778..c4551bb 100644 --- a/src/Phpml/FeatureExtraction/TokenCountVectorizer.php +++ b/src/Phpml/FeatureExtraction/TokenCountVectorizer.php @@ -46,6 +46,14 @@ class TokenCountVectorizer implements Transformer $this->frequencies = []; } + /** + * @param array $samples + */ + public function fit(array $samples) + { + // TODO: Implement fit() method. + } + /** * @param array $samples */ diff --git a/src/Phpml/Preprocessing/Imputer.php b/src/Phpml/Preprocessing/Imputer.php index 586e3f3..fdbfaf6 100644 --- a/src/Phpml/Preprocessing/Imputer.php +++ b/src/Phpml/Preprocessing/Imputer.php @@ -38,6 +38,14 @@ class Imputer implements Preprocessor $this->axis = $axis; } + /** + * @param array $samples + */ + public function fit(array $samples) + { + // TODO: Implement fit() method. + } + /** * @param array $samples */ diff --git a/src/Phpml/Preprocessing/Normalizer.php b/src/Phpml/Preprocessing/Normalizer.php index 832d044..11a0218 100644 --- a/src/Phpml/Preprocessing/Normalizer.php +++ b/src/Phpml/Preprocessing/Normalizer.php @@ -5,6 +5,7 @@ declare (strict_types = 1); namespace Phpml\Preprocessing; use Phpml\Exception\NormalizerException; +use Phpml\Exception\PreprocessorException; class Normalizer implements Preprocessor { @@ -30,6 +31,16 @@ class Normalizer implements Preprocessor $this->norm = $norm; } + /** + * @param array $samples + * + * @throws PreprocessorException + */ + public function fit(array $samples) + { + throw PreprocessorException::fitNotAllowed(); + } + /** * @param array $samples */ diff --git a/src/Phpml/Transformer.php b/src/Phpml/Transformer.php index 47c2ce3..1accdda 100644 --- a/src/Phpml/Transformer.php +++ b/src/Phpml/Transformer.php @@ -6,6 +6,12 @@ namespace Phpml; interface Transformer { + + /** + * @param array $samples + */ + public function fit(array $samples); + /** * @param array $samples */ diff --git a/tests/Phpml/FeatureExtraction/TfIdfTransformerTest.php b/tests/Phpml/FeatureExtraction/TfIdfTransformerTest.php index ca5db36..eceaeb3 100644 --- a/tests/Phpml/FeatureExtraction/TfIdfTransformerTest.php +++ b/tests/Phpml/FeatureExtraction/TfIdfTransformerTest.php @@ -22,7 +22,7 @@ class TfIdfTransformerTest extends \PHPUnit_Framework_TestCase [0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0.602, 5 => 0.903], ]; - $transformer = new TfIdfTransformer(); + $transformer = new TfIdfTransformer($samples); $transformer->transform($samples); $this->assertEquals($tfIdfSamples, $samples, '', 0.001);