<jupyter_start><jupyter_text>Decision Trees Regression<jupyter_code>import numpy as np
from sklearn import tree
import matplotlib.pyplot as plt
import graphviz<jupyter_output><empty_output><jupyter_text>Create a random dataset<jupyter_code>rng = np.random.RandomState(1)
X = np.sort(5 * rng.rand(80, 1), axis=0)
y = np.sin(X).ravel()
y[::5] += 3 * (0.5 - rng.rand(16))
X<jupyter_output><empty_output><jupyter_text>Create decision trees<jupyter_code>regr_1 = tree.DecisionTreeRegressor(max_depth=2)
regr_2 = tree.DecisionTreeRegressor()<jupyter_output><empty_output><jupyter_text>Fit regression models<jupyter_code>regr_1.fit(X, y)
regr_2.fit(X, y)<jupyter_output><empty_output><jupyter_text>Predict<jupyter_code>X_test = np.arange(0.0, 5.0, 0.01)[:, np.newaxis]
y_1 = regr_1.predict(X_test)
y_2 = regr_2.predict(X_test)<jupyter_output><empty_output><jupyter_text>Plot the results<jupyter_code>plt.figure()
plt.scatter(X, y, s=20, edgecolor="black",
            c="darkorange", label="data")
#plt.plot(X_test, y_1, color="cornflowerblue",
#         label="max_depth=2", linewidth=2)
plt.plot(X_test, y_2, color="yellowgreen", label="max_depth=3", linewidth=2)
plt.xlabel("data")
plt.ylabel("target")
plt.title("Decision Tree Regression")
plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>Display the decision trees<jupyter_code>dot_data = tree.export_graphviz(regr_1, out_file=None,    
    filled=True, rounded=True,  
    special_characters=True)  
graph = graphviz.Source(dot_data)  
graph
dot_data = tree.export_graphviz(regr_2, out_file=None,    
    filled=True, rounded=True,  
    special_characters=True)  
graph = graphviz.Source(dot_data)  
graph<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14151497357604229, 'fraction_numerical': 0.022313564298297124, 'mean_word_length': 7.435643564356436, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '2726', 'license': 'MIT', 'n_tokens_mistral': 720, 'n_tokens_neox': 691, 'n_words': 95, 'path': 'PXL_DIGITAL_JAAR_2/AI & Robotics/Oplossingen/Spring_Break/jupyter/regressor.ipynb', 'repo_name': 'RubenMoensJonkersPXL/PXL-DIGITAL', 'size': '1703'}