regression

How to calculate Total least squares in R? (Orthogonal regression) [closed]

安稳与你 提交于 2019-12-17 16:37:27
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 months ago . I didn't find a function to calculate the orthogonal regression (TLS - Total Least Squares). Is there a package with this kind of function? Update: I mean calculate the distance of each point symmetrically and not asymmetrically as lm() does. 回答1: You might want to consider the Deming() function in package

how to debug “factor has new levels” error for linear model and prediction

若如初见. 提交于 2019-12-17 13:36:19
问题 I am trying to make and test a linear model as follows: lm_model <- lm(Purchase ~., data = train) lm_prediction <- predict(lm_model, test) This results in the following error, stating that the Product_Category_1 column has values that exist in the test data frame but not the train data frame): factor Product_Category_1 has new levels 7, 9, 14, 16, 17, 18 However, if I check these they definitely look to appear in both data frames: > nrow(subset(train, Product_Category_1 == "7")) [1] 2923 >

how to debug “factor has new levels” error for linear model and prediction

和自甴很熟 提交于 2019-12-17 13:34:09
问题 I am trying to make and test a linear model as follows: lm_model <- lm(Purchase ~., data = train) lm_prediction <- predict(lm_model, test) This results in the following error, stating that the Product_Category_1 column has values that exist in the test data frame but not the train data frame): factor Product_Category_1 has new levels 7, 9, 14, 16, 17, 18 However, if I check these they definitely look to appear in both data frames: > nrow(subset(train, Product_Category_1 == "7")) [1] 2923 >

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

北城余情 提交于 2019-12-17 10:06:32
问题 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. 回答1: You need order() : P <- predict(quadratic.model) plot(y~x) reorder <- order(x) lines(x[reorder]

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

陌路散爱 提交于 2019-12-17 10:05:16
问题 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. 回答1: You need order() : P <- predict(quadratic.model) plot(y~x) reorder <- order(x) lines(x[reorder]

Working with neuralnet in R for the first time: get “requires numeric/complex matrix/vector arguments”

好久不见. 提交于 2019-12-17 09:22:09
问题 I'm in the process of attempting to learn to work with neural networks in R. As a learning problem, I've been using the following problem over at Kaggle: Don't worry, this problem is specifically designed for people to learn with, there's no reward tied to it. I started with a simple logistic regression, which was great for getting my feet wet. Now I'd like to learn to work with neural networks. My training data looks like this (Column:Row): - survived: 1 - pclass: 3 - sex: male - age: 22.0 -

Working with neuralnet in R for the first time: get “requires numeric/complex matrix/vector arguments”

ε祈祈猫儿з 提交于 2019-12-17 09:22:07
问题 I'm in the process of attempting to learn to work with neural networks in R. As a learning problem, I've been using the following problem over at Kaggle: Don't worry, this problem is specifically designed for people to learn with, there's no reward tied to it. I started with a simple logistic regression, which was great for getting my feet wet. Now I'd like to learn to work with neural networks. My training data looks like this (Column:Row): - survived: 1 - pclass: 3 - sex: male - age: 22.0 -

机器学习算法(二)——LR算法

徘徊边缘 提交于 2019-12-16 16:07:49
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 一、算法简介 线性回归算法(Linear Regression),即LR算法。 再讲解LR算法之前,我们先学习一下什么是线性?什么是非线性? 我们首先用弄清楚什么是线性,什么是非线性。 - 线性函数的定义是:一阶或零阶多项式。 - 特征是一维时,线性模型在二维空间构成一条直线; - 特征是二维时,线性模型在三维空间中构成一个平面; - 特征是三维时,则最终模型在四维空间中构成一个体;以此类推… 那么回归又是什么意思呢? - 回归:人们在测量事物的时候因为客观条件所限,求得的都是测量值,而不是事物真实的值。 - 为了能够得到真实值,无限次的进行测量,最后通过这些测量数据计算回归到真实值,这就是回归的由来。 通俗的说就是用一个函数去逼近这个真实值,那又有人问了,线性回归不是用来做预测吗?是的,通过大量的数据我们是可以预测到真实值的。 二、算法原理 线性回归: 就是能够用一个直线较为精确地描述数据之间的关系,这样当出现新的数据的时候,就能够预测出一个简单的值。 线性回归才是真正用于回归的,而不像logistic回归是用于分类, 基本思想是用梯度下降法对最小二乘法形式的误差函数进行优化 。 线性回归一般用于解决什么问题 寻找到数据与数据之间的规律所在,从而就可以模拟出结果,也就是对结果进行预测。

How to add a column of fitted values to a data frame by group?

泄露秘密 提交于 2019-12-14 02:49:37
问题 Say I have a data frame like this: X <- data_frame( x = rep(seq(from = 1, to = 10, by = 1), 3), y = 2*x + rnorm(length(x), sd = 0.5), g = rep(LETTERS[1:3], each = length(x)/3)) How can I fit a regression y~x grouped by variable g and add the values from the fitted and resid generic methods to the data frame? I know I can do: A <- X[X$g == "A",] mA <- with(A, lm(y ~ x)) A$fit <- fitted(mA) A$res <- resid(mA) B <- X[X$g == "B",] mB <- with(B, lm(y ~ x)) B$fit <- fitted(mB) B$res <- resid(mB) C

Python: Cubic Spline Regression for a time series data

戏子无情 提交于 2019-12-13 23:27:29
问题 I have the data as shown below. I want to find a CUBIC SPLINE curve that fits the entire data set (link to sample data). Things I've tried so far: I've gone through scipy's Cubic Spline Functions, but all of them are only able to give results at a single time only, whereas I want a single curve for the entire time range. I plotted a graph by taking an average of the spline coefficients generated by scipy.interpolate.splrep for a 4 number of knots, but the results were not good and didn't