首页 > 解决方案 > Python中的高错误机器学习回归器算法 - XGBOOST Regressor

问题描述

我有一个包含来自佛罗里达州的真实状态数据的数据框,它包括单间公寓和建筑物数据:

在此处输入图像描述

'TRUE_SITE_CITY': The city where the building is. variable: Miami, Aventura...;
'CONDO_FLAG': If it is a condominium or not, variable: yes/no;
'BEDROOM_COUNT': Number of total bethrooms, variable: integuer,
'BUILDING_actual_AREA': The area of the entire building, or apartment in the case that there are only one apartment or house. variable: integuer;
'FLOOR_COUNT': Number of the floors that the building has;
'DOR_CODE_CUR': the type of the building. Variable: categorical;
'UNIT_COUNT': Number of apartments or houses in the building. Variable: integuer;
'YEAR_BUILT': Year that the building or house or apartment was build: Variable: categorical;
'public_transport_min_distance': I have calculated the nearest stations of the public transport;
'Price': The variable that I want to predict.

我进行了探索性数据分析,我删除了一些具有空值的数据和一些不正确的数据。我也删除了带有异常值的值。

价格列(目标列)的基本统计:

在此处输入图像描述

我检查了分类特征,每个特征都有足够的变量将它们保留在模型中。

我已经做了一个管道来为分类值制作一个热编码器,并为数值制作一个标准标准化。在其中我包含了 XGBOOST 回归:

from xgboost import XGBRegressor
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import cross_validate
from sklearn import metrics
from sklearn import preprocessing, feature_extraction
from sklearn.pipeline import Pipeline
from sklearn import preprocessing, feature_extraction
from sklearn.pipeline import make_pipeline, make_union
from mlxtend.feature_selection import ColumnSelector
from sklearn.preprocessing import StandardScaler
from category_encoders import OneHotEncoder

x_numeric = df_x[['BEDROOM_COUNT','BATHROOM_COUNT',
       'HALF_BATHROOM_COUNT', 'FLOOR_COUNT','UNIT_COUNT','public_transport_min_distance','BUILDING_actual_AREA']]

x_categorical = df_x[['TRUE_SITE_CITY','CONDO_FLAG','YEAR_BUILT']]

categorical_col = x_categorical.columns

numeric_col = x_numeric.columns

estimator_pipeline = Pipeline([
    ('procesador', procesing_pipeline),
    ('estimador', estimator)
])

score2 = cross_validate(estimator_pipeline, X= df_x, y= df_y, scoring=scoring,return_train_score=False, cv=5,n_jobs=2)

但我得到了一个很高的错误。价格的平均值几乎是 200.000,我得到的错误是:

在此处输入图像描述

我已经使用 RFE 完成了特征选择,但我也获得了很高的错误。

我也运行它做 RandomizedSearchCV

from sklearn.model_selection import RandomizedSearchCV

params = {"estimator__learning_rate"    : [0.05, 0.10, 0.15, 0.20, 0.25, 0.30 ] ,
 "estimator__max_depth"        : [ 3, 4, 5, 6, 8, 10, 12, 15],
 "estimator__min_child_weight" : [ 1, 3, 5, 7 ],
 "estimator__gamma"            : [ 0.0, 0.1, 0.2 , 0.3, 0.4 ],
 "estimator__colsample_bytree" : [ 0.3, 0.4, 0.5 , 0.7 ] }

random_search = RandomizedSearchCV(
    estimator=estimator_pipeline, 
    param_distributions=params, cv=5, refit=True,
    scoring="neg_mean_squared_error", n_jobs= 3,
    return_train_score=True,
    n_iter=50)

但我获得了类似的错误值。

我能做什么?

标签: pythonpandasmachine-learningdata-sciencexgboost

解决方案


我这边的一些评论/建议。希望它会帮助你。

  1. 不要将 YEAR_BUILT 变量用作分类变量,而是将其用作数值变量,您也可以将此变量转换为描述建筑物/公寓年龄的新变量,然后您可以尝试不同的转换,
  2. 您可以尝试通过添加不同的变量来增加自变量的数量,这些变量是当前变量的转换,例如使用平方值
  3. 一般来说,考虑到您只有 9 个自变量和大型数据集,我将专注于创建新的潜在变量
  4. 使用基于决策树方法的算法,您不必对数值变量执行标准化
  5. 使用不同的提升算法,您应该专注于基础估计器(浅决策树)
  6. 尝试不同的算法(例如简单的决策树或随机森林)来比较结果

推荐阅读