% Define block styles
\tikzstyle{connector} = [diamond, draw, fill=blue!20, 
    text width=4.5em, text badly centered, node distance=0cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=lightgray, 
    text width=15em, text centered, rounded corners, minimum height=2em]
\tikzstyle{line} = [draw]
\tikzstyle{arrow} = [draw, -latex']

\begin{tikzpicture}[node distance=2cm, auto]
    % Place nodes
    \node [block] (f0) {Define a rating estimator $\mu$ algorithm and a error estimator algorithm $\sigma$.};
    \node [block, below of=f0] (f01) {Split the data into F folds $R^1, ..., R^F$. Let $R^{-f}$ denote the data excluding the $f$-th fold.};
    \node [block, below of=f01, node distance=2.3cm] (f1) {For $f \in 1,...,F$, train $\mu$ on $R^{-f}$, then predict $R^f$ and store the errors $\epsilon_{ui} = r_{ui} - \hat{r}^f_{ui} \forall (u, i, r_{ui}) \in R^f$.};
    \node [block, below of=f1, node distance=2.3cm] (f2) {The error estimator $\sigma$ is then trained on the errors (all folds joint).};
    \node [block, below of=f2] (f3) {Finally, train the rating estimator $\mu$ with the whole training ratings data.};
    \node [connector, left of=f1, node distance=4cm] (c0) {Training phase};
    
    \node [block, below of=f3, node distance=3cm] (p0) {Given a user-item pair $(u,\,i)$, calculate the rating predictions $\hat{r}_{ui}$ using $\mu$.};
    \node [block, below of=p0] (p1) {Calculate the error prediction $\hat{\epsilon}_{ui}$ using $\sigma$.};
    \node [block, below of=p1] (p2) {$\{\hat{r}_{ui}, \,\, \hat{\epsilon}_{ui}\}$ is a uncertain prediction for the user-item interaction.};
    \node [connector, left of=p1, node distance=4cm] (c1) {Prediction phase};
    
    % Draw edges
    \path [arrow] (f0) -- (f01);
    \path [arrow] (f01) -- (f1);
    \path [arrow] (f1) -- (f2);
    \path [arrow] (f2) -- (f3);
    \path [arrow] (p0) -- (p1);
    \path [arrow] (p1) -- (p2);
    \path [line] (c0) |- (f0);
    \path [line] (c0) |- (f3);
    \path [line] (c1) |- (p0);
    \path [line] (c1) |- (p2);
\end{tikzpicture}