Week 5 practice
Prediction modelling
In Week 5 Workshop we are introducing classification and regression models for prediction.
What is random?
In the week 4 interactable code we introduced the idea of random sampling when we generated a dataset of clusters.
Setting a seed in random number generation will ensure that the sequence of numbers generated by the random number generator is reproducible.
Here are examples:
Randomly sampling a number between 0 and 1
runif will randomly select from a uniform distribution (random uniform). runif(1) will generate a random number with equal probability from a uniform distribution between 0 and 1. Try changing the seeds
Randomly sampling in sequence
The seed initialises the random number generator to a known state. Each time a seed is set to the same value, the sequence of random numbers generated after that point will be the same.
Try changing the seeds:
Random and regular fields of points
The random field of points from Lecture 5. d1 is random points from the random uniform distribution:
To create the evenly distributed bit (d2), you have to start with an even grid of points:
Then add a little bit of random noise to it:
Paste them together and plot it:
Coin flips
We haven’t set a seed here - each time you run this cell, you will get different results. Try setting a seed.
Roll a dice
We’ve set our seed to the current time! Why might we do this?
The default random number generator for R is the Mersenne-Twister. https://en.wikipedia.org/wiki/Mersenne_Twister