2️⃣Logistic Regression
Logistic regression is a supervised learning algorithm used for classification. It is used to predict a binary outcome (1 / 0, Yes / No, True / False) given a set of independent variables. The outcome is modeled using a logistic function, also called the sigmoid function, which produces an output between 0 and 1.
The logistic regression model is based on the idea that there is a relationship between the input variables (x) and the log-odds of the output variable (y). The log-odds is the logarithm of the probability of the outcome being 1 (p) divided by the probability of the outcome being 0 (1-p). This relationship is represented by an equation of the form:
where b0, b1, b2, ..., bn are the coefficients of the logistic equation and x1, x2, ..., xn are the input variables. The coefficients are estimated from the training data using a method called maximum likelihood estimation (MLE).

Once the coefficients are estimated, the logistic regression model can be used to make predictions on new data. For example, given a new input data point (x), the predicted probability of the outcome being 1
Example
This code imports the necessary libraries and defines the input variable x as a 2-dimensional array of integers representing the features of the data and the output variable y as a 1-dimensional array of integers representing the target (0 for negative class and 1 for positive class).
Then, a LogisticRegression model is created, and then it's fit to the data using the fit()
method. The coefficients of the logistic equation, the intercept and the coefficient of x variable, are then printed using the intercept_
and coef_
attributes of the model.
Finally, the code makes predictions for new data points (x_new) using the predict()
method and prints the predictions.
This is a simple example, but in real world applications the dataset will be more complex and the features may be represented by multiple variables and the target will not always be binary.
Python code
Output
References:
https://www.javatpoint.com/logistic-regression-in-machine-learning
Last updated