小编mau*_*una的帖子

H2O的应用函数中FUN的约束是什么?

我正在使用版本3.10.4.8.

library(h2o)
h2o.init(nthreads = -1)

df <- as.h2o(data.frame(x = 1:5, y = 11:15))
Run Code Online (Sandbox Code Playgroud)

我正在尝试了解如何使用该apply()功能H2O.

以下按预期工作:

h2o::apply(df, 2, mean)
h2o::apply(df, 2, sum)
h2o::apply(df, 2, function(x) {2*x + 1})
Run Code Online (Sandbox Code Playgroud)

但这不是:

h2o::apply(df, 2, sd)
Run Code Online (Sandbox Code Playgroud)

返回的错误是:

[1]"查找无法找到is.H2OFrame".process.stmnt中的错误(stmnt,formalz,envs):不知道如何处理语句:is.H2OFrame x

我还以为它H2O实际上是使用自己的函数来进行计算,所以下面应该有效:

h2o::apply(df, 2, h2o.mean)
h2o::apply(df, 2, h2o.sum)
h2o::apply(df, 2, h2o.sd) 
Run Code Online (Sandbox Code Playgroud)

但事实并非如此.前两行给出以下错误:

[1]"查找无法找到.newExpr".process.stmnt中的错误(stmnt,formalz,envs):不知道如何处理语句:.newExpr sd x na.rm

而第三行给出以下错误:

[1]"查找无法找到.newExpr".process.stmnt中的错误(stmnt,formalz,envs):不知道如何处理语句:.newExpr sd x na.rm

FUN在将apply()函数传递给函数中的参数时,我应该注意什么?文档简单地描述FUN为"要应用的功能".

r apply h2o

6
推荐指数
0
解决办法
180
查看次数

如何在不使用库(pkg)的情况下修复“搜索列表中没有名为“ package:pkg”的项目”?

我正在编写一个名为testpkg的程序包,并将quantmod放在DESCRIPTION文件的Depends部分中。

我编写了以下功能:

#' hello1
#'
#' @return NA
#' @export
hello1 <- function() {
  print("hello1!")
  quantmod::is.HLC("Hello, world!")
}

#' hello2
#'
#' @return NA
#' @export
hello2 <- function () {

    x <- structure(c(25.85, 25.639999, 26.700001, 26.26, 26.92, 27.870001,
                   25.26, 25.52, 26.66, 25.610001, 26.85, 27.74, 26352700, 32512200,
                   64264600, 25.610001, 26.85, 27.74),
                 .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC",
                 src = "yahoo", updated = structure(1437653990.9303, class = c("POSIXct",
                                                                               "POSIXt")),
                 class = c("xts", "zoo"), index = structure(c(1167782400, …
Run Code Online (Sandbox Code Playgroud)

debugging r

5
推荐指数
0
解决办法
981
查看次数

如何创建自定义指标以在Tensorflow的Estimator类中使用?

在Tensorflow的tf.estimator指南中的Createing Estimators中,示例使用了tf.metrics模块中已预定义的指标。

是否有任何资源描述如何定义可用于评估估算器的自定义指标?我想实施F1指标。

tensorflow

5
推荐指数
0
解决办法
834
查看次数

TensorFlow 中相当于 PyTorch 中 expand() 的函数是什么?

假设我有一个 2 x 3 矩阵,我想创建一个 6 x 2 x 3 矩阵,其中第一维中的每个元素都是原始的 2 x 3 矩阵。

在 PyTorch 中,我可以这样做:

import torch
from torch.autograd import Variable
import numpy as np

x = np.array([[1, 2, 3], [4, 5, 6]])
x = Variable(torch.from_numpy(x))

# y is the desired result
y = x.unsqueeze(0).expand(6, 2, 3)
Run Code Online (Sandbox Code Playgroud)

在 TensorFlow 中执行此操作的等效方法是什么?我知道unsqueeze()相当于tf.expand_dims()但我不知道 TensorFlow 有任何相当于expand(). 我正在考虑使用tf.concat1 x 2 x 3 张量的列表,但不确定这是否是最好的方法。

python tensorflow pytorch

5
推荐指数
2
解决办法
3524
查看次数

有没有更好的方法来写这个时间序列的累积总和?

鉴于以下数据:

sample <- xts(c( 1,1,1,1,1,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,1,1,1,1,1,3,3,3,3,3,3,4,4,4,4,4,4,2,2,1,1,1,1,4,4,4,4,4,4,4,4,4),
          as.Date(x = "2014-11-03")+1:52)
Run Code Online (Sandbox Code Playgroud)

我想生产以下内容:

           [,1]
2014-11-05    0
2014-11-06    0
2014-11-07    0
2014-11-08    0
2014-11-09    1
2014-11-10    2
2014-11-11    3
2014-11-12    4
2014-11-13    5
2014-11-14    6
2014-11-15    7
2014-11-16    8
2014-11-17    9
2014-11-18   10
2014-11-19   11
2014-11-20   12
2014-11-21   13
2014-11-22   14
2014-11-23   15
2014-11-24    0
2014-11-25    0
2014-11-26    0
2014-11-27    0
2014-11-28    0
2014-11-29    1
2014-11-30    2
2014-12-01    3
2014-12-02    4
2014-12-03    5
2014-12-04    6
2014-12-05    7
2014-12-06    8
2014-12-07    9
2014-12-08   10
2014-12-09   11 …
Run Code Online (Sandbox Code Playgroud)

r time-series xts

3
推荐指数
1
解决办法
789
查看次数

如何使用R找到最合适的圆/椭圆?

我一直在阅读一些方法来使圆圈适合数据(像这样).我想看看这些方法如何处理真实数据以及为此使用R的想法.我试着在rseek上搜索可以帮助解决这个问题的软件包,但是却找不到任何有用的东西.

那么,是否有包可以帮助轻松计算给定数据集的最佳拟合圆(类似于lm()线性模型如何适应数据集)?否则,如何在R中执行这样的任务?

r best-fit-curve

3
推荐指数
1
解决办法
2667
查看次数

为什么tensorflow在训练Estimator多次时说Tensor不是该图的元素?

请考虑以下代码:

import tensorflow as tf

from tensorflow.python.estimator.model_fn import EstimatorSpec
from tensorflow.contrib.keras.api.keras.layers import Dense


def model_fn_1(features, labels, mode):
    x = [[1]]
    labels = [[10]]
    m = tf.constant([[1, 2], [3, 4]], tf.float32)
    lookup = tf.nn.embedding_lookup(m, x, name='embedding_lookup')

    preds = Dense(1)(lookup)
    loss = tf.reduce_mean(labels - preds)
    train_op = tf.train.GradientDescentOptimizer(0.01).minimize(loss, tf.train.get_global_step())

    eval_metric_ops = {'accuracy': tf.metrics.accuracy(labels, preds)}
    return EstimatorSpec(mode=mode, loss=loss, train_op=train_op, eval_metric_ops=eval_metric_ops)


model_1 = tf.estimator.Estimator(model_fn_1)
model_1.train(input_fn=lambda: None, steps=1)
Run Code Online (Sandbox Code Playgroud)

正如预期的那样,我可以执行model_1.train(input_fn=lambda: None, steps=1)多次,并且训练将从之前的执行继续进行.

现在,请考虑以下代码:

import tensorflow as tf
import numpy as np

from tensorflow.python.estimator.model_fn import …
Run Code Online (Sandbox Code Playgroud)

python machine-learning keras tensorflow

3
推荐指数
1
解决办法
2777
查看次数

Tensorflow:了解使用和不使用 Dropout Wrapper 的 LSTM 输出

import tensorflow as tf
import tensorflow.contrib.eager as tfe

tfe.enable_eager_execution()

x = tf.range(1, 11, dtype=tf.float32)
x = tf.reshape(x, (5, 1, 2))

cell = tf.contrib.rnn.LSTMCell(10)
initial_state = cell.zero_state(5, dtype=tf.float32)

y1, _ = tf.nn.dynamic_rnn(cell, x, dtype=tf.float32, initial_state=initial_state)

y2, _ = tf.nn.dynamic_rnn(
    tf.contrib.rnn.DropoutWrapper(cell, input_keep_prob=1.0, output_keep_prob=0.5, state_keep_prob=1.0),
    x,
    dtype=tf.float32,
    initial_state=initial_state)
Run Code Online (Sandbox Code Playgroud)

我正在使用 Tensorflow 1.8.0。

我期望的输出y2y1因为y2使用相同的 LSTM 单元相似,y1除了它也通过一个 dropout 层。由于 dropout 仅应用于 LSTM 单元的输出,我认为除了这里和那里的几个 0 之外,的值y2将相同y1。但这就是我得到的y1

<tf.Tensor: id=5540, shape=(5, 1, 10), dtype=float32, numpy= …
Run Code Online (Sandbox Code Playgroud)

lstm tensorflow dropout

2
推荐指数
1
解决办法
483
查看次数

为什么这两个 R 对象不相同?

我正在读《Data Mining with R》一书,发现了这段代码:

library(DMwR)

clean.algae <- knnImputation(algae, k = 10)
x <- sapply(names(clean.algae)[12:18],
            function(x,names.attrs) {
              f <- as.formula(paste(x,"~ ."))
              dataset(f,clean.algae[,c(names.attrs,x)],x)
            },
            names(clean.algae)[1:11])
Run Code Online (Sandbox Code Playgroud)

我认为x可以重写为:

y <- sapply(names(clean.algae)[12:18],
            function(x) {
              f <- as.formula(paste(x,"~ ."))
              dataset(f,clean.algae[,c(names(clean.algae)[1:11],x)],x)
            }
)
Run Code Online (Sandbox Code Playgroud)

然而,identical(x,y)回报FALSE

我决定通过将注意力限制在这些列表的第一个元素上来调查原因。

我找到:

identical(attributes(x[[1]])$data,
          attributes(y[[1]])$data)
[1] FALSE
Run Code Online (Sandbox Code Playgroud)

然而:

which(!(attributes(x[[1]])$data == attributes(y[[1]])$data))
integer(0)
Run Code Online (Sandbox Code Playgroud)

对我来说,这意味着数据框中的所有元素都是相等的,因此两个数据框必须相同。为什么情况并非如此?

我对对象的公式属性也有类似的问题:

> identical(attributes(x[[1]])$formula,
+           attributes(y[[1]])$formula)
[1] FALSE
> 
> attributes(x[[1]])$formula == attributes(y[[1]])$formula
[1] TRUE
Run Code Online (Sandbox Code Playgroud)

r

1
推荐指数
1
解决办法
331
查看次数