# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: 'Python 3.7.9 64-bit (''project_a'': conda)'
#     metadata:
#       interpreter:
#         hash: 8ce313a6b3c9b78445350349fbd036912d75f990b40ef4004f3a4aa570c04acb
#     name: 'Python 3.7.9 64-bit (''project_a'': conda)'
# ---

import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.optimizers import SGD
from sklearn import preprocessing

data = (r'C:\Users\Brick\Documents\Lambda_School\data_by_genres.csv')
data1 = (r'C:\Users\Brick\Documents\Lambda_School\data.csv')

df = pd.read_csv(data)
df1 = pd.read_csv(data1)
basic = pd.read_csv(data1)

df

basic

df1 = df1.drop(columns=['artists','explicit','id','name','release_date','year'])

# +
#df1 = df1.drop(columns=['genres'])
# -

from category_encoders import OrdinalEncoder
from sklearn.linear_model import LogisticRegression
encoder = OrdinalEncoder(cols=['genres']) 

edf= encoder.fit_transform(df) 

edf

cols = ['acousticness','danceability','duration_ms','energy','instrumentalness','liveness','loudness','speechiness','tempo','valence','popularity','key','mode']

df1

x = edf.drop(columns='genres')
y = edf['genres'].unique()

edf['genres'].unique

from sklearn.neighbors import KNeighborsClassifier
neigh = KNeighborsClassifier(n_neighbors=3)
neigh.fit(x, y)
print(neigh.predict(df1))

df1['genres'] = neigh.predict(df1)

df1

df1['numeric']=df1['genres']

df1.drop(columns='genres')

df1['artists'] = basic['artists']

df1['song_name'] = basic['name']

df1

compgen = pd.DataFrame(columns=['numeric','genres'])

compgen['numeric'] = edf['genres']

compgen['genres'] = df['genres']

compgen

test = df1.merge(compgen, on='numeric')

test

test = test.drop(columns=['genres_x','numeric'])

test = test.rename(columns={'genres_y':'genre'})

test['artists'] = test['artists'].astype('str')

test['artist'] = test['artists'].str.get(4)

for item in test['artist']:
    test['artist'] = test['artists'].str.extract()

test.drop(columns='artist')

#for num in test['artists']:
test['artists'].replace("[","")



StarcoderdataJupyterScriptsDedupFiltered