<jupyter_start><jupyter_text>METABRIC Data Set- **Input:** 350 clinical variables- **Output:** Classification, DR 1 or NDR 0 Preprocess Data<jupyter_code>raw_data = pd.read_csv(RAW_DATA_PATH)
raw_data.head()
# List of input features
feature_col_names = list(raw_data.columns)
feature_col_names.remove(target_col_name)
# Seperate input features and target column
X = raw_data.drop(columns=[target_col_name]).values  
y = raw_data[target_col_name].values
# Shuffle and store preprocessed data
data = pd.DataFrame(X, columns=feature_col_names)
data[target_col_name] = y
data.head()
assert data.columns[-1]==target_col_name, 'Target column must be last column in DataFrame'
import collections
collections.Counter(y)<jupyter_output><empty_output><jupyter_text>Save Clean Data<jupyter_code># Initialise new empty dataset folder
from model.generation.helpers import init_dataset_dir

path_to_data_folder = '../'
init_dataset_dir.run(dataset_name=dataset_name, path_to_data_folder=path_to_data_folder)
data_path = '../' + dataset_name + '/'
# Save cleaned data
data.to_csv(data_path + 'data.csv', index=False)<jupyter_output><empty_output><jupyter_text>Notepad<jupyter_code>from sklearn.tree import _tree
import numpy as np
def tree_to_code(tree, feature_names):
    tree_ = tree.tree_
    feature_name = [
        feature_names[i] if i != _tree.TREE_UNDEFINED else "undefined!"
        for i in tree_.feature
    ]
    pathto=dict()

    global k
    k = 0
    def recurse(node, depth, parent):
        global k
        indent = "  " * depth

        if tree_.feature[node] != _tree.TREE_UNDEFINED:
            name = feature_name[node]
            threshold = tree_.threshold[node]
            s= "{} <= {} ".format( name, threshold, node )
            if node == 0:
                pathto[node]=s
            else:
                pathto[node]=pathto[parent]+' & ' +s

            recurse(tree_.children_left[node], depth + 1, node)
            s="{} > {}".format( name, threshold)
            if node == 0:
                pathto[node]=s
            else:
                pathto[node]=pathto[parent]+' & ' +s
            recurse(tree_.children_right[node], depth + 1, node)
        else:
            k=k+1
            print(k,')',pathto[parent], np.argmax(tree_.value[node]))
    recurse(0, 1, 0)
from sklearn import tree
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.tree import _tree, DecisionTreeClassifier

iris = load_iris()
X = iris['data']
y = iris['target']

X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.3)
decision_tree = DecisionTreeClassifier(random_state=0, max_depth=3)
decision_tree = decision_tree.fit(X_train, y_train)
tree_to_code(decision_tree, iris["feature_names"])
pip install pydotplus
from sklearn.externals.six import StringIO  
from IPython.display import Image  
from sklearn.tree import export_graphviz
import pydotplus
dot_data = StringIO()
export_graphviz(decision_tree, out_file=dot_data,  
                filled=True, rounded=True,
                special_characters=True, feature_names = iris['feature_names'])
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())  
Image(graph.create_png())<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10918651407361583, 'fraction_numerical': 0.005876894525208784, 'mean_word_length': 3.8778280542986425, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '72925', 'license': 'MIT', 'n_tokens_mistral': 1104, 'n_tokens_neox': 1067, 'n_words': 223, 'path': 'data/preprocessing/.ipynb_checkpoints/MB-Clin-ER-checkpoint.ipynb', 'repo_name': 'ZohrehShams/IntegrativeRuleExtractionMethodology', 'size': '3233'}