2022-05-19 01:16:58 +02:00
|
|
|
from chefboost import Chefboost as chef
|
|
|
|
from multiprocessing import freeze_support
|
|
|
|
import pandas as pd
|
|
|
|
from numpy import random
|
|
|
|
|
|
|
|
|
|
|
|
class DecisionTrees:
|
2022-05-19 10:42:46 +02:00
|
|
|
|
2022-05-19 01:16:58 +02:00
|
|
|
def return_predict(self):
|
2022-05-19 10:42:46 +02:00
|
|
|
# Header looks like:
|
2022-05-19 01:16:58 +02:00
|
|
|
# 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())
|
|
|
|
|
|
|
|
# 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]))
|
|
|
|
|
2022-05-19 10:42:46 +02:00
|
|
|
size = random.randint(1, 10)
|
|
|
|
year = random.randint(1941, 2022)
|
|
|
|
protection = 0
|
|
|
|
if year >= 2000:
|
|
|
|
protection = random.choice([1, 0, 1])
|
|
|
|
m_under_the_ground = random.randint(0, 10)
|
|
|
|
detonation_chance = random.randint(0, 100)
|
|
|
|
detonation_power_in_m = random.randint(0, 10)
|
|
|
|
detonation_power_in_m = detonation_power_in_m - m_under_the_ground
|
|
|
|
if detonation_power_in_m <= 0:
|
|
|
|
detonation_power_in_m = 0
|
|
|
|
|
|
|
|
mine_characteristics = [size, year, protection, m_under_the_ground, detonation_chance, detonation_power_in_m]
|
|
|
|
|
|
|
|
print(mine_characteristics)
|
|
|
|
return chef.predict(model, mine_characteristics)
|