Skip to content
Snippets Groups Projects
Commit e8b07157 authored by Mirko Birbaumer's avatar Mirko Birbaumer
Browse files

adapted notebooks 3.5

parent 36330cd4
No related branches found
No related tags found
No related merge requests found
Pipeline #650601 passed
%% Cell type:markdown id:81fdcf78-334f-476c-80aa-d953dd0c852a tags: %% Cell type:markdown id:81fdcf78-334f-476c-80aa-d953dd0c852a tags:
# Beispiel 6.2 # Beispiel 6.2
Der Datensatz `Credit` wurde in den USA erhoben. Er führt für eine grössere Anzahl Individuen die Zielvariable `balance` (monatliche Kreditkartenrechnung) wie auch mehrere quantitative erklärende Variablen auf: `age` (Alter), `cards` (Anzahl Kreditkarten), `education` (Anzahl Jahre Ausbildung), `income` (Einkommen in Tausenden Dollars), `limit` (Kreditkartenlimite) und `rating` (Kreditwürdigkeit). Der Datensatz `Credit` wurde in den USA erhoben. Er führt für eine grössere Anzahl Individuen die Zielvariable `balance` (monatliche Kreditkartenrechnung) wie auch mehrere quantitative erklärende Variablen auf: `age` (Alter), `cards` (Anzahl Kreditkarten), `education` (Anzahl Jahre Ausbildung), `income` (Einkommen in Tausenden Dollars), `limit` (Kreditkartenlimite) und `rating` (Kreditwürdigkeit).
%% Cell type:code id:0b984ab2-563c-4e62-a08f-7b46170a583c tags: %% Cell type:code id:0b984ab2-563c-4e62-a08f-7b46170a583c tags:
``` python ``` python
import pandas as pd import pandas as pd
import arviz as az import arviz as az
df = pd.read_csv("./Daten/Credit.csv").drop("Unnamed: 0", axis=1) df = pd.read_csv("./Daten/Credit.csv").drop("Unnamed: 0", axis=1)
df.head() df.head()
``` ```
%% Output %% Output
Income Limit Rating Cards Age Education Gender Student Married \ Income Limit Rating Cards Age Education Gender Student Married \
0 14.891 3606 283 2 34 11 Male No Yes 0 14.891 3606 283 2 34 11 Male No Yes
1 106.025 6645 483 3 82 15 Female Yes Yes 1 106.025 6645 483 3 82 15 Female Yes Yes
2 104.593 7075 514 4 71 11 Male No No 2 104.593 7075 514 4 71 11 Male No No
3 148.924 9504 681 3 36 11 Female No No 3 148.924 9504 681 3 36 11 Female No No
4 55.882 4897 357 2 68 16 Male No Yes 4 55.882 4897 357 2 68 16 Male No Yes
Ethnicity Balance Ethnicity Balance
0 Caucasian 333 0 Caucasian 333
1 Asian 903 1 Asian 903
2 Asian 580 2 Asian 580
3 Asian 964 3 Asian 964
4 Caucasian 331 4 Caucasian 331
%% Cell type:code id:a70773ad-dc41-48a7-b18b-828c2d801be7 tags: %% Cell type:code id:a70773ad-dc41-48a7-b18b-828c2d801be7 tags:
``` python ``` python
df.columns df.columns
``` ```
%% Output %% Output
Index(['Income', 'Limit', 'Rating', 'Cards', 'Age', 'Education', 'Gender', Index(['Income', 'Limit', 'Rating', 'Cards', 'Age', 'Education', 'Gender',
'Student', 'Married', 'Ethnicity', 'Balance'], 'Student', 'Married', 'Ethnicity', 'Balance'],
dtype='object') dtype='object')
%% Cell type:code id:f604343b-4bcf-484b-9156-270e05c1fe7c tags: %% Cell type:code id:f604343b-4bcf-484b-9156-270e05c1fe7c tags:
``` python ``` python
import bambi as bmb import bambi as bmb
model_g = bmb.Model("Balance ~ Gender", df) model_g = bmb.Model("Balance ~ Gender", df)
idata_g = model_g.fit(random_seed=123) idata_g = model_g.fit(random_seed=123)
az.summary(idata_g) az.summary(idata_g)
``` ```
%% Output %% Output
Auto-assigning NUTS sampler... Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag... Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (4 chains in 4 jobs) Multiprocess sampling (4 chains in 4 jobs)
NUTS: [sigma, Intercept, Gender] NUTS: [sigma, Intercept, Gender]
Sampling 4 chains for 1_000 tune and 1_000 draw iterations (4_000 + 4_000 draws total) took 7 seconds. Sampling 4 chains for 1_000 tune and 1_000 draw iterations (4_000 + 4_000 draws total) took 7 seconds.
mean sd hdi_3% hdi_97% mcse_mean mcse_sd \ mean sd hdi_3% hdi_97% mcse_mean mcse_sd \
Gender[Female] 20.608 45.075 -60.900 108.348 0.557 0.640 Gender[Female] 20.608 45.075 -60.900 108.348 0.557 0.640
Intercept 509.429 33.143 442.139 568.286 0.405 0.288 Intercept 509.429 33.143 442.139 568.286 0.405 0.288
sigma 461.390 16.270 430.935 490.453 0.206 0.146 sigma 461.390 16.270 430.935 490.453 0.206 0.146
ess_bulk ess_tail r_hat ess_bulk ess_tail r_hat
Gender[Female] 6585.0 3183.0 1.0 Gender[Female] 6585.0 3183.0 1.0
Intercept 6723.0 2600.0 1.0 Intercept 6723.0 2600.0 1.0
sigma 6341.0 3246.0 1.0 sigma 6341.0 3246.0 1.0
%% Cell type:markdown id:5a0d7455-0d35-446f-ae95-230cde8a24e1 tags: %% Cell type:markdown id:5a0d7455-0d35-446f-ae95-230cde8a24e1 tags:
Es gibt keine spezielle Syntax in `Bambi`, um kategorische Variablen zu definieren. `Bambi` erkennt diese automatisch. Es gibt keine spezielle Syntax in `Bambi`, um kategorische Variablen zu definieren. `Bambi` erkennt diese automatisch.
%% Cell type:code id:137ad98a-a638-475e-bded-eb33e7356503 tags:
``` python
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment