<jupyter_start><jupyter_text>Необходимые библиотеки<jupyter_code>import sklearn.tree as tree
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.tree import DecisionTreeClassifier, DecisionTreeRegressor,plot_tree
import pydotplus
from sklearn.externals.six import StringIO 
from IPython.display import Image<jupyter_output><empty_output><jupyter_text>Чтение данных<jupyter_code>file_table="/content/drive/My Drive/Диссертация/data/data _Ulitca 17.04.xlsx"
DataListID=4
df=pd.read_excel(file_table,sheet_name=DataListID)
dft=pd.read_excel(file_table,sheet_name=1)<jupyter_output><empty_output><jupyter_text>Использование всех таблиц (необязательно)<jupyter_code>df_from_each_file=(pd.read_excel(file_table,sheet_name=i) for i in range(0,10,2))
dfvec=pd.concat(df_from_each_file, ignore_index=True).fillna(0)
df=dfvec<jupyter_output><empty_output><jupyter_text>Подготовка данных<jupyter_code>PC_map = {'YES': 1, 'NO': 0}
#df["PC"]=df["PC"].map(PC_map)

dft90=dft.T.copy()
dft90.columns=dft["Reference"]
dft90=dft90.drop(index="Reference")
df<jupyter_output><empty_output><jupyter_text>Проверка данных<jupyter_code>dft90
df<jupyter_output><empty_output><jupyter_text>Построение дерева решений<jupyter_code>attr_cols = [c for c in df if c.startswith('Attr')]
target_names=dft90[attr_cols].iloc[0].values
feature_names=df["PC"].values
X=df[attr_cols]
Y=df["PC"]
clf = tree.DecisionTreeClassifier()
clf = clf.fit(X,Y)
attr_cols.append("PC")<jupyter_output><empty_output><jupyter_text>Визуализация дерева решений<jupyter_code>dot_data = StringIO()
tree.export_graphviz(clf,
 out_file=dot_data,
 class_names=target_names, # the target names.
 filled=True, # Whether to fill in the boxes with colours.
 rounded=True, # Whether to round the corners of the boxes.
 special_characters=True)
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
Image(graph.create_png())<jupyter_output><empty_output><jupyter_text>Тестирование дерева решений<jupyter_code>def TestSec2PC(SecN):
    PC=clf.predict([X.iloc[SecN].values])
    print("Мы тестируем Sec = "+str(SecN)+" и получаем результат: нам нужен пешеходный переход на "+df['Name'].iloc[SecN]+": "+str(PC))

SecN=0
TestSec2PC(SecN)
SecN=9
TestSec2PC(SecN)

clf.predict([[1,0,0,0]])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1295971978984238, 'fraction_numerical': 0.01532399299474606, 'mean_word_length': 10.25615763546798, 'pattern_counts': {'":': 1, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '577547', 'license': 'MIT', 'n_tokens_mistral': 961, 'n_tokens_neox': 968, 'n_words': 133, 'path': 'SpDTree-1.ipynb', 'repo_name': 'arm2arm/SPiterDT', 'size': '2284'}