python - 将 RandomizedSeachCV 的评分参数设置为 r2

标签 python keras scikit-learn

我正在尝试使用 sklearn 中的 randomizedSearchCV() 来查找在使用 keras 构建的神经网络模型中使用的最佳参数。我希望它根据 r2 指标进行“评分” - 当我运行时它不会抛出任何错误,但运行后它会显示 best_score_ 为 -1.436。

这不是有效的 r2 指标(是吗?)。所以我想知道是否有人可以看一下下面的代码,看看他们是否可以发现

a) -1.436 的 best_score_ 是多少?

b) 如何修改以下代码以使函数返回 r2 指标?

我的神经网络模型称为 model4。 我在 RandomiszedSearchCV 中添加了“scoring = 'r2'”作为参数,我认为这是为了告诉它使用它作为分数

这是我用于RandomizedSearchCV()的代码:

model5 = KerasClassifier(build_fn=get_model4, epochs = 10)

params = {'num_layers' : [1,2,3,4], 'size_layers' : [5,10,25,100],'batchnorm' : [True,False], 'act' : ['relu','sigmoid','tanh'], 'lossfn' : ['mean_squared_error','mean_absolute_error','mean_squared_logarithmic_error'], 'lrate' : [0.01,0.001,0.0001]}


random_search = RandomizedSearchCV(model5, param_distributions=params, cv=KFold(3), scoring='r2')

random_search_results = random_search.fit(inputs,decisions)

print("Best: " + str(random_search_results.best_score_)+" using:"+str(random_search_results.best_params_))

最佳答案

是的,R^2分数可以是负数,它不是相关性而是决定系数,最大值为1.0,最小值为负无穷大。您可以从 scikit-learn documentation 获取此信息.

关于python - 将 RandomizedSeachCV 的评分参数设置为 r2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57536551/

相关文章:

Python VLC 脚本错误 : AttributeError: 'NoneType' object has no attribute 'media_player_new'

python - 如何将 Python 中的 Azure 认知服务中经过训练的分类器与 Keras 结合使用

python - 如何打印 Gridsearch 中每个组合的准确度分数?

python - Keras 可变大小的掩模或切片

machine-learning - DNN 二元分类器的准确率没有增加

python - 名称错误 : name 'x_train' is not defined

machine-learning - 使用sklearn DBSCAN模型对新条目进行分类

python - 在python中计算大数据集相似度矩阵的有效方法

python - 解析列中包含列表的 CSV

python - 重新findall : Inserting a variable value in regex failing when {} already used for range of occurences to match