keinos/php7-ml
PHP Machine Learning Library (PHP-ML) on Alpine.
139
Dockerfile of PHP-ML, the Machine Learning library for PHP, on Alpine Linux.
docker pull keinos/php7-ml:latest
Source: https://github.com/KEINOS/Dockerfile_of_PHP7-ML @ GitHub
Image: https://hub.docker.com/r/keinos/php7-ml @ Docker Hub
Base Image: keinos/php7-composer-alpine
User: www-data
Entry Point: not set
Composer: Installed under /usr/bin/composer
Working Directory: /app
(alias of /home/www-data
)
PHP-ML: Installed under /app/vendor/php-ai
via composer
/app/composer.json
:
{
"require": {
"php-ai/php-ml": "^0.8.0"
}
}
Mount the script on /app
and run.
$ docker run --rm -it -v $(pwd)/sample.php:/app/sample.php keinos/php7-ml:latest php /app/sample.php
Sample script:
<?php
/* sample.php */
require_once __DIR__ . '/vendor/autoload.php';
use Phpml\Classification\KNearestNeighbors;
$samples = [[1, 3], [1, 4], [2, 4], [3, 1], [4, 1], [4, 2]];
$labels = ['a', 'a', 'a', 'b', 'b', 'b'];
$classifier = new KNearestNeighbors();
$classifier->train($samples, $labels);
echo $classifier->predict([3, 2]);
// returns 'b'
docker pull keinos/php7-ml