我试图从命令行运行Weka分类,但我的代码:
java weka.classifiers.bayes.NaiveBayes -t file1.arff -T file2.arff -p
Run Code Online (Sandbox Code Playgroud)
提出错误消息:
"无法找到主类:weka.classifiers.bayes.NaiveBayes.程序将退出."
我在包含weka.jar的目录中运行该命令.怎么没找到分类器?
我通过apache mahout运行朴素贝叶斯分类器算法.我们可以选择在训练和运行算法实例时设置克大小.
将我的n-Gram大小从1更改为2会大大改变生成的分类.为什么会这样?n-gram的大小如何使结果发生剧烈变化?
我想在 C++ 代码中使用 R 函数rmultinom与 Rcpp 一起使用。我收到一个关于参数不足的错误 - 我不熟悉这些参数应该是什么,因为它们与 R 中函数使用的参数不对应。我也没有使用“::Rf_foo”的运气从 Rcpp 代码访问 R 函数的语法。
下面是我的代码的简化版本(是的,我正在编写一个 gibbs 采样器)。
#include <Rcpp.h>
using namespace Rcpp;
// C++ implementation of the R which() function.
int whichC(NumericVector x, double val) {
int ind = -1;
int n = x.size();
for (int i = 0; i < n; ++i) {
if (x[i] == val) {
if (ind == -1) {
ind = i;
} else {
throw std::invalid_argument( "value appears multiple times." ); …Run Code Online (Sandbox Code Playgroud) 我试图在使用司仪之前使用高斯,但似乎无法完全弄清楚。基本上我想更换
def lnprior(theta):
a, b, c = theta
if 1.0 < a < 2.0 and 1.0 < b < 2.0 and 1.0 < c < 2.0:
return 0.0
return -np.inf
Run Code Online (Sandbox Code Playgroud)
使用可以从具有 mu 和 sigma 的高斯分布中采样“a”的东西。我该怎么做?像这样?
def lnprior(theta):
a, b, c = theta
if 1.0 < b < 2.0 and 1.0 < c < 2.0:
return 0.0
if 0<a<20:
mu=10
sigma=1
s=np.random.normal(mu, sigma)
return s
return -np.inf
Run Code Online (Sandbox Code Playgroud)
但这似乎不对?
我试图了解这两种方法之间的差异bayes以及包mle的bn.fit功能bnlearn。
我知道频率论者和贝叶斯方法之间关于理解概率的争论。在理论上,我认为最大似然估计mle是一种简单的频率论方法,将相对频率设置为概率。但是进行了哪些计算才能得到bayes估计值?我已经查看了bnlearn 文档、bn.fit 函数的描述和一些应用示例,但没有任何地方对正在发生的事情进行真正的描述。
我还尝试通过首先检出bnlearn::bn.fit、导致bnlearn:::bn.fit.backend、导致来理解 R 中的函数,bnlearn:::smartSapply但后来我被卡住了。
当我将软件包用于学术工作时,我会非常感谢您的帮助,因此我应该能够解释会发生什么。
我试图了解如何在 pymc 中使用黑盒似然函数。基本上,这是解释here。我尝试使用一个非常简单的 Python 模型(一个双逻辑函数)自行实现它,并且没有梯度。除了我提到的链接中的代码,它围绕对数似然函数设置 theano 包装器,我有以下代码
# Define the model
def my_model(p, t, m_m, m_M):
"""An simple double logistic model"""
return m_m + (m_M - m_m) * (
1.0 / (1 + np.exp(-p[0] * (t - p[1] * 365)))
+ 1.0 / (1 + np.exp(p[2] * (t - p[3] * 365)))
- 1
)
# The loglikelihood function
def log_lklhood(theta, t, data, sigma):
"""Normal log-likelihoood"""
y_pred = my_model(theta, t, data.max(), data.min())
retval = -(0.5 / sigma ** …Run Code Online (Sandbox Code Playgroud) 我试图不流泪地复制贝叶斯统计论文中的三个数字:采样重采样视角,可以在这里找到:http ://hedibert.org/wp-content/uploads/2013/12/1992SmithGelfand.pdf 我的目标是复制第 5 节的结果。这是我的代码:
theta1<-runif(1000,0,1)
theta2<-runif(1000,0,1)
theta<-cbind(theta1,theta2)
theta<-as.data.frame(theta)
plot(theta1,theta2)
n1<-c(5,6,4)
n2<-c(5,4,6)
y<-c(7,5,6)
l<-rep(NA,nrow(theta))
for (i in 1:nrow(theta)){
llh.1.store<-rep(NA,4)
for (j in 2:5){
llh.1.store[j-1]<-(factorial(n1[1])/(factorial(j)*factorial(n1[1]-j)))*(factorial(n2[1])/(factorial(y[1]-j)*factorial(n2[1]-y[1]+j)))*(theta[i,1]^j)*((1-theta[i,1])^(n1[1]-j))*(theta[i,2]^(y[1]-j))*((1-theta[i,2])^(n2[1]-y[1]+j))
}
llh1<-sum(llh.1.store)
llh.2.store<-rep(NA,5)
for (x in 1:5){
llh.2.store[x]<-(factorial(n1[2])/(factorial(x)*factorial(n1[2]-x)))*(factorial(n2[2])/(factorial(y[2]-x)*factorial(n2[2]-y[2]+x)))*(theta[i,1]^x)*((1-theta[i,1])^(n1[2]-x))*(theta[i,2]^(y[2]-x))*((1-theta[i,2])^(n2[2]-y[2]+x))
}
llh2<-sum(llh.2.store)
llh.3.store<-rep(NA,5)
for (t in 0:4){
llh.3.store[t+1]<-(factorial(n1[3])/(factorial(t)*factorial(n1[3]-t)))*(factorial(n2[3])/(factorial(y[3]-t)*factorial(n2[3]-y[3]+t)))*(theta[i,1]^t)*((1-theta[i,1])^(n1[3]-t))*(theta[i,2]^(y[3]-t))*((1-theta[i,2])^(n2[3]-y[3]+t))
}
llh3<-sum(llh.3.store)
l[i]<-prod(llh1,llh2,llh3)
}
q<-l/sum(l)
post.theta<-sample_n(theta,1000,replace=TRUE,weight=q)
ggplot(post.theta) +
aes(x = theta1, y = theta2) +
geom_point(
shape = "circle",
size = 1.85,
colour = "#440154"
) +
labs(title = "Sample from Posterior") +
ggthemes::theme_few()
Run Code Online (Sandbox Code Playgroud)
但它不会生成与图 2 相同的图。任何人都可以告诉我我做错了什么吗?
基于这个网址,我发现了贝叶斯评级,这很好地解释了评级模型,我想总结一下公式,使任何人实现SQL语句都更容易.如果我总结这样的公式,这会是正确的吗?
avg_num_votes = Sum(votes)/Count(votes) * Count(votes)
avg_rating = sum(votes)/count(votes)
this_num_votes = count(votes)
this_rating = Positive_votes - Negative_votes
Run Code Online (Sandbox Code Playgroud)
迦特
我正在为贝叶斯分析结果准备一份Latex文档和幻灯片.R中"coda"包产生的跟踪图非常大.按大小,我的意思是千字节(KB)和加载时间.当我在慢速计算机或IPAD中向下滚动pdf文件时,加载涉及跟踪图的页面需要花费大量时间.有没有办法"减轻"这些情节,以便滚动时间大幅减少?(例如转换为另一种格式而不会丢失太多细节).
注意:我使用Rstudio和knitr来生成乳胶文档.
例如,我使用以下代码生成了一个图.如果我将其导出为单页PDF文档,则PDF的大小将为439 KB(与大小为7 KB的基本图表相比).
library(coda)
temp <- mcmc(matrix(rnorm(100000),ncol=1))
traceplot(temp)
Run Code Online (Sandbox Code Playgroud) 如何使用Pymc3模拟6面骰子卷?另外,我知道骰子的不同侧面有不同的分布吗?