A binary outcome is a response with exactly two categories, typically coded 0 and 1. Logistic regression uses predictors to estimate P(Y = 1 | X): the probability that an observation belongs to the category coded 1. The choice of which category receives 1 is arbitrary, but it determines how the probabilities are interpreted. section 5.1 section 5.2.1
Unlike linear regression’s numeric prediction, logistic regression passes a linear combination of predictors through the sigmoid function, producing a probability between 0 and 1. With a 0.5 cutoff, probabilities at or above 0.5 become predictions of 1; those below it become predictions of 0. Keep the probability as well as the predicted class: the class alone hides how close the result was to the cutoff. section 5.1 section 5.2.3
Code a categorical outcome
For raisin classification, map the original variety labels before fitting: `class_mapping = {'Kecimen': 0, 'Besni': 1}` followed by `raisins['Class'] = raisins['Class'].map(class_mapping)`. Check the resulting column against the original labels. A subsequent probability for this outcome refers specifically to Besni, the category coded 1. section 5.2.1
Before using a binary prediction for a decision:
- Explore predictor distributions by outcome class; grouped statistics and histograms can expose patterns and potential data issues. section 5.2.1 section 5.3
- Check model fit and predictor relationships rather than treating a computed probability as sufficient evidence. McFadden’s pseudo R² compares fit with an intercept-only model; the likelihood-ratio and predictor p-values address statistical significance. section 5.2.3 section 5.3
- Compare predicted classes with observed outcomes using true and false positive and negative rates, accuracy, misclassification, and area under the ROC curve. section 5.3
>>> print(raisins_subset.head(n = 3))
MinorAxisLength Perimeter Class probability prediction
0 253.29 1184.04 0 0.698821 1
1 243.03 1121.79 0 0.525426 1
2 266.33 1208.58 0 0.713766 1
>>> print(raisins_subset.tail(n = 3))
MinorAxisLength Perimeter Class probability prediction
897 298.84 1292.83 1 0.811597 1
898 254.18 1258.55 1 0.881365 1
899 215.27 1272.86 1 0.960193 1
The displayed raisin records retain the observed class beside the probability and thresholded prediction. The first three have observed class 0 but predictions of 1, making errors visible rather than reporting probabilities alone. section 5.2.3
The same outcome structure applies beyond logistic regression. A fourth-down football play either converts or fails; decision trees and random forests can be fitted to predict that result from play-by-play data. In either setting, define the two categories clearly before interpreting predictions or acting on them. section 6.2 section 5.2.1



