# Session-Based Recommendations for e-Commerce with Graph-Based Data Modeling
## 3 Recommendation Methods
### Recurrent Item Co-Occurrence Algorithm  
Whereas HSP is based primarily on the _Next_ relationship to determine the list of recommended items, our second proposed method is based primarily on the _InSameSession_ relationship, which neglects the relative position of the items in the session. Let \(\mathcal{I}=\{o_{1},\ldots,o_{N}\}\) be the set of all the items. Given a current item \(x\) we define the confidence weight \(\gamma(x|o_{i})\) of any other item \(o_{i}\) as the ratio of all the _InSameSession_ relations involving both \(x\) and \(o_{i}\) divided by the number of the _ItemInSession_ relations involving \(x\) and any session \(s\):  
\[\gamma(o_{i}|x)=\frac{\text{count}(\textit{InSameSession}(x,o_{i}))}{\text{ count}(\textit{ItemInSession}(x,s))}. \tag{4}\]  
This is equivalent to the confidence value \(\text{conf}(x\Rightarrow o_{i})\) of the association rule \(x\Rightarrow o_{i}\)[32]:  
\[\text{conf}(x\Rightarrow o_{i}) =P(s\
i o_{i}|s\
i x)=\frac{P\big{(}(s\
i x)\cap(s\
i o_{i})\big{)} }{P(s\
i x)}\] \[=\frac{\text{number of sessions containing both $x$ and $o_{i}$}}{\text{number of sessions containing $x$}}. \tag{5}\]  
A naive approach would be to build the recommendation list by simply sorting items by decreasing confidence \(\gamma(o_{i}|x)\). This approach, however, has two major drawbacks:  
1. it poorly treats the case where there is no co-occurrence of \(x\) and \(o_{i}\) in any session. As it happens, this is a very common situation where, obviously, \(\gamma(o_{i}|x)=0\). Since all such items are put in the same ranking position, they will be randomly sorted;
2. it is a memoryless approach since the recommendation list is built based solely on \(x\), ignoring any other items viewed prior to \(x\). To alleviate these problems, we define a new confidence value \(c_{i}\) for item \(o_{i}\) which is equal to \(\gamma(o_{i}|x)\) if \(x\) and \(o_{i}\) co-occur in at least one session; otherwise, \(c_{i}\) is equal to the cold-start probability \(P_{0}(o_{i})\) defined in Equation (1):  
\[c_{i}=\left\{ \begin{array}{ll}\gamma(o_{i}|x)&\text{if $\gamma(o_{i}|x)>0$}\\ P_{0}(o_{i})&\text{otherwise}\end{array} \right. \tag{6}\]  
With this approach, items with no history of co-occurrence with \(x\) are placed in decreasing cold-start probability. In order to introduce memory to the system, we further propose a simple, first order recurrent model that generates the item weights which will be used to build the recommendation list. Let \(x=item_{t}\) be the item viewed at step \(t\) in some session \(s\) and \(c_{i}(t)\) be  
Figure 2: The flowchart of the proposed Hierarchical Sequence Probability (HSP) algorithm. Whenever appending an item in the recommendation list, we make sure it is not already included to avoid duplicate recommendations. the confidence value of any item \(o_{i}\) based on \(item_{t}\) as described in Equation (6). Then, the weight \(w_{i}(t)\) of this item at time \(t\) will be defined by the recurrent model:  
\[w_{i}(t)=\alpha w_{i}(t-1)+(1-\alpha)c_{i}(t). \tag{7}\]  
The initial condition is again the cold-start probability \(w_{i}(0)=P_{0}(o_{i})\). The recommendation list at any time step \(t\) is built using the top \(n\) items with the largest weights \(w_{i}(t)\). Since the weights are computed independently for different items, the process can be easily parallelized using the vectors \(\mathbf{w}_{t}=[w_{1}(t),\ldots,w_{N}(t)]\), \(\mathbf{c}_{t}=[c_{1}(t),\ldots,c_{N}(t)]\), where now: \(\mathbf{w}_{t}=\alpha\mathbf{w}_{t-1}+(1-\alpha)\mathbf{c}_{t}\). The parameter \(1-\alpha\) (\(0\leq\alpha\leq 1\)) is the \"forgetting factor,\" which determines the memory length of the system. For \(1-\alpha=0\) the system has infinite memory, the confidence \(c_{i}(t)\) based on \(item_{t}\) is ignored and \(w_{i}(t)\) maintains a constant initial value through-out the session. If \(1-\alpha=1\) the model becomes memoryless and \(w_{i}(t)=c_{i}(t)\).