如果您对dask_ml.model_selection.GridSearchCV关于并行计算的问题感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于dask_ml.model_
如果您对dask_ml.model_selection.GridSearchCV关于并行计算的问题感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于dask_ml.model_selection.GridSearchCV关于并行计算的问题的详细内容,我们还将为您解答并行计算cuda的相关问题,并且为您提供关于Creating a Connection Between Enterprise Search and SAP HANA for ABAP CDS-Based Search Models、dask_ml GridSearchCV分布式崩溃,出现KeyError、GridSearchCV、GridSearchCV 与 RandomizedSearchCV 调参的有价值信息。
本文目录一览:- dask_ml.model_selection.GridSearchCV关于并行计算的问题(并行计算cuda)
- Creating a Connection Between Enterprise Search and SAP HANA for ABAP CDS-Based Search Models
- dask_ml GridSearchCV分布式崩溃,出现KeyError
- GridSearchCV
- GridSearchCV 与 RandomizedSearchCV 调参
dask_ml.model_selection.GridSearchCV关于并行计算的问题(并行计算cuda)
如何解决dask_ml.model_selection.GridSearchCV关于并行计算的问题?
有没有人遇到过在单个集群的并行计算中使用“dask_ml.model_selection.gridsearchcv(sklearn_function(),param_list,cv=5,n_jobs=20,scheduler="multiprocessing")”,但是遇到所有分配了20个cpu的worker永远睡不着?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
Creating a Connection Between Enterprise Search and SAP HANA for ABAP CDS-Based Search Models
from SAP help
If you want to use Enterprise Search in applications that use ABAP CDS-based search models, you first have to create the connection between the ABAP system of Enterprise Search and SAP HANA. Compared to the standard configuration, there are various points you need to consider.
Prerequisites
You have installed SAP HANA in revision 102 or higher.
Process
Log on to the SAP NetWeaver system and launch the Implementation Guide (IMG) by using transaction SPRO. Navigate to the node Search and Operational Analytics Common Settings for Operational Analytics and Enterprise Search Configure Indexing Define TREX/BWA Destination or SAP HANA Database Connection . When you launch the Customizing activity, the ABAP program ESH_ADM_SET_TREX_DESTINATION starts.
If you are performing the initial configuration of the Enterprise Search system, choose Use Primary DB Connection of SAP HANA: STANDARD and then Execute.
Note
If you are using an existing Enterprise Search system that is already configured, do not change the selected database connection.
Switch to SAP HANA studio.
To assign the required authorizations to the SAP HANA users, execute the following SQL statements as the SAP HANA system user:
If you are performing the initial configuration of the Enterprise Search system, execute the following SQL statements:
GRANT EXECUTE ON SYS.ESH_CONFIG TO <SAP HANA Primary DB Connection User>;
GRANT EXECUTE ON SYS.ESH_SEARCH TO <SAP HANA Primary DB Connection User>;
GRANT SELECT ON _SYS_RT.ESH_MODEL TO <SAP HANA Primary DB Connection User>;
GRANT SELECT ON _SYS_RT.ESH_MODEL_PROPERTY TO <SAP HANA Primary DB Connection User>;
GRANT EXECUTE ON SYS.TREXVIADBSL TO <SAP HANA Primary DB Connection User>;
GRANT EXECUTE ON SYS.TREXVIADBSLWITHPARAMETER TO <SAP HANA Primary DB Connection User>;
Note
You can find the name of the user of the primary database connection (SAP HANA Primary DB Connection User) in the ABAP system in the menu System Status... in the area Database Data in the field Owner.
If you are using an existing Enterprise Search system that is already configured, execute the following SQL statements instead:
GRANT EXECUTE ON SYS.ESH_CONFIG TO <SAP HANA Primary DB Connection User>;
GRANT EXECUTE ON SYS.ESH_SEARCH TO <SAP HANA Primary DB Connection User>;
GRANT SELECT ON _SYS_RT.ESH_MODEL TO <SAP HANA Primary DB Connection User>;
GRANT EXECUTE ON SYS.TREXVIADBSL TO <SAP HANA Search User>;
GRANT EXECUTE ON SYS.TREXVIADBSLWITHPARAMETER TO <SAP HANA Search User>;
Note
You can find the name of the user of the database connection for the search (SAP HANA Search User) in the ABAP system: Start the program ESH_ADM_SET_TREX_DESTINATION and check whether the primary or secondary database connection is used. If the primary database connection is selected, use the user name of the primary database connection as the name of the user of the database connection for the search (SAP HANA Search User).
If the secondary database connection is selected, the name of the database connection is displayed in the relevant field (DB Connection Name). Start transaction DBCO to find the user name that is assigned to this database connection. This user name corresponds to the user of the database connection for the search (SAP HANA Search User).
If you are using the secondary database connection in an existing Enterprise Search system that has already been configured (see the setting under ESH_ADM_SET_TREX_DESTINATION), you must grant authorization to the user of the database connection for the search (SAP HANA Search User) to execute the SQL statement SELECT on the database schema (SAPSID) of the primary database connection.
GRANT SELECT ON SCHEMA TO ;
本文同步分享在 博客 “汪子熙”(CSDN)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与 “OSC 源创计划”,欢迎正在阅读的你也加入,一起分享。
dask_ml GridSearchCV分布式崩溃,出现KeyError
如何解决dask_ml GridSearchCV分布式崩溃,出现KeyError?
我正在尝试在我们的HPC集群上运行分布式超参数优化。这段代码在sklearn上运行正常(缓慢),但是使用内置的dask功能,工作人员会立即因关键错误而失败。
client = Client(''<ip>'')
import numpy as np
import dask.array as da
X_train = np.load(<some numpy x binary>)
Y_train = np.load(<some numpy y binary>)
X_train = da.from_array(X_train,chunks=50000)
Y_train = da.from_array(Y_train,chunks=50000)
#from xgboost import XGBClassifier # These work
from dask_xgboost import XGBClassifier
#from sklearn.model_selection import gridsearchcv # These work
from dask_ml.model_selection import gridsearchcv
opt_clf = XGBClassifier()
hyparams={}
for par,val in param.items():
hyparams[par]=[val]
hyparams["eta"] = [0.2,0.5,0.9]
search = gridsearchcv(opt_clf,hyparams,scoring=''f1_macro'')
任务已分配给工人,我可以看到他们身上保留着的记忆,但是所有火车作业都失败了:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-12-cfe3d66f9554> in <module>
1 get_ipython().run_line_magic(''time'','''')
----> 2 search.fit(X_train,Y_train)
3 search.cv_results_
~/.local/lib/python3.6/site-packages/dask_ml/model_selection/_search.py in fit(self,X,y,groups,**fit_params)
1264 else:
1265 logger.warning("{} has Failed... retrying".format(future.key))
-> 1266 future.retry()
1267 ac.add(future)
1268
~/.local/lib/python3.6/site-packages/distributed/client.py in retry(self,**kwargs)
310 Client.retry
311 """
--> 312 return self.client.retry([self],**kwargs)
313
314 def cancelled(self):
~/.local/lib/python3.6/site-packages/distributed/client.py in retry(self,futures,asynchronous)
2234 futures: list of Futures
2235 """
-> 2236 return self.sync(self._retry,asynchronous=asynchronous)
2237
2238 async def _publish_dataset(self,*args,name=None,**kwargs):
~/.local/lib/python3.6/site-packages/distributed/client.py in sync(self,func,asynchronous,callback_timeout,**kwargs)
831 else:
832 return sync(
--> 833 self.loop,callback_timeout=callback_timeout,**kwargs
834 )
835
~/.local/lib/python3.6/site-packages/distributed/utils.py in sync(loop,**kwargs)
337 if error[0]:
338 typ,exc,tb = error[0]
--> 339 raise exc.with_traceback(tb)
340 else:
341 return result[0]
~/.local/lib/python3.6/site-packages/distributed/utils.py in f()
321 if callback_timeout is not None:
322 future = asyncio.wait_for(future,callback_timeout)
--> 323 result[0] = yield future
324 except Exception as exc:
325 error[0] = sys.exc_info()
~/.local/lib/python3.6/site-packages/tornado/gen.py in run(self)
733
734 try:
--> 735 value = future.result()
736 except Exception:
737 exc_info = sys.exc_info()
~/.local/lib/python3.6/site-packages/distributed/client.py in _retry(self,futures)
2223 response = await self.scheduler.retry(keys=keys,client=self.id)
2224 for key in response:
-> 2225 st = self.futures[key]
2226 st.retry()
2227
KeyError: ''xgbclassifier-a93a193c47acb611cde5ecdeb7347809''
有人对此问题有任何提示或调试方法吗?似乎工人只是没有返回经过训练的模型。
谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
GridSearchCV

from sklearn.model_selection import GridSearchCV
from sklearn.svm import SVC
from sklearn import datasets
iris = datasets.load_iris()
parameters = {''kernel'':(''rbf'', ''linear''), ''C'':[1, 10], ''gamma'': [''auto'']}
clf = GridSearchCV(
SVC(C=1, probability=True, class_weight="balanced"),
param_grid=parameters,
n_jobs=1,
cv=5,
scoring=''f1_weighted'',
verbose=3,
iid=False,
)
clf.fit(iris.data, iris.target)
print(clf.best_params_)
print(clf.best_score_)
SVC: 不需要优化的参数直接写在 SVM 中;
param_grid: 需要优化的参数写在此次;
verbose: 3 表示详细打印信息
cv: 将数据分成多少折,用其中一折做测试,其它用作训练
GridSearchCV 与 RandomizedSearchCV 调参
GridSearchCV
GridSearchCV的名字其实可以拆分为两部分,GridSearch和CV,即网格搜索和交叉验证。
这两个概念都比较好理解,网格搜索,搜索的是参数,即在指定的参数范围内,按步长依次调整参数,利用调整的参数训练学习器,从所有的参数中找到在验证集上精度最高的参数,这其实是一个循环和比较的过程。
GridSearchCV可以保证在指定的参数范围内找到精度最高的参数,但是这也是网格搜索的缺陷所在,它要求遍历所有可能参数的组合,在面对大数据集和多参数的情况下,非常耗时。这也是我通常不会使用GridSearchCV的原因,一般会采用后一种RandomizedSearchCV随机参数搜索的方法。
交叉验证的概念也很简单
· 将训练数据集划分为K份,K一般为10
· 依次取其中一份为验证集,其余为训练集训练分类器,测试分类器在验证集上的精度
· 取K次实验的平均精度为该分类器的平均精度
网格搜索就是利用交叉验证的形式比较每一个参数下训练器的精度的,但是交叉验证也要求大量的计算资源,加重了网格搜索的搜索时间
接下来以阿里IJCAI广告推荐数据集与XGBoostClassifier分类器为例,用代码的形式说明sklearn中GridSearchCV的使用方法
import numpy as np
import pandas as pd
import xgboost as xgb
from sklearn.grid_search import GridSearchCV
#导入训练数据
traindata = pd.read_csv("/traindata_4_3.txt",sep = '','')
traindata = traindata.set_index(''instance_id'')
trainlabel = traindata[''is_trade'']
del traindata[''is_trade'']
print(traindata.shape,trainlabel.shape)
#分类器使用 xgboost
clf1 = xgb.XGBClassifier()
#设定网格搜索的xgboost参数搜索范围,值搜索XGBoost的主要6个参数
param_dist = {
''n_estimators'':range(80,200,4),
''max_depth'':range(2,15,1),
''learning_rate'':np.linspace(0.01,2,20),
''subsample'':np.linspace(0.7,0.9,20),
''colsample_bytree'':np.linspace(0.5,0.98,10),
''min_child_weight'':range(1,9,1)
}
#GridSearchCV参数说明,clf1设置训练的学习器
#param_dist字典类型,放入参数搜索范围
#scoring = ''neg_log_loss'',精度评价方式设定为“neg_log_loss“
#n_iter=300,训练300次,数值越大,获得的参数精度越大,但是搜索时间越长
#n_jobs = -1,使用所有的CPU进行训练,默认为1,使用1个CPU
grid = GridSearchCV(clf1,param_dist,cv = 3,scoring = ''neg_log_loss'',n_iter=300,n_jobs = -1)
#在训练集上训练
grid.fit(traindata.values,np.ravel(trainlabel.values))
#返回最优的训练器
best_estimator = grid.best_estimator_
print(best_estimator)
#输出最优训练器的精度
print(grid.best_score_)
这里关于网格搜索的几个参数再说明一下,评分参数“scoring“,需要根据实际的评价标准设定,阿里的IJCAI的标准是’neg_log_loss’,所以这里设定的是’neg_log_loss’,sklearn中备选的评价标准有一下:
在一些情况下,sklearn中没有现成的评价函数,sklearn是允许我们自己的定义的,但需要注意格式,接下来给个例子
import numpy as np
from sklearn.metrics import make_scorer
def logloss(act, pred):
epsilon = 1e-15
pred = sp.maximum(epsilon, pred)
pred = sp.minimum(1-epsilon, pred)
ll = sum(act*sp.log(pred) + sp.subtract(1, act)*sp.log(sp.subtract(1, pred)))
ll = ll * -1.0/len(act)
return ll
#这里的greater_is_better参数决定了自定义的评价指标是越大越好还是越小越好
loss = make_scorer(logloss, greater_is_better=False)
score = make_scorer(logloss, greater_is_better=True)
定义好以后,再将其代入GridSearchCV函数就好
这里再贴一下常用的集成学习算法比较重要的需要调参的参数,供大家参考
RandomizedSearchCV
RandomizedSearchCV的使用方法其实是和GridSearchCV一致的,但它以随机在参数空间中采样的方式代替了GridSearchCV对于参数的网格搜索,在对于有连续变量的参数时,RandomizedSearchCV会将其当作一个分布进行采样这是网格搜索做不到的,它的搜索能力取决于设定的n_iter参数,同样的给出代码
import numpy as np
import pandas as pd
import xgboost as xgb
from sklearn.grid_search import RandomizedSearchCV
#导入训练数据
traindata = pd.read_csv("/traindata.txt",sep = '','')
traindata = traindata.set_index(''instance_id'')
trainlabel = traindata[''is_trade'']
del traindata[''is_trade'']
print(traindata.shape,trainlabel.shape)
#分类器使用 xgboost
clf1 = xgb.XGBClassifier()
#设定搜索的xgboost参数搜索范围,值搜索XGBoost的主要6个参数
param_dist = {
''n_estimators'':range(80,200,4),
''max_depth'':range(2,15,1),
''learning_rate'':np.linspace(0.01,2,20),
''subsample'':np.linspace(0.7,0.9,20),
''colsample_bytree'':np.linspace(0.5,0.98,10),
''min_child_weight'':range(1,9,1)
}
#RandomizedSearchCV参数说明,clf1设置训练的学习器
#param_dist字典类型,放入参数搜索范围
#scoring = ''neg_log_loss'',精度评价方式设定为“neg_log_loss“
#n_iter=300,训练300次,数值越大,获得的参数精度越大,但是搜索时间越长
#n_jobs = -1,使用所有的CPU进行训练,默认为1,使用1个CPU
grid = RandomizedSearchCV(clf1,param_dist,cv = 3,scoring = ''neg_log_loss'',n_iter=300,n_jobs = -1)
#在训练集上训练
grid.fit(traindata.values,np.ravel(trainlabel.values))
#返回最优的训练器
best_estimator = grid.best_estimator_
print(best_estimator)
#输出最优训练器的精度
print(grid.best_score_)
不过建议还是使用随机的搜索。
---------------------
作者:juezhanangle
来源:CSDN
原文:https://blog.csdn.net/juezhanangle/article/details/80051256
版权声明:本文为博主原创文章,转载请附上博文链接!
今天的关于dask_ml.model_selection.GridSearchCV关于并行计算的问题和并行计算cuda的分享已经结束,谢谢您的关注,如果想了解更多关于Creating a Connection Between Enterprise Search and SAP HANA for ABAP CDS-Based Search Models、dask_ml GridSearchCV分布式崩溃,出现KeyError、GridSearchCV、GridSearchCV 与 RandomizedSearchCV 调参的相关知识,请在本站进行查询。
本文标签: