44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
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]])) |