text_plain_output_2.png application_vnd.jupyter.stderr_output_1.png
from gensim.models import KeyedVectors

from sklearn.neighbors import NearestNeighbors

import numpy as np

import numpy as np # linear algebra

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

from sklearn.neighbors import NearestNeighbors
from gensim.models import KeyedVectors
import numpy as np
import ast
import pandas as pd
data_path = '/kaggle/input/2-recommended-reads-conversion-of-data-to-num/vectorizedData.csv'
data = pd.read_csv(data_path)
data = data.drop_duplicates(subset=['booktitle', 'authorname'], keep='first')
data['word2vec'] = data['word2vec'].apply(lambda x: x.strip('[]'))
data['word2vec'] = data['word2vec'].apply(lambda x: x.split())
data['word2vec'] = data['word2vec'].apply(lambda x: [float(y) for y in x])
model_path = '/kaggle/input/googlenewsvectors/GoogleNews-vectors-negative300.bin'
word_vectors = KeyedVectors.load_word2vec_format(model_path, binary=True)
user_description = 'a space adventure with friends'
user_vector = np.mean([word_vectors[word] for word in user_description.split() if word in word_vectors.key_to_index], axis=0)
nn_model = NearestNeighbors(n_neighbors=10, metric='cosine')
X = np.array(data['word2vec'].tolist())
nn_model.fit(X)
distances, indices = nn_model.kneighbors([user_vector])
recommended_books = data.iloc[indices[0]][['booktitle', 'authorname']].values.tolist()
print('Kullanıcının girdiği kitaba benzer kitaplar:')
for i, book in enumerate(recommended_books):
    similarity = 1 - distances[0][i]
    similarity_percent = round(similarity * 100, 2)
    print(f'{book[0]} by {book[1]} ({similarity_percent}%)')