02

ML Engineer · Step 2 of 8 · 8 min

Python and the core libraries

You can set up a free notebook, load a dataset with pandas and train a first model with scikit-learn.

Why Python

Almost all machine learning work happens in Python. The language is not the fastest, but the libraries underneath are written in fast C, C++ and CUDA. Python is the friendly handle on top of them.

You need less Python than you think: variables, lists and dictionaries, loops, functions, and how to install and import packages. Classes and type hints come later, when you write code other people will use.

The four libraries you will use every day

NumPy holds numbers in arrays and does maths on them quickly. pandas holds tables, like a spreadsheet you control with code: load a CSV, filter rows, group and summarise. Matplotlib (or its friendlier cousin seaborn) draws charts so you can see your data before you trust it.

scikit-learn is the toolbox of classic machine learning. Every model in it works the same way: create it, call fit on training data, call predict on new data. Learn that pattern once and you can try dozens of models.

Where to run your code

You do not need a powerful computer. Google Colab and Kaggle Notebooks give you a free notebook in the browser with these libraries already installed. Later you will want a local setup with a virtual environment, so each project keeps its own package versions.

Get used to writing code in small cells, running each one, and looking at the output. Print the first rows of a table. Check its shape. Most bugs in ML are data bugs, and you only catch them by looking.

Let a chatbot help, carefully

Chatbots are good at explaining an error message or writing a first draft of pandas code. Use them. But run the code, read it line by line, and make sure you could explain it to someone else. If you cannot, ask the chatbot to explain it more simply until you can.

Try it

Your first model in ten lines

  1. 1.Open colab.research.google.com and create a new notebook. Sign in with a Google account; it is free.
  2. 2.Ask a chatbot for the code in the prompt below and paste it into a cell.
  3. 3.Run it, then change the model to a DecisionTreeClassifier and run it again. Compare the two scores.
Write short Python code for Google Colab that loads the iris dataset from scikit-learn into a pandas DataFrame, shows the first five rows, splits it into training and test sets, trains a LogisticRegression model and prints the accuracy on the test set. Add a one-line comment above each step.
In scikit-learn, what is the basic pattern every model follows?

Check yourself

In scikit-learn, what is the basic pattern every model follows?

Read alongside