Skip to content

Instantly share code, notes, and snippets.

View MaxHilsdorf's full-sized avatar

Max Hilsdorf MaxHilsdorf

  • Germany
View GitHub Profile
Häxor are a rare species fruktade by the common folk for their use of mäktiga magic. However, häxorna are often missförstådda.
häxor: Witches
fruktade: feared
mäktiga: powerful/mighty
missförstådda: misunderstood
Genre Difficulty Artist Song Year
Pop Easy ABBA Money Money Money 1976
Pop Medium Ariana Grande Break Up With Your Girlfriend 2019
Metal Hard Slayer Angel of Death 1986
Metal Very Hard Amon Amarth The Pursuit of Vikings 2004
from tensorflow import keras
from keras import Sequential
from keras.layers import Conv2D, MaxPool2D, BatchNormalization, Flatten, Dense, Dropout, GRU, Reshape
model = Sequential(name="gtzan_crnn")
# Convolutional Block 1
model.add(Conv2D(filters=16, kernel_size=(3,3), input_shape=X_train.shape[1:])) # X_train holds the processed training spectrograms
model.add(MaxPool2D(pool_size=(2,2)))
model.add(BatchNormalization())
{
"project_folders": {
"base_folder": "my_path/gtzan/",
"raw_mp3_folder": "raw_mp3s/"
},
"build_dataset_params":{
"audio_slicing_params":{
"sliced_mp3_folder": "processed_mp3s/",
@MaxHilsdorf
MaxHilsdorf / recommend.py
Created October 14, 2021 06:51
A recommender function taking a spotify id, an authorization access object and a reference dataframe as an input and returning n mood-based recommendations.
def recommend(track_id, ref_df, sp, n_recs = 5):
# Crawl valence and arousal of given track from spotify api
track_features = sp.track_audio_features(track_id)
track_moodvec = np.array([track_features.valence, track_features.energy])
# Compute distances to all reference tracks
ref_df["distances"] = ref_df["mood_vec"].apply(lambda x: norm(track_moodvec-np.array(x)))
# Sort distances from lowest to highest
ref_df_sorted = ref_df.sort_values(by = "distances", ascending = True)
@MaxHilsdorf
MaxHilsdorf / crawl_valence_arousal_dataset.py
Last active April 6, 2023 15:03
This code crawls a dataset, which can be used for mood-based recommendations, from the Spotify API
#################
## PREPARATION ##
#################
# Import modules
import sys
# If your authentification script is not in the project directory
# append its folder to sys.path
sys.path.append("../spotify_api_web_app")
import authorization
ax.text(quant_5-.1, 0.17, "5th", size = 10, alpha = 0.8)
ax.text(quant_25-.13, 0.27, "25th", size = 11, alpha = 0.85)
ax.text(quant_50-.13, 0.37, "50th", size = 12, alpha = 1)
ax.text(quant_75-.13, 0.47, "75th", size = 11, alpha = 0.85)
ax.text(quant_95-.25, 0.57, "95th Percentile", size = 10, alpha =.8)
# Calculate percentiles
quant_5, quant_25, quant_50, quant_75, quant_95 = avocado.quantile(0.05), avocado.quantile(0.25), avocado.quantile(0.5), avocado.quantile(0.75), avocado.quantile(0.95)
# [quantile, opacity, length]
quants = [[quant_5, 0.6, 0.16], [quant_25, 0.8, 0.26], [quant_50, 1, 0.36], [quant_75, 0.8, 0.46], [quant_95, 0.6, 0.56]]
# Plot the lines with a loop
for i in quants:
ax.axvline(i[0], alpha = i[1], ymax = i[2], linestyle = ":")
@MaxHilsdorf
MaxHilsdorf / removed_information_plot.py
Created May 27, 2020 18:44
removed_information_plot
fig, ax = plt.subplots(figsize = (6,4))
# Plots #
# Plot histogram
avocado.plot(kind = "hist", density = True, bins = 15) # change density to true, because KDE uses density
# Plot KDE
avocado.plot(kind = "kde")
# X #
ax.set_xlabel("Average Price ($)")
@MaxHilsdorf
MaxHilsdorf / added_information_plot.py
Created May 27, 2020 18:43
added_information_plot
fig, ax = plt.subplots(figsize = (6,4))
# Plots #
# Plot histogram
avocado.plot(kind = "hist", density = True, bins = 15) # change density to true, because KDE uses density
# Plot KDE
avocado.plot(kind = "kde")
# X #
ax.set_xlabel("Average Price ($)")