commit c24978693bf8a974726e565ca150f1fa87477f89 Author: Arkadiusz Kondas Date: Thu Jul 7 00:53:38 2016 +0200 language detection example diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..73854f2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/vendor/ +humbuglog.* +/bin/phpunit diff --git a/README.md b/README.md new file mode 100644 index 0000000..744918e --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# PHP-ML - Machine Learning library for PHP - Examples + +Examples of the use of PHP-ML library + +## Examples + +* LanguageDetection.php - classifier build for language detection + +## License + +PHP-ML is released under the MIT Licence. See the bundled LICENSE file for details. + +## Author + +Arkadiusz Kondas (@ArkadiuszKondas) diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..a636e32 --- /dev/null +++ b/composer.json @@ -0,0 +1,17 @@ +{ + "name": "php-ai/php-ml-examples", + "type": "project", + "description": "Examples of the use of PHP-ML library", + "license": "MIT", + "keywords": ["machine learning","pattern recognition","computational learning theory","artificial intelligence"], + "homepage": "https://github.com/php-ai/php-ml-examples", + "authors": [ + { + "name": "Arkadiusz Kondas", + "email": "arkadiusz.kondas@gmail.com" + } + ], + "require": { + "php-ai/php-ml": "dev-develop" + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..aa9c1f8 --- /dev/null +++ b/composer.lock @@ -0,0 +1,67 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "1342a147b788083a903bdd811cf8b1a8", + "content-hash": "073a4d8adce8080a2e60222db7a59192", + "packages": [ + { + "name": "php-ai/php-ml", + "version": "dev-develop", + "source": { + "type": "git", + "url": "https://github.com/php-ai/php-ml.git", + "reference": "6c7416a9c40b596afce625617dce07892ccaa2fc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-ai/php-ml/zipball/6c7416a9c40b596afce625617dce07892ccaa2fc", + "reference": "6c7416a9c40b596afce625617dce07892ccaa2fc", + "shasum": "" + }, + "require": { + "php": ">=7.0.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.2" + }, + "type": "library", + "autoload": { + "psr-0": { + "Phpml": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Arkadiusz Kondas", + "email": "arkadiusz.kondas@gmail.com" + } + ], + "description": "PHP-ML - Machine Learning library for PHP", + "homepage": "https://github.com/php-ai/php-ml", + "keywords": [ + "artificial intelligence", + "computational learning theory", + "machine learning", + "pattern recognition" + ], + "time": "2016-07-06 22:29:58" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": { + "php-ai/php-ml": 20 + }, + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/data/languages.csv b/data/languages.csv new file mode 100644 index 0000000..7c14b70 --- /dev/null +++ b/data/languages.csv @@ -0,0 +1,61 @@ +"sentence","language" +"Hello, do you know what time the movie is tonight?","english" +"I am calling to make reservations","english" +"I would like to know if it is at all possible to check in","english" +"What time does the swimming pool open?","english" +"Where is the games room?","english" +"We must call the police.","english" +"How many pupils are there in your school?","english" +"Twenty litres of unleaded, please.","english" +"Is it near here?","english" +"Do I have to change?","english" +"Which counter do I go to to change money?","english" +"I would like two postcards, please.","english" +"There was a big explosion.","english" +"Where is the television room?","english" +"Where's the nearest railway station?","english" +"The storms caused flooding.","english" +"Where is the duty free shop?","english" +"I witnessed it happening.","english" +"I would like two postcards, please.","english" +"How about going to the cinema?","english" +"Où est la boulangerie?","french" +"Je voudrais une boîte de chocolates.","french" +"Y a-t-il un autre hôtel près d'ici?","french" +"Vérifiez la batterie, s'il vous plaît.","french" +"La banque ouvre à quelle heure?","french" +"Est-ce que je peux l'écouter?","french" +"Vous devez faire une déclaration de perte.","french" +"Combien des élèves y a-t-il dans votre collège?","french" +"Est-ce qu-il ya un car qui va à l'aéroport?","french" +"Nous voudrions rester jusqu'à Dimanche prochain.","french" +"Je ne comprends pas.","french" +"Voici une ordonnance pour des comprimés.","french" +"Je n'ai qu'un billet de cinquante francs.","french" +"À quelle heure commence le dernière séance?","french" +"Faut-il changer?","french" +"Il n'avait pas la priorité.","french" +"Puis-je prendre les places à l'avance?","french" +"Elle a trente et un ans.","french" +"Pour aller à la pharmacie, s'il vous plaît?","french" +"Voulez-vous me peser ce colis, s'il vous plaît.","french" +"Ciao, ti va di andare al cinema?","italian" +"Mi sai dire quando aprono il negozio?","italian" +"Quando c'è l'ultimo autobus?","italian" +"Lo posso provare addosso?","italian" +"C'è una presa elettrica per il nostro caravan?","italian" +"Vorrei una scatola di cioccolatini.","italian" +"Non e' stata colpa mia.","italian" +"Sono molto scarso in fisica.","italian" +"Vorrei del vino bianco.","italian" +"Me lo puo' spiegare, per piacere.","italian" +"Vorrei chiamare a spese del ricevente.","italian" +"Ho perso il mio passaporto.","italian" +"Posso avere i biglietti del cinema per favore?","italian" +"Vorrei un pacchetto di biscotti.","italian" +"Quali materie studi (studia)?","italian" +"Quanto frequenti sono gli autobus?","italian" +"A che ora sara' la prossima raccolta?","italian" +"Vorrei prenotare un posto.","italian" +"Per favore, quanto costa spedire una lettera in Germania?","italian" +"Mio padre e' un programmatore.","italian" \ No newline at end of file diff --git a/examples/LanguageDetection.php b/examples/LanguageDetection.php new file mode 100644 index 0000000..630a361 --- /dev/null +++ b/examples/LanguageDetection.php @@ -0,0 +1,32 @@ +getSamples() as $sample) { + $samples[] = $sample[0]; +} + +$vectorizer->transform($samples); +$dataset = new ArrayDataset($samples, $dataset->getTargets()); + +$randomSplit = new RandomSplit($dataset, 0.25); + +$classifier = new SVC(Kernel::RBF, 100); +$classifier->train($randomSplit->getTrainSamples(), $randomSplit->getTrainLabels()); + +$predictedLabels = $classifier->predict($randomSplit->getTestSamples()); + +echo Accuracy::score($randomSplit->getTestLabels(), $predictedLabels);