DecisionTree save and load from file
This commit is contained in:
parent
b3197dccd2
commit
01dae9185b
@ -4,6 +4,7 @@ import pydotplus
|
|||||||
from sklearn.tree import DecisionTreeClassifier
|
from sklearn.tree import DecisionTreeClassifier
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import matplotlib.image as pltimg
|
import matplotlib.image as pltimg
|
||||||
|
import joblib
|
||||||
|
|
||||||
df = pandas.read_csv("treedata\\data.csv")
|
df = pandas.read_csv("treedata\\data.csv")
|
||||||
|
|
||||||
@ -38,12 +39,14 @@ y = df['Decision']
|
|||||||
|
|
||||||
dtree = DecisionTreeClassifier()
|
dtree = DecisionTreeClassifier()
|
||||||
dtree = dtree.fit(X, y)
|
dtree = dtree.fit(X, y)
|
||||||
|
joblib.dump(dtree, 'treedata\\DecisionTree.pkl')
|
||||||
|
|
||||||
|
|
||||||
data = tree.export_graphviz(dtree, out_file=None, feature_names=features)
|
data = tree.export_graphviz(dtree, out_file=None, feature_names=features)
|
||||||
graph = pydotplus.graph_from_dot_data(data)
|
graph = pydotplus.graph_from_dot_data(data)
|
||||||
graph.write_png('mydecisiontree.png')
|
graph.write_png('treedata\\mydecisiontree.png')
|
||||||
|
|
||||||
img = pltimg.imread('mydecisiontree.png')
|
img = pltimg.imread('treedata\\mydecisiontree.png')
|
||||||
imgplot = plt.imshow(img)
|
imgplot = plt.imshow(img)
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
5
main.py
5
main.py
@ -7,11 +7,11 @@ import WeatherConditions
|
|||||||
import convertToPrediction
|
import convertToPrediction
|
||||||
import drawUI
|
import drawUI
|
||||||
import Graphsearch as graph
|
import Graphsearch as graph
|
||||||
from decisiontree import dtree
|
|
||||||
from Tractor import Tractor
|
from Tractor import Tractor
|
||||||
from TractorLoad import TillageUnit
|
from TractorLoad import TillageUnit
|
||||||
from constants import *
|
from constants import *
|
||||||
from manualSteering import manualSteeringDriver
|
from manualSteering import manualSteeringDriver
|
||||||
|
import joblib
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
|
||||||
@ -58,6 +58,9 @@ while working:
|
|||||||
weather, day_time, temperature, wind, humidy = WeatherConditions.checkConditions()
|
weather, day_time, temperature, wind, humidy = WeatherConditions.checkConditions()
|
||||||
|
|
||||||
question = [convertToPrediction.convert(field.state, weather, day_time, temperature, wind, humidy)]
|
question = [convertToPrediction.convert(field.state, weather, day_time, temperature, wind, humidy)]
|
||||||
|
|
||||||
|
dtree = joblib.load('treedata\\DecisionTree.pkl')
|
||||||
|
|
||||||
decision = dtree.predict(question)
|
decision = dtree.predict(question)
|
||||||
|
|
||||||
if tractor.autodrive:
|
if tractor.autodrive:
|
||||||
|
BIN
treedata/DecisionTree.pkl
Normal file
BIN
treedata/DecisionTree.pkl
Normal file
Binary file not shown.
Before Width: | Height: | Size: 122 KiB After Width: | Height: | Size: 122 KiB |
Loading…
Reference in New Issue
Block a user