Datasets:
Upload covertype.py
Browse files- covertype.py +60 -4
covertype.py
CHANGED
@@ -3,6 +3,7 @@ from typing import List
|
|
3 |
import datasets
|
4 |
|
5 |
import pandas
|
|
|
6 |
|
7 |
|
8 |
VERSION = datasets.Version("1.0.0")
|
@@ -15,8 +16,63 @@ _CITATION = """"""
|
|
15 |
|
16 |
# Dataset info
|
17 |
urls_per_split = {
|
18 |
-
"train": "https://
|
19 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
features_types_per_config = {
|
21 |
"covertype": {
|
22 |
"elevation": datasets.Value("float32"),
|
@@ -110,7 +166,8 @@ class Covertype(datasets.GeneratorBasedBuilder):
|
|
110 |
]
|
111 |
|
112 |
def _generate_examples(self, filepath: str):
|
113 |
-
|
|
|
114 |
data = self.preprocess(data, config=self.config.name)
|
115 |
|
116 |
for row_id, row in data.iterrows():
|
@@ -119,7 +176,6 @@ class Covertype(datasets.GeneratorBasedBuilder):
|
|
119 |
yield row_id, data_row
|
120 |
|
121 |
def preprocess(self, data: pandas.DataFrame, config: str = DEFAULT_CONFIG) -> pandas.DataFrame:
|
122 |
-
print(data.columns)
|
123 |
-
print(data.cover_type)
|
124 |
data.loc[:, "cover_type"] = data["cover_type"].apply(lambda x: x - 1)
|
|
|
125 |
return data
|
|
|
3 |
import datasets
|
4 |
|
5 |
import pandas
|
6 |
+
import gzip
|
7 |
|
8 |
|
9 |
VERSION = datasets.Version("1.0.0")
|
|
|
16 |
|
17 |
# Dataset info
|
18 |
urls_per_split = {
|
19 |
+
"train": "https://archive.ics.uci.edu/ml/machine-learning-databases/covtype/covtype.data.gz"
|
20 |
}
|
21 |
+
_BASE_FEATURE_NAMES = [
|
22 |
+
"elevation",
|
23 |
+
"aspect",
|
24 |
+
"slope",
|
25 |
+
"horizontal_distance_to_hydrology",
|
26 |
+
"vertical_distance_to_hydrology",
|
27 |
+
"horizontal_distance_to_roadways",
|
28 |
+
"hillshade_9am",
|
29 |
+
"hillshade_noon",
|
30 |
+
"hillshade_3pm",
|
31 |
+
"horizontal_distance_to_fire_points",
|
32 |
+
"is_a_wilderness_area",
|
33 |
+
"soil_type_id_0",
|
34 |
+
"soil_type_id_1",
|
35 |
+
"soil_type_id_2",
|
36 |
+
"soil_type_id_3",
|
37 |
+
"soil_type_id_4",
|
38 |
+
"soil_type_id_5",
|
39 |
+
"soil_type_id_6",
|
40 |
+
"soil_type_id_7",
|
41 |
+
"soil_type_id_8",
|
42 |
+
"soil_type_id_9",
|
43 |
+
"soil_type_id_10",
|
44 |
+
"soil_type_id_11",
|
45 |
+
"soil_type_id_12",
|
46 |
+
"soil_type_id_13",
|
47 |
+
"soil_type_id_14",
|
48 |
+
"soil_type_id_15",
|
49 |
+
"soil_type_id_16",
|
50 |
+
"soil_type_id_17",
|
51 |
+
"soil_type_id_18",
|
52 |
+
"soil_type_id_19",
|
53 |
+
"soil_type_id_20",
|
54 |
+
"soil_type_id_21",
|
55 |
+
"soil_type_id_22",
|
56 |
+
"soil_type_id_23",
|
57 |
+
"soil_type_id_24",
|
58 |
+
"soil_type_id_25",
|
59 |
+
"soil_type_id_26",
|
60 |
+
"soil_type_id_27",
|
61 |
+
"soil_type_id_28",
|
62 |
+
"soil_type_id_29",
|
63 |
+
"soil_type_id_30",
|
64 |
+
"soil_type_id_31",
|
65 |
+
"soil_type_id_32",
|
66 |
+
"soil_type_id_33",
|
67 |
+
"soil_type_id_34",
|
68 |
+
"soil_type_id_35",
|
69 |
+
"soil_type_id_36",
|
70 |
+
"soil_type_id_37",
|
71 |
+
"soil_type_id_38",
|
72 |
+
"soil_type_id_39",
|
73 |
+
"soil_type",
|
74 |
+
"cover_type"
|
75 |
+
]
|
76 |
features_types_per_config = {
|
77 |
"covertype": {
|
78 |
"elevation": datasets.Value("float32"),
|
|
|
166 |
]
|
167 |
|
168 |
def _generate_examples(self, filepath: str):
|
169 |
+
with gzip.open(filepath) as log:
|
170 |
+
data = pandas.read_csv(log, header=_BASE_FEATURE_NAMES)
|
171 |
data = self.preprocess(data, config=self.config.name)
|
172 |
|
173 |
for row_id, row in data.iterrows():
|
|
|
176 |
yield row_id, data_row
|
177 |
|
178 |
def preprocess(self, data: pandas.DataFrame, config: str = DEFAULT_CONFIG) -> pandas.DataFrame:
|
|
|
|
|
179 |
data.loc[:, "cover_type"] = data["cover_type"].apply(lambda x: x - 1)
|
180 |
+
|
181 |
return data
|