机器/深度学习PlaidML、phpml、Naive Bayesian Classifier介绍

以下为你介绍的机器学习/深度学习软件都可用在Linux系统上:PlaidML(跨平台高性能深度学习框架)、phpml(基于 PHP-ML 库实现机器学习)、Naive Bayesian Classifier(朴素贝叶斯分类器)。

1、PlaidML(跨平台高性能深度学习框架)

机器/深度学习PlaidML、phpml、Naive Bayesian Classifier介绍

PlaidML 致力于跨平台开发部署的开源高性能深度学习框架。一方面可以让硬件开发者快速集成到框架里,一方面也可以让框架的使用者有接入各种硬件的能力。

使开发者者能够在任何设备上部署高性能神经网络。

允许硬件开发人员快速与高级框架集成。

允许框架开发人员轻松添加对多种硬件的支持。

目前已经验证过的硬件有:

1]、AMD

R9 Nano

RX 480

2]、NVIDIA

K80、GTX 780

GTX 1070

先决条件:

Python(支持v2,建议v3)。

OpenCL 1.2或更高版本。

快速开始:

virtualenv plaidml

source plaidml/bin/activate

pip install plaidml-keras plaidbench

选择您要使用的加速器(许多计算机,尤其是笔记本电脑,有多个):

plaidml-setup

接下来,尝试对MobileNet推理性能进行基准测试:

plaidbench keras mobilenet

或者,尝试培训MobileNet:

plaidbench --batch-size 16 keras --train mobilenet

下载地址:https://github.com/plaidml/plaidml

2、phpml(基于 PHP-ML 库实现机器学习)

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;

下载地址:https://gitee.com/qieangel2013/phpml

3、Naive Bayesian Classifier(朴素贝叶斯分类器)

这是一个非常简单的 Python 库,实现了朴素贝叶斯分类器。

安装命令:

$ sudo pip install naiveBayesClassifier

示例代码:

"""

Suppose you have some texts of news and know their categories.

You want to train a system with this pre-categorized/pre-classified 

texts. So, you have better call this data your training set.

"""

from naiveBayesClassifier import tokenizer

from naiveBayesClassifier.trainer import Trainer

from naiveBayesClassifier.classifier import Classifier

newsTrainer = Trainer(tokenizer.Tokenizer(stop_words = [], signs_to_remove = ["?!#%&"]))

# You need to train the system passing each text one by one to the trainer module.

newsSet =[

{'text': 'not to eat too much is not enough to lose weight', 'category': 'health'},

{'text': 'Russia is trying to invade Ukraine', 'category': 'politics'},

{'text': 'do not neglect exercise', 'category': 'health'},

{'text': 'Syria is the main issue, Obama says', 'category': 'politics'},

{'text': 'eat to lose weight', 'category': 'health'},

{'text': 'you should not eat much', 'category': 'health'}

]

for news in newsSet:

newsTrainer.train(news['text'], news['category'])

# When you have sufficient trained data, you are almost done and can start to use

# a classifier.

newsClassifier = Classifier(newsTrainer.data, tokenizer.Tokenizer(stop_words = [], signs_to_remove = ["?!#%&"]))

# Now you have a classifier which can give a try to classifiy text of news whose

# category is unknown, yet.

unknownInstance = "Even if I eat too much, is not it possible to lose some weight"

classification = newsClassifier.classify(unknownInstance)

# the classification variable holds the possible categories sorted by 

# their probablity value

print classification

下载地址:https://github.com/muatik/naive-bayes-classifier

注明

以上就是机器/深度学习PlaidML、phpml、Naive Bayesian Classifier的介绍内容,这些机器学习/深度学习软件都能使用在Linux操作系统中。

栏目相关文章