# Expectation of sum is less than the second moment

Given $$E[f^2(X)] < \infty$$ and $$X_i \sim_{iid} X$$, need to show $$E\left[ \frac{1}{n} \left( \sum_{i=1}^{n} (f(X_i) - E[f(X)] \right)^2 \right] \leq E[f^2(X)].$$

My try:

$$E\left[ \frac{1}{n} \left( \sum_{i=1}^{n} (f(X_i) - E[f(X)] \right)^2 \right] = \frac{1}{n}E\left[ \left( \sum_{i=1}^{n} f(X_i) \right)^2 - n E[f(X)] \sum_{i=1}^{n} f(X_i) \right].$$

Now applying Cauchy-Schwarz inequality to the first term we get, $$E\left[ \frac{1}{n} \left( \sum_{i=1}^{n} (f(X_i) - E[f(X)] \right)^2 \right] \leq n \cdot Var[f(X)] .$$

I am not able to get rid of $$n$$ on RHS. Any help to fix this is appreciated!

The trick is that your random variables $$X_i$$ are independent, so that $$E[(f(X_i)-m)(f(X_j)-m)]=E[f(X_i)-m]E[f(X_j)-m]=0,$$ where $$m=E[X]$$.
This shows that $$E\left[\frac1n\left(\sum_if(X_i)-E[f(X)]\right)^2\right]=\frac1n\sum_iE\left[\left(f(X_i)-E[f(X)]\right)^2\right]=\mathrm{Var}(f(X)).$$