我试图在XGBoost上使用scikit-learn的GridSearchCV进行超级计量搜索.在网格搜索期间,我希望它能够提前停止,因为它可以大大减少搜索时间,并且(期望)在我的预测/回归任务上有更好的结果.我通过其Scikit-Learn API使用XGBoost.
model = xgb.XGBRegressor()
GridSearchCV(model, paramGrid, verbose=verbose ,fit_params={'early_stopping_rounds':42}, cv=TimeSeriesSplit(n_splits=cv).get_n_splits([trainX, trainY]), n_jobs=n_jobs, iid=iid).fit(trainX,trainY)
Run Code Online (Sandbox Code Playgroud)
我尝试使用fit_params提供早期停止参数,但之后它会抛出此错误,这主要是因为缺少早期停止所需的验证集:
/opt/anaconda/anaconda3/lib/python3.5/site-packages/xgboost/callback.py in callback(env=XGBoostCallbackEnv(model=<xgboost.core.Booster o...teration=4000, rank=0, evaluation_result_list=[]))
187 else:
188 assert env.cvfolds is not None
189
190 def callback(env):
191 """internal function"""
--> 192 score = env.evaluation_result_list[-1][1]
score = undefined
env.evaluation_result_list = []
193 if len(state) == 0:
194 init(env)
195 best_score = state['best_score']
196 best_iteration = state['best_iteration']
Run Code Online (Sandbox Code Playgroud)
如何使用early_stopping_rounds在XGBoost上应用GridSearch?
注意:模型在没有gridsearch的情况下工作,GridSearch的工作也没有'fit_params = {'early_stopping_rounds':42}
myList = [ 4,'a', 'b', 'c', 1 'd', 3]
Run Code Online (Sandbox Code Playgroud)
如何将此列表拆分为两个列表,其中一个包含字符串,另一个包含优雅/ pythonic方式的整数?
输出:
myStrList = [ 'a', 'b', 'c', 'd' ]
myIntList = [ 4, 1, 3 ]
Run Code Online (Sandbox Code Playgroud)
注意:没有实现这样的列表,只考虑如何找到一个优雅的答案(有没有?)这样的问题.
使用python 2.7:
>myCity = 'Isparta'
>myCity.lower()
>'isparta'
#-should be-
>'?sparta'
Run Code Online (Sandbox Code Playgroud)
尝试了一些解码,(比如,myCity.decode("utf-8").lower())但是找不到怎么做.
怎么能降低这种字母?('我''''','İ'>'我'等)
编辑:在土耳其语中,'我'的小写是'ı'.'i'的大写是'İ'
我需要以独立于平台的方式遵循:
1) read the file with using codecs.open() (for utf-8)
2) split lines according to two new lines.
3) split entities according to new line
Run Code Online (Sandbox Code Playgroud)
示例输入:
1) FIRST UTF-8 ENTITY ????\n
2) SECOND ELEMENT OF FIRST ENTITY\n
\n\n
1) SECOND ENTITIY\n
2) SECOND ELEMENT OF SECOND ENTITIY\n
Run Code Online (Sandbox Code Playgroud)
读取文件后, string.split('\n\n') 在 mac osx 中工作,但它似乎不是平台独立的处理方式(文件可能在另一个操作系统上准备)。
我知道 string.splitlines() 独立于平台工作,但是如何以独立于平台的方式在实体之间拆分两条新行?
编辑:文件可能在任何平台上准备,因此可能有任何类型的行尾。
我尝试使用pip,easy_install和源代码安装Cython.我在OsX Maverics上犯了以下错误:
clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
error: command 'cc' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)
我在用 Python 2.7.5
pip version 1.4.1
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个错误?
python ×4
string ×2
cython ×1
data-science ×1
encoding ×1
int ×1
list ×1
macos ×1
newline ×1
pip ×1
python-3.x ×1
regression ×1
scikit-learn ×1
unicode ×1
utf-8 ×1
xgboost ×1