regression

get x-value given y-value: general root finding for linear / non-linear interpolation function

久未见 提交于 2019-11-26 08:31:05
问题 I am interested in a general root finding problem for an interpolation function. Suppose I have the following (x, y) data: set.seed(0) x <- 1:10 + runif(10, -0.1, 0.1) y <- rnorm(10, 3, 1) as well as a linear interpolation and a cubic spline interpolation: f1 <- approxfun(x, y) f3 <- splinefun(x, y, method = \"fmm\") How can I find x -values where these interpolation functions cross a horizontal line y = y0 ? The following is a graphical illustration with y0 = 2.85 . par(mfrow = c(1, 2))

predict.lm() with an unknown factor level in test data

限于喜欢 提交于 2019-11-26 08:08:14
问题 I am fitting a model to factor data and predicting. If the newdata in predict.lm() contains a single factor level that is unknown to the model, all of predict.lm() fails and returns an error. Is there a good way to have predict.lm() return a prediction for those factor levels the model knows and NA for unknown factor levels, instead of only an error? Example code: foo <- data.frame(response=rnorm(3),predictor=as.factor(c(\"A\",\"B\",\"C\"))) model <- lm(response~predictor,foo) foo.new <- data

`lm` summary not display all factor levels

痞子三分冷 提交于 2019-11-26 05:34:33
问题 I am running a linear regression on a number of attributes including two categorical attributes, B and F , and I don\'t get a coefficient value for every factor level I have. B has 9 levels and F has 6 levels. When I initially ran the model (with intercepts), I got 8 coefficients for B and 5 for F which I understood as the first level of each being included in the intercept. I want ranking the levels within B and F based on their coefficient so I added -1 after each factor to lock the

What function defines accuracy in Keras when the loss is mean squared error (MSE)?

微笑、不失礼 提交于 2019-11-26 05:29:35
How is Accuracy defined when the loss function is mean square error? Is it mean absolute percentage error ? The model I use has output activation linear and is compiled with loss= mean_squared_error model.add(Dense(1)) model.add(Activation('linear')) # number model.compile(loss='mean_squared_error', optimizer='adam', metrics=['accuracy']) and the output looks like this: Epoch 99/100 1000/1000 [==============================] - 687s 687ms/step - loss: 0.0463 - acc: 0.9689 - val_loss: 3.7303 - val_acc: 0.3250 Epoch 100/100 1000/1000 [==============================] - 688s 688ms/step - loss: 0

Test labels for regression caffe, float not allowed?

点点圈 提交于 2019-11-26 04:56:38
I am doing regression using caffe, and my test.txt and train.txt files are like this: /home/foo/caffe/data/finetune/flickr/3860781056.jpg 2.0 /home/foo/caffe/data/finetune/flickr/4559004485.jpg 3.6 /home/foo/caffe/data/finetune/flickr/3208038920.jpg 3.2 /home/foo/caffe/data/finetune/flickr/6170430622.jpg 4.0 /home/foo/caffe/data/finetune/flickr/7508671542.jpg 2.7272 My problem is it seems caffe does not allow float labels like 2.0, when I use float labels while reading, for example the 'test.txt' file caffe only recognizes a total of 1 images which is wrong. But when I for example change the 2

Fast pairwise simple linear regression between variables in a data frame

醉酒当歌 提交于 2019-11-26 04:53:46
问题 I have seen pairwise or general paired simple linear regression many times on Stack Overflow. Here is a toy dataset for this kind of problem. set.seed(0) X <- matrix(runif(100), 100, 5, dimnames = list(1:100, LETTERS[1:5])) b <- c(1, 0.7, 1.3, 2.9, -2) dat <- X * b[col(X)] + matrix(rnorm(100 * 5, 0, 0.1), 100, 5) dat <- as.data.frame(dat) pairs(dat) So basically we want to compute 5 * 4 = 20 regression lines: ----- A ~ B A ~ C A ~ D A ~ E B ~ A ----- B ~ C B ~ D B ~ E C ~ A C ~ B ----- C ~ D

Extract regression coefficient values

半世苍凉 提交于 2019-11-26 04:38:29
问题 I have a regression model for some time series data investigating drug utilisation. The purpose is to fit a spline to a time series and work out 95% CI etc. The model goes as follows: id <- ts(1:length(drug$Date)) a1 <- ts(drug$Rate) a2 <- lag(a1-1) tg <- ts.union(a1,id,a2) mg <-lm (a1~a2+bs(id,df=df1),data=tg) The summary output of mg is: Call: lm(formula = a1 ~ a2 + bs(id, df = df1), data = tg) Residuals: Min 1Q Median 3Q Max -0.31617 -0.11711 -0.02897 0.12330 0.40442 Coefficients: Estimate

Test labels for regression caffe, float not allowed?

旧街凉风 提交于 2019-11-26 03:24:39
问题 I am doing regression using caffe, and my test.txt and train.txt files are like this: /home/foo/caffe/data/finetune/flickr/3860781056.jpg 2.0 /home/foo/caffe/data/finetune/flickr/4559004485.jpg 3.6 /home/foo/caffe/data/finetune/flickr/3208038920.jpg 3.2 /home/foo/caffe/data/finetune/flickr/6170430622.jpg 4.0 /home/foo/caffe/data/finetune/flickr/7508671542.jpg 2.7272 My problem is it seems caffe does not allow float labels like 2.0, when I use float labels while reading, for example the \'test

How to force R to use a specified factor level as reference in a regression?

眉间皱痕 提交于 2019-11-26 03:04:07
问题 How can I tell R to use a certain level as reference if I use binary explanatory variables in a regression? It\'s just using some level by default. lm(x ~ y + as.factor(b)) with b {0, 1, 2, 3, 4} . Let\'s say I want to use 3 instead of the zero that is used by R. 回答1: See the relevel() function. Here is an example: set.seed(123) x <- rnorm(100) DF <- data.frame(x = x, y = 4 + (1.5*x) + rnorm(100, sd = 2), b = gl(5, 20)) head(DF) str(DF) m1 <- lm(y ~ x + b, data = DF) summary(m1) Now alter the

How does predict.lm() compute confidence interval and prediction interval?

主宰稳场 提交于 2019-11-26 02:21:52
问题 I ran a regression: CopierDataRegression <- lm(V1~V2, data=CopierData1) and my task was to obtain a 90% confidence interval for the mean response given V2=6 and 90% prediction interval when V2=6 . I used the following code: X6 <- data.frame(V2=6) predict(CopierDataRegression, X6, se.fit=TRUE, interval=\"confidence\", level=0.90) predict(CopierDataRegression, X6, se.fit=TRUE, interval=\"prediction\", level=0.90) and I got (87.3, 91.9) and (74.5, 104.8) which seems to be correct since the PI