Created
November 29, 2020 23:41
-
-
Save HeenaR17/487a5061a78ace7bc5ade0cdcd658e6f to your computer and use it in GitHub Desktop.
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 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