【问题标题】:IndexError: tuple index out of range(XGBoost)IndexError:元组索引超出范围(XGBoost)
【发布时间】:2021-04-19 18:54:56
【问题描述】:

我正在尝试预测一堆商店的每周销售额。我想使用XGBoost,但我一直遇到这个错误:

IndexError: tuple index out of range

我的代码:

from sklearn.model_selection import train_test_split

features = ["Store",'Dept','Temperature','Fuel_Price','CPI','Unemployment']

y = allmergecopy.Weekly_Sales
X = allmergecopy[features]
X_train, y_train, X_valid, y_valid = train_test_split(y,X,test_size=.2, train_size=.8)

from xgboost import XGBRegressor

my_model = XGBRegressor(n_estimators=100)
my_model.fit(X_train, y_train)

供参考:

y_train.shape = (84314,), X_train.shape = (337256,).

【问题讨论】:

    标签: python xgboost index-error


    【解决方案1】:

    而不是:

    X_train, y_train, X_valid, y_valid = train_test_split(y,X,test_size=.2, train_size=.8)
    

    写:

    x_train,x_valid,y_train,y_valid= train_test_split(x,y,test_size=0.2)
    

    然后使用:

    from xgboost import XGBRegressor
    my_model = XGBRegressor(n_estimators=100)
    my_model.fit(x_train, y_train)
    

    【讨论】:

      【解决方案2】:

      使用 X 作为:

      X=allmergecopy.drop("Weekly_Sales",axis=1)

      【讨论】:

        猜你喜欢
        • 2013-07-28
        • 2018-11-16
        • 2017-07-12
        • 2013-12-16
        • 2021-12-21
        • 2014-08-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多