Задача 02A. Логистическая регрессия. Основы

Входной файл:Стандартный вход   Ограничение времени:1 сек
Выходной файл:Стандартный выход   Ограничение памяти:512 Мб
Максимальный балл:1  

Условие

Пусть задана логистическая регрессия для задачи бинарной классификации

f: X↦ y, X⊆ Rn, y = { − 1, 1}

f(x, θ) = σ(nxiθi)

σ(x) = 11 + e − x

Требуется реализовать следующие функции на языке Python.


import numpy as np

def logistic_func(theta: np.ndarray, x: np.ndarray) -> float:
    """Computes logistic regression value for sample x.
    
    Arguments:
        theta: 1d array of float, regression coefficients
        x: 1d array of float, sample to compute value for
    
    Returns:
        float, logistic regression value
    """
    pass

def logistic_func_all(theta: np.ndarray, X: np.ndarray) -> np.ndarray:
    """Computes logistic regression value for all samples in matrix X.
    
    Arguments:
        theta: 1d array of float, regression coefficients
        X: 2d array of float, row-major matrix of samples
        
    Returns:
        1d array of float, logistic regression values for all samples in matrix X
    """
    pass
    
def cross_entropy_loss(theta: np.ndarray, X: np.ndarray, y: np.ndarray) -> float:
    """Computes binary cross entropy loss for logistric regression with parameters `theta`
    on samples `X` and true labels `y`.
    
    Arguments:
        theta: 1d array of float, regression coefficients
        X: 2d array of float, row-major matrix of samples
        y: 1d array of int, true class lables from set {-1, 1}
        
    Returns:
        float, cross entropy loss value
    """
    pass
    

def grad_cross_entropy_loss(theta: np.ndarray, X: np.ndarray, y: np.ndarray) -> np.ndarray:
    """Computes gradient of binary cross entropy loss for logistic regression
    with parameters `theta` on samples `X` and true values `y`.
    
    Arguments:
        theta: 1d array of float, regresion coefficients
        X: 2d array of float, row-major matrix of samples
        y: 1d array of int, true class labels from set {-1, 1}
        
    Returns:
        1d array of float, cross entorpy gradient with respect to `theta`
    """
    pass

Формат выходных данных

Код должен содержать только реализацию функций.


0.057s 0.014s 15