WEBVTT 00:00:01.560 --> 00:00:08.360 To create your simple AI exercise timer,  you’ll train a machine learning (or ML) model.  00:00:08.360 --> 00:00:15.080 This model will recognise when you’re  exercising and when you’re not exercising. 00:00:15.080 --> 00:00:23.720 You’ll then combine the model with some  ready-made code for an exercise timer... 00:00:23.720 --> 00:00:28.720 before downloading it to your  micro:bit and using it in real life. 00:00:28.720 --> 00:00:35.960 Click ‘Open in micro:bit CreateAI’ to launch the project.  00:00:35.960 --> 00:00:40.760 The project comes with 3 samples  of movement data for exercising 00:00:40.760 --> 00:00:45.440 and 3 samples of movement  data for not exercising. 00:00:45.440 --> 00:00:51.000 You’ll need to add more samples by  recording your own movement data. 00:00:51.000 --> 00:00:56.480 micro:bit CreateAI collects movement  data samples using the accelerometer   00:00:56.480 --> 00:01:02.240 (or movement sensor) on the micro:bit. You will wear a micro:bit and battery   00:01:02.240 --> 00:01:08.840 pack on your wrist or ankle, so that you can move  freely to record your own movement data samples.  00:01:08.840 --> 00:01:13.480 To get started, you need to set  up the data collection micro:bit.  00:01:13.480 --> 00:01:22.240 Connect the wrist-worn micro:bit to CreateAI. If your computer has Bluetooth enabled then you   00:01:22.240 --> 00:01:28.680 will just need 1 micro:bit and a USB data lead. If you don’t have a Bluetooth connection,   00:01:28.680 --> 00:01:33.800 you’ll be prompted to use 2 micro:bits. The second micro:bit will remain connected   00:01:33.800 --> 00:01:39.640 to the USB cable and act as a radio  link to the data collection micro:bit. 00:01:39.640 --> 00:01:42.936 Follow the instructions on screen to connect. 00:01:44.495 --> 00:01:47.320 Once your data collection micro:bit is connected 00:01:47.320 --> 00:01:53.280 you’ll see the lines on the live graph  change as you move your micro:bit about. 00:01:53.280 --> 00:01:58.360 You’re now ready to add your  own movement data samples. 00:01:58.360 --> 00:02:04.440 As this project already includes some  data samples, we suggest you just add   00:02:04.440 --> 00:02:12.840 1 more sample for each action for now, and spend  more time collecting and analysing data later. 00:02:12.840 --> 00:02:16.600 Decide what ‘exercising’  action you are going to do.  00:02:16.600 --> 00:02:23.040 This could be running, walking briskly,  jumping, boxing, dancing, or any other exercise.  00:02:23.040 --> 00:02:29.920 Make sure the micro:bit is attached to  the wrist or ankle that will be moving. 00:02:29.920 --> 00:02:34.440 To add data to a specific action,  select it by clicking on it.  00:02:34.440 --> 00:02:39.640 You will get a 3 second countdown  before a 1 second recording starts.  00:02:39.640 --> 00:02:45.200 Click record and start moving right away  to ensure you get a clean data sample.  00:02:45.200 --> 00:02:49.080 A clean sample is one where you  are moving for the entire sample,   00:02:49.080 --> 00:02:55.440 you don’t start late or finish moving early. Next try adding an extra data sample   00:02:55.440 --> 00:03:00.920 to the ‘not exercising’ data set. Select it by clicking on the action,   00:03:00.920 --> 00:03:06.440 then stay still, or only move very  slightly as you record the sample.  00:03:06.440 --> 00:03:10.800 You’ll notice that the x,y,z  lines change places depending   00:03:10.800 --> 00:03:14.768 on the angle at which you hold your micro:bit. 00:03:14.768 --> 00:03:18.320 The project doesn’t have a lot of data right now,  00:03:18.320 --> 00:03:24.400 but we have enough to train our own  machine learning model using CreateAI.  00:03:24.400 --> 00:03:30.360 So click ‘Train’ to use the  current data to build an ML model. 00:03:30.360 --> 00:03:34.640 The tool now builds a mathematical  model that should recognise different   00:03:34.640 --> 00:03:39.360 actions when you move your micro:bit. As soon as the model has been trained,   00:03:39.360 --> 00:03:44.080 you’ll see the Testing model page. Your data collection micro:bit can now   00:03:44.080 --> 00:03:50.160 be used to test how well the model is working. It should still be connected to the tool,   00:03:50.160 --> 00:03:59.800 and you’ll see that as you move it, CreateAI  is estimating what action you are doing. 00:03:59.800 --> 00:04:05.240 Try out different levels of exercising or  not exercising to see both the estimated   00:04:05.240 --> 00:04:12.400 action and the certainty bar graph change. The % on the certainty bar graph shows how   00:04:12.400 --> 00:04:16.840 confident the model is that  you are doing each action. 00:04:16.840 --> 00:04:22.240 You may notice your model is not estimating  some actions accurately, or maybe it is   00:04:22.240 --> 00:04:28.560 working well for one action but not the other, so after exploring how it is currently working,   00:04:28.560 --> 00:04:34.520 it’s a good idea to click on ‘Edit  data samples’ and improve your model. 00:04:34.520 --> 00:04:41.320 Machine learning models usually work best with  more data, so record some extra samples for each   00:04:41.320 --> 00:04:48.800 of the actions, or focus on collecting more data  for the action that was problematic in testing. 00:04:48.800 --> 00:04:54.240 You can record 1 sample at a time or  you can record 10 samples in sequence. 00:04:54.240 --> 00:04:58.840 Clean data samples also  help an ML model work better  00:04:58.840 --> 00:05:05.560 so interrogate your data set and identify any  data samples that could confuse the model.  00:05:05.560 --> 00:05:12.080 You can delete these by pressing x. Once you’ve added more data and checked   00:05:12.080 --> 00:05:17.720 your data set, click Train model  again to use your amended data set.  00:05:17.720 --> 00:05:27.000 Then test the model again on  the ‘Testing model’ page. 00:05:27.000 --> 00:05:30.200 Once you’re happy with how  the ML model is behaving,   00:05:30.200 --> 00:05:34.120 you can use it with the ready-made project code. 00:05:34.120 --> 00:05:40.920 Click on 'Edit in MakeCode' to see the code blocks  in a special version of Microsoft MakeCode. 00:05:40.920 --> 00:05:48.560 You can always return to CreateAI using  the arrow in the top left of the screen. 00:05:48.560 --> 00:05:54.720 These code blocks use the model you  have created within an exercise timer. 00:05:54.720 --> 00:05:59.760 The code uses two variables to keep track  of how long you've been exercising and how   00:05:59.760 --> 00:06:04.160 long you've not been exercising. When the program first runs it sets   00:06:04.160 --> 00:06:09.360 these timer variables to 0. The 'on ML start' blocks are   00:06:09.360 --> 00:06:15.400 triggered when the ML model decides you have  started either exercising or not exercising.  00:06:15.400 --> 00:06:19.240 They show different icons on the  micro:bit's LED display depending   00:06:19.240 --> 00:06:25.920 on the action it has estimated you are doing. The 'on ML stop' blocks are triggered when the   00:06:25.920 --> 00:06:32.960 ML model decides you have finished an action,  in this case exercising or not exercising.  00:06:32.960 --> 00:06:38.240 Code inside each block clears the screen and  adds the duration of the action that has just   00:06:38.240 --> 00:06:43.360 finished to the variable storing  the total times for each action. 00:06:43.360 --> 00:06:49.680 The ML model works with the code to allow you  to view the total time spent on each action.  00:06:49.680 --> 00:06:55.160 Press button A to see the total time you have  been exercising and press button B to see the   00:06:55.160 --> 00:07:00.680 total time you have been inactive. The timer counts in milliseconds,   00:07:00.680 --> 00:07:07.880 thousandths of a second, so the number shown  is divided by 1000 to show a time in seconds. 00:07:07.880 --> 00:07:12.640 To make your simple AI exercise  timer run on your micro:bit, you   00:07:12.640 --> 00:07:19.360 just need to download this code to a micro:bit. If you don’t have another micro:bit available,   00:07:19.360 --> 00:07:26.440 simply replace the code currently on the data  collection micro:bit with the project code. 00:07:26.440 --> 00:07:31.200 Now test the project out in real life. Do the correct icons display   00:07:31.200 --> 00:07:36.640 when you are exercising or not? You can test if the timer code is working   00:07:36.640 --> 00:07:41.640 well with the model in 3 easy steps: Press the reset button. 00:07:41.640 --> 00:07:46.040 Exercise for 30 seconds. Then press button A. 00:07:46.040 --> 00:07:50.080 You should see the number 30  scroll across your display. 00:07:50.080 --> 00:07:55.240 You’re now ready to connect to CreateAI,  collect your own data, use it to train,   00:07:55.240 --> 00:08:00.160 test & improve a machine learning model. And you can then combine this model with   00:08:00.160 --> 00:08:05.642 the ready-made code and try  it out on your own micro:bit.