23
23
]
24
24
25
25
26
- def swap (arr , i1 , i2 ):
27
- arr [..., i1 ], arr [..., i2 ] = arr [..., i2 ], arr [..., i1 ].copy ()
28
-
29
-
30
26
def download_data ():
31
27
data_folder = "_Data"
32
28
idx_folder = os .path .join (data_folder , "idx" )
@@ -41,15 +37,12 @@ def download_data():
41
37
if os .path .isfile (data_file ) and os .path .isfile (idx_file ):
42
38
continue
43
39
dataset = datasets .get_dataset (idx )
44
- data , categorical_idx , names = dataset .get_data (
45
- return_categorical_indicator = True ,
46
- return_attribute_names = True
47
- )
48
- data = data .toarray () if not isinstance (data , np .ndarray ) else data
49
- target_idx = names .index (dataset .default_target_attribute )
40
+ x , y , categorical_idx , names = dataset .get_data (
41
+ target = dataset .default_target_attribute , dataset_format = "array" )
42
+ categorical_idx .append (False )
43
+ to_array = lambda arr : arr .toarray () if not isinstance (arr , np .ndarray ) else arr
44
+ data = np .hstack (list (map (to_array , [x , y .reshape ([- 1 , 1 ])])))
50
45
numerical_idx = ~ np .array (categorical_idx )
51
- swap (numerical_idx , target_idx , - 1 )
52
- swap (data , target_idx , - 1 )
53
46
with open (data_file , "w" ) as file :
54
47
file .write ("\n " .join ([" " .join (map (lambda n : str (n ), line )) for line in data ]))
55
48
np .save (idx_file , numerical_idx )
0 commit comments