Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 尝试拟合XgBoost模型时,元组索引超出范围_Python_Pandas_Xgboost - Fatal编程技术网

Python 尝试拟合XgBoost模型时,元组索引超出范围

Python 尝试拟合XgBoost模型时,元组索引超出范围,python,pandas,xgboost,Python,Pandas,Xgboost,我试着在单词向量上训练xgboost模型。 当我这样做的时候 model = xgb.XGBClassifier() model.fit(X_train["comment_preproc"], y_train["label"]) y_predict = model.predict(X_test["comment_preproc"]) 我得到了错误 IndexError Traceback (most recent call last

我试着在单词向量上训练xgboost模型。 当我这样做的时候

model = xgb.XGBClassifier()
model.fit(X_train["comment_preproc"], y_train["label"])
y_predict = model.predict(X_test["comment_preproc"])
我得到了错误

IndexError                                Traceback (most recent call last)
<ipython-input-26-870161aebeee> in <module>()
      1 model = xgb.XGBClassifier()
----> 2 model.fit(X_train["comment_preproc"], y_train["label"])
      3 y_predict = model.predict(X_test["comment_preproc"])

/usr/local/lib/python3.6/dist-packages/xgboost/sklearn.py in fit(self, X, y, sample_weight, eval_set, eval_metric, early_stopping_rounds, verbose, xgb_model, sample_weight_eval_set, callbacks)
    717             evals = ()
    718 
--> 719         self._features_count = X.shape[1]
    720 
    721         if sample_weight is not None:

IndexError: tuple index out of range
索引器错误回溯(最近一次调用)
在()
1模型=xgb.XGBClassifier()
---->2.模型拟合(X_系列[“注释”]、y_系列[“标签”])
3 y_predict=model.predict(X_测试[“评论预处理”])
/usr/local/lib/python3.6/dist-packages/xgboost/sklearn.py in-fit(self、X、y、样本权重、评估集、评估度量、提前停止、详细、xgb模型、样本权重评估集、回调)
717评估=()
718
-->719自我特征计数=X.形状[1]
720
721如果样品重量不是无:
索引器错误:元组索引超出范围
我想也许X_火车和y_火车有不同的形状,但事实并非如此

我做错了什么?

元组
(758079,)
(758079,)
只包含一个元素

因此,您会得到以下错误:

t=(758079,) >>>t[0] 758079 >>>t[1] 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 索引器错误:元组索引超出范围 只需将
.to\u frame()
添加到您的
X\u列车[“评论预处理”]
系列:

model.fit(X_train[“comment_preproc”]。到_frame(),y_train[“label”])

model.fit(X_列[[“评论”]、y_列[“标签”])
应该行得通