Difference in R-squared values for MATLAB and Python

I've fitted a data with following sigmoidal function with MATLAB using Curve Fitting Tool and with Python with scipy.curve_fit() for fitting and sklearn.metrics.r2_score for evaluation, and obtained strange results: $$R^2$$ = 0.582 for Python and 0.9609 for MATLAB. Data is identical for both Python and MATLAB as well as boundaries. Trust-Region was chosen as an algorithm.

Sigmoid: $$\sigma(x) = \frac{scale}{1+exp^{-slope*(x+xshift)}} + yshift$$.

Here is code for Python:

params,pconv = curve_fit(sigmoid, cD,cT, bounds=([-10,0,-500,5], [10,500,500,50]), maxfev=50000, loss = 'huber', f_scale = 0.5)

And here are MATLAB parameters:

However, fitted functions look similar:

Python:

MATLAB:

I think there should be a difference, but not so significant. It can be worse on the similar data(there are few datasets). Why does it happen?

UPD: After constraining data with new boundaries for cD $$R^2$$ increased (and that's what should be expected), but it is still lower than one, computed in MATLAB.

• In the Python plot there is no cD (X) data with a value greater than 45 or less than 5, but this is not true for the MATLAB plot. This is similarly true for plotted maximum values of the cT (Y) data. The plots indicate that these are two different data sets, is this correct? Sep 23, 2019 at 16:12
• Agree with James Phillips. The data is not the same, so why should the model metrics be?
– mkt
Sep 24, 2019 at 5:17
• My bad, edited the post, but issue remains the same. According to metrics on the last picture, R2 value seems to be computed correclty, at least in Python. Sep 24, 2019 at 7:06
• In Python you use a "Huber" loss. Why, then, is R-squared (which is appropriate for quadratic loss) even relevant? Indeed, no conceivable loss would be appropriate for these data given their extreme heteroscedasticity: both procedures performed admirably by finding good fits, but summarizing them by giving an overall measure of the residual sizes would be meaningless.
– whuber
Sep 24, 2019 at 11:41