Skip to content

Instantly share code, notes, and snippets.

@HeenaR17
Created November 29, 2020 23:41
Show Gist options
  • Save HeenaR17/487a5061a78ace7bc5ade0cdcd658e6f to your computer and use it in GitHub Desktop.
Save HeenaR17/487a5061a78ace7bc5ade0cdcd658e6f to your computer and use it in GitHub Desktop.
def getMyPizza(ingredients):
# load the dataset and clean the text
pizza_df = pd.read_csv("PizzaIngredients.csv",na_values=['?'," ",""])
pizza_df.Ingredients.replace(to_replace="[|]",value=" ",inplace=True,regex=True)
myRow = ['MyPizza'] #converting ingredients column to list
myRow.append(ingredients)
pizza_df.loc[len(pizza_df)] = myRow
cv=CountVectorizer()
cv_matrix=cv.fit_transform(pizza_df['Ingredients']) #gives the matrix of n*n with count of words matched
cs=cosine_similarity(cv_matrix) #gives cosine similarity
table=pd.DataFrame(index=pizza_df.PizzaName,columns=pizza_df.PizzaName,data=cs)
table=table.drop(['MyPizza'],axis=1)
if str(max(table.loc["MyPizza"])) != '0.0':
return table.idxmax(axis=1)['MyPizza']
else:
return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment