Logistic regression कैसे काम करती है

इंटरमीडिएट Regression with statsmodels in Python

Maarten Van den Broeck

Content Developer at DataCamp

Sum of squares काम नहीं करता

np.sum((y_pred - y_actual) ** 2)

y_actual हमेशा 0 या 1 होता है.

y_pred 0 और 1 के बीच होता है.

Sum of squares से बेहतर एक metric है.

इंटरमीडिएट Regression with statsmodels in Python

Likelihood

       y_pred * y_actual
इंटरमीडिएट Regression with statsmodels in Python

Likelihood

       y_pred * y_actual + (1 - y_pred) * (1 - y_actual)
इंटरमीडिएट Regression with statsmodels in Python

Likelihood

np.sum(y_pred * y_actual + (1 - y_pred) * (1 - y_actual))

जब y_actual = 1 हो

y_pred * 1 + (1 - y_pred) * (1 - 1) = y_pred

जब y_actual = 0 हो

y_pred * 0 + (1 - y_pred) * (1 - 0) = 1 - y_pred
इंटरमीडिएट Regression with statsmodels in Python

Log-likelihood

  • Likelihood की गणना में बहुत छोटे नंबर जोड़ने पड़ते हैं, जिससे numerical error हो सकती है.
  • Log-likelihood निकालना आसान है.
log_likelihood = np.log(y_pred) * y_actual + np.log(1 - y_pred) * (1 - y_actual)

दोनों समीकरण वही उत्तर देते हैं.

इंटरमीडिएट Regression with statsmodels in Python

Negative log-likelihood

Log-likelihood को अधिकतम करना, negative log-likelihood को न्यूनतम करने के समान है.

-np.sum(log_likelihoods)
इंटरमीडिएट Regression with statsmodels in Python

Logistic regression algorithm

def calc_neg_log_likelihood(coeffs)

intercept, slope = coeffs
# More calculation!
from scipy.optimize import minimize

minimize(
  fun=calc_neg_log_likelihood,
  x0=[0, 0]
)
इंटरमीडिएट Regression with statsmodels in Python

अभ्यास करते हैं!

इंटरमीडिएट Regression with statsmodels in Python

Preparing Video For Download...