text_html_output_1.png
from matplotlib import pyplot

from sklearn.metrics import mean_squared_error

from sklearn.metrics import r2_score

from sklearn.tree import DecisionTreeRegressor

from sklearn.tree import DecisionTreeRegressor
from sklearn.metrics import r2_score
from sklearn.metrics import mean_squared_error
from sklearn.tree import DecisionTreeClassifier
from matplotlib import pyplot
def evaluate_decision_tree(x_train, y_train, x_test, y_test):
    train_scores = []
    test_scores = []
    train_scores_mse, test_scores_mse = ([], [])
    values = [i for i in range(1, 20)]
    for i in values:
        model = DecisionTreeRegressor(max_depth=i)
        model.fit(x_train, y_train)
        train_predict = model.predict(x_train)
        train_r2 = round(r2_score(y_train, train_predict), 3)
        train_scores.append(train_r2)
        train_mse = round(mean_squared_error(y_train, train_predict), 3)
        train_scores_mse.append(train_mse)
        test_predict = model.predict(x_test)
        test_r2 = round(r2_score(y_test, test_predict), 3)
        test_scores.append(test_r2)
        test_mse = round(mean_squared_error(y_test, test_predict), 3)
        test_scores_mse.append(test_mse)

evaluate_decision_tree(x_train, y_train, x_test, y_test)