-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain_model.py
More file actions
27 lines (14 loc) · 767 Bytes
/
train_model.py
File metadata and controls
27 lines (14 loc) · 767 Bytes
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
import pandas as pd
import pickle
from surprise import SVD
from surprise import Dataset, Reader
from surprise.model_selection import train_test_split
ratings = pd.read_csv("/Users/ivyadiele/Desktop/PythonProject/MovieRecommendationSystem/data/ratings.dat", sep="::", engine="python", names=["userId", "movieId", "rating", "timestamp"])
reader = Reader(rating_scale=(0.5, 5.0))
data = Dataset.load_from_df(ratings[['userId', 'movieId', 'rating']], reader)
trainset, testset = train_test_split(data, test_size=0.2, random_state=42)
model = SVD()
model.fit(trainset)
with open("/Users/ivyadiele/Desktop/PythonProject/MovieRecommendationSystem/model/model.pkl", "wb") as f:
pickle.dump(model, f)
print("Model training completed & saved as 'model.pkl'")