Patsy processes the predictors from low-order to high-order, and from
left-to-right. In this case all the predictors are first order (no
intercept, no interaction terms), so it's just left to right.
So it processes 'x' first, and uses a full-rank encoding. Then it
processes 'z', and it notices that since 'x' had a full-rank encoding,
if it gives 'z' a full-rank encoding, that will create collinearity.
So it decides to use a reduced-rank encoding for 'z'.
Then it has to actually generate the values. Since you haven't
specified any particular coding system, it uses the default coding
system, which is patsy.Treatment:
https://patsy.readthedocs.io/en/latest/API-reference.html#patsy.Treatment
When the Treatment class gets asked to produce a full-rank encoding,
it uses full-rank dummy encoding. When it gets asked to produce a
reduced-rank encoding, it does that by dummy coding all the levels
except for the "reference level". By default the reference level is
whichever level comes first, and by default levels are sorted. So in
your data, "9" is the first level (because it's the smallest), and
that's what patsy.Treatment uses as the reference level.
You can change the ordering of levels by using C(data, levels=[...]),
or if you pass in a pandas Categorical then patsy respects its level
ordering. You can change Treatment coding to use a different reference
level -- see the link above for examples. You can switch to a
different coding system entirely, by passing it like C(data,
coding_system), and this coding system could be one of the ones that
ship as part of patsy (e.g. patsy.Poly for polynomial encoding), or
you can define your own custom system:
https://patsy.readthedocs.io/en/latest/categorical-coding.html
Hope that helps.
-n
> --
> You received this message because you are subscribed to the Google Groups
> "PyData" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
pydata+un...@googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.
--
Nathaniel J. Smith --
https://vorpus.org