-
Notifications
You must be signed in to change notification settings - Fork 2
LogisticRegressor
Logistic regression model that proceeds to sequential learning via gradient descent.
The model can be found in Bishop, Pattern Recognition and Machine Learning, p.205-206.
The letter sigma stands for the sigmoid function.
LogisticRegressor(phi, eta0=1, learning_rate='adaptive')
- phi : basis function applied to inputs' original features vectors.
- eta0 : initial learning rate value at the start of the training.
- learning_rate: learning rate schedule ('constant', 'adaptive' or 'invscaling').
!Note that L is the original number of features and M is the number of features after transformation with phi.train(self, X, t, nb_epoch, minibatch_size=1, weight_init=None)
Trains the logistic regressor according to the observations in the dataset X and their respective targets in t.
The weights are updated sequentially using the gradient of the cross-entropy loss.
- X: N x L numpy array with training observations.
- t: N x 1 numpy array with training labels.
- minibatch_size: size of minibatches used is gradient descent.
- weight_init: starting point of SGD in weight space, if weight_init=None, each of them are sampled from a standard normal distribution.
- return: updated weight vector (M x 1 numpy array).
reset_weights()
Resets the weights of the model randomly by sampling each of them from a standard normal distribution.
loss(X, t, return_predictions=False)
Computes the cross-entropy loss associated with our current model according to the observations in X and their respective labels in t.
- X: N x L numpy array with training observations.
- t: N x 1 numpy array with training labels.
- return_predictions: bool that indicates if the numpy array of predictions is returned.
- returns: loss (float), predictions (numpy array).
copy()
Creates a deep copy of the logistic regression model.
predict(x)
Predicts the probability of an input x to have label 1.
- x: 1 x L numpy array.
- return: predicted probability (float between 0 and 1 included).
plot_model(X, t, title=None, save=False, save_path='', filename='model', save_format='.pdf')
Plots the the prediction curve of our model (only available with 1-D or 2-D feature space).
The x-axis labels will be associated to .
- X: N x 1 numpy array with training observations.
- t: N x 1 numpy array with training labels
- title: title of the figure
- save: bool indicating if we want to save picture or not
- save_path: path indicating where we save the file if it is saved
- filename: name of the file if it is saved
- save_format: saving format