DSIC-Bayes-continuous/main.py

34 lines
890 B
Python
Raw Normal View History

2021-05-26 13:32:48 +02:00
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)
2021-05-26 15:25:00 +02:00
X_train, X_test, Y_train, Y_test = DataPreparator.train_test_split(data)
2021-05-26 21:08:58 +02:00
bayes = Bayes('_model.model')
2021-05-26 15:25:00 +02:00
if(not bayes.model_exists):
bayes.train(X_train, Y_train)
Y_predicted = bayes.predict(X_train)
eval_result = bayes.eval(Y_train, Y_predicted)
print("Train:")
print(eval_result[1])
Y_predicted = bayes.predict(X_test)
eval_result = bayes.eval(Y_test, Y_predicted)
2021-05-26 21:08:58 +02:00
2021-05-26 15:25:00 +02:00
print("Test:")
print(eval_result[1])
2021-05-26 21:08:58 +02:00
#Result preview
# for i in range(100):
# print(f"Expected: {Y_test.to_numpy()[i]}\tPred: {Y_predicted[i]}")
DataPreparator.print_df_info(data)