PHPMachineLearning
1.0.0
phplearn需要php> = 7.0
要安裝phplearn,將phplearn目錄的內容下載到您的Web服務器中,並在所有PHP腳本中創建並將“ phplearn.php”文件包含在您的Web服務器中。
include_once 'phpLearn.php';
實施腎小球算法算法的機器學習分類器。
$classifier = new KNearestNeighbors($k, $verbose);
訓練Nearestneighbors分類器提供火車樣品和標籤作為類型陣列。
例子:
$samples = [[1, 3], [1, 4], [2, 4], [3, 1], [4, 1], [4, 2]];
$targets = ['a', 'a', 'a', 'b', 'b', 'b'];
$classifier = new KNearestNeighbors(3, false);
$classifier->train($samples, $targets);
為了預測標籤,請使用“預測”方法。
$data = $classifier->predict([3, 2]);
// return 'b'
實施SVC算法的機器學習分類器。
$classifier = new SVC($verbose);
訓練Nearestneighbors分類器提供火車樣品和標籤作為類型陣列。
例子:
$samples = [[1, 3], [1, 4], [2, 4], [3, 1], [4, 2], [4, 2]];
$targets = ['a', 'a', 'a', 'b', 'b', 'b'];
$classifier = new SVC(true);
$classifier->train($samples, $targets);
為了預測標籤,請使用“預測”方法。
$data = $classifier->predict([0,1.2]);
// return 'b'
實現線性回歸方法的機器學習分類器。
$classifier = new LeastSquares($verbose);
要訓練最小值的Squares分類器,將火車樣品和標籤作為類型陣列提供。
例子:
$samples = [[60], [61], [62], [63], [65]];
$targets = [3.1, 3.6, 3.8, 4, 4.1];
$classifier = new LeastSquares(true);
$classifier->train($samples, $targets);
為了預測標籤,請使用“預測”方法。
$data = $classifier->predict(64);
// return 4.06
實現多個線性回歸的機器學習分類器。
$classifier = new MultipleLinearRegression($verbose);
要訓練多個線性回歸分類器,將火車樣品和標籤作為類型陣列提供。
例子:
$samples = [[73676, 1996], [77006, 1998], [10565, 2000], [146088, 1995], [15000, 2001], [65940, 2000], [9300, 2000], [93739, 1996], [153260, 1994], [17764, 2002], [57000, 1998], [15000, 2000]];
$targets = [2000, 2750, 15500, 960, 4400, 8800, 7100, 2550, 1025, 5900, 4600, 4400];
$classifier = new MultipleLinearRegression(true);
$classifier->train($samples, $targets);
為了預測標籤,請使用“預測”方法。
$data = $classifier->predict([60000, 1996]);
// return 4094.83
實現麥克數回歸的機器學習分類器。
$classifier = new MultipleLinearRegression($verbose);
訓練二次回歸分類器提供火車樣品和標籤作為類型陣列。
例子:
$samples = [[3], [6], [10], [5], [2]];
$targets = [2,5,7,9,12];
$classifier = new QuadraticRegression(true);
$classifier->train($samples, $targets);
為了預測標籤,請使用“預測”方法。
$data = $classifier->predict(8);
// return 7.39
幫助您輕鬆計算預測數據的準確性。
為了預測分數提供標籤,並將標籤預測為類型陣列。
$accuracy = new Accuracy();
$accuracy->score(['a', 'b', 'a'], ['a', 'a', 'a']);
return 0.666
輔助課程可讓您輕鬆地將培訓數據分解為陣列。
設置與樣品和標籤的關聯陣列。
$iris = new Data();
$data = $iris->iris();
$samples = $data['samples'];
$labels = $data['labels'];
輔助類讓您輕鬆獲得兩個數據點之間的距離。
在兩個分之間獲得歐幾里得的距離
$classifier = new distance();
$classifier->euclidean([5.1, 3.5, 1.4, 0.2], [55, 5, 150, 0.2]);
//return 156.76166623253
輔助課程可讓您輕鬆獲取腳本的運行時。
$timer = new timer();
$timer->start();
$timer->finish();
$timer->runtime();
//return 0.00000000546
Phplearn根據MIT許可發布。
Jehan Wadia(@Jwadia)