keinos/php8-ml

By keinos

Updated over 5 years ago

PHP-Machine Learning on Alpine + PHP8-ish + JIT enabled.

Image
0

212

Dockerfile of PHP8-ML

Dockerfile of PHP-ML, the Machine Learning library for PHP. (PHP8-ish + JIT on Alpine Linux)

docker pull keinos/php8-ml:latest

For ARMv6l(arm32v6) architecture such as RaspberryPi Zero W use the below image.

docker pull keinos/php8-ml:arm32v6

Basic Image Info

Sample Usage

Mount the script on /app and run.

$ docker run --rm -it -v $(pwd)/sample.php:/app/sample.php keinos/php8-ml:latest /bin/sh
/ $ cd /app
/ $ ls
sample.php
/ $ composer require php-ai/php-ml
...
/ $ php ./sample.php
b
  • 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]), PHP_EOL;
    // expect return: 'b'
    

Build

  1. Clone this repo.

  2. Decide tag name to use as a base image from:

  3. Build image specifing the base image tag.

    The below sample will build with the base image keinos/php8-jit:arm32v6 as myname/php8-ml:local.

    docker build --build-arg NAME_TAG_IMAGE=arm32v6 -t myname/php8-ml:local .
    

Docker Pull Command

docker pull keinos/php8-ml