Пример #1
0
    def predict(self, X):
        """
        Predict the Probabilistic Value of
        Input, in accordance with
        Logistic Regression Model.

        PARAMETERS
        ==========

        X: ndarray(dtype=float,ndim=1)
            1-D Array of Dataset's Input.

        prediction: ndarray(dtype=float,ndim=1)
            1-D Array of Predicted Values
            corresponding to each Input of
            Dataset.

        RETURNS
        =======

        ndarray(dtype=float,ndim=1)
            1-D Array of Probabilistic Values
            of whether the particular Input
            belongs to class 0 or class 1.
        """
        prediction = np.dot(X, self.weights).T
        return sigmoid(prediction)
Пример #2
0
 def classify(self, X):
     prediction = np.dot(X, self.weights).T
     prediction = sigmoid(prediction)
     actual_predictions = np.zeros((1, X.shape[0]))
     for i in range(prediction.shape[1]):
         if prediction[0][i] > 0.5:
             actual_predictions[0][i] = 1
     return actual_predictions
Пример #3
0
    def classify(self, X):
        """
        Classify the Input, according to
        Logistic Regression Model,i.e in this
        case, either class 0 or class 1.

        PARAMETERS
        ==========

        X: ndarray(dtype=float,ndim=1)
            1-D Array of Dataset's Input.

        prediction: ndarray(dtype=float,ndim=1)
            1-D Array of Predicted Values
            corresponding to their Inputs.

        actual_predictions: ndarray(dtype=int,ndim=1)
            1-D Array of Output, associated
            to each Input of Dataset,
            Predicted by Trained Logistic
            Regression Model.

        RETURNS
        =======

        ndarray
            1-D Array of Predicted classes
            (either 0 or 1) corresponding
            to their inputs.

        """
        prediction = np.dot(X, self.weights).T
        prediction = sigmoid(prediction)
        actual_predictions = np.zeros((1, X.shape[0]))
        for i in range(prediction.shape[1]):
            if prediction[0][i] > 0.5:
                actual_predictions[0][i] = 1

        return actual_predictions
Пример #4
0
    def derivative(X, Y, W):
        """
        Calculate derivative for logarithmic error method.

        PARAMETERS
        ==========

        X:ndarray(dtype=float,ndim=1)
          input vector
        Y:ndarray(dtype=float)
          output vector
        W:ndarray(dtype=float)
          Weights

         RETURNS
         =======

         array of derivates
        """
        M = X.shape[0]
        H = sigmoid(np.dot(X, W).T)
        return (1 / M) * (np.dot(X.T, (H - Y).T))
Пример #5
0
    def loss(X, Y, W):
        """
        Calculate loss by logarithmic error method.

        PARAMETERS
        ==========

        X:ndarray(dtype=float,ndim=1)
          input vector
        Y:ndarray(dtype=float)
          output vector
        W:ndarray(dtype=float)
          Weights

         RETURNS
         =======

         array of logarithmic losses
        """
        M = X.shape[0]
        H = sigmoid(np.dot(X, W).T)
        return (1 / M) * (np.sum((-Y) * np.log(H) - (1 - Y) * np.log(1 - H)))
Пример #6
0
 def derivative(X, Y, W):
     M = X.shape[0]
     H = sigmoid(np.dot(X, W).T)
     return (1 / M) * (np.dot(X.T, (H - Y).T))
Пример #7
0
 def loss(X, Y, W):
     M = X.shape[0]
     H = sigmoid(np.dot(X, W).T)
     return (1 / M) * (np.sum((-Y) * np.log(H) - (1 - Y) * np.log(1 - H)))
Пример #8
0
 def predict(self, X):
     prediction = np.dot(X, self.weights).T
     return sigmoid(prediction)