On 2020-02-23 15:58, Aaron Hall via Python-ideas wrote:
(Apologies for the html email, it was poorly formatted, making my example very 
difficult to follow. So let me try to give better examples.)

With sympy we would be able to create meaningful behavior for:

```
from sympy import symbols

y, x1, x2 = symbols('y x1 x2')

model = y ~ x1 + x2

model.is_linear() # -> True/False? (just an example!)
```

or

```
from sympy import symbols

theta, N, mu, sigma = symbols('theta N mu sigma')

distribution = theta ~ N(mu, sigma)
distribution.sample() # -> a symbolic sampling from the normal distribution
```

and for dataframes, arrays, or matrices, we could do something like:

```
model = df.y ~ df.x1 + df.x2
model.fit()
test_predictions = model.predict(df_test)
```

The thing is that you can already do that. You just can't do it with the specific character ~ for your operation. But that's not really a big deal is it? You could define this proposed behavior right now, using some other operator like `<<` and then make it so you can do

model = (df.y << df.x1) + df.x2

and so on. Also, since there's typically only one dependent variable, you could just define types that have a method `.depends_on` or `.modeled_by` or whatever, and an accessor attribute .term or something that so that you do

model = df.y.modeled_by(df.x1.term + df.x2)

I don't think think this is really much worse than R. In fact, I'd rather see something like "modeled_by" rather than the tilde. The problem, again, is not really the lack of the tilde, but the need to repeatedly specify `df`. I'm curious why you see the tilde as the crux of this issue, because it seems to me that the behavior you envision could already be implemented with another operator; it wouldn't look exactly like it does in R, but it could function pretty similarly.

--
Brendan Barnwell
"Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail."
   --author unknown
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/SJFJAJMVRGDMUJF2EQDICEDXW5HAZAGG/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to