我正在使用k中的kernlab包中的ksvm训练SVM.我想使用概率模型,但在sigmoid拟合期间,我得到以下错误消息:
line search fails -1.833726 0.5772808 5.844462e-05 5.839508e-05 -1.795008e-08
-1.794263e-08 -2.096847e-12
Run Code Online (Sandbox Code Playgroud)
当发生这种情况时,得到的值prob.model(m)是所有概率的向量,而不是拟合在这些概率上的S形函数的预期参数.导致此错误的原因是什么?如何防止它?搜索错误消息没有产生任何结果.
可重复的例子:
load(url('http://roelandvanbeek.nl/files/df.rdata'))
ksvm(label~value,df[1:1000],C=10,prob.model=TRUE)->m
prob.model(m) # works as it should, prints a list containing one named list
# the below, non-working problem, unfortunately takes an hour due to the large
# sample size
ksvm(label~value,df,C=10,prob.model=TRUE)->m # line search fails
prob.model(m) # just a vector of values
Run Code Online (Sandbox Code Playgroud) 我使用ksvmR中的kernlab包来预测概率,使用中的type="probabilities"选项predict.ksvm.但是,我发现有时使用predict(model,observation,type="r")产量而不是具有最高概率的类predict(model,observation,type="p").
例:
> predict(model,observation,type="r")
[1] A
Levels: A B
> predict(model,observation,type="p")
A B
[1,] 0.21 0.79
Run Code Online (Sandbox Code Playgroud)
这是正确的行为还是错误?如果它是正确的行为,我如何根据概率估计最可能的类?
尝试重现性的例子:
library(kernlab)
set.seed(1000)
# Generate fake data
n <- 1000
x <- rnorm(n)
p <- 1 / (1 + exp(-10*x))
y <- factor(rbinom(n, 1, p))
dat <- data.frame(x, y)
tmp <- split(dat, dat$y)
# Create unequal sizes in the groups (helps illustrate the problem)
newdat <- rbind(tmp[[1]][1:100,], tmp[[2]][1:10,])
# Fit the model using …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Swing制作可缩放的地图.该地图是JScrollPane中的JPanel.放大时,地图会更改大小,而paint()会将元素绘制在不同的位置.一切都很好.
但是,ScrollPane在增加图像大小时不会更改视口,因此放大始终会将我正在查看的元素移出屏幕.我试图解决这个问题scrollRectToVisible(),但我没有设法得到矩形的正确坐标,要么是因为我在做几何体时失败了,要么因为我不太了解Swing.
这是我有的:
public class MapPanel extends JPanel {
[...]
public void setZoom(double zoom) {
// get the current viewport rectangle and its center in the scaled coordinate system
JViewport vp = (JViewport) this.getParent();
Rectangle rect = vp.getViewRect();
Point middle = getMiddle(rect);
Dimension dim = rect.getSize();
// zoom in
scaler.setZoom(zoom);
setPreferredSize(scaler.transform(dim));
this.revalidate();
// calculate the full size of the scaled coordinate system
Dimension fullDim = scaler.transform(dim);
// calculate the non-scaled center of the viewport
Point nMiddle = new …Run Code Online (Sandbox Code Playgroud) 我在R中有一个数据框,不幸的是它里面有包含美元符号的字符串.当latex()包中的函数Hmisc将此数据框转换为LaTeX表时,美元符号不会被转义.这使得LaTeX无法编译.Hmisc在格式化数据框中的值时,有没有办法逃避美元符号?
之后我无法进行搜索并替换所有美元符号,因为它Hmisc本身会为空单元格添加美元符号.
最小的例子:
> latex("test$test",file="")
# returns:
\begin{table}[!tbp]
% [...]
test$test\tabularnewline
% [...]
\end{table}
# should return:
\begin{table}[!tbp]
% [...]
test\$test\tabularnewline
% [...]
\end{table}
Run Code Online (Sandbox Code Playgroud)