formula support for categorical endog variable in logistic regression
まだ誰も着手していません。
評価
調査の方向性
まず、issue にある 2 つの smf.logit の式の例を再現し、手動でダミー変数化した形式と C(sex) ~ C(smoker) + C(time) を比較します。報告されている patsy の制限を調査し、カテゴリ型の内生変数がどのように動作すべきかを決定します。カテゴリ型の式が適切な回帰結果と回帰カバレッジを伴ってサポートされた時点で、作業は完了です。
索引モデルが issue の本文から書いたものです。
説明
patsy: '0.5.1'
https://github.com/statsmodels/statsmodels/issues/5552
SM: 0.9.0
For categorical endog variable in logistic regression, I still have to gerneate a dummay variable for it like the following.import pandas as pd import seaborn as sns import numpy as np import statsmodels.formula.api as smf # generate dummy df['male'] = df.sex.map({'Male': 1, 'Female': 0}) # regression formula = 'male ~ C(smoker) + C(time)' model = smf.logit(formula, data=df).fit() model.summary()If I just do
formula = 'C(sex) ~ C(smoker) + C(time)' model = smf.logit(formula, data=df).fit() model.summary()I will get
ValueError: operands could not be broadcast together with shapes (244,2) (244,)This is a little bit weird, since the formula support all categorical variables but the endog. I wonder if this could be a poential feature to imporve.
Btw, is there any current workaround for this issue if I wanna use formula?
@bashtage:
This is a patsy limit. You could just define a function C1
def C1(cat): return pd.get_dummies(cat, drop_first=True)and then use
formula = 'C1(sex) ~ C(smoker) + C(time)'
- 主要言語
- Python
- スター
- 989
- フォーク
- 107
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
pydata/patsy のほかの issue
-
VarLookupDict should implement __iter__, causes CPython crash when using statsmodels in marimo notebook対応中かも @kouyouqi123 が 131 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
-
`build._eval_factor` error condition attempts to access attribute `dtype` on `DataFrame` object, but no such attribute exists対応中かも @kouyouqi123 が 131 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 55/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
MystenLabs/MemWal#1163 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
infertopics leaves new nodes without a topic when untopiced neighbours outnumber topiced ones対応中かも @moneebullah25 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
ClanGenOfficial/clangen#6254 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
FinanceFlash/unvibecode#218 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信