# Sequential Movie Genre Prediction Using Average Transition Probability with Clustering
## 3 Genre Prediction Algorithm
### Model Training
#### 3.4.3 Subgenre Trimming  
Finally, using the evaluation results of the trained models, we perform a subgenre trimming process based on a predefined threshold of the evaluation metric scores for each cluster. The detailed process is described as pseudocode of Algorithm 1. For this, we first select clusters that do not satisfy the criteria of evaluation metrics.  
```
Input: Set of movie genre matrices \(\mathcal{M}:=\{\mathcal{M}_{i}\}_{i=1}^{k}\) for each cluster \(C_{i}\) with each evaluated value \(P_{e}^{i}\), threshold parameters \(\eta\) and \(\theta\). Output: Subgenre trimmed matrices set \(\mathcal{M}^{{}^{\prime}}:=\{\mathcal{M}_{1}^{{}^{\prime}},\dots,\mathcal{M}_ {k}^{{}^{\prime}}\}\).  Set \(C_{i}^{{}^{\prime}}=\emptyset\) for all \(1\leq i\leq k\); for\(1\leq i\leq k\)do  Set \(|C_{i}|\) as the length (number of movies) of a cluster \(C_{i}\) for each \(i\) and set; \[P_{min}^{i}:=\min_{e\in\mathcal{E}}P_{e}^{i}.\] (18) if\(P_{min}<\eta\)then for\(1\leq j\leq n\)do  Count the number of genre \(j\) in a column of movie genre matrix \(\mathcal{M}_{i}\) and set it to \(g_{j}=\sum_{u\in C_{i}}c_{uj}\). If \(g_{j}<100\times\theta_{i}\), replace all values of the column \(j\) by zero; endfor endif \(\mathcal{M}_{i}^{{}^{\prime}}\leftarrow\mathcal{M}_{i}\); endfor  Return \(\mathcal{M}^{{}^{\prime}}:=\{\mathcal{M}_{1}^{{}^{\prime}},\dots,\mathcal{M}_ {k}^{{}^{\prime}}\}\);
```  
**Algorithm 1** Subgenre trimming.  
More precisely, let \(P_{e}^{i}\) be the value of the evaluation for a performance metric \(e\in\mathcal{E}\) of cluster \(i\), where \(\mathcal{E}\) is a set of performance metrics such as \(\mathcal{E}=\{Precision,Recall,Accuracy\}\).  
Next, we let \(P_{min}^{i}:=\min_{e\in\mathcal{E}}P_{e}^{i}\) be the minimum evaluated value of \(P_{e}\) for all \(e\in\mathcal{E}\). Then, we check the value \(P_{min}^{i}\) for each cluster, and if there exists an evaluation value less than a predefined threshold \(\eta>0\), i.e., \(P_{min}^{i}<\eta\), then we choose the cluster as the target cluster for the subgenre trimming. For example, if we consider the evaluation metrics as precision and recall and the threshold \(\eta\) is given by 0.5, the cluster 3 does not satisfy this as shown in Figure 10. Hence, it is regarded as a target cluster for the subgenre trimming. After selecting target clusters, we find that subgenres that are less than \(\theta_{i}\) percent of the total length (number of movies) of each target cluster \(i\) are trimmed. To do this, let \(\mathcal{M}_{i}=[c_{uj}]_{u\in C_{i},0\leq j\leq n}\) be the movie genre matrix for the cluster \(i\) and let \(\mathcal{M}:=\{\mathcal{M}_{i}\}_{i=1}^{k}\). Then, using the matrix, we find the genres that the number of total sum is less than \(100\times\theta_{i}\), i.e., \(\sum_{u\in C_{i}}c_{uj}<100\times\theta_{i}\). To minimize the data loss, we replace the values as zero rather than deleting them. The reason for this to increase the accuracy of evaluation of clusters that do not have explicit preferences. In the example of Figure 10, the length of the cluster is 100 and \(\theta=0.1\); then, we have \(100\times 0.1=10\). We choose genres that do not have more than 10 data in the cluster such as documentary and war. After these procedures, we finally obtain the subgenre trimmed matrix set \(\mathcal{M}^{{}^{\prime}}:=\{\mathcal{M}_{1}^{{}^{\prime}},\dots,\mathcal{M}_ {k}^{{}^{\prime}}\}\).These matrices are then used to obtain the performance results.