- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试使用 Keras 的顺序模型解决二元分类问题
并且必须满足给定的Balanced Error Rate (BER)
所以我认为使用 BER 而不是准确性作为指标是一个好主意。
我的 BER 自定义指标实现如下所示:
def balanced_error_rate(y_true, y_pred):
labels = theano.shared(np.asmatrix([[0, 1]], dtype='int8'))
label_matrix = K.repeat_elements(labels, K.shape(y_true)[0], axis=1)
true_matrix = K.repeat_elements(y_true, K.shape(labels)[0], axis=1)
pred_matrix = K.repeat_elements(K.round(y_pred), K.shape(labels)[0], axis=1)
class_lens = K.sum(K.equal(label_matrix, true_matrix), axis=1)
return K.sum(K.sum(class_lens - K.sum(K.equal(label_matrix, K.not_equal(true_matrix,pred_matrix)), axis=1), axis=0)/class_lens, axis=0)/2
这个想法是根据可用标签创建一个矩阵,并将其与输入数据进行比较(然后对这些数据求和)以获得该标签的元素数量......
我的问题是:
> K.shape(y_true)
Shape.0
> Typeinfo:
> type(y_true)
<class 'theano.tensor.var.TensorVariable'>
> type(K.shape(y_true))
<class 'theano.tensor.var.TensorVariable'>
...我找不到原因。
<小时/>我现在正在寻找:
获取数组维度的方法/解释为什么 shape
的行为如此/为什么 y_true
似乎具有 0
维度
或
通过重复给定的行/列向量来创建具有给定宽度/高度的张量矩阵的方法。
或
使用张量函数计算 BER 的更智能解决方案。
最佳答案
A way to get the array dimensions / an explanation why shape acts like it does / the reason why
y_true
seems to have 0 dimensions
处理 print
和 Theano 等抽象库的问题是,您通常不会获得值,而是获得值的表示。所以如果你这样做
print(foo.shape)
您不会获得实际的形状,而是获得运行时完成的操作的表示。由于这一切都是在外部设备上计算的,因此计算不会立即运行,而是仅在使用适当的输入创建函数(或调用 foo.shape.eval()
)之后运行。
打印该值的另一种方法是在使用该值时使用theano.printing.Print
,例如:
shape = theano.printing.Print('shape of foo')(foo.shape)
# use shape (not foo.shape!)
A method to create a tensor matrix with a given with/height by repeating a given row/column vector.
参见theano.tensor.repeat
为了那个原因。 numpy 中的示例(用法非常相似):
>>> x
array([[1, 2, 3]])
>>> x.repeat(3, axis=0)
array([[1, 2, 3],
[1, 2, 3],
[1, 2, 3]])
关于python - 平衡错误率作为度量函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37797621/
背景信息:对于国际销售表中的每一行,我需要检索过去特定日期的美元汇率,以便分析人员确定汇率变化的影响关于销售数字。然后,我将使用今天的汇率与过去的汇率之间的差值,并将其乘以销售额来确定影响。 实际问题
是否可以通过切片器值动态选取表中定义的适当 DAX 度量? 源表: +----------------+------------+ | col1 | col2 | +-
我有一个 ViewFlipper在我的主要 Activity View 上。在 onCreate 我实例化添加到 ViewFlipper 的 View 。之后,我将显示的 child 设置为第一个。当
我正在研究句子类别检测问题。每个句子可以属于多个类别例如: "It has great sushi and even better service." True Label: [[ 0. 0.
谁能帮我一起计算F-measure?我知道如何计算召回率和准确率,但不知道对于给定的算法如何计算一个 F-measure 值。 例如,假设我的算法创建了 m 个集群,但我知道相同数据有 n 个集群(由
我对通过宏精度和手动召回计算宏 f1-score 感兴趣。但结果并不相等。代码中 f1 和 f1_new 的最终公式有什么区别? from sklearn.metrics import precisi
我有一张记录了一些人体重的表格: Year Person Weight 2010 Mike 75 2010 Laura 60 2011 Mike 80 201
df分为训练数据帧和测试数据帧。训练数据帧分为训练数据帧和测试数据帧。因变量Y是二进制(因子),值为 0 和 1。我试图用此代码(神经网络,插入符号包)预测概率: library(caret) mod
我想使用 Hausdorff 距离作为训练指标,但我刚刚找到了 Weighted_Hausdorff_loss并将其用作医学图像分割的指标。 import math import numpy as n
我有一段时间没有使用 R,所以也许我只是不习惯它,但是..我在 R 中有一个表,有两个列,第一个有预测值(值可以是 0 或 1 ),第二个具有实际值(也是 0 或 1)。我需要找到召回率、精度和 f
我正在使用 Collectd 收集系统指标。我正在小范围内收集测量值以获得准确的值。但是我想使用 Statsd 在本地聚合这些值。 Statsd 应该聚合这些值并以更长的时间间隔将它们发送到 libr
我使用SciKit作为一个库来处理分类算法,例如:NB、SVM。 这是一个非常漂亮的binary classification implementation对于“垃圾邮件和HAM”电子邮件:
我正在寻找 MST 启发式算法的严格示例,它是度量旅行商问题的 2 近似算法。 这个算法在网上很容易找到,但我找不到具体的例子。我所说的严格示例是指给定算法返回的解决方案比最佳解决方案差 2 倍的示例
我使用 Data Studio 中的 Case 函数来确定某个值是否高于或低于 6,000 英镑,并根据输出呈现两个数字之一。这两个数字是计算字段。 第一个案例陈述: (大于或小于)- CASE WH
我正在使用 Ganglia + RRDTool为 monitoring a web farm .很多图很清楚,但是当我看到load_one metric , 我 don't have Y-axis l
以下是股票交易数据的简化版本。 StockData = DATATABLE ( "STOCK", STRING, "Date", DATETIME, "Buyer", STRI
我正在尝试将ASP.NET Core 7应用程序中的度量/跟踪发送到Grafana。。这是我的《码头工人》作文文件。。下面是我的收集器配置:。下面是配置OpenTelemeter的服务集合扩展方法。。
我正试图从我的ASP.NET Core 7应用程序向Grafana发送度量/跟踪。。这是我的《码头工人》作文文件。。下面是我的收集器配置:。下面是配置OpenTelemeter的服务集合扩展方法。。首
我是一名优秀的程序员,十分优秀!