<jupyter_start><jupyter_text>Imports<jupyter_code>import pandas as pd
import numpy as np
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.metrics.pairwise import cosine_similarity<jupyter_output><empty_output><jupyter_text>Helper Functions<jupyter_code>def title_from_index(index):
    return df[df.index == index]["Title"].values[0]

def index_from_artist(artist):
    return df[df['Artist'] == artist].index.values.astype(int)[0]<jupyter_output><empty_output><jupyter_text>Mock Data<jupyter_code>data = [["You should be sad", "Halsey", "2020", "Pop"], ["Old Town Road", "Lil Nas X", "2019", "Country"], 
        ["Godzilla", "Eminem", "2020", "Rap"], ["Piano Sonata No. 14", "Beethoven", "1801", "Classical"],
       ["Moonshine", "Caravan Palace", "2020", "Electroswing"], ["Sucker", "<NAME>", "2019", "Pop"],
       ["ADHD", "<NAME>", "2019", "Rap"], ["The Real Slim Shady", "Eminem", "2000", "Rap"]]
df = pd.DataFrame(data, columns=['Title', 'Artist', 'Year', 'Genre'])
user_test = "Eminem"
features = ['Title', 'Artist', 'Year', 'Genre']
features
# Create new column that is combination of features
def row_concat(row):
    return row['Title'] + " " + row['Artist'] + " " + row['Year'] + " " + row["Genre"]
#Test out new function
df['combined row'] = df.apply(row_concat, axis = 1)
# Try out CountVectorizer 
cv = CountVectorizer()
count_matrix = cv.fit_transform(df['combined row'])
#Find similarity
cosine_simil = cosine_similarity(count_matrix)
#Use helper function to find index of title.
artist_index = index_from_artist(user_test)
#Get a list of similar
similar_songs =  list(enumerate(cosine_simil[artist_index]))
#Sort list
sorted_similar_songs = sorted(similar_songs,key=lambda x:x[1],reverse=True)
## Step 8: Print titles of first 50 movies
i=0
for song in sorted_similar_songs:
        print(title_from_index(song[0]))
        i=i+1
        if i>50:
            break<jupyter_output>Godzilla
The Real Slim Shady
Moonshine
ADHD
You should be sad
Old Town Road
Piano Sonata No. 14
Sucker
{'fraction_non_alphanumeric': 0.1554787759131293, 'fraction_numerical': 0.023692003948667325, 'mean_word_length': 5.7792642140468224, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '567873', 'license': 'MIT', 'n_tokens_mistral': 755, 'n_tokens_neox': 711, 'n_words': 181, 'path': '.ipynb_checkpoints/Untitled-checkpoint.ipynb', 'repo_name': 'Spotify-Song-Suggester-4/DS', 'size': '2040'}