How to learn a regression if the formula is known, but coefficients are not? My goal is to predict delivery cost by distance and client.
Data sample. Known clients are one-hot encoded.




distance
client_a
client_b
cost




8
0
0
130


15
1
0
180


12
1
0
153


18
0
1
184


15
1
0
180


20
0
0
250


12
1
0
153


16
0
1
168


10
0
1
120


13
0
0
180




I suppose a formula
$$
cost = (distance \times c_{dist} + c_{fee}) \times (1 - client\_a \times c_a) \times (1 - client\_b \times c_b)
$$
where
$c_{dist}$ - cost per distance unit
$c_{fee}$ - quote fee
$c_a$, $c_b$ - discounts for known clients
The perfect coefficients for the example: $c_{dist} = 10$, $c_{fee} = 50$, $c_a = 0.1$, $c_b = 0.2$.
I see that simple linear model doesn't match the formula.
Which approach can I use to learn $c_{dist}$, $c_{fee}$, $c_a$ and $c_b$ from the data?
 A: Inspiring by @user2974951 and @whuber suggestions
I can fix coefficients alternately in the formula
$$
cost = (distance \times c_{dist} + c_{fee}) \times (1 - client\_a \times c_a) \times (1 - client\_b \times c_b)
$$

*

*I get a linear model fixing $c_a$ and $c_b$
$$
\dfrac{cost}{client\_corrections} = distance \times c_{dist} + c_{fee}
$$


*I get a linear-log model fixing $c_{dist}$ and $c_{fee}$
$$
log(\dfrac{cost}{distance\_based\_cost}) = client\_a * correction_a + client\_b * correction_b
$$
Python implementation
from sklearn.linear_model import LinearRegression
import pandas as pd
import numpy as np

df = pd.DataFrame({
    'distance': [8, 15, 12, 18, 15, 20, 12, 16, 10, 13],
    'client_a': [0, 1, 1, 0, 1, 0, 1, 0, 0, 0],
    'client_b': [0, 0, 0, 1, 0, 0, 0, 1, 1, 0],
    'cost': [130, 180, 153, 184, 180, 250, 153, 168, 120, 180]
})

linear_model = LinearRegression()
df_1 = pd.DataFrame({
    'distance': df['distance'],
    'cost': df['cost']
})
linear_model.fit(df_1.drop('cost', axis=1), df_1['cost'])
c_dist = linear_model.coef_[0]
c_fee = linear_model.intercept_
print(f'''
# Fit linear model fixing "client_a" and "client_b to zero"
c_dist = {c_dist:.06f}
c_fee = {c_fee:.06f}
''')

df_2 = pd.DataFrame({
    'distance_cost_log': np.log(df['distance'] * c_dist + c_fee),
    'client_a_correction': df['client_a'],
    'client_b_correction': df['client_b'],
    'cost_log': np.log(df['cost'])
})
linear_log_model = LinearRegression(fit_intercept=False)
linear_log_model.fit(df_2.drop('cost_log', axis=1), df_2['cost_log'])
c_a = (1.0 - np.exp(linear_log_model.coef_[1]))
c_b = (1.0 - np.exp(linear_log_model.coef_[2]))
print(f'''
# Fit linear-log model fixing "c_dist" and "c_fee"
c_a = {c_a:.06f}
c_b = {c_b:.06f}
''')

linear_model = LinearRegression()
df_3 = pd.DataFrame({
    'distance': df['distance'],
    'discounted_cost': df['cost'] / (1 - df['client_a'] * c_a) / (1 - df['client_b'] * c_b)
})
linear_model.fit(df_3.drop('discounted_cost', axis=1), df_3['discounted_cost'])
c_dist = linear_model.coef_[0]
c_fee = linear_model.intercept_
print(f'''
# Fit linear model fixing "client_a" and "client_b"
c_dist = {c_dist:.06f}
c_fee = {c_fee:.06f}
''')

df_4 = pd.DataFrame({
    'distance_cost_log': np.log(df['distance'] * c_dist + c_fee),
    'client_a_correction': df['client_a'],
    'client_b_correction': df['client_b'],
    'cost_log': np.log(df['cost'])
})
linear_log_model = LinearRegression(fit_intercept=False)
linear_log_model.fit(df_4.drop('cost_log', axis=1), df_4['cost_log'])
c_a = (1.0 - np.exp(linear_log_model.coef_[1]))
c_b = (1.0 - np.exp(linear_log_model.coef_[2]))
print(f'''
# Again, fit linear-log model fixing "c_dist" and "c_fee"
c_a = {c_a:.06f}
c_b = {c_b:.06f}
''')

Output
# Fit linear model fixing "client_a" and "client_b to zero"
c_dist = 8.829268
c_fee = 47.073171


# Fit linear-log model fixing "c_dist" and "c_fee"
c_a = 0.099476
c_b = 0.199846


# Fit linear model fixing "client_a" and "client_b"
c_dist = 9.999716
c_fee = 49.949534


# Again, fit linear-log model fixing "c_dist" and "c_fee"
c_a = 0.100008
c_b = 0.200017

