<jupyter_start><jupyter_text>Load data and explore a bit<jupyter_code># Import statements
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns


import json
import pickle

#from spotipy.oauth2 import SpotifyClientCredentials
#import spotipy



songs = pd.read_csv("data.csv")
songs.head()

songs.describe()
# check for nans
pd.isnull(songs).sum()
# awesome, no nans<jupyter_output><empty_output><jupyter_text>Model Stuff<jupyter_code># only include numeric cols for now
cols_i_want = ['artists',	'name',	'id',	'danceability',	'instrumentalness',	'loudness',	'speechiness',	'valence']
songs_new = songs[cols_i_want].copy()
songs_new.head()
from sklearn.model_selection import train_test_split

# train/test split
train, test = train_test_split(songs_new, test_size=0.2, random_state=42)
train.shape, test.shape
train.head()
from sklearn.neighbors import NearestNeighbors

def predicto(track_id):

    # Instantiate and fit knn to the correct columns
    NN = NearestNeighbors(n_neighbors=10)
    NN.fit(songs_new[songs_new.columns[4:]])

    obs = songs_new.index[songs_new['id'] == track_id]
    series = songs_new.iloc[obs, 4:].to_numpy()

    neighbors = NN.kneighbors(series)

    new_obs = neighbors[1][0][6:20]
    return list(songs_new.loc[new_obs, 'id'])
predicto('6fLvsD8uWsCRow8PfOpMav')
NN.kneighbors([['4yTDJt8yfOpRKvRNQ8uV5X']], 2, return_distance=False)
predicto('4yTDJt8yfOpRKvRNQ8uV5X')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11964649898028552, 'fraction_numerical': 0.017675050985723997, 'mean_word_length': 6.472081218274112, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '464754', 'license': 'MIT', 'n_tokens_mistral': 611, 'n_tokens_neox': 578, 'n_words': 113, 'path': 'ipynb/DylanSpotifyExploration.ipynb', 'repo_name': 'spotify-song-suggestion/data-science', 'size': '1471'}