regression

glmnet: How do I know which factor level of my response is coded as 1 in logistic regression

倾然丶 夕夏残阳落幕 提交于 2019-12-19 18:29:27
问题 I have a logistic regression model that I made using the glmnet package. My response variable was coded as a factor, the levels of which I will refer to as "a" and "b". The mathematics of logistic regression label one of the two classes as "0" and the other as "1". The feature coefficients of a logistic regression model are either positive, negative, or zero. If a feature "f"'s coefficient is positive, then increasing the value of "f" for a test observation x increases the probability that

机器学习算法(三)——Logistics Regression算法

匆匆过客 提交于 2019-12-19 14:07:23
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 一、算法简介 逻辑回归算法(Logistics Regression),虽然叫回归算法,但是主要用于处理因变量为分类变量的回归问题。 常见的是二分类或二项分布问题,也可以处理多分类问题,它实际上是属于一种分类算法。 二、算法原理 2-1 逻辑回归的推导 2-1-1 Sigmoid 函数:(z值就是预测值) 由于逻辑回归主要用于处理两分类问题。我们需要先找到一个预测函数(h),显然,该函数的输出必须是两个值(分别代表两个类别)。所以利用了Logistic函数(或称为Sigmoid函数),函数形式为: 二分类问题的概率与自变量之间的关系图形往往是一个S型曲线,如图所示,采用的Sigmoid函数实现: 该函数可以将任意的输入映射至[0,1]区间。我们在线性回归中,可以得到一个预测值,再将该值映射到Sigmoid函数中,就完成了由值到概率的转变。也就是分类问题。 2-1-2 用最大似然法来推导出损失函数 下面我们以二元逻辑回归为例子,假设我们的样本输出是0或者1两类。则: 合并上式: 其中y=0或者1。这样就得到了y的概率分布函数表达式。接下来我们用似然函数最大化来求解我们需要的模型参数 。 为了方便求解,我们用对数似然函数最大化,对数似然函数取反即为我们的损失函数 。 对数似然函数表达式为: 对数似然函数表达式

Rolling regression and prediction with lm() and predict()

六眼飞鱼酱① 提交于 2019-12-19 09:42:01
问题 I need to apply lm() to an enlarging subset of my dataframe dat , while making prediction for the next observation. For example, I am doing: fit model predict ---------- ------- dat[1:3, ] dat[4, ] dat[1:4, ] dat[5, ] . . . . dat[-1, ] dat[nrow(dat), ] I know what I should do for a particular subset (related to this question: predict() and newdata - How does this work?). For example to predict the last row, I do dat1 = dat[1:(nrow(dat)-1), ] dat2 = dat[nrow(dat), ] fit = lm(log(clicks) ~ log

plot.lm Error: $ operator is invalid for atomic vectors

拟墨画扇 提交于 2019-12-19 09:37:52
问题 I have the following regression model with transformations: fit <- lm( I(NewValue ^ (1 / 3)) ~ I(CurrentValue ^ (1 / 3)) + Age + Type - 1, data = dataReg) plot(fit) But plot gives me the following error: Error: $ operator is invalid for atomic vectors Any ideas about what I am doing wrong? Note : summary , predict , and residuals all work correctly. 回答1: This is actually quite a interesting observation. In fact, among all 6 plots supported by plot.lm , only the Q-Q plot fails in this case.

How to make a 2D Gaussian Process using GPML (Matlab) for regression?

一个人想着一个人 提交于 2019-12-19 09:15:46
问题 I have an Nx2 input matrix called X . I also have the output values Y which is a vector Nx1 . I create some data to test as follows: Xtest=linspace(x_min,x_max,n); Ytest=linspace(y_min,y_max,n); So, matrix Z is of nx2 dimensions and is going to be used as my test points. I use the default tuning of the parameters found in the demo provided with the GPML lib which is as follows: covfunc = {@covMaterniso, 3}; ell = 1/4; sf = 1; hyp.cov = log([ell; sf]); likfunc = @likGauss; sn = 0.1; hyp.lik =

How to create a graph showing the predictive model, data and residuals in R

倖福魔咒の 提交于 2019-12-19 06:44:50
问题 Given two variables, x and y , I run a dynlm regression on the variables and would like to plot the fitted model against one of the variables and the residual on the bottom showing how the actual data line differs from the predicting line. I've seen it done before and I've done it before, but for the life of me I can't remember how to do it or find anything that explains it. This gets me into the ballpark where I have a model and two variables, but I can't get the type of graph I want.

How to create a graph showing the predictive model, data and residuals in R

自闭症网瘾萝莉.ら 提交于 2019-12-19 06:44:07
问题 Given two variables, x and y , I run a dynlm regression on the variables and would like to plot the fitted model against one of the variables and the residual on the bottom showing how the actual data line differs from the predicting line. I've seen it done before and I've done it before, but for the life of me I can't remember how to do it or find anything that explains it. This gets me into the ballpark where I have a model and two variables, but I can't get the type of graph I want.

How to create a graph showing the predictive model, data and residuals in R

爷,独闯天下 提交于 2019-12-19 06:43:08
问题 Given two variables, x and y , I run a dynlm regression on the variables and would like to plot the fitted model against one of the variables and the residual on the bottom showing how the actual data line differs from the predicting line. I've seen it done before and I've done it before, but for the life of me I can't remember how to do it or find anything that explains it. This gets me into the ballpark where I have a model and two variables, but I can't get the type of graph I want.

Stock price predictions of keras multilayer LSTM model converge to a constant value

一笑奈何 提交于 2019-12-19 04:44:15
问题 I've made a multilayer LSTM model that uses regression to predict next frame's values of the data. The model finishes after 20 epochs. I then get some predictions and compare them to my ground truth values. As you can see them in the picture above, predictions converge to a constant value. I don't know why this happens. Here is my model so far: from keras.models import Sequential from keras.layers.core import Dense, Activation, Dropout from keras.layers import LSTM, BatchNormalization from

Regression by subset in R [duplicate]

泪湿孤枕 提交于 2019-12-19 04:12:29
问题 This question already has answers here : Linear Regression and group by in R (10 answers) Closed 3 years ago . I am new to R and am trying to run a linear regression on multiple subsets ("Cases") of data in a single file. I have 50 different cases, so I don't want to have to run 50 different regressions...be nice to automate this. I have found and experimented with the ddply method, but this, for some reason, returns the same coefficients to me for each case. Code I'm using is as follows: