@@ -264,7 +264,7 @@ def load_iris(return_X_y=False):
264
264
If True, returns ``(data, target)`` instead of a Bunch object.
265
265
See below for more information about the `data` and `target` object.
266
266
267
- .. versionadded:: 0.18
267
+ .. versionadded:: 0.18
268
268
269
269
Returns
270
270
-------
@@ -277,7 +277,7 @@ def load_iris(return_X_y=False):
277
277
278
278
(data, target) : tuple if ``return_X_y`` is True
279
279
280
- .. versionadded:: 0.18
280
+ .. versionadded:: 0.18
281
281
282
282
Examples
283
283
--------
@@ -338,7 +338,7 @@ def load_breast_cancer(return_X_y=False):
338
338
If True, returns ``(data, target)`` instead of a Bunch object.
339
339
See below for more information about the `data` and `target` object.
340
340
341
- .. versionadded:: 0.18
341
+ .. versionadded:: 0.18
342
342
343
343
Returns
344
344
-------
@@ -351,7 +351,7 @@ def load_breast_cancer(return_X_y=False):
351
351
352
352
(data, target) : tuple if ``return_X_y`` is True
353
353
354
- .. versionadded:: 0.18
354
+ .. versionadded:: 0.18
355
355
356
356
The copy of UCI ML Breast Cancer Wisconsin (Diagnostic) dataset is
357
357
downloaded from:
@@ -411,7 +411,7 @@ def load_breast_cancer(return_X_y=False):
411
411
feature_names = feature_names )
412
412
413
413
414
- def load_digits (n_class = 10 ):
414
+ def load_digits (n_class = 10 , return_X_y = False ):
415
415
"""Load and return the digits dataset (classification).
416
416
417
417
Each datapoint is a 8x8 image of a digit.
@@ -431,6 +431,12 @@ def load_digits(n_class=10):
431
431
n_class : integer, between 0 and 10, optional (default=10)
432
432
The number of classes to return.
433
433
434
+ return_X_y : boolean, default=False.
435
+ If True, returns ``(data, target)`` instead of a Bunch object.
436
+ See below for more information about the `data` and `target` object.
437
+
438
+ .. versionadded:: 0.18
439
+
434
440
Returns
435
441
-------
436
442
data : Bunch
@@ -440,6 +446,10 @@ def load_digits(n_class=10):
440
446
sample, 'target_names', the meaning of the labels, and 'DESCR',
441
447
the full description of the dataset.
442
448
449
+ (data, target) : tuple if ``return_X_y`` is True
450
+
451
+ .. versionadded:: 0.18
452
+
443
453
Examples
444
454
--------
445
455
To load the data and visualize the images::
@@ -458,7 +468,7 @@ def load_digits(n_class=10):
458
468
delimiter = ',' )
459
469
with open (join (module_path , 'descr' , 'digits.rst' )) as f :
460
470
descr = f .read ()
461
- target = data [:, - 1 ]
471
+ target = data [:, - 1 ]. astype ( np . int )
462
472
flat_data = data [:, :- 1 ]
463
473
images = flat_data .view ()
464
474
images .shape = (- 1 , 8 , 8 )
@@ -468,14 +478,17 @@ def load_digits(n_class=10):
468
478
flat_data , target = flat_data [idx ], target [idx ]
469
479
images = images [idx ]
470
480
481
+ if return_X_y :
482
+ return flat_data , target
483
+
471
484
return Bunch (data = flat_data ,
472
- target = target . astype ( np . int ) ,
485
+ target = target ,
473
486
target_names = np .arange (10 ),
474
487
images = images ,
475
488
DESCR = descr )
476
489
477
490
478
- def load_diabetes ():
491
+ def load_diabetes (return_X_y = False ):
479
492
"""Load and return the diabetes dataset (regression).
480
493
481
494
============== ==================
@@ -487,34 +500,62 @@ def load_diabetes():
487
500
488
501
Read more in the :ref:`User Guide <datasets>`.
489
502
503
+ Parameters
504
+ ----------
505
+ return_X_y : boolean, default=False.
506
+ If True, returns ``(data, target)`` instead of a Bunch object.
507
+ See below for more information about the `data` and `target` object.
508
+
509
+ .. versionadded:: 0.18
510
+
490
511
Returns
491
512
-------
492
513
data : Bunch
493
514
Dictionary-like object, the interesting attributes are:
494
515
'data', the data to learn and 'target', the regression target for each
495
516
sample.
517
+
518
+ (data, target) : tuple if ``return_X_y`` is True
519
+
520
+ .. versionadded:: 0.18
496
521
"""
497
522
base_dir = join (dirname (__file__ ), 'data' )
498
523
data = np .loadtxt (join (base_dir , 'diabetes_data.csv.gz' ))
499
524
target = np .loadtxt (join (base_dir , 'diabetes_target.csv.gz' ))
525
+
526
+ if return_X_y :
527
+ return data , target
528
+
500
529
return Bunch (data = data , target = target )
501
530
502
531
503
- def load_linnerud ():
532
+ def load_linnerud (return_X_y = False ):
504
533
"""Load and return the linnerud dataset (multivariate regression).
505
534
506
535
Samples total: 20
507
536
Dimensionality: 3 for both data and targets
508
537
Features: integer
509
538
Targets: integer
510
539
540
+ Parameters
541
+ ----------
542
+ return_X_y : boolean, default=False.
543
+ If True, returns ``(data, target)`` instead of a Bunch object.
544
+ See below for more information about the `data` and `target` object.
545
+
546
+ .. versionadded:: 0.18
547
+
511
548
Returns
512
549
-------
513
550
data : Bunch
514
551
Dictionary-like object, the interesting attributes are: 'data' and
515
552
'targets', the two multivariate datasets, with 'data' corresponding to
516
553
the exercise and 'targets' corresponding to the physiological
517
554
measurements, as well as 'feature_names' and 'target_names'.
555
+
556
+ (data, target) : tuple if ``return_X_y`` is True
557
+
558
+ .. versionadded:: 0.18
518
559
"""
519
560
base_dir = join (dirname (__file__ ), 'data/' )
520
561
# Read data
@@ -529,13 +570,16 @@ def load_linnerud():
529
570
with open (dirname (__file__ ) + '/descr/linnerud.rst' ) as f :
530
571
descr = f .read ()
531
572
573
+ if return_X_y :
574
+ return data_exercise , data_physiological
575
+
532
576
return Bunch (data = data_exercise , feature_names = header_exercise ,
533
577
target = data_physiological ,
534
578
target_names = header_physiological ,
535
579
DESCR = descr )
536
580
537
581
538
- def load_boston ():
582
+ def load_boston (return_X_y = False ):
539
583
"""Load and return the boston house-prices dataset (regression).
540
584
541
585
============== ==============
@@ -545,13 +589,25 @@ def load_boston():
545
589
Targets real 5. - 50.
546
590
============== ==============
547
591
592
+ Parameters
593
+ ----------
594
+ return_X_y : boolean, default=False.
595
+ If True, returns ``(data, target)`` instead of a Bunch object.
596
+ See below for more information about the `data` and `target` object.
597
+
598
+ .. versionadded:: 0.18
599
+
548
600
Returns
549
601
-------
550
602
data : Bunch
551
603
Dictionary-like object, the interesting attributes are:
552
604
'data', the data to learn, 'target', the regression targets,
553
605
and 'DESCR', the full description of the dataset.
554
606
607
+ (data, target) : tuple if ``return_X_y`` is True
608
+
609
+ .. versionadded:: 0.18
610
+
555
611
Examples
556
612
--------
557
613
>>> from sklearn.datasets import load_boston
@@ -580,6 +636,9 @@ def load_boston():
580
636
data [i ] = np .asarray (d [:- 1 ], dtype = np .float64 )
581
637
target [i ] = np .asarray (d [- 1 ], dtype = np .float64 )
582
638
639
+ if return_X_y :
640
+ return data , target
641
+
583
642
return Bunch (data = data ,
584
643
target = target ,
585
644
# last column is target value
0 commit comments