# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import sklearn as sk
from sklearn.preprocessing import StandardScaler
from sklearn.preprocessing import MinMaxScaler

# Набор данных взят с https://www.kaggle.com/aashi20/top-50-spotify-songs
# Top-50 песен в Spotify в 2019 году.
data = pd.read_csv("datasets/top50.csv")
print(data)

data = pd.read_csv("datasets/top50.csv")
data.head(15)

NewData = pd.DataFrame()
Dta = pd.get_dummies(data['Genre'])
NewData = pd.concat([NewData, Dta])
NewData.head()

dat = data['Beats.Per.Minute']
plt.hist(np.log(dat), bins=50)
plt.show()
dat = np.array(np.log(dat)).reshape(-1, 1)
dat = MinMaxScaler().fit_transform(dat).flatten()
NewData['Beats.Per.Minute'] = dat
NewData.head(15)

dat = data['Energy']
plt.hist(np.log(dat), bins=50)
plt.show()
dat = np.array(np.log(dat)).reshape(-1, 1)
dat = MinMaxScaler().fit_transform(dat).flatten()
NewData['Energy'] = dat
NewData.head(15)

dat = data['Danceability']
dat = np.clip(dat, 55, 100)
plt.hist(dat**0.5, bins=50)
plt.show()
dat = np.array(dat**0.5).reshape(-1, 1)
dat = MinMaxScaler().fit_transform(dat).flatten()
NewData['Danceability'] = dat
NewData.head(15)

dat = data['Loudness..dB..']
dat = np.clip(dat, -10, 0)
dat = np.array(dat).reshape(-1, 1)
dat= MinMaxScaler().fit_transform(dat).flatten()
NewData['Loudness..dB..'] = dat
NewData.head(15)

dat = data['Liveness']
dat = np.clip(dat, 0, 25)
plt.hist(np.log(dat), bins=50)
plt.show()
dat = np.array(np.log(dat)).reshape(-1, 1)
dat = MinMaxScaler().fit_transform(dat).flatten()
NewData['Liveness'] = dat
NewData.head(15)

dat = data['Valence.']
plt.hist(dat**0.5, bins=50)
plt.show()
dat = np.array(dat**0.5).reshape(-1, 1)
dat = MinMaxScaler().fit_transform(dat).flatten()
NewData['Valence.'] = dat
NewData.head(15)

dat = data['Length.']
dat = np.clip(dat, 140, 500)
plt.hist(dat**0.5, bins=50)
plt.show()
dat = np.array(dat**0.5).reshape(-1, 1)
dat = MinMaxScaler().fit_transform(dat).flatten()
NewData['Length.'] = dat
NewData.head(15)

dat = data['Acousticness..']
plt.hist(dat**0.5, bins=50)
plt.show()
dat = np.array(dat**0.5).reshape(-1, 1)
dat = MinMaxScaler().fit_transform(dat).flatten()
NewData['Acousticness..'] = dat
NewData.head(15)

dat = data['Speechiness.']
dat = np.clip(dat, 0, 40)
plt.hist(dat**0.5, bins=50)
plt.show()
dat = np.array(dat**0.5).reshape(-1, 1)
dat = MinMaxScaler().fit_transform(dat).flatten()
NewData['Speechiness.'] = dat
NewData.head(15)

dat = data['Popularity']
dat = np.clip(dat, 77, 100)
plt.hist(dat**0.5, bins=50)
plt.show()
dat = np.array(dat**0.5).reshape(-1, 1)
dat = MinMaxScaler().fit_transform(dat).flatten()
NewData['Popularity'] = dat
NewData.head(15)



StarcoderdataJupyterScriptsDedupFiltered