目录
代码:
from sklearn.datasets import load_boston
from sklearn.model_selection import train_test_split, GridSearchCV
from sklearn.tree import DecisionTreeRegressor
from sklearn.metrics import mean_squared_error
import matplotlib.pyplot as plt
from sklearn import tree
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier, export_text, export_graphviz
boston = load_boston()
X = boston.data
y = boston.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=1)
def build_decision_tree_model(X_train, y_train, max_depth=None, min_samples_split=2):
model = DecisionTreeRegressor(max_depth=max_depth, min_samples_split=min_samples_split, random_state=42)
model.fit(X_train, y_train)
return model
# 训练基础模型
base_model = build_decision_tree_model(X_train, y_train)
# 评估基础模型
y_pred_base = base_model.predict(X_test)
mse_base = mean_squared_error(y_te

最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



