linear-regression

Pandas DataFrame - 'cannot astype a datetimelike from [datetime64[ns]] to [float64]' when using ols/linear regression

大憨熊 提交于 2019-11-30 23:42:50
I have a DataFrame as follows: Ticker Date Close 0 ADBE 2016-02-16 78.88 1 ADBE 2016-02-17 81.85 2 ADBE 2016-02-18 80.53 3 ADBE 2016-02-19 80.87 4 ADBE 2016-02-22 83.80 5 ADBE 2016-02-23 83.07 ...and so on. The Date column is the issue. I'm trying to get the linear regression of the Date column with the Close column: ols1 = pd.ols(y=ADBE['Close'], x=ADBE['Date'], intercept=True) I get the following error: TypeError: cannot astype a datetimelike from [datetime64[ns]] to [float64] I've tried multiple ways of getting rid of this error, for examples: dates_input = ADBE['Date'].values.astype(

How to solve several independent time series at the same time using scikit linear regression model

一个人想着一个人 提交于 2019-11-30 22:31:13
I try to predict multiple independent time series simultaneously using sklearn linear regression model, but I seem not be able to get it right. My data is organised as follow: Xn is a matrix where each row contains a forecast window of 4 observations and yn are the target values for each row of Xn . import numpy as np # training data X1=np.array([[-0.31994,-0.32648,-0.33264,-0.33844],[-0.32648,-0.33264,-0.33844,-0.34393],[-0.33264,-0.33844,-0.34393,-0.34913],[-0.33844,-0.34393,-0.34913,-0.35406],[-0.34393,-0.34913,-.35406,-0.35873],[-0.34913,-0.35406,-0.35873,-0.36318],[-0.35406,-0.35873,-0

Linear regression with constraints on the coefficients

断了今生、忘了曾经 提交于 2019-11-30 20:55:10
I am trying to perform linear regression, for a model like this: Y = aX1 + bX2 + c So, Y ~ X1 + X2 Suppose I have the following response vector: set.seed(1) Y <- runif(100, -1.0, 1.0) And the following matrix of predictors: X1 <- runif(100, 0.4, 1.0) X2 <- sample(rep(0:1,each=50)) X <- cbind(X1, X2) I want to use the following constraints on the coefficients: a + c >= 0 c >= 0 So no constraint on b. I know that the glmc package can be used to apply constraints, but I was not able to determine how to apply it for my constraints. I also know that contr.sum can be used so that all coefficients

Regression on subset of data set

拜拜、爱过 提交于 2019-11-30 20:02:11
问题 I'd like to do the following and need some help: Calculate slope and intercept for "Height" over "Age" [lm(Height~Age)] separately for (A) each individual (B) gender and create a table containing the results (slope and intercept). Can I use "apply" for this? In a next step I would like to do a statistical test to determine if slope and intercept are significantly different between Gender. I know how to do the test in R but maybe there is a way to combine slope/intercept calculation and T

Regression (logistic) in R: Finding x value (predictor) for a particular y value (outcome)

杀马特。学长 韩版系。学妹 提交于 2019-11-30 19:39:16
I've fitted a logistic regression model that predicts the a binary outcome vs from mpg ( mtcars dataset). The plot is shown below. How can I determine the mpg value for any particular vs value? For example, I'm interested in finding out what the mpg value is when the probability of vs is 0.50. Appreciate any help anyone can provide! model <- glm(vs ~ mpg, data = mtcars, family = binomial) ggplot(mtcars, aes(mpg, vs)) + geom_point() + stat_smooth(method = "glm", method.args = list(family = "binomial"), se = FALSE) The easiest way to calculate predicted values from your model is with the predict

R extract regression coefficients from multiply regression via lapply command

一曲冷凌霜 提交于 2019-11-30 16:11:13
问题 I have a large dataset with several variables, one of which is a state variable, coded 1-50 for each state. I'd like to run a regression of 28 variables on the remaining 27 variables of the dataset (there are 55 variables total), and specific for each state. In other words, run a regression of variable1 on covariate1, covariate2, ..., covariate27 for observations where state==1. I'd then like to repeat this for variable1 for states 2-50, and the repeat the whole process for variable2,

Weighted Linear Regression in Java

纵饮孤独 提交于 2019-11-30 14:11:05
问题 Does anyone know of a scientific/mathematical library in Java that has a straightforward implementation of weighted linear regression? Something along the lines of a function that takes 3 arguments and returns the corresponding coefficients: linearRegression(x,y,weights) This seems fairly straightforward, so I imagine it exists somewhere. PS) I've tried Flannigan's library: http://www.ee.ucl.ac.uk/~mflanaga/java/Regression.html, it has the right idea but seems to crash sporadically and

How to manually set coefficients for variables in linear model? [duplicate]

人走茶凉 提交于 2019-11-30 13:25:41
问题 This question already has an answer here : Set one or more of coefficients to a specific integer (1 answer) Closed 3 years ago . In R, how can I set weights for particular variables and not observations in lm() function? Context is as follows. I'm trying to build personal ranking system for particular products, say, for phones. I can build linear model based on price as dependent variable and other features such as screen size, memory, OS and so on as independent variables. I can then use it

Prediction of 'mlm' linear model object from `lm()`

穿精又带淫゛_ 提交于 2019-11-30 09:37:20
问题 I have three datasets: response - matrix of 5(samples) x 10(dependent variables) predictors - matrix of 5(samples) x 2(independent variables) test_set - matrix of 10(samples) x 10(dependent variables defined in response) response <- matrix(sample.int(15, size = 5*10, replace = TRUE), nrow = 5, ncol = 10) colnames(response) <- c("1_DV","2_DV","3_DV","4_DV","5_DV","6_DV","7_DV","8_DV","9_DV","10_DV") predictors <- matrix(sample.int(15, size = 7*2, replace = TRUE), nrow = 5, ncol = 2) colnames

How to fit the 2D scatter data with a line with C++

可紊 提交于 2019-11-30 08:37:09
问题 I used to work with MATLAB, and for the question I raised I can use p = polyfit(x,y,1) to estimate the best fit line for the scatter data in a plate. I was wondering which resources I can rely on to implement the line fitting algorithm with C++. I understand there are a lot of algorithms for this subject, and for me I expect the algorithm should be fast and meantime it can obtain the comparable accuracy of polyfit function in MATLAB. 回答1: I would suggest coding it from scratch. It is a very