diff --git a/course/sparks-teacher.html b/course/sparks-teacher.html index 97a6220908..29d436c126 100755 --- a/course/sparks-teacher.html +++ b/course/sparks-teacher.html @@ -33,7 +33,7 @@
Perhaps you've heard of "AI": artificial intelligence. AI describes any strategy that helps a computer make smart decisions, like being able to make predictions about the future or being able to recognize the objects in an image.
One way to make a program smarter is to use machine learning: you feed the computer some data, the program learns from the data to build a model of the world, and then the program can make predictions or classifications based on its model of the world.
It sounds a lot like how humans learn about the world, right? Starting from childhood, we see more and more examples of things ("red apple!" "green apple!"), we start to make connections and form an idea in our head, and then we can apply our knowledge to new examples ("oh, a pink apple!"). Of course, we don't always get it right (a peach can be a very confusing fruit for a toddler who's only ever seen apples!). That's true of machine learning too: it's only as good as the data that goes into it and the algorithm that learns from the data.
In this lab, you'll use machine learning to teach a Snap program about the world, going through these sequence of steps:
Here's the question we're hoping our AI can answer: If all the students at your school stood in a line holding hands, how long would it take them to pass a hula hoop from one end of the line to the other?
✏️ First, make your own prediction and write it down on a paper or post-it note. Keep that paper or pass it to your teacher so they can put up all the predictions.
Now you're going to use a computer to answer the question, since it could take a REALLY long time to pass that hula hoop, and you probably can't spend all day in a circle. Plus, if you build a model that answers that question, you could then answer other questions, like other schools, the population of your town, etc.
The plan: You'll do this activity in increasing larger groups in your class, until you have data points for a range of sizes. That will become the input data for the model. The hope is that the model can learn from that data set and make predictions about much larger numbers.
Instructions:
Whenever we build a machine learning model, we need some sort of validation: a test of whether the model has correctly learned about the world. One form of validation is to split the original data into training data and test data, and then checking predictions on the test data to see how close the predictions are to the actual data.
So the sequence of steps is actually more like this:
How many data points should you reserve for the test data set? Often, machine learning engineers do an 80/20 split, keeping 80% of the original data as training data and 20% for validation. Mark a few of the rows in your sheet with stars to indicate that they'll be part of the test data set, at least two rows but not more than 20%. You don't have a lot of data to start off with, so if you reserve too much for the test data, there won't be enough training data!
Download this starter project.
Since your data is just on a piece of paper right now, the first step is to digitize the data.
Your data table is really a collection of data points, where each number of people is the x value and the amount of time taken is the y value. So you'll store it as a list of points in Snap.
Drag a list block into the main area, then drag a point block into the first slot.
Write the data point in that point block, putting the number of people in the first slot and then the time taken in the second slot.
Click on the block and you should see a table that looks like your actual table (but with only one row so far):
By the way, the point block is actually creating a 2-item list (you can peek inside the block definition to see!), but using the point block instead of a list block makes the program much easier to read.
To add the rest of your data, keep following the same process:
You should only be adding the training data points to this first list. Leave out the rows that you're saving as the test data points.
When you're done, clicking on the block should yield a table that looks familiar, minus the test data rows:
Now make another list for the remaining rows that you've designated as the test data.
Oftentimes in programming, we need to be able to reuse a piece of data multiple times. In this case, we're going to be reusing the data points in a few places. Instead of repeating the same list both times, it's more convenient to store the list in a variable. A variable has a name and a value. Once you store some value in a variable, you can simply reference the variable name when you want to use that data again.
To create a variable, click "Make a variable" and type the variable name "training data" in the pop-up. That variable will now show up in the sidebar, so that you can drag its name into any slot. A monitor for that variable will also show up on the stage along with its current value. That can be useful for debugging, but you can also un-select the checkbox to hide the stage monitor.
Now your program has a variable named training data, but it isn't storing any value yet. For that, drag the set variable block into the main area.
Instead of a slot, this block has a dropdown which shows you all the possible variable names in the program. Select "training data" from the dropdown and then drag the list block from earlier into the right-hand slot.
Now do the same for the test data. Make a new variable named "test data", and use another set variable block to store the test data list in that variable.
It's machine learning time! Here's a reminder of the process we're following:
Since we now have the training data stored in a variable, let's build a model based on that data.
First though, make a new variable called "model" to store the model. Drag another set variable block and snap it below the first two. Select "model" from the dropdown.
What about the value? That will be the actual model of the world built by the machine learning algorithm. Drag the build model block into the right-hand slot.
That model has a slot for the training data, which you now have stored in a variable. Instead of dragging the whole list into the slot, drag the variable name from the script variables block into the slot instead.
So, a model is now built, but what is a model really? Let's step back and…
The type of machine learning that we're using in this lab is called linear regression. It only works if there is a linear relationship between the data points - i.e. the amount of time increases at the same rate as the number of people. It learns that rate, and uses it for prediction.
We can visualize how the model works by making a graph of the training data.
Drag the make graph block into the main area. This block takes two input parameters: the first is the training data and the second is the model. Conveniently, those are already stored in variables! Drag the variable names into the block.
Click the whole sequence of blocks to build the model and make the graph. You should see a graph in the stage like this one:
This graph shows the data as blue circles, but it also shows a line that fits those points pretty well. That line represents the model, and the equation of the line can be used to predict the amount of time for *any* number of people.
How good is the model? How accurately can that line predict times for group sizes that were *not* in the training data?
One way to check the quality of the model is to calculate the average error: how far off the predicted value is from the actual value, on average. Drag the calculate average error block into the main area.
The block takes two input parameters, the test data and the model. You've got both of those stored in variables, so just drag the variable names into the slots. Click the block to see the average error. For the sample test data, I got an average error of 2 seconds, which seems pretty reasonable to me.
🤔 What error did you get? Does it feel like a reasonable error to you? You could compare with other groups in the class. If it's not, you may need more training data. There might have been an issue with the timekeeping in your original data or just not enough data points.
Remember the process? We're at the final step! Our program uses basic machine learning to build a model of the world, and we've tested that model on test data to validate that it has an understanding of the world. It's time to make some predictions...
You can make a prediction for any number of people using the prediction block:
Drag the model variable into the first slot and type any value in the second slot. That slot is called the x value, since that's how the number of people is represented on the graph, but for this situation, you can think of it as the number of people. Click the block to see the prediction.
If that prediction seems reasonable, it's time to answer the original question: how long would it take to pass the hula hoop amongst all the students in your school? Put the number of students in the prediction block and check out the result.
Discuss:
Number of people | Time (seconds) |
2 | |
2-DA-09 | Refine computational models based on the data they have generated. A model may be a programmed simulation of events or a representation of how various data is related. In order to refine a model, students need to consider which data points are relevant, how data points relate to each other, and if the data is accurate. For example, students may make a prediction about how far a ball will travel based on a table of data related to the height and angle of a track. The students could then test and refine their model by comparing predicted versus actual results and considering whether other factors are relevant (e.g., size and mass of the ball). Additionally, students could refine game mechanics based on test outcomes in order to make the game more balanced or fair. Practice(s): Creating Computational Artifacts, Developing and Using Abstractions: 5.3, 4.4 |
2-AP-11 | Create clearly named variables that represent different data types and perform operations on their values. A variable is like a container with a name, in which the contents may change, but the name (identifier) does not. When planning and developing programs, students should decide when and how to declare and name new variables. Students should use naming conventions to improve program readability. Examples of operations include adding points to the score, combining user input with words to make a sentence, changing the size of a picture, or adding a name to a list of people. Practice(s): Creating Computational Artifacts: 5.1, 5.2 |
diff --git a/img/4-internet/redundancy-simple.gif b/img/4-internet/redundancy-simple.gif new file mode 100644 index 0000000000..909366586a Binary files /dev/null and b/img/4-internet/redundancy-simple.gif differ diff --git a/img/4-internet/redundancy-simple.psd b/img/4-internet/redundancy-simple.psd new file mode 100644 index 0000000000..dcd82003f7 Binary files /dev/null and b/img/4-internet/redundancy-simple.psd differ diff --git a/sparks/img/U2/decision-tree.png b/sparks/img/U2/decision-tree.png index 4c31358d52..352c7c6471 100644 Binary files a/sparks/img/U2/decision-tree.png and b/sparks/img/U2/decision-tree.png differ diff --git a/sparks/img/U2/lab03/Screen Recording 2024-03-13 at 5.38.27 PM.mov b/sparks/img/U2/lab03/Screen Recording 2024-03-13 at 5.38.27 PM.mov new file mode 100644 index 0000000000..0763e969dc Binary files /dev/null and b/sparks/img/U2/lab03/Screen Recording 2024-03-13 at 5.38.27 PM.mov differ diff --git a/sparks/img/U2/lab03/Screen Shot 2024-03-13 at 6.10.27 PM.png b/sparks/img/U2/lab03/Screen Shot 2024-03-13 at 6.10.27 PM.png new file mode 100644 index 0000000000..f9095f9810 Binary files /dev/null and b/sparks/img/U2/lab03/Screen Shot 2024-03-13 at 6.10.27 PM.png differ diff --git a/sparks/img/U2/lab03/duplicate-block-definition.png b/sparks/img/U2/lab03/duplicate-block-definition.png new file mode 100644 index 0000000000..2bdc3f0509 Binary files /dev/null and b/sparks/img/U2/lab03/duplicate-block-definition.png differ diff --git a/sparks/img/U2/lab03/microphone(spectrum)-reporting.png b/sparks/img/U2/lab03/microphone(spectrum)-reporting.png index c61c2fc1ee..8aa798ddbc 100644 Binary files a/sparks/img/U2/lab03/microphone(spectrum)-reporting.png and b/sparks/img/U2/lab03/microphone(spectrum)-reporting.png differ diff --git a/sparks/img/U2/lab03/oscilloscope-core-1.png b/sparks/img/U2/lab03/oscilloscope-core-1.png index d8e0bdc934..f042df6061 100644 Binary files a/sparks/img/U2/lab03/oscilloscope-core-1.png and b/sparks/img/U2/lab03/oscilloscope-core-1.png differ diff --git a/sparks/img/U2/lab03/oscilloscope-core-2.png b/sparks/img/U2/lab03/oscilloscope-core-2.png index 8f5a7c2caa..993301dffe 100644 Binary files a/sparks/img/U2/lab03/oscilloscope-core-2.png and b/sparks/img/U2/lab03/oscilloscope-core-2.png differ diff --git a/sparks/img/U2/lab03/samplex150.png b/sparks/img/U2/lab03/samplex150.png index 61e2f293da..58c7f4880b 100644 Binary files a/sparks/img/U2/lab03/samplex150.png and b/sparks/img/U2/lab03/samplex150.png differ diff --git a/sparks/img/U2/lab03/set-variable-forever-show-volume-samples.png b/sparks/img/U2/lab03/set-variable-forever-show-volume-samples.png new file mode 100644 index 0000000000..58e30f46dc Binary files /dev/null and b/sparks/img/U2/lab03/set-variable-forever-show-volume-samples.png differ diff --git a/sparks/img/U2/lab03/show-frequencies.png b/sparks/img/U2/lab03/show-frequencies.png new file mode 100644 index 0000000000..cb7b236de6 Binary files /dev/null and b/sparks/img/U2/lab03/show-frequencies.png differ diff --git a/sparks/img/U2/lab03/show-volume-samples-code.png b/sparks/img/U2/lab03/show-volume-samples-code.png deleted file mode 100644 index 12157a743a..0000000000 Binary files a/sparks/img/U2/lab03/show-volume-samples-code.png and /dev/null differ diff --git a/sparks/img/U2/lab03/show-volume-samples-comments.png b/sparks/img/U2/lab03/show-volume-samples-comments.png new file mode 100644 index 0000000000..69d300a424 Binary files /dev/null and b/sparks/img/U2/lab03/show-volume-samples-comments.png differ diff --git a/sparks/img/U2/lab03/show-volume-samples-definition.png b/sparks/img/U2/lab03/show-volume-samples-definition.png new file mode 100644 index 0000000000..c1e6cb8602 Binary files /dev/null and b/sparks/img/U2/lab03/show-volume-samples-definition.png differ diff --git a/sparks/img/U2/lab03/show-volume-samples.png b/sparks/img/U2/lab03/show-volume-samples.png new file mode 100644 index 0000000000..052874b052 Binary files /dev/null and b/sparks/img/U2/lab03/show-volume-samples.png differ diff --git a/sparks/img/U2/lab03/sound-visualizer-with-labels.gif b/sparks/img/U2/lab03/sound-visualizer-with-labels.gif new file mode 100644 index 0000000000..c8a824b357 Binary files /dev/null and b/sparks/img/U2/lab03/sound-visualizer-with-labels.gif differ diff --git a/sparks/img/U2/lab03/spectrum-analyzer-core.png b/sparks/img/U2/lab03/spectrum-analyzer-core.png new file mode 100644 index 0000000000..1b87e62bd7 Binary files /dev/null and b/sparks/img/U2/lab03/spectrum-analyzer-core.png differ diff --git a/sparks/img/U2/lab03/spectrum-analyzer-with-labels.gif b/sparks/img/U2/lab03/spectrum-analyzer-with-labels.gif new file mode 100644 index 0000000000..cdb6e975c8 Binary files /dev/null and b/sparks/img/U2/lab03/spectrum-analyzer-with-labels.gif differ diff --git a/sparks/img/U2/lab03/spectrum-analyzer.gif b/sparks/img/U2/lab03/spectrum-analyzer.gif new file mode 100644 index 0000000000..587ad75343 Binary files /dev/null and b/sparks/img/U2/lab03/spectrum-analyzer.gif differ diff --git a/sparks/img/U2/lab04/attack-router.png b/sparks/img/U2/lab04/attack-router.png new file mode 100644 index 0000000000..917952f4ea Binary files /dev/null and b/sparks/img/U2/lab04/attack-router.png differ diff --git a/sparks/img/U2/lab04/cut-cable.png b/sparks/img/U2/lab04/cut-cable.png new file mode 100644 index 0000000000..24ec3d46b4 Binary files /dev/null and b/sparks/img/U2/lab04/cut-cable.png differ diff --git a/sparks/img/U2/lab04/destroy-router.png b/sparks/img/U2/lab04/destroy-router.png new file mode 100644 index 0000000000..f657349e04 Binary files /dev/null and b/sparks/img/U2/lab04/destroy-router.png differ diff --git a/sparks/img/U2/lab04/initialize-routers.png b/sparks/img/U2/lab04/initialize-routers.png new file mode 100644 index 0000000000..f060f02b3f Binary files /dev/null and b/sparks/img/U2/lab04/initialize-routers.png differ diff --git a/sparks/img/U2/lab04/router-setup.png b/sparks/img/U2/lab04/router-setup.png new file mode 100644 index 0000000000..99e791c32b Binary files /dev/null and b/sparks/img/U2/lab04/router-setup.png differ diff --git a/sparks/img/U2/lab04/router.jpg b/sparks/img/U2/lab04/router.jpg new file mode 100644 index 0000000000..51096a598c Binary files /dev/null and b/sparks/img/U2/lab04/router.jpg differ diff --git a/sparks/img/U2/lab04/send-message.png b/sparks/img/U2/lab04/send-message.png new file mode 100644 index 0000000000..f6c9578771 Binary files /dev/null and b/sparks/img/U2/lab04/send-message.png differ diff --git a/sparks/img/U2/lab05/Lab_ Decision Trees/image10.png b/sparks/img/U2/lab05/Lab_ Decision Trees/image10.png new file mode 100644 index 0000000000..8e978cbd50 Binary files /dev/null and b/sparks/img/U2/lab05/Lab_ Decision Trees/image10.png differ diff --git a/sparks/img/U2/lab05/Lab_ Decision Trees/image11.png b/sparks/img/U2/lab05/Lab_ Decision Trees/image11.png new file mode 100644 index 0000000000..57164e455f Binary files /dev/null and b/sparks/img/U2/lab05/Lab_ Decision Trees/image11.png differ diff --git a/sparks/img/U2/lab05/Lab_ Decision Trees/image13.png b/sparks/img/U2/lab05/Lab_ Decision Trees/image13.png new file mode 100644 index 0000000000..6cc63ca217 Binary files /dev/null and b/sparks/img/U2/lab05/Lab_ Decision Trees/image13.png differ diff --git a/sparks/img/U2/lab05/Lab_ Decision Trees/image15.png b/sparks/img/U2/lab05/Lab_ Decision Trees/image15.png new file mode 100644 index 0000000000..6046a4c682 Binary files /dev/null and b/sparks/img/U2/lab05/Lab_ Decision Trees/image15.png differ diff --git a/sparks/img/U2/lab05/Lab_ Decision Trees/image16.png b/sparks/img/U2/lab05/Lab_ Decision Trees/image16.png new file mode 100644 index 0000000000..a5e39c0941 Binary files /dev/null and b/sparks/img/U2/lab05/Lab_ Decision Trees/image16.png differ diff --git a/sparks/img/U2/lab05/Lab_ Decision Trees/image17.png b/sparks/img/U2/lab05/Lab_ Decision Trees/image17.png new file mode 100644 index 0000000000..dca598124e Binary files /dev/null and b/sparks/img/U2/lab05/Lab_ Decision Trees/image17.png differ diff --git a/sparks/img/U2/lab05/Lab_ Decision Trees/image18.png b/sparks/img/U2/lab05/Lab_ Decision Trees/image18.png new file mode 100644 index 0000000000..3201420ef8 Binary files /dev/null and b/sparks/img/U2/lab05/Lab_ Decision Trees/image18.png differ diff --git a/sparks/img/U2/lab05/Lab_ Decision Trees/image2.png b/sparks/img/U2/lab05/Lab_ Decision Trees/image2.png new file mode 100644 index 0000000000..cd1317c666 Binary files /dev/null and b/sparks/img/U2/lab05/Lab_ Decision Trees/image2.png differ diff --git a/sparks/img/U2/lab05/Lab_ Decision Trees/image20.png b/sparks/img/U2/lab05/Lab_ Decision Trees/image20.png new file mode 100644 index 0000000000..90d27f9ac8 Binary files /dev/null and b/sparks/img/U2/lab05/Lab_ Decision Trees/image20.png differ diff --git a/sparks/img/U2/lab05/Lab_ Decision Trees/image21.png b/sparks/img/U2/lab05/Lab_ Decision Trees/image21.png new file mode 100644 index 0000000000..b93273a2a2 Binary files /dev/null and b/sparks/img/U2/lab05/Lab_ Decision Trees/image21.png differ diff --git a/sparks/img/U2/lab05/Lab_ Decision Trees/image23.png b/sparks/img/U2/lab05/Lab_ Decision Trees/image23.png new file mode 100644 index 0000000000..47ba5c77ae Binary files /dev/null and b/sparks/img/U2/lab05/Lab_ Decision Trees/image23.png differ diff --git a/sparks/img/U2/lab05/Lab_ Decision Trees/image24.png b/sparks/img/U2/lab05/Lab_ Decision Trees/image24.png new file mode 100644 index 0000000000..9a3aa52e09 Binary files /dev/null and b/sparks/img/U2/lab05/Lab_ Decision Trees/image24.png differ diff --git a/sparks/img/U2/lab05/Lab_ Decision Trees/image26.png b/sparks/img/U2/lab05/Lab_ Decision Trees/image26.png new file mode 100644 index 0000000000..61ef9596c7 Binary files /dev/null and b/sparks/img/U2/lab05/Lab_ Decision Trees/image26.png differ diff --git a/sparks/img/U2/lab05/Lab_ Decision Trees/image3.png b/sparks/img/U2/lab05/Lab_ Decision Trees/image3.png new file mode 100644 index 0000000000..eb580f103b Binary files /dev/null and b/sparks/img/U2/lab05/Lab_ Decision Trees/image3.png differ diff --git a/sparks/img/U2/lab05/Lab_ Decision Trees/image5.png b/sparks/img/U2/lab05/Lab_ Decision Trees/image5.png new file mode 100644 index 0000000000..3faacdeddf Binary files /dev/null and b/sparks/img/U2/lab05/Lab_ Decision Trees/image5.png differ diff --git a/sparks/img/U2/lab05/Lab_ Decision Trees/image6.png b/sparks/img/U2/lab05/Lab_ Decision Trees/image6.png new file mode 100644 index 0000000000..4e0b87e784 Binary files /dev/null and b/sparks/img/U2/lab05/Lab_ Decision Trees/image6.png differ diff --git a/sparks/img/U2/lab05/Lab_ Decision Trees/image8.png b/sparks/img/U2/lab05/Lab_ Decision Trees/image8.png new file mode 100644 index 0000000000..f572fdb80f Binary files /dev/null and b/sparks/img/U2/lab05/Lab_ Decision Trees/image8.png differ diff --git a/sparks/img/U2/lab05/Lab_ Decision Trees/image9.png b/sparks/img/U2/lab05/Lab_ Decision Trees/image9.png new file mode 100644 index 0000000000..6ca7b7e91d Binary files /dev/null and b/sparks/img/U2/lab05/Lab_ Decision Trees/image9.png differ diff --git a/sparks/img/U2/lab05/Lab_ Machine learning (Linear regression)/LabMachinelearning_Linearregression_.html b/sparks/img/U2/lab05/Lab_ Machine learning (Linear regression)/LabMachinelearning_Linearregression_.html new file mode 100644 index 0000000000..1a2a42e139 --- /dev/null +++ b/sparks/img/U2/lab05/Lab_ Machine learning (Linear regression)/LabMachinelearning_Linearregression_.html @@ -0,0 +1 @@ +