umbmid/ai/logreg.py
def fit(self, features, labels, learn_rate=0.01, max_iter=10000):
        """Train (grad descent) the model to learn the model parameters

        Parameters
        ----------
        features : array_like
            The features for each sample
        labels : array_like
            The binary class labels (0s or 1s)
        learn_rate : float
            The learning rate used for gradient descent
        max_iter : int
            The maximum number of iterations before termination of the
            optimization routine
        """

        # Find the number of samples used for training
        n_samples = np.size(features, axis=0)

        # Init stopping-criteria parameters
        cost_change = 1e9
        threshold = 1e-5
        n_iter = 0

        # Init list for storing value of cost func at each iteration
        costs = []

        # While stopping criteria is not satisfied
        while cost_change > threshold and n_iter < max_iter:

            n_iter += 1  # Increment iteration number counter

            # Predict the scores for each sample
            preds = self.predict_proba(features)

            # Prevent crashes by removing not-acceptable values
            preds[preds == 0] = 1e-5
            preds[preds == 1] = 1 - 1e-5

            # Get the gradient of the cost function with respect to
            # each parameter
            param_grad = self._param_grad(features, labels, preds, n_samples)

            # Update the parameters using gradient descent
            self.params -= learn_rate * param_grad

            # Find the value of the cost function at this iteration
            cost = (1 / n_samples) * np.sum(-labels * np.log(preds)
                                            - (1 - labels) * np.log(1 - preds))

            # Store the cost function from this iteration
            costs.append(cost)
Train (grad descent) the model to learn the model parameters

        Parameters
        ----------
        features : array_like
            The features for each sample
        labels : array_like
            The binary class labels (0s or 1s)
        learn_rate : float
            The learning rate used for gradient descent
        max_iter : int
            The maximum number of iterations before termination of the
            optimization routine
        
Train (grad descent) the model to learn the model parameters
Train ( grad descent ) the model to learn the model parameters
def fit(self, features, labels, learn_rate=0.01, max_iter=10000):
        n_samples = np.size(features, axis=0)
        cost_change = 1e9
        threshold = 1e-5
        n_iter = 0
        costs = []
        while cost_change > threshold and n_iter < max_iter:
            n_iter += 1  
            preds = self.predict_proba(features)
            preds[preds == 0] = 1e-5
            preds[preds == 1] = 1 - 1e-5
            param_grad = self._param_grad(features, labels, preds, n_samples)
            self.params -= learn_rate * param_grad
            cost = (1 / n_samples) * np.sum(-labels * np.log(preds)
                                            - (1 - labels) * np.log(1 - preds))
            costs.append(cost)
def fit ( self , features , labels , learn_rate = 0.01 , max_iter = 10000 ) : n_samples = np . size ( features , axis = 0 ) cost_change = 1e9 threshold = 1e-5 n_iter = 0 costs = [ ] while cost_change > threshold and n_iter < max_iter : n_iter += 1 preds = self . predict_proba ( features ) preds [ preds == 0 ] = 1e-5 preds [ preds == 1 ] = 1 - 1e-5 param_grad = self . _param_grad ( features , labels , preds , n_samples ) self . params -= learn_rate * param_grad cost = ( 1 / n_samples ) * np . sum ( - labels * np . log ( preds ) - ( 1 - labels ) * np . log ( 1 - preds ) ) costs . append ( cost )
Train (grad descent) the model to learn the model parameters
Train ( grad descent ) the model to learn the model parameters
"""Train (grad descent) the model to learn the model parameters

        Parameters
        ----------
        features : array_like
            The features for each sample
        labels : array_like
            The binary class labels (0s or 1s)
        learn_rate : float
            The learning rate used for gradient descent
        max_iter : int
            The maximum number of iterations before termination of the
            optimization routine
        """ # Find the number of samples used for training
 # Init stopping-criteria parameters
 # Init list for storing value of cost func at each iteration
 # While stopping criteria is not satisfied
 # Increment iteration number counter
 # Predict the scores for each sample
 # Prevent crashes by removing not-acceptable values
 # Get the gradient of the cost function with respect to
 # each parameter
 # Update the parameters using gradient descent
 # Find the value of the cost function at this iteration
 # Store the cost function from this iteration

self
features
The features for each sample
The features for each sample
labels
The binary class labels (0s or 1s)
The binary class labels ( 0s or 1s )
learn_rate
The learning rate used for gradient descent
The learning rate used for gradient descent
max_iter
The maximum number of iterations before termination of the
optimization routine
The maximum number of iterations before termination of the optimization routine