Last active
April 26, 2021 14:35
-
-
Save LouisdeBruijn/043cdb8578cd0387eb7c2266c2c15f3e to your computer and use it in GitHub Desktop.
Build and test model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def model(): | |
'''computes p@k and map@k evaluation metrics and saves model''' | |
sparse_item_user = load_npz("sparse_item_user.npz") | |
train, test = train_test_split(sparse_item_user, train_percentage=0.8) | |
model = implicit.als.AlternatingLeastSquares(factors=100, | |
regularization=0.1, iterations=20, calculate_training_loss=False) | |
model.fit(train) | |
with open('model.sav', 'wb') as pickle_out: | |
pickle.dump(model, pickle_out) | |
train, test = train.T.tocsr(), test.T.tocsr() | |
p_at_k = precision_at_k(model, train_user_items=train, | |
test_user_items=test, K=10) | |
m_at_k = mean_average_precision_at_k(model, train, test, K=10) | |
return p_at_k, m_at_k | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment