楼主: rockykjy
5451 1

[问答] R软件中应用局部多项式拟合数据如何计算在指定的y值时,x的取值 [推广有奖]

  • 4关注
  • 0粉丝

讲师

0%

还不是VIP/贵宾

-

威望
0
论坛币
900 个
通用积分
70.8065
学术水平
1 点
热心指数
1 点
信用等级
1 点
经验
1930 点
帖子
185
精华
0
在线时间
613 小时
注册时间
2012-9-24
最后登录
2024-2-19

楼主
rockykjy 发表于 2015-3-23 10:19:03 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
方程为y ~ x + x^2请问是否有自带函数能在确定的因变量y值下求取x的可能值,比如predict函数(PS:试下来这个好像没办法)
如果在没有现成的函数,那么对x不断循环,使得其尽量逼近所需的y值,最终求得所需x值,这样的方法是否可取呢,谢谢。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:局部多项式 多项式拟合 r软件 多项式 predict 多项式 如何 软件

沙发
DM小菜鸟 发表于 2015-3-24 15:42:38
后半句说的是梯度下降法可以实现的内容

xs <- seq(0,4,len=20) # create some values

# define the function we want to optimize

f <-  function(x) {
1.2 * (x-2)^2 + 3.2
}

# plot the function
plot(xs , f (xs), type="l",xlab="x",ylab=expression(1.2(x-2)^2 +3.2))

# calculate the gradeint df/dx

grad <- function(x){
  1.2*2*(x-2)
}


# df/dx = 2.4(x-2), if x = 2 then 2.4(2-2) = 0
# The actual solution we will approximate with gradeint descent
# is  x = 2 as depicted in the plot below

lines (c (2,2), c (3,8), col="red",lty=2)
text (2.1,7, "Closedform solution",col="red",pos=4)


# gradient descent implementation
x <- 0.1 # initialize the first guess for x-value
xtrace <- x # store x -values for graphing purposes (initial)
ftrace <- f(x) # store y-values (function evaluated at x) for graphing purposes (initial)
stepFactor <- 0.6 # learning rate 'alpha'
for (step in 1:100) {
x <- x - stepFactor*grad(x) # gradient descent update
xtrace <- c(xtrace,x) # update for graph
ftrace <- c(ftrace,f(x)) # update for graph
}

lines ( xtrace , ftrace , type="b",col="blue")
text (0.5,6, "Gradient Descent",col="blue",pos= 4)

# print final value of x
print(x) # x converges to 2.0  

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-30 10:06