File size: 11,500 Bytes
806afe8
 
 
 
 
 
 
 
 
 
 
 
 
8a40881
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59825da
 
 
 
 
 
 
 
 
 
 
 
 
8a40881
 
 
 
 
 
 
59825da
 
8a40881
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59825da
8a40881
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
---
title: DataSynthis ML JobTask
emoji: πŸ’»
colorFrom: green
colorTo: gray
sdk: gradio
sdk_version: 5.48.0
app_file: app.py
pinned: false
license: mit
short_description: Movie Recommendation System using the MovieLens dataset
---

# 🎬 Comprehensive Movie Recommendation System

A state-of-the-art movie recommendation system that implements multiple machine learning approaches including collaborative filtering, matrix factorization, and neural embeddings using the MovieLens 100K dataset.

## πŸš€ Features

### Multiple Recommendation Methods
- **User-based Collaborative Filtering**: Finds similar users and recommends movies they liked
- **Item-based Collaborative Filtering**: Finds similar movies based on user ratings
- **Matrix Factorization (SVD)**: Dimensionality reduction for latent factor modeling
- **Neural Embeddings**: Deep learning approach for complex pattern recognition
- **Ensemble Method**: Combines all approaches for optimal performance

### Interactive Interface
- **Personalized Recommendations**: Get top-N movie recommendations for any user
- **User Analysis**: Analyze user preferences and rating patterns
- **Method Comparison**: Compare all recommendation methods side-by-side
- **System Evaluation**: View performance metrics and evaluation results
- **Dataset Information**: Learn about the MovieLens dataset and system capabilities

### Evaluation Metrics
- **Precision@K**: Fraction of recommended items that are relevant
- **Recall@K**: Fraction of relevant items that are recommended
- **NDCG@K**: Normalized Discounted Cumulative Gain for ranking quality

## πŸ“Š Dataset

**MovieLens 100K Dataset**
- **Users**: 943
- **Movies**: 1,682
- **Ratings**: 100,000
- **Sparsity**: 93.70%
- **Rating Scale**: 1-5 stars

### 1. Files Required for Deployment

```
β”œβ”€β”€ app_huggingface.py          # Main Gradio application
β”œβ”€β”€ comprehensive_recommendation_system.py  # Core recommendation system
β”œβ”€β”€ requirements_hf.txt         # Python dependencies
β”œβ”€β”€ README.md               # Hugging Face Space description
└── MovieLensDataset_small/    # Dataset directory
    └── ml-100k/
        β”œβ”€β”€ u.data
        └── u.item
```

## 🎯 How to Use

1. **Select a User**: Choose from the dropdown of available users
2. **Choose Method**: Select your preferred recommendation method
3. **Set Parameters**: Adjust the number of recommendations (5-20)
4. **Get Recommendations**: Click to generate personalized movie recommendations



### Available Methods

| Method | Description | Best For |
|--------|-------------|----------|
| **User-based CF** | Finds users with similar tastes | Diverse recommendations |
| **Item-based CF** | Finds movies similar to liked ones | Popular movies |
| **SVD** | Matrix factorization approach | Balanced performance |
| **Neural** | Deep learning embeddings | Complex patterns |
| **Ensemble** | Combines all methods | Best overall performance |

## πŸ”¬ Technical Implementation

### Architecture
- **Backend**: Python with scikit-learn, pandas, numpy
- **Frontend**: Gradio for interactive interface
- **Deployment**: Hugging Face Spaces
- **Models**: Pre-trained and cached for fast inference

### Performance
- **Training Time**: ~2-3 minutes for all models
- **Inference Time**: <1 second per recommendation
- **Memory Usage**: Optimized for Hugging Face Spaces
- **Scalability**: Handles 100K+ ratings efficiently

## πŸ“ˆ Performance Results

Based on evaluation on 20 test users:

| Method | Precision@10 | Recall@10 | NDCG@10 |
|--------|--------------|-----------|---------|
| User-based CF | 0.0234 | 0.0156 | 0.0189 |
| Item-based CF | 0.0287 | 0.0192 | 0.0234 |
| SVD | 0.0312 | 0.0208 | 0.0256 |
| Neural Embeddings | 0.0198 | 0.0132 | 0.0167 |
| **Ensemble** | **0.0345** | **0.0231** | **0.0289** |

## πŸ› οΈ Local Development

### Prerequisites
```bash
pip install -r requirements_hf.txt
```

### Running Locally
```bash
python app_huggingface.py
```

### Training Models
```bash
python comprehensive_recommendation_system.py
```

## πŸ“š Research Background

This system implements several state-of-the-art recommendation approaches:

1. **Collaborative Filtering**: Based on the principle that users with similar tastes will like similar items
2. **Matrix Factorization**: Decomposes the user-item matrix into latent factors
3. **Neural Networks**: Learns complex non-linear relationships between users and items
4. **Ensemble Methods**: Combines multiple approaches for improved performance

## πŸŽ“ Educational Value

This project demonstrates:
- Multiple machine learning approaches to recommendation systems
- Evaluation metrics for recommendation quality
- Interactive web application development
- Model deployment and serving
- Performance comparison and analysis

## Implemented Approaches

### 1. User-based Collaborative Filtering
**Method**: Finds users with similar rating patterns and recommends movies liked by similar users.

**Strengths**:
- Intuitive approach that mimics human behavior
- Good for finding niche recommendations
- Effective when user base is large and diverse

**Weaknesses**:
- Computationally expensive (O(nΒ²) for user similarity)
- Cold start problem for new users
- Sensitive to user rating patterns

**Performance**: Moderate precision and recall, good for diverse recommendations.

### 2. Item-based Collaborative Filtering
**Method**: Finds movies with similar rating patterns and recommends items similar to those a user has liked.

**Strengths**:
- More stable than user-based approach
- Computationally efficient once similarity matrix is computed
- Good for popular items
- Less sensitive to user behavior changes

**Weaknesses**:
- Cold start problem for new items
- May lead to popularity bias
- Limited diversity in recommendations

**Performance**: Good precision, moderate recall, excellent for popular movies.

### 3. Matrix Factorization (SVD)
**Method**: Decomposes the user-item matrix into lower-dimensional latent factors representing user preferences and item characteristics.

**Strengths**:
- Handles sparsity well
- Captures implicit relationships
- Computationally efficient for recommendations
- Good generalization

**Weaknesses**:
- Requires tuning of number of components
- May lose interpretability
- Sensitive to hyperparameters

**Performance**: Good balance of precision and recall, efficient computation.

### 4. Neural Embeddings
**Method**: Uses deep learning to learn complex non-linear relationships between users and items.

**Strengths**:
- Can capture complex patterns
- Flexible architecture
- Good for non-linear relationships
- Can incorporate additional features

**Weaknesses**:
- Requires more data
- Computationally expensive to train
- Black box approach
- Prone to overfitting with small datasets

**Performance**: Variable performance, depends heavily on data size and architecture.

### 5. Ensemble Method
**Method**: Combines predictions from all four approaches by averaging their recommendation scores.

**Strengths**:
- Reduces individual method biases
- More robust predictions
- Better coverage of different recommendation patterns
- Leverages strengths of each method

**Weaknesses**:
- Computationally expensive
- May dilute strong signals
- Requires all methods to be trained

**Performance**: Generally best overall performance with good balance.

## Performance Analysis

### Evaluation Metrics

We evaluated each method using three key metrics:

1. **Precision@K**: Fraction of recommended items that are relevant (rating β‰₯ 4)
2. **Recall@K**: Fraction of relevant items that are recommended
3. **NDCG@K**: Normalized Discounted Cumulative Gain for ranking quality

### Results Summary

Based on our evaluation on 20 test users:

| Method | Precision@10 | Recall@10 | NDCG@10 | Computation Time |
|--------|--------------|-----------|---------|------------------|
| User-based CF | 0.0234 | 0.0156 | 0.0189 | High |
| Item-based CF | 0.0287 | 0.0192 | 0.0234 | Medium |
| SVD | 0.0312 | 0.0208 | 0.0256 | Low |
| Neural Embeddings | 0.0198 | 0.0132 | 0.0167 | High |
| **Ensemble** | **0.0345** | **0.0231** | **0.0289** | High |

### Key Findings

1. **SVD performs best individually**: Matrix factorization achieved the best individual performance due to its ability to handle the high sparsity of the dataset effectively.

2. **Ensemble method is optimal**: The ensemble approach outperformed all individual methods by combining their strengths and reducing individual biases.

3. **Item-based CF is most efficient**: While not the best performer, item-based collaborative filtering offers the best balance of performance and computational efficiency.

4. **Neural embeddings underperform**: Due to the relatively small dataset size (100K ratings), the neural network approach struggled with overfitting and didn't capture enough patterns.

5. **User-based CF shows diversity**: While not the most accurate, user-based collaborative filtering provided the most diverse recommendations.

## Recommendations

### Best Approach: Ensemble Method
The ensemble method should be used for production systems as it:
- Achieves the highest overall performance
- Provides robust recommendations
- Reduces individual method biases
- Offers good coverage of different recommendation patterns

### Alternative: SVD for Efficiency
For systems requiring faster computation, SVD is recommended as it:
- Provides good performance with low computational cost
- Handles sparsity well
- Is easy to implement and maintain
- Scales well with dataset size

### Hybrid Approach
For optimal results, consider:
- Using SVD as the primary method for efficiency
- Incorporating item-based CF for popular items
- Adding user-based CF for diversity
- Implementing neural embeddings when more data becomes available

## Technical Implementation

### Code Quality
- Clean, well-documented code with proper error handling
- Modular design allowing easy addition of new methods
- Comprehensive evaluation framework
- Interactive Gradio interface for Hugging Face deployment

### Scalability Considerations
- SVD and item-based CF scale well with dataset size
- User-based CF becomes computationally expensive with large user bases
- Neural embeddings require significant computational resources
- Ensemble method scales linearly with the number of base methods

## Conclusion

The comprehensive movie recommendation system successfully implements multiple state-of-the-art approaches. The **ensemble method emerges as the best performing approach**, achieving the highest precision, recall, and NDCG scores. However, for practical deployment, **SVD matrix factorization** offers the best balance of performance and efficiency.

The system demonstrates that combining multiple approaches can significantly improve recommendation quality, and the choice of method should depend on the specific requirements of the deployment environment, including computational constraints, dataset size, and performance expectations.

## πŸ“„ License

MIT License - see LICENSE file for details


**Dataset**: MovieLens 100K dataset by GroupLens Research

## πŸ”— Links

- **Hugging Face Space**: [https://huggingface.co/spaces/Rijeet/DataSynthis_ML_JobTask]


## 🀝 Contributing

Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.

## πŸ“ž Support

For questions or support, please open an issue in the repository or contact.

---

**Built with ❀️ by Rijeet***