robpy 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of robpy might be problematic. Click here for more details.
- robpy/__init__.py +0 -0
- robpy/covariance/__init__.py +6 -0
- robpy/covariance/base.py +82 -0
- robpy/covariance/cellmcd.py +621 -0
- robpy/covariance/initial_ddcw.py +133 -0
- robpy/covariance/kendall.py +21 -0
- robpy/covariance/mcd.py +470 -0
- robpy/covariance/ogk.py +95 -0
- robpy/covariance/utils/alter_covariance.py +31 -0
- robpy/covariance/utils/cellmcd_utils.py +38 -0
- robpy/covariance/utils/cellmcd_visualization_utils.py +96 -0
- robpy/covariance/wrapping.py +72 -0
- robpy/datasets/__init__.py +4 -0
- robpy/datasets/base.py +389 -0
- robpy/datasets/data/animals.csv +66 -0
- robpy/datasets/data/glass.csv +181 -0
- robpy/datasets/data/stars.csv +48 -0
- robpy/datasets/data/telephone.csv +25 -0
- robpy/datasets/data/topgear.csv +298 -0
- robpy/datasets/descr/animals.rst +26 -0
- robpy/datasets/descr/glass.rst +20 -0
- robpy/datasets/descr/stars.rst +28 -0
- robpy/datasets/descr/telephone.rst +23 -0
- robpy/datasets/descr/topgear.rst +51 -0
- robpy/outliers/__init__.py +4 -0
- robpy/outliers/ddc.py +296 -0
- robpy/pca/__init__.py +3 -0
- robpy/pca/base.py +97 -0
- robpy/pca/robpca.py +89 -0
- robpy/pca/spca.py +48 -0
- robpy/preprocessing/__init__.py +3 -0
- robpy/preprocessing/data_cleaner.py +214 -0
- robpy/preprocessing/scaling.py +57 -0
- robpy/preprocessing/transfo.py +591 -0
- robpy/preprocessing/utils.py +63 -0
- robpy/regression/__init__.py +3 -0
- robpy/regression/base.py +116 -0
- robpy/regression/lts.py +408 -0
- robpy/regression/mm_estimator.py +57 -0
- robpy/regression/s_estimator.py +188 -0
- robpy/univariate/__init__.py +9 -0
- robpy/univariate/base.py +53 -0
- robpy/univariate/mcd.py +84 -0
- robpy/univariate/onestep_m.py +143 -0
- robpy/univariate/qn.py +112 -0
- robpy/univariate/tau.py +63 -0
- robpy/utils/distance.py +24 -0
- robpy/utils/general.py +31 -0
- robpy/utils/logging.py +22 -0
- robpy/utils/median.py +62 -0
- robpy/utils/outlyingness.py +61 -0
- robpy/utils/rho.py +35 -0
- robpy-0.1.0.dist-info/METADATA +31 -0
- robpy-0.1.0.dist-info/RECORD +55 -0
- robpy-0.1.0.dist-info/WHEEL +4 -0
robpy/datasets/base.py
ADDED
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import pathlib
|
|
2
|
+
import pandas as pd
|
|
3
|
+
import numpy as np
|
|
4
|
+
from sklearn.utils import Bunch
|
|
5
|
+
|
|
6
|
+
DATA_FOLDER = pathlib.Path(__file__).parent / "data"
|
|
7
|
+
DESCR_FOLDER = pathlib.Path(__file__).parent / "descr"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _load_data_and_descr(
|
|
11
|
+
data_file_name: str, descr_file_name: str, as_frame: bool, feature_names: list[str]
|
|
12
|
+
) -> tuple[pd.DataFrame | np.ndarray, str]:
|
|
13
|
+
"""Helper function to load data and description files.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
data_file_name (str): filename of the .csv file (must end in .csv)
|
|
17
|
+
descr_file_name (str): filename of the .rst file (must end in .rst)
|
|
18
|
+
as_frame (bool): whether data should be stored as a pandas DataFrame.
|
|
19
|
+
If False, it will be stored as a numpy array.
|
|
20
|
+
feature_names (list[str]): Columns to be selected, all other columns are ignored
|
|
21
|
+
|
|
22
|
+
Returns:
|
|
23
|
+
tuple[pd.DataFrame | np.ndarray, str]: The data matrix/dataframe and the description string
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
df = pd.read_csv(DATA_FOLDER / data_file_name)
|
|
27
|
+
|
|
28
|
+
with open(DESCR_FOLDER / descr_file_name, "r") as f:
|
|
29
|
+
fdescr = f.read()
|
|
30
|
+
|
|
31
|
+
data = df[feature_names]
|
|
32
|
+
|
|
33
|
+
if not as_frame:
|
|
34
|
+
data = data.values
|
|
35
|
+
|
|
36
|
+
return data, fdescr
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def load_telephone(*, as_frame=False):
|
|
40
|
+
"""Load and return the telephone dataset (regression with outliers).
|
|
41
|
+
|
|
42
|
+
The telephone dataset is well-known univariate regression problem with outliers.
|
|
43
|
+
|
|
44
|
+
================= ==============
|
|
45
|
+
Samples 24
|
|
46
|
+
Dimensionality 2
|
|
47
|
+
Features real, positive
|
|
48
|
+
================= ==============
|
|
49
|
+
|
|
50
|
+
Parameters
|
|
51
|
+
----------
|
|
52
|
+
as_frame : bool, default=False
|
|
53
|
+
If True, the data is a pandas DataFrame including columns with
|
|
54
|
+
appropriate dtypes (numeric). The target is
|
|
55
|
+
a pandas DataFrame or Series depending on the number of target columns.
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
Returns
|
|
59
|
+
-------
|
|
60
|
+
data : :class:`~sklearn.utils.Bunch`
|
|
61
|
+
Dictionary-like object, with the following attributes.
|
|
62
|
+
|
|
63
|
+
data : {ndarray, dataframe} of shape (24, 2)
|
|
64
|
+
The data matrix. If `as_frame=True`, `data` will be a pandas
|
|
65
|
+
DataFrame.
|
|
66
|
+
feature_names: list
|
|
67
|
+
The names of the dataset columns.
|
|
68
|
+
DESCR: str
|
|
69
|
+
The full description of the dataset.
|
|
70
|
+
filename: str
|
|
71
|
+
The path to the location of the data.
|
|
72
|
+
|
|
73
|
+
Examples
|
|
74
|
+
--------
|
|
75
|
+
Fitting a robust regression
|
|
76
|
+
|
|
77
|
+
>>> from robpy.datasets import load_telephone
|
|
78
|
+
>>> from robpy.regression import MMEstimator
|
|
79
|
+
>>> data = load_telephone()
|
|
80
|
+
>>> mm = MMEstimator().fit(data.data[:, 0], data.data[:, 1])
|
|
81
|
+
"""
|
|
82
|
+
data_file_name = "telephone.csv"
|
|
83
|
+
descr_file_name = "telephone.rst"
|
|
84
|
+
|
|
85
|
+
feature_names = ["Year", "Calls"]
|
|
86
|
+
data, fdescr = _load_data_and_descr(
|
|
87
|
+
data_file_name, descr_file_name, as_frame=as_frame, feature_names=feature_names
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
return Bunch(
|
|
91
|
+
data=data,
|
|
92
|
+
DESCR=fdescr,
|
|
93
|
+
feature_names=feature_names,
|
|
94
|
+
filename=data_file_name,
|
|
95
|
+
data_folder=DATA_FOLDER,
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def load_stars(*, as_frame=False):
|
|
100
|
+
"""Load and return the Hertzsprung-Russell Diagram Data of Star Cluster CYG OB1
|
|
101
|
+
(covariance/regression).
|
|
102
|
+
|
|
103
|
+
The stars dataset is well-known bivariate dataset used for demonstrating
|
|
104
|
+
robust covariance and regression estimators.
|
|
105
|
+
|
|
106
|
+
================= ==============
|
|
107
|
+
Samples 47
|
|
108
|
+
Dimensionality 2
|
|
109
|
+
Features real, positive
|
|
110
|
+
================= ==============
|
|
111
|
+
|
|
112
|
+
Parameters
|
|
113
|
+
----------
|
|
114
|
+
|
|
115
|
+
as_frame : bool, default=False
|
|
116
|
+
If True, the data is a pandas DataFrame including columns with
|
|
117
|
+
appropriate dtypes (numeric).
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
Returns
|
|
121
|
+
-------
|
|
122
|
+
data : :class:`~sklearn.utils.Bunch`
|
|
123
|
+
Dictionary-like object, with the following attributes.
|
|
124
|
+
|
|
125
|
+
data : {ndarray, dataframe} of shape (47, 2)
|
|
126
|
+
The data matrix. If `as_frame=True`, `data` will be a pandas
|
|
127
|
+
DataFrame.
|
|
128
|
+
feature_names: list
|
|
129
|
+
The names of the dataset columns.
|
|
130
|
+
DESCR: str
|
|
131
|
+
The full description of the dataset.
|
|
132
|
+
filename: str
|
|
133
|
+
The path to the location of the data.
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
Examples
|
|
137
|
+
--------
|
|
138
|
+
Fitting a robust covariance estimator
|
|
139
|
+
|
|
140
|
+
>>> from robpy.datasets import load_stars
|
|
141
|
+
>>> from robpy.covariance import FastMCDEstimator
|
|
142
|
+
>>> data = load_stars()
|
|
143
|
+
>>> mcd = FastMCDEstimator().fit(data.data)
|
|
144
|
+
"""
|
|
145
|
+
data_file_name = "stars.csv"
|
|
146
|
+
descr_file_name = "stars.rst"
|
|
147
|
+
|
|
148
|
+
feature_names = ["Te", "light"]
|
|
149
|
+
|
|
150
|
+
data, fdescr = _load_data_and_descr(data_file_name, descr_file_name, as_frame, feature_names)
|
|
151
|
+
|
|
152
|
+
return Bunch(
|
|
153
|
+
data=data,
|
|
154
|
+
DESCR=fdescr,
|
|
155
|
+
feature_names=feature_names,
|
|
156
|
+
filename=data_file_name,
|
|
157
|
+
data_folder=DATA_FOLDER,
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def load_animals(*, as_frame=False):
|
|
162
|
+
"""Load and return the Animals2 dataset from robustbase (R) (covariance / regression).
|
|
163
|
+
|
|
164
|
+
The animals dataset is a bivariate dataset used for demonstrating robust covariance estimators.
|
|
165
|
+
|
|
166
|
+
================= ==============
|
|
167
|
+
Samples 65
|
|
168
|
+
Dimensionality 2
|
|
169
|
+
Features real, positive
|
|
170
|
+
================= ==============
|
|
171
|
+
|
|
172
|
+
Parameters
|
|
173
|
+
----------
|
|
174
|
+
|
|
175
|
+
as_frame : bool, default=False
|
|
176
|
+
If True, the data is a pandas DataFrame including columns with
|
|
177
|
+
appropriate dtypes (numeric).
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
Returns
|
|
181
|
+
-------
|
|
182
|
+
data : :class:`~sklearn.utils.Bunch`
|
|
183
|
+
Dictionary-like object, with the following attributes.
|
|
184
|
+
|
|
185
|
+
data : {ndarray, dataframe} of shape (65, 2)
|
|
186
|
+
The data matrix. If `as_frame=True`, `data` will be a pandas
|
|
187
|
+
DataFrame.
|
|
188
|
+
feature_names: list
|
|
189
|
+
The names of the dataset columns.
|
|
190
|
+
DESCR: str
|
|
191
|
+
The full description of the dataset.
|
|
192
|
+
filename: str
|
|
193
|
+
The path to the location of the data.
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
Examples
|
|
197
|
+
--------
|
|
198
|
+
Fitting a robust covariance estimator
|
|
199
|
+
|
|
200
|
+
>>> from robpy.datasets import load_animals
|
|
201
|
+
>>> from robpy.covariance import FastMCDEstimator
|
|
202
|
+
>>> data = load_animals()
|
|
203
|
+
>>> mcd = FastMCDEstimator().fit(data.data)
|
|
204
|
+
"""
|
|
205
|
+
data_file_name = "animals.csv"
|
|
206
|
+
descr_file_name = "animals.rst"
|
|
207
|
+
|
|
208
|
+
feature_names = ["body", "brain"]
|
|
209
|
+
|
|
210
|
+
data, fdescr = _load_data_and_descr(data_file_name, descr_file_name, as_frame, feature_names)
|
|
211
|
+
|
|
212
|
+
return Bunch(
|
|
213
|
+
data=data,
|
|
214
|
+
DESCR=fdescr,
|
|
215
|
+
feature_names=feature_names,
|
|
216
|
+
filename=data_file_name,
|
|
217
|
+
data_folder=DATA_FOLDER,
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def load_topgear(*, as_frame=False):
|
|
222
|
+
"""Load and return the TopGear dataset from robustHD (R) (regression).
|
|
223
|
+
|
|
224
|
+
The TopGear dataset is a mixed variable dataset used for demonstrating
|
|
225
|
+
robust regression estimators.
|
|
226
|
+
|
|
227
|
+
================= ==============
|
|
228
|
+
Samples 297
|
|
229
|
+
Dimensionality 32
|
|
230
|
+
Features mixed
|
|
231
|
+
================= ==============
|
|
232
|
+
|
|
233
|
+
Parameters
|
|
234
|
+
----------
|
|
235
|
+
|
|
236
|
+
as_frame : bool, default=False
|
|
237
|
+
If True, the data is a pandas DataFrame including columns with
|
|
238
|
+
appropriate dtypes (numeric).
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
Returns
|
|
242
|
+
-------
|
|
243
|
+
data : :class:`~sklearn.utils.Bunch`
|
|
244
|
+
Dictionary-like object, with the following attributes.
|
|
245
|
+
|
|
246
|
+
data : {ndarray, dataframe} of shape (297, 32)
|
|
247
|
+
The data matrix. If `as_frame=True`, `data` will be a pandas
|
|
248
|
+
DataFrame.
|
|
249
|
+
feature_names: list
|
|
250
|
+
The names of the dataset columns.
|
|
251
|
+
categorical_features: list
|
|
252
|
+
The names of the categorical features.
|
|
253
|
+
DESCR: str
|
|
254
|
+
The full description of the dataset.
|
|
255
|
+
filename: str
|
|
256
|
+
The path to the location of the data.
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
Examples
|
|
260
|
+
--------
|
|
261
|
+
Fitting a robust regression estimator
|
|
262
|
+
|
|
263
|
+
>>> from robpy.datasets import load_topgear
|
|
264
|
+
>>> from robpy.regression import FastLTSRegressor
|
|
265
|
+
>>> data = load_topgear(as_frame=True)
|
|
266
|
+
>>> data.data = data.data.dropna(subset=["Cylinders", "Torque", "TopSpeed", "Price"])
|
|
267
|
+
>>> lts = FastLTSRegressor().fit(
|
|
268
|
+
data.data[["Cylinders", "Torque", "TopSpeed"]], data.data["Price"]
|
|
269
|
+
)
|
|
270
|
+
"""
|
|
271
|
+
data_file_name = "topgear.csv"
|
|
272
|
+
desc_file_name = "topgear.rst"
|
|
273
|
+
|
|
274
|
+
feature_names = [
|
|
275
|
+
"Maker",
|
|
276
|
+
"Model",
|
|
277
|
+
"Type",
|
|
278
|
+
"Fuel",
|
|
279
|
+
"Price",
|
|
280
|
+
"Cylinders",
|
|
281
|
+
"Displacement",
|
|
282
|
+
"DriveWheel",
|
|
283
|
+
"BHP",
|
|
284
|
+
"Torque",
|
|
285
|
+
"Acceleration",
|
|
286
|
+
"TopSpeed",
|
|
287
|
+
"MPG",
|
|
288
|
+
"Weight",
|
|
289
|
+
"Length",
|
|
290
|
+
"Width",
|
|
291
|
+
"Height",
|
|
292
|
+
"AdaptiveHeadlights",
|
|
293
|
+
"AdjustableSteering",
|
|
294
|
+
"AlarmSystem",
|
|
295
|
+
"Automatic",
|
|
296
|
+
"Bluetooth",
|
|
297
|
+
"ClimateControl",
|
|
298
|
+
"CruiseControl",
|
|
299
|
+
"ElectricSeats",
|
|
300
|
+
"Leather",
|
|
301
|
+
"ParkingSensors",
|
|
302
|
+
"PowerSteering",
|
|
303
|
+
"SatNav",
|
|
304
|
+
"ESP",
|
|
305
|
+
"Verdict",
|
|
306
|
+
"Origin",
|
|
307
|
+
]
|
|
308
|
+
categorical_features = [
|
|
309
|
+
"Maker",
|
|
310
|
+
"Model",
|
|
311
|
+
"Type",
|
|
312
|
+
"Fuel",
|
|
313
|
+
"DriveWheel",
|
|
314
|
+
"AdaptiveHeadlights",
|
|
315
|
+
"AdjustableSteering",
|
|
316
|
+
"AlarmSystem",
|
|
317
|
+
"Automatic",
|
|
318
|
+
"Bluetooth",
|
|
319
|
+
"ClimateControl",
|
|
320
|
+
"CruiseControl",
|
|
321
|
+
"ElectricSeats",
|
|
322
|
+
"Leather",
|
|
323
|
+
"ParkingSensors",
|
|
324
|
+
"PowerSteering",
|
|
325
|
+
"SatNav",
|
|
326
|
+
"ESP",
|
|
327
|
+
"Origin",
|
|
328
|
+
]
|
|
329
|
+
|
|
330
|
+
data, fdescr = _load_data_and_descr(data_file_name, desc_file_name, as_frame, feature_names)
|
|
331
|
+
|
|
332
|
+
return Bunch(
|
|
333
|
+
data=data,
|
|
334
|
+
DESCR=fdescr,
|
|
335
|
+
feature_names=feature_names,
|
|
336
|
+
categorical_features=categorical_features,
|
|
337
|
+
filename=data_file_name,
|
|
338
|
+
data_folder=DATA_FOLDER,
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
def load_glass(*, as_frame=False):
|
|
343
|
+
"""Load and return the glass dataset from cellWise (R) (outlier detection).
|
|
344
|
+
|
|
345
|
+
The glass dataset is a high dimensional dataset used for demonstrating outlier detectors.
|
|
346
|
+
|
|
347
|
+
================= ==============
|
|
348
|
+
Samples 180
|
|
349
|
+
Dimensionality 750
|
|
350
|
+
Features real, positive
|
|
351
|
+
================= ==============
|
|
352
|
+
|
|
353
|
+
Parameters
|
|
354
|
+
----------
|
|
355
|
+
|
|
356
|
+
as_frame : bool, default=False
|
|
357
|
+
If True, the data is a pandas DataFrame including columns with
|
|
358
|
+
appropriate dtypes (numeric).
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
Returns
|
|
362
|
+
-------
|
|
363
|
+
data : :class:`~sklearn.utils.Bunch`
|
|
364
|
+
Dictionary-like object, with the following attributes.
|
|
365
|
+
|
|
366
|
+
data : {ndarray, dataframe} of shape (65, 2)
|
|
367
|
+
The data matrix. If `as_frame=True`, `data` will be a pandas
|
|
368
|
+
DataFrame.
|
|
369
|
+
feature_names: list
|
|
370
|
+
The names of the dataset columns.
|
|
371
|
+
DESCR: str
|
|
372
|
+
The full description of the dataset.
|
|
373
|
+
filename: str
|
|
374
|
+
The path to the location of the data.
|
|
375
|
+
"""
|
|
376
|
+
data_file_name = "glass.csv"
|
|
377
|
+
descr_file_name = "glass.rst"
|
|
378
|
+
|
|
379
|
+
feature_names = [f"V{i}" for i in range(1, 751)]
|
|
380
|
+
|
|
381
|
+
data, fdescr = _load_data_and_descr(data_file_name, descr_file_name, as_frame, feature_names)
|
|
382
|
+
|
|
383
|
+
return Bunch(
|
|
384
|
+
data=data,
|
|
385
|
+
DESCR=fdescr,
|
|
386
|
+
feature_names=feature_names,
|
|
387
|
+
filename=data_file_name,
|
|
388
|
+
data_folder=DATA_FOLDER,
|
|
389
|
+
)
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"body","brain"
|
|
2
|
+
1.35,8.1
|
|
3
|
+
465,423
|
|
4
|
+
36.33,119.5
|
|
5
|
+
27.66,115
|
|
6
|
+
1.04,5.5
|
|
7
|
+
11700,50
|
|
8
|
+
2547,4603
|
|
9
|
+
187.1,419
|
|
10
|
+
521,655
|
|
11
|
+
10,115
|
|
12
|
+
3.3,25.6
|
|
13
|
+
529,680
|
|
14
|
+
207,406
|
|
15
|
+
62,1320
|
|
16
|
+
6654,5712
|
|
17
|
+
9400,70
|
|
18
|
+
6.8,179
|
|
19
|
+
35,56
|
|
20
|
+
0.12,1
|
|
21
|
+
0.023,0.4
|
|
22
|
+
2.5,12.1
|
|
23
|
+
55.5,175
|
|
24
|
+
100,157
|
|
25
|
+
52.16,440
|
|
26
|
+
0.28,1.9
|
|
27
|
+
87000,154.5
|
|
28
|
+
0.122,3
|
|
29
|
+
192,180
|
|
30
|
+
3.385,44.5
|
|
31
|
+
0.48,15.5
|
|
32
|
+
14.83,98.2
|
|
33
|
+
4.19,58
|
|
34
|
+
0.425,6.4
|
|
35
|
+
0.101,4
|
|
36
|
+
0.92,5.7
|
|
37
|
+
1,6.6
|
|
38
|
+
0.005,0.14
|
|
39
|
+
0.06,1
|
|
40
|
+
3.5,10.8
|
|
41
|
+
2,12.3
|
|
42
|
+
1.7,6.3
|
|
43
|
+
0.023,0.3
|
|
44
|
+
0.785,3.5
|
|
45
|
+
0.2,5
|
|
46
|
+
1.41,17.5
|
|
47
|
+
85,325
|
|
48
|
+
0.75,12.3
|
|
49
|
+
3.5,3.9
|
|
50
|
+
4.05,17
|
|
51
|
+
0.01,0.25
|
|
52
|
+
1.4,12.5
|
|
53
|
+
250,490
|
|
54
|
+
10.55,179.5
|
|
55
|
+
0.55,2.4
|
|
56
|
+
60,81
|
|
57
|
+
3.6,21
|
|
58
|
+
4.288,39.2
|
|
59
|
+
0.075,1.2
|
|
60
|
+
0.048,0.33
|
|
61
|
+
3,25
|
|
62
|
+
160,169
|
|
63
|
+
0.9,2.6
|
|
64
|
+
1.62,11.4
|
|
65
|
+
0.104,2.5
|
|
66
|
+
4.235,50.4
|