用AI赚第一桶💰低成本搭建一套AI赚钱工具,源码可二开。 广告
## MLPClassifier 多层感知器(MLP)是一种前馈人工神经网络模型,它将输入数据集映射到一组适当的输出上。 ### 构造函数参数 `$inputLayerFeatures`(int) - 输入图层要素的数量 `$hiddenLayers`(array) - 具有隐藏层配置的数组,每个值表示每层中的神经元数 `$classes`(array) - 具有不同训练集类的数组(忽略数组键) `$iterations`(int) - 训练迭代次数 `$learningRate`(float) - 学习率 `$activationFunction`(ActivationFunction) - 神经元激活功能 ``` use Phpml\Classification\MLPClassifier; $mlp = new MLPClassifier(4, [2], ['a', 'b', 'c']); // 4 nodes in input layer, 2 nodes in first hidden layer and 3 possible labels. ``` ***** ### 激活函数也可以与每个单独的隐藏层一起传递。例: ``` use Phpml\NeuralNetwork\ActivationFunction\PReLU; use Phpml\NeuralNetwork\ActivationFunction\Sigmoid; $mlp = new MLPClassifier(4, [[2, new PReLU], [2, new Sigmoid]], ['a', 'b', 'c']); ``` 它们也可以配置Layer对象,而不是将每个隐藏层配置为array。例: ``` use Phpml\NeuralNetwork\Layer; use Phpml\NeuralNetwork\Node\Neuron; $layer1 = new Layer(2, Neuron::class, new PReLU); $layer2 = new Layer(2, Neuron::class, new Sigmoid); $mlp = new MLPClassifier(4, [$layer1, $layer2], ['a', 'b', 'c']); ``` ### 训练 训练MLP只需提供队列样本和标签(如array)。例: ``` $mlp->train( $samples = [[1, 0, 0, 0], [0, 1, 1, 0], [1, 1, 1, 1], [0, 0, 0, 0]], $targets = ['a', 'a', 'b', 'c'] ); ``` ### 使用partialTrain方法批量训练。例: ``` $mlp->partialTrain( $samples = [[1, 0, 0, 0], [0, 1, 1, 0]], $targets = ['a', 'a'] ); $mlp->partialTrain( $samples = [[1, 1, 1, 1], [0, 0, 0, 0]], $targets = ['b', 'c'] ); ``` ***** 您可以更新partialTrain运行之间的学习率: ``` $mlp->setLearningRate(0.1); ``` ### 预测 预测样本标签使用预测方法。您可以提供一个样本或样本数组: ### 激活功能 * BinaryStep * Gaussian * HyperbolicTangent * Parametric Rectified Linear Unit * Sigmoid (default) * Thresholded Rectified Linear Unit