mastergopote44 commited on
Commit
71f5686
1 Parent(s): ee8bf6e
Files changed (1) hide show
  1. Long-Term-Care-Aggregated-Data.py +87 -80
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
- # You can add VERSION here if needed, e.g.:
58
- # VERSION = datasets.Version("1.0.0")
 
 
59
 
60
- # This function should return the dataset info
61
  def _info(self):
62
- return datasets.DatasetInfo(
63
- description="This dataset includes insurance data for 'incidence' and 'termination' categories, "
64
- "derived from the Long Term Care insurance policies data provided by the Society of Actuaries. "
65
- "It contains various features like gender, age bucket, policy year, and claim count, among others.",
66
- features=datasets.Features(
67
- {
68
- "incidence_features": datasets.Features({
69
- "Group_Indicator": datasets.Value("string"),
70
- "Gender": datasets.Value("string"),
71
- "Issue_Age_Bucket": datasets.Value("string"),
72
- "Incurred_Age_Bucket": datasets.Value("string"),
73
- "Issue_Year_Bucket": datasets.Value("string"),
74
- "Policy_Year": datasets.Value("string"),
75
- "Marital_Status": datasets.Value("string"),
76
- "Premium_Class": datasets.Value("string"),
77
- "Underwriting_Type": datasets.Value("string"),
78
- "Coverage_Type_Bucket": datasets.Value("string"),
79
- "Tax_Qualification_Status": datasets.Value("string"),
80
- "Inflation_Rider": datasets.Value("string"),
81
- "Rate_Increase_Flag": datasets.Value("string"),
82
- "Restoration_of_Benefits": datasets.Value("string"),
83
- "NH_Orig_Daily_Ben_Bucket": datasets.Value("string"),
84
- "ALF_Orig_Daily_Ben_Bucket": datasets.Value("string"),
85
- "HHC_Orig_Daily_Ben_Bucket": datasets.Value("string"),
86
- "NH_Ben_Period_Bucket": datasets.Value("string"),
87
- "ALF_Ben_Period_Bucket": datasets.Value("string"),
88
- "HHC_Ben_Period_Bucket": datasets.Value("string"),
89
- "NH_EP_Bucket": datasets.Value("string"),
90
- "ALF_EP_Bucket": datasets.Value("string"),
91
- "HHC_EP_Bucket": datasets.Value("string"),
92
- "Region": datasets.Value("string"),
93
- "Active_Exposure": datasets.Value("float64"),
94
- "Total_Exposure": datasets.Value("float64"),
95
- "Claim_Count": datasets.Value("int32"),
96
- "Count_NH": datasets.Value("int32"),
97
- "Count_ALF": datasets.Value("int32"),
98
- "Count_HHC": datasets.Value("int32"),
99
- "Count_Unk": datasets.Value("int32"),
100
- }),
101
- "termination_features": datasets.Features({
102
- "Gender": datasets.Value("string"),
103
- "Incurred_Age_Bucket": datasets.Value("string"),
104
- "Incurred_Year_Bucket": datasets.Value("string"),
105
- "Claim_Type": datasets.Value("string"),
106
- "Region": datasets.Value("string"),
107
- "Diagnosis_Category": datasets.Value("string"),
108
- "Claim_Duration": datasets.Value("int64"),
109
- "Exposure": datasets.Value("int64"),
110
- "Deaths": datasets.Value("int64"),
111
- "Recovery": datasets.Value("int64"),
112
- "Terminations": datasets.Value("int64"),
113
- "Benefit_Expiry": datasets.Value("int64"),
114
- "Others_Terminations": datasets.Value("int64"),
115
- }),
116
- }
117
- ),
118
- supervised_keys=None,
119
- homepage="https://www.soa.org/resources/experience-studies/2020/2000-2016-ltc-aggregate-database/",
120
- citation="Please cite this dataset as: Society of Actuaries (SOA). (2020). Long Term Care Insurance Aggregate Experience Data, 2000-2016."
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=datasets.Split.TRAIN,
138
- gen_kwargs={"filepath": downloaded_files["train_incidence"], "split": "train_incidence"}
 
 
 
139
  ),
140
  datasets.SplitGenerator(
141
- name=datasets.Split.VALIDATION,
142
- gen_kwargs={"filepath": downloaded_files["validation_incidence"], "split": "validation_incidence"}
 
 
 
143
  ),
144
  datasets.SplitGenerator(
145
- name=datasets.Split.TRAIN,
146
- gen_kwargs={"filepath": downloaded_files["train_termination"], "split": "train_termination"}
 
 
 
147
  ),
148
  datasets.SplitGenerator(
149
- name=datasets.Split.VALIDATION,
150
- gen_kwargs={"filepath": downloaded_files["validation_termination"], "split": "validation_termination"}
 
 
 
151
  ),
152
  ]
153
-
154
- def _generate_examples(self, filepath, split):
155
- # Read the CSV file for the given split
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