評点型コンジョイント分析を Python 初心者でも直感的に行えるパッケージ
Project description
py4conjoint
評点型コンジョイント分析を Python初心者でも直感的に 行えるパッケージです。
Microsoft Forms / Google Forms のアンケート回答ファイルを読み込み、 符号化・回帰分析・結果の解釈・可視化までを一貫して行えます。
インストール
pip install py4conjoint
Google Colab では:
!pip install py4conjoint
クイックスタート
1. アンケートデータを読み込む
import pandas as pd
import py4conjoint as pc
# カード設計(プロファイル)を作成
cards = pd.DataFrame({
"price": [6, 10, 6, 10],
"os": ["android", "apple", "apple", "android"],
"camera": ["標準", "標準", "高性能", "高性能"],
}, index=["P1", "P2", "P3", "P4"])
# Microsoft Forms の回答ファイルを読み込む(デフォルト)
df = pc.forms_to_conjoint_data(
responses_file="responses.xlsx",
n_cards=4,
attributes=cards,
respondent_cols={"性別": "gender"},
)
# Google Forms の場合
df = pc.forms_to_conjoint_data(
responses_file="responses.csv",
n_cards=4,
attributes=cards,
forms="google",
)
2. 符号化する
df_coded = pc.encode(
df,
reference_levels={
"price": 10, # 高い方を基準(評点が低くなりそうな水準を選ぶ)
"os": "android",
"camera": "標準",
},
)
3. 回帰分析を実行する
result = pc.fit(df_coded)
print(result.summary())
============================================================
コンジョイント分析の結果(和文サマリー)
============================================================
観測数 : 120
説明変数の数 : 3
決定係数 R² : 0.9582
自由度修正 R² : 0.9571
【推定された係数(部分効用 part-worth)】
変数名 係数 p値 有意
------------------------- ---------- ---------- -----
切片 (b0) 4.2417 0.0000 ***
price_6 1.2583 0.0000 ***
os_apple 0.9083 0.0000 ***
camera_高性能 0.5917 0.0000 ***
有意水準: *** p<0.001 ** p<0.01 * p<0.05 . p<0.1
============================================================
4. 結果を解釈する
# 相対重要度(合計100%)
result.importance()
# range importance
# 属性
# price 2.5167 45.62
# os 1.8167 32.94
# camera 1.1833 21.44
# WTP(支払意思額)
result.wtp()
# coef wtp
# 属性(符号化列名)
# os_apple 0.9083 2.8874
# camera_高性能 0.5917 1.8805
# 評点1点の金額換算
result.unit_rating_money()
# 1.5894
# 市場シェア予測
products = pd.DataFrame({
"price_6": [1, -1],
"os_apple": [1, 1],
"camera_高性能": [1, -1],
}, index=["製品A", "製品B"])
result.market_share(products)
# 製品A 0.926
# 製品B 0.074
5. 可視化する
result.plot_importance() # 相対重要度の棒グラフ
result.plot_partworth() # 部分効用の棒グラフ
result.plot_wtp(price_unit="万円") # WTPの棒グラフ
主な機能
| 関数 / メソッド | 説明 |
|---|---|
forms_to_conjoint_data() |
Microsoft/Google Forms の回答ファイルを long 形式 DataFrame に変換 |
encode() |
属性列を効果コーディング(-1/+1)に自動変換 |
auto_reference_levels() |
基準水準を自動推測(補助関数) |
fit() |
OLS 回帰を実行し ConjointResult を返す |
result.summary() |
係数表・R²・落とし穴チェックの和文サマリー |
result.warnings() |
落とし穴の一覧(severity / category でフィルタ可) |
result.importance() |
各属性の相対重要度(合計100%) |
result.wtp() |
各属性の WTP(支払意思額) |
result.unit_rating_money() |
評点1点の金額換算(float) |
result.market_share() |
市場シェア予測(logit / max) |
result.plot_importance() |
相対重要度の棒グラフ |
result.plot_partworth() |
部分効用(パートワース)の棒グラフ |
result.plot_wtp() |
WTP の棒グラフ |
落とし穴の自動検出
fit() と wtp() は、以下の問題を自動的に検出して警告します:
| カテゴリ | 重大度 | 内容 |
|---|---|---|
r2_low |
大 | R² < 0.20(説明力が低い) |
few_respondents |
大/中 | 回答者数が少ない(5人未満) |
price_sign_negative |
中 | 価格係数の符号が逆(符号化ミスの疑い) |
price_insignificant |
中 | 価格係数の p 値 ≥ 0.10(WTP の信頼性低下) |
wtp_extrapolation |
大/中 | |WTP| > 価格レンジ × 2(外挿値) |
result.warnings() # すべての警告
result.warnings(severity="大") # 重大度「大」のみ
result.warnings(category="r2_low") # カテゴリでフィルタ
依存パッケージ
| パッケージ | バージョン |
|---|---|
| pandas | ≥ 1.5 |
| numpy | ≥ 1.21 |
| statsmodels | ≥ 0.13 |
| matplotlib | ≥ 3.4 |
| openpyxl | ≥ 3.0 |
ライセンス
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py4conjoint-0.2.0.tar.gz.
File metadata
- Download URL: py4conjoint-0.2.0.tar.gz
- Upload date:
- Size: 34.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4f6e2f32bb83f4f6613513bb65a842f4702d38aba0fc27b04b86f3ce6ba8eb4
|
|
| MD5 |
809f6e04467a97be8cb8dfe5ba5abd69
|
|
| BLAKE2b-256 |
b24539e3ce65d23a40d82befcad7c86ba2369d47e3420b89869ccfe9a58fb44e
|
Provenance
The following attestation bundles were made for py4conjoint-0.2.0.tar.gz:
Publisher:
publish.yml on Py4Conjoint/py4conjoint
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py4conjoint-0.2.0.tar.gz -
Subject digest:
d4f6e2f32bb83f4f6613513bb65a842f4702d38aba0fc27b04b86f3ce6ba8eb4 - Sigstore transparency entry: 1565665485
- Sigstore integration time:
-
Permalink:
Py4Conjoint/py4conjoint@d1fa8c9672bafc6ee3bb7d3f13dad7c870adcb28 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Py4Conjoint
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d1fa8c9672bafc6ee3bb7d3f13dad7c870adcb28 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file py4conjoint-0.2.0-py3-none-any.whl.
File metadata
- Download URL: py4conjoint-0.2.0-py3-none-any.whl
- Upload date:
- Size: 31.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad7e139c57807ce10354027f8cf7d13501eb3b6766117c52af4f7dd8db44cdb5
|
|
| MD5 |
cda56dd3ef6b8d5dca45f61fe4d0f18a
|
|
| BLAKE2b-256 |
f52c2352f93174a360241d368deb85a93f429350f65fe17fc8099e2aef9728b9
|
Provenance
The following attestation bundles were made for py4conjoint-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on Py4Conjoint/py4conjoint
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py4conjoint-0.2.0-py3-none-any.whl -
Subject digest:
ad7e139c57807ce10354027f8cf7d13501eb3b6766117c52af4f7dd8db44cdb5 - Sigstore transparency entry: 1565665532
- Sigstore integration time:
-
Permalink:
Py4Conjoint/py4conjoint@d1fa8c9672bafc6ee3bb7d3f13dad7c870adcb28 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Py4Conjoint
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d1fa8c9672bafc6ee3bb7d3f13dad7c870adcb28 -
Trigger Event:
workflow_dispatch
-
Statement type: