least-squares

Python statsmodels OLS: how to save learned model to file

坚强是说给别人听的谎言 提交于 2019-12-18 11:55:19
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 6 years ago . I am trying to learn an ordinary least squares model using Python's statsmodels library, as described here. sm.OLS.fit() returns the learned model. Is there a way to save it to the file and reload it? My training data is huge and it takes around half a minute to learn the model. So I was wondering if any save/load capability exists in OLS model. I tried the repr() method on the

Non-linear Least Squares Optimization Library for C [closed]

蓝咒 提交于 2019-12-18 10:36:15
问题 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 2 years ago . I'm looking for a library in C that will do optimization of an objective function (preferrably Levenberg-Marquardt algorithm) and will support box constraints, linear inequality constraints and non-linear inequality constraints. I've tried several libraries already, but none of them do employ the necessary

Graphing perpendicular offsets in a least squares regression plot in R

一笑奈何 提交于 2019-12-18 10:24:19
问题 I'm interested in making a plot with a least squares regression line and line segments connecting the datapoints to the regression line as illustrated here in the graphic called perpendicular offsets: http://mathworld.wolfram.com/LeastSquaresFitting.html (from MathWorld - A Wolfram Web Resource: wolfram.com) I have the plot and regression line done here: ## Dataset from http://www.apsnet.org/education/advancedplantpath/topics/RModules/doc1/04_Linear_regression.html ## Disease severity as a

lapack dgels_ segmentation fault 11

余生颓废 提交于 2019-12-14 02:48:36
问题 I am trying to use LAPACK's dgels_ in C to solve a linear least squares problem. I have to read the matrix A (assumed to have full rank and m>=n) and a vector b from 2 text files. I can easily compile my code, but when i try to run it I get a "segmentation fault 11", but I can't really see why. It is my first time using LAPACK so I don't know if maybe I am using the dgels_ function wrong?? The way I get it the solution x will be overwritten in the vector b? : lssolve.c: #include <stdlib.h>

Force NNLS result

痴心易碎 提交于 2019-12-13 20:03:43
问题 I am using scipy.optimize.nnls to compute non-negative least square fit with a coefficients sum to 1 : #! /usr/bin/env python3 import numpy as np import scipy.optimize as soptimize if __name__ == '__main__': C = np.array([[112.771820, 174.429720, 312.175750, 97.348620], [112.857010, 174.208300, 312.185270, 93.467580], [114.897210, 175.661850, 314.275100, 99.015480] ]); d = np.array([[112.7718, 174.4297, 312.1758, 97.3486]]); for line in d: ret , _= soptimize.nnls(C.T, line) print(ret) And I

3D vectors intersection using least-squares approach

假装没事ソ 提交于 2019-12-13 18:08:41
问题 I have been trying to get the intersection point of some 3D lines. The lines are represented in the form Line: s + t*r. The lines doesn't really intersect, so I would like to get the point in 3D that the distance from that point to all lines is minimum I found solutions for finding the intersection between two lines, but in my case, it is a set of lines, like 5 or more. I found a solution that represents the distance between the point a to line l: p+t*r (p is the start point, and r is the

plot 3D line, matlab

岁酱吖の 提交于 2019-12-13 12:30:38
问题 My question is pretty standard but can't find a solution of that. I have points=[x,y,z] and want to plot best fit line. I am using function given below (and Thanx Smith) % LS3DLINE.M Least-squares line in 3 dimensions. % % Version 1.0 % Last amended I M Smith 27 May 2002. % Created I M Smith 08 Mar 2002 % --------------------------------------------------------------------- % Input % X Array [x y z] where x = vector of x-coordinates, % y = vector of y-coordinates and z = vector of % z

Parameters estimation on Lotka Volterra model with Scilab

风格不统一 提交于 2019-12-13 04:40:53
问题 I'm trying to make a parameters estimation on Lotka-Volterra model with Scilab (I am a total neophyte). When I try to run the script, Scilab warns about incoherent subtraction. I guess my problem is the same as in this topic, but the solution there uses a Matlab function. Here is my script: // 1. Create Lotka Volterra function function [dY]=LotkaVolterra(t,X,c,n,m,e) IngestC = c * X(1) * X(2) GrowthP = n * X(1) MortC = m * X(2) dY(1) = GrowthP - IngestC dY(2) = IngestC * e - MortC endfunction

Polynomial Least Squares for Image Curve Fitting

十年热恋 提交于 2019-12-12 23:16:32
问题 I am trying to fit a curve to a number of pixels in an image so I can do further processing regarding it's shape. Does anyone know how to implement a least squares method in C/++ preferably using the following parameters: an x array, a y array, and an answers array (the length of the answers array should tell how many coefficients need to be calculated)? 回答1: If this is not some exercise in implementing this yourself, I would suggest you use a ready-made library like GNU gsl. Have a look at

Method signature for Jacobian of a least squares function in scipy

做~自己de王妃 提交于 2019-12-12 08:34:27
问题 Can anyone provide an example of providing a Jacobian to a least squares function in scipy ? I can't figure out the method signature they want - they say it should be a function, yet it's very hard to figure out what input parameters in what order this function should accept. 回答1: Here's the exponential decay fitting that I got to work with this: import numpy as np from scipy.optimize import leastsq def f(var,xs): return var[0]*np.exp(-var[1]*xs)+var[2] def func(var, xs, ys): return f(var,xs)