linear-regression

How to implement multivariate linear stochastic gradient descent algorithm in tensorflow?

十年热恋 提交于 2019-12-09 06:15:55
问题 I started with simple implementation of single variable linear gradient descent but don't know to extend it to multivariate stochastic gradient descent algorithm ? Single variable linear regression import tensorflow as tf import numpy as np # create random data x_data = np.random.rand(100).astype(np.float32) y_data = x_data * 0.5 # Find values for W that compute y_data = W * x_data W = tf.Variable(tf.random_uniform([1], -1.0, 1.0)) y = W * x_data # Minimize the mean squared errors. loss = tf

linear regression using lm() - surprised by the result

为君一笑 提交于 2019-12-09 03:11:14
问题 I used a linear regression on data I have, using the lm function. Everything works (no error message), but I'm somehow surprised by the result: I am under the impression R "misses" a group of points, i.e. the intercept and slope are not the best fit. For instance, I am referring to the group of points at coordinates x=15-25,y=0-20. My questions: is there a function to compare fit with "expected" coefficients and "lm-calculated" coefficients? have I made a silly mistake when coding, leading

Why do different methods for solving Xc=y in python give different solution when they should not?

扶醉桌前 提交于 2019-12-09 01:21:42
问题 I was trying to solve a linear system Xc=y that was square. The methods I know to solve this are: using inverse c=<X^-1,y> using Gaussian elimination using the pseudo-inverse It seems as far as I can tell that these don't match what I thought would be the ground truth. First generate the truth parameters by fitting a polynomial of degree 30 to a cosine with frequency 5. So I have y_truth = X*c_truth . Then I check if the above three methods match the truth I tried it but the methods don't

How to correctly `dput` a fitted linear model (by `lm`) to an ASCII file and recreate it later?

梦想与她 提交于 2019-12-08 22:29:39
问题 I want to persist a lm object to a file and reload it into another program. I know I can do this by writing/reading a binary file via saveRDS / readRDS , but I'd like to have an ASCII file instead of a binary file. At a more general level, I'd like to know why my idioms for reading in dput output in general is not behaving as I'd expect. Below are examples of making a simple fit, and successful and unsuccessful recreations of the model: dat_train <- data.frame(x=1:4, z=c(1, 2.1, 2.9, 4)) fit

Linear regression for time series with Gnuplot

感情迁移 提交于 2019-12-08 18:48:20
问题 I am a big fan of Gnuplot and I used it all along my studies for various projects. Lately I wanted to use Gnuplot to chart some time series like weight loss, exercising results, gas consumptions etc. Therefore I scale the x-axis like set xdata time set timefmt "%d.%m %Y" set format x "%d.%m" Now I want to use the fit-function to give me a linear fit. My problem is, that I cannot get that to work if the x-axis is time-related. 回答1: R is probably a better tool for this kind of problem. It is

geom_smooth in ggplot2 not working/showing up

◇◆丶佛笑我妖孽 提交于 2019-12-08 14:44:03
问题 I am trying to add a linear regression line to my graph, but when it's run, it's not showing up. The code below is simplified. There are usually multiple points on each day. The graph comes out fine other than that. b<-data.frame(day=c('05/22','05/23','05/24','05/25','05/26','05/27','05/28','05/29','05/30','05/31','06/01','06/02','06/03','06/04','06/05','06/06','06/07','06/08','06/09','06/10','06/11','06/12','06/13','06/14','06/15','06/16','06/17','06/18','06/19','06/20','06/21','06/22','06

Is there a way to export the linear regression summaries from R as an image? I need to export the summaries as .jpeg or as .png

旧城冷巷雨未停 提交于 2019-12-08 13:42:54
问题 I am trying to export the linear regression summary to a powerpoint slide by R using the "R2PPT" package. But there is no option to export ".txt" file into powerpoint, so only "jpeg" files will do. Can someone please help me with this? 回答1: The package "Stargazer" would let you export the summary into beautifully formatted html, LaTex or plain ASCII text. Just open the resulting html file in a browser, copy it as is or capture it as an image and paste it into your presentation. library

Interpreting estimates of categorical predictors in linear regression [duplicate]

别说谁变了你拦得住时间么 提交于 2019-12-08 11:44:53
问题 This question already has answers here : Interpreting interactions in a regression model (2 answers) Closed 3 years ago . I'm new to linear regression and I'm trying to figure out how to interpret the summary results. I'm having difficulty interpreting the estimates of categorical predictors. Consider the following example. I added the columns age and length to include a numeric predictor and numeric target. library(MASS) data <- as.data.frame(HairEyeColor) data$length <- c(155, 173, 172, 176

how to plot the data for linear model with 3 variables in matlab?

爷,独闯天下 提交于 2019-12-08 11:35:25
问题 To plot the data in 3D plane for this model: y = a + a1*x1 + a2*x2 I do like this, the figure is shown in this website (http://kr.mathworks.com/help/stats/regress.html) , x1, x2, and y denote respectively vectors X, Y, and Z. scatter3(x1,x2,y,'filled') hold on x1fit = min(x1):100:max(x1); x2fit = min(x2):10:max(x2); [X1FIT,X2FIT] = meshgrid(x1fit,x2fit); YFIT = b(1) + b(2)*X1FIT + b(3)*X2FIT + b(4)*X1FIT.*X2FIT; mesh(X1FIT,X2FIT,YFIT) xlabel('Weight') ylabel('Horsepower') zlabel('MPG') view

TensorFlow: Reading and using data from CSV file

帅比萌擦擦* 提交于 2019-12-08 11:21:17
问题 I've tried the codes provided by Tensorflow here I've also tried the solution provided by Nicolas, I encountered an error: ValueError: Shape () must have rank at least 1 but I am incapable of manipulating the code such that I can grab the data and place it in train_X and train_Y variables. I'm currently using hard coded data for variable train_X and train_Y . My csv file contains 2 columns, Height & State of Charge(SoC), where height is a float value and SoC is a whole number (Int) starting