AI_PRO/createTreeData.py
2021-05-19 04:11:26 +02:00

102 lines
2.7 KiB
Python

from itertools import product
import numpy as np
import pandas as pd
import csv
import id3test
import pprint
import sys
import pandas
from sklearn import tree
import pydotplus
from sklearn.tree import DecisionTreeClassifier
import matplotlib.pyplot as plt
import matplotlib.image as pltimg
# stan pola: toCut, toPlow, toWater, toSeed, toFertilize
# pora dnia: dzień, noc
# pogoda: sunny, cloudy, rainy, hail
# temperatura: freezing, cold, mild, hot
# wiatr: windless, strong wind, gale
# humidy: low, high
field_states = ['toPlow', 'toWater', 'toSeed', 'toFertilize', 'toCut']
day_time = ['Day', 'Night']
weather = ['Clear Sky', 'Cloudy', 'Rainy', 'Hail']
temperature = ['Freezing', 'Cold', 'Mild', 'Hot']
wind = ['Windless', 'Strong Wind', 'Gale']
humidy = ['Low', 'High']
output = list(product(field_states, day_time, weather, temperature, wind, humidy))
dict = []
for x in range(len(output)):
while True:
mField = output[x][0]
mDay_time = output[x][1]
mWeather = output[x][2]
mTemperature = output[x][3]
mWind = output[x][4]
mHumidy = output[x][5]
mDecision = 'null'
# pora dnia: dzień 2, noc -2
# pogoda: sunny+3, cloudy+3, rainy-2, hail-5
# temperatura: freezing -3, cold-1, mild+4, hot+2
# wiatr: windless +2, strong wind-1, gale-3
# humidy: low+2, high-3
if mDay_time == 'Day':
valDay_time = 2
else:
valDay_time = -3
if mWeather == 'Sunny' or 'Cloudy':
valWeather = 3
elif mWeather == 'Rainy':
valWeather = -2
else:
valWeather = -5
if mTemperature == 'Freezing':
valTemperature = -3
elif mTemperature == 'Cold':
valTemperature = -1
elif mTemperature == 'Mild':
valTemperature = 4
else:
valTemperature = 2
if mWind == 'Windless':
valWind = +2
elif mWind == 'Strong Wind':
valWind = -1
else:
valWind = -3
if humidy == 'Low':
valHumidy = 2
else:
valHumidy = -2
result = valDay_time + valWeather + valTemperature + valWind + valHumidy
if result >= 0:
mDecision = "Make Action"
else:
mDecision = "Wait"
break
dict.append({'Field': mField, 'Day Time': mDay_time, 'Weather': mWeather,
'Temperature': mTemperature, 'Wind': mWind, 'Humidy': mHumidy, 'Decision': mDecision})
fields = ['Field', 'Day Time', 'Weather', 'Temperature', 'Wind', 'Humidy', 'Decision']
filename = "treedata\\data.csv"
with open(filename, 'w') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=fields)
writer.writeheader()
writer.writerows(dict)