Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

(no description)

File Size: 283 lines (9 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

LogisticRegression:: (9 methods):
  __construct()
  setLearningRate()
  setLambda()
  runTraining()
  runConjugateGradient()
  getCostFunction()
  output()
  outputClass()
  predictProbability()


Class: LogisticRegression  - X-Ref

__construct(int $maxIterations = 500,bool $normalizeInputs = true,int $trainingType = self::CONJUGATE_GRAD_TRAINING,string $cost = 'log',string $penalty = 'L2')   X-Ref
Initalize a Logistic Regression classifier with maximum number of iterations
and learning rule to be applied <br>

Maximum number of iterations can be an integer value greater than 0 <br>
If normalizeInputs is set to true, then every input given to the algorithm will be standardized
by use of standard deviation and mean calculation <br>

Cost function can be 'log' for log-likelihood and 'sse' for sum of squared errors <br>

Penalty (Regularization term) can be 'L2' or empty string to cancel penalty term


setLearningRate(float $learningRate)   X-Ref
Sets the learning rate if gradient descent algorithm is
selected for training


setLambda(float $lambda)   X-Ref
Lambda (λ) parameter of regularization term. If 0 is given,
then the regularization term is cancelled


runTraining(array $samples, array $targets)   X-Ref
Adapts the weights with respect to given samples and targets
by use of selected solver


runConjugateGradient(array $samples, array $targets, Closure $gradientFunc)   X-Ref
Executes Conjugate Gradient method to optimize the weights of the LogReg model


getCostFunction()   X-Ref
Returns the appropriate callback function for the selected cost function


output(array $sample)   X-Ref
Returns the output of the network, a float value between 0.0 and 1.0


outputClass(array $sample)   X-Ref
Returns the class value (either -1 or 1) for the given input


predictProbability(array $sample, $label)   X-Ref
Returns the probability of the sample of belonging to the given label.

The probability is simply taken as the distance of the sample
to the decision plane.

param: mixed $label