mastergopote44 commited on
Commit
616a5dc
1 Parent(s): b397095

Set my folder as the main source of truth

Browse files
Files changed (1) hide show
  1. Long-Term-Care-Aggregated-data.py +0 -179
Long-Term-Care-Aggregated-data.py DELETED
@@ -1,179 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- """Long-Term-Care-Aggregated-Data.ipynb
3
-
4
- Automatically generated by Colaboratory.
5
-
6
- Original file is located at
7
- https://colab.research.google.com/drive/14YdgB8b4TtNetbHpTstGH7W4DLa3Yyxq
8
- """
9
-
10
- from datasets import GeneratorBasedBuilder, DownloadManager, DatasetInfo, Array3D, BuilderConfig, SplitGenerator, Version
11
- from datasets.features import Features, Value, Sequence
12
- import datasets
13
- import pandas as pd
14
- import json
15
- import zipfile
16
- import numpy as np
17
- import io
18
- import csv
19
- import json
20
- import os
21
- from typing import List
22
- import datasets
23
- import logging
24
-
25
- _CITATION = """\
26
- @misc{long_term_care_aggregated_dataset,
27
- title = {Long-Term Care Aggregated Dataset},
28
- author = {Kao, Hsuan-Chen (Justin)},
29
- year = {2024},
30
- publisher = {Hugging Face},
31
- url = {https://github.com/justinkao44/STA663_Project_1},
32
- }
33
- """
34
-
35
- _DESCRIPTION = """\
36
- The Long-Term Care Aggregated Dataset is a collection of insurance data for 'incidence' and 'termination' categories.
37
- It is compiled from Long Term Care insurance policies data, providing insights into trends and patterns in insurance claims
38
- and terminations. This dataset can be used for actuarial analysis, risk assessment, and to inform insurance product development.
39
- """
40
-
41
- _HOMEPAGE = "https://github.com/justinkao44/STA663_Project_1"
42
-
43
- _LICENSE = "Apache-2.0"
44
-
45
- _URLS = {
46
- "train_incidence": "https://github.com/justinkao44/STA663_Project_1/raw/main/train_filtered_incidence_df.zip",
47
- "train_termination": "https://github.com/justinkao44/STA663_Project_1/raw/main/train_filtered_termination_df.zip",
48
- "validation_incidence": "https://github.com/justinkao44/STA663_Project_1/raw/main/validation_filtered_incidence_df.zip",
49
- "validation_termination": "https://github.com/justinkao44/STA663_Project_1/raw/main/validation_filtered_termination_df.zip",
50
- }
51
-
52
-
53
- class LongTermCareAggregatedData(datasets.GeneratorBasedBuilder):
54
- """Dataset for insurance 'incidence' and 'termination' data."""
55
-
56
- BUILDER_CONFIGS = [
57
- datasets.BuilderConfig(name="incidence", version=datasets.Version("1.0.0"), description="This part of the dataset includes incidence features"),
58
- datasets.BuilderConfig(name="termination", version=datasets.Version("1.0.0"), description="This part of the dataset includes termination features"),
59
- ]
60
-
61
- def _info(self):
62
- if self.config.name == "incidence":
63
- features = datasets.Features({
64
- "Group_Indicator": datasets.Value("string"),
65
- "Gender": datasets.Value("string"),
66
- "Issue_Age_Bucket": datasets.Value("string"),
67
- "Incurred_Age_Bucket": datasets.Value("string"),
68
- "Issue_Year_Bucket": datasets.Value("string"),
69
- "Policy_Year": datasets.Value("string"),
70
- "Marital_Status": datasets.Value("string"),
71
- "Premium_Class": datasets.Value("string"),
72
- "Underwriting_Type": datasets.Value("string"),
73
- "Coverage_Type_Bucket": datasets.Value("string"),
74
- "Tax_Qualification_Status": datasets.Value("string"),
75
- "Inflation_Rider": datasets.Value("string"),
76
- "Rate_Increase_Flag": datasets.Value("string"),
77
- "Restoration_of_Benefits": datasets.Value("string"),
78
- "NH_Orig_Daily_Ben_Bucket": datasets.Value("string"),
79
- "ALF_Orig_Daily_Ben_Bucket": datasets.Value("string"),
80
- "HHC_Orig_Daily_Ben_Bucket": datasets.Value("string"),
81
- "NH_Ben_Period_Bucket": datasets.Value("string"),
82
- "ALF_Ben_Period_Bucket": datasets.Value("string"),
83
- "HHC_Ben_Period_Bucket": datasets.Value("string"),
84
- "NH_EP_Bucket": datasets.Value("string"),
85
- "ALF_EP_Bucket": datasets.Value("string"),
86
- "HHC_EP_Bucket": datasets.Value("string"),
87
- "Region": datasets.Value("string"),
88
- "Active_Exposure": datasets.Value("float64"),
89
- "Total_Exposure": datasets.Value("float64"),
90
- "Claim_Count": datasets.Value("int32"),
91
- "Count_NH": datasets.Value("int32"),
92
- "Count_ALF": datasets.Value("int32"),
93
- "Count_HHC": datasets.Value("int32"),
94
- "Count_Unk": datasets.Value("int32"),
95
- })
96
- elif self.config.name == "termination":
97
- features = datasets.Features({
98
- "Gender": datasets.Value("string"),
99
- "Incurred_Age_Bucket": datasets.Value("string"),
100
- "Incurred_Year_Bucket": datasets.Value("string"),
101
- "Claim_Type": datasets.Value("string"),
102
- "Region": datasets.Value("string"),
103
- "Diagnosis_Category": datasets.Value("string"),
104
- "Claim_Duration": datasets.Value("string"),
105
- "Exposure": datasets.Value("string"),
106
- "Deaths": datasets.Value("string"),
107
- "Recovery": datasets.Value("string"),
108
- "Terminations": datasets.Value("string"),
109
- "Benefit_Expiry": datasets.Value("string"),
110
- "Others_Terminations": datasets.Value("string"),
111
- })
112
- else:
113
- raise ValueError(f"BuilderConfig name not recognized: {self.config.name}")
114
-
115
- return datasets.DatasetInfo(
116
- description=_DESCRIPTION,
117
- features=features,
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
-
124
- def _split_generators(self, dl_manager):
125
- downloaded_files = dl_manager.download(_URLS)
126
-
127
- train_file = downloaded_files[f"train_{self.config.name}"]
128
- validation_file = downloaded_files[f"validation_{self.config.name}"]
129
-
130
- return [
131
- datasets.SplitGenerator(
132
- name=datasets.Split.TRAIN,
133
- gen_kwargs={
134
- "data_file": train_file,
135
- "split": self.config.name,
136
- },
137
- ),
138
- datasets.SplitGenerator(
139
- name=datasets.Split.VALIDATION,
140
- gen_kwargs={
141
- "data_file": validation_file,
142
- "split": self.config.name,
143
- },
144
- ),
145
- ]
146
-
147
- def _generate_examples(self, data_file, split):
148
- with zipfile.ZipFile(data_file, 'r') as zip_ref:
149
- # Assume each zip contains only one CSV file
150
- csv_filename = zip_ref.namelist()[0]
151
- with zip_ref.open(csv_filename) as csv_file:
152
- dataframe = pd.read_csv(io.TextIOWrapper(csv_file))
153
-
154
- feature_columns = self._get_feature_columns_by_config()
155
-
156
- for idx, row in dataframe.iterrows():
157
- feature_dict = {column: row[column] for column in feature_columns if column in dataframe.columns}
158
- yield idx, feature_dict
159
-
160
- def _get_feature_columns_by_config(self):
161
- if self.config.name == "incidence":
162
- return [
163
- "Group_Indicator", "Gender", "Issue_Age_Bucket", "Incurred_Age_Bucket",
164
- "Issue_Year_Bucket", "Policy_Year", "Marital_Status", "Premium_Class",
165
- "Underwriting_Type", "Coverage_Type_Bucket", "Tax_Qualification_Status",
166
- "Inflation_Rider", "Rate_Increase_Flag", "Restoration_of_Benefits",
167
- "NH_Orig_Daily_Ben_Bucket", "ALF_Orig_Daily_Ben_Bucket", "HHC_Orig_Daily_Ben_Bucket",
168
- "NH_Ben_Period_Bucket", "ALF_Ben_Period_Bucket", "HHC_Ben_Period_Bucket",
169
- "NH_EP_Bucket", "ALF_EP_Bucket", "HHC_EP_Bucket", "Region",
170
- "Active_Exposure", "Total_Exposure", "Claim_Count", "Count_NH", "Count_ALF", "Count_HHC", "Count_Unk",
171
- ]
172
- elif self.config.name == "termination":
173
- return [
174
- "Gender", "Incurred_Age_Bucket", "Incurred_Year_Bucket", "Claim_Type",
175
- "Region", "Diagnosis_Category", "Claim_Duration", "Exposure", "Deaths",
176
- "Recovery", "Terminations", "Benefit_Expiry", "Others_Terminations",
177
- ]
178
- else:
179
- raise ValueError(f"Config name not recognized: {self.config.name}")