< AI and Machine Learning Module

Lesson 7: Importing Models in App Lab

45 minutes

Overview

In this lesson students are introduced to importing their models into App Lab and linking their model to their screens. They help create a book recommendation app and learn how to add a welcome screen and events to their code. This lesson assumes students are already familiar with App Lab - for classrooms that have not seen App Lab before, consider extending this lesson and including additional videos or activities that are recommended in the lesson plan.

Question of the Day: How can I create an app using machine learning?

Assessment Opportunities

  1. Create an app that uses machine learning

    Level 6 in Code Studio has a mini-rubric that can be used to assess this objective

  2. Add screens and events in App Lab

    Level 6 in Code Studio has a mini-rubric that can be used to assess this objective

CSTA K-12 Computer Science Standards (2017)
    • 2-AP-13 - Decompose problems and subproblems into parts to facilitate the design, implementation, and review of programs.
    • 3A-AP-16 - Design and iteratively develop computational artifacts for practical intent, personal expression, or to address a societal issue by using events to initiate instructions.
    • 2-IC-21 - Discuss issues of bias and accessibility in the design of existing technologies.

Agenda

Objectives

Students will be able to:
  • Add screens and events in App Lab
  • Create an app that uses machine learning

Preparation

  • Review the Code Studio levels before the lesson so you will be familiar with importing a model into App Lab
  • Decide if you would like to provide additional resources for students to become familiar with App Lab, as outlined in the lesson plan.

Links

Heads Up! Please make a copy of any documents you plan to share with students.

For the teachers
For the students

Teaching Guide

Warm Up (5 minutes)

Pre-Work

Student Survey: Students will be interacting with a survey as part of this lesson. Before class, you can create your own copy of the survey here: click to make a copy. Once you make a copy, you can have students take this version of the survey rather than the generic one in the lesson plan. Interacting with this version of the survey can be more personalized, since students can see data from other students within the class.

App Lab Experience: This is the first lesson where students will use App Lab. If students have not seen App Lab before, you might consider postponing this lesson and instead spending a few extra class periods introducing students to App Lab and Design Mode. Click here to read more about our recommendations for how to introduce students to App Lab.

Journal

Display: A class is interested in making a book recommendation app for new students. The app will ask several questions and, based on the responses, will recommend a book that other people in the class have read.

Prompt: What is a question you think they should ask to help recommend a book?

Have students journal individually, then share their answers with a neighbor. Ask students to share-out with the whole class and keep track of responses at the front of the classroom.

Discussion Goal: Students may suggest that the class ask about other books students have read before, or types of books people like reading. They may also suggest questions based on interest or hobby. Ask students to explain their questions, and listen for responses where students hope to find a relationship between the answers and the book recommendation. For example, someone who is interested in magic may be more likely to read a fantasy book - this is an example where gathering data can be useful in seeing if this relationship will be true.

Digitally Distribute: Have students log into a computer and digitally distribute the Book Recommender Quiz. Once they have completed the quiz, they can click the "See Previous Responses" link to view the data from the quiz.

Teaching Tip

Using Your Own Quiz: Rather than taking the generic survey available to everyone, you can also make a copy of the survey so it contains just data from your classes. To do this, Click Here to make a copy of the survey. You can then use this survey with your students and they will be able to view the results just from their class.

Why Google Forms? Later on in the unit, students will have the opportunity to create their own surveys using Google Forms. Even if you usually use a different survey tool for your classes, we using Google Forms for this lesson since it will help familiarize students with the tool by the time they get to their final project.

Display: Show the slide with the Data --> Model --> App process

Remarks

So far, we've explored how Data can be used to create a Model. Today, we'll see how you can use the Model to create an App that people can use. We're going to help create this Book Recommender app and learn how to use machine learning models in App Lab.

Question of the Day: How can I create an app using machine learning?

Activity (35 minutes)

Survey Analysis (15 minutes)

Code Studio: Have students log into Code Studio. The first contains a working version of the app that students will create today. Have students run the program a few times.

Discuss: What design elements did you see in this app?

Have students brainstorm on their own or record a list in their journals, then invite them to share as a full class.

Discussion Goal: Students will probably notice that buttons, images, and text labels are used extensively. Be sure to remind students that each screen is an element as well. If students are missing any elements, use this as an opportunity to remind students of design mode in App Lab.

Teaching Tip

Design Mode Reminder: If students need a reminder of design mode, you can provide copies of this handout or project it for students:

Discuss: What coding commands would you expect to see in this app?

Have students brainstorm on their own or record a list in their journals, then invite them to share as a full class.

Discussion Goal: Students should predict that onEvent is being used for each button, and that setScreen is used to switch between screens. If students have been through Unit 3 of CS Discoveries, they may also predict that if-statements are used to generate the final answer, but it is okay if this isn’t discussed.

Teaching Tip

Events Reminder: If students need a reminder of events in App Lab, you can provide copies of this handout or project it for students:

Prompt: The app is missing two questions from the survey:

  • Which type of sandwich is your favorite?
  • What kind of day do you like?

Why do you think those questions didn't make it into the model?

Discussion Goal: Guide students towards the conclusion that these questions probably didn't have strong relationships in the data or lead to an accurate model. Students may hypothesize that this is because the questions didn't seem to be related to books, but we'll never know for sure without seeing the actual data.

Prompt: This class considered asking about gender on the survey to help recommend a book, but decided against it.

Do you think there is any harm in including a question about gender in the survey? Why or why not?

Discussion Goal: This is an opportunity to explore how demographic features, like gender or race or age, should or shouldn't be used in machine learning models. Some students may think it's harmless to include gender in the survey, since it may have a strong relation to certain types of books. Other students may bring up how about gender can lead to stereotypes, or how there may not be enough data to be gender inclusive in the survey especially for non-binary students.

Guide students to consider whether or not it feels like the best type of question to ask considering that the class is trying to predict a book recommendation. Have the class consider whether gender feels like a necessary question, or if other questions will also lead to accurate recommendations. In this way, asking about gender is similar to the previous two questions about which sandwich you like or the type of day you're having: the other questions are probably better predictors of what type of book you may read.

Teaching Tip

Additional Resources: Even though including gender on a survey may feel innocent to some students, studies have shown that gender bias can creep into recommendation and selection processes in unintended and unexpected ways. For example, a machine learning algorithm designed to screen job candidates in the tech industry was discovered to be biased against against women and perpetuating stereotypes in the tech industry. Importantly, this phenomenon can exist even without AI and Machine Learning, such as a study showing how gender bias was impacting selection for symphonic orchestras.

If students are interested in this topic, consider having them explore the Survival of the Best Fit game which simulates a similar phenomenon.

Importing a Model (20 minutes)

Code Studio: Have students continue to the next level in Code Studio. Here they will import a model into their app and test that it works correctly. Have them follow the instructions on the screen to import their first model.

Teaching Tip

This Can Be Overwhelming: When models are imported into App Lab, a lot of code is pre-generated and this can be overwhelming. Students may feel nervous about needing to understand everything that’s happened. You may want to reassure students in the following way:

  • Remind students that they already know a lot of what’s happening based on the discussion they just had! All of the design mode elements are familiar, and the code uses the same onEvent blocks they were expecting
  • Assure students that we’ll uncover what most of this code does throughout the unit, and they don’t have to understand every little piece of it right now

Discuss:

  • Can you identify the line where the button press happens?
  • Can you identify where all of our data is collected into a variable?
  • Can you identify the line where our prediction happens?

Have students talk with a partner first before having a full-class discussion. Students will likely be unsure about some of their answers - encourage them to think of these as predictions rather than definite answers.

Discussion Goal: Help students identify the following information:

  • The button press happens on line 2 with the yellow onEvent block
  • The data is collected on lines 3 through 6 with the addPair blocks and the yellow getText blocks
  • The prediction happens on line 8 with the green getPrediction block

Code Studio: Have students continue to the next level. As they progress, they will update the style of their app using Themes and will add a “Welcome Screen” to the app for when a user first loads the app.

Circulate: As students complete these levels, they will continue automatically to keep customizing their apps. Here are some tips for how to support students in each level:

  • Level 3: Students will update the text on their app so it is easier for a user to understand. Instead of the one or two word description from the pre-generated design elements, students will use the same questions they saw in the survey.
  • Level 4: Students will choose a theme to update the design of their app. For now, just have them choose a theme. Later on, they can continue to customize their app with Design Mode
  • Level 5: Students add a home screen to their app. The instructions for this level may be difficult to keep track of - encourage students to “check off” each step as they complete it. They can also use the animated example on the level as a guide for how to complete this task.
  • Level 6: Students add a button from the home screen to the predict screen, and add an event to connect the two screens together. Support students in reading through the instructions and “checking off” each piece as they go along. They can also click the “Show Me How” lines in the instructions for screenshots of what each step can look like.
Assessment Opportunity

Formative Assessment: This level can be used as a formative assessment. A rubric is provided in the level, and written feedback can be given to students. Click here to learn more about giving feedback to students.

Choice Levels: Once students have created their Book Recommender app, they can choose from several example activities to continue improving their app. Each level uses the same Book Recommender app they’ve already built as a template to add to. Students can choose to complete as many of these levels as they would like - each one lets them continue to customize and improve their app.

Teaching Tip

Student Choice and Practice Levels: Having students choose their own practice levels are one way to differentiate instruction with your students. To learn more about how these levels support differentiation, as well as other strategies, you can review the CSD Guide to Differentiation

Wrap Up (5 minutes)

Journal

Prompt:

  1. What was a moment from today where you felt successful?

  2. What is a question or point of confusion you still have from today?

Have students write their responses in their journal. They can also share one of their responses with you as they leave for the day, or you can check their journals later.

Teaching Tip

Formative Assessment: There are a lot of places in this lesson where students may get lost or confused and not feel comfortable speaking up, especially if other students in the class have prior App Lab experience. Use this prompt as a way to determine if you need to check in with students at a later lesson, or revisit a concept from today. This is especially true if students have varied levels of experience with App Lab before this unit.

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.

Creative Commons License (CC BY-NC-SA 4.0).

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.