mastergopote44
commited on
Commit
•
71f5686
1
Parent(s):
ee8bf6e
My commit
Browse files
Long-Term-Care-Aggregated-Data.py
CHANGED
@@ -54,71 +54,72 @@ _URLS = {
|
|
54 |
class LongTermCareAggregatedData(datasets.GeneratorBasedBuilder):
|
55 |
"""Dataset for insurance 'incidence' and 'termination' data."""
|
56 |
|
57 |
-
|
58 |
-
|
|
|
|
|
59 |
|
60 |
-
# This function should return the dataset info
|
61 |
def _info(self):
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
"
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
"
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
|
123 |
def _split_generators(self, dl_manager):
|
124 |
# URLs of the raw CSV files on GitHub using the raw content feature
|
@@ -134,30 +135,37 @@ class LongTermCareAggregatedData(datasets.GeneratorBasedBuilder):
|
|
134 |
|
135 |
return [
|
136 |
datasets.SplitGenerator(
|
137 |
-
name=
|
138 |
-
gen_kwargs={
|
|
|
|
|
|
|
139 |
),
|
140 |
datasets.SplitGenerator(
|
141 |
-
name=
|
142 |
-
gen_kwargs={
|
|
|
|
|
|
|
143 |
),
|
144 |
datasets.SplitGenerator(
|
145 |
-
name=
|
146 |
-
gen_kwargs={
|
|
|
|
|
|
|
147 |
),
|
148 |
datasets.SplitGenerator(
|
149 |
-
name=
|
150 |
-
gen_kwargs={
|
|
|
|
|
|
|
151 |
),
|
152 |
]
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
dataframe = pd.read_csv(filepath)
|
157 |
-
|
158 |
-
# Determine the type of data we're generating examples for
|
159 |
-
feature_columns = []
|
160 |
-
if 'incidence' in split:
|
161 |
feature_columns = [
|
162 |
"Group_Indicator", "Gender", "Issue_Age_Bucket", "Incurred_Age_Bucket",
|
163 |
"Issue_Year_Bucket", "Policy_Year", "Marital_Status", "Premium_Class",
|
@@ -176,6 +184,5 @@ class LongTermCareAggregatedData(datasets.GeneratorBasedBuilder):
|
|
176 |
]
|
177 |
|
178 |
for idx, row in dataframe.iterrows():
|
179 |
-
# Generate the feature dictionary dynamically based on the columns
|
180 |
feature_dict = {column: row[column] for column in feature_columns}
|
181 |
yield idx, feature_dict
|
|
|
54 |
class LongTermCareAggregatedData(datasets.GeneratorBasedBuilder):
|
55 |
"""Dataset for insurance 'incidence' and 'termination' data."""
|
56 |
|
57 |
+
BUILDER_CONFIGS = [
|
58 |
+
datasets.BuilderConfig(name="incidence", version=datasets.Version("1.0.0"), description="This part of the dataset includes incidence features"),
|
59 |
+
datasets.BuilderConfig(name="termination", version=datasets.Version("1.0.0"), description="This part of the dataset includes termination features"),
|
60 |
+
]
|
61 |
|
|
|
62 |
def _info(self):
|
63 |
+
if self.config.name == "incidence":
|
64 |
+
features = datasets.Features({
|
65 |
+
"Group_Indicator": datasets.Value("string"),
|
66 |
+
"Gender": datasets.Value("string"),
|
67 |
+
"Issue_Age_Bucket": datasets.Value("string"),
|
68 |
+
"Incurred_Age_Bucket": datasets.Value("string"),
|
69 |
+
"Issue_Year_Bucket": datasets.Value("string"),
|
70 |
+
"Policy_Year": datasets.Value("string"),
|
71 |
+
"Marital_Status": datasets.Value("string"),
|
72 |
+
"Premium_Class": datasets.Value("string"),
|
73 |
+
"Underwriting_Type": datasets.Value("string"),
|
74 |
+
"Coverage_Type_Bucket": datasets.Value("string"),
|
75 |
+
"Tax_Qualification_Status": datasets.Value("string"),
|
76 |
+
"Inflation_Rider": datasets.Value("string"),
|
77 |
+
"Rate_Increase_Flag": datasets.Value("string"),
|
78 |
+
"Restoration_of_Benefits": datasets.Value("string"),
|
79 |
+
"NH_Orig_Daily_Ben_Bucket": datasets.Value("string"),
|
80 |
+
"ALF_Orig_Daily_Ben_Bucket": datasets.Value("string"),
|
81 |
+
"HHC_Orig_Daily_Ben_Bucket": datasets.Value("string"),
|
82 |
+
"NH_Ben_Period_Bucket": datasets.Value("string"),
|
83 |
+
"ALF_Ben_Period_Bucket": datasets.Value("string"),
|
84 |
+
"HHC_Ben_Period_Bucket": datasets.Value("string"),
|
85 |
+
"NH_EP_Bucket": datasets.Value("string"),
|
86 |
+
"ALF_EP_Bucket": datasets.Value("string"),
|
87 |
+
"HHC_EP_Bucket": datasets.Value("string"),
|
88 |
+
"Region": datasets.Value("string"),
|
89 |
+
"Active_Exposure": datasets.Value("float64"),
|
90 |
+
"Total_Exposure": datasets.Value("float64"),
|
91 |
+
"Claim_Count": datasets.Value("int32"),
|
92 |
+
"Count_NH": datasets.Value("int32"),
|
93 |
+
"Count_ALF": datasets.Value("int32"),
|
94 |
+
"Count_HHC": datasets.Value("int32"),
|
95 |
+
"Count_Unk": datasets.Value("int32"),
|
96 |
+
})
|
97 |
+
elif self.config.name == "termination":
|
98 |
+
features = datasets.Features({
|
99 |
+
"Gender": datasets.Value("string"),
|
100 |
+
"Incurred_Age_Bucket": datasets.Value("string"),
|
101 |
+
"Incurred_Year_Bucket": datasets.Value("string"),
|
102 |
+
"Claim_Type": datasets.Value("string"),
|
103 |
+
"Region": datasets.Value("string"),
|
104 |
+
"Diagnosis_Category": datasets.Value("string"),
|
105 |
+
"Claim_Duration": datasets.Value("int64"),
|
106 |
+
"Exposure": datasets.Value("int64"),
|
107 |
+
"Deaths": datasets.Value("int64"),
|
108 |
+
"Recovery": datasets.Value("int64"),
|
109 |
+
"Terminations": datasets.Value("int64"),
|
110 |
+
"Benefit_Expiry": datasets.Value("int64"),
|
111 |
+
"Others_Terminations": datasets.Value("int64"),
|
112 |
+
})
|
113 |
+
else:
|
114 |
+
raise ValueError(f"BuilderConfig name not recognized: {self.config.name}")
|
115 |
+
|
116 |
+
return datasets.DatasetInfo(
|
117 |
+
description=_DESCRIPTION,
|
118 |
+
features=features,
|
119 |
+
supervised_keys=None,
|
120 |
+
homepage="https://www.soa.org/resources/experience-studies/2020/2000-2016-ltc-aggregate-database/",
|
121 |
+
citation="Please cite this dataset as: Society of Actuaries (SOA). (2020). Long Term Care Insurance Aggregate Experience Data, 2000-2016."
|
122 |
+
)
|
123 |
|
124 |
def _split_generators(self, dl_manager):
|
125 |
# URLs of the raw CSV files on GitHub using the raw content feature
|
|
|
135 |
|
136 |
return [
|
137 |
datasets.SplitGenerator(
|
138 |
+
name="train_incidence",
|
139 |
+
gen_kwargs={
|
140 |
+
"filepath": downloaded_files["train_incidence"],
|
141 |
+
"split": "incidence"
|
142 |
+
},
|
143 |
),
|
144 |
datasets.SplitGenerator(
|
145 |
+
name="validation_incidence",
|
146 |
+
gen_kwargs={
|
147 |
+
"filepath": downloaded_files["validation_incidence"],
|
148 |
+
"split": "incidence"
|
149 |
+
},
|
150 |
),
|
151 |
datasets.SplitGenerator(
|
152 |
+
name="train_termination",
|
153 |
+
gen_kwargs={
|
154 |
+
"filepath": downloaded_files["train_termination"],
|
155 |
+
"split": "termination"
|
156 |
+
},
|
157 |
),
|
158 |
datasets.SplitGenerator(
|
159 |
+
name="validation_termination",
|
160 |
+
gen_kwargs={
|
161 |
+
"filepath": downloaded_files["validation_termination"],
|
162 |
+
"split": "termination"
|
163 |
+
},
|
164 |
),
|
165 |
]
|
166 |
+
def _generate_examples(self, incidence_filepath, termination_filepath, split):
|
167 |
+
if self.config.name == "incidence":
|
168 |
+
dataframe = pd.read_csv(incidence_filepath)
|
|
|
|
|
|
|
|
|
|
|
169 |
feature_columns = [
|
170 |
"Group_Indicator", "Gender", "Issue_Age_Bucket", "Incurred_Age_Bucket",
|
171 |
"Issue_Year_Bucket", "Policy_Year", "Marital_Status", "Premium_Class",
|
|
|
184 |
]
|
185 |
|
186 |
for idx, row in dataframe.iterrows():
|
|
|
187 |
feature_dict = {column: row[column] for column in feature_columns}
|
188 |
yield idx, feature_dict
|