regression

Multiple outputs in Keras

徘徊边缘 提交于 2019-11-27 12:10:58
问题 I have a problem which deals with predicting two outputs when given a vector of predictors. Assume that a predictor vector looks like x1, y1, att1, att2, ..., attn , which says x1, y1 are coordinates and att's are the other attributes attached to the occurrence of x1, y1 coordinates. Based on this predictor set I want to predict x2, y2 . This is a time series problem, which I am trying to solve using multiple regresssion. My question is how do I setup keras, which can give me 2 outputs in the

Multivariate (polynomial) best fit curve in python?

不羁的心 提交于 2019-11-27 11:16:15
问题 How do you calculate a best fit line in python, and then plot it on a scatterplot in matplotlib? I was I calculate the linear best-fit line using Ordinary Least Squares Regression as follows: from sklearn import linear_model clf = linear_model.LinearRegression() x = [[t.x1,t.x2,t.x3,t.x4,t.x5] for t in self.trainingTexts] y = [t.human_rating for t in self.trainingTexts] clf.fit(x,y) regress_coefs = clf.coef_ regress_intercept = clf.intercept_ This is multivariate (there are many x-values for

Fit a non-linear function to data/observations with pyMCMC/pyMC

旧街凉风 提交于 2019-11-27 11:14:57
I am trying to fit some data with a Gaussian (and more complex) function(s). I have created a small example below. My first question is, am I doing it right? My second question is, how do I add an error in the x-direction, i.e. in the x-position of the observations/data? It is very hard to find nice guides on how to do this kind of regression in pyMC. Perhaps because its easier to use some least squares, or similar approach, I however have many parameters in the end and need to see how well we can constrain them and compare different models, pyMC seemed like the good choice for that. import

Linear Regression with a known fixed intercept in R

孤者浪人 提交于 2019-11-27 10:57:09
I want to calculate a linear regression using the lm() function in R. Additionally I want to get the slope of a regression, where I explicitly give the intercept to lm() . I found an example on the internet and I tried to read the R-help "?lm" (unfortunately I'm not able to understand it), but I did not succeed. Can anyone tell me where my mistake is? lin <- data.frame(x = c(0:6), y = c(0.3, 0.1, 0.9, 3.1, 5, 4.9, 6.2)) plot (lin$x, lin$y) regImp = lm(formula = lin$x ~ lin$y) abline(regImp, col="blue") # Does not work: # Use 1 as intercept explicitIntercept = rep(1, length(lin$x)) regExp = lm

Run an OLS regression with Pandas Data Frame

↘锁芯ラ 提交于 2019-11-27 10:03:32
I have a pandas data frame and I would like to able to predict the values of column A from the values in columns B and C. Here is a toy example: import pandas as pd df = pd.DataFrame({"A": [10,20,30,40,50], "B": [20, 30, 10, 40, 50], "C": [32, 234, 23, 23, 42523]}) Ideally, I would have something like ols(A ~ B + C, data = df) but when I look at the examples from algorithm libraries like scikit-learn it appears to feed the data to the model with a list of rows instead of columns. This would require me to reformat the data into lists inside lists, which seems to defeat the purpose of using

Messy plot when plotting predictions of a polynomial regression using lm() in R

自古美人都是妖i 提交于 2019-11-27 09:52:53
I am building a quadratic model with lm in R: y <- data[[1]] x <- data[[2]] x2 <- x^2 quadratic.model = lm(y ~ x + x2) Now I want to display both the predicted values and the actual values on a plot. I tried this: par(las=1,bty="l") plot(y~x) P <- predict(quadratic.model) lines(x, P) but the line comes up all squiggely. Maybe it has to do with the fact that it's quadratic? Thanks for any help. 李哲源 You need order() : P <- predict(quadratic.model) plot(y~x) reorder <- order(x) lines(x[reorder], P[reorder]) My answer here is related: Problems displaying LOESS regression line and confidence

How do I deal with NAs in residuals in a regression in R?

泪湿孤枕 提交于 2019-11-27 09:06:49
So I am having some issues with some NA values in the residuals of a lm cross sectional regression in R. The issue isn't the NA values themselves, it's the way R presents them. For example: test$residuals # 1 2 4 5 # 0.2757677 -0.5772193 -5.3061303 4.5102816 test$residuals[3] # 4 # -5.30613 In this simple example a NA value will make one of the residuals go missing. When I extract the residuals I can clearly see the third index missing. So far so good, no complaints here. The problem is that the corresponding numeric vector is now one item shorter so the third index is actually the fourth. How

Screening (multi)collinearity in a regression model

主宰稳场 提交于 2019-11-27 09:01:24
问题 I hope that this one is not going to be "ask-and-answer" question... here goes: (multi)collinearity refers to extremely high correlations between predictors in the regression model. How to cure them... well, sometimes you don't need to "cure" collinearity, since it doesn't affect regression model itself, but interpretation of an effect of individual predictors. One way to spot collinearity is to put each predictor as a dependent variable, and other predictors as independent variables,

evaluate (i.e., predict) a smoothing spline outside R

夙愿已清 提交于 2019-11-27 08:52:42
问题 I fitted a smoothing spline to data in R with library(splines) Model <- smooth.spline(x, y, df =6) I would like to take the fitted spline and evaluate it for arbitrary new data in an external code (not in R). In other words, do what the predict.smooth.spline function does. I had a look at the Model object: > str(Total_work_model) List of 15 $ x : num [1:14] 0.0127 0.0186 0.0275 0.0343 0.0455 ... $ y : num [1:14] 3174 3049 2887 2862 2975 ... $ w : num [1:14] 1 1 1 1 1 1 1 1 1 1 ... $ yin : num

How `poly()` generates orthogonal polynomials? How to understand the “coefs” returned?

丶灬走出姿态 提交于 2019-11-27 08:28:50
My understanding of orthogonal polynomials is that they take the form y(x) = a1 + a2(x - c1) + a3(x - c2)(x - c3) + a4(x - c4)(x - c5)(x - c6)... up to the number of terms desired where a1 , a2 etc are coefficients to each orthogonal term (vary between fits), and c1 , c2 etc are coefficients within the orthogonal terms, determined such that the terms maintain orthogonality (consistent between fits using the same x values) I understand poly() is used to fit orthogonal polynomials. An example x = c(1.160, 1.143, 1.126, 1.109, 1.079, 1.053, 1.040, 1.027, 1.015, 1.004, 0.994, 0.985, 0.977) #