-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
305 additions
and
288 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
use Phpml\CrossValidation\RandomSplit; | ||
use Phpml\Dataset\ArrayDataset; | ||
|
||
require './vendor/autoload.php'; | ||
|
||
$dataset = new ArrayDataset( | ||
$samples = [[1], [2], [3], [4], [5], [6], [7], [8],[9],[10]], | ||
$targets = ['a', 'a', 'a', 'a', 'b', 'b', 'b', 'b','c','c'] | ||
); | ||
//第二个参数 是按照百分比 去分割的 | ||
//第三个参数 是播下一个更好的随机数发生器种子 是 mt_stand() 这个函数 | ||
$dataset_demp = new RandomSplit($dataset, 0.3, 1234); | ||
|
||
//随机取得训练数据 | ||
echo '<pre>'; | ||
print_r($dataset_demp->getTrainSamples()); //训练的数据 | ||
print_r($dataset_demp->getTrainLabels()); //训练的标记 | ||
|
||
//随机取得测试数据 | ||
echo '<pre>'; | ||
print_r($dataset_demp->getTestSamples()); //测试的数据 | ||
print_r($dataset_demp->getTestLabels()); //测试的标记 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
|
||
use Phpml\CrossValidation\StratifiedRandomSplit; | ||
use Phpml\Dataset\ArrayDataset; | ||
|
||
require './vendor/autoload.php'; | ||
|
||
$dataset = new ArrayDataset( | ||
$samples = [[1], [2], [3], [4], [5], [6], [7], [8],[9],[10]], | ||
$targets = ['a', 'a', 'a', 'a', 'b', 'b', 'b', 'b','c','c'] | ||
); | ||
|
||
$split = new StratifiedRandomSplit($dataset, 0.3); | ||
|
||
|
||
//随机取得训练数据 | ||
echo '<pre>'; | ||
print_r($split->getTrainSamples()); //训练的数据 | ||
print_r($split->getTrainLabels()); //训练的标记 | ||
|
||
//随机取得测试数据 | ||
echo '<pre>'; | ||
print_r($split->getTestSamples()); //测试的数据 | ||
print_r($split->getTestLabels()); //测试的标记 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# 交叉验证 | ||
|
||
交叉验证的基本思想是把在某种意义下将原始数据(dataset)进行分组, | ||
一部分做为训练集(train set), | ||
另一部分做为验证集(validation set or test set), | ||
首先用训练集对分类器进行训练,再利用验证集来测试训练得到的模型(model),以此来做为评价分类器的性能指标。 | ||
|
||
|
||
- 随机分割 [例如:A](../RandomSpilt.php) | ||
|
||
交叉验证最简单的方法之一就是实现RandomSpilt类。样本分为两组:训练组和测试组。您可以调整每个组的样本数量。 | ||
|
||
- 分层随机分割 [例如:B](../StratifiedRandomSplit.php) | ||
|
||
类似于RandomSpilt类样本被划分到两个组:列车组和试验组。样本的分布考虑到了他们的目标,并试图平分他们。您可以调整每个组的样本数量。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters