我正在尝试在Python中使用XGBoost包 运行此代码时出现此错误
@IBAction func didEndEditingTextField(sender: UITextField) {
geocodeAddressString(sender.text!) { coordinate, error in
self.chooseCoordinates = coordinate
// trigger whatever the next step is here, or in the `didSet` of `chooseCoordinates`
}
// don't try to use `chooseCooordinates` here
}
var chooseCoordinates: CLLocationCoordinate2D? // you probably should make this optional
let geocoder = CLGeocoder()
/// Geocode string
///
/// - parameter string: The string to geocode.
/// - parameter completionHandler: The closure that is called asynchronously (i.e. later) when the geocoding is done.
func geocodeAddressString(string: String, completionHandler: (CLLocationCoordinate2D?, NSError?) -> ()) {
geocoder.geocodeAddressString(string) { placemarks, error in
if error != nil {
print(error!)
}
if let placemark = placemarks?.first {
completionHandler(placemark.location!.coordinate, error)
} else {
completionHandler(nil, error)
}
}
}
----------------------------------------------- ---------------------------- XGBoostError Traceback(最近一次调用 最后)in() 17 18 num_round = 10 ---> 19 bst = xgb.train(plst,dtrain,num_round,evallist) 20 21 bst.save_model(' 0001.model')
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/xgboost/training.pyc 在火车上(params,dtrain,num_boost_round,evals,obj,feval,maximize, early_stopping_rounds,evals_result,verbose_eval,learning_rates, xgb_model) 122 nboost + = 1 123如果len(evals)!= 0: - > 124 bst_eval_set = bst.eval_set(evals,i,feval) 125 if isinstance(bst_eval_set,STRING_TYPES): 126 msg = bst_eval_set
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/xgboost/core.pyc 在eval_set中(self,evals,iteration,feval) 753 _check_call(_LIB.XGBoosterEvalOneIter(self.handle,iteration, 754 dmats,evnames,len(evals), - > 755 ctypes.byref(msg))) 756返回msg.value 757否则:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/xgboost/core.pyc 在_check_call(ret)中 95""" 96如果ret!= 0: ---> 97引发XGBoostError(_LIB.XGBGetLastError()) 98 99
XGBoostError:我们需要权重来评估ams
我在文档中看不到任何相关内容
https://xgboost.readthedocs.io/en/latest/python/python_intro.html
答案 0 :(得分:2)
计算ams指标时,您需要为每个标记的训练点设置权重。您可以在创建DMatrix时使用关键字参数权重来设置权重。一个简单的例子。
weights = np.ones(len(labels))
dtrain = xgb.DMatrix(data, label = labels, weight = weights)
最近的Kaggle比赛的一个深入的例子:https://github.com/tqchen/xgboost/blob/master/demo/kaggle-higgs/higgs-numpy.py。