-1
$\begingroup$

I have about 8 features as my predictors in a logistic model I am trying to fit in python. One of the features is TotalAward (Financial Aid) and the second is NEED. I am attempting to predict the likelihood of student retention (not leaving/transferring). Since the feature (NEED) affects the relationship between TotalAward and Retention (y=1), I would like to interact it without interacting any other features in my (X=df[[ 'x1', 'x2', etc]]). In other statistical software, like stata, you would simply do $X1*X2$. How can I do this in python?

Thanks.

$\endgroup$
0
$\begingroup$

If you work with pandas, you can simply multiply the two variables:

df['c'] = df.a * df.b

Other sklearn solutions are a little daunting. But with pasty, you can construct design matrixes.

https://patsy.readthedocs.io/en/latest/API-reference.html

E.g. X, y = dmatrices('y ~ x1 + x2 + x3 + x1:x2', df)

$\endgroup$
  • $\begingroup$ Thank you. I assume that the first solution is for two continuous variables. How would you interact a categorical (or binary) with a continuous variable. $\endgroup$ – Scott Sep 29 at 1:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.