I may have led in that direction, and I know R only passingly, not well.
But my understanding is that thinking of a data structure that gets parsed
by an evaluator, e.g. "do a linear regression with this structure (and a
DataFrame)" is better than a lambda.

I'm sure it's possible to describe this with a function, but the Patsy
documentation provides something that is probably more helpful:

from patsy import ModelDesc, Term, EvalFactorform1 =
ModelDesc([Term([EvalFactor("y")])],
          [Term([]),
           Term([EvalFactor("a")]),
           Term([EvalFactor("a"), EvalFactor("b")]),
           Term([EvalFactor("np.log(x)")])
           ])

Compare to what you get from parsing the above formula:

form2 = ModelDesc.from_formula("y ~ a + a:b + np.log(x)")

So given those two equivalent structures, we might call, identically:

decision_tree(form1, data=my_df)
decision_tree(form2, data=my_df)

I think if I were writing a high-level data structure rather than a simple
parse tree, I might do something more like:

{'dependent': ['y'],
 'independent': ['a', Combine('a', 'b'), np.log(x)]}

But whatever the exact structure, basically the syntax just is a
mini-language to say which names go in which structural places for an
evaluator.

On Mon, Feb 24, 2020 at 3:43 PM Serhiy Storchaka <storch...@gmail.com>
wrote:

> 24.02.20 22:02, Guido van Rossum пише:
> > Hm, that's actually an interesting take. Can you compare it to the kind
> > of "quoting" that happens in a lambda? Is there some kind of translation
> > of the OP's original example (Lottery ~ Literacy + Wealth + Region) to a
> > lambda involving those words?
>
> I think that a named function is more appropriate than a lambda, because
> we need also the name of the output parameter:
>
>      def Lottery(Literacy, Wealth, Region):
>
> And the most known application of such technique is fixtures in pytest.
> _______________________________________________
> 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/226FMNG77OX4N262QZXFZYZU54LGQJNW/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.
_______________________________________________
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/27JPTANMXK43BXA7YQ5PE226VPS6GUXK/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to