- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有几个数据点似乎适合于通过它们拟合样条曲线。当我这样做时,我得到了一个非常坎bump的拟合,例如过度拟合,这不是我所理解的平滑。
是否有特殊的选项/参数来恢复像here这样的非常平滑的样条曲线的功能。penalty
的smooth.spline
参数的使用没有任何可见的效果。也许我做错了吗?
以下是数据和代码:
results <- structure(
list(
beta = c(
0.983790622281964, 0.645152464354322,
0.924104713597375, 0.657703886566088, 0.788138034115623, 0.801080207252363,
1, 0.858337365965949, 0.999687052533693, 0.666552625121279, 0.717453633245958,
0.621570152961453, 0.964658181346544, 0.65071758770312, 0.788971505000918,
0.980476054183113, 0.670263506919246, 0.600387040967624, 0.759173403408052,
1, 0.986409675965, 0.982996471134736, 1, 0.995340781899163, 0.999855895958986,
1, 0.846179233381267, 0.879226324448832, 0.795820998892035, 0.997586607285667,
0.848036806290156, 0.905320944437968, 0.947709125535428, 0.592172373022407,
0.826847031044922, 0.996916006944244, 0.785967729206612, 0.650346929853076,
0.84206351833549, 0.999043126652724, 0.936879214753098, 0.76674066557003,
0.591431233516217, 1, 0.999833445117791, 0.999606223666537, 0.6224971799303,
1, 0.974537160571494, 0.966717133936379
), inventoryCost = c(
1750702.95138889,
442784.114583333, 1114717.44791667, 472669.357638889, 716895.920138889,
735396.180555556, 3837320.74652778, 872873.4375, 2872414.93055556,
481095.138888889, 538125.520833333, 392199.045138889, 1469500.95486111,
459873.784722222, 656220.486111111, 1654143.83680556, 437511.458333333,
393295.659722222, 630952.170138889, 4920958.85416667, 1723517.10069444,
1633579.86111111, 4639909.89583333, 2167748.35069444, 3062420.65972222,
5132702.34375, 838441.145833333, 937659.288194444, 697767.1875,
2523016.31944444, 800903.819444444, 1054991.49305556, 1266970.92013889,
369537.673611111, 764995.399305556, 2322879.6875, 656021.701388889,
458403.038194444, 844133.420138889, 2430700, 1232256.68402778,
695574.479166667, 351348.524305556, 3827440.71180556, 3687610.41666667,
2950652.51736111, 404550.78125, 4749901.64930556, 1510481.59722222,
1422708.07291667
)
), .Names = c("beta", "inventoryCost"), class = c("data.frame")
)
plot(results$beta,results$inventoryCost)
mySpline <- smooth.spline(results$beta,results$inventoryCost, penalty=999999)
lines(mySpline$x, mySpline$y, col="red", lwd = 2)
最佳答案
在建模之前,合理地转换数据
根据results$inventoryCost
的规模,对数转换是合适的。为了简单起见,下面我使用x
,y
。我也正在重新排序您的数据,以便x
升序:
x <- results$beta; y <- log(results$inventoryCost)
reorder <- order(x); x <- x[reorder]; y <- y[reorder]
par(mfrow = c(1,2))
plot(x, y, main = "take log transform")
hist(x, main = "x is skewed")
x
进行进一步转换,因为它偏斜了! (请参见右图)。
x1 <- -(1-x)^(1/3)
(1-x)
的立方根将使数据在
x = 1
周围更加分散。我添加了一个附加的
-1
,以便
x
和
x1
之间存在正的单调关系,而不是负的关系。现在让我们检查一下关系:
par(mfrow = c(1,2))
plot(x1, y, main = expression(y %~% ~ x1))
hist(x1, main = "x1 is well spread out")
fit <- smooth.spline(x1, y, nknots = 10)
pred <- stats:::predict.smooth.spline(fit, x1)$y ## predict at all x1
## or you can simply call: pred <- predict(fit, x1)$y
plot(x1, y) ## scatter plot
lines(x1, pred, lwd = 2, col = 2) ## fitted spline
nknots = 10
告诉
smooth.spline
放置了10个
内部结(按分位数);因此,我们要拟合
罚分回归样条而不是平滑样条。实际上,除非您放置
smooth.spline()
,否则
all.knots = TRUE
函数几乎永远不会适合平滑样条线(请参阅后面的示例)。
penalty = 999999
,因为这与平滑度控制无关。如果您真的想控制平滑度,而不是让
smooth.spline
通过GCV找出最佳的平滑度,则应使用
df
或
spar
参数。我将在后面给出示例。
plot(x, exp(y), main = expression(Inventory %~%~ beta))
lines(x, exp(pred), lwd = 2, col = 2)
> fit
Smoothing Parameter spar= 0.4549062 lambda= 0.0008657722 (11 iterations)
Equivalent Degrees of Freedom (Df): 6.022959
Penalized Criterion: 0.08517417
GCV: 0.004288539
lambda= 0.0008657722
。
x
转换为x1
(x, y)
。对于0.98之前的
x
,该关系相对稳定。随着
x
接近1,这种关系会迅速变得更加陡峭。 “变化点” 0.98具有很高的二阶导数,远高于其他位置的二阶导数。
y0 <- as.numeric(tapply(y, x, mean)) ## remove tied values
x0 <- unique(x) ## remove tied values
dy0 <- diff(y0)/diff(x0) ## 1st order difference
ddy0 <- diff(dy0)/diff(x0[-1]) ## 2nd order difference
plot(x0[1:43], abs(ddy0), pch = 19)
bad <- smooth.spline(x, y, all.knots = TRUE)
bad.pred <- predict(bad, x)$y
plot(x, exp(y), main = expression(Inventory %~% ~ beta))
lines(x, exp(bad.pred), col = 2, lwd = 3)
abline(v = 0.98, lwd = 2, lty = 2)
x = 0.98
之后,样条在逼近数据方面有些困难。
x = 0.98
之后,增加模型复杂度将获得更好的近似值,但同时也会使其他部分变得更加坎bump。现在,让我们尝试一个具有45个自由度的模型:
worse <- smooth.spline(x, y, all.knots = TRUE, df = 45)
worse.pred <- predict(worse, x)$y
plot(x, exp(y), main = expression(Inventory %~% ~ beta))
lines(x, exp(worse.pred), col = 2, lwd = 2)
smooth.spline()
的滥用是在做同样的事情:
> mySpline
Call:
smooth.spline(x = results$beta, y = results$inventoryCost, penalty = 999999)
Smoothing Parameter spar= -0.8074624 lambda= 3.266077e-19 (17 iterations)
Equivalent Degrees of Freedom (Df): 45
Penalized Criterion: 5.598386
GCV: 0.03824885
关于r - R smooth.spline(): smoothing spline is not smooth but overfitting my data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37528590/
我有几个数据点似乎适合于通过它们拟合样条曲线。当我这样做时,我得到了一个非常坎bump的拟合,例如过度拟合,这不是我所理解的平滑。 是否有特殊的选项/参数来恢复像here这样的非常平滑的样条曲线的功能
编辑:我找到了一个 jQuery 解决方案! https://codepen.io/chriscoyier/pen/dpBMVP这个确实适用于 iOS。我想 jQuery 桥接浏览器支持问题的日子还没
我正在阅读世界各国的一些数据,并正在使用 Google 的可视化小工具,尤其是 map visualizations 。问题是,美国总是走在前面。虽然大多数国家/地区的值在 1 到 50 之间,但美国
我在我的 friend Google 上搜索了一些代码来进行平滑滚动并找到了这个:Smooth vertical scrolling on mouse wheel in vanilla javascr
在过去的一个半星期里,我一直在使用 Java 和 Swing 从头开始编写游戏。到目前为止,游戏运行一切顺利,除了一件事:跳跃。我正在尝试实现抛物线跳跃,以便玩家不只是向上传送一点点。相反,我希望
我将数据从 Cursor 加载到 ListView ,但我的 ListView 并没有真正显示“平滑”。当我在 ListView 的 scollbar 上上下拖动时,数据会发生变化。有些项目在我的列表
谁能给我一些关于如何生成“平滑”随机数的提示?这就是我所说的平滑: 随机数应在游戏中使用,例如风向和强度(有没有人记得好老的“蠕虫”?)。当然,每隔一秒左右为这些值设置随机数看起来会非常不稳定。我宁愿
这是我第一次在这里写文章。我对 JQuery 动画有一些问题:当持续时间非常慢(例如 10000)时, Action 不够平滑。我的 div 需要一个“自然”的运动。有人知道我的问题的解决方案吗?或者
我有一个数组: array = [10, 10, 10, 10, 10] 我想遍历这个数组,以便它得到一个基于整数的“斜率”。所以如果整数是 2,结果将是: array = [0, 5, 10, 5,
我正在构建一个股票代码,我正在尝试使用 Smooth Div Scroll插件,但我无法让它与动态创建的段落标签一起使用。它不是创建滚动的水平列表,而是将 P 标签垂直转储到页面上。如果段落标签是静态
有没有办法在平滑滚动(参见示例)结束时获得回调? 我唯一能想到的就是观察 scroll 的缺失事件,但没有办法将它们与 anchor 点击联系起来 - 您如何将它们与只是自己滚动页面的用户区分开来?
问题背景: 我正在 ASP.NET MVC 项目中使用 Twitter Bootstrap 3 开发一个单页网站。 问题: 我目前正在尝试实现“平滑滚动”,该滚动应该通过从导航栏下拉列表中单击来滚动到
平滑滚动对我来说一直感觉非常缓慢和滞后(我希望一切都快快),但幸运的是可以在浏览器设置中禁用它。但是,我注意到越来越多的网页使用 javascript 强制平滑滚动,无论我的设置如何(例如 this
我有一个由 div 制成的小 table ,上面有一个“添加新”按钮来添加新行,每行上有一个 x 按钮来删除该行。表格有一个最大高度,一旦达到这个高度就会在添加新行时滚动到底部。我已经在 css 中将
我使用了 CSS TRICKS 的 Smooth Scroll Plugin,它工作得很好,但只有 2 个 ancoher 链接,而不是另一个链接,请在此处查看演示, LIVE DEMO 它对行业和定
我尝试为 Google 地球 (c++) 编写自己的应用程序界面。我正在使用 Earthlib 来控制相机 (EARTHLib::ICameraInfoGE)。该接口(interface)允许控制相机
如果我想编写一个函数(可能也是一个类),它从不可变的查找表(调用构造函数时固定)返回线性“平滑”数据,如下所示: 例如func(5.0) == 0.5。 存储查找表的最佳方式是什么? 我正在考虑使用两
根据 Chromecast 开发人员页面,Chromecast 支持 SmoothStreaming 容器,我相信它使用带有 .ismv 扩展名的视频块。我在播放这些视频文件时遇到问题。 如果我没记错
原始问题 我想平滑我的解释变量,例如车辆的“速度”数据,然后使用此平滑后的值。我搜索了很多东西,却没有发现直接答案。 我知道如何计算内核密度估计(density()或KernSmooth::bkde(
我尝试了几种不同的开箱即用选项来平滑我的数据中的一个步骤,但还没有完全找到我所追求的。在下面粘贴一个小的可复制示例。正如下面的屏幕截图中突出显示的,是否有一个 R 函数可以平滑步骤,类似于 smoot
我是一名优秀的程序员,十分优秀!