在将预测值四舍五入到类中之后,如何在keras中计算回归模型的准确性? [英] How do you compute accuracy in a regression model, after rounding predictions to classes, in keras?

查看:256
本文介绍了在将预测值四舍五入到类中之后,如何在keras中计算回归模型的准确性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,在将预测四舍五入到最接近的整数类之后,您将如何在喀拉拉邦中创建和显示准确性度量标准?

How would you create and display an accuracy metric in keras for a regression problem, for example after you round the predictions to the nearest integer class?

尽管对于回归问题而言,准确性本身通常没有得到有效定义,但要确定数据的常规类/标签,将其视为回归是合适的.但是,无论是kappa还是类似的东西,也可以方便地计算准确性指标.这是要修改的基本keras样板代码.

While accuracy is not itself effectively defined conventionally for a regression problem, to determine ordinal classes/labels for data, it is suitable to treat the problem as a regression. But then it would be convenient to also calculate an accuracy metric, whether it be kappa or something else like that. Here is a basic keras boilerplate code to modify.

from keras.models import Sequential
from keras.layers.core import Dense, Activation

model = Sequential()
model.add(Dense(10, 64))
model.add(Activation('tanh'))
model.add(Dense(64, 1))
model.compile(loss='mean_absolute_error', optimizer='rmsprop')

model.fit(X_train, y_train, nb_epoch=20, batch_size=16)
score = model.evaluate(X_test, y_test, batch_size=16)

推荐答案

我使用的舍入精度如下:

I use rounded accuracy like this:

def soft_acc(y_true, y_pred):
    return K.mean(K.equal(K.round(y_true), K.round(y_pred)))

model.compile(..., metrics=[soft_acc])

这篇关于在将预测值四舍五入到类中之后,如何在keras中计算回归模型的准确性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆