Dataset Viewer
Auto-converted to Parquet
Search is not available for this dataset
Year
class label
3 classes
MemberID
int64
4
100M
LabCount_total
int64
1
111
LabCount_months
int64
1
12
DrugCount_total
int64
1
84
DrugCount_months
int64
1
12
no_Claims
int64
0
44
no_Providers
int64
0
30
no_Vendors
int64
0
21
no_PCPs
int64
0
4
max_CharlsonIndex
int64
0
3
PayDelay_total
int64
0
6.2k
PayDelay_max
int64
0
162
PayDelay_min
int64
0
162
AgeAtFirstClaim
class label
10 classes
Sex
class label
3 classes
1Y2
4
null
null
null
null
1
1
1
1
0
43
43
43
00-9
2M
0Y1
210
2
1
5
3
8
4
4
2
0
720
162
22
330-39
0?
1Y2
210
1
1
null
null
6
3
3
1
0
308
128
31
330-39
0?
2Y3
210
1
1
5
4
4
2
2
1
0
143
44
23
330-39
0?
0Y1
3,197
null
null
5
4
5
3
3
1
0
492
162
36
00-9
1F
1Y2
3,197
2
1
3
2
5
4
3
1
0
148
34
26
00-9
1F
2Y3
3,197
null
null
6
5
11
3
1
1
1
379
119
21
00-9
1F
1Y2
3,457
null
null
null
null
1
1
1
1
0
63
63
63
00-9
2M
1Y2
3,713
9
2
17
4
10
5
5
2
0
562
118
23
440-49
1F
1Y2
3,741
11
5
35
11
20
3
3
1
1
360
36
8
770-79
1F
0Y1
3,889
10
1
30
10
13
7
7
1
1
919
162
33
9?
1F
2Y3
4,048
16
2
1
1
21
10
9
1
1
675
80
0
550-59
2M
0Y1
4,187
null
null
61
10
4
3
3
1
0
340
162
29
550-59
1F
1Y2
5,187
null
null
null
null
2
1
1
1
0
65
42
23
00-9
2M
2Y3
5,187
1
1
10
6
13
4
3
1
1
563
100
16
00-9
2M
1Y2
8,213
4
1
null
null
3
2
2
1
0
144
62
41
110-19
2M
0Y1
9,063
null
null
2
2
4
2
2
1
0
241
68
39
660-69
1F
1Y2
10,242
7
2
3
3
14
4
4
2
1
630
106
21
220-29
1F
0Y1
11,951
3
1
null
null
6
3
3
1
0
250
54
32
110-19
1F
1Y2
11,951
3
1
null
null
11
8
8
1
0
608
162
8
110-19
1F
1Y2
14,033
1
1
3
2
4
1
1
1
0
101
26
23
110-19
1F
2Y3
14,033
2
1
2
1
8
7
7
1
0
330
68
26
110-19
1F
2Y3
14,552
1
1
null
null
8
6
5
1
0
178
37
0
110-19
2M
0Y1
14,661
2
1
1
1
2
2
2
1
0
153
115
38
00-9
0?
1Y2
14,661
5
3
null
null
12
4
4
1
0
637
89
19
00-9
0?
2Y3
14,661
null
null
2
2
3
1
1
1
0
0
0
0
00-9
0?
0Y1
14,701
null
null
null
null
3
2
2
1
0
298
162
64
330-39
2M
0Y1
14,778
2
1
6
5
6
5
4
2
0
523
162
31
330-39
1F
1Y2
14,778
1
1
13
11
8
6
5
2
0
320
83
22
330-39
1F
2Y3
14,778
8
3
8
6
8
2
2
1
0
293
62
24
330-39
1F
0Y1
14,855
null
null
null
null
1
1
1
1
0
38
38
38
330-39
1F
2Y3
14,855
1
1
null
null
2
2
2
1
0
37
20
17
330-39
1F
0Y1
17,249
2
1
null
null
4
1
1
1
0
88
22
22
110-19
1F
1Y2
17,249
null
null
null
null
2
1
1
1
0
82
41
41
110-19
1F
2Y3
17,249
6
1
null
null
4
3
3
1
0
112
35
23
110-19
1F
0Y1
18,190
6
2
15
8
8
4
5
1
1
634
162
15
880+
1F
1Y2
18,190
6
1
58
12
18
12
9
1
1
925
125
10
880+
1F
2Y3
18,190
16
2
66
12
24
8
8
1
1
1,059
132
0
880+
1F
0Y1
18,333
6
2
10
7
10
2
2
1
1
338
55
23
880+
2M
1Y2
18,333
6
1
6
3
10
5
5
1
1
367
139
10
880+
2M
0Y1
18,514
5
1
null
null
4
2
2
1
0
149
58
27
550-59
1F
2Y3
18,514
5
1
null
null
4
2
2
1
0
123
78
15
550-59
1F
0Y1
20,072
1
1
13
7
14
6
6
1
0
772
162
14
9?
0?
1Y2
20,072
8
2
19
9
41
12
8
1
1
2,589
162
13
9?
0?
2Y3
20,072
1
1
24
9
22
8
6
1
1
758
66
0
9?
0?
0Y1
20,269
4
1
null
null
7
3
3
1
0
1,134
162
162
00-9
0?
0Y1
20,482
17
10
null
null
36
4
4
1
0
1,303
162
21
440-49
1F
1Y2
20,482
11
9
null
null
21
3
3
1
0
452
42
14
440-49
1F
2Y3
20,482
15
12
null
null
44
1
1
1
0
693
30
0
440-49
1F
2Y3
20,605
3
1
null
null
4
3
3
1
0
42
26
0
330-39
0?
0Y1
21,207
16
2
27
6
30
10
8
1
1
1,806
162
16
880+
1F
1Y2
21,207
4
3
71
12
16
8
6
1
1
900
123
16
880+
1F
2Y3
21,549
null
null
3
1
10
4
4
1
0
387
67
0
330-39
2M
0Y1
23,328
4
2
null
null
7
4
3
1
0
585
127
41
440-49
1F
2Y3
23,328
null
null
null
null
5
3
2
1
0
119
28
21
440-49
1F
1Y2
25,756
null
null
5
1
2
1
1
1
0
99
53
46
220-29
0?
2Y3
25,756
null
null
7
3
5
1
1
1
0
256
95
23
220-29
0?
0Y1
26,116
null
null
null
null
1
1
1
1
0
53
53
53
00-9
1F
1Y2
26,116
2
1
1
1
5
2
2
1
0
254
128
24
00-9
1F
2Y3
26,116
null
null
5
3
3
1
1
1
0
80
38
14
00-9
1F
2Y3
27,130
9
2
null
null
7
4
4
1
0
32
32
0
220-29
1F
0Y1
27,686
4
1
null
null
3
2
2
1
0
85
29
28
770-79
1F
1Y2
27,686
7
2
4
3
14
4
2
1
0
434
71
20
770-79
1F
2Y3
27,686
18
2
1
1
15
4
3
1
0
358
42
16
770-79
1F
0Y1
28,243
6
1
2
1
6
5
5
1
0
422
162
36
220-29
0?
1Y2
28,243
6
1
5
2
7
5
5
1
0
302
65
22
220-29
0?
2Y3
28,243
null
null
null
null
5
5
4
1
0
174
56
23
220-29
0?
1Y2
29,477
5
2
5
4
10
5
2
1
0
218
55
8
220-29
0?
2Y3
29,477
null
null
2
1
3
2
2
1
0
84
33
25
220-29
0?
2Y3
32,317
null
null
9
3
44
2
2
1
1
638
50
0
770-79
1F
0Y1
32,491
9
1
17
7
34
13
7
1
0
1,894
162
27
880+
0?
1Y2
32,491
18
5
33
12
41
11
8
1
2
1,282
78
13
880+
0?
2Y3
32,491
22
5
47
11
44
15
6
1
1
1,006
43
0
880+
0?
0Y1
33,120
11
3
18
6
9
5
5
1
0
475
122
24
9?
0?
1Y2
33,120
7
2
18
6
39
16
14
1
1
2,738
162
22
9?
0?
0Y1
33,803
null
null
5
2
6
3
3
1
0
236
68
20
110-19
2M
2Y3
33,803
null
null
null
null
1
1
1
1
0
37
37
37
110-19
2M
0Y1
34,208
10
1
9
6
3
2
2
1
1
115
93
11
330-39
1F
1Y2
34,208
null
null
7
4
5
4
4
1
1
155
72
7
330-39
1F
2Y3
34,208
4
2
9
4
12
8
8
1
1
447
78
18
330-39
1F
0Y1
34,791
3
1
19
9
10
5
4
2
0
518
162
28
770-79
1F
2Y3
36,126
null
null
null
null
2
1
1
1
0
36
36
0
440-49
1F
0Y1
36,908
3
1
null
null
4
3
3
1
0
213
70
31
110-19
2M
2Y3
36,908
null
null
null
null
1
1
1
1
0
35
35
35
110-19
2M
0Y1
39,767
null
null
null
null
1
1
1
1
0
91
91
91
110-19
1F
1Y2
39,767
null
null
1
1
3
2
2
1
0
212
99
36
110-19
1F
2Y3
40,000
null
null
null
null
4
2
2
1
1
84
84
0
110-19
2M
2Y3
40,717
2
1
2
1
6
4
4
1
1
184
41
15
550-59
1F
0Y1
42,216
9
2
19
5
21
8
5
1
0
2,228
162
12
660-69
0?
1Y2
42,395
null
null
null
null
6
3
2
1
1
144
35
16
330-39
0?
2Y3
42,395
18
3
null
null
44
15
11
1
1
1,533
162
0
330-39
0?
1Y2
42,758
26
4
null
null
43
15
13
1
2
3,253
162
21
660-69
2M
2Y3
42,758
null
null
null
null
44
10
10
1
1
4,320
162
0
660-69
2M
0Y1
43,452
4
2
null
null
6
3
3
1
0
251
87
30
330-39
1F
0Y1
43,467
null
null
null
null
1
1
1
1
0
43
43
43
440-49
2M
2Y3
47,061
23
5
13
9
33
10
10
1
0
1,541
146
15
770-79
2M
0Y1
47,103
9
1
7
6
8
4
4
1
1
686
162
30
770-79
0?
1Y2
47,103
13
2
37
10
40
19
15
1
1
2,389
162
15
770-79
0?
2Y3
47,103
7
1
8
4
15
7
5
1
0
494
86
20
770-79
0?
1Y2
47,211
16
2
null
null
14
6
6
1
0
1,292
162
23
550-59
1F
End of preview. Expand in Data Studio

Dataset Card for Heritage Health Prize

It is often believed that this piece of data can be found at here and here, although we have not yet figured out what this piece of data is really used for.

To save time, we directly follow the preprocessing script here. More specifically, we used the following script to produce this Hugging Face dataset.

"""
Preprocessing based on: https://github.com/truongkhanhduy95/Heritage-Health-Prize
"""
import zipfile
from os import path
from urllib import request

import numpy as np
import pandas as pd


column_names = ['MemberID', 'ProviderID', 'Sex', 'AgeAtFirstClaim']
claims_cat_names = ['PrimaryConditionGroup', 'Specialty', 'ProcedureGroup', 'PlaceSvc']


def preprocess_claims(df_claims):
    df_claims.loc[df_claims['PayDelay'] == '162+', 'PayDelay'] = 162
    df_claims['PayDelay'] = df_claims['PayDelay'].astype(int)

    df_claims.loc[df_claims['DSFS'] == '0- 1 month', 'DSFS'] = 1
    df_claims.loc[df_claims['DSFS'] == '1- 2 months', 'DSFS'] = 2
    df_claims.loc[df_claims['DSFS'] == '2- 3 months', 'DSFS'] = 3
    df_claims.loc[df_claims['DSFS'] == '3- 4 months', 'DSFS'] = 4
    df_claims.loc[df_claims['DSFS'] == '4- 5 months', 'DSFS'] = 5
    df_claims.loc[df_claims['DSFS'] == '5- 6 months', 'DSFS'] = 6
    df_claims.loc[df_claims['DSFS'] == '6- 7 months', 'DSFS'] = 7
    df_claims.loc[df_claims['DSFS'] == '7- 8 months', 'DSFS'] = 8
    df_claims.loc[df_claims['DSFS'] == '8- 9 months', 'DSFS'] = 9
    df_claims.loc[df_claims['DSFS'] == '9-10 months', 'DSFS'] = 10
    df_claims.loc[df_claims['DSFS'] == '10-11 months', 'DSFS'] = 11
    df_claims.loc[df_claims['DSFS'] == '11-12 months', 'DSFS'] = 12

    df_claims.loc[df_claims['CharlsonIndex'] == '0', 'CharlsonIndex'] = 0
    df_claims.loc[df_claims['CharlsonIndex'] == '1-2', 'CharlsonIndex'] = 1
    df_claims.loc[df_claims['CharlsonIndex'] == '3-4', 'CharlsonIndex'] = 2
    df_claims.loc[df_claims['CharlsonIndex'] == '5+', 'CharlsonIndex'] = 3

    df_claims.loc[df_claims['LengthOfStay'] == '1 day', 'LengthOfStay'] = 1
    df_claims.loc[df_claims['LengthOfStay'] == '2 days', 'LengthOfStay'] = 2
    df_claims.loc[df_claims['LengthOfStay'] == '3 days', 'LengthOfStay'] = 3
    df_claims.loc[df_claims['LengthOfStay'] == '4 days', 'LengthOfStay'] = 4
    df_claims.loc[df_claims['LengthOfStay'] == '5 days', 'LengthOfStay'] = 5
    df_claims.loc[df_claims['LengthOfStay'] == '6 days', 'LengthOfStay'] = 6
    df_claims.loc[df_claims['LengthOfStay'] == '1- 2 weeks', 'LengthOfStay'] = 11
    df_claims.loc[df_claims['LengthOfStay'] == '2- 4 weeks', 'LengthOfStay'] = 21
    df_claims.loc[df_claims['LengthOfStay'] == '4- 8 weeks', 'LengthOfStay'] = 42
    df_claims.loc[df_claims['LengthOfStay'] == '26+ weeks', 'LengthOfStay'] = 180
    df_claims['LengthOfStay'].fillna('?', inplace=True)
    # df_claims['LengthOfStay'] = df_claims['LengthOfStay'].astype(int)

    for cat_name in claims_cat_names:
        df_claims[cat_name].fillna('?', inplace=True)
    # df_claims = pd.get_dummies(df_claims, columns=claims_cat_names, prefix_sep='=')

    oh = [col for col in df_claims if '=' in col]

    agg = {
        'ProviderID': ['count', 'nunique'],
        'Vendor': 'nunique',
        'PCP': 'nunique',
        'CharlsonIndex': 'max',
        # 'PlaceSvc': 'nunique',
        # 'Specialty': 'nunique',
        # 'PrimaryConditionGroup': 'nunique',
        # 'ProcedureGroup': 'nunique',
        'PayDelay': ['sum', 'max', 'min']
    }
    for col in oh:
        agg[col] = 'sum'

    df_group = df_claims.groupby(['Year', 'MemberID'])
    df_claims = df_group.agg(agg).reset_index()
    df_claims.columns = [
                            'Year', 'MemberID', 'no_Claims', 'no_Providers', 'no_Vendors', 'no_PCPs',
                            'max_CharlsonIndex', 'PayDelay_total', 'PayDelay_max', 'PayDelay_min'
                        ] + oh

    return df_claims

def preprocess_drugs(df_drugs):
    df_drugs.drop(columns=['DSFS'], inplace=True)
    # df_drugs['DSFS'] = df_drugs['DSFS'].apply(lambda x: int(x.split('-')[0])+1)
    df_drugs['DrugCount'] = df_drugs['DrugCount'].apply(lambda x: int(x.replace('+', '')))
    df_drugs = df_drugs.groupby(['Year', 'MemberID']).agg({'DrugCount': ['sum', 'count']}).reset_index()
    df_drugs.columns = ['Year', 'MemberID', 'DrugCount_total', 'DrugCount_months']
    print('df_drugs.shape = ', df_drugs.shape)
    return df_drugs

def preprocess_labs(df_labs):
    df_labs.drop(columns=['DSFS'], inplace=True)
    # df_labs['DSFS'] = df_labs['DSFS'].apply(lambda x: int(x.split('-')[0])+1)
    df_labs['LabCount'] = df_labs['LabCount'].apply(lambda x: int(x.replace('+', '')))
    df_labs = df_labs.groupby(['Year', 'MemberID']).agg({'LabCount': ['sum', 'count']}).reset_index()
    df_labs.columns = ['Year', 'MemberID', 'LabCount_total', 'LabCount_months']
    print('df_labs.shape = ', df_labs.shape)
    return df_labs

def preprocess_members(df_members):
    df_members['AgeAtFirstClaim'].fillna('?', inplace=True)
    df_members['Sex'].fillna('?', inplace=True)
    # df_members = pd.get_dummies(
    #     df_members, columns=['AgeAtFirstClaim', 'Sex'], prefix_sep='='
    # )
    print('df_members.shape = ', df_members.shape)
    return df_members

# request.urlretrieve('https://foreverdata.org/1015/content/HHP_release3.zip', 'HHP_release3.zip')

zf = zipfile.ZipFile('HHP_release3.zip')

df_claims = preprocess_claims(pd.read_csv(zf.open('Claims.csv'), sep=','))
df_drugs = preprocess_drugs(pd.read_csv(zf.open('DrugCount.csv'), sep=','))
df_labs = preprocess_labs(pd.read_csv(zf.open('LabCount.csv'), sep=','))
df_members = preprocess_members(pd.read_csv(zf.open('Members.csv'), sep=','))

df_labs_drugs = pd.merge(df_labs, df_drugs, on=['MemberID', 'Year'], how='outer')
df_labs_drugs_claims = pd.merge(df_labs_drugs, df_claims, on=['MemberID', 'Year'], how='outer')
df_health = pd.merge(df_labs_drugs_claims, df_members, on=['MemberID'], how='outer')

# df_health.drop(['Year', 'MemberID'], axis=1, inplace=True)
# df_health.fillna(0, inplace=True)


# Convert continuous columns to float
continuous_columns = ["MemberID", "LabCount_total", 'LabCount_months',
 'DrugCount_total',
 'DrugCount_months',
 'no_Claims',
 'no_Providers',
 'no_Vendors',
 'no_PCPs',
 'max_CharlsonIndex',
 'PayDelay_total',
 'PayDelay_max',
 'PayDelay_min']

for col in continuous_columns:
    df_health[col] = pd.to_numeric(df_health[col], errors='coerce')


# Define categorical columns
categorical_columns = [
    'Year', 'AgeAtFirstClaim',
 'Sex'
]

# Dictionary to store category mappings
category_mappings = {}

for col in categorical_columns:
    # Convert train column to category and extract categories
    df_health[col] = df_health[col].astype("category")
    category_mappings[col] = df_health[col].cat.categories.to_list()  # Store category order

    # Convert to integer codes
    df_health[col] = df_health[col].cat.codes
    

from datasets import Dataset, DatasetDict, Features, Value, ClassLabel

# Define Hugging Face dataset schema
hf_features = Features({
    "Year": ClassLabel(names=category_mappings["Year"]),
    "AgeAtFirstClaim": ClassLabel(names=category_mappings["AgeAtFirstClaim"]),
    "Sex": ClassLabel(names=category_mappings["Sex"]),    
    **{col: Value("int64") for col in continuous_columns}
})

hf_features = Features({
    col: Value("int64") if col in continuous_columns else
         ClassLabel(names=category_mappings[col])
    for col in df_health.columns
})

from datasets import DatasetDict

# Store in a dataset dictionary
hf_dataset = DatasetDict({"train": Dataset.from_pandas(df_health, features=hf_features)})

# Print dataset structure
print(hf_dataset)

The printed output could look like

DatasetDict({
    train: Dataset({
        features: ['Year', 'MemberID', 'LabCount_total', 'LabCount_months', 'DrugCount_total', 'DrugCount_months', 'no_Claims', 'no_Providers', 'no_Vendors', 'no_PCPs', 'max_CharlsonIndex', 'PayDelay_total', 'PayDelay_max', 'PayDelay_min', 'AgeAtFirstClaim', 'Sex'],
        num_rows: 218415
    })
})

We may still update this dataset, once we figure out more.

Downloads last month
4