File size: 2,248 Bytes
1c4d52e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# -*- 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)")