RandomPieChartFromCsv / piechartonai.py
KristofGaming39's picture
main.py
1c4d52e
# -*- coding: utf-8 -*-
"""PiechartOnAI.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/17oqp758ffviqvK2q7mzgXY0VOJN6WLET
"""
import tensorflow as tf
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df = pd.read_csv('test1.csv')
slices = df['Slices']
randomness = df['Randomness']
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
slices_norm = scaler.fit_transform(slices.values.reshape(-1, 1))
randomness_norm = scaler.fit_transform(randomness.values.reshape(-1, 1))
# Define the model
inputs1 = tf.keras.layers.Input(shape=(1,))
inputs2 = tf.keras.layers.Input(shape=(1,))
x1 = tf.keras.layers.Dense(8, activation='relu')(inputs1)
x2 = tf.keras.layers.Dense(8, activation='relu')(inputs2)
x = tf.keras.layers.Concatenate()([x1, x2])
output = tf.keras.layers.Dense(1, activation='sigmoid')(x)
# Generate the target value
y = slices_norm + randomness_norm
y = y / np.sum(y)
model = tf.keras.models.Model(inputs=[inputs1, inputs2], outputs=output)
model.compile(loss='mse', optimizer='adam')
# Train the model
history = model.fit([slices_norm, randomness_norm], y, epochs=100, batch_size=32)
# Define the input values for the pie chart
slices_input = np.array([[0.25]])
randomness_input = np.array([[0.75]])
# Use the trained model to predict the target value
prediction = model.predict([slices_input, randomness_input])
prediction = prediction[0][0]
# Generate the pie chart using the predicted target value
labels = ['Elfogultságok','Vesztség','Súlyok','Véletlenszerűség']
sizes = [slices_input[0][0]*prediction*100, slices_input[0][0]*(1-prediction)*100, (1-slices_input[0][0])*prediction*100, (1-slices_input[0][0])*(1-prediction)*100]
explode = (0, 0, 0, 0.1)
fig1, ax1 = plt.subplots()
ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%', shadow=True, startangle=90)
ax1.axis('equal')
plt.show()
print("Véletlenszerűség (mennyire véletlenszerű az előrejelzés)")
print("Veszteség (Ha a veszteség nagy, az azt jelenti, hogy a tévedés nagy, különben a tévedés kicsi")
print("Súlyok (mennyit ér a tévedés az egyes neuronokon)")
print("Elfogultságok (Milyen jó az előrejelzés)")