<jupyter_start><jupyter_text>Data Preprocessing<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import pandas as pd<jupyter_output><empty_output><jupyter_text>Importing the Datasets<jupyter_code>dataset=pd.read_csv("E:\\Edu\Data Science and ML\\Machinelearningaz\\Datasets\\Part 2 - Regression\\Section 8 - Decision Tree Regression\\Position_Salaries.csv")
dataset.head()
dataset.shape
dataset.describe()
X=dataset.iloc[:,1:2].values    #  (Matrix)
y=dataset.iloc[:,2].values    #  (Vector)
print(X)
print(y)<jupyter_output>[[ 1]
 [ 2]
 [ 3]
 [ 4]
 [ 5]
 [ 6]
 [ 7]
 [ 8]
 [ 9]
 [10]]
[  45000   50000   60000   80000  110000  150000  200000  300000  500000
 1000000]<jupyter_text>Fitting DT Regression to Training Set<jupyter_code>from sklearn.tree import DecisionTreeRegressor
regressor=DecisionTreeRegressor(random_state=0)
regressor.fit(X,y)<jupyter_output><empty_output><jupyter_text>Predicting new Result with DT Regression<jupyter_code>regressor.predict(np.array([[6.5]]))  # Predict salry for the level 6.5<jupyter_output><empty_output><jupyter_text>Visualising the DT Regression results<jupyter_code>plt.scatter(X,y,color='red')
plt.plot(X,regressor.predict(X),color='blue')
plt.title("Truth or Bluff (DT Regression)")
plt.xlabel('Level/Position of work')
plt.ylabel('Salary')
plt.show()
#we are under Trap<jupyter_output><empty_output><jupyter_text>Visualising the DT Regression with Higher Resolution and smoother Curve<jupyter_code>X_grid=np.arange(min(X),max(X),0.01)
X_grid=X_grid.reshape((len(X_grid),1))
plt.scatter(X,y,color='red')
plt.plot(X_grid,regressor.predict(X_grid),color='blue')
plt.title("Truth or Bluff (Polynomial Regression)")
plt.xlabel('Level/Position of work')
plt.ylabel('Salary')
plt.show()
#In DT it predicts the value by taking avg in interval<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1380065717415115, 'fraction_numerical': 0.044906900328587074, 'mean_word_length': 7.266968325791855, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '511894', 'license': 'MIT', 'n_tokens_mistral': 768, 'n_tokens_neox': 689, 'n_words': 126, 'path': '2 Regression/5 Decision Tree Regression.ipynb', 'repo_name': 'BheemashankarJakkani/Machine_Learning', 'size': '1826'}