Python ML The Machine Learning Workflow
The machine learning workflow is a fixed order of seven steps. Every project in this course follows the same order.
Load: four rows come in
Load brings four rows into Python. The first row still carries its extra spaces.
raw = [" Ada, 28 ", "Bob, 31", "", " Cy, 25 "]
print(len(raw))
print(raw[0])Look: first row and last row
Look checks the edges of the data. The first row and the last row show the mess at once.
raw = [" Ada, 28 ", "Bob, 31", "", " Cy, 25 "]
print(raw[0])
print(raw[-1])Clean: spaces go, blanks go
Strip cuts the edge spaces. The blank row drops out. Three clean rows stay.
raw = [" Ada, 28 ", "Bob, 31", "", " Cy, 25 "]
cleaned = [line.strip() for line in raw if line.strip() != ""]
print(cleaned)
print(len(cleaned))Example
raw = [" Ada, 28 ", "Bob, 31", "", " Cy, 25 ", "Dee, 40"]
print("Loaded rows:", len(raw))
print("First row:", raw[0])
cleaned = [line.strip().lower() for line in raw if line.strip() != ""]
print("Clean rows:", len(cleaned))
print(cleaned)
print("Rows kept:", len(cleaned), "of", len(raw))Key points
- Workflow: a fixed order of steps that every project follows
- Load: bring the data into Python
- Look: check the shape and the first rows
- Clean: fix missing values and stray spaces
- Split: cut the data into a training part and a test part
- Train: let the program study the training part
- Evaluate: check the trained program on the test part
- Improve: change one thing and run the steps again
In this example, the program runs the first three steps of the workflow. Load brings five rows in. Look shows the first row with its spaces. Clean strips the spaces and drops the blank row. Four rows stay out of five. The workflow is a fixed order, and each step hands clean data to the next step.
Note
The steps run in order. Cleaning after the split would hide mistakes.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Python Playground
Exercise
What is the first step of the workflow?