小编Sam*_*Sam的帖子

如何设计keras神经网络用2类训练预测2(+1而非A不是B)类数据

我有一个用于二进制图像分类的convnet模型:cat/dog.

library(keras)
conv_base <- application_vgg16(
  weights = "imagenet",
  include_top = FALSE,
  input_shape = c(150, 150, 3)
)

# Hyperparameter construction
model <- keras_model_sequential() %>% 
  conv_base %>%
  layer_flatten() %>% 
  layer_dense(units = 256, activation = "relu") %>% 
  layer_dense(units = 1, activation = "sigmoid")

model %>% compile(
  loss = "binary_crossentropy",
  optimizer = optimizer_rmsprop(lr = 2e-5),
  metrics = c("accuracy")
)


img <- image_load('test_image.jpg', target_size = c(150, 150))
x <- image_to_array(img)
x <- array_reshape(x, c(1, dim(x)))
preds_class <- model %>% predict_classes(x)
model %>% predict(x)
Run Code Online (Sandbox Code Playgroud)

在 …

r deep-learning keras

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

使用tidytext和扫帚,但没有找到LDA_VEM整洁

tidytext书中有一些示例,主题模型更加整洁:

library(tidyverse)
library(tidytext)
library(topicmodels)
library(broom)

year_word_counts <- tibble(year = c("2007", "2008", "2009"),
+                            word = c("dog", "cat", "chicken"),
+                            n = c(1753L, 1157L, 1057L))

animal_dtm <- cast_dtm(data = year_word_counts, document = year, term = word, value = n)

animal_lda <- LDA(animal_dtm, k = 5, control = list( seed = 1234))

animal_lda <- tidy(animal_lda, matrix = "beta")

# Console output
Error in as.data.frame.default(x) : 
  cannot coerce class "structure("LDA_VEM", package = "topicmodels")" to a data.frame
In addition: Warning message:
In tidy.default(animal_lda, matrix …
Run Code Online (Sandbox Code Playgroud)

r broom tidytext

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

标签 统计

r ×2

broom ×1

deep-learning ×1

keras ×1

tidytext ×1