<jupyter_start><jupyter_text>Recommendation for existing user<jupyter_code>%%time
def get_recommendation(user_id):
    user_items = dataset_s
    recommendations = model.recommend(user_id, 
                                      user_items,
                                     )
    return dataset.columns[list(np.array(recommendations)[:,0].astype('int'))]

print(get_recommendation(1019410))<jupyter_output>Index(['<NAME>', '<NAME>', '<NAME>', 'Rihanna',
       '<NAME>', 'Harmonia', 'Beyoncé', '<NAME>',
       'Lady GaGa / <NAME>', '<NAME>'],
      dtype='object')
CPU times: user 4 ms, sys: 1.66 ms, total: 5.66 ms
Wall time: 3.57 ms<jupyter_text>Recommendation for new user<jupyter_code>%%time
def get_recommendation_new(new_user_data):
    user_items = sparse.vstack((dataset_s, 
                                sparse.csr_matrix(new_user_data)))
    user_id = user_items.shape[0] - 1

    recommendations = model.recommend(user_id,
                                      user_items, 
                                      recalculate_user=True,
                                     )
    return dataset.columns[list(np.array(recommendations)[:,0].astype('int'))]


new_user_data = np.zeros(dataset_s.shape[1])
new_user_data[:100] = 1
np.random.shuffle(new_user_data)

print(get_recommendation_new(new_user_data))<jupyter_output>Index(['Enya', 'The Avett Brothers', 'Fleet Foxes', 'Rammstein', '<NAME>',
       'Iron And Wine', 'Linkin Park', 'Coldplay', '<NAME>', 'Enigma'],
      dtype='object')
CPU times: user 151 ms, sys: 121 ms, total: 272 ms
Wall time: 271 ms<jupyter_text>Similar items<jupyter_code>def get_similar_artist(item_id):
    similar = model.similar_items(item_id, N=10)
    return dataset.columns[list(np.array(similar)[:,0].astype('int'))]

get_similar_artist(11836)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13995609220636662, 'fraction_numerical': 0.025246981339187707, 'mean_word_length': 3.17162471395881, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '443759', 'license': 'MIT', 'n_tokens_mistral': 666, 'n_tokens_neox': 619, 'n_words': 103, 'path': 'model_creation/basic_recommender.ipynb', 'repo_name': 'VkUserAnalyzer/Vk_user_analyzer', 'size': '1867'}