# How do I decide on my X and Y variables for the prediction of a coin toss?

So I'm new to data science and was trying to solve a few problems that my mentor gave to me. I came across this question where there are multiple coin tosses and ten of them are recorded. I am supposed to create a model that can predict the outcome of another coin toss.

I have attached an example of what the dataset could look like. [1]: https://i.stack.imgur.com/WsBve.png

I was trying to convert all Head to 1 and all Tail to 0 and then apply simple linear regression (as a starting point) but was very confused as to what my X and Y variable would be. Currently, I am not splitting the dataset into training and test sets since the dataset is relatively small.

Thanks in advance!

• What a strange problem for your mentor to give you - one cannot predict coin tosses. The whole point of a coin toss is that it is an unpredictable, independent trial. There shouldn't be any features (X) that you can use to predict whether you get heads or tails (Y). If there are, the trials are not independent and identically distributed, and aren't very well described as a "series of coin tosses". All you can really do is guess the most prevalent outcome you've seen, under the supposition that the coin is actually biased toward that face. Jun 22 at 18:43
• What else do you record besides the outcome of the coin toss? All I would do is note the proportion of heads and tails and guess whichever came up more often.
– Dave
Jun 22 at 18:43

## 2 Answers

From what was described, I would not use machine learning for this task. Just statistics. Take a look at the binomial distribution. Not knowing all of your data, I cannot solve the problem for you, but that is what your mentor is asking you do to. My guess is the data shows biased coins.

This type of problem is classification not regression. Simple linear regression would not be the algorithm to use.

My first thought was to calculate the probability of getting heads and the probability of getting tails (which would be $$1-P(\text{heads})$$). You then could use this to make your best guess about the next coin flip. If you get $$P(\text{heads})>0.5$$, you might be tempted to guess that the next flip will land as a heads. In the absence of more information, this works, but for a more complicated scenario (say disease detection), you might find one type of mistake less acceptable than another, so you might set a different threshold. This gets into ideas about probabilistic predictions (not hard classifications), proper scoring rules, and decision theory.

Then I looked at your attached image, and I have another idea. You have different coins being flipped. Yes, you could use the overall probability to make your guess, but the coins do not all have to have the same probability of landing with heads up. You could then use the outcome ($$0$$ for heads, $$1$$ for tails) as your $$Y$$ variable, and the coin as your $$X$$ variable. This would be akin to ANOVA, granted for more of a prediction purpose than ANOVA tends to be used (and also some kind of generalized linear model instead of the linear model, but that discussion warrants a separate question).

This can be fit with a logistic regression, shown in R code below.

coin <- as.factor(rep(1, 5), rep(2, 5), rep(3, 5), rep(4, 5), rep(5, 5))
flip_outcome <- c(0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1)
L <- glm(flip_outcome ~ coin, family = binomial)


You will have poor predictive ability with so few flips, but this is a fine toy example.

• This ignores any possible time dependence between the flips. I am comfortable making that assumption here. There may be situations where that is a poor assumption.
– Dave
Jun 23 at 15:10