<jupyter_start><jupyter_text>En este notebook vamos a hacer exactamente lo mismo que en DecisionTreeAgosto, pero vamos a hacer las pruebas con varios datasets de juguete de clasificación. Hay que destacar que los otros que vamos a usar son bastante más pequeños que el que venimos usando: 150 instancias frente a las 1500 que veníamos usando hasta ahora. A ver qué tal sale  Iris  150 instancias 3 clases 4 dimensionalidad valores positivos reales, entre 0 y 8<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from time import time
import math

# Import datasets, classifiers and performance metrics
from sklearn import datasets, pipeline
from sklearn.kernel_approximation import (RBFSampler,
                                          Nystroem)
from sklearn.tree import DecisionTreeClassifier
iris = datasets.load_iris()
data = iris.data
target = iris.target
N = data.shape[0]
prop_train = 3 / 4
N_train = math.ceil(N * prop_train)
N_test = N - N_train<jupyter_output><empty_output><jupyter_text>No cambio los datos para centrarlos en 0 con varianza 1<jupyter_code>data_train = data[:N_train]
data_test = data[N_train:]

target_train = target[:N_train]
target_test = target[N_train:]<jupyter_output><empty_output><jupyter_text>Decision Tree normal<jupyter_code>dtc = DecisionTreeClassifier()
dtc.fit(data_train, target_train)
train_score_normal_dt = dtc.score(data_train, target_train)
test_score_nomal_dt = dtc.score(data_test, target_test)
train_score_normal_dt, test_score_nomal_dt<jupyter_output><empty_output><jupyter_text>Decision Tree con RBFSampler<jupyter_code>feature_map_fourier = RBFSampler(gamma=.2, random_state=1)
dtc_rbf = pipeline.Pipeline([("feature_map", feature_map_fourier),
                             ("ctf", DecisionTreeClassifier())])
D = 500
dtc_rbf.set_params(feature_map__n_components=D)
dtc_rbf.fit(data_train, target_train)
train_score = dtc_rbf.score(data_train, target_train)
test_score = dtc_rbf.score(data_test, target_test)
train_score, test_score<jupyter_output><empty_output><jupyter_text>Con D = 500 parece dar mejores resultados que con D = 5000. Con 500 parece que mejora un poquitín, mientras que 500 se queda igual o empeora.  Wine 178 instancias 3 clases 13 dimensionalidad valores positivos reales, entre 0 y 1680<jupyter_code>wine = datasets.load_wine()
data = wine.data
target = wine.target
N = data.shape[0]
prop_train = 2 / 4
N_train = math.ceil(N * prop_train)
N_test = N - N_train
data_train = data[:N_train]
data_test = data[N_train:]

target_train = target[:N_train]
target_test = target[N_train:]<jupyter_output><empty_output><jupyter_text>Decision Tree Normal<jupyter_code>dtc = DecisionTreeClassifier()
dtc.fit(data_train, target_train)
train_score_normal_dt = dtc.score(data_train, target_train)
test_score_nomal_dt = dtc.score(data_test, target_test)
train_score_normal_dt, test_score_nomal_dt<jupyter_output><empty_output><jupyter_text>Decision Tree con RBFSampler<jupyter_code>feature_map_fourier = RBFSampler(gamma=.2, random_state=1)
dtc_rbf = pipeline.Pipeline([("feature_map", feature_map_fourier),
                             ("ctf", DecisionTreeClassifier())])
D = 500
dtc_rbf.set_params(feature_map__n_components=D)
dtc_rbf.fit(data_train, target_train)
train_score = dtc_rbf.score(data_train, target_train)
test_score = dtc_rbf.score(data_test, target_test)
train_score, test_score<jupyter_output><empty_output><jupyter_text>Cancer 569 instancias 2 clases 30 dimensionalidad valores positivos reales, entre 0 y 4254<jupyter_code>cancer = datasets.load_breast_cancer()
data = cancer.data
target = cancer.target
N = data.shape[0]
prop_train = 2 / 4
N_train = math.ceil(N * prop_train)
N_test = N - N_train
data_train = data[:N_train]
data_test = data[N_train:]

target_train = target[:N_train]
target_test = target[N_train:]<jupyter_output><empty_output><jupyter_text>Decision Tree Normal<jupyter_code>dtc = DecisionTreeClassifier()
dtc.fit(data_train, target_train)
train_score_normal_dt = dtc.score(data_train, target_train)
test_score_nomal_dt = dtc.score(data_test, target_test)
train_score_normal_dt, test_score_nomal_dt<jupyter_output><empty_output><jupyter_text>Decision Tree con RBFSampler<jupyter_code>feature_map_fourier = RBFSampler(gamma=.2, random_state=1)
dtc_rbf = pipeline.Pipeline([("feature_map", feature_map_fourier),
                             ("ctf", DecisionTreeClassifier())])
D = 500
dtc_rbf.set_params(feature_map__n_components=D)
dtc_rbf.fit(data_train, target_train)
train_score = dtc_rbf.score(data_train, target_train)
test_score = dtc_rbf.score(data_test, target_test)
train_score, test_score<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08743286788399571, 'fraction_numerical': 0.01611170784103115, 'mean_word_length': 6.6202945990180035, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '578010', 'license': 'MIT', 'n_tokens_mistral': 1745, 'n_tokens_neox': 1652, 'n_words': 351, 'path': 'code/notebooks/python/DecisionTreeSeptiembre/Untitled.ipynb', 'repo_name': 'ribes96/TFG', 'size': '4655'}