Upload 3 files
Browse files- README.md +41 -1
- soybean.data +0 -0
- soybean.py +180 -0
README.md
CHANGED
@@ -1,3 +1,43 @@
|
|
1 |
---
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
language:
|
3 |
+
- en
|
4 |
+
tags:
|
5 |
+
- soybean
|
6 |
+
- tabular_classification
|
7 |
+
- binary_classification
|
8 |
+
- multiclass_classification
|
9 |
+
- UCI
|
10 |
+
pretty_name: Isoybean
|
11 |
+
task_categories: # Full list at https://github.com/huggingface/hub-docs/blob/main/js/src/lib/interfaces/Types.ts
|
12 |
+
- tabular-classification
|
13 |
+
configs:
|
14 |
+
- soybean
|
15 |
---
|
16 |
+
# Soybean
|
17 |
+
The [Soybean dataset](https://archive-beta.ics.uci.edu/dataset/90/soybean+large) from the [UCI repository](https://archive-beta.ics.uci.edu/).
|
18 |
+
Classify the type of soybean.
|
19 |
+
|
20 |
+
|
21 |
+
# Configurations and tasks
|
22 |
+
| **Configuration** | **Task** | **Description** |
|
23 |
+
|-----------------------|---------------------------|-----------------|
|
24 |
+
| soybean | Binary classification.| Classify soybean type. |
|
25 |
+
| diaporthe_stem_canker | Binary classification | Is this instance of class diaporthe_stem_canker? |
|
26 |
+
| charcoal_rot | Binary classification | Is this instance of class charcoal_rot? |
|
27 |
+
| rhizoctonia_root_rot | Binary classification | Is this instance of class rhizoctonia_root_rot? |
|
28 |
+
| phytophthora_rot | Binary classification | Is this instance of class phytophthora_rot? |
|
29 |
+
| brown_stem_rot | Binary classification | Is this instance of class brown_stem_rot? |
|
30 |
+
| powdery_mildew | Binary classification | Is this instance of class powdery_mildew? |
|
31 |
+
| downy_mildew | Binary classification | Is this instance of class downy_mildew? |
|
32 |
+
| brown_spot | Binary classification | Is this instance of class brown_spot? |
|
33 |
+
| bacterial_blight | Binary classification | Is this instance of class bacterial_blight? |
|
34 |
+
| bacterial_pustule | Binary classification | Is this instance of class bacterial_pustule? |
|
35 |
+
| purple_seed_stain | Binary classification | Is this instance of class purple_seed_stain? |
|
36 |
+
| anthracnose | Binary classification | Is this instance of class anthracnose? |
|
37 |
+
| phyllosticta_leaf_spot | Binary classification | Is this instance of class phyllosticta_leaf_spot? |
|
38 |
+
| alternarialeaf_spot | Binary classification | Is this instance of class alternarialeaf_spot? |
|
39 |
+
| frog_eye_leaf_spot | Binary classification | Is this instance of class frog_eye_leaf_spot? |
|
40 |
+
| diaporthe_pod_&_stem_blight | Binary classification | Is this instance of class diaporthe_pod_? |
|
41 |
+
| cyst_nematode | Binary classification | Is this instance of class cyst_nematode? |
|
42 |
+
| 2_4_d_injury | Binary classification | Is this instance of class 2_4_d_injury? |
|
43 |
+
| herbicide_injury | Binary classification | Is this instance of class herbicide_injury? |
|
soybean.data
ADDED
The diff for this file is too large to render.
See raw diff
|
|
soybean.py
ADDED
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Soybean 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 |
+
value: i for i, value in enumerate(["diaporthe_stem_canker",
|
16 |
+
"charcoal_rot", "rhizoctonia_root_rot",
|
17 |
+
"phytophthora_rot", "brown_stem_rot", "powdery_mildew",
|
18 |
+
"downy_mildew", "brown_spot", "bacterial_blight",
|
19 |
+
"bacterial_pustule", "purple_seed_stain", "anthracnose",
|
20 |
+
"phyllosticta_leaf_spot", "alternarialeaf_spot",
|
21 |
+
"frog_eye_leaf_spot", "diaporthe_pod_&_stem_blight",
|
22 |
+
"cyst_nematode", "2_4_d_injury", "herbicide_injury"])
|
23 |
+
}
|
24 |
+
}
|
25 |
+
_BASE_FEATURE_NAMES = [
|
26 |
+
"date",
|
27 |
+
"plant_stand",
|
28 |
+
"precip",
|
29 |
+
"temp",
|
30 |
+
"hail",
|
31 |
+
"crop_hist",
|
32 |
+
"area_damaged",
|
33 |
+
"severity",
|
34 |
+
"seed_tmt",
|
35 |
+
"germination",
|
36 |
+
"plant_growth",
|
37 |
+
"leaves",
|
38 |
+
"leafspots_halo",
|
39 |
+
"leafspots_marg",
|
40 |
+
"leafspot_size",
|
41 |
+
"leaf_shread",
|
42 |
+
"leaf_malf",
|
43 |
+
"leaf_mild",
|
44 |
+
"stem",
|
45 |
+
"lodging",
|
46 |
+
"stem_cankers",
|
47 |
+
"canker_lesion",
|
48 |
+
"fruiting_bodies",
|
49 |
+
"external decay",
|
50 |
+
"mycelium",
|
51 |
+
"int_discolor",
|
52 |
+
"sclerotia",
|
53 |
+
"fruit_pods",
|
54 |
+
"fruit spots",
|
55 |
+
"seed",
|
56 |
+
"mold_growth",
|
57 |
+
"seed_discolor",
|
58 |
+
"seed_size",
|
59 |
+
"shriveling",
|
60 |
+
"roots",
|
61 |
+
"class",
|
62 |
+
]
|
63 |
+
|
64 |
+
DESCRIPTION = "Soybean dataset."
|
65 |
+
_HOMEPAGE = "https://archive-beta.ics.uci.edu/dataset/116/us+census+data+1990"
|
66 |
+
_URLS = ("https://archive-beta.ics.uci.edu/dataset/116/us+census+data+1990")
|
67 |
+
_CITATION = """
|
68 |
+
@misc{misc_us_census_data_(1990)_116,
|
69 |
+
author = {Meek,Meek, Thiesson,Thiesson & Heckerman,Heckerman},
|
70 |
+
title = {{US Census Data (1990)}},
|
71 |
+
howpublished = {UCI Machine Learning Repository},
|
72 |
+
note = {{DOI}: \\url{10.24432/C5VP42}}
|
73 |
+
}
|
74 |
+
"""
|
75 |
+
|
76 |
+
# Dataset info
|
77 |
+
urls_per_split = {
|
78 |
+
"train": "https://huggingface.co/datasets/mstz/soybean/resolve/main/soybean.csv"
|
79 |
+
}
|
80 |
+
features_types_per_config = {
|
81 |
+
"soybean": {
|
82 |
+
"date": datasets.Value("string"),
|
83 |
+
"plant_stand": datasets.Value("string"),
|
84 |
+
"precip": datasets.Value("string"),
|
85 |
+
"temp": datasets.Value("string"),
|
86 |
+
"hail": datasets.Value("string"),
|
87 |
+
"crop_hist": datasets.Value("string"),
|
88 |
+
"area_damaged": datasets.Value("string"),
|
89 |
+
"severity": datasets.Value("string"),
|
90 |
+
"seed_tmt": datasets.Value("string"),
|
91 |
+
"germination": datasets.Value("string"),
|
92 |
+
"plant_growth": datasets.Value("string"),
|
93 |
+
"leaves": datasets.Value("string"),
|
94 |
+
"leafspots_halo": datasets.Value("string"),
|
95 |
+
"leafspots_marg": datasets.Value("string"),
|
96 |
+
"leafspot_size": datasets.Value("string"),
|
97 |
+
"leaf_shread": datasets.Value("string"),
|
98 |
+
"leaf_malf": datasets.Value("string"),
|
99 |
+
"leaf_mild": datasets.Value("string"),
|
100 |
+
"stem": datasets.Value("string"),
|
101 |
+
"lodging": datasets.Value("string"),
|
102 |
+
"stem_cankers": datasets.Value("string"),
|
103 |
+
"canker_lesion": datasets.Value("string"),
|
104 |
+
"fruiting_bodies": datasets.Value("string"),
|
105 |
+
"external decay": datasets.Value("string"),
|
106 |
+
"mycelium": datasets.Value("string"),
|
107 |
+
"int_discolor": datasets.Value("string"),
|
108 |
+
"sclerotia": datasets.Value("string"),
|
109 |
+
"fruit_pods": datasets.Value("string"),
|
110 |
+
"fruit spots": datasets.Value("string"),
|
111 |
+
"seed": datasets.Value("string"),
|
112 |
+
"mold_growth": datasets.Value("string"),
|
113 |
+
"seed_discolor": datasets.Value("string"),
|
114 |
+
"seed_size": datasets.Value("string"),
|
115 |
+
"shriveling": datasets.Value("string"),
|
116 |
+
"roots": datasets.Value("string"),
|
117 |
+
"class": datasets.ClassLabel(num_classes=19)
|
118 |
+
}
|
119 |
+
}
|
120 |
+
features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
|
121 |
+
|
122 |
+
|
123 |
+
class SoybeanConfig(datasets.BuilderConfig):
|
124 |
+
def __init__(self, **kwargs):
|
125 |
+
super(SoybeanConfig, self).__init__(version=VERSION, **kwargs)
|
126 |
+
self.features = features_per_config[kwargs["name"]]
|
127 |
+
|
128 |
+
|
129 |
+
class Soybean(datasets.GeneratorBasedBuilder):
|
130 |
+
# dataset versions
|
131 |
+
DEFAULT_CONFIG = "soybean"
|
132 |
+
binary_configurations = [SoybeanConfig(name=c, description=f"Is this instance of class {c}?")
|
133 |
+
for c in _ENCODING_DICS["class"].keys()]
|
134 |
+
BUILDER_CONFIGS = [SoybeanConfig(name="soybean", description="Soybean for binary classification.")]
|
135 |
+
BUILDER_CONFIGS += binary_configurations
|
136 |
+
|
137 |
+
|
138 |
+
def _info(self):
|
139 |
+
info = datasets.DatasetInfo(description=DESCRIPTION, citation=_CITATION, homepage=_HOMEPAGE,
|
140 |
+
features=features_per_config[self.config.name])
|
141 |
+
|
142 |
+
return info
|
143 |
+
|
144 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
145 |
+
downloads = dl_manager.download_and_extract(urls_per_split)
|
146 |
+
|
147 |
+
return [
|
148 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloads["train"]}),
|
149 |
+
]
|
150 |
+
|
151 |
+
def _generate_examples(self, filepath: str):
|
152 |
+
data = pandas.read_csv(filepath, header=None)
|
153 |
+
data = self.preprocess(data)
|
154 |
+
|
155 |
+
for row_id, row in data.iterrows():
|
156 |
+
data_row = dict(row)
|
157 |
+
|
158 |
+
yield row_id, data_row
|
159 |
+
|
160 |
+
def preprocess(self, data: pandas.DataFrame) -> pandas.DataFrame:
|
161 |
+
data.columns = _BASE_FEATURE_NAMES
|
162 |
+
|
163 |
+
for c in _ENCODING_DICS["class"].keys():
|
164 |
+
if self.config.name == c:
|
165 |
+
data["class"] = data["class"].apply(lambda x: 1 if x == c else 0)
|
166 |
+
break
|
167 |
+
|
168 |
+
for feature in _ENCODING_DICS:
|
169 |
+
encoding_function = partial(self.encode, feature)
|
170 |
+
data[feature] = data[feature].apply(encoding_function)
|
171 |
+
|
172 |
+
data = data.rename(columns={"instance migration_code_change_in_msa": "migration_code_change_in_msa"})
|
173 |
+
|
174 |
+
|
175 |
+
return data[list(features_types_per_config[self.config.name].keys())]
|
176 |
+
|
177 |
+
def encode(self, feature, value):
|
178 |
+
if feature in _ENCODING_DICS:
|
179 |
+
return _ENCODING_DICS[feature][value]
|
180 |
+
raise ValueError(f"Unknown feature: {feature}")
|