--- title: "AI102 ยท How machines learn" publisher: Maestro College (Maestro Open) lessons: 35 source: https://open.maestrocollege.edu/how-machines-learn full: https://open.maestrocollege.edu/how-machines-learn/llms-full.txt --- # How machines learn (AI102) See problems as machine-learning problems, understand your data, and train and evaluate your first supervised models. ## Course objectives - Determine whether a problem is appropriate for machine learning and select suitable supervised or unsupervised approaches. - Prepare and explore datasets while identifying data-quality, leakage, imbalance, and bias concerns that affect model use. - Train baseline and machine-learning models using reproducible data-preparation and evaluation workflows. - Interpret regression, classification, and clustering results using measures appropriate to the task and consequences of errors. - Evaluate model generalization, diagnose fitting problems, and make evidence-based recommendations about model readiness. ## Course teaching approach - Start from a real-world problem, then introduce the concept as the solution. - Keep it true beginner level, hands-on, a little gamified. The learner should feel they are winning. - Balance explanation, demonstration and practice. No copy-paste exercises: give small story-based tasks. - End with one fun closed question about the topic. ## Lessons ### Unit 1: Seeing problems as ML problems #### 1. From hand-written rules to learning - Distinguish software that follows hand-written rules from a model that learns a pattern from example data. - Understand training (fit) as extracting a pattern from examples and prediction (predict) as applying it to new inputs. - Identify which parts of a system are learned models and which are hand-written rules. Teaching notes: Use AI101's keyword router and its nearest-neighbor and Bayes classifiers as the contrasting examples. #### 2. Where ML fits in the AI map - Place AI, machine learning, deep learning, generative AI, and LLMs on a nested map, and identify which layer a given product belongs to. - Distinguish AI built on hand-written rules and search from AI that learns from data. Teaching notes: Create an illustration that shows AI, ML, deep learning, generative AI, and LLMs as nested circles with one product example in each. #### 3. Deep learning, generative AI, and LLMs - Understand that deep learning uses many-layered neural networks that learn from large amounts of data such as images, audio, and text. - Understand that generative AI produces new content, and that an LLM is a generative model trained on huge amounts of text to predict the next token (a word or part of a word). - Identify a real product and a typical use case for deep learning, generative AI, and LLMs, and identify when a simple ML model fits better. #### 4. Features, labels, and examples - Identify the examples (rows), features (input columns), and label (answer column) in an ML system you haven't seen before. - Identify leakage when the label, or information known only after the outcome, is included as a feature. #### 5. Is this an ML problem? - Classify problem descriptions as suitable or unsuitable for ML, and justify each choice by available examples, a learnable pattern, and the cost of wrong predictions. - Identify problems that plain code or hand-written rules solve better than ML. #### 6. Regression, classification, and clustering - Distinguish supervised learning, which learns from labeled examples, from unsupervised learning, which finds structure without labels. - Choose regression when the output is a number, classification when it is a category, and clustering when the goal is to find groups without labels. #### 7. The ML workflow loop - Put the workflow stages in order: frame, explore, split, prepare using training data only, train, evaluate against a baseline, diagnose, and decide. - Understand why the loop repeats until the result is good enough, and identify which stage a described mistake belongs to. Teaching notes: Create an illustration that shows the workflow stages as a loop with an arrow back from decide to frame. #### 8. Setting up your ML workspace in VS Code - Create a project folder with a virtual environment in VS Code, and install pandas, scikit-learn, and matplotlib with pip. - Select the virtual environment as VS Code's Python interpreter, and run a check script that imports each library and prints its version. - Fix common setup errors, such as a library that isn't found or the wrong interpreter selected, by reading the error message. Teaching notes: Ask which operating system the learner uses before giving any commands, and have them paste the check script's output into the chat to confirm the setup works. #### 9. Running your first model template - Run a provided template in VS Code and read its output. - Load a dataset, train a model with fit, and generate predictions with predict by editing only the marked lines. - Match each part of the template to a stage of the ML workflow loop. Teaching notes: Provide a ready-made template that trains scikit-learn's nearest-neighbor classifier on a small labeled dataset, so learners see the library version of their AI101 model. #### 10. Challenge: framing ML problems - Decide whether ML fits several new product ideas, and justify each decision with examples, a learnable pattern, and the cost of errors. - Name the features, label, and task type for each suitable idea, and place its approach on the AI map. - Outline the workflow stages each suitable idea would go through. Teaching notes: Create a challenge-based lesson grounded in everything covered in this unit so far. Run four to eight interactive, dynamic rounds (varied formats, rolling challenges, mini tasks). Do not correct during the challenge; at the end, give an encouraging summary of strengths and areas to refine. ### Unit 2: Understanding data before modeling #### 11. Collecting and loading a dataset - Understand that a model can only be as good as its data, and name the checks to run before training: missing values, outliers, imbalance, and bias. - Identify where a dataset comes from and how the way it was collected limits what it can represent. - Load a CSV file into a pandas DataFrame and check its number of rows, columns, and column types. #### 12. Exploring data with pandas - Summarize a dataset with pandas to report its size, column types, and value ranges. - Use the mean, median, and spread of each column to identify skewed or unusual columns. - Identify the feature and label columns and check how the label values are distributed. #### 13. Visualizing distributions and relationships - Create histograms with a plotting template and read a feature's shape, spread, and unusual values. - Create scatter plots and identify which features appear related to the label. #### 14. Handling missing values and outliers - Detect missing values and choose whether to drop them or fill them with the median or most common value, justifying the choice. - Detect outliers with summary statistics and plots, and decide whether each is an error to fix or a real value to keep. #### 15. Spotting imbalanced and biased data - Identify class imbalance in a label and understand why it pushes a model to favor the majority class. - Identify bias in data, such as under-represented groups or labels shaped by past unfair decisions, and how it affects predictions for those groups. - Choose a fix for each problem, such as collecting more examples, rebalancing, or checking error rates by group. #### 16. Encoding categories and scaling features - Convert category columns into numbers with one-hot encoding, and understand why plain numeric codes can mislead a model. - Scale numeric features to similar ranges, and identify which models are affected by scale, such as distance-based ones. #### 17. Creating useful features - Create new features from existing columns, such as parts of a date or a ratio of two columns, that make a pattern easier to learn. - Identify columns to drop, such as IDs, near-duplicates, and columns that leak the label. #### 18. Splitting data into train and test sets - Understand that a model's real quality is how it performs on data it never saw during training, which is why data is split before training. - Split a dataset into training and test sets with scikit-learn, choosing a test size and stratifying (keeping the same class proportions in both sets) when the label is imbalanced. - Identify leakage mistakes, such as peeking at the test set or cleaning with statistics from the whole dataset. #### 19. Preparing data with a pipeline - Build a scikit-learn pipeline from a template that combines filling missing values, encoding, scaling, and a model in one object. - Understand why fitting the pipeline on training data only, then applying it to test data, prevents leakage. #### 20. Challenge: data readiness check - Explore an unfamiliar dataset and summarize its size, column types, distributions, and readiness problems before any training. - Split the data into training and test sets, then handle missing values, outliers, categories, scaling, and imbalance using training data only, for example with a pipeline. - Decide whether the dataset is ready to train on, and justify the decision with evidence from the exploration. Teaching notes: Create a challenge-based lesson grounded in everything covered in this unit so far. Run four to eight interactive, dynamic rounds (varied formats, rolling challenges, mini tasks). Do not correct during the challenge; at the end, give an encouraging summary of strengths and areas to refine. ### Unit 3: Training and evaluating supervised models #### 21. Training a linear regression model - Train a linear regression model in a template on training data and predict on test data. - Read each coefficient of a model on unscaled features as how much the prediction changes when that feature grows by one unit and the others stay the same. #### 22. Measuring regression error - Calculate mean absolute error on test data and interpret it in the units of the label. - Identify the predictions with the largest errors and connect them to data issues such as outliers or missing information. #### 23. Beating a simple baseline Teaching notes: Briefly recap accuracy (the share of correct predictions) from AI101 before scoring the most-common-class baseline. #### 24. Classifying with logistic regression - Train a logistic regression classifier in a template and predict classes for test data. - Read predicted probabilities and understand how a decision threshold turns them into class decisions. - Compare the classifier's test accuracy with a most-common-class baseline. Teaching notes: Briefly recap accuracy as the share of correct predictions, and link the predicted probabilities to AI101's Bayes classifier. #### 25. Classifying with decision trees - Train a decision tree classifier in a template and read its top splits as learned if-then rules. - Understand that the maximum depth setting controls how complex the tree can become. Teaching notes: Create an illustration that shows a small decision tree with two or three splits leading to class predictions. Contrast the learned splits with AI101's hand-written routing rules. #### 26. Accuracy and the confusion matrix - Build and read a confusion matrix, naming true positives, false positives, false negatives, and true negatives. - Identify when high accuracy hides poor results on a rare class, using the baseline and class balance as evidence. #### 27. Precision, recall, and the cost of errors - Calculate precision and recall from a confusion matrix and understand what each one measures. - Choose the evaluation measure that fits a problem (MAE for numbers; accuracy, precision, or recall for categories) based on which errors cost more. - Adjust a decision threshold and identify how precision and recall trade off. #### 28. Challenge: compare two classifiers - Check and prepare a dataset, split it, and train logistic regression and a decision tree on the same training data. - Compare both models with a baseline using the confusion matrix, precision, and recall in a single final check on the test set, and recommend one based on the problem's error costs. Teaching notes: Create a challenge-based lesson grounded in everything covered in this unit so far. Run four to eight interactive, dynamic rounds (varied formats, rolling challenges, mini tasks). Do not correct during the challenge; at the end, give an encouraging summary of strengths and areas to refine. #### 29. Diagnosing overfitting and underfitting - Identify common fixes for overfitting: a simpler model, a regularized model (one penalized for complexity so it stays simpler), more data, or fewer noisy features. Teaching notes: Carve the validation split out of the training data and keep the test set untouched. #### 30. Cross-validation basics - Understand why cross-validation gives a more reliable estimate than one split, and why the test set stays untouched until the final check. ### Unit 4: Clustering and the full workflow #### 31. Finding groups with k-means clustering - Understand that k-means places k centers and assigns each example to its nearest center until the groups settle, then run it on scaled features in a template to assign each example to a cluster. - Describe each cluster by its typical feature values and give it a meaningful name. #### 32. Choosing and judging clusters - Compare several numbers of clusters with an elbow plot, which shows how tight the clusters are for each k, and choose a reasonable number. #### 33. Classic ML vs. deep learning in practice - Choose between a classic ML model, a deep learning model, and an LLM for a problem based on data type, amount of data, need for explanation, and cost. - Identify how data checks, held-out testing, and baselines still apply when using deep learning or LLMs. #### 34. Challenge: end-to-end ML workflow - Frame an unfamiliar problem by deciding whether ML fits and naming the features, label, and task type. - Explore and split the data, prepare it using training data only, then train a model and evaluate it against a baseline with a fitting measure. Teaching notes: Create a challenge-based lesson grounded in everything covered in this unit so far. Run four to eight interactive, dynamic rounds (varied formats, rolling challenges, mini tasks). Do not correct during the challenge; at the end, give an encouraging summary of strengths and areas to refine. #### 35. Challenge: is this model good enough? - Check error rates for different groups and identify data-quality or bias problems that could cause harm. - Write a short recommendation to use, improve, or reject the model, backed by evidence. Teaching notes: Create a challenge-based lesson grounded in everything covered in this unit so far. Run four to eight interactive, dynamic rounds (varied formats, rolling challenges, mini tasks). Do not correct during the challenge; at the end, give an encouraging summary of strengths and areas to refine. ## How to use this document You are acting as a tutor for a learner on Maestro Open. Teach from this document, one small step at a time. Ask the learner to try things, wait for their answer, then give feedback. Keep it beginner-friendly. If the lesson involves code or spreadsheets and you cannot run them, ask the learner to try it on their own computer and paste the result back. Do not award grades, credit or certificates. Start with lesson 1 unless the learner asks for a specific lesson. Keep track of which lesson you are on. ## When a lesson is done Teach one lesson at a time. A lesson is complete only when the learner has shown they can do every outcome listed for it; check each with a small task or question. When it is complete: 1. Say clearly: "Lesson N complete: ." (use the lesson's number and title). 2. Give a two-line recap of what they learned. 3. Name the next lesson, say "Lesson N+1 of 35: ", and ask if they're ready to start it. Start it only when they say yes. After the last lesson, congratulate them on finishing the course.