diff --git a/LabWork01/LabWork6/ConvertorDataFrame.py b/LabWork01/LabWork6/ConvertorDataFrame.py
index 6ffb1c7..5cea1a8 100644
--- a/LabWork01/LabWork6/ConvertorDataFrame.py
+++ b/LabWork01/LabWork6/ConvertorDataFrame.py
@@ -1,6 +1,6 @@
import pandas as pd
-def covertorDataFrame():
+def CovertorDataFrame():
df = pd.read_csv("res/Stores.csv")
@@ -14,7 +14,7 @@ def covertorDataFrame():
lambda x: 'Small_Area' if x <= 1100 else ('Average_Area' if 1100 < x <= 1700 else 'Big_Area'))
mainDF['TextStoreSales'] = mainDF['Store_Sales'].apply(
- lambda x: 'Small_Sales' if x <= 50000 else ('Average_Sales' if 50000 < x <= 80000 else 'Big_Sales'))
+ lambda x: 'Small_Sales' if x <= 50000 else ('Average_Sales' if 50000 < x <= 70000 else 'Big_Sales'))
mainDF['TextDailyCustomerCount'] = mainDF['Daily_Customer_Count'].apply(
lambda x: 'Small_Customer' if x <= 400 else ('Average_Customer' if 400 < x <= 900 else 'Big_Customer'))
diff --git a/LabWork01/LabWork6/ReservCopy/CopyTree.py b/LabWork01/LabWork6/ReservCopy/CopyTree.py
index 0504c71..d47561e 100644
--- a/LabWork01/LabWork6/ReservCopy/CopyTree.py
+++ b/LabWork01/LabWork6/ReservCopy/CopyTree.py
@@ -2,7 +2,7 @@ import math
import pandas as pd
from functools import reduce
-from LabWork01.LabWork6.ConvertorDataFrame import covertorDataFrame
+from LabWork01.LabWork6.ConvertorDataFrame import CovertorDataFrame
# Дата сет
# data = [
@@ -18,7 +18,7 @@ from LabWork01.LabWork6.ConvertorDataFrame import covertorDataFrame
# df0 = pd.DataFrame(data)
# df0.columns = ["цвет", "форма", "результат"]
-df0 = covertorDataFrame()[0]
+df0 = CovertorDataFrame()[0]
# Лямбда-выражение для распределения значений, аргумент - pandas.Series,
# возвращаемое значение - массив с количеством каждого из значений
diff --git a/LabWork01/LabWork6/Tree.py b/LabWork01/LabWork6/Tree.py
index 0b749af..f8ea184 100644
--- a/LabWork01/LabWork6/Tree.py
+++ b/LabWork01/LabWork6/Tree.py
@@ -1,19 +1,20 @@
import math
from functools import reduce
-from LabWork01.LabWork6.ConvertorDataFrame import covertorDataFrame
+from LabWork01.LabWork6.ConvertorDataFrame import CovertorDataFrame
# дата-сет
-df0 = covertorDataFrame()[0]
+dfMain = CovertorDataFrame()[0]
+dfTest = CovertorDataFrame()[1]
cstr = lambda s: [k + ":" + str(v) for k, v in sorted(s.value_counts().items())]
# Структура данных Decision Tree
tree = {
# name: Название этого нода (узла)
- "name": "decision tree " + df0.columns[-1] + " " + str(cstr(df0.iloc[:, -1])),
+ "name": "decision tree " + dfMain.columns[-1] + " " + str(cstr(dfMain.iloc[:, -1])),
# df: Данные, связанные с этим нодом (узлом)
- "df": df0,
+ "df": dfMain,
# edges: Список ребер (ветвей), выходящих из этого узла, или пустой массив, если ниже нет листового узла.
"edges": [],
}
@@ -61,13 +62,37 @@ while (len(open) != 0):
pass
# Выводим дата сет
-print(df0, "\n-------------")
+print(dfMain, "\n-------------")
+
+# оценка тестовых данных
+def predict_bp(nodes, target) -> int:
+ overlap = None
+ for node in nodes:
+ check: bool = node["value"] == target[node["attr"]]
+ if check:
+ overlap = node
+ break
+ if overlap is None:
+ overlap = nodes[-1]
+ if len(overlap["edges"]) == 0:
+ return int(overlap["df"]["StoreSales"].mean())
+ else:
+ return predict_bp(overlap["edges"], target)
+
+def predict_str(count: int):
+ predictions = []
+ for i in range(count):
+ row = dfTest.iloc[i]
+ prediction = f"{ {'Age': row['Age'], 'BMI': row['BMI']} }" + \
+ f"
predict {predict_bp(tree['edges'], {'Age': row['Age'], 'BMI': row['BMI']})} / fact {row['BloodPressure']}"
+ predictions.append(prediction)
+ return '
'.join(predictions)
def tstr(tree, indent=""):
s = indent + tree["name"] + str(cstr(tree["df"].iloc[:, -1]) if len(tree["edges"]) == 0 else "") + "\n"
# Зацикливаем все ветви этого узла.
for e in tree["edges"]:
- s += tstr(e, indent + " ")
+ s += tstr(e, "\t" + indent + " ")
pass
return s
diff --git a/LabWork01/LoadDB.py b/LabWork01/LoadDB.py
index 1457cd6..bf5c2c7 100644
--- a/LabWork01/LoadDB.py
+++ b/LabWork01/LoadDB.py
@@ -14,7 +14,7 @@ from LabWork01.LabWork3.CustomGraphics import createCusGraphics
from LabWork01.LabWork3.DeletePng import deleteAllPng
from LabWork01.LabWork4.SiteSearch import SiteSearch
from LabWork01.LabWork5.create_plot import create_plot_jpg
-from LabWork01.LabWork6.ConvertorDataFrame import covertorDataFrame
+from LabWork01.LabWork6.ConvertorDataFrame import CovertorDataFrame
from LabWork01.LabWork6.Tree import getStringTree
app = Flask(__name__)
@@ -216,7 +216,7 @@ def get_plot_image():
@app.route('/createTree', methods=['GET'])
def get_data_Tree():
- DataTree = getStringTree()
+ DataTree = getStringTree().split('\n')
return render_template('tree_page.html', DataTree=DataTree)
diff --git a/LabWork01/templates/tree_page.html b/LabWork01/templates/tree_page.html
index e2f8283..56b9230 100644
--- a/LabWork01/templates/tree_page.html
+++ b/LabWork01/templates/tree_page.html
@@ -23,7 +23,15 @@
{{ DataTree }}
+ {% for item in DataTree %} + {% if item.count("\t") == 1 %} +{{ item }}
+ {% elif item.count("\t") == 2 %} +{{ item }}
+ {% else %} +{{ item }}
+ {% endif %} + {% endfor %}