Giter Site home page Giter Site logo

phpml's Introduction

phpml

基于PHP-ML库实现机器学习

基于语言学习

基于语言学习,根据语言编码实现学习

实例

require_once 'vendor/autoload.php';
use Phpml\Classification\KNearestNeighbors; 
use Phpml\Dataset\CsvDataset;
use Phpml\Dataset\ArrayDataset;
use Phpml\FeatureExtraction\TokenCountVectorizer;
use Phpml\Tokenization\WordTokenizer;
use Phpml\CrossValidation\StratifiedRandomSplit;
use Phpml\FeatureExtraction\TfIdfTransformer;
use Phpml\Metric\Accuracy;
use Phpml\Classification\SVC;
use Phpml\Regression\SVR;
use Phpml\SupportVectorMachine\Kernel;

$dataset = new CsvDataset('languages.csv', 1);
$vectorizer = new TokenCountVectorizer(new WordTokenizer());
$tfIdfTransformer = new TfIdfTransformer();

$testample=['我是**人'];


$samples = [];
foreach ($dataset->getSamples() as $sample) {
   $samples[] = $sample[0];
}


$vectorizer->fit($samples);
$vectorizer->transform($samples);

$vectorizer->fit($testample);
$vectorizer->transform($testample);

$tfIdfTransformer->fit($samples);
$tfIdfTransformer->transform($samples);



$dataset = new ArrayDataset($samples, $dataset->getTargets());

$randomSplit = new StratifiedRandomSplit($dataset, 0.1);


$classifier = new SVC(Kernel::RBF, 10000);
$classifier->train($randomSplit->getTrainSamples(), $randomSplit->getTrainLabels());
$testpredictedLabels = $classifier->predict($testample);

print_r($testpredictedLabels);// return  Array ( [0] => zh )
exit;

项目地址

github:https://github.com/qieangel2013/phpml
  码云:https://gitee.com/qieangel2013/phpml

phpml's People

Contributors

qieangel2013 avatar

Watchers

ZQF avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.