decision tree

This commit is contained in:
Łukasz 2021-05-19 04:02:14 +02:00
parent b12ed9bcda
commit 34599b9bfc
2 changed files with 54 additions and 0 deletions

10
WeatherConditions.py Normal file
View File

@ -0,0 +1,10 @@
import random
def checkConditions():
weather = random.choice(['Sunny', 'Cloudy', 'Rainy', 'Hail'])
day_time = random.choice(['Day', 'Night'])
temperature = random.choice(['Freezing', 'Cold', 'Mild', 'Hot'])
wind = random.choice(['Windless', 'Strong Wind', 'Gale'])
humidy = random.choice(['Low', 'High'])
return weather, day_time, temperature, wind, humidy

44
decisiontree.py Normal file
View File

@ -0,0 +1,44 @@
import pandas
from sklearn import tree
import pydotplus
from sklearn.tree import DecisionTreeClassifier
import matplotlib.pyplot as plt
import matplotlib.image as pltimg
df = pandas.read_csv("treedata\\data3.csv")
#Map text values to number values
d = {'toPlow' : 0, 'toWater' : 1, 'toSeed' : 2, 'toFertilize' : 3, 'toCut' : 4}
df['Field'] = df['Field'].map(d)
d = {'Night' : 0, 'Day' : 1}
df['Day Time'] = df['Day Time'].map(d)
d = {'Sunny' : 0, 'Cloudy' : 1, 'Rainy' : 2, 'Hail': 3}
df['Weather'] = df['Weather'].map(d)
d = {'Freezing' : 0, 'Cold' : 1, 'Mild': 2, 'Hot': 3}
df['Temperature'] = df['Temperature'].map(d)
d = {'Windless' : 0, 'Strong Wind' : 1, 'Gale': 2}
df['Wind'] = df['Wind'].map(d)
d={'Low': 0, 'High': 1}
df['Humidy'] = df['Humidy'].map(d)
d = {'Wait' : 0, 'Make Action' : 1}
df['Decision'] = df['Decision'].map(d)
#Separate the feature columns from targert columns
features = ['Field', 'Day Time', 'Weather', 'Temperature', 'Wind', 'Humidy']
X = df[features]
y = df['Decision']
dtree = DecisionTreeClassifier()
dtree = dtree.fit(X, y)
#print(dtree.predict([[0, 1, 0, 0, 0, 1]]))