from sklearn import tree from sklearn.cross_validation import train_test_split # 数据拆分 train_x, test_x, train_y, test_y = train_test_split(housing.data, housing.target, test_size=0.1, random_state=42) # 建立决策树 dtr = tree.DecisionTreeRegressor(random_state=42) # 训练数据 dtr.fit(train_x, train_y) # 打印出dtr得分, 这里的得分表示的是准确率 print(dtr.score(test_x, test_y))