relative path
This commit is contained in:
parent
135ab3e9c6
commit
7a95cdffdc
@ -9,13 +9,13 @@ from numpy import random
|
||||
|
||||
class DecisionTrees:
|
||||
def create_model(self):
|
||||
model = chef.fit(pd.read_csv("D:\\1 Python projects\Saper\data\db.txt"), {'algorithm': 'ID3'})
|
||||
model = chef.fit(pd.read_csv("data/db.txt"), {'algorithm': 'ID3'})
|
||||
return model
|
||||
|
||||
def return_predict(self, mod):
|
||||
|
||||
# read data
|
||||
df = pd.read_csv("D:\\1 Python projects\Saper\data\db.txt")
|
||||
#df = pd.read_csv("data/db.txt")
|
||||
|
||||
# Header of df looks like:
|
||||
header = ['Size(bigger_more_difficult)', 'Year(older_more_difficult)', 'Protection_from_defuse',
|
||||
@ -26,7 +26,7 @@ class DecisionTrees:
|
||||
# print(df.head())
|
||||
|
||||
# ID3 config
|
||||
config = {'algorithm': 'ID3'}
|
||||
#config = {'algorithm': 'ID3'}
|
||||
# create decision tree
|
||||
|
||||
# print predict
|
||||
|
31
outputs/rules/rules.json
Normal file
31
outputs/rules/rules.json
Normal file
@ -0,0 +1,31 @@
|
||||
[
|
||||
{"current_level": 1, "leaf_id": "2365989b-d788-11ec-ad21-989096c0661b", "parents": "root", "rule": "else: return 'detonate'", "feature_idx": -1, "feature_name": "", "instances": 200, "metric": 0, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 1, "leaf_id": "23660db8-d788-11ec-bced-989096c0661b", "parents": "root", "rule": "if obj[4]<=80.67436609605278:", "feature_idx": 4, "feature_name": "Random_detonation_chance", "instances": 200, "metric": 0.9964625048848765, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 2, "leaf_id": "2375e9de-d788-11ec-b6b3-989096c0661b", "parents": "23660db8-d788-11ec-bced-989096c0661b", "rule": "else: return 'detonate'", "feature_idx": -1, "feature_name": "", "instances": 161, "metric": 0, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 2, "leaf_id": "23765f02-d788-11ec-a11c-989096c0661b", "parents": "23660db8-d788-11ec-bced-989096c0661b", "rule": "if obj[2]<=0:", "feature_idx": 2, "feature_name": "Protection_from_defuse", "instances": 161, "metric": 0.9203523274205176, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 3, "leaf_id": "23843fa3-d788-11ec-a4cb-989096c0661b", "parents": "23765f02-d788-11ec-a11c-989096c0661b", "rule": "else: return 'detonate'", "feature_idx": -1, "feature_name": "", "instances": 135, "metric": 0, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 3, "leaf_id": "2384dbcd-d788-11ec-9ba5-989096c0661b", "parents": "23765f02-d788-11ec-a11c-989096c0661b", "rule": "if obj[3]<=7:", "feature_idx": 3, "feature_name": "Meters_under_the_ground", "instances": 135, "metric": 0.7364977795505669, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 4, "leaf_id": "238e9e6b-d788-11ec-a378-989096c0661b", "parents": "2384dbcd-d788-11ec-9ba5-989096c0661b", "rule": "else: return 'defuse'", "feature_idx": -1, "feature_name": "", "instances": 116, "metric": 0, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 4, "leaf_id": "238f3a74-d788-11ec-9bce-989096c0661b", "parents": "2384dbcd-d788-11ec-9ba5-989096c0661b", "rule": "if obj[1]<=1997.8794790831414:", "feature_idx": 1, "feature_name": "Year(older_more_difficult)", "instances": 116, "metric": 0.3936164041111624, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 5, "leaf_id": "2396b383-d788-11ec-8968-989096c0661b", "parents": "238f3a74-d788-11ec-9bce-989096c0661b", "rule": "else: return 'defuse'", "feature_idx": -1, "feature_name": "", "instances": 97, "metric": 0, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 5, "leaf_id": "2397289c-d788-11ec-b91c-989096c0661b", "parents": "238f3a74-d788-11ec-9bce-989096c0661b", "rule": "if obj[5]<=2:", "feature_idx": 5, "feature_name": "Detonation_power_in_m", "instances": 97, "metric": 0.445693177722561, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 6, "leaf_id": "239af870-d788-11ec-bbcb-989096c0661b", "parents": "2397289c-d788-11ec-b91c-989096c0661b", "rule": "else: return 'defuse'", "feature_idx": -1, "feature_name": "", "instances": 65, "metric": 0, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 6, "leaf_id": "239b6d8d-d788-11ec-8837-989096c0661b", "parents": "2397289c-d788-11ec-b91c-989096c0661b", "rule": "if obj[0]>3:", "feature_idx": 0, "feature_name": "Size(bigger_more_difficult)", "instances": 65, "metric": 0.33352200393097664, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 7, "leaf_id": "239b9498-d788-11ec-8f14-989096c0661b", "parents": "239b6d8d-d788-11ec-8837-989096c0661b", "rule": "return 'defuse'", "feature_idx": 0, "feature_name": "Size(bigger_more_difficult)", "instances": 65, "metric": 0, "return_statement": 1, "tree_id": 0},
|
||||
{"current_level": 6, "leaf_id": "239e053c-d788-11ec-9160-989096c0661b", "parents": "2397289c-d788-11ec-b91c-989096c0661b", "rule": "if obj[0]<=3:", "feature_idx": 0, "feature_name": "Size(bigger_more_difficult)", "instances": 65, "metric": 0.33352200393097664, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 7, "leaf_id": "239e053d-d788-11ec-8738-989096c0661b", "parents": "239e053c-d788-11ec-9160-989096c0661b", "rule": "return 'defuse'", "feature_idx": 0, "feature_name": "Size(bigger_more_difficult)", "instances": 65, "metric": 0, "return_statement": 1, "tree_id": 0},
|
||||
{"current_level": 5, "leaf_id": "23a24a5e-d788-11ec-a4d3-989096c0661b", "parents": "238f3a74-d788-11ec-9bce-989096c0661b", "rule": "if obj[5]>2:", "feature_idx": 5, "feature_name": "Detonation_power_in_m", "instances": 97, "metric": 0.445693177722561, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 6, "leaf_id": "23a61a8f-d788-11ec-a496-989096c0661b", "parents": "23a24a5e-d788-11ec-a4d3-989096c0661b", "rule": "else: return 'defuse'", "feature_idx": -1, "feature_name": "", "instances": 32, "metric": 0, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 6, "leaf_id": "23a6b685-d788-11ec-9255-989096c0661b", "parents": "23a24a5e-d788-11ec-a4d3-989096c0661b", "rule": "if obj[0]<=7:", "feature_idx": 0, "feature_name": "Size(bigger_more_difficult)", "instances": 32, "metric": 0.6252624052234231, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 7, "leaf_id": "23a6b686-d788-11ec-ae9e-989096c0661b", "parents": "23a6b685-d788-11ec-9255-989096c0661b", "rule": "return 'defuse'", "feature_idx": 0, "feature_name": "Size(bigger_more_difficult)", "instances": 32, "metric": 0, "return_statement": 1, "tree_id": 0},
|
||||
{"current_level": 6, "leaf_id": "23a90020-d788-11ec-9c68-989096c0661b", "parents": "23a24a5e-d788-11ec-a4d3-989096c0661b", "rule": "if obj[0]>7:", "feature_idx": 0, "feature_name": "Size(bigger_more_difficult)", "instances": 32, "metric": 0.6252624052234231, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 7, "leaf_id": "23a90021-d788-11ec-9a09-989096c0661b", "parents": "23a90020-d788-11ec-9c68-989096c0661b", "rule": "return 'defuse'", "feature_idx": 0, "feature_name": "Size(bigger_more_difficult)", "instances": 32, "metric": 0, "return_statement": 1, "tree_id": 0},
|
||||
{"current_level": 4, "leaf_id": "23aef2b5-d788-11ec-a1db-989096c0661b", "parents": "2384dbcd-d788-11ec-9ba5-989096c0661b", "rule": "if obj[1]>1997.8794790831414:", "feature_idx": 1, "feature_name": "Year(older_more_difficult)", "instances": 116, "metric": 0.3936164041111624, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 5, "leaf_id": "23aef2b6-d788-11ec-b971-989096c0661b", "parents": "23aef2b5-d788-11ec-a1db-989096c0661b", "rule": "return 'defuse'", "feature_idx": 1, "feature_name": "Year(older_more_difficult)", "instances": 116, "metric": 0, "return_statement": 1, "tree_id": 0},
|
||||
{"current_level": 3, "leaf_id": "23b2e9bf-d788-11ec-b73d-989096c0661b", "parents": "23765f02-d788-11ec-a11c-989096c0661b", "rule": "if obj[3]>7:", "feature_idx": 3, "feature_name": "Meters_under_the_ground", "instances": 135, "metric": 0.7364977795505669, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 4, "leaf_id": "23b2e9c0-d788-11ec-82d9-989096c0661b", "parents": "23b2e9bf-d788-11ec-b73d-989096c0661b", "rule": "return 'detonate'", "feature_idx": 3, "feature_name": "Meters_under_the_ground", "instances": 135, "metric": 0, "return_statement": 1, "tree_id": 0},
|
||||
{"current_level": 2, "leaf_id": "23b6e0c5-d788-11ec-8b0a-989096c0661b", "parents": "23660db8-d788-11ec-bced-989096c0661b", "rule": "if obj[2]>0:", "feature_idx": 2, "feature_name": "Protection_from_defuse", "instances": 161, "metric": 0.9203523274205176, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 3, "leaf_id": "23b6e0c6-d788-11ec-a0d1-989096c0661b", "parents": "23b6e0c5-d788-11ec-8b0a-989096c0661b", "rule": "return 'detonate'", "feature_idx": 2, "feature_name": "Protection_from_defuse", "instances": 161, "metric": 0, "return_statement": 1, "tree_id": 0},
|
||||
{"current_level": 1, "leaf_id": "23bad7d9-d788-11ec-bd81-989096c0661b", "parents": "root", "rule": "if obj[4]>80.67436609605278:", "feature_idx": 4, "feature_name": "Random_detonation_chance", "instances": 200, "metric": 0.9964625048848765, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 2, "leaf_id": "23bad7da-d788-11ec-a18d-989096c0661b", "parents": "23bad7d9-d788-11ec-bd81-989096c0661b", "rule": "return 'detonate'", "feature_idx": 4, "feature_name": "Random_detonation_chance", "instances": 200, "metric": 0, "return_statement": 1, "tree_id": 0}
|
||||
]
|
37
outputs/rules/rules.py
Normal file
37
outputs/rules/rules.py
Normal file
@ -0,0 +1,37 @@
|
||||
def findDecision(obj): #obj[0]: Size(bigger_more_difficult), obj[1]: Year(older_more_difficult), obj[2]: Protection_from_defuse, obj[3]: Meters_under_the_ground, obj[4]: Random_detonation_chance, obj[5]: Detonation_power_in_m
|
||||
# {"feature": "Random_detonation_chance", "instances": 200, "metric_value": 0.9965, "depth": 1}
|
||||
if obj[4]<=80.67436609605278:
|
||||
# {"feature": "Protection_from_defuse", "instances": 161, "metric_value": 0.9204, "depth": 2}
|
||||
if obj[2]<=0:
|
||||
# {"feature": "Meters_under_the_ground", "instances": 135, "metric_value": 0.7365, "depth": 3}
|
||||
if obj[3]<=7:
|
||||
# {"feature": "Year(older_more_difficult)", "instances": 116, "metric_value": 0.3936, "depth": 4}
|
||||
if obj[1]<=1997.8794790831414:
|
||||
# {"feature": "Detonation_power_in_m", "instances": 97, "metric_value": 0.4457, "depth": 5}
|
||||
if obj[5]<=2:
|
||||
# {"feature": "Size(bigger_more_difficult)", "instances": 65, "metric_value": 0.3335, "depth": 6}
|
||||
if obj[0]>3:
|
||||
return 'defuse'
|
||||
elif obj[0]<=3:
|
||||
return 'defuse'
|
||||
else: return 'defuse'
|
||||
elif obj[5]>2:
|
||||
# {"feature": "Size(bigger_more_difficult)", "instances": 32, "metric_value": 0.6253, "depth": 6}
|
||||
if obj[0]<=7:
|
||||
return 'defuse'
|
||||
elif obj[0]>7:
|
||||
return 'defuse'
|
||||
else: return 'defuse'
|
||||
else: return 'defuse'
|
||||
elif obj[1]>1997.8794790831414:
|
||||
return 'defuse'
|
||||
else: return 'defuse'
|
||||
elif obj[3]>7:
|
||||
return 'detonate'
|
||||
else: return 'detonate'
|
||||
elif obj[2]>0:
|
||||
return 'detonate'
|
||||
else: return 'detonate'
|
||||
elif obj[4]>80.67436609605278:
|
||||
return 'detonate'
|
||||
else: return 'detonate'
|
@ -1 +1,2 @@
|
||||
pygame
|
||||
pygame
|
||||
chefboost
|
Loading…
Reference in New Issue
Block a user