Why my Deming Regression line change so much when switching variables? If they seem to be a linear relationship betwen them? I am trying to fit a line that best predicts the production of energy Y given the speed of wind X, a typical Y = xm + b  , using deming regression. I am looking for the slope and the intercept of that line using the following formula:


I assume that  = 1.
This is my following python implementation of deming regression:
def deming_regresion(df, X, y, delta = 1):
'''Takes a pandas DataFrame, name of the 
columns as strings and the value of delta, 
and returns the slope and intercept following deming regression formula'''

    cov = df.cov()
    mean_x = df[X].mean()
    mean_y = df[y].mean()
    s_xx = cov[X][X]
    s_yy = cov[y][y]
    s_xy = cov[X][y]

    slope = (s_yy  - delta * s_xx + np.sqrt((s_yy - delta * s_xx) ** 2 + 4 * delta * s_xy ** 2)) / (2 * s_xy)

    intercept = media_y - pendiente  * media_x

    return slope, intercept

I meassure the % of MSE and MAE in the predictions and I get the following results when trying to predict Y = Energy Production and X = Wind Speed:

And the % of MSE and MAE are (MSE 97.72, MAE 69.85), slope, intercept of 17.85353671, -345.34106788.
When I switch variables, X = Energy Production and Y = Wind Speed I get this:

With these % of errors (MSE 44.9, MAE 32.23) and slope intercept of 0.04957782881808902, 21.051520903377014.
Why this happens? What am I doing wrong? I used Orthogonal Regression from scipy because my delta is equal to 1 and I still get very similar results. Maybe is a very stupid question but I will appreciate your help.
If you need any more info you can ask, I tried to put as much info as I could but maybe I missed something important. 
 A: You are getting very close to similar answer - but remember when you flip the axis, you flip the way the parameters come out.  You are initially fitting
$$y=ax+b$$
Then you fit
$$x=cy+d$$
For orthogonal regression these should indeed "match", but that doesn't mean $c=a$, instead, if we rearrange the second equation you get
$$y=\frac{x-d}{c}$$
so $a=c^{-1}$ and $b=-\frac{d}{c}$
Checking with your numbers then
$$17.85^{-1} = 0.056$$
$$\frac{-21.05}{0.0496} = -424.4$$
So not very far off.  I'm not sure where the rest of the difference will be coming from, but possibly you covariance estimates from pandas are not quite the calculation you expect?  Possibly an $n-1$ that should or should not be there.
A: When I try your function then it works as expected
import pandas as pd 
import numpy as np

np.random.seed(1)
df = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'))

mod1 = deming_regresion(df, 'A', 'B')
mod2 = deming_regresion(df, 'B', 'A')


print(1/mod1[0])
print(mod2[0])

returns
1.3756144526391498
1.3756144526391496

So it seems like you need to look into your auxiliary code. How do you call your function? Do you get errors in the computations? That sort of stuff.
