class SupervisedLearning::LogisticRegression

This class uses logistic regression to make discrete predictions (true or false) based on a training set. The algorithms in predict were provided by Andrew Ng (Stanford University). @author Michael Imstepf

Public Class Methods

new(training_set) click to toggle source

Initializes a LogisticRegression object with a training set @param training_set [Matrix] training_set, each feature/dimension has one column and the last column is the output column (type of value predict will return) @raise [ArgumentError] if training_set is not a Matrix or does not have at least two columns and one row

# File lib/supervised_learning.rb, line 157
def initialize(training_set)
  @training_set = training_set
  raise ArgumentError, 'input is not a Matrix' unless @training_set.is_a? Matrix
  raise ArgumentError, 'Matrix must have at least 2 columns and 1 row' unless @training_set.column_size > 1
end

Private Instance Methods

calculate_cost() click to toggle source
# File lib/supervised_learning.rb, line 172
def calculate_cost

end
calculate_sigmoid(z) click to toggle source
# File lib/supervised_learning.rb, line 165
def calculate_sigmoid(z)
  matrix_with_ones = Matrix.one(1, z.column_size)
  matrix_with_eulers_number = Matrix.build(1, z.column_size) {Math::E}
  z_negative = z * -1
  matrix_with_ones.element_division (matrix_with_ones + matrix_with_eulers_number.element_exponentiation(z_negative))
end