Merge pull request 'ID3 - drzewo decyzyjne' (#2) from ID3 into master

Reviewed-on: #2
This commit is contained in:
Zuzanna Myszczuk 2023-05-24 18:28:18 +02:00
commit 16b056047c
15 changed files with 708 additions and 0 deletions

3
.vs/ProjectSettings.json Normal file
View File

@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}

View File

@ -0,0 +1,8 @@
{
"ExpandedNodes": [
"",
"\\decisionTree"
],
"SelectedNode": "\\decisionTree\\decisionTree.sav",
"PreviewInSolutionExplorer": false
}

Binary file not shown.

BIN
.vs/slnx.sqlite Normal file

Binary file not shown.

200
decisionTree/database.txt Normal file
View File

@ -0,0 +1,200 @@
11100101
11011110
00001101
11101002
11111000
11101013
00100102
00000001
10011002
01011000
01111112
00010113
10111011
00111000
10010002
01011100
00110001
11001000
11011103
01100002
01110011
11101113
10110101
01010113
11101111
11000013
01001011
10101111
01110112
10000001
00110000
10000112
01111013
10100012
11010100
11001011
10001002
01001103
00011110
10101102
01111102
01000111
01000010
00110002
11111010
11101000
11000100
01010100
01001112
00101011
11101010
00010011
01001113
01001002
01101111
11100102
11111112
00111001
11110111
11011112
10001101
11100001
10101101
00111110
00101112
11100111
00100002
01011103
10111100
00100100
00001010
00001012
10100102
00001013
01011003
11111102
00011000
00101013
10111103
10100010
11111003
11000000
01100101
10010101
10011101
10101000
01100000
00111103
11000011
10010012
00111003
01001010
10101003
00010003
10000102
10110113
00011013
01011012
01100112
10010111
01110100
00110113
10000012
01100010
01100100
00110010
00110102
10100003
10000111
11010103
11011012
01111100
00000100
11100113
11101103
10111003
00110101
00011100
01100001
11100011
10110010
01001102
10101011
10000002
11100000
11101102
01110101
01100102
01001012
11111101
01110001
11000010
01010011
01100004
01000001
11010112
10110003
00010012
00001110
01001100
01001111
11010003
00000110
00110112
10110102
01111002
11110110
11010111
11111100
10111013
10001003
11100003
00110013
10100103
01010002
00001100
10001010
00100110
10110100
10000011
10101112
11110003
11011013
10101110
00001011
10010112
01100110
01010112
11011111
01011001
01101103
10000010
00110111
01001110
11001003
11110002
00111113
00000112
10100002
10110002
10001102
10010000
01111103
00000012
10000003
00011103
11000110
11001002
11010002
01110012
00100013
00010103
01110111
10010113
01010003
11001110
00011112
00010101
10100101
01011101

Binary file not shown.

200
decisionTree/decissions.txt Normal file
View File

@ -0,0 +1,200 @@
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

21
decisionTree/generator.py Normal file
View File

@ -0,0 +1,21 @@
import random
# Generowanie unikalnej losowej linii tekstu
def generate_unique_line(existing_lines):
while True:
line = ''.join(random.choice(['0', '1']) for _ in range(7))
last_digit = random.choice(['1', '2', '3', '0'])
line += last_digit
if line not in existing_lines:
return line
# Generowanie 200 unikalnych linii tekstu
lines = []
while len(lines) < 200:
line = generate_unique_line(lines)
lines.append(line)
# Zapisywanie linii tekstu do pliku
with open('decisionTree/database.txt', 'w') as file:
for line in lines:
file.write(line + '\n')

View File

@ -0,0 +1,200 @@
['rainy', 'planted', 'good', 'good', 'no snow', 'moist', 'healthy', 'noon']
['rainy', 'planted', 'bad', 'too strong', 'snow', 'moist', 'rot', 'morning']
['clear', 'not planted', 'bad', 'good', 'snow', 'moist', 'healthy', 'noon']
['rainy', 'planted', 'good', 'good', 'snow', 'dry', 'healthy', 'sunset']
['rainy', 'planted', 'good', 'too strong', 'snow', 'dry', 'healthy', 'morning']
['rainy', 'planted', 'good', 'good', 'snow', 'dry', 'rot', 'night']
['clear', 'not planted', 'good', 'good', 'no snow', 'moist', 'healthy', 'sunset']
['clear', 'not planted', 'bad', 'good', 'no snow', 'dry', 'healthy', 'noon']
['rainy', 'not planted', 'bad', 'too strong', 'snow', 'dry', 'healthy', 'sunset']
['clear', 'planted', 'bad', 'too strong', 'snow', 'dry', 'healthy', 'morning']
['clear', 'planted', 'good', 'too strong', 'snow', 'moist', 'rot', 'sunset']
['clear', 'not planted', 'bad', 'too strong', 'no snow', 'moist', 'rot', 'night']
['rainy', 'not planted', 'good', 'too strong', 'snow', 'dry', 'rot', 'noon']
['clear', 'not planted', 'good', 'too strong', 'snow', 'dry', 'healthy', 'morning']
['rainy', 'not planted', 'bad', 'too strong', 'no snow', 'dry', 'healthy', 'sunset']
['clear', 'planted', 'bad', 'too strong', 'snow', 'moist', 'healthy', 'morning']
['clear', 'not planted', 'good', 'too strong', 'no snow', 'dry', 'healthy', 'noon']
['rainy', 'planted', 'bad', 'good', 'snow', 'dry', 'healthy', 'morning']
['rainy', 'planted', 'bad', 'too strong', 'snow', 'moist', 'healthy', 'night']
['clear', 'planted', 'good', 'good', 'no snow', 'dry', 'healthy', 'sunset']
['clear', 'planted', 'good', 'too strong', 'no snow', 'dry', 'rot', 'noon']
['rainy', 'planted', 'good', 'good', 'snow', 'moist', 'rot', 'night']
['rainy', 'not planted', 'good', 'too strong', 'no snow', 'moist', 'healthy', 'noon']
['clear', 'planted', 'bad', 'too strong', 'no snow', 'moist', 'rot', 'night']
['rainy', 'planted', 'good', 'good', 'snow', 'moist', 'rot', 'noon']
['rainy', 'planted', 'bad', 'good', 'no snow', 'dry', 'rot', 'night']
['clear', 'planted', 'bad', 'good', 'snow', 'dry', 'rot', 'noon']
['rainy', 'not planted', 'good', 'good', 'snow', 'moist', 'rot', 'noon']
['clear', 'planted', 'good', 'too strong', 'no snow', 'moist', 'rot', 'sunset']
['rainy', 'not planted', 'bad', 'good', 'no snow', 'dry', 'healthy', 'noon']
['clear', 'not planted', 'good', 'too strong', 'no snow', 'dry', 'healthy', 'morning']
['rainy', 'not planted', 'bad', 'good', 'no snow', 'moist', 'rot', 'sunset']
['clear', 'planted', 'good', 'too strong', 'snow', 'dry', 'rot', 'night']
['rainy', 'not planted', 'good', 'good', 'no snow', 'dry', 'rot', 'sunset']
['rainy', 'planted', 'bad', 'too strong', 'no snow', 'moist', 'healthy', 'morning']
['rainy', 'planted', 'bad', 'good', 'snow', 'dry', 'rot', 'noon']
['rainy', 'not planted', 'bad', 'good', 'snow', 'dry', 'healthy', 'sunset']
['clear', 'planted', 'bad', 'good', 'snow', 'moist', 'healthy', 'night']
['clear', 'not planted', 'bad', 'too strong', 'snow', 'moist', 'rot', 'morning']
['rainy', 'not planted', 'good', 'good', 'snow', 'moist', 'healthy', 'sunset']
['clear', 'planted', 'good', 'too strong', 'snow', 'moist', 'healthy', 'sunset']
['clear', 'planted', 'bad', 'good', 'no snow', 'moist', 'rot', 'noon']
['clear', 'planted', 'bad', 'good', 'no snow', 'dry', 'rot', 'morning']
['clear', 'not planted', 'good', 'too strong', 'no snow', 'dry', 'healthy', 'sunset']
['rainy', 'planted', 'good', 'too strong', 'snow', 'dry', 'rot', 'morning']
['rainy', 'planted', 'good', 'good', 'snow', 'dry', 'healthy', 'morning']
['rainy', 'planted', 'bad', 'good', 'no snow', 'moist', 'healthy', 'morning']
['clear', 'planted', 'bad', 'too strong', 'no snow', 'moist', 'healthy', 'morning']
['clear', 'planted', 'bad', 'good', 'snow', 'moist', 'rot', 'sunset']
['clear', 'not planted', 'good', 'good', 'snow', 'dry', 'rot', 'noon']
['rainy', 'planted', 'good', 'good', 'snow', 'dry', 'rot', 'morning']
['clear', 'not planted', 'bad', 'too strong', 'no snow', 'dry', 'rot', 'noon']
['clear', 'planted', 'bad', 'good', 'snow', 'moist', 'rot', 'night']
['clear', 'planted', 'bad', 'good', 'snow', 'dry', 'healthy', 'sunset']
['clear', 'planted', 'good', 'good', 'snow', 'moist', 'rot', 'noon']
['rainy', 'planted', 'good', 'good', 'no snow', 'moist', 'healthy', 'sunset']
['rainy', 'planted', 'good', 'too strong', 'snow', 'moist', 'rot', 'sunset']
['clear', 'not planted', 'good', 'too strong', 'snow', 'dry', 'healthy', 'noon']
['rainy', 'planted', 'good', 'too strong', 'no snow', 'moist', 'rot', 'noon']
['rainy', 'planted', 'bad', 'too strong', 'snow', 'moist', 'rot', 'sunset']
['rainy', 'not planted', 'bad', 'good', 'snow', 'moist', 'healthy', 'noon']
['rainy', 'planted', 'good', 'good', 'no snow', 'dry', 'healthy', 'noon']
['rainy', 'not planted', 'good', 'good', 'snow', 'moist', 'healthy', 'noon']
['clear', 'not planted', 'good', 'too strong', 'snow', 'moist', 'rot', 'morning']
['clear', 'not planted', 'good', 'good', 'snow', 'moist', 'rot', 'sunset']
['rainy', 'planted', 'good', 'good', 'no snow', 'moist', 'rot', 'noon']
['clear', 'not planted', 'good', 'good', 'no snow', 'dry', 'healthy', 'sunset']
['clear', 'planted', 'bad', 'too strong', 'snow', 'moist', 'healthy', 'night']
['rainy', 'not planted', 'good', 'too strong', 'snow', 'moist', 'healthy', 'morning']
['clear', 'not planted', 'good', 'good', 'no snow', 'moist', 'healthy', 'morning']
['clear', 'not planted', 'bad', 'good', 'snow', 'dry', 'rot', 'morning']
['clear', 'not planted', 'bad', 'good', 'snow', 'dry', 'rot', 'sunset']
['rainy', 'not planted', 'good', 'good', 'no snow', 'moist', 'healthy', 'sunset']
['clear', 'not planted', 'bad', 'good', 'snow', 'dry', 'rot', 'night']
['clear', 'planted', 'bad', 'too strong', 'snow', 'dry', 'healthy', 'night']
['rainy', 'planted', 'good', 'too strong', 'snow', 'moist', 'healthy', 'sunset']
['clear', 'not planted', 'bad', 'too strong', 'snow', 'dry', 'healthy', 'morning']
['clear', 'not planted', 'good', 'good', 'snow', 'dry', 'rot', 'night']
['rainy', 'not planted', 'good', 'too strong', 'snow', 'moist', 'healthy', 'night']
['rainy', 'not planted', 'good', 'good', 'no snow', 'dry', 'rot', 'morning']
['rainy', 'planted', 'good', 'too strong', 'snow', 'dry', 'healthy', 'night']
['rainy', 'planted', 'bad', 'good', 'no snow', 'dry', 'healthy', 'morning']
['clear', 'planted', 'good', 'good', 'no snow', 'moist', 'healthy', 'noon']
['rainy', 'not planted', 'bad', 'too strong', 'no snow', 'moist', 'healthy', 'noon']
['rainy', 'not planted', 'bad', 'too strong', 'snow', 'moist', 'healthy', 'noon']
['rainy', 'not planted', 'good', 'good', 'snow', 'dry', 'healthy', 'morning']
['clear', 'planted', 'good', 'good', 'no snow', 'dry', 'healthy', 'morning']
['clear', 'not planted', 'good', 'too strong', 'snow', 'moist', 'healthy', 'night']
['rainy', 'planted', 'bad', 'good', 'no snow', 'dry', 'rot', 'noon']
['rainy', 'not planted', 'bad', 'too strong', 'no snow', 'dry', 'rot', 'sunset']
['clear', 'not planted', 'good', 'too strong', 'snow', 'dry', 'healthy', 'night']
['clear', 'planted', 'bad', 'good', 'snow', 'dry', 'rot', 'morning']
['rainy', 'not planted', 'good', 'good', 'snow', 'dry', 'healthy', 'night']
['clear', 'not planted', 'bad', 'too strong', 'no snow', 'dry', 'healthy', 'night']
['rainy', 'not planted', 'bad', 'good', 'no snow', 'moist', 'healthy', 'sunset']
['rainy', 'not planted', 'good', 'too strong', 'no snow', 'moist', 'rot', 'night']
['clear', 'not planted', 'bad', 'too strong', 'snow', 'dry', 'rot', 'night']
['clear', 'planted', 'bad', 'too strong', 'snow', 'dry', 'rot', 'sunset']
['clear', 'planted', 'good', 'good', 'no snow', 'moist', 'rot', 'sunset']
['rainy', 'not planted', 'bad', 'too strong', 'no snow', 'moist', 'rot', 'noon']
['clear', 'planted', 'good', 'too strong', 'no snow', 'moist', 'healthy', 'morning']
['clear', 'not planted', 'good', 'too strong', 'no snow', 'moist', 'rot', 'night']
['rainy', 'not planted', 'bad', 'good', 'no snow', 'dry', 'rot', 'sunset']
['clear', 'planted', 'good', 'good', 'no snow', 'dry', 'rot', 'morning']
['clear', 'planted', 'good', 'good', 'no snow', 'moist', 'healthy', 'morning']
['clear', 'not planted', 'good', 'too strong', 'no snow', 'dry', 'rot', 'morning']
['clear', 'not planted', 'good', 'too strong', 'no snow', 'moist', 'healthy', 'sunset']
['rainy', 'not planted', 'good', 'good', 'no snow', 'dry', 'healthy', 'night']
['rainy', 'not planted', 'bad', 'good', 'no snow', 'moist', 'rot', 'noon']
['rainy', 'planted', 'bad', 'too strong', 'no snow', 'moist', 'healthy', 'night']
['rainy', 'planted', 'bad', 'too strong', 'snow', 'dry', 'rot', 'sunset']
['clear', 'planted', 'good', 'too strong', 'snow', 'moist', 'healthy', 'morning']
['clear', 'not planted', 'bad', 'good', 'no snow', 'moist', 'healthy', 'morning']
['rainy', 'planted', 'good', 'good', 'no snow', 'moist', 'rot', 'night']
['rainy', 'planted', 'good', 'good', 'snow', 'moist', 'healthy', 'night']
['rainy', 'not planted', 'good', 'too strong', 'snow', 'dry', 'healthy', 'night']
['clear', 'not planted', 'good', 'too strong', 'no snow', 'moist', 'healthy', 'noon']
['clear', 'not planted', 'bad', 'too strong', 'snow', 'moist', 'healthy', 'morning']
['clear', 'planted', 'good', 'good', 'no snow', 'dry', 'healthy', 'noon']
['rainy', 'planted', 'good', 'good', 'no snow', 'dry', 'rot', 'noon']
['rainy', 'not planted', 'good', 'too strong', 'no snow', 'dry', 'rot', 'morning']
['clear', 'planted', 'bad', 'good', 'snow', 'moist', 'healthy', 'sunset']
['rainy', 'not planted', 'good', 'good', 'snow', 'dry', 'rot', 'noon']
['rainy', 'not planted', 'bad', 'good', 'no snow', 'dry', 'healthy', 'sunset']
['rainy', 'planted', 'good', 'good', 'no snow', 'dry', 'healthy', 'morning']
['rainy', 'planted', 'good', 'good', 'snow', 'moist', 'healthy', 'sunset']
['clear', 'planted', 'good', 'too strong', 'no snow', 'moist', 'healthy', 'noon']
['clear', 'planted', 'good', 'good', 'no snow', 'moist', 'healthy', 'sunset']
['clear', 'planted', 'bad', 'good', 'snow', 'dry', 'rot', 'sunset']
['rainy', 'planted', 'good', 'too strong', 'snow', 'moist', 'healthy', 'noon']
['clear', 'planted', 'good', 'too strong', 'no snow', 'dry', 'healthy', 'noon']
['rainy', 'planted', 'bad', 'good', 'no snow', 'dry', 'rot', 'morning']
['clear', 'planted', 'bad', 'too strong', 'no snow', 'dry', 'rot', 'noon']
['clear', 'planted', 'good', 'good', 'no snow', 'dry', 'healthy', 'night']
['clear', 'planted', 'bad', 'good', 'no snow', 'dry', 'healthy', 'noon']
['rainy', 'planted', 'bad', 'too strong', 'no snow', 'moist', 'rot', 'sunset']
['rainy', 'not planted', 'good', 'too strong', 'no snow', 'dry', 'healthy', 'night']
['clear', 'not planted', 'bad', 'too strong', 'no snow', 'dry', 'rot', 'sunset']
['clear', 'not planted', 'bad', 'good', 'snow', 'moist', 'rot', 'morning']
['clear', 'planted', 'bad', 'good', 'snow', 'moist', 'healthy', 'morning']
['clear', 'planted', 'bad', 'good', 'snow', 'moist', 'rot', 'noon']
['rainy', 'planted', 'bad', 'too strong', 'no snow', 'dry', 'healthy', 'night']
['clear', 'not planted', 'bad', 'good', 'no snow', 'moist', 'rot', 'morning']
['clear', 'not planted', 'good', 'too strong', 'no snow', 'moist', 'rot', 'sunset']
['rainy', 'not planted', 'good', 'too strong', 'no snow', 'moist', 'healthy', 'sunset']
['clear', 'planted', 'good', 'too strong', 'snow', 'dry', 'healthy', 'sunset']
['rainy', 'planted', 'good', 'too strong', 'no snow', 'moist', 'rot', 'morning']
['rainy', 'planted', 'bad', 'too strong', 'no snow', 'moist', 'rot', 'noon']
['rainy', 'planted', 'good', 'too strong', 'snow', 'moist', 'healthy', 'morning']
['rainy', 'not planted', 'good', 'too strong', 'snow', 'dry', 'rot', 'night']
['rainy', 'not planted', 'bad', 'good', 'snow', 'dry', 'healthy', 'night']
['rainy', 'planted', 'good', 'good', 'no snow', 'dry', 'healthy', 'night']
['clear', 'not planted', 'good', 'too strong', 'no snow', 'dry', 'rot', 'night']
['rainy', 'not planted', 'good', 'good', 'no snow', 'moist', 'healthy', 'night']
['clear', 'planted', 'bad', 'too strong', 'no snow', 'dry', 'healthy', 'sunset']
['clear', 'not planted', 'bad', 'good', 'snow', 'moist', 'healthy', 'morning']
['rainy', 'not planted', 'bad', 'good', 'snow', 'dry', 'rot', 'morning']
['clear', 'not planted', 'good', 'good', 'no snow', 'moist', 'rot', 'morning']
['rainy', 'not planted', 'good', 'too strong', 'no snow', 'moist', 'healthy', 'morning']
['rainy', 'not planted', 'bad', 'good', 'no snow', 'dry', 'rot', 'noon']
['rainy', 'not planted', 'good', 'good', 'snow', 'moist', 'rot', 'sunset']
['rainy', 'planted', 'good', 'too strong', 'no snow', 'dry', 'healthy', 'night']
['rainy', 'planted', 'bad', 'too strong', 'snow', 'dry', 'rot', 'night']
['rainy', 'not planted', 'good', 'good', 'snow', 'moist', 'rot', 'morning']
['clear', 'not planted', 'bad', 'good', 'snow', 'dry', 'rot', 'noon']
['rainy', 'not planted', 'bad', 'too strong', 'no snow', 'moist', 'rot', 'sunset']
['clear', 'planted', 'good', 'good', 'no snow', 'moist', 'rot', 'morning']
['clear', 'planted', 'bad', 'too strong', 'no snow', 'moist', 'rot', 'sunset']
['rainy', 'planted', 'bad', 'too strong', 'snow', 'moist', 'rot', 'noon']
['clear', 'planted', 'bad', 'too strong', 'snow', 'dry', 'healthy', 'noon']
['clear', 'planted', 'good', 'good', 'snow', 'moist', 'healthy', 'night']
['rainy', 'not planted', 'bad', 'good', 'no snow', 'dry', 'rot', 'morning']
['clear', 'not planted', 'good', 'too strong', 'no snow', 'moist', 'rot', 'noon']
['clear', 'planted', 'bad', 'good', 'snow', 'moist', 'rot', 'morning']
['rainy', 'planted', 'bad', 'good', 'snow', 'dry', 'healthy', 'night']
['rainy', 'planted', 'good', 'too strong', 'no snow', 'dry', 'healthy', 'sunset']
['clear', 'not planted', 'good', 'too strong', 'snow', 'moist', 'rot', 'night']
['clear', 'not planted', 'bad', 'good', 'no snow', 'moist', 'rot', 'sunset']
['rainy', 'not planted', 'good', 'good', 'no snow', 'dry', 'healthy', 'sunset']
['rainy', 'not planted', 'good', 'too strong', 'no snow', 'dry', 'healthy', 'sunset']
['rainy', 'not planted', 'bad', 'good', 'snow', 'moist', 'healthy', 'sunset']
['rainy', 'not planted', 'bad', 'too strong', 'no snow', 'dry', 'healthy', 'morning']
['clear', 'planted', 'good', 'too strong', 'snow', 'moist', 'healthy', 'night']
['clear', 'not planted', 'bad', 'good', 'no snow', 'dry', 'rot', 'sunset']
['rainy', 'not planted', 'bad', 'good', 'no snow', 'dry', 'healthy', 'night']
['clear', 'not planted', 'bad', 'too strong', 'snow', 'moist', 'healthy', 'night']
['rainy', 'planted', 'bad', 'good', 'no snow', 'moist', 'rot', 'morning']
['rainy', 'planted', 'bad', 'good', 'snow', 'dry', 'healthy', 'sunset']
['rainy', 'planted', 'bad', 'too strong', 'no snow', 'dry', 'healthy', 'sunset']
['clear', 'planted', 'good', 'too strong', 'no snow', 'dry', 'rot', 'sunset']
['clear', 'not planted', 'good', 'good', 'no snow', 'dry', 'rot', 'night']
['clear', 'not planted', 'bad', 'too strong', 'no snow', 'moist', 'healthy', 'night']
['clear', 'planted', 'good', 'too strong', 'no snow', 'moist', 'rot', 'noon']
['rainy', 'not planted', 'bad', 'too strong', 'no snow', 'moist', 'rot', 'night']
['clear', 'planted', 'bad', 'too strong', 'no snow', 'dry', 'healthy', 'night']
['rainy', 'planted', 'bad', 'good', 'snow', 'moist', 'rot', 'morning']
['clear', 'not planted', 'bad', 'too strong', 'snow', 'moist', 'rot', 'sunset']
['clear', 'not planted', 'bad', 'too strong', 'no snow', 'moist', 'healthy', 'noon']
['rainy', 'not planted', 'good', 'good', 'no snow', 'moist', 'healthy', 'noon']
['clear', 'planted', 'bad', 'too strong', 'snow', 'moist', 'healthy', 'noon']

76
decisionTree/treemaker.py Normal file
View File

@ -0,0 +1,76 @@
#from sklearn.datasets import load_iris
from sklearn.tree import export_text
from sklearn.tree import DecisionTreeClassifier
import joblib
X1 = []
view = []
with open("decisionTree/database.txt", 'r') as f:
for line in f:
line = line.strip()
test_list = [int(i) for i in line]
x = []
if line[0] == "0":
x.append("clear")
else:
x.append("rainy")
if line[1] == "0":
x.append("not planted")
else:
x.append("planted")
if line[2] == "0":
x.append("bad")
else:
x.append("good")
if line[3] == "0":
x.append("good")
else:
x.append("too strong")
if line[4] == "0":
x.append("no snow")
else:
x.append("snow")
if line[5] == "0":
x.append("dry")
else:
x.append("moist")
if line[6] == "0":
x.append("healthy")
else:
x.append("rot")
if line[7] == "0":
x.append("morning")
elif line[7] == "1":
x.append("noon")
elif line[7] == "2":
x.append("sunset")
else:
x.append("night")
view.append(x)
X1.append(test_list)
f = open("decisionTree/learning_set.txt", "w") #zapisuje atrybuty s³ownie
for i in view:
f.write(str(i)+"\n")
f.close()
Y1 = []
with open("decisionTree/decissions.txt", 'r') as f: #czyta decyzje
for line in f:
line = line.strip()
test = int(line)
Y1.append(test)
dataset = X1
decision = Y1
labels = ['Rain','Plant','Temperature','Sun','Snow','Moisture','Rotten','Time']
model = DecisionTreeClassifier(random_state=0, max_depth=20).fit(dataset, decision)
filename = 'decisionTree/decisionTree.sav'
print("Model trained")
print("Decision tree:")
print(export_text(model, feature_names=labels))
joblib.dump(model, filename)