小编api*_*sch的帖子

更改图例标题 ggplot2

我在基于 ggplot2 的 R 中得到了一个情节。不幸的是,我在这里没有足够的声誉来上传情节。现在,我想更改我的图例标题和两行标签的名称。

因此,我添加scale_fill_continuous(name = "New Legend Title", labels=c("Control", "Treatment"))到代码中。

ggplot(data=descripintens, 
aes(x=syear, y=workingintensity, group= treatment, colour=factor(treatment))) + 
geom_line() +
xlab("Year") +
ylab("Working intensity") +
scale_fill_continuous(name = "New Legend Title", labels=c("Control", "Treatment"))
Run Code Online (Sandbox Code Playgroud)

这是 stackoverflow 和 ggplot2 备忘单中的建议。没有什么改变。甚至没有出现错误。

我的代码有什么问题?

谢谢!

编辑:我用于绘图的数据是一个表格,它基于以下代码:

descripintens<-intensity141516 %>% 
  group_by(syear, treatment) %>%
  summarise(workingintensity=mean(intensity))
Run Code Online (Sandbox Code Playgroud)

该表descripintens如下所示:

   syear Treatment workingintensity
1  2014     0         96.2
2  2014     1         98.4
3  2015     0         101.00000
4  2015     1         102.00000
5  2016     0         105.9
6  2016     1         106.2
Run Code Online (Sandbox Code Playgroud)

r legend ggplot2

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

python3上numpy中float32数字的矩阵乘法不稳定性

当我使用numpy. 简而言之,对于数学上相同的计算,numpy给了我不同的结果。

下面的代码片段说明了这个问题:

import numpy as np
np.set_printoptions(precision=10)
np.random.seed(2)  # for reproducibility

# create matrices:
A = np.random.rand(300, 1)
A = A/np.sum(A)
A = np.repeat(A, 15, 1)
B = np.random.rand(300, 300)

# convert data to float32:
A_star = A.astype("float32")
B_star = B.astype("float32")

# do the matrix multiplication A'BA and take the diagonal:
res_star = np.diag(A_star.transpose().dot(B_star.dot(A_star)))

# print the results:
print(res_star)
Run Code Online (Sandbox Code Playgroud)

在此运行python3.5numpy1.11.1Windows机器上打印以下数组:

[0.5000683069  0.5000683069  0.5000683069  0.5000683069  0.5000683069
 0.5000683069  0.5000683069  0.5000683069  0.5000683069  0.5000683069
 0.5000683069 …
Run Code Online (Sandbox Code Playgroud)

numpy matrix-multiplication python-3.x

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

qqplot + stat_smooth 错误

我正在尝试绘制我的值并使用 nls 模型将它们与曲线拟合。但我收到一条错误消息,说我的变量没有起始值。

conc <- c(1.83, 3.66, 7.32, 14.65, 29.30, 58.59, 117.19, 468.75, 937.5, 1875, 3750)  
avg <- c(0.02, 0.03, 0.05, 0.09, 0.23, 0.40, 0.60, 0.79, 0.98, 0.82, 1)

DataSet <- data.frame(conc, avg)

ggplot(DataSet, aes(x = conc, y = avg)) + 
  geom_point() +
  scale_x_log10() + 
  stat_smooth(aes(x=conc, y = avg), method = "nls", 
              formula = "avg~Emax*(conc^Hill)/((EC50^Hill)+(conc^Hill))",
              method.args=list(start=c(Emax = 1, EC50 = 100, Hill = 2)),
              se = FALSE)

# Warning message:
# Computation failed in `stat_smooth()`:
# parameters without starting value …
Run Code Online (Sandbox Code Playgroud)

r curve-fitting nls ggplot2

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

keras model.evaluate() 不显示损失

我在 中创建了以下形式的神经网络keras

from keras.layers import Dense, Activation, Input
from keras import Model

input_dim_v = 3
hidden_dims=[100, 100, 100]

inputs = Input(shape=(input_dim_v,))
net = inputs

for h_dim in hidden_dims:
    net = Dense(h_dim)(net)
    net = Activation("elu")(net)

outputs = Dense(self.output_dim_v)(net)
model_v = Model(inputs=inputs, outputs=outputs)
model_v.compile(optimizer='adam', loss='mean_squared_error', metrics=['mse'])
Run Code Online (Sandbox Code Playgroud)

后来,我使用model_v.train_on_batch(X[i],y[i]).

为了测试神经网络是否正在成为更好的函数逼近器,我想定期评估模型的累积Xy(在我的情况下,随着时间的推移Xy增长)。但是,当我调用 时model_v.evaluate(X, y),控制台中只显示特征进度条,但不会打印损失值和 mse-metric(在这种情况下是相同的)。

我怎样才能改变它?

python reinforcement-learning neural-network keras

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

R - 使用 ggplot2 在线条图中绘制不同时间序列的滚动平均值

我想用.绘制不同时间序列数据的滚动平均值ggplot2。我的数据具有以下结构:

library(dplyr)
library(ggplot2)
library(zoo)
library(tidyr)

df <- data.frame(episode=seq(1:1000), 
                 t_0 = runif(1000), 
                 t_1 = 1 + runif(1000), 
                 t_2 = 2 + runif(1000))
df.tidy <- gather(df, "time", "value", -episode) %>% 
  separate("time", c("t", "time"), sep = "_") %>%
  subset(select = -t)

> head(df.tidy)
#  episode time     value
#1       1    0 0.7466480
#2       2    0 0.7238865
#3       3    0 0.9024454
#4       4    0 0.7274303
#5       5    0 0.1932375
#6       6    0 0.1826925
Run Code Online (Sandbox Code Playgroud)

现在,下面的代码创建了一个图,其中时间 = 1 和时间 = 2 的线在剧集开始时不代表数据,因为value填充了 NA …

r ggplot2 zoo

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