昨天和今天在网上搜索后,我获得图例工作的唯一方法是遵循“Brian Diggs”在这篇文章中的解决方案: 将图例添加到 ggplot2 线图
这给了我以下代码:
library(ggplot2)
ggplot()+
geom_line(data=myDf, aes(x=count, y=mean, color="TrueMean"))+
geom_hline(yintercept = myTrueMean, color="SampleMean")+
scale_colour_manual("",breaks=c("SampleMean", "TrueMean"),values=c("red","blue"))+
labs(title = "Plot showing convergens of Mean", x="Index", y="Mean")+
theme_minimal()
Run Code Online (Sandbox Code Playgroud)
如果我删除 的颜色,一切都会正常,但是如果我在不是实际颜色hline的颜色中添加一个值(例如),我会得到一个错误,它不是颜色(仅适用于)。添加一个像传奇这样常见的东西怎么会成为一个大问题呢?还有更简单的方法吗?hline"SampleMean"hline
创建原始数据:
#Initial variables
myAlpha=2
myBeta=2
successes=14
n=20
fails=n-successes
#Posterior values
postAlpha=myAlpha+successes
postBeta=myBeta+fails
#Calculating the mean and SD
myTrueMean=(myAlpha+successes)/(myAlpha+successes+myBeta+fails)
myTrueSD=sqrt(((myAlpha+successes)*(myBeta+fails))/((myAlpha+successes+myBeta+fails)^2*(myAlpha+successes+myBeta+fails+1)))
#Simulate the data
simulateBeta=function(n,tmpAlpha,tmpBeta){
tmpValues=rbeta(n, tmpAlpha, tmpBeta)
tmpMean=mean(tmpValues)
tmpSD=sd(tmpValues)
returnVector=c(count=n, mean=tmpMean, sd=tmpSD)
return(returnVector)
}
#Make a df for the data
myDf=data.frame(t(sapply(2:10000, simulateBeta, postAlpha, postBeta)))
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 PyCharm 中导入张量流,但是出现错误,提示找不到该模块。我使用pip install来安装tensorflow。另外,当我查看 PyCharm 中的解释器时,它说我的 pip 版本是 9.0.1,最新的是 10.0.1。我已使用 pip 命令升级到 10.0.1,当我运行 pip --version 时,它说我得到了 10.0.1。我尝试过重新安装 pycharm 和创建新项目,但没有成功。
我想计算一个数据帧中单词的出现频率。这是我要实现的示例。
words = ['Dungeon',
'Crawling',
'Puzzle',
'RPG',]
desc =
0 [Dungeon, count, game, kid, draw, toddler, Unique]
1 [Beautiful, simple, music, application, toddle]
2 [Fun, intuitive, number, game, baby, toddler]
Run Code Online (Sandbox Code Playgroud)
请注意,desc是1690行的熊猫数据帧。
现在,我想检查一下words[i] in desc
我是否不想嵌套for循环,因此设置了一个函数来检查单词是否在desc中,然后apply()对每行使用,然后使用sum。
我得到的功能是:
def tmp(word, desc):
return (word in desc)
Run Code Online (Sandbox Code Playgroud)
但是,当我使用以下代码时:desc.apply(tmp, args = words[0])我收到指出的错误:tmp() takes 2 positional arguments but 8 were given。但是,当我手动将其与值结合使用时,tmp(words[0], desc[0])它就可以正常工作...。
我的问题是我在客户端上运行python 3,而执行程序的服务器运行了python 2。
因此,我设置了以下脚本:
from math import radians, cos, sin, asin, sqrt, exp
from datetime import datetime
def dateSmoother(a, b):
#Format the date
a = datetime.strptime(a, "%Y-%m-%d")
b = datetime.strptime(b, "%Y-%m-%d")
diff = (a-b).days
return exp(-(diff/h_date)**2)
def timeSmoother(a, b):
# Since we only got readings from two different times
# We first check to see if they are the same
if (a==b):
return exp(-(0/h_time)**2)
else:
return exp(-(12/h_time)**2)
h_date = 30
h_time = 12
a = "2013-11-01"
b = "2013-11-13"
print(dateSmoother(a, …Run Code Online (Sandbox Code Playgroud) python ×2
python-3.x ×2
geom-hline ×1
ggplot2 ×1
pandas ×1
pycharm ×1
python-2.7 ×1
r ×1
tensorflow ×1