Path: ...!news.mixmin.net!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: ram@zedat.fu-berlin.de (Stefan Ram) Newsgroups: comp.lang.python Subject: Re: Scipy curve_fit Date: 9 Mar 2025 14:05:35 GMT Organization: Stefan Ram Lines: 46 Expires: 1 Mar 2026 11:59:58 GMT Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de I9fF8GQMeKgicTpDgf7hHwfAqLKpMmFVGzE51TKVofgSfn Cancel-Lock: sha1:dyBH4rG9pddG1/rFgmv9MaubjJM= sha256:6jLRvZFnEOIsv2gtAB8n5983hTPHySFxEfltaYCunWc= X-Copyright: (C) Copyright 2025 Stefan Ram. All rights reserved. Distribution through any means other than regular usenet channels is forbidden. It is forbidden to publish this article in the Web, to change URIs of this article into links, and to transfer the body without this notice, but quotations of parts in other Usenet posts are allowed. X-No-Archive: Yes Archive: no X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some services to mirror the article in the web. But the article may be kept on a Usenet archive server with only NNTP access. X-No-Html: yes Content-Language: en-US Bytes: 3265 Jorge Conrado Conforte wrote or quoted: >OptimizeWarning: Covariance of the parameters could not be estimated >Please how can I resolve this error. The OptimizeWarning you're running into isn't a full-blown error, but a heads-up that the covariance of the parameters couldn't be nailed down. This often crops up when the fit's all over the map or when there's something fishy with the model or data. To get around this and up your curve fitting game, give these tricks a whirl: 1. Throw in some initial parameter guesstimates: # Tweak the number and values of initial guesses based on your model popt, _ = curve_fit(non_linear_model, preciamz, areaqamz, p0=[1, 1, 1]) . 2. Set some guardrails for your parameters if you've got a ballpark idea of where they should land: # Adjust bounds based on your model and data popt, _ = curve_fit(non_linear_model, preciamz, areaqamz, bounds=([0, 0, 0], [100, 100, 100])) . 3. Make sure your `non_linear_model` function is on point and coughs up values for all input data: # Example function, tweak based on your specific model def non_linear_model(x, a, b, c): return a * np.exp(-b * x) + c . 4. Give your data a once-over for any oddball points or inconsistencies that might throw a wrench in the works. 5. If you're still hitting a wall, try a different optimization method: popt, _ = curve_fit(non_linear_model, preciamz, areaqamz, method='trf') . 6. Think about using the lmfit library for more bells and whistles in fitting options and better handling of parameter uncertainties. If you're still stuck, double-check your model and data to make sure they're suitable for curve fitting. Keep in mind that curve_fit assumes continuous variables, so discrete or step-like data might gum up the works.