2017-08-11 70 views
1

我跑mod.fit(X, y)和接收到的誤差:XGBRegressor .fit()方法類型錯誤:範圍()整數端參數預期,得到浮

"TypeError: range() integer end argument expected, got float."

(見下文堆棧跟蹤)。 Xy輸入沒有出現任何問題。該錯誤似乎是xgboost代碼中的某些內容。它成功地適應其他車型,但我最近通過暢達安裝了它:

conda install -c conda-forge xgboost

我在MacOS 10.10.5運行蟒蛇2.7.11。

模型的參數是:

{ 'base_score':   5.0, 
    'booster':   'gbtree', 
    'colsample_bylevel': 1, 
    'colsample_bytree': 1, 
    'gamma':    0, 
    'learning_rate':  0.07500000000000001, 
    'max_delta_step':  0, 
    'max_depth':   4, 
    'min_child_weight': 1, 
    'missing':   None, 
    'n_estimators':  75.0, 
    'n_jobs':   -1, 
    'nthread':   None, 
    'objective':   'reg:linear', 
    'random_state':  0, 
    'reg_alpha':   0, 
    'reg_lambda':   1, 
    'scale_pos_weight': 1, 
    'seed':    0, 
    'silent':    True, 
    'subsample':   1 
    } 

--------------------------------------------------------------------------- 
TypeError         Traceback (most recent call last) 
<ipython-input-30-38afa4aff6db> in <module>() 
----> 1 mod.fit(X_train.values, y_train.values) 

/Users/chriseal/anaconda/lib/python2.7/site-packages/xgboost/sklearn.pyc in fit(self, X, y, eval_set, eval_metric, early_stopping_rounds, verbose) 
    249        early_stopping_rounds=early_stopping_rounds, 
    250        evals_result=evals_result, obj=obj, feval=feval, 
--> 251        verbose_eval=verbose) 
    252 
    253   if evals_result: 

/Users/chriseal/anaconda/lib/python2.7/site-packages/xgboost/training.pyc in train(params, dtrain, num_boost_round, evals, obj, feval, maximize, early_stopping_rounds, evals_result, verbose_eval, learning_rates, xgb_model, callbacks) 
    203       evals=evals, 
    204       obj=obj, feval=feval, 
--> 205       xgb_model=xgb_model, callbacks=callbacks) 
    206 
    207 

/Users/chriseal/anaconda/lib/python2.7/site-packages/xgboost/training.pyc in _train_internal(params, dtrain, num_boost_round, evals, obj, feval, xgb_model, callbacks) 
    62   cb for cb in callbacks if not cb.__dict__.get('before_iteration', False)] 
    63 
---> 64  for i in range(start_iteration, num_boost_round): 
    65   for cb in callbacks_before_iter: 
    66    cb(CallbackEnv(model=bst, 

TypeError: range() integer end argument expected, got float. 

回答

0

我想通了。我在迭代超參數,並且n_estimatorsfloat(75.0)而不是整數(75)。輕鬆修復!

相關問題