TransWikia.com

logistic like curve fitting using machine learning

Data Science Asked on July 7, 2021

I have a set of points of a function k(x). I am trying to do some curve fitting to find the exact k(x) function. It seems that the data points fit to a logistic like curve only a little shifted and stressed.

So far I have tried polynomial regression, but I don’t feel the fitting is correct. I have attached a snap of the fitted curve here.

So my question is, is logistic regression only used in classification tasks? Or can it be used for curve fitting?

If not what are the other available techniques to fit a logistic like curve to a set of data points?

Polynomial regression

3 Answers

So my question is, is logistic regression only used in classification tasks?

Name Logistic regression indicates that we could use this algorithm for regression problems.

Or can it be used for curve fitting?

It could be used to curve fitting.

If not what are the other available techniques to fit a logistic like curve to a set of data points?

Try numpy or scipy:

https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html

https://lmfit.github.io/lmfit-py/model.html

Answered by fuwiak on July 7, 2021

I guess you need to look for a non-parametric approach, such as generalised additive models (GAM), e.g. regression splines. These method(s) are extremely flexible in fitting non-linear data. With polynomials, you still work in a parametric world. With regression splines, you are much more flexible and there is no need to worry about the parameterisation of the model.

I have not worked with regression splines in Python, but there are libraries. You can get a good overview of the method(s) in Chapter 7 of "Introduction to Statistical Learning". There also is Python code for the Labs in the ISL-book. So you can directly adapt these methods.

Here is a little R example:

# Lead packages
library(ISLR)
library(gam)
library(Metrics)

# OLS
reg1 = lm(mpg~qsec,data=mtcars)

# Generalised additive models (regression splines, 5 DF)
reg2 = gam(mpg~s(qsec,5),data=mtcars)
par(mfrow=c(1,1))
plot(reg2)

mae(mtcars$mpg, predict(reg1, newdata=mtcars))
mae(mtcars$mpg, predict(reg2, newdata=mtcars))

The simple GAM has an MAE of 3.4 while the linear (OLS) model has an MAE of 4.2. So quite an improvement.

This would be the GAM plot of the simple model above, including CI bands. Rather flexible fit with no effort.

enter image description here

Answered by Peter on July 7, 2021

I suppose that you want to fit a logistic function to your data. A general form of logistic function is : $$y(x)=a+frac{b}{1+c: e^{-p:x}}$$ So they are four parameters $a,c,b,p$ to optimize.

The usual method is a non-linear regression calculus. This is an iterative process which requires 'guessed' initial values for the parameters to start the iteration.

They are some specialized sofwares to do it. For example, on the figure below the result with LMSE criteria of fitting is given corresponding to the black curve.

If no particular criteria of fitting is required in the wording of the problem, a simpler method (not iterative, no initial guess) is shown below :

enter image description here

The details of calculus are given below as well as the results and the corresponding blue curve.

enter image description here

For information : The general principle of the method is explained in
https://fr.scribd.com/doc/14674814/Regressions-et-equations-integrales

Answered by JJacquelin on July 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP