Step 1: Import Required Libraries
Step 2: Load the Dataset
iris as a Python object containing everything about the dataset.
You can inspect it:
Dataset Contents
There are 4 numerical features.
Step 3: Separate Features and Labels
Step 4: Split the Dataset
Why Split?
If we train and test on the same data:random_state=42
42, every run produces the same split.
Step 5: Create a Pipeline
First Step
z=\frac{x-\mu}{\sigma}
] Example Original values
Second Step
Step 6: Train the Pipeline
Step A
Step B
Step C
Step 7: Predict
fit() on the scaler again. It reuses the mean and standard deviation learned from the training data.
Example output
Step 8: Evaluate
LogisticRegression, .score() returns accuracy.
Internally it is equivalent to:
Step 9: Save the Model
- StandardScaler (with learned mean and standard deviation)
- LogisticRegression (with learned coefficients)