AI Logistic Regression
Fit a binary classifier and distinguish its score from a decision.
How it works
Logistic regression maps a linear score through a logistic function. The output can be used as an estimated class probability under the fitted model, but calibration must be evaluated. A classification threshold converts the score into a label. This fictional example separates low and high tray counts; it does not establish a staffing rule.
Run the code
This is a local Python example, not supported by Bhylu’s plain Python browser editor. In a separate virtual environment use Python 3.12.14 with the pinned requirements: NumPy 2.5.4 and scikit-learn 1.9.1. Run python -m pip install -r requirements-local.txt in that environment, then run this complete downloaded source. These are reviewed versions, not a newest-release promise. No external dataset, provider account, database or PHP setting is needed.
Example
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
x = [[1],[2],[3],[7],[8],[9]]
y = [0,0,0,1,1,1]
model = make_pipeline(StandardScaler(), LogisticRegression(C=10, random_state=3))
model.fit(x,y)
print("classes:", model.predict([[1],[9]]).tolist())
probabilities = model.predict_proba([[1],[9]])
print("rows sum to one:", all(abs(sum(row)-1)<1e-10 for row in probabilities))
Expected result
classes: [0, 1] rows sum to one: True
The two predictions are made at extreme points of this tiny training fixture. Normalised probabilities are an API property, not a calibration test. Threshold choice belongs to a separate validation decision based on error costs and prevalence.