Regression

Module for regression tasks. Regression tasks aim to obtain the equation for a set of data and use that equation in order to predict values.

class mapyl.regression.LinearRegressor[source]

Linear Regressor instance

fit(X, y)[source]

Trains the LinearRegressor instance, returns none

Parameters:

X (ndarray): the training input

y (ndarray): the training output

Returns none

predict(X)[source]

predicts y value for the x input

Parameter:

X (ndarray): X value to be predicted

Returns y (ndarray): the predicted values for the supplied X

class mapyl.regression.GradientDescent(lr)[source]

Linear Gradient Descent regressor

Parameter:

lr(float): The learning rate

fit(X, y, iters)[source]

Trains the Gradient Descent instance

Parameters:

X (ndarray): ndarray of shape (num_samples, num_features) of the input

y (ndarray): ndarray of shape (num_samples,) of the output

iters (int): the number of iteration

Returns:

self: the fitted instance

predict(X)[source]

Predicts y value for the supplied X

Parameters:

X (ndarray): ndarray of shape (num_samples, num_features) of the input

Returns:

ndarray: The output of the supplied X

class mapyl.regression.SGD[source]

Stochastic Gradient descent instance

fit(X, y, epochs=50)[source]

Fits the instance

Parameters:

X (ndarray): ndarray of shape (num_samples, num_features) of the input values y (ndarray): ndarray of shape (num_samples,) of the output values epochs (int): The number of epochs. Defaults to 50.

Returns:

self: The fitted instance

predict(X)[source]

Predicts y value for the supplied X

Parameters:

X (ndarray): ndarray of shape (num_samples, num_features) of the input

Returns:

ndarray: The output of the supplied X

class mapyl.regression.PolyRegressor(degree=2)[source]

Polynomial Regressor instance, uses the degree of the data

fit(X, y)[source]

Fits the PolyRegressor instance

Parameters:

X (ndarray): ndarray of shape (num_samples, num_features) for input

y (ndarray): numpy array of shape (num_samples,) for output

Returns:

self: The fitted instance

predict(X)[source]

Predicts y values for supplied X

Parameter:

X (ndarray): X value to be predicted

Returns y (ndarray): the predicted values for the supplied X

Warning

The PolyRegressor instance does a polynomial expansion in order to work, so if there are too many degrees or too many features you can have overflow

class mapyl.regression.BinLogitRegressor(lr=0.01)[source]

Binary Logistic Regressor instance

Parameter:

lr(int): float of the learning rate. Defaults to 0.01

fit(X, y, iters=500)[source]

Fits the instance

Parameters:

X (ndarray): ndarray of shape (num_samples, num_features) of the input

y (ndarray): ndarray of shape (num_samples,) of the output

iters (int): The number of iterations. Defaults to 500

Returns none

predict(X)[source]

Predicts the class of the supplied X

Parameter:

X (ndarray): ndarray of shape (num_samples, num_features) to be classified

Returns: int classifying as 1 or 0

predict_prob(X)[source]

Predicts the probability of the classification

Parameter:

X (ndarray): ndarray to be classified

Returns: float of the probability of being 1

Note

The float returned by predict_prob represents the probability of the supplied instance being 1 or 0, a probability larger than 0.5 means that it belongs to 1 and a probability less than 0.5 means that it belongs to 0.