我使用的是H2O(Python),其中我使用H2OGridSearch
来表示GLM的alpha值(H2OGeneralizedLinearEstimator
),也使用了使用k-fold交叉验证的lambda_search=True
。在
如何获得最佳型号的lambda值?在
编辑:完全可复制示例
数据:
34.40 17:1 73:1 127:1 265:1 912:1 1162:1 1512:1 1556:1 1632:1 1738:1
205.10 127:1 138:1 338:1 347:1 883:1 912:1 1120:1 1122:1 1512:1
7.75 66:1 127:1 347:1 602:1 1422:1 1512:1 1535:1 1738:1
8.85 127:1 608:1 906:1 979:1 1077:1 1512:1 1738:1
51.80 127:1 347:1 608:1 766:1 912:1 928:1 952:1 1034:1 1512:1 1610:1 1738:1
110.00 127:1 229:1 347:1 602:1 608:1 1171:1 1512:1 1718:1
8.90 66:1 127:1 205:1 347:1 490:1 589:1 912:1 1016:1 1512:1
调用此文件h2o_example.svmlight
然后运行:
^{pr2}$最后两个命令失败,给我一个错误:
TypeError: 'property' object has no attribute '__getitem__'
显然,我用错了lambda_search
。如何根据我的标准为最佳模型获得单个alpha和lambda值?在
最终编辑
有多种获取lambda的方法(如下所示),但是这里有两种获得lambda的简洁方法(注意,完全可复制的代码位于底部)
如果有
lambda_search = True
,那么可以查看lambda_search
列下的模型摘要表,并查看为lambda.min
设置了什么值,这是最好的lambda它将生成一个字符串类似于:
^{pr2}$如果不使用lambda搜索,也不设置lambda值(或设置它),也可以使用摘要表
输出如下:
其他选项:
看看模型的实际参数:
best.actual_params['lambda']
best.actual_params['alpha']
在网格搜索结果中,
best
是您的最佳模型首次编辑
为了得到你能做的最好的模特
然后您可以使用:
完全可复制示例
我不知道为什么下面的方法不起作用
这可能是h2o的问题,但如果将上述更改为以下内容,则至少应能够访问这些参数:
^{pr2}$请注意,我已经将}中的内容可能不会根据您的错误标准进行排序。这需要您查看
0
更改为x
,因为您需要根据您的错误标准注意哪个模型执行得最好,因为{grid_table
,并记下模型的id,并查看模型是如何存储在grid
中的那么您至少应该能够引用}。但是,当您在alpha上运行网格搜索并通过
lambda
和{lambda_search
属性best.actual_params["lambda"]
启用对lambda
的搜索时,将返回搜索到的lambda的完整列表。您仍然可以通过考虑Lauren的建议来引用它,但是我通常喜欢查看表中的所有内容,并建议关闭lambda_search
并将其添加到您搜索的超参数中。在param_dict
应该是一个字典,它根据您指定的错误标准包含最佳模型的alpha和lambda值。在相关问题 更多 >
编程相关推荐