simple_neurone #28
@ -31,11 +31,33 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 6,
|
||||
"id": "04bbec40",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "ModuleNotFoundError",
|
||||
"evalue": "No module named 'pybrain3'",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
|
||||
"Input \u001b[0;32mIn [6]\u001b[0m, in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpybrain3\u001b[39;00m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpickle\u001b[39;00m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mmatplotlib\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mpylab\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mplt\u001b[39;00m \n",
|
||||
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'pybrain3'"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import pybrain3\n",
|
||||
"import pickle\n",
|
||||
"import matplotlib.pylab as plt \n",
|
||||
"from numpy import ravel\n",
|
||||
"from pybrain3.tools.shortcuts import buildNetwork\n",
|
||||
"from pybrain3.datasets import SupervisedDataSet\n",
|
||||
"from pybrain3.supervised.trainers import BackpropTrainer \n",
|
||||
"from pybrain3.tools.xml.networkwriter import NetworkWriter \n",
|
||||
"from pybrain3.tools.xml.networkreader import NetworkReader"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
|
@ -4,40 +4,18 @@
|
||||
| | | |--- class: 0
|
||||
| | |--- feature_0 > 1.50
|
||||
| | | |--- feature_3 <= 3.50
|
||||
| | | | |--- feature_4 <= 2.50
|
||||
| | | | |--- feature_2 <= 2.50
|
||||
| | | | | |--- class: 1
|
||||
| | | | |--- feature_4 > 2.50
|
||||
| | | | | |--- feature_2 <= 2.50
|
||||
| | | | |--- feature_2 > 2.50
|
||||
| | | | | |--- feature_4 <= 2.50
|
||||
| | | | | | |--- class: 1
|
||||
| | | | | |--- feature_2 > 2.50
|
||||
| | | | | |--- feature_4 > 2.50
|
||||
| | | | | | |--- class: 0
|
||||
| | | |--- feature_3 > 3.50
|
||||
| | | | |--- feature_3 <= 4.50
|
||||
| | | | | |--- feature_1 <= 2.50
|
||||
| | | | | | |--- feature_0 <= 2.50
|
||||
| | | | | | | |--- feature_1 <= 1.50
|
||||
| | | | | | | | |--- feature_4 <= 2.50
|
||||
| | | | | | | | | |--- class: 1
|
||||
| | | | | | | | |--- feature_4 > 2.50
|
||||
| | | | | | | | | |--- feature_2 <= 2.00
|
||||
| | | | | | | | | | |--- class: 1
|
||||
| | | | | | | | | |--- feature_2 > 2.00
|
||||
| | | | | | | | | | |--- class: 0
|
||||
| | | | | | | |--- feature_1 > 1.50
|
||||
| | | | | | | | |--- class: 0
|
||||
| | | | | | |--- feature_0 > 2.50
|
||||
| | | | | | | |--- feature_2 <= 2.50
|
||||
| | | | | | | | |--- class: 1
|
||||
| | | | | | | |--- feature_2 > 2.50
|
||||
| | | | | | | | |--- feature_4 <= 2.50
|
||||
| | | | | | | | | |--- class: 1
|
||||
| | | | | | | | |--- feature_4 > 2.50
|
||||
| | | | | | | | | |--- class: 0
|
||||
| | | | | |--- feature_1 > 2.50
|
||||
| | | | | | |--- feature_0 <= 3.50
|
||||
| | | | | | | |--- class: 0
|
||||
| | | | | | |--- feature_0 > 3.50
|
||||
| | | | | | | |--- feature_1 <= 3.50
|
||||
| | | | | | | | |--- feature_2 <= 2.50
|
||||
| | | | | | | | | |--- class: 1
|
||||
| | | | | | | | |--- feature_2 > 2.50
|
||||
@ -45,8 +23,30 @@
|
||||
| | | | | | | | | | |--- class: 1
|
||||
| | | | | | | | | |--- feature_4 > 2.00
|
||||
| | | | | | | | | | |--- class: 0
|
||||
| | | | | | | |--- feature_1 > 3.50
|
||||
| | | | | | | |--- feature_1 > 1.50
|
||||
| | | | | | | | |--- class: 0
|
||||
| | | | | | |--- feature_0 > 2.50
|
||||
| | | | | | | |--- feature_4 <= 2.50
|
||||
| | | | | | | | |--- class: 1
|
||||
| | | | | | | |--- feature_4 > 2.50
|
||||
| | | | | | | | |--- feature_2 <= 2.50
|
||||
| | | | | | | | | |--- class: 1
|
||||
| | | | | | | | |--- feature_2 > 2.50
|
||||
| | | | | | | | | |--- class: 0
|
||||
| | | | | |--- feature_1 > 2.50
|
||||
| | | | | | |--- feature_1 <= 3.50
|
||||
| | | | | | | |--- feature_0 <= 3.50
|
||||
| | | | | | | | |--- class: 0
|
||||
| | | | | | | |--- feature_0 > 3.50
|
||||
| | | | | | | | |--- feature_4 <= 2.50
|
||||
| | | | | | | | | |--- class: 1
|
||||
| | | | | | | | |--- feature_4 > 2.50
|
||||
| | | | | | | | | |--- feature_2 <= 2.00
|
||||
| | | | | | | | | | |--- class: 1
|
||||
| | | | | | | | | |--- feature_2 > 2.00
|
||||
| | | | | | | | | | |--- class: 0
|
||||
| | | | | | |--- feature_1 > 3.50
|
||||
| | | | | | | |--- class: 0
|
||||
| | | | |--- feature_3 > 4.50
|
||||
| | | | | |--- class: 0
|
||||
| |--- feature_4 > 3.50
|
||||
@ -59,13 +59,13 @@
|
||||
| | | | | | |--- class: 1
|
||||
| | | | |--- feature_3 > 3.50
|
||||
| | | | | |--- feature_1 <= 2.50
|
||||
| | | | | | |--- feature_3 <= 4.50
|
||||
| | | | | | | |--- feature_0 <= 2.50
|
||||
| | | | | | | | |--- class: 0
|
||||
| | | | | | | |--- feature_0 > 2.50
|
||||
| | | | | | | | |--- class: 1
|
||||
| | | | | | |--- feature_3 > 4.50
|
||||
| | | | | | |--- feature_0 <= 2.50
|
||||
| | | | | | | |--- class: 0
|
||||
| | | | | | |--- feature_0 > 2.50
|
||||
| | | | | | | |--- feature_3 <= 4.50
|
||||
| | | | | | | | |--- class: 1
|
||||
| | | | | | | |--- feature_3 > 4.50
|
||||
| | | | | | | | |--- class: 0
|
||||
| | | | | |--- feature_1 > 2.50
|
||||
| | | | | | |--- class: 0
|
||||
| | | |--- feature_4 > 4.50
|
||||
@ -73,8 +73,8 @@
|
||||
| | |--- feature_2 > 1.50
|
||||
| | | |--- class: 0
|
||||
|--- feature_2 > 3.50
|
||||
| |--- feature_4 <= 1.50
|
||||
| | |--- feature_1 <= 1.50
|
||||
| |--- feature_1 <= 1.50
|
||||
| | |--- feature_4 <= 1.50
|
||||
| | | |--- feature_2 <= 4.50
|
||||
| | | | |--- feature_3 <= 4.50
|
||||
| | | | | |--- feature_0 <= 1.50
|
||||
@ -85,7 +85,7 @@
|
||||
| | | | | |--- class: 0
|
||||
| | | |--- feature_2 > 4.50
|
||||
| | | | |--- class: 0
|
||||
| | |--- feature_1 > 1.50
|
||||
| | |--- feature_4 > 1.50
|
||||
| | | |--- class: 0
|
||||
| |--- feature_4 > 1.50
|
||||
| |--- feature_1 > 1.50
|
||||
| | |--- class: 0
|
||||
|
Binary file not shown.
4
main.py
4
main.py
@ -21,7 +21,7 @@ import itertools
|
||||
def getTree():
|
||||
tree = decisionTree.tree()
|
||||
decisionTree.tree_as_txt(tree)
|
||||
# decisionTree.tree_to_png(tree)
|
||||
decisionTree.tree_to_png(tree)
|
||||
decisionTree.tree_to_structure(tree)
|
||||
drzewo = decisionTree.tree_from_structure('./decision_tree/tree_model')
|
||||
# print("Dla losowych danych predykcja czy wziąć kosz to: ")
|
||||
@ -117,8 +117,6 @@ class Game():
|
||||
# print(i)
|
||||
# print('----')
|
||||
|
||||
print('positive actions')
|
||||
print(len(self.positive_actions))
|
||||
for i in self.positive_decision:
|
||||
# print(i.get_coords())
|
||||
trash_x, trash_y = i.get_coords()
|
||||
|
72
neurone/main.py
Normal file
72
neurone/main.py
Normal file
@ -0,0 +1,72 @@
|
||||
import pybrain3
|
||||
import pickle
|
||||
import matplotlib.pylab as plt
|
||||
from numpy import ravel
|
||||
from pybrain3.tools.shortcuts import buildNetwork
|
||||
from pybrain3.datasets import SupervisedDataSet
|
||||
from pybrain3.supervised.trainers import BackpropTrainer
|
||||
from pybrain3.tools.xml.networkwriter import NetworkWriter
|
||||
from pybrain3.tools.xml.networkreader import NetworkReader
|
||||
|
||||
# https://www.machinelearningmastery.ru/how-to-configure-the-number-of-layers-and-nodes-in-a-neural-network/
|
||||
class SupervisedDataSetModel():
|
||||
def __init__(self, metrics:int = 4,
|
||||
predictions:int = 1,
|
||||
input_layer:int = 4,
|
||||
hidden_layer:int = 3,
|
||||
output_layer:int = 1):
|
||||
# 4 метрики, 1 предикшн
|
||||
self.metrics = metrics
|
||||
self.predictions = predictions
|
||||
self.input_layer = input_layer
|
||||
self.hidden_layer = hidden_layer
|
||||
self.output_layer = output_layer
|
||||
self.ds = SupervisedDataSet(metrics, predictions)
|
||||
|
||||
|
||||
def activateModel(self):
|
||||
self.net = buildNetwork(self.input_layer, self.hidden_layer, self.output_layer, bias=True)
|
||||
self.trainer = BackpropTrainer(self.net, dataset=self.ds, momentum=0.1, learningrate=0.01, verbose=True, weightdecay=0.01)
|
||||
|
||||
self.trnerr, self.valerr = self.trainer.trainUntilConvergence()
|
||||
|
||||
plt.plot(self.trnerr, 'b', self.valerr, 'r')
|
||||
plt.show()
|
||||
|
||||
def addDataToModel(self, input:list, target:list):
|
||||
self.ds.addSample(inp=input, target=target)
|
||||
|
||||
def predict(self, data:list):
|
||||
y = self.net.activate(data)
|
||||
print(y)
|
||||
return y
|
||||
|
||||
def saveModel(self):
|
||||
fileObject = open('model.txt', 'wb')
|
||||
pickle.dump(self.net, fileObject)
|
||||
fileObject.close()
|
||||
|
||||
|
||||
@staticmethod
|
||||
def getModel():
|
||||
fileObject = open('model.txt', 'rb')
|
||||
net2 = pickle.load(fileObject)
|
||||
fileObject.close()
|
||||
return net2
|
||||
|
||||
model = SupervisedDataSetModel()
|
||||
|
||||
model.addDataToModel([2, 3, 80, 1], [5])
|
||||
model.addDataToModel([5, 5, 50, 2], [4])
|
||||
model.addDataToModel([10, 7, 40, 3], [3])
|
||||
model.addDataToModel([15, 9, 20, 4], [2])
|
||||
model.addDataToModel([20, 11, 10, 5], [1])
|
||||
|
||||
model.activateModel()
|
||||
|
||||
model.saveModel()
|
||||
|
||||
# USE MODEL - >
|
||||
# model = BackPropagationModel.getModel()
|
||||
# print(model.activate([2, 3, 80, 1]))
|
||||
|
BIN
neurone/model.txt
Normal file
BIN
neurone/model.txt
Normal file
Binary file not shown.
0
neurone/neurone_client.py
Normal file
0
neurone/neurone_client.py
Normal file
Loading…
Reference in New Issue
Block a user