InteligentnySaper/classes/decisionTrees.py

51 lines
1.5 KiB
Python

from chefboost import Chefboost as chef
from multiprocessing import freeze_support
import pandas as pd
from numpy import random
class DecisionTrees:
def return_predict(self):
# header = ['Size(bigger_more_difficult)', 'Year(older_more_difficult)', 'Protection_from_defuse',
# 'Meters_under_the_ground', 'Random_detonation_chance', 'Detonation_power_in_m',
# 'Decision']
# read data
df = pd.read_csv("D:\\1 Python projects\Saper\data\db.txt")
# print data
# print(df.head())
lines = []
with open('D:\\1 Python projects\Saper\data\db.txt') as f:
line = f.readline()
for i in range(0, 200):
line = f.readline()
line = line.rstrip()
line = line.replace(",detonate", "")
line = line.replace(",defuse", "")
lines.append(line)
ss = []
for line in lines:
ss.append(line.split(","))
normalized_data_for_predict = []
for i in ss:
normalized_data_for_predict.append(list(map(int, i)))
print(normalized_data_for_predict)
# ID3 config
config = {'algorithm': 'ID3'}
# create decision tree
model = chef.fit(df, config)
# print predict
# print(chef.predict(model, [1, 2022, 0, 0, 0, 10]))
predict = normalized_data_for_predict[random.randint(0, 199)]
return chef.predict(model, predict)