Datasets:
Upload 2 files
Browse files
heloc.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
heloc.py
ADDED
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Heloc Dataset"""
|
2 |
+
|
3 |
+
from typing import List
|
4 |
+
|
5 |
+
import datasets
|
6 |
+
|
7 |
+
import pandas
|
8 |
+
|
9 |
+
|
10 |
+
VERSION = datasets.Version("1.0.0")
|
11 |
+
_ORIGINAL_FEATURE_NAMES = [
|
12 |
+
"RiskPerformance",
|
13 |
+
"ExternalRiskEstimate",
|
14 |
+
"MSinceOldestTradeOpen",
|
15 |
+
"MSinceMostRecentTradeOpen",
|
16 |
+
"AverageMInFile",
|
17 |
+
"NumSatisfactoryTrades",
|
18 |
+
"NumTrades60Ever2DerogPubRec",
|
19 |
+
"NumTrades90Ever2DerogPubRec",
|
20 |
+
"PercentTradesNeverDelq",
|
21 |
+
"MSinceMostRecentDelq",
|
22 |
+
"MaxDelq2PublicRecLast12M",
|
23 |
+
"MaxDelqEver",
|
24 |
+
"NumTotalTrades",
|
25 |
+
"NumTradesOpeninLast12M",
|
26 |
+
"PercentInstallTrades",
|
27 |
+
"MSinceMostRecentInqexcl7days",
|
28 |
+
"NumInqLast6M",
|
29 |
+
"NumInqLast6Mexcl7days",
|
30 |
+
"NetFractionRevolvingBurden",
|
31 |
+
"NetFractionInstallBurden",
|
32 |
+
"NumRevolvingTradesWBalance",
|
33 |
+
"NumInstallTradesWBalance",
|
34 |
+
"NumBank2NatlTradesWHighUtilization",
|
35 |
+
"PercentTradesWBalance",
|
36 |
+
]
|
37 |
+
_BASE_FEATURE_NAMES = [
|
38 |
+
"is_at_risk",
|
39 |
+
"estimate_of_risk",
|
40 |
+
"months_since_first_trade",
|
41 |
+
"months_since_last_trade",
|
42 |
+
"average_duration_of_resolution",
|
43 |
+
"number_of_satisfactory_trades",
|
44 |
+
"nr_trades_insolvent_for_over_60_days",
|
45 |
+
"nr_trades_insolvent_for_over_90_days",
|
46 |
+
"percentage_of_legal_trades",
|
47 |
+
"months_since_last_illegal_trade",
|
48 |
+
"maximum_illegal_trades_over_last_year",
|
49 |
+
"maximum_illegal_trades",
|
50 |
+
"nr_total_trades",
|
51 |
+
"nr_trades_initiated_in_last_year",
|
52 |
+
"percentage_of_installment_trades",
|
53 |
+
"months_since_last_inquiry_not_recent",
|
54 |
+
"nr_inquiries_in_last_6_months",
|
55 |
+
"nr_inquiries_in_last_6_months_not_recent",
|
56 |
+
"net_fraction_of_revolving_burden",
|
57 |
+
"net_fraction_of_installment_burden",
|
58 |
+
"nr_revolving_trades_with_balance",
|
59 |
+
"nr_installment_trades_with_balance",
|
60 |
+
"nr_banks_with_high_ratio",
|
61 |
+
"percentage_trades_with_balance"
|
62 |
+
]
|
63 |
+
|
64 |
+
DESCRIPTION = "Heloc dataset for cancer prediction."
|
65 |
+
_HOMEPAGE = "https://community.fico.com/s/explainable-machine-learning-challenge?tabset-158d9=ca01a"
|
66 |
+
_URLS = ("https://community.fico.com/s/explainable-machine-learning-challenge?tabset-158d9=ca01a")
|
67 |
+
_CITATION = """
|
68 |
+
|
69 |
+
"""
|
70 |
+
|
71 |
+
# Dataset info
|
72 |
+
urls_per_split = {
|
73 |
+
"train": "https://huggingface.co/datasets/mstz/heloc/raw/main/heloc.csv",
|
74 |
+
}
|
75 |
+
features_types_per_config = {
|
76 |
+
"risk": {
|
77 |
+
"estimate_of_risk": datasets.Value("int8"),
|
78 |
+
"months_since_first_trade": datasets.Value("int32"),
|
79 |
+
"months_since_last_trade": datasets.Value("int32"),
|
80 |
+
"average_duration_of_resolution": datasets.Value("int32"),
|
81 |
+
"number_of_satisfactory_trades": datasets.Value("int16"),
|
82 |
+
"nr_trades_insolvent_for_over_60_days": datasets.Value("int16"),
|
83 |
+
"nr_trades_insolvent_for_over_90_days": datasets.Value("int16"),
|
84 |
+
"percentage_of_legal_trades": datasets.Value("int16"),
|
85 |
+
"months_since_last_illegal_trade": datasets.Value("int32"),
|
86 |
+
"maximum_illegal_trades_over_last_year": datasets.Value("int8"),
|
87 |
+
"maximum_illegal_trades": datasets.Value("int16"),
|
88 |
+
"nr_total_trades": datasets.Value("int16"),
|
89 |
+
"nr_trades_initiated_in_last_year": datasets.Value("int16"),
|
90 |
+
"percentage_of_installment_trades": datasets.Value("int16"),
|
91 |
+
"months_since_last_inquiry_not_recent": datasets.Value("int16"),
|
92 |
+
"nr_inquiries_in_last_6_months": datasets.Value("int16"),
|
93 |
+
"nr_inquiries_in_last_6_months_not_recent": datasets.Value("int16"),
|
94 |
+
"net_fraction_of_revolving_burden": datasets.Value("int32"),
|
95 |
+
"net_fraction_of_installment_burden": datasets.Value("int32"),
|
96 |
+
"nr_revolving_trades_with_balance": datasets.Value("int16"),
|
97 |
+
"nr_installment_trades_with_balance": datasets.Value("int16"),
|
98 |
+
"nr_banks_with_high_ratio": datasets.Value("int16"),
|
99 |
+
"percentage_trades_with_balance": datasets.Value("int16"),
|
100 |
+
"is_at_risk": datasets.ClassLabel(num_classes=2, names=("no", "yes"))
|
101 |
+
}
|
102 |
+
|
103 |
+
}
|
104 |
+
features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
|
105 |
+
|
106 |
+
|
107 |
+
class HelocConfig(datasets.BuilderConfig):
|
108 |
+
def __init__(self, **kwargs):
|
109 |
+
super(HelocConfig, self).__init__(version=VERSION, **kwargs)
|
110 |
+
self.features = features_per_config[kwargs["name"]]
|
111 |
+
|
112 |
+
|
113 |
+
class Heloc(datasets.GeneratorBasedBuilder):
|
114 |
+
# dataset versions
|
115 |
+
DEFAULT_CONFIG = "risk"
|
116 |
+
BUILDER_CONFIGS = [
|
117 |
+
HelocConfig(name="risk",
|
118 |
+
description="Binary classification of trade risk."),
|
119 |
+
]
|
120 |
+
|
121 |
+
|
122 |
+
def _info(self):
|
123 |
+
if self.config.name not in features_per_config:
|
124 |
+
raise ValueError(f"Unknown configuration: {self.config.name}")
|
125 |
+
|
126 |
+
info = datasets.DatasetInfo(description=DESCRIPTION, citation=_CITATION, homepage=_HOMEPAGE,
|
127 |
+
features=features_per_config[self.config.name])
|
128 |
+
|
129 |
+
return info
|
130 |
+
|
131 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
132 |
+
downloads = dl_manager.download_and_extract(urls_per_split)
|
133 |
+
|
134 |
+
return [
|
135 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloads["train"]}),
|
136 |
+
]
|
137 |
+
|
138 |
+
def _generate_examples(self, filepath: str):
|
139 |
+
data = pandas.read_csv(filepath)
|
140 |
+
data.columns=_ORIGINAL_FEATURE_NAMES
|
141 |
+
data = self.preprocess(data, config=self.config.name)
|
142 |
+
|
143 |
+
for row_id, row in data.iterrows():
|
144 |
+
data_row = dict(row)
|
145 |
+
|
146 |
+
yield row_id, data_row
|
147 |
+
|
148 |
+
def preprocess(self, data: pandas.DataFrame, config: str = "cancer") -> pandas.DataFrame:
|
149 |
+
data = data[features_types_per_config["risk"]]
|
150 |
+
|
151 |
+
if config == "risk":
|
152 |
+
return data
|
153 |
+
else:
|
154 |
+
raise ValueError(f"Unknown config: {config}")
|