--- dataset_info: features: - name: age dtype: int64 - name: workclass dtype: class_label: names: '0': '?' '1': Federal-gov '2': Local-gov '3': Never-worked '4': Private '5': Self-emp-inc '6': Self-emp-not-inc '7': State-gov '8': Without-pay - name: fnlwgt dtype: int64 - name: education dtype: class_label: names: '0': 10th '1': 11th '2': 12th '3': 1st-4th '4': 5th-6th '5': 7th-8th '6': 9th '7': Assoc-acdm '8': Assoc-voc '9': Bachelors '10': Doctorate '11': HS-grad '12': Masters '13': Preschool '14': Prof-school '15': Some-college - name: education-num dtype: int64 - name: marital-status dtype: class_label: names: '0': Divorced '1': Married-AF-spouse '2': Married-civ-spouse '3': Married-spouse-absent '4': Never-married '5': Separated '6': Widowed - name: occupation dtype: class_label: names: '0': '?' '1': Adm-clerical '2': Armed-Forces '3': Craft-repair '4': Exec-managerial '5': Farming-fishing '6': Handlers-cleaners '7': Machine-op-inspct '8': Other-service '9': Priv-house-serv '10': Prof-specialty '11': Protective-serv '12': Sales '13': Tech-support '14': Transport-moving - name: relationship dtype: class_label: names: '0': Husband '1': Not-in-family '2': Other-relative '3': Own-child '4': Unmarried '5': Wife - name: race dtype: class_label: names: '0': Amer-Indian-Eskimo '1': Asian-Pac-Islander '2': Black '3': Other '4': White - name: sex dtype: class_label: names: '0': Female '1': Male - name: capital-gain dtype: int64 - name: capital-loss dtype: int64 - name: hours-per-week dtype: int64 - name: native-country dtype: class_label: names: '0': '?' '1': Cambodia '2': Canada '3': China '4': Columbia '5': Cuba '6': Dominican-Republic '7': Ecuador '8': El-Salvador '9': England '10': France '11': Germany '12': Greece '13': Guatemala '14': Haiti '15': Holand-Netherlands '16': Honduras '17': Hong '18': Hungary '19': India '20': Iran '21': Ireland '22': Italy '23': Jamaica '24': Japan '25': Laos '26': Mexico '27': Nicaragua '28': Outlying-US(Guam-USVI-etc) '29': Peru '30': Philippines '31': Poland '32': Portugal '33': Puerto-Rico '34': Scotland '35': South '36': Taiwan '37': Thailand '38': Trinadad&Tobago '39': United-States '40': Vietnam '41': Yugoslavia - name: income dtype: class_label: names: '0': <=50K '1': '>50K' splits: - name: train num_bytes: 3907320 num_examples: 32561 - name: test num_bytes: 1953720 num_examples: 16281 download_size: 800983 dataset_size: 5861040 configs: - config_name: default data_files: - split: train path: data/train-* - split: test path: data/test-* --- # Dataset Card for Census Income (Adult) This dataset is a precise version of [Adult](https://archive.ics.uci.edu/dataset/2/adult) or [Census Income](https://archive.ics.uci.edu/dataset/20/census+income). This dataset from UCI somehow happens to occupy two links, but we checked and confirm that they are identical. We used the following python script to create this Hugging Face dataset. ```python import pandas as pd from datasets import Dataset, DatasetDict, Features, Value, ClassLabel # URLs url1 = "https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data" url2 = "https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.test" # Column names columns = [ "age", "workclass", "fnlwgt", "education", "education-num", "marital-status", "occupation", "relationship", "race", "sex", "capital-gain", "capital-loss", "hours-per-week", "native-country", "income" ] # Load datasets df_train = pd.read_csv(url1, names=columns, skipinitialspace=True) df_test = pd.read_csv(url2, names=columns, skipinitialspace=True, skiprows=1) # Convert continuous columns to float continuous_columns = ["age", "fnlwgt", "education-num", "capital-gain", "capital-loss", "hours-per-week"] for col in continuous_columns: df_train[col] = pd.to_numeric(df_train[col], errors='coerce') df_test[col] = pd.to_numeric(df_test[col], errors='coerce') df_test['income'] = df_test['income'].str.rstrip('.') # This is somewhat critical. # Define categorical columns categorical_columns = [ "workclass", "education", "marital-status", "occupation", "relationship", "race", "sex", "native-country", "income" ] # Dictionary to store category mappings category_mappings = {} for col in categorical_columns: # Convert train column to category and extract categories df_train[col] = df_train[col].astype("category") category_mappings[col] = df_train[col].cat.categories.to_list() # Store category order # Apply the same category mapping to test df_test[col] = pd.Categorical(df_test[col], categories=category_mappings[col]) # Convert to integer codes df_train[col] = df_train[col].cat.codes df_test[col] = df_test[col].cat.codes # Define Hugging Face dataset schema hf_features = Features({ "age": Value("int64"), "workclass": ClassLabel(names=category_mappings["workclass"]), "fnlwgt": Value("int64"), "education": ClassLabel(names=category_mappings["education"]), "education-num": Value("int64"), "marital-status": ClassLabel(names=category_mappings["marital-status"]), "occupation": ClassLabel(names=category_mappings["occupation"]), "relationship": ClassLabel(names=category_mappings["relationship"]), "race": ClassLabel(names=category_mappings["race"]), "sex": ClassLabel(names=category_mappings["sex"]), "capital-gain": Value("int64"), "capital-loss": Value("int64"), "hours-per-week": Value("int64"), "native-country": ClassLabel(names=category_mappings["native-country"]), "income": ClassLabel(names=category_mappings["income"]) }) # Convert pandas DataFrame to Hugging Face Dataset hf_train = Dataset.from_pandas(df_train, features=hf_features) hf_test = Dataset.from_pandas(df_test, features=hf_features) # Create a dataset dictionary hf_dataset = DatasetDict({ "train": hf_train, "test": hf_test }) # Print dataset structure print(hf_dataset) ``` The printed output could look like ``` DatasetDict({ train: Dataset({ features: ['age', 'workclass', 'fnlwgt', 'education', 'education-num', 'marital-status', 'occupation', 'relationship', 'race', 'sex', 'capital-gain', 'capital-loss', 'hours-per-week', 'native-country', 'income'], num_rows: 32561 }) test: Dataset({ features: ['age', 'workclass', 'fnlwgt', 'education', 'education-num', 'marital-status', 'occupation', 'relationship', 'race', 'sex', 'capital-gain', 'capital-loss', 'hours-per-week', 'native-country', 'income'], num_rows: 16281 }) }) ```