1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| # 切分训练集和数据集
data_train, data_test, target_train, target_test = train_test_split(
housing.data, housing.target, test_size=0.1, random_state=0)
# 构建决策树
dtr = tree.DecisionTreeRegressor(random_state=0)
dtr.fit(data_train, target_train)
# 查看score
score = dtr.score(data_test, target_test)
print("score=", score)
print(data_train[:1])
# 保存模型
dump(dtr, model_file_name)
|