Lesson 6: Introduction to AI Lab
45 minutes
Overview
In this lesson students will dive into the AI Lab tool for the first time, where they select features to train a model that predicts a given label. They start by exploring AI Lab and training a model to recognize shapes. Then they pretend they have been hired by several restaurants who would like to make recommendations to new customers based on survey data they’re collected, go through each dataset, and use data visualization tools to identify features with high relationships in the data.
Question of the Day: How can we use machine learning to make recommendations?
Assessment Opportunities
-
Use AI Lab to select features to train a model
Each level requires a minimum accuracy score to continue. Checking that students fully complete each level is enough to verify that they have met this objective.
-
Use data visualization tools to decide which features to include when training a model
Check the free responses in the activity guide to assess this objective.
Standards
BI-3 - Computers can learn from data
3-A-i - Nature of Learning - humans vs machines
- 3-A-i.6-8 - Contrast the unique characteristics of human learning with the ways machine learning systems operate.
3-A-iii - Nature of Learning - training a model
- 3-A-iii.6-8 - Train and evaluate a classification or prediction model using machine learning on a tabular dataset
3-C-i - Datasets - feature sets
- 3-C-i.3-5 - Create a labeled dataset with explicit features of several types and use a machine learning tool to train a classifier on this data.
- 3-C-i.6-8 - Create a dataset for training a decision tree classifier or predictor and explore the impact that different feature encodings have on the decision tree.
AP - Algorithms & Programming
- 2-AP-17 - Systematically test and refine programs using a range of test cases.
DA - Data & Analysis
- 3A-DA-12 - Create computational models that represent the relationships among different elements of data collected from a phenomenon or process.
- 3B-DA-05 - Use data analysis tools and techniques to identify patterns in data representing complex systems.
Agenda
Objectives
Students will be able to:
- Use AI Lab to select features to train a model
- Use data visualization tools to decide which features to include when training a model
Preparation
- Review the Code Studio levels before the lesson
- Watch the two videos in this lesson and be familiar with AI Lab
- Print or prepare to share online copies of the activity guide for each student
Links
Heads Up! Please make a copy of any documents you plan to share with students.
For the teachers
- Introduction to AI Lab - Slides
For the students
- Accuracy in AI Lab - Resource
- Introduction to AI Lab - Video
- Selecting Features - Resource
- Training a Model in AI Lab - Activity Guide
- Training and Testing in AI Lab - Video
- Using Data with Categorical Features - Resource
Teaching Guide
Warm Up (5 minutes)
Journal
Prompt: Yesterday we compared fruits based on how sweet they were and how easy they were to eat. What is another feature we could have used to compare foods?
Have students journal individually, then share with a neighbor before having several students share with the class
Discussion Goal: This prompt is meant to bridge yesterday's activity to today's lesson. Have some students share out, but keep this discussion brief so students can move into the widget portion of the warm up.
Code Studio: Have students log into Code Studio. The first level has a Fruit Explorer widget, which recreates some of the experience students had yesterday classifying fruits and veggies by hand.
Model: Read through the directions on the level and demonstrate how the widget works. As you explore the available features, refer back to the discussion especially if some student responses appear in the widget.
Exploring, Not Mastering: This widget has a lot going on and students aren't expected to master how to use it. The complexity of the widget is part of the point - as the lesson continues, students will see how AI Lab can simplify this process of exploring and analyzing data.
Do This: Using the dropdowns to adjust the features, draw a line that creates a model that correctly classifies at least 80% of the fruits and 80% of the veggies. An example is provided of what this can look like.
Overlapping Points: Sometimes a model will look like it's 100% accurate, but may not display as 100% accurate. This is because some points may overlap when they're drawn on the graph. This isn't always easy for students to see, since hovering over the points will only show one of the points. If students are struggling with this, have them watch the graphing process carefully to see the points overlap with each other.
Share Out: Ask students to quickly share out the features they used to create accurate models. Students should be able to find many different combinations of features and many possible lines that can create accurate models.
Remarks
This activity shows how, just adding a few more features and a few additional foods to our data, it becomes much more complex for us to create the same types of models as yesterday. Sometimes this process can become overwhelming as we try to keep track of all of our data and all of our features. Today, we'll learn how machines can make this process easier for us using a new tool called AI Lab
Question of the Day: How can you use AI Lab to create an accurate machine learning model?
Activity (35 minutes)
Recognizing Shapes (20 minutes)
Display: Show the the slide with the grid of 100 images
Discuss: We're going to practice using AI Lab to classify shapes. Based on these images, what are some features you think we can use in AI Lab to train a machine learning model?
Discussion Goal: Encourage students to notice different properties of the shapes. Some of them may be geometric, like number of sides or angle measurements. Also encourage students to identify visual features that a machine learning model might pick up on, like the border color or fill color.
Video: Watch the Introduction to AI Lab (5:25) video as a class.
Videos for Students: Videos are intended to be watched and discussed as a class, and so they are not provided as individual levels in Code Studio. If a student needs to re-watch a video, they can be found in the Help and Tips section of levels or by visiting the Student Resources page of each lesson.
Code Studio: Have students advance to the next level in Code Studio, which has the shapes dataset preloaded. Point out the features that are included in the dataset especially if they match the predictions from the earlier discussion.
Do This: Click on each column and look at the right-panel to notice patterns that AI Bot found in the data. Try to create sentences like "When a AI Bot sees [blank], it tends to be a [blank] shape" Do not press the Train button yet!
Discuss: What types of patterns did AI Bot notice?
Discussion Goal: Hopefully students will notice that the number of sides has a 100% relationship with each shape, which shouldn't be surprising. However, students may also notice additional patterns in the data, for example: small shapes tend to be triangles, or circles are only pink or yellow.
As students share their responses, refer back to the grid of shapes and ask them to notice if they can see the same patterns in the grid. Point out how quickly AI Bot was able to discover patterns, and that we can verify those patterns in the data - for example, when you focus just on the small shapes in the grid, most of them are triangles just like AI Bot identified.
Do This: Using the hot spots in data as a guide, select one or two features to use in your model. Then press the Train button to train your model
Circulate: As students press the train button, they will be taken to the second half of AI Lab - the training, testing, and accuracy screens. Students can explore these screens and may have questions, but reserve explanations for now. Once the majority of the class has trained a model, regroup and continue to the next slide.
Video: Watch the Training and Testing in AI Lab (3:59) video as a class.
Distribute: pass out a copy of Training a Model in AI Lab to each student.
Do This: Explore AI Lab to create models that can classify a shape. You should train multiple models from the same dataset and keep track of the accuracy by filling in the table on your activity guide
Once students have completed the table, regroup for a class discussion
Widget Fluency: For now, focus on helping students become fluent with AI Lab by making sure they can click columns and buttons, focus on appropriate panels, and navigate between screens. Students can also get help by reading the instructions, which update with each panel, or using the Help and Tips section to read help documents or re-watch the video.
Iterating on Features: Students should remain in this same level and not press the Continue button until told to do so. This represents how students will typically use AI Lab with more complex datasets - training multiple models in the same level and comparing accuracy, rather than training a model just once and continuing.
Discuss: This model is trained only on colors and is 90% accurate. What would happen if we tried to use this model in the real-world? Do you think it would be just as accurate?
Discussion Goal: Guide students to realize that just because this dataset has patterns with how the shapes are drawn doesn't mean it will represent shapes in the real world. Students can also verify this by testing the data in AI Lab - it shouldn't feel intuitive that our model can predict a shape just from its size and colors, especially if we tried showing it a wider variety of shapes. Remind students of the video, where high accuracy only means that the model can reproduce patterns in the data and that we - as humans - have control over deciding what features are important.
Human Responsibility in AI: Focusing on our role in selecting data and features for machine learning models foreshadows future lessons where students consider whether it is appropriate to include demographic features, such as race or gender, in machine learning models. Trying to classify a shape based on an unrelated property like its color can be analogous to trying to make a decision where unrelated features like race or gender are taken into consideration. This shouldn't be a focus in this discussion, but it can be helpful to refer back to this moment in later lessons.
Prompt: Training with all possible features created a model that was less accurate than just training on one feature. Why do you think this happened?
Discussion Goal: Students may have a hard time articulating this particular phenomenon, and it's okay to keep this discussion short and not come to a firm conclusions. Instead, use this brief brainstorm to transition to the next slide where it will be easier to explain how this happened.
Misconception Alert: This prompt and the following remarks are directly addressing the misconception that that training with all of the features will lead to the most accurate model. Breaking students of this habit now will lead to more fruitful investigations in future levels as students iterate and experiment in AI Lab to find the best models.
Display: Show the following slide, which has a picture of the shape that AI Bot identified incorrectly and a picture of the shape grid that was used to train AI Bot.
Discuss: Looking at the training data, why did AI Bot think this small brown shape with a red border was a triangle?
Discussion Goal: Encourage students to refer to the training data and see patterns with each of these features individually. For example:
- most small shapes in the training data were triangles with very few squares
- most shapes with a red outline in the training data were triangles with very few squares
- there aren't a lot of brown squares in the training data
If students don't notice these patterns explicitly, that's okay - you can summarize these observations in the remarks below.
Remarks
In this example, AI Bot thought this small brown square with a red border was a triangle. If we look at the rest of the training data, we see a lot of small shapes are triangles, a lot of triangles have red borders, and not a lot of squares are brown. With all these extra features, AI Bot got confused and thought these other patterns were more important than the number of sides. This is why it's important to only use data with a strong relationship to your model and not include extra features that don't have strong relationships.
Restaurant Recommendations (15 minutes)
Display: Show students the next slide, which introduces a new problem of creating recommendations based on user survey data. The class has been hired by a pizza restaurant to help figure out what customers like best based on the toppings they pick.
Code Studio: Have students continue to the next level in Code Studio. If they are on a different panel in AI Lab, they can use the bubbles at the top of their screen and click the next bubble to jump straight to the level.
Do This: Have students train a model to with at least 80% accuracy using the pizza data. They should record their results on their activity guide.
Circulate: Monitor students as they complete this task, focusing on how they are using the cross tab tables to inform their decisions. Students are able to continue to the next level only if they've trained a model with 80% accuracy.
Feature Selection: Now that students are familiar with AI Lab, this dataset emphasizes the decision making process involved with training machine learning models. Students should be using the cross-tab visualizations to make decisions about which features are useful for making recommendations, noticing when features have strong relationships and when features appear “random”. Help students see that choosing all the features or choosing features at random isn’t useful if it leads to an inaccurate model.
Order Matters: Students may discover that the order they select their features can sometimes matter - for example, choosing "peppers, fried chicken" may end up with different accuracy than "fried chicken, peppers". This is not a vital topic for using AI Lab fluently, and happens more often in these early levels because of the smaller dataset sizes. If students ask, one way to think about it is that the first feature represents how AI Bot first tries to separate the data before continuing on to the other features. Therefore: the stronger the relationship is with the first feature you pick, the stronger the patterns AI Bot will find.
Do This: The final level has several choices for datasets that students can investigate. All of them are similar to the ones we just investigated, with different foods available that they can make recommendations for. Students should select a dataset, then investigate how they can train a recommendation model for their situation. They should also keep track of their model on their Activity Guide.
Activity Completeness: It’s important for students to feel like investigators and experimenters as they try to find an accurate machine learning model, which means they may run out of time to finish the activity guide. This is okay, especially if they spend a long time investigating their data and deciding which features to choose. Even if they don't finish, make sure they complete the last question about the strategy they used to select their features.
Wrap Up (5 minutes)
Journal
Prompt: What is one example from today of how humans can influence the machine learning process?
Discussion Goal: Student answers may vary, but may focus on how the choice of data and features is something humans influence when creating a machine learning model. Students may also comment on our role in deciding to use a model even when it's highly accurate, such as with the shapes dataset from the first part of the lesson.
Lesson Feedback
Find a typo? Were some of the directions unclear? Have a suggestion for how to improve the flow of this lesson? We'd love to hear it! Please use the links below to provide feedback on this lesson.
This work is available under a Creative Commons License (CC BY-NC-SA 4.0).
If you are interested in licensing Code.org materials for commercial purposes contact us.