This commit is contained in:
Anna Nowak 2021-05-26 13:32:48 +02:00
parent 1305796eba
commit 07d97c5267
6 changed files with 1045 additions and 0 deletions

5
.gitignore vendored
View File

@ -0,0 +1,5 @@
venv*
.venv*
.vscode*
__pycache__*
music_genre.csv

3
bayes.py Normal file
View File

@ -0,0 +1,3 @@
class Bayes:
def __init__(self):
pass

23
datapreparator.py Normal file
View File

@ -0,0 +1,23 @@
from copy import deepcopy
import pandas as pd
class DataPreparator:
genre_dict = {
"blues" : 1,
"classical" : 2,
"country" : 3,
"disco" : 4,
"hiphop" : 5,
"jazz" : 6,
"metal" : 7,
"pop" : 8,
"reggae" : 9,
"rock" : 10
}
def prepare_data(df: pd.DataFrame) -> pd.DataFrame:
data = deepcopy(df)
column = df["label"].apply(lambda x: DataPreparator.genre_dict[x])
data.insert(0, 'genre', column, 'float')
data = data.drop(columns=['filename', 'label', 'length'])
return data

12
main.py Normal file
View File

@ -0,0 +1,12 @@
from bayes import Bayes
from datapreparator import DataPreparator
import pandas as pd
import os
filename = 'music_genre.csv'
if os.path.isfile(filename):
data = pd.read_csv(filename)
else:
data_raw = pd.read_csv('music_genre_raw.csv')
data = DataPreparator.prepare_data(data_raw)
data.to_csv(filename, index=False)

1001
music_genre_raw.csv Normal file

File diff suppressed because it is too large Load Diff

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
pandas==1.2.4