I have a pandas data frame containing list of wines with their respective wine attributes.
Then I made a new column vector that contains numpy vectors from these attributes.
def get_wine_profile(id):
wine = wines[wines['exclusiviId'] == id]
wine_vector = np.array(wine[wine_attrs].values.tolist()).flatten()
return wine_vector
wines['vector'] = wines.exclusiviId.apply(get_wine_profile)
hence the vector column look something like this
vector
[1, 1, 1, 2, 2, 2, 2, 1, 1, 1]
[3, 1, 2, 1, 2, 2, 2, 0, 1, 3]
[1, 1, 2, 1, 3, 3, 3, 0, 1, 1]
.
.
now I want to perform cosine similarity between this column and another vector that is resulting vector from the user input This is what i have tried so far
from scipy.spatial.distance import cosine
cos_vec = wines.apply(lambda x: (1-cosine(wines["vector"],[1, 1, 1, 2, 2, 2, 2, 1, 1, 1]), axis=1)
Print(cos_vec)
this is throwing error
ValueError: ('operands could not be broadcast together with shapes (63,) (10,) ', 'occurred at index 0')
I also tries using sklearn but it also have the same problem with the arrar shape
what i want as a final output is a column that has match score between this column and user input