Complete-case analysis¶
Dropping the incomplete samples is the honest alternative to imputing them: it introduces no synthetic data, at the cost of sample size and of a bias whenever the views are not missing completely at random.
Complete-case handling: discard samples instead of imputing them.
- class polyview.imputation.drop.DropIncompleteSamples(*args: Any, **kwargs: Any)¶
Bases:
BaseEstimatorTransformer that drops the samples with too many missing views.
- Parameters:
max_missing_views (int, default=0) – Maximum number of missing views a sample may have and still be kept.
how ({"all", "any"}, default="all") – Passed to
missing_view_mask().
- support_mask_¶
Truefor the samples kept by the last call totransform().- Type:
ndarray of bool of shape (n_samples,)
- n_features_in_¶
Number of features of each view.
- Type:
list of int
- n_dropped_¶
Number of samples the last
transform()removed.- Type:
int
Notes
This is the one estimator of the module that changes
n_samples. It therefore does not belong in the middle of a supervisedPolyPipeline, whereywould no longer line up with the rows; apply it to the data (and toy) beforehand, or usesupport_mask_()to subsetyyourself. AMultiViewDatasetin gives a dataset out, with its labels subset for you.Examples
>>> import numpy as np >>> from polyview.imputation import DropIncompleteSamples >>> X1 = np.array([[1.0], [np.nan], [3.0]]) >>> X2 = np.array([[4.0], [5.0], [6.0]]) >>> dropper = DropIncompleteSamples() >>> kept = dropper.fit_transform([X1, X2]) >>> kept[0].ravel() array([1., 3.]) >>> dropper.n_dropped_ 1
- fit(views, y=None) DropIncompleteSamples¶
Record the shape of the views. Nothing is learned from the data.
- Parameters:
views (list of array-like or MultiViewDataset)
y (ignored)
- Return type:
self
- fit_transform(views, y=None)¶
Fit and immediately drop.
- Parameters:
views (list of array-like or MultiViewDataset)
y (ignored)
- Return type:
list of ndarray, or MultiViewDataset
- transform(views)¶
Return
viewswithout the samples that miss too many views.- Parameters:
views (list of array-like or MultiViewDataset)
- Return type:
list of ndarray, or MultiViewDataset
- polyview.imputation.drop.drop_missing_views(views, max_missing_views: int = 0, how: str = 'all', return_mask: bool = False) List[numpy.ndarray] | Tuple[List[numpy.ndarray], numpy.ndarray]¶
Keep only the samples that have enough observed views.
Complete-case analysis is the honest baseline for missing views: it introduces no synthetic data, at the cost of sample size and of a bias whenever the views are not missing completely at random.
- Parameters:
views (list of array-like or MultiViewDataset)
max_missing_views (int, default=0) – Maximum number of missing views a sample may have and still be kept.
0keeps only fully observed samples.how ({"all", "any"}, default="all") – Passed to
missing_view_mask(): whether a view counts as missing only when the whole row isNaN, or as soon as one entry is.return_mask (bool, default=False) – Also return the boolean mask of the kept samples.
- Returns:
views_out (list of ndarray) – The views restricted to the kept samples.
support (ndarray of bool of shape (n_samples,)) – Only when
return_mask=True.Truefor kept samples.
Examples
>>> import numpy as np >>> from polyview.imputation import drop_missing_views >>> X1 = np.array([[1.0], [np.nan], [3.0]]) >>> X2 = np.array([[4.0], [5.0], [6.0]]) >>> kept, support = drop_missing_views([X1, X2], return_mask=True) >>> support array([ True, False, True]) >>> kept[0].ravel() array([1., 3.])