A Python library for describing statistical models and building design matrices, aimed at bringing the convenience of R “formulas” to Python.
Questions tagged [patsy]
113 questions
0
votes
1 answer
Python - Patsy apparently installed but python can't find it?
So my installation for statsmodels has been very messy - I've actually had to move the folder into Enthought's site-packages folder myself. But anyway now, when I choose to import statsmodels.api as smapi, I get the following list of error…

Joshua D'Agostino
- 39
- 4
- 10
0
votes
1 answer
Grouping factors in python patsy
This is an extension of this older SO question but for python and not R. I also think this solution isn't the best.
Suppose I have data that looks like this...
State Y
AL 5
AK 10
AZ 8
I want to write a patsy formula to convert…

none
- 1,187
- 2
- 13
- 17
0
votes
2 answers
Pandas + Patsy + Statsmodels Linear Reg issue passing in categorical variable (duplicate rows)
[Preface: I now realize I should've used a classification model (maybe decision tree) instead but I ended up using a linear regression model.]
I had a pandas dataframe as such:
And I want to predict audience score using genre, year, tomato-meter…

SpicyClubSauce
- 4,076
- 13
- 37
- 62
0
votes
2 answers
patsy formula - adding powers of a factor
I use patsy to build design matrix. I need to include powers of the original factors. For example, with the regression , I want to be able to write
patsy.dmatrix('y~x1 + x1**2 + x2 + x2**2 + x2**3', data)
where data is a dataframe that contains…

Tom Bennett
- 2,305
- 5
- 24
- 32
0
votes
1 answer
Logistic Regression Bigram Text Classification w/ Patsy
I'm working on upgrading a LogisticRegression text classification from single word features to bigrams (two word features). However when I include the two word feature in the formula sent to patsy.dmatrices, I receive the following error...
y, X =…

digitaldavenyc
- 1,302
- 1
- 12
- 24
0
votes
0 answers
regression on trend + seasonal using python statsmodels
I have a question regarding regression in python. To make a long story short, I need to find a model of form yt = mt + st where mt and st are trends and seasonal component respectively. In my earlier analysis, I have found that a good model for mt…

Rajan S.
- 79
- 1
- 8
-1
votes
2 answers
create categorical variables by condition in python with pandas or statsmodels
I want to create categorical variables from my data with this method:
cat.var condition
1 x > 10
2 x == 10
3 x < 10
I try using C() method from patsy , but it doesn't work, I know in stata I have to use code below, but…

Mehdi
- 1,260
- 2
- 16
- 36