KristofGaming39
commited on
Commit
•
1c4d52e
1
Parent(s):
34ec152
main.py
Browse filesThis AI Model is making a random pie chart from csv
- piechartonai.py +61 -0
piechartonai.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""PiechartOnAI.ipynb
|
3 |
+
|
4 |
+
Automatically generated by Colaboratory.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/17oqp758ffviqvK2q7mzgXY0VOJN6WLET
|
8 |
+
"""
|
9 |
+
|
10 |
+
import tensorflow as tf
|
11 |
+
import pandas as pd
|
12 |
+
import numpy as np
|
13 |
+
import matplotlib.pyplot as plt
|
14 |
+
|
15 |
+
df = pd.read_csv('test1.csv')
|
16 |
+
slices = df['Slices']
|
17 |
+
randomness = df['Randomness']
|
18 |
+
|
19 |
+
from sklearn.preprocessing import MinMaxScaler
|
20 |
+
scaler = MinMaxScaler()
|
21 |
+
slices_norm = scaler.fit_transform(slices.values.reshape(-1, 1))
|
22 |
+
randomness_norm = scaler.fit_transform(randomness.values.reshape(-1, 1))
|
23 |
+
|
24 |
+
# Define the model
|
25 |
+
inputs1 = tf.keras.layers.Input(shape=(1,))
|
26 |
+
inputs2 = tf.keras.layers.Input(shape=(1,))
|
27 |
+
x1 = tf.keras.layers.Dense(8, activation='relu')(inputs1)
|
28 |
+
x2 = tf.keras.layers.Dense(8, activation='relu')(inputs2)
|
29 |
+
x = tf.keras.layers.Concatenate()([x1, x2])
|
30 |
+
output = tf.keras.layers.Dense(1, activation='sigmoid')(x)
|
31 |
+
# Generate the target value
|
32 |
+
y = slices_norm + randomness_norm
|
33 |
+
y = y / np.sum(y)
|
34 |
+
|
35 |
+
model = tf.keras.models.Model(inputs=[inputs1, inputs2], outputs=output)
|
36 |
+
model.compile(loss='mse', optimizer='adam')
|
37 |
+
|
38 |
+
# Train the model
|
39 |
+
history = model.fit([slices_norm, randomness_norm], y, epochs=100, batch_size=32)
|
40 |
+
|
41 |
+
# Define the input values for the pie chart
|
42 |
+
slices_input = np.array([[0.25]])
|
43 |
+
randomness_input = np.array([[0.75]])
|
44 |
+
|
45 |
+
# Use the trained model to predict the target value
|
46 |
+
prediction = model.predict([slices_input, randomness_input])
|
47 |
+
prediction = prediction[0][0]
|
48 |
+
|
49 |
+
# Generate the pie chart using the predicted target value
|
50 |
+
labels = ['Elfogultságok','Vesztség','Súlyok','Véletlenszerűség']
|
51 |
+
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]
|
52 |
+
explode = (0, 0, 0, 0.1)
|
53 |
+
fig1, ax1 = plt.subplots()
|
54 |
+
ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%', shadow=True, startangle=90)
|
55 |
+
ax1.axis('equal')
|
56 |
+
plt.show()
|
57 |
+
print("Véletlenszerűség (mennyire véletlenszerű az előrejelzés)")
|
58 |
+
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")
|
59 |
+
print("Súlyok (mennyit ér a tévedés az egyes neuronokon)")
|
60 |
+
print("Elfogultságok (Milyen jó az előrejelzés)")
|
61 |
+
|