<jupyter_start><jupyter_text>使用AdaBoost回归预测<jupyter_code>from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
from sklearn.datasets import load_boston
from sklearn.ensemble import AdaBoostRegressor
# 加载数据
data = load_boston()
# 分割数据
train_x, test_x, train_y, test_y = train_test_split(
    data.data, data.target, test_size=0.25, random_state=33)
# 使用AdaBoost回归模型
regressor = AdaBoostRegressor()
regressor.fit(train_x, train_y)
pred_y = regressor.predict(test_x)
mse = mean_squared_error(test_y, pred_y)
print(f'房价预测结果 {pred_y}')
print(f'均方误差 = {round(mse, 2)}')<jupyter_output>房价预测结果 [19.73428571 11.04363636 14.25098039 17.77391304 24.77607656 22.49268293
 28.23794872 17.92928177 31.07777778 19.6116129  31.51384615 32.46666667
 11.75087719 24.64228188 13.03098592 24.77607656 17.77391304 16.81081081
 28.23794872 25.15863874 17.33882353 17.77391304 17.77391304 18.18341232
 31.92333333 17.28045977 22.49268293 24.77607656 11.75087719 31.46041667
 17.33882353 25.48478261 10.51282051 20.84210526 26.08762376 31.07777778
 25.15863874 11.75087719 13.55925926 25.06138614 15.54494382 13.03098592
 30.58387097 17.33882353 26.08762376 18.29545455 17.77391304 19.46266667
 25.25363128 19.47272727 17.28045977 33.56282051 15.88181818 17.09
 24.77607656 20.67181818 24.54505495 16.36181818 25.15863874 22.90852273
 18.63561644 16.36181818 44.95185185 20.8779661  16.63030303 25.48478261
 25.06138614 11.75087719 18.46460674 27.79485981 23.14038462 18.18341232
 17.57297297 27.17294686 18.70212766 46.55714286 15.5627451  11.40526316
 16.63030303 24.64228188 19.92272727 15.14545455 1[...]<jupyter_text>使用决策树预测<jupyter_code>from sklearn.tree import DecisionTreeRegressor
dec_regressor = DecisionTreeRegressor()
dec_regressor.fit(train_x, train_y)
pred_y = dec_regressor.predict(test_x)
mse = mean_squared_error(test_y, pred_y)
print(f'决策树军方误差 = {round(mse, 2)}')<jupyter_output>决策树军方误差 = 36.92<jupyter_text>使用KNN回归模型<jupyter_code>from sklearn.neighbors import KNeighborsRegressor
knn_regresson = KNeighborsRegressor()
knn_regresson.fit(train_x, train_y)
pred_y = knn_regresson.predict(test_x)
mse = mean_squared_error(test_y, pred_y)
print(f'KNN均方误差 = {round(mse, 2)}')<jupyter_output>KNN均方误差 = 27.87
{'fraction_non_alphanumeric': 0.09772423025435073, 'fraction_numerical': 0.36947791164658633, 'mean_word_length': 6.473333333333334, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '182856', 'license': 'Apache-2.0', 'n_tokens_mistral': 1582, 'n_tokens_neox': 1055, 'n_words': 159, 'path': '35-AdaBoost（下）：如何使用AdaBoost对房价进行预测？/AdaBoost_boston.ipynb', 'repo_name': 'justdoitgk/Data-analysis-in-action', 'size': '2241'}