mstz commited on
Commit
4d51c8f
1 Parent(s): 20e02ce

Upload 3 files

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. README.md +14 -1
  3. ipums.csv +3 -0
  4. ipums.py +136 -0
.gitattributes CHANGED
@@ -52,3 +52,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
52
  *.jpg filter=lfs diff=lfs merge=lfs -text
53
  *.jpeg filter=lfs diff=lfs merge=lfs -text
54
  *.webp filter=lfs diff=lfs merge=lfs -text
 
 
52
  *.jpg filter=lfs diff=lfs merge=lfs -text
53
  *.jpeg filter=lfs diff=lfs merge=lfs -text
54
  *.webp filter=lfs diff=lfs merge=lfs -text
55
+ ipums.csv filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,3 +1,16 @@
1
  ---
2
- license: cc-by-4.0
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
1
  ---
2
+ language:
3
+ - en
4
+ tags:
5
+ - ipums
6
+ - tabular_classification
7
+ - binary_classification
8
+ - UCI
9
+ pretty_name: Ipums
10
+ task_categories: # Full list at https://github.com/huggingface/hub-docs/blob/main/js/src/lib/interfaces/Types.ts
11
+ - tabular-classification
12
+ configs:
13
+ - ipums
14
  ---
15
+ # Ipums
16
+ The [Ipums dataset](https://archive-beta.ics.uci.edu/dataset/127/ipums+census+database) from the [UCI repository](https://archive-beta.ics.uci.edu/).
ipums.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c567ebe4186170819aa5a66d0ea501cafee5b99fb47c030c01e5bd2c421143cb
3
+ size 143523513
ipums.py ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Ipums Dataset"""
2
+
3
+ from typing import List
4
+ from functools import partial
5
+
6
+ import datasets
7
+
8
+ import pandas
9
+
10
+
11
+ VERSION = datasets.Version("1.0.0")
12
+
13
+ _ENCODING_DICS = {
14
+ "class": {
15
+ "- 50000.": 0,
16
+ "50000+.": 1
17
+ }
18
+ }
19
+
20
+ DESCRIPTION = "Ipums dataset."
21
+ _HOMEPAGE = "https://archive-beta.ics.uci.edu/dataset/127/ipums+census+database"
22
+ _URLS = ("https://archive-beta.ics.uci.edu/dataset/127/ipums+census+database")
23
+ _CITATION = """
24
+ @misc{misc_ipums_census_database_127,
25
+ author = {Ruggles,Steven & Sobek,Matthew},
26
+ title = {{IPUMS Census Database}},
27
+ year = {1999},
28
+ howpublished = {UCI Machine Learning Repository},
29
+ note = {{DOI}: \\url{10.24432/C5BG63}}
30
+ }
31
+ """
32
+
33
+ # Dataset info
34
+ urls_per_split = {
35
+ "train": "https://huggingface.co/datasets/mstz/ipums/raw/main/ipums.csv"
36
+ }
37
+ features_types_per_config = {
38
+ "ipums": {
39
+ "age": datasets.Value("int64"),
40
+ "class_of_worker": datasets.Value("string"),
41
+ "detailed_industry_recode": datasets.Value("string"),
42
+ "detailed_occupation_recode": datasets.Value("string"),
43
+ "education": datasets.Value("string"),
44
+ "wage_per_hour": datasets.Value("int64"),
45
+ "enroll_in_edu_inst_last_wk": datasets.Value("string"),
46
+ "marital_stat": datasets.Value("string"),
47
+ "major_industry_code": datasets.Value("string"),
48
+ "major_occupation_code": datasets.Value("string"),
49
+ "race": datasets.Value("string"),
50
+ "hispanic_origin": datasets.Value("string"),
51
+ "sex": datasets.Value("string"),
52
+ "member_of_a_labor_union": datasets.Value("string"),
53
+ "reason_for_unemployment": datasets.Value("string"),
54
+ "full_or_part_time_employment_stat": datasets.Value("string"),
55
+ "capital_gains": datasets.Value("int64"),
56
+ "capital_losses": datasets.Value("int64"),
57
+ "dividends_from_stocks": datasets.Value("int64"),
58
+ "tax_filer_stat": datasets.Value("string"),
59
+ "region_of_previous_residence": datasets.Value("string"),
60
+ "state_of_previous_residence": datasets.Value("string"),
61
+ "detailed_household_and_family_stat": datasets.Value("string"),
62
+ "detailed_household_summary_in_household": datasets.Value("string"),
63
+ # "instance_weight": datasets.Value("int64"),
64
+ "migration_code_change_in_msa": datasets.Value("string"),
65
+ "migration_code_change_in_reg": datasets.Value("string"),
66
+ "migration_code_move_within_reg": datasets.Value("string"),
67
+ "live_in_this_house_1_year_ago": datasets.Value("string"),
68
+ "migration_prev_res_in_sunbelt": datasets.Value("string"),
69
+ "num_persons_worked_for_employer": datasets.Value("int64"),
70
+ "family_members_under_18": datasets.Value("string"),
71
+ "country_of_birth_father": datasets.Value("string"),
72
+ "country_of_birth_mother": datasets.Value("string"),
73
+ "country_of_birth_self": datasets.Value("string"),
74
+ "citizenship": datasets.Value("string"),
75
+ "own_business_or_self_employed": datasets.Value("string"),
76
+ "fill_inc_questionnaire_for_veteran_admin": datasets.Value("string"),
77
+ "veterans_benefits": datasets.Value("string"),
78
+ "weeks_worked_in_year": datasets.Value("int64"),
79
+ "year": datasets.Value("int64"),
80
+ "class": datasets.ClassLabel(num_classes=2)
81
+ }
82
+ }
83
+ features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
84
+
85
+
86
+ class IpumsConfig(datasets.BuilderConfig):
87
+ def __init__(self, **kwargs):
88
+ super(IpumsConfig, self).__init__(version=VERSION, **kwargs)
89
+ self.features = features_per_config[kwargs["name"]]
90
+
91
+
92
+ class Ipums(datasets.GeneratorBasedBuilder):
93
+ # dataset versions
94
+ DEFAULT_CONFIG = "ipums"
95
+ BUILDER_CONFIGS = [
96
+ IpumsConfig(name="ipums", description="Ipums for binary classification."),
97
+
98
+
99
+ ]
100
+
101
+
102
+ def _info(self):
103
+ info = datasets.DatasetInfo(description=DESCRIPTION, citation=_CITATION, homepage=_HOMEPAGE,
104
+ features=features_per_config[self.config.name])
105
+
106
+ return info
107
+
108
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
109
+ downloads = dl_manager.download_and_extract(urls_per_split)
110
+
111
+ return [
112
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloads["train"]}),
113
+ ]
114
+
115
+ def _generate_examples(self, filepath: str):
116
+ data = pandas.read_csv(filepath)
117
+ data = self.preprocess(data)
118
+
119
+ for row_id, row in data.iterrows():
120
+ data_row = dict(row)
121
+
122
+ yield row_id, data_row
123
+
124
+ def preprocess(self, data: pandas.DataFrame) -> pandas.DataFrame:
125
+ for feature in _ENCODING_DICS:
126
+ encoding_function = partial(self.encode, feature)
127
+ data.loc[:, feature] = data[feature].apply(encoding_function)
128
+
129
+ data.drop("instance_weight", axis="columns", inplace=True)
130
+
131
+ return data[list(features_types_per_config[self.config.name].keys())]
132
+
133
+ def encode(self, feature, value):
134
+ if feature in _ENCODING_DICS:
135
+ return _ENCODING_DICS[feature][value]
136
+ raise ValueError(f"Unknown feature: {feature}")