Logistic Regression

Single Parameter

touvlo.lgx_rg.sgl_parm.cost_func(X, Y, theta)[source]

Computes the cost function J for Logistic Regression.

Parameters:
  • X (numpy.array) – Features’ dataset plus bias column.
  • Y (numpy.array) – Column vector of expected values.
  • theta (numpy.array) – Column vector of model’s parameters.
Returns:

Computed cost.

Return type:

float

touvlo.lgx_rg.sgl_parm.grad(X, Y, theta)[source]

Computes the gradient for the parameters theta.

Parameters:
  • X (numpy.array) – Features’ dataset plus bias column.
  • Y (numpy.array) – Column vector of expected values.
  • theta (numpy.array) – Column vector of model’s parameters.
Returns:

Gradient column vector.

Return type:

numpy.array

touvlo.lgx_rg.sgl_parm.h(X, theta)[source]

Logistic regression hypothesis.

Parameters:
  • X (numpy.array) – Features’ dataset plus bias column.
  • theta (numpy.array) – Column vector of model’s parameters.
Raises:

ValueError

Returns:

The probability that each entry belong to class 1.

Return type:

numpy.array

touvlo.lgx_rg.sgl_parm.p(x, threshold=0.5)[source]

Predicts whether a probability falls into class 1.

Parameters:
  • x (obj) – Probability that example belongs to class 1.
  • threshold (float) – point above which a probability is deemed of class 1.
Returns:

Binary value to denote class 1 or 0

Return type:

int

touvlo.lgx_rg.sgl_parm.predict(X, theta)[source]

Classifies each entry as class 1 or class 0.

Parameters:
  • X (numpy.array) – Features’ dataset plus bias column.
  • theta (numpy.array) – Column vector of model’s parameters.
Returns:

Column vector with each entry classification.

Return type:

numpy.array

touvlo.lgx_rg.sgl_parm.predict_prob(X, theta)[source]

Produces the probability that the entries belong to class 1.

Returns:Features’ dataset plus bias column. theta (numpy.array): Column vector of model’s parameters.
Return type:X (numpy.array)
Raises:ValueError
Returns:The probability that each entry belong to class 1.
Return type:numpy.array
touvlo.lgx_rg.sgl_parm.reg_cost_func(X, Y, theta, _lambda)[source]

Computes the regularized cost function J for Logistic Regression.

Parameters:
  • X (numpy.array) – Features’ dataset plus bias column.
  • Y (numpy.array) – Column vector of expected values.
  • theta (numpy.array) – Column vector of model’s parameters.
  • _lambda (float) – The regularization hyperparameter.
Returns:

Computed cost with regularization.

Return type:

float

touvlo.lgx_rg.sgl_parm.reg_grad(X, Y, theta, _lambda)[source]

Computes the regularized gradient for Logistic Regression.

Parameters:
  • X (numpy.array) – Features’ dataset plus bias column.
  • Y (numpy.array) – Column vector of expected values.
  • theta (numpy.array) – Column vector of model’s parameters.
  • _lambda (float) – The regularization hyperparameter.
Returns:

Regularized gradient column vector.

Return type:

numpy.array

Computation Graph

touvlo.lgx_rg.cmpt_grf.cost_func(X, Y, hyp=None, **kwargs)[source]

Computes the cost function J for Logistic Regression.

Parameters:
  • X (numpy.array) – Features’ dataset.
  • Y (numpy.array) – Row vector of expected values.
  • hyp (numpy.array) – The calculated model hypothesis, if not provided
  • named parameters to calculate it should be provided instead. (the) –
Returns:

Computed cost.

Return type:

float

touvlo.lgx_rg.cmpt_grf.grad(X, Y, w, b)[source]

Computes the gradient for the parameters w and b.

Parameters:
  • X (numpy.array) – Transpose features’ dataset.
  • Y (numpy.array) – Row vector of expected values.
  • w (numpy.array) – Column vector of model’s parameters.
  • b (float) – Model’s intercept parameter.
Returns:

A 2-tuple consisting of a gradient column

vector and a gradient value.

Return type:

(numpy.array, float)

touvlo.lgx_rg.cmpt_grf.h(X, w, b)[source]

Logistic regression hypothesis.

Parameters:
  • X (numpy.array) – Transposed features’ dataset.
  • w (numpy.array) – Column vector of model’s parameters.
  • b (float) – Model’s intercept parameter.
Returns:

The probability that each entry belong to class 1.

Return type:

numpy.array

touvlo.lgx_rg.cmpt_grf.predict(X, w, b, threshold=0.5)[source]

Predicts whether the given probabilities fall into class 1.

Parameters:
  • X (numpy.array) – Transpose features’ dataset.
  • threshold (float) – Point above which a probability is assigned
  • class 1. (to) –
Returns:

Binary value to denote class 1 or 0 for each example.

Return type:

numpy.array