Crowdsource Predictive Analytics - Netflix Data
Solution :
Library Installation:
To install required library files, Open Command Prompt or Terminal and execute the following commands
$ pip install surprise
PROGRAM: (CROWD_SOURCE.py)
from surprise import Dataset, SVD
from surprise.model_selection import train_test_split
from surprise.accuracy import rmse
# Load dataset (example: MovieLens)
data = Dataset.load_builtin('ml-100k')
trainset, testset = train_test_split(data, test_size=0.2, random_state=42)
# Initialize SVD model
model = SVD()
model.fit(trainset)
# Make predictions
predictions = model.test(testset)
# Evaluate RMSE
rmse(predictions)
# Show sample predictions
print("\nSample Predictions (userID, itemID, actual rating, predicted rating):")
for pred in predictions[:10]:
print(f"{pred.uid}, {pred.iid}, {pred.r_ui} => {round(pred.est, 2)}")
OUTPUT:
Dataset ml-100k could not be found. Do you want to download it? [Y/n] Y
Trying to download dataset from https://files.grouplens.org/datasets/movielens/ml-100k.zip...
Done! Dataset ml-100k has been saved to C:\Users\madhu/.surprise_data/ml-100k
RMSE: 0.9347
Sample Predictions (userID, itemID, actual rating, predicted rating):
907, 143, 5.0 => 4.78
371, 210, 4.0 => 4.21
218, 42, 4.0 => 3.62
829, 170, 4.0 => 3.99
733, 277, 1.0 => 3.31
363, 1512, 1.0 => 3.02
193, 487, 5.0 => 3.86
808, 313, 5.0 => 5
557, 682, 2.0 => 2.89
774, 196, 3.0 => 2.24
๐ป Run This Python Program
Crowdsource Predictive Analytics - Netflix Data
The selected Python program is loaded
automatically into the editor.
Edit the program, provide input through
STDIN if required
and click Run.
The compiler is embedded using OneCompiler.
Your Python program runs inside the embedded
Python environment; Study Glance does not execute
Python code directly on your web server.
If the program asks for input, type the value in the
STDIN box before clicking Run.
These programs use libraries such as NumPy, Pandas,
Matplotlib, scikit-learn, SciPy and statsmodels, and
graph windows (
plt.show()) cannot be displayed
here. The data files shown in the lesson (CSV) are loaded
into the editor automatically. If a library is not
available in the embedded compiler, use
Copy Program and run the program on your
computer (after pip install of the libraries)
or in Google Colab.