refactor dir structura and add wine example
This commit is contained in:
1 parent
f1f284ec2c
commit
b9b64da20f
4 files changed
+49
-2
No files matched your search
@@ -4,7 +4,19 @@ Examples of the use of PHP-ML library
|
||||
|
||||
## Examples
|
||||
|
||||
* LanguageDetection.php - classifier build for language detection
|
||||
To test example, select one of the following and run it from main folder (each category has its own folder).
|
||||
|
||||
```
|
||||
php classification/languageDetection.php
|
||||
```
|
||||
|
||||
Classification:
|
||||
|
||||
* `languageDetection.php` - classifier build for language detection
|
||||
|
||||
Regression:
|
||||
|
||||
* `wineQuality.php` - regression model to assess the quality of the wine
|
||||
|
||||
## License
|
||||
|
||||
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
echo "Fixing src/ folder"
|
||||
php-cs-fixer fix src/ --level=symfony
|
||||
|
||||
echo "Fixing tests/ folder"
|
||||
php-cs-fixer fix tests/ --level=symfony
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace PhpmlExamples;
|
||||
|
||||
include 'vendor/autoload.php';
|
||||
|
||||
use Phpml\Dataset\CsvDataset;
|
||||
@@ -36,4 +38,4 @@ $classifier->train($randomSplit->getTrainSamples(), $randomSplit->getTrainLabels
|
||||
|
||||
$predictedLabels = $classifier->predict($randomSplit->getTestSamples());
|
||||
|
||||
echo Accuracy::score($randomSplit->getTestLabels(), $predictedLabels);
|
||||
echo 'Accuracy: ' . Accuracy::score($randomSplit->getTestLabels(), $predictedLabels);
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace PhpmlExamples;
|
||||
|
||||
include 'vendor/autoload.php';
|
||||
|
||||
use Phpml\CrossValidation\StratifiedRandomSplit;
|
||||
use Phpml\Dataset\Demo\Wine;
|
||||
use Phpml\Metric\Accuracy;
|
||||
use Phpml\Regression\SVR;
|
||||
use Phpml\SupportVectorMachine\Kernel;
|
||||
|
||||
$dataset = new Wine();
|
||||
$split = new StratifiedRandomSplit($dataset);
|
||||
|
||||
$regression = new SVR(Kernel::RBF, 3, 0.1, 10);
|
||||
$regression->train($split->getTrainSamples(), $split->getTrainLabels());
|
||||
|
||||
$predicted = $regression->predict($split->getTestSamples());
|
||||
|
||||
// predicted target are regression result so to test accuracy we must round them
|
||||
|
||||
foreach ($predicted as &$target) {
|
||||
$target = round($target, 0);
|
||||
}
|
||||
|
||||
echo 'Accuracy: ' . Accuracy::score($split->getTestLabels(), $predicted);
|
||||
Reference in new issue
Block a user