diff --git a/client/src/features/packageData/model/PythonClass.test.ts b/client/src/features/packageData/model/PythonClass.test.ts index 2fef5b9de..324267b65 100644 --- a/client/src/features/packageData/model/PythonClass.test.ts +++ b/client/src/features/packageData/model/PythonClass.test.ts @@ -27,7 +27,16 @@ test('getByRelativePath with correct path', () => { 'Class', [], [], - [new PythonFunction('function', 'function', [], [pythonParameter])], + [ + new PythonFunction( + 'function', + 'function', + 'function', + 'function', + [], + [pythonParameter], + ), + ], ); expect(pythonClass.getByRelativePath(['function', 'param'])).toBe( pythonParameter, diff --git a/client/src/features/packageData/model/PythonDeclaration.ts b/client/src/features/packageData/model/PythonDeclaration.ts index 6009f1795..3cc679cee 100644 --- a/client/src/features/packageData/model/PythonDeclaration.ts +++ b/client/src/features/packageData/model/PythonDeclaration.ts @@ -8,12 +8,16 @@ export default abstract class PythonDeclaration { abstract children(): PythonDeclaration[]; + getUniqueName(): string { + return this.name; + } + path(): string[] { let current: Optional = this; const result: string[] = []; while (current !== null && current !== undefined) { - result.unshift(current.name); + result.unshift(current.getUniqueName()); current = current.parent(); } @@ -32,7 +36,7 @@ export default abstract class PythonDeclaration { const [head, ...tail] = relativePath; return ( this.children() - .find((it) => it.name === head) + .find((it) => it.getUniqueName() === head) ?.getByRelativePath(tail) ?? null ); } diff --git a/client/src/features/packageData/model/PythonFunction.test.ts b/client/src/features/packageData/model/PythonFunction.test.ts index cd37afea0..93fa9fab9 100644 --- a/client/src/features/packageData/model/PythonFunction.test.ts +++ b/client/src/features/packageData/model/PythonFunction.test.ts @@ -5,12 +5,22 @@ import PythonPackage from './PythonPackage'; import PythonParameter from './PythonParameter'; test('path without parent', () => { - const pythonFunction = new PythonFunction('function', 'function'); + const pythonFunction = new PythonFunction( + 'function', + 'function', + 'function', + 'function', + ); expect(pythonFunction.path()).toEqual(['function']); }); test('path with ancestors', () => { - const pythonFunction = new PythonFunction('function', 'function'); + const pythonFunction = new PythonFunction( + 'function', + 'function', + 'function', + 'function', + ); // eslint-disable-next-line no-new new PythonPackage('distribution', 'package', '0.0.1', [ @@ -33,6 +43,8 @@ test('path with ancestors', () => { test('getByRelativePath with correct path', () => { const pythonParameter = new PythonParameter('param'); const pythonFunction = new PythonFunction( + 'function', + 'function', 'function', 'function', [], @@ -42,18 +54,30 @@ test('getByRelativePath with correct path', () => { }); test('getByRelativePath with misleading path', () => { - const pythonFunction = new PythonFunction('function', 'function'); + const pythonFunction = new PythonFunction( + 'function', + 'function', + 'function', + 'function', + ); // eslint-disable-next-line testing-library/prefer-presence-queries expect(pythonFunction.getByRelativePath(['child'])).toBeNull(); }); test('toString without decorators and parameters', () => { - const pythonFunction = new PythonFunction('function', 'function'); + const pythonFunction = new PythonFunction( + 'function', + 'function', + 'function', + 'function', + ); expect(pythonFunction.toString()).toBe('def function()'); }); test('toString with decorators and parameters', () => { const pythonFunction = new PythonFunction( + 'function', + 'function', 'function', 'function', ['deco1', 'deco2'], diff --git a/client/src/features/packageData/model/PythonFunction.ts b/client/src/features/packageData/model/PythonFunction.ts index 518622d54..62e9b03e4 100644 --- a/client/src/features/packageData/model/PythonFunction.ts +++ b/client/src/features/packageData/model/PythonFunction.ts @@ -8,7 +8,9 @@ import PythonResult from './PythonResult'; export default class PythonFunction extends PythonDeclaration { readonly name: string; + readonly uniqueName: string; readonly qualifiedName: string; + readonly uniqueQualifiedName: string; readonly decorators: string[]; readonly parameters: PythonParameter[]; readonly results: PythonResult[]; @@ -19,7 +21,9 @@ export default class PythonFunction extends PythonDeclaration { constructor( name: string, + uniqueName: string, qualifiedName: string, + uniqueQualifiedName: string, decorators: string[] = [], parameters: PythonParameter[] = [], results: PythonResult[] = [], @@ -30,7 +34,9 @@ export default class PythonFunction extends PythonDeclaration { super(); this.name = name; + this.uniqueName = uniqueName; this.qualifiedName = qualifiedName; + this.uniqueQualifiedName = uniqueQualifiedName; this.decorators = decorators; this.parameters = parameters; this.results = results; @@ -56,6 +62,22 @@ export default class PythonFunction extends PythonDeclaration { return this.parameters; } + getUniqueName(): string { + return this.uniqueName; + } + + isGetter(): boolean { + return this.decorators.includes('property'); + } + + isSetter(): boolean { + return this.decorators.some((it) => /[^.]*.setter/u.test(it)); + } + + isDeleter(): boolean { + return this.decorators.some((it) => /[^.]*.deleter/u.test(it)); + } + explicitParameters(): PythonParameter[] { if (this.parent() instanceof PythonModule) { return this.children(); @@ -109,7 +131,9 @@ export default class PythonFunction extends PythonDeclaration { return new PythonFunction( this.name, + this.uniqueName, this.qualifiedName, + this.uniqueQualifiedName, this.decorators, parameters, results, diff --git a/client/src/features/packageData/model/PythonModule.test.ts b/client/src/features/packageData/model/PythonModule.test.ts index 9d71150f0..f582dd9dc 100644 --- a/client/src/features/packageData/model/PythonModule.test.ts +++ b/client/src/features/packageData/model/PythonModule.test.ts @@ -24,7 +24,16 @@ test('getByRelativePath with correct path', () => { [], [], [], - [new PythonFunction('function', 'function', [], [pythonParameter])], + [ + new PythonFunction( + 'function', + 'function', + 'function', + 'function', + [], + [pythonParameter], + ), + ], ); expect(pythonModule.getByRelativePath(['function', 'param'])).toBe( pythonParameter, diff --git a/client/src/features/packageData/model/PythonPackageBuilder.ts b/client/src/features/packageData/model/PythonPackageBuilder.ts index 0029299c4..c946da318 100644 --- a/client/src/features/packageData/model/PythonPackageBuilder.ts +++ b/client/src/features/packageData/model/PythonPackageBuilder.ts @@ -24,7 +24,7 @@ export const parsePythonPackageJson = function ( const functions = new Map( packageJson.functions .map(parsePythonFunctionJson) - .map((it) => [it.qualifiedName, it]), + .map((it) => [it.uniqueQualifiedName, it]), ); // Classes @@ -79,12 +79,14 @@ const parsePythonModuleJson = function ( ), moduleJson.functions .sort((a, b) => a.localeCompare(b)) - .filter((functionQualifiedName) => - functions.has(functionQualifiedName), + .filter((functionUniqueQualifiedName) => + functions.has(functionUniqueQualifiedName), ) .map( - (functionQualifiedName) => - functions.get(functionQualifiedName) as PythonFunction, + (functionUniqueQualifiedName) => + functions.get( + functionUniqueQualifiedName, + ) as PythonFunction, ), ); }; @@ -139,12 +141,14 @@ const parsePythonClassJson = function ( classJson.superclasses, classJson.methods .sort((a, b) => a.localeCompare(b)) - .filter((functionQualifiedName) => - functions.has(functionQualifiedName), + .filter((functionUniqueQualifiedName) => + functions.has(functionUniqueQualifiedName), ) .map( - (functionQualifiedName) => - functions.get(functionQualifiedName) as PythonFunction, + (functionUniqueQualifiedName) => + functions.get( + functionUniqueQualifiedName, + ) as PythonFunction, ), classJson.description ?? '', classJson.docstring ?? '', @@ -153,7 +157,9 @@ const parsePythonClassJson = function ( interface PythonFunctionJson { name: string; + unique_name: string; qname: string; + unique_qname: string; decorators: string[]; parameters: PythonParameterJson[]; results: PythonResultJson[]; @@ -168,7 +174,9 @@ const parsePythonFunctionJson = function ( ): PythonFunction { return new PythonFunction( functionJson.name, + functionJson.unique_name, functionJson.qname, + functionJson.unique_qname, functionJson.decorators, functionJson.parameters.map(parsePythonParameterJson), functionJson.results.map(parsePythonResultJson), diff --git a/client/src/features/packageData/model/PythonParameter.test.ts b/client/src/features/packageData/model/PythonParameter.test.ts index 3d71e803b..f2fd50713 100644 --- a/client/src/features/packageData/model/PythonParameter.test.ts +++ b/client/src/features/packageData/model/PythonParameter.test.ts @@ -26,6 +26,8 @@ test('path with ancestors', () => { [], [ new PythonFunction( + 'function', + 'function', 'function', 'function', [], diff --git a/client/src/features/packageData/model/PythonResult.test.ts b/client/src/features/packageData/model/PythonResult.test.ts index da2d32b5a..0622402f3 100644 --- a/client/src/features/packageData/model/PythonResult.test.ts +++ b/client/src/features/packageData/model/PythonResult.test.ts @@ -26,6 +26,8 @@ test('path with ancestors', () => { [], [ new PythonFunction( + 'function', + 'function', 'function', 'function', [], diff --git a/client/src/features/packageData/treeView/TreeNode.tsx b/client/src/features/packageData/treeView/TreeNode.tsx index 428fb6ad0..5fdd66d22 100644 --- a/client/src/features/packageData/treeView/TreeNode.tsx +++ b/client/src/features/packageData/treeView/TreeNode.tsx @@ -60,7 +60,7 @@ const TreeNode: React.FC = function ({ isSelected={isSelected(declaration, currentPathname)} /> - {declaration.name} + {declaration.getUniqueName()} ); }; diff --git a/data/scikit-learn__sklearn__1.0__api.json b/data/scikit-learn__sklearn__1.0.1__api.json similarity index 91% rename from data/scikit-learn__sklearn__1.0__api.json rename to data/scikit-learn__sklearn__1.0.1__api.json index 04bd6c172..041a547e7 100644 --- a/data/scikit-learn__sklearn__1.0__api.json +++ b/data/scikit-learn__sklearn__1.0.1__api.json @@ -1,7 +1,7 @@ { "distribution": "scikit-learn", "package": "sklearn", - "version": "1.0", + "version": "1.0.1", "modules": [ { "name": "sklearn", @@ -1291,16 +1291,6 @@ } ], "from_imports": [ - { - "module": "threadpoolctl", - "declaration": "threadpool_limits", - "alias": null - }, - { - "module": "threadpoolctl", - "declaration": "threadpool_info", - "alias": null - }, { "module": "sklearn.base", "declaration": "BaseEstimator", @@ -1336,6 +1326,16 @@ "declaration": "stable_cumsum", "alias": null }, + { + "module": "sklearn.utils.fixes", + "declaration": "threadpool_limits", + "alias": null + }, + { + "module": "sklearn.utils.fixes", + "declaration": "threadpool_info", + "alias": null + }, { "module": "sklearn.utils.sparsefuncs_fast", "declaration": "assign_rows_csr", @@ -1401,6 +1401,11 @@ "declaration": "_inertia_sparse", "alias": null }, + { + "module": "sklearn.cluster._k_means_common", + "declaration": "_is_same_clustering", + "alias": null + }, { "module": "sklearn.cluster._k_means_minibatch", "declaration": "_minibatch_update_dense", @@ -5714,6 +5719,11 @@ "module": "sklearn.utils.validation", "declaration": "_check_sample_weight", "alias": null + }, + { + "module": "sklearn.utils.validation", + "declaration": "_num_samples", + "alias": null } ], "classes": [ @@ -7085,21 +7095,6 @@ } ], "from_imports": [ - { - "module": "__future__", - "declaration": "division", - "alias": null - }, - { - "module": "__future__", - "declaration": "print_function", - "alias": null - }, - { - "module": "__future__", - "declaration": "absolute_import", - "alias": null - }, { "module": "scipy.linalg", "declaration": "inv", @@ -7125,11 +7120,6 @@ "declaration": "cholesky", "alias": null }, - { - "module": "scipy.linalg", - "declaration": "orth", - "alias": null - }, { "module": "scipy.linalg", "declaration": "LinAlgError", @@ -7139,12 +7129,15 @@ "module": "scipy.sparse.linalg", "declaration": "aslinearoperator", "alias": null + }, + { + "module": "numpy", + "declaration": "block", + "alias": "bmat" } ], "classes": [], "functions": [ - "sklearn.externals._lobpcg.bmat", - "sklearn.externals._lobpcg._save", "sklearn.externals._lobpcg._report_nonhermitian", "sklearn.externals._lobpcg._as2d", "sklearn.externals._lobpcg._makeOperator", @@ -7263,24 +7256,6 @@ "sklearn.externals._packaging.version._cmpkey" ] }, - { - "name": "sklearn.externals._pep562", - "imports": [ - { - "module": "sys", - "alias": null - } - ], - "from_imports": [ - { - "module": "__future__", - "declaration": "unicode_literals", - "alias": null - } - ], - "classes": ["sklearn.externals._pep562.Pep562"], - "functions": [] - }, { "name": "sklearn.externals._pilutil", "imports": [ @@ -7295,21 +7270,6 @@ "declaration": "Image", "alias": null }, - { - "module": "__future__", - "declaration": "division", - "alias": null - }, - { - "module": "__future__", - "declaration": "print_function", - "alias": null - }, - { - "module": "__future__", - "declaration": "absolute_import", - "alias": null - }, { "module": "numpy", "declaration": "amin", @@ -7715,6 +7675,11 @@ "declaration": "FLOAT_DTYPES", "alias": null }, + { + "module": "sklearn.utils.validation", + "declaration": "check_scalar", + "alias": null + }, { "module": "sklearn.utils.deprecation", "declaration": "deprecated", @@ -12546,12 +12511,7 @@ }, { "name": "sklearn.metrics._plot.base", - "imports": [ - { - "module": "numpy", - "alias": "np" - } - ], + "imports": [], "from_imports": [ { "module": "sklearn.base", @@ -15478,11 +15438,6 @@ } ], "from_imports": [ - { - "module": "__future__", - "declaration": "print_function", - "alias": null - }, { "module": "warnings", "declaration": "warn", @@ -19016,6 +18971,10 @@ "module": "functools", "alias": null }, + { + "module": "sklearn", + "alias": null + }, { "module": "numpy", "alias": "np" @@ -19027,6 +18986,10 @@ { "module": "scipy", "alias": null + }, + { + "module": "threadpoolctl", + "alias": null } ], "from_imports": [ @@ -19071,7 +19034,10 @@ "sklearn.utils.fixes._joblib_parallel_args", "sklearn.utils.fixes._take_along_axis", "sklearn.utils.fixes.delayed", - "sklearn.utils.fixes.linspace" + "sklearn.utils.fixes.linspace", + "sklearn.utils.fixes._get_threadpool_controller", + "sklearn.utils.fixes.threadpool_limits", + "sklearn.utils.fixes.threadpool_info" ] }, { @@ -19622,8 +19588,8 @@ "superclasses": ["ExponentialDispersionModel"], "methods": [ "sklearn._loss.glm_distribution.TweedieDistribution.__init__", - "sklearn._loss.glm_distribution.TweedieDistribution.power", - "sklearn._loss.glm_distribution.TweedieDistribution.power", + "sklearn._loss.glm_distribution.TweedieDistribution.power@getter", + "sklearn._loss.glm_distribution.TweedieDistribution.power@setter", "sklearn._loss.glm_distribution.TweedieDistribution.unit_variance", "sklearn._loss.glm_distribution.TweedieDistribution.unit_deviance" ], @@ -19649,14 +19615,14 @@ "sklearn.base.BaseEstimator._check_n_features", "sklearn.base.BaseEstimator._check_feature_names", "sklearn.base.BaseEstimator._validate_data", - "sklearn.base.BaseEstimator._repr_html_", + "sklearn.base.BaseEstimator._repr_html_@getter", "sklearn.base.BaseEstimator._repr_html_inner", "sklearn.base.BaseEstimator._repr_mimebundle_" ], "is_public": true, "description": "Base class for all estimators in scikit-learn.", "docstring": "Base class for all estimators in scikit-learn.\n\n Notes\n -----\n All estimators should specify all the parameters that can be set\n at the class level in their ``__init__`` as explicit keyword\n arguments (no ``*args`` or ``**kwargs``).\n ", - "source_code": "\n\nclass BaseEstimator:\n \"\"\"Base class for all estimators in scikit-learn.\n\n Notes\n -----\n All estimators should specify all the parameters that can be set\n at the class level in their ``__init__`` as explicit keyword\n arguments (no ``*args`` or ``**kwargs``).\n \"\"\"\n \n @classmethod\n def _get_param_names(cls):\n \"\"\"Get parameter names for the estimator\"\"\"\n init = getattr(cls.__init__, 'deprecated_original', cls.__init__)\n if init is object.__init__:\n return []\n init_signature = inspect.signature(init)\n parameters = [p for p in init_signature.parameters.values() if p.name != 'self' and p.kind != p.VAR_KEYWORD]\n for p in parameters:\n if p.kind == p.VAR_POSITIONAL:\n raise RuntimeError(\"scikit-learn estimators should always specify their parameters in the signature of their __init__ (no varargs). %s with constructor %s doesn't follow this convention.\" % (cls, init_signature))\n return sorted([p.name for p in parameters])\n \n def get_params(self, deep=True):\n \"\"\"\n Get parameters for this estimator.\n\n Parameters\n ----------\n deep : bool, default=True\n If True, will return the parameters for this estimator and\n contained subobjects that are estimators.\n\n Returns\n -------\n params : dict\n Parameter names mapped to their values.\n \"\"\"\n out = dict()\n for key in self._get_param_names():\n value = getattr(self, key)\n if deep and hasattr(value, 'get_params'):\n deep_items = value.get_params().items()\n out.update(((key + '__' + k, val) for (k, val) in deep_items))\n out[key] = value\n return out\n \n def set_params(self, **params):\n \"\"\"\n Set the parameters of this estimator.\n\n The method works on simple estimators as well as on nested objects\n (such as :class:`~sklearn.pipeline.Pipeline`). The latter have\n parameters of the form ``__`` so that it's\n possible to update each component of a nested object.\n\n Parameters\n ----------\n **params : dict\n Estimator parameters.\n\n Returns\n -------\n self : estimator instance\n Estimator instance.\n \"\"\"\n if not params:\n return self\n valid_params = self.get_params(deep=True)\n nested_params = defaultdict(dict)\n for (key, value) in params.items():\n (key, delim, sub_key) = key.partition('__')\n if key not in valid_params:\n raise ValueError('Invalid parameter %s for estimator %s. Check the list of available parameters with `estimator.get_params().keys()`.' % (key, self))\n if delim:\n nested_params[key][sub_key] = value\n else:\n setattr(self, key, value)\n valid_params[key] = value\n for (key, sub_params) in nested_params.items():\n valid_params[key].set_params(**sub_params)\n return self\n \n def __repr__(self, N_CHAR_MAX=700):\n from .utils._pprint import _EstimatorPrettyPrinter\n N_MAX_ELEMENTS_TO_SHOW = 30\n pp = _EstimatorPrettyPrinter(compact=True, indent=1, indent_at_name=True, n_max_elements_to_show=N_MAX_ELEMENTS_TO_SHOW)\n repr_ = pp.pformat(self)\n n_nonblank = len(''.join(repr_.split()))\n if n_nonblank > N_CHAR_MAX:\n lim = N_CHAR_MAX // 2\n regex = '^(\\\\s*\\\\S){%d}' % lim\n left_lim = re.match(regex, repr_).end()\n right_lim = re.match(regex, repr_[::-1]).end()\n if '\\n' in repr_[left_lim:-right_lim]:\n regex += '[^\\\\n]*\\\\n'\n right_lim = re.match(regex, repr_[::-1]).end()\n ellipsis = '...'\n if left_lim + len(ellipsis) < len(repr_) - right_lim:\n repr_ = repr_[:left_lim] + '...' + repr_[-right_lim:]\n return repr_\n \n def __getstate__(self):\n try:\n state = super().__getstate__()\n except AttributeError:\n state = self.__dict__.copy()\n if type(self).__module__.startswith('sklearn.'):\n return dict(state.items(), _sklearn_version=__version__)\n else:\n return state\n \n def __setstate__(self, state):\n if type(self).__module__.startswith('sklearn.'):\n pickle_version = state.pop('_sklearn_version', 'pre-0.18')\n if pickle_version != __version__:\n warnings.warn('Trying to unpickle estimator {0} from version {1} when using version {2}. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:\\nhttps://scikit-learn.org/stable/modules/model_persistence.html#security-maintainability-limitations'.format(self.__class__.__name__, pickle_version, __version__), UserWarning)\n try:\n super().__setstate__(state)\n except AttributeError:\n self.__dict__.update(state)\n \n def _more_tags(self):\n return _DEFAULT_TAGS\n \n def _get_tags(self):\n collected_tags = {}\n for base_class in reversed(inspect.getmro(self.__class__)):\n if hasattr(base_class, '_more_tags'):\n more_tags = base_class._more_tags(self)\n collected_tags.update(more_tags)\n return collected_tags\n \n def _check_n_features(self, X, reset):\n \"\"\"Set the `n_features_in_` attribute, or check against it.\n\n Parameters\n ----------\n X : {ndarray, sparse matrix} of shape (n_samples, n_features)\n The input samples.\n reset : bool\n If True, the `n_features_in_` attribute is set to `X.shape[1]`.\n If False and the attribute exists, then check that it is equal to\n `X.shape[1]`. If False and the attribute does *not* exist, then\n the check is skipped.\n .. note::\n It is recommended to call reset=True in `fit` and in the first\n call to `partial_fit`. All other methods that validate `X`\n should set `reset=False`.\n \"\"\"\n try:\n n_features = _num_features(X)\n except TypeError as e:\n if not reset and hasattr(self, 'n_features_in_'):\n raise ValueError(f'X does not contain any features, but {self.__class__.__name__} is expecting {self.n_features_in_} features') from e\n return\n if reset:\n self.n_features_in_ = n_features\n return\n if not hasattr(self, 'n_features_in_'):\n return\n if n_features != self.n_features_in_:\n raise ValueError(f'X has {n_features} features, but {self.__class__.__name__} is expecting {self.n_features_in_} features as input.')\n \n def _check_feature_names(self, X, *, reset):\n \"\"\"Set or check the `feature_names_in_` attribute.\n\n .. versionadded:: 1.0\n\n Parameters\n ----------\n X : {ndarray, dataframe} of shape (n_samples, n_features)\n The input samples.\n\n reset : bool\n Whether to reset the `feature_names_in_` attribute.\n If False, the input will be checked for consistency with\n feature names of data provided when reset was last True.\n .. note::\n It is recommended to call `reset=True` in `fit` and in the first\n call to `partial_fit`. All other methods that validate `X`\n should set `reset=False`.\n \"\"\"\n if reset:\n feature_names_in = _get_feature_names(X)\n if feature_names_in is not None:\n self.feature_names_in_ = feature_names_in\n return\n fitted_feature_names = getattr(self, 'feature_names_in_', None)\n X_feature_names = _get_feature_names(X)\n if fitted_feature_names is None and X_feature_names is None:\n return\n if X_feature_names is not None and fitted_feature_names is None:\n warnings.warn(f'X has feature names, but {self.__class__.__name__} was fitted without feature names')\n return\n if X_feature_names is None and fitted_feature_names is not None:\n warnings.warn(f'X does not have valid feature names, but {self.__class__.__name__} was fitted with feature names')\n return\n if len(fitted_feature_names) != len(X_feature_names) or np.any(fitted_feature_names != X_feature_names):\n message = 'The feature names should match those that were passed during fit. Starting version 1.2, an error will be raised.\\n'\n fitted_feature_names_set = set(fitted_feature_names)\n X_feature_names_set = set(X_feature_names)\n unexpected_names = sorted(X_feature_names_set - fitted_feature_names_set)\n missing_names = sorted(fitted_feature_names_set - X_feature_names_set)\n \n def add_names(names):\n output = ''\n max_n_names = 5\n for (i, name) in enumerate(names):\n if i >= max_n_names:\n output += '- ...\\n'\n break\n output += f'- {name}\\n'\n return output\n if unexpected_names:\n message += 'Feature names unseen at fit time:\\n'\n message += add_names(unexpected_names)\n if missing_names:\n message += 'Feature names seen at fit time, yet now missing:\\n'\n message += add_names(missing_names)\n if not missing_names and not missing_names:\n message += 'Feature names must be in the same order as they were in fit.\\n'\n warnings.warn(message, FutureWarning)\n \n def _validate_data(self, X='no_validation', y='no_validation', reset=True, validate_separately=False, **check_params):\n \"\"\"Validate input data and set or check the `n_features_in_` attribute.\n\n Parameters\n ----------\n X : {array-like, sparse matrix, dataframe} of shape (n_samples, n_features), default='no validation'\n The input samples.\n If `'no_validation'`, no validation is performed on `X`. This is\n useful for meta-estimator which can delegate input validation to\n their underlying estimator(s). In that case `y` must be passed and\n the only accepted `check_params` are `multi_output` and\n `y_numeric`.\n\n y : array-like of shape (n_samples,), default='no_validation'\n The targets.\n\n - If `None`, `check_array` is called on `X`. If the estimator's\n requires_y tag is True, then an error will be raised.\n - If `'no_validation'`, `check_array` is called on `X` and the\n estimator's requires_y tag is ignored. This is a default\n placeholder and is never meant to be explicitly set. In that case\n `X` must be passed.\n - Otherwise, only `y` with `_check_y` or both `X` and `y` are\n checked with either `check_array` or `check_X_y` depending on\n `validate_separately`.\n\n reset : bool, default=True\n Whether to reset the `n_features_in_` attribute.\n If False, the input will be checked for consistency with data\n provided when reset was last True.\n .. note::\n It is recommended to call reset=True in `fit` and in the first\n call to `partial_fit`. All other methods that validate `X`\n should set `reset=False`.\n validate_separately : False or tuple of dicts, default=False\n Only used if y is not None.\n If False, call validate_X_y(). Else, it must be a tuple of kwargs\n to be used for calling check_array() on X and y respectively.\n **check_params : kwargs\n Parameters passed to :func:`sklearn.utils.check_array` or\n :func:`sklearn.utils.check_X_y`. Ignored if validate_separately\n is not False.\n\n Returns\n -------\n out : {ndarray, sparse matrix} or tuple of these\n The validated input. A tuple is returned if both `X` and `y` are\n validated.\n \"\"\"\n self._check_feature_names(X, reset=reset)\n if y is None and self._get_tags()['requires_y']:\n raise ValueError(f'This {self.__class__.__name__} estimator requires y to be passed, but the target y is None.')\n no_val_X = isinstance(X, str) and X == 'no_validation'\n no_val_y = y is None or isinstance(y, str) and y == 'no_validation'\n if no_val_X and no_val_y:\n raise ValueError('Validation should be done on X, y or both.')\n elif not no_val_X and no_val_y:\n X = check_array(X, **check_params)\n out = X\n elif no_val_X and not no_val_y:\n y = _check_y(y, **check_params)\n out = y\n else:\n if validate_separately:\n (check_X_params, check_y_params) = validate_separately\n X = check_array(X, **check_X_params)\n y = check_array(y, **check_y_params)\n else:\n (X, y) = check_X_y(X, y, **check_params)\n out = (X, y)\n if not no_val_X and check_params.get('ensure_2d', True):\n self._check_n_features(X, reset=reset)\n return out\n \n @property\n def _repr_html_(self):\n \"\"\"HTML representation of estimator.\n\n This is redundant with the logic of `_repr_mimebundle_`. The latter\n should be favorted in the long term, `_repr_html_` is only\n implemented for consumers who do not interpret `_repr_mimbundle_`.\n \"\"\"\n if get_config()['display'] != 'diagram':\n raise AttributeError(\"_repr_html_ is only defined when the 'display' configuration option is set to 'diagram'\")\n return self._repr_html_inner\n \n def _repr_html_inner(self):\n \"\"\"This function is returned by the @property `_repr_html_` to make\n `hasattr(estimator, \"_repr_html_\") return `True` or `False` depending\n on `get_config()[\"display\"]`.\n \"\"\"\n return estimator_html_repr(self)\n \n def _repr_mimebundle_(self, **kwargs):\n \"\"\"Mime bundle used by jupyter kernels to display estimator\"\"\"\n output = {'text/plain': repr(self)}\n if get_config()['display'] == 'diagram':\n output['text/html'] = estimator_html_repr(self)\n return output\n" + "source_code": "\n\nclass BaseEstimator:\n \"\"\"Base class for all estimators in scikit-learn.\n\n Notes\n -----\n All estimators should specify all the parameters that can be set\n at the class level in their ``__init__`` as explicit keyword\n arguments (no ``*args`` or ``**kwargs``).\n \"\"\"\n \n @classmethod\n def _get_param_names(cls):\n \"\"\"Get parameter names for the estimator\"\"\"\n init = getattr(cls.__init__, 'deprecated_original', cls.__init__)\n if init is object.__init__:\n return []\n init_signature = inspect.signature(init)\n parameters = [p for p in init_signature.parameters.values() if p.name != 'self' and p.kind != p.VAR_KEYWORD]\n for p in parameters:\n if p.kind == p.VAR_POSITIONAL:\n raise RuntimeError(\"scikit-learn estimators should always specify their parameters in the signature of their __init__ (no varargs). %s with constructor %s doesn't follow this convention.\" % (cls, init_signature))\n return sorted([p.name for p in parameters])\n \n def get_params(self, deep=True):\n \"\"\"\n Get parameters for this estimator.\n\n Parameters\n ----------\n deep : bool, default=True\n If True, will return the parameters for this estimator and\n contained subobjects that are estimators.\n\n Returns\n -------\n params : dict\n Parameter names mapped to their values.\n \"\"\"\n out = dict()\n for key in self._get_param_names():\n value = getattr(self, key)\n if deep and hasattr(value, 'get_params'):\n deep_items = value.get_params().items()\n out.update(((key + '__' + k, val) for (k, val) in deep_items))\n out[key] = value\n return out\n \n def set_params(self, **params):\n \"\"\"\n Set the parameters of this estimator.\n\n The method works on simple estimators as well as on nested objects\n (such as :class:`~sklearn.pipeline.Pipeline`). The latter have\n parameters of the form ``__`` so that it's\n possible to update each component of a nested object.\n\n Parameters\n ----------\n **params : dict\n Estimator parameters.\n\n Returns\n -------\n self : estimator instance\n Estimator instance.\n \"\"\"\n if not params:\n return self\n valid_params = self.get_params(deep=True)\n nested_params = defaultdict(dict)\n for (key, value) in params.items():\n (key, delim, sub_key) = key.partition('__')\n if key not in valid_params:\n raise ValueError('Invalid parameter %s for estimator %s. Check the list of available parameters with `estimator.get_params().keys()`.' % (key, self))\n if delim:\n nested_params[key][sub_key] = value\n else:\n setattr(self, key, value)\n valid_params[key] = value\n for (key, sub_params) in nested_params.items():\n valid_params[key].set_params(**sub_params)\n return self\n \n def __repr__(self, N_CHAR_MAX=700):\n from .utils._pprint import _EstimatorPrettyPrinter\n N_MAX_ELEMENTS_TO_SHOW = 30\n pp = _EstimatorPrettyPrinter(compact=True, indent=1, indent_at_name=True, n_max_elements_to_show=N_MAX_ELEMENTS_TO_SHOW)\n repr_ = pp.pformat(self)\n n_nonblank = len(''.join(repr_.split()))\n if n_nonblank > N_CHAR_MAX:\n lim = N_CHAR_MAX // 2\n regex = '^(\\\\s*\\\\S){%d}' % lim\n left_lim = re.match(regex, repr_).end()\n right_lim = re.match(regex, repr_[::-1]).end()\n if '\\n' in repr_[left_lim:-right_lim]:\n regex += '[^\\\\n]*\\\\n'\n right_lim = re.match(regex, repr_[::-1]).end()\n ellipsis = '...'\n if left_lim + len(ellipsis) < len(repr_) - right_lim:\n repr_ = repr_[:left_lim] + '...' + repr_[-right_lim:]\n return repr_\n \n def __getstate__(self):\n try:\n state = super().__getstate__()\n except AttributeError:\n state = self.__dict__.copy()\n if type(self).__module__.startswith('sklearn.'):\n return dict(state.items(), _sklearn_version=__version__)\n else:\n return state\n \n def __setstate__(self, state):\n if type(self).__module__.startswith('sklearn.'):\n pickle_version = state.pop('_sklearn_version', 'pre-0.18')\n if pickle_version != __version__:\n warnings.warn('Trying to unpickle estimator {0} from version {1} when using version {2}. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:\\nhttps://scikit-learn.org/stable/modules/model_persistence.html#security-maintainability-limitations'.format(self.__class__.__name__, pickle_version, __version__), UserWarning)\n try:\n super().__setstate__(state)\n except AttributeError:\n self.__dict__.update(state)\n \n def _more_tags(self):\n return _DEFAULT_TAGS\n \n def _get_tags(self):\n collected_tags = {}\n for base_class in reversed(inspect.getmro(self.__class__)):\n if hasattr(base_class, '_more_tags'):\n more_tags = base_class._more_tags(self)\n collected_tags.update(more_tags)\n return collected_tags\n \n def _check_n_features(self, X, reset):\n \"\"\"Set the `n_features_in_` attribute, or check against it.\n\n Parameters\n ----------\n X : {ndarray, sparse matrix} of shape (n_samples, n_features)\n The input samples.\n reset : bool\n If True, the `n_features_in_` attribute is set to `X.shape[1]`.\n If False and the attribute exists, then check that it is equal to\n `X.shape[1]`. If False and the attribute does *not* exist, then\n the check is skipped.\n .. note::\n It is recommended to call reset=True in `fit` and in the first\n call to `partial_fit`. All other methods that validate `X`\n should set `reset=False`.\n \"\"\"\n try:\n n_features = _num_features(X)\n except TypeError as e:\n if not reset and hasattr(self, 'n_features_in_'):\n raise ValueError(f'X does not contain any features, but {self.__class__.__name__} is expecting {self.n_features_in_} features') from e\n return\n if reset:\n self.n_features_in_ = n_features\n return\n if not hasattr(self, 'n_features_in_'):\n return\n if n_features != self.n_features_in_:\n raise ValueError(f'X has {n_features} features, but {self.__class__.__name__} is expecting {self.n_features_in_} features as input.')\n \n def _check_feature_names(self, X, *, reset):\n \"\"\"Set or check the `feature_names_in_` attribute.\n\n .. versionadded:: 1.0\n\n Parameters\n ----------\n X : {ndarray, dataframe} of shape (n_samples, n_features)\n The input samples.\n\n reset : bool\n Whether to reset the `feature_names_in_` attribute.\n If False, the input will be checked for consistency with\n feature names of data provided when reset was last True.\n .. note::\n It is recommended to call `reset=True` in `fit` and in the first\n call to `partial_fit`. All other methods that validate `X`\n should set `reset=False`.\n \"\"\"\n if reset:\n feature_names_in = _get_feature_names(X)\n if feature_names_in is not None:\n self.feature_names_in_ = feature_names_in\n elif hasattr(self, 'feature_names_in_'):\n delattr(self, 'feature_names_in_')\n return\n fitted_feature_names = getattr(self, 'feature_names_in_', None)\n X_feature_names = _get_feature_names(X)\n if fitted_feature_names is None and X_feature_names is None:\n return\n if X_feature_names is not None and fitted_feature_names is None:\n warnings.warn(f'X has feature names, but {self.__class__.__name__} was fitted without feature names')\n return\n if X_feature_names is None and fitted_feature_names is not None:\n warnings.warn(f'X does not have valid feature names, but {self.__class__.__name__} was fitted with feature names')\n return\n if len(fitted_feature_names) != len(X_feature_names) or np.any(fitted_feature_names != X_feature_names):\n message = 'The feature names should match those that were passed during fit. Starting version 1.2, an error will be raised.\\n'\n fitted_feature_names_set = set(fitted_feature_names)\n X_feature_names_set = set(X_feature_names)\n unexpected_names = sorted(X_feature_names_set - fitted_feature_names_set)\n missing_names = sorted(fitted_feature_names_set - X_feature_names_set)\n \n def add_names(names):\n output = ''\n max_n_names = 5\n for (i, name) in enumerate(names):\n if i >= max_n_names:\n output += '- ...\\n'\n break\n output += f'- {name}\\n'\n return output\n if unexpected_names:\n message += 'Feature names unseen at fit time:\\n'\n message += add_names(unexpected_names)\n if missing_names:\n message += 'Feature names seen at fit time, yet now missing:\\n'\n message += add_names(missing_names)\n if not missing_names and not missing_names:\n message += 'Feature names must be in the same order as they were in fit.\\n'\n warnings.warn(message, FutureWarning)\n \n def _validate_data(self, X='no_validation', y='no_validation', reset=True, validate_separately=False, **check_params):\n \"\"\"Validate input data and set or check the `n_features_in_` attribute.\n\n Parameters\n ----------\n X : {array-like, sparse matrix, dataframe} of shape (n_samples, n_features), default='no validation'\n The input samples.\n If `'no_validation'`, no validation is performed on `X`. This is\n useful for meta-estimator which can delegate input validation to\n their underlying estimator(s). In that case `y` must be passed and\n the only accepted `check_params` are `multi_output` and\n `y_numeric`.\n\n y : array-like of shape (n_samples,), default='no_validation'\n The targets.\n\n - If `None`, `check_array` is called on `X`. If the estimator's\n requires_y tag is True, then an error will be raised.\n - If `'no_validation'`, `check_array` is called on `X` and the\n estimator's requires_y tag is ignored. This is a default\n placeholder and is never meant to be explicitly set. In that case\n `X` must be passed.\n - Otherwise, only `y` with `_check_y` or both `X` and `y` are\n checked with either `check_array` or `check_X_y` depending on\n `validate_separately`.\n\n reset : bool, default=True\n Whether to reset the `n_features_in_` attribute.\n If False, the input will be checked for consistency with data\n provided when reset was last True.\n .. note::\n It is recommended to call reset=True in `fit` and in the first\n call to `partial_fit`. All other methods that validate `X`\n should set `reset=False`.\n validate_separately : False or tuple of dicts, default=False\n Only used if y is not None.\n If False, call validate_X_y(). Else, it must be a tuple of kwargs\n to be used for calling check_array() on X and y respectively.\n **check_params : kwargs\n Parameters passed to :func:`sklearn.utils.check_array` or\n :func:`sklearn.utils.check_X_y`. Ignored if validate_separately\n is not False.\n\n Returns\n -------\n out : {ndarray, sparse matrix} or tuple of these\n The validated input. A tuple is returned if both `X` and `y` are\n validated.\n \"\"\"\n self._check_feature_names(X, reset=reset)\n if y is None and self._get_tags()['requires_y']:\n raise ValueError(f'This {self.__class__.__name__} estimator requires y to be passed, but the target y is None.')\n no_val_X = isinstance(X, str) and X == 'no_validation'\n no_val_y = y is None or isinstance(y, str) and y == 'no_validation'\n if no_val_X and no_val_y:\n raise ValueError('Validation should be done on X, y or both.')\n elif not no_val_X and no_val_y:\n X = check_array(X, **check_params)\n out = X\n elif no_val_X and not no_val_y:\n y = _check_y(y, **check_params)\n out = y\n else:\n if validate_separately:\n (check_X_params, check_y_params) = validate_separately\n X = check_array(X, **check_X_params)\n y = check_array(y, **check_y_params)\n else:\n (X, y) = check_X_y(X, y, **check_params)\n out = (X, y)\n if not no_val_X and check_params.get('ensure_2d', True):\n self._check_n_features(X, reset=reset)\n return out\n \n @property\n def _repr_html_(self):\n \"\"\"HTML representation of estimator.\n\n This is redundant with the logic of `_repr_mimebundle_`. The latter\n should be favorted in the long term, `_repr_html_` is only\n implemented for consumers who do not interpret `_repr_mimbundle_`.\n \"\"\"\n if get_config()['display'] != 'diagram':\n raise AttributeError(\"_repr_html_ is only defined when the 'display' configuration option is set to 'diagram'\")\n return self._repr_html_inner\n \n def _repr_html_inner(self):\n \"\"\"This function is returned by the @property `_repr_html_` to make\n `hasattr(estimator, \"_repr_html_\") return `True` or `False` depending\n on `get_config()[\"display\"]`.\n \"\"\"\n return estimator_html_repr(self)\n \n def _repr_mimebundle_(self, **kwargs):\n \"\"\"Mime bundle used by jupyter kernels to display estimator\"\"\"\n output = {'text/plain': repr(self)}\n if get_config()['display'] == 'diagram':\n output['text/html'] = estimator_html_repr(self)\n return output\n" }, { "name": "BiclusterMixin", @@ -19664,7 +19630,7 @@ "decorators": [], "superclasses": [], "methods": [ - "sklearn.base.BiclusterMixin.biclusters_", + "sklearn.base.BiclusterMixin.biclusters_@getter", "sklearn.base.BiclusterMixin.get_indices", "sklearn.base.BiclusterMixin.get_shape", "sklearn.base.BiclusterMixin.get_submatrix" @@ -19672,7 +19638,7 @@ "is_public": true, "description": "Mixin class for all bicluster estimators in scikit-learn.", "docstring": "Mixin class for all bicluster estimators in scikit-learn.", - "source_code": "\n\nclass BiclusterMixin:\n \"\"\"Mixin class for all bicluster estimators in scikit-learn.\"\"\"\n \n @property\n def biclusters_(self):\n \"\"\"Convenient way to get row and column indicators together.\n\n Returns the ``rows_`` and ``columns_`` members.\n \"\"\"\n return self.rows_, self.columns_\n \n def get_indices(self, i):\n \"\"\"Row and column indices of the `i`'th bicluster.\n\n Only works if ``rows_`` and ``columns_`` attributes exist.\n\n Parameters\n ----------\n i : int\n The index of the cluster.\n\n Returns\n -------\n row_ind : ndarray, dtype=np.intp\n Indices of rows in the dataset that belong to the bicluster.\n col_ind : ndarray, dtype=np.intp\n Indices of columns in the dataset that belong to the bicluster.\n\n \"\"\"\n rows = self.rows_[i]\n columns = self.columns_[i]\n return np.nonzero(rows)[0], np.nonzero(columns)[0]\n \n def get_shape(self, i):\n \"\"\"Shape of the `i`'th bicluster.\n\n Parameters\n ----------\n i : int\n The index of the cluster.\n\n Returns\n -------\n n_rows : int\n Number of rows in the bicluster.\n\n n_cols : int\n Number of columns in the bicluster.\n \"\"\"\n indices = self.get_indices(i)\n return tuple((len(i) for i in indices))\n \n def get_submatrix(self, i, data):\n \"\"\"Return the submatrix corresponding to bicluster `i`.\n\n Parameters\n ----------\n i : int\n The index of the cluster.\n data : array-like of shape (n_samples, n_features)\n The data.\n\n Returns\n -------\n submatrix : ndarray of shape (n_rows, n_cols)\n The submatrix corresponding to bicluster `i`.\n\n Notes\n -----\n Works with sparse matrices. Only works if ``rows_`` and\n ``columns_`` attributes exist.\n \"\"\"\n from .utils.validation import check_array\n data = check_array(data, accept_sparse='csr')\n (row_ind, col_ind) = self.get_indices(i)\n return data[row_ind[:, np.newaxis], col_ind]\n" + "source_code": "\n\nclass BiclusterMixin:\n \"\"\"Mixin class for all bicluster estimators in scikit-learn.\"\"\"\n \n @property\n def biclusters_(self):\n \"\"\"Convenient way to get row and column indicators together.\n\n Returns the ``rows_`` and ``columns_`` members.\n \"\"\"\n return self.rows_, self.columns_\n \n def get_indices(self, i):\n \"\"\"Row and column indices of the `i`'th bicluster.\n\n Only works if ``rows_`` and ``columns_`` attributes exist.\n\n Parameters\n ----------\n i : int\n The index of the cluster.\n\n Returns\n -------\n row_ind : ndarray, dtype=np.intp\n Indices of rows in the dataset that belong to the bicluster.\n col_ind : ndarray, dtype=np.intp\n Indices of columns in the dataset that belong to the bicluster.\n \"\"\"\n rows = self.rows_[i]\n columns = self.columns_[i]\n return np.nonzero(rows)[0], np.nonzero(columns)[0]\n \n def get_shape(self, i):\n \"\"\"Shape of the `i`'th bicluster.\n\n Parameters\n ----------\n i : int\n The index of the cluster.\n\n Returns\n -------\n n_rows : int\n Number of rows in the bicluster.\n\n n_cols : int\n Number of columns in the bicluster.\n \"\"\"\n indices = self.get_indices(i)\n return tuple((len(i) for i in indices))\n \n def get_submatrix(self, i, data):\n \"\"\"Return the submatrix corresponding to bicluster `i`.\n\n Parameters\n ----------\n i : int\n The index of the cluster.\n data : array-like of shape (n_samples, n_features)\n The data.\n\n Returns\n -------\n submatrix : ndarray of shape (n_rows, n_cols)\n The submatrix corresponding to bicluster `i`.\n\n Notes\n -----\n Works with sparse matrices. Only works if ``rows_`` and\n ``columns_`` attributes exist.\n \"\"\"\n from .utils.validation import check_array\n data = check_array(data, accept_sparse='csr')\n (row_ind, col_ind) = self.get_indices(i)\n return data[row_ind[:, np.newaxis], col_ind]\n" }, { "name": "ClassifierMixin", @@ -19814,7 +19780,7 @@ "is_public": true, "description": "Probability calibration with isotonic regression or logistic regression.\n\nThis class uses cross-validation to both estimate the parameters of a classifier and subsequently calibrate a classifier. With default `ensemble=True`, for each cv split it fits a copy of the base estimator to the training subset, and calibrates it using the testing subset. For prediction, predicted probabilities are averaged across these individual calibrated classifiers. When `ensemble=False`, cross-validation is used to obtain unbiased predictions, via :func:`~sklearn.model_selection.cross_val_predict`, which are then used for calibration. For prediction, the base estimator, trained using all the data, is used. This is the method implemented when `probabilities=True` for :mod:`sklearn.svm` estimators. Already fitted classifiers can be calibrated via the parameter `cv=\"prefit\"`. In this case, no cross-validation is used and all provided data is used for calibration. The user has to take care manually that data for model fitting and calibration are disjoint. The calibration is based on the :term:`decision_function` method of the `base_estimator` if it exists, else on :term:`predict_proba`. Read more in the :ref:`User Guide `.", "docstring": "Probability calibration with isotonic regression or logistic regression.\n\n This class uses cross-validation to both estimate the parameters of a\n classifier and subsequently calibrate a classifier. With default\n `ensemble=True`, for each cv split it\n fits a copy of the base estimator to the training subset, and calibrates it\n using the testing subset. For prediction, predicted probabilities are\n averaged across these individual calibrated classifiers. When\n `ensemble=False`, cross-validation is used to obtain unbiased predictions,\n via :func:`~sklearn.model_selection.cross_val_predict`, which are then\n used for calibration. For prediction, the base estimator, trained using all\n the data, is used. This is the method implemented when `probabilities=True`\n for :mod:`sklearn.svm` estimators.\n\n Already fitted classifiers can be calibrated via the parameter\n `cv=\"prefit\"`. In this case, no cross-validation is used and all provided\n data is used for calibration. The user has to take care manually that data\n for model fitting and calibration are disjoint.\n\n The calibration is based on the :term:`decision_function` method of the\n `base_estimator` if it exists, else on :term:`predict_proba`.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n base_estimator : estimator instance, default=None\n The classifier whose output need to be calibrated to provide more\n accurate `predict_proba` outputs. The default classifier is\n a :class:`~sklearn.svm.LinearSVC`.\n\n method : {'sigmoid', 'isotonic'}, default='sigmoid'\n The method to use for calibration. Can be 'sigmoid' which\n corresponds to Platt's method (i.e. a logistic regression model) or\n 'isotonic' which is a non-parametric approach. It is not advised to\n use isotonic calibration with too few calibration samples\n ``(<<1000)`` since it tends to overfit.\n\n cv : int, cross-validation generator, iterable or \"prefit\", default=None\n Determines the cross-validation splitting strategy.\n Possible inputs for cv are:\n\n - None, to use the default 5-fold cross-validation,\n - integer, to specify the number of folds.\n - :term:`CV splitter`,\n - An iterable yielding (train, test) splits as arrays of indices.\n\n For integer/None inputs, if ``y`` is binary or multiclass,\n :class:`~sklearn.model_selection.StratifiedKFold` is used. If ``y`` is\n neither binary nor multiclass, :class:`~sklearn.model_selection.KFold`\n is used.\n\n Refer to the :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n If \"prefit\" is passed, it is assumed that `base_estimator` has been\n fitted already and all data is used for calibration.\n\n .. versionchanged:: 0.22\n ``cv`` default value if None changed from 3-fold to 5-fold.\n\n n_jobs : int, default=None\n Number of jobs to run in parallel.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors.\n\n Base estimator clones are fitted in parallel across cross-validation\n iterations. Therefore parallelism happens only when `cv != \"prefit\"`.\n\n See :term:`Glossary ` for more details.\n\n .. versionadded:: 0.24\n\n ensemble : bool, default=True\n Determines how the calibrator is fitted when `cv` is not `'prefit'`.\n Ignored if `cv='prefit'`.\n\n If `True`, the `base_estimator` is fitted using training data and\n calibrated using testing data, for each `cv` fold. The final estimator\n is an ensemble of `n_cv` fitted classifier and calibrator pairs, where\n `n_cv` is the number of cross-validation folds. The output is the\n average predicted probabilities of all pairs.\n\n If `False`, `cv` is used to compute unbiased predictions, via\n :func:`~sklearn.model_selection.cross_val_predict`, which are then\n used for calibration. At prediction time, the classifier used is the\n `base_estimator` trained on all the data.\n Note that this method is also internally implemented in\n :mod:`sklearn.svm` estimators with the `probabilities=True` parameter.\n\n .. versionadded:: 0.24\n\n Attributes\n ----------\n classes_ : ndarray of shape (n_classes,)\n The class labels.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`. Only defined if the\n underlying base_estimator exposes such an attribute when fit.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Only defined if the\n underlying base_estimator exposes such an attribute when fit.\n\n .. versionadded:: 1.0\n\n calibrated_classifiers_ : list (len() equal to cv or 1 if `cv=\"prefit\"` or `ensemble=False`)\n The list of classifier and calibrator pairs.\n\n - When `cv=\"prefit\"`, the fitted `base_estimator` and fitted\n calibrator.\n - When `cv` is not \"prefit\" and `ensemble=True`, `n_cv` fitted\n `base_estimator` and calibrator pairs. `n_cv` is the number of\n cross-validation folds.\n - When `cv` is not \"prefit\" and `ensemble=False`, the `base_estimator`,\n fitted on all the data, and fitted calibrator.\n\n .. versionchanged:: 0.24\n Single calibrated classifier case when `ensemble=False`.\n\n See Also\n --------\n calibration_curve : Compute true and predicted probabilities\n for a calibration curve.\n\n References\n ----------\n .. [1] Obtaining calibrated probability estimates from decision trees\n and naive Bayesian classifiers, B. Zadrozny & C. Elkan, ICML 2001\n\n .. [2] Transforming Classifier Scores into Accurate Multiclass\n Probability Estimates, B. Zadrozny & C. Elkan, (KDD 2002)\n\n .. [3] Probabilistic Outputs for Support Vector Machines and Comparisons to\n Regularized Likelihood Methods, J. Platt, (1999)\n\n .. [4] Predicting Good Probabilities with Supervised Learning,\n A. Niculescu-Mizil & R. Caruana, ICML 2005\n\n Examples\n --------\n >>> from sklearn.datasets import make_classification\n >>> from sklearn.naive_bayes import GaussianNB\n >>> from sklearn.calibration import CalibratedClassifierCV\n >>> X, y = make_classification(n_samples=100, n_features=2,\n ... n_redundant=0, random_state=42)\n >>> base_clf = GaussianNB()\n >>> calibrated_clf = CalibratedClassifierCV(base_estimator=base_clf, cv=3)\n >>> calibrated_clf.fit(X, y)\n CalibratedClassifierCV(base_estimator=GaussianNB(), cv=3)\n >>> len(calibrated_clf.calibrated_classifiers_)\n 3\n >>> calibrated_clf.predict_proba(X)[:5, :]\n array([[0.110..., 0.889...],\n [0.072..., 0.927...],\n [0.928..., 0.071...],\n [0.928..., 0.071...],\n [0.071..., 0.928...]])\n >>> from sklearn.model_selection import train_test_split\n >>> X, y = make_classification(n_samples=100, n_features=2,\n ... n_redundant=0, random_state=42)\n >>> X_train, X_calib, y_train, y_calib = train_test_split(\n ... X, y, random_state=42\n ... )\n >>> base_clf = GaussianNB()\n >>> base_clf.fit(X_train, y_train)\n GaussianNB()\n >>> calibrated_clf = CalibratedClassifierCV(\n ... base_estimator=base_clf,\n ... cv=\"prefit\"\n ... )\n >>> calibrated_clf.fit(X_calib, y_calib)\n CalibratedClassifierCV(base_estimator=GaussianNB(), cv='prefit')\n >>> len(calibrated_clf.calibrated_classifiers_)\n 1\n >>> calibrated_clf.predict_proba([[-0.5, 0.5]])\n array([[0.936..., 0.063...]])\n ", - "source_code": "\n\nclass CalibratedClassifierCV(ClassifierMixin, MetaEstimatorMixin, BaseEstimator):\n \"\"\"Probability calibration with isotonic regression or logistic regression.\n\n This class uses cross-validation to both estimate the parameters of a\n classifier and subsequently calibrate a classifier. With default\n `ensemble=True`, for each cv split it\n fits a copy of the base estimator to the training subset, and calibrates it\n using the testing subset. For prediction, predicted probabilities are\n averaged across these individual calibrated classifiers. When\n `ensemble=False`, cross-validation is used to obtain unbiased predictions,\n via :func:`~sklearn.model_selection.cross_val_predict`, which are then\n used for calibration. For prediction, the base estimator, trained using all\n the data, is used. This is the method implemented when `probabilities=True`\n for :mod:`sklearn.svm` estimators.\n\n Already fitted classifiers can be calibrated via the parameter\n `cv=\"prefit\"`. In this case, no cross-validation is used and all provided\n data is used for calibration. The user has to take care manually that data\n for model fitting and calibration are disjoint.\n\n The calibration is based on the :term:`decision_function` method of the\n `base_estimator` if it exists, else on :term:`predict_proba`.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n base_estimator : estimator instance, default=None\n The classifier whose output need to be calibrated to provide more\n accurate `predict_proba` outputs. The default classifier is\n a :class:`~sklearn.svm.LinearSVC`.\n\n method : {'sigmoid', 'isotonic'}, default='sigmoid'\n The method to use for calibration. Can be 'sigmoid' which\n corresponds to Platt's method (i.e. a logistic regression model) or\n 'isotonic' which is a non-parametric approach. It is not advised to\n use isotonic calibration with too few calibration samples\n ``(<<1000)`` since it tends to overfit.\n\n cv : int, cross-validation generator, iterable or \"prefit\", default=None\n Determines the cross-validation splitting strategy.\n Possible inputs for cv are:\n\n - None, to use the default 5-fold cross-validation,\n - integer, to specify the number of folds.\n - :term:`CV splitter`,\n - An iterable yielding (train, test) splits as arrays of indices.\n\n For integer/None inputs, if ``y`` is binary or multiclass,\n :class:`~sklearn.model_selection.StratifiedKFold` is used. If ``y`` is\n neither binary nor multiclass, :class:`~sklearn.model_selection.KFold`\n is used.\n\n Refer to the :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n If \"prefit\" is passed, it is assumed that `base_estimator` has been\n fitted already and all data is used for calibration.\n\n .. versionchanged:: 0.22\n ``cv`` default value if None changed from 3-fold to 5-fold.\n\n n_jobs : int, default=None\n Number of jobs to run in parallel.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors.\n\n Base estimator clones are fitted in parallel across cross-validation\n iterations. Therefore parallelism happens only when `cv != \"prefit\"`.\n\n See :term:`Glossary ` for more details.\n\n .. versionadded:: 0.24\n\n ensemble : bool, default=True\n Determines how the calibrator is fitted when `cv` is not `'prefit'`.\n Ignored if `cv='prefit'`.\n\n If `True`, the `base_estimator` is fitted using training data and\n calibrated using testing data, for each `cv` fold. The final estimator\n is an ensemble of `n_cv` fitted classifier and calibrator pairs, where\n `n_cv` is the number of cross-validation folds. The output is the\n average predicted probabilities of all pairs.\n\n If `False`, `cv` is used to compute unbiased predictions, via\n :func:`~sklearn.model_selection.cross_val_predict`, which are then\n used for calibration. At prediction time, the classifier used is the\n `base_estimator` trained on all the data.\n Note that this method is also internally implemented in\n :mod:`sklearn.svm` estimators with the `probabilities=True` parameter.\n\n .. versionadded:: 0.24\n\n Attributes\n ----------\n classes_ : ndarray of shape (n_classes,)\n The class labels.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`. Only defined if the\n underlying base_estimator exposes such an attribute when fit.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Only defined if the\n underlying base_estimator exposes such an attribute when fit.\n\n .. versionadded:: 1.0\n\n calibrated_classifiers_ : list (len() equal to cv or 1 if `cv=\"prefit\"` or `ensemble=False`)\n The list of classifier and calibrator pairs.\n\n - When `cv=\"prefit\"`, the fitted `base_estimator` and fitted\n calibrator.\n - When `cv` is not \"prefit\" and `ensemble=True`, `n_cv` fitted\n `base_estimator` and calibrator pairs. `n_cv` is the number of\n cross-validation folds.\n - When `cv` is not \"prefit\" and `ensemble=False`, the `base_estimator`,\n fitted on all the data, and fitted calibrator.\n\n .. versionchanged:: 0.24\n Single calibrated classifier case when `ensemble=False`.\n\n See Also\n --------\n calibration_curve : Compute true and predicted probabilities\n for a calibration curve.\n\n References\n ----------\n .. [1] Obtaining calibrated probability estimates from decision trees\n and naive Bayesian classifiers, B. Zadrozny & C. Elkan, ICML 2001\n\n .. [2] Transforming Classifier Scores into Accurate Multiclass\n Probability Estimates, B. Zadrozny & C. Elkan, (KDD 2002)\n\n .. [3] Probabilistic Outputs for Support Vector Machines and Comparisons to\n Regularized Likelihood Methods, J. Platt, (1999)\n\n .. [4] Predicting Good Probabilities with Supervised Learning,\n A. Niculescu-Mizil & R. Caruana, ICML 2005\n\n Examples\n --------\n >>> from sklearn.datasets import make_classification\n >>> from sklearn.naive_bayes import GaussianNB\n >>> from sklearn.calibration import CalibratedClassifierCV\n >>> X, y = make_classification(n_samples=100, n_features=2,\n ... n_redundant=0, random_state=42)\n >>> base_clf = GaussianNB()\n >>> calibrated_clf = CalibratedClassifierCV(base_estimator=base_clf, cv=3)\n >>> calibrated_clf.fit(X, y)\n CalibratedClassifierCV(base_estimator=GaussianNB(), cv=3)\n >>> len(calibrated_clf.calibrated_classifiers_)\n 3\n >>> calibrated_clf.predict_proba(X)[:5, :]\n array([[0.110..., 0.889...],\n [0.072..., 0.927...],\n [0.928..., 0.071...],\n [0.928..., 0.071...],\n [0.071..., 0.928...]])\n >>> from sklearn.model_selection import train_test_split\n >>> X, y = make_classification(n_samples=100, n_features=2,\n ... n_redundant=0, random_state=42)\n >>> X_train, X_calib, y_train, y_calib = train_test_split(\n ... X, y, random_state=42\n ... )\n >>> base_clf = GaussianNB()\n >>> base_clf.fit(X_train, y_train)\n GaussianNB()\n >>> calibrated_clf = CalibratedClassifierCV(\n ... base_estimator=base_clf,\n ... cv=\"prefit\"\n ... )\n >>> calibrated_clf.fit(X_calib, y_calib)\n CalibratedClassifierCV(base_estimator=GaussianNB(), cv='prefit')\n >>> len(calibrated_clf.calibrated_classifiers_)\n 1\n >>> calibrated_clf.predict_proba([[-0.5, 0.5]])\n array([[0.936..., 0.063...]])\n \"\"\"\n \n def __init__(self, base_estimator=None, *, method='sigmoid', cv=None, n_jobs=None, ensemble=True):\n self.base_estimator = base_estimator\n self.method = method\n self.cv = cv\n self.n_jobs = n_jobs\n self.ensemble = ensemble\n \n def fit(self, X, y, sample_weight=None):\n \"\"\"Fit the calibrated model.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training data.\n\n y : array-like of shape (n_samples,)\n Target values.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n\n Returns\n -------\n self : object\n Returns an instance of self.\n \"\"\"\n check_classification_targets(y)\n (X, y) = indexable(X, y)\n if self.base_estimator is None:\n base_estimator = LinearSVC(random_state=0)\n else:\n base_estimator = self.base_estimator\n self.calibrated_classifiers_ = []\n if self.cv == 'prefit':\n check_is_fitted(self.base_estimator, attributes=['classes_'])\n self.classes_ = self.base_estimator.classes_\n (pred_method, method_name) = _get_prediction_method(base_estimator)\n n_classes = len(self.classes_)\n predictions = _compute_predictions(pred_method, method_name, X, n_classes)\n calibrated_classifier = _fit_calibrator(base_estimator, predictions, y, self.classes_, self.method, sample_weight)\n self.calibrated_classifiers_.append(calibrated_classifier)\n else:\n label_encoder_ = LabelEncoder().fit(y)\n self.classes_ = label_encoder_.classes_\n n_classes = len(self.classes_)\n fit_parameters = signature(base_estimator.fit).parameters\n supports_sw = 'sample_weight' in fit_parameters\n if sample_weight is not None:\n sample_weight = _check_sample_weight(sample_weight, X)\n if not supports_sw:\n estimator_name = type(base_estimator).__name__\n warnings.warn(f'Since {estimator_name} does not support sample_weights, sample weights will only be used for the calibration itself.')\n if isinstance(self.cv, int):\n n_folds = self.cv\n elif hasattr(self.cv, 'n_splits'):\n n_folds = self.cv.n_splits\n else:\n n_folds = None\n if n_folds and np.any([np.sum(y == class_) < n_folds for class_ in self.classes_]):\n raise ValueError(f'Requesting {n_folds}-fold cross-validation but provided less than {n_folds} examples for at least one class.')\n cv = check_cv(self.cv, y, classifier=True)\n if self.ensemble:\n parallel = Parallel(n_jobs=self.n_jobs)\n self.calibrated_classifiers_ = parallel((delayed(_fit_classifier_calibrator_pair)(clone(base_estimator), X, y, train=train, test=test, method=self.method, classes=self.classes_, supports_sw=supports_sw, sample_weight=sample_weight) for (train, test) in cv.split(X, y)))\n else:\n this_estimator = clone(base_estimator)\n (_, method_name) = _get_prediction_method(this_estimator)\n pred_method = partial(cross_val_predict, estimator=this_estimator, X=X, y=y, cv=cv, method=method_name, n_jobs=self.n_jobs)\n predictions = _compute_predictions(pred_method, method_name, X, n_classes)\n if sample_weight is not None and supports_sw:\n this_estimator.fit(X, y, sample_weight)\n else:\n this_estimator.fit(X, y)\n calibrated_classifier = _fit_calibrator(this_estimator, predictions, y, self.classes_, self.method, sample_weight)\n self.calibrated_classifiers_.append(calibrated_classifier)\n first_clf = self.calibrated_classifiers_[0].base_estimator\n if hasattr(first_clf, 'n_features_in_'):\n self.n_features_in_ = first_clf.n_features_in_\n if hasattr(first_clf, 'feature_names_in_'):\n self.feature_names_in_ = first_clf.feature_names_in_\n return self\n \n def predict_proba(self, X):\n \"\"\"Calibrated probabilities of classification.\n\n This function returns calibrated probabilities of classification\n according to each class on an array of test vectors X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The samples, as accepted by `base_estimator.predict_proba`.\n\n Returns\n -------\n C : ndarray of shape (n_samples, n_classes)\n The predicted probas.\n \"\"\"\n check_is_fitted(self)\n mean_proba = np.zeros((_num_samples(X), len(self.classes_)))\n for calibrated_classifier in self.calibrated_classifiers_:\n proba = calibrated_classifier.predict_proba(X)\n mean_proba += proba\n mean_proba /= len(self.calibrated_classifiers_)\n return mean_proba\n \n def predict(self, X):\n \"\"\"Predict the target of new samples.\n\n The predicted class is the class that has the highest probability,\n and can thus be different from the prediction of the uncalibrated classifier.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The samples, as accepted by `base_estimator.predict`.\n\n Returns\n -------\n C : ndarray of shape (n_samples,)\n The predicted class.\n \"\"\"\n check_is_fitted(self)\n return self.classes_[np.argmax(self.predict_proba(X), axis=1)]\n \n def _more_tags(self):\n return {'_xfail_checks': {'check_sample_weights_invariance': 'zero sample_weight is not equivalent to removing samples'}}\n" + "source_code": "\n\nclass CalibratedClassifierCV(ClassifierMixin, MetaEstimatorMixin, BaseEstimator):\n \"\"\"Probability calibration with isotonic regression or logistic regression.\n\n This class uses cross-validation to both estimate the parameters of a\n classifier and subsequently calibrate a classifier. With default\n `ensemble=True`, for each cv split it\n fits a copy of the base estimator to the training subset, and calibrates it\n using the testing subset. For prediction, predicted probabilities are\n averaged across these individual calibrated classifiers. When\n `ensemble=False`, cross-validation is used to obtain unbiased predictions,\n via :func:`~sklearn.model_selection.cross_val_predict`, which are then\n used for calibration. For prediction, the base estimator, trained using all\n the data, is used. This is the method implemented when `probabilities=True`\n for :mod:`sklearn.svm` estimators.\n\n Already fitted classifiers can be calibrated via the parameter\n `cv=\"prefit\"`. In this case, no cross-validation is used and all provided\n data is used for calibration. The user has to take care manually that data\n for model fitting and calibration are disjoint.\n\n The calibration is based on the :term:`decision_function` method of the\n `base_estimator` if it exists, else on :term:`predict_proba`.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n base_estimator : estimator instance, default=None\n The classifier whose output need to be calibrated to provide more\n accurate `predict_proba` outputs. The default classifier is\n a :class:`~sklearn.svm.LinearSVC`.\n\n method : {'sigmoid', 'isotonic'}, default='sigmoid'\n The method to use for calibration. Can be 'sigmoid' which\n corresponds to Platt's method (i.e. a logistic regression model) or\n 'isotonic' which is a non-parametric approach. It is not advised to\n use isotonic calibration with too few calibration samples\n ``(<<1000)`` since it tends to overfit.\n\n cv : int, cross-validation generator, iterable or \"prefit\", default=None\n Determines the cross-validation splitting strategy.\n Possible inputs for cv are:\n\n - None, to use the default 5-fold cross-validation,\n - integer, to specify the number of folds.\n - :term:`CV splitter`,\n - An iterable yielding (train, test) splits as arrays of indices.\n\n For integer/None inputs, if ``y`` is binary or multiclass,\n :class:`~sklearn.model_selection.StratifiedKFold` is used. If ``y`` is\n neither binary nor multiclass, :class:`~sklearn.model_selection.KFold`\n is used.\n\n Refer to the :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n If \"prefit\" is passed, it is assumed that `base_estimator` has been\n fitted already and all data is used for calibration.\n\n .. versionchanged:: 0.22\n ``cv`` default value if None changed from 3-fold to 5-fold.\n\n n_jobs : int, default=None\n Number of jobs to run in parallel.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors.\n\n Base estimator clones are fitted in parallel across cross-validation\n iterations. Therefore parallelism happens only when `cv != \"prefit\"`.\n\n See :term:`Glossary ` for more details.\n\n .. versionadded:: 0.24\n\n ensemble : bool, default=True\n Determines how the calibrator is fitted when `cv` is not `'prefit'`.\n Ignored if `cv='prefit'`.\n\n If `True`, the `base_estimator` is fitted using training data and\n calibrated using testing data, for each `cv` fold. The final estimator\n is an ensemble of `n_cv` fitted classifier and calibrator pairs, where\n `n_cv` is the number of cross-validation folds. The output is the\n average predicted probabilities of all pairs.\n\n If `False`, `cv` is used to compute unbiased predictions, via\n :func:`~sklearn.model_selection.cross_val_predict`, which are then\n used for calibration. At prediction time, the classifier used is the\n `base_estimator` trained on all the data.\n Note that this method is also internally implemented in\n :mod:`sklearn.svm` estimators with the `probabilities=True` parameter.\n\n .. versionadded:: 0.24\n\n Attributes\n ----------\n classes_ : ndarray of shape (n_classes,)\n The class labels.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`. Only defined if the\n underlying base_estimator exposes such an attribute when fit.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Only defined if the\n underlying base_estimator exposes such an attribute when fit.\n\n .. versionadded:: 1.0\n\n calibrated_classifiers_ : list (len() equal to cv or 1 if `cv=\"prefit\"` or `ensemble=False`)\n The list of classifier and calibrator pairs.\n\n - When `cv=\"prefit\"`, the fitted `base_estimator` and fitted\n calibrator.\n - When `cv` is not \"prefit\" and `ensemble=True`, `n_cv` fitted\n `base_estimator` and calibrator pairs. `n_cv` is the number of\n cross-validation folds.\n - When `cv` is not \"prefit\" and `ensemble=False`, the `base_estimator`,\n fitted on all the data, and fitted calibrator.\n\n .. versionchanged:: 0.24\n Single calibrated classifier case when `ensemble=False`.\n\n See Also\n --------\n calibration_curve : Compute true and predicted probabilities\n for a calibration curve.\n\n References\n ----------\n .. [1] Obtaining calibrated probability estimates from decision trees\n and naive Bayesian classifiers, B. Zadrozny & C. Elkan, ICML 2001\n\n .. [2] Transforming Classifier Scores into Accurate Multiclass\n Probability Estimates, B. Zadrozny & C. Elkan, (KDD 2002)\n\n .. [3] Probabilistic Outputs for Support Vector Machines and Comparisons to\n Regularized Likelihood Methods, J. Platt, (1999)\n\n .. [4] Predicting Good Probabilities with Supervised Learning,\n A. Niculescu-Mizil & R. Caruana, ICML 2005\n\n Examples\n --------\n >>> from sklearn.datasets import make_classification\n >>> from sklearn.naive_bayes import GaussianNB\n >>> from sklearn.calibration import CalibratedClassifierCV\n >>> X, y = make_classification(n_samples=100, n_features=2,\n ... n_redundant=0, random_state=42)\n >>> base_clf = GaussianNB()\n >>> calibrated_clf = CalibratedClassifierCV(base_estimator=base_clf, cv=3)\n >>> calibrated_clf.fit(X, y)\n CalibratedClassifierCV(base_estimator=GaussianNB(), cv=3)\n >>> len(calibrated_clf.calibrated_classifiers_)\n 3\n >>> calibrated_clf.predict_proba(X)[:5, :]\n array([[0.110..., 0.889...],\n [0.072..., 0.927...],\n [0.928..., 0.071...],\n [0.928..., 0.071...],\n [0.071..., 0.928...]])\n >>> from sklearn.model_selection import train_test_split\n >>> X, y = make_classification(n_samples=100, n_features=2,\n ... n_redundant=0, random_state=42)\n >>> X_train, X_calib, y_train, y_calib = train_test_split(\n ... X, y, random_state=42\n ... )\n >>> base_clf = GaussianNB()\n >>> base_clf.fit(X_train, y_train)\n GaussianNB()\n >>> calibrated_clf = CalibratedClassifierCV(\n ... base_estimator=base_clf,\n ... cv=\"prefit\"\n ... )\n >>> calibrated_clf.fit(X_calib, y_calib)\n CalibratedClassifierCV(base_estimator=GaussianNB(), cv='prefit')\n >>> len(calibrated_clf.calibrated_classifiers_)\n 1\n >>> calibrated_clf.predict_proba([[-0.5, 0.5]])\n array([[0.936..., 0.063...]])\n \"\"\"\n \n def __init__(self, base_estimator=None, *, method='sigmoid', cv=None, n_jobs=None, ensemble=True):\n self.base_estimator = base_estimator\n self.method = method\n self.cv = cv\n self.n_jobs = n_jobs\n self.ensemble = ensemble\n \n def fit(self, X, y, sample_weight=None):\n \"\"\"Fit the calibrated model.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training data.\n\n y : array-like of shape (n_samples,)\n Target values.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n\n Returns\n -------\n self : object\n Returns an instance of self.\n \"\"\"\n check_classification_targets(y)\n (X, y) = indexable(X, y)\n if sample_weight is not None:\n sample_weight = _check_sample_weight(sample_weight, X)\n if self.base_estimator is None:\n base_estimator = LinearSVC(random_state=0)\n else:\n base_estimator = self.base_estimator\n self.calibrated_classifiers_ = []\n if self.cv == 'prefit':\n check_is_fitted(self.base_estimator, attributes=['classes_'])\n self.classes_ = self.base_estimator.classes_\n (pred_method, method_name) = _get_prediction_method(base_estimator)\n n_classes = len(self.classes_)\n predictions = _compute_predictions(pred_method, method_name, X, n_classes)\n calibrated_classifier = _fit_calibrator(base_estimator, predictions, y, self.classes_, self.method, sample_weight)\n self.calibrated_classifiers_.append(calibrated_classifier)\n else:\n label_encoder_ = LabelEncoder().fit(y)\n self.classes_ = label_encoder_.classes_\n n_classes = len(self.classes_)\n fit_parameters = signature(base_estimator.fit).parameters\n supports_sw = 'sample_weight' in fit_parameters\n if sample_weight is not None and not supports_sw:\n estimator_name = type(base_estimator).__name__\n warnings.warn(f'Since {estimator_name} does not appear to accept sample_weight, sample weights will only be used for the calibration itself. This can be caused by a limitation of the current scikit-learn API. See the following issue for more details: https://github.com/scikit-learn/scikit-learn/issues/21134. Be warned that the result of the calibration is likely to be incorrect.')\n if isinstance(self.cv, int):\n n_folds = self.cv\n elif hasattr(self.cv, 'n_splits'):\n n_folds = self.cv.n_splits\n else:\n n_folds = None\n if n_folds and np.any([np.sum(y == class_) < n_folds for class_ in self.classes_]):\n raise ValueError(f'Requesting {n_folds}-fold cross-validation but provided less than {n_folds} examples for at least one class.')\n cv = check_cv(self.cv, y, classifier=True)\n if self.ensemble:\n parallel = Parallel(n_jobs=self.n_jobs)\n self.calibrated_classifiers_ = parallel((delayed(_fit_classifier_calibrator_pair)(clone(base_estimator), X, y, train=train, test=test, method=self.method, classes=self.classes_, supports_sw=supports_sw, sample_weight=sample_weight) for (train, test) in cv.split(X, y)))\n else:\n this_estimator = clone(base_estimator)\n (_, method_name) = _get_prediction_method(this_estimator)\n fit_params = {'sample_weight': sample_weight} if sample_weight is not None and supports_sw else None\n pred_method = partial(cross_val_predict, estimator=this_estimator, X=X, y=y, cv=cv, method=method_name, n_jobs=self.n_jobs, fit_params=fit_params)\n predictions = _compute_predictions(pred_method, method_name, X, n_classes)\n if sample_weight is not None and supports_sw:\n this_estimator.fit(X, y, sample_weight)\n else:\n this_estimator.fit(X, y)\n calibrated_classifier = _fit_calibrator(this_estimator, predictions, y, self.classes_, self.method, sample_weight)\n self.calibrated_classifiers_.append(calibrated_classifier)\n first_clf = self.calibrated_classifiers_[0].base_estimator\n if hasattr(first_clf, 'n_features_in_'):\n self.n_features_in_ = first_clf.n_features_in_\n if hasattr(first_clf, 'feature_names_in_'):\n self.feature_names_in_ = first_clf.feature_names_in_\n return self\n \n def predict_proba(self, X):\n \"\"\"Calibrated probabilities of classification.\n\n This function returns calibrated probabilities of classification\n according to each class on an array of test vectors X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The samples, as accepted by `base_estimator.predict_proba`.\n\n Returns\n -------\n C : ndarray of shape (n_samples, n_classes)\n The predicted probas.\n \"\"\"\n check_is_fitted(self)\n mean_proba = np.zeros((_num_samples(X), len(self.classes_)))\n for calibrated_classifier in self.calibrated_classifiers_:\n proba = calibrated_classifier.predict_proba(X)\n mean_proba += proba\n mean_proba /= len(self.calibrated_classifiers_)\n return mean_proba\n \n def predict(self, X):\n \"\"\"Predict the target of new samples.\n\n The predicted class is the class that has the highest probability,\n and can thus be different from the prediction of the uncalibrated classifier.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The samples, as accepted by `base_estimator.predict`.\n\n Returns\n -------\n C : ndarray of shape (n_samples,)\n The predicted class.\n \"\"\"\n check_is_fitted(self)\n return self.classes_[np.argmax(self.predict_proba(X), axis=1)]\n \n def _more_tags(self):\n return {'_xfail_checks': {'check_sample_weights_invariance': 'Due to the cross-validation and sample ordering, removing a sample is not strictly equal to putting is weight to zero. Specific unit tests are added for CalibratedClassifierCV specifically.'}}\n" }, { "name": "CalibrationDisplay", @@ -19830,7 +19796,7 @@ "is_public": true, "description": "Calibration curve (also known as reliability diagram) visualization.\n\nIt is recommended to use :func:`~sklearn.calibration.CalibrationDisplay.from_estimator` or :func:`~sklearn.calibration.CalibrationDisplay.from_predictions` to create a `CalibrationDisplay`. All parameters are stored as attributes. Read more about calibration in the :ref:`User Guide ` and more about the scikit-learn visualization API in :ref:`visualizations`. .. versionadded:: 1.0", "docstring": "Calibration curve (also known as reliability diagram) visualization.\n\n It is recommended to use\n :func:`~sklearn.calibration.CalibrationDisplay.from_estimator` or\n :func:`~sklearn.calibration.CalibrationDisplay.from_predictions`\n to create a `CalibrationDisplay`. All parameters are stored as attributes.\n\n Read more about calibration in the :ref:`User Guide ` and\n more about the scikit-learn visualization API in :ref:`visualizations`.\n\n .. versionadded:: 1.0\n\n Parameters\n -----------\n prob_true : ndarray of shape (n_bins,)\n The proportion of samples whose class is the positive class (fraction\n of positives), in each bin.\n\n prob_pred : ndarray of shape (n_bins,)\n The mean predicted probability in each bin.\n\n y_prob : ndarray of shape (n_samples,)\n Probability estimates for the positive class, for each sample.\n\n estimator_name : str, default=None\n Name of estimator. If None, the estimator name is not shown.\n\n Attributes\n ----------\n line_ : matplotlib Artist\n Calibration curve.\n\n ax_ : matplotlib Axes\n Axes with calibration curve.\n\n figure_ : matplotlib Figure\n Figure containing the curve.\n\n See Also\n --------\n calibration_curve : Compute true and predicted probabilities for a\n calibration curve.\n CalibrationDisplay.from_predictions : Plot calibration curve using true\n and predicted labels.\n CalibrationDisplay.from_estimator : Plot calibration curve using an\n estimator and data.\n\n Examples\n --------\n >>> from sklearn.datasets import make_classification\n >>> from sklearn.model_selection import train_test_split\n >>> from sklearn.linear_model import LogisticRegression\n >>> from sklearn.calibration import calibration_curve, CalibrationDisplay\n >>> X, y = make_classification(random_state=0)\n >>> X_train, X_test, y_train, y_test = train_test_split(\n ... X, y, random_state=0)\n >>> clf = LogisticRegression(random_state=0)\n >>> clf.fit(X_train, y_train)\n LogisticRegression(random_state=0)\n >>> y_prob = clf.predict_proba(X_test)[:, 1]\n >>> prob_true, prob_pred = calibration_curve(y_test, y_prob, n_bins=10)\n >>> disp = CalibrationDisplay(prob_true, prob_pred, y_prob)\n >>> disp.plot()\n <...>\n ", - "source_code": "\n\nclass CalibrationDisplay:\n \"\"\"Calibration curve (also known as reliability diagram) visualization.\n\n It is recommended to use\n :func:`~sklearn.calibration.CalibrationDisplay.from_estimator` or\n :func:`~sklearn.calibration.CalibrationDisplay.from_predictions`\n to create a `CalibrationDisplay`. All parameters are stored as attributes.\n\n Read more about calibration in the :ref:`User Guide ` and\n more about the scikit-learn visualization API in :ref:`visualizations`.\n\n .. versionadded:: 1.0\n\n Parameters\n -----------\n prob_true : ndarray of shape (n_bins,)\n The proportion of samples whose class is the positive class (fraction\n of positives), in each bin.\n\n prob_pred : ndarray of shape (n_bins,)\n The mean predicted probability in each bin.\n\n y_prob : ndarray of shape (n_samples,)\n Probability estimates for the positive class, for each sample.\n\n estimator_name : str, default=None\n Name of estimator. If None, the estimator name is not shown.\n\n Attributes\n ----------\n line_ : matplotlib Artist\n Calibration curve.\n\n ax_ : matplotlib Axes\n Axes with calibration curve.\n\n figure_ : matplotlib Figure\n Figure containing the curve.\n\n See Also\n --------\n calibration_curve : Compute true and predicted probabilities for a\n calibration curve.\n CalibrationDisplay.from_predictions : Plot calibration curve using true\n and predicted labels.\n CalibrationDisplay.from_estimator : Plot calibration curve using an\n estimator and data.\n\n Examples\n --------\n >>> from sklearn.datasets import make_classification\n >>> from sklearn.model_selection import train_test_split\n >>> from sklearn.linear_model import LogisticRegression\n >>> from sklearn.calibration import calibration_curve, CalibrationDisplay\n >>> X, y = make_classification(random_state=0)\n >>> X_train, X_test, y_train, y_test = train_test_split(\n ... X, y, random_state=0)\n >>> clf = LogisticRegression(random_state=0)\n >>> clf.fit(X_train, y_train)\n LogisticRegression(random_state=0)\n >>> y_prob = clf.predict_proba(X_test)[:, 1]\n >>> prob_true, prob_pred = calibration_curve(y_test, y_prob, n_bins=10)\n >>> disp = CalibrationDisplay(prob_true, prob_pred, y_prob)\n >>> disp.plot()\n <...>\n \"\"\"\n \n def __init__(self, prob_true, prob_pred, y_prob, *, estimator_name=None):\n self.prob_true = prob_true\n self.prob_pred = prob_pred\n self.y_prob = y_prob\n self.estimator_name = estimator_name\n \n def plot(self, *, ax=None, name=None, ref_line=True, **kwargs):\n \"\"\"Plot visualization.\n\n Extra keyword arguments will be passed to\n :func:`matplotlib.pyplot.plot`.\n\n Parameters\n ----------\n ax : Matplotlib Axes, default=None\n Axes object to plot on. If `None`, a new figure and axes is\n created.\n\n name : str, default=None\n Name for labeling curve. If `None`, use `estimator_name` if\n not `None`, otherwise no labeling is shown.\n\n ref_line : bool, default=True\n If `True`, plots a reference line representing a perfectly\n calibrated classifier.\n\n **kwargs : dict\n Keyword arguments to be passed to :func:`matplotlib.pyplot.plot`.\n\n Returns\n -------\n display : :class:`~sklearn.calibration.CalibrationDisplay`\n Object that stores computed values.\n \"\"\"\n check_matplotlib_support('CalibrationDisplay.plot')\n import matplotlib.pyplot as plt\n if ax is None:\n (fig, ax) = plt.subplots()\n name = self.estimator_name if name is None else name\n line_kwargs = {}\n if name is not None:\n line_kwargs['label'] = name\n line_kwargs.update(**kwargs)\n ref_line_label = 'Perfectly calibrated'\n existing_ref_line = ref_line_label in ax.get_legend_handles_labels()[1]\n if ref_line and not existing_ref_line:\n ax.plot([0, 1], [0, 1], 'k:', label=ref_line_label)\n self.line_ = ax.plot(self.prob_pred, self.prob_true, 's-', **line_kwargs)[0]\n if 'label' in line_kwargs:\n ax.legend(loc='lower right')\n ax.set(xlabel='Mean predicted probability', ylabel='Fraction of positives')\n self.ax_ = ax\n self.figure_ = ax.figure\n return self\n \n @classmethod\n def from_estimator(cls, estimator, X, y, *, n_bins=5, strategy='uniform', name=None, ref_line=True, ax=None, **kwargs):\n \"\"\"Plot calibration curve using an binary classifier and data.\n\n Calibration curve, also known as reliability diagram, uses inputs\n from a binary classifier and plots the average predicted probability\n for each bin against the fraction of positive classes, on the\n y-axis.\n\n Extra keyword arguments will be passed to\n :func:`matplotlib.pyplot.plot`.\n\n Read more about calibration in the :ref:`User Guide ` and\n more about the scikit-learn visualization API in :ref:`visualizations`.\n\n .. versionadded:: 1.0\n\n Parameters\n ----------\n estimator : estimator instance\n Fitted classifier or a fitted :class:`~sklearn.pipeline.Pipeline`\n in which the last estimator is a classifier. The classifier must\n have a :term:`predict_proba` method.\n\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input values.\n\n y : array-like of shape (n_samples,)\n Binary target values.\n\n n_bins : int, default=5\n Number of bins to discretize the [0, 1] interval into when\n calculating the calibration curve. A bigger number requires more\n data.\n\n strategy : {'uniform', 'quantile'}, default='uniform'\n Strategy used to define the widths of the bins.\n\n - `'uniform'`: The bins have identical widths.\n - `'quantile'`: The bins have the same number of samples and depend\n on predicted probabilities.\n\n name : str, default=None\n Name for labeling curve. If `None`, the name of the estimator is\n used.\n\n ref_line : bool, default=True\n If `True`, plots a reference line representing a perfectly\n calibrated classifier.\n\n ax : matplotlib axes, default=None\n Axes object to plot on. If `None`, a new figure and axes is\n created.\n\n **kwargs : dict\n Keyword arguments to be passed to :func:`matplotlib.pyplot.plot`.\n\n Returns\n -------\n display : :class:`~sklearn.calibration.CalibrationDisplay`.\n Object that stores computed values.\n\n See Also\n --------\n CalibrationDisplay.from_predictions : Plot calibration curve using true\n and predicted labels.\n\n Examples\n --------\n >>> import matplotlib.pyplot as plt\n >>> from sklearn.datasets import make_classification\n >>> from sklearn.model_selection import train_test_split\n >>> from sklearn.linear_model import LogisticRegression\n >>> from sklearn.calibration import CalibrationDisplay\n >>> X, y = make_classification(random_state=0)\n >>> X_train, X_test, y_train, y_test = train_test_split(\n ... X, y, random_state=0)\n >>> clf = LogisticRegression(random_state=0)\n >>> clf.fit(X_train, y_train)\n LogisticRegression(random_state=0)\n >>> disp = CalibrationDisplay.from_estimator(clf, X_test, y_test)\n >>> plt.show()\n \"\"\"\n method_name = f'{cls.__name__}.from_estimator'\n check_matplotlib_support(method_name)\n if not is_classifier(estimator):\n raise ValueError(\"'estimator' should be a fitted classifier.\")\n (y_prob, _) = _get_response(X, estimator, response_method='predict_proba', pos_label=None)\n name = name if name is not None else estimator.__class__.__name__\n return cls.from_predictions(y, y_prob, n_bins=n_bins, strategy=strategy, name=name, ref_line=ref_line, ax=ax, **kwargs)\n \n @classmethod\n def from_predictions(cls, y_true, y_prob, *, n_bins=5, strategy='uniform', name=None, ref_line=True, ax=None, **kwargs):\n \"\"\"Plot calibration curve using true labels and predicted probabilities.\n\n Calibration curve, also known as reliability diagram, uses inputs\n from a binary classifier and plots the average predicted probability\n for each bin against the fraction of positive classes, on the\n y-axis.\n\n Extra keyword arguments will be passed to\n :func:`matplotlib.pyplot.plot`.\n\n Read more about calibration in the :ref:`User Guide ` and\n more about the scikit-learn visualization API in :ref:`visualizations`.\n\n .. versionadded:: 1.0\n\n Parameters\n ----------\n y_true : array-like of shape (n_samples,)\n True labels.\n\n y_prob : array-like of shape (n_samples,)\n The predicted probabilities of the positive class.\n\n n_bins : int, default=5\n Number of bins to discretize the [0, 1] interval into when\n calculating the calibration curve. A bigger number requires more\n data.\n\n strategy : {'uniform', 'quantile'}, default='uniform'\n Strategy used to define the widths of the bins.\n\n - `'uniform'`: The bins have identical widths.\n - `'quantile'`: The bins have the same number of samples and depend\n on predicted probabilities.\n\n name : str, default=None\n Name for labeling curve.\n\n ref_line : bool, default=True\n If `True`, plots a reference line representing a perfectly\n calibrated classifier.\n\n ax : matplotlib axes, default=None\n Axes object to plot on. If `None`, a new figure and axes is\n created.\n\n **kwargs : dict\n Keyword arguments to be passed to :func:`matplotlib.pyplot.plot`.\n\n Returns\n -------\n display : :class:`~sklearn.calibration.CalibrationDisplay`.\n Object that stores computed values.\n\n See Also\n --------\n CalibrationDisplay.from_estimator : Plot calibration curve using an\n estimator and data.\n\n Examples\n --------\n >>> import matplotlib.pyplot as plt\n >>> from sklearn.datasets import make_classification\n >>> from sklearn.model_selection import train_test_split\n >>> from sklearn.linear_model import LogisticRegression\n >>> from sklearn.calibration import CalibrationDisplay\n >>> X, y = make_classification(random_state=0)\n >>> X_train, X_test, y_train, y_test = train_test_split(\n ... X, y, random_state=0)\n >>> clf = LogisticRegression(random_state=0)\n >>> clf.fit(X_train, y_train)\n LogisticRegression(random_state=0)\n >>> y_prob = clf.predict_proba(X_test)[:, 1]\n >>> disp = CalibrationDisplay.from_predictions(y_test, y_prob)\n >>> plt.show()\n \"\"\"\n method_name = f'{cls.__name__}.from_estimator'\n check_matplotlib_support(method_name)\n (prob_true, prob_pred) = calibration_curve(y_true, y_prob, n_bins=n_bins, strategy=strategy)\n name = name if name is not None else 'Classifier'\n disp = cls(prob_true=prob_true, prob_pred=prob_pred, y_prob=y_prob, estimator_name=name)\n return disp.plot(ax=ax, ref_line=ref_line, **kwargs)\n" + "source_code": "\n\nclass CalibrationDisplay:\n \"\"\"Calibration curve (also known as reliability diagram) visualization.\n\n It is recommended to use\n :func:`~sklearn.calibration.CalibrationDisplay.from_estimator` or\n :func:`~sklearn.calibration.CalibrationDisplay.from_predictions`\n to create a `CalibrationDisplay`. All parameters are stored as attributes.\n\n Read more about calibration in the :ref:`User Guide ` and\n more about the scikit-learn visualization API in :ref:`visualizations`.\n\n .. versionadded:: 1.0\n\n Parameters\n -----------\n prob_true : ndarray of shape (n_bins,)\n The proportion of samples whose class is the positive class (fraction\n of positives), in each bin.\n\n prob_pred : ndarray of shape (n_bins,)\n The mean predicted probability in each bin.\n\n y_prob : ndarray of shape (n_samples,)\n Probability estimates for the positive class, for each sample.\n\n estimator_name : str, default=None\n Name of estimator. If None, the estimator name is not shown.\n\n Attributes\n ----------\n line_ : matplotlib Artist\n Calibration curve.\n\n ax_ : matplotlib Axes\n Axes with calibration curve.\n\n figure_ : matplotlib Figure\n Figure containing the curve.\n\n See Also\n --------\n calibration_curve : Compute true and predicted probabilities for a\n calibration curve.\n CalibrationDisplay.from_predictions : Plot calibration curve using true\n and predicted labels.\n CalibrationDisplay.from_estimator : Plot calibration curve using an\n estimator and data.\n\n Examples\n --------\n >>> from sklearn.datasets import make_classification\n >>> from sklearn.model_selection import train_test_split\n >>> from sklearn.linear_model import LogisticRegression\n >>> from sklearn.calibration import calibration_curve, CalibrationDisplay\n >>> X, y = make_classification(random_state=0)\n >>> X_train, X_test, y_train, y_test = train_test_split(\n ... X, y, random_state=0)\n >>> clf = LogisticRegression(random_state=0)\n >>> clf.fit(X_train, y_train)\n LogisticRegression(random_state=0)\n >>> y_prob = clf.predict_proba(X_test)[:, 1]\n >>> prob_true, prob_pred = calibration_curve(y_test, y_prob, n_bins=10)\n >>> disp = CalibrationDisplay(prob_true, prob_pred, y_prob)\n >>> disp.plot()\n <...>\n \"\"\"\n \n def __init__(self, prob_true, prob_pred, y_prob, *, estimator_name=None):\n self.prob_true = prob_true\n self.prob_pred = prob_pred\n self.y_prob = y_prob\n self.estimator_name = estimator_name\n \n def plot(self, *, ax=None, name=None, ref_line=True, **kwargs):\n \"\"\"Plot visualization.\n\n Extra keyword arguments will be passed to\n :func:`matplotlib.pyplot.plot`.\n\n Parameters\n ----------\n ax : Matplotlib Axes, default=None\n Axes object to plot on. If `None`, a new figure and axes is\n created.\n\n name : str, default=None\n Name for labeling curve. If `None`, use `estimator_name` if\n not `None`, otherwise no labeling is shown.\n\n ref_line : bool, default=True\n If `True`, plots a reference line representing a perfectly\n calibrated classifier.\n\n **kwargs : dict\n Keyword arguments to be passed to :func:`matplotlib.pyplot.plot`.\n\n Returns\n -------\n display : :class:`~sklearn.calibration.CalibrationDisplay`\n Object that stores computed values.\n \"\"\"\n check_matplotlib_support('CalibrationDisplay.plot')\n import matplotlib.pyplot as plt\n if ax is None:\n (fig, ax) = plt.subplots()\n name = self.estimator_name if name is None else name\n line_kwargs = {}\n if name is not None:\n line_kwargs['label'] = name\n line_kwargs.update(**kwargs)\n ref_line_label = 'Perfectly calibrated'\n existing_ref_line = ref_line_label in ax.get_legend_handles_labels()[1]\n if ref_line and not existing_ref_line:\n ax.plot([0, 1], [0, 1], 'k:', label=ref_line_label)\n self.line_ = ax.plot(self.prob_pred, self.prob_true, 's-', **line_kwargs)[0]\n if 'label' in line_kwargs:\n ax.legend(loc='lower right')\n ax.set(xlabel='Mean predicted probability', ylabel='Fraction of positives')\n self.ax_ = ax\n self.figure_ = ax.figure\n return self\n \n @classmethod\n def from_estimator(cls, estimator, X, y, *, n_bins=5, strategy='uniform', name=None, ref_line=True, ax=None, **kwargs):\n \"\"\"Plot calibration curve using a binary classifier and data.\n\n A calibration curve, also known as a reliability diagram, uses inputs\n from a binary classifier and plots the average predicted probability\n for each bin against the fraction of positive classes, on the\n y-axis.\n\n Extra keyword arguments will be passed to\n :func:`matplotlib.pyplot.plot`.\n\n Read more about calibration in the :ref:`User Guide ` and\n more about the scikit-learn visualization API in :ref:`visualizations`.\n\n .. versionadded:: 1.0\n\n Parameters\n ----------\n estimator : estimator instance\n Fitted classifier or a fitted :class:`~sklearn.pipeline.Pipeline`\n in which the last estimator is a classifier. The classifier must\n have a :term:`predict_proba` method.\n\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input values.\n\n y : array-like of shape (n_samples,)\n Binary target values.\n\n n_bins : int, default=5\n Number of bins to discretize the [0, 1] interval into when\n calculating the calibration curve. A bigger number requires more\n data.\n\n strategy : {'uniform', 'quantile'}, default='uniform'\n Strategy used to define the widths of the bins.\n\n - `'uniform'`: The bins have identical widths.\n - `'quantile'`: The bins have the same number of samples and depend\n on predicted probabilities.\n\n name : str, default=None\n Name for labeling curve. If `None`, the name of the estimator is\n used.\n\n ref_line : bool, default=True\n If `True`, plots a reference line representing a perfectly\n calibrated classifier.\n\n ax : matplotlib axes, default=None\n Axes object to plot on. If `None`, a new figure and axes is\n created.\n\n **kwargs : dict\n Keyword arguments to be passed to :func:`matplotlib.pyplot.plot`.\n\n Returns\n -------\n display : :class:`~sklearn.calibration.CalibrationDisplay`.\n Object that stores computed values.\n\n See Also\n --------\n CalibrationDisplay.from_predictions : Plot calibration curve using true\n and predicted labels.\n\n Examples\n --------\n >>> import matplotlib.pyplot as plt\n >>> from sklearn.datasets import make_classification\n >>> from sklearn.model_selection import train_test_split\n >>> from sklearn.linear_model import LogisticRegression\n >>> from sklearn.calibration import CalibrationDisplay\n >>> X, y = make_classification(random_state=0)\n >>> X_train, X_test, y_train, y_test = train_test_split(\n ... X, y, random_state=0)\n >>> clf = LogisticRegression(random_state=0)\n >>> clf.fit(X_train, y_train)\n LogisticRegression(random_state=0)\n >>> disp = CalibrationDisplay.from_estimator(clf, X_test, y_test)\n >>> plt.show()\n \"\"\"\n method_name = f'{cls.__name__}.from_estimator'\n check_matplotlib_support(method_name)\n if not is_classifier(estimator):\n raise ValueError(\"'estimator' should be a fitted classifier.\")\n (y_prob, _) = _get_response(X, estimator, response_method='predict_proba', pos_label=None)\n name = name if name is not None else estimator.__class__.__name__\n return cls.from_predictions(y, y_prob, n_bins=n_bins, strategy=strategy, name=name, ref_line=ref_line, ax=ax, **kwargs)\n \n @classmethod\n def from_predictions(cls, y_true, y_prob, *, n_bins=5, strategy='uniform', name=None, ref_line=True, ax=None, **kwargs):\n \"\"\"Plot calibration curve using true labels and predicted probabilities.\n\n Calibration curve, also known as reliability diagram, uses inputs\n from a binary classifier and plots the average predicted probability\n for each bin against the fraction of positive classes, on the\n y-axis.\n\n Extra keyword arguments will be passed to\n :func:`matplotlib.pyplot.plot`.\n\n Read more about calibration in the :ref:`User Guide ` and\n more about the scikit-learn visualization API in :ref:`visualizations`.\n\n .. versionadded:: 1.0\n\n Parameters\n ----------\n y_true : array-like of shape (n_samples,)\n True labels.\n\n y_prob : array-like of shape (n_samples,)\n The predicted probabilities of the positive class.\n\n n_bins : int, default=5\n Number of bins to discretize the [0, 1] interval into when\n calculating the calibration curve. A bigger number requires more\n data.\n\n strategy : {'uniform', 'quantile'}, default='uniform'\n Strategy used to define the widths of the bins.\n\n - `'uniform'`: The bins have identical widths.\n - `'quantile'`: The bins have the same number of samples and depend\n on predicted probabilities.\n\n name : str, default=None\n Name for labeling curve.\n\n ref_line : bool, default=True\n If `True`, plots a reference line representing a perfectly\n calibrated classifier.\n\n ax : matplotlib axes, default=None\n Axes object to plot on. If `None`, a new figure and axes is\n created.\n\n **kwargs : dict\n Keyword arguments to be passed to :func:`matplotlib.pyplot.plot`.\n\n Returns\n -------\n display : :class:`~sklearn.calibration.CalibrationDisplay`.\n Object that stores computed values.\n\n See Also\n --------\n CalibrationDisplay.from_estimator : Plot calibration curve using an\n estimator and data.\n\n Examples\n --------\n >>> import matplotlib.pyplot as plt\n >>> from sklearn.datasets import make_classification\n >>> from sklearn.model_selection import train_test_split\n >>> from sklearn.linear_model import LogisticRegression\n >>> from sklearn.calibration import CalibrationDisplay\n >>> X, y = make_classification(random_state=0)\n >>> X_train, X_test, y_train, y_test = train_test_split(\n ... X, y, random_state=0)\n >>> clf = LogisticRegression(random_state=0)\n >>> clf.fit(X_train, y_train)\n LogisticRegression(random_state=0)\n >>> y_prob = clf.predict_proba(X_test)[:, 1]\n >>> disp = CalibrationDisplay.from_predictions(y_test, y_prob)\n >>> plt.show()\n \"\"\"\n method_name = f'{cls.__name__}.from_estimator'\n check_matplotlib_support(method_name)\n (prob_true, prob_pred) = calibration_curve(y_true, y_prob, n_bins=n_bins, strategy=strategy)\n name = name if name is not None else 'Classifier'\n disp = cls(prob_true=prob_true, prob_pred=prob_pred, y_prob=y_prob, estimator_name=name)\n return disp.plot(ax=ax, ref_line=ref_line, **kwargs)\n" }, { "name": "_CalibratedClassifier", @@ -19839,7 +19805,7 @@ "superclasses": [], "methods": [ "sklearn.calibration._CalibratedClassifier.__init__", - "sklearn.calibration._CalibratedClassifier.calibrators_", + "sklearn.calibration._CalibratedClassifier.calibrators_@getter", "sklearn.calibration._CalibratedClassifier.predict_proba" ], "is_public": false, @@ -19868,7 +19834,7 @@ "superclasses": ["ClusterMixin", "BaseEstimator"], "methods": [ "sklearn.cluster._affinity_propagation.AffinityPropagation.__init__", - "sklearn.cluster._affinity_propagation.AffinityPropagation._pairwise", + "sklearn.cluster._affinity_propagation.AffinityPropagation._pairwise@getter", "sklearn.cluster._affinity_propagation.AffinityPropagation._more_tags", "sklearn.cluster._affinity_propagation.AffinityPropagation.fit", "sklearn.cluster._affinity_propagation.AffinityPropagation.predict", @@ -19887,12 +19853,13 @@ "methods": [ "sklearn.cluster._agglomerative.AgglomerativeClustering.__init__", "sklearn.cluster._agglomerative.AgglomerativeClustering.fit", + "sklearn.cluster._agglomerative.AgglomerativeClustering._fit", "sklearn.cluster._agglomerative.AgglomerativeClustering.fit_predict" ], "is_public": true, "description": "Agglomerative Clustering.\n\nRecursively merges pair of clusters of sample data; uses linkage distance. Read more in the :ref:`User Guide `.", "docstring": "\n Agglomerative Clustering.\n\n Recursively merges pair of clusters of sample data; uses linkage distance.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_clusters : int or None, default=2\n The number of clusters to find. It must be ``None`` if\n ``distance_threshold`` is not ``None``.\n\n affinity : str or callable, default='euclidean'\n Metric used to compute the linkage. Can be \"euclidean\", \"l1\", \"l2\",\n \"manhattan\", \"cosine\", or \"precomputed\".\n If linkage is \"ward\", only \"euclidean\" is accepted.\n If \"precomputed\", a distance matrix (instead of a similarity matrix)\n is needed as input for the fit method.\n\n memory : str or object with the joblib.Memory interface, default=None\n Used to cache the output of the computation of the tree.\n By default, no caching is done. If a string is given, it is the\n path to the caching directory.\n\n connectivity : array-like or callable, default=None\n Connectivity matrix. Defines for each sample the neighboring\n samples following a given structure of the data.\n This can be a connectivity matrix itself or a callable that transforms\n the data into a connectivity matrix, such as derived from\n `kneighbors_graph`. Default is ``None``, i.e, the\n hierarchical clustering algorithm is unstructured.\n\n compute_full_tree : 'auto' or bool, default='auto'\n Stop early the construction of the tree at ``n_clusters``. This is\n useful to decrease computation time if the number of clusters is not\n small compared to the number of samples. This option is useful only\n when specifying a connectivity matrix. Note also that when varying the\n number of clusters and using caching, it may be advantageous to compute\n the full tree. It must be ``True`` if ``distance_threshold`` is not\n ``None``. By default `compute_full_tree` is \"auto\", which is equivalent\n to `True` when `distance_threshold` is not `None` or that `n_clusters`\n is inferior to the maximum between 100 or `0.02 * n_samples`.\n Otherwise, \"auto\" is equivalent to `False`.\n\n linkage : {'ward', 'complete', 'average', 'single'}, default='ward'\n Which linkage criterion to use. The linkage criterion determines which\n distance to use between sets of observation. The algorithm will merge\n the pairs of cluster that minimize this criterion.\n\n - 'ward' minimizes the variance of the clusters being merged.\n - 'average' uses the average of the distances of each observation of\n the two sets.\n - 'complete' or 'maximum' linkage uses the maximum distances between\n all observations of the two sets.\n - 'single' uses the minimum of the distances between all observations\n of the two sets.\n\n .. versionadded:: 0.20\n Added the 'single' option\n\n distance_threshold : float, default=None\n The linkage distance threshold above which, clusters will not be\n merged. If not ``None``, ``n_clusters`` must be ``None`` and\n ``compute_full_tree`` must be ``True``.\n\n .. versionadded:: 0.21\n\n compute_distances : bool, default=False\n Computes distances between clusters even if `distance_threshold` is not\n used. This can be used to make dendrogram visualization, but introduces\n a computational and memory overhead.\n\n .. versionadded:: 0.24\n\n Attributes\n ----------\n n_clusters_ : int\n The number of clusters found by the algorithm. If\n ``distance_threshold=None``, it will be equal to the given\n ``n_clusters``.\n\n labels_ : ndarray of shape (n_samples)\n Cluster labels for each point.\n\n n_leaves_ : int\n Number of leaves in the hierarchical tree.\n\n n_connected_components_ : int\n The estimated number of connected components in the graph.\n\n .. versionadded:: 0.21\n ``n_connected_components_`` was added to replace ``n_components_``.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n children_ : array-like of shape (n_samples-1, 2)\n The children of each non-leaf node. Values less than `n_samples`\n correspond to leaves of the tree which are the original samples.\n A node `i` greater than or equal to `n_samples` is a non-leaf\n node and has children `children_[i - n_samples]`. Alternatively\n at the i-th iteration, children[i][0] and children[i][1]\n are merged to form node `n_samples + i`.\n\n distances_ : array-like of shape (n_nodes-1,)\n Distances between nodes in the corresponding place in `children_`.\n Only computed if `distance_threshold` is used or `compute_distances`\n is set to `True`.\n\n See Also\n --------\n FeatureAgglomeration : Agglomerative clustering but for features instead of\n samples.\n ward_tree : Hierarchical clustering with ward linkage.\n\n Examples\n --------\n >>> from sklearn.cluster import AgglomerativeClustering\n >>> import numpy as np\n >>> X = np.array([[1, 2], [1, 4], [1, 0],\n ... [4, 2], [4, 4], [4, 0]])\n >>> clustering = AgglomerativeClustering().fit(X)\n >>> clustering\n AgglomerativeClustering()\n >>> clustering.labels_\n array([1, 1, 1, 0, 0, 0])\n ", - "source_code": "\n\nclass AgglomerativeClustering(ClusterMixin, BaseEstimator):\n \"\"\"\n Agglomerative Clustering.\n\n Recursively merges pair of clusters of sample data; uses linkage distance.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_clusters : int or None, default=2\n The number of clusters to find. It must be ``None`` if\n ``distance_threshold`` is not ``None``.\n\n affinity : str or callable, default='euclidean'\n Metric used to compute the linkage. Can be \"euclidean\", \"l1\", \"l2\",\n \"manhattan\", \"cosine\", or \"precomputed\".\n If linkage is \"ward\", only \"euclidean\" is accepted.\n If \"precomputed\", a distance matrix (instead of a similarity matrix)\n is needed as input for the fit method.\n\n memory : str or object with the joblib.Memory interface, default=None\n Used to cache the output of the computation of the tree.\n By default, no caching is done. If a string is given, it is the\n path to the caching directory.\n\n connectivity : array-like or callable, default=None\n Connectivity matrix. Defines for each sample the neighboring\n samples following a given structure of the data.\n This can be a connectivity matrix itself or a callable that transforms\n the data into a connectivity matrix, such as derived from\n `kneighbors_graph`. Default is ``None``, i.e, the\n hierarchical clustering algorithm is unstructured.\n\n compute_full_tree : 'auto' or bool, default='auto'\n Stop early the construction of the tree at ``n_clusters``. This is\n useful to decrease computation time if the number of clusters is not\n small compared to the number of samples. This option is useful only\n when specifying a connectivity matrix. Note also that when varying the\n number of clusters and using caching, it may be advantageous to compute\n the full tree. It must be ``True`` if ``distance_threshold`` is not\n ``None``. By default `compute_full_tree` is \"auto\", which is equivalent\n to `True` when `distance_threshold` is not `None` or that `n_clusters`\n is inferior to the maximum between 100 or `0.02 * n_samples`.\n Otherwise, \"auto\" is equivalent to `False`.\n\n linkage : {'ward', 'complete', 'average', 'single'}, default='ward'\n Which linkage criterion to use. The linkage criterion determines which\n distance to use between sets of observation. The algorithm will merge\n the pairs of cluster that minimize this criterion.\n\n - 'ward' minimizes the variance of the clusters being merged.\n - 'average' uses the average of the distances of each observation of\n the two sets.\n - 'complete' or 'maximum' linkage uses the maximum distances between\n all observations of the two sets.\n - 'single' uses the minimum of the distances between all observations\n of the two sets.\n\n .. versionadded:: 0.20\n Added the 'single' option\n\n distance_threshold : float, default=None\n The linkage distance threshold above which, clusters will not be\n merged. If not ``None``, ``n_clusters`` must be ``None`` and\n ``compute_full_tree`` must be ``True``.\n\n .. versionadded:: 0.21\n\n compute_distances : bool, default=False\n Computes distances between clusters even if `distance_threshold` is not\n used. This can be used to make dendrogram visualization, but introduces\n a computational and memory overhead.\n\n .. versionadded:: 0.24\n\n Attributes\n ----------\n n_clusters_ : int\n The number of clusters found by the algorithm. If\n ``distance_threshold=None``, it will be equal to the given\n ``n_clusters``.\n\n labels_ : ndarray of shape (n_samples)\n Cluster labels for each point.\n\n n_leaves_ : int\n Number of leaves in the hierarchical tree.\n\n n_connected_components_ : int\n The estimated number of connected components in the graph.\n\n .. versionadded:: 0.21\n ``n_connected_components_`` was added to replace ``n_components_``.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n children_ : array-like of shape (n_samples-1, 2)\n The children of each non-leaf node. Values less than `n_samples`\n correspond to leaves of the tree which are the original samples.\n A node `i` greater than or equal to `n_samples` is a non-leaf\n node and has children `children_[i - n_samples]`. Alternatively\n at the i-th iteration, children[i][0] and children[i][1]\n are merged to form node `n_samples + i`.\n\n distances_ : array-like of shape (n_nodes-1,)\n Distances between nodes in the corresponding place in `children_`.\n Only computed if `distance_threshold` is used or `compute_distances`\n is set to `True`.\n\n See Also\n --------\n FeatureAgglomeration : Agglomerative clustering but for features instead of\n samples.\n ward_tree : Hierarchical clustering with ward linkage.\n\n Examples\n --------\n >>> from sklearn.cluster import AgglomerativeClustering\n >>> import numpy as np\n >>> X = np.array([[1, 2], [1, 4], [1, 0],\n ... [4, 2], [4, 4], [4, 0]])\n >>> clustering = AgglomerativeClustering().fit(X)\n >>> clustering\n AgglomerativeClustering()\n >>> clustering.labels_\n array([1, 1, 1, 0, 0, 0])\n \"\"\"\n \n def __init__(self, n_clusters=2, *, affinity='euclidean', memory=None, connectivity=None, compute_full_tree='auto', linkage='ward', distance_threshold=None, compute_distances=False):\n self.n_clusters = n_clusters\n self.distance_threshold = distance_threshold\n self.memory = memory\n self.connectivity = connectivity\n self.compute_full_tree = compute_full_tree\n self.linkage = linkage\n self.affinity = affinity\n self.compute_distances = compute_distances\n \n def fit(self, X, y=None):\n \"\"\"Fit the hierarchical clustering from features, or distance matrix.\n\n Parameters\n ----------\n X : array-like, shape (n_samples, n_features) or (n_samples, n_samples)\n Training instances to cluster, or distances between instances if\n ``affinity='precomputed'``.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self : object\n Returns the fitted instance.\n \"\"\"\n X = self._validate_data(X, ensure_min_samples=2, estimator=self)\n memory = check_memory(self.memory)\n if self.n_clusters is not None and self.n_clusters <= 0:\n raise ValueError('n_clusters should be an integer greater than 0. %s was provided.' % str(self.n_clusters))\n if not (self.n_clusters is None) ^ (self.distance_threshold is None):\n raise ValueError('Exactly one of n_clusters and distance_threshold has to be set, and the other needs to be None.')\n if self.distance_threshold is not None and not self.compute_full_tree:\n raise ValueError('compute_full_tree must be True if distance_threshold is set.')\n if self.linkage == 'ward' and self.affinity != 'euclidean':\n raise ValueError('%s was provided as affinity. Ward can only work with euclidean distances.' % (self.affinity, ))\n if self.linkage not in _TREE_BUILDERS:\n raise ValueError('Unknown linkage type %s. Valid options are %s' % (self.linkage, _TREE_BUILDERS.keys()))\n tree_builder = _TREE_BUILDERS[self.linkage]\n connectivity = self.connectivity\n if self.connectivity is not None:\n if callable(self.connectivity):\n connectivity = self.connectivity(X)\n connectivity = check_array(connectivity, accept_sparse=['csr', 'coo', 'lil'])\n n_samples = len(X)\n compute_full_tree = self.compute_full_tree\n if self.connectivity is None:\n compute_full_tree = True\n if compute_full_tree == 'auto':\n if self.distance_threshold is not None:\n compute_full_tree = True\n else:\n compute_full_tree = self.n_clusters < max(100, 0.02 * n_samples)\n n_clusters = self.n_clusters\n if compute_full_tree:\n n_clusters = None\n kwargs = {}\n if self.linkage != 'ward':\n kwargs['linkage'] = self.linkage\n kwargs['affinity'] = self.affinity\n distance_threshold = self.distance_threshold\n return_distance = distance_threshold is not None or self.compute_distances\n out = memory.cache(tree_builder)(X, connectivity=connectivity, n_clusters=n_clusters, return_distance=return_distance, **kwargs)\n (self.children_, self.n_connected_components_, self.n_leaves_, parents) = out[:4]\n if return_distance:\n self.distances_ = out[-1]\n if self.distance_threshold is not None:\n self.n_clusters_ = np.count_nonzero(self.distances_ >= distance_threshold) + 1\n else:\n self.n_clusters_ = self.n_clusters\n if compute_full_tree:\n self.labels_ = _hc_cut(self.n_clusters_, self.children_, self.n_leaves_)\n else:\n labels = _hierarchical.hc_get_heads(parents, copy=False)\n labels = np.copy(labels[:n_samples])\n self.labels_ = np.searchsorted(np.unique(labels), labels)\n return self\n \n def fit_predict(self, X, y=None):\n \"\"\"Fit and return the result of each sample's clustering assignment.\n\n In addition to fitting, this method also return the result of the\n clustering assignment for each sample in the training set.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features) or (n_samples, n_samples)\n Training instances to cluster, or distances between instances if\n ``affinity='precomputed'``.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n labels : ndarray of shape (n_samples,)\n Cluster labels.\n \"\"\"\n return super().fit_predict(X, y)\n" + "source_code": "\n\nclass AgglomerativeClustering(ClusterMixin, BaseEstimator):\n \"\"\"\n Agglomerative Clustering.\n\n Recursively merges pair of clusters of sample data; uses linkage distance.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_clusters : int or None, default=2\n The number of clusters to find. It must be ``None`` if\n ``distance_threshold`` is not ``None``.\n\n affinity : str or callable, default='euclidean'\n Metric used to compute the linkage. Can be \"euclidean\", \"l1\", \"l2\",\n \"manhattan\", \"cosine\", or \"precomputed\".\n If linkage is \"ward\", only \"euclidean\" is accepted.\n If \"precomputed\", a distance matrix (instead of a similarity matrix)\n is needed as input for the fit method.\n\n memory : str or object with the joblib.Memory interface, default=None\n Used to cache the output of the computation of the tree.\n By default, no caching is done. If a string is given, it is the\n path to the caching directory.\n\n connectivity : array-like or callable, default=None\n Connectivity matrix. Defines for each sample the neighboring\n samples following a given structure of the data.\n This can be a connectivity matrix itself or a callable that transforms\n the data into a connectivity matrix, such as derived from\n `kneighbors_graph`. Default is ``None``, i.e, the\n hierarchical clustering algorithm is unstructured.\n\n compute_full_tree : 'auto' or bool, default='auto'\n Stop early the construction of the tree at ``n_clusters``. This is\n useful to decrease computation time if the number of clusters is not\n small compared to the number of samples. This option is useful only\n when specifying a connectivity matrix. Note also that when varying the\n number of clusters and using caching, it may be advantageous to compute\n the full tree. It must be ``True`` if ``distance_threshold`` is not\n ``None``. By default `compute_full_tree` is \"auto\", which is equivalent\n to `True` when `distance_threshold` is not `None` or that `n_clusters`\n is inferior to the maximum between 100 or `0.02 * n_samples`.\n Otherwise, \"auto\" is equivalent to `False`.\n\n linkage : {'ward', 'complete', 'average', 'single'}, default='ward'\n Which linkage criterion to use. The linkage criterion determines which\n distance to use between sets of observation. The algorithm will merge\n the pairs of cluster that minimize this criterion.\n\n - 'ward' minimizes the variance of the clusters being merged.\n - 'average' uses the average of the distances of each observation of\n the two sets.\n - 'complete' or 'maximum' linkage uses the maximum distances between\n all observations of the two sets.\n - 'single' uses the minimum of the distances between all observations\n of the two sets.\n\n .. versionadded:: 0.20\n Added the 'single' option\n\n distance_threshold : float, default=None\n The linkage distance threshold above which, clusters will not be\n merged. If not ``None``, ``n_clusters`` must be ``None`` and\n ``compute_full_tree`` must be ``True``.\n\n .. versionadded:: 0.21\n\n compute_distances : bool, default=False\n Computes distances between clusters even if `distance_threshold` is not\n used. This can be used to make dendrogram visualization, but introduces\n a computational and memory overhead.\n\n .. versionadded:: 0.24\n\n Attributes\n ----------\n n_clusters_ : int\n The number of clusters found by the algorithm. If\n ``distance_threshold=None``, it will be equal to the given\n ``n_clusters``.\n\n labels_ : ndarray of shape (n_samples)\n Cluster labels for each point.\n\n n_leaves_ : int\n Number of leaves in the hierarchical tree.\n\n n_connected_components_ : int\n The estimated number of connected components in the graph.\n\n .. versionadded:: 0.21\n ``n_connected_components_`` was added to replace ``n_components_``.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n children_ : array-like of shape (n_samples-1, 2)\n The children of each non-leaf node. Values less than `n_samples`\n correspond to leaves of the tree which are the original samples.\n A node `i` greater than or equal to `n_samples` is a non-leaf\n node and has children `children_[i - n_samples]`. Alternatively\n at the i-th iteration, children[i][0] and children[i][1]\n are merged to form node `n_samples + i`.\n\n distances_ : array-like of shape (n_nodes-1,)\n Distances between nodes in the corresponding place in `children_`.\n Only computed if `distance_threshold` is used or `compute_distances`\n is set to `True`.\n\n See Also\n --------\n FeatureAgglomeration : Agglomerative clustering but for features instead of\n samples.\n ward_tree : Hierarchical clustering with ward linkage.\n\n Examples\n --------\n >>> from sklearn.cluster import AgglomerativeClustering\n >>> import numpy as np\n >>> X = np.array([[1, 2], [1, 4], [1, 0],\n ... [4, 2], [4, 4], [4, 0]])\n >>> clustering = AgglomerativeClustering().fit(X)\n >>> clustering\n AgglomerativeClustering()\n >>> clustering.labels_\n array([1, 1, 1, 0, 0, 0])\n \"\"\"\n \n def __init__(self, n_clusters=2, *, affinity='euclidean', memory=None, connectivity=None, compute_full_tree='auto', linkage='ward', distance_threshold=None, compute_distances=False):\n self.n_clusters = n_clusters\n self.distance_threshold = distance_threshold\n self.memory = memory\n self.connectivity = connectivity\n self.compute_full_tree = compute_full_tree\n self.linkage = linkage\n self.affinity = affinity\n self.compute_distances = compute_distances\n \n def fit(self, X, y=None):\n \"\"\"Fit the hierarchical clustering from features, or distance matrix.\n\n Parameters\n ----------\n X : array-like, shape (n_samples, n_features) or (n_samples, n_samples)\n Training instances to cluster, or distances between instances if\n ``affinity='precomputed'``.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self : object\n Returns the fitted instance.\n \"\"\"\n X = self._validate_data(X, ensure_min_samples=2, estimator=self)\n return self._fit(X)\n \n def _fit(self, X):\n \"\"\"Fit without validation\n\n Parameters\n ----------\n X : ndarray of shape (n_samples, n_features) or (n_samples, n_samples)\n Training instances to cluster, or distances between instances if\n ``affinity='precomputed'``.\n\n Returns\n -------\n self : object\n Returns the fitted instance.\n \"\"\"\n memory = check_memory(self.memory)\n if self.n_clusters is not None and self.n_clusters <= 0:\n raise ValueError('n_clusters should be an integer greater than 0. %s was provided.' % str(self.n_clusters))\n if not (self.n_clusters is None) ^ (self.distance_threshold is None):\n raise ValueError('Exactly one of n_clusters and distance_threshold has to be set, and the other needs to be None.')\n if self.distance_threshold is not None and not self.compute_full_tree:\n raise ValueError('compute_full_tree must be True if distance_threshold is set.')\n if self.linkage == 'ward' and self.affinity != 'euclidean':\n raise ValueError('%s was provided as affinity. Ward can only work with euclidean distances.' % (self.affinity, ))\n if self.linkage not in _TREE_BUILDERS:\n raise ValueError('Unknown linkage type %s. Valid options are %s' % (self.linkage, _TREE_BUILDERS.keys()))\n tree_builder = _TREE_BUILDERS[self.linkage]\n connectivity = self.connectivity\n if self.connectivity is not None:\n if callable(self.connectivity):\n connectivity = self.connectivity(X)\n connectivity = check_array(connectivity, accept_sparse=['csr', 'coo', 'lil'])\n n_samples = len(X)\n compute_full_tree = self.compute_full_tree\n if self.connectivity is None:\n compute_full_tree = True\n if compute_full_tree == 'auto':\n if self.distance_threshold is not None:\n compute_full_tree = True\n else:\n compute_full_tree = self.n_clusters < max(100, 0.02 * n_samples)\n n_clusters = self.n_clusters\n if compute_full_tree:\n n_clusters = None\n kwargs = {}\n if self.linkage != 'ward':\n kwargs['linkage'] = self.linkage\n kwargs['affinity'] = self.affinity\n distance_threshold = self.distance_threshold\n return_distance = distance_threshold is not None or self.compute_distances\n out = memory.cache(tree_builder)(X, connectivity=connectivity, n_clusters=n_clusters, return_distance=return_distance, **kwargs)\n (self.children_, self.n_connected_components_, self.n_leaves_, parents) = out[:4]\n if return_distance:\n self.distances_ = out[-1]\n if self.distance_threshold is not None:\n self.n_clusters_ = np.count_nonzero(self.distances_ >= distance_threshold) + 1\n else:\n self.n_clusters_ = self.n_clusters\n if compute_full_tree:\n self.labels_ = _hc_cut(self.n_clusters_, self.children_, self.n_leaves_)\n else:\n labels = _hierarchical.hc_get_heads(parents, copy=False)\n labels = np.copy(labels[:n_samples])\n self.labels_ = np.searchsorted(np.unique(labels), labels)\n return self\n \n def fit_predict(self, X, y=None):\n \"\"\"Fit and return the result of each sample's clustering assignment.\n\n In addition to fitting, this method also return the result of the\n clustering assignment for each sample in the training set.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features) or (n_samples, n_samples)\n Training instances to cluster, or distances between instances if\n ``affinity='precomputed'``.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n labels : ndarray of shape (n_samples,)\n Cluster labels.\n \"\"\"\n return super().fit_predict(X, y)\n" }, { "name": "FeatureAgglomeration", @@ -19905,12 +19872,12 @@ "methods": [ "sklearn.cluster._agglomerative.FeatureAgglomeration.__init__", "sklearn.cluster._agglomerative.FeatureAgglomeration.fit", - "sklearn.cluster._agglomerative.FeatureAgglomeration.fit_predict" + "sklearn.cluster._agglomerative.FeatureAgglomeration.fit_predict@getter" ], "is_public": true, "description": "Agglomerate features.\n\nRecursively merges pair of clusters of features. Read more in the :ref:`User Guide `.", "docstring": "Agglomerate features.\n\n Recursively merges pair of clusters of features.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_clusters : int, default=2\n The number of clusters to find. It must be ``None`` if\n ``distance_threshold`` is not ``None``.\n\n affinity : str or callable, default='euclidean'\n Metric used to compute the linkage. Can be \"euclidean\", \"l1\", \"l2\",\n \"manhattan\", \"cosine\", or 'precomputed'.\n If linkage is \"ward\", only \"euclidean\" is accepted.\n\n memory : str or object with the joblib.Memory interface, default=None\n Used to cache the output of the computation of the tree.\n By default, no caching is done. If a string is given, it is the\n path to the caching directory.\n\n connectivity : array-like or callable, default=None\n Connectivity matrix. Defines for each feature the neighboring\n features following a given structure of the data.\n This can be a connectivity matrix itself or a callable that transforms\n the data into a connectivity matrix, such as derived from\n `kneighbors_graph`. Default is `None`, i.e, the\n hierarchical clustering algorithm is unstructured.\n\n compute_full_tree : 'auto' or bool, default='auto'\n Stop early the construction of the tree at `n_clusters`. This is useful\n to decrease computation time if the number of clusters is not small\n compared to the number of features. This option is useful only when\n specifying a connectivity matrix. Note also that when varying the\n number of clusters and using caching, it may be advantageous to compute\n the full tree. It must be ``True`` if ``distance_threshold`` is not\n ``None``. By default `compute_full_tree` is \"auto\", which is equivalent\n to `True` when `distance_threshold` is not `None` or that `n_clusters`\n is inferior to the maximum between 100 or `0.02 * n_samples`.\n Otherwise, \"auto\" is equivalent to `False`.\n\n linkage : {\"ward\", \"complete\", \"average\", \"single\"}, default=\"ward\"\n Which linkage criterion to use. The linkage criterion determines which\n distance to use between sets of features. The algorithm will merge\n the pairs of cluster that minimize this criterion.\n\n - \"ward\" minimizes the variance of the clusters being merged.\n - \"complete\" or maximum linkage uses the maximum distances between\n all features of the two sets.\n - \"average\" uses the average of the distances of each feature of\n the two sets.\n - \"single\" uses the minimum of the distances between all features\n of the two sets.\n\n pooling_func : callable, default=np.mean\n This combines the values of agglomerated features into a single\n value, and should accept an array of shape [M, N] and the keyword\n argument `axis=1`, and reduce it to an array of size [M].\n\n distance_threshold : float, default=None\n The linkage distance threshold above which, clusters will not be\n merged. If not ``None``, ``n_clusters`` must be ``None`` and\n ``compute_full_tree`` must be ``True``.\n\n .. versionadded:: 0.21\n\n compute_distances : bool, default=False\n Computes distances between clusters even if `distance_threshold` is not\n used. This can be used to make dendrogram visualization, but introduces\n a computational and memory overhead.\n\n .. versionadded:: 0.24\n\n Attributes\n ----------\n n_clusters_ : int\n The number of clusters found by the algorithm. If\n ``distance_threshold=None``, it will be equal to the given\n ``n_clusters``.\n\n labels_ : array-like of (n_features,)\n Cluster labels for each feature.\n\n n_leaves_ : int\n Number of leaves in the hierarchical tree.\n\n n_connected_components_ : int\n The estimated number of connected components in the graph.\n\n .. versionadded:: 0.21\n ``n_connected_components_`` was added to replace ``n_components_``.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n children_ : array-like of shape (n_nodes-1, 2)\n The children of each non-leaf node. Values less than `n_features`\n correspond to leaves of the tree which are the original samples.\n A node `i` greater than or equal to `n_features` is a non-leaf\n node and has children `children_[i - n_features]`. Alternatively\n at the i-th iteration, children[i][0] and children[i][1]\n are merged to form node `n_features + i`.\n\n distances_ : array-like of shape (n_nodes-1,)\n Distances between nodes in the corresponding place in `children_`.\n Only computed if `distance_threshold` is used or `compute_distances`\n is set to `True`.\n\n See Also\n --------\n AgglomerativeClustering : Agglomerative clustering samples instead of\n features.\n ward_tree : Hierarchical clustering with ward linkage.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn import datasets, cluster\n >>> digits = datasets.load_digits()\n >>> images = digits.images\n >>> X = np.reshape(images, (len(images), -1))\n >>> agglo = cluster.FeatureAgglomeration(n_clusters=32)\n >>> agglo.fit(X)\n FeatureAgglomeration(n_clusters=32)\n >>> X_reduced = agglo.transform(X)\n >>> X_reduced.shape\n (1797, 32)\n ", - "source_code": "\n\nclass FeatureAgglomeration(AgglomerativeClustering, AgglomerationTransform):\n \"\"\"Agglomerate features.\n\n Recursively merges pair of clusters of features.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_clusters : int, default=2\n The number of clusters to find. It must be ``None`` if\n ``distance_threshold`` is not ``None``.\n\n affinity : str or callable, default='euclidean'\n Metric used to compute the linkage. Can be \"euclidean\", \"l1\", \"l2\",\n \"manhattan\", \"cosine\", or 'precomputed'.\n If linkage is \"ward\", only \"euclidean\" is accepted.\n\n memory : str or object with the joblib.Memory interface, default=None\n Used to cache the output of the computation of the tree.\n By default, no caching is done. If a string is given, it is the\n path to the caching directory.\n\n connectivity : array-like or callable, default=None\n Connectivity matrix. Defines for each feature the neighboring\n features following a given structure of the data.\n This can be a connectivity matrix itself or a callable that transforms\n the data into a connectivity matrix, such as derived from\n `kneighbors_graph`. Default is `None`, i.e, the\n hierarchical clustering algorithm is unstructured.\n\n compute_full_tree : 'auto' or bool, default='auto'\n Stop early the construction of the tree at `n_clusters`. This is useful\n to decrease computation time if the number of clusters is not small\n compared to the number of features. This option is useful only when\n specifying a connectivity matrix. Note also that when varying the\n number of clusters and using caching, it may be advantageous to compute\n the full tree. It must be ``True`` if ``distance_threshold`` is not\n ``None``. By default `compute_full_tree` is \"auto\", which is equivalent\n to `True` when `distance_threshold` is not `None` or that `n_clusters`\n is inferior to the maximum between 100 or `0.02 * n_samples`.\n Otherwise, \"auto\" is equivalent to `False`.\n\n linkage : {\"ward\", \"complete\", \"average\", \"single\"}, default=\"ward\"\n Which linkage criterion to use. The linkage criterion determines which\n distance to use between sets of features. The algorithm will merge\n the pairs of cluster that minimize this criterion.\n\n - \"ward\" minimizes the variance of the clusters being merged.\n - \"complete\" or maximum linkage uses the maximum distances between\n all features of the two sets.\n - \"average\" uses the average of the distances of each feature of\n the two sets.\n - \"single\" uses the minimum of the distances between all features\n of the two sets.\n\n pooling_func : callable, default=np.mean\n This combines the values of agglomerated features into a single\n value, and should accept an array of shape [M, N] and the keyword\n argument `axis=1`, and reduce it to an array of size [M].\n\n distance_threshold : float, default=None\n The linkage distance threshold above which, clusters will not be\n merged. If not ``None``, ``n_clusters`` must be ``None`` and\n ``compute_full_tree`` must be ``True``.\n\n .. versionadded:: 0.21\n\n compute_distances : bool, default=False\n Computes distances between clusters even if `distance_threshold` is not\n used. This can be used to make dendrogram visualization, but introduces\n a computational and memory overhead.\n\n .. versionadded:: 0.24\n\n Attributes\n ----------\n n_clusters_ : int\n The number of clusters found by the algorithm. If\n ``distance_threshold=None``, it will be equal to the given\n ``n_clusters``.\n\n labels_ : array-like of (n_features,)\n Cluster labels for each feature.\n\n n_leaves_ : int\n Number of leaves in the hierarchical tree.\n\n n_connected_components_ : int\n The estimated number of connected components in the graph.\n\n .. versionadded:: 0.21\n ``n_connected_components_`` was added to replace ``n_components_``.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n children_ : array-like of shape (n_nodes-1, 2)\n The children of each non-leaf node. Values less than `n_features`\n correspond to leaves of the tree which are the original samples.\n A node `i` greater than or equal to `n_features` is a non-leaf\n node and has children `children_[i - n_features]`. Alternatively\n at the i-th iteration, children[i][0] and children[i][1]\n are merged to form node `n_features + i`.\n\n distances_ : array-like of shape (n_nodes-1,)\n Distances between nodes in the corresponding place in `children_`.\n Only computed if `distance_threshold` is used or `compute_distances`\n is set to `True`.\n\n See Also\n --------\n AgglomerativeClustering : Agglomerative clustering samples instead of\n features.\n ward_tree : Hierarchical clustering with ward linkage.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn import datasets, cluster\n >>> digits = datasets.load_digits()\n >>> images = digits.images\n >>> X = np.reshape(images, (len(images), -1))\n >>> agglo = cluster.FeatureAgglomeration(n_clusters=32)\n >>> agglo.fit(X)\n FeatureAgglomeration(n_clusters=32)\n >>> X_reduced = agglo.transform(X)\n >>> X_reduced.shape\n (1797, 32)\n \"\"\"\n \n def __init__(self, n_clusters=2, *, affinity='euclidean', memory=None, connectivity=None, compute_full_tree='auto', linkage='ward', pooling_func=np.mean, distance_threshold=None, compute_distances=False):\n super().__init__(n_clusters=n_clusters, memory=memory, connectivity=connectivity, compute_full_tree=compute_full_tree, linkage=linkage, affinity=affinity, distance_threshold=distance_threshold, compute_distances=compute_distances)\n self.pooling_func = pooling_func\n \n def fit(self, X, y=None):\n \"\"\"Fit the hierarchical clustering on the data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self : object\n Returns the transformer.\n \"\"\"\n X = self._validate_data(X, accept_sparse=['csr', 'csc', 'coo'], ensure_min_features=2, estimator=self)\n n_features_in_ = self.n_features_in_\n AgglomerativeClustering.fit(self, X.T)\n self.n_features_in_ = n_features_in_\n return self\n \n @property\n def fit_predict(self):\n \"\"\"Fit and return the result of each sample's clustering assignment.\"\"\"\n raise AttributeError\n" + "source_code": "\n\nclass FeatureAgglomeration(AgglomerativeClustering, AgglomerationTransform):\n \"\"\"Agglomerate features.\n\n Recursively merges pair of clusters of features.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_clusters : int, default=2\n The number of clusters to find. It must be ``None`` if\n ``distance_threshold`` is not ``None``.\n\n affinity : str or callable, default='euclidean'\n Metric used to compute the linkage. Can be \"euclidean\", \"l1\", \"l2\",\n \"manhattan\", \"cosine\", or 'precomputed'.\n If linkage is \"ward\", only \"euclidean\" is accepted.\n\n memory : str or object with the joblib.Memory interface, default=None\n Used to cache the output of the computation of the tree.\n By default, no caching is done. If a string is given, it is the\n path to the caching directory.\n\n connectivity : array-like or callable, default=None\n Connectivity matrix. Defines for each feature the neighboring\n features following a given structure of the data.\n This can be a connectivity matrix itself or a callable that transforms\n the data into a connectivity matrix, such as derived from\n `kneighbors_graph`. Default is `None`, i.e, the\n hierarchical clustering algorithm is unstructured.\n\n compute_full_tree : 'auto' or bool, default='auto'\n Stop early the construction of the tree at `n_clusters`. This is useful\n to decrease computation time if the number of clusters is not small\n compared to the number of features. This option is useful only when\n specifying a connectivity matrix. Note also that when varying the\n number of clusters and using caching, it may be advantageous to compute\n the full tree. It must be ``True`` if ``distance_threshold`` is not\n ``None``. By default `compute_full_tree` is \"auto\", which is equivalent\n to `True` when `distance_threshold` is not `None` or that `n_clusters`\n is inferior to the maximum between 100 or `0.02 * n_samples`.\n Otherwise, \"auto\" is equivalent to `False`.\n\n linkage : {\"ward\", \"complete\", \"average\", \"single\"}, default=\"ward\"\n Which linkage criterion to use. The linkage criterion determines which\n distance to use between sets of features. The algorithm will merge\n the pairs of cluster that minimize this criterion.\n\n - \"ward\" minimizes the variance of the clusters being merged.\n - \"complete\" or maximum linkage uses the maximum distances between\n all features of the two sets.\n - \"average\" uses the average of the distances of each feature of\n the two sets.\n - \"single\" uses the minimum of the distances between all features\n of the two sets.\n\n pooling_func : callable, default=np.mean\n This combines the values of agglomerated features into a single\n value, and should accept an array of shape [M, N] and the keyword\n argument `axis=1`, and reduce it to an array of size [M].\n\n distance_threshold : float, default=None\n The linkage distance threshold above which, clusters will not be\n merged. If not ``None``, ``n_clusters`` must be ``None`` and\n ``compute_full_tree`` must be ``True``.\n\n .. versionadded:: 0.21\n\n compute_distances : bool, default=False\n Computes distances between clusters even if `distance_threshold` is not\n used. This can be used to make dendrogram visualization, but introduces\n a computational and memory overhead.\n\n .. versionadded:: 0.24\n\n Attributes\n ----------\n n_clusters_ : int\n The number of clusters found by the algorithm. If\n ``distance_threshold=None``, it will be equal to the given\n ``n_clusters``.\n\n labels_ : array-like of (n_features,)\n Cluster labels for each feature.\n\n n_leaves_ : int\n Number of leaves in the hierarchical tree.\n\n n_connected_components_ : int\n The estimated number of connected components in the graph.\n\n .. versionadded:: 0.21\n ``n_connected_components_`` was added to replace ``n_components_``.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n children_ : array-like of shape (n_nodes-1, 2)\n The children of each non-leaf node. Values less than `n_features`\n correspond to leaves of the tree which are the original samples.\n A node `i` greater than or equal to `n_features` is a non-leaf\n node and has children `children_[i - n_features]`. Alternatively\n at the i-th iteration, children[i][0] and children[i][1]\n are merged to form node `n_features + i`.\n\n distances_ : array-like of shape (n_nodes-1,)\n Distances between nodes in the corresponding place in `children_`.\n Only computed if `distance_threshold` is used or `compute_distances`\n is set to `True`.\n\n See Also\n --------\n AgglomerativeClustering : Agglomerative clustering samples instead of\n features.\n ward_tree : Hierarchical clustering with ward linkage.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn import datasets, cluster\n >>> digits = datasets.load_digits()\n >>> images = digits.images\n >>> X = np.reshape(images, (len(images), -1))\n >>> agglo = cluster.FeatureAgglomeration(n_clusters=32)\n >>> agglo.fit(X)\n FeatureAgglomeration(n_clusters=32)\n >>> X_reduced = agglo.transform(X)\n >>> X_reduced.shape\n (1797, 32)\n \"\"\"\n \n def __init__(self, n_clusters=2, *, affinity='euclidean', memory=None, connectivity=None, compute_full_tree='auto', linkage='ward', pooling_func=np.mean, distance_threshold=None, compute_distances=False):\n super().__init__(n_clusters=n_clusters, memory=memory, connectivity=connectivity, compute_full_tree=compute_full_tree, linkage=linkage, affinity=affinity, distance_threshold=distance_threshold, compute_distances=compute_distances)\n self.pooling_func = pooling_func\n \n def fit(self, X, y=None):\n \"\"\"Fit the hierarchical clustering on the data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self : object\n Returns the transformer.\n \"\"\"\n X = self._validate_data(X, ensure_min_features=2, estimator=self)\n super()._fit(X.T)\n return self\n \n @property\n def fit_predict(self):\n \"\"\"Fit and return the result of each sample's clustering assignment.\"\"\"\n raise AttributeError\n" }, { "name": "BaseSpectral", @@ -19928,7 +19895,7 @@ "is_public": false, "description": "Base class for spectral biclustering.", "docstring": "Base class for spectral biclustering.", - "source_code": "\n\nclass BaseSpectral(BiclusterMixin, BaseEstimator, metaclass=ABCMeta):\n \"\"\"Base class for spectral biclustering.\"\"\"\n \n @abstractmethod\n def __init__(self, n_clusters=3, svd_method='randomized', n_svd_vecs=None, mini_batch=False, init='k-means++', n_init=10, random_state=None):\n self.n_clusters = n_clusters\n self.svd_method = svd_method\n self.n_svd_vecs = n_svd_vecs\n self.mini_batch = mini_batch\n self.init = init\n self.n_init = n_init\n self.random_state = random_state\n \n def _check_parameters(self):\n legal_svd_methods = ('randomized', 'arpack')\n if self.svd_method not in legal_svd_methods:\n raise ValueError(\"Unknown SVD method: '{0}'. svd_method must be one of {1}.\".format(self.svd_method, legal_svd_methods))\n \n def fit(self, X, y=None):\n \"\"\"Creates a biclustering for X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n\n y : Ignored\n\n \"\"\"\n X = self._validate_data(X, accept_sparse='csr', dtype=np.float64)\n self._check_parameters()\n self._fit(X)\n return self\n \n def _svd(self, array, n_components, n_discard):\n \"\"\"Returns first `n_components` left and right singular\n vectors u and v, discarding the first `n_discard`.\n\n \"\"\"\n if self.svd_method == 'randomized':\n kwargs = {}\n if self.n_svd_vecs is not None:\n kwargs['n_oversamples'] = self.n_svd_vecs\n (u, _, vt) = randomized_svd(array, n_components, random_state=self.random_state, **kwargs)\n elif self.svd_method == 'arpack':\n (u, _, vt) = svds(array, k=n_components, ncv=self.n_svd_vecs)\n if np.any(np.isnan(vt)):\n A = safe_sparse_dot(array.T, array)\n random_state = check_random_state(self.random_state)\n v0 = random_state.uniform(-1, 1, A.shape[0])\n (_, v) = eigsh(A, ncv=self.n_svd_vecs, v0=v0)\n vt = v.T\n if np.any(np.isnan(u)):\n A = safe_sparse_dot(array, array.T)\n random_state = check_random_state(self.random_state)\n v0 = random_state.uniform(-1, 1, A.shape[0])\n (_, u) = eigsh(A, ncv=self.n_svd_vecs, v0=v0)\n assert_all_finite(u)\n assert_all_finite(vt)\n u = u[:, n_discard:]\n vt = vt[n_discard:]\n return u, vt.T\n \n def _k_means(self, data, n_clusters):\n if self.mini_batch:\n model = MiniBatchKMeans(n_clusters, init=self.init, n_init=self.n_init, random_state=self.random_state)\n else:\n model = KMeans(n_clusters, init=self.init, n_init=self.n_init, random_state=self.random_state)\n model.fit(data)\n centroid = model.cluster_centers_\n labels = model.labels_\n return centroid, labels\n \n def _more_tags(self):\n return {'_xfail_checks': {'check_estimators_dtypes': 'raises nan error', 'check_fit2d_1sample': '_scale_normalize fails', 'check_fit2d_1feature': 'raises apply_along_axis error', 'check_estimator_sparse_data': 'does not fail gracefully', 'check_methods_subset_invariance': 'empty array passed inside', 'check_dont_overwrite_parameters': 'empty array passed inside', 'check_fit2d_predict1d': 'empty array passed inside'}}\n" + "source_code": "\n\nclass BaseSpectral(BiclusterMixin, BaseEstimator, metaclass=ABCMeta):\n \"\"\"Base class for spectral biclustering.\"\"\"\n \n @abstractmethod\n def __init__(self, n_clusters=3, svd_method='randomized', n_svd_vecs=None, mini_batch=False, init='k-means++', n_init=10, random_state=None):\n self.n_clusters = n_clusters\n self.svd_method = svd_method\n self.n_svd_vecs = n_svd_vecs\n self.mini_batch = mini_batch\n self.init = init\n self.n_init = n_init\n self.random_state = random_state\n \n def _check_parameters(self):\n legal_svd_methods = ('randomized', 'arpack')\n if self.svd_method not in legal_svd_methods:\n raise ValueError(\"Unknown SVD method: '{0}'. svd_method must be one of {1}.\".format(self.svd_method, legal_svd_methods))\n \n def fit(self, X, y=None):\n \"\"\"Create a biclustering for X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training data.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n self : object\n SpectralBiclustering instance.\n \"\"\"\n X = self._validate_data(X, accept_sparse='csr', dtype=np.float64)\n self._check_parameters()\n self._fit(X)\n return self\n \n def _svd(self, array, n_components, n_discard):\n \"\"\"Returns first `n_components` left and right singular\n vectors u and v, discarding the first `n_discard`.\n\n \"\"\"\n if self.svd_method == 'randomized':\n kwargs = {}\n if self.n_svd_vecs is not None:\n kwargs['n_oversamples'] = self.n_svd_vecs\n (u, _, vt) = randomized_svd(array, n_components, random_state=self.random_state, **kwargs)\n elif self.svd_method == 'arpack':\n (u, _, vt) = svds(array, k=n_components, ncv=self.n_svd_vecs)\n if np.any(np.isnan(vt)):\n A = safe_sparse_dot(array.T, array)\n random_state = check_random_state(self.random_state)\n v0 = random_state.uniform(-1, 1, A.shape[0])\n (_, v) = eigsh(A, ncv=self.n_svd_vecs, v0=v0)\n vt = v.T\n if np.any(np.isnan(u)):\n A = safe_sparse_dot(array, array.T)\n random_state = check_random_state(self.random_state)\n v0 = random_state.uniform(-1, 1, A.shape[0])\n (_, u) = eigsh(A, ncv=self.n_svd_vecs, v0=v0)\n assert_all_finite(u)\n assert_all_finite(vt)\n u = u[:, n_discard:]\n vt = vt[n_discard:]\n return u, vt.T\n \n def _k_means(self, data, n_clusters):\n if self.mini_batch:\n model = MiniBatchKMeans(n_clusters, init=self.init, n_init=self.n_init, random_state=self.random_state)\n else:\n model = KMeans(n_clusters, init=self.init, n_init=self.n_init, random_state=self.random_state)\n model.fit(data)\n centroid = model.cluster_centers_\n labels = model.labels_\n return centroid, labels\n \n def _more_tags(self):\n return {'_xfail_checks': {'check_estimators_dtypes': 'raises nan error', 'check_fit2d_1sample': '_scale_normalize fails', 'check_fit2d_1feature': 'raises apply_along_axis error', 'check_estimator_sparse_data': 'does not fail gracefully', 'check_methods_subset_invariance': 'empty array passed inside', 'check_dont_overwrite_parameters': 'empty array passed inside', 'check_fit2d_predict1d': 'empty array passed inside'}}\n" }, { "name": "SpectralBiclustering", @@ -19944,8 +19911,8 @@ ], "is_public": true, "description": "Spectral biclustering (Kluger, 2003).\n\nPartitions rows and columns under the assumption that the data has an underlying checkerboard structure. For instance, if there are two row partitions and three column partitions, each row will belong to three biclusters, and each column will belong to two biclusters. The outer product of the corresponding row and column label vectors gives this checkerboard structure. Read more in the :ref:`User Guide `.", - "docstring": "Spectral biclustering (Kluger, 2003).\n\n Partitions rows and columns under the assumption that the data has\n an underlying checkerboard structure. For instance, if there are\n two row partitions and three column partitions, each row will\n belong to three biclusters, and each column will belong to two\n biclusters. The outer product of the corresponding row and column\n label vectors gives this checkerboard structure.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_clusters : int or tuple (n_row_clusters, n_column_clusters), default=3\n The number of row and column clusters in the checkerboard\n structure.\n\n method : {'bistochastic', 'scale', 'log'}, default='bistochastic'\n Method of normalizing and converting singular vectors into\n biclusters. May be one of 'scale', 'bistochastic', or 'log'.\n The authors recommend using 'log'. If the data is sparse,\n however, log normalization will not work, which is why the\n default is 'bistochastic'.\n\n .. warning::\n if `method='log'`, the data must be sparse.\n\n n_components : int, default=6\n Number of singular vectors to check.\n\n n_best : int, default=3\n Number of best singular vectors to which to project the data\n for clustering.\n\n svd_method : {'randomized', 'arpack'}, default='randomized'\n Selects the algorithm for finding singular vectors. May be\n 'randomized' or 'arpack'. If 'randomized', uses\n :func:`~sklearn.utils.extmath.randomized_svd`, which may be faster\n for large matrices. If 'arpack', uses\n `scipy.sparse.linalg.svds`, which is more accurate, but\n possibly slower in some cases.\n\n n_svd_vecs : int, default=None\n Number of vectors to use in calculating the SVD. Corresponds\n to `ncv` when `svd_method=arpack` and `n_oversamples` when\n `svd_method` is 'randomized`.\n\n mini_batch : bool, default=False\n Whether to use mini-batch k-means, which is faster but may get\n different results.\n\n init : {'k-means++', 'random'} or ndarray of (n_clusters, n_features), default='k-means++'\n Method for initialization of k-means algorithm; defaults to\n 'k-means++'.\n\n n_init : int, default=10\n Number of random initializations that are tried with the\n k-means algorithm.\n\n If mini-batch k-means is used, the best initialization is\n chosen and the algorithm runs once. Otherwise, the algorithm\n is run for each initialization and the best solution chosen.\n\n random_state : int, RandomState instance, default=None\n Used for randomizing the singular value decomposition and the k-means\n initialization. Use an int to make the randomness deterministic.\n See :term:`Glossary `.\n\n Attributes\n ----------\n rows_ : array-like of shape (n_row_clusters, n_rows)\n Results of the clustering. `rows[i, r]` is True if\n cluster `i` contains row `r`. Available only after calling ``fit``.\n\n columns_ : array-like of shape (n_column_clusters, n_columns)\n Results of the clustering, like `rows`.\n\n row_labels_ : array-like of shape (n_rows,)\n Row partition labels.\n\n column_labels_ : array-like of shape (n_cols,)\n Column partition labels.\n\n biclusters_ : tuple of two ndarrays\n The tuple contains the `rows_` and `columns_` arrays.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn.cluster import SpectralBiclustering\n >>> import numpy as np\n >>> X = np.array([[1, 1], [2, 1], [1, 0],\n ... [4, 7], [3, 5], [3, 6]])\n >>> clustering = SpectralBiclustering(n_clusters=2, random_state=0).fit(X)\n >>> clustering.row_labels_\n array([1, 1, 1, 0, 0, 0], dtype=int32)\n >>> clustering.column_labels_\n array([0, 1], dtype=int32)\n >>> clustering\n SpectralBiclustering(n_clusters=2, random_state=0)\n\n References\n ----------\n\n * Kluger, Yuval, et. al., 2003. `Spectral biclustering of microarray\n data: coclustering genes and conditions\n `__.\n\n ", - "source_code": "\n\nclass SpectralBiclustering(BaseSpectral):\n \"\"\"Spectral biclustering (Kluger, 2003).\n\n Partitions rows and columns under the assumption that the data has\n an underlying checkerboard structure. For instance, if there are\n two row partitions and three column partitions, each row will\n belong to three biclusters, and each column will belong to two\n biclusters. The outer product of the corresponding row and column\n label vectors gives this checkerboard structure.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_clusters : int or tuple (n_row_clusters, n_column_clusters), default=3\n The number of row and column clusters in the checkerboard\n structure.\n\n method : {'bistochastic', 'scale', 'log'}, default='bistochastic'\n Method of normalizing and converting singular vectors into\n biclusters. May be one of 'scale', 'bistochastic', or 'log'.\n The authors recommend using 'log'. If the data is sparse,\n however, log normalization will not work, which is why the\n default is 'bistochastic'.\n\n .. warning::\n if `method='log'`, the data must be sparse.\n\n n_components : int, default=6\n Number of singular vectors to check.\n\n n_best : int, default=3\n Number of best singular vectors to which to project the data\n for clustering.\n\n svd_method : {'randomized', 'arpack'}, default='randomized'\n Selects the algorithm for finding singular vectors. May be\n 'randomized' or 'arpack'. If 'randomized', uses\n :func:`~sklearn.utils.extmath.randomized_svd`, which may be faster\n for large matrices. If 'arpack', uses\n `scipy.sparse.linalg.svds`, which is more accurate, but\n possibly slower in some cases.\n\n n_svd_vecs : int, default=None\n Number of vectors to use in calculating the SVD. Corresponds\n to `ncv` when `svd_method=arpack` and `n_oversamples` when\n `svd_method` is 'randomized`.\n\n mini_batch : bool, default=False\n Whether to use mini-batch k-means, which is faster but may get\n different results.\n\n init : {'k-means++', 'random'} or ndarray of (n_clusters, n_features), default='k-means++'\n Method for initialization of k-means algorithm; defaults to\n 'k-means++'.\n\n n_init : int, default=10\n Number of random initializations that are tried with the\n k-means algorithm.\n\n If mini-batch k-means is used, the best initialization is\n chosen and the algorithm runs once. Otherwise, the algorithm\n is run for each initialization and the best solution chosen.\n\n random_state : int, RandomState instance, default=None\n Used for randomizing the singular value decomposition and the k-means\n initialization. Use an int to make the randomness deterministic.\n See :term:`Glossary `.\n\n Attributes\n ----------\n rows_ : array-like of shape (n_row_clusters, n_rows)\n Results of the clustering. `rows[i, r]` is True if\n cluster `i` contains row `r`. Available only after calling ``fit``.\n\n columns_ : array-like of shape (n_column_clusters, n_columns)\n Results of the clustering, like `rows`.\n\n row_labels_ : array-like of shape (n_rows,)\n Row partition labels.\n\n column_labels_ : array-like of shape (n_cols,)\n Column partition labels.\n\n biclusters_ : tuple of two ndarrays\n The tuple contains the `rows_` and `columns_` arrays.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn.cluster import SpectralBiclustering\n >>> import numpy as np\n >>> X = np.array([[1, 1], [2, 1], [1, 0],\n ... [4, 7], [3, 5], [3, 6]])\n >>> clustering = SpectralBiclustering(n_clusters=2, random_state=0).fit(X)\n >>> clustering.row_labels_\n array([1, 1, 1, 0, 0, 0], dtype=int32)\n >>> clustering.column_labels_\n array([0, 1], dtype=int32)\n >>> clustering\n SpectralBiclustering(n_clusters=2, random_state=0)\n\n References\n ----------\n\n * Kluger, Yuval, et. al., 2003. `Spectral biclustering of microarray\n data: coclustering genes and conditions\n `__.\n\n \"\"\"\n \n def __init__(self, n_clusters=3, *, method='bistochastic', n_components=6, n_best=3, svd_method='randomized', n_svd_vecs=None, mini_batch=False, init='k-means++', n_init=10, random_state=None):\n super().__init__(n_clusters, svd_method, n_svd_vecs, mini_batch, init, n_init, random_state)\n self.method = method\n self.n_components = n_components\n self.n_best = n_best\n \n def _check_parameters(self):\n super()._check_parameters()\n legal_methods = ('bistochastic', 'scale', 'log')\n if self.method not in legal_methods:\n raise ValueError(\"Unknown method: '{0}'. method must be one of {1}.\".format(self.method, legal_methods))\n try:\n int(self.n_clusters)\n except TypeError:\n try:\n (r, c) = self.n_clusters\n int(r)\n int(c)\n except (ValueError, TypeError) as e:\n raise ValueError('Incorrect parameter n_clusters has value: {}. It should either be a single integer or an iterable with two integers: (n_row_clusters, n_column_clusters)') from e\n if self.n_components < 1:\n raise ValueError('Parameter n_components must be greater than 0, but its value is {}'.format(self.n_components))\n if self.n_best < 1:\n raise ValueError('Parameter n_best must be greater than 0, but its value is {}'.format(self.n_best))\n if self.n_best > self.n_components:\n raise ValueError('n_best cannot be larger than n_components, but {} > {}'.format(self.n_best, self.n_components))\n \n def _fit(self, X):\n n_sv = self.n_components\n if self.method == 'bistochastic':\n normalized_data = _bistochastic_normalize(X)\n n_sv += 1\n elif self.method == 'scale':\n (normalized_data, _, _) = _scale_normalize(X)\n n_sv += 1\n elif self.method == 'log':\n normalized_data = _log_normalize(X)\n n_discard = 0 if self.method == 'log' else 1\n (u, v) = self._svd(normalized_data, n_sv, n_discard)\n ut = u.T\n vt = v.T\n try:\n (n_row_clusters, n_col_clusters) = self.n_clusters\n except TypeError:\n n_row_clusters = n_col_clusters = self.n_clusters\n best_ut = self._fit_best_piecewise(ut, self.n_best, n_row_clusters)\n best_vt = self._fit_best_piecewise(vt, self.n_best, n_col_clusters)\n self.row_labels_ = self._project_and_cluster(X, best_vt.T, n_row_clusters)\n self.column_labels_ = self._project_and_cluster(X.T, best_ut.T, n_col_clusters)\n self.rows_ = np.vstack([self.row_labels_ == label for label in range(n_row_clusters) for _ in range(n_col_clusters)])\n self.columns_ = np.vstack([self.column_labels_ == label for _ in range(n_row_clusters) for label in range(n_col_clusters)])\n \n def _fit_best_piecewise(self, vectors, n_best, n_clusters):\n \"\"\"Find the ``n_best`` vectors that are best approximated by piecewise\n constant vectors.\n\n The piecewise vectors are found by k-means; the best is chosen\n according to Euclidean distance.\n\n \"\"\"\n \n def make_piecewise(v):\n (centroid, labels) = self._k_means(v.reshape(-1, 1), n_clusters)\n return centroid[labels].ravel()\n piecewise_vectors = np.apply_along_axis(make_piecewise, axis=1, arr=vectors)\n dists = np.apply_along_axis(norm, axis=1, arr=vectors - piecewise_vectors)\n result = vectors[np.argsort(dists)[:n_best]]\n return result\n \n def _project_and_cluster(self, data, vectors, n_clusters):\n \"\"\"Project ``data`` to ``vectors`` and cluster the result.\"\"\"\n projected = safe_sparse_dot(data, vectors)\n (_, labels) = self._k_means(projected, n_clusters)\n return labels\n" + "docstring": "Spectral biclustering (Kluger, 2003).\n\n Partitions rows and columns under the assumption that the data has\n an underlying checkerboard structure. For instance, if there are\n two row partitions and three column partitions, each row will\n belong to three biclusters, and each column will belong to two\n biclusters. The outer product of the corresponding row and column\n label vectors gives this checkerboard structure.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_clusters : int or tuple (n_row_clusters, n_column_clusters), default=3\n The number of row and column clusters in the checkerboard\n structure.\n\n method : {'bistochastic', 'scale', 'log'}, default='bistochastic'\n Method of normalizing and converting singular vectors into\n biclusters. May be one of 'scale', 'bistochastic', or 'log'.\n The authors recommend using 'log'. If the data is sparse,\n however, log normalization will not work, which is why the\n default is 'bistochastic'.\n\n .. warning::\n if `method='log'`, the data must be sparse.\n\n n_components : int, default=6\n Number of singular vectors to check.\n\n n_best : int, default=3\n Number of best singular vectors to which to project the data\n for clustering.\n\n svd_method : {'randomized', 'arpack'}, default='randomized'\n Selects the algorithm for finding singular vectors. May be\n 'randomized' or 'arpack'. If 'randomized', uses\n :func:`~sklearn.utils.extmath.randomized_svd`, which may be faster\n for large matrices. If 'arpack', uses\n `scipy.sparse.linalg.svds`, which is more accurate, but\n possibly slower in some cases.\n\n n_svd_vecs : int, default=None\n Number of vectors to use in calculating the SVD. Corresponds\n to `ncv` when `svd_method=arpack` and `n_oversamples` when\n `svd_method` is 'randomized`.\n\n mini_batch : bool, default=False\n Whether to use mini-batch k-means, which is faster but may get\n different results.\n\n init : {'k-means++', 'random'} or ndarray of (n_clusters, n_features), default='k-means++'\n Method for initialization of k-means algorithm; defaults to\n 'k-means++'.\n\n n_init : int, default=10\n Number of random initializations that are tried with the\n k-means algorithm.\n\n If mini-batch k-means is used, the best initialization is\n chosen and the algorithm runs once. Otherwise, the algorithm\n is run for each initialization and the best solution chosen.\n\n random_state : int, RandomState instance, default=None\n Used for randomizing the singular value decomposition and the k-means\n initialization. Use an int to make the randomness deterministic.\n See :term:`Glossary `.\n\n Attributes\n ----------\n rows_ : array-like of shape (n_row_clusters, n_rows)\n Results of the clustering. `rows[i, r]` is True if\n cluster `i` contains row `r`. Available only after calling ``fit``.\n\n columns_ : array-like of shape (n_column_clusters, n_columns)\n Results of the clustering, like `rows`.\n\n row_labels_ : array-like of shape (n_rows,)\n Row partition labels.\n\n column_labels_ : array-like of shape (n_cols,)\n Column partition labels.\n\n biclusters_ : tuple of two ndarrays\n The tuple contains the `rows_` and `columns_` arrays.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n SpectralCoclustering : Spectral Co-Clustering algorithm (Dhillon, 2001).\n\n References\n ----------\n\n * Kluger, Yuval, et. al., 2003. `Spectral biclustering of microarray\n data: coclustering genes and conditions\n `__.\n\n Examples\n --------\n >>> from sklearn.cluster import SpectralBiclustering\n >>> import numpy as np\n >>> X = np.array([[1, 1], [2, 1], [1, 0],\n ... [4, 7], [3, 5], [3, 6]])\n >>> clustering = SpectralBiclustering(n_clusters=2, random_state=0).fit(X)\n >>> clustering.row_labels_\n array([1, 1, 1, 0, 0, 0], dtype=int32)\n >>> clustering.column_labels_\n array([0, 1], dtype=int32)\n >>> clustering\n SpectralBiclustering(n_clusters=2, random_state=0)\n ", + "source_code": "\n\nclass SpectralBiclustering(BaseSpectral):\n \"\"\"Spectral biclustering (Kluger, 2003).\n\n Partitions rows and columns under the assumption that the data has\n an underlying checkerboard structure. For instance, if there are\n two row partitions and three column partitions, each row will\n belong to three biclusters, and each column will belong to two\n biclusters. The outer product of the corresponding row and column\n label vectors gives this checkerboard structure.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_clusters : int or tuple (n_row_clusters, n_column_clusters), default=3\n The number of row and column clusters in the checkerboard\n structure.\n\n method : {'bistochastic', 'scale', 'log'}, default='bistochastic'\n Method of normalizing and converting singular vectors into\n biclusters. May be one of 'scale', 'bistochastic', or 'log'.\n The authors recommend using 'log'. If the data is sparse,\n however, log normalization will not work, which is why the\n default is 'bistochastic'.\n\n .. warning::\n if `method='log'`, the data must be sparse.\n\n n_components : int, default=6\n Number of singular vectors to check.\n\n n_best : int, default=3\n Number of best singular vectors to which to project the data\n for clustering.\n\n svd_method : {'randomized', 'arpack'}, default='randomized'\n Selects the algorithm for finding singular vectors. May be\n 'randomized' or 'arpack'. If 'randomized', uses\n :func:`~sklearn.utils.extmath.randomized_svd`, which may be faster\n for large matrices. If 'arpack', uses\n `scipy.sparse.linalg.svds`, which is more accurate, but\n possibly slower in some cases.\n\n n_svd_vecs : int, default=None\n Number of vectors to use in calculating the SVD. Corresponds\n to `ncv` when `svd_method=arpack` and `n_oversamples` when\n `svd_method` is 'randomized`.\n\n mini_batch : bool, default=False\n Whether to use mini-batch k-means, which is faster but may get\n different results.\n\n init : {'k-means++', 'random'} or ndarray of (n_clusters, n_features), default='k-means++'\n Method for initialization of k-means algorithm; defaults to\n 'k-means++'.\n\n n_init : int, default=10\n Number of random initializations that are tried with the\n k-means algorithm.\n\n If mini-batch k-means is used, the best initialization is\n chosen and the algorithm runs once. Otherwise, the algorithm\n is run for each initialization and the best solution chosen.\n\n random_state : int, RandomState instance, default=None\n Used for randomizing the singular value decomposition and the k-means\n initialization. Use an int to make the randomness deterministic.\n See :term:`Glossary `.\n\n Attributes\n ----------\n rows_ : array-like of shape (n_row_clusters, n_rows)\n Results of the clustering. `rows[i, r]` is True if\n cluster `i` contains row `r`. Available only after calling ``fit``.\n\n columns_ : array-like of shape (n_column_clusters, n_columns)\n Results of the clustering, like `rows`.\n\n row_labels_ : array-like of shape (n_rows,)\n Row partition labels.\n\n column_labels_ : array-like of shape (n_cols,)\n Column partition labels.\n\n biclusters_ : tuple of two ndarrays\n The tuple contains the `rows_` and `columns_` arrays.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n SpectralCoclustering : Spectral Co-Clustering algorithm (Dhillon, 2001).\n\n References\n ----------\n\n * Kluger, Yuval, et. al., 2003. `Spectral biclustering of microarray\n data: coclustering genes and conditions\n `__.\n\n Examples\n --------\n >>> from sklearn.cluster import SpectralBiclustering\n >>> import numpy as np\n >>> X = np.array([[1, 1], [2, 1], [1, 0],\n ... [4, 7], [3, 5], [3, 6]])\n >>> clustering = SpectralBiclustering(n_clusters=2, random_state=0).fit(X)\n >>> clustering.row_labels_\n array([1, 1, 1, 0, 0, 0], dtype=int32)\n >>> clustering.column_labels_\n array([0, 1], dtype=int32)\n >>> clustering\n SpectralBiclustering(n_clusters=2, random_state=0)\n \"\"\"\n \n def __init__(self, n_clusters=3, *, method='bistochastic', n_components=6, n_best=3, svd_method='randomized', n_svd_vecs=None, mini_batch=False, init='k-means++', n_init=10, random_state=None):\n super().__init__(n_clusters, svd_method, n_svd_vecs, mini_batch, init, n_init, random_state)\n self.method = method\n self.n_components = n_components\n self.n_best = n_best\n \n def _check_parameters(self):\n super()._check_parameters()\n legal_methods = ('bistochastic', 'scale', 'log')\n if self.method not in legal_methods:\n raise ValueError(\"Unknown method: '{0}'. method must be one of {1}.\".format(self.method, legal_methods))\n try:\n int(self.n_clusters)\n except TypeError:\n try:\n (r, c) = self.n_clusters\n int(r)\n int(c)\n except (ValueError, TypeError) as e:\n raise ValueError('Incorrect parameter n_clusters has value: {}. It should either be a single integer or an iterable with two integers: (n_row_clusters, n_column_clusters)') from e\n if self.n_components < 1:\n raise ValueError('Parameter n_components must be greater than 0, but its value is {}'.format(self.n_components))\n if self.n_best < 1:\n raise ValueError('Parameter n_best must be greater than 0, but its value is {}'.format(self.n_best))\n if self.n_best > self.n_components:\n raise ValueError('n_best cannot be larger than n_components, but {} > {}'.format(self.n_best, self.n_components))\n \n def _fit(self, X):\n n_sv = self.n_components\n if self.method == 'bistochastic':\n normalized_data = _bistochastic_normalize(X)\n n_sv += 1\n elif self.method == 'scale':\n (normalized_data, _, _) = _scale_normalize(X)\n n_sv += 1\n elif self.method == 'log':\n normalized_data = _log_normalize(X)\n n_discard = 0 if self.method == 'log' else 1\n (u, v) = self._svd(normalized_data, n_sv, n_discard)\n ut = u.T\n vt = v.T\n try:\n (n_row_clusters, n_col_clusters) = self.n_clusters\n except TypeError:\n n_row_clusters = n_col_clusters = self.n_clusters\n best_ut = self._fit_best_piecewise(ut, self.n_best, n_row_clusters)\n best_vt = self._fit_best_piecewise(vt, self.n_best, n_col_clusters)\n self.row_labels_ = self._project_and_cluster(X, best_vt.T, n_row_clusters)\n self.column_labels_ = self._project_and_cluster(X.T, best_ut.T, n_col_clusters)\n self.rows_ = np.vstack([self.row_labels_ == label for label in range(n_row_clusters) for _ in range(n_col_clusters)])\n self.columns_ = np.vstack([self.column_labels_ == label for _ in range(n_row_clusters) for label in range(n_col_clusters)])\n \n def _fit_best_piecewise(self, vectors, n_best, n_clusters):\n \"\"\"Find the ``n_best`` vectors that are best approximated by piecewise\n constant vectors.\n\n The piecewise vectors are found by k-means; the best is chosen\n according to Euclidean distance.\n\n \"\"\"\n \n def make_piecewise(v):\n (centroid, labels) = self._k_means(v.reshape(-1, 1), n_clusters)\n return centroid[labels].ravel()\n piecewise_vectors = np.apply_along_axis(make_piecewise, axis=1, arr=vectors)\n dists = np.apply_along_axis(norm, axis=1, arr=vectors - piecewise_vectors)\n result = vectors[np.argsort(dists)[:n_best]]\n return result\n \n def _project_and_cluster(self, data, vectors, n_clusters):\n \"\"\"Project ``data`` to ``vectors`` and cluster the result.\"\"\"\n projected = safe_sparse_dot(data, vectors)\n (_, labels) = self._k_means(projected, n_clusters)\n return labels\n" }, { "name": "SpectralCoclustering", @@ -19972,8 +19939,8 @@ ], "methods": [ "sklearn.cluster._birch.Birch.__init__", - "sklearn.cluster._birch.Birch.fit_", - "sklearn.cluster._birch.Birch.partial_fit_", + "sklearn.cluster._birch.Birch.fit_@getter", + "sklearn.cluster._birch.Birch.partial_fit_@getter", "sklearn.cluster._birch.Birch.fit", "sklearn.cluster._birch.Birch._fit", "sklearn.cluster._birch.Birch._get_leaves", @@ -20013,7 +19980,7 @@ "sklearn.cluster._birch._CFSubcluster.__init__", "sklearn.cluster._birch._CFSubcluster.update", "sklearn.cluster._birch._CFSubcluster.merge_subcluster", - "sklearn.cluster._birch._CFSubcluster.radius" + "sklearn.cluster._birch._CFSubcluster.radius@getter" ], "is_public": false, "description": "Each subcluster in a CFNode is called a CFSubcluster.\n\nA CFSubcluster can have a CFNode has its child.", @@ -20077,7 +20044,7 @@ "is_public": true, "description": "K-Means clustering.\n\nRead more in the :ref:`User Guide `.", "docstring": "K-Means clustering.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n\n n_clusters : int, default=8\n The number of clusters to form as well as the number of\n centroids to generate.\n\n init : {'k-means++', 'random'}, callable or array-like of shape (n_clusters, n_features), default='k-means++'\n Method for initialization:\n\n 'k-means++' : selects initial cluster centers for k-mean\n clustering in a smart way to speed up convergence. See section\n Notes in k_init for more details.\n\n 'random': choose `n_clusters` observations (rows) at random from data\n for the initial centroids.\n\n If an array is passed, it should be of shape (n_clusters, n_features)\n and gives the initial centers.\n\n If a callable is passed, it should take arguments X, n_clusters and a\n random state and return an initialization.\n\n n_init : int, default=10\n Number of time the k-means algorithm will be run with different\n centroid seeds. The final results will be the best output of\n n_init consecutive runs in terms of inertia.\n\n max_iter : int, default=300\n Maximum number of iterations of the k-means algorithm for a\n single run.\n\n tol : float, default=1e-4\n Relative tolerance with regards to Frobenius norm of the difference\n in the cluster centers of two consecutive iterations to declare\n convergence.\n\n verbose : int, default=0\n Verbosity mode.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation for centroid initialization. Use\n an int to make the randomness deterministic.\n See :term:`Glossary `.\n\n copy_x : bool, default=True\n When pre-computing distances it is more numerically accurate to center\n the data first. If copy_x is True (default), then the original data is\n not modified. If False, the original data is modified, and put back\n before the function returns, but small numerical differences may be\n introduced by subtracting and then adding the data mean. Note that if\n the original data is not C-contiguous, a copy will be made even if\n copy_x is False. If the original data is sparse, but not in CSR format,\n a copy will be made even if copy_x is False.\n\n algorithm : {\"auto\", \"full\", \"elkan\"}, default=\"auto\"\n K-means algorithm to use. The classical EM-style algorithm is \"full\".\n The \"elkan\" variation is more efficient on data with well-defined\n clusters, by using the triangle inequality. However it's more memory\n intensive due to the allocation of an extra array of shape\n (n_samples, n_clusters).\n\n For now \"auto\" (kept for backward compatibility) chooses \"elkan\" but it\n might change in the future for a better heuristic.\n\n .. versionchanged:: 0.18\n Added Elkan algorithm\n\n Attributes\n ----------\n cluster_centers_ : ndarray of shape (n_clusters, n_features)\n Coordinates of cluster centers. If the algorithm stops before fully\n converging (see ``tol`` and ``max_iter``), these will not be\n consistent with ``labels_``.\n\n labels_ : ndarray of shape (n_samples,)\n Labels of each point\n\n inertia_ : float\n Sum of squared distances of samples to their closest cluster center,\n weighted by the sample weights if provided.\n\n n_iter_ : int\n Number of iterations run.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n MiniBatchKMeans : Alternative online implementation that does incremental\n updates of the centers positions using mini-batches.\n For large scale learning (say n_samples > 10k) MiniBatchKMeans is\n probably much faster than the default batch implementation.\n\n Notes\n -----\n The k-means problem is solved using either Lloyd's or Elkan's algorithm.\n\n The average complexity is given by O(k n T), where n is the number of\n samples and T is the number of iteration.\n\n The worst case complexity is given by O(n^(k+2/p)) with\n n = n_samples, p = n_features. (D. Arthur and S. Vassilvitskii,\n 'How slow is the k-means method?' SoCG2006)\n\n In practice, the k-means algorithm is very fast (one of the fastest\n clustering algorithms available), but it falls in local minima. That's why\n it can be useful to restart it several times.\n\n If the algorithm stops before fully converging (because of ``tol`` or\n ``max_iter``), ``labels_`` and ``cluster_centers_`` will not be consistent,\n i.e. the ``cluster_centers_`` will not be the means of the points in each\n cluster. Also, the estimator will reassign ``labels_`` after the last\n iteration to make ``labels_`` consistent with ``predict`` on the training\n set.\n\n Examples\n --------\n\n >>> from sklearn.cluster import KMeans\n >>> import numpy as np\n >>> X = np.array([[1, 2], [1, 4], [1, 0],\n ... [10, 2], [10, 4], [10, 0]])\n >>> kmeans = KMeans(n_clusters=2, random_state=0).fit(X)\n >>> kmeans.labels_\n array([1, 1, 1, 0, 0, 0], dtype=int32)\n >>> kmeans.predict([[0, 0], [12, 3]])\n array([1, 0], dtype=int32)\n >>> kmeans.cluster_centers_\n array([[10., 2.],\n [ 1., 2.]])\n ", - "source_code": "\n\nclass KMeans(TransformerMixin, ClusterMixin, BaseEstimator):\n \"\"\"K-Means clustering.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n\n n_clusters : int, default=8\n The number of clusters to form as well as the number of\n centroids to generate.\n\n init : {'k-means++', 'random'}, callable or array-like of shape (n_clusters, n_features), default='k-means++'\n Method for initialization:\n\n 'k-means++' : selects initial cluster centers for k-mean\n clustering in a smart way to speed up convergence. See section\n Notes in k_init for more details.\n\n 'random': choose `n_clusters` observations (rows) at random from data\n for the initial centroids.\n\n If an array is passed, it should be of shape (n_clusters, n_features)\n and gives the initial centers.\n\n If a callable is passed, it should take arguments X, n_clusters and a\n random state and return an initialization.\n\n n_init : int, default=10\n Number of time the k-means algorithm will be run with different\n centroid seeds. The final results will be the best output of\n n_init consecutive runs in terms of inertia.\n\n max_iter : int, default=300\n Maximum number of iterations of the k-means algorithm for a\n single run.\n\n tol : float, default=1e-4\n Relative tolerance with regards to Frobenius norm of the difference\n in the cluster centers of two consecutive iterations to declare\n convergence.\n\n verbose : int, default=0\n Verbosity mode.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation for centroid initialization. Use\n an int to make the randomness deterministic.\n See :term:`Glossary `.\n\n copy_x : bool, default=True\n When pre-computing distances it is more numerically accurate to center\n the data first. If copy_x is True (default), then the original data is\n not modified. If False, the original data is modified, and put back\n before the function returns, but small numerical differences may be\n introduced by subtracting and then adding the data mean. Note that if\n the original data is not C-contiguous, a copy will be made even if\n copy_x is False. If the original data is sparse, but not in CSR format,\n a copy will be made even if copy_x is False.\n\n algorithm : {\"auto\", \"full\", \"elkan\"}, default=\"auto\"\n K-means algorithm to use. The classical EM-style algorithm is \"full\".\n The \"elkan\" variation is more efficient on data with well-defined\n clusters, by using the triangle inequality. However it's more memory\n intensive due to the allocation of an extra array of shape\n (n_samples, n_clusters).\n\n For now \"auto\" (kept for backward compatibility) chooses \"elkan\" but it\n might change in the future for a better heuristic.\n\n .. versionchanged:: 0.18\n Added Elkan algorithm\n\n Attributes\n ----------\n cluster_centers_ : ndarray of shape (n_clusters, n_features)\n Coordinates of cluster centers. If the algorithm stops before fully\n converging (see ``tol`` and ``max_iter``), these will not be\n consistent with ``labels_``.\n\n labels_ : ndarray of shape (n_samples,)\n Labels of each point\n\n inertia_ : float\n Sum of squared distances of samples to their closest cluster center,\n weighted by the sample weights if provided.\n\n n_iter_ : int\n Number of iterations run.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n MiniBatchKMeans : Alternative online implementation that does incremental\n updates of the centers positions using mini-batches.\n For large scale learning (say n_samples > 10k) MiniBatchKMeans is\n probably much faster than the default batch implementation.\n\n Notes\n -----\n The k-means problem is solved using either Lloyd's or Elkan's algorithm.\n\n The average complexity is given by O(k n T), where n is the number of\n samples and T is the number of iteration.\n\n The worst case complexity is given by O(n^(k+2/p)) with\n n = n_samples, p = n_features. (D. Arthur and S. Vassilvitskii,\n 'How slow is the k-means method?' SoCG2006)\n\n In practice, the k-means algorithm is very fast (one of the fastest\n clustering algorithms available), but it falls in local minima. That's why\n it can be useful to restart it several times.\n\n If the algorithm stops before fully converging (because of ``tol`` or\n ``max_iter``), ``labels_`` and ``cluster_centers_`` will not be consistent,\n i.e. the ``cluster_centers_`` will not be the means of the points in each\n cluster. Also, the estimator will reassign ``labels_`` after the last\n iteration to make ``labels_`` consistent with ``predict`` on the training\n set.\n\n Examples\n --------\n\n >>> from sklearn.cluster import KMeans\n >>> import numpy as np\n >>> X = np.array([[1, 2], [1, 4], [1, 0],\n ... [10, 2], [10, 4], [10, 0]])\n >>> kmeans = KMeans(n_clusters=2, random_state=0).fit(X)\n >>> kmeans.labels_\n array([1, 1, 1, 0, 0, 0], dtype=int32)\n >>> kmeans.predict([[0, 0], [12, 3]])\n array([1, 0], dtype=int32)\n >>> kmeans.cluster_centers_\n array([[10., 2.],\n [ 1., 2.]])\n \"\"\"\n \n def __init__(self, n_clusters=8, *, init='k-means++', n_init=10, max_iter=300, tol=0.0001, verbose=0, random_state=None, copy_x=True, algorithm='auto'):\n self.n_clusters = n_clusters\n self.init = init\n self.max_iter = max_iter\n self.tol = tol\n self.n_init = n_init\n self.verbose = verbose\n self.random_state = random_state\n self.copy_x = copy_x\n self.algorithm = algorithm\n \n def _check_params(self, X):\n if self.n_init <= 0:\n raise ValueError(f'n_init should be > 0, got {self.n_init} instead.')\n self._n_init = self.n_init\n if self.max_iter <= 0:\n raise ValueError(f'max_iter should be > 0, got {self.max_iter} instead.')\n if X.shape[0] < self.n_clusters:\n raise ValueError(f'n_samples={X.shape[0]} should be >= n_clusters={self.n_clusters}.')\n self._tol = _tolerance(X, self.tol)\n if self.algorithm not in ('auto', 'full', 'elkan'):\n raise ValueError(f\"Algorithm must be 'auto', 'full' or 'elkan', got {self.algorithm} instead.\")\n self._algorithm = self.algorithm\n if self._algorithm == 'auto':\n self._algorithm = 'full' if self.n_clusters == 1 else 'elkan'\n if self._algorithm == 'elkan' and self.n_clusters == 1:\n warnings.warn(\"algorithm='elkan' doesn't make sense for a single cluster. Using 'full' instead.\", RuntimeWarning)\n self._algorithm = 'full'\n if not (hasattr(self.init, '__array__') or callable(self.init) or isinstance(self.init, str) and self.init in ['k-means++', 'random']):\n raise ValueError(f\"init should be either 'k-means++', 'random', a ndarray or a callable, got '{self.init}' instead.\")\n if hasattr(self.init, '__array__') and self._n_init != 1:\n warnings.warn(f'Explicit initial center position passed: performing only one init in {self.__class__.__name__} instead of n_init={self._n_init}.', RuntimeWarning, stacklevel=2)\n self._n_init = 1\n \n def _validate_center_shape(self, X, centers):\n \"\"\"Check if centers is compatible with X and n_clusters.\"\"\"\n if centers.shape[0] != self.n_clusters:\n raise ValueError(f'The shape of the initial centers {centers.shape} does not match the number of clusters {self.n_clusters}.')\n if centers.shape[1] != X.shape[1]:\n raise ValueError(f'The shape of the initial centers {centers.shape} does not match the number of features of the data {X.shape[1]}.')\n \n def _check_test_data(self, X):\n X = self._validate_data(X, accept_sparse='csr', reset=False, dtype=[np.float64, np.float32], order='C', accept_large_sparse=False)\n return X\n \n def _check_mkl_vcomp(self, X, n_samples):\n \"\"\"Warns when vcomp and mkl are both present\"\"\"\n if sp.issparse(X):\n return\n active_threads = int(np.ceil(n_samples / CHUNK_SIZE))\n if active_threads < self._n_threads:\n modules = threadpool_info()\n has_vcomp = 'vcomp' in [module['prefix'] for module in modules]\n has_mkl = ('mkl', 'intel') in [(module['internal_api'], module.get('threading_layer', None)) for module in modules]\n if has_vcomp and has_mkl:\n if not hasattr(self, 'batch_size'):\n warnings.warn(f'KMeans is known to have a memory leak on Windows with MKL, when there are less chunks than available threads. You can avoid it by setting the environment variable OMP_NUM_THREADS={active_threads}.')\n else:\n warnings.warn(f'MiniBatchKMeans is known to have a memory leak on Windows with MKL, when there are less chunks than available threads. You can prevent it by setting batch_size >= {self._n_threads * CHUNK_SIZE} or by setting the environment variable OMP_NUM_THREADS={active_threads}')\n \n def _init_centroids(self, X, x_squared_norms, init, random_state, init_size=None):\n \"\"\"Compute the initial centroids.\n\n Parameters\n ----------\n X : {ndarray, sparse matrix} of shape (n_samples, n_features)\n The input samples.\n\n x_squared_norms : ndarray of shape (n_samples,)\n Squared euclidean norm of each data point. Pass it if you have it\n at hands already to avoid it being recomputed here.\n\n init : {'k-means++', 'random'}, callable or ndarray of shape (n_clusters, n_features)\n Method for initialization.\n\n random_state : RandomState instance\n Determines random number generation for centroid initialization.\n See :term:`Glossary `.\n\n init_size : int, default=None\n Number of samples to randomly sample for speeding up the\n initialization (sometimes at the expense of accuracy).\n\n Returns\n -------\n centers : ndarray of shape (n_clusters, n_features)\n \"\"\"\n n_samples = X.shape[0]\n n_clusters = self.n_clusters\n if init_size is not None and init_size < n_samples:\n init_indices = random_state.randint(0, n_samples, init_size)\n X = X[init_indices]\n x_squared_norms = x_squared_norms[init_indices]\n n_samples = X.shape[0]\n if isinstance(init, str) and init == 'k-means++':\n (centers, _) = _kmeans_plusplus(X, n_clusters, random_state=random_state, x_squared_norms=x_squared_norms)\n elif isinstance(init, str) and init == 'random':\n seeds = random_state.permutation(n_samples)[:n_clusters]\n centers = X[seeds]\n elif hasattr(init, '__array__'):\n centers = init\n elif callable(init):\n centers = init(X, n_clusters, random_state=random_state)\n centers = check_array(centers, dtype=X.dtype, copy=False, order='C')\n self._validate_center_shape(X, centers)\n if sp.issparse(centers):\n centers = centers.toarray()\n return centers\n \n def fit(self, X, y=None, sample_weight=None):\n \"\"\"Compute k-means clustering.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training instances to cluster. It must be noted that the data\n will be converted to C ordering, which will cause a memory\n copy if the given data is not C-contiguous.\n If a sparse matrix is passed, a copy will be made if it's not in\n CSR format.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n .. versionadded:: 0.20\n\n Returns\n -------\n self\n Fitted estimator.\n \"\"\"\n X = self._validate_data(X, accept_sparse='csr', dtype=[np.float64, np.float32], order='C', copy=self.copy_x, accept_large_sparse=False)\n self._check_params(X)\n random_state = check_random_state(self.random_state)\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n self._n_threads = _openmp_effective_n_threads()\n init = self.init\n if hasattr(init, '__array__'):\n init = check_array(init, dtype=X.dtype, copy=True, order='C')\n self._validate_center_shape(X, init)\n if not sp.issparse(X):\n X_mean = X.mean(axis=0)\n X -= X_mean\n if hasattr(init, '__array__'):\n init -= X_mean\n x_squared_norms = row_norms(X, squared=True)\n if self._algorithm == 'full':\n kmeans_single = _kmeans_single_lloyd\n self._check_mkl_vcomp(X, X.shape[0])\n else:\n kmeans_single = _kmeans_single_elkan\n best_inertia = None\n for i in range(self._n_init):\n centers_init = self._init_centroids(X, x_squared_norms=x_squared_norms, init=init, random_state=random_state)\n if self.verbose:\n print('Initialization complete')\n (labels, inertia, centers, n_iter_) = kmeans_single(X, sample_weight, centers_init, max_iter=self.max_iter, verbose=self.verbose, tol=self._tol, x_squared_norms=x_squared_norms, n_threads=self._n_threads)\n if best_inertia is None or inertia < best_inertia * (1 - 1e-06):\n best_labels = labels\n best_centers = centers\n best_inertia = inertia\n best_n_iter = n_iter_\n if not sp.issparse(X):\n if not self.copy_x:\n X += X_mean\n best_centers += X_mean\n distinct_clusters = len(set(best_labels))\n if distinct_clusters < self.n_clusters:\n warnings.warn('Number of distinct clusters ({}) found smaller than n_clusters ({}). Possibly due to duplicate points in X.'.format(distinct_clusters, self.n_clusters), ConvergenceWarning, stacklevel=2)\n self.cluster_centers_ = best_centers\n self.labels_ = best_labels\n self.inertia_ = best_inertia\n self.n_iter_ = best_n_iter\n return self\n \n def fit_predict(self, X, y=None, sample_weight=None):\n \"\"\"Compute cluster centers and predict cluster index for each sample.\n\n Convenience method; equivalent to calling fit(X) followed by\n predict(X).\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n New data to transform.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n Returns\n -------\n labels : ndarray of shape (n_samples,)\n Index of the cluster each sample belongs to.\n \"\"\"\n return self.fit(X, sample_weight=sample_weight).labels_\n \n def fit_transform(self, X, y=None, sample_weight=None):\n \"\"\"Compute clustering and transform X to cluster-distance space.\n\n Equivalent to fit(X).transform(X), but more efficiently implemented.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n New data to transform.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n Returns\n -------\n X_new : ndarray of shape (n_samples, n_clusters)\n X transformed in the new space.\n \"\"\"\n return self.fit(X, sample_weight=sample_weight)._transform(X)\n \n def transform(self, X):\n \"\"\"Transform X to a cluster-distance space.\n\n In the new space, each dimension is the distance to the cluster\n centers. Note that even if X is sparse, the array returned by\n `transform` will typically be dense.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n New data to transform.\n\n Returns\n -------\n X_new : ndarray of shape (n_samples, n_clusters)\n X transformed in the new space.\n \"\"\"\n check_is_fitted(self)\n X = self._check_test_data(X)\n return self._transform(X)\n \n def _transform(self, X):\n \"\"\"Guts of transform method; no input validation.\"\"\"\n return euclidean_distances(X, self.cluster_centers_)\n \n def predict(self, X, sample_weight=None):\n \"\"\"Predict the closest cluster each sample in X belongs to.\n\n In the vector quantization literature, `cluster_centers_` is called\n the code book and each value returned by `predict` is the index of\n the closest code in the code book.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n New data to predict.\n\n sample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n Returns\n -------\n labels : ndarray of shape (n_samples,)\n Index of the cluster each sample belongs to.\n \"\"\"\n check_is_fitted(self)\n X = self._check_test_data(X)\n x_squared_norms = row_norms(X, squared=True)\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n return _labels_inertia_threadpool_limit(X, sample_weight, x_squared_norms, self.cluster_centers_, self._n_threads)[0]\n \n def score(self, X, y=None, sample_weight=None):\n \"\"\"Opposite of the value of X on the K-means objective.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n New data.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n Returns\n -------\n score : float\n Opposite of the value of X on the K-means objective.\n \"\"\"\n check_is_fitted(self)\n X = self._check_test_data(X)\n x_squared_norms = row_norms(X, squared=True)\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n return -_labels_inertia_threadpool_limit(X, sample_weight, x_squared_norms, self.cluster_centers_, self._n_threads)[1]\n \n def _more_tags(self):\n return {'_xfail_checks': {'check_sample_weights_invariance': 'zero sample_weight is not equivalent to removing samples'}}\n" + "source_code": "\n\nclass KMeans(TransformerMixin, ClusterMixin, BaseEstimator):\n \"\"\"K-Means clustering.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n\n n_clusters : int, default=8\n The number of clusters to form as well as the number of\n centroids to generate.\n\n init : {'k-means++', 'random'}, callable or array-like of shape (n_clusters, n_features), default='k-means++'\n Method for initialization:\n\n 'k-means++' : selects initial cluster centers for k-mean\n clustering in a smart way to speed up convergence. See section\n Notes in k_init for more details.\n\n 'random': choose `n_clusters` observations (rows) at random from data\n for the initial centroids.\n\n If an array is passed, it should be of shape (n_clusters, n_features)\n and gives the initial centers.\n\n If a callable is passed, it should take arguments X, n_clusters and a\n random state and return an initialization.\n\n n_init : int, default=10\n Number of time the k-means algorithm will be run with different\n centroid seeds. The final results will be the best output of\n n_init consecutive runs in terms of inertia.\n\n max_iter : int, default=300\n Maximum number of iterations of the k-means algorithm for a\n single run.\n\n tol : float, default=1e-4\n Relative tolerance with regards to Frobenius norm of the difference\n in the cluster centers of two consecutive iterations to declare\n convergence.\n\n verbose : int, default=0\n Verbosity mode.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation for centroid initialization. Use\n an int to make the randomness deterministic.\n See :term:`Glossary `.\n\n copy_x : bool, default=True\n When pre-computing distances it is more numerically accurate to center\n the data first. If copy_x is True (default), then the original data is\n not modified. If False, the original data is modified, and put back\n before the function returns, but small numerical differences may be\n introduced by subtracting and then adding the data mean. Note that if\n the original data is not C-contiguous, a copy will be made even if\n copy_x is False. If the original data is sparse, but not in CSR format,\n a copy will be made even if copy_x is False.\n\n algorithm : {\"auto\", \"full\", \"elkan\"}, default=\"auto\"\n K-means algorithm to use. The classical EM-style algorithm is \"full\".\n The \"elkan\" variation is more efficient on data with well-defined\n clusters, by using the triangle inequality. However it's more memory\n intensive due to the allocation of an extra array of shape\n (n_samples, n_clusters).\n\n For now \"auto\" (kept for backward compatibility) chooses \"elkan\" but it\n might change in the future for a better heuristic.\n\n .. versionchanged:: 0.18\n Added Elkan algorithm\n\n Attributes\n ----------\n cluster_centers_ : ndarray of shape (n_clusters, n_features)\n Coordinates of cluster centers. If the algorithm stops before fully\n converging (see ``tol`` and ``max_iter``), these will not be\n consistent with ``labels_``.\n\n labels_ : ndarray of shape (n_samples,)\n Labels of each point\n\n inertia_ : float\n Sum of squared distances of samples to their closest cluster center,\n weighted by the sample weights if provided.\n\n n_iter_ : int\n Number of iterations run.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n MiniBatchKMeans : Alternative online implementation that does incremental\n updates of the centers positions using mini-batches.\n For large scale learning (say n_samples > 10k) MiniBatchKMeans is\n probably much faster than the default batch implementation.\n\n Notes\n -----\n The k-means problem is solved using either Lloyd's or Elkan's algorithm.\n\n The average complexity is given by O(k n T), where n is the number of\n samples and T is the number of iteration.\n\n The worst case complexity is given by O(n^(k+2/p)) with\n n = n_samples, p = n_features. (D. Arthur and S. Vassilvitskii,\n 'How slow is the k-means method?' SoCG2006)\n\n In practice, the k-means algorithm is very fast (one of the fastest\n clustering algorithms available), but it falls in local minima. That's why\n it can be useful to restart it several times.\n\n If the algorithm stops before fully converging (because of ``tol`` or\n ``max_iter``), ``labels_`` and ``cluster_centers_`` will not be consistent,\n i.e. the ``cluster_centers_`` will not be the means of the points in each\n cluster. Also, the estimator will reassign ``labels_`` after the last\n iteration to make ``labels_`` consistent with ``predict`` on the training\n set.\n\n Examples\n --------\n\n >>> from sklearn.cluster import KMeans\n >>> import numpy as np\n >>> X = np.array([[1, 2], [1, 4], [1, 0],\n ... [10, 2], [10, 4], [10, 0]])\n >>> kmeans = KMeans(n_clusters=2, random_state=0).fit(X)\n >>> kmeans.labels_\n array([1, 1, 1, 0, 0, 0], dtype=int32)\n >>> kmeans.predict([[0, 0], [12, 3]])\n array([1, 0], dtype=int32)\n >>> kmeans.cluster_centers_\n array([[10., 2.],\n [ 1., 2.]])\n \"\"\"\n \n def __init__(self, n_clusters=8, *, init='k-means++', n_init=10, max_iter=300, tol=0.0001, verbose=0, random_state=None, copy_x=True, algorithm='auto'):\n self.n_clusters = n_clusters\n self.init = init\n self.max_iter = max_iter\n self.tol = tol\n self.n_init = n_init\n self.verbose = verbose\n self.random_state = random_state\n self.copy_x = copy_x\n self.algorithm = algorithm\n \n def _check_params(self, X):\n if self.n_init <= 0:\n raise ValueError(f'n_init should be > 0, got {self.n_init} instead.')\n self._n_init = self.n_init\n if self.max_iter <= 0:\n raise ValueError(f'max_iter should be > 0, got {self.max_iter} instead.')\n if X.shape[0] < self.n_clusters:\n raise ValueError(f'n_samples={X.shape[0]} should be >= n_clusters={self.n_clusters}.')\n self._tol = _tolerance(X, self.tol)\n if self.algorithm not in ('auto', 'full', 'elkan'):\n raise ValueError(f\"Algorithm must be 'auto', 'full' or 'elkan', got {self.algorithm} instead.\")\n self._algorithm = self.algorithm\n if self._algorithm == 'auto':\n self._algorithm = 'full' if self.n_clusters == 1 else 'elkan'\n if self._algorithm == 'elkan' and self.n_clusters == 1:\n warnings.warn(\"algorithm='elkan' doesn't make sense for a single cluster. Using 'full' instead.\", RuntimeWarning)\n self._algorithm = 'full'\n if not (hasattr(self.init, '__array__') or callable(self.init) or isinstance(self.init, str) and self.init in ['k-means++', 'random']):\n raise ValueError(f\"init should be either 'k-means++', 'random', a ndarray or a callable, got '{self.init}' instead.\")\n if hasattr(self.init, '__array__') and self._n_init != 1:\n warnings.warn(f'Explicit initial center position passed: performing only one init in {self.__class__.__name__} instead of n_init={self._n_init}.', RuntimeWarning, stacklevel=2)\n self._n_init = 1\n \n def _validate_center_shape(self, X, centers):\n \"\"\"Check if centers is compatible with X and n_clusters.\"\"\"\n if centers.shape[0] != self.n_clusters:\n raise ValueError(f'The shape of the initial centers {centers.shape} does not match the number of clusters {self.n_clusters}.')\n if centers.shape[1] != X.shape[1]:\n raise ValueError(f'The shape of the initial centers {centers.shape} does not match the number of features of the data {X.shape[1]}.')\n \n def _check_test_data(self, X):\n X = self._validate_data(X, accept_sparse='csr', reset=False, dtype=[np.float64, np.float32], order='C', accept_large_sparse=False)\n return X\n \n def _check_mkl_vcomp(self, X, n_samples):\n \"\"\"Warns when vcomp and mkl are both present\"\"\"\n if sp.issparse(X):\n return\n active_threads = int(np.ceil(n_samples / CHUNK_SIZE))\n if active_threads < self._n_threads:\n modules = threadpool_info()\n has_vcomp = 'vcomp' in [module['prefix'] for module in modules]\n has_mkl = ('mkl', 'intel') in [(module['internal_api'], module.get('threading_layer', None)) for module in modules]\n if has_vcomp and has_mkl:\n if not hasattr(self, 'batch_size'):\n warnings.warn(f'KMeans is known to have a memory leak on Windows with MKL, when there are less chunks than available threads. You can avoid it by setting the environment variable OMP_NUM_THREADS={active_threads}.')\n else:\n warnings.warn(f'MiniBatchKMeans is known to have a memory leak on Windows with MKL, when there are less chunks than available threads. You can prevent it by setting batch_size >= {self._n_threads * CHUNK_SIZE} or by setting the environment variable OMP_NUM_THREADS={active_threads}')\n \n def _init_centroids(self, X, x_squared_norms, init, random_state, init_size=None):\n \"\"\"Compute the initial centroids.\n\n Parameters\n ----------\n X : {ndarray, sparse matrix} of shape (n_samples, n_features)\n The input samples.\n\n x_squared_norms : ndarray of shape (n_samples,)\n Squared euclidean norm of each data point. Pass it if you have it\n at hands already to avoid it being recomputed here.\n\n init : {'k-means++', 'random'}, callable or ndarray of shape (n_clusters, n_features)\n Method for initialization.\n\n random_state : RandomState instance\n Determines random number generation for centroid initialization.\n See :term:`Glossary `.\n\n init_size : int, default=None\n Number of samples to randomly sample for speeding up the\n initialization (sometimes at the expense of accuracy).\n\n Returns\n -------\n centers : ndarray of shape (n_clusters, n_features)\n \"\"\"\n n_samples = X.shape[0]\n n_clusters = self.n_clusters\n if init_size is not None and init_size < n_samples:\n init_indices = random_state.randint(0, n_samples, init_size)\n X = X[init_indices]\n x_squared_norms = x_squared_norms[init_indices]\n n_samples = X.shape[0]\n if isinstance(init, str) and init == 'k-means++':\n (centers, _) = _kmeans_plusplus(X, n_clusters, random_state=random_state, x_squared_norms=x_squared_norms)\n elif isinstance(init, str) and init == 'random':\n seeds = random_state.permutation(n_samples)[:n_clusters]\n centers = X[seeds]\n elif hasattr(init, '__array__'):\n centers = init\n elif callable(init):\n centers = init(X, n_clusters, random_state=random_state)\n centers = check_array(centers, dtype=X.dtype, copy=False, order='C')\n self._validate_center_shape(X, centers)\n if sp.issparse(centers):\n centers = centers.toarray()\n return centers\n \n def fit(self, X, y=None, sample_weight=None):\n \"\"\"Compute k-means clustering.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training instances to cluster. It must be noted that the data\n will be converted to C ordering, which will cause a memory\n copy if the given data is not C-contiguous.\n If a sparse matrix is passed, a copy will be made if it's not in\n CSR format.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n .. versionadded:: 0.20\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n X = self._validate_data(X, accept_sparse='csr', dtype=[np.float64, np.float32], order='C', copy=self.copy_x, accept_large_sparse=False)\n self._check_params(X)\n random_state = check_random_state(self.random_state)\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n self._n_threads = _openmp_effective_n_threads()\n init = self.init\n if hasattr(init, '__array__'):\n init = check_array(init, dtype=X.dtype, copy=True, order='C')\n self._validate_center_shape(X, init)\n if not sp.issparse(X):\n X_mean = X.mean(axis=0)\n X -= X_mean\n if hasattr(init, '__array__'):\n init -= X_mean\n x_squared_norms = row_norms(X, squared=True)\n if self._algorithm == 'full':\n kmeans_single = _kmeans_single_lloyd\n self._check_mkl_vcomp(X, X.shape[0])\n else:\n kmeans_single = _kmeans_single_elkan\n (best_inertia, best_labels) = (None, None)\n for i in range(self._n_init):\n centers_init = self._init_centroids(X, x_squared_norms=x_squared_norms, init=init, random_state=random_state)\n if self.verbose:\n print('Initialization complete')\n (labels, inertia, centers, n_iter_) = kmeans_single(X, sample_weight, centers_init, max_iter=self.max_iter, verbose=self.verbose, tol=self._tol, x_squared_norms=x_squared_norms, n_threads=self._n_threads)\n if best_inertia is None or inertia < best_inertia and not _is_same_clustering(labels, best_labels, self.n_clusters):\n best_labels = labels\n best_centers = centers\n best_inertia = inertia\n best_n_iter = n_iter_\n if not sp.issparse(X):\n if not self.copy_x:\n X += X_mean\n best_centers += X_mean\n distinct_clusters = len(set(best_labels))\n if distinct_clusters < self.n_clusters:\n warnings.warn('Number of distinct clusters ({}) found smaller than n_clusters ({}). Possibly due to duplicate points in X.'.format(distinct_clusters, self.n_clusters), ConvergenceWarning, stacklevel=2)\n self.cluster_centers_ = best_centers\n self.labels_ = best_labels\n self.inertia_ = best_inertia\n self.n_iter_ = best_n_iter\n return self\n \n def fit_predict(self, X, y=None, sample_weight=None):\n \"\"\"Compute cluster centers and predict cluster index for each sample.\n\n Convenience method; equivalent to calling fit(X) followed by\n predict(X).\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n New data to transform.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n Returns\n -------\n labels : ndarray of shape (n_samples,)\n Index of the cluster each sample belongs to.\n \"\"\"\n return self.fit(X, sample_weight=sample_weight).labels_\n \n def fit_transform(self, X, y=None, sample_weight=None):\n \"\"\"Compute clustering and transform X to cluster-distance space.\n\n Equivalent to fit(X).transform(X), but more efficiently implemented.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n New data to transform.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n Returns\n -------\n X_new : ndarray of shape (n_samples, n_clusters)\n X transformed in the new space.\n \"\"\"\n return self.fit(X, sample_weight=sample_weight)._transform(X)\n \n def transform(self, X):\n \"\"\"Transform X to a cluster-distance space.\n\n In the new space, each dimension is the distance to the cluster\n centers. Note that even if X is sparse, the array returned by\n `transform` will typically be dense.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n New data to transform.\n\n Returns\n -------\n X_new : ndarray of shape (n_samples, n_clusters)\n X transformed in the new space.\n \"\"\"\n check_is_fitted(self)\n X = self._check_test_data(X)\n return self._transform(X)\n \n def _transform(self, X):\n \"\"\"Guts of transform method; no input validation.\"\"\"\n return euclidean_distances(X, self.cluster_centers_)\n \n def predict(self, X, sample_weight=None):\n \"\"\"Predict the closest cluster each sample in X belongs to.\n\n In the vector quantization literature, `cluster_centers_` is called\n the code book and each value returned by `predict` is the index of\n the closest code in the code book.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n New data to predict.\n\n sample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n Returns\n -------\n labels : ndarray of shape (n_samples,)\n Index of the cluster each sample belongs to.\n \"\"\"\n check_is_fitted(self)\n X = self._check_test_data(X)\n x_squared_norms = row_norms(X, squared=True)\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n return _labels_inertia_threadpool_limit(X, sample_weight, x_squared_norms, self.cluster_centers_, self._n_threads)[0]\n \n def score(self, X, y=None, sample_weight=None):\n \"\"\"Opposite of the value of X on the K-means objective.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n New data.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n Returns\n -------\n score : float\n Opposite of the value of X on the K-means objective.\n \"\"\"\n check_is_fitted(self)\n X = self._check_test_data(X)\n x_squared_norms = row_norms(X, squared=True)\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n return -_labels_inertia_threadpool_limit(X, sample_weight, x_squared_norms, self.cluster_centers_, self._n_threads)[1]\n \n def _more_tags(self):\n return {'_xfail_checks': {'check_sample_weights_invariance': 'zero sample_weight is not equivalent to removing samples'}}\n" }, { "name": "MiniBatchKMeans", @@ -20086,9 +20053,9 @@ "superclasses": ["KMeans"], "methods": [ "sklearn.cluster._kmeans.MiniBatchKMeans.__init__", - "sklearn.cluster._kmeans.MiniBatchKMeans.counts_", - "sklearn.cluster._kmeans.MiniBatchKMeans.init_size_", - "sklearn.cluster._kmeans.MiniBatchKMeans.random_state_", + "sklearn.cluster._kmeans.MiniBatchKMeans.counts_@getter", + "sklearn.cluster._kmeans.MiniBatchKMeans.init_size_@getter", + "sklearn.cluster._kmeans.MiniBatchKMeans.random_state_@getter", "sklearn.cluster._kmeans.MiniBatchKMeans._check_params", "sklearn.cluster._kmeans.MiniBatchKMeans._mini_batch_convergence", "sklearn.cluster._kmeans.MiniBatchKMeans._random_reassign", @@ -20100,7 +20067,7 @@ "is_public": true, "description": "Mini-Batch K-Means clustering.\n\nRead more in the :ref:`User Guide `.", "docstring": "\n Mini-Batch K-Means clustering.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n\n n_clusters : int, default=8\n The number of clusters to form as well as the number of\n centroids to generate.\n\n init : {'k-means++', 'random'}, callable or array-like of shape (n_clusters, n_features), default='k-means++'\n Method for initialization:\n\n 'k-means++' : selects initial cluster centers for k-mean\n clustering in a smart way to speed up convergence. See section\n Notes in k_init for more details.\n\n 'random': choose `n_clusters` observations (rows) at random from data\n for the initial centroids.\n\n If an array is passed, it should be of shape (n_clusters, n_features)\n and gives the initial centers.\n\n If a callable is passed, it should take arguments X, n_clusters and a\n random state and return an initialization.\n\n max_iter : int, default=100\n Maximum number of iterations over the complete dataset before\n stopping independently of any early stopping criterion heuristics.\n\n batch_size : int, default=1024\n Size of the mini batches.\n For faster compuations, you can set the ``batch_size`` greater than\n 256 * number of cores to enable parallelism on all cores.\n\n .. versionchanged:: 1.0\n `batch_size` default changed from 100 to 1024.\n\n verbose : int, default=0\n Verbosity mode.\n\n compute_labels : bool, default=True\n Compute label assignment and inertia for the complete dataset\n once the minibatch optimization has converged in fit.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation for centroid initialization and\n random reassignment. Use an int to make the randomness deterministic.\n See :term:`Glossary `.\n\n tol : float, default=0.0\n Control early stopping based on the relative center changes as\n measured by a smoothed, variance-normalized of the mean center\n squared position changes. This early stopping heuristics is\n closer to the one used for the batch variant of the algorithms\n but induces a slight computational and memory overhead over the\n inertia heuristic.\n\n To disable convergence detection based on normalized center\n change, set tol to 0.0 (default).\n\n max_no_improvement : int, default=10\n Control early stopping based on the consecutive number of mini\n batches that does not yield an improvement on the smoothed inertia.\n\n To disable convergence detection based on inertia, set\n max_no_improvement to None.\n\n init_size : int, default=None\n Number of samples to randomly sample for speeding up the\n initialization (sometimes at the expense of accuracy): the\n only algorithm is initialized by running a batch KMeans on a\n random subset of the data. This needs to be larger than n_clusters.\n\n If `None`, the heuristic is `init_size = 3 * batch_size` if\n `3 * batch_size < n_clusters`, else `init_size = 3 * n_clusters`.\n\n n_init : int, default=3\n Number of random initializations that are tried.\n In contrast to KMeans, the algorithm is only run once, using the\n best of the ``n_init`` initializations as measured by inertia.\n\n reassignment_ratio : float, default=0.01\n Control the fraction of the maximum number of counts for a center to\n be reassigned. A higher value means that low count centers are more\n easily reassigned, which means that the model will take longer to\n converge, but should converge in a better clustering. However, too high\n a value may cause convergence issues, especially with a small batch\n size.\n\n Attributes\n ----------\n\n cluster_centers_ : ndarray of shape (n_clusters, n_features)\n Coordinates of cluster centers.\n\n labels_ : ndarray of shape (n_samples,)\n Labels of each point (if compute_labels is set to True).\n\n inertia_ : float\n The value of the inertia criterion associated with the chosen\n partition if compute_labels is set to True. If compute_labels is set to\n False, it's an approximation of the inertia based on an exponentially\n weighted average of the batch inertiae.\n The inertia is defined as the sum of square distances of samples to\n their cluster center, weighted by the sample weights if provided.\n\n n_iter_ : int\n Number of iterations over the full dataset.\n\n n_steps_ : int\n Number of minibatches processed.\n\n .. versionadded:: 1.0\n\n counts_ : ndarray of shape (n_clusters,)\n Weight sum of each cluster.\n\n .. deprecated:: 0.24\n This attribute is deprecated in 0.24 and will be removed in\n 1.1 (renaming of 0.26).\n\n init_size_ : int\n The effective number of samples used for the initialization.\n\n .. deprecated:: 0.24\n This attribute is deprecated in 0.24 and will be removed in\n 1.1 (renaming of 0.26).\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n KMeans : The classic implementation of the clustering method based on the\n Lloyd's algorithm. It consumes the whole set of input data at each\n iteration.\n\n Notes\n -----\n See https://www.eecs.tufts.edu/~dsculley/papers/fastkmeans.pdf\n\n Examples\n --------\n >>> from sklearn.cluster import MiniBatchKMeans\n >>> import numpy as np\n >>> X = np.array([[1, 2], [1, 4], [1, 0],\n ... [4, 2], [4, 0], [4, 4],\n ... [4, 5], [0, 1], [2, 2],\n ... [3, 2], [5, 5], [1, -1]])\n >>> # manually fit on batches\n >>> kmeans = MiniBatchKMeans(n_clusters=2,\n ... random_state=0,\n ... batch_size=6)\n >>> kmeans = kmeans.partial_fit(X[0:6,:])\n >>> kmeans = kmeans.partial_fit(X[6:12,:])\n >>> kmeans.cluster_centers_\n array([[2. , 1. ],\n [3.5, 4.5]])\n >>> kmeans.predict([[0, 0], [4, 4]])\n array([0, 1], dtype=int32)\n >>> # fit on the whole data\n >>> kmeans = MiniBatchKMeans(n_clusters=2,\n ... random_state=0,\n ... batch_size=6,\n ... max_iter=10).fit(X)\n >>> kmeans.cluster_centers_\n array([[1.19..., 1.22...],\n [4.03..., 2.46...]])\n >>> kmeans.predict([[0, 0], [4, 4]])\n array([0, 1], dtype=int32)\n ", - "source_code": "\n\nclass MiniBatchKMeans(KMeans):\n \"\"\"\n Mini-Batch K-Means clustering.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n\n n_clusters : int, default=8\n The number of clusters to form as well as the number of\n centroids to generate.\n\n init : {'k-means++', 'random'}, callable or array-like of shape (n_clusters, n_features), default='k-means++'\n Method for initialization:\n\n 'k-means++' : selects initial cluster centers for k-mean\n clustering in a smart way to speed up convergence. See section\n Notes in k_init for more details.\n\n 'random': choose `n_clusters` observations (rows) at random from data\n for the initial centroids.\n\n If an array is passed, it should be of shape (n_clusters, n_features)\n and gives the initial centers.\n\n If a callable is passed, it should take arguments X, n_clusters and a\n random state and return an initialization.\n\n max_iter : int, default=100\n Maximum number of iterations over the complete dataset before\n stopping independently of any early stopping criterion heuristics.\n\n batch_size : int, default=1024\n Size of the mini batches.\n For faster compuations, you can set the ``batch_size`` greater than\n 256 * number of cores to enable parallelism on all cores.\n\n .. versionchanged:: 1.0\n `batch_size` default changed from 100 to 1024.\n\n verbose : int, default=0\n Verbosity mode.\n\n compute_labels : bool, default=True\n Compute label assignment and inertia for the complete dataset\n once the minibatch optimization has converged in fit.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation for centroid initialization and\n random reassignment. Use an int to make the randomness deterministic.\n See :term:`Glossary `.\n\n tol : float, default=0.0\n Control early stopping based on the relative center changes as\n measured by a smoothed, variance-normalized of the mean center\n squared position changes. This early stopping heuristics is\n closer to the one used for the batch variant of the algorithms\n but induces a slight computational and memory overhead over the\n inertia heuristic.\n\n To disable convergence detection based on normalized center\n change, set tol to 0.0 (default).\n\n max_no_improvement : int, default=10\n Control early stopping based on the consecutive number of mini\n batches that does not yield an improvement on the smoothed inertia.\n\n To disable convergence detection based on inertia, set\n max_no_improvement to None.\n\n init_size : int, default=None\n Number of samples to randomly sample for speeding up the\n initialization (sometimes at the expense of accuracy): the\n only algorithm is initialized by running a batch KMeans on a\n random subset of the data. This needs to be larger than n_clusters.\n\n If `None`, the heuristic is `init_size = 3 * batch_size` if\n `3 * batch_size < n_clusters`, else `init_size = 3 * n_clusters`.\n\n n_init : int, default=3\n Number of random initializations that are tried.\n In contrast to KMeans, the algorithm is only run once, using the\n best of the ``n_init`` initializations as measured by inertia.\n\n reassignment_ratio : float, default=0.01\n Control the fraction of the maximum number of counts for a center to\n be reassigned. A higher value means that low count centers are more\n easily reassigned, which means that the model will take longer to\n converge, but should converge in a better clustering. However, too high\n a value may cause convergence issues, especially with a small batch\n size.\n\n Attributes\n ----------\n\n cluster_centers_ : ndarray of shape (n_clusters, n_features)\n Coordinates of cluster centers.\n\n labels_ : ndarray of shape (n_samples,)\n Labels of each point (if compute_labels is set to True).\n\n inertia_ : float\n The value of the inertia criterion associated with the chosen\n partition if compute_labels is set to True. If compute_labels is set to\n False, it's an approximation of the inertia based on an exponentially\n weighted average of the batch inertiae.\n The inertia is defined as the sum of square distances of samples to\n their cluster center, weighted by the sample weights if provided.\n\n n_iter_ : int\n Number of iterations over the full dataset.\n\n n_steps_ : int\n Number of minibatches processed.\n\n .. versionadded:: 1.0\n\n counts_ : ndarray of shape (n_clusters,)\n Weight sum of each cluster.\n\n .. deprecated:: 0.24\n This attribute is deprecated in 0.24 and will be removed in\n 1.1 (renaming of 0.26).\n\n init_size_ : int\n The effective number of samples used for the initialization.\n\n .. deprecated:: 0.24\n This attribute is deprecated in 0.24 and will be removed in\n 1.1 (renaming of 0.26).\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n KMeans : The classic implementation of the clustering method based on the\n Lloyd's algorithm. It consumes the whole set of input data at each\n iteration.\n\n Notes\n -----\n See https://www.eecs.tufts.edu/~dsculley/papers/fastkmeans.pdf\n\n Examples\n --------\n >>> from sklearn.cluster import MiniBatchKMeans\n >>> import numpy as np\n >>> X = np.array([[1, 2], [1, 4], [1, 0],\n ... [4, 2], [4, 0], [4, 4],\n ... [4, 5], [0, 1], [2, 2],\n ... [3, 2], [5, 5], [1, -1]])\n >>> # manually fit on batches\n >>> kmeans = MiniBatchKMeans(n_clusters=2,\n ... random_state=0,\n ... batch_size=6)\n >>> kmeans = kmeans.partial_fit(X[0:6,:])\n >>> kmeans = kmeans.partial_fit(X[6:12,:])\n >>> kmeans.cluster_centers_\n array([[2. , 1. ],\n [3.5, 4.5]])\n >>> kmeans.predict([[0, 0], [4, 4]])\n array([0, 1], dtype=int32)\n >>> # fit on the whole data\n >>> kmeans = MiniBatchKMeans(n_clusters=2,\n ... random_state=0,\n ... batch_size=6,\n ... max_iter=10).fit(X)\n >>> kmeans.cluster_centers_\n array([[1.19..., 1.22...],\n [4.03..., 2.46...]])\n >>> kmeans.predict([[0, 0], [4, 4]])\n array([0, 1], dtype=int32)\n \"\"\"\n \n def __init__(self, n_clusters=8, *, init='k-means++', max_iter=100, batch_size=1024, verbose=0, compute_labels=True, random_state=None, tol=0.0, max_no_improvement=10, init_size=None, n_init=3, reassignment_ratio=0.01):\n super().__init__(n_clusters=n_clusters, init=init, max_iter=max_iter, verbose=verbose, random_state=random_state, tol=tol, n_init=n_init)\n self.max_no_improvement = max_no_improvement\n self.batch_size = batch_size\n self.compute_labels = compute_labels\n self.init_size = init_size\n self.reassignment_ratio = reassignment_ratio\n \n @deprecated('The attribute `counts_` is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def counts_(self):\n return self._counts\n \n @deprecated('The attribute `init_size_` is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def init_size_(self):\n return self._init_size\n \n @deprecated('The attribute `random_state_` is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def random_state_(self):\n return getattr(self, '_random_state', None)\n \n def _check_params(self, X):\n super()._check_params(X)\n if self.max_no_improvement is not None and self.max_no_improvement < 0:\n raise ValueError(f'max_no_improvement should be >= 0, got {self.max_no_improvement} instead.')\n if self.batch_size <= 0:\n raise ValueError(f'batch_size should be > 0, got {self.batch_size} instead.')\n self._batch_size = min(self.batch_size, X.shape[0])\n if self.init_size is not None and self.init_size <= 0:\n raise ValueError(f'init_size should be > 0, got {self.init_size} instead.')\n self._init_size = self.init_size\n if self._init_size is None:\n self._init_size = 3 * self._batch_size\n if self._init_size < self.n_clusters:\n self._init_size = 3 * self.n_clusters\n elif self._init_size < self.n_clusters:\n warnings.warn(f'init_size={self._init_size} should be larger than n_clusters={self.n_clusters}. Setting it to min(3*n_clusters, n_samples)', RuntimeWarning, stacklevel=2)\n self._init_size = 3 * self.n_clusters\n self._init_size = min(self._init_size, X.shape[0])\n if self.reassignment_ratio < 0:\n raise ValueError(f'reassignment_ratio should be >= 0, got {self.reassignment_ratio} instead.')\n \n def _mini_batch_convergence(self, step, n_steps, n_samples, centers_squared_diff, batch_inertia):\n \"\"\"Helper function to encapsulate the early stopping logic\"\"\"\n batch_inertia /= self._batch_size\n step = step + 1\n if step == 1:\n if self.verbose:\n print(f'Minibatch step {step}/{n_steps}: mean batch inertia: {batch_inertia}')\n return False\n if self._ewa_inertia is None:\n self._ewa_inertia = batch_inertia\n else:\n alpha = self._batch_size * 2.0 / (n_samples + 1)\n alpha = min(alpha, 1)\n self._ewa_inertia = self._ewa_inertia * (1 - alpha) + batch_inertia * alpha\n if self.verbose:\n print(f'Minibatch step {step}/{n_steps}: mean batch inertia: {batch_inertia}, ewa inertia: {self._ewa_inertia}')\n if self._tol > 0.0 and centers_squared_diff <= self._tol:\n if self.verbose:\n print(f'Converged (small centers change) at step {step}/{n_steps}')\n return True\n if self._ewa_inertia_min is None or self._ewa_inertia < self._ewa_inertia_min:\n self._no_improvement = 0\n self._ewa_inertia_min = self._ewa_inertia\n else:\n self._no_improvement += 1\n if self.max_no_improvement is not None and self._no_improvement >= self.max_no_improvement:\n if self.verbose:\n print(f'Converged (lack of improvement in inertia) at step {step}/{n_steps}')\n return True\n return False\n \n def _random_reassign(self):\n \"\"\"Check if a random reassignment needs to be done.\n\n Do random reassignments each time 10 * n_clusters samples have been\n processed.\n\n If there are empty clusters we always want to reassign.\n \"\"\"\n self._n_since_last_reassign += self._batch_size\n if (self._counts == 0).any() or self._n_since_last_reassign >= 10 * self.n_clusters:\n self._n_since_last_reassign = 0\n return True\n return False\n \n def fit(self, X, y=None, sample_weight=None):\n \"\"\"Compute the centroids on X by chunking it into mini-batches.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training instances to cluster. It must be noted that the data\n will be converted to C ordering, which will cause a memory copy\n if the given data is not C-contiguous.\n If a sparse matrix is passed, a copy will be made if it's not in\n CSR format.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n .. versionadded:: 0.20\n\n Returns\n -------\n self\n \"\"\"\n X = self._validate_data(X, accept_sparse='csr', dtype=[np.float64, np.float32], order='C', accept_large_sparse=False)\n self._check_params(X)\n random_state = check_random_state(self.random_state)\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n self._n_threads = _openmp_effective_n_threads()\n (n_samples, n_features) = X.shape\n init = self.init\n if hasattr(init, '__array__'):\n init = check_array(init, dtype=X.dtype, copy=True, order='C')\n self._validate_center_shape(X, init)\n self._check_mkl_vcomp(X, self._batch_size)\n x_squared_norms = row_norms(X, squared=True)\n validation_indices = random_state.randint(0, n_samples, self._init_size)\n X_valid = X[validation_indices]\n sample_weight_valid = sample_weight[validation_indices]\n x_squared_norms_valid = x_squared_norms[validation_indices]\n best_inertia = None\n for init_idx in range(self._n_init):\n if self.verbose:\n print(f'Init {init_idx + 1}/{self._n_init} with method {init}')\n cluster_centers = self._init_centroids(X, x_squared_norms=x_squared_norms, init=init, random_state=random_state, init_size=self._init_size)\n (_, inertia) = _labels_inertia_threadpool_limit(X_valid, sample_weight_valid, x_squared_norms_valid, cluster_centers, n_threads=self._n_threads)\n if self.verbose:\n print(f'Inertia for init {init_idx + 1}/{self._n_init}: {inertia}')\n if best_inertia is None or inertia < best_inertia:\n init_centers = cluster_centers\n best_inertia = inertia\n centers = init_centers\n centers_new = np.empty_like(centers)\n self._counts = np.zeros(self.n_clusters, dtype=X.dtype)\n self._ewa_inertia = None\n self._ewa_inertia_min = None\n self._no_improvement = 0\n self._n_since_last_reassign = 0\n n_steps = self.max_iter * n_samples // self._batch_size\n with threadpool_limits(limits=1, user_api='blas'):\n for i in range(n_steps):\n minibatch_indices = random_state.randint(0, n_samples, self._batch_size)\n batch_inertia = _mini_batch_step(X=X[minibatch_indices], x_squared_norms=x_squared_norms[minibatch_indices], sample_weight=sample_weight[minibatch_indices], centers=centers, centers_new=centers_new, weight_sums=self._counts, random_state=random_state, random_reassign=self._random_reassign(), reassignment_ratio=self.reassignment_ratio, verbose=self.verbose, n_threads=self._n_threads)\n if self._tol > 0.0:\n centers_squared_diff = np.sum((centers_new - centers)**2)\n else:\n centers_squared_diff = 0\n (centers, centers_new) = (centers_new, centers)\n if self._mini_batch_convergence(i, n_steps, n_samples, centers_squared_diff, batch_inertia):\n break\n self.cluster_centers_ = centers\n self.n_steps_ = i + 1\n self.n_iter_ = int(np.ceil((i + 1) * self._batch_size / n_samples))\n if self.compute_labels:\n (self.labels_, self.inertia_) = _labels_inertia_threadpool_limit(X, sample_weight, x_squared_norms, self.cluster_centers_, n_threads=self._n_threads)\n else:\n self.inertia_ = self._ewa_inertia * n_samples\n return self\n \n def partial_fit(self, X, y=None, sample_weight=None):\n \"\"\"Update k means estimate on a single mini-batch X.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training instances to cluster. It must be noted that the data\n will be converted to C ordering, which will cause a memory copy\n if the given data is not C-contiguous.\n If a sparse matrix is passed, a copy will be made if it's not in\n CSR format.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n Returns\n -------\n self\n \"\"\"\n has_centers = hasattr(self, 'cluster_centers_')\n X = self._validate_data(X, accept_sparse='csr', dtype=[np.float64, np.float32], order='C', accept_large_sparse=False, reset=not has_centers)\n self._random_state = getattr(self, '_random_state', check_random_state(self.random_state))\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n self.n_steps_ = getattr(self, 'n_steps_', 0)\n x_squared_norms = row_norms(X, squared=True)\n if not has_centers:\n self._check_params(X)\n self._n_threads = _openmp_effective_n_threads()\n init = self.init\n if hasattr(init, '__array__'):\n init = check_array(init, dtype=X.dtype, copy=True, order='C')\n self._validate_center_shape(X, init)\n self._check_mkl_vcomp(X, X.shape[0])\n self.cluster_centers_ = self._init_centroids(X, x_squared_norms=x_squared_norms, init=init, random_state=self._random_state, init_size=self._init_size)\n self._counts = np.zeros(self.n_clusters, dtype=X.dtype)\n self._n_since_last_reassign = 0\n with threadpool_limits(limits=1, user_api='blas'):\n _mini_batch_step(X, x_squared_norms=x_squared_norms, sample_weight=sample_weight, centers=self.cluster_centers_, centers_new=self.cluster_centers_, weight_sums=self._counts, random_state=self._random_state, random_reassign=self._random_reassign(), reassignment_ratio=self.reassignment_ratio, verbose=self.verbose, n_threads=self._n_threads)\n if self.compute_labels:\n (self.labels_, self.inertia_) = _labels_inertia_threadpool_limit(X, sample_weight, x_squared_norms, self.cluster_centers_, n_threads=self._n_threads)\n self.n_steps_ += 1\n return self\n \n def predict(self, X, sample_weight=None):\n \"\"\"Predict the closest cluster each sample in X belongs to.\n\n In the vector quantization literature, `cluster_centers_` is called\n the code book and each value returned by `predict` is the index of\n the closest code in the code book.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n New data to predict.\n\n sample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n Returns\n -------\n labels : ndarray of shape (n_samples,)\n Index of the cluster each sample belongs to.\n \"\"\"\n check_is_fitted(self)\n X = self._check_test_data(X)\n x_squared_norms = row_norms(X, squared=True)\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n (labels, _) = _labels_inertia_threadpool_limit(X, sample_weight, x_squared_norms, self.cluster_centers_, n_threads=self._n_threads)\n return labels\n \n def _more_tags(self):\n return {'_xfail_checks': {'check_sample_weights_invariance': 'zero sample_weight is not equivalent to removing samples'}}\n" + "source_code": "\n\nclass MiniBatchKMeans(KMeans):\n \"\"\"\n Mini-Batch K-Means clustering.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n\n n_clusters : int, default=8\n The number of clusters to form as well as the number of\n centroids to generate.\n\n init : {'k-means++', 'random'}, callable or array-like of shape (n_clusters, n_features), default='k-means++'\n Method for initialization:\n\n 'k-means++' : selects initial cluster centers for k-mean\n clustering in a smart way to speed up convergence. See section\n Notes in k_init for more details.\n\n 'random': choose `n_clusters` observations (rows) at random from data\n for the initial centroids.\n\n If an array is passed, it should be of shape (n_clusters, n_features)\n and gives the initial centers.\n\n If a callable is passed, it should take arguments X, n_clusters and a\n random state and return an initialization.\n\n max_iter : int, default=100\n Maximum number of iterations over the complete dataset before\n stopping independently of any early stopping criterion heuristics.\n\n batch_size : int, default=1024\n Size of the mini batches.\n For faster compuations, you can set the ``batch_size`` greater than\n 256 * number of cores to enable parallelism on all cores.\n\n .. versionchanged:: 1.0\n `batch_size` default changed from 100 to 1024.\n\n verbose : int, default=0\n Verbosity mode.\n\n compute_labels : bool, default=True\n Compute label assignment and inertia for the complete dataset\n once the minibatch optimization has converged in fit.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation for centroid initialization and\n random reassignment. Use an int to make the randomness deterministic.\n See :term:`Glossary `.\n\n tol : float, default=0.0\n Control early stopping based on the relative center changes as\n measured by a smoothed, variance-normalized of the mean center\n squared position changes. This early stopping heuristics is\n closer to the one used for the batch variant of the algorithms\n but induces a slight computational and memory overhead over the\n inertia heuristic.\n\n To disable convergence detection based on normalized center\n change, set tol to 0.0 (default).\n\n max_no_improvement : int, default=10\n Control early stopping based on the consecutive number of mini\n batches that does not yield an improvement on the smoothed inertia.\n\n To disable convergence detection based on inertia, set\n max_no_improvement to None.\n\n init_size : int, default=None\n Number of samples to randomly sample for speeding up the\n initialization (sometimes at the expense of accuracy): the\n only algorithm is initialized by running a batch KMeans on a\n random subset of the data. This needs to be larger than n_clusters.\n\n If `None`, the heuristic is `init_size = 3 * batch_size` if\n `3 * batch_size < n_clusters`, else `init_size = 3 * n_clusters`.\n\n n_init : int, default=3\n Number of random initializations that are tried.\n In contrast to KMeans, the algorithm is only run once, using the\n best of the ``n_init`` initializations as measured by inertia.\n\n reassignment_ratio : float, default=0.01\n Control the fraction of the maximum number of counts for a center to\n be reassigned. A higher value means that low count centers are more\n easily reassigned, which means that the model will take longer to\n converge, but should converge in a better clustering. However, too high\n a value may cause convergence issues, especially with a small batch\n size.\n\n Attributes\n ----------\n\n cluster_centers_ : ndarray of shape (n_clusters, n_features)\n Coordinates of cluster centers.\n\n labels_ : ndarray of shape (n_samples,)\n Labels of each point (if compute_labels is set to True).\n\n inertia_ : float\n The value of the inertia criterion associated with the chosen\n partition if compute_labels is set to True. If compute_labels is set to\n False, it's an approximation of the inertia based on an exponentially\n weighted average of the batch inertiae.\n The inertia is defined as the sum of square distances of samples to\n their cluster center, weighted by the sample weights if provided.\n\n n_iter_ : int\n Number of iterations over the full dataset.\n\n n_steps_ : int\n Number of minibatches processed.\n\n .. versionadded:: 1.0\n\n counts_ : ndarray of shape (n_clusters,)\n Weight sum of each cluster.\n\n .. deprecated:: 0.24\n This attribute is deprecated in 0.24 and will be removed in\n 1.1 (renaming of 0.26).\n\n init_size_ : int\n The effective number of samples used for the initialization.\n\n .. deprecated:: 0.24\n This attribute is deprecated in 0.24 and will be removed in\n 1.1 (renaming of 0.26).\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n KMeans : The classic implementation of the clustering method based on the\n Lloyd's algorithm. It consumes the whole set of input data at each\n iteration.\n\n Notes\n -----\n See https://www.eecs.tufts.edu/~dsculley/papers/fastkmeans.pdf\n\n Examples\n --------\n >>> from sklearn.cluster import MiniBatchKMeans\n >>> import numpy as np\n >>> X = np.array([[1, 2], [1, 4], [1, 0],\n ... [4, 2], [4, 0], [4, 4],\n ... [4, 5], [0, 1], [2, 2],\n ... [3, 2], [5, 5], [1, -1]])\n >>> # manually fit on batches\n >>> kmeans = MiniBatchKMeans(n_clusters=2,\n ... random_state=0,\n ... batch_size=6)\n >>> kmeans = kmeans.partial_fit(X[0:6,:])\n >>> kmeans = kmeans.partial_fit(X[6:12,:])\n >>> kmeans.cluster_centers_\n array([[2. , 1. ],\n [3.5, 4.5]])\n >>> kmeans.predict([[0, 0], [4, 4]])\n array([0, 1], dtype=int32)\n >>> # fit on the whole data\n >>> kmeans = MiniBatchKMeans(n_clusters=2,\n ... random_state=0,\n ... batch_size=6,\n ... max_iter=10).fit(X)\n >>> kmeans.cluster_centers_\n array([[1.19..., 1.22...],\n [4.03..., 2.46...]])\n >>> kmeans.predict([[0, 0], [4, 4]])\n array([0, 1], dtype=int32)\n \"\"\"\n \n def __init__(self, n_clusters=8, *, init='k-means++', max_iter=100, batch_size=1024, verbose=0, compute_labels=True, random_state=None, tol=0.0, max_no_improvement=10, init_size=None, n_init=3, reassignment_ratio=0.01):\n super().__init__(n_clusters=n_clusters, init=init, max_iter=max_iter, verbose=verbose, random_state=random_state, tol=tol, n_init=n_init)\n self.max_no_improvement = max_no_improvement\n self.batch_size = batch_size\n self.compute_labels = compute_labels\n self.init_size = init_size\n self.reassignment_ratio = reassignment_ratio\n \n @deprecated('The attribute `counts_` is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def counts_(self):\n return self._counts\n \n @deprecated('The attribute `init_size_` is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def init_size_(self):\n return self._init_size\n \n @deprecated('The attribute `random_state_` is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def random_state_(self):\n return getattr(self, '_random_state', None)\n \n def _check_params(self, X):\n super()._check_params(X)\n if self.max_no_improvement is not None and self.max_no_improvement < 0:\n raise ValueError(f'max_no_improvement should be >= 0, got {self.max_no_improvement} instead.')\n if self.batch_size <= 0:\n raise ValueError(f'batch_size should be > 0, got {self.batch_size} instead.')\n self._batch_size = min(self.batch_size, X.shape[0])\n if self.init_size is not None and self.init_size <= 0:\n raise ValueError(f'init_size should be > 0, got {self.init_size} instead.')\n self._init_size = self.init_size\n if self._init_size is None:\n self._init_size = 3 * self._batch_size\n if self._init_size < self.n_clusters:\n self._init_size = 3 * self.n_clusters\n elif self._init_size < self.n_clusters:\n warnings.warn(f'init_size={self._init_size} should be larger than n_clusters={self.n_clusters}. Setting it to min(3*n_clusters, n_samples)', RuntimeWarning, stacklevel=2)\n self._init_size = 3 * self.n_clusters\n self._init_size = min(self._init_size, X.shape[0])\n if self.reassignment_ratio < 0:\n raise ValueError(f'reassignment_ratio should be >= 0, got {self.reassignment_ratio} instead.')\n \n def _mini_batch_convergence(self, step, n_steps, n_samples, centers_squared_diff, batch_inertia):\n \"\"\"Helper function to encapsulate the early stopping logic\"\"\"\n batch_inertia /= self._batch_size\n step = step + 1\n if step == 1:\n if self.verbose:\n print(f'Minibatch step {step}/{n_steps}: mean batch inertia: {batch_inertia}')\n return False\n if self._ewa_inertia is None:\n self._ewa_inertia = batch_inertia\n else:\n alpha = self._batch_size * 2.0 / (n_samples + 1)\n alpha = min(alpha, 1)\n self._ewa_inertia = self._ewa_inertia * (1 - alpha) + batch_inertia * alpha\n if self.verbose:\n print(f'Minibatch step {step}/{n_steps}: mean batch inertia: {batch_inertia}, ewa inertia: {self._ewa_inertia}')\n if self._tol > 0.0 and centers_squared_diff <= self._tol:\n if self.verbose:\n print(f'Converged (small centers change) at step {step}/{n_steps}')\n return True\n if self._ewa_inertia_min is None or self._ewa_inertia < self._ewa_inertia_min:\n self._no_improvement = 0\n self._ewa_inertia_min = self._ewa_inertia\n else:\n self._no_improvement += 1\n if self.max_no_improvement is not None and self._no_improvement >= self.max_no_improvement:\n if self.verbose:\n print(f'Converged (lack of improvement in inertia) at step {step}/{n_steps}')\n return True\n return False\n \n def _random_reassign(self):\n \"\"\"Check if a random reassignment needs to be done.\n\n Do random reassignments each time 10 * n_clusters samples have been\n processed.\n\n If there are empty clusters we always want to reassign.\n \"\"\"\n self._n_since_last_reassign += self._batch_size\n if (self._counts == 0).any() or self._n_since_last_reassign >= 10 * self.n_clusters:\n self._n_since_last_reassign = 0\n return True\n return False\n \n def fit(self, X, y=None, sample_weight=None):\n \"\"\"Compute the centroids on X by chunking it into mini-batches.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training instances to cluster. It must be noted that the data\n will be converted to C ordering, which will cause a memory copy\n if the given data is not C-contiguous.\n If a sparse matrix is passed, a copy will be made if it's not in\n CSR format.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n .. versionadded:: 0.20\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n X = self._validate_data(X, accept_sparse='csr', dtype=[np.float64, np.float32], order='C', accept_large_sparse=False)\n self._check_params(X)\n random_state = check_random_state(self.random_state)\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n self._n_threads = _openmp_effective_n_threads()\n (n_samples, n_features) = X.shape\n init = self.init\n if hasattr(init, '__array__'):\n init = check_array(init, dtype=X.dtype, copy=True, order='C')\n self._validate_center_shape(X, init)\n self._check_mkl_vcomp(X, self._batch_size)\n x_squared_norms = row_norms(X, squared=True)\n validation_indices = random_state.randint(0, n_samples, self._init_size)\n X_valid = X[validation_indices]\n sample_weight_valid = sample_weight[validation_indices]\n x_squared_norms_valid = x_squared_norms[validation_indices]\n best_inertia = None\n for init_idx in range(self._n_init):\n if self.verbose:\n print(f'Init {init_idx + 1}/{self._n_init} with method {init}')\n cluster_centers = self._init_centroids(X, x_squared_norms=x_squared_norms, init=init, random_state=random_state, init_size=self._init_size)\n (_, inertia) = _labels_inertia_threadpool_limit(X_valid, sample_weight_valid, x_squared_norms_valid, cluster_centers, n_threads=self._n_threads)\n if self.verbose:\n print(f'Inertia for init {init_idx + 1}/{self._n_init}: {inertia}')\n if best_inertia is None or inertia < best_inertia:\n init_centers = cluster_centers\n best_inertia = inertia\n centers = init_centers\n centers_new = np.empty_like(centers)\n self._counts = np.zeros(self.n_clusters, dtype=X.dtype)\n self._ewa_inertia = None\n self._ewa_inertia_min = None\n self._no_improvement = 0\n self._n_since_last_reassign = 0\n n_steps = self.max_iter * n_samples // self._batch_size\n with threadpool_limits(limits=1, user_api='blas'):\n for i in range(n_steps):\n minibatch_indices = random_state.randint(0, n_samples, self._batch_size)\n batch_inertia = _mini_batch_step(X=X[minibatch_indices], x_squared_norms=x_squared_norms[minibatch_indices], sample_weight=sample_weight[minibatch_indices], centers=centers, centers_new=centers_new, weight_sums=self._counts, random_state=random_state, random_reassign=self._random_reassign(), reassignment_ratio=self.reassignment_ratio, verbose=self.verbose, n_threads=self._n_threads)\n if self._tol > 0.0:\n centers_squared_diff = np.sum((centers_new - centers)**2)\n else:\n centers_squared_diff = 0\n (centers, centers_new) = (centers_new, centers)\n if self._mini_batch_convergence(i, n_steps, n_samples, centers_squared_diff, batch_inertia):\n break\n self.cluster_centers_ = centers\n self.n_steps_ = i + 1\n self.n_iter_ = int(np.ceil((i + 1) * self._batch_size / n_samples))\n if self.compute_labels:\n (self.labels_, self.inertia_) = _labels_inertia_threadpool_limit(X, sample_weight, x_squared_norms, self.cluster_centers_, n_threads=self._n_threads)\n else:\n self.inertia_ = self._ewa_inertia * n_samples\n return self\n \n def partial_fit(self, X, y=None, sample_weight=None):\n \"\"\"Update k means estimate on a single mini-batch X.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training instances to cluster. It must be noted that the data\n will be converted to C ordering, which will cause a memory copy\n if the given data is not C-contiguous.\n If a sparse matrix is passed, a copy will be made if it's not in\n CSR format.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n Returns\n -------\n self : object\n Return updated estimator.\n \"\"\"\n has_centers = hasattr(self, 'cluster_centers_')\n X = self._validate_data(X, accept_sparse='csr', dtype=[np.float64, np.float32], order='C', accept_large_sparse=False, reset=not has_centers)\n self._random_state = getattr(self, '_random_state', check_random_state(self.random_state))\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n self.n_steps_ = getattr(self, 'n_steps_', 0)\n x_squared_norms = row_norms(X, squared=True)\n if not has_centers:\n self._check_params(X)\n self._n_threads = _openmp_effective_n_threads()\n init = self.init\n if hasattr(init, '__array__'):\n init = check_array(init, dtype=X.dtype, copy=True, order='C')\n self._validate_center_shape(X, init)\n self._check_mkl_vcomp(X, X.shape[0])\n self.cluster_centers_ = self._init_centroids(X, x_squared_norms=x_squared_norms, init=init, random_state=self._random_state, init_size=self._init_size)\n self._counts = np.zeros(self.n_clusters, dtype=X.dtype)\n self._n_since_last_reassign = 0\n with threadpool_limits(limits=1, user_api='blas'):\n _mini_batch_step(X, x_squared_norms=x_squared_norms, sample_weight=sample_weight, centers=self.cluster_centers_, centers_new=self.cluster_centers_, weight_sums=self._counts, random_state=self._random_state, random_reassign=self._random_reassign(), reassignment_ratio=self.reassignment_ratio, verbose=self.verbose, n_threads=self._n_threads)\n if self.compute_labels:\n (self.labels_, self.inertia_) = _labels_inertia_threadpool_limit(X, sample_weight, x_squared_norms, self.cluster_centers_, n_threads=self._n_threads)\n self.n_steps_ += 1\n return self\n \n def predict(self, X, sample_weight=None):\n \"\"\"Predict the closest cluster each sample in X belongs to.\n\n In the vector quantization literature, `cluster_centers_` is called\n the code book and each value returned by `predict` is the index of\n the closest code in the code book.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n New data to predict.\n\n sample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n Returns\n -------\n labels : ndarray of shape (n_samples,)\n Index of the cluster each sample belongs to.\n \"\"\"\n check_is_fitted(self)\n X = self._check_test_data(X)\n x_squared_norms = row_norms(X, squared=True)\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n (labels, _) = _labels_inertia_threadpool_limit(X, sample_weight, x_squared_norms, self.cluster_centers_, n_threads=self._n_threads)\n return labels\n \n def _more_tags(self):\n return {'_xfail_checks': {'check_sample_weights_invariance': 'zero sample_weight is not equivalent to removing samples'}}\n" }, { "name": "MeanShift", @@ -20115,7 +20082,7 @@ "is_public": true, "description": "Mean shift clustering using a flat kernel.\n\nMean shift clustering aims to discover \"blobs\" in a smooth density of samples. It is a centroid-based algorithm, which works by updating candidates for centroids to be the mean of the points within a given region. These candidates are then filtered in a post-processing stage to eliminate near-duplicates to form the final set of centroids. Seeding is performed using a binning technique for scalability. Read more in the :ref:`User Guide `.", "docstring": "Mean shift clustering using a flat kernel.\n\n Mean shift clustering aims to discover \"blobs\" in a smooth density of\n samples. It is a centroid-based algorithm, which works by updating\n candidates for centroids to be the mean of the points within a given\n region. These candidates are then filtered in a post-processing stage to\n eliminate near-duplicates to form the final set of centroids.\n\n Seeding is performed using a binning technique for scalability.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n bandwidth : float, default=None\n Bandwidth used in the RBF kernel.\n\n If not given, the bandwidth is estimated using\n sklearn.cluster.estimate_bandwidth; see the documentation for that\n function for hints on scalability (see also the Notes, below).\n\n seeds : array-like of shape (n_samples, n_features), default=None\n Seeds used to initialize kernels. If not set,\n the seeds are calculated by clustering.get_bin_seeds\n with bandwidth as the grid size and default values for\n other parameters.\n\n bin_seeding : bool, default=False\n If true, initial kernel locations are not locations of all\n points, but rather the location of the discretized version of\n points, where points are binned onto a grid whose coarseness\n corresponds to the bandwidth. Setting this option to True will speed\n up the algorithm because fewer seeds will be initialized.\n The default value is False.\n Ignored if seeds argument is not None.\n\n min_bin_freq : int, default=1\n To speed up the algorithm, accept only those bins with at least\n min_bin_freq points as seeds.\n\n cluster_all : bool, default=True\n If true, then all points are clustered, even those orphans that are\n not within any kernel. Orphans are assigned to the nearest kernel.\n If false, then orphans are given cluster label -1.\n\n n_jobs : int, default=None\n The number of jobs to use for the computation. This works by computing\n each of the n_init runs in parallel.\n\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n max_iter : int, default=300\n Maximum number of iterations, per seed point before the clustering\n operation terminates (for that seed point), if has not converged yet.\n\n .. versionadded:: 0.22\n\n Attributes\n ----------\n cluster_centers_ : ndarray of shape (n_clusters, n_features)\n Coordinates of cluster centers.\n\n labels_ : ndarray of shape (n_samples,)\n Labels of each point.\n\n n_iter_ : int\n Maximum number of iterations performed on each seed.\n\n .. versionadded:: 0.22\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n KMeans : K-Means clustering.\n\n Notes\n -----\n\n Scalability:\n\n Because this implementation uses a flat kernel and\n a Ball Tree to look up members of each kernel, the complexity will tend\n towards O(T*n*log(n)) in lower dimensions, with n the number of samples\n and T the number of points. In higher dimensions the complexity will\n tend towards O(T*n^2).\n\n Scalability can be boosted by using fewer seeds, for example by using\n a higher value of min_bin_freq in the get_bin_seeds function.\n\n Note that the estimate_bandwidth function is much less scalable than the\n mean shift algorithm and will be the bottleneck if it is used.\n\n References\n ----------\n\n Dorin Comaniciu and Peter Meer, \"Mean Shift: A robust approach toward\n feature space analysis\". IEEE Transactions on Pattern Analysis and\n Machine Intelligence. 2002. pp. 603-619.\n\n Examples\n --------\n >>> from sklearn.cluster import MeanShift\n >>> import numpy as np\n >>> X = np.array([[1, 1], [2, 1], [1, 0],\n ... [4, 7], [3, 5], [3, 6]])\n >>> clustering = MeanShift(bandwidth=2).fit(X)\n >>> clustering.labels_\n array([1, 1, 1, 0, 0, 0])\n >>> clustering.predict([[0, 0], [5, 5]])\n array([1, 0])\n >>> clustering\n MeanShift(bandwidth=2)\n ", - "source_code": "\n\nclass MeanShift(ClusterMixin, BaseEstimator):\n \"\"\"Mean shift clustering using a flat kernel.\n\n Mean shift clustering aims to discover \"blobs\" in a smooth density of\n samples. It is a centroid-based algorithm, which works by updating\n candidates for centroids to be the mean of the points within a given\n region. These candidates are then filtered in a post-processing stage to\n eliminate near-duplicates to form the final set of centroids.\n\n Seeding is performed using a binning technique for scalability.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n bandwidth : float, default=None\n Bandwidth used in the RBF kernel.\n\n If not given, the bandwidth is estimated using\n sklearn.cluster.estimate_bandwidth; see the documentation for that\n function for hints on scalability (see also the Notes, below).\n\n seeds : array-like of shape (n_samples, n_features), default=None\n Seeds used to initialize kernels. If not set,\n the seeds are calculated by clustering.get_bin_seeds\n with bandwidth as the grid size and default values for\n other parameters.\n\n bin_seeding : bool, default=False\n If true, initial kernel locations are not locations of all\n points, but rather the location of the discretized version of\n points, where points are binned onto a grid whose coarseness\n corresponds to the bandwidth. Setting this option to True will speed\n up the algorithm because fewer seeds will be initialized.\n The default value is False.\n Ignored if seeds argument is not None.\n\n min_bin_freq : int, default=1\n To speed up the algorithm, accept only those bins with at least\n min_bin_freq points as seeds.\n\n cluster_all : bool, default=True\n If true, then all points are clustered, even those orphans that are\n not within any kernel. Orphans are assigned to the nearest kernel.\n If false, then orphans are given cluster label -1.\n\n n_jobs : int, default=None\n The number of jobs to use for the computation. This works by computing\n each of the n_init runs in parallel.\n\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n max_iter : int, default=300\n Maximum number of iterations, per seed point before the clustering\n operation terminates (for that seed point), if has not converged yet.\n\n .. versionadded:: 0.22\n\n Attributes\n ----------\n cluster_centers_ : ndarray of shape (n_clusters, n_features)\n Coordinates of cluster centers.\n\n labels_ : ndarray of shape (n_samples,)\n Labels of each point.\n\n n_iter_ : int\n Maximum number of iterations performed on each seed.\n\n .. versionadded:: 0.22\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n KMeans : K-Means clustering.\n\n Notes\n -----\n\n Scalability:\n\n Because this implementation uses a flat kernel and\n a Ball Tree to look up members of each kernel, the complexity will tend\n towards O(T*n*log(n)) in lower dimensions, with n the number of samples\n and T the number of points. In higher dimensions the complexity will\n tend towards O(T*n^2).\n\n Scalability can be boosted by using fewer seeds, for example by using\n a higher value of min_bin_freq in the get_bin_seeds function.\n\n Note that the estimate_bandwidth function is much less scalable than the\n mean shift algorithm and will be the bottleneck if it is used.\n\n References\n ----------\n\n Dorin Comaniciu and Peter Meer, \"Mean Shift: A robust approach toward\n feature space analysis\". IEEE Transactions on Pattern Analysis and\n Machine Intelligence. 2002. pp. 603-619.\n\n Examples\n --------\n >>> from sklearn.cluster import MeanShift\n >>> import numpy as np\n >>> X = np.array([[1, 1], [2, 1], [1, 0],\n ... [4, 7], [3, 5], [3, 6]])\n >>> clustering = MeanShift(bandwidth=2).fit(X)\n >>> clustering.labels_\n array([1, 1, 1, 0, 0, 0])\n >>> clustering.predict([[0, 0], [5, 5]])\n array([1, 0])\n >>> clustering\n MeanShift(bandwidth=2)\n \"\"\"\n \n def __init__(self, *, bandwidth=None, seeds=None, bin_seeding=False, min_bin_freq=1, cluster_all=True, n_jobs=None, max_iter=300):\n self.bandwidth = bandwidth\n self.seeds = seeds\n self.bin_seeding = bin_seeding\n self.cluster_all = cluster_all\n self.min_bin_freq = min_bin_freq\n self.n_jobs = n_jobs\n self.max_iter = max_iter\n \n def fit(self, X, y=None):\n \"\"\"Perform clustering.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Samples to cluster.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n self : object\n Fitted instance.\n \"\"\"\n X = self._validate_data(X)\n bandwidth = self.bandwidth\n if bandwidth is None:\n bandwidth = estimate_bandwidth(X, n_jobs=self.n_jobs)\n elif bandwidth <= 0:\n raise ValueError('bandwidth needs to be greater than zero or None, got %f' % bandwidth)\n seeds = self.seeds\n if seeds is None:\n if self.bin_seeding:\n seeds = get_bin_seeds(X, bandwidth, self.min_bin_freq)\n else:\n seeds = X\n (n_samples, n_features) = X.shape\n center_intensity_dict = {}\n nbrs = NearestNeighbors(radius=bandwidth, n_jobs=1).fit(X)\n all_res = Parallel(n_jobs=self.n_jobs)((delayed(_mean_shift_single_seed)(seed, X, nbrs, self.max_iter) for seed in seeds))\n for i in range(len(seeds)):\n if all_res[i][1]:\n center_intensity_dict[all_res[i][0]] = all_res[i][1]\n self.n_iter_ = max([x[2] for x in all_res])\n if not center_intensity_dict:\n raise ValueError('No point was within bandwidth=%f of any seed. Try a different seeding strategy or increase the bandwidth.' % bandwidth)\n sorted_by_intensity = sorted(center_intensity_dict.items(), key=lambda tup: (tup[1], tup[0]), reverse=True)\n sorted_centers = np.array([tup[0] for tup in sorted_by_intensity])\n unique = np.ones(len(sorted_centers), dtype=bool)\n nbrs = NearestNeighbors(radius=bandwidth, n_jobs=self.n_jobs).fit(sorted_centers)\n for (i, center) in enumerate(sorted_centers):\n if unique[i]:\n neighbor_idxs = nbrs.radius_neighbors([center], return_distance=False)[0]\n unique[neighbor_idxs] = 0\n unique[i] = 1\n cluster_centers = sorted_centers[unique]\n nbrs = NearestNeighbors(n_neighbors=1, n_jobs=self.n_jobs).fit(cluster_centers)\n labels = np.zeros(n_samples, dtype=int)\n (distances, idxs) = nbrs.kneighbors(X)\n if self.cluster_all:\n labels = idxs.flatten()\n else:\n labels.fill(-1)\n bool_selector = distances.flatten() <= bandwidth\n labels[bool_selector] = idxs.flatten()[bool_selector]\n (self.cluster_centers_, self.labels_) = (cluster_centers, labels)\n return self\n \n def predict(self, X):\n \"\"\"Predict the closest cluster each sample in X belongs to.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n New data to predict.\n\n Returns\n -------\n labels : ndarray of shape (n_samples,)\n Index of the cluster each sample belongs to.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, reset=False)\n with config_context(assume_finite=True):\n return pairwise_distances_argmin(X, self.cluster_centers_)\n" + "source_code": "\n\nclass MeanShift(ClusterMixin, BaseEstimator):\n \"\"\"Mean shift clustering using a flat kernel.\n\n Mean shift clustering aims to discover \"blobs\" in a smooth density of\n samples. It is a centroid-based algorithm, which works by updating\n candidates for centroids to be the mean of the points within a given\n region. These candidates are then filtered in a post-processing stage to\n eliminate near-duplicates to form the final set of centroids.\n\n Seeding is performed using a binning technique for scalability.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n bandwidth : float, default=None\n Bandwidth used in the RBF kernel.\n\n If not given, the bandwidth is estimated using\n sklearn.cluster.estimate_bandwidth; see the documentation for that\n function for hints on scalability (see also the Notes, below).\n\n seeds : array-like of shape (n_samples, n_features), default=None\n Seeds used to initialize kernels. If not set,\n the seeds are calculated by clustering.get_bin_seeds\n with bandwidth as the grid size and default values for\n other parameters.\n\n bin_seeding : bool, default=False\n If true, initial kernel locations are not locations of all\n points, but rather the location of the discretized version of\n points, where points are binned onto a grid whose coarseness\n corresponds to the bandwidth. Setting this option to True will speed\n up the algorithm because fewer seeds will be initialized.\n The default value is False.\n Ignored if seeds argument is not None.\n\n min_bin_freq : int, default=1\n To speed up the algorithm, accept only those bins with at least\n min_bin_freq points as seeds.\n\n cluster_all : bool, default=True\n If true, then all points are clustered, even those orphans that are\n not within any kernel. Orphans are assigned to the nearest kernel.\n If false, then orphans are given cluster label -1.\n\n n_jobs : int, default=None\n The number of jobs to use for the computation. This works by computing\n each of the n_init runs in parallel.\n\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n max_iter : int, default=300\n Maximum number of iterations, per seed point before the clustering\n operation terminates (for that seed point), if has not converged yet.\n\n .. versionadded:: 0.22\n\n Attributes\n ----------\n cluster_centers_ : ndarray of shape (n_clusters, n_features)\n Coordinates of cluster centers.\n\n labels_ : ndarray of shape (n_samples,)\n Labels of each point.\n\n n_iter_ : int\n Maximum number of iterations performed on each seed.\n\n .. versionadded:: 0.22\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n KMeans : K-Means clustering.\n\n Notes\n -----\n\n Scalability:\n\n Because this implementation uses a flat kernel and\n a Ball Tree to look up members of each kernel, the complexity will tend\n towards O(T*n*log(n)) in lower dimensions, with n the number of samples\n and T the number of points. In higher dimensions the complexity will\n tend towards O(T*n^2).\n\n Scalability can be boosted by using fewer seeds, for example by using\n a higher value of min_bin_freq in the get_bin_seeds function.\n\n Note that the estimate_bandwidth function is much less scalable than the\n mean shift algorithm and will be the bottleneck if it is used.\n\n References\n ----------\n\n Dorin Comaniciu and Peter Meer, \"Mean Shift: A robust approach toward\n feature space analysis\". IEEE Transactions on Pattern Analysis and\n Machine Intelligence. 2002. pp. 603-619.\n\n Examples\n --------\n >>> from sklearn.cluster import MeanShift\n >>> import numpy as np\n >>> X = np.array([[1, 1], [2, 1], [1, 0],\n ... [4, 7], [3, 5], [3, 6]])\n >>> clustering = MeanShift(bandwidth=2).fit(X)\n >>> clustering.labels_\n array([1, 1, 1, 0, 0, 0])\n >>> clustering.predict([[0, 0], [5, 5]])\n array([1, 0])\n >>> clustering\n MeanShift(bandwidth=2)\n \"\"\"\n \n def __init__(self, *, bandwidth=None, seeds=None, bin_seeding=False, min_bin_freq=1, cluster_all=True, n_jobs=None, max_iter=300):\n self.bandwidth = bandwidth\n self.seeds = seeds\n self.bin_seeding = bin_seeding\n self.cluster_all = cluster_all\n self.min_bin_freq = min_bin_freq\n self.n_jobs = n_jobs\n self.max_iter = max_iter\n \n def fit(self, X, y=None):\n \"\"\"Perform clustering.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Samples to cluster.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n self : object\n Fitted instance.\n \"\"\"\n X = self._validate_data(X)\n bandwidth = self.bandwidth\n if bandwidth is None:\n bandwidth = estimate_bandwidth(X, n_jobs=self.n_jobs)\n elif bandwidth <= 0:\n raise ValueError('bandwidth needs to be greater than zero or None, got %f' % bandwidth)\n seeds = self.seeds\n if seeds is None:\n if self.bin_seeding:\n seeds = get_bin_seeds(X, bandwidth, self.min_bin_freq)\n else:\n seeds = X\n (n_samples, n_features) = X.shape\n center_intensity_dict = {}\n nbrs = NearestNeighbors(radius=bandwidth, n_jobs=1).fit(X)\n all_res = Parallel(n_jobs=self.n_jobs)((delayed(_mean_shift_single_seed)(seed, X, nbrs, self.max_iter) for seed in seeds))\n for i in range(len(seeds)):\n if all_res[i][1]:\n center_intensity_dict[all_res[i][0]] = all_res[i][1]\n self.n_iter_ = max([x[2] for x in all_res])\n if not center_intensity_dict:\n raise ValueError('No point was within bandwidth=%f of any seed. Try a different seeding strategy or increase the bandwidth.' % bandwidth)\n sorted_by_intensity = sorted(center_intensity_dict.items(), key=lambda tup: (tup[1], tup[0]), reverse=True)\n sorted_centers = np.array([tup[0] for tup in sorted_by_intensity])\n unique = np.ones(len(sorted_centers), dtype=bool)\n nbrs = NearestNeighbors(radius=bandwidth, n_jobs=self.n_jobs).fit(sorted_centers)\n for (i, center) in enumerate(sorted_centers):\n if unique[i]:\n neighbor_idxs = nbrs.radius_neighbors([center], return_distance=False)[0]\n unique[neighbor_idxs] = 0\n unique[i] = 1\n cluster_centers = sorted_centers[unique]\n nbrs = NearestNeighbors(n_neighbors=1, n_jobs=self.n_jobs).fit(cluster_centers)\n labels = np.zeros(n_samples, dtype=int)\n (distances, idxs) = nbrs.kneighbors(X)\n if self.cluster_all:\n labels = idxs.flatten()\n else:\n labels.fill(-1)\n bool_selector = distances.flatten() <= bandwidth\n labels[bool_selector] = idxs.flatten()[bool_selector]\n (self.cluster_centers_, self.labels_) = (cluster_centers, labels)\n return self\n \n def predict(self, X):\n \"\"\"Predict the closest cluster each sample in X belongs to.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n New data to predict.\n\n Returns\n -------\n labels : ndarray of shape (n_samples,)\n Index of the cluster each sample belongs to.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, reset=False)\n with config_context(assume_finite=True):\n return pairwise_distances_argmin(X, self.cluster_centers_)\n" }, { "name": "OPTICS", @@ -20141,12 +20108,12 @@ "sklearn.cluster._spectral.SpectralClustering.fit", "sklearn.cluster._spectral.SpectralClustering.fit_predict", "sklearn.cluster._spectral.SpectralClustering._more_tags", - "sklearn.cluster._spectral.SpectralClustering._pairwise" + "sklearn.cluster._spectral.SpectralClustering._pairwise@getter" ], "is_public": true, - "description": "Apply clustering to a projection of the normalized Laplacian.\n\nIn practice Spectral Clustering is very useful when the structure of the individual clusters is highly non-convex, or more generally when a measure of the center and spread of the cluster is not a suitable description of the complete cluster, such as when clusters are nested circles on the 2D plane. If the affinity matrix is the adjacency matrix of a graph, this method can be used to find normalized graph cuts. When calling ``fit``, an affinity matrix is constructed using either a kernel function such the Gaussian (aka RBF) kernel with Euclidean distance ``d(X, X)``:: np.exp(-gamma * d(X,X) ** 2) or a k-nearest neighbors connectivity matrix. Alternatively, a user-provided affinity matrix can be specified by setting ``affinity='precomputed'``. Read more in the :ref:`User Guide `.", - "docstring": "Apply clustering to a projection of the normalized Laplacian.\n\n In practice Spectral Clustering is very useful when the structure of\n the individual clusters is highly non-convex, or more generally when\n a measure of the center and spread of the cluster is not a suitable\n description of the complete cluster, such as when clusters are\n nested circles on the 2D plane.\n\n If the affinity matrix is the adjacency matrix of a graph, this method\n can be used to find normalized graph cuts.\n\n When calling ``fit``, an affinity matrix is constructed using either\n a kernel function such the Gaussian (aka RBF) kernel with Euclidean\n distance ``d(X, X)``::\n\n np.exp(-gamma * d(X,X) ** 2)\n\n or a k-nearest neighbors connectivity matrix.\n\n Alternatively, a user-provided affinity matrix can be specified by\n setting ``affinity='precomputed'``.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_clusters : int, default=8\n The dimension of the projection subspace.\n\n eigen_solver : {'arpack', 'lobpcg', 'amg'}, default=None\n The eigenvalue decomposition strategy to use. AMG requires pyamg\n to be installed. It can be faster on very large, sparse problems,\n but may also lead to instabilities. If None, then ``'arpack'`` is\n used.\n\n n_components : int, default=n_clusters\n Number of eigenvectors to use for the spectral embedding\n\n random_state : int, RandomState instance, default=None\n A pseudo random number generator used for the initialization\n of the lobpcg eigenvectors decomposition when `eigen_solver ==\n 'amg'`, and for the K-Means initialization. Use an int to make\n the results deterministic across calls (See\n :term:`Glossary `).\n\n .. note::\n When using `eigen_solver == 'amg'`,\n it is necessary to also fix the global numpy seed with\n `np.random.seed(int)` to get deterministic results. See\n https://github.com/pyamg/pyamg/issues/139 for further\n information.\n\n n_init : int, default=10\n Number of time the k-means algorithm will be run with different\n centroid seeds. The final results will be the best output of n_init\n consecutive runs in terms of inertia. Only used if\n ``assign_labels='kmeans'``.\n\n gamma : float, default=1.0\n Kernel coefficient for rbf, poly, sigmoid, laplacian and chi2 kernels.\n Ignored for ``affinity='nearest_neighbors'``.\n\n affinity : str or callable, default='rbf'\n How to construct the affinity matrix.\n - 'nearest_neighbors': construct the affinity matrix by computing a\n graph of nearest neighbors.\n - 'rbf': construct the affinity matrix using a radial basis function\n (RBF) kernel.\n - 'precomputed': interpret ``X`` as a precomputed affinity matrix,\n where larger values indicate greater similarity between instances.\n - 'precomputed_nearest_neighbors': interpret ``X`` as a sparse graph\n of precomputed distances, and construct a binary affinity matrix\n from the ``n_neighbors`` nearest neighbors of each instance.\n - one of the kernels supported by\n :func:`~sklearn.metrics.pairwise_kernels`.\n\n Only kernels that produce similarity scores (non-negative values that\n increase with similarity) should be used. This property is not checked\n by the clustering algorithm.\n\n n_neighbors : int, default=10\n Number of neighbors to use when constructing the affinity matrix using\n the nearest neighbors method. Ignored for ``affinity='rbf'``.\n\n eigen_tol : float, default=0.0\n Stopping criterion for eigendecomposition of the Laplacian matrix\n when ``eigen_solver='arpack'``.\n\n assign_labels : {'kmeans', 'discretize'}, default='kmeans'\n The strategy for assigning labels in the embedding space. There are two\n ways to assign labels after the Laplacian embedding. k-means is a\n popular choice, but it can be sensitive to initialization.\n Discretization is another approach which is less sensitive to random\n initialization.\n\n degree : float, default=3\n Degree of the polynomial kernel. Ignored by other kernels.\n\n coef0 : float, default=1\n Zero coefficient for polynomial and sigmoid kernels.\n Ignored by other kernels.\n\n kernel_params : dict of str to any, default=None\n Parameters (keyword arguments) and values for kernel passed as\n callable object. Ignored by other kernels.\n\n n_jobs : int, default=None\n The number of parallel jobs to run when `affinity='nearest_neighbors'`\n or `affinity='precomputed_nearest_neighbors'`. The neighbors search\n will be done in parallel.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n verbose : bool, default=False\n Verbosity mode.\n\n .. versionadded:: 0.24\n\n Attributes\n ----------\n affinity_matrix_ : array-like of shape (n_samples, n_samples)\n Affinity matrix used for clustering. Available only after calling\n ``fit``.\n\n labels_ : ndarray of shape (n_samples,)\n Labels of each point\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn.cluster import SpectralClustering\n >>> import numpy as np\n >>> X = np.array([[1, 1], [2, 1], [1, 0],\n ... [4, 7], [3, 5], [3, 6]])\n >>> clustering = SpectralClustering(n_clusters=2,\n ... assign_labels='discretize',\n ... random_state=0).fit(X)\n >>> clustering.labels_\n array([1, 1, 1, 0, 0, 0])\n >>> clustering\n SpectralClustering(assign_labels='discretize', n_clusters=2,\n random_state=0)\n\n Notes\n -----\n A distance matrix for which 0 indicates identical elements and high values\n indicate very dissimilar elements can be transformed into an affinity /\n similarity matrix that is well-suited for the algorithm by\n applying the Gaussian (aka RBF, heat) kernel::\n\n np.exp(- dist_matrix ** 2 / (2. * delta ** 2))\n\n where ``delta`` is a free parameter representing the width of the Gaussian\n kernel.\n\n An alternative is to take a symmetric version of the k-nearest neighbors\n connectivity matrix of the points.\n\n If the pyamg package is installed, it is used: this greatly\n speeds up computation.\n\n References\n ----------\n\n - Normalized cuts and image segmentation, 2000\n Jianbo Shi, Jitendra Malik\n http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.160.2324\n\n - A Tutorial on Spectral Clustering, 2007\n Ulrike von Luxburg\n http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.165.9323\n\n - Multiclass spectral clustering, 2003\n Stella X. Yu, Jianbo Shi\n https://www1.icsi.berkeley.edu/~stellayu/publication/doc/2003kwayICCV.pdf\n ", - "source_code": "\n\nclass SpectralClustering(ClusterMixin, BaseEstimator):\n \"\"\"Apply clustering to a projection of the normalized Laplacian.\n\n In practice Spectral Clustering is very useful when the structure of\n the individual clusters is highly non-convex, or more generally when\n a measure of the center and spread of the cluster is not a suitable\n description of the complete cluster, such as when clusters are\n nested circles on the 2D plane.\n\n If the affinity matrix is the adjacency matrix of a graph, this method\n can be used to find normalized graph cuts.\n\n When calling ``fit``, an affinity matrix is constructed using either\n a kernel function such the Gaussian (aka RBF) kernel with Euclidean\n distance ``d(X, X)``::\n\n np.exp(-gamma * d(X,X) ** 2)\n\n or a k-nearest neighbors connectivity matrix.\n\n Alternatively, a user-provided affinity matrix can be specified by\n setting ``affinity='precomputed'``.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_clusters : int, default=8\n The dimension of the projection subspace.\n\n eigen_solver : {'arpack', 'lobpcg', 'amg'}, default=None\n The eigenvalue decomposition strategy to use. AMG requires pyamg\n to be installed. It can be faster on very large, sparse problems,\n but may also lead to instabilities. If None, then ``'arpack'`` is\n used.\n\n n_components : int, default=n_clusters\n Number of eigenvectors to use for the spectral embedding\n\n random_state : int, RandomState instance, default=None\n A pseudo random number generator used for the initialization\n of the lobpcg eigenvectors decomposition when `eigen_solver ==\n 'amg'`, and for the K-Means initialization. Use an int to make\n the results deterministic across calls (See\n :term:`Glossary `).\n\n .. note::\n When using `eigen_solver == 'amg'`,\n it is necessary to also fix the global numpy seed with\n `np.random.seed(int)` to get deterministic results. See\n https://github.com/pyamg/pyamg/issues/139 for further\n information.\n\n n_init : int, default=10\n Number of time the k-means algorithm will be run with different\n centroid seeds. The final results will be the best output of n_init\n consecutive runs in terms of inertia. Only used if\n ``assign_labels='kmeans'``.\n\n gamma : float, default=1.0\n Kernel coefficient for rbf, poly, sigmoid, laplacian and chi2 kernels.\n Ignored for ``affinity='nearest_neighbors'``.\n\n affinity : str or callable, default='rbf'\n How to construct the affinity matrix.\n - 'nearest_neighbors': construct the affinity matrix by computing a\n graph of nearest neighbors.\n - 'rbf': construct the affinity matrix using a radial basis function\n (RBF) kernel.\n - 'precomputed': interpret ``X`` as a precomputed affinity matrix,\n where larger values indicate greater similarity between instances.\n - 'precomputed_nearest_neighbors': interpret ``X`` as a sparse graph\n of precomputed distances, and construct a binary affinity matrix\n from the ``n_neighbors`` nearest neighbors of each instance.\n - one of the kernels supported by\n :func:`~sklearn.metrics.pairwise_kernels`.\n\n Only kernels that produce similarity scores (non-negative values that\n increase with similarity) should be used. This property is not checked\n by the clustering algorithm.\n\n n_neighbors : int, default=10\n Number of neighbors to use when constructing the affinity matrix using\n the nearest neighbors method. Ignored for ``affinity='rbf'``.\n\n eigen_tol : float, default=0.0\n Stopping criterion for eigendecomposition of the Laplacian matrix\n when ``eigen_solver='arpack'``.\n\n assign_labels : {'kmeans', 'discretize'}, default='kmeans'\n The strategy for assigning labels in the embedding space. There are two\n ways to assign labels after the Laplacian embedding. k-means is a\n popular choice, but it can be sensitive to initialization.\n Discretization is another approach which is less sensitive to random\n initialization.\n\n degree : float, default=3\n Degree of the polynomial kernel. Ignored by other kernels.\n\n coef0 : float, default=1\n Zero coefficient for polynomial and sigmoid kernels.\n Ignored by other kernels.\n\n kernel_params : dict of str to any, default=None\n Parameters (keyword arguments) and values for kernel passed as\n callable object. Ignored by other kernels.\n\n n_jobs : int, default=None\n The number of parallel jobs to run when `affinity='nearest_neighbors'`\n or `affinity='precomputed_nearest_neighbors'`. The neighbors search\n will be done in parallel.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n verbose : bool, default=False\n Verbosity mode.\n\n .. versionadded:: 0.24\n\n Attributes\n ----------\n affinity_matrix_ : array-like of shape (n_samples, n_samples)\n Affinity matrix used for clustering. Available only after calling\n ``fit``.\n\n labels_ : ndarray of shape (n_samples,)\n Labels of each point\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn.cluster import SpectralClustering\n >>> import numpy as np\n >>> X = np.array([[1, 1], [2, 1], [1, 0],\n ... [4, 7], [3, 5], [3, 6]])\n >>> clustering = SpectralClustering(n_clusters=2,\n ... assign_labels='discretize',\n ... random_state=0).fit(X)\n >>> clustering.labels_\n array([1, 1, 1, 0, 0, 0])\n >>> clustering\n SpectralClustering(assign_labels='discretize', n_clusters=2,\n random_state=0)\n\n Notes\n -----\n A distance matrix for which 0 indicates identical elements and high values\n indicate very dissimilar elements can be transformed into an affinity /\n similarity matrix that is well-suited for the algorithm by\n applying the Gaussian (aka RBF, heat) kernel::\n\n np.exp(- dist_matrix ** 2 / (2. * delta ** 2))\n\n where ``delta`` is a free parameter representing the width of the Gaussian\n kernel.\n\n An alternative is to take a symmetric version of the k-nearest neighbors\n connectivity matrix of the points.\n\n If the pyamg package is installed, it is used: this greatly\n speeds up computation.\n\n References\n ----------\n\n - Normalized cuts and image segmentation, 2000\n Jianbo Shi, Jitendra Malik\n http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.160.2324\n\n - A Tutorial on Spectral Clustering, 2007\n Ulrike von Luxburg\n http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.165.9323\n\n - Multiclass spectral clustering, 2003\n Stella X. Yu, Jianbo Shi\n https://www1.icsi.berkeley.edu/~stellayu/publication/doc/2003kwayICCV.pdf\n \"\"\"\n \n def __init__(self, n_clusters=8, *, eigen_solver=None, n_components=None, random_state=None, n_init=10, gamma=1.0, affinity='rbf', n_neighbors=10, eigen_tol=0.0, assign_labels='kmeans', degree=3, coef0=1, kernel_params=None, n_jobs=None, verbose=False):\n self.n_clusters = n_clusters\n self.eigen_solver = eigen_solver\n self.n_components = n_components\n self.random_state = random_state\n self.n_init = n_init\n self.gamma = gamma\n self.affinity = affinity\n self.n_neighbors = n_neighbors\n self.eigen_tol = eigen_tol\n self.assign_labels = assign_labels\n self.degree = degree\n self.coef0 = coef0\n self.kernel_params = kernel_params\n self.n_jobs = n_jobs\n self.verbose = verbose\n \n def fit(self, X, y=None):\n \"\"\"Perform spectral clustering from features, or affinity matrix.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples)\n Training instances to cluster, similarities / affinities between\n instances if ``affinity='precomputed'``, or distances between\n instances if ``affinity='precomputed_nearest_neighbors``. If a\n sparse matrix is provided in a format other than ``csr_matrix``,\n ``csc_matrix``, or ``coo_matrix``, it will be converted into a\n sparse ``csr_matrix``.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self\n\n \"\"\"\n X = self._validate_data(X, accept_sparse=['csr', 'csc', 'coo'], dtype=np.float64, ensure_min_samples=2)\n allow_squared = self.affinity in ['precomputed', 'precomputed_nearest_neighbors']\n if X.shape[0] == X.shape[1] and not allow_squared:\n warnings.warn('The spectral clustering API has changed. ``fit``now constructs an affinity matrix from data. To use a custom affinity matrix, set ``affinity=precomputed``.')\n if self.affinity == 'nearest_neighbors':\n connectivity = kneighbors_graph(X, n_neighbors=self.n_neighbors, include_self=True, n_jobs=self.n_jobs)\n self.affinity_matrix_ = 0.5 * (connectivity + connectivity.T)\n elif self.affinity == 'precomputed_nearest_neighbors':\n estimator = NearestNeighbors(n_neighbors=self.n_neighbors, n_jobs=self.n_jobs, metric='precomputed').fit(X)\n connectivity = estimator.kneighbors_graph(X=X, mode='connectivity')\n self.affinity_matrix_ = 0.5 * (connectivity + connectivity.T)\n elif self.affinity == 'precomputed':\n self.affinity_matrix_ = X\n else:\n params = self.kernel_params\n if params is None:\n params = {}\n if not callable(self.affinity):\n params['gamma'] = self.gamma\n params['degree'] = self.degree\n params['coef0'] = self.coef0\n self.affinity_matrix_ = pairwise_kernels(X, metric=self.affinity, filter_params=True, **params)\n random_state = check_random_state(self.random_state)\n self.labels_ = spectral_clustering(self.affinity_matrix_, n_clusters=self.n_clusters, n_components=self.n_components, eigen_solver=self.eigen_solver, random_state=random_state, n_init=self.n_init, eigen_tol=self.eigen_tol, assign_labels=self.assign_labels, verbose=self.verbose)\n return self\n \n def fit_predict(self, X, y=None):\n \"\"\"Perform spectral clustering from features, or affinity matrix,\n and return cluster labels.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples)\n Training instances to cluster, similarities / affinities between\n instances if ``affinity='precomputed'``, or distances between\n instances if ``affinity='precomputed_nearest_neighbors``. If a\n sparse matrix is provided in a format other than ``csr_matrix``,\n ``csc_matrix``, or ``coo_matrix``, it will be converted into a\n sparse ``csr_matrix``.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n labels : ndarray of shape (n_samples,)\n Cluster labels.\n \"\"\"\n return super().fit_predict(X, y)\n \n def _more_tags(self):\n return {'pairwise': self.affinity in ['precomputed', 'precomputed_nearest_neighbors']}\n \n @deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def _pairwise(self):\n return self.affinity in ['precomputed', 'precomputed_nearest_neighbors']\n" + "description": "Apply clustering to a projection of the normalized Laplacian.\n\nIn practice Spectral Clustering is very useful when the structure of the individual clusters is highly non-convex, or more generally when a measure of the center and spread of the cluster is not a suitable description of the complete cluster, such as when clusters are nested circles on the 2D plane. If the affinity matrix is the adjacency matrix of a graph, this method can be used to find normalized graph cuts [1]_, [2]_. When calling ``fit``, an affinity matrix is constructed using either a kernel function such the Gaussian (aka RBF) kernel with Euclidean distance ``d(X, X)``:: np.exp(-gamma * d(X,X) ** 2) or a k-nearest neighbors connectivity matrix. Alternatively, a user-provided affinity matrix can be specified by setting ``affinity='precomputed'``. Read more in the :ref:`User Guide `.", + "docstring": "Apply clustering to a projection of the normalized Laplacian.\n\n In practice Spectral Clustering is very useful when the structure of\n the individual clusters is highly non-convex, or more generally when\n a measure of the center and spread of the cluster is not a suitable\n description of the complete cluster, such as when clusters are\n nested circles on the 2D plane.\n\n If the affinity matrix is the adjacency matrix of a graph, this method\n can be used to find normalized graph cuts [1]_, [2]_.\n\n When calling ``fit``, an affinity matrix is constructed using either\n a kernel function such the Gaussian (aka RBF) kernel with Euclidean\n distance ``d(X, X)``::\n\n np.exp(-gamma * d(X,X) ** 2)\n\n or a k-nearest neighbors connectivity matrix.\n\n Alternatively, a user-provided affinity matrix can be specified by\n setting ``affinity='precomputed'``.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_clusters : int, default=8\n The dimension of the projection subspace.\n\n eigen_solver : {'arpack', 'lobpcg', 'amg'}, default=None\n The eigenvalue decomposition strategy to use. AMG requires pyamg\n to be installed. It can be faster on very large, sparse problems,\n but may also lead to instabilities. If None, then ``'arpack'`` is\n used. See [4]_ for more details regarding `'lobpcg'`.\n\n n_components : int, default=n_clusters\n Number of eigenvectors to use for the spectral embedding.\n\n random_state : int, RandomState instance, default=None\n A pseudo random number generator used for the initialization\n of the lobpcg eigenvectors decomposition when `eigen_solver ==\n 'amg'`, and for the K-Means initialization. Use an int to make\n the results deterministic across calls (See\n :term:`Glossary `).\n\n .. note::\n When using `eigen_solver == 'amg'`,\n it is necessary to also fix the global numpy seed with\n `np.random.seed(int)` to get deterministic results. See\n https://github.com/pyamg/pyamg/issues/139 for further\n information.\n\n n_init : int, default=10\n Number of time the k-means algorithm will be run with different\n centroid seeds. The final results will be the best output of n_init\n consecutive runs in terms of inertia. Only used if\n ``assign_labels='kmeans'``.\n\n gamma : float, default=1.0\n Kernel coefficient for rbf, poly, sigmoid, laplacian and chi2 kernels.\n Ignored for ``affinity='nearest_neighbors'``.\n\n affinity : str or callable, default='rbf'\n How to construct the affinity matrix.\n - 'nearest_neighbors': construct the affinity matrix by computing a\n graph of nearest neighbors.\n - 'rbf': construct the affinity matrix using a radial basis function\n (RBF) kernel.\n - 'precomputed': interpret ``X`` as a precomputed affinity matrix,\n where larger values indicate greater similarity between instances.\n - 'precomputed_nearest_neighbors': interpret ``X`` as a sparse graph\n of precomputed distances, and construct a binary affinity matrix\n from the ``n_neighbors`` nearest neighbors of each instance.\n - one of the kernels supported by\n :func:`~sklearn.metrics.pairwise_kernels`.\n\n Only kernels that produce similarity scores (non-negative values that\n increase with similarity) should be used. This property is not checked\n by the clustering algorithm.\n\n n_neighbors : int, default=10\n Number of neighbors to use when constructing the affinity matrix using\n the nearest neighbors method. Ignored for ``affinity='rbf'``.\n\n eigen_tol : float, default=0.0\n Stopping criterion for eigendecomposition of the Laplacian matrix\n when ``eigen_solver='arpack'``.\n\n assign_labels : {'kmeans', 'discretize'}, default='kmeans'\n The strategy for assigning labels in the embedding space. There are two\n ways to assign labels after the Laplacian embedding. k-means is a\n popular choice, but it can be sensitive to initialization.\n Discretization is another approach which is less sensitive to random\n initialization [3]_.\n\n degree : float, default=3\n Degree of the polynomial kernel. Ignored by other kernels.\n\n coef0 : float, default=1\n Zero coefficient for polynomial and sigmoid kernels.\n Ignored by other kernels.\n\n kernel_params : dict of str to any, default=None\n Parameters (keyword arguments) and values for kernel passed as\n callable object. Ignored by other kernels.\n\n n_jobs : int, default=None\n The number of parallel jobs to run when `affinity='nearest_neighbors'`\n or `affinity='precomputed_nearest_neighbors'`. The neighbors search\n will be done in parallel.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n verbose : bool, default=False\n Verbosity mode.\n\n .. versionadded:: 0.24\n\n Attributes\n ----------\n affinity_matrix_ : array-like of shape (n_samples, n_samples)\n Affinity matrix used for clustering. Available only after calling\n ``fit``.\n\n labels_ : ndarray of shape (n_samples,)\n Labels of each point\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n sklearn.cluster.KMeans : K-Means clustering.\n sklearn.cluster.DBSCAN : Density-Based Spatial Clustering of\n Applications with Noise.\n\n Notes\n -----\n A distance matrix for which 0 indicates identical elements and high values\n indicate very dissimilar elements can be transformed into an affinity /\n similarity matrix that is well-suited for the algorithm by\n applying the Gaussian (aka RBF, heat) kernel::\n\n np.exp(- dist_matrix ** 2 / (2. * delta ** 2))\n\n where ``delta`` is a free parameter representing the width of the Gaussian\n kernel.\n\n An alternative is to take a symmetric version of the k-nearest neighbors\n connectivity matrix of the points.\n\n If the pyamg package is installed, it is used: this greatly\n speeds up computation.\n\n References\n ----------\n .. [1] `Normalized cuts and image segmentation, 2000\n Jianbo Shi, Jitendra Malik\n `_\n\n .. [2] `A Tutorial on Spectral Clustering, 2007\n Ulrike von Luxburg\n `_\n\n .. [3] `Multiclass spectral clustering, 2003\n Stella X. Yu, Jianbo Shi\n `_\n\n .. [4] `Toward the Optimal Preconditioned Eigensolver:\n Locally Optimal Block Preconditioned Conjugate Gradient Method, 2001.\n A. V. Knyazev\n SIAM Journal on Scientific Computing 23, no. 2, pp. 517-541.\n `_\n\n Examples\n --------\n >>> from sklearn.cluster import SpectralClustering\n >>> import numpy as np\n >>> X = np.array([[1, 1], [2, 1], [1, 0],\n ... [4, 7], [3, 5], [3, 6]])\n >>> clustering = SpectralClustering(n_clusters=2,\n ... assign_labels='discretize',\n ... random_state=0).fit(X)\n >>> clustering.labels_\n array([1, 1, 1, 0, 0, 0])\n >>> clustering\n SpectralClustering(assign_labels='discretize', n_clusters=2,\n random_state=0)\n ", + "source_code": "\n\nclass SpectralClustering(ClusterMixin, BaseEstimator):\n \"\"\"Apply clustering to a projection of the normalized Laplacian.\n\n In practice Spectral Clustering is very useful when the structure of\n the individual clusters is highly non-convex, or more generally when\n a measure of the center and spread of the cluster is not a suitable\n description of the complete cluster, such as when clusters are\n nested circles on the 2D plane.\n\n If the affinity matrix is the adjacency matrix of a graph, this method\n can be used to find normalized graph cuts [1]_, [2]_.\n\n When calling ``fit``, an affinity matrix is constructed using either\n a kernel function such the Gaussian (aka RBF) kernel with Euclidean\n distance ``d(X, X)``::\n\n np.exp(-gamma * d(X,X) ** 2)\n\n or a k-nearest neighbors connectivity matrix.\n\n Alternatively, a user-provided affinity matrix can be specified by\n setting ``affinity='precomputed'``.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_clusters : int, default=8\n The dimension of the projection subspace.\n\n eigen_solver : {'arpack', 'lobpcg', 'amg'}, default=None\n The eigenvalue decomposition strategy to use. AMG requires pyamg\n to be installed. It can be faster on very large, sparse problems,\n but may also lead to instabilities. If None, then ``'arpack'`` is\n used. See [4]_ for more details regarding `'lobpcg'`.\n\n n_components : int, default=n_clusters\n Number of eigenvectors to use for the spectral embedding.\n\n random_state : int, RandomState instance, default=None\n A pseudo random number generator used for the initialization\n of the lobpcg eigenvectors decomposition when `eigen_solver ==\n 'amg'`, and for the K-Means initialization. Use an int to make\n the results deterministic across calls (See\n :term:`Glossary `).\n\n .. note::\n When using `eigen_solver == 'amg'`,\n it is necessary to also fix the global numpy seed with\n `np.random.seed(int)` to get deterministic results. See\n https://github.com/pyamg/pyamg/issues/139 for further\n information.\n\n n_init : int, default=10\n Number of time the k-means algorithm will be run with different\n centroid seeds. The final results will be the best output of n_init\n consecutive runs in terms of inertia. Only used if\n ``assign_labels='kmeans'``.\n\n gamma : float, default=1.0\n Kernel coefficient for rbf, poly, sigmoid, laplacian and chi2 kernels.\n Ignored for ``affinity='nearest_neighbors'``.\n\n affinity : str or callable, default='rbf'\n How to construct the affinity matrix.\n - 'nearest_neighbors': construct the affinity matrix by computing a\n graph of nearest neighbors.\n - 'rbf': construct the affinity matrix using a radial basis function\n (RBF) kernel.\n - 'precomputed': interpret ``X`` as a precomputed affinity matrix,\n where larger values indicate greater similarity between instances.\n - 'precomputed_nearest_neighbors': interpret ``X`` as a sparse graph\n of precomputed distances, and construct a binary affinity matrix\n from the ``n_neighbors`` nearest neighbors of each instance.\n - one of the kernels supported by\n :func:`~sklearn.metrics.pairwise_kernels`.\n\n Only kernels that produce similarity scores (non-negative values that\n increase with similarity) should be used. This property is not checked\n by the clustering algorithm.\n\n n_neighbors : int, default=10\n Number of neighbors to use when constructing the affinity matrix using\n the nearest neighbors method. Ignored for ``affinity='rbf'``.\n\n eigen_tol : float, default=0.0\n Stopping criterion for eigendecomposition of the Laplacian matrix\n when ``eigen_solver='arpack'``.\n\n assign_labels : {'kmeans', 'discretize'}, default='kmeans'\n The strategy for assigning labels in the embedding space. There are two\n ways to assign labels after the Laplacian embedding. k-means is a\n popular choice, but it can be sensitive to initialization.\n Discretization is another approach which is less sensitive to random\n initialization [3]_.\n\n degree : float, default=3\n Degree of the polynomial kernel. Ignored by other kernels.\n\n coef0 : float, default=1\n Zero coefficient for polynomial and sigmoid kernels.\n Ignored by other kernels.\n\n kernel_params : dict of str to any, default=None\n Parameters (keyword arguments) and values for kernel passed as\n callable object. Ignored by other kernels.\n\n n_jobs : int, default=None\n The number of parallel jobs to run when `affinity='nearest_neighbors'`\n or `affinity='precomputed_nearest_neighbors'`. The neighbors search\n will be done in parallel.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n verbose : bool, default=False\n Verbosity mode.\n\n .. versionadded:: 0.24\n\n Attributes\n ----------\n affinity_matrix_ : array-like of shape (n_samples, n_samples)\n Affinity matrix used for clustering. Available only after calling\n ``fit``.\n\n labels_ : ndarray of shape (n_samples,)\n Labels of each point\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n sklearn.cluster.KMeans : K-Means clustering.\n sklearn.cluster.DBSCAN : Density-Based Spatial Clustering of\n Applications with Noise.\n\n Notes\n -----\n A distance matrix for which 0 indicates identical elements and high values\n indicate very dissimilar elements can be transformed into an affinity /\n similarity matrix that is well-suited for the algorithm by\n applying the Gaussian (aka RBF, heat) kernel::\n\n np.exp(- dist_matrix ** 2 / (2. * delta ** 2))\n\n where ``delta`` is a free parameter representing the width of the Gaussian\n kernel.\n\n An alternative is to take a symmetric version of the k-nearest neighbors\n connectivity matrix of the points.\n\n If the pyamg package is installed, it is used: this greatly\n speeds up computation.\n\n References\n ----------\n .. [1] `Normalized cuts and image segmentation, 2000\n Jianbo Shi, Jitendra Malik\n `_\n\n .. [2] `A Tutorial on Spectral Clustering, 2007\n Ulrike von Luxburg\n `_\n\n .. [3] `Multiclass spectral clustering, 2003\n Stella X. Yu, Jianbo Shi\n `_\n\n .. [4] `Toward the Optimal Preconditioned Eigensolver:\n Locally Optimal Block Preconditioned Conjugate Gradient Method, 2001.\n A. V. Knyazev\n SIAM Journal on Scientific Computing 23, no. 2, pp. 517-541.\n `_\n\n Examples\n --------\n >>> from sklearn.cluster import SpectralClustering\n >>> import numpy as np\n >>> X = np.array([[1, 1], [2, 1], [1, 0],\n ... [4, 7], [3, 5], [3, 6]])\n >>> clustering = SpectralClustering(n_clusters=2,\n ... assign_labels='discretize',\n ... random_state=0).fit(X)\n >>> clustering.labels_\n array([1, 1, 1, 0, 0, 0])\n >>> clustering\n SpectralClustering(assign_labels='discretize', n_clusters=2,\n random_state=0)\n \"\"\"\n \n def __init__(self, n_clusters=8, *, eigen_solver=None, n_components=None, random_state=None, n_init=10, gamma=1.0, affinity='rbf', n_neighbors=10, eigen_tol=0.0, assign_labels='kmeans', degree=3, coef0=1, kernel_params=None, n_jobs=None, verbose=False):\n self.n_clusters = n_clusters\n self.eigen_solver = eigen_solver\n self.n_components = n_components\n self.random_state = random_state\n self.n_init = n_init\n self.gamma = gamma\n self.affinity = affinity\n self.n_neighbors = n_neighbors\n self.eigen_tol = eigen_tol\n self.assign_labels = assign_labels\n self.degree = degree\n self.coef0 = coef0\n self.kernel_params = kernel_params\n self.n_jobs = n_jobs\n self.verbose = verbose\n \n def fit(self, X, y=None):\n \"\"\"Perform spectral clustering from features, or affinity matrix.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples)\n Training instances to cluster, similarities / affinities between\n instances if ``affinity='precomputed'``, or distances between\n instances if ``affinity='precomputed_nearest_neighbors``. If a\n sparse matrix is provided in a format other than ``csr_matrix``,\n ``csc_matrix``, or ``coo_matrix``, it will be converted into a\n sparse ``csr_matrix``.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self : object\n A fitted instance of the estimator.\n \"\"\"\n X = self._validate_data(X, accept_sparse=['csr', 'csc', 'coo'], dtype=np.float64, ensure_min_samples=2)\n allow_squared = self.affinity in ['precomputed', 'precomputed_nearest_neighbors']\n if X.shape[0] == X.shape[1] and not allow_squared:\n warnings.warn('The spectral clustering API has changed. ``fit``now constructs an affinity matrix from data. To use a custom affinity matrix, set ``affinity=precomputed``.')\n if self.affinity == 'nearest_neighbors':\n connectivity = kneighbors_graph(X, n_neighbors=self.n_neighbors, include_self=True, n_jobs=self.n_jobs)\n self.affinity_matrix_ = 0.5 * (connectivity + connectivity.T)\n elif self.affinity == 'precomputed_nearest_neighbors':\n estimator = NearestNeighbors(n_neighbors=self.n_neighbors, n_jobs=self.n_jobs, metric='precomputed').fit(X)\n connectivity = estimator.kneighbors_graph(X=X, mode='connectivity')\n self.affinity_matrix_ = 0.5 * (connectivity + connectivity.T)\n elif self.affinity == 'precomputed':\n self.affinity_matrix_ = X\n else:\n params = self.kernel_params\n if params is None:\n params = {}\n if not callable(self.affinity):\n params['gamma'] = self.gamma\n params['degree'] = self.degree\n params['coef0'] = self.coef0\n self.affinity_matrix_ = pairwise_kernels(X, metric=self.affinity, filter_params=True, **params)\n random_state = check_random_state(self.random_state)\n self.labels_ = spectral_clustering(self.affinity_matrix_, n_clusters=self.n_clusters, n_components=self.n_components, eigen_solver=self.eigen_solver, random_state=random_state, n_init=self.n_init, eigen_tol=self.eigen_tol, assign_labels=self.assign_labels, verbose=self.verbose)\n return self\n \n def fit_predict(self, X, y=None):\n \"\"\"Perform spectral clustering on `X` and return cluster labels.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples)\n Training instances to cluster, similarities / affinities between\n instances if ``affinity='precomputed'``, or distances between\n instances if ``affinity='precomputed_nearest_neighbors``. If a\n sparse matrix is provided in a format other than ``csr_matrix``,\n ``csc_matrix``, or ``coo_matrix``, it will be converted into a\n sparse ``csr_matrix``.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n labels : ndarray of shape (n_samples,)\n Cluster labels.\n \"\"\"\n return super().fit_predict(X, y)\n \n def _more_tags(self):\n return {'pairwise': self.affinity in ['precomputed', 'precomputed_nearest_neighbors']}\n \n @deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def _pairwise(self):\n return self.affinity in ['precomputed', 'precomputed_nearest_neighbors']\n" }, { "name": "ColumnTransformer", @@ -20155,15 +20122,15 @@ "superclasses": ["TransformerMixin", "_BaseComposition"], "methods": [ "sklearn.compose._column_transformer.ColumnTransformer.__init__", - "sklearn.compose._column_transformer.ColumnTransformer._transformers", - "sklearn.compose._column_transformer.ColumnTransformer._transformers", + "sklearn.compose._column_transformer.ColumnTransformer._transformers@getter", + "sklearn.compose._column_transformer.ColumnTransformer._transformers@setter", "sklearn.compose._column_transformer.ColumnTransformer.get_params", "sklearn.compose._column_transformer.ColumnTransformer.set_params", "sklearn.compose._column_transformer.ColumnTransformer._iter", "sklearn.compose._column_transformer.ColumnTransformer._validate_transformers", "sklearn.compose._column_transformer.ColumnTransformer._validate_column_callables", "sklearn.compose._column_transformer.ColumnTransformer._validate_remainder", - "sklearn.compose._column_transformer.ColumnTransformer.named_transformers_", + "sklearn.compose._column_transformer.ColumnTransformer.named_transformers_@getter", "sklearn.compose._column_transformer.ColumnTransformer.get_feature_names", "sklearn.compose._column_transformer.ColumnTransformer._get_feature_name_out_for_transformer", "sklearn.compose._column_transformer.ColumnTransformer.get_feature_names_out", @@ -20194,8 +20161,8 @@ ], "is_public": true, "description": "Create a callable to select columns to be used with :class:`ColumnTransformer`.\n\n:func:`make_column_selector` can select columns based on datatype or the columns name with a regex. When using multiple selection criteria, **all** criteria must match for a column to be selected.", - "docstring": "Create a callable to select columns to be used with\n :class:`ColumnTransformer`.\n\n :func:`make_column_selector` can select columns based on datatype or the\n columns name with a regex. When using multiple selection criteria, **all**\n criteria must match for a column to be selected.\n\n Parameters\n ----------\n pattern : str, default=None\n Name of columns containing this regex pattern will be included. If\n None, column selection will not be selected based on pattern.\n\n dtype_include : column dtype or list of column dtypes, default=None\n A selection of dtypes to include. For more details, see\n :meth:`pandas.DataFrame.select_dtypes`.\n\n dtype_exclude : column dtype or list of column dtypes, default=None\n A selection of dtypes to exclude. For more details, see\n :meth:`pandas.DataFrame.select_dtypes`.\n\n Returns\n -------\n selector : callable\n Callable for column selection to be used by a\n :class:`ColumnTransformer`.\n\n See Also\n --------\n ColumnTransformer : Class that allows combining the\n outputs of multiple transformer objects used on column subsets\n of the data into a single feature space.\n\n Examples\n --------\n >>> from sklearn.preprocessing import StandardScaler, OneHotEncoder\n >>> from sklearn.compose import make_column_transformer\n >>> from sklearn.compose import make_column_selector\n >>> import pandas as pd # doctest: +SKIP\n >>> X = pd.DataFrame({'city': ['London', 'London', 'Paris', 'Sallisaw'],\n ... 'rating': [5, 3, 4, 5]}) # doctest: +SKIP\n >>> ct = make_column_transformer(\n ... (StandardScaler(),\n ... make_column_selector(dtype_include=np.number)), # rating\n ... (OneHotEncoder(),\n ... make_column_selector(dtype_include=object))) # city\n >>> ct.fit_transform(X) # doctest: +SKIP\n array([[ 0.90453403, 1. , 0. , 0. ],\n [-1.50755672, 1. , 0. , 0. ],\n [-0.30151134, 0. , 1. , 0. ],\n [ 0.90453403, 0. , 0. , 1. ]])\n ", - "source_code": "\n\nclass make_column_selector:\n \"\"\"Create a callable to select columns to be used with\n :class:`ColumnTransformer`.\n\n :func:`make_column_selector` can select columns based on datatype or the\n columns name with a regex. When using multiple selection criteria, **all**\n criteria must match for a column to be selected.\n\n Parameters\n ----------\n pattern : str, default=None\n Name of columns containing this regex pattern will be included. If\n None, column selection will not be selected based on pattern.\n\n dtype_include : column dtype or list of column dtypes, default=None\n A selection of dtypes to include. For more details, see\n :meth:`pandas.DataFrame.select_dtypes`.\n\n dtype_exclude : column dtype or list of column dtypes, default=None\n A selection of dtypes to exclude. For more details, see\n :meth:`pandas.DataFrame.select_dtypes`.\n\n Returns\n -------\n selector : callable\n Callable for column selection to be used by a\n :class:`ColumnTransformer`.\n\n See Also\n --------\n ColumnTransformer : Class that allows combining the\n outputs of multiple transformer objects used on column subsets\n of the data into a single feature space.\n\n Examples\n --------\n >>> from sklearn.preprocessing import StandardScaler, OneHotEncoder\n >>> from sklearn.compose import make_column_transformer\n >>> from sklearn.compose import make_column_selector\n >>> import pandas as pd # doctest: +SKIP\n >>> X = pd.DataFrame({'city': ['London', 'London', 'Paris', 'Sallisaw'],\n ... 'rating': [5, 3, 4, 5]}) # doctest: +SKIP\n >>> ct = make_column_transformer(\n ... (StandardScaler(),\n ... make_column_selector(dtype_include=np.number)), # rating\n ... (OneHotEncoder(),\n ... make_column_selector(dtype_include=object))) # city\n >>> ct.fit_transform(X) # doctest: +SKIP\n array([[ 0.90453403, 1. , 0. , 0. ],\n [-1.50755672, 1. , 0. , 0. ],\n [-0.30151134, 0. , 1. , 0. ],\n [ 0.90453403, 0. , 0. , 1. ]])\n \"\"\"\n \n def __init__(self, pattern=None, *, dtype_include=None, dtype_exclude=None):\n self.pattern = pattern\n self.dtype_include = dtype_include\n self.dtype_exclude = dtype_exclude\n \n def __call__(self, df):\n \"\"\"Callable for column selection to be used by a\n :class:`ColumnTransformer`.\n\n Parameters\n ----------\n df : dataframe of shape (n_features, n_samples)\n DataFrame to select columns from.\n \"\"\"\n if not hasattr(df, 'iloc'):\n raise ValueError('make_column_selector can only be applied to pandas dataframes')\n df_row = df.iloc[:1]\n if self.dtype_include is not None or self.dtype_exclude is not None:\n df_row = df_row.select_dtypes(include=self.dtype_include, exclude=self.dtype_exclude)\n cols = df_row.columns\n if self.pattern is not None:\n cols = cols[cols.str.contains(self.pattern, regex=True)]\n return cols.tolist()\n" + "docstring": "Create a callable to select columns to be used with\n :class:`ColumnTransformer`.\n\n :func:`make_column_selector` can select columns based on datatype or the\n columns name with a regex. When using multiple selection criteria, **all**\n criteria must match for a column to be selected.\n\n Parameters\n ----------\n pattern : str, default=None\n Name of columns containing this regex pattern will be included. If\n None, column selection will not be selected based on pattern.\n\n dtype_include : column dtype or list of column dtypes, default=None\n A selection of dtypes to include. For more details, see\n :meth:`pandas.DataFrame.select_dtypes`.\n\n dtype_exclude : column dtype or list of column dtypes, default=None\n A selection of dtypes to exclude. For more details, see\n :meth:`pandas.DataFrame.select_dtypes`.\n\n Returns\n -------\n selector : callable\n Callable for column selection to be used by a\n :class:`ColumnTransformer`.\n\n See Also\n --------\n ColumnTransformer : Class that allows combining the\n outputs of multiple transformer objects used on column subsets\n of the data into a single feature space.\n\n Examples\n --------\n >>> from sklearn.preprocessing import StandardScaler, OneHotEncoder\n >>> from sklearn.compose import make_column_transformer\n >>> from sklearn.compose import make_column_selector\n >>> import numpy as np\n >>> import pandas as pd # doctest: +SKIP\n >>> X = pd.DataFrame({'city': ['London', 'London', 'Paris', 'Sallisaw'],\n ... 'rating': [5, 3, 4, 5]}) # doctest: +SKIP\n >>> ct = make_column_transformer(\n ... (StandardScaler(),\n ... make_column_selector(dtype_include=np.number)), # rating\n ... (OneHotEncoder(),\n ... make_column_selector(dtype_include=object))) # city\n >>> ct.fit_transform(X) # doctest: +SKIP\n array([[ 0.90453403, 1. , 0. , 0. ],\n [-1.50755672, 1. , 0. , 0. ],\n [-0.30151134, 0. , 1. , 0. ],\n [ 0.90453403, 0. , 0. , 1. ]])\n ", + "source_code": "\n\nclass make_column_selector:\n \"\"\"Create a callable to select columns to be used with\n :class:`ColumnTransformer`.\n\n :func:`make_column_selector` can select columns based on datatype or the\n columns name with a regex. When using multiple selection criteria, **all**\n criteria must match for a column to be selected.\n\n Parameters\n ----------\n pattern : str, default=None\n Name of columns containing this regex pattern will be included. If\n None, column selection will not be selected based on pattern.\n\n dtype_include : column dtype or list of column dtypes, default=None\n A selection of dtypes to include. For more details, see\n :meth:`pandas.DataFrame.select_dtypes`.\n\n dtype_exclude : column dtype or list of column dtypes, default=None\n A selection of dtypes to exclude. For more details, see\n :meth:`pandas.DataFrame.select_dtypes`.\n\n Returns\n -------\n selector : callable\n Callable for column selection to be used by a\n :class:`ColumnTransformer`.\n\n See Also\n --------\n ColumnTransformer : Class that allows combining the\n outputs of multiple transformer objects used on column subsets\n of the data into a single feature space.\n\n Examples\n --------\n >>> from sklearn.preprocessing import StandardScaler, OneHotEncoder\n >>> from sklearn.compose import make_column_transformer\n >>> from sklearn.compose import make_column_selector\n >>> import numpy as np\n >>> import pandas as pd # doctest: +SKIP\n >>> X = pd.DataFrame({'city': ['London', 'London', 'Paris', 'Sallisaw'],\n ... 'rating': [5, 3, 4, 5]}) # doctest: +SKIP\n >>> ct = make_column_transformer(\n ... (StandardScaler(),\n ... make_column_selector(dtype_include=np.number)), # rating\n ... (OneHotEncoder(),\n ... make_column_selector(dtype_include=object))) # city\n >>> ct.fit_transform(X) # doctest: +SKIP\n array([[ 0.90453403, 1. , 0. , 0. ],\n [-1.50755672, 1. , 0. , 0. ],\n [-0.30151134, 0. , 1. , 0. ],\n [ 0.90453403, 0. , 0. , 1. ]])\n \"\"\"\n \n def __init__(self, pattern=None, *, dtype_include=None, dtype_exclude=None):\n self.pattern = pattern\n self.dtype_include = dtype_include\n self.dtype_exclude = dtype_exclude\n \n def __call__(self, df):\n \"\"\"Callable for column selection to be used by a\n :class:`ColumnTransformer`.\n\n Parameters\n ----------\n df : dataframe of shape (n_features, n_samples)\n DataFrame to select columns from.\n \"\"\"\n if not hasattr(df, 'iloc'):\n raise ValueError('make_column_selector can only be applied to pandas dataframes')\n df_row = df.iloc[:1]\n if self.dtype_include is not None or self.dtype_exclude is not None:\n df_row = df_row.select_dtypes(include=self.dtype_include, exclude=self.dtype_exclude)\n cols = df_row.columns\n if self.pattern is not None:\n cols = cols[cols.str.contains(self.pattern, regex=True)]\n return cols.tolist()\n" }, { "name": "TransformedTargetRegressor", @@ -20208,12 +20175,12 @@ "sklearn.compose._target.TransformedTargetRegressor.fit", "sklearn.compose._target.TransformedTargetRegressor.predict", "sklearn.compose._target.TransformedTargetRegressor._more_tags", - "sklearn.compose._target.TransformedTargetRegressor.n_features_in_" + "sklearn.compose._target.TransformedTargetRegressor.n_features_in_@getter" ], "is_public": true, - "description": "Meta-estimator to regress on a transformed target.\n\nUseful for applying a non-linear transformation to the target ``y`` in regression problems. This transformation can be given as a Transformer such as the QuantileTransformer or as a function and its inverse such as ``log`` and ``exp``. The computation during ``fit`` is:: regressor.fit(X, func(y)) or:: regressor.fit(X, transformer.transform(y)) The computation during ``predict`` is:: inverse_func(regressor.predict(X)) or:: transformer.inverse_transform(regressor.predict(X)) Read more in the :ref:`User Guide `. .. versionadded:: 0.20", - "docstring": "Meta-estimator to regress on a transformed target.\n\n Useful for applying a non-linear transformation to the target ``y`` in\n regression problems. This transformation can be given as a Transformer\n such as the QuantileTransformer or as a function and its inverse such as\n ``log`` and ``exp``.\n\n The computation during ``fit`` is::\n\n regressor.fit(X, func(y))\n\n or::\n\n regressor.fit(X, transformer.transform(y))\n\n The computation during ``predict`` is::\n\n inverse_func(regressor.predict(X))\n\n or::\n\n transformer.inverse_transform(regressor.predict(X))\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.20\n\n Parameters\n ----------\n regressor : object, default=None\n Regressor object such as derived from ``RegressorMixin``. This\n regressor will automatically be cloned each time prior to fitting.\n If regressor is ``None``, ``LinearRegression()`` is created and used.\n\n transformer : object, default=None\n Estimator object such as derived from ``TransformerMixin``. Cannot be\n set at the same time as ``func`` and ``inverse_func``. If\n ``transformer`` is ``None`` as well as ``func`` and ``inverse_func``,\n the transformer will be an identity transformer. Note that the\n transformer will be cloned during fitting. Also, the transformer is\n restricting ``y`` to be a numpy array.\n\n func : function, default=None\n Function to apply to ``y`` before passing to ``fit``. Cannot be set at\n the same time as ``transformer``. The function needs to return a\n 2-dimensional array. If ``func`` is ``None``, the function used will be\n the identity function.\n\n inverse_func : function, default=None\n Function to apply to the prediction of the regressor. Cannot be set at\n the same time as ``transformer`` as well. The function needs to return\n a 2-dimensional array. The inverse function is used to return\n predictions to the same space of the original training labels.\n\n check_inverse : bool, default=True\n Whether to check that ``transform`` followed by ``inverse_transform``\n or ``func`` followed by ``inverse_func`` leads to the original targets.\n\n Attributes\n ----------\n regressor_ : object\n Fitted regressor.\n\n transformer_ : object\n Transformer used in ``fit`` and ``predict``.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`. Only defined if the\n underlying regressor exposes such an attribute when fit.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.linear_model import LinearRegression\n >>> from sklearn.compose import TransformedTargetRegressor\n >>> tt = TransformedTargetRegressor(regressor=LinearRegression(),\n ... func=np.log, inverse_func=np.exp)\n >>> X = np.arange(4).reshape(-1, 1)\n >>> y = np.exp(2 * X).ravel()\n >>> tt.fit(X, y)\n TransformedTargetRegressor(...)\n >>> tt.score(X, y)\n 1.0\n >>> tt.regressor_.coef_\n array([2.])\n\n Notes\n -----\n Internally, the target ``y`` is always converted into a 2-dimensional array\n to be used by scikit-learn transformers. At the time of prediction, the\n output will be reshaped to a have the same number of dimensions as ``y``.\n\n See :ref:`examples/compose/plot_transformed_target.py\n `.\n\n ", - "source_code": "\n\nclass TransformedTargetRegressor(RegressorMixin, BaseEstimator):\n \"\"\"Meta-estimator to regress on a transformed target.\n\n Useful for applying a non-linear transformation to the target ``y`` in\n regression problems. This transformation can be given as a Transformer\n such as the QuantileTransformer or as a function and its inverse such as\n ``log`` and ``exp``.\n\n The computation during ``fit`` is::\n\n regressor.fit(X, func(y))\n\n or::\n\n regressor.fit(X, transformer.transform(y))\n\n The computation during ``predict`` is::\n\n inverse_func(regressor.predict(X))\n\n or::\n\n transformer.inverse_transform(regressor.predict(X))\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.20\n\n Parameters\n ----------\n regressor : object, default=None\n Regressor object such as derived from ``RegressorMixin``. This\n regressor will automatically be cloned each time prior to fitting.\n If regressor is ``None``, ``LinearRegression()`` is created and used.\n\n transformer : object, default=None\n Estimator object such as derived from ``TransformerMixin``. Cannot be\n set at the same time as ``func`` and ``inverse_func``. If\n ``transformer`` is ``None`` as well as ``func`` and ``inverse_func``,\n the transformer will be an identity transformer. Note that the\n transformer will be cloned during fitting. Also, the transformer is\n restricting ``y`` to be a numpy array.\n\n func : function, default=None\n Function to apply to ``y`` before passing to ``fit``. Cannot be set at\n the same time as ``transformer``. The function needs to return a\n 2-dimensional array. If ``func`` is ``None``, the function used will be\n the identity function.\n\n inverse_func : function, default=None\n Function to apply to the prediction of the regressor. Cannot be set at\n the same time as ``transformer`` as well. The function needs to return\n a 2-dimensional array. The inverse function is used to return\n predictions to the same space of the original training labels.\n\n check_inverse : bool, default=True\n Whether to check that ``transform`` followed by ``inverse_transform``\n or ``func`` followed by ``inverse_func`` leads to the original targets.\n\n Attributes\n ----------\n regressor_ : object\n Fitted regressor.\n\n transformer_ : object\n Transformer used in ``fit`` and ``predict``.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`. Only defined if the\n underlying regressor exposes such an attribute when fit.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.linear_model import LinearRegression\n >>> from sklearn.compose import TransformedTargetRegressor\n >>> tt = TransformedTargetRegressor(regressor=LinearRegression(),\n ... func=np.log, inverse_func=np.exp)\n >>> X = np.arange(4).reshape(-1, 1)\n >>> y = np.exp(2 * X).ravel()\n >>> tt.fit(X, y)\n TransformedTargetRegressor(...)\n >>> tt.score(X, y)\n 1.0\n >>> tt.regressor_.coef_\n array([2.])\n\n Notes\n -----\n Internally, the target ``y`` is always converted into a 2-dimensional array\n to be used by scikit-learn transformers. At the time of prediction, the\n output will be reshaped to a have the same number of dimensions as ``y``.\n\n See :ref:`examples/compose/plot_transformed_target.py\n `.\n\n \"\"\"\n \n def __init__(self, regressor=None, *, transformer=None, func=None, inverse_func=None, check_inverse=True):\n self.regressor = regressor\n self.transformer = transformer\n self.func = func\n self.inverse_func = inverse_func\n self.check_inverse = check_inverse\n \n def _fit_transformer(self, y):\n \"\"\"Check transformer and fit transformer.\n\n Create the default transformer, fit it and make additional inverse\n check on a subset (optional).\n\n \"\"\"\n if self.transformer is not None and (self.func is not None or self.inverse_func is not None):\n raise ValueError(\"'transformer' and functions 'func'/'inverse_func' cannot both be set.\")\n elif self.transformer is not None:\n self.transformer_ = clone(self.transformer)\n else:\n if self.func is not None and self.inverse_func is None:\n raise ValueError(\"When 'func' is provided, 'inverse_func' must also be provided\")\n self.transformer_ = FunctionTransformer(func=self.func, inverse_func=self.inverse_func, validate=True, check_inverse=self.check_inverse)\n self.transformer_.fit(y)\n if self.check_inverse:\n idx_selected = slice(None, None, max(1, y.shape[0] // 10))\n y_sel = _safe_indexing(y, idx_selected)\n y_sel_t = self.transformer_.transform(y_sel)\n if not np.allclose(y_sel, self.transformer_.inverse_transform(y_sel_t)):\n warnings.warn(\"The provided functions or transformer are not strictly inverse of each other. If you are sure you want to proceed regardless, set 'check_inverse=False'\", UserWarning)\n \n def fit(self, X, y, **fit_params):\n \"\"\"Fit the model according to the given training data.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target values.\n\n **fit_params : dict\n Parameters passed to the ``fit`` method of the underlying\n regressor.\n\n\n Returns\n -------\n self : object\n \"\"\"\n y = check_array(y, accept_sparse=False, force_all_finite=True, ensure_2d=False, dtype='numeric', allow_nd=True)\n self._training_dim = y.ndim\n if y.ndim == 1:\n y_2d = y.reshape(-1, 1)\n else:\n y_2d = y\n self._fit_transformer(y_2d)\n y_trans = self.transformer_.transform(y_2d)\n if y_trans.ndim == 2 and y_trans.shape[1] == 1:\n y_trans = y_trans.squeeze(axis=1)\n if self.regressor is None:\n from ..linear_model import LinearRegression\n self.regressor_ = LinearRegression()\n else:\n self.regressor_ = clone(self.regressor)\n self.regressor_.fit(X, y_trans, **fit_params)\n if hasattr(self.regressor_, 'feature_names_in_'):\n self.feature_names_in_ = self.regressor_.feature_names_in_\n return self\n \n def predict(self, X, **predict_params):\n \"\"\"Predict using the base regressor, applying inverse.\n\n The regressor is used to predict and the ``inverse_func`` or\n ``inverse_transform`` is applied before returning the prediction.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Samples.\n\n **predict_params : dict of str -> object\n Parameters passed to the `predict` method of the underlying\n regressor.\n\n Returns\n -------\n y_hat : ndarray of shape (n_samples,)\n Predicted values.\n\n \"\"\"\n check_is_fitted(self)\n pred = self.regressor_.predict(X, **predict_params)\n if pred.ndim == 1:\n pred_trans = self.transformer_.inverse_transform(pred.reshape(-1, 1))\n else:\n pred_trans = self.transformer_.inverse_transform(pred)\n if self._training_dim == 1 and pred_trans.ndim == 2 and pred_trans.shape[1] == 1:\n pred_trans = pred_trans.squeeze(axis=1)\n return pred_trans\n \n def _more_tags(self):\n regressor = self.regressor\n if regressor is None:\n from ..linear_model import LinearRegression\n regressor = LinearRegression()\n return {'poor_score': True, 'multioutput': _safe_tags(regressor, key='multioutput')}\n \n @property\n def n_features_in_(self):\n try:\n check_is_fitted(self)\n except NotFittedError as nfe:\n raise AttributeError('{} object has no n_features_in_ attribute.'.format(self.__class__.__name__)) from nfe\n return self.regressor_.n_features_in_\n" + "description": "Meta-estimator to regress on a transformed target.\n\nUseful for applying a non-linear transformation to the target `y` in regression problems. This transformation can be given as a Transformer such as the :class:`~sklearn.preprocessing.QuantileTransformer` or as a function and its inverse such as `np.log` and `np.exp`. The computation during :meth:`fit` is:: regressor.fit(X, func(y)) or:: regressor.fit(X, transformer.transform(y)) The computation during :meth:`predict` is:: inverse_func(regressor.predict(X)) or:: transformer.inverse_transform(regressor.predict(X)) Read more in the :ref:`User Guide `. .. versionadded:: 0.20", + "docstring": "Meta-estimator to regress on a transformed target.\n\n Useful for applying a non-linear transformation to the target `y` in\n regression problems. This transformation can be given as a Transformer\n such as the :class:`~sklearn.preprocessing.QuantileTransformer` or as a\n function and its inverse such as `np.log` and `np.exp`.\n\n The computation during :meth:`fit` is::\n\n regressor.fit(X, func(y))\n\n or::\n\n regressor.fit(X, transformer.transform(y))\n\n The computation during :meth:`predict` is::\n\n inverse_func(regressor.predict(X))\n\n or::\n\n transformer.inverse_transform(regressor.predict(X))\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.20\n\n Parameters\n ----------\n regressor : object, default=None\n Regressor object such as derived from\n :class:`~sklearn.base.RegressorMixin`. This regressor will\n automatically be cloned each time prior to fitting. If `regressor is\n None`, :class:`~sklearn.linear_model.LinearRegression` is created and used.\n\n transformer : object, default=None\n Estimator object such as derived from\n :class:`~sklearn.base.TransformerMixin`. Cannot be set at the same time\n as `func` and `inverse_func`. If `transformer is None` as well as\n `func` and `inverse_func`, the transformer will be an identity\n transformer. Note that the transformer will be cloned during fitting.\n Also, the transformer is restricting `y` to be a numpy array.\n\n func : function, default=None\n Function to apply to `y` before passing to :meth:`fit`. Cannot be set\n at the same time as `transformer`. The function needs to return a\n 2-dimensional array. If `func is None`, the function used will be the\n identity function.\n\n inverse_func : function, default=None\n Function to apply to the prediction of the regressor. Cannot be set at\n the same time as `transformer`. The function needs to return a\n 2-dimensional array. The inverse function is used to return\n predictions to the same space of the original training labels.\n\n check_inverse : bool, default=True\n Whether to check that `transform` followed by `inverse_transform`\n or `func` followed by `inverse_func` leads to the original targets.\n\n Attributes\n ----------\n regressor_ : object\n Fitted regressor.\n\n transformer_ : object\n Transformer used in :meth:`fit` and :meth:`predict`.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`. Only defined if the\n underlying regressor exposes such an attribute when fit.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n sklearn.preprocessing.FunctionTransformer : Construct a transformer from an\n arbitrary callable.\n\n Notes\n -----\n Internally, the target `y` is always converted into a 2-dimensional array\n to be used by scikit-learn transformers. At the time of prediction, the\n output will be reshaped to a have the same number of dimensions as `y`.\n\n See :ref:`examples/compose/plot_transformed_target.py\n `.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.linear_model import LinearRegression\n >>> from sklearn.compose import TransformedTargetRegressor\n >>> tt = TransformedTargetRegressor(regressor=LinearRegression(),\n ... func=np.log, inverse_func=np.exp)\n >>> X = np.arange(4).reshape(-1, 1)\n >>> y = np.exp(2 * X).ravel()\n >>> tt.fit(X, y)\n TransformedTargetRegressor(...)\n >>> tt.score(X, y)\n 1.0\n >>> tt.regressor_.coef_\n array([2.])\n ", + "source_code": "\n\nclass TransformedTargetRegressor(RegressorMixin, BaseEstimator):\n \"\"\"Meta-estimator to regress on a transformed target.\n\n Useful for applying a non-linear transformation to the target `y` in\n regression problems. This transformation can be given as a Transformer\n such as the :class:`~sklearn.preprocessing.QuantileTransformer` or as a\n function and its inverse such as `np.log` and `np.exp`.\n\n The computation during :meth:`fit` is::\n\n regressor.fit(X, func(y))\n\n or::\n\n regressor.fit(X, transformer.transform(y))\n\n The computation during :meth:`predict` is::\n\n inverse_func(regressor.predict(X))\n\n or::\n\n transformer.inverse_transform(regressor.predict(X))\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.20\n\n Parameters\n ----------\n regressor : object, default=None\n Regressor object such as derived from\n :class:`~sklearn.base.RegressorMixin`. This regressor will\n automatically be cloned each time prior to fitting. If `regressor is\n None`, :class:`~sklearn.linear_model.LinearRegression` is created and used.\n\n transformer : object, default=None\n Estimator object such as derived from\n :class:`~sklearn.base.TransformerMixin`. Cannot be set at the same time\n as `func` and `inverse_func`. If `transformer is None` as well as\n `func` and `inverse_func`, the transformer will be an identity\n transformer. Note that the transformer will be cloned during fitting.\n Also, the transformer is restricting `y` to be a numpy array.\n\n func : function, default=None\n Function to apply to `y` before passing to :meth:`fit`. Cannot be set\n at the same time as `transformer`. The function needs to return a\n 2-dimensional array. If `func is None`, the function used will be the\n identity function.\n\n inverse_func : function, default=None\n Function to apply to the prediction of the regressor. Cannot be set at\n the same time as `transformer`. The function needs to return a\n 2-dimensional array. The inverse function is used to return\n predictions to the same space of the original training labels.\n\n check_inverse : bool, default=True\n Whether to check that `transform` followed by `inverse_transform`\n or `func` followed by `inverse_func` leads to the original targets.\n\n Attributes\n ----------\n regressor_ : object\n Fitted regressor.\n\n transformer_ : object\n Transformer used in :meth:`fit` and :meth:`predict`.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`. Only defined if the\n underlying regressor exposes such an attribute when fit.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n sklearn.preprocessing.FunctionTransformer : Construct a transformer from an\n arbitrary callable.\n\n Notes\n -----\n Internally, the target `y` is always converted into a 2-dimensional array\n to be used by scikit-learn transformers. At the time of prediction, the\n output will be reshaped to a have the same number of dimensions as `y`.\n\n See :ref:`examples/compose/plot_transformed_target.py\n `.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.linear_model import LinearRegression\n >>> from sklearn.compose import TransformedTargetRegressor\n >>> tt = TransformedTargetRegressor(regressor=LinearRegression(),\n ... func=np.log, inverse_func=np.exp)\n >>> X = np.arange(4).reshape(-1, 1)\n >>> y = np.exp(2 * X).ravel()\n >>> tt.fit(X, y)\n TransformedTargetRegressor(...)\n >>> tt.score(X, y)\n 1.0\n >>> tt.regressor_.coef_\n array([2.])\n \"\"\"\n \n def __init__(self, regressor=None, *, transformer=None, func=None, inverse_func=None, check_inverse=True):\n self.regressor = regressor\n self.transformer = transformer\n self.func = func\n self.inverse_func = inverse_func\n self.check_inverse = check_inverse\n \n def _fit_transformer(self, y):\n \"\"\"Check transformer and fit transformer.\n\n Create the default transformer, fit it and make additional inverse\n check on a subset (optional).\n\n \"\"\"\n if self.transformer is not None and (self.func is not None or self.inverse_func is not None):\n raise ValueError(\"'transformer' and functions 'func'/'inverse_func' cannot both be set.\")\n elif self.transformer is not None:\n self.transformer_ = clone(self.transformer)\n else:\n if self.func is not None and self.inverse_func is None:\n raise ValueError(\"When 'func' is provided, 'inverse_func' must also be provided\")\n self.transformer_ = FunctionTransformer(func=self.func, inverse_func=self.inverse_func, validate=True, check_inverse=self.check_inverse)\n self.transformer_.fit(y)\n if self.check_inverse:\n idx_selected = slice(None, None, max(1, y.shape[0] // 10))\n y_sel = _safe_indexing(y, idx_selected)\n y_sel_t = self.transformer_.transform(y_sel)\n if not np.allclose(y_sel, self.transformer_.inverse_transform(y_sel_t)):\n warnings.warn(\"The provided functions or transformer are not strictly inverse of each other. If you are sure you want to proceed regardless, set 'check_inverse=False'\", UserWarning)\n \n def fit(self, X, y, **fit_params):\n \"\"\"Fit the model according to the given training data.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target values.\n\n **fit_params : dict\n Parameters passed to the `fit` method of the underlying\n regressor.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n y = check_array(y, accept_sparse=False, force_all_finite=True, ensure_2d=False, dtype='numeric', allow_nd=True)\n self._training_dim = y.ndim\n if y.ndim == 1:\n y_2d = y.reshape(-1, 1)\n else:\n y_2d = y\n self._fit_transformer(y_2d)\n y_trans = self.transformer_.transform(y_2d)\n if y_trans.ndim == 2 and y_trans.shape[1] == 1:\n y_trans = y_trans.squeeze(axis=1)\n if self.regressor is None:\n from ..linear_model import LinearRegression\n self.regressor_ = LinearRegression()\n else:\n self.regressor_ = clone(self.regressor)\n self.regressor_.fit(X, y_trans, **fit_params)\n if hasattr(self.regressor_, 'feature_names_in_'):\n self.feature_names_in_ = self.regressor_.feature_names_in_\n return self\n \n def predict(self, X, **predict_params):\n \"\"\"Predict using the base regressor, applying inverse.\n\n The regressor is used to predict and the `inverse_func` or\n `inverse_transform` is applied before returning the prediction.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Samples.\n\n **predict_params : dict of str -> object\n Parameters passed to the `predict` method of the underlying\n regressor.\n\n Returns\n -------\n y_hat : ndarray of shape (n_samples,)\n Predicted values.\n \"\"\"\n check_is_fitted(self)\n pred = self.regressor_.predict(X, **predict_params)\n if pred.ndim == 1:\n pred_trans = self.transformer_.inverse_transform(pred.reshape(-1, 1))\n else:\n pred_trans = self.transformer_.inverse_transform(pred)\n if self._training_dim == 1 and pred_trans.ndim == 2 and pred_trans.shape[1] == 1:\n pred_trans = pred_trans.squeeze(axis=1)\n return pred_trans\n \n def _more_tags(self):\n regressor = self.regressor\n if regressor is None:\n from ..linear_model import LinearRegression\n regressor = LinearRegression()\n return {'poor_score': True, 'multioutput': _safe_tags(regressor, key='multioutput')}\n \n @property\n def n_features_in_(self):\n \"\"\"Number of features seen during :term:`fit`.\"\"\"\n try:\n check_is_fitted(self)\n except NotFittedError as nfe:\n raise AttributeError('{} object has no n_features_in_ attribute.'.format(self.__class__.__name__)) from nfe\n return self.regressor_.n_features_in_\n" }, { "name": "EllipticEnvelope", @@ -20230,8 +20197,8 @@ ], "is_public": true, "description": "An object for detecting outliers in a Gaussian distributed dataset.\n\nRead more in the :ref:`User Guide `.", - "docstring": "An object for detecting outliers in a Gaussian distributed dataset.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n store_precision : bool, default=True\n Specify if the estimated precision is stored.\n\n assume_centered : bool, default=False\n If True, the support of robust location and covariance estimates\n is computed, and a covariance estimate is recomputed from it,\n without centering the data.\n Useful to work with data whose mean is significantly equal to\n zero but is not exactly zero.\n If False, the robust location and covariance are directly computed\n with the FastMCD algorithm without additional treatment.\n\n support_fraction : float, default=None\n The proportion of points to be included in the support of the raw\n MCD estimate. If None, the minimum value of support_fraction will\n be used within the algorithm: `[n_sample + n_features + 1] / 2`.\n Range is (0, 1).\n\n contamination : float, default=0.1\n The amount of contamination of the data set, i.e. the proportion\n of outliers in the data set. Range is (0, 0.5].\n\n random_state : int, RandomState instance or None, default=None\n Determines the pseudo random number generator for shuffling\n the data. Pass an int for reproducible results across multiple function\n calls. See :term: `Glossary `.\n\n Attributes\n ----------\n location_ : ndarray of shape (n_features,)\n Estimated robust location.\n\n covariance_ : ndarray of shape (n_features, n_features)\n Estimated robust covariance matrix.\n\n precision_ : ndarray of shape (n_features, n_features)\n Estimated pseudo inverse matrix.\n (stored only if store_precision is True)\n\n support_ : ndarray of shape (n_samples,)\n A mask of the observations that have been used to compute the\n robust estimates of location and shape.\n\n offset_ : float\n Offset used to define the decision function from the raw scores.\n We have the relation: ``decision_function = score_samples - offset_``.\n The offset depends on the contamination parameter and is defined in\n such a way we obtain the expected number of outliers (samples with\n decision function < 0) in training.\n\n .. versionadded:: 0.20\n\n raw_location_ : ndarray of shape (n_features,)\n The raw robust estimated location before correction and re-weighting.\n\n raw_covariance_ : ndarray of shape (n_features, n_features)\n The raw robust estimated covariance before correction and re-weighting.\n\n raw_support_ : ndarray of shape (n_samples,)\n A mask of the observations that have been used to compute\n the raw robust estimates of location and shape, before correction\n and re-weighting.\n\n dist_ : ndarray of shape (n_samples,)\n Mahalanobis distances of the training set (on which :meth:`fit` is\n called) observations.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n EmpiricalCovariance : Maximum likelihood covariance estimator.\n GraphicalLasso : Sparse inverse covariance estimation\n with an l1-penalized estimator.\n LedoitWolf : LedoitWolf Estimator.\n MinCovDet : Minimum Covariance Determinant\n (robust estimator of covariance).\n OAS : Oracle Approximating Shrinkage Estimator.\n ShrunkCovariance : Covariance estimator with shrinkage.\n\n Notes\n -----\n Outlier detection from covariance estimation may break or not\n perform well in high-dimensional settings. In particular, one will\n always take care to work with ``n_samples > n_features ** 2``.\n\n References\n ----------\n .. [1] Rousseeuw, P.J., Van Driessen, K. \"A fast algorithm for the\n minimum covariance determinant estimator\" Technometrics 41(3), 212\n (1999)\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.covariance import EllipticEnvelope\n >>> true_cov = np.array([[.8, .3],\n ... [.3, .4]])\n >>> X = np.random.RandomState(0).multivariate_normal(mean=[0, 0],\n ... cov=true_cov,\n ... size=500)\n >>> cov = EllipticEnvelope(random_state=0).fit(X)\n >>> # predict returns 1 for an inlier and -1 for an outlier\n >>> cov.predict([[0, 0],\n ... [3, 3]])\n array([ 1, -1])\n >>> cov.covariance_\n array([[0.7411..., 0.2535...],\n [0.2535..., 0.3053...]])\n >>> cov.location_\n array([0.0813... , 0.0427...])\n ", - "source_code": "\n\nclass EllipticEnvelope(OutlierMixin, MinCovDet):\n \"\"\"An object for detecting outliers in a Gaussian distributed dataset.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n store_precision : bool, default=True\n Specify if the estimated precision is stored.\n\n assume_centered : bool, default=False\n If True, the support of robust location and covariance estimates\n is computed, and a covariance estimate is recomputed from it,\n without centering the data.\n Useful to work with data whose mean is significantly equal to\n zero but is not exactly zero.\n If False, the robust location and covariance are directly computed\n with the FastMCD algorithm without additional treatment.\n\n support_fraction : float, default=None\n The proportion of points to be included in the support of the raw\n MCD estimate. If None, the minimum value of support_fraction will\n be used within the algorithm: `[n_sample + n_features + 1] / 2`.\n Range is (0, 1).\n\n contamination : float, default=0.1\n The amount of contamination of the data set, i.e. the proportion\n of outliers in the data set. Range is (0, 0.5].\n\n random_state : int, RandomState instance or None, default=None\n Determines the pseudo random number generator for shuffling\n the data. Pass an int for reproducible results across multiple function\n calls. See :term: `Glossary `.\n\n Attributes\n ----------\n location_ : ndarray of shape (n_features,)\n Estimated robust location.\n\n covariance_ : ndarray of shape (n_features, n_features)\n Estimated robust covariance matrix.\n\n precision_ : ndarray of shape (n_features, n_features)\n Estimated pseudo inverse matrix.\n (stored only if store_precision is True)\n\n support_ : ndarray of shape (n_samples,)\n A mask of the observations that have been used to compute the\n robust estimates of location and shape.\n\n offset_ : float\n Offset used to define the decision function from the raw scores.\n We have the relation: ``decision_function = score_samples - offset_``.\n The offset depends on the contamination parameter and is defined in\n such a way we obtain the expected number of outliers (samples with\n decision function < 0) in training.\n\n .. versionadded:: 0.20\n\n raw_location_ : ndarray of shape (n_features,)\n The raw robust estimated location before correction and re-weighting.\n\n raw_covariance_ : ndarray of shape (n_features, n_features)\n The raw robust estimated covariance before correction and re-weighting.\n\n raw_support_ : ndarray of shape (n_samples,)\n A mask of the observations that have been used to compute\n the raw robust estimates of location and shape, before correction\n and re-weighting.\n\n dist_ : ndarray of shape (n_samples,)\n Mahalanobis distances of the training set (on which :meth:`fit` is\n called) observations.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n EmpiricalCovariance : Maximum likelihood covariance estimator.\n GraphicalLasso : Sparse inverse covariance estimation\n with an l1-penalized estimator.\n LedoitWolf : LedoitWolf Estimator.\n MinCovDet : Minimum Covariance Determinant\n (robust estimator of covariance).\n OAS : Oracle Approximating Shrinkage Estimator.\n ShrunkCovariance : Covariance estimator with shrinkage.\n\n Notes\n -----\n Outlier detection from covariance estimation may break or not\n perform well in high-dimensional settings. In particular, one will\n always take care to work with ``n_samples > n_features ** 2``.\n\n References\n ----------\n .. [1] Rousseeuw, P.J., Van Driessen, K. \"A fast algorithm for the\n minimum covariance determinant estimator\" Technometrics 41(3), 212\n (1999)\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.covariance import EllipticEnvelope\n >>> true_cov = np.array([[.8, .3],\n ... [.3, .4]])\n >>> X = np.random.RandomState(0).multivariate_normal(mean=[0, 0],\n ... cov=true_cov,\n ... size=500)\n >>> cov = EllipticEnvelope(random_state=0).fit(X)\n >>> # predict returns 1 for an inlier and -1 for an outlier\n >>> cov.predict([[0, 0],\n ... [3, 3]])\n array([ 1, -1])\n >>> cov.covariance_\n array([[0.7411..., 0.2535...],\n [0.2535..., 0.3053...]])\n >>> cov.location_\n array([0.0813... , 0.0427...])\n \"\"\"\n \n def __init__(self, *, store_precision=True, assume_centered=False, support_fraction=None, contamination=0.1, random_state=None):\n super().__init__(store_precision=store_precision, assume_centered=assume_centered, support_fraction=support_fraction, random_state=random_state)\n self.contamination = contamination\n \n def fit(self, X, y=None):\n \"\"\"Fit the EllipticEnvelope model.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training data.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n if self.contamination != 'auto':\n if not 0.0 < self.contamination <= 0.5:\n raise ValueError('contamination must be in (0, 0.5], got: %f' % self.contamination)\n super().fit(X)\n self.offset_ = np.percentile(-self.dist_, 100.0 * self.contamination)\n return self\n \n def decision_function(self, X):\n \"\"\"Compute the decision function of the given observations.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data matrix.\n\n Returns\n -------\n decision : ndarray of shape (n_samples,)\n Decision function of the samples.\n It is equal to the shifted Mahalanobis distances.\n The threshold for being an outlier is 0, which ensures a\n compatibility with other outlier detection algorithms.\n \"\"\"\n check_is_fitted(self)\n negative_mahal_dist = self.score_samples(X)\n return negative_mahal_dist - self.offset_\n \n def score_samples(self, X):\n \"\"\"Compute the negative Mahalanobis distances.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data matrix.\n\n Returns\n -------\n negative_mahal_distances : array-like of shape (n_samples,)\n Opposite of the Mahalanobis distances.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, reset=False)\n return -self.mahalanobis(X)\n \n def predict(self, X):\n \"\"\"\n Predict labels (1 inlier, -1 outlier) of X according to fitted model.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data matrix.\n\n Returns\n -------\n is_inlier : ndarray of shape (n_samples,)\n Returns -1 for anomalies/outliers and +1 for inliers.\n \"\"\"\n values = self.decision_function(X)\n is_inlier = np.full(values.shape[0], -1, dtype=int)\n is_inlier[values >= 0] = 1\n return is_inlier\n \n def score(self, X, y, sample_weight=None):\n \"\"\"Return the mean accuracy on the given test data and labels.\n\n In multi-label classification, this is the subset accuracy\n which is a harsh metric since you require for each sample that\n each label set be correctly predicted.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Test samples.\n\n y : array-like of shape (n_samples,) or (n_samples, n_outputs)\n True labels for X.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights.\n\n Returns\n -------\n score : float\n Mean accuracy of self.predict(X) w.r.t. y.\n \"\"\"\n return accuracy_score(y, self.predict(X), sample_weight=sample_weight)\n" + "docstring": "An object for detecting outliers in a Gaussian distributed dataset.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n store_precision : bool, default=True\n Specify if the estimated precision is stored.\n\n assume_centered : bool, default=False\n If True, the support of robust location and covariance estimates\n is computed, and a covariance estimate is recomputed from it,\n without centering the data.\n Useful to work with data whose mean is significantly equal to\n zero but is not exactly zero.\n If False, the robust location and covariance are directly computed\n with the FastMCD algorithm without additional treatment.\n\n support_fraction : float, default=None\n The proportion of points to be included in the support of the raw\n MCD estimate. If None, the minimum value of support_fraction will\n be used within the algorithm: `[n_sample + n_features + 1] / 2`.\n Range is (0, 1).\n\n contamination : float, default=0.1\n The amount of contamination of the data set, i.e. the proportion\n of outliers in the data set. Range is (0, 0.5].\n\n random_state : int, RandomState instance or None, default=None\n Determines the pseudo random number generator for shuffling\n the data. Pass an int for reproducible results across multiple function\n calls. See :term:`Glossary `.\n\n Attributes\n ----------\n location_ : ndarray of shape (n_features,)\n Estimated robust location.\n\n covariance_ : ndarray of shape (n_features, n_features)\n Estimated robust covariance matrix.\n\n precision_ : ndarray of shape (n_features, n_features)\n Estimated pseudo inverse matrix.\n (stored only if store_precision is True)\n\n support_ : ndarray of shape (n_samples,)\n A mask of the observations that have been used to compute the\n robust estimates of location and shape.\n\n offset_ : float\n Offset used to define the decision function from the raw scores.\n We have the relation: ``decision_function = score_samples - offset_``.\n The offset depends on the contamination parameter and is defined in\n such a way we obtain the expected number of outliers (samples with\n decision function < 0) in training.\n\n .. versionadded:: 0.20\n\n raw_location_ : ndarray of shape (n_features,)\n The raw robust estimated location before correction and re-weighting.\n\n raw_covariance_ : ndarray of shape (n_features, n_features)\n The raw robust estimated covariance before correction and re-weighting.\n\n raw_support_ : ndarray of shape (n_samples,)\n A mask of the observations that have been used to compute\n the raw robust estimates of location and shape, before correction\n and re-weighting.\n\n dist_ : ndarray of shape (n_samples,)\n Mahalanobis distances of the training set (on which :meth:`fit` is\n called) observations.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n EmpiricalCovariance : Maximum likelihood covariance estimator.\n GraphicalLasso : Sparse inverse covariance estimation\n with an l1-penalized estimator.\n LedoitWolf : LedoitWolf Estimator.\n MinCovDet : Minimum Covariance Determinant\n (robust estimator of covariance).\n OAS : Oracle Approximating Shrinkage Estimator.\n ShrunkCovariance : Covariance estimator with shrinkage.\n\n Notes\n -----\n Outlier detection from covariance estimation may break or not\n perform well in high-dimensional settings. In particular, one will\n always take care to work with ``n_samples > n_features ** 2``.\n\n References\n ----------\n .. [1] Rousseeuw, P.J., Van Driessen, K. \"A fast algorithm for the\n minimum covariance determinant estimator\" Technometrics 41(3), 212\n (1999)\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.covariance import EllipticEnvelope\n >>> true_cov = np.array([[.8, .3],\n ... [.3, .4]])\n >>> X = np.random.RandomState(0).multivariate_normal(mean=[0, 0],\n ... cov=true_cov,\n ... size=500)\n >>> cov = EllipticEnvelope(random_state=0).fit(X)\n >>> # predict returns 1 for an inlier and -1 for an outlier\n >>> cov.predict([[0, 0],\n ... [3, 3]])\n array([ 1, -1])\n >>> cov.covariance_\n array([[0.7411..., 0.2535...],\n [0.2535..., 0.3053...]])\n >>> cov.location_\n array([0.0813... , 0.0427...])\n ", + "source_code": "\n\nclass EllipticEnvelope(OutlierMixin, MinCovDet):\n \"\"\"An object for detecting outliers in a Gaussian distributed dataset.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n store_precision : bool, default=True\n Specify if the estimated precision is stored.\n\n assume_centered : bool, default=False\n If True, the support of robust location and covariance estimates\n is computed, and a covariance estimate is recomputed from it,\n without centering the data.\n Useful to work with data whose mean is significantly equal to\n zero but is not exactly zero.\n If False, the robust location and covariance are directly computed\n with the FastMCD algorithm without additional treatment.\n\n support_fraction : float, default=None\n The proportion of points to be included in the support of the raw\n MCD estimate. If None, the minimum value of support_fraction will\n be used within the algorithm: `[n_sample + n_features + 1] / 2`.\n Range is (0, 1).\n\n contamination : float, default=0.1\n The amount of contamination of the data set, i.e. the proportion\n of outliers in the data set. Range is (0, 0.5].\n\n random_state : int, RandomState instance or None, default=None\n Determines the pseudo random number generator for shuffling\n the data. Pass an int for reproducible results across multiple function\n calls. See :term:`Glossary `.\n\n Attributes\n ----------\n location_ : ndarray of shape (n_features,)\n Estimated robust location.\n\n covariance_ : ndarray of shape (n_features, n_features)\n Estimated robust covariance matrix.\n\n precision_ : ndarray of shape (n_features, n_features)\n Estimated pseudo inverse matrix.\n (stored only if store_precision is True)\n\n support_ : ndarray of shape (n_samples,)\n A mask of the observations that have been used to compute the\n robust estimates of location and shape.\n\n offset_ : float\n Offset used to define the decision function from the raw scores.\n We have the relation: ``decision_function = score_samples - offset_``.\n The offset depends on the contamination parameter and is defined in\n such a way we obtain the expected number of outliers (samples with\n decision function < 0) in training.\n\n .. versionadded:: 0.20\n\n raw_location_ : ndarray of shape (n_features,)\n The raw robust estimated location before correction and re-weighting.\n\n raw_covariance_ : ndarray of shape (n_features, n_features)\n The raw robust estimated covariance before correction and re-weighting.\n\n raw_support_ : ndarray of shape (n_samples,)\n A mask of the observations that have been used to compute\n the raw robust estimates of location and shape, before correction\n and re-weighting.\n\n dist_ : ndarray of shape (n_samples,)\n Mahalanobis distances of the training set (on which :meth:`fit` is\n called) observations.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n EmpiricalCovariance : Maximum likelihood covariance estimator.\n GraphicalLasso : Sparse inverse covariance estimation\n with an l1-penalized estimator.\n LedoitWolf : LedoitWolf Estimator.\n MinCovDet : Minimum Covariance Determinant\n (robust estimator of covariance).\n OAS : Oracle Approximating Shrinkage Estimator.\n ShrunkCovariance : Covariance estimator with shrinkage.\n\n Notes\n -----\n Outlier detection from covariance estimation may break or not\n perform well in high-dimensional settings. In particular, one will\n always take care to work with ``n_samples > n_features ** 2``.\n\n References\n ----------\n .. [1] Rousseeuw, P.J., Van Driessen, K. \"A fast algorithm for the\n minimum covariance determinant estimator\" Technometrics 41(3), 212\n (1999)\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.covariance import EllipticEnvelope\n >>> true_cov = np.array([[.8, .3],\n ... [.3, .4]])\n >>> X = np.random.RandomState(0).multivariate_normal(mean=[0, 0],\n ... cov=true_cov,\n ... size=500)\n >>> cov = EllipticEnvelope(random_state=0).fit(X)\n >>> # predict returns 1 for an inlier and -1 for an outlier\n >>> cov.predict([[0, 0],\n ... [3, 3]])\n array([ 1, -1])\n >>> cov.covariance_\n array([[0.7411..., 0.2535...],\n [0.2535..., 0.3053...]])\n >>> cov.location_\n array([0.0813... , 0.0427...])\n \"\"\"\n \n def __init__(self, *, store_precision=True, assume_centered=False, support_fraction=None, contamination=0.1, random_state=None):\n super().__init__(store_precision=store_precision, assume_centered=assume_centered, support_fraction=support_fraction, random_state=random_state)\n self.contamination = contamination\n \n def fit(self, X, y=None):\n \"\"\"Fit the EllipticEnvelope model.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training data.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n if self.contamination != 'auto':\n if not 0.0 < self.contamination <= 0.5:\n raise ValueError('contamination must be in (0, 0.5], got: %f' % self.contamination)\n super().fit(X)\n self.offset_ = np.percentile(-self.dist_, 100.0 * self.contamination)\n return self\n \n def decision_function(self, X):\n \"\"\"Compute the decision function of the given observations.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data matrix.\n\n Returns\n -------\n decision : ndarray of shape (n_samples,)\n Decision function of the samples.\n It is equal to the shifted Mahalanobis distances.\n The threshold for being an outlier is 0, which ensures a\n compatibility with other outlier detection algorithms.\n \"\"\"\n check_is_fitted(self)\n negative_mahal_dist = self.score_samples(X)\n return negative_mahal_dist - self.offset_\n \n def score_samples(self, X):\n \"\"\"Compute the negative Mahalanobis distances.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data matrix.\n\n Returns\n -------\n negative_mahal_distances : array-like of shape (n_samples,)\n Opposite of the Mahalanobis distances.\n \"\"\"\n check_is_fitted(self)\n return -self.mahalanobis(X)\n \n def predict(self, X):\n \"\"\"\n Predict labels (1 inlier, -1 outlier) of X according to fitted model.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data matrix.\n\n Returns\n -------\n is_inlier : ndarray of shape (n_samples,)\n Returns -1 for anomalies/outliers and +1 for inliers.\n \"\"\"\n values = self.decision_function(X)\n is_inlier = np.full(values.shape[0], -1, dtype=int)\n is_inlier[values >= 0] = 1\n return is_inlier\n \n def score(self, X, y, sample_weight=None):\n \"\"\"Return the mean accuracy on the given test data and labels.\n\n In multi-label classification, this is the subset accuracy\n which is a harsh metric since you require for each sample that\n each label set be correctly predicted.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Test samples.\n\n y : array-like of shape (n_samples,) or (n_samples, n_outputs)\n True labels for X.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights.\n\n Returns\n -------\n score : float\n Mean accuracy of self.predict(X) w.r.t. y.\n \"\"\"\n return accuracy_score(y, self.predict(X), sample_weight=sample_weight)\n" }, { "name": "EmpiricalCovariance", @@ -20274,8 +20241,8 @@ "methods": [ "sklearn.covariance._graph_lasso.GraphicalLassoCV.__init__", "sklearn.covariance._graph_lasso.GraphicalLassoCV.fit", - "sklearn.covariance._graph_lasso.GraphicalLassoCV.grid_scores_", - "sklearn.covariance._graph_lasso.GraphicalLassoCV.cv_alphas_" + "sklearn.covariance._graph_lasso.GraphicalLassoCV.grid_scores_@getter", + "sklearn.covariance._graph_lasso.GraphicalLassoCV.cv_alphas_@getter" ], "is_public": true, "description": "Sparse inverse covariance w/ cross-validated choice of the l1 penalty.\n\nSee glossary entry for :term:`cross-validation estimator`. Read more in the :ref:`User Guide `. .. versionchanged:: v0.20 GraphLassoCV has been renamed to GraphicalLassoCV", @@ -20310,8 +20277,8 @@ ], "is_public": true, "description": "Minimum Covariance Determinant (MCD): robust estimator of covariance.\n\nThe Minimum Covariance Determinant covariance estimator is to be applied on Gaussian-distributed data, but could still be relevant on data drawn from a unimodal, symmetric distribution. It is not meant to be used with multi-modal data (the algorithm used to fit a MinCovDet object is likely to fail in such a case). One should consider projection pursuit methods to deal with multi-modal datasets. Read more in the :ref:`User Guide `.", - "docstring": "Minimum Covariance Determinant (MCD): robust estimator of covariance.\n\n The Minimum Covariance Determinant covariance estimator is to be applied\n on Gaussian-distributed data, but could still be relevant on data\n drawn from a unimodal, symmetric distribution. It is not meant to be used\n with multi-modal data (the algorithm used to fit a MinCovDet object is\n likely to fail in such a case).\n One should consider projection pursuit methods to deal with multi-modal\n datasets.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n store_precision : bool, default=True\n Specify if the estimated precision is stored.\n\n assume_centered : bool, default=False\n If True, the support of the robust location and the covariance\n estimates is computed, and a covariance estimate is recomputed from\n it, without centering the data.\n Useful to work with data whose mean is significantly equal to\n zero but is not exactly zero.\n If False, the robust location and covariance are directly computed\n with the FastMCD algorithm without additional treatment.\n\n support_fraction : float, default=None\n The proportion of points to be included in the support of the raw\n MCD estimate. Default is None, which implies that the minimum\n value of support_fraction will be used within the algorithm:\n `(n_sample + n_features + 1) / 2`. The parameter must be in the range\n (0, 1).\n\n random_state : int, RandomState instance or None, default=None\n Determines the pseudo random number generator for shuffling the data.\n Pass an int for reproducible results across multiple function calls.\n See :term: `Glossary `.\n\n Attributes\n ----------\n raw_location_ : ndarray of shape (n_features,)\n The raw robust estimated location before correction and re-weighting.\n\n raw_covariance_ : ndarray of shape (n_features, n_features)\n The raw robust estimated covariance before correction and re-weighting.\n\n raw_support_ : ndarray of shape (n_samples,)\n A mask of the observations that have been used to compute\n the raw robust estimates of location and shape, before correction\n and re-weighting.\n\n location_ : ndarray of shape (n_features,)\n Estimated robust location.\n\n covariance_ : ndarray of shape (n_features, n_features)\n Estimated robust covariance matrix.\n\n precision_ : ndarray of shape (n_features, n_features)\n Estimated pseudo inverse matrix.\n (stored only if store_precision is True)\n\n support_ : ndarray of shape (n_samples,)\n A mask of the observations that have been used to compute\n the robust estimates of location and shape.\n\n dist_ : ndarray of shape (n_samples,)\n Mahalanobis distances of the training set (on which :meth:`fit` is\n called) observations.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n EllipticEnvelope : An object for detecting outliers in\n a Gaussian distributed dataset.\n EmpiricalCovariance : Maximum likelihood covariance estimator.\n GraphicalLasso : Sparse inverse covariance estimation\n with an l1-penalized estimator.\n GraphicalLassoCV : Sparse inverse covariance with cross-validated\n choice of the l1 penalty.\n LedoitWolf : LedoitWolf Estimator.\n OAS : Oracle Approximating Shrinkage Estimator.\n ShrunkCovariance : Covariance estimator with shrinkage.\n\n References\n ----------\n\n .. [Rouseeuw1984] P. J. Rousseeuw. Least median of squares regression.\n J. Am Stat Ass, 79:871, 1984.\n .. [Rousseeuw] A Fast Algorithm for the Minimum Covariance Determinant\n Estimator, 1999, American Statistical Association and the American\n Society for Quality, TECHNOMETRICS\n .. [ButlerDavies] R. W. Butler, P. L. Davies and M. Jhun,\n Asymptotics For The Minimum Covariance Determinant Estimator,\n The Annals of Statistics, 1993, Vol. 21, No. 3, 1385-1400\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.covariance import MinCovDet\n >>> from sklearn.datasets import make_gaussian_quantiles\n >>> real_cov = np.array([[.8, .3],\n ... [.3, .4]])\n >>> rng = np.random.RandomState(0)\n >>> X = rng.multivariate_normal(mean=[0, 0],\n ... cov=real_cov,\n ... size=500)\n >>> cov = MinCovDet(random_state=0).fit(X)\n >>> cov.covariance_\n array([[0.7411..., 0.2535...],\n [0.2535..., 0.3053...]])\n >>> cov.location_\n array([0.0813... , 0.0427...])\n ", - "source_code": "\n\nclass MinCovDet(EmpiricalCovariance):\n \"\"\"Minimum Covariance Determinant (MCD): robust estimator of covariance.\n\n The Minimum Covariance Determinant covariance estimator is to be applied\n on Gaussian-distributed data, but could still be relevant on data\n drawn from a unimodal, symmetric distribution. It is not meant to be used\n with multi-modal data (the algorithm used to fit a MinCovDet object is\n likely to fail in such a case).\n One should consider projection pursuit methods to deal with multi-modal\n datasets.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n store_precision : bool, default=True\n Specify if the estimated precision is stored.\n\n assume_centered : bool, default=False\n If True, the support of the robust location and the covariance\n estimates is computed, and a covariance estimate is recomputed from\n it, without centering the data.\n Useful to work with data whose mean is significantly equal to\n zero but is not exactly zero.\n If False, the robust location and covariance are directly computed\n with the FastMCD algorithm without additional treatment.\n\n support_fraction : float, default=None\n The proportion of points to be included in the support of the raw\n MCD estimate. Default is None, which implies that the minimum\n value of support_fraction will be used within the algorithm:\n `(n_sample + n_features + 1) / 2`. The parameter must be in the range\n (0, 1).\n\n random_state : int, RandomState instance or None, default=None\n Determines the pseudo random number generator for shuffling the data.\n Pass an int for reproducible results across multiple function calls.\n See :term: `Glossary `.\n\n Attributes\n ----------\n raw_location_ : ndarray of shape (n_features,)\n The raw robust estimated location before correction and re-weighting.\n\n raw_covariance_ : ndarray of shape (n_features, n_features)\n The raw robust estimated covariance before correction and re-weighting.\n\n raw_support_ : ndarray of shape (n_samples,)\n A mask of the observations that have been used to compute\n the raw robust estimates of location and shape, before correction\n and re-weighting.\n\n location_ : ndarray of shape (n_features,)\n Estimated robust location.\n\n covariance_ : ndarray of shape (n_features, n_features)\n Estimated robust covariance matrix.\n\n precision_ : ndarray of shape (n_features, n_features)\n Estimated pseudo inverse matrix.\n (stored only if store_precision is True)\n\n support_ : ndarray of shape (n_samples,)\n A mask of the observations that have been used to compute\n the robust estimates of location and shape.\n\n dist_ : ndarray of shape (n_samples,)\n Mahalanobis distances of the training set (on which :meth:`fit` is\n called) observations.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n EllipticEnvelope : An object for detecting outliers in\n a Gaussian distributed dataset.\n EmpiricalCovariance : Maximum likelihood covariance estimator.\n GraphicalLasso : Sparse inverse covariance estimation\n with an l1-penalized estimator.\n GraphicalLassoCV : Sparse inverse covariance with cross-validated\n choice of the l1 penalty.\n LedoitWolf : LedoitWolf Estimator.\n OAS : Oracle Approximating Shrinkage Estimator.\n ShrunkCovariance : Covariance estimator with shrinkage.\n\n References\n ----------\n\n .. [Rouseeuw1984] P. J. Rousseeuw. Least median of squares regression.\n J. Am Stat Ass, 79:871, 1984.\n .. [Rousseeuw] A Fast Algorithm for the Minimum Covariance Determinant\n Estimator, 1999, American Statistical Association and the American\n Society for Quality, TECHNOMETRICS\n .. [ButlerDavies] R. W. Butler, P. L. Davies and M. Jhun,\n Asymptotics For The Minimum Covariance Determinant Estimator,\n The Annals of Statistics, 1993, Vol. 21, No. 3, 1385-1400\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.covariance import MinCovDet\n >>> from sklearn.datasets import make_gaussian_quantiles\n >>> real_cov = np.array([[.8, .3],\n ... [.3, .4]])\n >>> rng = np.random.RandomState(0)\n >>> X = rng.multivariate_normal(mean=[0, 0],\n ... cov=real_cov,\n ... size=500)\n >>> cov = MinCovDet(random_state=0).fit(X)\n >>> cov.covariance_\n array([[0.7411..., 0.2535...],\n [0.2535..., 0.3053...]])\n >>> cov.location_\n array([0.0813... , 0.0427...])\n \"\"\"\n _nonrobust_covariance = staticmethod(empirical_covariance)\n \n def __init__(self, *, store_precision=True, assume_centered=False, support_fraction=None, random_state=None):\n self.store_precision = store_precision\n self.assume_centered = assume_centered\n self.support_fraction = support_fraction\n self.random_state = random_state\n \n def fit(self, X, y=None):\n \"\"\"Fit a Minimum Covariance Determinant with the FastMCD algorithm.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training data, where `n_samples` is the number of samples\n and `n_features` is the number of features.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n X = self._validate_data(X, ensure_min_samples=2, estimator='MinCovDet')\n random_state = check_random_state(self.random_state)\n (n_samples, n_features) = X.shape\n if (linalg.svdvals(np.dot(X.T, X)) > 1e-08).sum() != n_features:\n warnings.warn('The covariance matrix associated to your dataset is not full rank')\n (raw_location, raw_covariance, raw_support, raw_dist) = fast_mcd(X, support_fraction=self.support_fraction, cov_computation_method=self._nonrobust_covariance, random_state=random_state)\n if self.assume_centered:\n raw_location = np.zeros(n_features)\n raw_covariance = self._nonrobust_covariance(X[raw_support], assume_centered=True)\n precision = linalg.pinvh(raw_covariance)\n raw_dist = np.sum(np.dot(X, precision) * X, 1)\n self.raw_location_ = raw_location\n self.raw_covariance_ = raw_covariance\n self.raw_support_ = raw_support\n self.location_ = raw_location\n self.support_ = raw_support\n self.dist_ = raw_dist\n self.correct_covariance(X)\n self.reweight_covariance(X)\n return self\n \n def correct_covariance(self, data):\n \"\"\"Apply a correction to raw Minimum Covariance Determinant estimates.\n\n Correction using the empirical correction factor suggested\n by Rousseeuw and Van Driessen in [RVD]_.\n\n Parameters\n ----------\n data : array-like of shape (n_samples, n_features)\n The data matrix, with p features and n samples.\n The data set must be the one which was used to compute\n the raw estimates.\n\n Returns\n -------\n covariance_corrected : ndarray of shape (n_features, n_features)\n Corrected robust covariance estimate.\n\n References\n ----------\n\n .. [RVD] A Fast Algorithm for the Minimum Covariance\n Determinant Estimator, 1999, American Statistical Association\n and the American Society for Quality, TECHNOMETRICS\n \"\"\"\n n_samples = len(self.dist_)\n n_support = np.sum(self.support_)\n if n_support < n_samples and np.allclose(self.raw_covariance_, 0):\n raise ValueError('The covariance matrix of the support data is equal to 0, try to increase support_fraction')\n correction = np.median(self.dist_) / chi2(data.shape[1]).isf(0.5)\n covariance_corrected = self.raw_covariance_ * correction\n self.dist_ /= correction\n return covariance_corrected\n \n def reweight_covariance(self, data):\n \"\"\"Re-weight raw Minimum Covariance Determinant estimates.\n\n Re-weight observations using Rousseeuw's method (equivalent to\n deleting outlying observations from the data set before\n computing location and covariance estimates) described\n in [RVDriessen]_.\n\n Parameters\n ----------\n data : array-like of shape (n_samples, n_features)\n The data matrix, with p features and n samples.\n The data set must be the one which was used to compute\n the raw estimates.\n\n Returns\n -------\n location_reweighted : ndarray of shape (n_features,)\n Re-weighted robust location estimate.\n\n covariance_reweighted : ndarray of shape (n_features, n_features)\n Re-weighted robust covariance estimate.\n\n support_reweighted : ndarray of shape (n_samples,), dtype=bool\n A mask of the observations that have been used to compute\n the re-weighted robust location and covariance estimates.\n\n References\n ----------\n\n .. [RVDriessen] A Fast Algorithm for the Minimum Covariance\n Determinant Estimator, 1999, American Statistical Association\n and the American Society for Quality, TECHNOMETRICS\n \"\"\"\n (n_samples, n_features) = data.shape\n mask = self.dist_ < chi2(n_features).isf(0.025)\n if self.assume_centered:\n location_reweighted = np.zeros(n_features)\n else:\n location_reweighted = data[mask].mean(0)\n covariance_reweighted = self._nonrobust_covariance(data[mask], assume_centered=self.assume_centered)\n support_reweighted = np.zeros(n_samples, dtype=bool)\n support_reweighted[mask] = True\n self._set_covariance(covariance_reweighted)\n self.location_ = location_reweighted\n self.support_ = support_reweighted\n X_centered = data - self.location_\n self.dist_ = np.sum(np.dot(X_centered, self.get_precision()) * X_centered, 1)\n return location_reweighted, covariance_reweighted, support_reweighted\n" + "docstring": "Minimum Covariance Determinant (MCD): robust estimator of covariance.\n\n The Minimum Covariance Determinant covariance estimator is to be applied\n on Gaussian-distributed data, but could still be relevant on data\n drawn from a unimodal, symmetric distribution. It is not meant to be used\n with multi-modal data (the algorithm used to fit a MinCovDet object is\n likely to fail in such a case).\n One should consider projection pursuit methods to deal with multi-modal\n datasets.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n store_precision : bool, default=True\n Specify if the estimated precision is stored.\n\n assume_centered : bool, default=False\n If True, the support of the robust location and the covariance\n estimates is computed, and a covariance estimate is recomputed from\n it, without centering the data.\n Useful to work with data whose mean is significantly equal to\n zero but is not exactly zero.\n If False, the robust location and covariance are directly computed\n with the FastMCD algorithm without additional treatment.\n\n support_fraction : float, default=None\n The proportion of points to be included in the support of the raw\n MCD estimate. Default is None, which implies that the minimum\n value of support_fraction will be used within the algorithm:\n `(n_sample + n_features + 1) / 2`. The parameter must be in the range\n (0, 1).\n\n random_state : int, RandomState instance or None, default=None\n Determines the pseudo random number generator for shuffling the data.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n Attributes\n ----------\n raw_location_ : ndarray of shape (n_features,)\n The raw robust estimated location before correction and re-weighting.\n\n raw_covariance_ : ndarray of shape (n_features, n_features)\n The raw robust estimated covariance before correction and re-weighting.\n\n raw_support_ : ndarray of shape (n_samples,)\n A mask of the observations that have been used to compute\n the raw robust estimates of location and shape, before correction\n and re-weighting.\n\n location_ : ndarray of shape (n_features,)\n Estimated robust location.\n\n covariance_ : ndarray of shape (n_features, n_features)\n Estimated robust covariance matrix.\n\n precision_ : ndarray of shape (n_features, n_features)\n Estimated pseudo inverse matrix.\n (stored only if store_precision is True)\n\n support_ : ndarray of shape (n_samples,)\n A mask of the observations that have been used to compute\n the robust estimates of location and shape.\n\n dist_ : ndarray of shape (n_samples,)\n Mahalanobis distances of the training set (on which :meth:`fit` is\n called) observations.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n EllipticEnvelope : An object for detecting outliers in\n a Gaussian distributed dataset.\n EmpiricalCovariance : Maximum likelihood covariance estimator.\n GraphicalLasso : Sparse inverse covariance estimation\n with an l1-penalized estimator.\n GraphicalLassoCV : Sparse inverse covariance with cross-validated\n choice of the l1 penalty.\n LedoitWolf : LedoitWolf Estimator.\n OAS : Oracle Approximating Shrinkage Estimator.\n ShrunkCovariance : Covariance estimator with shrinkage.\n\n References\n ----------\n\n .. [Rouseeuw1984] P. J. Rousseeuw. Least median of squares regression.\n J. Am Stat Ass, 79:871, 1984.\n .. [Rousseeuw] A Fast Algorithm for the Minimum Covariance Determinant\n Estimator, 1999, American Statistical Association and the American\n Society for Quality, TECHNOMETRICS\n .. [ButlerDavies] R. W. Butler, P. L. Davies and M. Jhun,\n Asymptotics For The Minimum Covariance Determinant Estimator,\n The Annals of Statistics, 1993, Vol. 21, No. 3, 1385-1400\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.covariance import MinCovDet\n >>> from sklearn.datasets import make_gaussian_quantiles\n >>> real_cov = np.array([[.8, .3],\n ... [.3, .4]])\n >>> rng = np.random.RandomState(0)\n >>> X = rng.multivariate_normal(mean=[0, 0],\n ... cov=real_cov,\n ... size=500)\n >>> cov = MinCovDet(random_state=0).fit(X)\n >>> cov.covariance_\n array([[0.7411..., 0.2535...],\n [0.2535..., 0.3053...]])\n >>> cov.location_\n array([0.0813... , 0.0427...])\n ", + "source_code": "\n\nclass MinCovDet(EmpiricalCovariance):\n \"\"\"Minimum Covariance Determinant (MCD): robust estimator of covariance.\n\n The Minimum Covariance Determinant covariance estimator is to be applied\n on Gaussian-distributed data, but could still be relevant on data\n drawn from a unimodal, symmetric distribution. It is not meant to be used\n with multi-modal data (the algorithm used to fit a MinCovDet object is\n likely to fail in such a case).\n One should consider projection pursuit methods to deal with multi-modal\n datasets.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n store_precision : bool, default=True\n Specify if the estimated precision is stored.\n\n assume_centered : bool, default=False\n If True, the support of the robust location and the covariance\n estimates is computed, and a covariance estimate is recomputed from\n it, without centering the data.\n Useful to work with data whose mean is significantly equal to\n zero but is not exactly zero.\n If False, the robust location and covariance are directly computed\n with the FastMCD algorithm without additional treatment.\n\n support_fraction : float, default=None\n The proportion of points to be included in the support of the raw\n MCD estimate. Default is None, which implies that the minimum\n value of support_fraction will be used within the algorithm:\n `(n_sample + n_features + 1) / 2`. The parameter must be in the range\n (0, 1).\n\n random_state : int, RandomState instance or None, default=None\n Determines the pseudo random number generator for shuffling the data.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n Attributes\n ----------\n raw_location_ : ndarray of shape (n_features,)\n The raw robust estimated location before correction and re-weighting.\n\n raw_covariance_ : ndarray of shape (n_features, n_features)\n The raw robust estimated covariance before correction and re-weighting.\n\n raw_support_ : ndarray of shape (n_samples,)\n A mask of the observations that have been used to compute\n the raw robust estimates of location and shape, before correction\n and re-weighting.\n\n location_ : ndarray of shape (n_features,)\n Estimated robust location.\n\n covariance_ : ndarray of shape (n_features, n_features)\n Estimated robust covariance matrix.\n\n precision_ : ndarray of shape (n_features, n_features)\n Estimated pseudo inverse matrix.\n (stored only if store_precision is True)\n\n support_ : ndarray of shape (n_samples,)\n A mask of the observations that have been used to compute\n the robust estimates of location and shape.\n\n dist_ : ndarray of shape (n_samples,)\n Mahalanobis distances of the training set (on which :meth:`fit` is\n called) observations.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n EllipticEnvelope : An object for detecting outliers in\n a Gaussian distributed dataset.\n EmpiricalCovariance : Maximum likelihood covariance estimator.\n GraphicalLasso : Sparse inverse covariance estimation\n with an l1-penalized estimator.\n GraphicalLassoCV : Sparse inverse covariance with cross-validated\n choice of the l1 penalty.\n LedoitWolf : LedoitWolf Estimator.\n OAS : Oracle Approximating Shrinkage Estimator.\n ShrunkCovariance : Covariance estimator with shrinkage.\n\n References\n ----------\n\n .. [Rouseeuw1984] P. J. Rousseeuw. Least median of squares regression.\n J. Am Stat Ass, 79:871, 1984.\n .. [Rousseeuw] A Fast Algorithm for the Minimum Covariance Determinant\n Estimator, 1999, American Statistical Association and the American\n Society for Quality, TECHNOMETRICS\n .. [ButlerDavies] R. W. Butler, P. L. Davies and M. Jhun,\n Asymptotics For The Minimum Covariance Determinant Estimator,\n The Annals of Statistics, 1993, Vol. 21, No. 3, 1385-1400\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.covariance import MinCovDet\n >>> from sklearn.datasets import make_gaussian_quantiles\n >>> real_cov = np.array([[.8, .3],\n ... [.3, .4]])\n >>> rng = np.random.RandomState(0)\n >>> X = rng.multivariate_normal(mean=[0, 0],\n ... cov=real_cov,\n ... size=500)\n >>> cov = MinCovDet(random_state=0).fit(X)\n >>> cov.covariance_\n array([[0.7411..., 0.2535...],\n [0.2535..., 0.3053...]])\n >>> cov.location_\n array([0.0813... , 0.0427...])\n \"\"\"\n _nonrobust_covariance = staticmethod(empirical_covariance)\n \n def __init__(self, *, store_precision=True, assume_centered=False, support_fraction=None, random_state=None):\n self.store_precision = store_precision\n self.assume_centered = assume_centered\n self.support_fraction = support_fraction\n self.random_state = random_state\n \n def fit(self, X, y=None):\n \"\"\"Fit a Minimum Covariance Determinant with the FastMCD algorithm.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training data, where `n_samples` is the number of samples\n and `n_features` is the number of features.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n X = self._validate_data(X, ensure_min_samples=2, estimator='MinCovDet')\n random_state = check_random_state(self.random_state)\n (n_samples, n_features) = X.shape\n if (linalg.svdvals(np.dot(X.T, X)) > 1e-08).sum() != n_features:\n warnings.warn('The covariance matrix associated to your dataset is not full rank')\n (raw_location, raw_covariance, raw_support, raw_dist) = fast_mcd(X, support_fraction=self.support_fraction, cov_computation_method=self._nonrobust_covariance, random_state=random_state)\n if self.assume_centered:\n raw_location = np.zeros(n_features)\n raw_covariance = self._nonrobust_covariance(X[raw_support], assume_centered=True)\n precision = linalg.pinvh(raw_covariance)\n raw_dist = np.sum(np.dot(X, precision) * X, 1)\n self.raw_location_ = raw_location\n self.raw_covariance_ = raw_covariance\n self.raw_support_ = raw_support\n self.location_ = raw_location\n self.support_ = raw_support\n self.dist_ = raw_dist\n self.correct_covariance(X)\n self.reweight_covariance(X)\n return self\n \n def correct_covariance(self, data):\n \"\"\"Apply a correction to raw Minimum Covariance Determinant estimates.\n\n Correction using the empirical correction factor suggested\n by Rousseeuw and Van Driessen in [RVD]_.\n\n Parameters\n ----------\n data : array-like of shape (n_samples, n_features)\n The data matrix, with p features and n samples.\n The data set must be the one which was used to compute\n the raw estimates.\n\n Returns\n -------\n covariance_corrected : ndarray of shape (n_features, n_features)\n Corrected robust covariance estimate.\n\n References\n ----------\n\n .. [RVD] A Fast Algorithm for the Minimum Covariance\n Determinant Estimator, 1999, American Statistical Association\n and the American Society for Quality, TECHNOMETRICS\n \"\"\"\n n_samples = len(self.dist_)\n n_support = np.sum(self.support_)\n if n_support < n_samples and np.allclose(self.raw_covariance_, 0):\n raise ValueError('The covariance matrix of the support data is equal to 0, try to increase support_fraction')\n correction = np.median(self.dist_) / chi2(data.shape[1]).isf(0.5)\n covariance_corrected = self.raw_covariance_ * correction\n self.dist_ /= correction\n return covariance_corrected\n \n def reweight_covariance(self, data):\n \"\"\"Re-weight raw Minimum Covariance Determinant estimates.\n\n Re-weight observations using Rousseeuw's method (equivalent to\n deleting outlying observations from the data set before\n computing location and covariance estimates) described\n in [RVDriessen]_.\n\n Parameters\n ----------\n data : array-like of shape (n_samples, n_features)\n The data matrix, with p features and n samples.\n The data set must be the one which was used to compute\n the raw estimates.\n\n Returns\n -------\n location_reweighted : ndarray of shape (n_features,)\n Re-weighted robust location estimate.\n\n covariance_reweighted : ndarray of shape (n_features, n_features)\n Re-weighted robust covariance estimate.\n\n support_reweighted : ndarray of shape (n_samples,), dtype=bool\n A mask of the observations that have been used to compute\n the re-weighted robust location and covariance estimates.\n\n References\n ----------\n\n .. [RVDriessen] A Fast Algorithm for the Minimum Covariance\n Determinant Estimator, 1999, American Statistical Association\n and the American Society for Quality, TECHNOMETRICS\n \"\"\"\n (n_samples, n_features) = data.shape\n mask = self.dist_ < chi2(n_features).isf(0.025)\n if self.assume_centered:\n location_reweighted = np.zeros(n_features)\n else:\n location_reweighted = data[mask].mean(0)\n covariance_reweighted = self._nonrobust_covariance(data[mask], assume_centered=self.assume_centered)\n support_reweighted = np.zeros(n_samples, dtype=bool)\n support_reweighted[mask] = True\n self._set_covariance(covariance_reweighted)\n self.location_ = location_reweighted\n self.support_ = support_reweighted\n X_centered = data - self.location_\n self.dist_ = np.sum(np.dot(X_centered, self.get_precision()) * X_centered, 1)\n return location_reweighted, covariance_reweighted, support_reweighted\n" }, { "name": "LedoitWolf", @@ -20373,8 +20340,8 @@ ], "is_public": true, "description": "Partial Least Squares transformer and regressor.\n\nRead more in the :ref:`User Guide `. .. versionadded:: 0.8", - "docstring": "Partial Least Squares transformer and regressor.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.8\n\n Parameters\n ----------\n n_components : int, default=2\n Number of components to keep. Should be in `[1, min(n_samples,\n n_features, n_targets)]`.\n\n scale : bool, default=True\n Whether to scale `X` and `Y`.\n\n algorithm : {'nipals', 'svd'}, default='nipals'\n The algorithm used to estimate the first singular vectors of the\n cross-covariance matrix. 'nipals' uses the power method while 'svd'\n will compute the whole SVD.\n\n max_iter : int, default=500\n the maximum number of iterations of the power method when\n `algorithm='nipals'`. Ignored otherwise.\n\n tol : float, default=1e-06\n The tolerance used as convergence criteria in the power method: the\n algorithm stops whenever the squared norm of `u_i - u_{i-1}` is less\n than `tol`, where `u` corresponds to the left singular vector.\n\n copy : bool, default=True\n Whether to copy `X` and `Y` in fit before applying centering, and\n potentially scaling. If False, these operations will be done inplace,\n modifying both arrays.\n\n Attributes\n ----------\n x_weights_ : ndarray of shape (n_features, n_components)\n The left singular vectors of the cross-covariance matrices of each\n iteration.\n\n y_weights_ : ndarray of shape (n_targets, n_components)\n The right singular vectors of the cross-covariance matrices of each\n iteration.\n\n x_loadings_ : ndarray of shape (n_features, n_components)\n The loadings of `X`.\n\n y_loadings_ : ndarray of shape (n_targets, n_components)\n The loadings of `Y`.\n\n x_scores_ : ndarray of shape (n_samples, n_components)\n The transformed training samples.\n\n .. deprecated:: 0.24\n `x_scores_` is deprecated in 0.24 and will be removed in 1.1\n (renaming of 0.26). You can just call `transform` on the training\n data instead.\n\n y_scores_ : ndarray of shape (n_samples, n_components)\n The transformed training targets.\n\n .. deprecated:: 0.24\n `y_scores_` is deprecated in 0.24 and will be removed in 1.1\n (renaming of 0.26). You can just call `transform` on the training\n data instead.\n\n x_rotations_ : ndarray of shape (n_features, n_components)\n The projection matrix used to transform `X`.\n\n y_rotations_ : ndarray of shape (n_features, n_components)\n The projection matrix used to transform `Y`.\n\n coef_ : ndarray of shape (n_features, n_targets)\n The coefficients of the linear model such that `Y` is approximated as\n `Y = X @ coef_`.\n\n n_iter_ : list of shape (n_components,)\n Number of iterations of the power method, for each\n component. Empty if `algorithm='svd'`.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn.cross_decomposition import PLSCanonical\n >>> X = [[0., 0., 1.], [1.,0.,0.], [2.,2.,2.], [2.,5.,4.]]\n >>> Y = [[0.1, -0.2], [0.9, 1.1], [6.2, 5.9], [11.9, 12.3]]\n >>> plsca = PLSCanonical(n_components=2)\n >>> plsca.fit(X, Y)\n PLSCanonical()\n >>> X_c, Y_c = plsca.transform(X, Y)\n\n See Also\n --------\n CCA\n PLSSVD\n ", - "source_code": "\n\nclass PLSCanonical(_PLS):\n \"\"\"Partial Least Squares transformer and regressor.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.8\n\n Parameters\n ----------\n n_components : int, default=2\n Number of components to keep. Should be in `[1, min(n_samples,\n n_features, n_targets)]`.\n\n scale : bool, default=True\n Whether to scale `X` and `Y`.\n\n algorithm : {'nipals', 'svd'}, default='nipals'\n The algorithm used to estimate the first singular vectors of the\n cross-covariance matrix. 'nipals' uses the power method while 'svd'\n will compute the whole SVD.\n\n max_iter : int, default=500\n the maximum number of iterations of the power method when\n `algorithm='nipals'`. Ignored otherwise.\n\n tol : float, default=1e-06\n The tolerance used as convergence criteria in the power method: the\n algorithm stops whenever the squared norm of `u_i - u_{i-1}` is less\n than `tol`, where `u` corresponds to the left singular vector.\n\n copy : bool, default=True\n Whether to copy `X` and `Y` in fit before applying centering, and\n potentially scaling. If False, these operations will be done inplace,\n modifying both arrays.\n\n Attributes\n ----------\n x_weights_ : ndarray of shape (n_features, n_components)\n The left singular vectors of the cross-covariance matrices of each\n iteration.\n\n y_weights_ : ndarray of shape (n_targets, n_components)\n The right singular vectors of the cross-covariance matrices of each\n iteration.\n\n x_loadings_ : ndarray of shape (n_features, n_components)\n The loadings of `X`.\n\n y_loadings_ : ndarray of shape (n_targets, n_components)\n The loadings of `Y`.\n\n x_scores_ : ndarray of shape (n_samples, n_components)\n The transformed training samples.\n\n .. deprecated:: 0.24\n `x_scores_` is deprecated in 0.24 and will be removed in 1.1\n (renaming of 0.26). You can just call `transform` on the training\n data instead.\n\n y_scores_ : ndarray of shape (n_samples, n_components)\n The transformed training targets.\n\n .. deprecated:: 0.24\n `y_scores_` is deprecated in 0.24 and will be removed in 1.1\n (renaming of 0.26). You can just call `transform` on the training\n data instead.\n\n x_rotations_ : ndarray of shape (n_features, n_components)\n The projection matrix used to transform `X`.\n\n y_rotations_ : ndarray of shape (n_features, n_components)\n The projection matrix used to transform `Y`.\n\n coef_ : ndarray of shape (n_features, n_targets)\n The coefficients of the linear model such that `Y` is approximated as\n `Y = X @ coef_`.\n\n n_iter_ : list of shape (n_components,)\n Number of iterations of the power method, for each\n component. Empty if `algorithm='svd'`.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn.cross_decomposition import PLSCanonical\n >>> X = [[0., 0., 1.], [1.,0.,0.], [2.,2.,2.], [2.,5.,4.]]\n >>> Y = [[0.1, -0.2], [0.9, 1.1], [6.2, 5.9], [11.9, 12.3]]\n >>> plsca = PLSCanonical(n_components=2)\n >>> plsca.fit(X, Y)\n PLSCanonical()\n >>> X_c, Y_c = plsca.transform(X, Y)\n\n See Also\n --------\n CCA\n PLSSVD\n \"\"\"\n \n def __init__(self, n_components=2, *, scale=True, algorithm='nipals', max_iter=500, tol=1e-06, copy=True):\n super().__init__(n_components=n_components, scale=scale, deflation_mode='canonical', mode='A', algorithm=algorithm, max_iter=max_iter, tol=tol, copy=copy)\n" + "docstring": "Partial Least Squares transformer and regressor.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.8\n\n Parameters\n ----------\n n_components : int, default=2\n Number of components to keep. Should be in `[1, min(n_samples,\n n_features, n_targets)]`.\n\n scale : bool, default=True\n Whether to scale `X` and `Y`.\n\n algorithm : {'nipals', 'svd'}, default='nipals'\n The algorithm used to estimate the first singular vectors of the\n cross-covariance matrix. 'nipals' uses the power method while 'svd'\n will compute the whole SVD.\n\n max_iter : int, default=500\n The maximum number of iterations of the power method when\n `algorithm='nipals'`. Ignored otherwise.\n\n tol : float, default=1e-06\n The tolerance used as convergence criteria in the power method: the\n algorithm stops whenever the squared norm of `u_i - u_{i-1}` is less\n than `tol`, where `u` corresponds to the left singular vector.\n\n copy : bool, default=True\n Whether to copy `X` and `Y` in fit before applying centering, and\n potentially scaling. If False, these operations will be done inplace,\n modifying both arrays.\n\n Attributes\n ----------\n x_weights_ : ndarray of shape (n_features, n_components)\n The left singular vectors of the cross-covariance matrices of each\n iteration.\n\n y_weights_ : ndarray of shape (n_targets, n_components)\n The right singular vectors of the cross-covariance matrices of each\n iteration.\n\n x_loadings_ : ndarray of shape (n_features, n_components)\n The loadings of `X`.\n\n y_loadings_ : ndarray of shape (n_targets, n_components)\n The loadings of `Y`.\n\n x_scores_ : ndarray of shape (n_samples, n_components)\n The transformed training samples.\n\n .. deprecated:: 0.24\n `x_scores_` is deprecated in 0.24 and will be removed in 1.1\n (renaming of 0.26). You can just call `transform` on the training\n data instead.\n\n y_scores_ : ndarray of shape (n_samples, n_components)\n The transformed training targets.\n\n .. deprecated:: 0.24\n `y_scores_` is deprecated in 0.24 and will be removed in 1.1\n (renaming of 0.26). You can just call `transform` on the training\n data instead.\n\n x_rotations_ : ndarray of shape (n_features, n_components)\n The projection matrix used to transform `X`.\n\n y_rotations_ : ndarray of shape (n_features, n_components)\n The projection matrix used to transform `Y`.\n\n coef_ : ndarray of shape (n_features, n_targets)\n The coefficients of the linear model such that `Y` is approximated as\n `Y = X @ coef_`.\n\n n_iter_ : list of shape (n_components,)\n Number of iterations of the power method, for each\n component. Empty if `algorithm='svd'`.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n CCA : Canonical Correlation Analysis.\n PLSSVD : Partial Least Square SVD.\n\n Examples\n --------\n >>> from sklearn.cross_decomposition import PLSCanonical\n >>> X = [[0., 0., 1.], [1.,0.,0.], [2.,2.,2.], [2.,5.,4.]]\n >>> Y = [[0.1, -0.2], [0.9, 1.1], [6.2, 5.9], [11.9, 12.3]]\n >>> plsca = PLSCanonical(n_components=2)\n >>> plsca.fit(X, Y)\n PLSCanonical()\n >>> X_c, Y_c = plsca.transform(X, Y)\n ", + "source_code": "\n\nclass PLSCanonical(_PLS):\n \"\"\"Partial Least Squares transformer and regressor.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.8\n\n Parameters\n ----------\n n_components : int, default=2\n Number of components to keep. Should be in `[1, min(n_samples,\n n_features, n_targets)]`.\n\n scale : bool, default=True\n Whether to scale `X` and `Y`.\n\n algorithm : {'nipals', 'svd'}, default='nipals'\n The algorithm used to estimate the first singular vectors of the\n cross-covariance matrix. 'nipals' uses the power method while 'svd'\n will compute the whole SVD.\n\n max_iter : int, default=500\n The maximum number of iterations of the power method when\n `algorithm='nipals'`. Ignored otherwise.\n\n tol : float, default=1e-06\n The tolerance used as convergence criteria in the power method: the\n algorithm stops whenever the squared norm of `u_i - u_{i-1}` is less\n than `tol`, where `u` corresponds to the left singular vector.\n\n copy : bool, default=True\n Whether to copy `X` and `Y` in fit before applying centering, and\n potentially scaling. If False, these operations will be done inplace,\n modifying both arrays.\n\n Attributes\n ----------\n x_weights_ : ndarray of shape (n_features, n_components)\n The left singular vectors of the cross-covariance matrices of each\n iteration.\n\n y_weights_ : ndarray of shape (n_targets, n_components)\n The right singular vectors of the cross-covariance matrices of each\n iteration.\n\n x_loadings_ : ndarray of shape (n_features, n_components)\n The loadings of `X`.\n\n y_loadings_ : ndarray of shape (n_targets, n_components)\n The loadings of `Y`.\n\n x_scores_ : ndarray of shape (n_samples, n_components)\n The transformed training samples.\n\n .. deprecated:: 0.24\n `x_scores_` is deprecated in 0.24 and will be removed in 1.1\n (renaming of 0.26). You can just call `transform` on the training\n data instead.\n\n y_scores_ : ndarray of shape (n_samples, n_components)\n The transformed training targets.\n\n .. deprecated:: 0.24\n `y_scores_` is deprecated in 0.24 and will be removed in 1.1\n (renaming of 0.26). You can just call `transform` on the training\n data instead.\n\n x_rotations_ : ndarray of shape (n_features, n_components)\n The projection matrix used to transform `X`.\n\n y_rotations_ : ndarray of shape (n_features, n_components)\n The projection matrix used to transform `Y`.\n\n coef_ : ndarray of shape (n_features, n_targets)\n The coefficients of the linear model such that `Y` is approximated as\n `Y = X @ coef_`.\n\n n_iter_ : list of shape (n_components,)\n Number of iterations of the power method, for each\n component. Empty if `algorithm='svd'`.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n CCA : Canonical Correlation Analysis.\n PLSSVD : Partial Least Square SVD.\n\n Examples\n --------\n >>> from sklearn.cross_decomposition import PLSCanonical\n >>> X = [[0., 0., 1.], [1.,0.,0.], [2.,2.,2.], [2.,5.,4.]]\n >>> Y = [[0.1, -0.2], [0.9, 1.1], [6.2, 5.9], [11.9, 12.3]]\n >>> plsca = PLSCanonical(n_components=2)\n >>> plsca.fit(X, Y)\n PLSCanonical()\n >>> X_c, Y_c = plsca.transform(X, Y)\n \"\"\"\n \n def __init__(self, n_components=2, *, scale=True, algorithm='nipals', max_iter=500, tol=1e-06, copy=True):\n super().__init__(n_components=n_components, scale=scale, deflation_mode='canonical', mode='A', algorithm=algorithm, max_iter=max_iter, tol=tol, copy=copy)\n" }, { "name": "PLSRegression", @@ -20385,9 +20352,9 @@ "sklearn.cross_decomposition._pls.PLSRegression.__init__" ], "is_public": true, - "description": "PLS regression\n\nPLSRegression is also known as PLS2 or PLS1, depending on the number of targets. Read more in the :ref:`User Guide `. .. versionadded:: 0.8", - "docstring": "PLS regression\n\n PLSRegression is also known as PLS2 or PLS1, depending on the number of\n targets.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.8\n\n Parameters\n ----------\n n_components : int, default=2\n Number of components to keep. Should be in `[1, min(n_samples,\n n_features, n_targets)]`.\n\n scale : bool, default=True\n Whether to scale `X` and `Y`.\n\n max_iter : int, default=500\n The maximum number of iterations of the power method when\n `algorithm='nipals'`. Ignored otherwise.\n\n tol : float, default=1e-06\n The tolerance used as convergence criteria in the power method: the\n algorithm stops whenever the squared norm of `u_i - u_{i-1}` is less\n than `tol`, where `u` corresponds to the left singular vector.\n\n copy : bool, default=True\n Whether to copy `X` and `Y` in fit before applying centering, and\n potentially scaling. If False, these operations will be done inplace,\n modifying both arrays.\n\n Attributes\n ----------\n x_weights_ : ndarray of shape (n_features, n_components)\n The left singular vectors of the cross-covariance matrices of each\n iteration.\n\n y_weights_ : ndarray of shape (n_targets, n_components)\n The right singular vectors of the cross-covariance matrices of each\n iteration.\n\n x_loadings_ : ndarray of shape (n_features, n_components)\n The loadings of `X`.\n\n y_loadings_ : ndarray of shape (n_targets, n_components)\n The loadings of `Y`.\n\n x_scores_ : ndarray of shape (n_samples, n_components)\n The transformed training samples.\n\n y_scores_ : ndarray of shape (n_samples, n_components)\n The transformed training targets.\n\n x_rotations_ : ndarray of shape (n_features, n_components)\n The projection matrix used to transform `X`.\n\n y_rotations_ : ndarray of shape (n_features, n_components)\n The projection matrix used to transform `Y`.\n\n coef_ : ndarray of shape (n_features, n_targets)\n The coefficients of the linear model such that `Y` is approximated as\n `Y = X @ coef_`.\n\n n_iter_ : list of shape (n_components,)\n Number of iterations of the power method, for each\n component.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn.cross_decomposition import PLSRegression\n >>> X = [[0., 0., 1.], [1.,0.,0.], [2.,2.,2.], [2.,5.,4.]]\n >>> Y = [[0.1, -0.2], [0.9, 1.1], [6.2, 5.9], [11.9, 12.3]]\n >>> pls2 = PLSRegression(n_components=2)\n >>> pls2.fit(X, Y)\n PLSRegression()\n >>> Y_pred = pls2.predict(X)\n ", - "source_code": "\n\nclass PLSRegression(_PLS):\n \"\"\"PLS regression\n\n PLSRegression is also known as PLS2 or PLS1, depending on the number of\n targets.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.8\n\n Parameters\n ----------\n n_components : int, default=2\n Number of components to keep. Should be in `[1, min(n_samples,\n n_features, n_targets)]`.\n\n scale : bool, default=True\n Whether to scale `X` and `Y`.\n\n max_iter : int, default=500\n The maximum number of iterations of the power method when\n `algorithm='nipals'`. Ignored otherwise.\n\n tol : float, default=1e-06\n The tolerance used as convergence criteria in the power method: the\n algorithm stops whenever the squared norm of `u_i - u_{i-1}` is less\n than `tol`, where `u` corresponds to the left singular vector.\n\n copy : bool, default=True\n Whether to copy `X` and `Y` in fit before applying centering, and\n potentially scaling. If False, these operations will be done inplace,\n modifying both arrays.\n\n Attributes\n ----------\n x_weights_ : ndarray of shape (n_features, n_components)\n The left singular vectors of the cross-covariance matrices of each\n iteration.\n\n y_weights_ : ndarray of shape (n_targets, n_components)\n The right singular vectors of the cross-covariance matrices of each\n iteration.\n\n x_loadings_ : ndarray of shape (n_features, n_components)\n The loadings of `X`.\n\n y_loadings_ : ndarray of shape (n_targets, n_components)\n The loadings of `Y`.\n\n x_scores_ : ndarray of shape (n_samples, n_components)\n The transformed training samples.\n\n y_scores_ : ndarray of shape (n_samples, n_components)\n The transformed training targets.\n\n x_rotations_ : ndarray of shape (n_features, n_components)\n The projection matrix used to transform `X`.\n\n y_rotations_ : ndarray of shape (n_features, n_components)\n The projection matrix used to transform `Y`.\n\n coef_ : ndarray of shape (n_features, n_targets)\n The coefficients of the linear model such that `Y` is approximated as\n `Y = X @ coef_`.\n\n n_iter_ : list of shape (n_components,)\n Number of iterations of the power method, for each\n component.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn.cross_decomposition import PLSRegression\n >>> X = [[0., 0., 1.], [1.,0.,0.], [2.,2.,2.], [2.,5.,4.]]\n >>> Y = [[0.1, -0.2], [0.9, 1.1], [6.2, 5.9], [11.9, 12.3]]\n >>> pls2 = PLSRegression(n_components=2)\n >>> pls2.fit(X, Y)\n PLSRegression()\n >>> Y_pred = pls2.predict(X)\n \"\"\"\n \n def __init__(self, n_components=2, *, scale=True, max_iter=500, tol=1e-06, copy=True):\n super().__init__(n_components=n_components, scale=scale, deflation_mode='regression', mode='A', algorithm='nipals', max_iter=max_iter, tol=tol, copy=copy)\n" + "description": "PLS regression.\n\nPLSRegression is also known as PLS2 or PLS1, depending on the number of targets. Read more in the :ref:`User Guide `. .. versionadded:: 0.8", + "docstring": "PLS regression.\n\n PLSRegression is also known as PLS2 or PLS1, depending on the number of\n targets.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.8\n\n Parameters\n ----------\n n_components : int, default=2\n Number of components to keep. Should be in `[1, min(n_samples,\n n_features, n_targets)]`.\n\n scale : bool, default=True\n Whether to scale `X` and `Y`.\n\n max_iter : int, default=500\n The maximum number of iterations of the power method when\n `algorithm='nipals'`. Ignored otherwise.\n\n tol : float, default=1e-06\n The tolerance used as convergence criteria in the power method: the\n algorithm stops whenever the squared norm of `u_i - u_{i-1}` is less\n than `tol`, where `u` corresponds to the left singular vector.\n\n copy : bool, default=True\n Whether to copy `X` and `Y` in :term:`fit` before applying centering,\n and potentially scaling. If `False`, these operations will be done\n inplace, modifying both arrays.\n\n Attributes\n ----------\n x_weights_ : ndarray of shape (n_features, n_components)\n The left singular vectors of the cross-covariance matrices of each\n iteration.\n\n y_weights_ : ndarray of shape (n_targets, n_components)\n The right singular vectors of the cross-covariance matrices of each\n iteration.\n\n x_loadings_ : ndarray of shape (n_features, n_components)\n The loadings of `X`.\n\n y_loadings_ : ndarray of shape (n_targets, n_components)\n The loadings of `Y`.\n\n x_scores_ : ndarray of shape (n_samples, n_components)\n The transformed training samples.\n\n y_scores_ : ndarray of shape (n_samples, n_components)\n The transformed training targets.\n\n x_rotations_ : ndarray of shape (n_features, n_components)\n The projection matrix used to transform `X`.\n\n y_rotations_ : ndarray of shape (n_features, n_components)\n The projection matrix used to transform `Y`.\n\n coef_ : ndarray of shape (n_features, n_targets)\n The coefficients of the linear model such that `Y` is approximated as\n `Y = X @ coef_`.\n\n n_iter_ : list of shape (n_components,)\n Number of iterations of the power method, for each\n component.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n PLSCanonical : Partial Least Squares transformer and regressor.\n\n Examples\n --------\n >>> from sklearn.cross_decomposition import PLSRegression\n >>> X = [[0., 0., 1.], [1.,0.,0.], [2.,2.,2.], [2.,5.,4.]]\n >>> Y = [[0.1, -0.2], [0.9, 1.1], [6.2, 5.9], [11.9, 12.3]]\n >>> pls2 = PLSRegression(n_components=2)\n >>> pls2.fit(X, Y)\n PLSRegression()\n >>> Y_pred = pls2.predict(X)\n ", + "source_code": "\n\nclass PLSRegression(_PLS):\n \"\"\"PLS regression.\n\n PLSRegression is also known as PLS2 or PLS1, depending on the number of\n targets.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.8\n\n Parameters\n ----------\n n_components : int, default=2\n Number of components to keep. Should be in `[1, min(n_samples,\n n_features, n_targets)]`.\n\n scale : bool, default=True\n Whether to scale `X` and `Y`.\n\n max_iter : int, default=500\n The maximum number of iterations of the power method when\n `algorithm='nipals'`. Ignored otherwise.\n\n tol : float, default=1e-06\n The tolerance used as convergence criteria in the power method: the\n algorithm stops whenever the squared norm of `u_i - u_{i-1}` is less\n than `tol`, where `u` corresponds to the left singular vector.\n\n copy : bool, default=True\n Whether to copy `X` and `Y` in :term:`fit` before applying centering,\n and potentially scaling. If `False`, these operations will be done\n inplace, modifying both arrays.\n\n Attributes\n ----------\n x_weights_ : ndarray of shape (n_features, n_components)\n The left singular vectors of the cross-covariance matrices of each\n iteration.\n\n y_weights_ : ndarray of shape (n_targets, n_components)\n The right singular vectors of the cross-covariance matrices of each\n iteration.\n\n x_loadings_ : ndarray of shape (n_features, n_components)\n The loadings of `X`.\n\n y_loadings_ : ndarray of shape (n_targets, n_components)\n The loadings of `Y`.\n\n x_scores_ : ndarray of shape (n_samples, n_components)\n The transformed training samples.\n\n y_scores_ : ndarray of shape (n_samples, n_components)\n The transformed training targets.\n\n x_rotations_ : ndarray of shape (n_features, n_components)\n The projection matrix used to transform `X`.\n\n y_rotations_ : ndarray of shape (n_features, n_components)\n The projection matrix used to transform `Y`.\n\n coef_ : ndarray of shape (n_features, n_targets)\n The coefficients of the linear model such that `Y` is approximated as\n `Y = X @ coef_`.\n\n n_iter_ : list of shape (n_components,)\n Number of iterations of the power method, for each\n component.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n PLSCanonical : Partial Least Squares transformer and regressor.\n\n Examples\n --------\n >>> from sklearn.cross_decomposition import PLSRegression\n >>> X = [[0., 0., 1.], [1.,0.,0.], [2.,2.,2.], [2.,5.,4.]]\n >>> Y = [[0.1, -0.2], [0.9, 1.1], [6.2, 5.9], [11.9, 12.3]]\n >>> pls2 = PLSRegression(n_components=2)\n >>> pls2.fit(X, Y)\n PLSRegression()\n >>> Y_pred = pls2.predict(X)\n \"\"\"\n \n def __init__(self, n_components=2, *, scale=True, max_iter=500, tol=1e-06, copy=True):\n super().__init__(n_components=n_components, scale=scale, deflation_mode='regression', mode='A', algorithm='nipals', max_iter=max_iter, tol=tol, copy=copy)\n" }, { "name": "PLSSVD", @@ -20397,19 +20364,19 @@ "methods": [ "sklearn.cross_decomposition._pls.PLSSVD.__init__", "sklearn.cross_decomposition._pls.PLSSVD.fit", - "sklearn.cross_decomposition._pls.PLSSVD.x_scores_", - "sklearn.cross_decomposition._pls.PLSSVD.y_scores_", - "sklearn.cross_decomposition._pls.PLSSVD.x_mean_", - "sklearn.cross_decomposition._pls.PLSSVD.y_mean_", - "sklearn.cross_decomposition._pls.PLSSVD.x_std_", - "sklearn.cross_decomposition._pls.PLSSVD.y_std_", + "sklearn.cross_decomposition._pls.PLSSVD.x_scores_@getter", + "sklearn.cross_decomposition._pls.PLSSVD.y_scores_@getter", + "sklearn.cross_decomposition._pls.PLSSVD.x_mean_@getter", + "sklearn.cross_decomposition._pls.PLSSVD.y_mean_@getter", + "sklearn.cross_decomposition._pls.PLSSVD.x_std_@getter", + "sklearn.cross_decomposition._pls.PLSSVD.y_std_@getter", "sklearn.cross_decomposition._pls.PLSSVD.transform", "sklearn.cross_decomposition._pls.PLSSVD.fit_transform" ], "is_public": true, - "description": "Partial Least Square SVD.\n\nThis transformer simply performs a SVD on the crosscovariance matrix X'Y. It is able to project both the training data `X` and the targets `Y`. The training data X is projected on the left singular vectors, while the targets are projected on the right singular vectors. Read more in the :ref:`User Guide `. .. versionadded:: 0.8", - "docstring": "Partial Least Square SVD.\n\n This transformer simply performs a SVD on the crosscovariance matrix X'Y.\n It is able to project both the training data `X` and the targets `Y`. The\n training data X is projected on the left singular vectors, while the\n targets are projected on the right singular vectors.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.8\n\n Parameters\n ----------\n n_components : int, default=2\n The number of components to keep. Should be in `[1,\n min(n_samples, n_features, n_targets)]`.\n\n scale : bool, default=True\n Whether to scale `X` and `Y`.\n\n copy : bool, default=True\n Whether to copy `X` and `Y` in fit before applying centering, and\n potentially scaling. If False, these operations will be done inplace,\n modifying both arrays.\n\n Attributes\n ----------\n x_weights_ : ndarray of shape (n_features, n_components)\n The left singular vectors of the SVD of the cross-covariance matrix.\n Used to project `X` in `transform`.\n\n y_weights_ : ndarray of (n_targets, n_components)\n The right singular vectors of the SVD of the cross-covariance matrix.\n Used to project `X` in `transform`.\n\n x_scores_ : ndarray of shape (n_samples, n_components)\n The transformed training samples.\n\n .. deprecated:: 0.24\n `x_scores_` is deprecated in 0.24 and will be removed in 1.1\n (renaming of 0.26). You can just call `transform` on the training\n data instead.\n\n y_scores_ : ndarray of shape (n_samples, n_components)\n The transformed training targets.\n\n .. deprecated:: 0.24\n `y_scores_` is deprecated in 0.24 and will be removed in 1.1\n (renaming of 0.26). You can just call `transform` on the training\n data instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.cross_decomposition import PLSSVD\n >>> X = np.array([[0., 0., 1.],\n ... [1., 0., 0.],\n ... [2., 2., 2.],\n ... [2., 5., 4.]])\n >>> Y = np.array([[0.1, -0.2],\n ... [0.9, 1.1],\n ... [6.2, 5.9],\n ... [11.9, 12.3]])\n >>> pls = PLSSVD(n_components=2).fit(X, Y)\n >>> X_c, Y_c = pls.transform(X, Y)\n >>> X_c.shape, Y_c.shape\n ((4, 2), (4, 2))\n\n See Also\n --------\n PLSCanonical\n CCA\n ", - "source_code": "\n\nclass PLSSVD(TransformerMixin, BaseEstimator):\n \"\"\"Partial Least Square SVD.\n\n This transformer simply performs a SVD on the crosscovariance matrix X'Y.\n It is able to project both the training data `X` and the targets `Y`. The\n training data X is projected on the left singular vectors, while the\n targets are projected on the right singular vectors.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.8\n\n Parameters\n ----------\n n_components : int, default=2\n The number of components to keep. Should be in `[1,\n min(n_samples, n_features, n_targets)]`.\n\n scale : bool, default=True\n Whether to scale `X` and `Y`.\n\n copy : bool, default=True\n Whether to copy `X` and `Y` in fit before applying centering, and\n potentially scaling. If False, these operations will be done inplace,\n modifying both arrays.\n\n Attributes\n ----------\n x_weights_ : ndarray of shape (n_features, n_components)\n The left singular vectors of the SVD of the cross-covariance matrix.\n Used to project `X` in `transform`.\n\n y_weights_ : ndarray of (n_targets, n_components)\n The right singular vectors of the SVD of the cross-covariance matrix.\n Used to project `X` in `transform`.\n\n x_scores_ : ndarray of shape (n_samples, n_components)\n The transformed training samples.\n\n .. deprecated:: 0.24\n `x_scores_` is deprecated in 0.24 and will be removed in 1.1\n (renaming of 0.26). You can just call `transform` on the training\n data instead.\n\n y_scores_ : ndarray of shape (n_samples, n_components)\n The transformed training targets.\n\n .. deprecated:: 0.24\n `y_scores_` is deprecated in 0.24 and will be removed in 1.1\n (renaming of 0.26). You can just call `transform` on the training\n data instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.cross_decomposition import PLSSVD\n >>> X = np.array([[0., 0., 1.],\n ... [1., 0., 0.],\n ... [2., 2., 2.],\n ... [2., 5., 4.]])\n >>> Y = np.array([[0.1, -0.2],\n ... [0.9, 1.1],\n ... [6.2, 5.9],\n ... [11.9, 12.3]])\n >>> pls = PLSSVD(n_components=2).fit(X, Y)\n >>> X_c, Y_c = pls.transform(X, Y)\n >>> X_c.shape, Y_c.shape\n ((4, 2), (4, 2))\n\n See Also\n --------\n PLSCanonical\n CCA\n \"\"\"\n \n def __init__(self, n_components=2, *, scale=True, copy=True):\n self.n_components = n_components\n self.scale = scale\n self.copy = copy\n \n def fit(self, X, Y):\n \"\"\"Fit model to data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training samples.\n\n Y : array-like of shape (n_samples,) or (n_samples, n_targets)\n Targets.\n \"\"\"\n check_consistent_length(X, Y)\n X = self._validate_data(X, dtype=np.float64, copy=self.copy, ensure_min_samples=2)\n Y = check_array(Y, dtype=np.float64, copy=self.copy, ensure_2d=False)\n if Y.ndim == 1:\n Y = Y.reshape(-1, 1)\n n_components = self.n_components\n rank_upper_bound = min(X.shape[0], X.shape[1], Y.shape[1])\n if not 1 <= n_components <= rank_upper_bound:\n warnings.warn(f'As of version 0.24, n_components({n_components}) should be in [1, min(n_features, n_samples, n_targets)] = [1, {rank_upper_bound}]. n_components={rank_upper_bound} will be used instead. In version 1.1 (renaming of 0.26), an error will be raised.', FutureWarning)\n n_components = rank_upper_bound\n (X, Y, self._x_mean, self._y_mean, self._x_std, self._y_std) = _center_scale_xy(X, Y, self.scale)\n C = np.dot(X.T, Y)\n (U, s, Vt) = svd(C, full_matrices=False)\n U = U[:, :n_components]\n Vt = Vt[:n_components]\n (U, Vt) = svd_flip(U, Vt)\n V = Vt.T\n self._x_scores = np.dot(X, U)\n self._y_scores = np.dot(Y, V)\n self.x_weights_ = U\n self.y_weights_ = V\n return self\n \n @deprecated('Attribute `x_scores_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26). Use est.transform(X) on the training data instead.')\n @property\n def x_scores_(self):\n return self._x_scores\n \n @deprecated('Attribute `y_scores_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26). Use est.transform(X, Y) on the training data instead.')\n @property\n def y_scores_(self):\n return self._y_scores\n \n @deprecated('Attribute `x_mean_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def x_mean_(self):\n return self._x_mean\n \n @deprecated('Attribute `y_mean_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def y_mean_(self):\n return self._y_mean\n \n @deprecated('Attribute `x_std_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def x_std_(self):\n return self._x_std\n \n @deprecated('Attribute `y_std_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def y_std_(self):\n return self._y_std\n \n def transform(self, X, Y=None):\n \"\"\"\n Apply the dimensionality reduction.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Samples to be transformed.\n\n Y : array-like of shape (n_samples,) or (n_samples, n_targets), default=None\n Targets.\n\n Returns\n -------\n x_scores : array-like or tuple of array-like\n The transformed data `X_tranformed` if `Y` is not None,\n `(X_transformed, Y_transformed)` otherwise.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, dtype=np.float64, reset=False)\n Xr = (X - self._x_mean) / self._x_std\n x_scores = np.dot(Xr, self.x_weights_)\n if Y is not None:\n Y = check_array(Y, ensure_2d=False, dtype=np.float64)\n if Y.ndim == 1:\n Y = Y.reshape(-1, 1)\n Yr = (Y - self._y_mean) / self._y_std\n y_scores = np.dot(Yr, self.y_weights_)\n return x_scores, y_scores\n return x_scores\n \n def fit_transform(self, X, y=None):\n \"\"\"Learn and apply the dimensionality reduction.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training samples.\n\n y : array-like of shape (n_samples,) or (n_samples, n_targets), default=None\n Targets.\n\n Returns\n -------\n out : array-like or tuple of array-like\n The transformed data `X_tranformed` if `Y` is not None,\n `(X_transformed, Y_transformed)` otherwise.\n \"\"\"\n return self.fit(X, y).transform(X, y)\n" + "description": "Partial Least Square SVD.\n\nThis transformer simply performs a SVD on the cross-covariance matrix `X'Y`. It is able to project both the training data `X` and the targets `Y`. The training data `X` is projected on the left singular vectors, while the targets are projected on the right singular vectors. Read more in the :ref:`User Guide `. .. versionadded:: 0.8", + "docstring": "Partial Least Square SVD.\n\n This transformer simply performs a SVD on the cross-covariance matrix\n `X'Y`. It is able to project both the training data `X` and the targets\n `Y`. The training data `X` is projected on the left singular vectors, while\n the targets are projected on the right singular vectors.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.8\n\n Parameters\n ----------\n n_components : int, default=2\n The number of components to keep. Should be in `[1,\n min(n_samples, n_features, n_targets)]`.\n\n scale : bool, default=True\n Whether to scale `X` and `Y`.\n\n copy : bool, default=True\n Whether to copy `X` and `Y` in fit before applying centering, and\n potentially scaling. If `False`, these operations will be done inplace,\n modifying both arrays.\n\n Attributes\n ----------\n x_weights_ : ndarray of shape (n_features, n_components)\n The left singular vectors of the SVD of the cross-covariance matrix.\n Used to project `X` in :meth:`transform`.\n\n y_weights_ : ndarray of (n_targets, n_components)\n The right singular vectors of the SVD of the cross-covariance matrix.\n Used to project `X` in :meth:`transform`.\n\n x_scores_ : ndarray of shape (n_samples, n_components)\n The transformed training samples.\n\n .. deprecated:: 0.24\n `x_scores_` is deprecated in 0.24 and will be removed in 1.1\n (renaming of 0.26). You can just call `transform` on the training\n data instead.\n\n y_scores_ : ndarray of shape (n_samples, n_components)\n The transformed training targets.\n\n .. deprecated:: 0.24\n `y_scores_` is deprecated in 0.24 and will be removed in 1.1\n (renaming of 0.26). You can just call `transform` on the training\n data instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n PLSCanonical : Partial Least Squares transformer and regressor.\n CCA : Canonical Correlation Analysis.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.cross_decomposition import PLSSVD\n >>> X = np.array([[0., 0., 1.],\n ... [1., 0., 0.],\n ... [2., 2., 2.],\n ... [2., 5., 4.]])\n >>> Y = np.array([[0.1, -0.2],\n ... [0.9, 1.1],\n ... [6.2, 5.9],\n ... [11.9, 12.3]])\n >>> pls = PLSSVD(n_components=2).fit(X, Y)\n >>> X_c, Y_c = pls.transform(X, Y)\n >>> X_c.shape, Y_c.shape\n ((4, 2), (4, 2))\n ", + "source_code": "\n\nclass PLSSVD(TransformerMixin, BaseEstimator):\n \"\"\"Partial Least Square SVD.\n\n This transformer simply performs a SVD on the cross-covariance matrix\n `X'Y`. It is able to project both the training data `X` and the targets\n `Y`. The training data `X` is projected on the left singular vectors, while\n the targets are projected on the right singular vectors.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.8\n\n Parameters\n ----------\n n_components : int, default=2\n The number of components to keep. Should be in `[1,\n min(n_samples, n_features, n_targets)]`.\n\n scale : bool, default=True\n Whether to scale `X` and `Y`.\n\n copy : bool, default=True\n Whether to copy `X` and `Y` in fit before applying centering, and\n potentially scaling. If `False`, these operations will be done inplace,\n modifying both arrays.\n\n Attributes\n ----------\n x_weights_ : ndarray of shape (n_features, n_components)\n The left singular vectors of the SVD of the cross-covariance matrix.\n Used to project `X` in :meth:`transform`.\n\n y_weights_ : ndarray of (n_targets, n_components)\n The right singular vectors of the SVD of the cross-covariance matrix.\n Used to project `X` in :meth:`transform`.\n\n x_scores_ : ndarray of shape (n_samples, n_components)\n The transformed training samples.\n\n .. deprecated:: 0.24\n `x_scores_` is deprecated in 0.24 and will be removed in 1.1\n (renaming of 0.26). You can just call `transform` on the training\n data instead.\n\n y_scores_ : ndarray of shape (n_samples, n_components)\n The transformed training targets.\n\n .. deprecated:: 0.24\n `y_scores_` is deprecated in 0.24 and will be removed in 1.1\n (renaming of 0.26). You can just call `transform` on the training\n data instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n PLSCanonical : Partial Least Squares transformer and regressor.\n CCA : Canonical Correlation Analysis.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.cross_decomposition import PLSSVD\n >>> X = np.array([[0., 0., 1.],\n ... [1., 0., 0.],\n ... [2., 2., 2.],\n ... [2., 5., 4.]])\n >>> Y = np.array([[0.1, -0.2],\n ... [0.9, 1.1],\n ... [6.2, 5.9],\n ... [11.9, 12.3]])\n >>> pls = PLSSVD(n_components=2).fit(X, Y)\n >>> X_c, Y_c = pls.transform(X, Y)\n >>> X_c.shape, Y_c.shape\n ((4, 2), (4, 2))\n \"\"\"\n \n def __init__(self, n_components=2, *, scale=True, copy=True):\n self.n_components = n_components\n self.scale = scale\n self.copy = copy\n \n def fit(self, X, Y):\n \"\"\"Fit model to data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training samples.\n\n Y : array-like of shape (n_samples,) or (n_samples, n_targets)\n Targets.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n check_consistent_length(X, Y)\n X = self._validate_data(X, dtype=np.float64, copy=self.copy, ensure_min_samples=2)\n Y = check_array(Y, dtype=np.float64, copy=self.copy, ensure_2d=False)\n if Y.ndim == 1:\n Y = Y.reshape(-1, 1)\n n_components = self.n_components\n rank_upper_bound = min(X.shape[0], X.shape[1], Y.shape[1])\n if not 1 <= n_components <= rank_upper_bound:\n warnings.warn(f'As of version 0.24, n_components({n_components}) should be in [1, min(n_features, n_samples, n_targets)] = [1, {rank_upper_bound}]. n_components={rank_upper_bound} will be used instead. In version 1.1 (renaming of 0.26), an error will be raised.', FutureWarning)\n n_components = rank_upper_bound\n (X, Y, self._x_mean, self._y_mean, self._x_std, self._y_std) = _center_scale_xy(X, Y, self.scale)\n C = np.dot(X.T, Y)\n (U, s, Vt) = svd(C, full_matrices=False)\n U = U[:, :n_components]\n Vt = Vt[:n_components]\n (U, Vt) = svd_flip(U, Vt)\n V = Vt.T\n self._x_scores = np.dot(X, U)\n self._y_scores = np.dot(Y, V)\n self.x_weights_ = U\n self.y_weights_ = V\n return self\n \n @deprecated('Attribute `x_scores_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26). Use est.transform(X) on the training data instead.')\n @property\n def x_scores_(self):\n return self._x_scores\n \n @deprecated('Attribute `y_scores_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26). Use est.transform(X, Y) on the training data instead.')\n @property\n def y_scores_(self):\n return self._y_scores\n \n @deprecated('Attribute `x_mean_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def x_mean_(self):\n return self._x_mean\n \n @deprecated('Attribute `y_mean_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def y_mean_(self):\n return self._y_mean\n \n @deprecated('Attribute `x_std_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def x_std_(self):\n return self._x_std\n \n @deprecated('Attribute `y_std_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def y_std_(self):\n return self._y_std\n \n def transform(self, X, Y=None):\n \"\"\"\n Apply the dimensionality reduction.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Samples to be transformed.\n\n Y : array-like of shape (n_samples,) or (n_samples, n_targets), default=None\n Targets.\n\n Returns\n -------\n x_scores : array-like or tuple of array-like\n The transformed data `X_tranformed` if `Y is not None`,\n `(X_transformed, Y_transformed)` otherwise.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, dtype=np.float64, reset=False)\n Xr = (X - self._x_mean) / self._x_std\n x_scores = np.dot(Xr, self.x_weights_)\n if Y is not None:\n Y = check_array(Y, ensure_2d=False, dtype=np.float64)\n if Y.ndim == 1:\n Y = Y.reshape(-1, 1)\n Yr = (Y - self._y_mean) / self._y_std\n y_scores = np.dot(Yr, self.y_weights_)\n return x_scores, y_scores\n return x_scores\n \n def fit_transform(self, X, y=None):\n \"\"\"Learn and apply the dimensionality reduction.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training samples.\n\n y : array-like of shape (n_samples,) or (n_samples, n_targets), default=None\n Targets.\n\n Returns\n -------\n out : array-like or tuple of array-like\n The transformed data `X_tranformed` if `Y is not None`,\n `(X_transformed, Y_transformed)` otherwise.\n \"\"\"\n return self.fit(X, y).transform(X, y)\n" }, { "name": "_PLS", @@ -20428,13 +20395,13 @@ "sklearn.cross_decomposition._pls._PLS.inverse_transform", "sklearn.cross_decomposition._pls._PLS.predict", "sklearn.cross_decomposition._pls._PLS.fit_transform", - "sklearn.cross_decomposition._pls._PLS.norm_y_weights", - "sklearn.cross_decomposition._pls._PLS.x_mean_", - "sklearn.cross_decomposition._pls._PLS.y_mean_", - "sklearn.cross_decomposition._pls._PLS.x_std_", - "sklearn.cross_decomposition._pls._PLS.y_std_", - "sklearn.cross_decomposition._pls._PLS.x_scores_", - "sklearn.cross_decomposition._pls._PLS.y_scores_", + "sklearn.cross_decomposition._pls._PLS.norm_y_weights@getter", + "sklearn.cross_decomposition._pls._PLS.x_mean_@getter", + "sklearn.cross_decomposition._pls._PLS.y_mean_@getter", + "sklearn.cross_decomposition._pls._PLS.x_std_@getter", + "sklearn.cross_decomposition._pls._PLS.y_std_@getter", + "sklearn.cross_decomposition._pls._PLS.x_scores_@getter", + "sklearn.cross_decomposition._pls._PLS.y_scores_@getter", "sklearn.cross_decomposition._pls._PLS._more_tags" ], "is_public": false, @@ -20507,11 +20474,11 @@ "methods": [ "sklearn.decomposition._dict_learning.SparseCoder.__init__", "sklearn.decomposition._dict_learning.SparseCoder.fit", - "sklearn.decomposition._dict_learning.SparseCoder.components_", + "sklearn.decomposition._dict_learning.SparseCoder.components_@getter", "sklearn.decomposition._dict_learning.SparseCoder.transform", "sklearn.decomposition._dict_learning.SparseCoder._more_tags", - "sklearn.decomposition._dict_learning.SparseCoder.n_components_", - "sklearn.decomposition._dict_learning.SparseCoder.n_features_in_" + "sklearn.decomposition._dict_learning.SparseCoder.n_components_@getter", + "sklearn.decomposition._dict_learning.SparseCoder.n_features_in_@getter" ], "is_public": true, "description": "Sparse coding.\n\nFinds a sparse representation of data against a fixed, precomputed dictionary. Each row of the result is the solution to a sparse coding problem. The goal is to find a sparse array `code` such that:: X ~= code * dictionary Read more in the :ref:`User Guide `.", @@ -20594,9 +20561,9 @@ "superclasses": ["TransformerMixin", "BaseEstimator"], "methods": [ "sklearn.decomposition._kernel_pca.KernelPCA.__init__", - "sklearn.decomposition._kernel_pca.KernelPCA._pairwise", - "sklearn.decomposition._kernel_pca.KernelPCA.lambdas_", - "sklearn.decomposition._kernel_pca.KernelPCA.alphas_", + "sklearn.decomposition._kernel_pca.KernelPCA._pairwise@getter", + "sklearn.decomposition._kernel_pca.KernelPCA.lambdas_@getter", + "sklearn.decomposition._kernel_pca.KernelPCA.alphas_@getter", "sklearn.decomposition._kernel_pca.KernelPCA._get_kernel", "sklearn.decomposition._kernel_pca.KernelPCA._fit_transform", "sklearn.decomposition._kernel_pca.KernelPCA._fit_inverse_transform", @@ -20636,7 +20603,7 @@ "is_public": true, "description": "Latent Dirichlet Allocation with online variational Bayes algorithm.\n\nThe implementation is based on [1]_ and [2]_. .. versionadded:: 0.17 Read more in the :ref:`User Guide `.", "docstring": "Latent Dirichlet Allocation with online variational Bayes algorithm.\n\n The implementation is based on [1]_ and [2]_.\n\n .. versionadded:: 0.17\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_components : int, default=10\n Number of topics.\n\n .. versionchanged:: 0.19\n ``n_topics`` was renamed to ``n_components``\n\n doc_topic_prior : float, default=None\n Prior of document topic distribution `theta`. If the value is None,\n defaults to `1 / n_components`.\n In [1]_, this is called `alpha`.\n\n topic_word_prior : float, default=None\n Prior of topic word distribution `beta`. If the value is None, defaults\n to `1 / n_components`.\n In [1]_, this is called `eta`.\n\n learning_method : {'batch', 'online'}, default='batch'\n Method used to update `_component`. Only used in :meth:`fit` method.\n In general, if the data size is large, the online update will be much\n faster than the batch update.\n\n Valid options::\n\n 'batch': Batch variational Bayes method. Use all training data in\n each EM update.\n Old `components_` will be overwritten in each iteration.\n 'online': Online variational Bayes method. In each EM update, use\n mini-batch of training data to update the ``components_``\n variable incrementally. The learning rate is controlled by the\n ``learning_decay`` and the ``learning_offset`` parameters.\n\n .. versionchanged:: 0.20\n The default learning method is now ``\"batch\"``.\n\n learning_decay : float, default=0.7\n It is a parameter that control learning rate in the online learning\n method. The value should be set between (0.5, 1.0] to guarantee\n asymptotic convergence. When the value is 0.0 and batch_size is\n ``n_samples``, the update method is same as batch learning. In the\n literature, this is called kappa.\n\n learning_offset : float, default=10.0\n A (positive) parameter that downweights early iterations in online\n learning. It should be greater than 1.0. In the literature, this is\n called tau_0.\n\n max_iter : int, default=10\n The maximum number of passes over the training data (aka epochs).\n It only impacts the behavior in the :meth:`fit` method, and not the\n :meth:`partial_fit` method.\n\n batch_size : int, default=128\n Number of documents to use in each EM iteration. Only used in online\n learning.\n\n evaluate_every : int, default=-1\n How often to evaluate perplexity. Only used in `fit` method.\n set it to 0 or negative number to not evaluate perplexity in\n training at all. Evaluating perplexity can help you check convergence\n in training process, but it will also increase total training time.\n Evaluating perplexity in every iteration might increase training time\n up to two-fold.\n\n total_samples : int, default=1e6\n Total number of documents. Only used in the :meth:`partial_fit` method.\n\n perp_tol : float, default=1e-1\n Perplexity tolerance in batch learning. Only used when\n ``evaluate_every`` is greater than 0.\n\n mean_change_tol : float, default=1e-3\n Stopping tolerance for updating document topic distribution in E-step.\n\n max_doc_update_iter : int, default=100\n Max number of iterations for updating document topic distribution in\n the E-step.\n\n n_jobs : int, default=None\n The number of jobs to use in the E-step.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n verbose : int, default=0\n Verbosity level.\n\n random_state : int, RandomState instance or None, default=None\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n Attributes\n ----------\n components_ : ndarray of shape (n_components, n_features)\n Variational parameters for topic word distribution. Since the complete\n conditional for topic word distribution is a Dirichlet,\n ``components_[i, j]`` can be viewed as pseudocount that represents the\n number of times word `j` was assigned to topic `i`.\n It can also be viewed as distribution over the words for each topic\n after normalization:\n ``model.components_ / model.components_.sum(axis=1)[:, np.newaxis]``.\n\n exp_dirichlet_component_ : ndarray of shape (n_components, n_features)\n Exponential value of expectation of log topic word distribution.\n In the literature, this is `exp(E[log(beta)])`.\n\n n_batch_iter_ : int\n Number of iterations of the EM step.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n Number of passes over the dataset.\n\n bound_ : float\n Final perplexity score on training set.\n\n doc_topic_prior_ : float\n Prior of document topic distribution `theta`. If the value is None,\n it is `1 / n_components`.\n\n random_state_ : RandomState instance\n RandomState instance that is generated either from a seed, the random\n number generator or by `np.random`.\n\n topic_word_prior_ : float\n Prior of topic word distribution `beta`. If the value is None, it is\n `1 / n_components`.\n\n See Also\n --------\n sklearn.discriminant_analysis.LinearDiscriminantAnalysis:\n A classifier with a linear decision boundary, generated by fitting\n class conditional densities to the data and using Bayes\u2019 rule.\n\n References\n ----------\n .. [1] \"Online Learning for Latent Dirichlet Allocation\", Matthew D.\n Hoffman, David M. Blei, Francis Bach, 2010\n https://github.com/blei-lab/onlineldavb\n\n .. [2] \"Stochastic Variational Inference\", Matthew D. Hoffman,\n David M. Blei, Chong Wang, John Paisley, 2013\n\n Examples\n --------\n >>> from sklearn.decomposition import LatentDirichletAllocation\n >>> from sklearn.datasets import make_multilabel_classification\n >>> # This produces a feature matrix of token counts, similar to what\n >>> # CountVectorizer would produce on text.\n >>> X, _ = make_multilabel_classification(random_state=0)\n >>> lda = LatentDirichletAllocation(n_components=5,\n ... random_state=0)\n >>> lda.fit(X)\n LatentDirichletAllocation(...)\n >>> # get topics for some given samples:\n >>> lda.transform(X[-2:])\n array([[0.00360392, 0.25499205, 0.0036211 , 0.64236448, 0.09541846],\n [0.15297572, 0.00362644, 0.44412786, 0.39568399, 0.003586 ]])\n ", - "source_code": "\n\nclass LatentDirichletAllocation(TransformerMixin, BaseEstimator):\n \"\"\"Latent Dirichlet Allocation with online variational Bayes algorithm.\n\n The implementation is based on [1]_ and [2]_.\n\n .. versionadded:: 0.17\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_components : int, default=10\n Number of topics.\n\n .. versionchanged:: 0.19\n ``n_topics`` was renamed to ``n_components``\n\n doc_topic_prior : float, default=None\n Prior of document topic distribution `theta`. If the value is None,\n defaults to `1 / n_components`.\n In [1]_, this is called `alpha`.\n\n topic_word_prior : float, default=None\n Prior of topic word distribution `beta`. If the value is None, defaults\n to `1 / n_components`.\n In [1]_, this is called `eta`.\n\n learning_method : {'batch', 'online'}, default='batch'\n Method used to update `_component`. Only used in :meth:`fit` method.\n In general, if the data size is large, the online update will be much\n faster than the batch update.\n\n Valid options::\n\n 'batch': Batch variational Bayes method. Use all training data in\n each EM update.\n Old `components_` will be overwritten in each iteration.\n 'online': Online variational Bayes method. In each EM update, use\n mini-batch of training data to update the ``components_``\n variable incrementally. The learning rate is controlled by the\n ``learning_decay`` and the ``learning_offset`` parameters.\n\n .. versionchanged:: 0.20\n The default learning method is now ``\"batch\"``.\n\n learning_decay : float, default=0.7\n It is a parameter that control learning rate in the online learning\n method. The value should be set between (0.5, 1.0] to guarantee\n asymptotic convergence. When the value is 0.0 and batch_size is\n ``n_samples``, the update method is same as batch learning. In the\n literature, this is called kappa.\n\n learning_offset : float, default=10.0\n A (positive) parameter that downweights early iterations in online\n learning. It should be greater than 1.0. In the literature, this is\n called tau_0.\n\n max_iter : int, default=10\n The maximum number of passes over the training data (aka epochs).\n It only impacts the behavior in the :meth:`fit` method, and not the\n :meth:`partial_fit` method.\n\n batch_size : int, default=128\n Number of documents to use in each EM iteration. Only used in online\n learning.\n\n evaluate_every : int, default=-1\n How often to evaluate perplexity. Only used in `fit` method.\n set it to 0 or negative number to not evaluate perplexity in\n training at all. Evaluating perplexity can help you check convergence\n in training process, but it will also increase total training time.\n Evaluating perplexity in every iteration might increase training time\n up to two-fold.\n\n total_samples : int, default=1e6\n Total number of documents. Only used in the :meth:`partial_fit` method.\n\n perp_tol : float, default=1e-1\n Perplexity tolerance in batch learning. Only used when\n ``evaluate_every`` is greater than 0.\n\n mean_change_tol : float, default=1e-3\n Stopping tolerance for updating document topic distribution in E-step.\n\n max_doc_update_iter : int, default=100\n Max number of iterations for updating document topic distribution in\n the E-step.\n\n n_jobs : int, default=None\n The number of jobs to use in the E-step.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n verbose : int, default=0\n Verbosity level.\n\n random_state : int, RandomState instance or None, default=None\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n Attributes\n ----------\n components_ : ndarray of shape (n_components, n_features)\n Variational parameters for topic word distribution. Since the complete\n conditional for topic word distribution is a Dirichlet,\n ``components_[i, j]`` can be viewed as pseudocount that represents the\n number of times word `j` was assigned to topic `i`.\n It can also be viewed as distribution over the words for each topic\n after normalization:\n ``model.components_ / model.components_.sum(axis=1)[:, np.newaxis]``.\n\n exp_dirichlet_component_ : ndarray of shape (n_components, n_features)\n Exponential value of expectation of log topic word distribution.\n In the literature, this is `exp(E[log(beta)])`.\n\n n_batch_iter_ : int\n Number of iterations of the EM step.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n Number of passes over the dataset.\n\n bound_ : float\n Final perplexity score on training set.\n\n doc_topic_prior_ : float\n Prior of document topic distribution `theta`. If the value is None,\n it is `1 / n_components`.\n\n random_state_ : RandomState instance\n RandomState instance that is generated either from a seed, the random\n number generator or by `np.random`.\n\n topic_word_prior_ : float\n Prior of topic word distribution `beta`. If the value is None, it is\n `1 / n_components`.\n\n See Also\n --------\n sklearn.discriminant_analysis.LinearDiscriminantAnalysis:\n A classifier with a linear decision boundary, generated by fitting\n class conditional densities to the data and using Bayes\u2019 rule.\n\n References\n ----------\n .. [1] \"Online Learning for Latent Dirichlet Allocation\", Matthew D.\n Hoffman, David M. Blei, Francis Bach, 2010\n https://github.com/blei-lab/onlineldavb\n\n .. [2] \"Stochastic Variational Inference\", Matthew D. Hoffman,\n David M. Blei, Chong Wang, John Paisley, 2013\n\n Examples\n --------\n >>> from sklearn.decomposition import LatentDirichletAllocation\n >>> from sklearn.datasets import make_multilabel_classification\n >>> # This produces a feature matrix of token counts, similar to what\n >>> # CountVectorizer would produce on text.\n >>> X, _ = make_multilabel_classification(random_state=0)\n >>> lda = LatentDirichletAllocation(n_components=5,\n ... random_state=0)\n >>> lda.fit(X)\n LatentDirichletAllocation(...)\n >>> # get topics for some given samples:\n >>> lda.transform(X[-2:])\n array([[0.00360392, 0.25499205, 0.0036211 , 0.64236448, 0.09541846],\n [0.15297572, 0.00362644, 0.44412786, 0.39568399, 0.003586 ]])\n \"\"\"\n \n def __init__(self, n_components=10, *, doc_topic_prior=None, topic_word_prior=None, learning_method='batch', learning_decay=0.7, learning_offset=10.0, max_iter=10, batch_size=128, evaluate_every=-1, total_samples=1000000.0, perp_tol=0.1, mean_change_tol=0.001, max_doc_update_iter=100, n_jobs=None, verbose=0, random_state=None):\n self.n_components = n_components\n self.doc_topic_prior = doc_topic_prior\n self.topic_word_prior = topic_word_prior\n self.learning_method = learning_method\n self.learning_decay = learning_decay\n self.learning_offset = learning_offset\n self.max_iter = max_iter\n self.batch_size = batch_size\n self.evaluate_every = evaluate_every\n self.total_samples = total_samples\n self.perp_tol = perp_tol\n self.mean_change_tol = mean_change_tol\n self.max_doc_update_iter = max_doc_update_iter\n self.n_jobs = n_jobs\n self.verbose = verbose\n self.random_state = random_state\n \n def _check_params(self):\n \"\"\"Check model parameters.\"\"\"\n if self.n_components <= 0:\n raise ValueError(\"Invalid 'n_components' parameter: %r\" % self.n_components)\n if self.total_samples <= 0:\n raise ValueError(\"Invalid 'total_samples' parameter: %r\" % self.total_samples)\n if self.learning_offset < 0:\n raise ValueError(\"Invalid 'learning_offset' parameter: %r\" % self.learning_offset)\n if self.learning_method not in ('batch', 'online'):\n raise ValueError(\"Invalid 'learning_method' parameter: %r\" % self.learning_method)\n \n def _init_latent_vars(self, n_features):\n \"\"\"Initialize latent variables.\"\"\"\n self.random_state_ = check_random_state(self.random_state)\n self.n_batch_iter_ = 1\n self.n_iter_ = 0\n if self.doc_topic_prior is None:\n self.doc_topic_prior_ = 1.0 / self.n_components\n else:\n self.doc_topic_prior_ = self.doc_topic_prior\n if self.topic_word_prior is None:\n self.topic_word_prior_ = 1.0 / self.n_components\n else:\n self.topic_word_prior_ = self.topic_word_prior\n init_gamma = 100.0\n init_var = 1.0 / init_gamma\n self.components_ = self.random_state_.gamma(init_gamma, init_var, (self.n_components, n_features))\n self.exp_dirichlet_component_ = np.exp(_dirichlet_expectation_2d(self.components_))\n \n def _e_step(self, X, cal_sstats, random_init, parallel=None):\n \"\"\"E-step in EM update.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n cal_sstats : bool\n Parameter that indicate whether to calculate sufficient statistics\n or not. Set ``cal_sstats`` to True when we need to run M-step.\n\n random_init : bool\n Parameter that indicate whether to initialize document topic\n distribution randomly in the E-step. Set it to True in training\n steps.\n\n parallel : joblib.Parallel, default=None\n Pre-initialized instance of joblib.Parallel.\n\n Returns\n -------\n (doc_topic_distr, suff_stats) :\n `doc_topic_distr` is unnormalized topic distribution for each\n document. In the literature, this is called `gamma`.\n `suff_stats` is expected sufficient statistics for the M-step.\n When `cal_sstats == False`, it will be None.\n\n \"\"\"\n random_state = self.random_state_ if random_init else None\n n_jobs = effective_n_jobs(self.n_jobs)\n if parallel is None:\n parallel = Parallel(n_jobs=n_jobs, verbose=max(0, self.verbose - 1))\n results = parallel((delayed(_update_doc_distribution)(X[idx_slice, :], self.exp_dirichlet_component_, self.doc_topic_prior_, self.max_doc_update_iter, self.mean_change_tol, cal_sstats, random_state) for idx_slice in gen_even_slices(X.shape[0], n_jobs)))\n (doc_topics, sstats_list) = zip(*results)\n doc_topic_distr = np.vstack(doc_topics)\n if cal_sstats:\n suff_stats = np.zeros(self.components_.shape)\n for sstats in sstats_list:\n suff_stats += sstats\n suff_stats *= self.exp_dirichlet_component_\n else:\n suff_stats = None\n return doc_topic_distr, suff_stats\n \n def _em_step(self, X, total_samples, batch_update, parallel=None):\n \"\"\"EM update for 1 iteration.\n\n update `_component` by batch VB or online VB.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n total_samples : int\n Total number of documents. It is only used when\n batch_update is `False`.\n\n batch_update : bool\n Parameter that controls updating method.\n `True` for batch learning, `False` for online learning.\n\n parallel : joblib.Parallel, default=None\n Pre-initialized instance of joblib.Parallel\n\n Returns\n -------\n doc_topic_distr : ndarray of shape (n_samples, n_components)\n Unnormalized document topic distribution.\n \"\"\"\n (_, suff_stats) = self._e_step(X, cal_sstats=True, random_init=True, parallel=parallel)\n if batch_update:\n self.components_ = self.topic_word_prior_ + suff_stats\n else:\n weight = np.power(self.learning_offset + self.n_batch_iter_, -self.learning_decay)\n doc_ratio = float(total_samples) / X.shape[0]\n self.components_ *= 1 - weight\n self.components_ += weight * (self.topic_word_prior_ + doc_ratio * suff_stats)\n self.exp_dirichlet_component_ = np.exp(_dirichlet_expectation_2d(self.components_))\n self.n_batch_iter_ += 1\n return\n \n def _more_tags(self):\n return {'requires_positive_X': True}\n \n def _check_non_neg_array(self, X, reset_n_features, whom):\n \"\"\"check X format\n\n check X format and make sure no negative value in X.\n\n Parameters\n ----------\n X : array-like or sparse matrix\n\n \"\"\"\n X = self._validate_data(X, reset=reset_n_features, accept_sparse='csr')\n check_non_negative(X, whom)\n return X\n \n def partial_fit(self, X, y=None):\n \"\"\"Online VB with Mini-Batch update.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self\n Partially fitted estimator.\n \"\"\"\n self._check_params()\n first_time = not hasattr(self, 'components_')\n X = self._check_non_neg_array(X, reset_n_features=first_time, whom='LatentDirichletAllocation.partial_fit')\n (n_samples, n_features) = X.shape\n batch_size = self.batch_size\n if first_time:\n self._init_latent_vars(n_features)\n if n_features != self.components_.shape[1]:\n raise ValueError('The provided data has %d dimensions while the model was trained with feature size %d.' % (n_features, self.components_.shape[1]))\n n_jobs = effective_n_jobs(self.n_jobs)\n with Parallel(n_jobs=n_jobs, verbose=max(0, self.verbose - 1)) as parallel:\n for idx_slice in gen_batches(n_samples, batch_size):\n self._em_step(X[idx_slice, :], total_samples=self.total_samples, batch_update=False, parallel=parallel)\n return self\n \n def fit(self, X, y=None):\n \"\"\"Learn model for the data X with variational Bayes method.\n\n When `learning_method` is 'online', use mini-batch update.\n Otherwise, use batch update.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self\n Fitted estimator.\n \"\"\"\n self._check_params()\n X = self._check_non_neg_array(X, reset_n_features=True, whom='LatentDirichletAllocation.fit')\n (n_samples, n_features) = X.shape\n max_iter = self.max_iter\n evaluate_every = self.evaluate_every\n learning_method = self.learning_method\n batch_size = self.batch_size\n self._init_latent_vars(n_features)\n last_bound = None\n n_jobs = effective_n_jobs(self.n_jobs)\n with Parallel(n_jobs=n_jobs, verbose=max(0, self.verbose - 1)) as parallel:\n for i in range(max_iter):\n if learning_method == 'online':\n for idx_slice in gen_batches(n_samples, batch_size):\n self._em_step(X[idx_slice, :], total_samples=n_samples, batch_update=False, parallel=parallel)\n else:\n self._em_step(X, total_samples=n_samples, batch_update=True, parallel=parallel)\n if evaluate_every > 0 and (i + 1) % evaluate_every == 0:\n (doc_topics_distr, _) = self._e_step(X, cal_sstats=False, random_init=False, parallel=parallel)\n bound = self._perplexity_precomp_distr(X, doc_topics_distr, sub_sampling=False)\n if self.verbose:\n print('iteration: %d of max_iter: %d, perplexity: %.4f' % (i + 1, max_iter, bound))\n if last_bound and abs(last_bound - bound) < self.perp_tol:\n break\n last_bound = bound\n elif self.verbose:\n print('iteration: %d of max_iter: %d' % (i + 1, max_iter))\n self.n_iter_ += 1\n (doc_topics_distr, _) = self._e_step(X, cal_sstats=False, random_init=False, parallel=parallel)\n self.bound_ = self._perplexity_precomp_distr(X, doc_topics_distr, sub_sampling=False)\n return self\n \n def _unnormalized_transform(self, X):\n \"\"\"Transform data X according to fitted model.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n Returns\n -------\n doc_topic_distr : ndarray of shape (n_samples, n_components)\n Document topic distribution for X.\n \"\"\"\n check_is_fitted(self)\n X = self._check_non_neg_array(X, reset_n_features=True, whom='LatentDirichletAllocation.transform')\n (n_samples, n_features) = X.shape\n if n_features != self.components_.shape[1]:\n raise ValueError('The provided data has %d dimensions while the model was trained with feature size %d.' % (n_features, self.components_.shape[1]))\n (doc_topic_distr, _) = self._e_step(X, cal_sstats=False, random_init=False)\n return doc_topic_distr\n \n def transform(self, X):\n \"\"\"Transform data X according to the fitted model.\n\n .. versionchanged:: 0.18\n *doc_topic_distr* is now normalized\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n Returns\n -------\n doc_topic_distr : ndarray of shape (n_samples, n_components)\n Document topic distribution for X.\n \"\"\"\n check_is_fitted(self)\n X = self._check_non_neg_array(X, reset_n_features=False, whom='LatentDirichletAllocation.transform')\n doc_topic_distr = self._unnormalized_transform(X)\n doc_topic_distr /= doc_topic_distr.sum(axis=1)[:, np.newaxis]\n return doc_topic_distr\n \n def _approx_bound(self, X, doc_topic_distr, sub_sampling):\n \"\"\"Estimate the variational bound.\n\n Estimate the variational bound over \"all documents\" using only the\n documents passed in as X. Since log-likelihood of each word cannot\n be computed directly, we use this bound to estimate it.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n doc_topic_distr : ndarray of shape (n_samples, n_components)\n Document topic distribution. In the literature, this is called\n gamma.\n\n sub_sampling : bool, default=False\n Compensate for subsampling of documents.\n It is used in calculate bound in online learning.\n\n Returns\n -------\n score : float\n\n \"\"\"\n \n def _loglikelihood(prior, distr, dirichlet_distr, size):\n score = np.sum((prior - distr) * dirichlet_distr)\n score += np.sum(gammaln(distr) - gammaln(prior))\n score += np.sum(gammaln(prior * size) - gammaln(np.sum(distr, 1)))\n return score\n is_sparse_x = sp.issparse(X)\n (n_samples, n_components) = doc_topic_distr.shape\n n_features = self.components_.shape[1]\n score = 0\n dirichlet_doc_topic = _dirichlet_expectation_2d(doc_topic_distr)\n dirichlet_component_ = _dirichlet_expectation_2d(self.components_)\n doc_topic_prior = self.doc_topic_prior_\n topic_word_prior = self.topic_word_prior_\n if is_sparse_x:\n X_data = X.data\n X_indices = X.indices\n X_indptr = X.indptr\n for idx_d in range(0, n_samples):\n if is_sparse_x:\n ids = X_indices[X_indptr[idx_d]:X_indptr[idx_d + 1]]\n cnts = X_data[X_indptr[idx_d]:X_indptr[idx_d + 1]]\n else:\n ids = np.nonzero(X[idx_d, :])[0]\n cnts = X[idx_d, ids]\n temp = dirichlet_doc_topic[idx_d, :, np.newaxis] + dirichlet_component_[:, ids]\n norm_phi = logsumexp(temp, axis=0)\n score += np.dot(cnts, norm_phi)\n score += _loglikelihood(doc_topic_prior, doc_topic_distr, dirichlet_doc_topic, self.n_components)\n if sub_sampling:\n doc_ratio = float(self.total_samples) / n_samples\n score *= doc_ratio\n score += _loglikelihood(topic_word_prior, self.components_, dirichlet_component_, n_features)\n return score\n \n def score(self, X, y=None):\n \"\"\"Calculate approximate log-likelihood as score.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n score : float\n Use approximate bound as score.\n \"\"\"\n check_is_fitted(self)\n X = self._check_non_neg_array(X, reset_n_features=False, whom='LatentDirichletAllocation.score')\n doc_topic_distr = self._unnormalized_transform(X)\n score = self._approx_bound(X, doc_topic_distr, sub_sampling=False)\n return score\n \n def _perplexity_precomp_distr(self, X, doc_topic_distr=None, sub_sampling=False):\n \"\"\"Calculate approximate perplexity for data X with ability to accept\n precomputed doc_topic_distr\n\n Perplexity is defined as exp(-1. * log-likelihood per word)\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n doc_topic_distr : ndarray of shape (n_samples, n_components), default=None\n Document topic distribution.\n If it is None, it will be generated by applying transform on X.\n\n Returns\n -------\n score : float\n Perplexity score.\n \"\"\"\n check_is_fitted(self)\n X = self._check_non_neg_array(X, reset_n_features=True, whom='LatentDirichletAllocation.perplexity')\n if doc_topic_distr is None:\n doc_topic_distr = self._unnormalized_transform(X)\n else:\n (n_samples, n_components) = doc_topic_distr.shape\n if n_samples != X.shape[0]:\n raise ValueError('Number of samples in X and doc_topic_distr do not match.')\n if n_components != self.n_components:\n raise ValueError('Number of topics does not match.')\n current_samples = X.shape[0]\n bound = self._approx_bound(X, doc_topic_distr, sub_sampling)\n if sub_sampling:\n word_cnt = X.sum() * (float(self.total_samples) / current_samples)\n else:\n word_cnt = X.sum()\n perword_bound = bound / word_cnt\n return np.exp(-1.0 * perword_bound)\n \n def perplexity(self, X, sub_sampling=False):\n \"\"\"Calculate approximate perplexity for data X.\n\n Perplexity is defined as exp(-1. * log-likelihood per word)\n\n .. versionchanged:: 0.19\n *doc_topic_distr* argument has been deprecated and is ignored\n because user no longer has access to unnormalized distribution\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n sub_sampling : bool\n Do sub-sampling or not.\n\n Returns\n -------\n score : float\n Perplexity score.\n \"\"\"\n return self._perplexity_precomp_distr(X, sub_sampling=sub_sampling)\n" + "source_code": "\n\nclass LatentDirichletAllocation(TransformerMixin, BaseEstimator):\n \"\"\"Latent Dirichlet Allocation with online variational Bayes algorithm.\n\n The implementation is based on [1]_ and [2]_.\n\n .. versionadded:: 0.17\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_components : int, default=10\n Number of topics.\n\n .. versionchanged:: 0.19\n ``n_topics`` was renamed to ``n_components``\n\n doc_topic_prior : float, default=None\n Prior of document topic distribution `theta`. If the value is None,\n defaults to `1 / n_components`.\n In [1]_, this is called `alpha`.\n\n topic_word_prior : float, default=None\n Prior of topic word distribution `beta`. If the value is None, defaults\n to `1 / n_components`.\n In [1]_, this is called `eta`.\n\n learning_method : {'batch', 'online'}, default='batch'\n Method used to update `_component`. Only used in :meth:`fit` method.\n In general, if the data size is large, the online update will be much\n faster than the batch update.\n\n Valid options::\n\n 'batch': Batch variational Bayes method. Use all training data in\n each EM update.\n Old `components_` will be overwritten in each iteration.\n 'online': Online variational Bayes method. In each EM update, use\n mini-batch of training data to update the ``components_``\n variable incrementally. The learning rate is controlled by the\n ``learning_decay`` and the ``learning_offset`` parameters.\n\n .. versionchanged:: 0.20\n The default learning method is now ``\"batch\"``.\n\n learning_decay : float, default=0.7\n It is a parameter that control learning rate in the online learning\n method. The value should be set between (0.5, 1.0] to guarantee\n asymptotic convergence. When the value is 0.0 and batch_size is\n ``n_samples``, the update method is same as batch learning. In the\n literature, this is called kappa.\n\n learning_offset : float, default=10.0\n A (positive) parameter that downweights early iterations in online\n learning. It should be greater than 1.0. In the literature, this is\n called tau_0.\n\n max_iter : int, default=10\n The maximum number of passes over the training data (aka epochs).\n It only impacts the behavior in the :meth:`fit` method, and not the\n :meth:`partial_fit` method.\n\n batch_size : int, default=128\n Number of documents to use in each EM iteration. Only used in online\n learning.\n\n evaluate_every : int, default=-1\n How often to evaluate perplexity. Only used in `fit` method.\n set it to 0 or negative number to not evaluate perplexity in\n training at all. Evaluating perplexity can help you check convergence\n in training process, but it will also increase total training time.\n Evaluating perplexity in every iteration might increase training time\n up to two-fold.\n\n total_samples : int, default=1e6\n Total number of documents. Only used in the :meth:`partial_fit` method.\n\n perp_tol : float, default=1e-1\n Perplexity tolerance in batch learning. Only used when\n ``evaluate_every`` is greater than 0.\n\n mean_change_tol : float, default=1e-3\n Stopping tolerance for updating document topic distribution in E-step.\n\n max_doc_update_iter : int, default=100\n Max number of iterations for updating document topic distribution in\n the E-step.\n\n n_jobs : int, default=None\n The number of jobs to use in the E-step.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n verbose : int, default=0\n Verbosity level.\n\n random_state : int, RandomState instance or None, default=None\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n Attributes\n ----------\n components_ : ndarray of shape (n_components, n_features)\n Variational parameters for topic word distribution. Since the complete\n conditional for topic word distribution is a Dirichlet,\n ``components_[i, j]`` can be viewed as pseudocount that represents the\n number of times word `j` was assigned to topic `i`.\n It can also be viewed as distribution over the words for each topic\n after normalization:\n ``model.components_ / model.components_.sum(axis=1)[:, np.newaxis]``.\n\n exp_dirichlet_component_ : ndarray of shape (n_components, n_features)\n Exponential value of expectation of log topic word distribution.\n In the literature, this is `exp(E[log(beta)])`.\n\n n_batch_iter_ : int\n Number of iterations of the EM step.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n Number of passes over the dataset.\n\n bound_ : float\n Final perplexity score on training set.\n\n doc_topic_prior_ : float\n Prior of document topic distribution `theta`. If the value is None,\n it is `1 / n_components`.\n\n random_state_ : RandomState instance\n RandomState instance that is generated either from a seed, the random\n number generator or by `np.random`.\n\n topic_word_prior_ : float\n Prior of topic word distribution `beta`. If the value is None, it is\n `1 / n_components`.\n\n See Also\n --------\n sklearn.discriminant_analysis.LinearDiscriminantAnalysis:\n A classifier with a linear decision boundary, generated by fitting\n class conditional densities to the data and using Bayes\u2019 rule.\n\n References\n ----------\n .. [1] \"Online Learning for Latent Dirichlet Allocation\", Matthew D.\n Hoffman, David M. Blei, Francis Bach, 2010\n https://github.com/blei-lab/onlineldavb\n\n .. [2] \"Stochastic Variational Inference\", Matthew D. Hoffman,\n David M. Blei, Chong Wang, John Paisley, 2013\n\n Examples\n --------\n >>> from sklearn.decomposition import LatentDirichletAllocation\n >>> from sklearn.datasets import make_multilabel_classification\n >>> # This produces a feature matrix of token counts, similar to what\n >>> # CountVectorizer would produce on text.\n >>> X, _ = make_multilabel_classification(random_state=0)\n >>> lda = LatentDirichletAllocation(n_components=5,\n ... random_state=0)\n >>> lda.fit(X)\n LatentDirichletAllocation(...)\n >>> # get topics for some given samples:\n >>> lda.transform(X[-2:])\n array([[0.00360392, 0.25499205, 0.0036211 , 0.64236448, 0.09541846],\n [0.15297572, 0.00362644, 0.44412786, 0.39568399, 0.003586 ]])\n \"\"\"\n \n def __init__(self, n_components=10, *, doc_topic_prior=None, topic_word_prior=None, learning_method='batch', learning_decay=0.7, learning_offset=10.0, max_iter=10, batch_size=128, evaluate_every=-1, total_samples=1000000.0, perp_tol=0.1, mean_change_tol=0.001, max_doc_update_iter=100, n_jobs=None, verbose=0, random_state=None):\n self.n_components = n_components\n self.doc_topic_prior = doc_topic_prior\n self.topic_word_prior = topic_word_prior\n self.learning_method = learning_method\n self.learning_decay = learning_decay\n self.learning_offset = learning_offset\n self.max_iter = max_iter\n self.batch_size = batch_size\n self.evaluate_every = evaluate_every\n self.total_samples = total_samples\n self.perp_tol = perp_tol\n self.mean_change_tol = mean_change_tol\n self.max_doc_update_iter = max_doc_update_iter\n self.n_jobs = n_jobs\n self.verbose = verbose\n self.random_state = random_state\n \n def _check_params(self):\n \"\"\"Check model parameters.\"\"\"\n if self.n_components <= 0:\n raise ValueError(\"Invalid 'n_components' parameter: %r\" % self.n_components)\n if self.total_samples <= 0:\n raise ValueError(\"Invalid 'total_samples' parameter: %r\" % self.total_samples)\n if self.learning_offset < 0:\n raise ValueError(\"Invalid 'learning_offset' parameter: %r\" % self.learning_offset)\n if self.learning_method not in ('batch', 'online'):\n raise ValueError(\"Invalid 'learning_method' parameter: %r\" % self.learning_method)\n \n def _init_latent_vars(self, n_features):\n \"\"\"Initialize latent variables.\"\"\"\n self.random_state_ = check_random_state(self.random_state)\n self.n_batch_iter_ = 1\n self.n_iter_ = 0\n if self.doc_topic_prior is None:\n self.doc_topic_prior_ = 1.0 / self.n_components\n else:\n self.doc_topic_prior_ = self.doc_topic_prior\n if self.topic_word_prior is None:\n self.topic_word_prior_ = 1.0 / self.n_components\n else:\n self.topic_word_prior_ = self.topic_word_prior\n init_gamma = 100.0\n init_var = 1.0 / init_gamma\n self.components_ = self.random_state_.gamma(init_gamma, init_var, (self.n_components, n_features))\n self.exp_dirichlet_component_ = np.exp(_dirichlet_expectation_2d(self.components_))\n \n def _e_step(self, X, cal_sstats, random_init, parallel=None):\n \"\"\"E-step in EM update.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n cal_sstats : bool\n Parameter that indicate whether to calculate sufficient statistics\n or not. Set ``cal_sstats`` to True when we need to run M-step.\n\n random_init : bool\n Parameter that indicate whether to initialize document topic\n distribution randomly in the E-step. Set it to True in training\n steps.\n\n parallel : joblib.Parallel, default=None\n Pre-initialized instance of joblib.Parallel.\n\n Returns\n -------\n (doc_topic_distr, suff_stats) :\n `doc_topic_distr` is unnormalized topic distribution for each\n document. In the literature, this is called `gamma`.\n `suff_stats` is expected sufficient statistics for the M-step.\n When `cal_sstats == False`, it will be None.\n\n \"\"\"\n random_state = self.random_state_ if random_init else None\n n_jobs = effective_n_jobs(self.n_jobs)\n if parallel is None:\n parallel = Parallel(n_jobs=n_jobs, verbose=max(0, self.verbose - 1))\n results = parallel((delayed(_update_doc_distribution)(X[idx_slice, :], self.exp_dirichlet_component_, self.doc_topic_prior_, self.max_doc_update_iter, self.mean_change_tol, cal_sstats, random_state) for idx_slice in gen_even_slices(X.shape[0], n_jobs)))\n (doc_topics, sstats_list) = zip(*results)\n doc_topic_distr = np.vstack(doc_topics)\n if cal_sstats:\n suff_stats = np.zeros(self.components_.shape)\n for sstats in sstats_list:\n suff_stats += sstats\n suff_stats *= self.exp_dirichlet_component_\n else:\n suff_stats = None\n return doc_topic_distr, suff_stats\n \n def _em_step(self, X, total_samples, batch_update, parallel=None):\n \"\"\"EM update for 1 iteration.\n\n update `_component` by batch VB or online VB.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n total_samples : int\n Total number of documents. It is only used when\n batch_update is `False`.\n\n batch_update : bool\n Parameter that controls updating method.\n `True` for batch learning, `False` for online learning.\n\n parallel : joblib.Parallel, default=None\n Pre-initialized instance of joblib.Parallel\n\n Returns\n -------\n doc_topic_distr : ndarray of shape (n_samples, n_components)\n Unnormalized document topic distribution.\n \"\"\"\n (_, suff_stats) = self._e_step(X, cal_sstats=True, random_init=True, parallel=parallel)\n if batch_update:\n self.components_ = self.topic_word_prior_ + suff_stats\n else:\n weight = np.power(self.learning_offset + self.n_batch_iter_, -self.learning_decay)\n doc_ratio = float(total_samples) / X.shape[0]\n self.components_ *= 1 - weight\n self.components_ += weight * (self.topic_word_prior_ + doc_ratio * suff_stats)\n self.exp_dirichlet_component_ = np.exp(_dirichlet_expectation_2d(self.components_))\n self.n_batch_iter_ += 1\n return\n \n def _more_tags(self):\n return {'requires_positive_X': True}\n \n def _check_non_neg_array(self, X, reset_n_features, whom):\n \"\"\"check X format\n\n check X format and make sure no negative value in X.\n\n Parameters\n ----------\n X : array-like or sparse matrix\n\n \"\"\"\n X = self._validate_data(X, reset=reset_n_features, accept_sparse='csr')\n check_non_negative(X, whom)\n return X\n \n def partial_fit(self, X, y=None):\n \"\"\"Online VB with Mini-Batch update.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self\n Partially fitted estimator.\n \"\"\"\n self._check_params()\n first_time = not hasattr(self, 'components_')\n X = self._check_non_neg_array(X, reset_n_features=first_time, whom='LatentDirichletAllocation.partial_fit')\n (n_samples, n_features) = X.shape\n batch_size = self.batch_size\n if first_time:\n self._init_latent_vars(n_features)\n if n_features != self.components_.shape[1]:\n raise ValueError('The provided data has %d dimensions while the model was trained with feature size %d.' % (n_features, self.components_.shape[1]))\n n_jobs = effective_n_jobs(self.n_jobs)\n with Parallel(n_jobs=n_jobs, verbose=max(0, self.verbose - 1)) as parallel:\n for idx_slice in gen_batches(n_samples, batch_size):\n self._em_step(X[idx_slice, :], total_samples=self.total_samples, batch_update=False, parallel=parallel)\n return self\n \n def fit(self, X, y=None):\n \"\"\"Learn model for the data X with variational Bayes method.\n\n When `learning_method` is 'online', use mini-batch update.\n Otherwise, use batch update.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self\n Fitted estimator.\n \"\"\"\n self._check_params()\n X = self._check_non_neg_array(X, reset_n_features=True, whom='LatentDirichletAllocation.fit')\n (n_samples, n_features) = X.shape\n max_iter = self.max_iter\n evaluate_every = self.evaluate_every\n learning_method = self.learning_method\n batch_size = self.batch_size\n self._init_latent_vars(n_features)\n last_bound = None\n n_jobs = effective_n_jobs(self.n_jobs)\n with Parallel(n_jobs=n_jobs, verbose=max(0, self.verbose - 1)) as parallel:\n for i in range(max_iter):\n if learning_method == 'online':\n for idx_slice in gen_batches(n_samples, batch_size):\n self._em_step(X[idx_slice, :], total_samples=n_samples, batch_update=False, parallel=parallel)\n else:\n self._em_step(X, total_samples=n_samples, batch_update=True, parallel=parallel)\n if evaluate_every > 0 and (i + 1) % evaluate_every == 0:\n (doc_topics_distr, _) = self._e_step(X, cal_sstats=False, random_init=False, parallel=parallel)\n bound = self._perplexity_precomp_distr(X, doc_topics_distr, sub_sampling=False)\n if self.verbose:\n print('iteration: %d of max_iter: %d, perplexity: %.4f' % (i + 1, max_iter, bound))\n if last_bound and abs(last_bound - bound) < self.perp_tol:\n break\n last_bound = bound\n elif self.verbose:\n print('iteration: %d of max_iter: %d' % (i + 1, max_iter))\n self.n_iter_ += 1\n (doc_topics_distr, _) = self._e_step(X, cal_sstats=False, random_init=False, parallel=parallel)\n self.bound_ = self._perplexity_precomp_distr(X, doc_topics_distr, sub_sampling=False)\n return self\n \n def _unnormalized_transform(self, X):\n \"\"\"Transform data X according to fitted model.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n Returns\n -------\n doc_topic_distr : ndarray of shape (n_samples, n_components)\n Document topic distribution for X.\n \"\"\"\n (doc_topic_distr, _) = self._e_step(X, cal_sstats=False, random_init=False)\n return doc_topic_distr\n \n def transform(self, X):\n \"\"\"Transform data X according to the fitted model.\n\n .. versionchanged:: 0.18\n *doc_topic_distr* is now normalized\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n Returns\n -------\n doc_topic_distr : ndarray of shape (n_samples, n_components)\n Document topic distribution for X.\n \"\"\"\n check_is_fitted(self)\n X = self._check_non_neg_array(X, reset_n_features=False, whom='LatentDirichletAllocation.transform')\n doc_topic_distr = self._unnormalized_transform(X)\n doc_topic_distr /= doc_topic_distr.sum(axis=1)[:, np.newaxis]\n return doc_topic_distr\n \n def _approx_bound(self, X, doc_topic_distr, sub_sampling):\n \"\"\"Estimate the variational bound.\n\n Estimate the variational bound over \"all documents\" using only the\n documents passed in as X. Since log-likelihood of each word cannot\n be computed directly, we use this bound to estimate it.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n doc_topic_distr : ndarray of shape (n_samples, n_components)\n Document topic distribution. In the literature, this is called\n gamma.\n\n sub_sampling : bool, default=False\n Compensate for subsampling of documents.\n It is used in calculate bound in online learning.\n\n Returns\n -------\n score : float\n\n \"\"\"\n \n def _loglikelihood(prior, distr, dirichlet_distr, size):\n score = np.sum((prior - distr) * dirichlet_distr)\n score += np.sum(gammaln(distr) - gammaln(prior))\n score += np.sum(gammaln(prior * size) - gammaln(np.sum(distr, 1)))\n return score\n is_sparse_x = sp.issparse(X)\n (n_samples, n_components) = doc_topic_distr.shape\n n_features = self.components_.shape[1]\n score = 0\n dirichlet_doc_topic = _dirichlet_expectation_2d(doc_topic_distr)\n dirichlet_component_ = _dirichlet_expectation_2d(self.components_)\n doc_topic_prior = self.doc_topic_prior_\n topic_word_prior = self.topic_word_prior_\n if is_sparse_x:\n X_data = X.data\n X_indices = X.indices\n X_indptr = X.indptr\n for idx_d in range(0, n_samples):\n if is_sparse_x:\n ids = X_indices[X_indptr[idx_d]:X_indptr[idx_d + 1]]\n cnts = X_data[X_indptr[idx_d]:X_indptr[idx_d + 1]]\n else:\n ids = np.nonzero(X[idx_d, :])[0]\n cnts = X[idx_d, ids]\n temp = dirichlet_doc_topic[idx_d, :, np.newaxis] + dirichlet_component_[:, ids]\n norm_phi = logsumexp(temp, axis=0)\n score += np.dot(cnts, norm_phi)\n score += _loglikelihood(doc_topic_prior, doc_topic_distr, dirichlet_doc_topic, self.n_components)\n if sub_sampling:\n doc_ratio = float(self.total_samples) / n_samples\n score *= doc_ratio\n score += _loglikelihood(topic_word_prior, self.components_, dirichlet_component_, n_features)\n return score\n \n def score(self, X, y=None):\n \"\"\"Calculate approximate log-likelihood as score.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n score : float\n Use approximate bound as score.\n \"\"\"\n check_is_fitted(self)\n X = self._check_non_neg_array(X, reset_n_features=False, whom='LatentDirichletAllocation.score')\n doc_topic_distr = self._unnormalized_transform(X)\n score = self._approx_bound(X, doc_topic_distr, sub_sampling=False)\n return score\n \n def _perplexity_precomp_distr(self, X, doc_topic_distr=None, sub_sampling=False):\n \"\"\"Calculate approximate perplexity for data X with ability to accept\n precomputed doc_topic_distr\n\n Perplexity is defined as exp(-1. * log-likelihood per word)\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n doc_topic_distr : ndarray of shape (n_samples, n_components), default=None\n Document topic distribution.\n If it is None, it will be generated by applying transform on X.\n\n Returns\n -------\n score : float\n Perplexity score.\n \"\"\"\n if doc_topic_distr is None:\n doc_topic_distr = self._unnormalized_transform(X)\n else:\n (n_samples, n_components) = doc_topic_distr.shape\n if n_samples != X.shape[0]:\n raise ValueError('Number of samples in X and doc_topic_distr do not match.')\n if n_components != self.n_components:\n raise ValueError('Number of topics does not match.')\n current_samples = X.shape[0]\n bound = self._approx_bound(X, doc_topic_distr, sub_sampling)\n if sub_sampling:\n word_cnt = X.sum() * (float(self.total_samples) / current_samples)\n else:\n word_cnt = X.sum()\n perword_bound = bound / word_cnt\n return np.exp(-1.0 * perword_bound)\n \n def perplexity(self, X, sub_sampling=False):\n \"\"\"Calculate approximate perplexity for data X.\n\n Perplexity is defined as exp(-1. * log-likelihood per word)\n\n .. versionchanged:: 0.19\n *doc_topic_distr* argument has been deprecated and is ignored\n because user no longer has access to unnormalized distribution\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n sub_sampling : bool\n Do sub-sampling or not.\n\n Returns\n -------\n score : float\n Perplexity score.\n \"\"\"\n check_is_fitted(self)\n X = self._check_non_neg_array(X, reset_n_features=True, whom='LatentDirichletAllocation.perplexity')\n return self._perplexity_precomp_distr(X, sub_sampling=sub_sampling)\n" }, { "name": "NMF", @@ -20768,9 +20735,9 @@ "sklearn.discriminant_analysis.QuadraticDiscriminantAnalysis.predict_log_proba" ], "is_public": true, - "description": "Quadratic Discriminant Analysis\n\nA classifier with a quadratic decision boundary, generated by fitting class conditional densities to the data and using Bayes' rule. The model fits a Gaussian density to each class. .. versionadded:: 0.17 *QuadraticDiscriminantAnalysis* Read more in the :ref:`User Guide `.", - "docstring": "Quadratic Discriminant Analysis\n\n A classifier with a quadratic decision boundary, generated\n by fitting class conditional densities to the data\n and using Bayes' rule.\n\n The model fits a Gaussian density to each class.\n\n .. versionadded:: 0.17\n *QuadraticDiscriminantAnalysis*\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n priors : ndarray of shape (n_classes,), default=None\n Class priors. By default, the class proportions are inferred from the\n training data.\n\n reg_param : float, default=0.0\n Regularizes the per-class covariance estimates by transforming S2 as\n ``S2 = (1 - reg_param) * S2 + reg_param * np.eye(n_features)``,\n where S2 corresponds to the `scaling_` attribute of a given class.\n\n store_covariance : bool, default=False\n If True, the class covariance matrices are explicitly computed and\n stored in the `self.covariance_` attribute.\n\n .. versionadded:: 0.17\n\n tol : float, default=1.0e-4\n Absolute threshold for a singular value to be considered significant,\n used to estimate the rank of `Xk` where `Xk` is the centered matrix\n of samples in class k. This parameter does not affect the\n predictions. It only controls a warning that is raised when features\n are considered to be colinear.\n\n .. versionadded:: 0.17\n\n Attributes\n ----------\n covariance_ : list of len n_classes of ndarray of shape (n_features, n_features)\n For each class, gives the covariance matrix estimated using the\n samples of that class. The estimations are unbiased. Only present if\n `store_covariance` is True.\n\n means_ : array-like of shape (n_classes, n_features)\n Class-wise means.\n\n priors_ : array-like of shape (n_classes,)\n Class priors (sum to 1).\n\n rotations_ : list of len n_classes of ndarray of shape (n_features, n_k)\n For each class k an array of shape (n_features, n_k), where\n ``n_k = min(n_features, number of elements in class k)``\n It is the rotation of the Gaussian distribution, i.e. its\n principal axis. It corresponds to `V`, the matrix of eigenvectors\n coming from the SVD of `Xk = U S Vt` where `Xk` is the centered\n matrix of samples from class k.\n\n scalings_ : list of len n_classes of ndarray of shape (n_k,)\n For each class, contains the scaling of\n the Gaussian distributions along its principal axes, i.e. the\n variance in the rotated coordinate system. It corresponds to `S^2 /\n (n_samples - 1)`, where `S` is the diagonal matrix of singular values\n from the SVD of `Xk`, where `Xk` is the centered matrix of samples\n from class k.\n\n classes_ : ndarray of shape (n_classes,)\n Unique class labels.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis\n >>> import numpy as np\n >>> X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])\n >>> y = np.array([1, 1, 1, 2, 2, 2])\n >>> clf = QuadraticDiscriminantAnalysis()\n >>> clf.fit(X, y)\n QuadraticDiscriminantAnalysis()\n >>> print(clf.predict([[-0.8, -1]]))\n [1]\n\n See Also\n --------\n LinearDiscriminantAnalysis : Linear Discriminant Analysis.\n ", - "source_code": "\n\nclass QuadraticDiscriminantAnalysis(ClassifierMixin, BaseEstimator):\n \"\"\"Quadratic Discriminant Analysis\n\n A classifier with a quadratic decision boundary, generated\n by fitting class conditional densities to the data\n and using Bayes' rule.\n\n The model fits a Gaussian density to each class.\n\n .. versionadded:: 0.17\n *QuadraticDiscriminantAnalysis*\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n priors : ndarray of shape (n_classes,), default=None\n Class priors. By default, the class proportions are inferred from the\n training data.\n\n reg_param : float, default=0.0\n Regularizes the per-class covariance estimates by transforming S2 as\n ``S2 = (1 - reg_param) * S2 + reg_param * np.eye(n_features)``,\n where S2 corresponds to the `scaling_` attribute of a given class.\n\n store_covariance : bool, default=False\n If True, the class covariance matrices are explicitly computed and\n stored in the `self.covariance_` attribute.\n\n .. versionadded:: 0.17\n\n tol : float, default=1.0e-4\n Absolute threshold for a singular value to be considered significant,\n used to estimate the rank of `Xk` where `Xk` is the centered matrix\n of samples in class k. This parameter does not affect the\n predictions. It only controls a warning that is raised when features\n are considered to be colinear.\n\n .. versionadded:: 0.17\n\n Attributes\n ----------\n covariance_ : list of len n_classes of ndarray of shape (n_features, n_features)\n For each class, gives the covariance matrix estimated using the\n samples of that class. The estimations are unbiased. Only present if\n `store_covariance` is True.\n\n means_ : array-like of shape (n_classes, n_features)\n Class-wise means.\n\n priors_ : array-like of shape (n_classes,)\n Class priors (sum to 1).\n\n rotations_ : list of len n_classes of ndarray of shape (n_features, n_k)\n For each class k an array of shape (n_features, n_k), where\n ``n_k = min(n_features, number of elements in class k)``\n It is the rotation of the Gaussian distribution, i.e. its\n principal axis. It corresponds to `V`, the matrix of eigenvectors\n coming from the SVD of `Xk = U S Vt` where `Xk` is the centered\n matrix of samples from class k.\n\n scalings_ : list of len n_classes of ndarray of shape (n_k,)\n For each class, contains the scaling of\n the Gaussian distributions along its principal axes, i.e. the\n variance in the rotated coordinate system. It corresponds to `S^2 /\n (n_samples - 1)`, where `S` is the diagonal matrix of singular values\n from the SVD of `Xk`, where `Xk` is the centered matrix of samples\n from class k.\n\n classes_ : ndarray of shape (n_classes,)\n Unique class labels.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis\n >>> import numpy as np\n >>> X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])\n >>> y = np.array([1, 1, 1, 2, 2, 2])\n >>> clf = QuadraticDiscriminantAnalysis()\n >>> clf.fit(X, y)\n QuadraticDiscriminantAnalysis()\n >>> print(clf.predict([[-0.8, -1]]))\n [1]\n\n See Also\n --------\n LinearDiscriminantAnalysis : Linear Discriminant Analysis.\n \"\"\"\n \n def __init__(self, *, priors=None, reg_param=0.0, store_covariance=False, tol=0.0001):\n self.priors = np.asarray(priors) if priors is not None else None\n self.reg_param = reg_param\n self.store_covariance = store_covariance\n self.tol = tol\n \n def fit(self, X, y):\n \"\"\"Fit the model according to the given training data and parameters.\n\n .. versionchanged:: 0.19\n ``store_covariances`` has been moved to main constructor as\n ``store_covariance``\n\n .. versionchanged:: 0.19\n ``tol`` has been moved to main constructor.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target values (integers)\n \"\"\"\n (X, y) = self._validate_data(X, y)\n check_classification_targets(y)\n (self.classes_, y) = np.unique(y, return_inverse=True)\n (n_samples, n_features) = X.shape\n n_classes = len(self.classes_)\n if n_classes < 2:\n raise ValueError('The number of classes has to be greater than one; got %d class' % n_classes)\n if self.priors is None:\n self.priors_ = np.bincount(y) / float(n_samples)\n else:\n self.priors_ = self.priors\n cov = None\n store_covariance = self.store_covariance\n if store_covariance:\n cov = []\n means = []\n scalings = []\n rotations = []\n for ind in range(n_classes):\n Xg = X[y == ind, :]\n meang = Xg.mean(0)\n means.append(meang)\n if len(Xg) == 1:\n raise ValueError('y has only 1 sample in class %s, covariance is ill defined.' % str(self.classes_[ind]))\n Xgc = Xg - meang\n (_, S, Vt) = np.linalg.svd(Xgc, full_matrices=False)\n rank = np.sum(S > self.tol)\n if rank < n_features:\n warnings.warn('Variables are collinear')\n S2 = S**2 / (len(Xg) - 1)\n S2 = (1 - self.reg_param) * S2 + self.reg_param\n if self.store_covariance or store_covariance:\n cov.append(np.dot(S2 * Vt.T, Vt))\n scalings.append(S2)\n rotations.append(Vt.T)\n if self.store_covariance or store_covariance:\n self.covariance_ = cov\n self.means_ = np.asarray(means)\n self.scalings_ = scalings\n self.rotations_ = rotations\n return self\n \n def _decision_function(self, X):\n check_is_fitted(self)\n X = self._validate_data(X, reset=False)\n norm2 = []\n for i in range(len(self.classes_)):\n R = self.rotations_[i]\n S = self.scalings_[i]\n Xm = X - self.means_[i]\n X2 = np.dot(Xm, R * S**(-0.5))\n norm2.append(np.sum(X2**2, axis=1))\n norm2 = np.array(norm2).T\n u = np.asarray([np.sum(np.log(s)) for s in self.scalings_])\n return -0.5 * (norm2 + u) + np.log(self.priors_)\n \n def decision_function(self, X):\n \"\"\"Apply decision function to an array of samples.\n\n The decision function is equal (up to a constant factor) to the\n log-posterior of the model, i.e. `log p(y = k | x)`. In a binary\n classification setting this instead corresponds to the difference\n `log p(y = 1 | x) - log p(y = 0 | x)`. See :ref:`lda_qda_math`.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Array of samples (test vectors).\n\n Returns\n -------\n C : ndarray of shape (n_samples,) or (n_samples, n_classes)\n Decision function values related to each class, per sample.\n In the two-class case, the shape is (n_samples,), giving the\n log likelihood ratio of the positive class.\n \"\"\"\n dec_func = self._decision_function(X)\n if len(self.classes_) == 2:\n return dec_func[:, 1] - dec_func[:, 0]\n return dec_func\n \n def predict(self, X):\n \"\"\"Perform classification on an array of test vectors X.\n\n The predicted class C for each sample in X is returned.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n\n Returns\n -------\n C : ndarray of shape (n_samples,)\n \"\"\"\n d = self._decision_function(X)\n y_pred = self.classes_.take(d.argmax(1))\n return y_pred\n \n def predict_proba(self, X):\n \"\"\"Return posterior probabilities of classification.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Array of samples/test vectors.\n\n Returns\n -------\n C : ndarray of shape (n_samples, n_classes)\n Posterior probabilities of classification per class.\n \"\"\"\n values = self._decision_function(X)\n likelihood = np.exp(values - values.max(axis=1)[:, np.newaxis])\n return likelihood / likelihood.sum(axis=1)[:, np.newaxis]\n \n def predict_log_proba(self, X):\n \"\"\"Return log of posterior probabilities of classification.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Array of samples/test vectors.\n\n Returns\n -------\n C : ndarray of shape (n_samples, n_classes)\n Posterior log-probabilities of classification per class.\n \"\"\"\n probas_ = self.predict_proba(X)\n return np.log(probas_)\n" + "description": "Quadratic Discriminant Analysis.\n\nA classifier with a quadratic decision boundary, generated by fitting class conditional densities to the data and using Bayes' rule. The model fits a Gaussian density to each class. .. versionadded:: 0.17 *QuadraticDiscriminantAnalysis* Read more in the :ref:`User Guide `.", + "docstring": "Quadratic Discriminant Analysis.\n\n A classifier with a quadratic decision boundary, generated\n by fitting class conditional densities to the data\n and using Bayes' rule.\n\n The model fits a Gaussian density to each class.\n\n .. versionadded:: 0.17\n *QuadraticDiscriminantAnalysis*\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n priors : ndarray of shape (n_classes,), default=None\n Class priors. By default, the class proportions are inferred from the\n training data.\n\n reg_param : float, default=0.0\n Regularizes the per-class covariance estimates by transforming S2 as\n ``S2 = (1 - reg_param) * S2 + reg_param * np.eye(n_features)``,\n where S2 corresponds to the `scaling_` attribute of a given class.\n\n store_covariance : bool, default=False\n If True, the class covariance matrices are explicitly computed and\n stored in the `self.covariance_` attribute.\n\n .. versionadded:: 0.17\n\n tol : float, default=1.0e-4\n Absolute threshold for a singular value to be considered significant,\n used to estimate the rank of `Xk` where `Xk` is the centered matrix\n of samples in class k. This parameter does not affect the\n predictions. It only controls a warning that is raised when features\n are considered to be colinear.\n\n .. versionadded:: 0.17\n\n Attributes\n ----------\n covariance_ : list of len n_classes of ndarray of shape (n_features, n_features)\n For each class, gives the covariance matrix estimated using the\n samples of that class. The estimations are unbiased. Only present if\n `store_covariance` is True.\n\n means_ : array-like of shape (n_classes, n_features)\n Class-wise means.\n\n priors_ : array-like of shape (n_classes,)\n Class priors (sum to 1).\n\n rotations_ : list of len n_classes of ndarray of shape (n_features, n_k)\n For each class k an array of shape (n_features, n_k), where\n ``n_k = min(n_features, number of elements in class k)``\n It is the rotation of the Gaussian distribution, i.e. its\n principal axis. It corresponds to `V`, the matrix of eigenvectors\n coming from the SVD of `Xk = U S Vt` where `Xk` is the centered\n matrix of samples from class k.\n\n scalings_ : list of len n_classes of ndarray of shape (n_k,)\n For each class, contains the scaling of\n the Gaussian distributions along its principal axes, i.e. the\n variance in the rotated coordinate system. It corresponds to `S^2 /\n (n_samples - 1)`, where `S` is the diagonal matrix of singular values\n from the SVD of `Xk`, where `Xk` is the centered matrix of samples\n from class k.\n\n classes_ : ndarray of shape (n_classes,)\n Unique class labels.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n LinearDiscriminantAnalysis : Linear Discriminant Analysis.\n\n Examples\n --------\n >>> from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis\n >>> import numpy as np\n >>> X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])\n >>> y = np.array([1, 1, 1, 2, 2, 2])\n >>> clf = QuadraticDiscriminantAnalysis()\n >>> clf.fit(X, y)\n QuadraticDiscriminantAnalysis()\n >>> print(clf.predict([[-0.8, -1]]))\n [1]\n ", + "source_code": "\n\nclass QuadraticDiscriminantAnalysis(ClassifierMixin, BaseEstimator):\n \"\"\"Quadratic Discriminant Analysis.\n\n A classifier with a quadratic decision boundary, generated\n by fitting class conditional densities to the data\n and using Bayes' rule.\n\n The model fits a Gaussian density to each class.\n\n .. versionadded:: 0.17\n *QuadraticDiscriminantAnalysis*\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n priors : ndarray of shape (n_classes,), default=None\n Class priors. By default, the class proportions are inferred from the\n training data.\n\n reg_param : float, default=0.0\n Regularizes the per-class covariance estimates by transforming S2 as\n ``S2 = (1 - reg_param) * S2 + reg_param * np.eye(n_features)``,\n where S2 corresponds to the `scaling_` attribute of a given class.\n\n store_covariance : bool, default=False\n If True, the class covariance matrices are explicitly computed and\n stored in the `self.covariance_` attribute.\n\n .. versionadded:: 0.17\n\n tol : float, default=1.0e-4\n Absolute threshold for a singular value to be considered significant,\n used to estimate the rank of `Xk` where `Xk` is the centered matrix\n of samples in class k. This parameter does not affect the\n predictions. It only controls a warning that is raised when features\n are considered to be colinear.\n\n .. versionadded:: 0.17\n\n Attributes\n ----------\n covariance_ : list of len n_classes of ndarray of shape (n_features, n_features)\n For each class, gives the covariance matrix estimated using the\n samples of that class. The estimations are unbiased. Only present if\n `store_covariance` is True.\n\n means_ : array-like of shape (n_classes, n_features)\n Class-wise means.\n\n priors_ : array-like of shape (n_classes,)\n Class priors (sum to 1).\n\n rotations_ : list of len n_classes of ndarray of shape (n_features, n_k)\n For each class k an array of shape (n_features, n_k), where\n ``n_k = min(n_features, number of elements in class k)``\n It is the rotation of the Gaussian distribution, i.e. its\n principal axis. It corresponds to `V`, the matrix of eigenvectors\n coming from the SVD of `Xk = U S Vt` where `Xk` is the centered\n matrix of samples from class k.\n\n scalings_ : list of len n_classes of ndarray of shape (n_k,)\n For each class, contains the scaling of\n the Gaussian distributions along its principal axes, i.e. the\n variance in the rotated coordinate system. It corresponds to `S^2 /\n (n_samples - 1)`, where `S` is the diagonal matrix of singular values\n from the SVD of `Xk`, where `Xk` is the centered matrix of samples\n from class k.\n\n classes_ : ndarray of shape (n_classes,)\n Unique class labels.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n LinearDiscriminantAnalysis : Linear Discriminant Analysis.\n\n Examples\n --------\n >>> from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis\n >>> import numpy as np\n >>> X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])\n >>> y = np.array([1, 1, 1, 2, 2, 2])\n >>> clf = QuadraticDiscriminantAnalysis()\n >>> clf.fit(X, y)\n QuadraticDiscriminantAnalysis()\n >>> print(clf.predict([[-0.8, -1]]))\n [1]\n \"\"\"\n \n def __init__(self, *, priors=None, reg_param=0.0, store_covariance=False, tol=0.0001):\n self.priors = np.asarray(priors) if priors is not None else None\n self.reg_param = reg_param\n self.store_covariance = store_covariance\n self.tol = tol\n \n def fit(self, X, y):\n \"\"\"Fit the model according to the given training data and parameters.\n\n .. versionchanged:: 0.19\n ``store_covariances`` has been moved to main constructor as\n ``store_covariance``\n\n .. versionchanged:: 0.19\n ``tol`` has been moved to main constructor.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target values (integers).\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n (X, y) = self._validate_data(X, y)\n check_classification_targets(y)\n (self.classes_, y) = np.unique(y, return_inverse=True)\n (n_samples, n_features) = X.shape\n n_classes = len(self.classes_)\n if n_classes < 2:\n raise ValueError('The number of classes has to be greater than one; got %d class' % n_classes)\n if self.priors is None:\n self.priors_ = np.bincount(y) / float(n_samples)\n else:\n self.priors_ = self.priors\n cov = None\n store_covariance = self.store_covariance\n if store_covariance:\n cov = []\n means = []\n scalings = []\n rotations = []\n for ind in range(n_classes):\n Xg = X[y == ind, :]\n meang = Xg.mean(0)\n means.append(meang)\n if len(Xg) == 1:\n raise ValueError('y has only 1 sample in class %s, covariance is ill defined.' % str(self.classes_[ind]))\n Xgc = Xg - meang\n (_, S, Vt) = np.linalg.svd(Xgc, full_matrices=False)\n rank = np.sum(S > self.tol)\n if rank < n_features:\n warnings.warn('Variables are collinear')\n S2 = S**2 / (len(Xg) - 1)\n S2 = (1 - self.reg_param) * S2 + self.reg_param\n if self.store_covariance or store_covariance:\n cov.append(np.dot(S2 * Vt.T, Vt))\n scalings.append(S2)\n rotations.append(Vt.T)\n if self.store_covariance or store_covariance:\n self.covariance_ = cov\n self.means_ = np.asarray(means)\n self.scalings_ = scalings\n self.rotations_ = rotations\n return self\n \n def _decision_function(self, X):\n check_is_fitted(self)\n X = self._validate_data(X, reset=False)\n norm2 = []\n for i in range(len(self.classes_)):\n R = self.rotations_[i]\n S = self.scalings_[i]\n Xm = X - self.means_[i]\n X2 = np.dot(Xm, R * S**(-0.5))\n norm2.append(np.sum(X2**2, axis=1))\n norm2 = np.array(norm2).T\n u = np.asarray([np.sum(np.log(s)) for s in self.scalings_])\n return -0.5 * (norm2 + u) + np.log(self.priors_)\n \n def decision_function(self, X):\n \"\"\"Apply decision function to an array of samples.\n\n The decision function is equal (up to a constant factor) to the\n log-posterior of the model, i.e. `log p(y = k | x)`. In a binary\n classification setting this instead corresponds to the difference\n `log p(y = 1 | x) - log p(y = 0 | x)`. See :ref:`lda_qda_math`.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Array of samples (test vectors).\n\n Returns\n -------\n C : ndarray of shape (n_samples,) or (n_samples, n_classes)\n Decision function values related to each class, per sample.\n In the two-class case, the shape is (n_samples,), giving the\n log likelihood ratio of the positive class.\n \"\"\"\n dec_func = self._decision_function(X)\n if len(self.classes_) == 2:\n return dec_func[:, 1] - dec_func[:, 0]\n return dec_func\n \n def predict(self, X):\n \"\"\"Perform classification on an array of test vectors X.\n\n The predicted class C for each sample in X is returned.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Vector to be scored, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n Returns\n -------\n C : ndarray of shape (n_samples,)\n Estimated probabilities.\n \"\"\"\n d = self._decision_function(X)\n y_pred = self.classes_.take(d.argmax(1))\n return y_pred\n \n def predict_proba(self, X):\n \"\"\"Return posterior probabilities of classification.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Array of samples/test vectors.\n\n Returns\n -------\n C : ndarray of shape (n_samples, n_classes)\n Posterior probabilities of classification per class.\n \"\"\"\n values = self._decision_function(X)\n likelihood = np.exp(values - values.max(axis=1)[:, np.newaxis])\n return likelihood / likelihood.sum(axis=1)[:, np.newaxis]\n \n def predict_log_proba(self, X):\n \"\"\"Return log of posterior probabilities of classification.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Array of samples/test vectors.\n\n Returns\n -------\n C : ndarray of shape (n_samples, n_classes)\n Posterior log-probabilities of classification per class.\n \"\"\"\n probas_ = self.predict_proba(X)\n return np.log(probas_)\n" }, { "name": "DummyClassifier", @@ -20789,7 +20756,7 @@ "sklearn.dummy.DummyClassifier.predict_log_proba", "sklearn.dummy.DummyClassifier._more_tags", "sklearn.dummy.DummyClassifier.score", - "sklearn.dummy.DummyClassifier.n_features_in_" + "sklearn.dummy.DummyClassifier.n_features_in_@getter" ], "is_public": true, "description": "DummyClassifier is a classifier that makes predictions using simple rules.\n\nThis classifier is useful as a simple baseline to compare with other (real) classifiers. Do not use it for real problems. Read more in the :ref:`User Guide `. .. versionadded:: 0.13", @@ -20811,7 +20778,7 @@ "sklearn.dummy.DummyRegressor.predict", "sklearn.dummy.DummyRegressor._more_tags", "sklearn.dummy.DummyRegressor.score", - "sklearn.dummy.DummyRegressor.n_features_in_" + "sklearn.dummy.DummyRegressor.n_features_in_@getter" ], "is_public": true, "description": "Regressor that makes predictions using simple rules.\n\nThis regressor is useful as a simple baseline to compare with other (real) regressors. Do not use it for real problems. Read more in the :ref:`User Guide `. .. versionadded:: 0.13", @@ -20867,13 +20834,13 @@ "sklearn.ensemble._bagging.BaseBagging._set_oob_score", "sklearn.ensemble._bagging.BaseBagging._validate_y", "sklearn.ensemble._bagging.BaseBagging._get_estimators_indices", - "sklearn.ensemble._bagging.BaseBagging.estimators_samples_", - "sklearn.ensemble._bagging.BaseBagging.n_features_" + "sklearn.ensemble._bagging.BaseBagging.estimators_samples_@getter", + "sklearn.ensemble._bagging.BaseBagging.n_features_@getter" ], "is_public": false, "description": "Base class for Bagging meta-estimator.\n\nWarning: This class should not be used directly. Use derived classes instead.", "docstring": "Base class for Bagging meta-estimator.\n\n Warning: This class should not be used directly. Use derived classes\n instead.\n ", - "source_code": "\n\nclass BaseBagging(BaseEnsemble, metaclass=ABCMeta):\n \"\"\"Base class for Bagging meta-estimator.\n\n Warning: This class should not be used directly. Use derived classes\n instead.\n \"\"\"\n \n @abstractmethod\n def __init__(self, base_estimator=None, n_estimators=10, *, max_samples=1.0, max_features=1.0, bootstrap=True, bootstrap_features=False, oob_score=False, warm_start=False, n_jobs=None, random_state=None, verbose=0):\n super().__init__(base_estimator=base_estimator, n_estimators=n_estimators)\n self.max_samples = max_samples\n self.max_features = max_features\n self.bootstrap = bootstrap\n self.bootstrap_features = bootstrap_features\n self.oob_score = oob_score\n self.warm_start = warm_start\n self.n_jobs = n_jobs\n self.random_state = random_state\n self.verbose = verbose\n \n def fit(self, X, y, sample_weight=None):\n \"\"\"Build a Bagging ensemble of estimators from the training set (X, y).\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrices are accepted only if\n they are supported by the base estimator.\n\n y : array-like of shape (n_samples,)\n The target values (class labels in classification, real numbers in\n regression).\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n Note that this is supported only if the base estimator supports\n sample weighting.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n return self._fit(X, y, self.max_samples, sample_weight=sample_weight)\n \n def _parallel_args(self):\n return {}\n \n def _fit(self, X, y, max_samples=None, max_depth=None, sample_weight=None):\n \"\"\"Build a Bagging ensemble of estimators from the training\n set (X, y).\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrices are accepted only if\n they are supported by the base estimator.\n\n y : array-like of shape (n_samples,)\n The target values (class labels in classification, real numbers in\n regression).\n\n max_samples : int or float, default=None\n Argument to use instead of self.max_samples.\n\n max_depth : int, default=None\n Override value used when constructing base estimator. Only\n supported if the base estimator has a max_depth parameter.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n Note that this is supported only if the base estimator supports\n sample weighting.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n random_state = check_random_state(self.random_state)\n (X, y) = self._validate_data(X, y, accept_sparse=['csr', 'csc'], dtype=None, force_all_finite=False, multi_output=True)\n if sample_weight is not None:\n sample_weight = _check_sample_weight(sample_weight, X, dtype=None)\n n_samples = X.shape[0]\n self._n_samples = n_samples\n y = self._validate_y(y)\n self._validate_estimator()\n if max_depth is not None:\n self.base_estimator_.max_depth = max_depth\n if max_samples is None:\n max_samples = self.max_samples\n elif not isinstance(max_samples, numbers.Integral):\n max_samples = int(max_samples * X.shape[0])\n if not 0 < max_samples <= X.shape[0]:\n raise ValueError('max_samples must be in (0, n_samples]')\n self._max_samples = max_samples\n if isinstance(self.max_features, numbers.Integral):\n max_features = self.max_features\n elif isinstance(self.max_features, float):\n max_features = self.max_features * self.n_features_in_\n else:\n raise ValueError('max_features must be int or float')\n if not 0 < max_features <= self.n_features_in_:\n raise ValueError('max_features must be in (0, n_features]')\n max_features = max(1, int(max_features))\n self._max_features = max_features\n if not self.bootstrap and self.oob_score:\n raise ValueError('Out of bag estimation only available if bootstrap=True')\n if self.warm_start and self.oob_score:\n raise ValueError('Out of bag estimate only available if warm_start=False')\n if hasattr(self, 'oob_score_') and self.warm_start:\n del self.oob_score_\n if not self.warm_start or not hasattr(self, 'estimators_'):\n self.estimators_ = []\n self.estimators_features_ = []\n n_more_estimators = self.n_estimators - len(self.estimators_)\n if n_more_estimators < 0:\n raise ValueError('n_estimators=%d must be larger or equal to len(estimators_)=%d when warm_start==True' % (self.n_estimators, len(self.estimators_)))\n elif n_more_estimators == 0:\n warn('Warm-start fitting without increasing n_estimators does not fit new trees.')\n return self\n (n_jobs, n_estimators, starts) = _partition_estimators(n_more_estimators, self.n_jobs)\n total_n_estimators = sum(n_estimators)\n if self.warm_start and len(self.estimators_) > 0:\n random_state.randint(MAX_INT, size=len(self.estimators_))\n seeds = random_state.randint(MAX_INT, size=n_more_estimators)\n self._seeds = seeds\n all_results = Parallel(n_jobs=n_jobs, verbose=self.verbose, **self._parallel_args())((delayed(_parallel_build_estimators)(n_estimators[i], self, X, y, sample_weight, seeds[starts[i]:starts[i + 1]], total_n_estimators, verbose=self.verbose) for i in range(n_jobs)))\n self.estimators_ += list(itertools.chain.from_iterable((t[0] for t in all_results)))\n self.estimators_features_ += list(itertools.chain.from_iterable((t[1] for t in all_results)))\n if self.oob_score:\n self._set_oob_score(X, y)\n return self\n \n @abstractmethod\n def _set_oob_score(self, X, y):\n \"\"\"Calculate out of bag predictions and score.\"\"\"\n \n \n def _validate_y(self, y):\n if len(y.shape) == 1 or y.shape[1] == 1:\n return column_or_1d(y, warn=True)\n else:\n return y\n \n def _get_estimators_indices(self):\n for seed in self._seeds:\n (feature_indices, sample_indices) = _generate_bagging_indices(seed, self.bootstrap_features, self.bootstrap, self.n_features_in_, self._n_samples, self._max_features, self._max_samples)\n yield (feature_indices, sample_indices)\n \n @property\n def estimators_samples_(self):\n \"\"\"\n The subset of drawn samples for each base estimator.\n\n Returns a dynamically generated list of indices identifying\n the samples used for fitting each member of the ensemble, i.e.,\n the in-bag samples.\n\n Note: the list is re-created at each call to the property in order\n to reduce the object memory footprint by not storing the sampling\n data. Thus fetching the property may be slower than expected.\n \"\"\"\n return [sample_indices for (_, sample_indices) in self._get_estimators_indices()]\n \n @deprecated('Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead.')\n @property\n def n_features_(self):\n return self.n_features_in_\n" + "source_code": "\n\nclass BaseBagging(BaseEnsemble, metaclass=ABCMeta):\n \"\"\"Base class for Bagging meta-estimator.\n\n Warning: This class should not be used directly. Use derived classes\n instead.\n \"\"\"\n \n @abstractmethod\n def __init__(self, base_estimator=None, n_estimators=10, *, max_samples=1.0, max_features=1.0, bootstrap=True, bootstrap_features=False, oob_score=False, warm_start=False, n_jobs=None, random_state=None, verbose=0):\n super().__init__(base_estimator=base_estimator, n_estimators=n_estimators)\n self.max_samples = max_samples\n self.max_features = max_features\n self.bootstrap = bootstrap\n self.bootstrap_features = bootstrap_features\n self.oob_score = oob_score\n self.warm_start = warm_start\n self.n_jobs = n_jobs\n self.random_state = random_state\n self.verbose = verbose\n \n def fit(self, X, y, sample_weight=None):\n \"\"\"Build a Bagging ensemble of estimators from the training set (X, y).\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrices are accepted only if\n they are supported by the base estimator.\n\n y : array-like of shape (n_samples,)\n The target values (class labels in classification, real numbers in\n regression).\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n Note that this is supported only if the base estimator supports\n sample weighting.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n (X, y) = self._validate_data(X, y, accept_sparse=['csr', 'csc'], dtype=None, force_all_finite=False, multi_output=True)\n return self._fit(X, y, self.max_samples, sample_weight=sample_weight)\n \n def _parallel_args(self):\n return {}\n \n def _fit(self, X, y, max_samples=None, max_depth=None, sample_weight=None):\n \"\"\"Build a Bagging ensemble of estimators from the training\n set (X, y).\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrices are accepted only if\n they are supported by the base estimator.\n\n y : array-like of shape (n_samples,)\n The target values (class labels in classification, real numbers in\n regression).\n\n max_samples : int or float, default=None\n Argument to use instead of self.max_samples.\n\n max_depth : int, default=None\n Override value used when constructing base estimator. Only\n supported if the base estimator has a max_depth parameter.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n Note that this is supported only if the base estimator supports\n sample weighting.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n random_state = check_random_state(self.random_state)\n if sample_weight is not None:\n sample_weight = _check_sample_weight(sample_weight, X, dtype=None)\n n_samples = X.shape[0]\n self._n_samples = n_samples\n y = self._validate_y(y)\n self._validate_estimator()\n if max_depth is not None:\n self.base_estimator_.max_depth = max_depth\n if max_samples is None:\n max_samples = self.max_samples\n elif not isinstance(max_samples, numbers.Integral):\n max_samples = int(max_samples * X.shape[0])\n if not 0 < max_samples <= X.shape[0]:\n raise ValueError('max_samples must be in (0, n_samples]')\n self._max_samples = max_samples\n if isinstance(self.max_features, numbers.Integral):\n max_features = self.max_features\n elif isinstance(self.max_features, float):\n max_features = self.max_features * self.n_features_in_\n else:\n raise ValueError('max_features must be int or float')\n if not 0 < max_features <= self.n_features_in_:\n raise ValueError('max_features must be in (0, n_features]')\n max_features = max(1, int(max_features))\n self._max_features = max_features\n if not self.bootstrap and self.oob_score:\n raise ValueError('Out of bag estimation only available if bootstrap=True')\n if self.warm_start and self.oob_score:\n raise ValueError('Out of bag estimate only available if warm_start=False')\n if hasattr(self, 'oob_score_') and self.warm_start:\n del self.oob_score_\n if not self.warm_start or not hasattr(self, 'estimators_'):\n self.estimators_ = []\n self.estimators_features_ = []\n n_more_estimators = self.n_estimators - len(self.estimators_)\n if n_more_estimators < 0:\n raise ValueError('n_estimators=%d must be larger or equal to len(estimators_)=%d when warm_start==True' % (self.n_estimators, len(self.estimators_)))\n elif n_more_estimators == 0:\n warn('Warm-start fitting without increasing n_estimators does not fit new trees.')\n return self\n (n_jobs, n_estimators, starts) = _partition_estimators(n_more_estimators, self.n_jobs)\n total_n_estimators = sum(n_estimators)\n if self.warm_start and len(self.estimators_) > 0:\n random_state.randint(MAX_INT, size=len(self.estimators_))\n seeds = random_state.randint(MAX_INT, size=n_more_estimators)\n self._seeds = seeds\n all_results = Parallel(n_jobs=n_jobs, verbose=self.verbose, **self._parallel_args())((delayed(_parallel_build_estimators)(n_estimators[i], self, X, y, sample_weight, seeds[starts[i]:starts[i + 1]], total_n_estimators, verbose=self.verbose) for i in range(n_jobs)))\n self.estimators_ += list(itertools.chain.from_iterable((t[0] for t in all_results)))\n self.estimators_features_ += list(itertools.chain.from_iterable((t[1] for t in all_results)))\n if self.oob_score:\n self._set_oob_score(X, y)\n return self\n \n @abstractmethod\n def _set_oob_score(self, X, y):\n \"\"\"Calculate out of bag predictions and score.\"\"\"\n \n \n def _validate_y(self, y):\n if len(y.shape) == 1 or y.shape[1] == 1:\n return column_or_1d(y, warn=True)\n else:\n return y\n \n def _get_estimators_indices(self):\n for seed in self._seeds:\n (feature_indices, sample_indices) = _generate_bagging_indices(seed, self.bootstrap_features, self.bootstrap, self.n_features_in_, self._n_samples, self._max_features, self._max_samples)\n yield (feature_indices, sample_indices)\n \n @property\n def estimators_samples_(self):\n \"\"\"\n The subset of drawn samples for each base estimator.\n\n Returns a dynamically generated list of indices identifying\n the samples used for fitting each member of the ensemble, i.e.,\n the in-bag samples.\n\n Note: the list is re-created at each call to the property in order\n to reduce the object memory footprint by not storing the sampling\n data. Thus fetching the property may be slower than expected.\n \"\"\"\n return [sample_indices for (_, sample_indices) in self._get_estimators_indices()]\n \n @deprecated('Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead.')\n @property\n def n_features_(self):\n return self.n_features_in_\n" }, { "name": "BaseEnsemble", @@ -20899,7 +20866,7 @@ "decorators": [], "superclasses": ["MetaEstimatorMixin", "_BaseComposition"], "methods": [ - "sklearn.ensemble._base._BaseHeterogeneousEnsemble.named_estimators", + "sklearn.ensemble._base._BaseHeterogeneousEnsemble.named_estimators@getter", "sklearn.ensemble._base._BaseHeterogeneousEnsemble.__init__", "sklearn.ensemble._base._BaseHeterogeneousEnsemble._validate_estimators", "sklearn.ensemble._base._BaseHeterogeneousEnsemble.set_params", @@ -20924,8 +20891,8 @@ "sklearn.ensemble._forest.BaseForest._compute_oob_predictions", "sklearn.ensemble._forest.BaseForest._validate_y_class_weight", "sklearn.ensemble._forest.BaseForest._validate_X_predict", - "sklearn.ensemble._forest.BaseForest.feature_importances_", - "sklearn.ensemble._forest.BaseForest.n_features_" + "sklearn.ensemble._forest.BaseForest.feature_importances_@getter", + "sklearn.ensemble._forest.BaseForest.n_features_@getter" ], "is_public": false, "description": "Base class for forests of trees.\n\nWarning: This class should not be used directly. Use derived classes instead.", @@ -20955,8 +20922,8 @@ ], "is_public": true, "description": "An extra-trees regressor.\n\nThis class implements a meta estimator that fits a number of randomized decision trees (a.k.a. extra-trees) on various sub-samples of the dataset and uses averaging to improve the predictive accuracy and control over-fitting. Read more in the :ref:`User Guide `.", - "docstring": "\n An extra-trees regressor.\n\n This class implements a meta estimator that fits a number of\n randomized decision trees (a.k.a. extra-trees) on various sub-samples\n of the dataset and uses averaging to improve the predictive accuracy\n and control over-fitting.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_estimators : int, default=100\n The number of trees in the forest.\n\n .. versionchanged:: 0.22\n The default value of ``n_estimators`` changed from 10 to 100\n in 0.22.\n\n criterion : {\"squared_error\", \"mse\", \"absolute_error\", \"mae\"}, default=\"squared_error\"\n The function to measure the quality of a split. Supported criteria\n are \"squared_error\" for the mean squared error, which is equal to\n variance reduction as feature selection criterion, and \"absolute_error\"\n for the mean absolute error.\n\n .. versionadded:: 0.18\n Mean Absolute Error (MAE) criterion.\n\n .. deprecated:: 1.0\n Criterion \"mse\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"squared_error\"` which is equivalent.\n\n .. deprecated:: 1.0\n Criterion \"mae\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"absolute_error\"` which is equivalent.\n\n max_depth : int, default=None\n The maximum depth of the tree. If None, then nodes are expanded until\n all leaves are pure or until all leaves contain less than\n min_samples_split samples.\n\n min_samples_split : int or float, default=2\n The minimum number of samples required to split an internal node:\n\n - If int, then consider `min_samples_split` as the minimum number.\n - If float, then `min_samples_split` is a fraction and\n `ceil(min_samples_split * n_samples)` are the minimum\n number of samples for each split.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_samples_leaf : int or float, default=1\n The minimum number of samples required to be at a leaf node.\n A split point at any depth will only be considered if it leaves at\n least ``min_samples_leaf`` training samples in each of the left and\n right branches. This may have the effect of smoothing the model,\n especially in regression.\n\n - If int, then consider `min_samples_leaf` as the minimum number.\n - If float, then `min_samples_leaf` is a fraction and\n `ceil(min_samples_leaf * n_samples)` are the minimum\n number of samples for each node.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_weight_fraction_leaf : float, default=0.0\n The minimum weighted fraction of the sum total of weights (of all\n the input samples) required to be at a leaf node. Samples have\n equal weight when sample_weight is not provided.\n\n max_features : {\"auto\", \"sqrt\", \"log2\"}, int or float, default=\"auto\"\n The number of features to consider when looking for the best split:\n\n - If int, then consider `max_features` features at each split.\n - If float, then `max_features` is a fraction and\n `round(max_features * n_features)` features are considered at each\n split.\n - If \"auto\", then `max_features=n_features`.\n - If \"sqrt\", then `max_features=sqrt(n_features)`.\n - If \"log2\", then `max_features=log2(n_features)`.\n - If None, then `max_features=n_features`.\n\n Note: the search for a split does not stop until at least one\n valid partition of the node samples is found, even if it requires to\n effectively inspect more than ``max_features`` features.\n\n max_leaf_nodes : int, default=None\n Grow trees with ``max_leaf_nodes`` in best-first fashion.\n Best nodes are defined as relative reduction in impurity.\n If None then unlimited number of leaf nodes.\n\n min_impurity_decrease : float, default=0.0\n A node will be split if this split induces a decrease of the impurity\n greater than or equal to this value.\n\n The weighted impurity decrease equation is the following::\n\n N_t / N * (impurity - N_t_R / N_t * right_impurity\n - N_t_L / N_t * left_impurity)\n\n where ``N`` is the total number of samples, ``N_t`` is the number of\n samples at the current node, ``N_t_L`` is the number of samples in the\n left child, and ``N_t_R`` is the number of samples in the right child.\n\n ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n if ``sample_weight`` is passed.\n\n .. versionadded:: 0.19\n\n bootstrap : bool, default=False\n Whether bootstrap samples are used when building trees. If False, the\n whole dataset is used to build each tree.\n\n oob_score : bool, default=False\n Whether to use out-of-bag samples to estimate the generalization score.\n Only available if bootstrap=True.\n\n n_jobs : int, default=None\n The number of jobs to run in parallel. :meth:`fit`, :meth:`predict`,\n :meth:`decision_path` and :meth:`apply` are all parallelized over the\n trees. ``None`` means 1 unless in a :obj:`joblib.parallel_backend`\n context. ``-1`` means using all processors. See :term:`Glossary\n ` for more details.\n\n random_state : int, RandomState instance or None, default=None\n Controls 3 sources of randomness:\n\n - the bootstrapping of the samples used when building trees\n (if ``bootstrap=True``)\n - the sampling of the features to consider when looking for the best\n split at each node (if ``max_features < n_features``)\n - the draw of the splits for each of the `max_features`\n\n See :term:`Glossary ` for details.\n\n verbose : int, default=0\n Controls the verbosity when fitting and predicting.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit\n and add more estimators to the ensemble, otherwise, just fit a whole\n new forest. See :term:`the Glossary `.\n\n ccp_alpha : non-negative float, default=0.0\n Complexity parameter used for Minimal Cost-Complexity Pruning. The\n subtree with the largest cost complexity that is smaller than\n ``ccp_alpha`` will be chosen. By default, no pruning is performed. See\n :ref:`minimal_cost_complexity_pruning` for details.\n\n .. versionadded:: 0.22\n\n max_samples : int or float, default=None\n If bootstrap is True, the number of samples to draw from X\n to train each base estimator.\n\n - If None (default), then draw `X.shape[0]` samples.\n - If int, then draw `max_samples` samples.\n - If float, then draw `max_samples * X.shape[0]` samples. Thus,\n `max_samples` should be in the interval `(0.0, 1.0]`.\n\n .. versionadded:: 0.22\n\n Attributes\n ----------\n base_estimator_ : ExtraTreeRegressor\n The child estimator template used to create the collection of fitted\n sub-estimators.\n\n estimators_ : list of DecisionTreeRegressor\n The collection of fitted sub-estimators.\n\n feature_importances_ : ndarray of shape (n_features,)\n The impurity-based feature importances.\n The higher, the more important the feature.\n The importance of a feature is computed as the (normalized)\n total reduction of the criterion brought by that feature. It is also\n known as the Gini importance.\n\n Warning: impurity-based feature importances can be misleading for\n high cardinality features (many unique values). See\n :func:`sklearn.inspection.permutation_importance` as an alternative.\n\n n_features_ : int\n The number of features.\n\n .. deprecated:: 1.0\n Attribute `n_features_` was deprecated in version 1.0 and will be\n removed in 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n .. versionadded:: 1.0\n\n n_outputs_ : int\n The number of outputs.\n\n oob_score_ : float\n Score of the training dataset obtained using an out-of-bag estimate.\n This attribute exists only when ``oob_score`` is True.\n\n oob_prediction_ : ndarray of shape (n_samples,) or (n_samples, n_outputs)\n Prediction computed with out-of-bag estimate on the training set.\n This attribute exists only when ``oob_score`` is True.\n\n See Also\n --------\n ExtraTreesClassifier : An extra-trees classifier with random splits.\n RandomForestClassifier : A random forest classifier with optimal splits.\n RandomForestRegressor : Ensemble regressor using trees with optimal splits.\n\n Notes\n -----\n The default values for the parameters controlling the size of the trees\n (e.g. ``max_depth``, ``min_samples_leaf``, etc.) lead to fully grown and\n unpruned trees which can potentially be very large on some data sets. To\n reduce memory consumption, the complexity and size of the trees should be\n controlled by setting those parameter values.\n\n References\n ----------\n .. [1] P. Geurts, D. Ernst., and L. Wehenkel, \"Extremely randomized trees\",\n Machine Learning, 63(1), 3-42, 2006.\n\n Examples\n --------\n >>> from sklearn.datasets import load_diabetes\n >>> from sklearn.model_selection import train_test_split\n >>> from sklearn.ensemble import ExtraTreesRegressor\n >>> X, y = load_diabetes(return_X_y=True)\n >>> X_train, X_test, y_train, y_test = train_test_split(\n ... X, y, random_state=0)\n >>> reg = ExtraTreesRegressor(n_estimators=100, random_state=0).fit(\n ... X_train, y_train)\n >>> reg.score(X_test, y_test)\n 0.2708...\n ", - "source_code": "\n\nclass ExtraTreesRegressor(ForestRegressor):\n \"\"\"\n An extra-trees regressor.\n\n This class implements a meta estimator that fits a number of\n randomized decision trees (a.k.a. extra-trees) on various sub-samples\n of the dataset and uses averaging to improve the predictive accuracy\n and control over-fitting.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_estimators : int, default=100\n The number of trees in the forest.\n\n .. versionchanged:: 0.22\n The default value of ``n_estimators`` changed from 10 to 100\n in 0.22.\n\n criterion : {\"squared_error\", \"mse\", \"absolute_error\", \"mae\"}, default=\"squared_error\"\n The function to measure the quality of a split. Supported criteria\n are \"squared_error\" for the mean squared error, which is equal to\n variance reduction as feature selection criterion, and \"absolute_error\"\n for the mean absolute error.\n\n .. versionadded:: 0.18\n Mean Absolute Error (MAE) criterion.\n\n .. deprecated:: 1.0\n Criterion \"mse\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"squared_error\"` which is equivalent.\n\n .. deprecated:: 1.0\n Criterion \"mae\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"absolute_error\"` which is equivalent.\n\n max_depth : int, default=None\n The maximum depth of the tree. If None, then nodes are expanded until\n all leaves are pure or until all leaves contain less than\n min_samples_split samples.\n\n min_samples_split : int or float, default=2\n The minimum number of samples required to split an internal node:\n\n - If int, then consider `min_samples_split` as the minimum number.\n - If float, then `min_samples_split` is a fraction and\n `ceil(min_samples_split * n_samples)` are the minimum\n number of samples for each split.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_samples_leaf : int or float, default=1\n The minimum number of samples required to be at a leaf node.\n A split point at any depth will only be considered if it leaves at\n least ``min_samples_leaf`` training samples in each of the left and\n right branches. This may have the effect of smoothing the model,\n especially in regression.\n\n - If int, then consider `min_samples_leaf` as the minimum number.\n - If float, then `min_samples_leaf` is a fraction and\n `ceil(min_samples_leaf * n_samples)` are the minimum\n number of samples for each node.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_weight_fraction_leaf : float, default=0.0\n The minimum weighted fraction of the sum total of weights (of all\n the input samples) required to be at a leaf node. Samples have\n equal weight when sample_weight is not provided.\n\n max_features : {\"auto\", \"sqrt\", \"log2\"}, int or float, default=\"auto\"\n The number of features to consider when looking for the best split:\n\n - If int, then consider `max_features` features at each split.\n - If float, then `max_features` is a fraction and\n `round(max_features * n_features)` features are considered at each\n split.\n - If \"auto\", then `max_features=n_features`.\n - If \"sqrt\", then `max_features=sqrt(n_features)`.\n - If \"log2\", then `max_features=log2(n_features)`.\n - If None, then `max_features=n_features`.\n\n Note: the search for a split does not stop until at least one\n valid partition of the node samples is found, even if it requires to\n effectively inspect more than ``max_features`` features.\n\n max_leaf_nodes : int, default=None\n Grow trees with ``max_leaf_nodes`` in best-first fashion.\n Best nodes are defined as relative reduction in impurity.\n If None then unlimited number of leaf nodes.\n\n min_impurity_decrease : float, default=0.0\n A node will be split if this split induces a decrease of the impurity\n greater than or equal to this value.\n\n The weighted impurity decrease equation is the following::\n\n N_t / N * (impurity - N_t_R / N_t * right_impurity\n - N_t_L / N_t * left_impurity)\n\n where ``N`` is the total number of samples, ``N_t`` is the number of\n samples at the current node, ``N_t_L`` is the number of samples in the\n left child, and ``N_t_R`` is the number of samples in the right child.\n\n ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n if ``sample_weight`` is passed.\n\n .. versionadded:: 0.19\n\n bootstrap : bool, default=False\n Whether bootstrap samples are used when building trees. If False, the\n whole dataset is used to build each tree.\n\n oob_score : bool, default=False\n Whether to use out-of-bag samples to estimate the generalization score.\n Only available if bootstrap=True.\n\n n_jobs : int, default=None\n The number of jobs to run in parallel. :meth:`fit`, :meth:`predict`,\n :meth:`decision_path` and :meth:`apply` are all parallelized over the\n trees. ``None`` means 1 unless in a :obj:`joblib.parallel_backend`\n context. ``-1`` means using all processors. See :term:`Glossary\n ` for more details.\n\n random_state : int, RandomState instance or None, default=None\n Controls 3 sources of randomness:\n\n - the bootstrapping of the samples used when building trees\n (if ``bootstrap=True``)\n - the sampling of the features to consider when looking for the best\n split at each node (if ``max_features < n_features``)\n - the draw of the splits for each of the `max_features`\n\n See :term:`Glossary ` for details.\n\n verbose : int, default=0\n Controls the verbosity when fitting and predicting.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit\n and add more estimators to the ensemble, otherwise, just fit a whole\n new forest. See :term:`the Glossary `.\n\n ccp_alpha : non-negative float, default=0.0\n Complexity parameter used for Minimal Cost-Complexity Pruning. The\n subtree with the largest cost complexity that is smaller than\n ``ccp_alpha`` will be chosen. By default, no pruning is performed. See\n :ref:`minimal_cost_complexity_pruning` for details.\n\n .. versionadded:: 0.22\n\n max_samples : int or float, default=None\n If bootstrap is True, the number of samples to draw from X\n to train each base estimator.\n\n - If None (default), then draw `X.shape[0]` samples.\n - If int, then draw `max_samples` samples.\n - If float, then draw `max_samples * X.shape[0]` samples. Thus,\n `max_samples` should be in the interval `(0.0, 1.0]`.\n\n .. versionadded:: 0.22\n\n Attributes\n ----------\n base_estimator_ : ExtraTreeRegressor\n The child estimator template used to create the collection of fitted\n sub-estimators.\n\n estimators_ : list of DecisionTreeRegressor\n The collection of fitted sub-estimators.\n\n feature_importances_ : ndarray of shape (n_features,)\n The impurity-based feature importances.\n The higher, the more important the feature.\n The importance of a feature is computed as the (normalized)\n total reduction of the criterion brought by that feature. It is also\n known as the Gini importance.\n\n Warning: impurity-based feature importances can be misleading for\n high cardinality features (many unique values). See\n :func:`sklearn.inspection.permutation_importance` as an alternative.\n\n n_features_ : int\n The number of features.\n\n .. deprecated:: 1.0\n Attribute `n_features_` was deprecated in version 1.0 and will be\n removed in 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n .. versionadded:: 1.0\n\n n_outputs_ : int\n The number of outputs.\n\n oob_score_ : float\n Score of the training dataset obtained using an out-of-bag estimate.\n This attribute exists only when ``oob_score`` is True.\n\n oob_prediction_ : ndarray of shape (n_samples,) or (n_samples, n_outputs)\n Prediction computed with out-of-bag estimate on the training set.\n This attribute exists only when ``oob_score`` is True.\n\n See Also\n --------\n ExtraTreesClassifier : An extra-trees classifier with random splits.\n RandomForestClassifier : A random forest classifier with optimal splits.\n RandomForestRegressor : Ensemble regressor using trees with optimal splits.\n\n Notes\n -----\n The default values for the parameters controlling the size of the trees\n (e.g. ``max_depth``, ``min_samples_leaf``, etc.) lead to fully grown and\n unpruned trees which can potentially be very large on some data sets. To\n reduce memory consumption, the complexity and size of the trees should be\n controlled by setting those parameter values.\n\n References\n ----------\n .. [1] P. Geurts, D. Ernst., and L. Wehenkel, \"Extremely randomized trees\",\n Machine Learning, 63(1), 3-42, 2006.\n\n Examples\n --------\n >>> from sklearn.datasets import load_diabetes\n >>> from sklearn.model_selection import train_test_split\n >>> from sklearn.ensemble import ExtraTreesRegressor\n >>> X, y = load_diabetes(return_X_y=True)\n >>> X_train, X_test, y_train, y_test = train_test_split(\n ... X, y, random_state=0)\n >>> reg = ExtraTreesRegressor(n_estimators=100, random_state=0).fit(\n ... X_train, y_train)\n >>> reg.score(X_test, y_test)\n 0.2708...\n \"\"\"\n \n def __init__(self, n_estimators=100, *, criterion='squared_error', max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features='auto', max_leaf_nodes=None, min_impurity_decrease=0.0, bootstrap=False, oob_score=False, n_jobs=None, random_state=None, verbose=0, warm_start=False, ccp_alpha=0.0, max_samples=None):\n super().__init__(base_estimator=ExtraTreeRegressor(), n_estimators=n_estimators, estimator_params=('criterion', 'max_depth', 'min_samples_split', 'min_samples_leaf', 'min_weight_fraction_leaf', 'max_features', 'max_leaf_nodes', 'min_impurity_decrease', 'random_state', 'ccp_alpha'), bootstrap=bootstrap, oob_score=oob_score, n_jobs=n_jobs, random_state=random_state, verbose=verbose, warm_start=warm_start, max_samples=max_samples)\n self.criterion = criterion\n self.max_depth = max_depth\n self.min_samples_split = min_samples_split\n self.min_samples_leaf = min_samples_leaf\n self.min_weight_fraction_leaf = min_weight_fraction_leaf\n self.max_features = max_features\n self.max_leaf_nodes = max_leaf_nodes\n self.min_impurity_decrease = min_impurity_decrease\n self.ccp_alpha = ccp_alpha\n" + "docstring": "\n An extra-trees regressor.\n\n This class implements a meta estimator that fits a number of\n randomized decision trees (a.k.a. extra-trees) on various sub-samples\n of the dataset and uses averaging to improve the predictive accuracy\n and control over-fitting.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_estimators : int, default=100\n The number of trees in the forest.\n\n .. versionchanged:: 0.22\n The default value of ``n_estimators`` changed from 10 to 100\n in 0.22.\n\n criterion : {\"squared_error\", \"absolute_error\"}, default=\"squared_error\"\n The function to measure the quality of a split. Supported criteria\n are \"squared_error\" for the mean squared error, which is equal to\n variance reduction as feature selection criterion, and \"absolute_error\"\n for the mean absolute error.\n\n .. versionadded:: 0.18\n Mean Absolute Error (MAE) criterion.\n\n .. deprecated:: 1.0\n Criterion \"mse\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"squared_error\"` which is equivalent.\n\n .. deprecated:: 1.0\n Criterion \"mae\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"absolute_error\"` which is equivalent.\n\n max_depth : int, default=None\n The maximum depth of the tree. If None, then nodes are expanded until\n all leaves are pure or until all leaves contain less than\n min_samples_split samples.\n\n min_samples_split : int or float, default=2\n The minimum number of samples required to split an internal node:\n\n - If int, then consider `min_samples_split` as the minimum number.\n - If float, then `min_samples_split` is a fraction and\n `ceil(min_samples_split * n_samples)` are the minimum\n number of samples for each split.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_samples_leaf : int or float, default=1\n The minimum number of samples required to be at a leaf node.\n A split point at any depth will only be considered if it leaves at\n least ``min_samples_leaf`` training samples in each of the left and\n right branches. This may have the effect of smoothing the model,\n especially in regression.\n\n - If int, then consider `min_samples_leaf` as the minimum number.\n - If float, then `min_samples_leaf` is a fraction and\n `ceil(min_samples_leaf * n_samples)` are the minimum\n number of samples for each node.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_weight_fraction_leaf : float, default=0.0\n The minimum weighted fraction of the sum total of weights (of all\n the input samples) required to be at a leaf node. Samples have\n equal weight when sample_weight is not provided.\n\n max_features : {\"auto\", \"sqrt\", \"log2\"}, int or float, default=\"auto\"\n The number of features to consider when looking for the best split:\n\n - If int, then consider `max_features` features at each split.\n - If float, then `max_features` is a fraction and\n `round(max_features * n_features)` features are considered at each\n split.\n - If \"auto\", then `max_features=n_features`.\n - If \"sqrt\", then `max_features=sqrt(n_features)`.\n - If \"log2\", then `max_features=log2(n_features)`.\n - If None, then `max_features=n_features`.\n\n Note: the search for a split does not stop until at least one\n valid partition of the node samples is found, even if it requires to\n effectively inspect more than ``max_features`` features.\n\n max_leaf_nodes : int, default=None\n Grow trees with ``max_leaf_nodes`` in best-first fashion.\n Best nodes are defined as relative reduction in impurity.\n If None then unlimited number of leaf nodes.\n\n min_impurity_decrease : float, default=0.0\n A node will be split if this split induces a decrease of the impurity\n greater than or equal to this value.\n\n The weighted impurity decrease equation is the following::\n\n N_t / N * (impurity - N_t_R / N_t * right_impurity\n - N_t_L / N_t * left_impurity)\n\n where ``N`` is the total number of samples, ``N_t`` is the number of\n samples at the current node, ``N_t_L`` is the number of samples in the\n left child, and ``N_t_R`` is the number of samples in the right child.\n\n ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n if ``sample_weight`` is passed.\n\n .. versionadded:: 0.19\n\n bootstrap : bool, default=False\n Whether bootstrap samples are used when building trees. If False, the\n whole dataset is used to build each tree.\n\n oob_score : bool, default=False\n Whether to use out-of-bag samples to estimate the generalization score.\n Only available if bootstrap=True.\n\n n_jobs : int, default=None\n The number of jobs to run in parallel. :meth:`fit`, :meth:`predict`,\n :meth:`decision_path` and :meth:`apply` are all parallelized over the\n trees. ``None`` means 1 unless in a :obj:`joblib.parallel_backend`\n context. ``-1`` means using all processors. See :term:`Glossary\n ` for more details.\n\n random_state : int, RandomState instance or None, default=None\n Controls 3 sources of randomness:\n\n - the bootstrapping of the samples used when building trees\n (if ``bootstrap=True``)\n - the sampling of the features to consider when looking for the best\n split at each node (if ``max_features < n_features``)\n - the draw of the splits for each of the `max_features`\n\n See :term:`Glossary ` for details.\n\n verbose : int, default=0\n Controls the verbosity when fitting and predicting.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit\n and add more estimators to the ensemble, otherwise, just fit a whole\n new forest. See :term:`the Glossary `.\n\n ccp_alpha : non-negative float, default=0.0\n Complexity parameter used for Minimal Cost-Complexity Pruning. The\n subtree with the largest cost complexity that is smaller than\n ``ccp_alpha`` will be chosen. By default, no pruning is performed. See\n :ref:`minimal_cost_complexity_pruning` for details.\n\n .. versionadded:: 0.22\n\n max_samples : int or float, default=None\n If bootstrap is True, the number of samples to draw from X\n to train each base estimator.\n\n - If None (default), then draw `X.shape[0]` samples.\n - If int, then draw `max_samples` samples.\n - If float, then draw `max_samples * X.shape[0]` samples. Thus,\n `max_samples` should be in the interval `(0.0, 1.0]`.\n\n .. versionadded:: 0.22\n\n Attributes\n ----------\n base_estimator_ : ExtraTreeRegressor\n The child estimator template used to create the collection of fitted\n sub-estimators.\n\n estimators_ : list of DecisionTreeRegressor\n The collection of fitted sub-estimators.\n\n feature_importances_ : ndarray of shape (n_features,)\n The impurity-based feature importances.\n The higher, the more important the feature.\n The importance of a feature is computed as the (normalized)\n total reduction of the criterion brought by that feature. It is also\n known as the Gini importance.\n\n Warning: impurity-based feature importances can be misleading for\n high cardinality features (many unique values). See\n :func:`sklearn.inspection.permutation_importance` as an alternative.\n\n n_features_ : int\n The number of features.\n\n .. deprecated:: 1.0\n Attribute `n_features_` was deprecated in version 1.0 and will be\n removed in 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n .. versionadded:: 1.0\n\n n_outputs_ : int\n The number of outputs.\n\n oob_score_ : float\n Score of the training dataset obtained using an out-of-bag estimate.\n This attribute exists only when ``oob_score`` is True.\n\n oob_prediction_ : ndarray of shape (n_samples,) or (n_samples, n_outputs)\n Prediction computed with out-of-bag estimate on the training set.\n This attribute exists only when ``oob_score`` is True.\n\n See Also\n --------\n ExtraTreesClassifier : An extra-trees classifier with random splits.\n RandomForestClassifier : A random forest classifier with optimal splits.\n RandomForestRegressor : Ensemble regressor using trees with optimal splits.\n\n Notes\n -----\n The default values for the parameters controlling the size of the trees\n (e.g. ``max_depth``, ``min_samples_leaf``, etc.) lead to fully grown and\n unpruned trees which can potentially be very large on some data sets. To\n reduce memory consumption, the complexity and size of the trees should be\n controlled by setting those parameter values.\n\n References\n ----------\n .. [1] P. Geurts, D. Ernst., and L. Wehenkel, \"Extremely randomized trees\",\n Machine Learning, 63(1), 3-42, 2006.\n\n Examples\n --------\n >>> from sklearn.datasets import load_diabetes\n >>> from sklearn.model_selection import train_test_split\n >>> from sklearn.ensemble import ExtraTreesRegressor\n >>> X, y = load_diabetes(return_X_y=True)\n >>> X_train, X_test, y_train, y_test = train_test_split(\n ... X, y, random_state=0)\n >>> reg = ExtraTreesRegressor(n_estimators=100, random_state=0).fit(\n ... X_train, y_train)\n >>> reg.score(X_test, y_test)\n 0.2708...\n ", + "source_code": "\n\nclass ExtraTreesRegressor(ForestRegressor):\n \"\"\"\n An extra-trees regressor.\n\n This class implements a meta estimator that fits a number of\n randomized decision trees (a.k.a. extra-trees) on various sub-samples\n of the dataset and uses averaging to improve the predictive accuracy\n and control over-fitting.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_estimators : int, default=100\n The number of trees in the forest.\n\n .. versionchanged:: 0.22\n The default value of ``n_estimators`` changed from 10 to 100\n in 0.22.\n\n criterion : {\"squared_error\", \"absolute_error\"}, default=\"squared_error\"\n The function to measure the quality of a split. Supported criteria\n are \"squared_error\" for the mean squared error, which is equal to\n variance reduction as feature selection criterion, and \"absolute_error\"\n for the mean absolute error.\n\n .. versionadded:: 0.18\n Mean Absolute Error (MAE) criterion.\n\n .. deprecated:: 1.0\n Criterion \"mse\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"squared_error\"` which is equivalent.\n\n .. deprecated:: 1.0\n Criterion \"mae\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"absolute_error\"` which is equivalent.\n\n max_depth : int, default=None\n The maximum depth of the tree. If None, then nodes are expanded until\n all leaves are pure or until all leaves contain less than\n min_samples_split samples.\n\n min_samples_split : int or float, default=2\n The minimum number of samples required to split an internal node:\n\n - If int, then consider `min_samples_split` as the minimum number.\n - If float, then `min_samples_split` is a fraction and\n `ceil(min_samples_split * n_samples)` are the minimum\n number of samples for each split.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_samples_leaf : int or float, default=1\n The minimum number of samples required to be at a leaf node.\n A split point at any depth will only be considered if it leaves at\n least ``min_samples_leaf`` training samples in each of the left and\n right branches. This may have the effect of smoothing the model,\n especially in regression.\n\n - If int, then consider `min_samples_leaf` as the minimum number.\n - If float, then `min_samples_leaf` is a fraction and\n `ceil(min_samples_leaf * n_samples)` are the minimum\n number of samples for each node.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_weight_fraction_leaf : float, default=0.0\n The minimum weighted fraction of the sum total of weights (of all\n the input samples) required to be at a leaf node. Samples have\n equal weight when sample_weight is not provided.\n\n max_features : {\"auto\", \"sqrt\", \"log2\"}, int or float, default=\"auto\"\n The number of features to consider when looking for the best split:\n\n - If int, then consider `max_features` features at each split.\n - If float, then `max_features` is a fraction and\n `round(max_features * n_features)` features are considered at each\n split.\n - If \"auto\", then `max_features=n_features`.\n - If \"sqrt\", then `max_features=sqrt(n_features)`.\n - If \"log2\", then `max_features=log2(n_features)`.\n - If None, then `max_features=n_features`.\n\n Note: the search for a split does not stop until at least one\n valid partition of the node samples is found, even if it requires to\n effectively inspect more than ``max_features`` features.\n\n max_leaf_nodes : int, default=None\n Grow trees with ``max_leaf_nodes`` in best-first fashion.\n Best nodes are defined as relative reduction in impurity.\n If None then unlimited number of leaf nodes.\n\n min_impurity_decrease : float, default=0.0\n A node will be split if this split induces a decrease of the impurity\n greater than or equal to this value.\n\n The weighted impurity decrease equation is the following::\n\n N_t / N * (impurity - N_t_R / N_t * right_impurity\n - N_t_L / N_t * left_impurity)\n\n where ``N`` is the total number of samples, ``N_t`` is the number of\n samples at the current node, ``N_t_L`` is the number of samples in the\n left child, and ``N_t_R`` is the number of samples in the right child.\n\n ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n if ``sample_weight`` is passed.\n\n .. versionadded:: 0.19\n\n bootstrap : bool, default=False\n Whether bootstrap samples are used when building trees. If False, the\n whole dataset is used to build each tree.\n\n oob_score : bool, default=False\n Whether to use out-of-bag samples to estimate the generalization score.\n Only available if bootstrap=True.\n\n n_jobs : int, default=None\n The number of jobs to run in parallel. :meth:`fit`, :meth:`predict`,\n :meth:`decision_path` and :meth:`apply` are all parallelized over the\n trees. ``None`` means 1 unless in a :obj:`joblib.parallel_backend`\n context. ``-1`` means using all processors. See :term:`Glossary\n ` for more details.\n\n random_state : int, RandomState instance or None, default=None\n Controls 3 sources of randomness:\n\n - the bootstrapping of the samples used when building trees\n (if ``bootstrap=True``)\n - the sampling of the features to consider when looking for the best\n split at each node (if ``max_features < n_features``)\n - the draw of the splits for each of the `max_features`\n\n See :term:`Glossary ` for details.\n\n verbose : int, default=0\n Controls the verbosity when fitting and predicting.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit\n and add more estimators to the ensemble, otherwise, just fit a whole\n new forest. See :term:`the Glossary `.\n\n ccp_alpha : non-negative float, default=0.0\n Complexity parameter used for Minimal Cost-Complexity Pruning. The\n subtree with the largest cost complexity that is smaller than\n ``ccp_alpha`` will be chosen. By default, no pruning is performed. See\n :ref:`minimal_cost_complexity_pruning` for details.\n\n .. versionadded:: 0.22\n\n max_samples : int or float, default=None\n If bootstrap is True, the number of samples to draw from X\n to train each base estimator.\n\n - If None (default), then draw `X.shape[0]` samples.\n - If int, then draw `max_samples` samples.\n - If float, then draw `max_samples * X.shape[0]` samples. Thus,\n `max_samples` should be in the interval `(0.0, 1.0]`.\n\n .. versionadded:: 0.22\n\n Attributes\n ----------\n base_estimator_ : ExtraTreeRegressor\n The child estimator template used to create the collection of fitted\n sub-estimators.\n\n estimators_ : list of DecisionTreeRegressor\n The collection of fitted sub-estimators.\n\n feature_importances_ : ndarray of shape (n_features,)\n The impurity-based feature importances.\n The higher, the more important the feature.\n The importance of a feature is computed as the (normalized)\n total reduction of the criterion brought by that feature. It is also\n known as the Gini importance.\n\n Warning: impurity-based feature importances can be misleading for\n high cardinality features (many unique values). See\n :func:`sklearn.inspection.permutation_importance` as an alternative.\n\n n_features_ : int\n The number of features.\n\n .. deprecated:: 1.0\n Attribute `n_features_` was deprecated in version 1.0 and will be\n removed in 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n .. versionadded:: 1.0\n\n n_outputs_ : int\n The number of outputs.\n\n oob_score_ : float\n Score of the training dataset obtained using an out-of-bag estimate.\n This attribute exists only when ``oob_score`` is True.\n\n oob_prediction_ : ndarray of shape (n_samples,) or (n_samples, n_outputs)\n Prediction computed with out-of-bag estimate on the training set.\n This attribute exists only when ``oob_score`` is True.\n\n See Also\n --------\n ExtraTreesClassifier : An extra-trees classifier with random splits.\n RandomForestClassifier : A random forest classifier with optimal splits.\n RandomForestRegressor : Ensemble regressor using trees with optimal splits.\n\n Notes\n -----\n The default values for the parameters controlling the size of the trees\n (e.g. ``max_depth``, ``min_samples_leaf``, etc.) lead to fully grown and\n unpruned trees which can potentially be very large on some data sets. To\n reduce memory consumption, the complexity and size of the trees should be\n controlled by setting those parameter values.\n\n References\n ----------\n .. [1] P. Geurts, D. Ernst., and L. Wehenkel, \"Extremely randomized trees\",\n Machine Learning, 63(1), 3-42, 2006.\n\n Examples\n --------\n >>> from sklearn.datasets import load_diabetes\n >>> from sklearn.model_selection import train_test_split\n >>> from sklearn.ensemble import ExtraTreesRegressor\n >>> X, y = load_diabetes(return_X_y=True)\n >>> X_train, X_test, y_train, y_test = train_test_split(\n ... X, y, random_state=0)\n >>> reg = ExtraTreesRegressor(n_estimators=100, random_state=0).fit(\n ... X_train, y_train)\n >>> reg.score(X_test, y_test)\n 0.2708...\n \"\"\"\n \n def __init__(self, n_estimators=100, *, criterion='squared_error', max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features='auto', max_leaf_nodes=None, min_impurity_decrease=0.0, bootstrap=False, oob_score=False, n_jobs=None, random_state=None, verbose=0, warm_start=False, ccp_alpha=0.0, max_samples=None):\n super().__init__(base_estimator=ExtraTreeRegressor(), n_estimators=n_estimators, estimator_params=('criterion', 'max_depth', 'min_samples_split', 'min_samples_leaf', 'min_weight_fraction_leaf', 'max_features', 'max_leaf_nodes', 'min_impurity_decrease', 'random_state', 'ccp_alpha'), bootstrap=bootstrap, oob_score=oob_score, n_jobs=n_jobs, random_state=random_state, verbose=verbose, warm_start=warm_start, max_samples=max_samples)\n self.criterion = criterion\n self.max_depth = max_depth\n self.min_samples_split = min_samples_split\n self.min_samples_leaf = min_samples_leaf\n self.min_weight_fraction_leaf = min_weight_fraction_leaf\n self.max_features = max_features\n self.max_leaf_nodes = max_leaf_nodes\n self.min_impurity_decrease = min_impurity_decrease\n self.ccp_alpha = ccp_alpha\n" }, { "name": "ForestClassifier", @@ -21019,8 +20986,8 @@ ], "is_public": true, "description": "A random forest regressor.\n\nA random forest is a meta estimator that fits a number of classifying decision trees on various sub-samples of the dataset and uses averaging to improve the predictive accuracy and control over-fitting. The sub-sample size is controlled with the `max_samples` parameter if `bootstrap=True` (default), otherwise the whole dataset is used to build each tree. Read more in the :ref:`User Guide `.", - "docstring": "\n A random forest regressor.\n\n A random forest is a meta estimator that fits a number of classifying\n decision trees on various sub-samples of the dataset and uses averaging\n to improve the predictive accuracy and control over-fitting.\n The sub-sample size is controlled with the `max_samples` parameter if\n `bootstrap=True` (default), otherwise the whole dataset is used to build\n each tree.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_estimators : int, default=100\n The number of trees in the forest.\n\n .. versionchanged:: 0.22\n The default value of ``n_estimators`` changed from 10 to 100\n in 0.22.\n\n criterion : {\"squared_error\", \"mse\", \"absolute_error\", \"poisson\"}, default=\"squared_error\"\n The function to measure the quality of a split. Supported criteria\n are \"squared_error\" for the mean squared error, which is equal to\n variance reduction as feature selection criterion, \"absolute_error\"\n for the mean absolute error, and \"poisson\" which uses reduction in\n Poisson deviance to find splits.\n Training using \"absolute_error\" is significantly slower\n than when using \"squared_error\".\n\n .. versionadded:: 0.18\n Mean Absolute Error (MAE) criterion.\n\n .. versionadded:: 1.0\n Poisson criterion.\n\n .. deprecated:: 1.0\n Criterion \"mse\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"squared_error\"` which is equivalent.\n\n .. deprecated:: 1.0\n Criterion \"mae\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"absolute_error\"` which is equivalent.\n\n max_depth : int, default=None\n The maximum depth of the tree. If None, then nodes are expanded until\n all leaves are pure or until all leaves contain less than\n min_samples_split samples.\n\n min_samples_split : int or float, default=2\n The minimum number of samples required to split an internal node:\n\n - If int, then consider `min_samples_split` as the minimum number.\n - If float, then `min_samples_split` is a fraction and\n `ceil(min_samples_split * n_samples)` are the minimum\n number of samples for each split.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_samples_leaf : int or float, default=1\n The minimum number of samples required to be at a leaf node.\n A split point at any depth will only be considered if it leaves at\n least ``min_samples_leaf`` training samples in each of the left and\n right branches. This may have the effect of smoothing the model,\n especially in regression.\n\n - If int, then consider `min_samples_leaf` as the minimum number.\n - If float, then `min_samples_leaf` is a fraction and\n `ceil(min_samples_leaf * n_samples)` are the minimum\n number of samples for each node.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_weight_fraction_leaf : float, default=0.0\n The minimum weighted fraction of the sum total of weights (of all\n the input samples) required to be at a leaf node. Samples have\n equal weight when sample_weight is not provided.\n\n max_features : {\"auto\", \"sqrt\", \"log2\"}, int or float, default=\"auto\"\n The number of features to consider when looking for the best split:\n\n - If int, then consider `max_features` features at each split.\n - If float, then `max_features` is a fraction and\n `round(max_features * n_features)` features are considered at each\n split.\n - If \"auto\", then `max_features=n_features`.\n - If \"sqrt\", then `max_features=sqrt(n_features)`.\n - If \"log2\", then `max_features=log2(n_features)`.\n - If None, then `max_features=n_features`.\n\n Note: the search for a split does not stop until at least one\n valid partition of the node samples is found, even if it requires to\n effectively inspect more than ``max_features`` features.\n\n max_leaf_nodes : int, default=None\n Grow trees with ``max_leaf_nodes`` in best-first fashion.\n Best nodes are defined as relative reduction in impurity.\n If None then unlimited number of leaf nodes.\n\n min_impurity_decrease : float, default=0.0\n A node will be split if this split induces a decrease of the impurity\n greater than or equal to this value.\n\n The weighted impurity decrease equation is the following::\n\n N_t / N * (impurity - N_t_R / N_t * right_impurity\n - N_t_L / N_t * left_impurity)\n\n where ``N`` is the total number of samples, ``N_t`` is the number of\n samples at the current node, ``N_t_L`` is the number of samples in the\n left child, and ``N_t_R`` is the number of samples in the right child.\n\n ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n if ``sample_weight`` is passed.\n\n .. versionadded:: 0.19\n\n bootstrap : bool, default=True\n Whether bootstrap samples are used when building trees. If False, the\n whole dataset is used to build each tree.\n\n oob_score : bool, default=False\n Whether to use out-of-bag samples to estimate the generalization score.\n Only available if bootstrap=True.\n\n n_jobs : int, default=None\n The number of jobs to run in parallel. :meth:`fit`, :meth:`predict`,\n :meth:`decision_path` and :meth:`apply` are all parallelized over the\n trees. ``None`` means 1 unless in a :obj:`joblib.parallel_backend`\n context. ``-1`` means using all processors. See :term:`Glossary\n ` for more details.\n\n random_state : int, RandomState instance or None, default=None\n Controls both the randomness of the bootstrapping of the samples used\n when building trees (if ``bootstrap=True``) and the sampling of the\n features to consider when looking for the best split at each node\n (if ``max_features < n_features``).\n See :term:`Glossary ` for details.\n\n verbose : int, default=0\n Controls the verbosity when fitting and predicting.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit\n and add more estimators to the ensemble, otherwise, just fit a whole\n new forest. See :term:`the Glossary `.\n\n ccp_alpha : non-negative float, default=0.0\n Complexity parameter used for Minimal Cost-Complexity Pruning. The\n subtree with the largest cost complexity that is smaller than\n ``ccp_alpha`` will be chosen. By default, no pruning is performed. See\n :ref:`minimal_cost_complexity_pruning` for details.\n\n .. versionadded:: 0.22\n\n max_samples : int or float, default=None\n If bootstrap is True, the number of samples to draw from X\n to train each base estimator.\n\n - If None (default), then draw `X.shape[0]` samples.\n - If int, then draw `max_samples` samples.\n - If float, then draw `max_samples * X.shape[0]` samples. Thus,\n `max_samples` should be in the interval `(0.0, 1.0]`.\n\n .. versionadded:: 0.22\n\n Attributes\n ----------\n base_estimator_ : DecisionTreeRegressor\n The child estimator template used to create the collection of fitted\n sub-estimators.\n\n estimators_ : list of DecisionTreeRegressor\n The collection of fitted sub-estimators.\n\n feature_importances_ : ndarray of shape (n_features,)\n The impurity-based feature importances.\n The higher, the more important the feature.\n The importance of a feature is computed as the (normalized)\n total reduction of the criterion brought by that feature. It is also\n known as the Gini importance.\n\n Warning: impurity-based feature importances can be misleading for\n high cardinality features (many unique values). See\n :func:`sklearn.inspection.permutation_importance` as an alternative.\n\n n_features_ : int\n The number of features when ``fit`` is performed.\n\n .. deprecated:: 1.0\n Attribute `n_features_` was deprecated in version 1.0 and will be\n removed in 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n .. versionadded:: 1.0\n\n n_outputs_ : int\n The number of outputs when ``fit`` is performed.\n\n oob_score_ : float\n Score of the training dataset obtained using an out-of-bag estimate.\n This attribute exists only when ``oob_score`` is True.\n\n oob_prediction_ : ndarray of shape (n_samples,) or (n_samples, n_outputs)\n Prediction computed with out-of-bag estimate on the training set.\n This attribute exists only when ``oob_score`` is True.\n\n See Also\n --------\n sklearn.tree.DecisionTreeRegressor : A decision tree regressor.\n sklearn.ensemble.ExtraTreesRegressor : Ensemble of extremely randomized\n tree regressors.\n\n Notes\n -----\n The default values for the parameters controlling the size of the trees\n (e.g. ``max_depth``, ``min_samples_leaf``, etc.) lead to fully grown and\n unpruned trees which can potentially be very large on some data sets. To\n reduce memory consumption, the complexity and size of the trees should be\n controlled by setting those parameter values.\n\n The features are always randomly permuted at each split. Therefore,\n the best found split may vary, even with the same training data,\n ``max_features=n_features`` and ``bootstrap=False``, if the improvement\n of the criterion is identical for several splits enumerated during the\n search of the best split. To obtain a deterministic behaviour during\n fitting, ``random_state`` has to be fixed.\n\n The default value ``max_features=\"auto\"`` uses ``n_features``\n rather than ``n_features / 3``. The latter was originally suggested in\n [1], whereas the former was more recently justified empirically in [2].\n\n References\n ----------\n .. [1] L. Breiman, \"Random Forests\", Machine Learning, 45(1), 5-32, 2001.\n\n .. [2] P. Geurts, D. Ernst., and L. Wehenkel, \"Extremely randomized\n trees\", Machine Learning, 63(1), 3-42, 2006.\n\n Examples\n --------\n >>> from sklearn.ensemble import RandomForestRegressor\n >>> from sklearn.datasets import make_regression\n >>> X, y = make_regression(n_features=4, n_informative=2,\n ... random_state=0, shuffle=False)\n >>> regr = RandomForestRegressor(max_depth=2, random_state=0)\n >>> regr.fit(X, y)\n RandomForestRegressor(...)\n >>> print(regr.predict([[0, 0, 0, 0]]))\n [-8.32987858]\n ", - "source_code": "\n\nclass RandomForestRegressor(ForestRegressor):\n \"\"\"\n A random forest regressor.\n\n A random forest is a meta estimator that fits a number of classifying\n decision trees on various sub-samples of the dataset and uses averaging\n to improve the predictive accuracy and control over-fitting.\n The sub-sample size is controlled with the `max_samples` parameter if\n `bootstrap=True` (default), otherwise the whole dataset is used to build\n each tree.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_estimators : int, default=100\n The number of trees in the forest.\n\n .. versionchanged:: 0.22\n The default value of ``n_estimators`` changed from 10 to 100\n in 0.22.\n\n criterion : {\"squared_error\", \"mse\", \"absolute_error\", \"poisson\"}, default=\"squared_error\"\n The function to measure the quality of a split. Supported criteria\n are \"squared_error\" for the mean squared error, which is equal to\n variance reduction as feature selection criterion, \"absolute_error\"\n for the mean absolute error, and \"poisson\" which uses reduction in\n Poisson deviance to find splits.\n Training using \"absolute_error\" is significantly slower\n than when using \"squared_error\".\n\n .. versionadded:: 0.18\n Mean Absolute Error (MAE) criterion.\n\n .. versionadded:: 1.0\n Poisson criterion.\n\n .. deprecated:: 1.0\n Criterion \"mse\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"squared_error\"` which is equivalent.\n\n .. deprecated:: 1.0\n Criterion \"mae\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"absolute_error\"` which is equivalent.\n\n max_depth : int, default=None\n The maximum depth of the tree. If None, then nodes are expanded until\n all leaves are pure or until all leaves contain less than\n min_samples_split samples.\n\n min_samples_split : int or float, default=2\n The minimum number of samples required to split an internal node:\n\n - If int, then consider `min_samples_split` as the minimum number.\n - If float, then `min_samples_split` is a fraction and\n `ceil(min_samples_split * n_samples)` are the minimum\n number of samples for each split.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_samples_leaf : int or float, default=1\n The minimum number of samples required to be at a leaf node.\n A split point at any depth will only be considered if it leaves at\n least ``min_samples_leaf`` training samples in each of the left and\n right branches. This may have the effect of smoothing the model,\n especially in regression.\n\n - If int, then consider `min_samples_leaf` as the minimum number.\n - If float, then `min_samples_leaf` is a fraction and\n `ceil(min_samples_leaf * n_samples)` are the minimum\n number of samples for each node.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_weight_fraction_leaf : float, default=0.0\n The minimum weighted fraction of the sum total of weights (of all\n the input samples) required to be at a leaf node. Samples have\n equal weight when sample_weight is not provided.\n\n max_features : {\"auto\", \"sqrt\", \"log2\"}, int or float, default=\"auto\"\n The number of features to consider when looking for the best split:\n\n - If int, then consider `max_features` features at each split.\n - If float, then `max_features` is a fraction and\n `round(max_features * n_features)` features are considered at each\n split.\n - If \"auto\", then `max_features=n_features`.\n - If \"sqrt\", then `max_features=sqrt(n_features)`.\n - If \"log2\", then `max_features=log2(n_features)`.\n - If None, then `max_features=n_features`.\n\n Note: the search for a split does not stop until at least one\n valid partition of the node samples is found, even if it requires to\n effectively inspect more than ``max_features`` features.\n\n max_leaf_nodes : int, default=None\n Grow trees with ``max_leaf_nodes`` in best-first fashion.\n Best nodes are defined as relative reduction in impurity.\n If None then unlimited number of leaf nodes.\n\n min_impurity_decrease : float, default=0.0\n A node will be split if this split induces a decrease of the impurity\n greater than or equal to this value.\n\n The weighted impurity decrease equation is the following::\n\n N_t / N * (impurity - N_t_R / N_t * right_impurity\n - N_t_L / N_t * left_impurity)\n\n where ``N`` is the total number of samples, ``N_t`` is the number of\n samples at the current node, ``N_t_L`` is the number of samples in the\n left child, and ``N_t_R`` is the number of samples in the right child.\n\n ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n if ``sample_weight`` is passed.\n\n .. versionadded:: 0.19\n\n bootstrap : bool, default=True\n Whether bootstrap samples are used when building trees. If False, the\n whole dataset is used to build each tree.\n\n oob_score : bool, default=False\n Whether to use out-of-bag samples to estimate the generalization score.\n Only available if bootstrap=True.\n\n n_jobs : int, default=None\n The number of jobs to run in parallel. :meth:`fit`, :meth:`predict`,\n :meth:`decision_path` and :meth:`apply` are all parallelized over the\n trees. ``None`` means 1 unless in a :obj:`joblib.parallel_backend`\n context. ``-1`` means using all processors. See :term:`Glossary\n ` for more details.\n\n random_state : int, RandomState instance or None, default=None\n Controls both the randomness of the bootstrapping of the samples used\n when building trees (if ``bootstrap=True``) and the sampling of the\n features to consider when looking for the best split at each node\n (if ``max_features < n_features``).\n See :term:`Glossary ` for details.\n\n verbose : int, default=0\n Controls the verbosity when fitting and predicting.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit\n and add more estimators to the ensemble, otherwise, just fit a whole\n new forest. See :term:`the Glossary `.\n\n ccp_alpha : non-negative float, default=0.0\n Complexity parameter used for Minimal Cost-Complexity Pruning. The\n subtree with the largest cost complexity that is smaller than\n ``ccp_alpha`` will be chosen. By default, no pruning is performed. See\n :ref:`minimal_cost_complexity_pruning` for details.\n\n .. versionadded:: 0.22\n\n max_samples : int or float, default=None\n If bootstrap is True, the number of samples to draw from X\n to train each base estimator.\n\n - If None (default), then draw `X.shape[0]` samples.\n - If int, then draw `max_samples` samples.\n - If float, then draw `max_samples * X.shape[0]` samples. Thus,\n `max_samples` should be in the interval `(0.0, 1.0]`.\n\n .. versionadded:: 0.22\n\n Attributes\n ----------\n base_estimator_ : DecisionTreeRegressor\n The child estimator template used to create the collection of fitted\n sub-estimators.\n\n estimators_ : list of DecisionTreeRegressor\n The collection of fitted sub-estimators.\n\n feature_importances_ : ndarray of shape (n_features,)\n The impurity-based feature importances.\n The higher, the more important the feature.\n The importance of a feature is computed as the (normalized)\n total reduction of the criterion brought by that feature. It is also\n known as the Gini importance.\n\n Warning: impurity-based feature importances can be misleading for\n high cardinality features (many unique values). See\n :func:`sklearn.inspection.permutation_importance` as an alternative.\n\n n_features_ : int\n The number of features when ``fit`` is performed.\n\n .. deprecated:: 1.0\n Attribute `n_features_` was deprecated in version 1.0 and will be\n removed in 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n .. versionadded:: 1.0\n\n n_outputs_ : int\n The number of outputs when ``fit`` is performed.\n\n oob_score_ : float\n Score of the training dataset obtained using an out-of-bag estimate.\n This attribute exists only when ``oob_score`` is True.\n\n oob_prediction_ : ndarray of shape (n_samples,) or (n_samples, n_outputs)\n Prediction computed with out-of-bag estimate on the training set.\n This attribute exists only when ``oob_score`` is True.\n\n See Also\n --------\n sklearn.tree.DecisionTreeRegressor : A decision tree regressor.\n sklearn.ensemble.ExtraTreesRegressor : Ensemble of extremely randomized\n tree regressors.\n\n Notes\n -----\n The default values for the parameters controlling the size of the trees\n (e.g. ``max_depth``, ``min_samples_leaf``, etc.) lead to fully grown and\n unpruned trees which can potentially be very large on some data sets. To\n reduce memory consumption, the complexity and size of the trees should be\n controlled by setting those parameter values.\n\n The features are always randomly permuted at each split. Therefore,\n the best found split may vary, even with the same training data,\n ``max_features=n_features`` and ``bootstrap=False``, if the improvement\n of the criterion is identical for several splits enumerated during the\n search of the best split. To obtain a deterministic behaviour during\n fitting, ``random_state`` has to be fixed.\n\n The default value ``max_features=\"auto\"`` uses ``n_features``\n rather than ``n_features / 3``. The latter was originally suggested in\n [1], whereas the former was more recently justified empirically in [2].\n\n References\n ----------\n .. [1] L. Breiman, \"Random Forests\", Machine Learning, 45(1), 5-32, 2001.\n\n .. [2] P. Geurts, D. Ernst., and L. Wehenkel, \"Extremely randomized\n trees\", Machine Learning, 63(1), 3-42, 2006.\n\n Examples\n --------\n >>> from sklearn.ensemble import RandomForestRegressor\n >>> from sklearn.datasets import make_regression\n >>> X, y = make_regression(n_features=4, n_informative=2,\n ... random_state=0, shuffle=False)\n >>> regr = RandomForestRegressor(max_depth=2, random_state=0)\n >>> regr.fit(X, y)\n RandomForestRegressor(...)\n >>> print(regr.predict([[0, 0, 0, 0]]))\n [-8.32987858]\n \"\"\"\n \n def __init__(self, n_estimators=100, *, criterion='squared_error', max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features='auto', max_leaf_nodes=None, min_impurity_decrease=0.0, bootstrap=True, oob_score=False, n_jobs=None, random_state=None, verbose=0, warm_start=False, ccp_alpha=0.0, max_samples=None):\n super().__init__(base_estimator=DecisionTreeRegressor(), n_estimators=n_estimators, estimator_params=('criterion', 'max_depth', 'min_samples_split', 'min_samples_leaf', 'min_weight_fraction_leaf', 'max_features', 'max_leaf_nodes', 'min_impurity_decrease', 'random_state', 'ccp_alpha'), bootstrap=bootstrap, oob_score=oob_score, n_jobs=n_jobs, random_state=random_state, verbose=verbose, warm_start=warm_start, max_samples=max_samples)\n self.criterion = criterion\n self.max_depth = max_depth\n self.min_samples_split = min_samples_split\n self.min_samples_leaf = min_samples_leaf\n self.min_weight_fraction_leaf = min_weight_fraction_leaf\n self.max_features = max_features\n self.max_leaf_nodes = max_leaf_nodes\n self.min_impurity_decrease = min_impurity_decrease\n self.ccp_alpha = ccp_alpha\n" + "docstring": "\n A random forest regressor.\n\n A random forest is a meta estimator that fits a number of classifying\n decision trees on various sub-samples of the dataset and uses averaging\n to improve the predictive accuracy and control over-fitting.\n The sub-sample size is controlled with the `max_samples` parameter if\n `bootstrap=True` (default), otherwise the whole dataset is used to build\n each tree.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_estimators : int, default=100\n The number of trees in the forest.\n\n .. versionchanged:: 0.22\n The default value of ``n_estimators`` changed from 10 to 100\n in 0.22.\n\n criterion : {\"squared_error\", \"absolute_error\", \"poisson\"}, default=\"squared_error\"\n The function to measure the quality of a split. Supported criteria\n are \"squared_error\" for the mean squared error, which is equal to\n variance reduction as feature selection criterion, \"absolute_error\"\n for the mean absolute error, and \"poisson\" which uses reduction in\n Poisson deviance to find splits.\n Training using \"absolute_error\" is significantly slower\n than when using \"squared_error\".\n\n .. versionadded:: 0.18\n Mean Absolute Error (MAE) criterion.\n\n .. versionadded:: 1.0\n Poisson criterion.\n\n .. deprecated:: 1.0\n Criterion \"mse\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"squared_error\"` which is equivalent.\n\n .. deprecated:: 1.0\n Criterion \"mae\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"absolute_error\"` which is equivalent.\n\n max_depth : int, default=None\n The maximum depth of the tree. If None, then nodes are expanded until\n all leaves are pure or until all leaves contain less than\n min_samples_split samples.\n\n min_samples_split : int or float, default=2\n The minimum number of samples required to split an internal node:\n\n - If int, then consider `min_samples_split` as the minimum number.\n - If float, then `min_samples_split` is a fraction and\n `ceil(min_samples_split * n_samples)` are the minimum\n number of samples for each split.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_samples_leaf : int or float, default=1\n The minimum number of samples required to be at a leaf node.\n A split point at any depth will only be considered if it leaves at\n least ``min_samples_leaf`` training samples in each of the left and\n right branches. This may have the effect of smoothing the model,\n especially in regression.\n\n - If int, then consider `min_samples_leaf` as the minimum number.\n - If float, then `min_samples_leaf` is a fraction and\n `ceil(min_samples_leaf * n_samples)` are the minimum\n number of samples for each node.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_weight_fraction_leaf : float, default=0.0\n The minimum weighted fraction of the sum total of weights (of all\n the input samples) required to be at a leaf node. Samples have\n equal weight when sample_weight is not provided.\n\n max_features : {\"auto\", \"sqrt\", \"log2\"}, int or float, default=\"auto\"\n The number of features to consider when looking for the best split:\n\n - If int, then consider `max_features` features at each split.\n - If float, then `max_features` is a fraction and\n `round(max_features * n_features)` features are considered at each\n split.\n - If \"auto\", then `max_features=n_features`.\n - If \"sqrt\", then `max_features=sqrt(n_features)`.\n - If \"log2\", then `max_features=log2(n_features)`.\n - If None, then `max_features=n_features`.\n\n Note: the search for a split does not stop until at least one\n valid partition of the node samples is found, even if it requires to\n effectively inspect more than ``max_features`` features.\n\n max_leaf_nodes : int, default=None\n Grow trees with ``max_leaf_nodes`` in best-first fashion.\n Best nodes are defined as relative reduction in impurity.\n If None then unlimited number of leaf nodes.\n\n min_impurity_decrease : float, default=0.0\n A node will be split if this split induces a decrease of the impurity\n greater than or equal to this value.\n\n The weighted impurity decrease equation is the following::\n\n N_t / N * (impurity - N_t_R / N_t * right_impurity\n - N_t_L / N_t * left_impurity)\n\n where ``N`` is the total number of samples, ``N_t`` is the number of\n samples at the current node, ``N_t_L`` is the number of samples in the\n left child, and ``N_t_R`` is the number of samples in the right child.\n\n ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n if ``sample_weight`` is passed.\n\n .. versionadded:: 0.19\n\n bootstrap : bool, default=True\n Whether bootstrap samples are used when building trees. If False, the\n whole dataset is used to build each tree.\n\n oob_score : bool, default=False\n Whether to use out-of-bag samples to estimate the generalization score.\n Only available if bootstrap=True.\n\n n_jobs : int, default=None\n The number of jobs to run in parallel. :meth:`fit`, :meth:`predict`,\n :meth:`decision_path` and :meth:`apply` are all parallelized over the\n trees. ``None`` means 1 unless in a :obj:`joblib.parallel_backend`\n context. ``-1`` means using all processors. See :term:`Glossary\n ` for more details.\n\n random_state : int, RandomState instance or None, default=None\n Controls both the randomness of the bootstrapping of the samples used\n when building trees (if ``bootstrap=True``) and the sampling of the\n features to consider when looking for the best split at each node\n (if ``max_features < n_features``).\n See :term:`Glossary ` for details.\n\n verbose : int, default=0\n Controls the verbosity when fitting and predicting.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit\n and add more estimators to the ensemble, otherwise, just fit a whole\n new forest. See :term:`the Glossary `.\n\n ccp_alpha : non-negative float, default=0.0\n Complexity parameter used for Minimal Cost-Complexity Pruning. The\n subtree with the largest cost complexity that is smaller than\n ``ccp_alpha`` will be chosen. By default, no pruning is performed. See\n :ref:`minimal_cost_complexity_pruning` for details.\n\n .. versionadded:: 0.22\n\n max_samples : int or float, default=None\n If bootstrap is True, the number of samples to draw from X\n to train each base estimator.\n\n - If None (default), then draw `X.shape[0]` samples.\n - If int, then draw `max_samples` samples.\n - If float, then draw `max_samples * X.shape[0]` samples. Thus,\n `max_samples` should be in the interval `(0.0, 1.0]`.\n\n .. versionadded:: 0.22\n\n Attributes\n ----------\n base_estimator_ : DecisionTreeRegressor\n The child estimator template used to create the collection of fitted\n sub-estimators.\n\n estimators_ : list of DecisionTreeRegressor\n The collection of fitted sub-estimators.\n\n feature_importances_ : ndarray of shape (n_features,)\n The impurity-based feature importances.\n The higher, the more important the feature.\n The importance of a feature is computed as the (normalized)\n total reduction of the criterion brought by that feature. It is also\n known as the Gini importance.\n\n Warning: impurity-based feature importances can be misleading for\n high cardinality features (many unique values). See\n :func:`sklearn.inspection.permutation_importance` as an alternative.\n\n n_features_ : int\n The number of features when ``fit`` is performed.\n\n .. deprecated:: 1.0\n Attribute `n_features_` was deprecated in version 1.0 and will be\n removed in 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n .. versionadded:: 1.0\n\n n_outputs_ : int\n The number of outputs when ``fit`` is performed.\n\n oob_score_ : float\n Score of the training dataset obtained using an out-of-bag estimate.\n This attribute exists only when ``oob_score`` is True.\n\n oob_prediction_ : ndarray of shape (n_samples,) or (n_samples, n_outputs)\n Prediction computed with out-of-bag estimate on the training set.\n This attribute exists only when ``oob_score`` is True.\n\n See Also\n --------\n sklearn.tree.DecisionTreeRegressor : A decision tree regressor.\n sklearn.ensemble.ExtraTreesRegressor : Ensemble of extremely randomized\n tree regressors.\n\n Notes\n -----\n The default values for the parameters controlling the size of the trees\n (e.g. ``max_depth``, ``min_samples_leaf``, etc.) lead to fully grown and\n unpruned trees which can potentially be very large on some data sets. To\n reduce memory consumption, the complexity and size of the trees should be\n controlled by setting those parameter values.\n\n The features are always randomly permuted at each split. Therefore,\n the best found split may vary, even with the same training data,\n ``max_features=n_features`` and ``bootstrap=False``, if the improvement\n of the criterion is identical for several splits enumerated during the\n search of the best split. To obtain a deterministic behaviour during\n fitting, ``random_state`` has to be fixed.\n\n The default value ``max_features=\"auto\"`` uses ``n_features``\n rather than ``n_features / 3``. The latter was originally suggested in\n [1], whereas the former was more recently justified empirically in [2].\n\n References\n ----------\n .. [1] L. Breiman, \"Random Forests\", Machine Learning, 45(1), 5-32, 2001.\n\n .. [2] P. Geurts, D. Ernst., and L. Wehenkel, \"Extremely randomized\n trees\", Machine Learning, 63(1), 3-42, 2006.\n\n Examples\n --------\n >>> from sklearn.ensemble import RandomForestRegressor\n >>> from sklearn.datasets import make_regression\n >>> X, y = make_regression(n_features=4, n_informative=2,\n ... random_state=0, shuffle=False)\n >>> regr = RandomForestRegressor(max_depth=2, random_state=0)\n >>> regr.fit(X, y)\n RandomForestRegressor(...)\n >>> print(regr.predict([[0, 0, 0, 0]]))\n [-8.32987858]\n ", + "source_code": "\n\nclass RandomForestRegressor(ForestRegressor):\n \"\"\"\n A random forest regressor.\n\n A random forest is a meta estimator that fits a number of classifying\n decision trees on various sub-samples of the dataset and uses averaging\n to improve the predictive accuracy and control over-fitting.\n The sub-sample size is controlled with the `max_samples` parameter if\n `bootstrap=True` (default), otherwise the whole dataset is used to build\n each tree.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_estimators : int, default=100\n The number of trees in the forest.\n\n .. versionchanged:: 0.22\n The default value of ``n_estimators`` changed from 10 to 100\n in 0.22.\n\n criterion : {\"squared_error\", \"absolute_error\", \"poisson\"}, default=\"squared_error\"\n The function to measure the quality of a split. Supported criteria\n are \"squared_error\" for the mean squared error, which is equal to\n variance reduction as feature selection criterion, \"absolute_error\"\n for the mean absolute error, and \"poisson\" which uses reduction in\n Poisson deviance to find splits.\n Training using \"absolute_error\" is significantly slower\n than when using \"squared_error\".\n\n .. versionadded:: 0.18\n Mean Absolute Error (MAE) criterion.\n\n .. versionadded:: 1.0\n Poisson criterion.\n\n .. deprecated:: 1.0\n Criterion \"mse\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"squared_error\"` which is equivalent.\n\n .. deprecated:: 1.0\n Criterion \"mae\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"absolute_error\"` which is equivalent.\n\n max_depth : int, default=None\n The maximum depth of the tree. If None, then nodes are expanded until\n all leaves are pure or until all leaves contain less than\n min_samples_split samples.\n\n min_samples_split : int or float, default=2\n The minimum number of samples required to split an internal node:\n\n - If int, then consider `min_samples_split` as the minimum number.\n - If float, then `min_samples_split` is a fraction and\n `ceil(min_samples_split * n_samples)` are the minimum\n number of samples for each split.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_samples_leaf : int or float, default=1\n The minimum number of samples required to be at a leaf node.\n A split point at any depth will only be considered if it leaves at\n least ``min_samples_leaf`` training samples in each of the left and\n right branches. This may have the effect of smoothing the model,\n especially in regression.\n\n - If int, then consider `min_samples_leaf` as the minimum number.\n - If float, then `min_samples_leaf` is a fraction and\n `ceil(min_samples_leaf * n_samples)` are the minimum\n number of samples for each node.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_weight_fraction_leaf : float, default=0.0\n The minimum weighted fraction of the sum total of weights (of all\n the input samples) required to be at a leaf node. Samples have\n equal weight when sample_weight is not provided.\n\n max_features : {\"auto\", \"sqrt\", \"log2\"}, int or float, default=\"auto\"\n The number of features to consider when looking for the best split:\n\n - If int, then consider `max_features` features at each split.\n - If float, then `max_features` is a fraction and\n `round(max_features * n_features)` features are considered at each\n split.\n - If \"auto\", then `max_features=n_features`.\n - If \"sqrt\", then `max_features=sqrt(n_features)`.\n - If \"log2\", then `max_features=log2(n_features)`.\n - If None, then `max_features=n_features`.\n\n Note: the search for a split does not stop until at least one\n valid partition of the node samples is found, even if it requires to\n effectively inspect more than ``max_features`` features.\n\n max_leaf_nodes : int, default=None\n Grow trees with ``max_leaf_nodes`` in best-first fashion.\n Best nodes are defined as relative reduction in impurity.\n If None then unlimited number of leaf nodes.\n\n min_impurity_decrease : float, default=0.0\n A node will be split if this split induces a decrease of the impurity\n greater than or equal to this value.\n\n The weighted impurity decrease equation is the following::\n\n N_t / N * (impurity - N_t_R / N_t * right_impurity\n - N_t_L / N_t * left_impurity)\n\n where ``N`` is the total number of samples, ``N_t`` is the number of\n samples at the current node, ``N_t_L`` is the number of samples in the\n left child, and ``N_t_R`` is the number of samples in the right child.\n\n ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n if ``sample_weight`` is passed.\n\n .. versionadded:: 0.19\n\n bootstrap : bool, default=True\n Whether bootstrap samples are used when building trees. If False, the\n whole dataset is used to build each tree.\n\n oob_score : bool, default=False\n Whether to use out-of-bag samples to estimate the generalization score.\n Only available if bootstrap=True.\n\n n_jobs : int, default=None\n The number of jobs to run in parallel. :meth:`fit`, :meth:`predict`,\n :meth:`decision_path` and :meth:`apply` are all parallelized over the\n trees. ``None`` means 1 unless in a :obj:`joblib.parallel_backend`\n context. ``-1`` means using all processors. See :term:`Glossary\n ` for more details.\n\n random_state : int, RandomState instance or None, default=None\n Controls both the randomness of the bootstrapping of the samples used\n when building trees (if ``bootstrap=True``) and the sampling of the\n features to consider when looking for the best split at each node\n (if ``max_features < n_features``).\n See :term:`Glossary ` for details.\n\n verbose : int, default=0\n Controls the verbosity when fitting and predicting.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit\n and add more estimators to the ensemble, otherwise, just fit a whole\n new forest. See :term:`the Glossary `.\n\n ccp_alpha : non-negative float, default=0.0\n Complexity parameter used for Minimal Cost-Complexity Pruning. The\n subtree with the largest cost complexity that is smaller than\n ``ccp_alpha`` will be chosen. By default, no pruning is performed. See\n :ref:`minimal_cost_complexity_pruning` for details.\n\n .. versionadded:: 0.22\n\n max_samples : int or float, default=None\n If bootstrap is True, the number of samples to draw from X\n to train each base estimator.\n\n - If None (default), then draw `X.shape[0]` samples.\n - If int, then draw `max_samples` samples.\n - If float, then draw `max_samples * X.shape[0]` samples. Thus,\n `max_samples` should be in the interval `(0.0, 1.0]`.\n\n .. versionadded:: 0.22\n\n Attributes\n ----------\n base_estimator_ : DecisionTreeRegressor\n The child estimator template used to create the collection of fitted\n sub-estimators.\n\n estimators_ : list of DecisionTreeRegressor\n The collection of fitted sub-estimators.\n\n feature_importances_ : ndarray of shape (n_features,)\n The impurity-based feature importances.\n The higher, the more important the feature.\n The importance of a feature is computed as the (normalized)\n total reduction of the criterion brought by that feature. It is also\n known as the Gini importance.\n\n Warning: impurity-based feature importances can be misleading for\n high cardinality features (many unique values). See\n :func:`sklearn.inspection.permutation_importance` as an alternative.\n\n n_features_ : int\n The number of features when ``fit`` is performed.\n\n .. deprecated:: 1.0\n Attribute `n_features_` was deprecated in version 1.0 and will be\n removed in 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n .. versionadded:: 1.0\n\n n_outputs_ : int\n The number of outputs when ``fit`` is performed.\n\n oob_score_ : float\n Score of the training dataset obtained using an out-of-bag estimate.\n This attribute exists only when ``oob_score`` is True.\n\n oob_prediction_ : ndarray of shape (n_samples,) or (n_samples, n_outputs)\n Prediction computed with out-of-bag estimate on the training set.\n This attribute exists only when ``oob_score`` is True.\n\n See Also\n --------\n sklearn.tree.DecisionTreeRegressor : A decision tree regressor.\n sklearn.ensemble.ExtraTreesRegressor : Ensemble of extremely randomized\n tree regressors.\n\n Notes\n -----\n The default values for the parameters controlling the size of the trees\n (e.g. ``max_depth``, ``min_samples_leaf``, etc.) lead to fully grown and\n unpruned trees which can potentially be very large on some data sets. To\n reduce memory consumption, the complexity and size of the trees should be\n controlled by setting those parameter values.\n\n The features are always randomly permuted at each split. Therefore,\n the best found split may vary, even with the same training data,\n ``max_features=n_features`` and ``bootstrap=False``, if the improvement\n of the criterion is identical for several splits enumerated during the\n search of the best split. To obtain a deterministic behaviour during\n fitting, ``random_state`` has to be fixed.\n\n The default value ``max_features=\"auto\"`` uses ``n_features``\n rather than ``n_features / 3``. The latter was originally suggested in\n [1], whereas the former was more recently justified empirically in [2].\n\n References\n ----------\n .. [1] L. Breiman, \"Random Forests\", Machine Learning, 45(1), 5-32, 2001.\n\n .. [2] P. Geurts, D. Ernst., and L. Wehenkel, \"Extremely randomized\n trees\", Machine Learning, 63(1), 3-42, 2006.\n\n Examples\n --------\n >>> from sklearn.ensemble import RandomForestRegressor\n >>> from sklearn.datasets import make_regression\n >>> X, y = make_regression(n_features=4, n_informative=2,\n ... random_state=0, shuffle=False)\n >>> regr = RandomForestRegressor(max_depth=2, random_state=0)\n >>> regr.fit(X, y)\n RandomForestRegressor(...)\n >>> print(regr.predict([[0, 0, 0, 0]]))\n [-8.32987858]\n \"\"\"\n \n def __init__(self, n_estimators=100, *, criterion='squared_error', max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features='auto', max_leaf_nodes=None, min_impurity_decrease=0.0, bootstrap=True, oob_score=False, n_jobs=None, random_state=None, verbose=0, warm_start=False, ccp_alpha=0.0, max_samples=None):\n super().__init__(base_estimator=DecisionTreeRegressor(), n_estimators=n_estimators, estimator_params=('criterion', 'max_depth', 'min_samples_split', 'min_samples_leaf', 'min_weight_fraction_leaf', 'max_features', 'max_leaf_nodes', 'min_impurity_decrease', 'random_state', 'ccp_alpha'), bootstrap=bootstrap, oob_score=oob_score, n_jobs=n_jobs, random_state=random_state, verbose=verbose, warm_start=warm_start, max_samples=max_samples)\n self.criterion = criterion\n self.max_depth = max_depth\n self.min_samples_split = min_samples_split\n self.min_samples_leaf = min_samples_leaf\n self.min_weight_fraction_leaf = min_weight_fraction_leaf\n self.max_features = max_features\n self.max_leaf_nodes = max_leaf_nodes\n self.min_impurity_decrease = min_impurity_decrease\n self.ccp_alpha = ccp_alpha\n" }, { "name": "RandomTreesEmbedding", @@ -21036,8 +21003,8 @@ ], "is_public": true, "description": "An ensemble of totally random trees.\n\nAn unsupervised transformation of a dataset to a high-dimensional sparse representation. A datapoint is coded according to which leaf of each tree it is sorted into. Using a one-hot encoding of the leaves, this leads to a binary coding with as many ones as there are trees in the forest. The dimensionality of the resulting representation is ``n_out <= n_estimators * max_leaf_nodes``. If ``max_leaf_nodes == None``, the number of leaf nodes is at most ``n_estimators * 2 ** max_depth``. Read more in the :ref:`User Guide `.", - "docstring": "\n An ensemble of totally random trees.\n\n An unsupervised transformation of a dataset to a high-dimensional\n sparse representation. A datapoint is coded according to which leaf of\n each tree it is sorted into. Using a one-hot encoding of the leaves,\n this leads to a binary coding with as many ones as there are trees in\n the forest.\n\n The dimensionality of the resulting representation is\n ``n_out <= n_estimators * max_leaf_nodes``. If ``max_leaf_nodes == None``,\n the number of leaf nodes is at most ``n_estimators * 2 ** max_depth``.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_estimators : int, default=100\n Number of trees in the forest.\n\n .. versionchanged:: 0.22\n The default value of ``n_estimators`` changed from 10 to 100\n in 0.22.\n\n max_depth : int, default=5\n The maximum depth of each tree. If None, then nodes are expanded until\n all leaves are pure or until all leaves contain less than\n min_samples_split samples.\n\n min_samples_split : int or float, default=2\n The minimum number of samples required to split an internal node:\n\n - If int, then consider `min_samples_split` as the minimum number.\n - If float, then `min_samples_split` is a fraction and\n `ceil(min_samples_split * n_samples)` is the minimum\n number of samples for each split.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_samples_leaf : int or float, default=1\n The minimum number of samples required to be at a leaf node.\n A split point at any depth will only be considered if it leaves at\n least ``min_samples_leaf`` training samples in each of the left and\n right branches. This may have the effect of smoothing the model,\n especially in regression.\n\n - If int, then consider `min_samples_leaf` as the minimum number.\n - If float, then `min_samples_leaf` is a fraction and\n `ceil(min_samples_leaf * n_samples)` is the minimum\n number of samples for each node.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_weight_fraction_leaf : float, default=0.0\n The minimum weighted fraction of the sum total of weights (of all\n the input samples) required to be at a leaf node. Samples have\n equal weight when sample_weight is not provided.\n\n max_leaf_nodes : int, default=None\n Grow trees with ``max_leaf_nodes`` in best-first fashion.\n Best nodes are defined as relative reduction in impurity.\n If None then unlimited number of leaf nodes.\n\n min_impurity_decrease : float, default=0.0\n A node will be split if this split induces a decrease of the impurity\n greater than or equal to this value.\n\n The weighted impurity decrease equation is the following::\n\n N_t / N * (impurity - N_t_R / N_t * right_impurity\n - N_t_L / N_t * left_impurity)\n\n where ``N`` is the total number of samples, ``N_t`` is the number of\n samples at the current node, ``N_t_L`` is the number of samples in the\n left child, and ``N_t_R`` is the number of samples in the right child.\n\n ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n if ``sample_weight`` is passed.\n\n .. versionadded:: 0.19\n\n sparse_output : bool, default=True\n Whether or not to return a sparse CSR matrix, as default behavior,\n or to return a dense array compatible with dense pipeline operators.\n\n n_jobs : int, default=None\n The number of jobs to run in parallel. :meth:`fit`, :meth:`transform`,\n :meth:`decision_path` and :meth:`apply` are all parallelized over the\n trees. ``None`` means 1 unless in a :obj:`joblib.parallel_backend`\n context. ``-1`` means using all processors. See :term:`Glossary\n ` for more details.\n\n random_state : int, RandomState instance or None, default=None\n Controls the generation of the random `y` used to fit the trees\n and the draw of the splits for each feature at the trees' nodes.\n See :term:`Glossary ` for details.\n\n verbose : int, default=0\n Controls the verbosity when fitting and predicting.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit\n and add more estimators to the ensemble, otherwise, just fit a whole\n new forest. See :term:`the Glossary `.\n\n Attributes\n ----------\n base_estimator_ : DecisionTreeClassifier instance\n The child estimator template used to create the collection of fitted\n sub-estimators.\n\n estimators_ : list of DecisionTreeClassifier instances\n The collection of fitted sub-estimators.\n\n feature_importances_ : ndarray of shape (n_features,)\n The feature importances (the higher, the more important the feature).\n\n n_features_ : int\n The number of features when ``fit`` is performed.\n\n .. deprecated:: 1.0\n Attribute `n_features_` was deprecated in version 1.0 and will be\n removed in 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n .. versionadded:: 1.0\n\n n_outputs_ : int\n The number of outputs when ``fit`` is performed.\n\n one_hot_encoder_ : OneHotEncoder instance\n One-hot encoder used to create the sparse embedding.\n\n See Also\n --------\n ExtraTreesClassifier : An extra-trees classifier.\n ExtraTreesRegressor : An extra-trees regressor.\n RandomForestClassifier : A random forest classifier.\n RandomForestRegressor : A random forest regressor.\n sklearn.tree.ExtraTreeClassifier: An extremely randomized\n tree classifier.\n sklearn.tree.ExtraTreeRegressor : An extremely randomized\n tree regressor.\n\n References\n ----------\n .. [1] P. Geurts, D. Ernst., and L. Wehenkel, \"Extremely randomized trees\",\n Machine Learning, 63(1), 3-42, 2006.\n .. [2] Moosmann, F. and Triggs, B. and Jurie, F. \"Fast discriminative\n visual codebooks using randomized clustering forests\"\n NIPS 2007\n\n Examples\n --------\n >>> from sklearn.ensemble import RandomTreesEmbedding\n >>> X = [[0,0], [1,0], [0,1], [-1,0], [0,-1]]\n >>> random_trees = RandomTreesEmbedding(\n ... n_estimators=5, random_state=0, max_depth=1).fit(X)\n >>> X_sparse_embedding = random_trees.transform(X)\n >>> X_sparse_embedding.toarray()\n array([[0., 1., 1., 0., 1., 0., 0., 1., 1., 0.],\n [0., 1., 1., 0., 1., 0., 0., 1., 1., 0.],\n [0., 1., 0., 1., 0., 1., 0., 1., 0., 1.],\n [1., 0., 1., 0., 1., 0., 1., 0., 1., 0.],\n [0., 1., 1., 0., 1., 0., 0., 1., 1., 0.]])\n ", - "source_code": "\n\nclass RandomTreesEmbedding(BaseForest):\n \"\"\"\n An ensemble of totally random trees.\n\n An unsupervised transformation of a dataset to a high-dimensional\n sparse representation. A datapoint is coded according to which leaf of\n each tree it is sorted into. Using a one-hot encoding of the leaves,\n this leads to a binary coding with as many ones as there are trees in\n the forest.\n\n The dimensionality of the resulting representation is\n ``n_out <= n_estimators * max_leaf_nodes``. If ``max_leaf_nodes == None``,\n the number of leaf nodes is at most ``n_estimators * 2 ** max_depth``.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_estimators : int, default=100\n Number of trees in the forest.\n\n .. versionchanged:: 0.22\n The default value of ``n_estimators`` changed from 10 to 100\n in 0.22.\n\n max_depth : int, default=5\n The maximum depth of each tree. If None, then nodes are expanded until\n all leaves are pure or until all leaves contain less than\n min_samples_split samples.\n\n min_samples_split : int or float, default=2\n The minimum number of samples required to split an internal node:\n\n - If int, then consider `min_samples_split` as the minimum number.\n - If float, then `min_samples_split` is a fraction and\n `ceil(min_samples_split * n_samples)` is the minimum\n number of samples for each split.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_samples_leaf : int or float, default=1\n The minimum number of samples required to be at a leaf node.\n A split point at any depth will only be considered if it leaves at\n least ``min_samples_leaf`` training samples in each of the left and\n right branches. This may have the effect of smoothing the model,\n especially in regression.\n\n - If int, then consider `min_samples_leaf` as the minimum number.\n - If float, then `min_samples_leaf` is a fraction and\n `ceil(min_samples_leaf * n_samples)` is the minimum\n number of samples for each node.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_weight_fraction_leaf : float, default=0.0\n The minimum weighted fraction of the sum total of weights (of all\n the input samples) required to be at a leaf node. Samples have\n equal weight when sample_weight is not provided.\n\n max_leaf_nodes : int, default=None\n Grow trees with ``max_leaf_nodes`` in best-first fashion.\n Best nodes are defined as relative reduction in impurity.\n If None then unlimited number of leaf nodes.\n\n min_impurity_decrease : float, default=0.0\n A node will be split if this split induces a decrease of the impurity\n greater than or equal to this value.\n\n The weighted impurity decrease equation is the following::\n\n N_t / N * (impurity - N_t_R / N_t * right_impurity\n - N_t_L / N_t * left_impurity)\n\n where ``N`` is the total number of samples, ``N_t`` is the number of\n samples at the current node, ``N_t_L`` is the number of samples in the\n left child, and ``N_t_R`` is the number of samples in the right child.\n\n ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n if ``sample_weight`` is passed.\n\n .. versionadded:: 0.19\n\n sparse_output : bool, default=True\n Whether or not to return a sparse CSR matrix, as default behavior,\n or to return a dense array compatible with dense pipeline operators.\n\n n_jobs : int, default=None\n The number of jobs to run in parallel. :meth:`fit`, :meth:`transform`,\n :meth:`decision_path` and :meth:`apply` are all parallelized over the\n trees. ``None`` means 1 unless in a :obj:`joblib.parallel_backend`\n context. ``-1`` means using all processors. See :term:`Glossary\n ` for more details.\n\n random_state : int, RandomState instance or None, default=None\n Controls the generation of the random `y` used to fit the trees\n and the draw of the splits for each feature at the trees' nodes.\n See :term:`Glossary ` for details.\n\n verbose : int, default=0\n Controls the verbosity when fitting and predicting.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit\n and add more estimators to the ensemble, otherwise, just fit a whole\n new forest. See :term:`the Glossary `.\n\n Attributes\n ----------\n base_estimator_ : DecisionTreeClassifier instance\n The child estimator template used to create the collection of fitted\n sub-estimators.\n\n estimators_ : list of DecisionTreeClassifier instances\n The collection of fitted sub-estimators.\n\n feature_importances_ : ndarray of shape (n_features,)\n The feature importances (the higher, the more important the feature).\n\n n_features_ : int\n The number of features when ``fit`` is performed.\n\n .. deprecated:: 1.0\n Attribute `n_features_` was deprecated in version 1.0 and will be\n removed in 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n .. versionadded:: 1.0\n\n n_outputs_ : int\n The number of outputs when ``fit`` is performed.\n\n one_hot_encoder_ : OneHotEncoder instance\n One-hot encoder used to create the sparse embedding.\n\n See Also\n --------\n ExtraTreesClassifier : An extra-trees classifier.\n ExtraTreesRegressor : An extra-trees regressor.\n RandomForestClassifier : A random forest classifier.\n RandomForestRegressor : A random forest regressor.\n sklearn.tree.ExtraTreeClassifier: An extremely randomized\n tree classifier.\n sklearn.tree.ExtraTreeRegressor : An extremely randomized\n tree regressor.\n\n References\n ----------\n .. [1] P. Geurts, D. Ernst., and L. Wehenkel, \"Extremely randomized trees\",\n Machine Learning, 63(1), 3-42, 2006.\n .. [2] Moosmann, F. and Triggs, B. and Jurie, F. \"Fast discriminative\n visual codebooks using randomized clustering forests\"\n NIPS 2007\n\n Examples\n --------\n >>> from sklearn.ensemble import RandomTreesEmbedding\n >>> X = [[0,0], [1,0], [0,1], [-1,0], [0,-1]]\n >>> random_trees = RandomTreesEmbedding(\n ... n_estimators=5, random_state=0, max_depth=1).fit(X)\n >>> X_sparse_embedding = random_trees.transform(X)\n >>> X_sparse_embedding.toarray()\n array([[0., 1., 1., 0., 1., 0., 0., 1., 1., 0.],\n [0., 1., 1., 0., 1., 0., 0., 1., 1., 0.],\n [0., 1., 0., 1., 0., 1., 0., 1., 0., 1.],\n [1., 0., 1., 0., 1., 0., 1., 0., 1., 0.],\n [0., 1., 1., 0., 1., 0., 0., 1., 1., 0.]])\n \"\"\"\n criterion = 'squared_error'\n max_features = 1\n \n def __init__(self, n_estimators=100, *, max_depth=5, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_leaf_nodes=None, min_impurity_decrease=0.0, sparse_output=True, n_jobs=None, random_state=None, verbose=0, warm_start=False):\n super().__init__(base_estimator=ExtraTreeRegressor(), n_estimators=n_estimators, estimator_params=('criterion', 'max_depth', 'min_samples_split', 'min_samples_leaf', 'min_weight_fraction_leaf', 'max_features', 'max_leaf_nodes', 'min_impurity_decrease', 'random_state'), bootstrap=False, oob_score=False, n_jobs=n_jobs, random_state=random_state, verbose=verbose, warm_start=warm_start, max_samples=None)\n self.max_depth = max_depth\n self.min_samples_split = min_samples_split\n self.min_samples_leaf = min_samples_leaf\n self.min_weight_fraction_leaf = min_weight_fraction_leaf\n self.max_leaf_nodes = max_leaf_nodes\n self.min_impurity_decrease = min_impurity_decrease\n self.sparse_output = sparse_output\n \n def _set_oob_score_and_attributes(self, X, y):\n raise NotImplementedError('OOB score not supported by tree embedding')\n \n def fit(self, X, y=None, sample_weight=None):\n \"\"\"\n Fit estimator.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The input samples. Use ``dtype=np.float32`` for maximum\n efficiency. Sparse matrices are also supported, use sparse\n ``csc_matrix`` for maximum efficiency.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted. Splits\n that would create child nodes with net zero or negative weight are\n ignored while searching for a split in each node. In the case of\n classification, splits are also ignored if they would result in any\n single class carrying a negative weight in either child node.\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n self.fit_transform(X, y, sample_weight=sample_weight)\n return self\n \n def fit_transform(self, X, y=None, sample_weight=None):\n \"\"\"\n Fit estimator and transform dataset.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input data used to build forests. Use ``dtype=np.float32`` for\n maximum efficiency.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted. Splits\n that would create child nodes with net zero or negative weight are\n ignored while searching for a split in each node. In the case of\n classification, splits are also ignored if they would result in any\n single class carrying a negative weight in either child node.\n\n Returns\n -------\n X_transformed : sparse matrix of shape (n_samples, n_out)\n Transformed dataset.\n \"\"\"\n X = self._validate_data(X, accept_sparse=['csc'])\n if issparse(X):\n X.sort_indices()\n rnd = check_random_state(self.random_state)\n y = rnd.uniform(size=X.shape[0])\n super().fit(X, y, sample_weight=sample_weight)\n self.one_hot_encoder_ = OneHotEncoder(sparse=self.sparse_output)\n return self.one_hot_encoder_.fit_transform(self.apply(X))\n \n def transform(self, X):\n \"\"\"\n Transform dataset.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input data to be transformed. Use ``dtype=np.float32`` for maximum\n efficiency. Sparse matrices are also supported, use sparse\n ``csr_matrix`` for maximum efficiency.\n\n Returns\n -------\n X_transformed : sparse matrix of shape (n_samples, n_out)\n Transformed dataset.\n \"\"\"\n check_is_fitted(self)\n return self.one_hot_encoder_.transform(self.apply(X))\n" + "docstring": "\n An ensemble of totally random trees.\n\n An unsupervised transformation of a dataset to a high-dimensional\n sparse representation. A datapoint is coded according to which leaf of\n each tree it is sorted into. Using a one-hot encoding of the leaves,\n this leads to a binary coding with as many ones as there are trees in\n the forest.\n\n The dimensionality of the resulting representation is\n ``n_out <= n_estimators * max_leaf_nodes``. If ``max_leaf_nodes == None``,\n the number of leaf nodes is at most ``n_estimators * 2 ** max_depth``.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_estimators : int, default=100\n Number of trees in the forest.\n\n .. versionchanged:: 0.22\n The default value of ``n_estimators`` changed from 10 to 100\n in 0.22.\n\n max_depth : int, default=5\n The maximum depth of each tree. If None, then nodes are expanded until\n all leaves are pure or until all leaves contain less than\n min_samples_split samples.\n\n min_samples_split : int or float, default=2\n The minimum number of samples required to split an internal node:\n\n - If int, then consider `min_samples_split` as the minimum number.\n - If float, then `min_samples_split` is a fraction and\n `ceil(min_samples_split * n_samples)` is the minimum\n number of samples for each split.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_samples_leaf : int or float, default=1\n The minimum number of samples required to be at a leaf node.\n A split point at any depth will only be considered if it leaves at\n least ``min_samples_leaf`` training samples in each of the left and\n right branches. This may have the effect of smoothing the model,\n especially in regression.\n\n - If int, then consider `min_samples_leaf` as the minimum number.\n - If float, then `min_samples_leaf` is a fraction and\n `ceil(min_samples_leaf * n_samples)` is the minimum\n number of samples for each node.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_weight_fraction_leaf : float, default=0.0\n The minimum weighted fraction of the sum total of weights (of all\n the input samples) required to be at a leaf node. Samples have\n equal weight when sample_weight is not provided.\n\n max_leaf_nodes : int, default=None\n Grow trees with ``max_leaf_nodes`` in best-first fashion.\n Best nodes are defined as relative reduction in impurity.\n If None then unlimited number of leaf nodes.\n\n min_impurity_decrease : float, default=0.0\n A node will be split if this split induces a decrease of the impurity\n greater than or equal to this value.\n\n The weighted impurity decrease equation is the following::\n\n N_t / N * (impurity - N_t_R / N_t * right_impurity\n - N_t_L / N_t * left_impurity)\n\n where ``N`` is the total number of samples, ``N_t`` is the number of\n samples at the current node, ``N_t_L`` is the number of samples in the\n left child, and ``N_t_R`` is the number of samples in the right child.\n\n ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n if ``sample_weight`` is passed.\n\n .. versionadded:: 0.19\n\n sparse_output : bool, default=True\n Whether or not to return a sparse CSR matrix, as default behavior,\n or to return a dense array compatible with dense pipeline operators.\n\n n_jobs : int, default=None\n The number of jobs to run in parallel. :meth:`fit`, :meth:`transform`,\n :meth:`decision_path` and :meth:`apply` are all parallelized over the\n trees. ``None`` means 1 unless in a :obj:`joblib.parallel_backend`\n context. ``-1`` means using all processors. See :term:`Glossary\n ` for more details.\n\n random_state : int, RandomState instance or None, default=None\n Controls the generation of the random `y` used to fit the trees\n and the draw of the splits for each feature at the trees' nodes.\n See :term:`Glossary ` for details.\n\n verbose : int, default=0\n Controls the verbosity when fitting and predicting.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit\n and add more estimators to the ensemble, otherwise, just fit a whole\n new forest. See :term:`the Glossary `.\n\n Attributes\n ----------\n base_estimator_ : :class:`~sklearn.tree.ExtraTreeClassifier` instance\n The child estimator template used to create the collection of fitted\n sub-estimators.\n\n estimators_ : list of :class:`~sklearn.tree.ExtraTreeClassifier` instances\n The collection of fitted sub-estimators.\n\n feature_importances_ : ndarray of shape (n_features,)\n The feature importances (the higher, the more important the feature).\n\n n_features_ : int\n The number of features when ``fit`` is performed.\n\n .. deprecated:: 1.0\n Attribute `n_features_` was deprecated in version 1.0 and will be\n removed in 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n .. versionadded:: 1.0\n\n n_outputs_ : int\n The number of outputs when ``fit`` is performed.\n\n one_hot_encoder_ : OneHotEncoder instance\n One-hot encoder used to create the sparse embedding.\n\n See Also\n --------\n ExtraTreesClassifier : An extra-trees classifier.\n ExtraTreesRegressor : An extra-trees regressor.\n RandomForestClassifier : A random forest classifier.\n RandomForestRegressor : A random forest regressor.\n sklearn.tree.ExtraTreeClassifier: An extremely randomized\n tree classifier.\n sklearn.tree.ExtraTreeRegressor : An extremely randomized\n tree regressor.\n\n References\n ----------\n .. [1] P. Geurts, D. Ernst., and L. Wehenkel, \"Extremely randomized trees\",\n Machine Learning, 63(1), 3-42, 2006.\n .. [2] Moosmann, F. and Triggs, B. and Jurie, F. \"Fast discriminative\n visual codebooks using randomized clustering forests\"\n NIPS 2007\n\n Examples\n --------\n >>> from sklearn.ensemble import RandomTreesEmbedding\n >>> X = [[0,0], [1,0], [0,1], [-1,0], [0,-1]]\n >>> random_trees = RandomTreesEmbedding(\n ... n_estimators=5, random_state=0, max_depth=1).fit(X)\n >>> X_sparse_embedding = random_trees.transform(X)\n >>> X_sparse_embedding.toarray()\n array([[0., 1., 1., 0., 1., 0., 0., 1., 1., 0.],\n [0., 1., 1., 0., 1., 0., 0., 1., 1., 0.],\n [0., 1., 0., 1., 0., 1., 0., 1., 0., 1.],\n [1., 0., 1., 0., 1., 0., 1., 0., 1., 0.],\n [0., 1., 1., 0., 1., 0., 0., 1., 1., 0.]])\n ", + "source_code": "\n\nclass RandomTreesEmbedding(BaseForest):\n \"\"\"\n An ensemble of totally random trees.\n\n An unsupervised transformation of a dataset to a high-dimensional\n sparse representation. A datapoint is coded according to which leaf of\n each tree it is sorted into. Using a one-hot encoding of the leaves,\n this leads to a binary coding with as many ones as there are trees in\n the forest.\n\n The dimensionality of the resulting representation is\n ``n_out <= n_estimators * max_leaf_nodes``. If ``max_leaf_nodes == None``,\n the number of leaf nodes is at most ``n_estimators * 2 ** max_depth``.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_estimators : int, default=100\n Number of trees in the forest.\n\n .. versionchanged:: 0.22\n The default value of ``n_estimators`` changed from 10 to 100\n in 0.22.\n\n max_depth : int, default=5\n The maximum depth of each tree. If None, then nodes are expanded until\n all leaves are pure or until all leaves contain less than\n min_samples_split samples.\n\n min_samples_split : int or float, default=2\n The minimum number of samples required to split an internal node:\n\n - If int, then consider `min_samples_split` as the minimum number.\n - If float, then `min_samples_split` is a fraction and\n `ceil(min_samples_split * n_samples)` is the minimum\n number of samples for each split.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_samples_leaf : int or float, default=1\n The minimum number of samples required to be at a leaf node.\n A split point at any depth will only be considered if it leaves at\n least ``min_samples_leaf`` training samples in each of the left and\n right branches. This may have the effect of smoothing the model,\n especially in regression.\n\n - If int, then consider `min_samples_leaf` as the minimum number.\n - If float, then `min_samples_leaf` is a fraction and\n `ceil(min_samples_leaf * n_samples)` is the minimum\n number of samples for each node.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_weight_fraction_leaf : float, default=0.0\n The minimum weighted fraction of the sum total of weights (of all\n the input samples) required to be at a leaf node. Samples have\n equal weight when sample_weight is not provided.\n\n max_leaf_nodes : int, default=None\n Grow trees with ``max_leaf_nodes`` in best-first fashion.\n Best nodes are defined as relative reduction in impurity.\n If None then unlimited number of leaf nodes.\n\n min_impurity_decrease : float, default=0.0\n A node will be split if this split induces a decrease of the impurity\n greater than or equal to this value.\n\n The weighted impurity decrease equation is the following::\n\n N_t / N * (impurity - N_t_R / N_t * right_impurity\n - N_t_L / N_t * left_impurity)\n\n where ``N`` is the total number of samples, ``N_t`` is the number of\n samples at the current node, ``N_t_L`` is the number of samples in the\n left child, and ``N_t_R`` is the number of samples in the right child.\n\n ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n if ``sample_weight`` is passed.\n\n .. versionadded:: 0.19\n\n sparse_output : bool, default=True\n Whether or not to return a sparse CSR matrix, as default behavior,\n or to return a dense array compatible with dense pipeline operators.\n\n n_jobs : int, default=None\n The number of jobs to run in parallel. :meth:`fit`, :meth:`transform`,\n :meth:`decision_path` and :meth:`apply` are all parallelized over the\n trees. ``None`` means 1 unless in a :obj:`joblib.parallel_backend`\n context. ``-1`` means using all processors. See :term:`Glossary\n ` for more details.\n\n random_state : int, RandomState instance or None, default=None\n Controls the generation of the random `y` used to fit the trees\n and the draw of the splits for each feature at the trees' nodes.\n See :term:`Glossary ` for details.\n\n verbose : int, default=0\n Controls the verbosity when fitting and predicting.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit\n and add more estimators to the ensemble, otherwise, just fit a whole\n new forest. See :term:`the Glossary `.\n\n Attributes\n ----------\n base_estimator_ : :class:`~sklearn.tree.ExtraTreeClassifier` instance\n The child estimator template used to create the collection of fitted\n sub-estimators.\n\n estimators_ : list of :class:`~sklearn.tree.ExtraTreeClassifier` instances\n The collection of fitted sub-estimators.\n\n feature_importances_ : ndarray of shape (n_features,)\n The feature importances (the higher, the more important the feature).\n\n n_features_ : int\n The number of features when ``fit`` is performed.\n\n .. deprecated:: 1.0\n Attribute `n_features_` was deprecated in version 1.0 and will be\n removed in 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n .. versionadded:: 1.0\n\n n_outputs_ : int\n The number of outputs when ``fit`` is performed.\n\n one_hot_encoder_ : OneHotEncoder instance\n One-hot encoder used to create the sparse embedding.\n\n See Also\n --------\n ExtraTreesClassifier : An extra-trees classifier.\n ExtraTreesRegressor : An extra-trees regressor.\n RandomForestClassifier : A random forest classifier.\n RandomForestRegressor : A random forest regressor.\n sklearn.tree.ExtraTreeClassifier: An extremely randomized\n tree classifier.\n sklearn.tree.ExtraTreeRegressor : An extremely randomized\n tree regressor.\n\n References\n ----------\n .. [1] P. Geurts, D. Ernst., and L. Wehenkel, \"Extremely randomized trees\",\n Machine Learning, 63(1), 3-42, 2006.\n .. [2] Moosmann, F. and Triggs, B. and Jurie, F. \"Fast discriminative\n visual codebooks using randomized clustering forests\"\n NIPS 2007\n\n Examples\n --------\n >>> from sklearn.ensemble import RandomTreesEmbedding\n >>> X = [[0,0], [1,0], [0,1], [-1,0], [0,-1]]\n >>> random_trees = RandomTreesEmbedding(\n ... n_estimators=5, random_state=0, max_depth=1).fit(X)\n >>> X_sparse_embedding = random_trees.transform(X)\n >>> X_sparse_embedding.toarray()\n array([[0., 1., 1., 0., 1., 0., 0., 1., 1., 0.],\n [0., 1., 1., 0., 1., 0., 0., 1., 1., 0.],\n [0., 1., 0., 1., 0., 1., 0., 1., 0., 1.],\n [1., 0., 1., 0., 1., 0., 1., 0., 1., 0.],\n [0., 1., 1., 0., 1., 0., 0., 1., 1., 0.]])\n \"\"\"\n criterion = 'squared_error'\n max_features = 1\n \n def __init__(self, n_estimators=100, *, max_depth=5, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_leaf_nodes=None, min_impurity_decrease=0.0, sparse_output=True, n_jobs=None, random_state=None, verbose=0, warm_start=False):\n super().__init__(base_estimator=ExtraTreeRegressor(), n_estimators=n_estimators, estimator_params=('criterion', 'max_depth', 'min_samples_split', 'min_samples_leaf', 'min_weight_fraction_leaf', 'max_features', 'max_leaf_nodes', 'min_impurity_decrease', 'random_state'), bootstrap=False, oob_score=False, n_jobs=n_jobs, random_state=random_state, verbose=verbose, warm_start=warm_start, max_samples=None)\n self.max_depth = max_depth\n self.min_samples_split = min_samples_split\n self.min_samples_leaf = min_samples_leaf\n self.min_weight_fraction_leaf = min_weight_fraction_leaf\n self.max_leaf_nodes = max_leaf_nodes\n self.min_impurity_decrease = min_impurity_decrease\n self.sparse_output = sparse_output\n \n def _set_oob_score_and_attributes(self, X, y):\n raise NotImplementedError('OOB score not supported by tree embedding')\n \n def fit(self, X, y=None, sample_weight=None):\n \"\"\"\n Fit estimator.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The input samples. Use ``dtype=np.float32`` for maximum\n efficiency. Sparse matrices are also supported, use sparse\n ``csc_matrix`` for maximum efficiency.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted. Splits\n that would create child nodes with net zero or negative weight are\n ignored while searching for a split in each node. In the case of\n classification, splits are also ignored if they would result in any\n single class carrying a negative weight in either child node.\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n self.fit_transform(X, y, sample_weight=sample_weight)\n return self\n \n def fit_transform(self, X, y=None, sample_weight=None):\n \"\"\"\n Fit estimator and transform dataset.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input data used to build forests. Use ``dtype=np.float32`` for\n maximum efficiency.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted. Splits\n that would create child nodes with net zero or negative weight are\n ignored while searching for a split in each node. In the case of\n classification, splits are also ignored if they would result in any\n single class carrying a negative weight in either child node.\n\n Returns\n -------\n X_transformed : sparse matrix of shape (n_samples, n_out)\n Transformed dataset.\n \"\"\"\n rnd = check_random_state(self.random_state)\n y = rnd.uniform(size=_num_samples(X))\n super().fit(X, y, sample_weight=sample_weight)\n self.one_hot_encoder_ = OneHotEncoder(sparse=self.sparse_output)\n return self.one_hot_encoder_.fit_transform(self.apply(X))\n \n def transform(self, X):\n \"\"\"\n Transform dataset.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input data to be transformed. Use ``dtype=np.float32`` for maximum\n efficiency. Sparse matrices are also supported, use sparse\n ``csr_matrix`` for maximum efficiency.\n\n Returns\n -------\n X_transformed : sparse matrix of shape (n_samples, n_out)\n Transformed dataset.\n \"\"\"\n check_is_fitted(self)\n return self.one_hot_encoder_.transform(self.apply(X))\n" }, { "name": "BaseGradientBoosting", @@ -21061,10 +21028,10 @@ "sklearn.ensemble._gb.BaseGradientBoosting._raw_predict_init", "sklearn.ensemble._gb.BaseGradientBoosting._raw_predict", "sklearn.ensemble._gb.BaseGradientBoosting._staged_raw_predict", - "sklearn.ensemble._gb.BaseGradientBoosting.feature_importances_", + "sklearn.ensemble._gb.BaseGradientBoosting.feature_importances_@getter", "sklearn.ensemble._gb.BaseGradientBoosting._compute_partial_dependence_recursion", "sklearn.ensemble._gb.BaseGradientBoosting.apply", - "sklearn.ensemble._gb.BaseGradientBoosting.n_features_" + "sklearn.ensemble._gb.BaseGradientBoosting.n_features_@getter" ], "is_public": false, "description": "Abstract base class for Gradient Boosting.", @@ -21105,12 +21072,12 @@ "sklearn.ensemble._gb.GradientBoostingRegressor.predict", "sklearn.ensemble._gb.GradientBoostingRegressor.staged_predict", "sklearn.ensemble._gb.GradientBoostingRegressor.apply", - "sklearn.ensemble._gb.GradientBoostingRegressor.n_classes_" + "sklearn.ensemble._gb.GradientBoostingRegressor.n_classes_@getter" ], "is_public": true, "description": "Gradient Boosting for regression.\n\nGB builds an additive model in a forward stage-wise fashion; it allows for the optimization of arbitrary differentiable loss functions. In each stage a regression tree is fit on the negative gradient of the given loss function. Read more in the :ref:`User Guide `.", - "docstring": "Gradient Boosting for regression.\n\n GB builds an additive model in a forward stage-wise fashion;\n it allows for the optimization of arbitrary differentiable loss functions.\n In each stage a regression tree is fit on the negative gradient of the\n given loss function.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n loss : {'squared_error', 'ls', 'absolute_error', 'lad', 'huber', 'quantile'}, default='squared_error'\n Loss function to be optimized. 'squared_error' refers to the squared\n error for regression. 'absolute_error' refers to the absolute error of\n regression and is a robust loss function. 'huber' is a\n combination of the two. 'quantile' allows quantile regression (use\n `alpha` to specify the quantile).\n\n .. deprecated:: 1.0\n The loss 'ls' was deprecated in v1.0 and will be removed in\n version 1.2. Use `loss='squared_error'` which is equivalent.\n\n .. deprecated:: 1.0\n The loss 'lad' was deprecated in v1.0 and will be removed in\n version 1.2. Use `loss='absolute_error'` which is equivalent.\n\n learning_rate : float, default=0.1\n Learning rate shrinks the contribution of each tree by `learning_rate`.\n There is a trade-off between learning_rate and n_estimators.\n\n n_estimators : int, default=100\n The number of boosting stages to perform. Gradient boosting\n is fairly robust to over-fitting so a large number usually\n results in better performance.\n\n subsample : float, default=1.0\n The fraction of samples to be used for fitting the individual base\n learners. If smaller than 1.0 this results in Stochastic Gradient\n Boosting. `subsample` interacts with the parameter `n_estimators`.\n Choosing `subsample < 1.0` leads to a reduction of variance\n and an increase in bias.\n\n criterion : {'friedman_mse', 'squared_error', 'mse', 'mae'}, default='friedman_mse'\n The function to measure the quality of a split. Supported criteria\n are \"friedman_mse\" for the mean squared error with improvement\n score by Friedman, \"squared_error\" for mean squared error, and \"mae\"\n for the mean absolute error. The default value of \"friedman_mse\" is\n generally the best as it can provide a better approximation in some\n cases.\n\n .. versionadded:: 0.18\n\n .. deprecated:: 0.24\n `criterion='mae'` is deprecated and will be removed in version\n 1.1 (renaming of 0.26). The correct way of minimizing the absolute\n error is to use `loss='absolute_error'` instead.\n\n .. deprecated:: 1.0\n Criterion 'mse' was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion='squared_error'` which is equivalent.\n\n min_samples_split : int or float, default=2\n The minimum number of samples required to split an internal node:\n\n - If int, then consider `min_samples_split` as the minimum number.\n - If float, then `min_samples_split` is a fraction and\n `ceil(min_samples_split * n_samples)` are the minimum\n number of samples for each split.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_samples_leaf : int or float, default=1\n The minimum number of samples required to be at a leaf node.\n A split point at any depth will only be considered if it leaves at\n least ``min_samples_leaf`` training samples in each of the left and\n right branches. This may have the effect of smoothing the model,\n especially in regression.\n\n - If int, then consider `min_samples_leaf` as the minimum number.\n - If float, then `min_samples_leaf` is a fraction and\n `ceil(min_samples_leaf * n_samples)` are the minimum\n number of samples for each node.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_weight_fraction_leaf : float, default=0.0\n The minimum weighted fraction of the sum total of weights (of all\n the input samples) required to be at a leaf node. Samples have\n equal weight when sample_weight is not provided.\n\n max_depth : int, default=3\n Maximum depth of the individual regression estimators. The maximum\n depth limits the number of nodes in the tree. Tune this parameter\n for best performance; the best value depends on the interaction\n of the input variables.\n\n min_impurity_decrease : float, default=0.0\n A node will be split if this split induces a decrease of the impurity\n greater than or equal to this value.\n\n The weighted impurity decrease equation is the following::\n\n N_t / N * (impurity - N_t_R / N_t * right_impurity\n - N_t_L / N_t * left_impurity)\n\n where ``N`` is the total number of samples, ``N_t`` is the number of\n samples at the current node, ``N_t_L`` is the number of samples in the\n left child, and ``N_t_R`` is the number of samples in the right child.\n\n ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n if ``sample_weight`` is passed.\n\n .. versionadded:: 0.19\n\n init : estimator or 'zero', default=None\n An estimator object that is used to compute the initial predictions.\n ``init`` has to provide :term:`fit` and :term:`predict`. If 'zero', the\n initial raw predictions are set to zero. By default a\n ``DummyEstimator`` is used, predicting either the average target value\n (for loss='squared_error'), or a quantile for the other losses.\n\n random_state : int, RandomState instance or None, default=None\n Controls the random seed given to each Tree estimator at each\n boosting iteration.\n In addition, it controls the random permutation of the features at\n each split (see Notes for more details).\n It also controls the random splitting of the training data to obtain a\n validation set if `n_iter_no_change` is not None.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n max_features : {'auto', 'sqrt', 'log2'}, int or float, default=None\n The number of features to consider when looking for the best split:\n\n - If int, then consider `max_features` features at each split.\n - If float, then `max_features` is a fraction and\n `int(max_features * n_features)` features are considered at each\n split.\n - If \"auto\", then `max_features=n_features`.\n - If \"sqrt\", then `max_features=sqrt(n_features)`.\n - If \"log2\", then `max_features=log2(n_features)`.\n - If None, then `max_features=n_features`.\n\n Choosing `max_features < n_features` leads to a reduction of variance\n and an increase in bias.\n\n Note: the search for a split does not stop until at least one\n valid partition of the node samples is found, even if it requires to\n effectively inspect more than ``max_features`` features.\n\n alpha : float, default=0.9\n The alpha-quantile of the huber loss function and the quantile\n loss function. Only if ``loss='huber'`` or ``loss='quantile'``.\n\n verbose : int, default=0\n Enable verbose output. If 1 then it prints progress and performance\n once in a while (the more trees the lower the frequency). If greater\n than 1 then it prints progress and performance for every tree.\n\n max_leaf_nodes : int, default=None\n Grow trees with ``max_leaf_nodes`` in best-first fashion.\n Best nodes are defined as relative reduction in impurity.\n If None then unlimited number of leaf nodes.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit\n and add more estimators to the ensemble, otherwise, just erase the\n previous solution. See :term:`the Glossary `.\n\n validation_fraction : float, default=0.1\n The proportion of training data to set aside as validation set for\n early stopping. Must be between 0 and 1.\n Only used if ``n_iter_no_change`` is set to an integer.\n\n .. versionadded:: 0.20\n\n n_iter_no_change : int, default=None\n ``n_iter_no_change`` is used to decide if early stopping will be used\n to terminate training when validation score is not improving. By\n default it is set to None to disable early stopping. If set to a\n number, it will set aside ``validation_fraction`` size of the training\n data as validation and terminate training when validation score is not\n improving in all of the previous ``n_iter_no_change`` numbers of\n iterations.\n\n .. versionadded:: 0.20\n\n tol : float, default=1e-4\n Tolerance for the early stopping. When the loss is not improving\n by at least tol for ``n_iter_no_change`` iterations (if set to a\n number), the training stops.\n\n .. versionadded:: 0.20\n\n ccp_alpha : non-negative float, default=0.0\n Complexity parameter used for Minimal Cost-Complexity Pruning. The\n subtree with the largest cost complexity that is smaller than\n ``ccp_alpha`` will be chosen. By default, no pruning is performed. See\n :ref:`minimal_cost_complexity_pruning` for details.\n\n .. versionadded:: 0.22\n\n Attributes\n ----------\n feature_importances_ : ndarray of shape (n_features,)\n The impurity-based feature importances.\n The higher, the more important the feature.\n The importance of a feature is computed as the (normalized)\n total reduction of the criterion brought by that feature. It is also\n known as the Gini importance.\n\n Warning: impurity-based feature importances can be misleading for\n high cardinality features (many unique values). See\n :func:`sklearn.inspection.permutation_importance` as an alternative.\n\n oob_improvement_ : ndarray of shape (n_estimators,)\n The improvement in loss (= deviance) on the out-of-bag samples\n relative to the previous iteration.\n ``oob_improvement_[0]`` is the improvement in\n loss of the first stage over the ``init`` estimator.\n Only available if ``subsample < 1.0``\n\n train_score_ : ndarray of shape (n_estimators,)\n The i-th score ``train_score_[i]`` is the deviance (= loss) of the\n model at iteration ``i`` on the in-bag sample.\n If ``subsample == 1`` this is the deviance on the training data.\n\n loss_ : LossFunction\n The concrete ``LossFunction`` object.\n\n init_ : estimator\n The estimator that provides the initial predictions.\n Set via the ``init`` argument or ``loss.init_estimator``.\n\n estimators_ : ndarray of DecisionTreeRegressor of shape (n_estimators, 1)\n The collection of fitted sub-estimators.\n\n n_classes_ : int\n The number of classes, set to 1 for regressors.\n\n .. deprecated:: 0.24\n Attribute ``n_classes_`` was deprecated in version 0.24 and\n will be removed in 1.1 (renaming of 0.26).\n\n n_estimators_ : int\n The number of estimators as selected by early stopping (if\n ``n_iter_no_change`` is specified). Otherwise it is set to\n ``n_estimators``.\n\n n_features_ : int\n The number of data features.\n\n .. deprecated:: 1.0\n Attribute `n_features_` was deprecated in version 1.0 and will be\n removed in 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n max_features_ : int\n The inferred value of max_features.\n\n See Also\n --------\n HistGradientBoostingRegressor : Histogram-based Gradient Boosting\n Classification Tree.\n sklearn.tree.DecisionTreeRegressor : A decision tree regressor.\n sklearn.ensemble.RandomForestRegressor : A random forest regressor.\n\n Notes\n -----\n The features are always randomly permuted at each split. Therefore,\n the best found split may vary, even with the same training data and\n ``max_features=n_features``, if the improvement of the criterion is\n identical for several splits enumerated during the search of the best\n split. To obtain a deterministic behaviour during fitting,\n ``random_state`` has to be fixed.\n\n References\n ----------\n J. Friedman, Greedy Function Approximation: A Gradient Boosting\n Machine, The Annals of Statistics, Vol. 29, No. 5, 2001.\n\n J. Friedman, Stochastic Gradient Boosting, 1999\n\n T. Hastie, R. Tibshirani and J. Friedman.\n Elements of Statistical Learning Ed. 2, Springer, 2009.\n\n Examples\n --------\n >>> from sklearn.datasets import make_regression\n >>> from sklearn.ensemble import GradientBoostingRegressor\n >>> from sklearn.model_selection import train_test_split\n >>> X, y = make_regression(random_state=0)\n >>> X_train, X_test, y_train, y_test = train_test_split(\n ... X, y, random_state=0)\n >>> reg = GradientBoostingRegressor(random_state=0)\n >>> reg.fit(X_train, y_train)\n GradientBoostingRegressor(random_state=0)\n >>> reg.predict(X_test[1:2])\n array([-61...])\n >>> reg.score(X_test, y_test)\n 0.4...\n ", - "source_code": "\n\nclass GradientBoostingRegressor(RegressorMixin, BaseGradientBoosting):\n \"\"\"Gradient Boosting for regression.\n\n GB builds an additive model in a forward stage-wise fashion;\n it allows for the optimization of arbitrary differentiable loss functions.\n In each stage a regression tree is fit on the negative gradient of the\n given loss function.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n loss : {'squared_error', 'ls', 'absolute_error', 'lad', 'huber', 'quantile'}, default='squared_error'\n Loss function to be optimized. 'squared_error' refers to the squared\n error for regression. 'absolute_error' refers to the absolute error of\n regression and is a robust loss function. 'huber' is a\n combination of the two. 'quantile' allows quantile regression (use\n `alpha` to specify the quantile).\n\n .. deprecated:: 1.0\n The loss 'ls' was deprecated in v1.0 and will be removed in\n version 1.2. Use `loss='squared_error'` which is equivalent.\n\n .. deprecated:: 1.0\n The loss 'lad' was deprecated in v1.0 and will be removed in\n version 1.2. Use `loss='absolute_error'` which is equivalent.\n\n learning_rate : float, default=0.1\n Learning rate shrinks the contribution of each tree by `learning_rate`.\n There is a trade-off between learning_rate and n_estimators.\n\n n_estimators : int, default=100\n The number of boosting stages to perform. Gradient boosting\n is fairly robust to over-fitting so a large number usually\n results in better performance.\n\n subsample : float, default=1.0\n The fraction of samples to be used for fitting the individual base\n learners. If smaller than 1.0 this results in Stochastic Gradient\n Boosting. `subsample` interacts with the parameter `n_estimators`.\n Choosing `subsample < 1.0` leads to a reduction of variance\n and an increase in bias.\n\n criterion : {'friedman_mse', 'squared_error', 'mse', 'mae'}, default='friedman_mse'\n The function to measure the quality of a split. Supported criteria\n are \"friedman_mse\" for the mean squared error with improvement\n score by Friedman, \"squared_error\" for mean squared error, and \"mae\"\n for the mean absolute error. The default value of \"friedman_mse\" is\n generally the best as it can provide a better approximation in some\n cases.\n\n .. versionadded:: 0.18\n\n .. deprecated:: 0.24\n `criterion='mae'` is deprecated and will be removed in version\n 1.1 (renaming of 0.26). The correct way of minimizing the absolute\n error is to use `loss='absolute_error'` instead.\n\n .. deprecated:: 1.0\n Criterion 'mse' was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion='squared_error'` which is equivalent.\n\n min_samples_split : int or float, default=2\n The minimum number of samples required to split an internal node:\n\n - If int, then consider `min_samples_split` as the minimum number.\n - If float, then `min_samples_split` is a fraction and\n `ceil(min_samples_split * n_samples)` are the minimum\n number of samples for each split.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_samples_leaf : int or float, default=1\n The minimum number of samples required to be at a leaf node.\n A split point at any depth will only be considered if it leaves at\n least ``min_samples_leaf`` training samples in each of the left and\n right branches. This may have the effect of smoothing the model,\n especially in regression.\n\n - If int, then consider `min_samples_leaf` as the minimum number.\n - If float, then `min_samples_leaf` is a fraction and\n `ceil(min_samples_leaf * n_samples)` are the minimum\n number of samples for each node.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_weight_fraction_leaf : float, default=0.0\n The minimum weighted fraction of the sum total of weights (of all\n the input samples) required to be at a leaf node. Samples have\n equal weight when sample_weight is not provided.\n\n max_depth : int, default=3\n Maximum depth of the individual regression estimators. The maximum\n depth limits the number of nodes in the tree. Tune this parameter\n for best performance; the best value depends on the interaction\n of the input variables.\n\n min_impurity_decrease : float, default=0.0\n A node will be split if this split induces a decrease of the impurity\n greater than or equal to this value.\n\n The weighted impurity decrease equation is the following::\n\n N_t / N * (impurity - N_t_R / N_t * right_impurity\n - N_t_L / N_t * left_impurity)\n\n where ``N`` is the total number of samples, ``N_t`` is the number of\n samples at the current node, ``N_t_L`` is the number of samples in the\n left child, and ``N_t_R`` is the number of samples in the right child.\n\n ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n if ``sample_weight`` is passed.\n\n .. versionadded:: 0.19\n\n init : estimator or 'zero', default=None\n An estimator object that is used to compute the initial predictions.\n ``init`` has to provide :term:`fit` and :term:`predict`. If 'zero', the\n initial raw predictions are set to zero. By default a\n ``DummyEstimator`` is used, predicting either the average target value\n (for loss='squared_error'), or a quantile for the other losses.\n\n random_state : int, RandomState instance or None, default=None\n Controls the random seed given to each Tree estimator at each\n boosting iteration.\n In addition, it controls the random permutation of the features at\n each split (see Notes for more details).\n It also controls the random splitting of the training data to obtain a\n validation set if `n_iter_no_change` is not None.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n max_features : {'auto', 'sqrt', 'log2'}, int or float, default=None\n The number of features to consider when looking for the best split:\n\n - If int, then consider `max_features` features at each split.\n - If float, then `max_features` is a fraction and\n `int(max_features * n_features)` features are considered at each\n split.\n - If \"auto\", then `max_features=n_features`.\n - If \"sqrt\", then `max_features=sqrt(n_features)`.\n - If \"log2\", then `max_features=log2(n_features)`.\n - If None, then `max_features=n_features`.\n\n Choosing `max_features < n_features` leads to a reduction of variance\n and an increase in bias.\n\n Note: the search for a split does not stop until at least one\n valid partition of the node samples is found, even if it requires to\n effectively inspect more than ``max_features`` features.\n\n alpha : float, default=0.9\n The alpha-quantile of the huber loss function and the quantile\n loss function. Only if ``loss='huber'`` or ``loss='quantile'``.\n\n verbose : int, default=0\n Enable verbose output. If 1 then it prints progress and performance\n once in a while (the more trees the lower the frequency). If greater\n than 1 then it prints progress and performance for every tree.\n\n max_leaf_nodes : int, default=None\n Grow trees with ``max_leaf_nodes`` in best-first fashion.\n Best nodes are defined as relative reduction in impurity.\n If None then unlimited number of leaf nodes.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit\n and add more estimators to the ensemble, otherwise, just erase the\n previous solution. See :term:`the Glossary `.\n\n validation_fraction : float, default=0.1\n The proportion of training data to set aside as validation set for\n early stopping. Must be between 0 and 1.\n Only used if ``n_iter_no_change`` is set to an integer.\n\n .. versionadded:: 0.20\n\n n_iter_no_change : int, default=None\n ``n_iter_no_change`` is used to decide if early stopping will be used\n to terminate training when validation score is not improving. By\n default it is set to None to disable early stopping. If set to a\n number, it will set aside ``validation_fraction`` size of the training\n data as validation and terminate training when validation score is not\n improving in all of the previous ``n_iter_no_change`` numbers of\n iterations.\n\n .. versionadded:: 0.20\n\n tol : float, default=1e-4\n Tolerance for the early stopping. When the loss is not improving\n by at least tol for ``n_iter_no_change`` iterations (if set to a\n number), the training stops.\n\n .. versionadded:: 0.20\n\n ccp_alpha : non-negative float, default=0.0\n Complexity parameter used for Minimal Cost-Complexity Pruning. The\n subtree with the largest cost complexity that is smaller than\n ``ccp_alpha`` will be chosen. By default, no pruning is performed. See\n :ref:`minimal_cost_complexity_pruning` for details.\n\n .. versionadded:: 0.22\n\n Attributes\n ----------\n feature_importances_ : ndarray of shape (n_features,)\n The impurity-based feature importances.\n The higher, the more important the feature.\n The importance of a feature is computed as the (normalized)\n total reduction of the criterion brought by that feature. It is also\n known as the Gini importance.\n\n Warning: impurity-based feature importances can be misleading for\n high cardinality features (many unique values). See\n :func:`sklearn.inspection.permutation_importance` as an alternative.\n\n oob_improvement_ : ndarray of shape (n_estimators,)\n The improvement in loss (= deviance) on the out-of-bag samples\n relative to the previous iteration.\n ``oob_improvement_[0]`` is the improvement in\n loss of the first stage over the ``init`` estimator.\n Only available if ``subsample < 1.0``\n\n train_score_ : ndarray of shape (n_estimators,)\n The i-th score ``train_score_[i]`` is the deviance (= loss) of the\n model at iteration ``i`` on the in-bag sample.\n If ``subsample == 1`` this is the deviance on the training data.\n\n loss_ : LossFunction\n The concrete ``LossFunction`` object.\n\n init_ : estimator\n The estimator that provides the initial predictions.\n Set via the ``init`` argument or ``loss.init_estimator``.\n\n estimators_ : ndarray of DecisionTreeRegressor of shape (n_estimators, 1)\n The collection of fitted sub-estimators.\n\n n_classes_ : int\n The number of classes, set to 1 for regressors.\n\n .. deprecated:: 0.24\n Attribute ``n_classes_`` was deprecated in version 0.24 and\n will be removed in 1.1 (renaming of 0.26).\n\n n_estimators_ : int\n The number of estimators as selected by early stopping (if\n ``n_iter_no_change`` is specified). Otherwise it is set to\n ``n_estimators``.\n\n n_features_ : int\n The number of data features.\n\n .. deprecated:: 1.0\n Attribute `n_features_` was deprecated in version 1.0 and will be\n removed in 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n max_features_ : int\n The inferred value of max_features.\n\n See Also\n --------\n HistGradientBoostingRegressor : Histogram-based Gradient Boosting\n Classification Tree.\n sklearn.tree.DecisionTreeRegressor : A decision tree regressor.\n sklearn.ensemble.RandomForestRegressor : A random forest regressor.\n\n Notes\n -----\n The features are always randomly permuted at each split. Therefore,\n the best found split may vary, even with the same training data and\n ``max_features=n_features``, if the improvement of the criterion is\n identical for several splits enumerated during the search of the best\n split. To obtain a deterministic behaviour during fitting,\n ``random_state`` has to be fixed.\n\n References\n ----------\n J. Friedman, Greedy Function Approximation: A Gradient Boosting\n Machine, The Annals of Statistics, Vol. 29, No. 5, 2001.\n\n J. Friedman, Stochastic Gradient Boosting, 1999\n\n T. Hastie, R. Tibshirani and J. Friedman.\n Elements of Statistical Learning Ed. 2, Springer, 2009.\n\n Examples\n --------\n >>> from sklearn.datasets import make_regression\n >>> from sklearn.ensemble import GradientBoostingRegressor\n >>> from sklearn.model_selection import train_test_split\n >>> X, y = make_regression(random_state=0)\n >>> X_train, X_test, y_train, y_test = train_test_split(\n ... X, y, random_state=0)\n >>> reg = GradientBoostingRegressor(random_state=0)\n >>> reg.fit(X_train, y_train)\n GradientBoostingRegressor(random_state=0)\n >>> reg.predict(X_test[1:2])\n array([-61...])\n >>> reg.score(X_test, y_test)\n 0.4...\n \"\"\"\n _SUPPORTED_LOSS = ('squared_error', 'ls', 'absolute_error', 'lad', 'huber', 'quantile')\n \n def __init__(self, *, loss='squared_error', learning_rate=0.1, n_estimators=100, subsample=1.0, criterion='friedman_mse', min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_depth=3, min_impurity_decrease=0.0, init=None, random_state=None, max_features=None, alpha=0.9, verbose=0, max_leaf_nodes=None, warm_start=False, validation_fraction=0.1, n_iter_no_change=None, tol=0.0001, ccp_alpha=0.0):\n super().__init__(loss=loss, learning_rate=learning_rate, n_estimators=n_estimators, criterion=criterion, min_samples_split=min_samples_split, min_samples_leaf=min_samples_leaf, min_weight_fraction_leaf=min_weight_fraction_leaf, max_depth=max_depth, init=init, subsample=subsample, max_features=max_features, min_impurity_decrease=min_impurity_decrease, random_state=random_state, alpha=alpha, verbose=verbose, max_leaf_nodes=max_leaf_nodes, warm_start=warm_start, validation_fraction=validation_fraction, n_iter_no_change=n_iter_no_change, tol=tol, ccp_alpha=ccp_alpha)\n \n def _validate_y(self, y, sample_weight=None):\n if y.dtype.kind == 'O':\n y = y.astype(DOUBLE)\n return y\n \n def _warn_mae_for_criterion(self):\n warnings.warn(\"criterion='mae' was deprecated in version 0.24 and will be removed in version 1.1 (renaming of 0.26). The correct way of minimizing the absolute error is to use loss='absolute_error' instead.\", FutureWarning)\n \n def predict(self, X):\n \"\"\"Predict regression target for X.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The input samples. Internally, it will be converted to\n ``dtype=np.float32`` and if a sparse matrix is provided\n to a sparse ``csr_matrix``.\n\n Returns\n -------\n y : ndarray of shape (n_samples,)\n The predicted values.\n \"\"\"\n X = self._validate_data(X, dtype=DTYPE, order='C', accept_sparse='csr', reset=False)\n return self._raw_predict(X).ravel()\n \n def staged_predict(self, X):\n \"\"\"Predict regression target at each stage for X.\n\n This method allows monitoring (i.e. determine error on testing set)\n after each stage.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The input samples. Internally, it will be converted to\n ``dtype=np.float32`` and if a sparse matrix is provided\n to a sparse ``csr_matrix``.\n\n Yields\n ------\n y : generator of ndarray of shape (n_samples,)\n The predicted value of the input samples.\n \"\"\"\n for raw_predictions in self._staged_raw_predict(X):\n yield raw_predictions.ravel()\n \n def apply(self, X):\n \"\"\"Apply trees in the ensemble to X, return leaf indices.\n\n .. versionadded:: 0.17\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The input samples. Internally, its dtype will be converted to\n ``dtype=np.float32``. If a sparse matrix is provided, it will\n be converted to a sparse ``csr_matrix``.\n\n Returns\n -------\n X_leaves : array-like of shape (n_samples, n_estimators)\n For each datapoint x in X and for each tree in the ensemble,\n return the index of the leaf x ends up in each estimator.\n \"\"\"\n leaves = super().apply(X)\n leaves = leaves.reshape(X.shape[0], self.estimators_.shape[0])\n return leaves\n \n @deprecated('Attribute `n_classes_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def n_classes_(self):\n try:\n check_is_fitted(self)\n except NotFittedError as nfe:\n raise AttributeError('{} object has no n_classes_ attribute.'.format(self.__class__.__name__)) from nfe\n return 1\n" + "docstring": "Gradient Boosting for regression.\n\n GB builds an additive model in a forward stage-wise fashion;\n it allows for the optimization of arbitrary differentiable loss functions.\n In each stage a regression tree is fit on the negative gradient of the\n given loss function.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n loss : {'squared_error', 'absolute_error', 'huber', 'quantile'}, default='squared_error'\n Loss function to be optimized. 'squared_error' refers to the squared\n error for regression. 'absolute_error' refers to the absolute error of\n regression and is a robust loss function. 'huber' is a\n combination of the two. 'quantile' allows quantile regression (use\n `alpha` to specify the quantile).\n\n .. deprecated:: 1.0\n The loss 'ls' was deprecated in v1.0 and will be removed in\n version 1.2. Use `loss='squared_error'` which is equivalent.\n\n .. deprecated:: 1.0\n The loss 'lad' was deprecated in v1.0 and will be removed in\n version 1.2. Use `loss='absolute_error'` which is equivalent.\n\n learning_rate : float, default=0.1\n Learning rate shrinks the contribution of each tree by `learning_rate`.\n There is a trade-off between learning_rate and n_estimators.\n\n n_estimators : int, default=100\n The number of boosting stages to perform. Gradient boosting\n is fairly robust to over-fitting so a large number usually\n results in better performance.\n\n subsample : float, default=1.0\n The fraction of samples to be used for fitting the individual base\n learners. If smaller than 1.0 this results in Stochastic Gradient\n Boosting. `subsample` interacts with the parameter `n_estimators`.\n Choosing `subsample < 1.0` leads to a reduction of variance\n and an increase in bias.\n\n criterion : {'friedman_mse', 'squared_error', 'mse', 'mae'}, default='friedman_mse'\n The function to measure the quality of a split. Supported criteria\n are \"friedman_mse\" for the mean squared error with improvement\n score by Friedman, \"squared_error\" for mean squared error, and \"mae\"\n for the mean absolute error. The default value of \"friedman_mse\" is\n generally the best as it can provide a better approximation in some\n cases.\n\n .. versionadded:: 0.18\n\n .. deprecated:: 0.24\n `criterion='mae'` is deprecated and will be removed in version\n 1.1 (renaming of 0.26). The correct way of minimizing the absolute\n error is to use `loss='absolute_error'` instead.\n\n .. deprecated:: 1.0\n Criterion 'mse' was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion='squared_error'` which is equivalent.\n\n min_samples_split : int or float, default=2\n The minimum number of samples required to split an internal node:\n\n - If int, then consider `min_samples_split` as the minimum number.\n - If float, then `min_samples_split` is a fraction and\n `ceil(min_samples_split * n_samples)` are the minimum\n number of samples for each split.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_samples_leaf : int or float, default=1\n The minimum number of samples required to be at a leaf node.\n A split point at any depth will only be considered if it leaves at\n least ``min_samples_leaf`` training samples in each of the left and\n right branches. This may have the effect of smoothing the model,\n especially in regression.\n\n - If int, then consider `min_samples_leaf` as the minimum number.\n - If float, then `min_samples_leaf` is a fraction and\n `ceil(min_samples_leaf * n_samples)` are the minimum\n number of samples for each node.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_weight_fraction_leaf : float, default=0.0\n The minimum weighted fraction of the sum total of weights (of all\n the input samples) required to be at a leaf node. Samples have\n equal weight when sample_weight is not provided.\n\n max_depth : int, default=3\n Maximum depth of the individual regression estimators. The maximum\n depth limits the number of nodes in the tree. Tune this parameter\n for best performance; the best value depends on the interaction\n of the input variables.\n\n min_impurity_decrease : float, default=0.0\n A node will be split if this split induces a decrease of the impurity\n greater than or equal to this value.\n\n The weighted impurity decrease equation is the following::\n\n N_t / N * (impurity - N_t_R / N_t * right_impurity\n - N_t_L / N_t * left_impurity)\n\n where ``N`` is the total number of samples, ``N_t`` is the number of\n samples at the current node, ``N_t_L`` is the number of samples in the\n left child, and ``N_t_R`` is the number of samples in the right child.\n\n ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n if ``sample_weight`` is passed.\n\n .. versionadded:: 0.19\n\n init : estimator or 'zero', default=None\n An estimator object that is used to compute the initial predictions.\n ``init`` has to provide :term:`fit` and :term:`predict`. If 'zero', the\n initial raw predictions are set to zero. By default a\n ``DummyEstimator`` is used, predicting either the average target value\n (for loss='squared_error'), or a quantile for the other losses.\n\n random_state : int, RandomState instance or None, default=None\n Controls the random seed given to each Tree estimator at each\n boosting iteration.\n In addition, it controls the random permutation of the features at\n each split (see Notes for more details).\n It also controls the random splitting of the training data to obtain a\n validation set if `n_iter_no_change` is not None.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n max_features : {'auto', 'sqrt', 'log2'}, int or float, default=None\n The number of features to consider when looking for the best split:\n\n - If int, then consider `max_features` features at each split.\n - If float, then `max_features` is a fraction and\n `int(max_features * n_features)` features are considered at each\n split.\n - If \"auto\", then `max_features=n_features`.\n - If \"sqrt\", then `max_features=sqrt(n_features)`.\n - If \"log2\", then `max_features=log2(n_features)`.\n - If None, then `max_features=n_features`.\n\n Choosing `max_features < n_features` leads to a reduction of variance\n and an increase in bias.\n\n Note: the search for a split does not stop until at least one\n valid partition of the node samples is found, even if it requires to\n effectively inspect more than ``max_features`` features.\n\n alpha : float, default=0.9\n The alpha-quantile of the huber loss function and the quantile\n loss function. Only if ``loss='huber'`` or ``loss='quantile'``.\n\n verbose : int, default=0\n Enable verbose output. If 1 then it prints progress and performance\n once in a while (the more trees the lower the frequency). If greater\n than 1 then it prints progress and performance for every tree.\n\n max_leaf_nodes : int, default=None\n Grow trees with ``max_leaf_nodes`` in best-first fashion.\n Best nodes are defined as relative reduction in impurity.\n If None then unlimited number of leaf nodes.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit\n and add more estimators to the ensemble, otherwise, just erase the\n previous solution. See :term:`the Glossary `.\n\n validation_fraction : float, default=0.1\n The proportion of training data to set aside as validation set for\n early stopping. Must be between 0 and 1.\n Only used if ``n_iter_no_change`` is set to an integer.\n\n .. versionadded:: 0.20\n\n n_iter_no_change : int, default=None\n ``n_iter_no_change`` is used to decide if early stopping will be used\n to terminate training when validation score is not improving. By\n default it is set to None to disable early stopping. If set to a\n number, it will set aside ``validation_fraction`` size of the training\n data as validation and terminate training when validation score is not\n improving in all of the previous ``n_iter_no_change`` numbers of\n iterations.\n\n .. versionadded:: 0.20\n\n tol : float, default=1e-4\n Tolerance for the early stopping. When the loss is not improving\n by at least tol for ``n_iter_no_change`` iterations (if set to a\n number), the training stops.\n\n .. versionadded:: 0.20\n\n ccp_alpha : non-negative float, default=0.0\n Complexity parameter used for Minimal Cost-Complexity Pruning. The\n subtree with the largest cost complexity that is smaller than\n ``ccp_alpha`` will be chosen. By default, no pruning is performed. See\n :ref:`minimal_cost_complexity_pruning` for details.\n\n .. versionadded:: 0.22\n\n Attributes\n ----------\n feature_importances_ : ndarray of shape (n_features,)\n The impurity-based feature importances.\n The higher, the more important the feature.\n The importance of a feature is computed as the (normalized)\n total reduction of the criterion brought by that feature. It is also\n known as the Gini importance.\n\n Warning: impurity-based feature importances can be misleading for\n high cardinality features (many unique values). See\n :func:`sklearn.inspection.permutation_importance` as an alternative.\n\n oob_improvement_ : ndarray of shape (n_estimators,)\n The improvement in loss (= deviance) on the out-of-bag samples\n relative to the previous iteration.\n ``oob_improvement_[0]`` is the improvement in\n loss of the first stage over the ``init`` estimator.\n Only available if ``subsample < 1.0``\n\n train_score_ : ndarray of shape (n_estimators,)\n The i-th score ``train_score_[i]`` is the deviance (= loss) of the\n model at iteration ``i`` on the in-bag sample.\n If ``subsample == 1`` this is the deviance on the training data.\n\n loss_ : LossFunction\n The concrete ``LossFunction`` object.\n\n init_ : estimator\n The estimator that provides the initial predictions.\n Set via the ``init`` argument or ``loss.init_estimator``.\n\n estimators_ : ndarray of DecisionTreeRegressor of shape (n_estimators, 1)\n The collection of fitted sub-estimators.\n\n n_classes_ : int\n The number of classes, set to 1 for regressors.\n\n .. deprecated:: 0.24\n Attribute ``n_classes_`` was deprecated in version 0.24 and\n will be removed in 1.1 (renaming of 0.26).\n\n n_estimators_ : int\n The number of estimators as selected by early stopping (if\n ``n_iter_no_change`` is specified). Otherwise it is set to\n ``n_estimators``.\n\n n_features_ : int\n The number of data features.\n\n .. deprecated:: 1.0\n Attribute `n_features_` was deprecated in version 1.0 and will be\n removed in 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n max_features_ : int\n The inferred value of max_features.\n\n See Also\n --------\n HistGradientBoostingRegressor : Histogram-based Gradient Boosting\n Classification Tree.\n sklearn.tree.DecisionTreeRegressor : A decision tree regressor.\n sklearn.ensemble.RandomForestRegressor : A random forest regressor.\n\n Notes\n -----\n The features are always randomly permuted at each split. Therefore,\n the best found split may vary, even with the same training data and\n ``max_features=n_features``, if the improvement of the criterion is\n identical for several splits enumerated during the search of the best\n split. To obtain a deterministic behaviour during fitting,\n ``random_state`` has to be fixed.\n\n References\n ----------\n J. Friedman, Greedy Function Approximation: A Gradient Boosting\n Machine, The Annals of Statistics, Vol. 29, No. 5, 2001.\n\n J. Friedman, Stochastic Gradient Boosting, 1999\n\n T. Hastie, R. Tibshirani and J. Friedman.\n Elements of Statistical Learning Ed. 2, Springer, 2009.\n\n Examples\n --------\n >>> from sklearn.datasets import make_regression\n >>> from sklearn.ensemble import GradientBoostingRegressor\n >>> from sklearn.model_selection import train_test_split\n >>> X, y = make_regression(random_state=0)\n >>> X_train, X_test, y_train, y_test = train_test_split(\n ... X, y, random_state=0)\n >>> reg = GradientBoostingRegressor(random_state=0)\n >>> reg.fit(X_train, y_train)\n GradientBoostingRegressor(random_state=0)\n >>> reg.predict(X_test[1:2])\n array([-61...])\n >>> reg.score(X_test, y_test)\n 0.4...\n ", + "source_code": "\n\nclass GradientBoostingRegressor(RegressorMixin, BaseGradientBoosting):\n \"\"\"Gradient Boosting for regression.\n\n GB builds an additive model in a forward stage-wise fashion;\n it allows for the optimization of arbitrary differentiable loss functions.\n In each stage a regression tree is fit on the negative gradient of the\n given loss function.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n loss : {'squared_error', 'absolute_error', 'huber', 'quantile'}, default='squared_error'\n Loss function to be optimized. 'squared_error' refers to the squared\n error for regression. 'absolute_error' refers to the absolute error of\n regression and is a robust loss function. 'huber' is a\n combination of the two. 'quantile' allows quantile regression (use\n `alpha` to specify the quantile).\n\n .. deprecated:: 1.0\n The loss 'ls' was deprecated in v1.0 and will be removed in\n version 1.2. Use `loss='squared_error'` which is equivalent.\n\n .. deprecated:: 1.0\n The loss 'lad' was deprecated in v1.0 and will be removed in\n version 1.2. Use `loss='absolute_error'` which is equivalent.\n\n learning_rate : float, default=0.1\n Learning rate shrinks the contribution of each tree by `learning_rate`.\n There is a trade-off between learning_rate and n_estimators.\n\n n_estimators : int, default=100\n The number of boosting stages to perform. Gradient boosting\n is fairly robust to over-fitting so a large number usually\n results in better performance.\n\n subsample : float, default=1.0\n The fraction of samples to be used for fitting the individual base\n learners. If smaller than 1.0 this results in Stochastic Gradient\n Boosting. `subsample` interacts with the parameter `n_estimators`.\n Choosing `subsample < 1.0` leads to a reduction of variance\n and an increase in bias.\n\n criterion : {'friedman_mse', 'squared_error', 'mse', 'mae'}, default='friedman_mse'\n The function to measure the quality of a split. Supported criteria\n are \"friedman_mse\" for the mean squared error with improvement\n score by Friedman, \"squared_error\" for mean squared error, and \"mae\"\n for the mean absolute error. The default value of \"friedman_mse\" is\n generally the best as it can provide a better approximation in some\n cases.\n\n .. versionadded:: 0.18\n\n .. deprecated:: 0.24\n `criterion='mae'` is deprecated and will be removed in version\n 1.1 (renaming of 0.26). The correct way of minimizing the absolute\n error is to use `loss='absolute_error'` instead.\n\n .. deprecated:: 1.0\n Criterion 'mse' was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion='squared_error'` which is equivalent.\n\n min_samples_split : int or float, default=2\n The minimum number of samples required to split an internal node:\n\n - If int, then consider `min_samples_split` as the minimum number.\n - If float, then `min_samples_split` is a fraction and\n `ceil(min_samples_split * n_samples)` are the minimum\n number of samples for each split.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_samples_leaf : int or float, default=1\n The minimum number of samples required to be at a leaf node.\n A split point at any depth will only be considered if it leaves at\n least ``min_samples_leaf`` training samples in each of the left and\n right branches. This may have the effect of smoothing the model,\n especially in regression.\n\n - If int, then consider `min_samples_leaf` as the minimum number.\n - If float, then `min_samples_leaf` is a fraction and\n `ceil(min_samples_leaf * n_samples)` are the minimum\n number of samples for each node.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_weight_fraction_leaf : float, default=0.0\n The minimum weighted fraction of the sum total of weights (of all\n the input samples) required to be at a leaf node. Samples have\n equal weight when sample_weight is not provided.\n\n max_depth : int, default=3\n Maximum depth of the individual regression estimators. The maximum\n depth limits the number of nodes in the tree. Tune this parameter\n for best performance; the best value depends on the interaction\n of the input variables.\n\n min_impurity_decrease : float, default=0.0\n A node will be split if this split induces a decrease of the impurity\n greater than or equal to this value.\n\n The weighted impurity decrease equation is the following::\n\n N_t / N * (impurity - N_t_R / N_t * right_impurity\n - N_t_L / N_t * left_impurity)\n\n where ``N`` is the total number of samples, ``N_t`` is the number of\n samples at the current node, ``N_t_L`` is the number of samples in the\n left child, and ``N_t_R`` is the number of samples in the right child.\n\n ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n if ``sample_weight`` is passed.\n\n .. versionadded:: 0.19\n\n init : estimator or 'zero', default=None\n An estimator object that is used to compute the initial predictions.\n ``init`` has to provide :term:`fit` and :term:`predict`. If 'zero', the\n initial raw predictions are set to zero. By default a\n ``DummyEstimator`` is used, predicting either the average target value\n (for loss='squared_error'), or a quantile for the other losses.\n\n random_state : int, RandomState instance or None, default=None\n Controls the random seed given to each Tree estimator at each\n boosting iteration.\n In addition, it controls the random permutation of the features at\n each split (see Notes for more details).\n It also controls the random splitting of the training data to obtain a\n validation set if `n_iter_no_change` is not None.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n max_features : {'auto', 'sqrt', 'log2'}, int or float, default=None\n The number of features to consider when looking for the best split:\n\n - If int, then consider `max_features` features at each split.\n - If float, then `max_features` is a fraction and\n `int(max_features * n_features)` features are considered at each\n split.\n - If \"auto\", then `max_features=n_features`.\n - If \"sqrt\", then `max_features=sqrt(n_features)`.\n - If \"log2\", then `max_features=log2(n_features)`.\n - If None, then `max_features=n_features`.\n\n Choosing `max_features < n_features` leads to a reduction of variance\n and an increase in bias.\n\n Note: the search for a split does not stop until at least one\n valid partition of the node samples is found, even if it requires to\n effectively inspect more than ``max_features`` features.\n\n alpha : float, default=0.9\n The alpha-quantile of the huber loss function and the quantile\n loss function. Only if ``loss='huber'`` or ``loss='quantile'``.\n\n verbose : int, default=0\n Enable verbose output. If 1 then it prints progress and performance\n once in a while (the more trees the lower the frequency). If greater\n than 1 then it prints progress and performance for every tree.\n\n max_leaf_nodes : int, default=None\n Grow trees with ``max_leaf_nodes`` in best-first fashion.\n Best nodes are defined as relative reduction in impurity.\n If None then unlimited number of leaf nodes.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit\n and add more estimators to the ensemble, otherwise, just erase the\n previous solution. See :term:`the Glossary `.\n\n validation_fraction : float, default=0.1\n The proportion of training data to set aside as validation set for\n early stopping. Must be between 0 and 1.\n Only used if ``n_iter_no_change`` is set to an integer.\n\n .. versionadded:: 0.20\n\n n_iter_no_change : int, default=None\n ``n_iter_no_change`` is used to decide if early stopping will be used\n to terminate training when validation score is not improving. By\n default it is set to None to disable early stopping. If set to a\n number, it will set aside ``validation_fraction`` size of the training\n data as validation and terminate training when validation score is not\n improving in all of the previous ``n_iter_no_change`` numbers of\n iterations.\n\n .. versionadded:: 0.20\n\n tol : float, default=1e-4\n Tolerance for the early stopping. When the loss is not improving\n by at least tol for ``n_iter_no_change`` iterations (if set to a\n number), the training stops.\n\n .. versionadded:: 0.20\n\n ccp_alpha : non-negative float, default=0.0\n Complexity parameter used for Minimal Cost-Complexity Pruning. The\n subtree with the largest cost complexity that is smaller than\n ``ccp_alpha`` will be chosen. By default, no pruning is performed. See\n :ref:`minimal_cost_complexity_pruning` for details.\n\n .. versionadded:: 0.22\n\n Attributes\n ----------\n feature_importances_ : ndarray of shape (n_features,)\n The impurity-based feature importances.\n The higher, the more important the feature.\n The importance of a feature is computed as the (normalized)\n total reduction of the criterion brought by that feature. It is also\n known as the Gini importance.\n\n Warning: impurity-based feature importances can be misleading for\n high cardinality features (many unique values). See\n :func:`sklearn.inspection.permutation_importance` as an alternative.\n\n oob_improvement_ : ndarray of shape (n_estimators,)\n The improvement in loss (= deviance) on the out-of-bag samples\n relative to the previous iteration.\n ``oob_improvement_[0]`` is the improvement in\n loss of the first stage over the ``init`` estimator.\n Only available if ``subsample < 1.0``\n\n train_score_ : ndarray of shape (n_estimators,)\n The i-th score ``train_score_[i]`` is the deviance (= loss) of the\n model at iteration ``i`` on the in-bag sample.\n If ``subsample == 1`` this is the deviance on the training data.\n\n loss_ : LossFunction\n The concrete ``LossFunction`` object.\n\n init_ : estimator\n The estimator that provides the initial predictions.\n Set via the ``init`` argument or ``loss.init_estimator``.\n\n estimators_ : ndarray of DecisionTreeRegressor of shape (n_estimators, 1)\n The collection of fitted sub-estimators.\n\n n_classes_ : int\n The number of classes, set to 1 for regressors.\n\n .. deprecated:: 0.24\n Attribute ``n_classes_`` was deprecated in version 0.24 and\n will be removed in 1.1 (renaming of 0.26).\n\n n_estimators_ : int\n The number of estimators as selected by early stopping (if\n ``n_iter_no_change`` is specified). Otherwise it is set to\n ``n_estimators``.\n\n n_features_ : int\n The number of data features.\n\n .. deprecated:: 1.0\n Attribute `n_features_` was deprecated in version 1.0 and will be\n removed in 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n max_features_ : int\n The inferred value of max_features.\n\n See Also\n --------\n HistGradientBoostingRegressor : Histogram-based Gradient Boosting\n Classification Tree.\n sklearn.tree.DecisionTreeRegressor : A decision tree regressor.\n sklearn.ensemble.RandomForestRegressor : A random forest regressor.\n\n Notes\n -----\n The features are always randomly permuted at each split. Therefore,\n the best found split may vary, even with the same training data and\n ``max_features=n_features``, if the improvement of the criterion is\n identical for several splits enumerated during the search of the best\n split. To obtain a deterministic behaviour during fitting,\n ``random_state`` has to be fixed.\n\n References\n ----------\n J. Friedman, Greedy Function Approximation: A Gradient Boosting\n Machine, The Annals of Statistics, Vol. 29, No. 5, 2001.\n\n J. Friedman, Stochastic Gradient Boosting, 1999\n\n T. Hastie, R. Tibshirani and J. Friedman.\n Elements of Statistical Learning Ed. 2, Springer, 2009.\n\n Examples\n --------\n >>> from sklearn.datasets import make_regression\n >>> from sklearn.ensemble import GradientBoostingRegressor\n >>> from sklearn.model_selection import train_test_split\n >>> X, y = make_regression(random_state=0)\n >>> X_train, X_test, y_train, y_test = train_test_split(\n ... X, y, random_state=0)\n >>> reg = GradientBoostingRegressor(random_state=0)\n >>> reg.fit(X_train, y_train)\n GradientBoostingRegressor(random_state=0)\n >>> reg.predict(X_test[1:2])\n array([-61...])\n >>> reg.score(X_test, y_test)\n 0.4...\n \"\"\"\n _SUPPORTED_LOSS = ('squared_error', 'ls', 'absolute_error', 'lad', 'huber', 'quantile')\n \n def __init__(self, *, loss='squared_error', learning_rate=0.1, n_estimators=100, subsample=1.0, criterion='friedman_mse', min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_depth=3, min_impurity_decrease=0.0, init=None, random_state=None, max_features=None, alpha=0.9, verbose=0, max_leaf_nodes=None, warm_start=False, validation_fraction=0.1, n_iter_no_change=None, tol=0.0001, ccp_alpha=0.0):\n super().__init__(loss=loss, learning_rate=learning_rate, n_estimators=n_estimators, criterion=criterion, min_samples_split=min_samples_split, min_samples_leaf=min_samples_leaf, min_weight_fraction_leaf=min_weight_fraction_leaf, max_depth=max_depth, init=init, subsample=subsample, max_features=max_features, min_impurity_decrease=min_impurity_decrease, random_state=random_state, alpha=alpha, verbose=verbose, max_leaf_nodes=max_leaf_nodes, warm_start=warm_start, validation_fraction=validation_fraction, n_iter_no_change=n_iter_no_change, tol=tol, ccp_alpha=ccp_alpha)\n \n def _validate_y(self, y, sample_weight=None):\n if y.dtype.kind == 'O':\n y = y.astype(DOUBLE)\n return y\n \n def _warn_mae_for_criterion(self):\n warnings.warn(\"criterion='mae' was deprecated in version 0.24 and will be removed in version 1.1 (renaming of 0.26). The correct way of minimizing the absolute error is to use loss='absolute_error' instead.\", FutureWarning)\n \n def predict(self, X):\n \"\"\"Predict regression target for X.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The input samples. Internally, it will be converted to\n ``dtype=np.float32`` and if a sparse matrix is provided\n to a sparse ``csr_matrix``.\n\n Returns\n -------\n y : ndarray of shape (n_samples,)\n The predicted values.\n \"\"\"\n X = self._validate_data(X, dtype=DTYPE, order='C', accept_sparse='csr', reset=False)\n return self._raw_predict(X).ravel()\n \n def staged_predict(self, X):\n \"\"\"Predict regression target at each stage for X.\n\n This method allows monitoring (i.e. determine error on testing set)\n after each stage.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The input samples. Internally, it will be converted to\n ``dtype=np.float32`` and if a sparse matrix is provided\n to a sparse ``csr_matrix``.\n\n Yields\n ------\n y : generator of ndarray of shape (n_samples,)\n The predicted value of the input samples.\n \"\"\"\n for raw_predictions in self._staged_raw_predict(X):\n yield raw_predictions.ravel()\n \n def apply(self, X):\n \"\"\"Apply trees in the ensemble to X, return leaf indices.\n\n .. versionadded:: 0.17\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The input samples. Internally, its dtype will be converted to\n ``dtype=np.float32``. If a sparse matrix is provided, it will\n be converted to a sparse ``csr_matrix``.\n\n Returns\n -------\n X_leaves : array-like of shape (n_samples, n_estimators)\n For each datapoint x in X and for each tree in the ensemble,\n return the index of the leaf x ends up in each estimator.\n \"\"\"\n leaves = super().apply(X)\n leaves = leaves.reshape(X.shape[0], self.estimators_.shape[0])\n return leaves\n \n @deprecated('Attribute `n_classes_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def n_classes_(self):\n try:\n check_is_fitted(self)\n except NotFittedError as nfe:\n raise AttributeError('{} object has no n_classes_ attribute.'.format(self.__class__.__name__)) from nfe\n return 1\n" }, { "name": "VerboseReporter", @@ -21316,8 +21283,8 @@ ], "is_public": false, "description": "Transformer that maps a dataset into integer-valued bins.\n\nFor continuous features, the bins are created in a feature-wise fashion, using quantiles so that each bins contains approximately the same number of samples. For large datasets, quantiles are computed on a subset of the data to speed-up the binning, but the quantiles should remain stable. For categorical features, the raw categorical values are expected to be in [0, 254] (this is not validated here though) and each category corresponds to a bin. All categorical values must be known at initialization: transform() doesn't know how to bin unknown categorical values. Note that transform() is only used on non-training data in the case of early stopping. Features with a small number of values may be binned into less than ``n_bins`` bins. The last bin (at index ``n_bins - 1``) is always reserved for missing values.", - "docstring": "Transformer that maps a dataset into integer-valued bins.\n\n For continuous features, the bins are created in a feature-wise fashion,\n using quantiles so that each bins contains approximately the same number\n of samples. For large datasets, quantiles are computed on a subset of the\n data to speed-up the binning, but the quantiles should remain stable.\n\n For categorical features, the raw categorical values are expected to be\n in [0, 254] (this is not validated here though) and each category\n corresponds to a bin. All categorical values must be known at\n initialization: transform() doesn't know how to bin unknown categorical\n values. Note that transform() is only used on non-training data in the\n case of early stopping.\n\n Features with a small number of values may be binned into less than\n ``n_bins`` bins. The last bin (at index ``n_bins - 1``) is always reserved\n for missing values.\n\n Parameters\n ----------\n n_bins : int, default=256\n The maximum number of bins to use (including the bin for missing\n values). Should be in [3, 256]. Non-missing values are binned on\n ``max_bins = n_bins - 1`` bins. The last bin is always reserved for\n missing values. If for a given feature the number of unique values is\n less than ``max_bins``, then those unique values will be used to\n compute the bin thresholds, instead of the quantiles. For categorical\n features indicated by ``is_categorical``, the docstring for\n ``is_categorical`` details on this procedure.\n subsample : int or None, default=2e5\n If ``n_samples > subsample``, then ``sub_samples`` samples will be\n randomly chosen to compute the quantiles. If ``None``, the whole data\n is used.\n is_categorical : ndarray of bool of shape (n_features,), default=None\n Indicates categorical features. By default, all features are\n considered continuous.\n known_categories : list of {ndarray, None} of shape (n_features,), default=none\n For each categorical feature, the array indicates the set of unique\n categorical values. These should be the possible values over all the\n data, not just the training data. For continuous features, the\n corresponding entry should be None.\n random_state: int, RandomState instance or None, default=None\n Pseudo-random number generator to control the random sub-sampling.\n Pass an int for reproducible output across multiple\n function calls.\n See :term: `Glossary `.\n n_threads : int, default=None\n Number of OpenMP threads to use. `_openmp_effective_n_threads` is called\n to determine the effective number of threads use, which takes cgroups CPU\n quotes into account. See the docstring of `_openmp_effective_n_threads`\n for details.\n\n Attributes\n ----------\n bin_thresholds_ : list of ndarray\n For each feature, each array indicates how to map a feature into a\n binned feature. The semantic and size depends on the nature of the\n feature:\n - for real-valued features, the array corresponds to the real-valued\n bin thresholds (the upper bound of each bin). There are ``max_bins\n - 1`` thresholds, where ``max_bins = n_bins - 1`` is the number of\n bins used for non-missing values.\n - for categorical features, the array is a map from a binned category\n value to the raw category value. The size of the array is equal to\n ``min(max_bins, category_cardinality)`` where we ignore missing\n values in the cardinality.\n n_bins_non_missing_ : ndarray, dtype=np.uint32\n For each feature, gives the number of bins actually used for\n non-missing values. For features with a lot of unique values, this is\n equal to ``n_bins - 1``.\n is_categorical_ : ndarray of shape (n_features,), dtype=np.uint8\n Indicator for categorical features.\n missing_values_bin_idx_ : np.uint8\n The index of the bin where missing values are mapped. This is a\n constant across all features. This corresponds to the last bin, and\n it is always equal to ``n_bins - 1``. Note that if ``n_bins_missing_``\n is less than ``n_bins - 1`` for a given feature, then there are\n empty (and unused) bins.\n ", - "source_code": "\n\nclass _BinMapper(TransformerMixin, BaseEstimator):\n \"\"\"Transformer that maps a dataset into integer-valued bins.\n\n For continuous features, the bins are created in a feature-wise fashion,\n using quantiles so that each bins contains approximately the same number\n of samples. For large datasets, quantiles are computed on a subset of the\n data to speed-up the binning, but the quantiles should remain stable.\n\n For categorical features, the raw categorical values are expected to be\n in [0, 254] (this is not validated here though) and each category\n corresponds to a bin. All categorical values must be known at\n initialization: transform() doesn't know how to bin unknown categorical\n values. Note that transform() is only used on non-training data in the\n case of early stopping.\n\n Features with a small number of values may be binned into less than\n ``n_bins`` bins. The last bin (at index ``n_bins - 1``) is always reserved\n for missing values.\n\n Parameters\n ----------\n n_bins : int, default=256\n The maximum number of bins to use (including the bin for missing\n values). Should be in [3, 256]. Non-missing values are binned on\n ``max_bins = n_bins - 1`` bins. The last bin is always reserved for\n missing values. If for a given feature the number of unique values is\n less than ``max_bins``, then those unique values will be used to\n compute the bin thresholds, instead of the quantiles. For categorical\n features indicated by ``is_categorical``, the docstring for\n ``is_categorical`` details on this procedure.\n subsample : int or None, default=2e5\n If ``n_samples > subsample``, then ``sub_samples`` samples will be\n randomly chosen to compute the quantiles. If ``None``, the whole data\n is used.\n is_categorical : ndarray of bool of shape (n_features,), default=None\n Indicates categorical features. By default, all features are\n considered continuous.\n known_categories : list of {ndarray, None} of shape (n_features,), default=none\n For each categorical feature, the array indicates the set of unique\n categorical values. These should be the possible values over all the\n data, not just the training data. For continuous features, the\n corresponding entry should be None.\n random_state: int, RandomState instance or None, default=None\n Pseudo-random number generator to control the random sub-sampling.\n Pass an int for reproducible output across multiple\n function calls.\n See :term: `Glossary `.\n n_threads : int, default=None\n Number of OpenMP threads to use. `_openmp_effective_n_threads` is called\n to determine the effective number of threads use, which takes cgroups CPU\n quotes into account. See the docstring of `_openmp_effective_n_threads`\n for details.\n\n Attributes\n ----------\n bin_thresholds_ : list of ndarray\n For each feature, each array indicates how to map a feature into a\n binned feature. The semantic and size depends on the nature of the\n feature:\n - for real-valued features, the array corresponds to the real-valued\n bin thresholds (the upper bound of each bin). There are ``max_bins\n - 1`` thresholds, where ``max_bins = n_bins - 1`` is the number of\n bins used for non-missing values.\n - for categorical features, the array is a map from a binned category\n value to the raw category value. The size of the array is equal to\n ``min(max_bins, category_cardinality)`` where we ignore missing\n values in the cardinality.\n n_bins_non_missing_ : ndarray, dtype=np.uint32\n For each feature, gives the number of bins actually used for\n non-missing values. For features with a lot of unique values, this is\n equal to ``n_bins - 1``.\n is_categorical_ : ndarray of shape (n_features,), dtype=np.uint8\n Indicator for categorical features.\n missing_values_bin_idx_ : np.uint8\n The index of the bin where missing values are mapped. This is a\n constant across all features. This corresponds to the last bin, and\n it is always equal to ``n_bins - 1``. Note that if ``n_bins_missing_``\n is less than ``n_bins - 1`` for a given feature, then there are\n empty (and unused) bins.\n \"\"\"\n \n def __init__(self, n_bins=256, subsample=int(200000.0), is_categorical=None, known_categories=None, random_state=None, n_threads=None):\n self.n_bins = n_bins\n self.subsample = subsample\n self.is_categorical = is_categorical\n self.known_categories = known_categories\n self.random_state = random_state\n self.n_threads = n_threads\n \n def fit(self, X, y=None):\n \"\"\"Fit data X by computing the binning thresholds.\n\n The last bin is reserved for missing values, whether missing values\n are present in the data or not.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data to bin.\n y: None\n Ignored.\n\n Returns\n -------\n self : object\n \"\"\"\n if not 3 <= self.n_bins <= 256:\n raise ValueError('n_bins={} should be no smaller than 3 and no larger than 256.'.format(self.n_bins))\n X = check_array(X, dtype=[X_DTYPE], force_all_finite=False)\n max_bins = self.n_bins - 1\n rng = check_random_state(self.random_state)\n if self.subsample is not None and X.shape[0] > self.subsample:\n subset = rng.choice(X.shape[0], self.subsample, replace=False)\n X = X.take(subset, axis=0)\n if self.is_categorical is None:\n self.is_categorical_ = np.zeros(X.shape[1], dtype=np.uint8)\n else:\n self.is_categorical_ = np.asarray(self.is_categorical, dtype=np.uint8)\n n_features = X.shape[1]\n known_categories = self.known_categories\n if known_categories is None:\n known_categories = [None] * n_features\n for f_idx in range(n_features):\n is_categorical = self.is_categorical_[f_idx]\n known_cats = known_categories[f_idx]\n if is_categorical and known_cats is None:\n raise ValueError(f'Known categories for feature {f_idx} must be provided.')\n if not is_categorical and known_cats is not None:\n raise ValueError(f\"Feature {f_idx} isn't marked as a categorical feature, but categories were passed.\")\n self.missing_values_bin_idx_ = self.n_bins - 1\n self.bin_thresholds_ = []\n n_bins_non_missing = []\n for f_idx in range(n_features):\n if not self.is_categorical_[f_idx]:\n thresholds = _find_binning_thresholds(X[:, f_idx], max_bins)\n n_bins_non_missing.append(thresholds.shape[0] + 1)\n else:\n thresholds = known_categories[f_idx]\n n_bins_non_missing.append(thresholds.shape[0])\n self.bin_thresholds_.append(thresholds)\n self.n_bins_non_missing_ = np.array(n_bins_non_missing, dtype=np.uint32)\n return self\n \n def transform(self, X):\n \"\"\"Bin data X.\n\n Missing values will be mapped to the last bin.\n\n For categorical features, the mapping will be incorrect for unknown\n categories. Since the BinMapper is given known_categories of the\n entire training data (i.e. before the call to train_test_split() in\n case of early-stopping), this never happens.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data to bin.\n\n Returns\n -------\n X_binned : array-like of shape (n_samples, n_features)\n The binned data (fortran-aligned).\n \"\"\"\n X = check_array(X, dtype=[X_DTYPE], force_all_finite=False)\n check_is_fitted(self)\n if X.shape[1] != self.n_bins_non_missing_.shape[0]:\n raise ValueError('This estimator was fitted with {} features but {} got passed to transform()'.format(self.n_bins_non_missing_.shape[0], X.shape[1]))\n n_threads = _openmp_effective_n_threads(self.n_threads)\n binned = np.zeros_like(X, dtype=X_BINNED_DTYPE, order='F')\n _map_to_bins(X, self.bin_thresholds_, self.missing_values_bin_idx_, n_threads, binned)\n return binned\n \n def make_known_categories_bitsets(self):\n \"\"\"Create bitsets of known categories.\n\n Returns\n -------\n - known_cat_bitsets : ndarray of shape (n_categorical_features, 8)\n Array of bitsets of known categories, for each categorical feature.\n - f_idx_map : ndarray of shape (n_features,)\n Map from original feature index to the corresponding index in the\n known_cat_bitsets array.\n \"\"\"\n categorical_features_indices = np.flatnonzero(self.is_categorical_)\n n_features = self.is_categorical_.size\n n_categorical_features = categorical_features_indices.size\n f_idx_map = np.zeros(n_features, dtype=np.uint32)\n f_idx_map[categorical_features_indices] = np.arange(n_categorical_features, dtype=np.uint32)\n known_categories = self.bin_thresholds_\n known_cat_bitsets = np.zeros((n_categorical_features, 8), dtype=X_BITSET_INNER_DTYPE)\n for (mapped_f_idx, f_idx) in enumerate(categorical_features_indices):\n for raw_cat_val in known_categories[f_idx]:\n set_bitset_memoryview(known_cat_bitsets[mapped_f_idx], raw_cat_val)\n return known_cat_bitsets, f_idx_map\n" + "docstring": "Transformer that maps a dataset into integer-valued bins.\n\n For continuous features, the bins are created in a feature-wise fashion,\n using quantiles so that each bins contains approximately the same number\n of samples. For large datasets, quantiles are computed on a subset of the\n data to speed-up the binning, but the quantiles should remain stable.\n\n For categorical features, the raw categorical values are expected to be\n in [0, 254] (this is not validated here though) and each category\n corresponds to a bin. All categorical values must be known at\n initialization: transform() doesn't know how to bin unknown categorical\n values. Note that transform() is only used on non-training data in the\n case of early stopping.\n\n Features with a small number of values may be binned into less than\n ``n_bins`` bins. The last bin (at index ``n_bins - 1``) is always reserved\n for missing values.\n\n Parameters\n ----------\n n_bins : int, default=256\n The maximum number of bins to use (including the bin for missing\n values). Should be in [3, 256]. Non-missing values are binned on\n ``max_bins = n_bins - 1`` bins. The last bin is always reserved for\n missing values. If for a given feature the number of unique values is\n less than ``max_bins``, then those unique values will be used to\n compute the bin thresholds, instead of the quantiles. For categorical\n features indicated by ``is_categorical``, the docstring for\n ``is_categorical`` details on this procedure.\n subsample : int or None, default=2e5\n If ``n_samples > subsample``, then ``sub_samples`` samples will be\n randomly chosen to compute the quantiles. If ``None``, the whole data\n is used.\n is_categorical : ndarray of bool of shape (n_features,), default=None\n Indicates categorical features. By default, all features are\n considered continuous.\n known_categories : list of {ndarray, None} of shape (n_features,), default=none\n For each categorical feature, the array indicates the set of unique\n categorical values. These should be the possible values over all the\n data, not just the training data. For continuous features, the\n corresponding entry should be None.\n random_state: int, RandomState instance or None, default=None\n Pseudo-random number generator to control the random sub-sampling.\n Pass an int for reproducible output across multiple\n function calls.\n See :term:`Glossary `.\n n_threads : int, default=None\n Number of OpenMP threads to use. `_openmp_effective_n_threads` is called\n to determine the effective number of threads use, which takes cgroups CPU\n quotes into account. See the docstring of `_openmp_effective_n_threads`\n for details.\n\n Attributes\n ----------\n bin_thresholds_ : list of ndarray\n For each feature, each array indicates how to map a feature into a\n binned feature. The semantic and size depends on the nature of the\n feature:\n - for real-valued features, the array corresponds to the real-valued\n bin thresholds (the upper bound of each bin). There are ``max_bins\n - 1`` thresholds, where ``max_bins = n_bins - 1`` is the number of\n bins used for non-missing values.\n - for categorical features, the array is a map from a binned category\n value to the raw category value. The size of the array is equal to\n ``min(max_bins, category_cardinality)`` where we ignore missing\n values in the cardinality.\n n_bins_non_missing_ : ndarray, dtype=np.uint32\n For each feature, gives the number of bins actually used for\n non-missing values. For features with a lot of unique values, this is\n equal to ``n_bins - 1``.\n is_categorical_ : ndarray of shape (n_features,), dtype=np.uint8\n Indicator for categorical features.\n missing_values_bin_idx_ : np.uint8\n The index of the bin where missing values are mapped. This is a\n constant across all features. This corresponds to the last bin, and\n it is always equal to ``n_bins - 1``. Note that if ``n_bins_missing_``\n is less than ``n_bins - 1`` for a given feature, then there are\n empty (and unused) bins.\n ", + "source_code": "\n\nclass _BinMapper(TransformerMixin, BaseEstimator):\n \"\"\"Transformer that maps a dataset into integer-valued bins.\n\n For continuous features, the bins are created in a feature-wise fashion,\n using quantiles so that each bins contains approximately the same number\n of samples. For large datasets, quantiles are computed on a subset of the\n data to speed-up the binning, but the quantiles should remain stable.\n\n For categorical features, the raw categorical values are expected to be\n in [0, 254] (this is not validated here though) and each category\n corresponds to a bin. All categorical values must be known at\n initialization: transform() doesn't know how to bin unknown categorical\n values. Note that transform() is only used on non-training data in the\n case of early stopping.\n\n Features with a small number of values may be binned into less than\n ``n_bins`` bins. The last bin (at index ``n_bins - 1``) is always reserved\n for missing values.\n\n Parameters\n ----------\n n_bins : int, default=256\n The maximum number of bins to use (including the bin for missing\n values). Should be in [3, 256]. Non-missing values are binned on\n ``max_bins = n_bins - 1`` bins. The last bin is always reserved for\n missing values. If for a given feature the number of unique values is\n less than ``max_bins``, then those unique values will be used to\n compute the bin thresholds, instead of the quantiles. For categorical\n features indicated by ``is_categorical``, the docstring for\n ``is_categorical`` details on this procedure.\n subsample : int or None, default=2e5\n If ``n_samples > subsample``, then ``sub_samples`` samples will be\n randomly chosen to compute the quantiles. If ``None``, the whole data\n is used.\n is_categorical : ndarray of bool of shape (n_features,), default=None\n Indicates categorical features. By default, all features are\n considered continuous.\n known_categories : list of {ndarray, None} of shape (n_features,), default=none\n For each categorical feature, the array indicates the set of unique\n categorical values. These should be the possible values over all the\n data, not just the training data. For continuous features, the\n corresponding entry should be None.\n random_state: int, RandomState instance or None, default=None\n Pseudo-random number generator to control the random sub-sampling.\n Pass an int for reproducible output across multiple\n function calls.\n See :term:`Glossary `.\n n_threads : int, default=None\n Number of OpenMP threads to use. `_openmp_effective_n_threads` is called\n to determine the effective number of threads use, which takes cgroups CPU\n quotes into account. See the docstring of `_openmp_effective_n_threads`\n for details.\n\n Attributes\n ----------\n bin_thresholds_ : list of ndarray\n For each feature, each array indicates how to map a feature into a\n binned feature. The semantic and size depends on the nature of the\n feature:\n - for real-valued features, the array corresponds to the real-valued\n bin thresholds (the upper bound of each bin). There are ``max_bins\n - 1`` thresholds, where ``max_bins = n_bins - 1`` is the number of\n bins used for non-missing values.\n - for categorical features, the array is a map from a binned category\n value to the raw category value. The size of the array is equal to\n ``min(max_bins, category_cardinality)`` where we ignore missing\n values in the cardinality.\n n_bins_non_missing_ : ndarray, dtype=np.uint32\n For each feature, gives the number of bins actually used for\n non-missing values. For features with a lot of unique values, this is\n equal to ``n_bins - 1``.\n is_categorical_ : ndarray of shape (n_features,), dtype=np.uint8\n Indicator for categorical features.\n missing_values_bin_idx_ : np.uint8\n The index of the bin where missing values are mapped. This is a\n constant across all features. This corresponds to the last bin, and\n it is always equal to ``n_bins - 1``. Note that if ``n_bins_missing_``\n is less than ``n_bins - 1`` for a given feature, then there are\n empty (and unused) bins.\n \"\"\"\n \n def __init__(self, n_bins=256, subsample=int(200000.0), is_categorical=None, known_categories=None, random_state=None, n_threads=None):\n self.n_bins = n_bins\n self.subsample = subsample\n self.is_categorical = is_categorical\n self.known_categories = known_categories\n self.random_state = random_state\n self.n_threads = n_threads\n \n def fit(self, X, y=None):\n \"\"\"Fit data X by computing the binning thresholds.\n\n The last bin is reserved for missing values, whether missing values\n are present in the data or not.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data to bin.\n y: None\n Ignored.\n\n Returns\n -------\n self : object\n \"\"\"\n if not 3 <= self.n_bins <= 256:\n raise ValueError('n_bins={} should be no smaller than 3 and no larger than 256.'.format(self.n_bins))\n X = check_array(X, dtype=[X_DTYPE], force_all_finite=False)\n max_bins = self.n_bins - 1\n rng = check_random_state(self.random_state)\n if self.subsample is not None and X.shape[0] > self.subsample:\n subset = rng.choice(X.shape[0], self.subsample, replace=False)\n X = X.take(subset, axis=0)\n if self.is_categorical is None:\n self.is_categorical_ = np.zeros(X.shape[1], dtype=np.uint8)\n else:\n self.is_categorical_ = np.asarray(self.is_categorical, dtype=np.uint8)\n n_features = X.shape[1]\n known_categories = self.known_categories\n if known_categories is None:\n known_categories = [None] * n_features\n for f_idx in range(n_features):\n is_categorical = self.is_categorical_[f_idx]\n known_cats = known_categories[f_idx]\n if is_categorical and known_cats is None:\n raise ValueError(f'Known categories for feature {f_idx} must be provided.')\n if not is_categorical and known_cats is not None:\n raise ValueError(f\"Feature {f_idx} isn't marked as a categorical feature, but categories were passed.\")\n self.missing_values_bin_idx_ = self.n_bins - 1\n self.bin_thresholds_ = []\n n_bins_non_missing = []\n for f_idx in range(n_features):\n if not self.is_categorical_[f_idx]:\n thresholds = _find_binning_thresholds(X[:, f_idx], max_bins)\n n_bins_non_missing.append(thresholds.shape[0] + 1)\n else:\n thresholds = known_categories[f_idx]\n n_bins_non_missing.append(thresholds.shape[0])\n self.bin_thresholds_.append(thresholds)\n self.n_bins_non_missing_ = np.array(n_bins_non_missing, dtype=np.uint32)\n return self\n \n def transform(self, X):\n \"\"\"Bin data X.\n\n Missing values will be mapped to the last bin.\n\n For categorical features, the mapping will be incorrect for unknown\n categories. Since the BinMapper is given known_categories of the\n entire training data (i.e. before the call to train_test_split() in\n case of early-stopping), this never happens.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data to bin.\n\n Returns\n -------\n X_binned : array-like of shape (n_samples, n_features)\n The binned data (fortran-aligned).\n \"\"\"\n X = check_array(X, dtype=[X_DTYPE], force_all_finite=False)\n check_is_fitted(self)\n if X.shape[1] != self.n_bins_non_missing_.shape[0]:\n raise ValueError('This estimator was fitted with {} features but {} got passed to transform()'.format(self.n_bins_non_missing_.shape[0], X.shape[1]))\n n_threads = _openmp_effective_n_threads(self.n_threads)\n binned = np.zeros_like(X, dtype=X_BINNED_DTYPE, order='F')\n _map_to_bins(X, self.bin_thresholds_, self.missing_values_bin_idx_, n_threads, binned)\n return binned\n \n def make_known_categories_bitsets(self):\n \"\"\"Create bitsets of known categories.\n\n Returns\n -------\n - known_cat_bitsets : ndarray of shape (n_categorical_features, 8)\n Array of bitsets of known categories, for each categorical feature.\n - f_idx_map : ndarray of shape (n_features,)\n Map from original feature index to the corresponding index in the\n known_cat_bitsets array.\n \"\"\"\n categorical_features_indices = np.flatnonzero(self.is_categorical_)\n n_features = self.is_categorical_.size\n n_categorical_features = categorical_features_indices.size\n f_idx_map = np.zeros(n_features, dtype=np.uint32)\n f_idx_map[categorical_features_indices] = np.arange(n_categorical_features, dtype=np.uint32)\n known_categories = self.bin_thresholds_\n known_cat_bitsets = np.zeros((n_categorical_features, 8), dtype=X_BITSET_INNER_DTYPE)\n for (mapped_f_idx, f_idx) in enumerate(categorical_features_indices):\n for raw_cat_val in known_categories[f_idx]:\n set_bitset_memoryview(known_cat_bitsets[mapped_f_idx], raw_cat_val)\n return known_cat_bitsets, f_idx_map\n" }, { "name": "BaseHistGradientBoosting", @@ -21344,7 +21311,7 @@ "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._more_tags", "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._get_loss", "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._encode_y", - "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting.n_iter_" + "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting.n_iter_@getter" ], "is_public": false, "description": "Base class for histogram-based gradient boosting estimators.", @@ -21386,8 +21353,8 @@ ], "is_public": true, "description": "Histogram-based Gradient Boosting Regression Tree.\n\nThis estimator is much faster than :class:`GradientBoostingRegressor` for big datasets (n_samples >= 10 000). This estimator has native support for missing values (NaNs). During training, the tree grower learns at each split point whether samples with missing values should go to the left or right child, based on the potential gain. When predicting, samples with missing values are assigned to the left or right child consequently. If no missing values were encountered for a given feature during training, then samples with missing values are mapped to whichever child has the most samples. This implementation is inspired by `LightGBM `_. Read more in the :ref:`User Guide `. .. versionadded:: 0.21", - "docstring": "Histogram-based Gradient Boosting Regression Tree.\n\n This estimator is much faster than\n :class:`GradientBoostingRegressor`\n for big datasets (n_samples >= 10 000).\n\n This estimator has native support for missing values (NaNs). During\n training, the tree grower learns at each split point whether samples\n with missing values should go to the left or right child, based on the\n potential gain. When predicting, samples with missing values are\n assigned to the left or right child consequently. If no missing values\n were encountered for a given feature during training, then samples with\n missing values are mapped to whichever child has the most samples.\n\n This implementation is inspired by\n `LightGBM `_.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.21\n\n Parameters\n ----------\n loss : {'squared_error', 'least_squares', 'absolute_error', 'least_absolute_deviation', 'poisson'}, default='squared_error'\n The loss function to use in the boosting process. Note that the\n \"least squares\" and \"poisson\" losses actually implement\n \"half least squares loss\" and \"half poisson deviance\" to simplify the\n computation of the gradient. Furthermore, \"poisson\" loss internally\n uses a log-link and requires ``y >= 0``.\n\n .. versionchanged:: 0.23\n Added option 'poisson'.\n\n .. deprecated:: 1.0\n The loss 'least_squares' was deprecated in v1.0 and will be removed\n in version 1.2. Use `loss='squared_error'` which is equivalent.\n\n .. deprecated:: 1.0\n The loss 'least_absolute_deviation' was deprecated in v1.0 and will\n be removed in version 1.2. Use `loss='absolute_error'` which is\n equivalent.\n\n learning_rate : float, default=0.1\n The learning rate, also known as *shrinkage*. This is used as a\n multiplicative factor for the leaves values. Use ``1`` for no\n shrinkage.\n max_iter : int, default=100\n The maximum number of iterations of the boosting process, i.e. the\n maximum number of trees.\n max_leaf_nodes : int or None, default=31\n The maximum number of leaves for each tree. Must be strictly greater\n than 1. If None, there is no maximum limit.\n max_depth : int or None, default=None\n The maximum depth of each tree. The depth of a tree is the number of\n edges to go from the root to the deepest leaf.\n Depth isn't constrained by default.\n min_samples_leaf : int, default=20\n The minimum number of samples per leaf. For small datasets with less\n than a few hundred samples, it is recommended to lower this value\n since only very shallow trees would be built.\n l2_regularization : float, default=0\n The L2 regularization parameter. Use ``0`` for no regularization\n (default).\n max_bins : int, default=255\n The maximum number of bins to use for non-missing values. Before\n training, each feature of the input array `X` is binned into\n integer-valued bins, which allows for a much faster training stage.\n Features with a small number of unique values may use less than\n ``max_bins`` bins. In addition to the ``max_bins`` bins, one more bin\n is always reserved for missing values. Must be no larger than 255.\n categorical_features : array-like of {bool, int} of shape (n_features) or shape (n_categorical_features,), default=None\n Indicates the categorical features.\n\n - None : no feature will be considered categorical.\n - boolean array-like : boolean mask indicating categorical features.\n - integer array-like : integer indices indicating categorical\n features.\n\n For each categorical feature, there must be at most `max_bins` unique\n categories, and each categorical value must be in [0, max_bins -1].\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.24\n\n monotonic_cst : array-like of int of shape (n_features), default=None\n Indicates the monotonic constraint to enforce on each feature. -1, 1\n and 0 respectively correspond to a negative constraint, positive\n constraint and no constraint. Read more in the :ref:`User Guide\n `.\n\n .. versionadded:: 0.23\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit\n and add more estimators to the ensemble. For results to be valid, the\n estimator should be re-trained on the same data only.\n See :term:`the Glossary `.\n early_stopping : 'auto' or bool, default='auto'\n If 'auto', early stopping is enabled if the sample size is larger than\n 10000. If True, early stopping is enabled, otherwise early stopping is\n disabled.\n\n .. versionadded:: 0.23\n\n scoring : str or callable or None, default='loss'\n Scoring parameter to use for early stopping. It can be a single\n string (see :ref:`scoring_parameter`) or a callable (see\n :ref:`scoring`). If None, the estimator's default scorer is used. If\n ``scoring='loss'``, early stopping is checked w.r.t the loss value.\n Only used if early stopping is performed.\n validation_fraction : int or float or None, default=0.1\n Proportion (or absolute size) of training data to set aside as\n validation data for early stopping. If None, early stopping is done on\n the training data. Only used if early stopping is performed.\n n_iter_no_change : int, default=10\n Used to determine when to \"early stop\". The fitting process is\n stopped when none of the last ``n_iter_no_change`` scores are better\n than the ``n_iter_no_change - 1`` -th-to-last one, up to some\n tolerance. Only used if early stopping is performed.\n tol : float, default=1e-7\n The absolute tolerance to use when comparing scores during early\n stopping. The higher the tolerance, the more likely we are to early\n stop: higher tolerance means that it will be harder for subsequent\n iterations to be considered an improvement upon the reference score.\n verbose : int, default=0\n The verbosity level. If not zero, print some information about the\n fitting process.\n random_state : int, RandomState instance or None, default=None\n Pseudo-random number generator to control the subsampling in the\n binning process, and the train/validation data split if early stopping\n is enabled.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n Attributes\n ----------\n do_early_stopping_ : bool\n Indicates whether early stopping is used during training.\n n_iter_ : int\n The number of iterations as selected by early stopping, depending on\n the `early_stopping` parameter. Otherwise it corresponds to max_iter.\n n_trees_per_iteration_ : int\n The number of tree that are built at each iteration. For regressors,\n this is always 1.\n train_score_ : ndarray, shape (n_iter_+1,)\n The scores at each iteration on the training data. The first entry\n is the score of the ensemble before the first iteration. Scores are\n computed according to the ``scoring`` parameter. If ``scoring`` is\n not 'loss', scores are computed on a subset of at most 10 000\n samples. Empty if no early stopping.\n validation_score_ : ndarray, shape (n_iter_+1,)\n The scores at each iteration on the held-out validation data. The\n first entry is the score of the ensemble before the first iteration.\n Scores are computed according to the ``scoring`` parameter. Empty if\n no early stopping or if ``validation_fraction`` is None.\n is_categorical_ : ndarray, shape (n_features, ) or None\n Boolean mask for the categorical features. ``None`` if there are no\n categorical features.\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n GradientBoostingRegressor : Exact gradient boosting method that does not\n scale as good on datasets with a large number of samples.\n sklearn.tree.DecisionTreeRegressor : A decision tree regressor.\n RandomForestRegressor : A meta-estimator that fits a number of decision\n tree regressors on various sub-samples of the dataset and uses\n averaging to improve the statistical performance and control\n over-fitting.\n AdaBoostRegressor : A meta-estimator that begins by fitting a regressor\n on the original dataset and then fits additional copies of the\n regressor on the same dataset but where the weights of instances are\n adjusted according to the error of the current prediction. As such,\n subsequent regressors focus more on difficult cases.\n\n Examples\n --------\n >>> from sklearn.ensemble import HistGradientBoostingRegressor\n >>> from sklearn.datasets import load_diabetes\n >>> X, y = load_diabetes(return_X_y=True)\n >>> est = HistGradientBoostingRegressor().fit(X, y)\n >>> est.score(X, y)\n 0.92...\n ", - "source_code": "\n\nclass HistGradientBoostingRegressor(RegressorMixin, BaseHistGradientBoosting):\n \"\"\"Histogram-based Gradient Boosting Regression Tree.\n\n This estimator is much faster than\n :class:`GradientBoostingRegressor`\n for big datasets (n_samples >= 10 000).\n\n This estimator has native support for missing values (NaNs). During\n training, the tree grower learns at each split point whether samples\n with missing values should go to the left or right child, based on the\n potential gain. When predicting, samples with missing values are\n assigned to the left or right child consequently. If no missing values\n were encountered for a given feature during training, then samples with\n missing values are mapped to whichever child has the most samples.\n\n This implementation is inspired by\n `LightGBM `_.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.21\n\n Parameters\n ----------\n loss : {'squared_error', 'least_squares', 'absolute_error', 'least_absolute_deviation', 'poisson'}, default='squared_error'\n The loss function to use in the boosting process. Note that the\n \"least squares\" and \"poisson\" losses actually implement\n \"half least squares loss\" and \"half poisson deviance\" to simplify the\n computation of the gradient. Furthermore, \"poisson\" loss internally\n uses a log-link and requires ``y >= 0``.\n\n .. versionchanged:: 0.23\n Added option 'poisson'.\n\n .. deprecated:: 1.0\n The loss 'least_squares' was deprecated in v1.0 and will be removed\n in version 1.2. Use `loss='squared_error'` which is equivalent.\n\n .. deprecated:: 1.0\n The loss 'least_absolute_deviation' was deprecated in v1.0 and will\n be removed in version 1.2. Use `loss='absolute_error'` which is\n equivalent.\n\n learning_rate : float, default=0.1\n The learning rate, also known as *shrinkage*. This is used as a\n multiplicative factor for the leaves values. Use ``1`` for no\n shrinkage.\n max_iter : int, default=100\n The maximum number of iterations of the boosting process, i.e. the\n maximum number of trees.\n max_leaf_nodes : int or None, default=31\n The maximum number of leaves for each tree. Must be strictly greater\n than 1. If None, there is no maximum limit.\n max_depth : int or None, default=None\n The maximum depth of each tree. The depth of a tree is the number of\n edges to go from the root to the deepest leaf.\n Depth isn't constrained by default.\n min_samples_leaf : int, default=20\n The minimum number of samples per leaf. For small datasets with less\n than a few hundred samples, it is recommended to lower this value\n since only very shallow trees would be built.\n l2_regularization : float, default=0\n The L2 regularization parameter. Use ``0`` for no regularization\n (default).\n max_bins : int, default=255\n The maximum number of bins to use for non-missing values. Before\n training, each feature of the input array `X` is binned into\n integer-valued bins, which allows for a much faster training stage.\n Features with a small number of unique values may use less than\n ``max_bins`` bins. In addition to the ``max_bins`` bins, one more bin\n is always reserved for missing values. Must be no larger than 255.\n categorical_features : array-like of {bool, int} of shape (n_features) or shape (n_categorical_features,), default=None\n Indicates the categorical features.\n\n - None : no feature will be considered categorical.\n - boolean array-like : boolean mask indicating categorical features.\n - integer array-like : integer indices indicating categorical\n features.\n\n For each categorical feature, there must be at most `max_bins` unique\n categories, and each categorical value must be in [0, max_bins -1].\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.24\n\n monotonic_cst : array-like of int of shape (n_features), default=None\n Indicates the monotonic constraint to enforce on each feature. -1, 1\n and 0 respectively correspond to a negative constraint, positive\n constraint and no constraint. Read more in the :ref:`User Guide\n `.\n\n .. versionadded:: 0.23\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit\n and add more estimators to the ensemble. For results to be valid, the\n estimator should be re-trained on the same data only.\n See :term:`the Glossary `.\n early_stopping : 'auto' or bool, default='auto'\n If 'auto', early stopping is enabled if the sample size is larger than\n 10000. If True, early stopping is enabled, otherwise early stopping is\n disabled.\n\n .. versionadded:: 0.23\n\n scoring : str or callable or None, default='loss'\n Scoring parameter to use for early stopping. It can be a single\n string (see :ref:`scoring_parameter`) or a callable (see\n :ref:`scoring`). If None, the estimator's default scorer is used. If\n ``scoring='loss'``, early stopping is checked w.r.t the loss value.\n Only used if early stopping is performed.\n validation_fraction : int or float or None, default=0.1\n Proportion (or absolute size) of training data to set aside as\n validation data for early stopping. If None, early stopping is done on\n the training data. Only used if early stopping is performed.\n n_iter_no_change : int, default=10\n Used to determine when to \"early stop\". The fitting process is\n stopped when none of the last ``n_iter_no_change`` scores are better\n than the ``n_iter_no_change - 1`` -th-to-last one, up to some\n tolerance. Only used if early stopping is performed.\n tol : float, default=1e-7\n The absolute tolerance to use when comparing scores during early\n stopping. The higher the tolerance, the more likely we are to early\n stop: higher tolerance means that it will be harder for subsequent\n iterations to be considered an improvement upon the reference score.\n verbose : int, default=0\n The verbosity level. If not zero, print some information about the\n fitting process.\n random_state : int, RandomState instance or None, default=None\n Pseudo-random number generator to control the subsampling in the\n binning process, and the train/validation data split if early stopping\n is enabled.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n Attributes\n ----------\n do_early_stopping_ : bool\n Indicates whether early stopping is used during training.\n n_iter_ : int\n The number of iterations as selected by early stopping, depending on\n the `early_stopping` parameter. Otherwise it corresponds to max_iter.\n n_trees_per_iteration_ : int\n The number of tree that are built at each iteration. For regressors,\n this is always 1.\n train_score_ : ndarray, shape (n_iter_+1,)\n The scores at each iteration on the training data. The first entry\n is the score of the ensemble before the first iteration. Scores are\n computed according to the ``scoring`` parameter. If ``scoring`` is\n not 'loss', scores are computed on a subset of at most 10 000\n samples. Empty if no early stopping.\n validation_score_ : ndarray, shape (n_iter_+1,)\n The scores at each iteration on the held-out validation data. The\n first entry is the score of the ensemble before the first iteration.\n Scores are computed according to the ``scoring`` parameter. Empty if\n no early stopping or if ``validation_fraction`` is None.\n is_categorical_ : ndarray, shape (n_features, ) or None\n Boolean mask for the categorical features. ``None`` if there are no\n categorical features.\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n GradientBoostingRegressor : Exact gradient boosting method that does not\n scale as good on datasets with a large number of samples.\n sklearn.tree.DecisionTreeRegressor : A decision tree regressor.\n RandomForestRegressor : A meta-estimator that fits a number of decision\n tree regressors on various sub-samples of the dataset and uses\n averaging to improve the statistical performance and control\n over-fitting.\n AdaBoostRegressor : A meta-estimator that begins by fitting a regressor\n on the original dataset and then fits additional copies of the\n regressor on the same dataset but where the weights of instances are\n adjusted according to the error of the current prediction. As such,\n subsequent regressors focus more on difficult cases.\n\n Examples\n --------\n >>> from sklearn.ensemble import HistGradientBoostingRegressor\n >>> from sklearn.datasets import load_diabetes\n >>> X, y = load_diabetes(return_X_y=True)\n >>> est = HistGradientBoostingRegressor().fit(X, y)\n >>> est.score(X, y)\n 0.92...\n \"\"\"\n _VALID_LOSSES = ('squared_error', 'least_squares', 'absolute_error', 'least_absolute_deviation', 'poisson')\n \n def __init__(self, loss='squared_error', *, learning_rate=0.1, max_iter=100, max_leaf_nodes=31, max_depth=None, min_samples_leaf=20, l2_regularization=0.0, max_bins=255, categorical_features=None, monotonic_cst=None, warm_start=False, early_stopping='auto', scoring='loss', validation_fraction=0.1, n_iter_no_change=10, tol=1e-07, verbose=0, random_state=None):\n super(HistGradientBoostingRegressor, self).__init__(loss=loss, learning_rate=learning_rate, max_iter=max_iter, max_leaf_nodes=max_leaf_nodes, max_depth=max_depth, min_samples_leaf=min_samples_leaf, l2_regularization=l2_regularization, max_bins=max_bins, monotonic_cst=monotonic_cst, categorical_features=categorical_features, early_stopping=early_stopping, warm_start=warm_start, scoring=scoring, validation_fraction=validation_fraction, n_iter_no_change=n_iter_no_change, tol=tol, verbose=verbose, random_state=random_state)\n \n def predict(self, X):\n \"\"\"Predict values for X.\n\n Parameters\n ----------\n X : array-like, shape (n_samples, n_features)\n The input samples.\n\n Returns\n -------\n y : ndarray, shape (n_samples,)\n The predicted values.\n \"\"\"\n check_is_fitted(self)\n return self._loss.inverse_link_function(self._raw_predict(X).ravel())\n \n def staged_predict(self, X):\n \"\"\"Predict regression target for each iteration.\n\n This method allows monitoring (i.e. determine error on testing set)\n after each stage.\n\n .. versionadded:: 0.24\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The input samples.\n\n Yields\n -------\n y : generator of ndarray of shape (n_samples,)\n The predicted values of the input samples, for each iteration.\n \"\"\"\n for raw_predictions in self._staged_raw_predict(X):\n yield self._loss.inverse_link_function(raw_predictions.ravel())\n \n def _encode_y(self, y):\n self.n_trees_per_iteration_ = 1\n y = y.astype(Y_DTYPE, copy=False)\n if self.loss == 'poisson':\n if not (np.all(y >= 0) and np.sum(y) > 0):\n raise ValueError(\"loss='poisson' requires non-negative y and sum(y) > 0.\")\n return y\n \n def _get_loss(self, sample_weight, n_threads):\n if self.loss == 'least_squares':\n warnings.warn(\"The loss 'least_squares' was deprecated in v1.0 and will be removed in version 1.2. Use 'squared_error' which is equivalent.\", FutureWarning)\n return _LOSSES['squared_error'](sample_weight=sample_weight, n_threads=n_threads)\n elif self.loss == 'least_absolute_deviation':\n warnings.warn(\"The loss 'least_absolute_deviation' was deprecated in v1.0 and will be removed in version 1.2. Use 'absolute_error' which is equivalent.\", FutureWarning)\n return _LOSSES['absolute_error'](sample_weight=sample_weight, n_threads=n_threads)\n return _LOSSES[self.loss](sample_weight=sample_weight, n_threads=n_threads)\n" + "docstring": "Histogram-based Gradient Boosting Regression Tree.\n\n This estimator is much faster than\n :class:`GradientBoostingRegressor`\n for big datasets (n_samples >= 10 000).\n\n This estimator has native support for missing values (NaNs). During\n training, the tree grower learns at each split point whether samples\n with missing values should go to the left or right child, based on the\n potential gain. When predicting, samples with missing values are\n assigned to the left or right child consequently. If no missing values\n were encountered for a given feature during training, then samples with\n missing values are mapped to whichever child has the most samples.\n\n This implementation is inspired by\n `LightGBM `_.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.21\n\n Parameters\n ----------\n loss : {'squared_error', 'absolute_error', 'poisson'}, default='squared_error'\n The loss function to use in the boosting process. Note that the\n \"squared error\" and \"poisson\" losses actually implement\n \"half least squares loss\" and \"half poisson deviance\" to simplify the\n computation of the gradient. Furthermore, \"poisson\" loss internally\n uses a log-link and requires ``y >= 0``.\n\n .. versionchanged:: 0.23\n Added option 'poisson'.\n\n .. deprecated:: 1.0\n The loss 'least_squares' was deprecated in v1.0 and will be removed\n in version 1.2. Use `loss='squared_error'` which is equivalent.\n\n .. deprecated:: 1.0\n The loss 'least_absolute_deviation' was deprecated in v1.0 and will\n be removed in version 1.2. Use `loss='absolute_error'` which is\n equivalent.\n\n learning_rate : float, default=0.1\n The learning rate, also known as *shrinkage*. This is used as a\n multiplicative factor for the leaves values. Use ``1`` for no\n shrinkage.\n max_iter : int, default=100\n The maximum number of iterations of the boosting process, i.e. the\n maximum number of trees.\n max_leaf_nodes : int or None, default=31\n The maximum number of leaves for each tree. Must be strictly greater\n than 1. If None, there is no maximum limit.\n max_depth : int or None, default=None\n The maximum depth of each tree. The depth of a tree is the number of\n edges to go from the root to the deepest leaf.\n Depth isn't constrained by default.\n min_samples_leaf : int, default=20\n The minimum number of samples per leaf. For small datasets with less\n than a few hundred samples, it is recommended to lower this value\n since only very shallow trees would be built.\n l2_regularization : float, default=0\n The L2 regularization parameter. Use ``0`` for no regularization\n (default).\n max_bins : int, default=255\n The maximum number of bins to use for non-missing values. Before\n training, each feature of the input array `X` is binned into\n integer-valued bins, which allows for a much faster training stage.\n Features with a small number of unique values may use less than\n ``max_bins`` bins. In addition to the ``max_bins`` bins, one more bin\n is always reserved for missing values. Must be no larger than 255.\n categorical_features : array-like of {bool, int} of shape (n_features) or shape (n_categorical_features,), default=None\n Indicates the categorical features.\n\n - None : no feature will be considered categorical.\n - boolean array-like : boolean mask indicating categorical features.\n - integer array-like : integer indices indicating categorical\n features.\n\n For each categorical feature, there must be at most `max_bins` unique\n categories, and each categorical value must be in [0, max_bins -1].\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.24\n\n monotonic_cst : array-like of int of shape (n_features), default=None\n Indicates the monotonic constraint to enforce on each feature. -1, 1\n and 0 respectively correspond to a negative constraint, positive\n constraint and no constraint. Read more in the :ref:`User Guide\n `.\n\n .. versionadded:: 0.23\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit\n and add more estimators to the ensemble. For results to be valid, the\n estimator should be re-trained on the same data only.\n See :term:`the Glossary `.\n early_stopping : 'auto' or bool, default='auto'\n If 'auto', early stopping is enabled if the sample size is larger than\n 10000. If True, early stopping is enabled, otherwise early stopping is\n disabled.\n\n .. versionadded:: 0.23\n\n scoring : str or callable or None, default='loss'\n Scoring parameter to use for early stopping. It can be a single\n string (see :ref:`scoring_parameter`) or a callable (see\n :ref:`scoring`). If None, the estimator's default scorer is used. If\n ``scoring='loss'``, early stopping is checked w.r.t the loss value.\n Only used if early stopping is performed.\n validation_fraction : int or float or None, default=0.1\n Proportion (or absolute size) of training data to set aside as\n validation data for early stopping. If None, early stopping is done on\n the training data. Only used if early stopping is performed.\n n_iter_no_change : int, default=10\n Used to determine when to \"early stop\". The fitting process is\n stopped when none of the last ``n_iter_no_change`` scores are better\n than the ``n_iter_no_change - 1`` -th-to-last one, up to some\n tolerance. Only used if early stopping is performed.\n tol : float, default=1e-7\n The absolute tolerance to use when comparing scores during early\n stopping. The higher the tolerance, the more likely we are to early\n stop: higher tolerance means that it will be harder for subsequent\n iterations to be considered an improvement upon the reference score.\n verbose : int, default=0\n The verbosity level. If not zero, print some information about the\n fitting process.\n random_state : int, RandomState instance or None, default=None\n Pseudo-random number generator to control the subsampling in the\n binning process, and the train/validation data split if early stopping\n is enabled.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n Attributes\n ----------\n do_early_stopping_ : bool\n Indicates whether early stopping is used during training.\n n_iter_ : int\n The number of iterations as selected by early stopping, depending on\n the `early_stopping` parameter. Otherwise it corresponds to max_iter.\n n_trees_per_iteration_ : int\n The number of tree that are built at each iteration. For regressors,\n this is always 1.\n train_score_ : ndarray, shape (n_iter_+1,)\n The scores at each iteration on the training data. The first entry\n is the score of the ensemble before the first iteration. Scores are\n computed according to the ``scoring`` parameter. If ``scoring`` is\n not 'loss', scores are computed on a subset of at most 10 000\n samples. Empty if no early stopping.\n validation_score_ : ndarray, shape (n_iter_+1,)\n The scores at each iteration on the held-out validation data. The\n first entry is the score of the ensemble before the first iteration.\n Scores are computed according to the ``scoring`` parameter. Empty if\n no early stopping or if ``validation_fraction`` is None.\n is_categorical_ : ndarray, shape (n_features, ) or None\n Boolean mask for the categorical features. ``None`` if there are no\n categorical features.\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n GradientBoostingRegressor : Exact gradient boosting method that does not\n scale as good on datasets with a large number of samples.\n sklearn.tree.DecisionTreeRegressor : A decision tree regressor.\n RandomForestRegressor : A meta-estimator that fits a number of decision\n tree regressors on various sub-samples of the dataset and uses\n averaging to improve the statistical performance and control\n over-fitting.\n AdaBoostRegressor : A meta-estimator that begins by fitting a regressor\n on the original dataset and then fits additional copies of the\n regressor on the same dataset but where the weights of instances are\n adjusted according to the error of the current prediction. As such,\n subsequent regressors focus more on difficult cases.\n\n Examples\n --------\n >>> from sklearn.ensemble import HistGradientBoostingRegressor\n >>> from sklearn.datasets import load_diabetes\n >>> X, y = load_diabetes(return_X_y=True)\n >>> est = HistGradientBoostingRegressor().fit(X, y)\n >>> est.score(X, y)\n 0.92...\n ", + "source_code": "\n\nclass HistGradientBoostingRegressor(RegressorMixin, BaseHistGradientBoosting):\n \"\"\"Histogram-based Gradient Boosting Regression Tree.\n\n This estimator is much faster than\n :class:`GradientBoostingRegressor`\n for big datasets (n_samples >= 10 000).\n\n This estimator has native support for missing values (NaNs). During\n training, the tree grower learns at each split point whether samples\n with missing values should go to the left or right child, based on the\n potential gain. When predicting, samples with missing values are\n assigned to the left or right child consequently. If no missing values\n were encountered for a given feature during training, then samples with\n missing values are mapped to whichever child has the most samples.\n\n This implementation is inspired by\n `LightGBM `_.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.21\n\n Parameters\n ----------\n loss : {'squared_error', 'absolute_error', 'poisson'}, default='squared_error'\n The loss function to use in the boosting process. Note that the\n \"squared error\" and \"poisson\" losses actually implement\n \"half least squares loss\" and \"half poisson deviance\" to simplify the\n computation of the gradient. Furthermore, \"poisson\" loss internally\n uses a log-link and requires ``y >= 0``.\n\n .. versionchanged:: 0.23\n Added option 'poisson'.\n\n .. deprecated:: 1.0\n The loss 'least_squares' was deprecated in v1.0 and will be removed\n in version 1.2. Use `loss='squared_error'` which is equivalent.\n\n .. deprecated:: 1.0\n The loss 'least_absolute_deviation' was deprecated in v1.0 and will\n be removed in version 1.2. Use `loss='absolute_error'` which is\n equivalent.\n\n learning_rate : float, default=0.1\n The learning rate, also known as *shrinkage*. This is used as a\n multiplicative factor for the leaves values. Use ``1`` for no\n shrinkage.\n max_iter : int, default=100\n The maximum number of iterations of the boosting process, i.e. the\n maximum number of trees.\n max_leaf_nodes : int or None, default=31\n The maximum number of leaves for each tree. Must be strictly greater\n than 1. If None, there is no maximum limit.\n max_depth : int or None, default=None\n The maximum depth of each tree. The depth of a tree is the number of\n edges to go from the root to the deepest leaf.\n Depth isn't constrained by default.\n min_samples_leaf : int, default=20\n The minimum number of samples per leaf. For small datasets with less\n than a few hundred samples, it is recommended to lower this value\n since only very shallow trees would be built.\n l2_regularization : float, default=0\n The L2 regularization parameter. Use ``0`` for no regularization\n (default).\n max_bins : int, default=255\n The maximum number of bins to use for non-missing values. Before\n training, each feature of the input array `X` is binned into\n integer-valued bins, which allows for a much faster training stage.\n Features with a small number of unique values may use less than\n ``max_bins`` bins. In addition to the ``max_bins`` bins, one more bin\n is always reserved for missing values. Must be no larger than 255.\n categorical_features : array-like of {bool, int} of shape (n_features) or shape (n_categorical_features,), default=None\n Indicates the categorical features.\n\n - None : no feature will be considered categorical.\n - boolean array-like : boolean mask indicating categorical features.\n - integer array-like : integer indices indicating categorical\n features.\n\n For each categorical feature, there must be at most `max_bins` unique\n categories, and each categorical value must be in [0, max_bins -1].\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.24\n\n monotonic_cst : array-like of int of shape (n_features), default=None\n Indicates the monotonic constraint to enforce on each feature. -1, 1\n and 0 respectively correspond to a negative constraint, positive\n constraint and no constraint. Read more in the :ref:`User Guide\n `.\n\n .. versionadded:: 0.23\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit\n and add more estimators to the ensemble. For results to be valid, the\n estimator should be re-trained on the same data only.\n See :term:`the Glossary `.\n early_stopping : 'auto' or bool, default='auto'\n If 'auto', early stopping is enabled if the sample size is larger than\n 10000. If True, early stopping is enabled, otherwise early stopping is\n disabled.\n\n .. versionadded:: 0.23\n\n scoring : str or callable or None, default='loss'\n Scoring parameter to use for early stopping. It can be a single\n string (see :ref:`scoring_parameter`) or a callable (see\n :ref:`scoring`). If None, the estimator's default scorer is used. If\n ``scoring='loss'``, early stopping is checked w.r.t the loss value.\n Only used if early stopping is performed.\n validation_fraction : int or float or None, default=0.1\n Proportion (or absolute size) of training data to set aside as\n validation data for early stopping. If None, early stopping is done on\n the training data. Only used if early stopping is performed.\n n_iter_no_change : int, default=10\n Used to determine when to \"early stop\". The fitting process is\n stopped when none of the last ``n_iter_no_change`` scores are better\n than the ``n_iter_no_change - 1`` -th-to-last one, up to some\n tolerance. Only used if early stopping is performed.\n tol : float, default=1e-7\n The absolute tolerance to use when comparing scores during early\n stopping. The higher the tolerance, the more likely we are to early\n stop: higher tolerance means that it will be harder for subsequent\n iterations to be considered an improvement upon the reference score.\n verbose : int, default=0\n The verbosity level. If not zero, print some information about the\n fitting process.\n random_state : int, RandomState instance or None, default=None\n Pseudo-random number generator to control the subsampling in the\n binning process, and the train/validation data split if early stopping\n is enabled.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n Attributes\n ----------\n do_early_stopping_ : bool\n Indicates whether early stopping is used during training.\n n_iter_ : int\n The number of iterations as selected by early stopping, depending on\n the `early_stopping` parameter. Otherwise it corresponds to max_iter.\n n_trees_per_iteration_ : int\n The number of tree that are built at each iteration. For regressors,\n this is always 1.\n train_score_ : ndarray, shape (n_iter_+1,)\n The scores at each iteration on the training data. The first entry\n is the score of the ensemble before the first iteration. Scores are\n computed according to the ``scoring`` parameter. If ``scoring`` is\n not 'loss', scores are computed on a subset of at most 10 000\n samples. Empty if no early stopping.\n validation_score_ : ndarray, shape (n_iter_+1,)\n The scores at each iteration on the held-out validation data. The\n first entry is the score of the ensemble before the first iteration.\n Scores are computed according to the ``scoring`` parameter. Empty if\n no early stopping or if ``validation_fraction`` is None.\n is_categorical_ : ndarray, shape (n_features, ) or None\n Boolean mask for the categorical features. ``None`` if there are no\n categorical features.\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n GradientBoostingRegressor : Exact gradient boosting method that does not\n scale as good on datasets with a large number of samples.\n sklearn.tree.DecisionTreeRegressor : A decision tree regressor.\n RandomForestRegressor : A meta-estimator that fits a number of decision\n tree regressors on various sub-samples of the dataset and uses\n averaging to improve the statistical performance and control\n over-fitting.\n AdaBoostRegressor : A meta-estimator that begins by fitting a regressor\n on the original dataset and then fits additional copies of the\n regressor on the same dataset but where the weights of instances are\n adjusted according to the error of the current prediction. As such,\n subsequent regressors focus more on difficult cases.\n\n Examples\n --------\n >>> from sklearn.ensemble import HistGradientBoostingRegressor\n >>> from sklearn.datasets import load_diabetes\n >>> X, y = load_diabetes(return_X_y=True)\n >>> est = HistGradientBoostingRegressor().fit(X, y)\n >>> est.score(X, y)\n 0.92...\n \"\"\"\n _VALID_LOSSES = ('squared_error', 'least_squares', 'absolute_error', 'least_absolute_deviation', 'poisson')\n \n def __init__(self, loss='squared_error', *, learning_rate=0.1, max_iter=100, max_leaf_nodes=31, max_depth=None, min_samples_leaf=20, l2_regularization=0.0, max_bins=255, categorical_features=None, monotonic_cst=None, warm_start=False, early_stopping='auto', scoring='loss', validation_fraction=0.1, n_iter_no_change=10, tol=1e-07, verbose=0, random_state=None):\n super(HistGradientBoostingRegressor, self).__init__(loss=loss, learning_rate=learning_rate, max_iter=max_iter, max_leaf_nodes=max_leaf_nodes, max_depth=max_depth, min_samples_leaf=min_samples_leaf, l2_regularization=l2_regularization, max_bins=max_bins, monotonic_cst=monotonic_cst, categorical_features=categorical_features, early_stopping=early_stopping, warm_start=warm_start, scoring=scoring, validation_fraction=validation_fraction, n_iter_no_change=n_iter_no_change, tol=tol, verbose=verbose, random_state=random_state)\n \n def predict(self, X):\n \"\"\"Predict values for X.\n\n Parameters\n ----------\n X : array-like, shape (n_samples, n_features)\n The input samples.\n\n Returns\n -------\n y : ndarray, shape (n_samples,)\n The predicted values.\n \"\"\"\n check_is_fitted(self)\n return self._loss.inverse_link_function(self._raw_predict(X).ravel())\n \n def staged_predict(self, X):\n \"\"\"Predict regression target for each iteration.\n\n This method allows monitoring (i.e. determine error on testing set)\n after each stage.\n\n .. versionadded:: 0.24\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The input samples.\n\n Yields\n -------\n y : generator of ndarray of shape (n_samples,)\n The predicted values of the input samples, for each iteration.\n \"\"\"\n for raw_predictions in self._staged_raw_predict(X):\n yield self._loss.inverse_link_function(raw_predictions.ravel())\n \n def _encode_y(self, y):\n self.n_trees_per_iteration_ = 1\n y = y.astype(Y_DTYPE, copy=False)\n if self.loss == 'poisson':\n if not (np.all(y >= 0) and np.sum(y) > 0):\n raise ValueError(\"loss='poisson' requires non-negative y and sum(y) > 0.\")\n return y\n \n def _get_loss(self, sample_weight, n_threads):\n if self.loss == 'least_squares':\n warnings.warn(\"The loss 'least_squares' was deprecated in v1.0 and will be removed in version 1.2. Use 'squared_error' which is equivalent.\", FutureWarning)\n return _LOSSES['squared_error'](sample_weight=sample_weight, n_threads=n_threads)\n elif self.loss == 'least_absolute_deviation':\n warnings.warn(\"The loss 'least_absolute_deviation' was deprecated in v1.0 and will be removed in version 1.2. Use 'absolute_error' which is equivalent.\", FutureWarning)\n return _LOSSES['absolute_error'](sample_weight=sample_weight, n_threads=n_threads)\n return _LOSSES[self.loss](sample_weight=sample_weight, n_threads=n_threads)\n" }, { "name": "TreeGrower", @@ -21567,7 +21534,7 @@ "is_public": true, "description": "Isolation Forest Algorithm.\n\nReturn the anomaly score of each sample using the IsolationForest algorithm The IsolationForest 'isolates' observations by randomly selecting a feature and then randomly selecting a split value between the maximum and minimum values of the selected feature. Since recursive partitioning can be represented by a tree structure, the number of splittings required to isolate a sample is equivalent to the path length from the root node to the terminating node. This path length, averaged over a forest of such random trees, is a measure of normality and our decision function. Random partitioning produces noticeably shorter paths for anomalies. Hence, when a forest of random trees collectively produce shorter path lengths for particular samples, they are highly likely to be anomalies. Read more in the :ref:`User Guide `. .. versionadded:: 0.18", "docstring": "\n Isolation Forest Algorithm.\n\n Return the anomaly score of each sample using the IsolationForest algorithm\n\n The IsolationForest 'isolates' observations by randomly selecting a feature\n and then randomly selecting a split value between the maximum and minimum\n values of the selected feature.\n\n Since recursive partitioning can be represented by a tree structure, the\n number of splittings required to isolate a sample is equivalent to the path\n length from the root node to the terminating node.\n\n This path length, averaged over a forest of such random trees, is a\n measure of normality and our decision function.\n\n Random partitioning produces noticeably shorter paths for anomalies.\n Hence, when a forest of random trees collectively produce shorter path\n lengths for particular samples, they are highly likely to be anomalies.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.18\n\n Parameters\n ----------\n n_estimators : int, default=100\n The number of base estimators in the ensemble.\n\n max_samples : \"auto\", int or float, default=\"auto\"\n The number of samples to draw from X to train each base estimator.\n - If int, then draw `max_samples` samples.\n - If float, then draw `max_samples * X.shape[0]` samples.\n - If \"auto\", then `max_samples=min(256, n_samples)`.\n\n If max_samples is larger than the number of samples provided,\n all samples will be used for all trees (no sampling).\n\n contamination : 'auto' or float, default='auto'\n The amount of contamination of the data set, i.e. the proportion\n of outliers in the data set. Used when fitting to define the threshold\n on the scores of the samples.\n\n - If 'auto', the threshold is determined as in the\n original paper.\n - If float, the contamination should be in the range (0, 0.5].\n\n .. versionchanged:: 0.22\n The default value of ``contamination`` changed from 0.1\n to ``'auto'``.\n\n max_features : int or float, default=1.0\n The number of features to draw from X to train each base estimator.\n\n - If int, then draw `max_features` features.\n - If float, then draw `max_features * X.shape[1]` features.\n\n bootstrap : bool, default=False\n If True, individual trees are fit on random subsets of the training\n data sampled with replacement. If False, sampling without replacement\n is performed.\n\n n_jobs : int, default=None\n The number of jobs to run in parallel for both :meth:`fit` and\n :meth:`predict`. ``None`` means 1 unless in a\n :obj:`joblib.parallel_backend` context. ``-1`` means using all\n processors. See :term:`Glossary ` for more details.\n\n random_state : int, RandomState instance or None, default=None\n Controls the pseudo-randomness of the selection of the feature\n and split values for each branching step and each tree in the forest.\n\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n verbose : int, default=0\n Controls the verbosity of the tree building process.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit\n and add more estimators to the ensemble, otherwise, just fit a whole\n new forest. See :term:`the Glossary `.\n\n .. versionadded:: 0.21\n\n Attributes\n ----------\n base_estimator_ : ExtraTreeRegressor instance\n The child estimator template used to create the collection of\n fitted sub-estimators.\n\n estimators_ : list of ExtraTreeRegressor instances\n The collection of fitted sub-estimators.\n\n estimators_features_ : list of ndarray\n The subset of drawn features for each base estimator.\n\n estimators_samples_ : list of ndarray\n The subset of drawn samples (i.e., the in-bag samples) for each base\n estimator.\n\n max_samples_ : int\n The actual number of samples.\n\n offset_ : float\n Offset used to define the decision function from the raw scores. We\n have the relation: ``decision_function = score_samples - offset_``.\n ``offset_`` is defined as follows. When the contamination parameter is\n set to \"auto\", the offset is equal to -0.5 as the scores of inliers are\n close to 0 and the scores of outliers are close to -1. When a\n contamination parameter different than \"auto\" is provided, the offset\n is defined in such a way we obtain the expected number of outliers\n (samples with decision function < 0) in training.\n\n .. versionadded:: 0.20\n\n n_features_ : int\n The number of features when ``fit`` is performed.\n\n .. deprecated:: 1.0\n Attribute `n_features_` was deprecated in version 1.0 and will be\n removed in 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Notes\n -----\n The implementation is based on an ensemble of ExtraTreeRegressor. The\n maximum depth of each tree is set to ``ceil(log_2(n))`` where\n :math:`n` is the number of samples used to build the tree\n (see (Liu et al., 2008) for more details).\n\n References\n ----------\n .. [1] Liu, Fei Tony, Ting, Kai Ming and Zhou, Zhi-Hua. \"Isolation forest.\"\n Data Mining, 2008. ICDM'08. Eighth IEEE International Conference on.\n .. [2] Liu, Fei Tony, Ting, Kai Ming and Zhou, Zhi-Hua. \"Isolation-based\n anomaly detection.\" ACM Transactions on Knowledge Discovery from\n Data (TKDD) 6.1 (2012): 3.\n\n See Also\n ----------\n sklearn.covariance.EllipticEnvelope : An object for detecting outliers in a\n Gaussian distributed dataset.\n sklearn.svm.OneClassSVM : Unsupervised Outlier Detection.\n Estimate the support of a high-dimensional distribution.\n The implementation is based on libsvm.\n sklearn.neighbors.LocalOutlierFactor : Unsupervised Outlier Detection\n using Local Outlier Factor (LOF).\n\n Examples\n --------\n >>> from sklearn.ensemble import IsolationForest\n >>> X = [[-1.1], [0.3], [0.5], [100]]\n >>> clf = IsolationForest(random_state=0).fit(X)\n >>> clf.predict([[0.1], [0], [90]])\n array([ 1, 1, -1])\n ", - "source_code": "\n\nclass IsolationForest(OutlierMixin, BaseBagging):\n \"\"\"\n Isolation Forest Algorithm.\n\n Return the anomaly score of each sample using the IsolationForest algorithm\n\n The IsolationForest 'isolates' observations by randomly selecting a feature\n and then randomly selecting a split value between the maximum and minimum\n values of the selected feature.\n\n Since recursive partitioning can be represented by a tree structure, the\n number of splittings required to isolate a sample is equivalent to the path\n length from the root node to the terminating node.\n\n This path length, averaged over a forest of such random trees, is a\n measure of normality and our decision function.\n\n Random partitioning produces noticeably shorter paths for anomalies.\n Hence, when a forest of random trees collectively produce shorter path\n lengths for particular samples, they are highly likely to be anomalies.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.18\n\n Parameters\n ----------\n n_estimators : int, default=100\n The number of base estimators in the ensemble.\n\n max_samples : \"auto\", int or float, default=\"auto\"\n The number of samples to draw from X to train each base estimator.\n - If int, then draw `max_samples` samples.\n - If float, then draw `max_samples * X.shape[0]` samples.\n - If \"auto\", then `max_samples=min(256, n_samples)`.\n\n If max_samples is larger than the number of samples provided,\n all samples will be used for all trees (no sampling).\n\n contamination : 'auto' or float, default='auto'\n The amount of contamination of the data set, i.e. the proportion\n of outliers in the data set. Used when fitting to define the threshold\n on the scores of the samples.\n\n - If 'auto', the threshold is determined as in the\n original paper.\n - If float, the contamination should be in the range (0, 0.5].\n\n .. versionchanged:: 0.22\n The default value of ``contamination`` changed from 0.1\n to ``'auto'``.\n\n max_features : int or float, default=1.0\n The number of features to draw from X to train each base estimator.\n\n - If int, then draw `max_features` features.\n - If float, then draw `max_features * X.shape[1]` features.\n\n bootstrap : bool, default=False\n If True, individual trees are fit on random subsets of the training\n data sampled with replacement. If False, sampling without replacement\n is performed.\n\n n_jobs : int, default=None\n The number of jobs to run in parallel for both :meth:`fit` and\n :meth:`predict`. ``None`` means 1 unless in a\n :obj:`joblib.parallel_backend` context. ``-1`` means using all\n processors. See :term:`Glossary ` for more details.\n\n random_state : int, RandomState instance or None, default=None\n Controls the pseudo-randomness of the selection of the feature\n and split values for each branching step and each tree in the forest.\n\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n verbose : int, default=0\n Controls the verbosity of the tree building process.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit\n and add more estimators to the ensemble, otherwise, just fit a whole\n new forest. See :term:`the Glossary `.\n\n .. versionadded:: 0.21\n\n Attributes\n ----------\n base_estimator_ : ExtraTreeRegressor instance\n The child estimator template used to create the collection of\n fitted sub-estimators.\n\n estimators_ : list of ExtraTreeRegressor instances\n The collection of fitted sub-estimators.\n\n estimators_features_ : list of ndarray\n The subset of drawn features for each base estimator.\n\n estimators_samples_ : list of ndarray\n The subset of drawn samples (i.e., the in-bag samples) for each base\n estimator.\n\n max_samples_ : int\n The actual number of samples.\n\n offset_ : float\n Offset used to define the decision function from the raw scores. We\n have the relation: ``decision_function = score_samples - offset_``.\n ``offset_`` is defined as follows. When the contamination parameter is\n set to \"auto\", the offset is equal to -0.5 as the scores of inliers are\n close to 0 and the scores of outliers are close to -1. When a\n contamination parameter different than \"auto\" is provided, the offset\n is defined in such a way we obtain the expected number of outliers\n (samples with decision function < 0) in training.\n\n .. versionadded:: 0.20\n\n n_features_ : int\n The number of features when ``fit`` is performed.\n\n .. deprecated:: 1.0\n Attribute `n_features_` was deprecated in version 1.0 and will be\n removed in 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Notes\n -----\n The implementation is based on an ensemble of ExtraTreeRegressor. The\n maximum depth of each tree is set to ``ceil(log_2(n))`` where\n :math:`n` is the number of samples used to build the tree\n (see (Liu et al., 2008) for more details).\n\n References\n ----------\n .. [1] Liu, Fei Tony, Ting, Kai Ming and Zhou, Zhi-Hua. \"Isolation forest.\"\n Data Mining, 2008. ICDM'08. Eighth IEEE International Conference on.\n .. [2] Liu, Fei Tony, Ting, Kai Ming and Zhou, Zhi-Hua. \"Isolation-based\n anomaly detection.\" ACM Transactions on Knowledge Discovery from\n Data (TKDD) 6.1 (2012): 3.\n\n See Also\n ----------\n sklearn.covariance.EllipticEnvelope : An object for detecting outliers in a\n Gaussian distributed dataset.\n sklearn.svm.OneClassSVM : Unsupervised Outlier Detection.\n Estimate the support of a high-dimensional distribution.\n The implementation is based on libsvm.\n sklearn.neighbors.LocalOutlierFactor : Unsupervised Outlier Detection\n using Local Outlier Factor (LOF).\n\n Examples\n --------\n >>> from sklearn.ensemble import IsolationForest\n >>> X = [[-1.1], [0.3], [0.5], [100]]\n >>> clf = IsolationForest(random_state=0).fit(X)\n >>> clf.predict([[0.1], [0], [90]])\n array([ 1, 1, -1])\n \"\"\"\n \n def __init__(self, *, n_estimators=100, max_samples='auto', contamination='auto', max_features=1.0, bootstrap=False, n_jobs=None, random_state=None, verbose=0, warm_start=False):\n super().__init__(base_estimator=ExtraTreeRegressor(max_features=1, splitter='random', random_state=random_state), bootstrap=bootstrap, bootstrap_features=False, n_estimators=n_estimators, max_samples=max_samples, max_features=max_features, warm_start=warm_start, n_jobs=n_jobs, random_state=random_state, verbose=verbose)\n self.contamination = contamination\n \n def _set_oob_score(self, X, y):\n raise NotImplementedError('OOB score not supported by iforest')\n \n def _parallel_args(self):\n return _joblib_parallel_args(prefer='threads')\n \n def fit(self, X, y=None, sample_weight=None):\n \"\"\"\n Fit estimator.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The input samples. Use ``dtype=np.float32`` for maximum\n efficiency. Sparse matrices are also supported, use sparse\n ``csc_matrix`` for maximum efficiency.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n X = self._validate_data(X, accept_sparse=['csc'])\n if issparse(X):\n X.sort_indices()\n rnd = check_random_state(self.random_state)\n y = rnd.uniform(size=X.shape[0])\n n_samples = X.shape[0]\n if self.contamination != 'auto':\n if not 0.0 < self.contamination <= 0.5:\n raise ValueError('contamination must be in (0, 0.5], got: %f' % self.contamination)\n if isinstance(self.max_samples, str):\n if self.max_samples == 'auto':\n max_samples = min(256, n_samples)\n else:\n raise ValueError('max_samples (%s) is not supported.Valid choices are: \"auto\", int orfloat' % self.max_samples)\n elif isinstance(self.max_samples, numbers.Integral):\n if self.max_samples > n_samples:\n warn('max_samples (%s) is greater than the total number of samples (%s). max_samples will be set to n_samples for estimation.' % (self.max_samples, n_samples))\n max_samples = n_samples\n else:\n max_samples = self.max_samples\n else:\n if not 0.0 < self.max_samples <= 1.0:\n raise ValueError('max_samples must be in (0, 1], got %r' % self.max_samples)\n max_samples = int(self.max_samples * X.shape[0])\n self.max_samples_ = max_samples\n max_depth = int(np.ceil(np.log2(max(max_samples, 2))))\n super()._fit(X, y, max_samples, max_depth=max_depth, sample_weight=sample_weight)\n if self.contamination == 'auto':\n self.offset_ = -0.5\n return self\n self.offset_ = np.percentile(self.score_samples(X), 100.0 * self.contamination)\n return self\n \n def predict(self, X):\n \"\"\"\n Predict if a particular sample is an outlier or not.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The input samples. Internally, it will be converted to\n ``dtype=np.float32`` and if a sparse matrix is provided\n to a sparse ``csr_matrix``.\n\n Returns\n -------\n is_inlier : ndarray of shape (n_samples,)\n For each observation, tells whether or not (+1 or -1) it should\n be considered as an inlier according to the fitted model.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse='csr', reset=False)\n is_inlier = np.ones(X.shape[0], dtype=int)\n is_inlier[self.decision_function(X) < 0] = -1\n return is_inlier\n \n def decision_function(self, X):\n \"\"\"\n Average anomaly score of X of the base classifiers.\n\n The anomaly score of an input sample is computed as\n the mean anomaly score of the trees in the forest.\n\n The measure of normality of an observation given a tree is the depth\n of the leaf containing this observation, which is equivalent to\n the number of splittings required to isolate this point. In case of\n several observations n_left in the leaf, the average path length of\n a n_left samples isolation tree is added.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The input samples. Internally, it will be converted to\n ``dtype=np.float32`` and if a sparse matrix is provided\n to a sparse ``csr_matrix``.\n\n Returns\n -------\n scores : ndarray of shape (n_samples,)\n The anomaly score of the input samples.\n The lower, the more abnormal. Negative scores represent outliers,\n positive scores represent inliers.\n \"\"\"\n return self.score_samples(X) - self.offset_\n \n def score_samples(self, X):\n \"\"\"\n Opposite of the anomaly score defined in the original paper.\n\n The anomaly score of an input sample is computed as\n the mean anomaly score of the trees in the forest.\n\n The measure of normality of an observation given a tree is the depth\n of the leaf containing this observation, which is equivalent to\n the number of splittings required to isolate this point. In case of\n several observations n_left in the leaf, the average path length of\n a n_left samples isolation tree is added.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The input samples.\n\n Returns\n -------\n scores : ndarray of shape (n_samples,)\n The anomaly score of the input samples.\n The lower, the more abnormal.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse='csr', reset=False)\n return -self._compute_chunked_score_samples(X)\n \n def _compute_chunked_score_samples(self, X):\n n_samples = _num_samples(X)\n if self._max_features == X.shape[1]:\n subsample_features = False\n else:\n subsample_features = True\n chunk_n_rows = get_chunk_n_rows(row_bytes=16 * self._max_features, max_n_rows=n_samples)\n slices = gen_batches(n_samples, chunk_n_rows)\n scores = np.zeros(n_samples, order='f')\n for sl in slices:\n scores[sl] = self._compute_score_samples(X[sl], subsample_features)\n return scores\n \n def _compute_score_samples(self, X, subsample_features):\n \"\"\"\n Compute the score of each samples in X going through the extra trees.\n\n Parameters\n ----------\n X : array-like or sparse matrix\n Data matrix.\n\n subsample_features : bool\n Whether features should be subsampled.\n \"\"\"\n n_samples = X.shape[0]\n depths = np.zeros(n_samples, order='f')\n for (tree, features) in zip(self.estimators_, self.estimators_features_):\n X_subset = X[:, features] if subsample_features else X\n leaves_index = tree.apply(X_subset)\n node_indicator = tree.decision_path(X_subset)\n n_samples_leaf = tree.tree_.n_node_samples[leaves_index]\n depths += np.ravel(node_indicator.sum(axis=1)) + _average_path_length(n_samples_leaf) - 1.0\n denominator = len(self.estimators_) * _average_path_length([self.max_samples_])\n scores = 2**(-np.divide(depths, denominator, out=np.ones_like(depths), where=denominator != 0))\n return scores\n \n def _more_tags(self):\n return {'_xfail_checks': {'check_sample_weights_invariance': 'zero sample_weight is not equivalent to removing samples'}}\n" + "source_code": "\n\nclass IsolationForest(OutlierMixin, BaseBagging):\n \"\"\"\n Isolation Forest Algorithm.\n\n Return the anomaly score of each sample using the IsolationForest algorithm\n\n The IsolationForest 'isolates' observations by randomly selecting a feature\n and then randomly selecting a split value between the maximum and minimum\n values of the selected feature.\n\n Since recursive partitioning can be represented by a tree structure, the\n number of splittings required to isolate a sample is equivalent to the path\n length from the root node to the terminating node.\n\n This path length, averaged over a forest of such random trees, is a\n measure of normality and our decision function.\n\n Random partitioning produces noticeably shorter paths for anomalies.\n Hence, when a forest of random trees collectively produce shorter path\n lengths for particular samples, they are highly likely to be anomalies.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.18\n\n Parameters\n ----------\n n_estimators : int, default=100\n The number of base estimators in the ensemble.\n\n max_samples : \"auto\", int or float, default=\"auto\"\n The number of samples to draw from X to train each base estimator.\n - If int, then draw `max_samples` samples.\n - If float, then draw `max_samples * X.shape[0]` samples.\n - If \"auto\", then `max_samples=min(256, n_samples)`.\n\n If max_samples is larger than the number of samples provided,\n all samples will be used for all trees (no sampling).\n\n contamination : 'auto' or float, default='auto'\n The amount of contamination of the data set, i.e. the proportion\n of outliers in the data set. Used when fitting to define the threshold\n on the scores of the samples.\n\n - If 'auto', the threshold is determined as in the\n original paper.\n - If float, the contamination should be in the range (0, 0.5].\n\n .. versionchanged:: 0.22\n The default value of ``contamination`` changed from 0.1\n to ``'auto'``.\n\n max_features : int or float, default=1.0\n The number of features to draw from X to train each base estimator.\n\n - If int, then draw `max_features` features.\n - If float, then draw `max_features * X.shape[1]` features.\n\n bootstrap : bool, default=False\n If True, individual trees are fit on random subsets of the training\n data sampled with replacement. If False, sampling without replacement\n is performed.\n\n n_jobs : int, default=None\n The number of jobs to run in parallel for both :meth:`fit` and\n :meth:`predict`. ``None`` means 1 unless in a\n :obj:`joblib.parallel_backend` context. ``-1`` means using all\n processors. See :term:`Glossary ` for more details.\n\n random_state : int, RandomState instance or None, default=None\n Controls the pseudo-randomness of the selection of the feature\n and split values for each branching step and each tree in the forest.\n\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n verbose : int, default=0\n Controls the verbosity of the tree building process.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit\n and add more estimators to the ensemble, otherwise, just fit a whole\n new forest. See :term:`the Glossary `.\n\n .. versionadded:: 0.21\n\n Attributes\n ----------\n base_estimator_ : ExtraTreeRegressor instance\n The child estimator template used to create the collection of\n fitted sub-estimators.\n\n estimators_ : list of ExtraTreeRegressor instances\n The collection of fitted sub-estimators.\n\n estimators_features_ : list of ndarray\n The subset of drawn features for each base estimator.\n\n estimators_samples_ : list of ndarray\n The subset of drawn samples (i.e., the in-bag samples) for each base\n estimator.\n\n max_samples_ : int\n The actual number of samples.\n\n offset_ : float\n Offset used to define the decision function from the raw scores. We\n have the relation: ``decision_function = score_samples - offset_``.\n ``offset_`` is defined as follows. When the contamination parameter is\n set to \"auto\", the offset is equal to -0.5 as the scores of inliers are\n close to 0 and the scores of outliers are close to -1. When a\n contamination parameter different than \"auto\" is provided, the offset\n is defined in such a way we obtain the expected number of outliers\n (samples with decision function < 0) in training.\n\n .. versionadded:: 0.20\n\n n_features_ : int\n The number of features when ``fit`` is performed.\n\n .. deprecated:: 1.0\n Attribute `n_features_` was deprecated in version 1.0 and will be\n removed in 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Notes\n -----\n The implementation is based on an ensemble of ExtraTreeRegressor. The\n maximum depth of each tree is set to ``ceil(log_2(n))`` where\n :math:`n` is the number of samples used to build the tree\n (see (Liu et al., 2008) for more details).\n\n References\n ----------\n .. [1] Liu, Fei Tony, Ting, Kai Ming and Zhou, Zhi-Hua. \"Isolation forest.\"\n Data Mining, 2008. ICDM'08. Eighth IEEE International Conference on.\n .. [2] Liu, Fei Tony, Ting, Kai Ming and Zhou, Zhi-Hua. \"Isolation-based\n anomaly detection.\" ACM Transactions on Knowledge Discovery from\n Data (TKDD) 6.1 (2012): 3.\n\n See Also\n ----------\n sklearn.covariance.EllipticEnvelope : An object for detecting outliers in a\n Gaussian distributed dataset.\n sklearn.svm.OneClassSVM : Unsupervised Outlier Detection.\n Estimate the support of a high-dimensional distribution.\n The implementation is based on libsvm.\n sklearn.neighbors.LocalOutlierFactor : Unsupervised Outlier Detection\n using Local Outlier Factor (LOF).\n\n Examples\n --------\n >>> from sklearn.ensemble import IsolationForest\n >>> X = [[-1.1], [0.3], [0.5], [100]]\n >>> clf = IsolationForest(random_state=0).fit(X)\n >>> clf.predict([[0.1], [0], [90]])\n array([ 1, 1, -1])\n \"\"\"\n \n def __init__(self, *, n_estimators=100, max_samples='auto', contamination='auto', max_features=1.0, bootstrap=False, n_jobs=None, random_state=None, verbose=0, warm_start=False):\n super().__init__(base_estimator=ExtraTreeRegressor(max_features=1, splitter='random', random_state=random_state), bootstrap=bootstrap, bootstrap_features=False, n_estimators=n_estimators, max_samples=max_samples, max_features=max_features, warm_start=warm_start, n_jobs=n_jobs, random_state=random_state, verbose=verbose)\n self.contamination = contamination\n \n def _set_oob_score(self, X, y):\n raise NotImplementedError('OOB score not supported by iforest')\n \n def _parallel_args(self):\n return _joblib_parallel_args(prefer='threads')\n \n def fit(self, X, y=None, sample_weight=None):\n \"\"\"\n Fit estimator.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The input samples. Use ``dtype=np.float32`` for maximum\n efficiency. Sparse matrices are also supported, use sparse\n ``csc_matrix`` for maximum efficiency.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n X = self._validate_data(X, accept_sparse=['csc'])\n if issparse(X):\n X.sort_indices()\n rnd = check_random_state(self.random_state)\n y = rnd.uniform(size=X.shape[0])\n n_samples = X.shape[0]\n if self.contamination != 'auto':\n if not 0.0 < self.contamination <= 0.5:\n raise ValueError('contamination must be in (0, 0.5], got: %f' % self.contamination)\n if isinstance(self.max_samples, str):\n if self.max_samples == 'auto':\n max_samples = min(256, n_samples)\n else:\n raise ValueError('max_samples (%s) is not supported.Valid choices are: \"auto\", int orfloat' % self.max_samples)\n elif isinstance(self.max_samples, numbers.Integral):\n if self.max_samples > n_samples:\n warn('max_samples (%s) is greater than the total number of samples (%s). max_samples will be set to n_samples for estimation.' % (self.max_samples, n_samples))\n max_samples = n_samples\n else:\n max_samples = self.max_samples\n else:\n if not 0.0 < self.max_samples <= 1.0:\n raise ValueError('max_samples must be in (0, 1], got %r' % self.max_samples)\n max_samples = int(self.max_samples * X.shape[0])\n self.max_samples_ = max_samples\n max_depth = int(np.ceil(np.log2(max(max_samples, 2))))\n super()._fit(X, y, max_samples, max_depth=max_depth, sample_weight=sample_weight)\n if self.contamination == 'auto':\n self.offset_ = -0.5\n return self\n self.offset_ = np.percentile(self.score_samples(X), 100.0 * self.contamination)\n return self\n \n def predict(self, X):\n \"\"\"\n Predict if a particular sample is an outlier or not.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The input samples. Internally, it will be converted to\n ``dtype=np.float32`` and if a sparse matrix is provided\n to a sparse ``csr_matrix``.\n\n Returns\n -------\n is_inlier : ndarray of shape (n_samples,)\n For each observation, tells whether or not (+1 or -1) it should\n be considered as an inlier according to the fitted model.\n \"\"\"\n check_is_fitted(self)\n decision_func = self.decision_function(X)\n is_inlier = np.ones_like(decision_func, dtype=int)\n is_inlier[decision_func < 0] = -1\n return is_inlier\n \n def decision_function(self, X):\n \"\"\"\n Average anomaly score of X of the base classifiers.\n\n The anomaly score of an input sample is computed as\n the mean anomaly score of the trees in the forest.\n\n The measure of normality of an observation given a tree is the depth\n of the leaf containing this observation, which is equivalent to\n the number of splittings required to isolate this point. In case of\n several observations n_left in the leaf, the average path length of\n a n_left samples isolation tree is added.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The input samples. Internally, it will be converted to\n ``dtype=np.float32`` and if a sparse matrix is provided\n to a sparse ``csr_matrix``.\n\n Returns\n -------\n scores : ndarray of shape (n_samples,)\n The anomaly score of the input samples.\n The lower, the more abnormal. Negative scores represent outliers,\n positive scores represent inliers.\n \"\"\"\n return self.score_samples(X) - self.offset_\n \n def score_samples(self, X):\n \"\"\"\n Opposite of the anomaly score defined in the original paper.\n\n The anomaly score of an input sample is computed as\n the mean anomaly score of the trees in the forest.\n\n The measure of normality of an observation given a tree is the depth\n of the leaf containing this observation, which is equivalent to\n the number of splittings required to isolate this point. In case of\n several observations n_left in the leaf, the average path length of\n a n_left samples isolation tree is added.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The input samples.\n\n Returns\n -------\n scores : ndarray of shape (n_samples,)\n The anomaly score of the input samples.\n The lower, the more abnormal.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse='csr', reset=False)\n return -self._compute_chunked_score_samples(X)\n \n def _compute_chunked_score_samples(self, X):\n n_samples = _num_samples(X)\n if self._max_features == X.shape[1]:\n subsample_features = False\n else:\n subsample_features = True\n chunk_n_rows = get_chunk_n_rows(row_bytes=16 * self._max_features, max_n_rows=n_samples)\n slices = gen_batches(n_samples, chunk_n_rows)\n scores = np.zeros(n_samples, order='f')\n for sl in slices:\n scores[sl] = self._compute_score_samples(X[sl], subsample_features)\n return scores\n \n def _compute_score_samples(self, X, subsample_features):\n \"\"\"\n Compute the score of each samples in X going through the extra trees.\n\n Parameters\n ----------\n X : array-like or sparse matrix\n Data matrix.\n\n subsample_features : bool\n Whether features should be subsampled.\n \"\"\"\n n_samples = X.shape[0]\n depths = np.zeros(n_samples, order='f')\n for (tree, features) in zip(self.estimators_, self.estimators_features_):\n X_subset = X[:, features] if subsample_features else X\n leaves_index = tree.apply(X_subset)\n node_indicator = tree.decision_path(X_subset)\n n_samples_leaf = tree.tree_.n_node_samples[leaves_index]\n depths += np.ravel(node_indicator.sum(axis=1)) + _average_path_length(n_samples_leaf) - 1.0\n denominator = len(self.estimators_) * _average_path_length([self.max_samples_])\n scores = 2**(-np.divide(depths, denominator, out=np.ones_like(depths), where=denominator != 0))\n return scores\n \n def _more_tags(self):\n return {'_xfail_checks': {'check_sample_weights_invariance': 'zero sample_weight is not equivalent to removing samples'}}\n" }, { "name": "StackingClassifier", @@ -21586,8 +21553,8 @@ ], "is_public": true, "description": "Stack of estimators with a final classifier.\n\nStacked generalization consists in stacking the output of individual estimator and use a classifier to compute the final prediction. Stacking allows to use the strength of each individual estimator by using their output as input of a final estimator. Note that `estimators_` are fitted on the full `X` while `final_estimator_` is trained using cross-validated predictions of the base estimators using `cross_val_predict`. Read more in the :ref:`User Guide `. .. versionadded:: 0.22", - "docstring": "Stack of estimators with a final classifier.\n\n Stacked generalization consists in stacking the output of individual\n estimator and use a classifier to compute the final prediction. Stacking\n allows to use the strength of each individual estimator by using their\n output as input of a final estimator.\n\n Note that `estimators_` are fitted on the full `X` while `final_estimator_`\n is trained using cross-validated predictions of the base estimators using\n `cross_val_predict`.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.22\n\n Parameters\n ----------\n estimators : list of (str, estimator)\n Base estimators which will be stacked together. Each element of the\n list is defined as a tuple of string (i.e. name) and an estimator\n instance. An estimator can be set to 'drop' using `set_params`.\n\n final_estimator : estimator, default=None\n A classifier which will be used to combine the base estimators.\n The default classifier is a\n :class:`~sklearn.linear_model.LogisticRegression`.\n\n cv : int, cross-validation generator or an iterable, default=None\n Determines the cross-validation splitting strategy used in\n `cross_val_predict` to train `final_estimator`. Possible inputs for\n cv are:\n\n * None, to use the default 5-fold cross validation,\n * integer, to specify the number of folds in a (Stratified) KFold,\n * An object to be used as a cross-validation generator,\n * An iterable yielding train, test splits.\n\n For integer/None inputs, if the estimator is a classifier and y is\n either binary or multiclass,\n :class:`~sklearn.model_selection.StratifiedKFold` is used.\n In all other cases, :class:`~sklearn.model_selection.KFold` is used.\n These splitters are instantiated with `shuffle=False` so the splits\n will be the same across calls.\n\n Refer :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n .. note::\n A larger number of split will provide no benefits if the number\n of training samples is large enough. Indeed, the training time\n will increase. ``cv`` is not used for model evaluation but for\n prediction.\n\n stack_method : {'auto', 'predict_proba', 'decision_function', 'predict'}, default='auto'\n Methods called for each base estimator. It can be:\n\n * if 'auto', it will try to invoke, for each estimator,\n `'predict_proba'`, `'decision_function'` or `'predict'` in that\n order.\n * otherwise, one of `'predict_proba'`, `'decision_function'` or\n `'predict'`. If the method is not implemented by the estimator, it\n will raise an error.\n\n n_jobs : int, default=None\n The number of jobs to run in parallel all `estimators` `fit`.\n `None` means 1 unless in a `joblib.parallel_backend` context. -1 means\n using all processors. See Glossary for more details.\n\n passthrough : bool, default=False\n When False, only the predictions of estimators will be used as\n training data for `final_estimator`. When True, the\n `final_estimator` is trained on the predictions as well as the\n original training data.\n\n verbose : int, default=0\n Verbosity level.\n\n Attributes\n ----------\n classes_ : ndarray of shape (n_classes,)\n Class labels.\n\n estimators_ : list of estimators\n The elements of the estimators parameter, having been fitted on the\n training data. If an estimator has been set to `'drop'`, it\n will not appear in `estimators_`.\n\n named_estimators_ : :class:`~sklearn.utils.Bunch`\n Attribute to access any fitted sub-estimators by name.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`. Only defined if the\n underlying classifier exposes such an attribute when fit.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Only defined if the\n underlying estimators expose such an attribute when fit.\n .. versionadded:: 1.0\n\n final_estimator_ : estimator\n The classifier which predicts given the output of `estimators_`.\n\n stack_method_ : list of str\n The method used by each base estimator.\n\n Notes\n -----\n When `predict_proba` is used by each estimator (i.e. most of the time for\n `stack_method='auto'` or specifically for `stack_method='predict_proba'`),\n The first column predicted by each estimator will be dropped in the case\n of a binary classification problem. Indeed, both feature will be perfectly\n collinear.\n\n References\n ----------\n .. [1] Wolpert, David H. \"Stacked generalization.\" Neural networks 5.2\n (1992): 241-259.\n\n Examples\n --------\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.ensemble import RandomForestClassifier\n >>> from sklearn.svm import LinearSVC\n >>> from sklearn.linear_model import LogisticRegression\n >>> from sklearn.preprocessing import StandardScaler\n >>> from sklearn.pipeline import make_pipeline\n >>> from sklearn.ensemble import StackingClassifier\n >>> X, y = load_iris(return_X_y=True)\n >>> estimators = [\n ... ('rf', RandomForestClassifier(n_estimators=10, random_state=42)),\n ... ('svr', make_pipeline(StandardScaler(),\n ... LinearSVC(random_state=42)))\n ... ]\n >>> clf = StackingClassifier(\n ... estimators=estimators, final_estimator=LogisticRegression()\n ... )\n >>> from sklearn.model_selection import train_test_split\n >>> X_train, X_test, y_train, y_test = train_test_split(\n ... X, y, stratify=y, random_state=42\n ... )\n >>> clf.fit(X_train, y_train).score(X_test, y_test)\n 0.9...\n\n ", - "source_code": "\n\nclass StackingClassifier(ClassifierMixin, _BaseStacking):\n \"\"\"Stack of estimators with a final classifier.\n\n Stacked generalization consists in stacking the output of individual\n estimator and use a classifier to compute the final prediction. Stacking\n allows to use the strength of each individual estimator by using their\n output as input of a final estimator.\n\n Note that `estimators_` are fitted on the full `X` while `final_estimator_`\n is trained using cross-validated predictions of the base estimators using\n `cross_val_predict`.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.22\n\n Parameters\n ----------\n estimators : list of (str, estimator)\n Base estimators which will be stacked together. Each element of the\n list is defined as a tuple of string (i.e. name) and an estimator\n instance. An estimator can be set to 'drop' using `set_params`.\n\n final_estimator : estimator, default=None\n A classifier which will be used to combine the base estimators.\n The default classifier is a\n :class:`~sklearn.linear_model.LogisticRegression`.\n\n cv : int, cross-validation generator or an iterable, default=None\n Determines the cross-validation splitting strategy used in\n `cross_val_predict` to train `final_estimator`. Possible inputs for\n cv are:\n\n * None, to use the default 5-fold cross validation,\n * integer, to specify the number of folds in a (Stratified) KFold,\n * An object to be used as a cross-validation generator,\n * An iterable yielding train, test splits.\n\n For integer/None inputs, if the estimator is a classifier and y is\n either binary or multiclass,\n :class:`~sklearn.model_selection.StratifiedKFold` is used.\n In all other cases, :class:`~sklearn.model_selection.KFold` is used.\n These splitters are instantiated with `shuffle=False` so the splits\n will be the same across calls.\n\n Refer :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n .. note::\n A larger number of split will provide no benefits if the number\n of training samples is large enough. Indeed, the training time\n will increase. ``cv`` is not used for model evaluation but for\n prediction.\n\n stack_method : {'auto', 'predict_proba', 'decision_function', 'predict'}, default='auto'\n Methods called for each base estimator. It can be:\n\n * if 'auto', it will try to invoke, for each estimator,\n `'predict_proba'`, `'decision_function'` or `'predict'` in that\n order.\n * otherwise, one of `'predict_proba'`, `'decision_function'` or\n `'predict'`. If the method is not implemented by the estimator, it\n will raise an error.\n\n n_jobs : int, default=None\n The number of jobs to run in parallel all `estimators` `fit`.\n `None` means 1 unless in a `joblib.parallel_backend` context. -1 means\n using all processors. See Glossary for more details.\n\n passthrough : bool, default=False\n When False, only the predictions of estimators will be used as\n training data for `final_estimator`. When True, the\n `final_estimator` is trained on the predictions as well as the\n original training data.\n\n verbose : int, default=0\n Verbosity level.\n\n Attributes\n ----------\n classes_ : ndarray of shape (n_classes,)\n Class labels.\n\n estimators_ : list of estimators\n The elements of the estimators parameter, having been fitted on the\n training data. If an estimator has been set to `'drop'`, it\n will not appear in `estimators_`.\n\n named_estimators_ : :class:`~sklearn.utils.Bunch`\n Attribute to access any fitted sub-estimators by name.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`. Only defined if the\n underlying classifier exposes such an attribute when fit.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Only defined if the\n underlying estimators expose such an attribute when fit.\n .. versionadded:: 1.0\n\n final_estimator_ : estimator\n The classifier which predicts given the output of `estimators_`.\n\n stack_method_ : list of str\n The method used by each base estimator.\n\n Notes\n -----\n When `predict_proba` is used by each estimator (i.e. most of the time for\n `stack_method='auto'` or specifically for `stack_method='predict_proba'`),\n The first column predicted by each estimator will be dropped in the case\n of a binary classification problem. Indeed, both feature will be perfectly\n collinear.\n\n References\n ----------\n .. [1] Wolpert, David H. \"Stacked generalization.\" Neural networks 5.2\n (1992): 241-259.\n\n Examples\n --------\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.ensemble import RandomForestClassifier\n >>> from sklearn.svm import LinearSVC\n >>> from sklearn.linear_model import LogisticRegression\n >>> from sklearn.preprocessing import StandardScaler\n >>> from sklearn.pipeline import make_pipeline\n >>> from sklearn.ensemble import StackingClassifier\n >>> X, y = load_iris(return_X_y=True)\n >>> estimators = [\n ... ('rf', RandomForestClassifier(n_estimators=10, random_state=42)),\n ... ('svr', make_pipeline(StandardScaler(),\n ... LinearSVC(random_state=42)))\n ... ]\n >>> clf = StackingClassifier(\n ... estimators=estimators, final_estimator=LogisticRegression()\n ... )\n >>> from sklearn.model_selection import train_test_split\n >>> X_train, X_test, y_train, y_test = train_test_split(\n ... X, y, stratify=y, random_state=42\n ... )\n >>> clf.fit(X_train, y_train).score(X_test, y_test)\n 0.9...\n\n \"\"\"\n \n def __init__(self, estimators, final_estimator=None, *, cv=None, stack_method='auto', n_jobs=None, passthrough=False, verbose=0):\n super().__init__(estimators=estimators, final_estimator=final_estimator, cv=cv, stack_method=stack_method, n_jobs=n_jobs, passthrough=passthrough, verbose=verbose)\n \n def _validate_final_estimator(self):\n self._clone_final_estimator(default=LogisticRegression())\n if not is_classifier(self.final_estimator_):\n raise ValueError(\"'final_estimator' parameter should be a classifier. Got {}\".format(self.final_estimator_))\n \n def fit(self, X, y, sample_weight=None):\n \"\"\"Fit the estimators.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target values.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n Note that this is supported only if all underlying estimators\n support sample weights.\n\n Returns\n -------\n self : object\n \"\"\"\n check_classification_targets(y)\n self._le = LabelEncoder().fit(y)\n self.classes_ = self._le.classes_\n return super().fit(X, self._le.transform(y), sample_weight)\n \n @if_delegate_has_method(delegate='final_estimator_')\n def predict(self, X, **predict_params):\n \"\"\"Predict target for X.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n **predict_params : dict of str -> obj\n Parameters to the `predict` called by the `final_estimator`. Note\n that this may be used to return uncertainties from some estimators\n with `return_std` or `return_cov`. Be aware that it will only\n accounts for uncertainty in the final estimator.\n\n Returns\n -------\n y_pred : ndarray of shape (n_samples,) or (n_samples, n_output)\n Predicted targets.\n \"\"\"\n y_pred = super().predict(X, **predict_params)\n return self._le.inverse_transform(y_pred)\n \n @if_delegate_has_method(delegate='final_estimator_')\n def predict_proba(self, X):\n \"\"\"Predict class probabilities for X using\n `final_estimator_.predict_proba`.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n Returns\n -------\n probabilities : ndarray of shape (n_samples, n_classes) or list of ndarray of shape (n_output,)\n The class probabilities of the input samples.\n \"\"\"\n check_is_fitted(self)\n return self.final_estimator_.predict_proba(self.transform(X))\n \n @if_delegate_has_method(delegate='final_estimator_')\n def decision_function(self, X):\n \"\"\"Predict decision function for samples in X using\n `final_estimator_.decision_function`.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n Returns\n -------\n decisions : ndarray of shape (n_samples,), (n_samples, n_classes), or (n_samples, n_classes * (n_classes-1) / 2)\n The decision function computed the final estimator.\n \"\"\"\n check_is_fitted(self)\n return self.final_estimator_.decision_function(self.transform(X))\n \n def transform(self, X):\n \"\"\"Return class labels or probabilities for X for each estimator.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n Returns\n -------\n y_preds : ndarray of shape (n_samples, n_estimators) or (n_samples, n_classes * n_estimators)\n Prediction outputs for each estimator.\n \"\"\"\n return self._transform(X)\n \n def _sk_visual_block_(self):\n if self.final_estimator is None:\n final_estimator = LogisticRegression()\n else:\n final_estimator = self.final_estimator\n return super()._sk_visual_block_(final_estimator)\n" + "docstring": "Stack of estimators with a final classifier.\n\n Stacked generalization consists in stacking the output of individual\n estimator and use a classifier to compute the final prediction. Stacking\n allows to use the strength of each individual estimator by using their\n output as input of a final estimator.\n\n Note that `estimators_` are fitted on the full `X` while `final_estimator_`\n is trained using cross-validated predictions of the base estimators using\n `cross_val_predict`.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.22\n\n Parameters\n ----------\n estimators : list of (str, estimator)\n Base estimators which will be stacked together. Each element of the\n list is defined as a tuple of string (i.e. name) and an estimator\n instance. An estimator can be set to 'drop' using `set_params`.\n\n final_estimator : estimator, default=None\n A classifier which will be used to combine the base estimators.\n The default classifier is a\n :class:`~sklearn.linear_model.LogisticRegression`.\n\n cv : int, cross-validation generator or an iterable, default=None\n Determines the cross-validation splitting strategy used in\n `cross_val_predict` to train `final_estimator`. Possible inputs for\n cv are:\n\n * None, to use the default 5-fold cross validation,\n * integer, to specify the number of folds in a (Stratified) KFold,\n * An object to be used as a cross-validation generator,\n * An iterable yielding train, test splits.\n\n For integer/None inputs, if the estimator is a classifier and y is\n either binary or multiclass,\n :class:`~sklearn.model_selection.StratifiedKFold` is used.\n In all other cases, :class:`~sklearn.model_selection.KFold` is used.\n These splitters are instantiated with `shuffle=False` so the splits\n will be the same across calls.\n\n Refer :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n .. note::\n A larger number of split will provide no benefits if the number\n of training samples is large enough. Indeed, the training time\n will increase. ``cv`` is not used for model evaluation but for\n prediction.\n\n stack_method : {'auto', 'predict_proba', 'decision_function', 'predict'}, default='auto'\n Methods called for each base estimator. It can be:\n\n * if 'auto', it will try to invoke, for each estimator,\n `'predict_proba'`, `'decision_function'` or `'predict'` in that\n order.\n * otherwise, one of `'predict_proba'`, `'decision_function'` or\n `'predict'`. If the method is not implemented by the estimator, it\n will raise an error.\n\n n_jobs : int, default=None\n The number of jobs to run in parallel all `estimators` `fit`.\n `None` means 1 unless in a `joblib.parallel_backend` context. -1 means\n using all processors. See Glossary for more details.\n\n passthrough : bool, default=False\n When False, only the predictions of estimators will be used as\n training data for `final_estimator`. When True, the\n `final_estimator` is trained on the predictions as well as the\n original training data.\n\n verbose : int, default=0\n Verbosity level.\n\n Attributes\n ----------\n classes_ : ndarray of shape (n_classes,)\n Class labels.\n\n estimators_ : list of estimators\n The elements of the estimators parameter, having been fitted on the\n training data. If an estimator has been set to `'drop'`, it\n will not appear in `estimators_`.\n\n named_estimators_ : :class:`~sklearn.utils.Bunch`\n Attribute to access any fitted sub-estimators by name.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`. Only defined if the\n underlying classifier exposes such an attribute when fit.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Only defined if the\n underlying estimators expose such an attribute when fit.\n .. versionadded:: 1.0\n\n final_estimator_ : estimator\n The classifier which predicts given the output of `estimators_`.\n\n stack_method_ : list of str\n The method used by each base estimator.\n\n See Also\n --------\n StackingRegressor : Stack of estimators with a final regressor.\n\n Notes\n -----\n When `predict_proba` is used by each estimator (i.e. most of the time for\n `stack_method='auto'` or specifically for `stack_method='predict_proba'`),\n The first column predicted by each estimator will be dropped in the case\n of a binary classification problem. Indeed, both feature will be perfectly\n collinear.\n\n References\n ----------\n .. [1] Wolpert, David H. \"Stacked generalization.\" Neural networks 5.2\n (1992): 241-259.\n\n Examples\n --------\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.ensemble import RandomForestClassifier\n >>> from sklearn.svm import LinearSVC\n >>> from sklearn.linear_model import LogisticRegression\n >>> from sklearn.preprocessing import StandardScaler\n >>> from sklearn.pipeline import make_pipeline\n >>> from sklearn.ensemble import StackingClassifier\n >>> X, y = load_iris(return_X_y=True)\n >>> estimators = [\n ... ('rf', RandomForestClassifier(n_estimators=10, random_state=42)),\n ... ('svr', make_pipeline(StandardScaler(),\n ... LinearSVC(random_state=42)))\n ... ]\n >>> clf = StackingClassifier(\n ... estimators=estimators, final_estimator=LogisticRegression()\n ... )\n >>> from sklearn.model_selection import train_test_split\n >>> X_train, X_test, y_train, y_test = train_test_split(\n ... X, y, stratify=y, random_state=42\n ... )\n >>> clf.fit(X_train, y_train).score(X_test, y_test)\n 0.9...\n ", + "source_code": "\n\nclass StackingClassifier(ClassifierMixin, _BaseStacking):\n \"\"\"Stack of estimators with a final classifier.\n\n Stacked generalization consists in stacking the output of individual\n estimator and use a classifier to compute the final prediction. Stacking\n allows to use the strength of each individual estimator by using their\n output as input of a final estimator.\n\n Note that `estimators_` are fitted on the full `X` while `final_estimator_`\n is trained using cross-validated predictions of the base estimators using\n `cross_val_predict`.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.22\n\n Parameters\n ----------\n estimators : list of (str, estimator)\n Base estimators which will be stacked together. Each element of the\n list is defined as a tuple of string (i.e. name) and an estimator\n instance. An estimator can be set to 'drop' using `set_params`.\n\n final_estimator : estimator, default=None\n A classifier which will be used to combine the base estimators.\n The default classifier is a\n :class:`~sklearn.linear_model.LogisticRegression`.\n\n cv : int, cross-validation generator or an iterable, default=None\n Determines the cross-validation splitting strategy used in\n `cross_val_predict` to train `final_estimator`. Possible inputs for\n cv are:\n\n * None, to use the default 5-fold cross validation,\n * integer, to specify the number of folds in a (Stratified) KFold,\n * An object to be used as a cross-validation generator,\n * An iterable yielding train, test splits.\n\n For integer/None inputs, if the estimator is a classifier and y is\n either binary or multiclass,\n :class:`~sklearn.model_selection.StratifiedKFold` is used.\n In all other cases, :class:`~sklearn.model_selection.KFold` is used.\n These splitters are instantiated with `shuffle=False` so the splits\n will be the same across calls.\n\n Refer :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n .. note::\n A larger number of split will provide no benefits if the number\n of training samples is large enough. Indeed, the training time\n will increase. ``cv`` is not used for model evaluation but for\n prediction.\n\n stack_method : {'auto', 'predict_proba', 'decision_function', 'predict'}, default='auto'\n Methods called for each base estimator. It can be:\n\n * if 'auto', it will try to invoke, for each estimator,\n `'predict_proba'`, `'decision_function'` or `'predict'` in that\n order.\n * otherwise, one of `'predict_proba'`, `'decision_function'` or\n `'predict'`. If the method is not implemented by the estimator, it\n will raise an error.\n\n n_jobs : int, default=None\n The number of jobs to run in parallel all `estimators` `fit`.\n `None` means 1 unless in a `joblib.parallel_backend` context. -1 means\n using all processors. See Glossary for more details.\n\n passthrough : bool, default=False\n When False, only the predictions of estimators will be used as\n training data for `final_estimator`. When True, the\n `final_estimator` is trained on the predictions as well as the\n original training data.\n\n verbose : int, default=0\n Verbosity level.\n\n Attributes\n ----------\n classes_ : ndarray of shape (n_classes,)\n Class labels.\n\n estimators_ : list of estimators\n The elements of the estimators parameter, having been fitted on the\n training data. If an estimator has been set to `'drop'`, it\n will not appear in `estimators_`.\n\n named_estimators_ : :class:`~sklearn.utils.Bunch`\n Attribute to access any fitted sub-estimators by name.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`. Only defined if the\n underlying classifier exposes such an attribute when fit.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Only defined if the\n underlying estimators expose such an attribute when fit.\n .. versionadded:: 1.0\n\n final_estimator_ : estimator\n The classifier which predicts given the output of `estimators_`.\n\n stack_method_ : list of str\n The method used by each base estimator.\n\n See Also\n --------\n StackingRegressor : Stack of estimators with a final regressor.\n\n Notes\n -----\n When `predict_proba` is used by each estimator (i.e. most of the time for\n `stack_method='auto'` or specifically for `stack_method='predict_proba'`),\n The first column predicted by each estimator will be dropped in the case\n of a binary classification problem. Indeed, both feature will be perfectly\n collinear.\n\n References\n ----------\n .. [1] Wolpert, David H. \"Stacked generalization.\" Neural networks 5.2\n (1992): 241-259.\n\n Examples\n --------\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.ensemble import RandomForestClassifier\n >>> from sklearn.svm import LinearSVC\n >>> from sklearn.linear_model import LogisticRegression\n >>> from sklearn.preprocessing import StandardScaler\n >>> from sklearn.pipeline import make_pipeline\n >>> from sklearn.ensemble import StackingClassifier\n >>> X, y = load_iris(return_X_y=True)\n >>> estimators = [\n ... ('rf', RandomForestClassifier(n_estimators=10, random_state=42)),\n ... ('svr', make_pipeline(StandardScaler(),\n ... LinearSVC(random_state=42)))\n ... ]\n >>> clf = StackingClassifier(\n ... estimators=estimators, final_estimator=LogisticRegression()\n ... )\n >>> from sklearn.model_selection import train_test_split\n >>> X_train, X_test, y_train, y_test = train_test_split(\n ... X, y, stratify=y, random_state=42\n ... )\n >>> clf.fit(X_train, y_train).score(X_test, y_test)\n 0.9...\n \"\"\"\n \n def __init__(self, estimators, final_estimator=None, *, cv=None, stack_method='auto', n_jobs=None, passthrough=False, verbose=0):\n super().__init__(estimators=estimators, final_estimator=final_estimator, cv=cv, stack_method=stack_method, n_jobs=n_jobs, passthrough=passthrough, verbose=verbose)\n \n def _validate_final_estimator(self):\n self._clone_final_estimator(default=LogisticRegression())\n if not is_classifier(self.final_estimator_):\n raise ValueError(\"'final_estimator' parameter should be a classifier. Got {}\".format(self.final_estimator_))\n \n def fit(self, X, y, sample_weight=None):\n \"\"\"Fit the estimators.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target values.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n Note that this is supported only if all underlying estimators\n support sample weights.\n\n Returns\n -------\n self : object\n Returns a fitted instance of estimator.\n \"\"\"\n check_classification_targets(y)\n self._le = LabelEncoder().fit(y)\n self.classes_ = self._le.classes_\n return super().fit(X, self._le.transform(y), sample_weight)\n \n @if_delegate_has_method(delegate='final_estimator_')\n def predict(self, X, **predict_params):\n \"\"\"Predict target for X.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n **predict_params : dict of str -> obj\n Parameters to the `predict` called by the `final_estimator`. Note\n that this may be used to return uncertainties from some estimators\n with `return_std` or `return_cov`. Be aware that it will only\n accounts for uncertainty in the final estimator.\n\n Returns\n -------\n y_pred : ndarray of shape (n_samples,) or (n_samples, n_output)\n Predicted targets.\n \"\"\"\n y_pred = super().predict(X, **predict_params)\n return self._le.inverse_transform(y_pred)\n \n @if_delegate_has_method(delegate='final_estimator_')\n def predict_proba(self, X):\n \"\"\"Predict class probabilities for `X` using the final estimator.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n Returns\n -------\n probabilities : ndarray of shape (n_samples, n_classes) or list of ndarray of shape (n_output,)\n The class probabilities of the input samples.\n \"\"\"\n check_is_fitted(self)\n return self.final_estimator_.predict_proba(self.transform(X))\n \n @if_delegate_has_method(delegate='final_estimator_')\n def decision_function(self, X):\n \"\"\"Decision function for samples in `X` using the final estimator.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n Returns\n -------\n decisions : ndarray of shape (n_samples,), (n_samples, n_classes), or (n_samples, n_classes * (n_classes-1) / 2)\n The decision function computed the final estimator.\n \"\"\"\n check_is_fitted(self)\n return self.final_estimator_.decision_function(self.transform(X))\n \n def transform(self, X):\n \"\"\"Return class labels or probabilities for X for each estimator.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n Returns\n -------\n y_preds : ndarray of shape (n_samples, n_estimators) or (n_samples, n_classes * n_estimators)\n Prediction outputs for each estimator.\n \"\"\"\n return self._transform(X)\n \n def _sk_visual_block_(self):\n if self.final_estimator is None:\n final_estimator = LogisticRegression()\n else:\n final_estimator = self.final_estimator\n return super()._sk_visual_block_(final_estimator)\n" }, { "name": "StackingRegressor", @@ -21617,7 +21584,7 @@ "sklearn.ensemble._stacking._BaseStacking._concatenate_predictions", "sklearn.ensemble._stacking._BaseStacking._method_name", "sklearn.ensemble._stacking._BaseStacking.fit", - "sklearn.ensemble._stacking._BaseStacking.n_features_in_", + "sklearn.ensemble._stacking._BaseStacking.n_features_in_@getter", "sklearn.ensemble._stacking._BaseStacking._transform", "sklearn.ensemble._stacking._BaseStacking.predict", "sklearn.ensemble._stacking._BaseStacking._sk_visual_block_" @@ -21669,11 +21636,11 @@ "superclasses": ["TransformerMixin", "_BaseHeterogeneousEnsemble"], "methods": [ "sklearn.ensemble._voting._BaseVoting._log_message", - "sklearn.ensemble._voting._BaseVoting._weights_not_none", + "sklearn.ensemble._voting._BaseVoting._weights_not_none@getter", "sklearn.ensemble._voting._BaseVoting._predict", "sklearn.ensemble._voting._BaseVoting.fit", "sklearn.ensemble._voting._BaseVoting.fit_transform", - "sklearn.ensemble._voting._BaseVoting.n_features_in_", + "sklearn.ensemble._voting._BaseVoting.n_features_in_@getter", "sklearn.ensemble._voting._BaseVoting._sk_visual_block_", "sklearn.ensemble._voting._BaseVoting._more_tags" ], @@ -21706,7 +21673,7 @@ "is_public": true, "description": "An AdaBoost classifier.\n\nAn AdaBoost [1] classifier is a meta-estimator that begins by fitting a classifier on the original dataset and then fits additional copies of the classifier on the same dataset but where the weights of incorrectly classified instances are adjusted such that subsequent classifiers focus more on difficult cases. This class implements the algorithm known as AdaBoost-SAMME [2]. Read more in the :ref:`User Guide `. .. versionadded:: 0.14", "docstring": "An AdaBoost classifier.\n\n An AdaBoost [1] classifier is a meta-estimator that begins by fitting a\n classifier on the original dataset and then fits additional copies of the\n classifier on the same dataset but where the weights of incorrectly\n classified instances are adjusted such that subsequent classifiers focus\n more on difficult cases.\n\n This class implements the algorithm known as AdaBoost-SAMME [2].\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.14\n\n Parameters\n ----------\n base_estimator : object, default=None\n The base estimator from which the boosted ensemble is built.\n Support for sample weighting is required, as well as proper\n ``classes_`` and ``n_classes_`` attributes. If ``None``, then\n the base estimator is :class:`~sklearn.tree.DecisionTreeClassifier`\n initialized with `max_depth=1`.\n\n n_estimators : int, default=50\n The maximum number of estimators at which boosting is terminated.\n In case of perfect fit, the learning procedure is stopped early.\n\n learning_rate : float, default=1.0\n Weight applied to each classifier at each boosting iteration. A higher\n learning rate increases the contribution of each classifier. There is\n a trade-off between the `learning_rate` and `n_estimators` parameters.\n\n algorithm : {'SAMME', 'SAMME.R'}, default='SAMME.R'\n If 'SAMME.R' then use the SAMME.R real boosting algorithm.\n ``base_estimator`` must support calculation of class probabilities.\n If 'SAMME' then use the SAMME discrete boosting algorithm.\n The SAMME.R algorithm typically converges faster than SAMME,\n achieving a lower test error with fewer boosting iterations.\n\n random_state : int, RandomState instance or None, default=None\n Controls the random seed given at each `base_estimator` at each\n boosting iteration.\n Thus, it is only used when `base_estimator` exposes a `random_state`.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n Attributes\n ----------\n base_estimator_ : estimator\n The base estimator from which the ensemble is grown.\n\n estimators_ : list of classifiers\n The collection of fitted sub-estimators.\n\n classes_ : ndarray of shape (n_classes,)\n The classes labels.\n\n n_classes_ : int\n The number of classes.\n\n estimator_weights_ : ndarray of floats\n Weights for each estimator in the boosted ensemble.\n\n estimator_errors_ : ndarray of floats\n Classification error for each estimator in the boosted\n ensemble.\n\n feature_importances_ : ndarray of shape (n_features,)\n The impurity-based feature importances if supported by the\n ``base_estimator`` (when based on decision trees).\n\n Warning: impurity-based feature importances can be misleading for\n high cardinality features (many unique values). See\n :func:`sklearn.inspection.permutation_importance` as an alternative.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n AdaBoostRegressor : An AdaBoost regressor that begins by fitting a\n regressor on the original dataset and then fits additional copies of\n the regressor on the same dataset but where the weights of instances\n are adjusted according to the error of the current prediction.\n\n GradientBoostingClassifier : GB builds an additive model in a forward\n stage-wise fashion. Regression trees are fit on the negative gradient\n of the binomial or multinomial deviance loss function. Binary\n classification is a special case where only a single regression tree is\n induced.\n\n sklearn.tree.DecisionTreeClassifier : A non-parametric supervised learning\n method used for classification.\n Creates a model that predicts the value of a target variable by\n learning simple decision rules inferred from the data features.\n\n References\n ----------\n .. [1] Y. Freund, R. Schapire, \"A Decision-Theoretic Generalization of\n on-Line Learning and an Application to Boosting\", 1995.\n\n .. [2] J. Zhu, H. Zou, S. Rosset, T. Hastie, \"Multi-class AdaBoost\", 2009.\n\n Examples\n --------\n >>> from sklearn.ensemble import AdaBoostClassifier\n >>> from sklearn.datasets import make_classification\n >>> X, y = make_classification(n_samples=1000, n_features=4,\n ... n_informative=2, n_redundant=0,\n ... random_state=0, shuffle=False)\n >>> clf = AdaBoostClassifier(n_estimators=100, random_state=0)\n >>> clf.fit(X, y)\n AdaBoostClassifier(n_estimators=100, random_state=0)\n >>> clf.predict([[0, 0, 0, 0]])\n array([1])\n >>> clf.score(X, y)\n 0.983...\n ", - "source_code": "\n\nclass AdaBoostClassifier(ClassifierMixin, BaseWeightBoosting):\n \"\"\"An AdaBoost classifier.\n\n An AdaBoost [1] classifier is a meta-estimator that begins by fitting a\n classifier on the original dataset and then fits additional copies of the\n classifier on the same dataset but where the weights of incorrectly\n classified instances are adjusted such that subsequent classifiers focus\n more on difficult cases.\n\n This class implements the algorithm known as AdaBoost-SAMME [2].\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.14\n\n Parameters\n ----------\n base_estimator : object, default=None\n The base estimator from which the boosted ensemble is built.\n Support for sample weighting is required, as well as proper\n ``classes_`` and ``n_classes_`` attributes. If ``None``, then\n the base estimator is :class:`~sklearn.tree.DecisionTreeClassifier`\n initialized with `max_depth=1`.\n\n n_estimators : int, default=50\n The maximum number of estimators at which boosting is terminated.\n In case of perfect fit, the learning procedure is stopped early.\n\n learning_rate : float, default=1.0\n Weight applied to each classifier at each boosting iteration. A higher\n learning rate increases the contribution of each classifier. There is\n a trade-off between the `learning_rate` and `n_estimators` parameters.\n\n algorithm : {'SAMME', 'SAMME.R'}, default='SAMME.R'\n If 'SAMME.R' then use the SAMME.R real boosting algorithm.\n ``base_estimator`` must support calculation of class probabilities.\n If 'SAMME' then use the SAMME discrete boosting algorithm.\n The SAMME.R algorithm typically converges faster than SAMME,\n achieving a lower test error with fewer boosting iterations.\n\n random_state : int, RandomState instance or None, default=None\n Controls the random seed given at each `base_estimator` at each\n boosting iteration.\n Thus, it is only used when `base_estimator` exposes a `random_state`.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n Attributes\n ----------\n base_estimator_ : estimator\n The base estimator from which the ensemble is grown.\n\n estimators_ : list of classifiers\n The collection of fitted sub-estimators.\n\n classes_ : ndarray of shape (n_classes,)\n The classes labels.\n\n n_classes_ : int\n The number of classes.\n\n estimator_weights_ : ndarray of floats\n Weights for each estimator in the boosted ensemble.\n\n estimator_errors_ : ndarray of floats\n Classification error for each estimator in the boosted\n ensemble.\n\n feature_importances_ : ndarray of shape (n_features,)\n The impurity-based feature importances if supported by the\n ``base_estimator`` (when based on decision trees).\n\n Warning: impurity-based feature importances can be misleading for\n high cardinality features (many unique values). See\n :func:`sklearn.inspection.permutation_importance` as an alternative.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n AdaBoostRegressor : An AdaBoost regressor that begins by fitting a\n regressor on the original dataset and then fits additional copies of\n the regressor on the same dataset but where the weights of instances\n are adjusted according to the error of the current prediction.\n\n GradientBoostingClassifier : GB builds an additive model in a forward\n stage-wise fashion. Regression trees are fit on the negative gradient\n of the binomial or multinomial deviance loss function. Binary\n classification is a special case where only a single regression tree is\n induced.\n\n sklearn.tree.DecisionTreeClassifier : A non-parametric supervised learning\n method used for classification.\n Creates a model that predicts the value of a target variable by\n learning simple decision rules inferred from the data features.\n\n References\n ----------\n .. [1] Y. Freund, R. Schapire, \"A Decision-Theoretic Generalization of\n on-Line Learning and an Application to Boosting\", 1995.\n\n .. [2] J. Zhu, H. Zou, S. Rosset, T. Hastie, \"Multi-class AdaBoost\", 2009.\n\n Examples\n --------\n >>> from sklearn.ensemble import AdaBoostClassifier\n >>> from sklearn.datasets import make_classification\n >>> X, y = make_classification(n_samples=1000, n_features=4,\n ... n_informative=2, n_redundant=0,\n ... random_state=0, shuffle=False)\n >>> clf = AdaBoostClassifier(n_estimators=100, random_state=0)\n >>> clf.fit(X, y)\n AdaBoostClassifier(n_estimators=100, random_state=0)\n >>> clf.predict([[0, 0, 0, 0]])\n array([1])\n >>> clf.score(X, y)\n 0.983...\n \"\"\"\n \n def __init__(self, base_estimator=None, *, n_estimators=50, learning_rate=1.0, algorithm='SAMME.R', random_state=None):\n super().__init__(base_estimator=base_estimator, n_estimators=n_estimators, learning_rate=learning_rate, random_state=random_state)\n self.algorithm = algorithm\n \n def fit(self, X, y, sample_weight=None):\n \"\"\"Build a boosted classifier from the training set (X, y).\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\n y : array-like of shape (n_samples,)\n The target values (class labels).\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, the sample weights are initialized to\n ``1 / n_samples``.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n if self.algorithm not in ('SAMME', 'SAMME.R'):\n raise ValueError('algorithm %s is not supported' % self.algorithm)\n return super().fit(X, y, sample_weight)\n \n def _validate_estimator(self):\n \"\"\"Check the estimator and set the base_estimator_ attribute.\"\"\"\n super()._validate_estimator(default=DecisionTreeClassifier(max_depth=1))\n if self.algorithm == 'SAMME.R':\n if not hasattr(self.base_estimator_, 'predict_proba'):\n raise TypeError(\"AdaBoostClassifier with algorithm='SAMME.R' requires that the weak learner supports the calculation of class probabilities with a predict_proba method.\\nPlease change the base estimator or set algorithm='SAMME' instead.\")\n if not has_fit_parameter(self.base_estimator_, 'sample_weight'):\n raise ValueError(\"%s doesn't support sample_weight.\" % self.base_estimator_.__class__.__name__)\n \n def _boost(self, iboost, X, y, sample_weight, random_state):\n \"\"\"Implement a single boost.\n\n Perform a single boost according to the real multi-class SAMME.R\n algorithm or to the discrete SAMME algorithm and return the updated\n sample weights.\n\n Parameters\n ----------\n iboost : int\n The index of the current boost iteration.\n\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples.\n\n y : array-like of shape (n_samples,)\n The target values (class labels).\n\n sample_weight : array-like of shape (n_samples,)\n The current sample weights.\n\n random_state : RandomState instance\n The RandomState instance used if the base estimator accepts a\n `random_state` attribute.\n\n Returns\n -------\n sample_weight : array-like of shape (n_samples,) or None\n The reweighted sample weights.\n If None then boosting has terminated early.\n\n estimator_weight : float\n The weight for the current boost.\n If None then boosting has terminated early.\n\n estimator_error : float\n The classification error for the current boost.\n If None then boosting has terminated early.\n \"\"\"\n if self.algorithm == 'SAMME.R':\n return self._boost_real(iboost, X, y, sample_weight, random_state)\n else:\n return self._boost_discrete(iboost, X, y, sample_weight, random_state)\n \n def _boost_real(self, iboost, X, y, sample_weight, random_state):\n \"\"\"Implement a single boost using the SAMME.R real algorithm.\"\"\"\n estimator = self._make_estimator(random_state=random_state)\n estimator.fit(X, y, sample_weight=sample_weight)\n y_predict_proba = estimator.predict_proba(X)\n if iboost == 0:\n self.classes_ = getattr(estimator, 'classes_', None)\n self.n_classes_ = len(self.classes_)\n y_predict = self.classes_.take(np.argmax(y_predict_proba, axis=1), axis=0)\n incorrect = y_predict != y\n estimator_error = np.mean(np.average(incorrect, weights=sample_weight, axis=0))\n if estimator_error <= 0:\n return sample_weight, 1.0, 0.0\n n_classes = self.n_classes_\n classes = self.classes_\n y_codes = np.array([-1.0 / (n_classes - 1), 1.0])\n y_coding = y_codes.take(classes == y[:, np.newaxis])\n proba = y_predict_proba\n np.clip(proba, np.finfo(proba.dtype).eps, None, out=proba)\n estimator_weight = -1.0 * self.learning_rate * ((n_classes - 1.0) / n_classes) * xlogy(y_coding, y_predict_proba).sum(axis=1)\n if not iboost == self.n_estimators - 1:\n sample_weight *= np.exp(estimator_weight * ((sample_weight > 0) | (estimator_weight < 0)))\n return sample_weight, 1.0, estimator_error\n \n def _boost_discrete(self, iboost, X, y, sample_weight, random_state):\n \"\"\"Implement a single boost using the SAMME discrete algorithm.\"\"\"\n estimator = self._make_estimator(random_state=random_state)\n estimator.fit(X, y, sample_weight=sample_weight)\n y_predict = estimator.predict(X)\n if iboost == 0:\n self.classes_ = getattr(estimator, 'classes_', None)\n self.n_classes_ = len(self.classes_)\n incorrect = y_predict != y\n estimator_error = np.mean(np.average(incorrect, weights=sample_weight, axis=0))\n if estimator_error <= 0:\n return sample_weight, 1.0, 0.0\n n_classes = self.n_classes_\n if estimator_error >= 1.0 - 1.0 / n_classes:\n self.estimators_.pop(-1)\n if len(self.estimators_) == 0:\n raise ValueError('BaseClassifier in AdaBoostClassifier ensemble is worse than random, ensemble can not be fit.')\n return None, None, None\n estimator_weight = self.learning_rate * (np.log((1.0 - estimator_error) / estimator_error) + np.log(n_classes - 1.0))\n if not iboost == self.n_estimators - 1:\n sample_weight = np.exp(np.log(sample_weight) + estimator_weight * incorrect * (sample_weight > 0))\n return sample_weight, estimator_weight, estimator_error\n \n def predict(self, X):\n \"\"\"Predict classes for X.\n\n The predicted class of an input sample is computed as the weighted mean\n prediction of the classifiers in the ensemble.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\n Returns\n -------\n y : ndarray of shape (n_samples,)\n The predicted classes.\n \"\"\"\n X = self._check_X(X)\n pred = self.decision_function(X)\n if self.n_classes_ == 2:\n return self.classes_.take(pred > 0, axis=0)\n return self.classes_.take(np.argmax(pred, axis=1), axis=0)\n \n def staged_predict(self, X):\n \"\"\"Return staged predictions for X.\n\n The predicted class of an input sample is computed as the weighted mean\n prediction of the classifiers in the ensemble.\n\n This generator method yields the ensemble prediction after each\n iteration of boosting and therefore allows monitoring, such as to\n determine the prediction on a test set after each boost.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\n Yields\n ------\n y : generator of ndarray of shape (n_samples,)\n The predicted classes.\n \"\"\"\n X = self._check_X(X)\n n_classes = self.n_classes_\n classes = self.classes_\n if n_classes == 2:\n for pred in self.staged_decision_function(X):\n yield np.array(classes.take(pred > 0, axis=0))\n else:\n for pred in self.staged_decision_function(X):\n yield np.array(classes.take(np.argmax(pred, axis=1), axis=0))\n \n def decision_function(self, X):\n \"\"\"Compute the decision function of ``X``.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\n Returns\n -------\n score : ndarray of shape of (n_samples, k)\n The decision function of the input samples. The order of\n outputs is the same of that of the :term:`classes_` attribute.\n Binary classification is a special cases with ``k == 1``,\n otherwise ``k==n_classes``. For binary classification,\n values closer to -1 or 1 mean more like the first or second\n class in ``classes_``, respectively.\n \"\"\"\n check_is_fitted(self)\n X = self._check_X(X)\n n_classes = self.n_classes_\n classes = self.classes_[:, np.newaxis]\n if self.algorithm == 'SAMME.R':\n pred = sum((_samme_proba(estimator, n_classes, X) for estimator in self.estimators_))\n else:\n pred = sum(((estimator.predict(X) == classes).T * w for (estimator, w) in zip(self.estimators_, self.estimator_weights_)))\n pred /= self.estimator_weights_.sum()\n if n_classes == 2:\n pred[:, 0] *= -1\n return pred.sum(axis=1)\n return pred\n \n def staged_decision_function(self, X):\n \"\"\"Compute decision function of ``X`` for each boosting iteration.\n\n This method allows monitoring (i.e. determine error on testing set)\n after each boosting iteration.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\n Yields\n ------\n score : generator of ndarray of shape (n_samples, k)\n The decision function of the input samples. The order of\n outputs is the same of that of the :term:`classes_` attribute.\n Binary classification is a special cases with ``k == 1``,\n otherwise ``k==n_classes``. For binary classification,\n values closer to -1 or 1 mean more like the first or second\n class in ``classes_``, respectively.\n \"\"\"\n check_is_fitted(self)\n X = self._check_X(X)\n n_classes = self.n_classes_\n classes = self.classes_[:, np.newaxis]\n pred = None\n norm = 0.0\n for (weight, estimator) in zip(self.estimator_weights_, self.estimators_):\n norm += weight\n if self.algorithm == 'SAMME.R':\n current_pred = _samme_proba(estimator, n_classes, X)\n else:\n current_pred = estimator.predict(X)\n current_pred = (current_pred == classes).T * weight\n if pred is None:\n pred = current_pred\n else:\n pred += current_pred\n if n_classes == 2:\n tmp_pred = np.copy(pred)\n tmp_pred[:, 0] *= -1\n yield (tmp_pred / norm).sum(axis=1)\n else:\n yield pred / norm\n \n @staticmethod\n def _compute_proba_from_decision(decision, n_classes):\n \"\"\"Compute probabilities from the decision function.\n\n This is based eq. (4) of [1] where:\n p(y=c|X) = exp((1 / K-1) f_c(X)) / sum_k(exp((1 / K-1) f_k(X)))\n = softmax((1 / K-1) * f(X))\n\n References\n ----------\n .. [1] J. Zhu, H. Zou, S. Rosset, T. Hastie, \"Multi-class AdaBoost\",\n 2009.\n \"\"\"\n if n_classes == 2:\n decision = np.vstack([-decision, decision]).T / 2\n else:\n decision /= n_classes - 1\n return softmax(decision, copy=False)\n \n def predict_proba(self, X):\n \"\"\"Predict class probabilities for X.\n\n The predicted class probabilities of an input sample is computed as\n the weighted mean predicted class probabilities of the classifiers\n in the ensemble.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\n Returns\n -------\n p : ndarray of shape (n_samples, n_classes)\n The class probabilities of the input samples. The order of\n outputs is the same of that of the :term:`classes_` attribute.\n \"\"\"\n check_is_fitted(self)\n X = self._check_X(X)\n n_classes = self.n_classes_\n if n_classes == 1:\n return np.ones((_num_samples(X), 1))\n decision = self.decision_function(X)\n return self._compute_proba_from_decision(decision, n_classes)\n \n def staged_predict_proba(self, X):\n \"\"\"Predict class probabilities for X.\n\n The predicted class probabilities of an input sample is computed as\n the weighted mean predicted class probabilities of the classifiers\n in the ensemble.\n\n This generator method yields the ensemble predicted class probabilities\n after each iteration of boosting and therefore allows monitoring, such\n as to determine the predicted class probabilities on a test set after\n each boost.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\n Yields\n -------\n p : generator of ndarray of shape (n_samples,)\n The class probabilities of the input samples. The order of\n outputs is the same of that of the :term:`classes_` attribute.\n \"\"\"\n X = self._check_X(X)\n n_classes = self.n_classes_\n for decision in self.staged_decision_function(X):\n yield self._compute_proba_from_decision(decision, n_classes)\n \n def predict_log_proba(self, X):\n \"\"\"Predict class log-probabilities for X.\n\n The predicted class log-probabilities of an input sample is computed as\n the weighted mean predicted class log-probabilities of the classifiers\n in the ensemble.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\n Returns\n -------\n p : ndarray of shape (n_samples, n_classes)\n The class probabilities of the input samples. The order of\n outputs is the same of that of the :term:`classes_` attribute.\n \"\"\"\n X = self._check_X(X)\n return np.log(self.predict_proba(X))\n" + "source_code": "\n\nclass AdaBoostClassifier(ClassifierMixin, BaseWeightBoosting):\n \"\"\"An AdaBoost classifier.\n\n An AdaBoost [1] classifier is a meta-estimator that begins by fitting a\n classifier on the original dataset and then fits additional copies of the\n classifier on the same dataset but where the weights of incorrectly\n classified instances are adjusted such that subsequent classifiers focus\n more on difficult cases.\n\n This class implements the algorithm known as AdaBoost-SAMME [2].\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.14\n\n Parameters\n ----------\n base_estimator : object, default=None\n The base estimator from which the boosted ensemble is built.\n Support for sample weighting is required, as well as proper\n ``classes_`` and ``n_classes_`` attributes. If ``None``, then\n the base estimator is :class:`~sklearn.tree.DecisionTreeClassifier`\n initialized with `max_depth=1`.\n\n n_estimators : int, default=50\n The maximum number of estimators at which boosting is terminated.\n In case of perfect fit, the learning procedure is stopped early.\n\n learning_rate : float, default=1.0\n Weight applied to each classifier at each boosting iteration. A higher\n learning rate increases the contribution of each classifier. There is\n a trade-off between the `learning_rate` and `n_estimators` parameters.\n\n algorithm : {'SAMME', 'SAMME.R'}, default='SAMME.R'\n If 'SAMME.R' then use the SAMME.R real boosting algorithm.\n ``base_estimator`` must support calculation of class probabilities.\n If 'SAMME' then use the SAMME discrete boosting algorithm.\n The SAMME.R algorithm typically converges faster than SAMME,\n achieving a lower test error with fewer boosting iterations.\n\n random_state : int, RandomState instance or None, default=None\n Controls the random seed given at each `base_estimator` at each\n boosting iteration.\n Thus, it is only used when `base_estimator` exposes a `random_state`.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n Attributes\n ----------\n base_estimator_ : estimator\n The base estimator from which the ensemble is grown.\n\n estimators_ : list of classifiers\n The collection of fitted sub-estimators.\n\n classes_ : ndarray of shape (n_classes,)\n The classes labels.\n\n n_classes_ : int\n The number of classes.\n\n estimator_weights_ : ndarray of floats\n Weights for each estimator in the boosted ensemble.\n\n estimator_errors_ : ndarray of floats\n Classification error for each estimator in the boosted\n ensemble.\n\n feature_importances_ : ndarray of shape (n_features,)\n The impurity-based feature importances if supported by the\n ``base_estimator`` (when based on decision trees).\n\n Warning: impurity-based feature importances can be misleading for\n high cardinality features (many unique values). See\n :func:`sklearn.inspection.permutation_importance` as an alternative.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n AdaBoostRegressor : An AdaBoost regressor that begins by fitting a\n regressor on the original dataset and then fits additional copies of\n the regressor on the same dataset but where the weights of instances\n are adjusted according to the error of the current prediction.\n\n GradientBoostingClassifier : GB builds an additive model in a forward\n stage-wise fashion. Regression trees are fit on the negative gradient\n of the binomial or multinomial deviance loss function. Binary\n classification is a special case where only a single regression tree is\n induced.\n\n sklearn.tree.DecisionTreeClassifier : A non-parametric supervised learning\n method used for classification.\n Creates a model that predicts the value of a target variable by\n learning simple decision rules inferred from the data features.\n\n References\n ----------\n .. [1] Y. Freund, R. Schapire, \"A Decision-Theoretic Generalization of\n on-Line Learning and an Application to Boosting\", 1995.\n\n .. [2] J. Zhu, H. Zou, S. Rosset, T. Hastie, \"Multi-class AdaBoost\", 2009.\n\n Examples\n --------\n >>> from sklearn.ensemble import AdaBoostClassifier\n >>> from sklearn.datasets import make_classification\n >>> X, y = make_classification(n_samples=1000, n_features=4,\n ... n_informative=2, n_redundant=0,\n ... random_state=0, shuffle=False)\n >>> clf = AdaBoostClassifier(n_estimators=100, random_state=0)\n >>> clf.fit(X, y)\n AdaBoostClassifier(n_estimators=100, random_state=0)\n >>> clf.predict([[0, 0, 0, 0]])\n array([1])\n >>> clf.score(X, y)\n 0.983...\n \"\"\"\n \n def __init__(self, base_estimator=None, *, n_estimators=50, learning_rate=1.0, algorithm='SAMME.R', random_state=None):\n super().__init__(base_estimator=base_estimator, n_estimators=n_estimators, learning_rate=learning_rate, random_state=random_state)\n self.algorithm = algorithm\n \n def fit(self, X, y, sample_weight=None):\n \"\"\"Build a boosted classifier from the training set (X, y).\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\n y : array-like of shape (n_samples,)\n The target values (class labels).\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, the sample weights are initialized to\n ``1 / n_samples``.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n if self.algorithm not in ('SAMME', 'SAMME.R'):\n raise ValueError('algorithm %s is not supported' % self.algorithm)\n return super().fit(X, y, sample_weight)\n \n def _validate_estimator(self):\n \"\"\"Check the estimator and set the base_estimator_ attribute.\"\"\"\n super()._validate_estimator(default=DecisionTreeClassifier(max_depth=1))\n if self.algorithm == 'SAMME.R':\n if not hasattr(self.base_estimator_, 'predict_proba'):\n raise TypeError(\"AdaBoostClassifier with algorithm='SAMME.R' requires that the weak learner supports the calculation of class probabilities with a predict_proba method.\\nPlease change the base estimator or set algorithm='SAMME' instead.\")\n if not has_fit_parameter(self.base_estimator_, 'sample_weight'):\n raise ValueError(\"%s doesn't support sample_weight.\" % self.base_estimator_.__class__.__name__)\n \n def _boost(self, iboost, X, y, sample_weight, random_state):\n \"\"\"Implement a single boost.\n\n Perform a single boost according to the real multi-class SAMME.R\n algorithm or to the discrete SAMME algorithm and return the updated\n sample weights.\n\n Parameters\n ----------\n iboost : int\n The index of the current boost iteration.\n\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples.\n\n y : array-like of shape (n_samples,)\n The target values (class labels).\n\n sample_weight : array-like of shape (n_samples,)\n The current sample weights.\n\n random_state : RandomState instance\n The RandomState instance used if the base estimator accepts a\n `random_state` attribute.\n\n Returns\n -------\n sample_weight : array-like of shape (n_samples,) or None\n The reweighted sample weights.\n If None then boosting has terminated early.\n\n estimator_weight : float\n The weight for the current boost.\n If None then boosting has terminated early.\n\n estimator_error : float\n The classification error for the current boost.\n If None then boosting has terminated early.\n \"\"\"\n if self.algorithm == 'SAMME.R':\n return self._boost_real(iboost, X, y, sample_weight, random_state)\n else:\n return self._boost_discrete(iboost, X, y, sample_weight, random_state)\n \n def _boost_real(self, iboost, X, y, sample_weight, random_state):\n \"\"\"Implement a single boost using the SAMME.R real algorithm.\"\"\"\n estimator = self._make_estimator(random_state=random_state)\n estimator.fit(X, y, sample_weight=sample_weight)\n y_predict_proba = estimator.predict_proba(X)\n if iboost == 0:\n self.classes_ = getattr(estimator, 'classes_', None)\n self.n_classes_ = len(self.classes_)\n y_predict = self.classes_.take(np.argmax(y_predict_proba, axis=1), axis=0)\n incorrect = y_predict != y\n estimator_error = np.mean(np.average(incorrect, weights=sample_weight, axis=0))\n if estimator_error <= 0:\n return sample_weight, 1.0, 0.0\n n_classes = self.n_classes_\n classes = self.classes_\n y_codes = np.array([-1.0 / (n_classes - 1), 1.0])\n y_coding = y_codes.take(classes == y[:, np.newaxis])\n proba = y_predict_proba\n np.clip(proba, np.finfo(proba.dtype).eps, None, out=proba)\n estimator_weight = -1.0 * self.learning_rate * ((n_classes - 1.0) / n_classes) * xlogy(y_coding, y_predict_proba).sum(axis=1)\n if not iboost == self.n_estimators - 1:\n sample_weight *= np.exp(estimator_weight * ((sample_weight > 0) | (estimator_weight < 0)))\n return sample_weight, 1.0, estimator_error\n \n def _boost_discrete(self, iboost, X, y, sample_weight, random_state):\n \"\"\"Implement a single boost using the SAMME discrete algorithm.\"\"\"\n estimator = self._make_estimator(random_state=random_state)\n estimator.fit(X, y, sample_weight=sample_weight)\n y_predict = estimator.predict(X)\n if iboost == 0:\n self.classes_ = getattr(estimator, 'classes_', None)\n self.n_classes_ = len(self.classes_)\n incorrect = y_predict != y\n estimator_error = np.mean(np.average(incorrect, weights=sample_weight, axis=0))\n if estimator_error <= 0:\n return sample_weight, 1.0, 0.0\n n_classes = self.n_classes_\n if estimator_error >= 1.0 - 1.0 / n_classes:\n self.estimators_.pop(-1)\n if len(self.estimators_) == 0:\n raise ValueError('BaseClassifier in AdaBoostClassifier ensemble is worse than random, ensemble can not be fit.')\n return None, None, None\n estimator_weight = self.learning_rate * (np.log((1.0 - estimator_error) / estimator_error) + np.log(n_classes - 1.0))\n if not iboost == self.n_estimators - 1:\n sample_weight = np.exp(np.log(sample_weight) + estimator_weight * incorrect * (sample_weight > 0))\n return sample_weight, estimator_weight, estimator_error\n \n def predict(self, X):\n \"\"\"Predict classes for X.\n\n The predicted class of an input sample is computed as the weighted mean\n prediction of the classifiers in the ensemble.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\n Returns\n -------\n y : ndarray of shape (n_samples,)\n The predicted classes.\n \"\"\"\n pred = self.decision_function(X)\n if self.n_classes_ == 2:\n return self.classes_.take(pred > 0, axis=0)\n return self.classes_.take(np.argmax(pred, axis=1), axis=0)\n \n def staged_predict(self, X):\n \"\"\"Return staged predictions for X.\n\n The predicted class of an input sample is computed as the weighted mean\n prediction of the classifiers in the ensemble.\n\n This generator method yields the ensemble prediction after each\n iteration of boosting and therefore allows monitoring, such as to\n determine the prediction on a test set after each boost.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\n Yields\n ------\n y : generator of ndarray of shape (n_samples,)\n The predicted classes.\n \"\"\"\n X = self._check_X(X)\n n_classes = self.n_classes_\n classes = self.classes_\n if n_classes == 2:\n for pred in self.staged_decision_function(X):\n yield np.array(classes.take(pred > 0, axis=0))\n else:\n for pred in self.staged_decision_function(X):\n yield np.array(classes.take(np.argmax(pred, axis=1), axis=0))\n \n def decision_function(self, X):\n \"\"\"Compute the decision function of ``X``.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\n Returns\n -------\n score : ndarray of shape of (n_samples, k)\n The decision function of the input samples. The order of\n outputs is the same of that of the :term:`classes_` attribute.\n Binary classification is a special cases with ``k == 1``,\n otherwise ``k==n_classes``. For binary classification,\n values closer to -1 or 1 mean more like the first or second\n class in ``classes_``, respectively.\n \"\"\"\n check_is_fitted(self)\n X = self._check_X(X)\n n_classes = self.n_classes_\n classes = self.classes_[:, np.newaxis]\n if self.algorithm == 'SAMME.R':\n pred = sum((_samme_proba(estimator, n_classes, X) for estimator in self.estimators_))\n else:\n pred = sum(((estimator.predict(X) == classes).T * w for (estimator, w) in zip(self.estimators_, self.estimator_weights_)))\n pred /= self.estimator_weights_.sum()\n if n_classes == 2:\n pred[:, 0] *= -1\n return pred.sum(axis=1)\n return pred\n \n def staged_decision_function(self, X):\n \"\"\"Compute decision function of ``X`` for each boosting iteration.\n\n This method allows monitoring (i.e. determine error on testing set)\n after each boosting iteration.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\n Yields\n ------\n score : generator of ndarray of shape (n_samples, k)\n The decision function of the input samples. The order of\n outputs is the same of that of the :term:`classes_` attribute.\n Binary classification is a special cases with ``k == 1``,\n otherwise ``k==n_classes``. For binary classification,\n values closer to -1 or 1 mean more like the first or second\n class in ``classes_``, respectively.\n \"\"\"\n check_is_fitted(self)\n X = self._check_X(X)\n n_classes = self.n_classes_\n classes = self.classes_[:, np.newaxis]\n pred = None\n norm = 0.0\n for (weight, estimator) in zip(self.estimator_weights_, self.estimators_):\n norm += weight\n if self.algorithm == 'SAMME.R':\n current_pred = _samme_proba(estimator, n_classes, X)\n else:\n current_pred = estimator.predict(X)\n current_pred = (current_pred == classes).T * weight\n if pred is None:\n pred = current_pred\n else:\n pred += current_pred\n if n_classes == 2:\n tmp_pred = np.copy(pred)\n tmp_pred[:, 0] *= -1\n yield (tmp_pred / norm).sum(axis=1)\n else:\n yield pred / norm\n \n @staticmethod\n def _compute_proba_from_decision(decision, n_classes):\n \"\"\"Compute probabilities from the decision function.\n\n This is based eq. (4) of [1] where:\n p(y=c|X) = exp((1 / K-1) f_c(X)) / sum_k(exp((1 / K-1) f_k(X)))\n = softmax((1 / K-1) * f(X))\n\n References\n ----------\n .. [1] J. Zhu, H. Zou, S. Rosset, T. Hastie, \"Multi-class AdaBoost\",\n 2009.\n \"\"\"\n if n_classes == 2:\n decision = np.vstack([-decision, decision]).T / 2\n else:\n decision /= n_classes - 1\n return softmax(decision, copy=False)\n \n def predict_proba(self, X):\n \"\"\"Predict class probabilities for X.\n\n The predicted class probabilities of an input sample is computed as\n the weighted mean predicted class probabilities of the classifiers\n in the ensemble.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\n Returns\n -------\n p : ndarray of shape (n_samples, n_classes)\n The class probabilities of the input samples. The order of\n outputs is the same of that of the :term:`classes_` attribute.\n \"\"\"\n check_is_fitted(self)\n n_classes = self.n_classes_\n if n_classes == 1:\n return np.ones((_num_samples(X), 1))\n decision = self.decision_function(X)\n return self._compute_proba_from_decision(decision, n_classes)\n \n def staged_predict_proba(self, X):\n \"\"\"Predict class probabilities for X.\n\n The predicted class probabilities of an input sample is computed as\n the weighted mean predicted class probabilities of the classifiers\n in the ensemble.\n\n This generator method yields the ensemble predicted class probabilities\n after each iteration of boosting and therefore allows monitoring, such\n as to determine the predicted class probabilities on a test set after\n each boost.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\n Yields\n ------\n p : generator of ndarray of shape (n_samples,)\n The class probabilities of the input samples. The order of\n outputs is the same of that of the :term:`classes_` attribute.\n \"\"\"\n n_classes = self.n_classes_\n for decision in self.staged_decision_function(X):\n yield self._compute_proba_from_decision(decision, n_classes)\n \n def predict_log_proba(self, X):\n \"\"\"Predict class log-probabilities for X.\n\n The predicted class log-probabilities of an input sample is computed as\n the weighted mean predicted class log-probabilities of the classifiers\n in the ensemble.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\n Returns\n -------\n p : ndarray of shape (n_samples, n_classes)\n The class probabilities of the input samples. The order of\n outputs is the same of that of the :term:`classes_` attribute.\n \"\"\"\n return np.log(self.predict_proba(X))\n" }, { "name": "AdaBoostRegressor", @@ -21738,7 +21705,7 @@ "sklearn.ensemble._weight_boosting.BaseWeightBoosting.fit", "sklearn.ensemble._weight_boosting.BaseWeightBoosting._boost", "sklearn.ensemble._weight_boosting.BaseWeightBoosting.staged_score", - "sklearn.ensemble._weight_boosting.BaseWeightBoosting.feature_importances_" + "sklearn.ensemble._weight_boosting.BaseWeightBoosting.feature_importances_@getter" ], "is_public": false, "description": "Base class for AdaBoost estimators.\n\nWarning: This class should not be used directly. Use derived classes instead.", @@ -22222,17 +22189,17 @@ "sklearn.externals._packaging.version.LegacyVersion.__init__", "sklearn.externals._packaging.version.LegacyVersion.__str__", "sklearn.externals._packaging.version.LegacyVersion.__repr__", - "sklearn.externals._packaging.version.LegacyVersion.public", - "sklearn.externals._packaging.version.LegacyVersion.base_version", - "sklearn.externals._packaging.version.LegacyVersion.epoch", - "sklearn.externals._packaging.version.LegacyVersion.release", - "sklearn.externals._packaging.version.LegacyVersion.pre", - "sklearn.externals._packaging.version.LegacyVersion.post", - "sklearn.externals._packaging.version.LegacyVersion.dev", - "sklearn.externals._packaging.version.LegacyVersion.local", - "sklearn.externals._packaging.version.LegacyVersion.is_prerelease", - "sklearn.externals._packaging.version.LegacyVersion.is_postrelease", - "sklearn.externals._packaging.version.LegacyVersion.is_devrelease" + "sklearn.externals._packaging.version.LegacyVersion.public@getter", + "sklearn.externals._packaging.version.LegacyVersion.base_version@getter", + "sklearn.externals._packaging.version.LegacyVersion.epoch@getter", + "sklearn.externals._packaging.version.LegacyVersion.release@getter", + "sklearn.externals._packaging.version.LegacyVersion.pre@getter", + "sklearn.externals._packaging.version.LegacyVersion.post@getter", + "sklearn.externals._packaging.version.LegacyVersion.dev@getter", + "sklearn.externals._packaging.version.LegacyVersion.local@getter", + "sklearn.externals._packaging.version.LegacyVersion.is_prerelease@getter", + "sklearn.externals._packaging.version.LegacyVersion.is_postrelease@getter", + "sklearn.externals._packaging.version.LegacyVersion.is_devrelease@getter" ], "is_public": false, "description": "", @@ -22248,20 +22215,20 @@ "sklearn.externals._packaging.version.Version.__init__", "sklearn.externals._packaging.version.Version.__repr__", "sklearn.externals._packaging.version.Version.__str__", - "sklearn.externals._packaging.version.Version.epoch", - "sklearn.externals._packaging.version.Version.release", - "sklearn.externals._packaging.version.Version.pre", - "sklearn.externals._packaging.version.Version.post", - "sklearn.externals._packaging.version.Version.dev", - "sklearn.externals._packaging.version.Version.local", - "sklearn.externals._packaging.version.Version.public", - "sklearn.externals._packaging.version.Version.base_version", - "sklearn.externals._packaging.version.Version.is_prerelease", - "sklearn.externals._packaging.version.Version.is_postrelease", - "sklearn.externals._packaging.version.Version.is_devrelease", - "sklearn.externals._packaging.version.Version.major", - "sklearn.externals._packaging.version.Version.minor", - "sklearn.externals._packaging.version.Version.micro" + "sklearn.externals._packaging.version.Version.epoch@getter", + "sklearn.externals._packaging.version.Version.release@getter", + "sklearn.externals._packaging.version.Version.pre@getter", + "sklearn.externals._packaging.version.Version.post@getter", + "sklearn.externals._packaging.version.Version.dev@getter", + "sklearn.externals._packaging.version.Version.local@getter", + "sklearn.externals._packaging.version.Version.public@getter", + "sklearn.externals._packaging.version.Version.base_version@getter", + "sklearn.externals._packaging.version.Version.is_prerelease@getter", + "sklearn.externals._packaging.version.Version.is_postrelease@getter", + "sklearn.externals._packaging.version.Version.is_devrelease@getter", + "sklearn.externals._packaging.version.Version.major@getter", + "sklearn.externals._packaging.version.Version.minor@getter", + "sklearn.externals._packaging.version.Version.micro@getter" ], "is_public": false, "description": "", @@ -22287,21 +22254,6 @@ "docstring": null, "source_code": "\n\nclass _BaseVersion:\n _key: Union[CmpKey, LegacyCmpKey]\n \n def __hash__(self) -> int:\n return hash(self._key)\n \n def __lt__(self, other: '_BaseVersion') -> bool:\n if not isinstance(other, _BaseVersion):\n return NotImplemented\n return self._key < other._key\n \n def __le__(self, other: '_BaseVersion') -> bool:\n if not isinstance(other, _BaseVersion):\n return NotImplemented\n return self._key <= other._key\n \n def __eq__(self, other: object) -> bool:\n if not isinstance(other, _BaseVersion):\n return NotImplemented\n return self._key == other._key\n \n def __ge__(self, other: '_BaseVersion') -> bool:\n if not isinstance(other, _BaseVersion):\n return NotImplemented\n return self._key >= other._key\n \n def __gt__(self, other: '_BaseVersion') -> bool:\n if not isinstance(other, _BaseVersion):\n return NotImplemented\n return self._key > other._key\n \n def __ne__(self, other: object) -> bool:\n if not isinstance(other, _BaseVersion):\n return NotImplemented\n return self._key != other._key\n" }, - { - "name": "Pep562", - "qname": "sklearn.externals._pep562.Pep562", - "decorators": [], - "superclasses": ["object"], - "methods": [ - "sklearn.externals._pep562.Pep562.__init__", - "sklearn.externals._pep562.Pep562.__dir__", - "sklearn.externals._pep562.Pep562.__getattr__" - ], - "is_public": false, - "description": "Backport of PEP 562 .\n\nWraps the module in a class that exposes the mechanics to override `__dir__` and `__getattr__`. The given module will be searched for overrides of `__dir__` and `__getattr__` and use them when needed.", - "docstring": "\n Backport of PEP 562 .\n\n Wraps the module in a class that exposes the mechanics to override `__dir__` and `__getattr__`.\n The given module will be searched for overrides of `__dir__` and `__getattr__` and use them when needed.\n ", - "source_code": "\n\nclass Pep562(object):\n \"\"\"\n Backport of PEP 562 .\n\n Wraps the module in a class that exposes the mechanics to override `__dir__` and `__getattr__`.\n The given module will be searched for overrides of `__dir__` and `__getattr__` and use them when needed.\n \"\"\"\n \n def __init__(self, name):\n \"\"\"Acquire `__getattr__` and `__dir__`, but only replace module for versions less than Python 3.7.\"\"\"\n self._module = sys.modules[name]\n self._get_attr = getattr(self._module, '__getattr__', None)\n self._get_dir = getattr(self._module, '__dir__', None)\n sys.modules[name] = self\n \n def __dir__(self):\n \"\"\"Return the overridden `dir` if one was provided, else apply `dir` to the module.\"\"\"\n return self._get_dir() if self._get_dir else dir(self._module)\n \n def __getattr__(self, name):\n \"\"\"Attempt to retrieve the attribute from the module, and if missing, use the overridden function if present.\"\"\"\n try:\n return getattr(self._module, name)\n except AttributeError:\n if self._get_attr:\n return self._get_attr(name)\n raise\n" - }, { "name": "DictVectorizer", "qname": "sklearn.feature_extraction._dict_vectorizer.DictVectorizer", @@ -22354,9 +22306,9 @@ "sklearn.feature_extraction.image.PatchExtractor._more_tags" ], "is_public": true, - "description": "Extracts patches from a collection of images\n\nRead more in the :ref:`User Guide `. .. versionadded:: 0.9", - "docstring": "Extracts patches from a collection of images\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.9\n\n Parameters\n ----------\n patch_size : tuple of int (patch_height, patch_width), default=None\n The dimensions of one patch.\n\n max_patches : int or float, default=None\n The maximum number of patches per image to extract. If max_patches is a\n float in (0, 1), it is taken to mean a proportion of the total number\n of patches.\n\n random_state : int, RandomState instance, default=None\n Determines the random number generator used for random sampling when\n `max_patches` is not None. Use an int to make the randomness\n deterministic.\n See :term:`Glossary `.\n\n Examples\n --------\n >>> from sklearn.datasets import load_sample_images\n >>> from sklearn.feature_extraction import image\n >>> # Use the array data from the second image in this dataset:\n >>> X = load_sample_images().images[1]\n >>> print('Image shape: {}'.format(X.shape))\n Image shape: (427, 640, 3)\n >>> pe = image.PatchExtractor(patch_size=(2, 2))\n >>> pe_fit = pe.fit(X)\n >>> pe_trans = pe.transform(X)\n >>> print('Patches shape: {}'.format(pe_trans.shape))\n Patches shape: (545706, 2, 2)\n ", - "source_code": "\n\nclass PatchExtractor(BaseEstimator):\n \"\"\"Extracts patches from a collection of images\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.9\n\n Parameters\n ----------\n patch_size : tuple of int (patch_height, patch_width), default=None\n The dimensions of one patch.\n\n max_patches : int or float, default=None\n The maximum number of patches per image to extract. If max_patches is a\n float in (0, 1), it is taken to mean a proportion of the total number\n of patches.\n\n random_state : int, RandomState instance, default=None\n Determines the random number generator used for random sampling when\n `max_patches` is not None. Use an int to make the randomness\n deterministic.\n See :term:`Glossary `.\n\n Examples\n --------\n >>> from sklearn.datasets import load_sample_images\n >>> from sklearn.feature_extraction import image\n >>> # Use the array data from the second image in this dataset:\n >>> X = load_sample_images().images[1]\n >>> print('Image shape: {}'.format(X.shape))\n Image shape: (427, 640, 3)\n >>> pe = image.PatchExtractor(patch_size=(2, 2))\n >>> pe_fit = pe.fit(X)\n >>> pe_trans = pe.transform(X)\n >>> print('Patches shape: {}'.format(pe_trans.shape))\n Patches shape: (545706, 2, 2)\n \"\"\"\n \n def __init__(self, *, patch_size=None, max_patches=None, random_state=None):\n self.patch_size = patch_size\n self.max_patches = max_patches\n self.random_state = random_state\n \n def fit(self, X, y=None):\n \"\"\"Do nothing and return the estimator unchanged.\n\n This method is just there to implement the usual API and hence\n work in pipelines.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training data.\n \"\"\"\n return self\n \n def transform(self, X):\n \"\"\"Transforms the image samples in X into a matrix of patch data.\n\n Parameters\n ----------\n X : ndarray of shape (n_samples, image_height, image_width) or (n_samples, image_height, image_width, n_channels)\n Array of images from which to extract patches. For color images,\n the last dimension specifies the channel: a RGB image would have\n `n_channels=3`.\n\n Returns\n -------\n patches : array of shape (n_patches, patch_height, patch_width) or (n_patches, patch_height, patch_width, n_channels)\n The collection of patches extracted from the images, where\n `n_patches` is either `n_samples * max_patches` or the total\n number of patches that can be extracted.\n \"\"\"\n self.random_state = check_random_state(self.random_state)\n (n_images, i_h, i_w) = X.shape[:3]\n X = np.reshape(X, (n_images, i_h, i_w, -1))\n n_channels = X.shape[-1]\n if self.patch_size is None:\n patch_size = (i_h // 10, i_w // 10)\n else:\n patch_size = self.patch_size\n (p_h, p_w) = patch_size\n n_patches = _compute_n_patches(i_h, i_w, p_h, p_w, self.max_patches)\n patches_shape = (n_images * n_patches, ) + patch_size\n if n_channels > 1:\n patches_shape += (n_channels, )\n patches = np.empty(patches_shape)\n for (ii, image) in enumerate(X):\n patches[ii * n_patches:(ii + 1) * n_patches] = extract_patches_2d(image, patch_size, max_patches=self.max_patches, random_state=self.random_state)\n return patches\n \n def _more_tags(self):\n return {'X_types': ['3darray']}\n" + "description": "Extracts patches from a collection of images.\n\nRead more in the :ref:`User Guide `. .. versionadded:: 0.9", + "docstring": "Extracts patches from a collection of images.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.9\n\n Parameters\n ----------\n patch_size : tuple of int (patch_height, patch_width), default=None\n The dimensions of one patch.\n\n max_patches : int or float, default=None\n The maximum number of patches per image to extract. If `max_patches` is\n a float in (0, 1), it is taken to mean a proportion of the total number\n of patches.\n\n random_state : int, RandomState instance, default=None\n Determines the random number generator used for random sampling when\n `max_patches is not None`. Use an int to make the randomness\n deterministic.\n See :term:`Glossary `.\n\n See Also\n --------\n reconstruct_from_patches_2d : Reconstruct image from all of its patches.\n\n Examples\n --------\n >>> from sklearn.datasets import load_sample_images\n >>> from sklearn.feature_extraction import image\n >>> # Use the array data from the second image in this dataset:\n >>> X = load_sample_images().images[1]\n >>> print('Image shape: {}'.format(X.shape))\n Image shape: (427, 640, 3)\n >>> pe = image.PatchExtractor(patch_size=(2, 2))\n >>> pe_fit = pe.fit(X)\n >>> pe_trans = pe.transform(X)\n >>> print('Patches shape: {}'.format(pe_trans.shape))\n Patches shape: (545706, 2, 2)\n ", + "source_code": "\n\nclass PatchExtractor(BaseEstimator):\n \"\"\"Extracts patches from a collection of images.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.9\n\n Parameters\n ----------\n patch_size : tuple of int (patch_height, patch_width), default=None\n The dimensions of one patch.\n\n max_patches : int or float, default=None\n The maximum number of patches per image to extract. If `max_patches` is\n a float in (0, 1), it is taken to mean a proportion of the total number\n of patches.\n\n random_state : int, RandomState instance, default=None\n Determines the random number generator used for random sampling when\n `max_patches is not None`. Use an int to make the randomness\n deterministic.\n See :term:`Glossary `.\n\n See Also\n --------\n reconstruct_from_patches_2d : Reconstruct image from all of its patches.\n\n Examples\n --------\n >>> from sklearn.datasets import load_sample_images\n >>> from sklearn.feature_extraction import image\n >>> # Use the array data from the second image in this dataset:\n >>> X = load_sample_images().images[1]\n >>> print('Image shape: {}'.format(X.shape))\n Image shape: (427, 640, 3)\n >>> pe = image.PatchExtractor(patch_size=(2, 2))\n >>> pe_fit = pe.fit(X)\n >>> pe_trans = pe.transform(X)\n >>> print('Patches shape: {}'.format(pe_trans.shape))\n Patches shape: (545706, 2, 2)\n \"\"\"\n \n def __init__(self, *, patch_size=None, max_patches=None, random_state=None):\n self.patch_size = patch_size\n self.max_patches = max_patches\n self.random_state = random_state\n \n def fit(self, X, y=None):\n \"\"\"Do nothing and return the estimator unchanged.\n\n This method is just there to implement the usual API and hence\n work in pipelines.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training data.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n return self\n \n def transform(self, X):\n \"\"\"Transform the image samples in `X` into a matrix of patch data.\n\n Parameters\n ----------\n X : ndarray of shape (n_samples, image_height, image_width) or (n_samples, image_height, image_width, n_channels)\n Array of images from which to extract patches. For color images,\n the last dimension specifies the channel: a RGB image would have\n `n_channels=3`.\n\n Returns\n -------\n patches : array of shape (n_patches, patch_height, patch_width) or (n_patches, patch_height, patch_width, n_channels)\n The collection of patches extracted from the images, where\n `n_patches` is either `n_samples * max_patches` or the total\n number of patches that can be extracted.\n \"\"\"\n self.random_state = check_random_state(self.random_state)\n (n_images, i_h, i_w) = X.shape[:3]\n X = np.reshape(X, (n_images, i_h, i_w, -1))\n n_channels = X.shape[-1]\n if self.patch_size is None:\n patch_size = (i_h // 10, i_w // 10)\n else:\n patch_size = self.patch_size\n (p_h, p_w) = patch_size\n n_patches = _compute_n_patches(i_h, i_w, p_h, p_w, self.max_patches)\n patches_shape = (n_images * n_patches, ) + patch_size\n if n_channels > 1:\n patches_shape += (n_channels, )\n patches = np.empty(patches_shape)\n for (ii, image) in enumerate(X):\n patches[ii * n_patches:(ii + 1) * n_patches] = extract_patches_2d(image, patch_size, max_patches=self.max_patches, random_state=self.random_state)\n return patches\n \n def _more_tags(self):\n return {'X_types': ['3darray']}\n" }, { "name": "CountVectorizer", @@ -22368,6 +22320,7 @@ "sklearn.feature_extraction.text.CountVectorizer._sort_features", "sklearn.feature_extraction.text.CountVectorizer._limit_features", "sklearn.feature_extraction.text.CountVectorizer._count_vocab", + "sklearn.feature_extraction.text.CountVectorizer._validate_params", "sklearn.feature_extraction.text.CountVectorizer.fit", "sklearn.feature_extraction.text.CountVectorizer.fit_transform", "sklearn.feature_extraction.text.CountVectorizer.transform", @@ -22379,7 +22332,7 @@ "is_public": true, "description": "Convert a collection of text documents to a matrix of token counts.\n\nThis implementation produces a sparse representation of the counts using scipy.sparse.csr_matrix. If you do not provide an a-priori dictionary and you do not use an analyzer that does some kind of feature selection then the number of features will be equal to the vocabulary size found by analyzing the data. Read more in the :ref:`User Guide `.", "docstring": "Convert a collection of text documents to a matrix of token counts.\n\n This implementation produces a sparse representation of the counts using\n scipy.sparse.csr_matrix.\n\n If you do not provide an a-priori dictionary and you do not use an analyzer\n that does some kind of feature selection then the number of features will\n be equal to the vocabulary size found by analyzing the data.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n input : {'filename', 'file', 'content'}, default='content'\n - If `'filename'`, the sequence passed as an argument to fit is\n expected to be a list of filenames that need reading to fetch\n the raw content to analyze.\n\n - If `'file'`, the sequence items must have a 'read' method (file-like\n object) that is called to fetch the bytes in memory.\n\n - If `'content'`, the input is expected to be a sequence of items that\n can be of type string or byte.\n\n encoding : str, default='utf-8'\n If bytes or files are given to analyze, this encoding is used to\n decode.\n\n decode_error : {'strict', 'ignore', 'replace'}, default='strict'\n Instruction on what to do if a byte sequence is given to analyze that\n contains characters not of the given `encoding`. By default, it is\n 'strict', meaning that a UnicodeDecodeError will be raised. Other\n values are 'ignore' and 'replace'.\n\n strip_accents : {'ascii', 'unicode'}, default=None\n Remove accents and perform other character normalization\n during the preprocessing step.\n 'ascii' is a fast method that only works on characters that have\n an direct ASCII mapping.\n 'unicode' is a slightly slower method that works on any characters.\n None (default) does nothing.\n\n Both 'ascii' and 'unicode' use NFKD normalization from\n :func:`unicodedata.normalize`.\n\n lowercase : bool, default=True\n Convert all characters to lowercase before tokenizing.\n\n preprocessor : callable, default=None\n Override the preprocessing (strip_accents and lowercase) stage while\n preserving the tokenizing and n-grams generation steps.\n Only applies if ``analyzer is not callable``.\n\n tokenizer : callable, default=None\n Override the string tokenization step while preserving the\n preprocessing and n-grams generation steps.\n Only applies if ``analyzer == 'word'``.\n\n stop_words : {'english'}, list, default=None\n If 'english', a built-in stop word list for English is used.\n There are several known issues with 'english' and you should\n consider an alternative (see :ref:`stop_words`).\n\n If a list, that list is assumed to contain stop words, all of which\n will be removed from the resulting tokens.\n Only applies if ``analyzer == 'word'``.\n\n If None, no stop words will be used. max_df can be set to a value\n in the range [0.7, 1.0) to automatically detect and filter stop\n words based on intra corpus document frequency of terms.\n\n token_pattern : str, default=r\"(?u)\\\\b\\\\w\\\\w+\\\\b\"\n Regular expression denoting what constitutes a \"token\", only used\n if ``analyzer == 'word'``. The default regexp select tokens of 2\n or more alphanumeric characters (punctuation is completely ignored\n and always treated as a token separator).\n\n If there is a capturing group in token_pattern then the\n captured group content, not the entire match, becomes the token.\n At most one capturing group is permitted.\n\n ngram_range : tuple (min_n, max_n), default=(1, 1)\n The lower and upper boundary of the range of n-values for different\n word n-grams or char n-grams to be extracted. All values of n such\n such that min_n <= n <= max_n will be used. For example an\n ``ngram_range`` of ``(1, 1)`` means only unigrams, ``(1, 2)`` means\n unigrams and bigrams, and ``(2, 2)`` means only bigrams.\n Only applies if ``analyzer is not callable``.\n\n analyzer : {'word', 'char', 'char_wb'} or callable, default='word'\n Whether the feature should be made of word n-gram or character\n n-grams.\n Option 'char_wb' creates character n-grams only from text inside\n word boundaries; n-grams at the edges of words are padded with space.\n\n If a callable is passed it is used to extract the sequence of features\n out of the raw, unprocessed input.\n\n .. versionchanged:: 0.21\n\n Since v0.21, if ``input`` is ``filename`` or ``file``, the data is\n first read from the file and then passed to the given callable\n analyzer.\n\n max_df : float in range [0.0, 1.0] or int, default=1.0\n When building the vocabulary ignore terms that have a document\n frequency strictly higher than the given threshold (corpus-specific\n stop words).\n If float, the parameter represents a proportion of documents, integer\n absolute counts.\n This parameter is ignored if vocabulary is not None.\n\n min_df : float in range [0.0, 1.0] or int, default=1\n When building the vocabulary ignore terms that have a document\n frequency strictly lower than the given threshold. This value is also\n called cut-off in the literature.\n If float, the parameter represents a proportion of documents, integer\n absolute counts.\n This parameter is ignored if vocabulary is not None.\n\n max_features : int, default=None\n If not None, build a vocabulary that only consider the top\n max_features ordered by term frequency across the corpus.\n\n This parameter is ignored if vocabulary is not None.\n\n vocabulary : Mapping or iterable, default=None\n Either a Mapping (e.g., a dict) where keys are terms and values are\n indices in the feature matrix, or an iterable over terms. If not\n given, a vocabulary is determined from the input documents. Indices\n in the mapping should not be repeated and should not have any gap\n between 0 and the largest index.\n\n binary : bool, default=False\n If True, all non zero counts are set to 1. This is useful for discrete\n probabilistic models that model binary events rather than integer\n counts.\n\n dtype : type, default=np.int64\n Type of the matrix returned by fit_transform() or transform().\n\n Attributes\n ----------\n vocabulary_ : dict\n A mapping of terms to feature indices.\n\n fixed_vocabulary_ : bool\n True if a fixed vocabulary of term to indices mapping\n is provided by the user.\n\n stop_words_ : set\n Terms that were ignored because they either:\n\n - occurred in too many documents (`max_df`)\n - occurred in too few documents (`min_df`)\n - were cut off by feature selection (`max_features`).\n\n This is only available if no vocabulary was given.\n\n See Also\n --------\n HashingVectorizer : Convert a collection of text documents to a\n matrix of token counts.\n\n TfidfVectorizer : Convert a collection of raw documents to a matrix\n of TF-IDF features.\n\n Notes\n -----\n The ``stop_words_`` attribute can get large and increase the model size\n when pickling. This attribute is provided only for introspection and can\n be safely removed using delattr or set to None before pickling.\n\n Examples\n --------\n >>> from sklearn.feature_extraction.text import CountVectorizer\n >>> corpus = [\n ... 'This is the first document.',\n ... 'This document is the second document.',\n ... 'And this is the third one.',\n ... 'Is this the first document?',\n ... ]\n >>> vectorizer = CountVectorizer()\n >>> X = vectorizer.fit_transform(corpus)\n >>> vectorizer.get_feature_names_out()\n array(['and', 'document', 'first', 'is', 'one', 'second', 'the', 'third',\n 'this'], ...)\n >>> print(X.toarray())\n [[0 1 1 1 0 0 1 0 1]\n [0 2 0 1 0 1 1 0 1]\n [1 0 0 1 1 0 1 1 1]\n [0 1 1 1 0 0 1 0 1]]\n >>> vectorizer2 = CountVectorizer(analyzer='word', ngram_range=(2, 2))\n >>> X2 = vectorizer2.fit_transform(corpus)\n >>> vectorizer2.get_feature_names_out()\n array(['and this', 'document is', 'first document', 'is the', 'is this',\n 'second document', 'the first', 'the second', 'the third', 'third one',\n 'this document', 'this is', 'this the'], ...)\n >>> print(X2.toarray())\n [[0 0 1 1 0 0 1 0 0 0 0 1 0]\n [0 1 0 1 0 1 0 1 0 0 1 0 0]\n [1 0 0 1 0 0 0 0 1 1 0 1 0]\n [0 0 1 0 1 0 1 0 0 0 0 0 1]]\n ", - "source_code": "\n\nclass CountVectorizer(_VectorizerMixin, BaseEstimator):\n \"\"\"Convert a collection of text documents to a matrix of token counts.\n\n This implementation produces a sparse representation of the counts using\n scipy.sparse.csr_matrix.\n\n If you do not provide an a-priori dictionary and you do not use an analyzer\n that does some kind of feature selection then the number of features will\n be equal to the vocabulary size found by analyzing the data.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n input : {'filename', 'file', 'content'}, default='content'\n - If `'filename'`, the sequence passed as an argument to fit is\n expected to be a list of filenames that need reading to fetch\n the raw content to analyze.\n\n - If `'file'`, the sequence items must have a 'read' method (file-like\n object) that is called to fetch the bytes in memory.\n\n - If `'content'`, the input is expected to be a sequence of items that\n can be of type string or byte.\n\n encoding : str, default='utf-8'\n If bytes or files are given to analyze, this encoding is used to\n decode.\n\n decode_error : {'strict', 'ignore', 'replace'}, default='strict'\n Instruction on what to do if a byte sequence is given to analyze that\n contains characters not of the given `encoding`. By default, it is\n 'strict', meaning that a UnicodeDecodeError will be raised. Other\n values are 'ignore' and 'replace'.\n\n strip_accents : {'ascii', 'unicode'}, default=None\n Remove accents and perform other character normalization\n during the preprocessing step.\n 'ascii' is a fast method that only works on characters that have\n an direct ASCII mapping.\n 'unicode' is a slightly slower method that works on any characters.\n None (default) does nothing.\n\n Both 'ascii' and 'unicode' use NFKD normalization from\n :func:`unicodedata.normalize`.\n\n lowercase : bool, default=True\n Convert all characters to lowercase before tokenizing.\n\n preprocessor : callable, default=None\n Override the preprocessing (strip_accents and lowercase) stage while\n preserving the tokenizing and n-grams generation steps.\n Only applies if ``analyzer is not callable``.\n\n tokenizer : callable, default=None\n Override the string tokenization step while preserving the\n preprocessing and n-grams generation steps.\n Only applies if ``analyzer == 'word'``.\n\n stop_words : {'english'}, list, default=None\n If 'english', a built-in stop word list for English is used.\n There are several known issues with 'english' and you should\n consider an alternative (see :ref:`stop_words`).\n\n If a list, that list is assumed to contain stop words, all of which\n will be removed from the resulting tokens.\n Only applies if ``analyzer == 'word'``.\n\n If None, no stop words will be used. max_df can be set to a value\n in the range [0.7, 1.0) to automatically detect and filter stop\n words based on intra corpus document frequency of terms.\n\n token_pattern : str, default=r\"(?u)\\\\b\\\\w\\\\w+\\\\b\"\n Regular expression denoting what constitutes a \"token\", only used\n if ``analyzer == 'word'``. The default regexp select tokens of 2\n or more alphanumeric characters (punctuation is completely ignored\n and always treated as a token separator).\n\n If there is a capturing group in token_pattern then the\n captured group content, not the entire match, becomes the token.\n At most one capturing group is permitted.\n\n ngram_range : tuple (min_n, max_n), default=(1, 1)\n The lower and upper boundary of the range of n-values for different\n word n-grams or char n-grams to be extracted. All values of n such\n such that min_n <= n <= max_n will be used. For example an\n ``ngram_range`` of ``(1, 1)`` means only unigrams, ``(1, 2)`` means\n unigrams and bigrams, and ``(2, 2)`` means only bigrams.\n Only applies if ``analyzer is not callable``.\n\n analyzer : {'word', 'char', 'char_wb'} or callable, default='word'\n Whether the feature should be made of word n-gram or character\n n-grams.\n Option 'char_wb' creates character n-grams only from text inside\n word boundaries; n-grams at the edges of words are padded with space.\n\n If a callable is passed it is used to extract the sequence of features\n out of the raw, unprocessed input.\n\n .. versionchanged:: 0.21\n\n Since v0.21, if ``input`` is ``filename`` or ``file``, the data is\n first read from the file and then passed to the given callable\n analyzer.\n\n max_df : float in range [0.0, 1.0] or int, default=1.0\n When building the vocabulary ignore terms that have a document\n frequency strictly higher than the given threshold (corpus-specific\n stop words).\n If float, the parameter represents a proportion of documents, integer\n absolute counts.\n This parameter is ignored if vocabulary is not None.\n\n min_df : float in range [0.0, 1.0] or int, default=1\n When building the vocabulary ignore terms that have a document\n frequency strictly lower than the given threshold. This value is also\n called cut-off in the literature.\n If float, the parameter represents a proportion of documents, integer\n absolute counts.\n This parameter is ignored if vocabulary is not None.\n\n max_features : int, default=None\n If not None, build a vocabulary that only consider the top\n max_features ordered by term frequency across the corpus.\n\n This parameter is ignored if vocabulary is not None.\n\n vocabulary : Mapping or iterable, default=None\n Either a Mapping (e.g., a dict) where keys are terms and values are\n indices in the feature matrix, or an iterable over terms. If not\n given, a vocabulary is determined from the input documents. Indices\n in the mapping should not be repeated and should not have any gap\n between 0 and the largest index.\n\n binary : bool, default=False\n If True, all non zero counts are set to 1. This is useful for discrete\n probabilistic models that model binary events rather than integer\n counts.\n\n dtype : type, default=np.int64\n Type of the matrix returned by fit_transform() or transform().\n\n Attributes\n ----------\n vocabulary_ : dict\n A mapping of terms to feature indices.\n\n fixed_vocabulary_ : bool\n True if a fixed vocabulary of term to indices mapping\n is provided by the user.\n\n stop_words_ : set\n Terms that were ignored because they either:\n\n - occurred in too many documents (`max_df`)\n - occurred in too few documents (`min_df`)\n - were cut off by feature selection (`max_features`).\n\n This is only available if no vocabulary was given.\n\n See Also\n --------\n HashingVectorizer : Convert a collection of text documents to a\n matrix of token counts.\n\n TfidfVectorizer : Convert a collection of raw documents to a matrix\n of TF-IDF features.\n\n Notes\n -----\n The ``stop_words_`` attribute can get large and increase the model size\n when pickling. This attribute is provided only for introspection and can\n be safely removed using delattr or set to None before pickling.\n\n Examples\n --------\n >>> from sklearn.feature_extraction.text import CountVectorizer\n >>> corpus = [\n ... 'This is the first document.',\n ... 'This document is the second document.',\n ... 'And this is the third one.',\n ... 'Is this the first document?',\n ... ]\n >>> vectorizer = CountVectorizer()\n >>> X = vectorizer.fit_transform(corpus)\n >>> vectorizer.get_feature_names_out()\n array(['and', 'document', 'first', 'is', 'one', 'second', 'the', 'third',\n 'this'], ...)\n >>> print(X.toarray())\n [[0 1 1 1 0 0 1 0 1]\n [0 2 0 1 0 1 1 0 1]\n [1 0 0 1 1 0 1 1 1]\n [0 1 1 1 0 0 1 0 1]]\n >>> vectorizer2 = CountVectorizer(analyzer='word', ngram_range=(2, 2))\n >>> X2 = vectorizer2.fit_transform(corpus)\n >>> vectorizer2.get_feature_names_out()\n array(['and this', 'document is', 'first document', 'is the', 'is this',\n 'second document', 'the first', 'the second', 'the third', 'third one',\n 'this document', 'this is', 'this the'], ...)\n >>> print(X2.toarray())\n [[0 0 1 1 0 0 1 0 0 0 0 1 0]\n [0 1 0 1 0 1 0 1 0 0 1 0 0]\n [1 0 0 1 0 0 0 0 1 1 0 1 0]\n [0 0 1 0 1 0 1 0 0 0 0 0 1]]\n \"\"\"\n \n def __init__(self, *, input='content', encoding='utf-8', decode_error='strict', strip_accents=None, lowercase=True, preprocessor=None, tokenizer=None, stop_words=None, token_pattern='(?u)\\\\b\\\\w\\\\w+\\\\b', ngram_range=(1, 1), analyzer='word', max_df=1.0, min_df=1, max_features=None, vocabulary=None, binary=False, dtype=np.int64):\n self.input = input\n self.encoding = encoding\n self.decode_error = decode_error\n self.strip_accents = strip_accents\n self.preprocessor = preprocessor\n self.tokenizer = tokenizer\n self.analyzer = analyzer\n self.lowercase = lowercase\n self.token_pattern = token_pattern\n self.stop_words = stop_words\n self.max_df = max_df\n self.min_df = min_df\n if max_df < 0 or min_df < 0:\n raise ValueError('negative value for max_df or min_df')\n self.max_features = max_features\n if max_features is not None:\n if not isinstance(max_features, numbers.Integral) or max_features <= 0:\n raise ValueError('max_features=%r, neither a positive integer nor None' % max_features)\n self.ngram_range = ngram_range\n self.vocabulary = vocabulary\n self.binary = binary\n self.dtype = dtype\n \n def _sort_features(self, X, vocabulary):\n \"\"\"Sort features by name\n\n Returns a reordered matrix and modifies the vocabulary in place\n \"\"\"\n sorted_features = sorted(vocabulary.items())\n map_index = np.empty(len(sorted_features), dtype=X.indices.dtype)\n for (new_val, (term, old_val)) in enumerate(sorted_features):\n vocabulary[term] = new_val\n map_index[old_val] = new_val\n X.indices = map_index.take(X.indices, mode='clip')\n return X\n \n def _limit_features(self, X, vocabulary, high=None, low=None, limit=None):\n \"\"\"Remove too rare or too common features.\n\n Prune features that are non zero in more samples than high or less\n documents than low, modifying the vocabulary, and restricting it to\n at most the limit most frequent.\n\n This does not prune samples with zero features.\n \"\"\"\n if high is None and low is None and limit is None:\n return X, set()\n dfs = _document_frequency(X)\n mask = np.ones(len(dfs), dtype=bool)\n if high is not None:\n mask &= dfs <= high\n if low is not None:\n mask &= dfs >= low\n if limit is not None and mask.sum() > limit:\n tfs = np.asarray(X.sum(axis=0)).ravel()\n mask_inds = (-tfs[mask]).argsort()[:limit]\n new_mask = np.zeros(len(dfs), dtype=bool)\n new_mask[np.where(mask)[0][mask_inds]] = True\n mask = new_mask\n new_indices = np.cumsum(mask) - 1\n removed_terms = set()\n for (term, old_index) in list(vocabulary.items()):\n if mask[old_index]:\n vocabulary[term] = new_indices[old_index]\n else:\n del vocabulary[term]\n removed_terms.add(term)\n kept_indices = np.where(mask)[0]\n if len(kept_indices) == 0:\n raise ValueError('After pruning, no terms remain. Try a lower min_df or a higher max_df.')\n return X[:, kept_indices], removed_terms\n \n def _count_vocab(self, raw_documents, fixed_vocab):\n \"\"\"Create sparse feature matrix, and vocabulary where fixed_vocab=False\"\"\"\n if fixed_vocab:\n vocabulary = self.vocabulary_\n else:\n vocabulary = defaultdict()\n vocabulary.default_factory = vocabulary.__len__\n analyze = self.build_analyzer()\n j_indices = []\n indptr = []\n if self.lowercase:\n for vocab in vocabulary:\n if any(map(str.isupper, vocab)):\n warnings.warn(\"Upper case characters found in vocabulary while 'lowercase' is True. These entries will not be matched with any documents\")\n break\n values = _make_int_array()\n indptr.append(0)\n for doc in raw_documents:\n feature_counter = {}\n for feature in analyze(doc):\n try:\n feature_idx = vocabulary[feature]\n if feature_idx not in feature_counter:\n feature_counter[feature_idx] = 1\n else:\n feature_counter[feature_idx] += 1\n except KeyError:\n continue\n j_indices.extend(feature_counter.keys())\n values.extend(feature_counter.values())\n indptr.append(len(j_indices))\n if not fixed_vocab:\n vocabulary = dict(vocabulary)\n if not vocabulary:\n raise ValueError('empty vocabulary; perhaps the documents only contain stop words')\n if indptr[-1] > np.iinfo(np.int32).max:\n if _IS_32BIT:\n raise ValueError('sparse CSR array has {} non-zero elements and requires 64 bit indexing, which is unsupported with 32 bit Python.'.format(indptr[-1]))\n indices_dtype = np.int64\n else:\n indices_dtype = np.int32\n j_indices = np.asarray(j_indices, dtype=indices_dtype)\n indptr = np.asarray(indptr, dtype=indices_dtype)\n values = np.frombuffer(values, dtype=np.intc)\n X = sp.csr_matrix((values, j_indices, indptr), shape=(len(indptr) - 1, len(vocabulary)), dtype=self.dtype)\n X.sort_indices()\n return vocabulary, X\n \n def fit(self, raw_documents, y=None):\n \"\"\"Learn a vocabulary dictionary of all tokens in the raw documents.\n\n Parameters\n ----------\n raw_documents : iterable\n An iterable which generates either str, unicode or file objects.\n\n y : None\n This parameter is ignored.\n\n Returns\n -------\n self : object\n Fitted vectorizer.\n \"\"\"\n self._warn_for_unused_params()\n self.fit_transform(raw_documents)\n return self\n \n def fit_transform(self, raw_documents, y=None):\n \"\"\"Learn the vocabulary dictionary and return document-term matrix.\n\n This is equivalent to fit followed by transform, but more efficiently\n implemented.\n\n Parameters\n ----------\n raw_documents : iterable\n An iterable which generates either str, unicode or file objects.\n\n y : None\n This parameter is ignored.\n\n Returns\n -------\n X : array of shape (n_samples, n_features)\n Document-term matrix.\n \"\"\"\n if isinstance(raw_documents, str):\n raise ValueError('Iterable over raw text documents expected, string object received.')\n self._validate_params()\n self._validate_vocabulary()\n max_df = self.max_df\n min_df = self.min_df\n max_features = self.max_features\n (vocabulary, X) = self._count_vocab(raw_documents, self.fixed_vocabulary_)\n if self.binary:\n X.data.fill(1)\n if not self.fixed_vocabulary_:\n n_doc = X.shape[0]\n max_doc_count = max_df if isinstance(max_df, numbers.Integral) else max_df * n_doc\n min_doc_count = min_df if isinstance(min_df, numbers.Integral) else min_df * n_doc\n if max_doc_count < min_doc_count:\n raise ValueError('max_df corresponds to < documents than min_df')\n if max_features is not None:\n X = self._sort_features(X, vocabulary)\n (X, self.stop_words_) = self._limit_features(X, vocabulary, max_doc_count, min_doc_count, max_features)\n if max_features is None:\n X = self._sort_features(X, vocabulary)\n self.vocabulary_ = vocabulary\n return X\n \n def transform(self, raw_documents):\n \"\"\"Transform documents to document-term matrix.\n\n Extract token counts out of raw text documents using the vocabulary\n fitted with fit or the one provided to the constructor.\n\n Parameters\n ----------\n raw_documents : iterable\n An iterable which generates either str, unicode or file objects.\n\n Returns\n -------\n X : sparse matrix of shape (n_samples, n_features)\n Document-term matrix.\n \"\"\"\n if isinstance(raw_documents, str):\n raise ValueError('Iterable over raw text documents expected, string object received.')\n self._check_vocabulary()\n (_, X) = self._count_vocab(raw_documents, fixed_vocab=True)\n if self.binary:\n X.data.fill(1)\n return X\n \n def inverse_transform(self, X):\n \"\"\"Return terms per document with nonzero entries in X.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document-term matrix.\n\n Returns\n -------\n X_inv : list of arrays of shape (n_samples,)\n List of arrays of terms.\n \"\"\"\n self._check_vocabulary()\n X = check_array(X, accept_sparse='csr')\n n_samples = X.shape[0]\n terms = np.array(list(self.vocabulary_.keys()))\n indices = np.array(list(self.vocabulary_.values()))\n inverse_vocabulary = terms[np.argsort(indices)]\n if sp.issparse(X):\n return [inverse_vocabulary[X[i, :].nonzero()[1]].ravel() for i in range(n_samples)]\n else:\n return [inverse_vocabulary[np.flatnonzero(X[i, :])].ravel() for i in range(n_samples)]\n \n @deprecated('get_feature_names is deprecated in 1.0 and will be removed in 1.2. Please use get_feature_names_out instead.')\n def get_feature_names(self):\n \"\"\"Array mapping from feature integer indices to feature name.\n\n Returns\n -------\n feature_names : list\n A list of feature names.\n \"\"\"\n self._check_vocabulary()\n return [t for (t, i) in sorted(self.vocabulary_.items(), key=itemgetter(1))]\n \n def get_feature_names_out(self, input_features=None):\n \"\"\"Get output feature names for transformation.\n\n Parameters\n ----------\n input_features : array-like of str or None, default=None\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n feature_names_out : ndarray of str objects\n Transformed feature names.\n \"\"\"\n self._check_vocabulary()\n return np.asarray([t for (t, i) in sorted(self.vocabulary_.items(), key=itemgetter(1))], dtype=object)\n \n def _more_tags(self):\n return {'X_types': ['string']}\n" + "source_code": "\n\nclass CountVectorizer(_VectorizerMixin, BaseEstimator):\n \"\"\"Convert a collection of text documents to a matrix of token counts.\n\n This implementation produces a sparse representation of the counts using\n scipy.sparse.csr_matrix.\n\n If you do not provide an a-priori dictionary and you do not use an analyzer\n that does some kind of feature selection then the number of features will\n be equal to the vocabulary size found by analyzing the data.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n input : {'filename', 'file', 'content'}, default='content'\n - If `'filename'`, the sequence passed as an argument to fit is\n expected to be a list of filenames that need reading to fetch\n the raw content to analyze.\n\n - If `'file'`, the sequence items must have a 'read' method (file-like\n object) that is called to fetch the bytes in memory.\n\n - If `'content'`, the input is expected to be a sequence of items that\n can be of type string or byte.\n\n encoding : str, default='utf-8'\n If bytes or files are given to analyze, this encoding is used to\n decode.\n\n decode_error : {'strict', 'ignore', 'replace'}, default='strict'\n Instruction on what to do if a byte sequence is given to analyze that\n contains characters not of the given `encoding`. By default, it is\n 'strict', meaning that a UnicodeDecodeError will be raised. Other\n values are 'ignore' and 'replace'.\n\n strip_accents : {'ascii', 'unicode'}, default=None\n Remove accents and perform other character normalization\n during the preprocessing step.\n 'ascii' is a fast method that only works on characters that have\n an direct ASCII mapping.\n 'unicode' is a slightly slower method that works on any characters.\n None (default) does nothing.\n\n Both 'ascii' and 'unicode' use NFKD normalization from\n :func:`unicodedata.normalize`.\n\n lowercase : bool, default=True\n Convert all characters to lowercase before tokenizing.\n\n preprocessor : callable, default=None\n Override the preprocessing (strip_accents and lowercase) stage while\n preserving the tokenizing and n-grams generation steps.\n Only applies if ``analyzer is not callable``.\n\n tokenizer : callable, default=None\n Override the string tokenization step while preserving the\n preprocessing and n-grams generation steps.\n Only applies if ``analyzer == 'word'``.\n\n stop_words : {'english'}, list, default=None\n If 'english', a built-in stop word list for English is used.\n There are several known issues with 'english' and you should\n consider an alternative (see :ref:`stop_words`).\n\n If a list, that list is assumed to contain stop words, all of which\n will be removed from the resulting tokens.\n Only applies if ``analyzer == 'word'``.\n\n If None, no stop words will be used. max_df can be set to a value\n in the range [0.7, 1.0) to automatically detect and filter stop\n words based on intra corpus document frequency of terms.\n\n token_pattern : str, default=r\"(?u)\\\\b\\\\w\\\\w+\\\\b\"\n Regular expression denoting what constitutes a \"token\", only used\n if ``analyzer == 'word'``. The default regexp select tokens of 2\n or more alphanumeric characters (punctuation is completely ignored\n and always treated as a token separator).\n\n If there is a capturing group in token_pattern then the\n captured group content, not the entire match, becomes the token.\n At most one capturing group is permitted.\n\n ngram_range : tuple (min_n, max_n), default=(1, 1)\n The lower and upper boundary of the range of n-values for different\n word n-grams or char n-grams to be extracted. All values of n such\n such that min_n <= n <= max_n will be used. For example an\n ``ngram_range`` of ``(1, 1)`` means only unigrams, ``(1, 2)`` means\n unigrams and bigrams, and ``(2, 2)`` means only bigrams.\n Only applies if ``analyzer is not callable``.\n\n analyzer : {'word', 'char', 'char_wb'} or callable, default='word'\n Whether the feature should be made of word n-gram or character\n n-grams.\n Option 'char_wb' creates character n-grams only from text inside\n word boundaries; n-grams at the edges of words are padded with space.\n\n If a callable is passed it is used to extract the sequence of features\n out of the raw, unprocessed input.\n\n .. versionchanged:: 0.21\n\n Since v0.21, if ``input`` is ``filename`` or ``file``, the data is\n first read from the file and then passed to the given callable\n analyzer.\n\n max_df : float in range [0.0, 1.0] or int, default=1.0\n When building the vocabulary ignore terms that have a document\n frequency strictly higher than the given threshold (corpus-specific\n stop words).\n If float, the parameter represents a proportion of documents, integer\n absolute counts.\n This parameter is ignored if vocabulary is not None.\n\n min_df : float in range [0.0, 1.0] or int, default=1\n When building the vocabulary ignore terms that have a document\n frequency strictly lower than the given threshold. This value is also\n called cut-off in the literature.\n If float, the parameter represents a proportion of documents, integer\n absolute counts.\n This parameter is ignored if vocabulary is not None.\n\n max_features : int, default=None\n If not None, build a vocabulary that only consider the top\n max_features ordered by term frequency across the corpus.\n\n This parameter is ignored if vocabulary is not None.\n\n vocabulary : Mapping or iterable, default=None\n Either a Mapping (e.g., a dict) where keys are terms and values are\n indices in the feature matrix, or an iterable over terms. If not\n given, a vocabulary is determined from the input documents. Indices\n in the mapping should not be repeated and should not have any gap\n between 0 and the largest index.\n\n binary : bool, default=False\n If True, all non zero counts are set to 1. This is useful for discrete\n probabilistic models that model binary events rather than integer\n counts.\n\n dtype : type, default=np.int64\n Type of the matrix returned by fit_transform() or transform().\n\n Attributes\n ----------\n vocabulary_ : dict\n A mapping of terms to feature indices.\n\n fixed_vocabulary_ : bool\n True if a fixed vocabulary of term to indices mapping\n is provided by the user.\n\n stop_words_ : set\n Terms that were ignored because they either:\n\n - occurred in too many documents (`max_df`)\n - occurred in too few documents (`min_df`)\n - were cut off by feature selection (`max_features`).\n\n This is only available if no vocabulary was given.\n\n See Also\n --------\n HashingVectorizer : Convert a collection of text documents to a\n matrix of token counts.\n\n TfidfVectorizer : Convert a collection of raw documents to a matrix\n of TF-IDF features.\n\n Notes\n -----\n The ``stop_words_`` attribute can get large and increase the model size\n when pickling. This attribute is provided only for introspection and can\n be safely removed using delattr or set to None before pickling.\n\n Examples\n --------\n >>> from sklearn.feature_extraction.text import CountVectorizer\n >>> corpus = [\n ... 'This is the first document.',\n ... 'This document is the second document.',\n ... 'And this is the third one.',\n ... 'Is this the first document?',\n ... ]\n >>> vectorizer = CountVectorizer()\n >>> X = vectorizer.fit_transform(corpus)\n >>> vectorizer.get_feature_names_out()\n array(['and', 'document', 'first', 'is', 'one', 'second', 'the', 'third',\n 'this'], ...)\n >>> print(X.toarray())\n [[0 1 1 1 0 0 1 0 1]\n [0 2 0 1 0 1 1 0 1]\n [1 0 0 1 1 0 1 1 1]\n [0 1 1 1 0 0 1 0 1]]\n >>> vectorizer2 = CountVectorizer(analyzer='word', ngram_range=(2, 2))\n >>> X2 = vectorizer2.fit_transform(corpus)\n >>> vectorizer2.get_feature_names_out()\n array(['and this', 'document is', 'first document', 'is the', 'is this',\n 'second document', 'the first', 'the second', 'the third', 'third one',\n 'this document', 'this is', 'this the'], ...)\n >>> print(X2.toarray())\n [[0 0 1 1 0 0 1 0 0 0 0 1 0]\n [0 1 0 1 0 1 0 1 0 0 1 0 0]\n [1 0 0 1 0 0 0 0 1 1 0 1 0]\n [0 0 1 0 1 0 1 0 0 0 0 0 1]]\n \"\"\"\n \n def __init__(self, *, input='content', encoding='utf-8', decode_error='strict', strip_accents=None, lowercase=True, preprocessor=None, tokenizer=None, stop_words=None, token_pattern='(?u)\\\\b\\\\w\\\\w+\\\\b', ngram_range=(1, 1), analyzer='word', max_df=1.0, min_df=1, max_features=None, vocabulary=None, binary=False, dtype=np.int64):\n self.input = input\n self.encoding = encoding\n self.decode_error = decode_error\n self.strip_accents = strip_accents\n self.preprocessor = preprocessor\n self.tokenizer = tokenizer\n self.analyzer = analyzer\n self.lowercase = lowercase\n self.token_pattern = token_pattern\n self.stop_words = stop_words\n self.max_df = max_df\n self.min_df = min_df\n self.max_features = max_features\n self.ngram_range = ngram_range\n self.vocabulary = vocabulary\n self.binary = binary\n self.dtype = dtype\n \n def _sort_features(self, X, vocabulary):\n \"\"\"Sort features by name\n\n Returns a reordered matrix and modifies the vocabulary in place\n \"\"\"\n sorted_features = sorted(vocabulary.items())\n map_index = np.empty(len(sorted_features), dtype=X.indices.dtype)\n for (new_val, (term, old_val)) in enumerate(sorted_features):\n vocabulary[term] = new_val\n map_index[old_val] = new_val\n X.indices = map_index.take(X.indices, mode='clip')\n return X\n \n def _limit_features(self, X, vocabulary, high=None, low=None, limit=None):\n \"\"\"Remove too rare or too common features.\n\n Prune features that are non zero in more samples than high or less\n documents than low, modifying the vocabulary, and restricting it to\n at most the limit most frequent.\n\n This does not prune samples with zero features.\n \"\"\"\n if high is None and low is None and limit is None:\n return X, set()\n dfs = _document_frequency(X)\n mask = np.ones(len(dfs), dtype=bool)\n if high is not None:\n mask &= dfs <= high\n if low is not None:\n mask &= dfs >= low\n if limit is not None and mask.sum() > limit:\n tfs = np.asarray(X.sum(axis=0)).ravel()\n mask_inds = (-tfs[mask]).argsort()[:limit]\n new_mask = np.zeros(len(dfs), dtype=bool)\n new_mask[np.where(mask)[0][mask_inds]] = True\n mask = new_mask\n new_indices = np.cumsum(mask) - 1\n removed_terms = set()\n for (term, old_index) in list(vocabulary.items()):\n if mask[old_index]:\n vocabulary[term] = new_indices[old_index]\n else:\n del vocabulary[term]\n removed_terms.add(term)\n kept_indices = np.where(mask)[0]\n if len(kept_indices) == 0:\n raise ValueError('After pruning, no terms remain. Try a lower min_df or a higher max_df.')\n return X[:, kept_indices], removed_terms\n \n def _count_vocab(self, raw_documents, fixed_vocab):\n \"\"\"Create sparse feature matrix, and vocabulary where fixed_vocab=False\"\"\"\n if fixed_vocab:\n vocabulary = self.vocabulary_\n else:\n vocabulary = defaultdict()\n vocabulary.default_factory = vocabulary.__len__\n analyze = self.build_analyzer()\n j_indices = []\n indptr = []\n values = _make_int_array()\n indptr.append(0)\n for doc in raw_documents:\n feature_counter = {}\n for feature in analyze(doc):\n try:\n feature_idx = vocabulary[feature]\n if feature_idx not in feature_counter:\n feature_counter[feature_idx] = 1\n else:\n feature_counter[feature_idx] += 1\n except KeyError:\n continue\n j_indices.extend(feature_counter.keys())\n values.extend(feature_counter.values())\n indptr.append(len(j_indices))\n if not fixed_vocab:\n vocabulary = dict(vocabulary)\n if not vocabulary:\n raise ValueError('empty vocabulary; perhaps the documents only contain stop words')\n if indptr[-1] > np.iinfo(np.int32).max:\n if _IS_32BIT:\n raise ValueError('sparse CSR array has {} non-zero elements and requires 64 bit indexing, which is unsupported with 32 bit Python.'.format(indptr[-1]))\n indices_dtype = np.int64\n else:\n indices_dtype = np.int32\n j_indices = np.asarray(j_indices, dtype=indices_dtype)\n indptr = np.asarray(indptr, dtype=indices_dtype)\n values = np.frombuffer(values, dtype=np.intc)\n X = sp.csr_matrix((values, j_indices, indptr), shape=(len(indptr) - 1, len(vocabulary)), dtype=self.dtype)\n X.sort_indices()\n return vocabulary, X\n \n def _validate_params(self):\n \"\"\"Validation of min_df, max_df and max_features\"\"\"\n super()._validate_params()\n if self.max_features is not None:\n check_scalar(self.max_features, 'max_features', numbers.Integral, min_val=0)\n if isinstance(self.min_df, numbers.Integral):\n check_scalar(self.min_df, 'min_df', numbers.Integral, min_val=0)\n else:\n check_scalar(self.min_df, 'min_df', numbers.Real, min_val=0.0, max_val=1.0)\n if isinstance(self.max_df, numbers.Integral):\n check_scalar(self.max_df, 'max_df', numbers.Integral, min_val=0)\n else:\n check_scalar(self.max_df, 'max_df', numbers.Real, min_val=0.0, max_val=1.0)\n \n def fit(self, raw_documents, y=None):\n \"\"\"Learn a vocabulary dictionary of all tokens in the raw documents.\n\n Parameters\n ----------\n raw_documents : iterable\n An iterable which generates either str, unicode or file objects.\n\n y : None\n This parameter is ignored.\n\n Returns\n -------\n self : object\n Fitted vectorizer.\n \"\"\"\n self._warn_for_unused_params()\n self.fit_transform(raw_documents)\n return self\n \n def fit_transform(self, raw_documents, y=None):\n \"\"\"Learn the vocabulary dictionary and return document-term matrix.\n\n This is equivalent to fit followed by transform, but more efficiently\n implemented.\n\n Parameters\n ----------\n raw_documents : iterable\n An iterable which generates either str, unicode or file objects.\n\n y : None\n This parameter is ignored.\n\n Returns\n -------\n X : array of shape (n_samples, n_features)\n Document-term matrix.\n \"\"\"\n if isinstance(raw_documents, str):\n raise ValueError('Iterable over raw text documents expected, string object received.')\n self._validate_params()\n self._validate_vocabulary()\n max_df = self.max_df\n min_df = self.min_df\n max_features = self.max_features\n if self.fixed_vocabulary_ and self.lowercase:\n for term in self.vocabulary:\n if any(map(str.isupper, term)):\n warnings.warn(\"Upper case characters found in vocabulary while 'lowercase' is True. These entries will not be matched with any documents\")\n break\n (vocabulary, X) = self._count_vocab(raw_documents, self.fixed_vocabulary_)\n if self.binary:\n X.data.fill(1)\n if not self.fixed_vocabulary_:\n n_doc = X.shape[0]\n max_doc_count = max_df if isinstance(max_df, numbers.Integral) else max_df * n_doc\n min_doc_count = min_df if isinstance(min_df, numbers.Integral) else min_df * n_doc\n if max_doc_count < min_doc_count:\n raise ValueError('max_df corresponds to < documents than min_df')\n if max_features is not None:\n X = self._sort_features(X, vocabulary)\n (X, self.stop_words_) = self._limit_features(X, vocabulary, max_doc_count, min_doc_count, max_features)\n if max_features is None:\n X = self._sort_features(X, vocabulary)\n self.vocabulary_ = vocabulary\n return X\n \n def transform(self, raw_documents):\n \"\"\"Transform documents to document-term matrix.\n\n Extract token counts out of raw text documents using the vocabulary\n fitted with fit or the one provided to the constructor.\n\n Parameters\n ----------\n raw_documents : iterable\n An iterable which generates either str, unicode or file objects.\n\n Returns\n -------\n X : sparse matrix of shape (n_samples, n_features)\n Document-term matrix.\n \"\"\"\n if isinstance(raw_documents, str):\n raise ValueError('Iterable over raw text documents expected, string object received.')\n self._check_vocabulary()\n (_, X) = self._count_vocab(raw_documents, fixed_vocab=True)\n if self.binary:\n X.data.fill(1)\n return X\n \n def inverse_transform(self, X):\n \"\"\"Return terms per document with nonzero entries in X.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document-term matrix.\n\n Returns\n -------\n X_inv : list of arrays of shape (n_samples,)\n List of arrays of terms.\n \"\"\"\n self._check_vocabulary()\n X = check_array(X, accept_sparse='csr')\n n_samples = X.shape[0]\n terms = np.array(list(self.vocabulary_.keys()))\n indices = np.array(list(self.vocabulary_.values()))\n inverse_vocabulary = terms[np.argsort(indices)]\n if sp.issparse(X):\n return [inverse_vocabulary[X[i, :].nonzero()[1]].ravel() for i in range(n_samples)]\n else:\n return [inverse_vocabulary[np.flatnonzero(X[i, :])].ravel() for i in range(n_samples)]\n \n @deprecated('get_feature_names is deprecated in 1.0 and will be removed in 1.2. Please use get_feature_names_out instead.')\n def get_feature_names(self):\n \"\"\"Array mapping from feature integer indices to feature name.\n\n Returns\n -------\n feature_names : list\n A list of feature names.\n \"\"\"\n self._check_vocabulary()\n return [t for (t, i) in sorted(self.vocabulary_.items(), key=itemgetter(1))]\n \n def get_feature_names_out(self, input_features=None):\n \"\"\"Get output feature names for transformation.\n\n Parameters\n ----------\n input_features : array-like of str or None, default=None\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n feature_names_out : ndarray of str objects\n Transformed feature names.\n \"\"\"\n self._check_vocabulary()\n return np.asarray([t for (t, i) in sorted(self.vocabulary_.items(), key=itemgetter(1))], dtype=object)\n \n def _more_tags(self):\n return {'X_types': ['string']}\n" }, { "name": "HashingVectorizer", @@ -22401,8 +22354,8 @@ ], "is_public": true, "description": "Convert a collection of text documents to a matrix of token occurrences.\n\nIt turns a collection of text documents into a scipy.sparse matrix holding token occurrence counts (or binary occurrence information), possibly normalized as token frequencies if norm='l1' or projected on the euclidean unit sphere if norm='l2'. This text vectorizer implementation uses the hashing trick to find the token string name to feature integer index mapping. This strategy has several advantages: - it is very low memory scalable to large datasets as there is no need to store a vocabulary dictionary in memory. - it is fast to pickle and un-pickle as it holds no state besides the constructor parameters. - it can be used in a streaming (partial fit) or parallel pipeline as there is no state computed during fit. There are also a couple of cons (vs using a CountVectorizer with an in-memory vocabulary): - there is no way to compute the inverse transform (from feature indices to string feature names) which can be a problem when trying to introspect which features are most important to a model. - there can be collisions: distinct tokens can be mapped to the same feature index. However in practice this is rarely an issue if n_features is large enough (e.g. 2 ** 18 for text classification problems). - no IDF weighting as this would render the transformer stateful. The hash function employed is the signed 32-bit version of Murmurhash3. Read more in the :ref:`User Guide `.", - "docstring": "Convert a collection of text documents to a matrix of token occurrences.\n\n It turns a collection of text documents into a scipy.sparse matrix holding\n token occurrence counts (or binary occurrence information), possibly\n normalized as token frequencies if norm='l1' or projected on the euclidean\n unit sphere if norm='l2'.\n\n This text vectorizer implementation uses the hashing trick to find the\n token string name to feature integer index mapping.\n\n This strategy has several advantages:\n\n - it is very low memory scalable to large datasets as there is no need to\n store a vocabulary dictionary in memory.\n\n - it is fast to pickle and un-pickle as it holds no state besides the\n constructor parameters.\n\n - it can be used in a streaming (partial fit) or parallel pipeline as there\n is no state computed during fit.\n\n There are also a couple of cons (vs using a CountVectorizer with an\n in-memory vocabulary):\n\n - there is no way to compute the inverse transform (from feature indices to\n string feature names) which can be a problem when trying to introspect\n which features are most important to a model.\n\n - there can be collisions: distinct tokens can be mapped to the same\n feature index. However in practice this is rarely an issue if n_features\n is large enough (e.g. 2 ** 18 for text classification problems).\n\n - no IDF weighting as this would render the transformer stateful.\n\n The hash function employed is the signed 32-bit version of Murmurhash3.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n input : {'filename', 'file', 'content'}, default='content'\n - If `'filename'`, the sequence passed as an argument to fit is\n expected to be a list of filenames that need reading to fetch\n the raw content to analyze.\n\n - If `'file'`, the sequence items must have a 'read' method (file-like\n object) that is called to fetch the bytes in memory.\n\n - If `'content'`, the input is expected to be a sequence of items that\n can be of type string or byte.\n\n encoding : str, default='utf-8'\n If bytes or files are given to analyze, this encoding is used to\n decode.\n\n decode_error : {'strict', 'ignore', 'replace'}, default='strict'\n Instruction on what to do if a byte sequence is given to analyze that\n contains characters not of the given `encoding`. By default, it is\n 'strict', meaning that a UnicodeDecodeError will be raised. Other\n values are 'ignore' and 'replace'.\n\n strip_accents : {'ascii', 'unicode'}, default=None\n Remove accents and perform other character normalization\n during the preprocessing step.\n 'ascii' is a fast method that only works on characters that have\n an direct ASCII mapping.\n 'unicode' is a slightly slower method that works on any characters.\n None (default) does nothing.\n\n Both 'ascii' and 'unicode' use NFKD normalization from\n :func:`unicodedata.normalize`.\n\n lowercase : bool, default=True\n Convert all characters to lowercase before tokenizing.\n\n preprocessor : callable, default=None\n Override the preprocessing (string transformation) stage while\n preserving the tokenizing and n-grams generation steps.\n Only applies if ``analyzer is not callable``.\n\n tokenizer : callable, default=None\n Override the string tokenization step while preserving the\n preprocessing and n-grams generation steps.\n Only applies if ``analyzer == 'word'``.\n\n stop_words : {'english'}, list, default=None\n If 'english', a built-in stop word list for English is used.\n There are several known issues with 'english' and you should\n consider an alternative (see :ref:`stop_words`).\n\n If a list, that list is assumed to contain stop words, all of which\n will be removed from the resulting tokens.\n Only applies if ``analyzer == 'word'``.\n\n token_pattern : str, default=r\"(?u)\\\\b\\\\w\\\\w+\\\\b\"\n Regular expression denoting what constitutes a \"token\", only used\n if ``analyzer == 'word'``. The default regexp selects tokens of 2\n or more alphanumeric characters (punctuation is completely ignored\n and always treated as a token separator).\n\n If there is a capturing group in token_pattern then the\n captured group content, not the entire match, becomes the token.\n At most one capturing group is permitted.\n\n ngram_range : tuple (min_n, max_n), default=(1, 1)\n The lower and upper boundary of the range of n-values for different\n n-grams to be extracted. All values of n such that min_n <= n <= max_n\n will be used. For example an ``ngram_range`` of ``(1, 1)`` means only\n unigrams, ``(1, 2)`` means unigrams and bigrams, and ``(2, 2)`` means\n only bigrams.\n Only applies if ``analyzer is not callable``.\n\n analyzer : {'word', 'char', 'char_wb'} or callable, default='word'\n Whether the feature should be made of word or character n-grams.\n Option 'char_wb' creates character n-grams only from text inside\n word boundaries; n-grams at the edges of words are padded with space.\n\n If a callable is passed it is used to extract the sequence of features\n out of the raw, unprocessed input.\n\n .. versionchanged:: 0.21\n Since v0.21, if ``input`` is ``'filename'`` or ``'file'``, the data\n is first read from the file and then passed to the given callable\n analyzer.\n\n n_features : int, default=(2 ** 20)\n The number of features (columns) in the output matrices. Small numbers\n of features are likely to cause hash collisions, but large numbers\n will cause larger coefficient dimensions in linear learners.\n\n binary : bool, default=False\n If True, all non zero counts are set to 1. This is useful for discrete\n probabilistic models that model binary events rather than integer\n counts.\n\n norm : {'l1', 'l2'}, default='l2'\n Norm used to normalize term vectors. None for no normalization.\n\n alternate_sign : bool, default=True\n When True, an alternating sign is added to the features as to\n approximately conserve the inner product in the hashed space even for\n small n_features. This approach is similar to sparse random projection.\n\n .. versionadded:: 0.19\n\n dtype : type, default=np.float64\n Type of the matrix returned by fit_transform() or transform().\n\n See Also\n --------\n CountVectorizer : Convert a collection of text documents to a matrix of\n token counts.\n TfidfVectorizer : Convert a collection of raw documents to a matrix of\n TF-IDF features.\n\n Examples\n --------\n >>> from sklearn.feature_extraction.text import HashingVectorizer\n >>> corpus = [\n ... 'This is the first document.',\n ... 'This document is the second document.',\n ... 'And this is the third one.',\n ... 'Is this the first document?',\n ... ]\n >>> vectorizer = HashingVectorizer(n_features=2**4)\n >>> X = vectorizer.fit_transform(corpus)\n >>> print(X.shape)\n (4, 16)\n ", - "source_code": "\n\nclass HashingVectorizer(TransformerMixin, _VectorizerMixin, BaseEstimator):\n \"\"\"Convert a collection of text documents to a matrix of token occurrences.\n\n It turns a collection of text documents into a scipy.sparse matrix holding\n token occurrence counts (or binary occurrence information), possibly\n normalized as token frequencies if norm='l1' or projected on the euclidean\n unit sphere if norm='l2'.\n\n This text vectorizer implementation uses the hashing trick to find the\n token string name to feature integer index mapping.\n\n This strategy has several advantages:\n\n - it is very low memory scalable to large datasets as there is no need to\n store a vocabulary dictionary in memory.\n\n - it is fast to pickle and un-pickle as it holds no state besides the\n constructor parameters.\n\n - it can be used in a streaming (partial fit) or parallel pipeline as there\n is no state computed during fit.\n\n There are also a couple of cons (vs using a CountVectorizer with an\n in-memory vocabulary):\n\n - there is no way to compute the inverse transform (from feature indices to\n string feature names) which can be a problem when trying to introspect\n which features are most important to a model.\n\n - there can be collisions: distinct tokens can be mapped to the same\n feature index. However in practice this is rarely an issue if n_features\n is large enough (e.g. 2 ** 18 for text classification problems).\n\n - no IDF weighting as this would render the transformer stateful.\n\n The hash function employed is the signed 32-bit version of Murmurhash3.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n input : {'filename', 'file', 'content'}, default='content'\n - If `'filename'`, the sequence passed as an argument to fit is\n expected to be a list of filenames that need reading to fetch\n the raw content to analyze.\n\n - If `'file'`, the sequence items must have a 'read' method (file-like\n object) that is called to fetch the bytes in memory.\n\n - If `'content'`, the input is expected to be a sequence of items that\n can be of type string or byte.\n\n encoding : str, default='utf-8'\n If bytes or files are given to analyze, this encoding is used to\n decode.\n\n decode_error : {'strict', 'ignore', 'replace'}, default='strict'\n Instruction on what to do if a byte sequence is given to analyze that\n contains characters not of the given `encoding`. By default, it is\n 'strict', meaning that a UnicodeDecodeError will be raised. Other\n values are 'ignore' and 'replace'.\n\n strip_accents : {'ascii', 'unicode'}, default=None\n Remove accents and perform other character normalization\n during the preprocessing step.\n 'ascii' is a fast method that only works on characters that have\n an direct ASCII mapping.\n 'unicode' is a slightly slower method that works on any characters.\n None (default) does nothing.\n\n Both 'ascii' and 'unicode' use NFKD normalization from\n :func:`unicodedata.normalize`.\n\n lowercase : bool, default=True\n Convert all characters to lowercase before tokenizing.\n\n preprocessor : callable, default=None\n Override the preprocessing (string transformation) stage while\n preserving the tokenizing and n-grams generation steps.\n Only applies if ``analyzer is not callable``.\n\n tokenizer : callable, default=None\n Override the string tokenization step while preserving the\n preprocessing and n-grams generation steps.\n Only applies if ``analyzer == 'word'``.\n\n stop_words : {'english'}, list, default=None\n If 'english', a built-in stop word list for English is used.\n There are several known issues with 'english' and you should\n consider an alternative (see :ref:`stop_words`).\n\n If a list, that list is assumed to contain stop words, all of which\n will be removed from the resulting tokens.\n Only applies if ``analyzer == 'word'``.\n\n token_pattern : str, default=r\"(?u)\\\\b\\\\w\\\\w+\\\\b\"\n Regular expression denoting what constitutes a \"token\", only used\n if ``analyzer == 'word'``. The default regexp selects tokens of 2\n or more alphanumeric characters (punctuation is completely ignored\n and always treated as a token separator).\n\n If there is a capturing group in token_pattern then the\n captured group content, not the entire match, becomes the token.\n At most one capturing group is permitted.\n\n ngram_range : tuple (min_n, max_n), default=(1, 1)\n The lower and upper boundary of the range of n-values for different\n n-grams to be extracted. All values of n such that min_n <= n <= max_n\n will be used. For example an ``ngram_range`` of ``(1, 1)`` means only\n unigrams, ``(1, 2)`` means unigrams and bigrams, and ``(2, 2)`` means\n only bigrams.\n Only applies if ``analyzer is not callable``.\n\n analyzer : {'word', 'char', 'char_wb'} or callable, default='word'\n Whether the feature should be made of word or character n-grams.\n Option 'char_wb' creates character n-grams only from text inside\n word boundaries; n-grams at the edges of words are padded with space.\n\n If a callable is passed it is used to extract the sequence of features\n out of the raw, unprocessed input.\n\n .. versionchanged:: 0.21\n Since v0.21, if ``input`` is ``'filename'`` or ``'file'``, the data\n is first read from the file and then passed to the given callable\n analyzer.\n\n n_features : int, default=(2 ** 20)\n The number of features (columns) in the output matrices. Small numbers\n of features are likely to cause hash collisions, but large numbers\n will cause larger coefficient dimensions in linear learners.\n\n binary : bool, default=False\n If True, all non zero counts are set to 1. This is useful for discrete\n probabilistic models that model binary events rather than integer\n counts.\n\n norm : {'l1', 'l2'}, default='l2'\n Norm used to normalize term vectors. None for no normalization.\n\n alternate_sign : bool, default=True\n When True, an alternating sign is added to the features as to\n approximately conserve the inner product in the hashed space even for\n small n_features. This approach is similar to sparse random projection.\n\n .. versionadded:: 0.19\n\n dtype : type, default=np.float64\n Type of the matrix returned by fit_transform() or transform().\n\n See Also\n --------\n CountVectorizer : Convert a collection of text documents to a matrix of\n token counts.\n TfidfVectorizer : Convert a collection of raw documents to a matrix of\n TF-IDF features.\n\n Examples\n --------\n >>> from sklearn.feature_extraction.text import HashingVectorizer\n >>> corpus = [\n ... 'This is the first document.',\n ... 'This document is the second document.',\n ... 'And this is the third one.',\n ... 'Is this the first document?',\n ... ]\n >>> vectorizer = HashingVectorizer(n_features=2**4)\n >>> X = vectorizer.fit_transform(corpus)\n >>> print(X.shape)\n (4, 16)\n \"\"\"\n \n def __init__(self, *, input='content', encoding='utf-8', decode_error='strict', strip_accents=None, lowercase=True, preprocessor=None, tokenizer=None, stop_words=None, token_pattern='(?u)\\\\b\\\\w\\\\w+\\\\b', ngram_range=(1, 1), analyzer='word', n_features=2**20, binary=False, norm='l2', alternate_sign=True, dtype=np.float64):\n self.input = input\n self.encoding = encoding\n self.decode_error = decode_error\n self.strip_accents = strip_accents\n self.preprocessor = preprocessor\n self.tokenizer = tokenizer\n self.analyzer = analyzer\n self.lowercase = lowercase\n self.token_pattern = token_pattern\n self.stop_words = stop_words\n self.n_features = n_features\n self.ngram_range = ngram_range\n self.binary = binary\n self.norm = norm\n self.alternate_sign = alternate_sign\n self.dtype = dtype\n \n def partial_fit(self, X, y=None):\n \"\"\"No-op: this transformer is stateless.\n\n This method is just there to mark the fact that this transformer\n can work in a streaming setup.\n\n Parameters\n ----------\n X : ndarray of shape [n_samples, n_features]\n Training data.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n self : object\n HashingVectorizer instance.\n \"\"\"\n return self\n \n def fit(self, X, y=None):\n \"\"\"No-op: this transformer is stateless.\n\n Parameters\n ----------\n X : ndarray of shape [n_samples, n_features]\n Training data.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n self : object\n HashingVectorizer instance.\n \"\"\"\n if isinstance(X, str):\n raise ValueError('Iterable over raw text documents expected, string object received.')\n self._warn_for_unused_params()\n self._validate_params()\n self._get_hasher().fit(X, y=y)\n return self\n \n def transform(self, X):\n \"\"\"Transform a sequence of documents to a document-term matrix.\n\n Parameters\n ----------\n X : iterable over raw text documents, length = n_samples\n Samples. Each sample must be a text document (either bytes or\n unicode strings, file name or file object depending on the\n constructor argument) which will be tokenized and hashed.\n\n Returns\n -------\n X : sparse matrix of shape (n_samples, n_features)\n Document-term matrix.\n \"\"\"\n if isinstance(X, str):\n raise ValueError('Iterable over raw text documents expected, string object received.')\n self._validate_params()\n analyzer = self.build_analyzer()\n X = self._get_hasher().transform((analyzer(doc) for doc in X))\n if self.binary:\n X.data.fill(1)\n if self.norm is not None:\n X = normalize(X, norm=self.norm, copy=False)\n return X\n \n def fit_transform(self, X, y=None):\n \"\"\"Transform a sequence of documents to a document-term matrix.\n\n Parameters\n ----------\n X : iterable over raw text documents, length = n_samples\n Samples. Each sample must be a text document (either bytes or\n unicode strings, file name or file object depending on the\n constructor argument) which will be tokenized and hashed.\n y : any\n Ignored. This parameter exists only for compatibility with\n sklearn.pipeline.Pipeline.\n\n Returns\n -------\n X : sparse matrix of shape (n_samples, n_features)\n Document-term matrix.\n \"\"\"\n return self.fit(X, y).transform(X)\n \n def _get_hasher(self):\n return FeatureHasher(n_features=self.n_features, input_type='string', dtype=self.dtype, alternate_sign=self.alternate_sign)\n \n def _more_tags(self):\n return {'X_types': ['string']}\n" + "docstring": "Convert a collection of text documents to a matrix of token occurrences.\n\n It turns a collection of text documents into a scipy.sparse matrix holding\n token occurrence counts (or binary occurrence information), possibly\n normalized as token frequencies if norm='l1' or projected on the euclidean\n unit sphere if norm='l2'.\n\n This text vectorizer implementation uses the hashing trick to find the\n token string name to feature integer index mapping.\n\n This strategy has several advantages:\n\n - it is very low memory scalable to large datasets as there is no need to\n store a vocabulary dictionary in memory.\n\n - it is fast to pickle and un-pickle as it holds no state besides the\n constructor parameters.\n\n - it can be used in a streaming (partial fit) or parallel pipeline as there\n is no state computed during fit.\n\n There are also a couple of cons (vs using a CountVectorizer with an\n in-memory vocabulary):\n\n - there is no way to compute the inverse transform (from feature indices to\n string feature names) which can be a problem when trying to introspect\n which features are most important to a model.\n\n - there can be collisions: distinct tokens can be mapped to the same\n feature index. However in practice this is rarely an issue if n_features\n is large enough (e.g. 2 ** 18 for text classification problems).\n\n - no IDF weighting as this would render the transformer stateful.\n\n The hash function employed is the signed 32-bit version of Murmurhash3.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n input : {'filename', 'file', 'content'}, default='content'\n - If `'filename'`, the sequence passed as an argument to fit is\n expected to be a list of filenames that need reading to fetch\n the raw content to analyze.\n\n - If `'file'`, the sequence items must have a 'read' method (file-like\n object) that is called to fetch the bytes in memory.\n\n - If `'content'`, the input is expected to be a sequence of items that\n can be of type string or byte.\n\n encoding : str, default='utf-8'\n If bytes or files are given to analyze, this encoding is used to\n decode.\n\n decode_error : {'strict', 'ignore', 'replace'}, default='strict'\n Instruction on what to do if a byte sequence is given to analyze that\n contains characters not of the given `encoding`. By default, it is\n 'strict', meaning that a UnicodeDecodeError will be raised. Other\n values are 'ignore' and 'replace'.\n\n strip_accents : {'ascii', 'unicode'}, default=None\n Remove accents and perform other character normalization\n during the preprocessing step.\n 'ascii' is a fast method that only works on characters that have\n a direct ASCII mapping.\n 'unicode' is a slightly slower method that works on any characters.\n None (default) does nothing.\n\n Both 'ascii' and 'unicode' use NFKD normalization from\n :func:`unicodedata.normalize`.\n\n lowercase : bool, default=True\n Convert all characters to lowercase before tokenizing.\n\n preprocessor : callable, default=None\n Override the preprocessing (string transformation) stage while\n preserving the tokenizing and n-grams generation steps.\n Only applies if ``analyzer is not callable``.\n\n tokenizer : callable, default=None\n Override the string tokenization step while preserving the\n preprocessing and n-grams generation steps.\n Only applies if ``analyzer == 'word'``.\n\n stop_words : {'english'}, list, default=None\n If 'english', a built-in stop word list for English is used.\n There are several known issues with 'english' and you should\n consider an alternative (see :ref:`stop_words`).\n\n If a list, that list is assumed to contain stop words, all of which\n will be removed from the resulting tokens.\n Only applies if ``analyzer == 'word'``.\n\n token_pattern : str, default=r\"(?u)\\\\b\\\\w\\\\w+\\\\b\"\n Regular expression denoting what constitutes a \"token\", only used\n if ``analyzer == 'word'``. The default regexp selects tokens of 2\n or more alphanumeric characters (punctuation is completely ignored\n and always treated as a token separator).\n\n If there is a capturing group in token_pattern then the\n captured group content, not the entire match, becomes the token.\n At most one capturing group is permitted.\n\n ngram_range : tuple (min_n, max_n), default=(1, 1)\n The lower and upper boundary of the range of n-values for different\n n-grams to be extracted. All values of n such that min_n <= n <= max_n\n will be used. For example an ``ngram_range`` of ``(1, 1)`` means only\n unigrams, ``(1, 2)`` means unigrams and bigrams, and ``(2, 2)`` means\n only bigrams.\n Only applies if ``analyzer is not callable``.\n\n analyzer : {'word', 'char', 'char_wb'} or callable, default='word'\n Whether the feature should be made of word or character n-grams.\n Option 'char_wb' creates character n-grams only from text inside\n word boundaries; n-grams at the edges of words are padded with space.\n\n If a callable is passed it is used to extract the sequence of features\n out of the raw, unprocessed input.\n\n .. versionchanged:: 0.21\n Since v0.21, if ``input`` is ``'filename'`` or ``'file'``, the data\n is first read from the file and then passed to the given callable\n analyzer.\n\n n_features : int, default=(2 ** 20)\n The number of features (columns) in the output matrices. Small numbers\n of features are likely to cause hash collisions, but large numbers\n will cause larger coefficient dimensions in linear learners.\n\n binary : bool, default=False\n If True, all non zero counts are set to 1. This is useful for discrete\n probabilistic models that model binary events rather than integer\n counts.\n\n norm : {'l1', 'l2'}, default='l2'\n Norm used to normalize term vectors. None for no normalization.\n\n alternate_sign : bool, default=True\n When True, an alternating sign is added to the features as to\n approximately conserve the inner product in the hashed space even for\n small n_features. This approach is similar to sparse random projection.\n\n .. versionadded:: 0.19\n\n dtype : type, default=np.float64\n Type of the matrix returned by fit_transform() or transform().\n\n See Also\n --------\n CountVectorizer : Convert a collection of text documents to a matrix of\n token counts.\n TfidfVectorizer : Convert a collection of raw documents to a matrix of\n TF-IDF features.\n\n Examples\n --------\n >>> from sklearn.feature_extraction.text import HashingVectorizer\n >>> corpus = [\n ... 'This is the first document.',\n ... 'This document is the second document.',\n ... 'And this is the third one.',\n ... 'Is this the first document?',\n ... ]\n >>> vectorizer = HashingVectorizer(n_features=2**4)\n >>> X = vectorizer.fit_transform(corpus)\n >>> print(X.shape)\n (4, 16)\n ", + "source_code": "\n\nclass HashingVectorizer(TransformerMixin, _VectorizerMixin, BaseEstimator):\n \"\"\"Convert a collection of text documents to a matrix of token occurrences.\n\n It turns a collection of text documents into a scipy.sparse matrix holding\n token occurrence counts (or binary occurrence information), possibly\n normalized as token frequencies if norm='l1' or projected on the euclidean\n unit sphere if norm='l2'.\n\n This text vectorizer implementation uses the hashing trick to find the\n token string name to feature integer index mapping.\n\n This strategy has several advantages:\n\n - it is very low memory scalable to large datasets as there is no need to\n store a vocabulary dictionary in memory.\n\n - it is fast to pickle and un-pickle as it holds no state besides the\n constructor parameters.\n\n - it can be used in a streaming (partial fit) or parallel pipeline as there\n is no state computed during fit.\n\n There are also a couple of cons (vs using a CountVectorizer with an\n in-memory vocabulary):\n\n - there is no way to compute the inverse transform (from feature indices to\n string feature names) which can be a problem when trying to introspect\n which features are most important to a model.\n\n - there can be collisions: distinct tokens can be mapped to the same\n feature index. However in practice this is rarely an issue if n_features\n is large enough (e.g. 2 ** 18 for text classification problems).\n\n - no IDF weighting as this would render the transformer stateful.\n\n The hash function employed is the signed 32-bit version of Murmurhash3.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n input : {'filename', 'file', 'content'}, default='content'\n - If `'filename'`, the sequence passed as an argument to fit is\n expected to be a list of filenames that need reading to fetch\n the raw content to analyze.\n\n - If `'file'`, the sequence items must have a 'read' method (file-like\n object) that is called to fetch the bytes in memory.\n\n - If `'content'`, the input is expected to be a sequence of items that\n can be of type string or byte.\n\n encoding : str, default='utf-8'\n If bytes or files are given to analyze, this encoding is used to\n decode.\n\n decode_error : {'strict', 'ignore', 'replace'}, default='strict'\n Instruction on what to do if a byte sequence is given to analyze that\n contains characters not of the given `encoding`. By default, it is\n 'strict', meaning that a UnicodeDecodeError will be raised. Other\n values are 'ignore' and 'replace'.\n\n strip_accents : {'ascii', 'unicode'}, default=None\n Remove accents and perform other character normalization\n during the preprocessing step.\n 'ascii' is a fast method that only works on characters that have\n a direct ASCII mapping.\n 'unicode' is a slightly slower method that works on any characters.\n None (default) does nothing.\n\n Both 'ascii' and 'unicode' use NFKD normalization from\n :func:`unicodedata.normalize`.\n\n lowercase : bool, default=True\n Convert all characters to lowercase before tokenizing.\n\n preprocessor : callable, default=None\n Override the preprocessing (string transformation) stage while\n preserving the tokenizing and n-grams generation steps.\n Only applies if ``analyzer is not callable``.\n\n tokenizer : callable, default=None\n Override the string tokenization step while preserving the\n preprocessing and n-grams generation steps.\n Only applies if ``analyzer == 'word'``.\n\n stop_words : {'english'}, list, default=None\n If 'english', a built-in stop word list for English is used.\n There are several known issues with 'english' and you should\n consider an alternative (see :ref:`stop_words`).\n\n If a list, that list is assumed to contain stop words, all of which\n will be removed from the resulting tokens.\n Only applies if ``analyzer == 'word'``.\n\n token_pattern : str, default=r\"(?u)\\\\b\\\\w\\\\w+\\\\b\"\n Regular expression denoting what constitutes a \"token\", only used\n if ``analyzer == 'word'``. The default regexp selects tokens of 2\n or more alphanumeric characters (punctuation is completely ignored\n and always treated as a token separator).\n\n If there is a capturing group in token_pattern then the\n captured group content, not the entire match, becomes the token.\n At most one capturing group is permitted.\n\n ngram_range : tuple (min_n, max_n), default=(1, 1)\n The lower and upper boundary of the range of n-values for different\n n-grams to be extracted. All values of n such that min_n <= n <= max_n\n will be used. For example an ``ngram_range`` of ``(1, 1)`` means only\n unigrams, ``(1, 2)`` means unigrams and bigrams, and ``(2, 2)`` means\n only bigrams.\n Only applies if ``analyzer is not callable``.\n\n analyzer : {'word', 'char', 'char_wb'} or callable, default='word'\n Whether the feature should be made of word or character n-grams.\n Option 'char_wb' creates character n-grams only from text inside\n word boundaries; n-grams at the edges of words are padded with space.\n\n If a callable is passed it is used to extract the sequence of features\n out of the raw, unprocessed input.\n\n .. versionchanged:: 0.21\n Since v0.21, if ``input`` is ``'filename'`` or ``'file'``, the data\n is first read from the file and then passed to the given callable\n analyzer.\n\n n_features : int, default=(2 ** 20)\n The number of features (columns) in the output matrices. Small numbers\n of features are likely to cause hash collisions, but large numbers\n will cause larger coefficient dimensions in linear learners.\n\n binary : bool, default=False\n If True, all non zero counts are set to 1. This is useful for discrete\n probabilistic models that model binary events rather than integer\n counts.\n\n norm : {'l1', 'l2'}, default='l2'\n Norm used to normalize term vectors. None for no normalization.\n\n alternate_sign : bool, default=True\n When True, an alternating sign is added to the features as to\n approximately conserve the inner product in the hashed space even for\n small n_features. This approach is similar to sparse random projection.\n\n .. versionadded:: 0.19\n\n dtype : type, default=np.float64\n Type of the matrix returned by fit_transform() or transform().\n\n See Also\n --------\n CountVectorizer : Convert a collection of text documents to a matrix of\n token counts.\n TfidfVectorizer : Convert a collection of raw documents to a matrix of\n TF-IDF features.\n\n Examples\n --------\n >>> from sklearn.feature_extraction.text import HashingVectorizer\n >>> corpus = [\n ... 'This is the first document.',\n ... 'This document is the second document.',\n ... 'And this is the third one.',\n ... 'Is this the first document?',\n ... ]\n >>> vectorizer = HashingVectorizer(n_features=2**4)\n >>> X = vectorizer.fit_transform(corpus)\n >>> print(X.shape)\n (4, 16)\n \"\"\"\n \n def __init__(self, *, input='content', encoding='utf-8', decode_error='strict', strip_accents=None, lowercase=True, preprocessor=None, tokenizer=None, stop_words=None, token_pattern='(?u)\\\\b\\\\w\\\\w+\\\\b', ngram_range=(1, 1), analyzer='word', n_features=2**20, binary=False, norm='l2', alternate_sign=True, dtype=np.float64):\n self.input = input\n self.encoding = encoding\n self.decode_error = decode_error\n self.strip_accents = strip_accents\n self.preprocessor = preprocessor\n self.tokenizer = tokenizer\n self.analyzer = analyzer\n self.lowercase = lowercase\n self.token_pattern = token_pattern\n self.stop_words = stop_words\n self.n_features = n_features\n self.ngram_range = ngram_range\n self.binary = binary\n self.norm = norm\n self.alternate_sign = alternate_sign\n self.dtype = dtype\n \n def partial_fit(self, X, y=None):\n \"\"\"No-op: this transformer is stateless.\n\n This method is just there to mark the fact that this transformer\n can work in a streaming setup.\n\n Parameters\n ----------\n X : ndarray of shape [n_samples, n_features]\n Training data.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n self : object\n HashingVectorizer instance.\n \"\"\"\n return self\n \n def fit(self, X, y=None):\n \"\"\"No-op: this transformer is stateless.\n\n Parameters\n ----------\n X : ndarray of shape [n_samples, n_features]\n Training data.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n self : object\n HashingVectorizer instance.\n \"\"\"\n if isinstance(X, str):\n raise ValueError('Iterable over raw text documents expected, string object received.')\n self._warn_for_unused_params()\n self._validate_params()\n self._get_hasher().fit(X, y=y)\n return self\n \n def transform(self, X):\n \"\"\"Transform a sequence of documents to a document-term matrix.\n\n Parameters\n ----------\n X : iterable over raw text documents, length = n_samples\n Samples. Each sample must be a text document (either bytes or\n unicode strings, file name or file object depending on the\n constructor argument) which will be tokenized and hashed.\n\n Returns\n -------\n X : sparse matrix of shape (n_samples, n_features)\n Document-term matrix.\n \"\"\"\n if isinstance(X, str):\n raise ValueError('Iterable over raw text documents expected, string object received.')\n self._validate_params()\n analyzer = self.build_analyzer()\n X = self._get_hasher().transform((analyzer(doc) for doc in X))\n if self.binary:\n X.data.fill(1)\n if self.norm is not None:\n X = normalize(X, norm=self.norm, copy=False)\n return X\n \n def fit_transform(self, X, y=None):\n \"\"\"Transform a sequence of documents to a document-term matrix.\n\n Parameters\n ----------\n X : iterable over raw text documents, length = n_samples\n Samples. Each sample must be a text document (either bytes or\n unicode strings, file name or file object depending on the\n constructor argument) which will be tokenized and hashed.\n y : any\n Ignored. This parameter exists only for compatibility with\n sklearn.pipeline.Pipeline.\n\n Returns\n -------\n X : sparse matrix of shape (n_samples, n_features)\n Document-term matrix.\n \"\"\"\n return self.fit(X, y).transform(X)\n \n def _get_hasher(self):\n return FeatureHasher(n_features=self.n_features, input_type='string', dtype=self.dtype, alternate_sign=self.alternate_sign)\n \n def _more_tags(self):\n return {'X_types': ['string']}\n" }, { "name": "TfidfTransformer", @@ -22417,14 +22370,14 @@ "sklearn.feature_extraction.text.TfidfTransformer.__init__", "sklearn.feature_extraction.text.TfidfTransformer.fit", "sklearn.feature_extraction.text.TfidfTransformer.transform", - "sklearn.feature_extraction.text.TfidfTransformer.idf_", - "sklearn.feature_extraction.text.TfidfTransformer.idf_", + "sklearn.feature_extraction.text.TfidfTransformer.idf_@getter", + "sklearn.feature_extraction.text.TfidfTransformer.idf_@setter", "sklearn.feature_extraction.text.TfidfTransformer._more_tags" ], "is_public": true, "description": "Transform a count matrix to a normalized tf or tf-idf representation.\n\nTf means term-frequency while tf-idf means term-frequency times inverse document-frequency. This is a common term weighting scheme in information retrieval, that has also found good use in document classification. The goal of using tf-idf instead of the raw frequencies of occurrence of a token in a given document is to scale down the impact of tokens that occur very frequently in a given corpus and that are hence empirically less informative than features that occur in a small fraction of the training corpus. The formula that is used to compute the tf-idf for a term t of a document d in a document set is tf-idf(t, d) = tf(t, d) * idf(t), and the idf is computed as idf(t) = log [ n / df(t) ] + 1 (if ``smooth_idf=False``), where n is the total number of documents in the document set and df(t) is the document frequency of t; the document frequency is the number of documents in the document set that contain the term t. The effect of adding \"1\" to the idf in the equation above is that terms with zero idf, i.e., terms that occur in all documents in a training set, will not be entirely ignored. (Note that the idf formula above differs from the standard textbook notation that defines the idf as idf(t) = log [ n / (df(t) + 1) ]). If ``smooth_idf=True`` (the default), the constant \"1\" is added to the numerator and denominator of the idf as if an extra document was seen containing every term in the collection exactly once, which prevents zero divisions: idf(t) = log [ (1 + n) / (1 + df(t)) ] + 1. Furthermore, the formulas used to compute tf and idf depend on parameter settings that correspond to the SMART notation used in IR as follows: Tf is \"n\" (natural) by default, \"l\" (logarithmic) when ``sublinear_tf=True``. Idf is \"t\" when use_idf is given, \"n\" (none) otherwise. Normalization is \"c\" (cosine) when ``norm='l2'``, \"n\" (none) when ``norm=None``. Read more in the :ref:`User Guide `.", - "docstring": "Transform a count matrix to a normalized tf or tf-idf representation.\n\n Tf means term-frequency while tf-idf means term-frequency times inverse\n document-frequency. This is a common term weighting scheme in information\n retrieval, that has also found good use in document classification.\n\n The goal of using tf-idf instead of the raw frequencies of occurrence of a\n token in a given document is to scale down the impact of tokens that occur\n very frequently in a given corpus and that are hence empirically less\n informative than features that occur in a small fraction of the training\n corpus.\n\n The formula that is used to compute the tf-idf for a term t of a document d\n in a document set is tf-idf(t, d) = tf(t, d) * idf(t), and the idf is\n computed as idf(t) = log [ n / df(t) ] + 1 (if ``smooth_idf=False``), where\n n is the total number of documents in the document set and df(t) is the\n document frequency of t; the document frequency is the number of documents\n in the document set that contain the term t. The effect of adding \"1\" to\n the idf in the equation above is that terms with zero idf, i.e., terms\n that occur in all documents in a training set, will not be entirely\n ignored.\n (Note that the idf formula above differs from the standard textbook\n notation that defines the idf as\n idf(t) = log [ n / (df(t) + 1) ]).\n\n If ``smooth_idf=True`` (the default), the constant \"1\" is added to the\n numerator and denominator of the idf as if an extra document was seen\n containing every term in the collection exactly once, which prevents\n zero divisions: idf(t) = log [ (1 + n) / (1 + df(t)) ] + 1.\n\n Furthermore, the formulas used to compute tf and idf depend\n on parameter settings that correspond to the SMART notation used in IR\n as follows:\n\n Tf is \"n\" (natural) by default, \"l\" (logarithmic) when\n ``sublinear_tf=True``.\n Idf is \"t\" when use_idf is given, \"n\" (none) otherwise.\n Normalization is \"c\" (cosine) when ``norm='l2'``, \"n\" (none)\n when ``norm=None``.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n norm : {'l1', 'l2'}, default='l2'\n Each output row will have unit norm, either:\n\n - 'l2': Sum of squares of vector elements is 1. The cosine\n similarity between two vectors is their dot product when l2 norm has\n been applied.\n - 'l1': Sum of absolute values of vector elements is 1.\n See :func:`preprocessing.normalize`.\n\n use_idf : bool, default=True\n Enable inverse-document-frequency reweighting.\n\n smooth_idf : bool, default=True\n Smooth idf weights by adding one to document frequencies, as if an\n extra document was seen containing every term in the collection\n exactly once. Prevents zero divisions.\n\n sublinear_tf : bool, default=False\n Apply sublinear tf scaling, i.e. replace tf with 1 + log(tf).\n\n Attributes\n ----------\n idf_ : array of shape (n_features)\n The inverse document frequency (IDF) vector; only defined\n if ``use_idf`` is True.\n\n .. versionadded:: 0.20\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 1.0\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n CountVectorizer : Transforms text into a sparse matrix of n-gram counts.\n\n TfidfVectorizer : Convert a collection of raw documents to a matrix of\n TF-IDF features.\n\n HashingVectorizer : Convert a collection of text documents to a matrix\n of token occurrences.\n\n References\n ----------\n .. [Yates2011] R. Baeza-Yates and B. Ribeiro-Neto (2011). Modern\n Information Retrieval. Addison Wesley, pp. 68-74.\n\n .. [MRS2008] C.D. Manning, P. Raghavan and H. Sch\u00fctze (2008).\n Introduction to Information Retrieval. Cambridge University\n Press, pp. 118-120.\n\n Examples\n --------\n >>> from sklearn.feature_extraction.text import TfidfTransformer\n >>> from sklearn.feature_extraction.text import CountVectorizer\n >>> from sklearn.pipeline import Pipeline\n >>> import numpy as np\n >>> corpus = ['this is the first document',\n ... 'this document is the second document',\n ... 'and this is the third one',\n ... 'is this the first document']\n >>> vocabulary = ['this', 'document', 'first', 'is', 'second', 'the',\n ... 'and', 'one']\n >>> pipe = Pipeline([('count', CountVectorizer(vocabulary=vocabulary)),\n ... ('tfid', TfidfTransformer())]).fit(corpus)\n >>> pipe['count'].transform(corpus).toarray()\n array([[1, 1, 1, 1, 0, 1, 0, 0],\n [1, 2, 0, 1, 1, 1, 0, 0],\n [1, 0, 0, 1, 0, 1, 1, 1],\n [1, 1, 1, 1, 0, 1, 0, 0]])\n >>> pipe['tfid'].idf_\n array([1. , 1.22314355, 1.51082562, 1. , 1.91629073,\n 1. , 1.91629073, 1.91629073])\n >>> pipe.transform(corpus).shape\n (4, 8)\n ", - "source_code": "\n\nclass TfidfTransformer(_OneToOneFeatureMixin, TransformerMixin, BaseEstimator):\n \"\"\"Transform a count matrix to a normalized tf or tf-idf representation.\n\n Tf means term-frequency while tf-idf means term-frequency times inverse\n document-frequency. This is a common term weighting scheme in information\n retrieval, that has also found good use in document classification.\n\n The goal of using tf-idf instead of the raw frequencies of occurrence of a\n token in a given document is to scale down the impact of tokens that occur\n very frequently in a given corpus and that are hence empirically less\n informative than features that occur in a small fraction of the training\n corpus.\n\n The formula that is used to compute the tf-idf for a term t of a document d\n in a document set is tf-idf(t, d) = tf(t, d) * idf(t), and the idf is\n computed as idf(t) = log [ n / df(t) ] + 1 (if ``smooth_idf=False``), where\n n is the total number of documents in the document set and df(t) is the\n document frequency of t; the document frequency is the number of documents\n in the document set that contain the term t. The effect of adding \"1\" to\n the idf in the equation above is that terms with zero idf, i.e., terms\n that occur in all documents in a training set, will not be entirely\n ignored.\n (Note that the idf formula above differs from the standard textbook\n notation that defines the idf as\n idf(t) = log [ n / (df(t) + 1) ]).\n\n If ``smooth_idf=True`` (the default), the constant \"1\" is added to the\n numerator and denominator of the idf as if an extra document was seen\n containing every term in the collection exactly once, which prevents\n zero divisions: idf(t) = log [ (1 + n) / (1 + df(t)) ] + 1.\n\n Furthermore, the formulas used to compute tf and idf depend\n on parameter settings that correspond to the SMART notation used in IR\n as follows:\n\n Tf is \"n\" (natural) by default, \"l\" (logarithmic) when\n ``sublinear_tf=True``.\n Idf is \"t\" when use_idf is given, \"n\" (none) otherwise.\n Normalization is \"c\" (cosine) when ``norm='l2'``, \"n\" (none)\n when ``norm=None``.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n norm : {'l1', 'l2'}, default='l2'\n Each output row will have unit norm, either:\n\n - 'l2': Sum of squares of vector elements is 1. The cosine\n similarity between two vectors is their dot product when l2 norm has\n been applied.\n - 'l1': Sum of absolute values of vector elements is 1.\n See :func:`preprocessing.normalize`.\n\n use_idf : bool, default=True\n Enable inverse-document-frequency reweighting.\n\n smooth_idf : bool, default=True\n Smooth idf weights by adding one to document frequencies, as if an\n extra document was seen containing every term in the collection\n exactly once. Prevents zero divisions.\n\n sublinear_tf : bool, default=False\n Apply sublinear tf scaling, i.e. replace tf with 1 + log(tf).\n\n Attributes\n ----------\n idf_ : array of shape (n_features)\n The inverse document frequency (IDF) vector; only defined\n if ``use_idf`` is True.\n\n .. versionadded:: 0.20\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 1.0\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n CountVectorizer : Transforms text into a sparse matrix of n-gram counts.\n\n TfidfVectorizer : Convert a collection of raw documents to a matrix of\n TF-IDF features.\n\n HashingVectorizer : Convert a collection of text documents to a matrix\n of token occurrences.\n\n References\n ----------\n .. [Yates2011] R. Baeza-Yates and B. Ribeiro-Neto (2011). Modern\n Information Retrieval. Addison Wesley, pp. 68-74.\n\n .. [MRS2008] C.D. Manning, P. Raghavan and H. Sch\u00fctze (2008).\n Introduction to Information Retrieval. Cambridge University\n Press, pp. 118-120.\n\n Examples\n --------\n >>> from sklearn.feature_extraction.text import TfidfTransformer\n >>> from sklearn.feature_extraction.text import CountVectorizer\n >>> from sklearn.pipeline import Pipeline\n >>> import numpy as np\n >>> corpus = ['this is the first document',\n ... 'this document is the second document',\n ... 'and this is the third one',\n ... 'is this the first document']\n >>> vocabulary = ['this', 'document', 'first', 'is', 'second', 'the',\n ... 'and', 'one']\n >>> pipe = Pipeline([('count', CountVectorizer(vocabulary=vocabulary)),\n ... ('tfid', TfidfTransformer())]).fit(corpus)\n >>> pipe['count'].transform(corpus).toarray()\n array([[1, 1, 1, 1, 0, 1, 0, 0],\n [1, 2, 0, 1, 1, 1, 0, 0],\n [1, 0, 0, 1, 0, 1, 1, 1],\n [1, 1, 1, 1, 0, 1, 0, 0]])\n >>> pipe['tfid'].idf_\n array([1. , 1.22314355, 1.51082562, 1. , 1.91629073,\n 1. , 1.91629073, 1.91629073])\n >>> pipe.transform(corpus).shape\n (4, 8)\n \"\"\"\n \n def __init__(self, *, norm='l2', use_idf=True, smooth_idf=True, sublinear_tf=False):\n self.norm = norm\n self.use_idf = use_idf\n self.smooth_idf = smooth_idf\n self.sublinear_tf = sublinear_tf\n \n def fit(self, X, y=None):\n \"\"\"Learn the idf vector (global term weights).\n\n Parameters\n ----------\n X : sparse matrix of shape n_samples, n_features)\n A matrix of term/token counts.\n\n y : None\n This parameter is not needed to compute tf-idf.\n\n Returns\n -------\n self : object\n Fitted transformer.\n \"\"\"\n X = self._validate_data(X, accept_sparse=('csr', 'csc'), accept_large_sparse=not _IS_32BIT)\n if not sp.issparse(X):\n X = sp.csr_matrix(X)\n dtype = X.dtype if X.dtype in FLOAT_DTYPES else np.float64\n if self.use_idf:\n (n_samples, n_features) = X.shape\n df = _document_frequency(X)\n df = df.astype(dtype, **_astype_copy_false(df))\n df += int(self.smooth_idf)\n n_samples += int(self.smooth_idf)\n idf = np.log(n_samples / df) + 1\n self._idf_diag = sp.diags(idf, offsets=0, shape=(n_features, n_features), format='csr', dtype=dtype)\n return self\n \n def transform(self, X, copy=True):\n \"\"\"Transform a count matrix to a tf or tf-idf representation.\n\n Parameters\n ----------\n X : sparse matrix of (n_samples, n_features)\n A matrix of term/token counts.\n\n copy : bool, default=True\n Whether to copy X and operate on the copy or perform in-place\n operations.\n\n Returns\n -------\n vectors : sparse matrix of shape (n_samples, n_features)\n Tf-idf-weighted document-term matrix.\n \"\"\"\n X = self._validate_data(X, accept_sparse='csr', dtype=FLOAT_DTYPES, copy=copy, reset=False)\n if not sp.issparse(X):\n X = sp.csr_matrix(X, dtype=np.float64)\n if self.sublinear_tf:\n np.log(X.data, X.data)\n X.data += 1\n if self.use_idf:\n check_is_fitted(self, attributes=['idf_'], msg='idf vector is not fitted')\n X = X * self._idf_diag\n if self.norm:\n X = normalize(X, norm=self.norm, copy=False)\n return X\n \n @property\n def idf_(self):\n \"\"\"Inverse document frequency vector, only defined if `use_idf=True`.\n\n Returns\n -------\n ndarray of shape (n_features,)\n \"\"\"\n return np.ravel(self._idf_diag.sum(axis=0))\n \n @idf_.setter\n def idf_(self, value):\n value = np.asarray(value, dtype=np.float64)\n n_features = value.shape[0]\n self._idf_diag = sp.spdiags(value, diags=0, m=n_features, n=n_features, format='csr')\n \n def _more_tags(self):\n return {'X_types': ['2darray', 'sparse']}\n" + "docstring": "Transform a count matrix to a normalized tf or tf-idf representation.\n\n Tf means term-frequency while tf-idf means term-frequency times inverse\n document-frequency. This is a common term weighting scheme in information\n retrieval, that has also found good use in document classification.\n\n The goal of using tf-idf instead of the raw frequencies of occurrence of a\n token in a given document is to scale down the impact of tokens that occur\n very frequently in a given corpus and that are hence empirically less\n informative than features that occur in a small fraction of the training\n corpus.\n\n The formula that is used to compute the tf-idf for a term t of a document d\n in a document set is tf-idf(t, d) = tf(t, d) * idf(t), and the idf is\n computed as idf(t) = log [ n / df(t) ] + 1 (if ``smooth_idf=False``), where\n n is the total number of documents in the document set and df(t) is the\n document frequency of t; the document frequency is the number of documents\n in the document set that contain the term t. The effect of adding \"1\" to\n the idf in the equation above is that terms with zero idf, i.e., terms\n that occur in all documents in a training set, will not be entirely\n ignored.\n (Note that the idf formula above differs from the standard textbook\n notation that defines the idf as\n idf(t) = log [ n / (df(t) + 1) ]).\n\n If ``smooth_idf=True`` (the default), the constant \"1\" is added to the\n numerator and denominator of the idf as if an extra document was seen\n containing every term in the collection exactly once, which prevents\n zero divisions: idf(t) = log [ (1 + n) / (1 + df(t)) ] + 1.\n\n Furthermore, the formulas used to compute tf and idf depend\n on parameter settings that correspond to the SMART notation used in IR\n as follows:\n\n Tf is \"n\" (natural) by default, \"l\" (logarithmic) when\n ``sublinear_tf=True``.\n Idf is \"t\" when use_idf is given, \"n\" (none) otherwise.\n Normalization is \"c\" (cosine) when ``norm='l2'``, \"n\" (none)\n when ``norm=None``.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n norm : {'l1', 'l2'}, default='l2'\n Each output row will have unit norm, either:\n\n - 'l2': Sum of squares of vector elements is 1. The cosine\n similarity between two vectors is their dot product when l2 norm has\n been applied.\n - 'l1': Sum of absolute values of vector elements is 1.\n See :func:`preprocessing.normalize`.\n\n use_idf : bool, default=True\n Enable inverse-document-frequency reweighting. If False, idf(t) = 1.\n\n smooth_idf : bool, default=True\n Smooth idf weights by adding one to document frequencies, as if an\n extra document was seen containing every term in the collection\n exactly once. Prevents zero divisions.\n\n sublinear_tf : bool, default=False\n Apply sublinear tf scaling, i.e. replace tf with 1 + log(tf).\n\n Attributes\n ----------\n idf_ : array of shape (n_features)\n The inverse document frequency (IDF) vector; only defined\n if ``use_idf`` is True.\n\n .. versionadded:: 0.20\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 1.0\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n CountVectorizer : Transforms text into a sparse matrix of n-gram counts.\n\n TfidfVectorizer : Convert a collection of raw documents to a matrix of\n TF-IDF features.\n\n HashingVectorizer : Convert a collection of text documents to a matrix\n of token occurrences.\n\n References\n ----------\n .. [Yates2011] R. Baeza-Yates and B. Ribeiro-Neto (2011). Modern\n Information Retrieval. Addison Wesley, pp. 68-74.\n\n .. [MRS2008] C.D. Manning, P. Raghavan and H. Sch\u00fctze (2008).\n Introduction to Information Retrieval. Cambridge University\n Press, pp. 118-120.\n\n Examples\n --------\n >>> from sklearn.feature_extraction.text import TfidfTransformer\n >>> from sklearn.feature_extraction.text import CountVectorizer\n >>> from sklearn.pipeline import Pipeline\n >>> corpus = ['this is the first document',\n ... 'this document is the second document',\n ... 'and this is the third one',\n ... 'is this the first document']\n >>> vocabulary = ['this', 'document', 'first', 'is', 'second', 'the',\n ... 'and', 'one']\n >>> pipe = Pipeline([('count', CountVectorizer(vocabulary=vocabulary)),\n ... ('tfid', TfidfTransformer())]).fit(corpus)\n >>> pipe['count'].transform(corpus).toarray()\n array([[1, 1, 1, 1, 0, 1, 0, 0],\n [1, 2, 0, 1, 1, 1, 0, 0],\n [1, 0, 0, 1, 0, 1, 1, 1],\n [1, 1, 1, 1, 0, 1, 0, 0]])\n >>> pipe['tfid'].idf_\n array([1. , 1.22314355, 1.51082562, 1. , 1.91629073,\n 1. , 1.91629073, 1.91629073])\n >>> pipe.transform(corpus).shape\n (4, 8)\n ", + "source_code": "\n\nclass TfidfTransformer(_OneToOneFeatureMixin, TransformerMixin, BaseEstimator):\n \"\"\"Transform a count matrix to a normalized tf or tf-idf representation.\n\n Tf means term-frequency while tf-idf means term-frequency times inverse\n document-frequency. This is a common term weighting scheme in information\n retrieval, that has also found good use in document classification.\n\n The goal of using tf-idf instead of the raw frequencies of occurrence of a\n token in a given document is to scale down the impact of tokens that occur\n very frequently in a given corpus and that are hence empirically less\n informative than features that occur in a small fraction of the training\n corpus.\n\n The formula that is used to compute the tf-idf for a term t of a document d\n in a document set is tf-idf(t, d) = tf(t, d) * idf(t), and the idf is\n computed as idf(t) = log [ n / df(t) ] + 1 (if ``smooth_idf=False``), where\n n is the total number of documents in the document set and df(t) is the\n document frequency of t; the document frequency is the number of documents\n in the document set that contain the term t. The effect of adding \"1\" to\n the idf in the equation above is that terms with zero idf, i.e., terms\n that occur in all documents in a training set, will not be entirely\n ignored.\n (Note that the idf formula above differs from the standard textbook\n notation that defines the idf as\n idf(t) = log [ n / (df(t) + 1) ]).\n\n If ``smooth_idf=True`` (the default), the constant \"1\" is added to the\n numerator and denominator of the idf as if an extra document was seen\n containing every term in the collection exactly once, which prevents\n zero divisions: idf(t) = log [ (1 + n) / (1 + df(t)) ] + 1.\n\n Furthermore, the formulas used to compute tf and idf depend\n on parameter settings that correspond to the SMART notation used in IR\n as follows:\n\n Tf is \"n\" (natural) by default, \"l\" (logarithmic) when\n ``sublinear_tf=True``.\n Idf is \"t\" when use_idf is given, \"n\" (none) otherwise.\n Normalization is \"c\" (cosine) when ``norm='l2'``, \"n\" (none)\n when ``norm=None``.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n norm : {'l1', 'l2'}, default='l2'\n Each output row will have unit norm, either:\n\n - 'l2': Sum of squares of vector elements is 1. The cosine\n similarity between two vectors is their dot product when l2 norm has\n been applied.\n - 'l1': Sum of absolute values of vector elements is 1.\n See :func:`preprocessing.normalize`.\n\n use_idf : bool, default=True\n Enable inverse-document-frequency reweighting. If False, idf(t) = 1.\n\n smooth_idf : bool, default=True\n Smooth idf weights by adding one to document frequencies, as if an\n extra document was seen containing every term in the collection\n exactly once. Prevents zero divisions.\n\n sublinear_tf : bool, default=False\n Apply sublinear tf scaling, i.e. replace tf with 1 + log(tf).\n\n Attributes\n ----------\n idf_ : array of shape (n_features)\n The inverse document frequency (IDF) vector; only defined\n if ``use_idf`` is True.\n\n .. versionadded:: 0.20\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 1.0\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n CountVectorizer : Transforms text into a sparse matrix of n-gram counts.\n\n TfidfVectorizer : Convert a collection of raw documents to a matrix of\n TF-IDF features.\n\n HashingVectorizer : Convert a collection of text documents to a matrix\n of token occurrences.\n\n References\n ----------\n .. [Yates2011] R. Baeza-Yates and B. Ribeiro-Neto (2011). Modern\n Information Retrieval. Addison Wesley, pp. 68-74.\n\n .. [MRS2008] C.D. Manning, P. Raghavan and H. Sch\u00fctze (2008).\n Introduction to Information Retrieval. Cambridge University\n Press, pp. 118-120.\n\n Examples\n --------\n >>> from sklearn.feature_extraction.text import TfidfTransformer\n >>> from sklearn.feature_extraction.text import CountVectorizer\n >>> from sklearn.pipeline import Pipeline\n >>> corpus = ['this is the first document',\n ... 'this document is the second document',\n ... 'and this is the third one',\n ... 'is this the first document']\n >>> vocabulary = ['this', 'document', 'first', 'is', 'second', 'the',\n ... 'and', 'one']\n >>> pipe = Pipeline([('count', CountVectorizer(vocabulary=vocabulary)),\n ... ('tfid', TfidfTransformer())]).fit(corpus)\n >>> pipe['count'].transform(corpus).toarray()\n array([[1, 1, 1, 1, 0, 1, 0, 0],\n [1, 2, 0, 1, 1, 1, 0, 0],\n [1, 0, 0, 1, 0, 1, 1, 1],\n [1, 1, 1, 1, 0, 1, 0, 0]])\n >>> pipe['tfid'].idf_\n array([1. , 1.22314355, 1.51082562, 1. , 1.91629073,\n 1. , 1.91629073, 1.91629073])\n >>> pipe.transform(corpus).shape\n (4, 8)\n \"\"\"\n \n def __init__(self, *, norm='l2', use_idf=True, smooth_idf=True, sublinear_tf=False):\n self.norm = norm\n self.use_idf = use_idf\n self.smooth_idf = smooth_idf\n self.sublinear_tf = sublinear_tf\n \n def fit(self, X, y=None):\n \"\"\"Learn the idf vector (global term weights).\n\n Parameters\n ----------\n X : sparse matrix of shape n_samples, n_features)\n A matrix of term/token counts.\n\n y : None\n This parameter is not needed to compute tf-idf.\n\n Returns\n -------\n self : object\n Fitted transformer.\n \"\"\"\n X = self._validate_data(X, accept_sparse=('csr', 'csc'), accept_large_sparse=not _IS_32BIT)\n if not sp.issparse(X):\n X = sp.csr_matrix(X)\n dtype = X.dtype if X.dtype in FLOAT_DTYPES else np.float64\n if self.use_idf:\n (n_samples, n_features) = X.shape\n df = _document_frequency(X)\n df = df.astype(dtype, **_astype_copy_false(df))\n df += int(self.smooth_idf)\n n_samples += int(self.smooth_idf)\n idf = np.log(n_samples / df) + 1\n self._idf_diag = sp.diags(idf, offsets=0, shape=(n_features, n_features), format='csr', dtype=dtype)\n return self\n \n def transform(self, X, copy=True):\n \"\"\"Transform a count matrix to a tf or tf-idf representation.\n\n Parameters\n ----------\n X : sparse matrix of (n_samples, n_features)\n A matrix of term/token counts.\n\n copy : bool, default=True\n Whether to copy X and operate on the copy or perform in-place\n operations.\n\n Returns\n -------\n vectors : sparse matrix of shape (n_samples, n_features)\n Tf-idf-weighted document-term matrix.\n \"\"\"\n X = self._validate_data(X, accept_sparse='csr', dtype=FLOAT_DTYPES, copy=copy, reset=False)\n if not sp.issparse(X):\n X = sp.csr_matrix(X, dtype=np.float64)\n if self.sublinear_tf:\n np.log(X.data, X.data)\n X.data += 1\n if self.use_idf:\n check_is_fitted(self, attributes=['idf_'], msg='idf vector is not fitted')\n X = X * self._idf_diag\n if self.norm:\n X = normalize(X, norm=self.norm, copy=False)\n return X\n \n @property\n def idf_(self):\n \"\"\"Inverse document frequency vector, only defined if `use_idf=True`.\n\n Returns\n -------\n ndarray of shape (n_features,)\n \"\"\"\n return np.ravel(self._idf_diag.sum(axis=0))\n \n @idf_.setter\n def idf_(self, value):\n value = np.asarray(value, dtype=np.float64)\n n_features = value.shape[0]\n self._idf_diag = sp.spdiags(value, diags=0, m=n_features, n=n_features, format='csr')\n \n def _more_tags(self):\n return {'X_types': ['2darray', 'sparse']}\n" }, { "name": "TfidfVectorizer", @@ -22433,16 +22386,16 @@ "superclasses": ["CountVectorizer"], "methods": [ "sklearn.feature_extraction.text.TfidfVectorizer.__init__", - "sklearn.feature_extraction.text.TfidfVectorizer.norm", - "sklearn.feature_extraction.text.TfidfVectorizer.norm", - "sklearn.feature_extraction.text.TfidfVectorizer.use_idf", - "sklearn.feature_extraction.text.TfidfVectorizer.use_idf", - "sklearn.feature_extraction.text.TfidfVectorizer.smooth_idf", - "sklearn.feature_extraction.text.TfidfVectorizer.smooth_idf", - "sklearn.feature_extraction.text.TfidfVectorizer.sublinear_tf", - "sklearn.feature_extraction.text.TfidfVectorizer.sublinear_tf", - "sklearn.feature_extraction.text.TfidfVectorizer.idf_", - "sklearn.feature_extraction.text.TfidfVectorizer.idf_", + "sklearn.feature_extraction.text.TfidfVectorizer.norm@getter", + "sklearn.feature_extraction.text.TfidfVectorizer.norm@setter", + "sklearn.feature_extraction.text.TfidfVectorizer.use_idf@getter", + "sklearn.feature_extraction.text.TfidfVectorizer.use_idf@setter", + "sklearn.feature_extraction.text.TfidfVectorizer.smooth_idf@getter", + "sklearn.feature_extraction.text.TfidfVectorizer.smooth_idf@setter", + "sklearn.feature_extraction.text.TfidfVectorizer.sublinear_tf@getter", + "sklearn.feature_extraction.text.TfidfVectorizer.sublinear_tf@setter", + "sklearn.feature_extraction.text.TfidfVectorizer.idf_@getter", + "sklearn.feature_extraction.text.TfidfVectorizer.idf_@setter", "sklearn.feature_extraction.text.TfidfVectorizer._check_params", "sklearn.feature_extraction.text.TfidfVectorizer.fit", "sklearn.feature_extraction.text.TfidfVectorizer.fit_transform", @@ -22451,8 +22404,8 @@ ], "is_public": true, "description": "Convert a collection of raw documents to a matrix of TF-IDF features.\n\nEquivalent to :class:`CountVectorizer` followed by :class:`TfidfTransformer`. Read more in the :ref:`User Guide `.", - "docstring": "Convert a collection of raw documents to a matrix of TF-IDF features.\n\n Equivalent to :class:`CountVectorizer` followed by\n :class:`TfidfTransformer`.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n input : {'filename', 'file', 'content'}, default='content'\n - If `'filename'`, the sequence passed as an argument to fit is\n expected to be a list of filenames that need reading to fetch\n the raw content to analyze.\n\n - If `'file'`, the sequence items must have a 'read' method (file-like\n object) that is called to fetch the bytes in memory.\n\n - If `'content'`, the input is expected to be a sequence of items that\n can be of type string or byte.\n\n encoding : str, default='utf-8'\n If bytes or files are given to analyze, this encoding is used to\n decode.\n\n decode_error : {'strict', 'ignore', 'replace'}, default='strict'\n Instruction on what to do if a byte sequence is given to analyze that\n contains characters not of the given `encoding`. By default, it is\n 'strict', meaning that a UnicodeDecodeError will be raised. Other\n values are 'ignore' and 'replace'.\n\n strip_accents : {'ascii', 'unicode'}, default=None\n Remove accents and perform other character normalization\n during the preprocessing step.\n 'ascii' is a fast method that only works on characters that have\n an direct ASCII mapping.\n 'unicode' is a slightly slower method that works on any characters.\n None (default) does nothing.\n\n Both 'ascii' and 'unicode' use NFKD normalization from\n :func:`unicodedata.normalize`.\n\n lowercase : bool, default=True\n Convert all characters to lowercase before tokenizing.\n\n preprocessor : callable, default=None\n Override the preprocessing (string transformation) stage while\n preserving the tokenizing and n-grams generation steps.\n Only applies if ``analyzer is not callable``.\n\n tokenizer : callable, default=None\n Override the string tokenization step while preserving the\n preprocessing and n-grams generation steps.\n Only applies if ``analyzer == 'word'``.\n\n analyzer : {'word', 'char', 'char_wb'} or callable, default='word'\n Whether the feature should be made of word or character n-grams.\n Option 'char_wb' creates character n-grams only from text inside\n word boundaries; n-grams at the edges of words are padded with space.\n\n If a callable is passed it is used to extract the sequence of features\n out of the raw, unprocessed input.\n\n .. versionchanged:: 0.21\n Since v0.21, if ``input`` is ``'filename'`` or ``'file'``, the data\n is first read from the file and then passed to the given callable\n analyzer.\n\n stop_words : {'english'}, list, default=None\n If a string, it is passed to _check_stop_list and the appropriate stop\n list is returned. 'english' is currently the only supported string\n value.\n There are several known issues with 'english' and you should\n consider an alternative (see :ref:`stop_words`).\n\n If a list, that list is assumed to contain stop words, all of which\n will be removed from the resulting tokens.\n Only applies if ``analyzer == 'word'``.\n\n If None, no stop words will be used. max_df can be set to a value\n in the range [0.7, 1.0) to automatically detect and filter stop\n words based on intra corpus document frequency of terms.\n\n token_pattern : str, default=r\"(?u)\\\\b\\\\w\\\\w+\\\\b\"\n Regular expression denoting what constitutes a \"token\", only used\n if ``analyzer == 'word'``. The default regexp selects tokens of 2\n or more alphanumeric characters (punctuation is completely ignored\n and always treated as a token separator).\n\n If there is a capturing group in token_pattern then the\n captured group content, not the entire match, becomes the token.\n At most one capturing group is permitted.\n\n ngram_range : tuple (min_n, max_n), default=(1, 1)\n The lower and upper boundary of the range of n-values for different\n n-grams to be extracted. All values of n such that min_n <= n <= max_n\n will be used. For example an ``ngram_range`` of ``(1, 1)`` means only\n unigrams, ``(1, 2)`` means unigrams and bigrams, and ``(2, 2)`` means\n only bigrams.\n Only applies if ``analyzer is not callable``.\n\n max_df : float or int, default=1.0\n When building the vocabulary ignore terms that have a document\n frequency strictly higher than the given threshold (corpus-specific\n stop words).\n If float in range [0.0, 1.0], the parameter represents a proportion of\n documents, integer absolute counts.\n This parameter is ignored if vocabulary is not None.\n\n min_df : float or int, default=1\n When building the vocabulary ignore terms that have a document\n frequency strictly lower than the given threshold. This value is also\n called cut-off in the literature.\n If float in range of [0.0, 1.0], the parameter represents a proportion\n of documents, integer absolute counts.\n This parameter is ignored if vocabulary is not None.\n\n max_features : int, default=None\n If not None, build a vocabulary that only consider the top\n max_features ordered by term frequency across the corpus.\n\n This parameter is ignored if vocabulary is not None.\n\n vocabulary : Mapping or iterable, default=None\n Either a Mapping (e.g., a dict) where keys are terms and values are\n indices in the feature matrix, or an iterable over terms. If not\n given, a vocabulary is determined from the input documents.\n\n binary : bool, default=False\n If True, all non-zero term counts are set to 1. This does not mean\n outputs will have only 0/1 values, only that the tf term in tf-idf\n is binary. (Set idf and normalization to False to get 0/1 outputs).\n\n dtype : dtype, default=float64\n Type of the matrix returned by fit_transform() or transform().\n\n norm : {'l1', 'l2'}, default='l2'\n Each output row will have unit norm, either:\n\n - 'l2': Sum of squares of vector elements is 1. The cosine\n similarity between two vectors is their dot product when l2 norm has\n been applied.\n - 'l1': Sum of absolute values of vector elements is 1.\n See :func:`preprocessing.normalize`.\n\n use_idf : bool, default=True\n Enable inverse-document-frequency reweighting.\n\n smooth_idf : bool, default=True\n Smooth idf weights by adding one to document frequencies, as if an\n extra document was seen containing every term in the collection\n exactly once. Prevents zero divisions.\n\n sublinear_tf : bool, default=False\n Apply sublinear tf scaling, i.e. replace tf with 1 + log(tf).\n\n Attributes\n ----------\n vocabulary_ : dict\n A mapping of terms to feature indices.\n\n fixed_vocabulary_ : bool\n True if a fixed vocabulary of term to indices mapping\n is provided by the user.\n\n idf_ : array of shape (n_features,)\n The inverse document frequency (IDF) vector; only defined\n if ``use_idf`` is True.\n\n stop_words_ : set\n Terms that were ignored because they either:\n\n - occurred in too many documents (`max_df`)\n - occurred in too few documents (`min_df`)\n - were cut off by feature selection (`max_features`).\n\n This is only available if no vocabulary was given.\n\n See Also\n --------\n CountVectorizer : Transforms text into a sparse matrix of n-gram counts.\n\n TfidfTransformer : Performs the TF-IDF transformation from a provided\n matrix of counts.\n\n Notes\n -----\n The ``stop_words_`` attribute can get large and increase the model size\n when pickling. This attribute is provided only for introspection and can\n be safely removed using delattr or set to None before pickling.\n\n Examples\n --------\n >>> from sklearn.feature_extraction.text import TfidfVectorizer\n >>> corpus = [\n ... 'This is the first document.',\n ... 'This document is the second document.',\n ... 'And this is the third one.',\n ... 'Is this the first document?',\n ... ]\n >>> vectorizer = TfidfVectorizer()\n >>> X = vectorizer.fit_transform(corpus)\n >>> vectorizer.get_feature_names_out()\n array(['and', 'document', 'first', 'is', 'one', 'second', 'the', 'third',\n 'this'], ...)\n >>> print(X.shape)\n (4, 9)\n ", - "source_code": "\n\nclass TfidfVectorizer(CountVectorizer):\n \"\"\"Convert a collection of raw documents to a matrix of TF-IDF features.\n\n Equivalent to :class:`CountVectorizer` followed by\n :class:`TfidfTransformer`.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n input : {'filename', 'file', 'content'}, default='content'\n - If `'filename'`, the sequence passed as an argument to fit is\n expected to be a list of filenames that need reading to fetch\n the raw content to analyze.\n\n - If `'file'`, the sequence items must have a 'read' method (file-like\n object) that is called to fetch the bytes in memory.\n\n - If `'content'`, the input is expected to be a sequence of items that\n can be of type string or byte.\n\n encoding : str, default='utf-8'\n If bytes or files are given to analyze, this encoding is used to\n decode.\n\n decode_error : {'strict', 'ignore', 'replace'}, default='strict'\n Instruction on what to do if a byte sequence is given to analyze that\n contains characters not of the given `encoding`. By default, it is\n 'strict', meaning that a UnicodeDecodeError will be raised. Other\n values are 'ignore' and 'replace'.\n\n strip_accents : {'ascii', 'unicode'}, default=None\n Remove accents and perform other character normalization\n during the preprocessing step.\n 'ascii' is a fast method that only works on characters that have\n an direct ASCII mapping.\n 'unicode' is a slightly slower method that works on any characters.\n None (default) does nothing.\n\n Both 'ascii' and 'unicode' use NFKD normalization from\n :func:`unicodedata.normalize`.\n\n lowercase : bool, default=True\n Convert all characters to lowercase before tokenizing.\n\n preprocessor : callable, default=None\n Override the preprocessing (string transformation) stage while\n preserving the tokenizing and n-grams generation steps.\n Only applies if ``analyzer is not callable``.\n\n tokenizer : callable, default=None\n Override the string tokenization step while preserving the\n preprocessing and n-grams generation steps.\n Only applies if ``analyzer == 'word'``.\n\n analyzer : {'word', 'char', 'char_wb'} or callable, default='word'\n Whether the feature should be made of word or character n-grams.\n Option 'char_wb' creates character n-grams only from text inside\n word boundaries; n-grams at the edges of words are padded with space.\n\n If a callable is passed it is used to extract the sequence of features\n out of the raw, unprocessed input.\n\n .. versionchanged:: 0.21\n Since v0.21, if ``input`` is ``'filename'`` or ``'file'``, the data\n is first read from the file and then passed to the given callable\n analyzer.\n\n stop_words : {'english'}, list, default=None\n If a string, it is passed to _check_stop_list and the appropriate stop\n list is returned. 'english' is currently the only supported string\n value.\n There are several known issues with 'english' and you should\n consider an alternative (see :ref:`stop_words`).\n\n If a list, that list is assumed to contain stop words, all of which\n will be removed from the resulting tokens.\n Only applies if ``analyzer == 'word'``.\n\n If None, no stop words will be used. max_df can be set to a value\n in the range [0.7, 1.0) to automatically detect and filter stop\n words based on intra corpus document frequency of terms.\n\n token_pattern : str, default=r\"(?u)\\\\b\\\\w\\\\w+\\\\b\"\n Regular expression denoting what constitutes a \"token\", only used\n if ``analyzer == 'word'``. The default regexp selects tokens of 2\n or more alphanumeric characters (punctuation is completely ignored\n and always treated as a token separator).\n\n If there is a capturing group in token_pattern then the\n captured group content, not the entire match, becomes the token.\n At most one capturing group is permitted.\n\n ngram_range : tuple (min_n, max_n), default=(1, 1)\n The lower and upper boundary of the range of n-values for different\n n-grams to be extracted. All values of n such that min_n <= n <= max_n\n will be used. For example an ``ngram_range`` of ``(1, 1)`` means only\n unigrams, ``(1, 2)`` means unigrams and bigrams, and ``(2, 2)`` means\n only bigrams.\n Only applies if ``analyzer is not callable``.\n\n max_df : float or int, default=1.0\n When building the vocabulary ignore terms that have a document\n frequency strictly higher than the given threshold (corpus-specific\n stop words).\n If float in range [0.0, 1.0], the parameter represents a proportion of\n documents, integer absolute counts.\n This parameter is ignored if vocabulary is not None.\n\n min_df : float or int, default=1\n When building the vocabulary ignore terms that have a document\n frequency strictly lower than the given threshold. This value is also\n called cut-off in the literature.\n If float in range of [0.0, 1.0], the parameter represents a proportion\n of documents, integer absolute counts.\n This parameter is ignored if vocabulary is not None.\n\n max_features : int, default=None\n If not None, build a vocabulary that only consider the top\n max_features ordered by term frequency across the corpus.\n\n This parameter is ignored if vocabulary is not None.\n\n vocabulary : Mapping or iterable, default=None\n Either a Mapping (e.g., a dict) where keys are terms and values are\n indices in the feature matrix, or an iterable over terms. If not\n given, a vocabulary is determined from the input documents.\n\n binary : bool, default=False\n If True, all non-zero term counts are set to 1. This does not mean\n outputs will have only 0/1 values, only that the tf term in tf-idf\n is binary. (Set idf and normalization to False to get 0/1 outputs).\n\n dtype : dtype, default=float64\n Type of the matrix returned by fit_transform() or transform().\n\n norm : {'l1', 'l2'}, default='l2'\n Each output row will have unit norm, either:\n\n - 'l2': Sum of squares of vector elements is 1. The cosine\n similarity between two vectors is their dot product when l2 norm has\n been applied.\n - 'l1': Sum of absolute values of vector elements is 1.\n See :func:`preprocessing.normalize`.\n\n use_idf : bool, default=True\n Enable inverse-document-frequency reweighting.\n\n smooth_idf : bool, default=True\n Smooth idf weights by adding one to document frequencies, as if an\n extra document was seen containing every term in the collection\n exactly once. Prevents zero divisions.\n\n sublinear_tf : bool, default=False\n Apply sublinear tf scaling, i.e. replace tf with 1 + log(tf).\n\n Attributes\n ----------\n vocabulary_ : dict\n A mapping of terms to feature indices.\n\n fixed_vocabulary_ : bool\n True if a fixed vocabulary of term to indices mapping\n is provided by the user.\n\n idf_ : array of shape (n_features,)\n The inverse document frequency (IDF) vector; only defined\n if ``use_idf`` is True.\n\n stop_words_ : set\n Terms that were ignored because they either:\n\n - occurred in too many documents (`max_df`)\n - occurred in too few documents (`min_df`)\n - were cut off by feature selection (`max_features`).\n\n This is only available if no vocabulary was given.\n\n See Also\n --------\n CountVectorizer : Transforms text into a sparse matrix of n-gram counts.\n\n TfidfTransformer : Performs the TF-IDF transformation from a provided\n matrix of counts.\n\n Notes\n -----\n The ``stop_words_`` attribute can get large and increase the model size\n when pickling. This attribute is provided only for introspection and can\n be safely removed using delattr or set to None before pickling.\n\n Examples\n --------\n >>> from sklearn.feature_extraction.text import TfidfVectorizer\n >>> corpus = [\n ... 'This is the first document.',\n ... 'This document is the second document.',\n ... 'And this is the third one.',\n ... 'Is this the first document?',\n ... ]\n >>> vectorizer = TfidfVectorizer()\n >>> X = vectorizer.fit_transform(corpus)\n >>> vectorizer.get_feature_names_out()\n array(['and', 'document', 'first', 'is', 'one', 'second', 'the', 'third',\n 'this'], ...)\n >>> print(X.shape)\n (4, 9)\n \"\"\"\n \n def __init__(self, *, input='content', encoding='utf-8', decode_error='strict', strip_accents=None, lowercase=True, preprocessor=None, tokenizer=None, analyzer='word', stop_words=None, token_pattern='(?u)\\\\b\\\\w\\\\w+\\\\b', ngram_range=(1, 1), max_df=1.0, min_df=1, max_features=None, vocabulary=None, binary=False, dtype=np.float64, norm='l2', use_idf=True, smooth_idf=True, sublinear_tf=False):\n super().__init__(input=input, encoding=encoding, decode_error=decode_error, strip_accents=strip_accents, lowercase=lowercase, preprocessor=preprocessor, tokenizer=tokenizer, analyzer=analyzer, stop_words=stop_words, token_pattern=token_pattern, ngram_range=ngram_range, max_df=max_df, min_df=min_df, max_features=max_features, vocabulary=vocabulary, binary=binary, dtype=dtype)\n self._tfidf = TfidfTransformer(norm=norm, use_idf=use_idf, smooth_idf=smooth_idf, sublinear_tf=sublinear_tf)\n \n @property\n def norm(self):\n \"\"\"Norm of each row output, can be either \"l1\" or \"l2\".\"\"\"\n return self._tfidf.norm\n \n @norm.setter\n def norm(self, value):\n self._tfidf.norm = value\n \n @property\n def use_idf(self):\n \"\"\"Whether or not IDF re-weighting is used.\"\"\"\n return self._tfidf.use_idf\n \n @use_idf.setter\n def use_idf(self, value):\n self._tfidf.use_idf = value\n \n @property\n def smooth_idf(self):\n \"\"\"Whether or not IDF weights are smoothed.\"\"\"\n return self._tfidf.smooth_idf\n \n @smooth_idf.setter\n def smooth_idf(self, value):\n self._tfidf.smooth_idf = value\n \n @property\n def sublinear_tf(self):\n \"\"\"Whether or not sublinear TF scaling is applied.\"\"\"\n return self._tfidf.sublinear_tf\n \n @sublinear_tf.setter\n def sublinear_tf(self, value):\n self._tfidf.sublinear_tf = value\n \n @property\n def idf_(self):\n \"\"\"Inverse document frequency vector, only defined if `use_idf=True`.\n\n Returns\n -------\n ndarray of shape (n_features,)\n \"\"\"\n return self._tfidf.idf_\n \n @idf_.setter\n def idf_(self, value):\n self._validate_vocabulary()\n if hasattr(self, 'vocabulary_'):\n if len(self.vocabulary_) != len(value):\n raise ValueError('idf length = %d must be equal to vocabulary size = %d' % (len(value), len(self.vocabulary)))\n self._tfidf.idf_ = value\n \n def _check_params(self):\n if self.dtype not in FLOAT_DTYPES:\n warnings.warn(\"Only {} 'dtype' should be used. {} 'dtype' will be converted to np.float64.\".format(FLOAT_DTYPES, self.dtype), UserWarning)\n \n def fit(self, raw_documents, y=None):\n \"\"\"Learn vocabulary and idf from training set.\n\n Parameters\n ----------\n raw_documents : iterable\n An iterable which generates either str, unicode or file objects.\n\n y : None\n This parameter is not needed to compute tfidf.\n\n Returns\n -------\n self : object\n Fitted vectorizer.\n \"\"\"\n self._check_params()\n self._warn_for_unused_params()\n X = super().fit_transform(raw_documents)\n self._tfidf.fit(X)\n return self\n \n def fit_transform(self, raw_documents, y=None):\n \"\"\"Learn vocabulary and idf, return document-term matrix.\n\n This is equivalent to fit followed by transform, but more efficiently\n implemented.\n\n Parameters\n ----------\n raw_documents : iterable\n An iterable which generates either str, unicode or file objects.\n\n y : None\n This parameter is ignored.\n\n Returns\n -------\n X : sparse matrix of (n_samples, n_features)\n Tf-idf-weighted document-term matrix.\n \"\"\"\n self._check_params()\n X = super().fit_transform(raw_documents)\n self._tfidf.fit(X)\n return self._tfidf.transform(X, copy=False)\n \n def transform(self, raw_documents):\n \"\"\"Transform documents to document-term matrix.\n\n Uses the vocabulary and document frequencies (df) learned by fit (or\n fit_transform).\n\n Parameters\n ----------\n raw_documents : iterable\n An iterable which generates either str, unicode or file objects.\n\n Returns\n -------\n X : sparse matrix of (n_samples, n_features)\n Tf-idf-weighted document-term matrix.\n \"\"\"\n check_is_fitted(self, msg='The TF-IDF vectorizer is not fitted')\n X = super().transform(raw_documents)\n return self._tfidf.transform(X, copy=False)\n \n def _more_tags(self):\n return {'X_types': ['string'], '_skip_test': True}\n" + "docstring": "Convert a collection of raw documents to a matrix of TF-IDF features.\n\n Equivalent to :class:`CountVectorizer` followed by\n :class:`TfidfTransformer`.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n input : {'filename', 'file', 'content'}, default='content'\n - If `'filename'`, the sequence passed as an argument to fit is\n expected to be a list of filenames that need reading to fetch\n the raw content to analyze.\n\n - If `'file'`, the sequence items must have a 'read' method (file-like\n object) that is called to fetch the bytes in memory.\n\n - If `'content'`, the input is expected to be a sequence of items that\n can be of type string or byte.\n\n encoding : str, default='utf-8'\n If bytes or files are given to analyze, this encoding is used to\n decode.\n\n decode_error : {'strict', 'ignore', 'replace'}, default='strict'\n Instruction on what to do if a byte sequence is given to analyze that\n contains characters not of the given `encoding`. By default, it is\n 'strict', meaning that a UnicodeDecodeError will be raised. Other\n values are 'ignore' and 'replace'.\n\n strip_accents : {'ascii', 'unicode'}, default=None\n Remove accents and perform other character normalization\n during the preprocessing step.\n 'ascii' is a fast method that only works on characters that have\n an direct ASCII mapping.\n 'unicode' is a slightly slower method that works on any characters.\n None (default) does nothing.\n\n Both 'ascii' and 'unicode' use NFKD normalization from\n :func:`unicodedata.normalize`.\n\n lowercase : bool, default=True\n Convert all characters to lowercase before tokenizing.\n\n preprocessor : callable, default=None\n Override the preprocessing (string transformation) stage while\n preserving the tokenizing and n-grams generation steps.\n Only applies if ``analyzer is not callable``.\n\n tokenizer : callable, default=None\n Override the string tokenization step while preserving the\n preprocessing and n-grams generation steps.\n Only applies if ``analyzer == 'word'``.\n\n analyzer : {'word', 'char', 'char_wb'} or callable, default='word'\n Whether the feature should be made of word or character n-grams.\n Option 'char_wb' creates character n-grams only from text inside\n word boundaries; n-grams at the edges of words are padded with space.\n\n If a callable is passed it is used to extract the sequence of features\n out of the raw, unprocessed input.\n\n .. versionchanged:: 0.21\n Since v0.21, if ``input`` is ``'filename'`` or ``'file'``, the data\n is first read from the file and then passed to the given callable\n analyzer.\n\n stop_words : {'english'}, list, default=None\n If a string, it is passed to _check_stop_list and the appropriate stop\n list is returned. 'english' is currently the only supported string\n value.\n There are several known issues with 'english' and you should\n consider an alternative (see :ref:`stop_words`).\n\n If a list, that list is assumed to contain stop words, all of which\n will be removed from the resulting tokens.\n Only applies if ``analyzer == 'word'``.\n\n If None, no stop words will be used. max_df can be set to a value\n in the range [0.7, 1.0) to automatically detect and filter stop\n words based on intra corpus document frequency of terms.\n\n token_pattern : str, default=r\"(?u)\\\\b\\\\w\\\\w+\\\\b\"\n Regular expression denoting what constitutes a \"token\", only used\n if ``analyzer == 'word'``. The default regexp selects tokens of 2\n or more alphanumeric characters (punctuation is completely ignored\n and always treated as a token separator).\n\n If there is a capturing group in token_pattern then the\n captured group content, not the entire match, becomes the token.\n At most one capturing group is permitted.\n\n ngram_range : tuple (min_n, max_n), default=(1, 1)\n The lower and upper boundary of the range of n-values for different\n n-grams to be extracted. All values of n such that min_n <= n <= max_n\n will be used. For example an ``ngram_range`` of ``(1, 1)`` means only\n unigrams, ``(1, 2)`` means unigrams and bigrams, and ``(2, 2)`` means\n only bigrams.\n Only applies if ``analyzer is not callable``.\n\n max_df : float or int, default=1.0\n When building the vocabulary ignore terms that have a document\n frequency strictly higher than the given threshold (corpus-specific\n stop words).\n If float in range [0.0, 1.0], the parameter represents a proportion of\n documents, integer absolute counts.\n This parameter is ignored if vocabulary is not None.\n\n min_df : float or int, default=1\n When building the vocabulary ignore terms that have a document\n frequency strictly lower than the given threshold. This value is also\n called cut-off in the literature.\n If float in range of [0.0, 1.0], the parameter represents a proportion\n of documents, integer absolute counts.\n This parameter is ignored if vocabulary is not None.\n\n max_features : int, default=None\n If not None, build a vocabulary that only consider the top\n max_features ordered by term frequency across the corpus.\n\n This parameter is ignored if vocabulary is not None.\n\n vocabulary : Mapping or iterable, default=None\n Either a Mapping (e.g., a dict) where keys are terms and values are\n indices in the feature matrix, or an iterable over terms. If not\n given, a vocabulary is determined from the input documents.\n\n binary : bool, default=False\n If True, all non-zero term counts are set to 1. This does not mean\n outputs will have only 0/1 values, only that the tf term in tf-idf\n is binary. (Set idf and normalization to False to get 0/1 outputs).\n\n dtype : dtype, default=float64\n Type of the matrix returned by fit_transform() or transform().\n\n norm : {'l1', 'l2'}, default='l2'\n Each output row will have unit norm, either:\n\n - 'l2': Sum of squares of vector elements is 1. The cosine\n similarity between two vectors is their dot product when l2 norm has\n been applied.\n - 'l1': Sum of absolute values of vector elements is 1.\n See :func:`preprocessing.normalize`.\n\n use_idf : bool, default=True\n Enable inverse-document-frequency reweighting. If False, idf(t) = 1.\n\n smooth_idf : bool, default=True\n Smooth idf weights by adding one to document frequencies, as if an\n extra document was seen containing every term in the collection\n exactly once. Prevents zero divisions.\n\n sublinear_tf : bool, default=False\n Apply sublinear tf scaling, i.e. replace tf with 1 + log(tf).\n\n Attributes\n ----------\n vocabulary_ : dict\n A mapping of terms to feature indices.\n\n fixed_vocabulary_ : bool\n True if a fixed vocabulary of term to indices mapping\n is provided by the user.\n\n idf_ : array of shape (n_features,)\n The inverse document frequency (IDF) vector; only defined\n if ``use_idf`` is True.\n\n stop_words_ : set\n Terms that were ignored because they either:\n\n - occurred in too many documents (`max_df`)\n - occurred in too few documents (`min_df`)\n - were cut off by feature selection (`max_features`).\n\n This is only available if no vocabulary was given.\n\n See Also\n --------\n CountVectorizer : Transforms text into a sparse matrix of n-gram counts.\n\n TfidfTransformer : Performs the TF-IDF transformation from a provided\n matrix of counts.\n\n Notes\n -----\n The ``stop_words_`` attribute can get large and increase the model size\n when pickling. This attribute is provided only for introspection and can\n be safely removed using delattr or set to None before pickling.\n\n Examples\n --------\n >>> from sklearn.feature_extraction.text import TfidfVectorizer\n >>> corpus = [\n ... 'This is the first document.',\n ... 'This document is the second document.',\n ... 'And this is the third one.',\n ... 'Is this the first document?',\n ... ]\n >>> vectorizer = TfidfVectorizer()\n >>> X = vectorizer.fit_transform(corpus)\n >>> vectorizer.get_feature_names_out()\n array(['and', 'document', 'first', 'is', 'one', 'second', 'the', 'third',\n 'this'], ...)\n >>> print(X.shape)\n (4, 9)\n ", + "source_code": "\n\nclass TfidfVectorizer(CountVectorizer):\n \"\"\"Convert a collection of raw documents to a matrix of TF-IDF features.\n\n Equivalent to :class:`CountVectorizer` followed by\n :class:`TfidfTransformer`.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n input : {'filename', 'file', 'content'}, default='content'\n - If `'filename'`, the sequence passed as an argument to fit is\n expected to be a list of filenames that need reading to fetch\n the raw content to analyze.\n\n - If `'file'`, the sequence items must have a 'read' method (file-like\n object) that is called to fetch the bytes in memory.\n\n - If `'content'`, the input is expected to be a sequence of items that\n can be of type string or byte.\n\n encoding : str, default='utf-8'\n If bytes or files are given to analyze, this encoding is used to\n decode.\n\n decode_error : {'strict', 'ignore', 'replace'}, default='strict'\n Instruction on what to do if a byte sequence is given to analyze that\n contains characters not of the given `encoding`. By default, it is\n 'strict', meaning that a UnicodeDecodeError will be raised. Other\n values are 'ignore' and 'replace'.\n\n strip_accents : {'ascii', 'unicode'}, default=None\n Remove accents and perform other character normalization\n during the preprocessing step.\n 'ascii' is a fast method that only works on characters that have\n an direct ASCII mapping.\n 'unicode' is a slightly slower method that works on any characters.\n None (default) does nothing.\n\n Both 'ascii' and 'unicode' use NFKD normalization from\n :func:`unicodedata.normalize`.\n\n lowercase : bool, default=True\n Convert all characters to lowercase before tokenizing.\n\n preprocessor : callable, default=None\n Override the preprocessing (string transformation) stage while\n preserving the tokenizing and n-grams generation steps.\n Only applies if ``analyzer is not callable``.\n\n tokenizer : callable, default=None\n Override the string tokenization step while preserving the\n preprocessing and n-grams generation steps.\n Only applies if ``analyzer == 'word'``.\n\n analyzer : {'word', 'char', 'char_wb'} or callable, default='word'\n Whether the feature should be made of word or character n-grams.\n Option 'char_wb' creates character n-grams only from text inside\n word boundaries; n-grams at the edges of words are padded with space.\n\n If a callable is passed it is used to extract the sequence of features\n out of the raw, unprocessed input.\n\n .. versionchanged:: 0.21\n Since v0.21, if ``input`` is ``'filename'`` or ``'file'``, the data\n is first read from the file and then passed to the given callable\n analyzer.\n\n stop_words : {'english'}, list, default=None\n If a string, it is passed to _check_stop_list and the appropriate stop\n list is returned. 'english' is currently the only supported string\n value.\n There are several known issues with 'english' and you should\n consider an alternative (see :ref:`stop_words`).\n\n If a list, that list is assumed to contain stop words, all of which\n will be removed from the resulting tokens.\n Only applies if ``analyzer == 'word'``.\n\n If None, no stop words will be used. max_df can be set to a value\n in the range [0.7, 1.0) to automatically detect and filter stop\n words based on intra corpus document frequency of terms.\n\n token_pattern : str, default=r\"(?u)\\\\b\\\\w\\\\w+\\\\b\"\n Regular expression denoting what constitutes a \"token\", only used\n if ``analyzer == 'word'``. The default regexp selects tokens of 2\n or more alphanumeric characters (punctuation is completely ignored\n and always treated as a token separator).\n\n If there is a capturing group in token_pattern then the\n captured group content, not the entire match, becomes the token.\n At most one capturing group is permitted.\n\n ngram_range : tuple (min_n, max_n), default=(1, 1)\n The lower and upper boundary of the range of n-values for different\n n-grams to be extracted. All values of n such that min_n <= n <= max_n\n will be used. For example an ``ngram_range`` of ``(1, 1)`` means only\n unigrams, ``(1, 2)`` means unigrams and bigrams, and ``(2, 2)`` means\n only bigrams.\n Only applies if ``analyzer is not callable``.\n\n max_df : float or int, default=1.0\n When building the vocabulary ignore terms that have a document\n frequency strictly higher than the given threshold (corpus-specific\n stop words).\n If float in range [0.0, 1.0], the parameter represents a proportion of\n documents, integer absolute counts.\n This parameter is ignored if vocabulary is not None.\n\n min_df : float or int, default=1\n When building the vocabulary ignore terms that have a document\n frequency strictly lower than the given threshold. This value is also\n called cut-off in the literature.\n If float in range of [0.0, 1.0], the parameter represents a proportion\n of documents, integer absolute counts.\n This parameter is ignored if vocabulary is not None.\n\n max_features : int, default=None\n If not None, build a vocabulary that only consider the top\n max_features ordered by term frequency across the corpus.\n\n This parameter is ignored if vocabulary is not None.\n\n vocabulary : Mapping or iterable, default=None\n Either a Mapping (e.g., a dict) where keys are terms and values are\n indices in the feature matrix, or an iterable over terms. If not\n given, a vocabulary is determined from the input documents.\n\n binary : bool, default=False\n If True, all non-zero term counts are set to 1. This does not mean\n outputs will have only 0/1 values, only that the tf term in tf-idf\n is binary. (Set idf and normalization to False to get 0/1 outputs).\n\n dtype : dtype, default=float64\n Type of the matrix returned by fit_transform() or transform().\n\n norm : {'l1', 'l2'}, default='l2'\n Each output row will have unit norm, either:\n\n - 'l2': Sum of squares of vector elements is 1. The cosine\n similarity between two vectors is their dot product when l2 norm has\n been applied.\n - 'l1': Sum of absolute values of vector elements is 1.\n See :func:`preprocessing.normalize`.\n\n use_idf : bool, default=True\n Enable inverse-document-frequency reweighting. If False, idf(t) = 1.\n\n smooth_idf : bool, default=True\n Smooth idf weights by adding one to document frequencies, as if an\n extra document was seen containing every term in the collection\n exactly once. Prevents zero divisions.\n\n sublinear_tf : bool, default=False\n Apply sublinear tf scaling, i.e. replace tf with 1 + log(tf).\n\n Attributes\n ----------\n vocabulary_ : dict\n A mapping of terms to feature indices.\n\n fixed_vocabulary_ : bool\n True if a fixed vocabulary of term to indices mapping\n is provided by the user.\n\n idf_ : array of shape (n_features,)\n The inverse document frequency (IDF) vector; only defined\n if ``use_idf`` is True.\n\n stop_words_ : set\n Terms that were ignored because they either:\n\n - occurred in too many documents (`max_df`)\n - occurred in too few documents (`min_df`)\n - were cut off by feature selection (`max_features`).\n\n This is only available if no vocabulary was given.\n\n See Also\n --------\n CountVectorizer : Transforms text into a sparse matrix of n-gram counts.\n\n TfidfTransformer : Performs the TF-IDF transformation from a provided\n matrix of counts.\n\n Notes\n -----\n The ``stop_words_`` attribute can get large and increase the model size\n when pickling. This attribute is provided only for introspection and can\n be safely removed using delattr or set to None before pickling.\n\n Examples\n --------\n >>> from sklearn.feature_extraction.text import TfidfVectorizer\n >>> corpus = [\n ... 'This is the first document.',\n ... 'This document is the second document.',\n ... 'And this is the third one.',\n ... 'Is this the first document?',\n ... ]\n >>> vectorizer = TfidfVectorizer()\n >>> X = vectorizer.fit_transform(corpus)\n >>> vectorizer.get_feature_names_out()\n array(['and', 'document', 'first', 'is', 'one', 'second', 'the', 'third',\n 'this'], ...)\n >>> print(X.shape)\n (4, 9)\n \"\"\"\n \n def __init__(self, *, input='content', encoding='utf-8', decode_error='strict', strip_accents=None, lowercase=True, preprocessor=None, tokenizer=None, analyzer='word', stop_words=None, token_pattern='(?u)\\\\b\\\\w\\\\w+\\\\b', ngram_range=(1, 1), max_df=1.0, min_df=1, max_features=None, vocabulary=None, binary=False, dtype=np.float64, norm='l2', use_idf=True, smooth_idf=True, sublinear_tf=False):\n super().__init__(input=input, encoding=encoding, decode_error=decode_error, strip_accents=strip_accents, lowercase=lowercase, preprocessor=preprocessor, tokenizer=tokenizer, analyzer=analyzer, stop_words=stop_words, token_pattern=token_pattern, ngram_range=ngram_range, max_df=max_df, min_df=min_df, max_features=max_features, vocabulary=vocabulary, binary=binary, dtype=dtype)\n self._tfidf = TfidfTransformer(norm=norm, use_idf=use_idf, smooth_idf=smooth_idf, sublinear_tf=sublinear_tf)\n \n @property\n def norm(self):\n \"\"\"Norm of each row output, can be either \"l1\" or \"l2\".\"\"\"\n return self._tfidf.norm\n \n @norm.setter\n def norm(self, value):\n self._tfidf.norm = value\n \n @property\n def use_idf(self):\n \"\"\"Whether or not IDF re-weighting is used.\"\"\"\n return self._tfidf.use_idf\n \n @use_idf.setter\n def use_idf(self, value):\n self._tfidf.use_idf = value\n \n @property\n def smooth_idf(self):\n \"\"\"Whether or not IDF weights are smoothed.\"\"\"\n return self._tfidf.smooth_idf\n \n @smooth_idf.setter\n def smooth_idf(self, value):\n self._tfidf.smooth_idf = value\n \n @property\n def sublinear_tf(self):\n \"\"\"Whether or not sublinear TF scaling is applied.\"\"\"\n return self._tfidf.sublinear_tf\n \n @sublinear_tf.setter\n def sublinear_tf(self, value):\n self._tfidf.sublinear_tf = value\n \n @property\n def idf_(self):\n \"\"\"Inverse document frequency vector, only defined if `use_idf=True`.\n\n Returns\n -------\n ndarray of shape (n_features,)\n \"\"\"\n return self._tfidf.idf_\n \n @idf_.setter\n def idf_(self, value):\n self._validate_vocabulary()\n if hasattr(self, 'vocabulary_'):\n if len(self.vocabulary_) != len(value):\n raise ValueError('idf length = %d must be equal to vocabulary size = %d' % (len(value), len(self.vocabulary)))\n self._tfidf.idf_ = value\n \n def _check_params(self):\n if self.dtype not in FLOAT_DTYPES:\n warnings.warn(\"Only {} 'dtype' should be used. {} 'dtype' will be converted to np.float64.\".format(FLOAT_DTYPES, self.dtype), UserWarning)\n \n def fit(self, raw_documents, y=None):\n \"\"\"Learn vocabulary and idf from training set.\n\n Parameters\n ----------\n raw_documents : iterable\n An iterable which generates either str, unicode or file objects.\n\n y : None\n This parameter is not needed to compute tfidf.\n\n Returns\n -------\n self : object\n Fitted vectorizer.\n \"\"\"\n self._check_params()\n self._warn_for_unused_params()\n X = super().fit_transform(raw_documents)\n self._tfidf.fit(X)\n return self\n \n def fit_transform(self, raw_documents, y=None):\n \"\"\"Learn vocabulary and idf, return document-term matrix.\n\n This is equivalent to fit followed by transform, but more efficiently\n implemented.\n\n Parameters\n ----------\n raw_documents : iterable\n An iterable which generates either str, unicode or file objects.\n\n y : None\n This parameter is ignored.\n\n Returns\n -------\n X : sparse matrix of (n_samples, n_features)\n Tf-idf-weighted document-term matrix.\n \"\"\"\n self._check_params()\n X = super().fit_transform(raw_documents)\n self._tfidf.fit(X)\n return self._tfidf.transform(X, copy=False)\n \n def transform(self, raw_documents):\n \"\"\"Transform documents to document-term matrix.\n\n Uses the vocabulary and document frequencies (df) learned by fit (or\n fit_transform).\n\n Parameters\n ----------\n raw_documents : iterable\n An iterable which generates either str, unicode or file objects.\n\n Returns\n -------\n X : sparse matrix of (n_samples, n_features)\n Tf-idf-weighted document-term matrix.\n \"\"\"\n check_is_fitted(self, msg='The TF-IDF vectorizer is not fitted')\n X = super().transform(raw_documents)\n return self._tfidf.transform(X, copy=False)\n \n def _more_tags(self):\n return {'X_types': ['string'], '_skip_test': True}\n" }, { "name": "_VectorizerMixin", @@ -22477,7 +22430,7 @@ "is_public": false, "description": "Provides common code for text vectorizers (tokenization logic).", "docstring": "Provides common code for text vectorizers (tokenization logic).", - "source_code": "\n\nclass _VectorizerMixin:\n \"\"\"Provides common code for text vectorizers (tokenization logic).\"\"\"\n _white_spaces = re.compile('\\\\s\\\\s+')\n \n def decode(self, doc):\n \"\"\"Decode the input into a string of unicode symbols.\n\n The decoding strategy depends on the vectorizer parameters.\n\n Parameters\n ----------\n doc : str\n The string to decode.\n\n Returns\n -------\n doc: str\n A string of unicode symbols.\n \"\"\"\n if self.input == 'filename':\n with open(doc, 'rb') as fh:\n doc = fh.read()\n elif self.input == 'file':\n doc = doc.read()\n if isinstance(doc, bytes):\n doc = doc.decode(self.encoding, self.decode_error)\n if doc is np.nan:\n raise ValueError('np.nan is an invalid document, expected byte or unicode string.')\n return doc\n \n def _word_ngrams(self, tokens, stop_words=None):\n \"\"\"Turn tokens into a sequence of n-grams after stop words filtering\"\"\"\n if stop_words is not None:\n tokens = [w for w in tokens if w not in stop_words]\n (min_n, max_n) = self.ngram_range\n if max_n != 1:\n original_tokens = tokens\n if min_n == 1:\n tokens = list(original_tokens)\n min_n += 1\n else:\n tokens = []\n n_original_tokens = len(original_tokens)\n tokens_append = tokens.append\n space_join = ' '.join\n for n in range(min_n, min(max_n + 1, n_original_tokens + 1)):\n for i in range(n_original_tokens - n + 1):\n tokens_append(space_join(original_tokens[i:i + n]))\n return tokens\n \n def _char_ngrams(self, text_document):\n \"\"\"Tokenize text_document into a sequence of character n-grams\"\"\"\n text_document = self._white_spaces.sub(' ', text_document)\n text_len = len(text_document)\n (min_n, max_n) = self.ngram_range\n if min_n == 1:\n ngrams = list(text_document)\n min_n += 1\n else:\n ngrams = []\n ngrams_append = ngrams.append\n for n in range(min_n, min(max_n + 1, text_len + 1)):\n for i in range(text_len - n + 1):\n ngrams_append(text_document[i:i + n])\n return ngrams\n \n def _char_wb_ngrams(self, text_document):\n \"\"\"Whitespace sensitive char-n-gram tokenization.\n\n Tokenize text_document into a sequence of character n-grams\n operating only inside word boundaries. n-grams at the edges\n of words are padded with space.\"\"\"\n text_document = self._white_spaces.sub(' ', text_document)\n (min_n, max_n) = self.ngram_range\n ngrams = []\n ngrams_append = ngrams.append\n for w in text_document.split():\n w = ' ' + w + ' '\n w_len = len(w)\n for n in range(min_n, max_n + 1):\n offset = 0\n ngrams_append(w[offset:offset + n])\n while offset + n < w_len:\n offset += 1\n ngrams_append(w[offset:offset + n])\n if offset == 0:\n break\n return ngrams\n \n def build_preprocessor(self):\n \"\"\"Return a function to preprocess the text before tokenization.\n\n Returns\n -------\n preprocessor: callable\n A function to preprocess the text before tokenization.\n \"\"\"\n if self.preprocessor is not None:\n return self.preprocessor\n if not self.strip_accents:\n strip_accents = None\n elif callable(self.strip_accents):\n strip_accents = self.strip_accents\n elif self.strip_accents == 'ascii':\n strip_accents = strip_accents_ascii\n elif self.strip_accents == 'unicode':\n strip_accents = strip_accents_unicode\n else:\n raise ValueError('Invalid value for \"strip_accents\": %s' % self.strip_accents)\n return partial(_preprocess, accent_function=strip_accents, lower=self.lowercase)\n \n def build_tokenizer(self):\n \"\"\"Return a function that splits a string into a sequence of tokens.\n\n Returns\n -------\n tokenizer: callable\n A function to split a string into a sequence of tokens.\n \"\"\"\n if self.tokenizer is not None:\n return self.tokenizer\n token_pattern = re.compile(self.token_pattern)\n if token_pattern.groups > 1:\n raise ValueError('More than 1 capturing group in token pattern. Only a single group should be captured.')\n return token_pattern.findall\n \n def get_stop_words(self):\n \"\"\"Build or fetch the effective stop words list.\n\n Returns\n -------\n stop_words: list or None\n A list of stop words.\n \"\"\"\n return _check_stop_list(self.stop_words)\n \n def _check_stop_words_consistency(self, stop_words, preprocess, tokenize):\n \"\"\"Check if stop words are consistent\n\n Returns\n -------\n is_consistent : True if stop words are consistent with the preprocessor\n and tokenizer, False if they are not, None if the check\n was previously performed, \"error\" if it could not be\n performed (e.g. because of the use of a custom\n preprocessor / tokenizer)\n \"\"\"\n if id(self.stop_words) == getattr(self, '_stop_words_id', None):\n return None\n try:\n inconsistent = set()\n for w in stop_words or ():\n tokens = list(tokenize(preprocess(w)))\n for token in tokens:\n if token not in stop_words:\n inconsistent.add(token)\n self._stop_words_id = id(self.stop_words)\n if inconsistent:\n warnings.warn('Your stop_words may be inconsistent with your preprocessing. Tokenizing the stop words generated tokens %r not in stop_words.' % sorted(inconsistent))\n return not inconsistent\n except Exception:\n self._stop_words_id = id(self.stop_words)\n return 'error'\n \n def build_analyzer(self):\n \"\"\"Return a callable to process input data.\n\n The callable handles that handles preprocessing, tokenization, and\n n-grams generation.\n\n Returns\n -------\n analyzer: callable\n A function to handle preprocessing, tokenization\n and n-grams generation.\n \"\"\"\n if callable(self.analyzer):\n return partial(_analyze, analyzer=self.analyzer, decoder=self.decode)\n preprocess = self.build_preprocessor()\n if self.analyzer == 'char':\n return partial(_analyze, ngrams=self._char_ngrams, preprocessor=preprocess, decoder=self.decode)\n elif self.analyzer == 'char_wb':\n return partial(_analyze, ngrams=self._char_wb_ngrams, preprocessor=preprocess, decoder=self.decode)\n elif self.analyzer == 'word':\n stop_words = self.get_stop_words()\n tokenize = self.build_tokenizer()\n self._check_stop_words_consistency(stop_words, preprocess, tokenize)\n return partial(_analyze, ngrams=self._word_ngrams, tokenizer=tokenize, preprocessor=preprocess, decoder=self.decode, stop_words=stop_words)\n else:\n raise ValueError('%s is not a valid tokenization scheme/analyzer' % self.analyzer)\n \n def _validate_vocabulary(self):\n vocabulary = self.vocabulary\n if vocabulary is not None:\n if isinstance(vocabulary, set):\n vocabulary = sorted(vocabulary)\n if not isinstance(vocabulary, Mapping):\n vocab = {}\n for (i, t) in enumerate(vocabulary):\n if vocab.setdefault(t, i) != i:\n msg = 'Duplicate term in vocabulary: %r' % t\n raise ValueError(msg)\n vocabulary = vocab\n else:\n indices = set(vocabulary.values())\n if len(indices) != len(vocabulary):\n raise ValueError('Vocabulary contains repeated indices.')\n for i in range(len(vocabulary)):\n if i not in indices:\n msg = \"Vocabulary of size %d doesn't contain index %d.\" % (len(vocabulary), i)\n raise ValueError(msg)\n if not vocabulary:\n raise ValueError('empty vocabulary passed to fit')\n self.fixed_vocabulary_ = True\n self.vocabulary_ = dict(vocabulary)\n else:\n self.fixed_vocabulary_ = False\n \n def _check_vocabulary(self):\n \"\"\"Check if vocabulary is empty or missing (not fitted)\"\"\"\n if not hasattr(self, 'vocabulary_'):\n self._validate_vocabulary()\n if not self.fixed_vocabulary_:\n raise NotFittedError('Vocabulary not fitted or provided')\n if len(self.vocabulary_) == 0:\n raise ValueError('Vocabulary is empty')\n \n def _validate_params(self):\n \"\"\"Check validity of ngram_range parameter\"\"\"\n (min_n, max_m) = self.ngram_range\n if min_n > max_m:\n raise ValueError('Invalid value for ngram_range=%s lower boundary larger than the upper boundary.' % str(self.ngram_range))\n \n def _warn_for_unused_params(self):\n if self.tokenizer is not None and self.token_pattern is not None:\n warnings.warn(\"The parameter 'token_pattern' will not be used since 'tokenizer' is not None'\")\n if self.preprocessor is not None and callable(self.analyzer):\n warnings.warn(\"The parameter 'preprocessor' will not be used since 'analyzer' is callable'\")\n if self.ngram_range != (1, 1) and self.ngram_range is not None and callable(self.analyzer):\n warnings.warn(\"The parameter 'ngram_range' will not be used since 'analyzer' is callable'\")\n if self.analyzer != 'word' or callable(self.analyzer):\n if self.stop_words is not None:\n warnings.warn(\"The parameter 'stop_words' will not be used since 'analyzer' != 'word'\")\n if self.token_pattern is not None and self.token_pattern != '(?u)\\\\b\\\\w\\\\w+\\\\b':\n warnings.warn(\"The parameter 'token_pattern' will not be used since 'analyzer' != 'word'\")\n if self.tokenizer is not None:\n warnings.warn(\"The parameter 'tokenizer' will not be used since 'analyzer' != 'word'\")\n" + "source_code": "\n\nclass _VectorizerMixin:\n \"\"\"Provides common code for text vectorizers (tokenization logic).\"\"\"\n _white_spaces = re.compile('\\\\s\\\\s+')\n \n def decode(self, doc):\n \"\"\"Decode the input into a string of unicode symbols.\n\n The decoding strategy depends on the vectorizer parameters.\n\n Parameters\n ----------\n doc : bytes or str\n The string to decode.\n\n Returns\n -------\n doc: str\n A string of unicode symbols.\n \"\"\"\n if self.input == 'filename':\n with open(doc, 'rb') as fh:\n doc = fh.read()\n elif self.input == 'file':\n doc = doc.read()\n if isinstance(doc, bytes):\n doc = doc.decode(self.encoding, self.decode_error)\n if doc is np.nan:\n raise ValueError('np.nan is an invalid document, expected byte or unicode string.')\n return doc\n \n def _word_ngrams(self, tokens, stop_words=None):\n \"\"\"Turn tokens into a sequence of n-grams after stop words filtering\"\"\"\n if stop_words is not None:\n tokens = [w for w in tokens if w not in stop_words]\n (min_n, max_n) = self.ngram_range\n if max_n != 1:\n original_tokens = tokens\n if min_n == 1:\n tokens = list(original_tokens)\n min_n += 1\n else:\n tokens = []\n n_original_tokens = len(original_tokens)\n tokens_append = tokens.append\n space_join = ' '.join\n for n in range(min_n, min(max_n + 1, n_original_tokens + 1)):\n for i in range(n_original_tokens - n + 1):\n tokens_append(space_join(original_tokens[i:i + n]))\n return tokens\n \n def _char_ngrams(self, text_document):\n \"\"\"Tokenize text_document into a sequence of character n-grams\"\"\"\n text_document = self._white_spaces.sub(' ', text_document)\n text_len = len(text_document)\n (min_n, max_n) = self.ngram_range\n if min_n == 1:\n ngrams = list(text_document)\n min_n += 1\n else:\n ngrams = []\n ngrams_append = ngrams.append\n for n in range(min_n, min(max_n + 1, text_len + 1)):\n for i in range(text_len - n + 1):\n ngrams_append(text_document[i:i + n])\n return ngrams\n \n def _char_wb_ngrams(self, text_document):\n \"\"\"Whitespace sensitive char-n-gram tokenization.\n\n Tokenize text_document into a sequence of character n-grams\n operating only inside word boundaries. n-grams at the edges\n of words are padded with space.\"\"\"\n text_document = self._white_spaces.sub(' ', text_document)\n (min_n, max_n) = self.ngram_range\n ngrams = []\n ngrams_append = ngrams.append\n for w in text_document.split():\n w = ' ' + w + ' '\n w_len = len(w)\n for n in range(min_n, max_n + 1):\n offset = 0\n ngrams_append(w[offset:offset + n])\n while offset + n < w_len:\n offset += 1\n ngrams_append(w[offset:offset + n])\n if offset == 0:\n break\n return ngrams\n \n def build_preprocessor(self):\n \"\"\"Return a function to preprocess the text before tokenization.\n\n Returns\n -------\n preprocessor: callable\n A function to preprocess the text before tokenization.\n \"\"\"\n if self.preprocessor is not None:\n return self.preprocessor\n if not self.strip_accents:\n strip_accents = None\n elif callable(self.strip_accents):\n strip_accents = self.strip_accents\n elif self.strip_accents == 'ascii':\n strip_accents = strip_accents_ascii\n elif self.strip_accents == 'unicode':\n strip_accents = strip_accents_unicode\n else:\n raise ValueError('Invalid value for \"strip_accents\": %s' % self.strip_accents)\n return partial(_preprocess, accent_function=strip_accents, lower=self.lowercase)\n \n def build_tokenizer(self):\n \"\"\"Return a function that splits a string into a sequence of tokens.\n\n Returns\n -------\n tokenizer: callable\n A function to split a string into a sequence of tokens.\n \"\"\"\n if self.tokenizer is not None:\n return self.tokenizer\n token_pattern = re.compile(self.token_pattern)\n if token_pattern.groups > 1:\n raise ValueError('More than 1 capturing group in token pattern. Only a single group should be captured.')\n return token_pattern.findall\n \n def get_stop_words(self):\n \"\"\"Build or fetch the effective stop words list.\n\n Returns\n -------\n stop_words: list or None\n A list of stop words.\n \"\"\"\n return _check_stop_list(self.stop_words)\n \n def _check_stop_words_consistency(self, stop_words, preprocess, tokenize):\n \"\"\"Check if stop words are consistent\n\n Returns\n -------\n is_consistent : True if stop words are consistent with the preprocessor\n and tokenizer, False if they are not, None if the check\n was previously performed, \"error\" if it could not be\n performed (e.g. because of the use of a custom\n preprocessor / tokenizer)\n \"\"\"\n if id(self.stop_words) == getattr(self, '_stop_words_id', None):\n return None\n try:\n inconsistent = set()\n for w in stop_words or ():\n tokens = list(tokenize(preprocess(w)))\n for token in tokens:\n if token not in stop_words:\n inconsistent.add(token)\n self._stop_words_id = id(self.stop_words)\n if inconsistent:\n warnings.warn('Your stop_words may be inconsistent with your preprocessing. Tokenizing the stop words generated tokens %r not in stop_words.' % sorted(inconsistent))\n return not inconsistent\n except Exception:\n self._stop_words_id = id(self.stop_words)\n return 'error'\n \n def build_analyzer(self):\n \"\"\"Return a callable to process input data.\n\n The callable handles that handles preprocessing, tokenization, and\n n-grams generation.\n\n Returns\n -------\n analyzer: callable\n A function to handle preprocessing, tokenization\n and n-grams generation.\n \"\"\"\n if callable(self.analyzer):\n return partial(_analyze, analyzer=self.analyzer, decoder=self.decode)\n preprocess = self.build_preprocessor()\n if self.analyzer == 'char':\n return partial(_analyze, ngrams=self._char_ngrams, preprocessor=preprocess, decoder=self.decode)\n elif self.analyzer == 'char_wb':\n return partial(_analyze, ngrams=self._char_wb_ngrams, preprocessor=preprocess, decoder=self.decode)\n elif self.analyzer == 'word':\n stop_words = self.get_stop_words()\n tokenize = self.build_tokenizer()\n self._check_stop_words_consistency(stop_words, preprocess, tokenize)\n return partial(_analyze, ngrams=self._word_ngrams, tokenizer=tokenize, preprocessor=preprocess, decoder=self.decode, stop_words=stop_words)\n else:\n raise ValueError('%s is not a valid tokenization scheme/analyzer' % self.analyzer)\n \n def _validate_vocabulary(self):\n vocabulary = self.vocabulary\n if vocabulary is not None:\n if isinstance(vocabulary, set):\n vocabulary = sorted(vocabulary)\n if not isinstance(vocabulary, Mapping):\n vocab = {}\n for (i, t) in enumerate(vocabulary):\n if vocab.setdefault(t, i) != i:\n msg = 'Duplicate term in vocabulary: %r' % t\n raise ValueError(msg)\n vocabulary = vocab\n else:\n indices = set(vocabulary.values())\n if len(indices) != len(vocabulary):\n raise ValueError('Vocabulary contains repeated indices.')\n for i in range(len(vocabulary)):\n if i not in indices:\n msg = \"Vocabulary of size %d doesn't contain index %d.\" % (len(vocabulary), i)\n raise ValueError(msg)\n if not vocabulary:\n raise ValueError('empty vocabulary passed to fit')\n self.fixed_vocabulary_ = True\n self.vocabulary_ = dict(vocabulary)\n else:\n self.fixed_vocabulary_ = False\n \n def _check_vocabulary(self):\n \"\"\"Check if vocabulary is empty or missing (not fitted)\"\"\"\n if not hasattr(self, 'vocabulary_'):\n self._validate_vocabulary()\n if not self.fixed_vocabulary_:\n raise NotFittedError('Vocabulary not fitted or provided')\n if len(self.vocabulary_) == 0:\n raise ValueError('Vocabulary is empty')\n \n def _validate_params(self):\n \"\"\"Check validity of ngram_range parameter\"\"\"\n (min_n, max_m) = self.ngram_range\n if min_n > max_m:\n raise ValueError('Invalid value for ngram_range=%s lower boundary larger than the upper boundary.' % str(self.ngram_range))\n \n def _warn_for_unused_params(self):\n if self.tokenizer is not None and self.token_pattern is not None:\n warnings.warn(\"The parameter 'token_pattern' will not be used since 'tokenizer' is not None'\")\n if self.preprocessor is not None and callable(self.analyzer):\n warnings.warn(\"The parameter 'preprocessor' will not be used since 'analyzer' is callable'\")\n if self.ngram_range != (1, 1) and self.ngram_range is not None and callable(self.analyzer):\n warnings.warn(\"The parameter 'ngram_range' will not be used since 'analyzer' is callable'\")\n if self.analyzer != 'word' or callable(self.analyzer):\n if self.stop_words is not None:\n warnings.warn(\"The parameter 'stop_words' will not be used since 'analyzer' != 'word'\")\n if self.token_pattern is not None and self.token_pattern != '(?u)\\\\b\\\\w\\\\w+\\\\b':\n warnings.warn(\"The parameter 'token_pattern' will not be used since 'analyzer' != 'word'\")\n if self.tokenizer is not None:\n warnings.warn(\"The parameter 'tokenizer' will not be used since 'analyzer' != 'word'\")\n" }, { "name": "SelectorMixin", @@ -22509,9 +22462,9 @@ "sklearn.feature_selection._from_model.SelectFromModel.__init__", "sklearn.feature_selection._from_model.SelectFromModel._get_support_mask", "sklearn.feature_selection._from_model.SelectFromModel.fit", - "sklearn.feature_selection._from_model.SelectFromModel.threshold_", + "sklearn.feature_selection._from_model.SelectFromModel.threshold_@getter", "sklearn.feature_selection._from_model.SelectFromModel.partial_fit", - "sklearn.feature_selection._from_model.SelectFromModel.n_features_in_", + "sklearn.feature_selection._from_model.SelectFromModel.n_features_in_@getter", "sklearn.feature_selection._from_model.SelectFromModel._more_tags" ], "is_public": true, @@ -22530,8 +22483,8 @@ ], "methods": [ "sklearn.feature_selection._rfe.RFE.__init__", - "sklearn.feature_selection._rfe.RFE._estimator_type", - "sklearn.feature_selection._rfe.RFE.classes_", + "sklearn.feature_selection._rfe.RFE._estimator_type@getter", + "sklearn.feature_selection._rfe.RFE.classes_@getter", "sklearn.feature_selection._rfe.RFE.fit", "sklearn.feature_selection._rfe.RFE._fit", "sklearn.feature_selection._rfe.RFE.predict", @@ -22555,7 +22508,7 @@ "methods": [ "sklearn.feature_selection._rfe.RFECV.__init__", "sklearn.feature_selection._rfe.RFECV.fit", - "sklearn.feature_selection._rfe.RFECV.grid_scores_" + "sklearn.feature_selection._rfe.RFECV.grid_scores_@getter" ], "is_public": true, "description": "Recursive feature elimination with cross-validation to select the number of features.\n\nSee glossary entry for :term:`cross-validation estimator`. Read more in the :ref:`User Guide `.", @@ -22700,8 +22653,8 @@ ], "is_public": true, "description": "Feature selector that removes all low-variance features.\n\nThis feature selection algorithm looks only at the features (X), not the desired outputs (y), and can thus be used for unsupervised learning. Read more in the :ref:`User Guide `.", - "docstring": "Feature selector that removes all low-variance features.\n\n This feature selection algorithm looks only at the features (X), not the\n desired outputs (y), and can thus be used for unsupervised learning.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n threshold : float, default=0\n Features with a training-set variance lower than this threshold will\n be removed. The default is to keep all features with non-zero variance,\n i.e. remove the features that have the same value in all samples.\n\n Attributes\n ----------\n variances_ : array, shape (n_features,)\n Variances of individual features.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n SelectFromModel: Meta-transformer for selecting features based on\n importance weights.\n SelectPercentile : Select features according to a percentile of the highest\n scores.\n SequentialFeatureSelector : Transformer that performs Sequential Feature\n Selection.\n\n Notes\n -----\n Allows NaN in the input.\n Raises ValueError if no feature in X meets the variance threshold.\n\n Examples\n --------\n The following dataset has integer features, two of which are the same\n in every sample. These are removed with the default setting for threshold::\n\n >>> X = [[0, 2, 0, 3], [0, 1, 4, 3], [0, 1, 1, 3]]\n >>> selector = VarianceThreshold()\n >>> selector.fit_transform(X)\n array([[2, 0],\n [1, 4],\n [1, 1]])\n ", - "source_code": "\n\nclass VarianceThreshold(SelectorMixin, BaseEstimator):\n \"\"\"Feature selector that removes all low-variance features.\n\n This feature selection algorithm looks only at the features (X), not the\n desired outputs (y), and can thus be used for unsupervised learning.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n threshold : float, default=0\n Features with a training-set variance lower than this threshold will\n be removed. The default is to keep all features with non-zero variance,\n i.e. remove the features that have the same value in all samples.\n\n Attributes\n ----------\n variances_ : array, shape (n_features,)\n Variances of individual features.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n SelectFromModel: Meta-transformer for selecting features based on\n importance weights.\n SelectPercentile : Select features according to a percentile of the highest\n scores.\n SequentialFeatureSelector : Transformer that performs Sequential Feature\n Selection.\n\n Notes\n -----\n Allows NaN in the input.\n Raises ValueError if no feature in X meets the variance threshold.\n\n Examples\n --------\n The following dataset has integer features, two of which are the same\n in every sample. These are removed with the default setting for threshold::\n\n >>> X = [[0, 2, 0, 3], [0, 1, 4, 3], [0, 1, 1, 3]]\n >>> selector = VarianceThreshold()\n >>> selector.fit_transform(X)\n array([[2, 0],\n [1, 4],\n [1, 1]])\n \"\"\"\n \n def __init__(self, threshold=0.0):\n self.threshold = threshold\n \n def fit(self, X, y=None):\n \"\"\"Learn empirical variances from X.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Data from which to compute variances, where `n_samples` is\n the number of samples and `n_features` is the number of features.\n\n y : any, default=None\n Ignored. This parameter exists only for compatibility with\n sklearn.pipeline.Pipeline.\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n X = self._validate_data(X, accept_sparse=('csr', 'csc'), dtype=np.float64, force_all_finite='allow-nan')\n if hasattr(X, 'toarray'):\n (_, self.variances_) = mean_variance_axis(X, axis=0)\n if self.threshold == 0:\n (mins, maxes) = min_max_axis(X, axis=0)\n peak_to_peaks = maxes - mins\n else:\n self.variances_ = np.nanvar(X, axis=0)\n if self.threshold == 0:\n peak_to_peaks = np.ptp(X, axis=0)\n if self.threshold == 0:\n compare_arr = np.array([self.variances_, peak_to_peaks])\n self.variances_ = np.nanmin(compare_arr, axis=0)\n elif self.threshold < 0.0:\n raise ValueError(f'Threshold must be non-negative. Got: {self.threshold}')\n if np.all(~np.isfinite(self.variances_) | (self.variances_ <= self.threshold)):\n msg = 'No feature in X meets the variance threshold {0:.5f}'\n if X.shape[0] == 1:\n msg += ' (X contains only one sample)'\n raise ValueError(msg.format(self.threshold))\n return self\n \n def _get_support_mask(self):\n check_is_fitted(self)\n return self.variances_ > self.threshold\n \n def _more_tags(self):\n return {'allow_nan': True}\n" + "docstring": "Feature selector that removes all low-variance features.\n\n This feature selection algorithm looks only at the features (X), not the\n desired outputs (y), and can thus be used for unsupervised learning.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n threshold : float, default=0\n Features with a training-set variance lower than this threshold will\n be removed. The default is to keep all features with non-zero variance,\n i.e. remove the features that have the same value in all samples.\n\n Attributes\n ----------\n variances_ : array, shape (n_features,)\n Variances of individual features.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n SelectFromModel: Meta-transformer for selecting features based on\n importance weights.\n SelectPercentile : Select features according to a percentile of the highest\n scores.\n SequentialFeatureSelector : Transformer that performs Sequential Feature\n Selection.\n\n Notes\n -----\n Allows NaN in the input.\n Raises ValueError if no feature in X meets the variance threshold.\n\n Examples\n --------\n The following dataset has integer features, two of which are the same\n in every sample. These are removed with the default setting for threshold::\n\n >>> from sklearn.feature_selection import VarianceThreshold\n >>> X = [[0, 2, 0, 3], [0, 1, 4, 3], [0, 1, 1, 3]]\n >>> selector = VarianceThreshold()\n >>> selector.fit_transform(X)\n array([[2, 0],\n [1, 4],\n [1, 1]])\n ", + "source_code": "\n\nclass VarianceThreshold(SelectorMixin, BaseEstimator):\n \"\"\"Feature selector that removes all low-variance features.\n\n This feature selection algorithm looks only at the features (X), not the\n desired outputs (y), and can thus be used for unsupervised learning.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n threshold : float, default=0\n Features with a training-set variance lower than this threshold will\n be removed. The default is to keep all features with non-zero variance,\n i.e. remove the features that have the same value in all samples.\n\n Attributes\n ----------\n variances_ : array, shape (n_features,)\n Variances of individual features.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n SelectFromModel: Meta-transformer for selecting features based on\n importance weights.\n SelectPercentile : Select features according to a percentile of the highest\n scores.\n SequentialFeatureSelector : Transformer that performs Sequential Feature\n Selection.\n\n Notes\n -----\n Allows NaN in the input.\n Raises ValueError if no feature in X meets the variance threshold.\n\n Examples\n --------\n The following dataset has integer features, two of which are the same\n in every sample. These are removed with the default setting for threshold::\n\n >>> from sklearn.feature_selection import VarianceThreshold\n >>> X = [[0, 2, 0, 3], [0, 1, 4, 3], [0, 1, 1, 3]]\n >>> selector = VarianceThreshold()\n >>> selector.fit_transform(X)\n array([[2, 0],\n [1, 4],\n [1, 1]])\n \"\"\"\n \n def __init__(self, threshold=0.0):\n self.threshold = threshold\n \n def fit(self, X, y=None):\n \"\"\"Learn empirical variances from X.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Data from which to compute variances, where `n_samples` is\n the number of samples and `n_features` is the number of features.\n\n y : any, default=None\n Ignored. This parameter exists only for compatibility with\n sklearn.pipeline.Pipeline.\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n X = self._validate_data(X, accept_sparse=('csr', 'csc'), dtype=np.float64, force_all_finite='allow-nan')\n if hasattr(X, 'toarray'):\n (_, self.variances_) = mean_variance_axis(X, axis=0)\n if self.threshold == 0:\n (mins, maxes) = min_max_axis(X, axis=0)\n peak_to_peaks = maxes - mins\n else:\n self.variances_ = np.nanvar(X, axis=0)\n if self.threshold == 0:\n peak_to_peaks = np.ptp(X, axis=0)\n if self.threshold == 0:\n compare_arr = np.array([self.variances_, peak_to_peaks])\n self.variances_ = np.nanmin(compare_arr, axis=0)\n elif self.threshold < 0.0:\n raise ValueError(f'Threshold must be non-negative. Got: {self.threshold}')\n if np.all(~np.isfinite(self.variances_) | (self.variances_ <= self.threshold)):\n msg = 'No feature in X meets the variance threshold {0:.5f}'\n if X.shape[0] == 1:\n msg += ' (X contains only one sample)'\n raise ValueError(msg.format(self.threshold))\n return self\n \n def _get_support_mask(self):\n check_is_fitted(self)\n return self.variances_ > self.threshold\n \n def _more_tags(self):\n return {'allow_nan': True}\n" }, { "name": "GaussianProcessClassifier", @@ -22713,13 +22666,13 @@ "sklearn.gaussian_process._gpc.GaussianProcessClassifier.fit", "sklearn.gaussian_process._gpc.GaussianProcessClassifier.predict", "sklearn.gaussian_process._gpc.GaussianProcessClassifier.predict_proba", - "sklearn.gaussian_process._gpc.GaussianProcessClassifier.kernel_", + "sklearn.gaussian_process._gpc.GaussianProcessClassifier.kernel_@getter", "sklearn.gaussian_process._gpc.GaussianProcessClassifier.log_marginal_likelihood" ], "is_public": true, - "description": "Gaussian process classification (GPC) based on Laplace approximation.\n\nThe implementation is based on Algorithm 3.1, 3.2, and 5.1 of Gaussian Processes for Machine Learning (GPML) by Rasmussen and Williams. Internally, the Laplace approximation is used for approximating the non-Gaussian posterior by a Gaussian. Currently, the implementation is restricted to using the logistic link function. For multi-class classification, several binary one-versus rest classifiers are fitted. Note that this class thus does not implement a true multi-class Laplace approximation. Read more in the :ref:`User Guide `.", - "docstring": "Gaussian process classification (GPC) based on Laplace approximation.\n\n The implementation is based on Algorithm 3.1, 3.2, and 5.1 of\n Gaussian Processes for Machine Learning (GPML) by Rasmussen and\n Williams.\n\n Internally, the Laplace approximation is used for approximating the\n non-Gaussian posterior by a Gaussian.\n\n Currently, the implementation is restricted to using the logistic link\n function. For multi-class classification, several binary one-versus rest\n classifiers are fitted. Note that this class thus does not implement\n a true multi-class Laplace approximation.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n kernel : kernel instance, default=None\n The kernel specifying the covariance function of the GP. If None is\n passed, the kernel \"1.0 * RBF(1.0)\" is used as default. Note that\n the kernel's hyperparameters are optimized during fitting.\n\n optimizer : 'fmin_l_bfgs_b' or callable, default='fmin_l_bfgs_b'\n Can either be one of the internally supported optimizers for optimizing\n the kernel's parameters, specified by a string, or an externally\n defined optimizer passed as a callable. If a callable is passed, it\n must have the signature::\n\n def optimizer(obj_func, initial_theta, bounds):\n # * 'obj_func' is the objective function to be maximized, which\n # takes the hyperparameters theta as parameter and an\n # optional flag eval_gradient, which determines if the\n # gradient is returned additionally to the function value\n # * 'initial_theta': the initial value for theta, which can be\n # used by local optimizers\n # * 'bounds': the bounds on the values of theta\n ....\n # Returned are the best found hyperparameters theta and\n # the corresponding value of the target function.\n return theta_opt, func_min\n\n Per default, the 'L-BFGS-B' algorithm from scipy.optimize.minimize\n is used. If None is passed, the kernel's parameters are kept fixed.\n Available internal optimizers are::\n\n 'fmin_l_bfgs_b'\n\n n_restarts_optimizer : int, default=0\n The number of restarts of the optimizer for finding the kernel's\n parameters which maximize the log-marginal likelihood. The first run\n of the optimizer is performed from the kernel's initial parameters,\n the remaining ones (if any) from thetas sampled log-uniform randomly\n from the space of allowed theta-values. If greater than 0, all bounds\n must be finite. Note that n_restarts_optimizer=0 implies that one\n run is performed.\n\n max_iter_predict : int, default=100\n The maximum number of iterations in Newton's method for approximating\n the posterior during predict. Smaller values will reduce computation\n time at the cost of worse results.\n\n warm_start : bool, default=False\n If warm-starts are enabled, the solution of the last Newton iteration\n on the Laplace approximation of the posterior mode is used as\n initialization for the next call of _posterior_mode(). This can speed\n up convergence when _posterior_mode is called several times on similar\n problems as in hyperparameter optimization. See :term:`the Glossary\n `.\n\n copy_X_train : bool, default=True\n If True, a persistent copy of the training data is stored in the\n object. Otherwise, just a reference to the training data is stored,\n which might cause predictions to change if the data is modified\n externally.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation used to initialize the centers.\n Pass an int for reproducible results across multiple function calls.\n See :term: `Glossary `.\n\n multi_class : {'one_vs_rest', 'one_vs_one'}, default='one_vs_rest'\n Specifies how multi-class classification problems are handled.\n Supported are 'one_vs_rest' and 'one_vs_one'. In 'one_vs_rest',\n one binary Gaussian process classifier is fitted for each class, which\n is trained to separate this class from the rest. In 'one_vs_one', one\n binary Gaussian process classifier is fitted for each pair of classes,\n which is trained to separate these two classes. The predictions of\n these binary predictors are combined into multi-class predictions.\n Note that 'one_vs_one' does not support predicting probability\n estimates.\n\n n_jobs : int, default=None\n The number of jobs to use for the computation: the specified\n multiclass problems are computed in parallel.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n Attributes\n ----------\n base_estimator_ : ``Estimator`` instance\n The estimator instance that defines the likelihood function\n using the observed data.\n\n kernel_ : kernel instance\n The kernel used for prediction. In case of binary classification,\n the structure of the kernel is the same as the one passed as parameter\n but with optimized hyperparameters. In case of multi-class\n classification, a CompoundKernel is returned which consists of the\n different kernels used in the one-versus-rest classifiers.\n\n log_marginal_likelihood_value_ : float\n The log-marginal-likelihood of ``self.kernel_.theta``\n\n classes_ : array-like of shape (n_classes,)\n Unique class labels.\n\n n_classes_ : int\n The number of classes in the training data\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n GaussianProcessRegressor : Gaussian process regression (GPR).\n\n Examples\n --------\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.gaussian_process import GaussianProcessClassifier\n >>> from sklearn.gaussian_process.kernels import RBF\n >>> X, y = load_iris(return_X_y=True)\n >>> kernel = 1.0 * RBF(1.0)\n >>> gpc = GaussianProcessClassifier(kernel=kernel,\n ... random_state=0).fit(X, y)\n >>> gpc.score(X, y)\n 0.9866...\n >>> gpc.predict_proba(X[:2,:])\n array([[0.83548752, 0.03228706, 0.13222543],\n [0.79064206, 0.06525643, 0.14410151]])\n\n .. versionadded:: 0.18\n ", - "source_code": "\n\nclass GaussianProcessClassifier(ClassifierMixin, BaseEstimator):\n \"\"\"Gaussian process classification (GPC) based on Laplace approximation.\n\n The implementation is based on Algorithm 3.1, 3.2, and 5.1 of\n Gaussian Processes for Machine Learning (GPML) by Rasmussen and\n Williams.\n\n Internally, the Laplace approximation is used for approximating the\n non-Gaussian posterior by a Gaussian.\n\n Currently, the implementation is restricted to using the logistic link\n function. For multi-class classification, several binary one-versus rest\n classifiers are fitted. Note that this class thus does not implement\n a true multi-class Laplace approximation.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n kernel : kernel instance, default=None\n The kernel specifying the covariance function of the GP. If None is\n passed, the kernel \"1.0 * RBF(1.0)\" is used as default. Note that\n the kernel's hyperparameters are optimized during fitting.\n\n optimizer : 'fmin_l_bfgs_b' or callable, default='fmin_l_bfgs_b'\n Can either be one of the internally supported optimizers for optimizing\n the kernel's parameters, specified by a string, or an externally\n defined optimizer passed as a callable. If a callable is passed, it\n must have the signature::\n\n def optimizer(obj_func, initial_theta, bounds):\n # * 'obj_func' is the objective function to be maximized, which\n # takes the hyperparameters theta as parameter and an\n # optional flag eval_gradient, which determines if the\n # gradient is returned additionally to the function value\n # * 'initial_theta': the initial value for theta, which can be\n # used by local optimizers\n # * 'bounds': the bounds on the values of theta\n ....\n # Returned are the best found hyperparameters theta and\n # the corresponding value of the target function.\n return theta_opt, func_min\n\n Per default, the 'L-BFGS-B' algorithm from scipy.optimize.minimize\n is used. If None is passed, the kernel's parameters are kept fixed.\n Available internal optimizers are::\n\n 'fmin_l_bfgs_b'\n\n n_restarts_optimizer : int, default=0\n The number of restarts of the optimizer for finding the kernel's\n parameters which maximize the log-marginal likelihood. The first run\n of the optimizer is performed from the kernel's initial parameters,\n the remaining ones (if any) from thetas sampled log-uniform randomly\n from the space of allowed theta-values. If greater than 0, all bounds\n must be finite. Note that n_restarts_optimizer=0 implies that one\n run is performed.\n\n max_iter_predict : int, default=100\n The maximum number of iterations in Newton's method for approximating\n the posterior during predict. Smaller values will reduce computation\n time at the cost of worse results.\n\n warm_start : bool, default=False\n If warm-starts are enabled, the solution of the last Newton iteration\n on the Laplace approximation of the posterior mode is used as\n initialization for the next call of _posterior_mode(). This can speed\n up convergence when _posterior_mode is called several times on similar\n problems as in hyperparameter optimization. See :term:`the Glossary\n `.\n\n copy_X_train : bool, default=True\n If True, a persistent copy of the training data is stored in the\n object. Otherwise, just a reference to the training data is stored,\n which might cause predictions to change if the data is modified\n externally.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation used to initialize the centers.\n Pass an int for reproducible results across multiple function calls.\n See :term: `Glossary `.\n\n multi_class : {'one_vs_rest', 'one_vs_one'}, default='one_vs_rest'\n Specifies how multi-class classification problems are handled.\n Supported are 'one_vs_rest' and 'one_vs_one'. In 'one_vs_rest',\n one binary Gaussian process classifier is fitted for each class, which\n is trained to separate this class from the rest. In 'one_vs_one', one\n binary Gaussian process classifier is fitted for each pair of classes,\n which is trained to separate these two classes. The predictions of\n these binary predictors are combined into multi-class predictions.\n Note that 'one_vs_one' does not support predicting probability\n estimates.\n\n n_jobs : int, default=None\n The number of jobs to use for the computation: the specified\n multiclass problems are computed in parallel.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n Attributes\n ----------\n base_estimator_ : ``Estimator`` instance\n The estimator instance that defines the likelihood function\n using the observed data.\n\n kernel_ : kernel instance\n The kernel used for prediction. In case of binary classification,\n the structure of the kernel is the same as the one passed as parameter\n but with optimized hyperparameters. In case of multi-class\n classification, a CompoundKernel is returned which consists of the\n different kernels used in the one-versus-rest classifiers.\n\n log_marginal_likelihood_value_ : float\n The log-marginal-likelihood of ``self.kernel_.theta``\n\n classes_ : array-like of shape (n_classes,)\n Unique class labels.\n\n n_classes_ : int\n The number of classes in the training data\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n GaussianProcessRegressor : Gaussian process regression (GPR).\n\n Examples\n --------\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.gaussian_process import GaussianProcessClassifier\n >>> from sklearn.gaussian_process.kernels import RBF\n >>> X, y = load_iris(return_X_y=True)\n >>> kernel = 1.0 * RBF(1.0)\n >>> gpc = GaussianProcessClassifier(kernel=kernel,\n ... random_state=0).fit(X, y)\n >>> gpc.score(X, y)\n 0.9866...\n >>> gpc.predict_proba(X[:2,:])\n array([[0.83548752, 0.03228706, 0.13222543],\n [0.79064206, 0.06525643, 0.14410151]])\n\n .. versionadded:: 0.18\n \"\"\"\n \n def __init__(self, kernel=None, *, optimizer='fmin_l_bfgs_b', n_restarts_optimizer=0, max_iter_predict=100, warm_start=False, copy_X_train=True, random_state=None, multi_class='one_vs_rest', n_jobs=None):\n self.kernel = kernel\n self.optimizer = optimizer\n self.n_restarts_optimizer = n_restarts_optimizer\n self.max_iter_predict = max_iter_predict\n self.warm_start = warm_start\n self.copy_X_train = copy_X_train\n self.random_state = random_state\n self.multi_class = multi_class\n self.n_jobs = n_jobs\n \n def fit(self, X, y):\n \"\"\"Fit Gaussian process classification model.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features) or list of object\n Feature vectors or other representations of training data.\n\n y : array-like of shape (n_samples,)\n Target values, must be binary.\n\n Returns\n -------\n self : object\n Returns an instance of self.\n \"\"\"\n if self.kernel is None or self.kernel.requires_vector_input:\n (X, y) = self._validate_data(X, y, multi_output=False, ensure_2d=True, dtype='numeric')\n else:\n (X, y) = self._validate_data(X, y, multi_output=False, ensure_2d=False, dtype=None)\n self.base_estimator_ = _BinaryGaussianProcessClassifierLaplace(kernel=self.kernel, optimizer=self.optimizer, n_restarts_optimizer=self.n_restarts_optimizer, max_iter_predict=self.max_iter_predict, warm_start=self.warm_start, copy_X_train=self.copy_X_train, random_state=self.random_state)\n self.classes_ = np.unique(y)\n self.n_classes_ = self.classes_.size\n if self.n_classes_ == 1:\n raise ValueError('GaussianProcessClassifier requires 2 or more distinct classes; got %d class (only class %s is present)' % (self.n_classes_, self.classes_[0]))\n if self.n_classes_ > 2:\n if self.multi_class == 'one_vs_rest':\n self.base_estimator_ = OneVsRestClassifier(self.base_estimator_, n_jobs=self.n_jobs)\n elif self.multi_class == 'one_vs_one':\n self.base_estimator_ = OneVsOneClassifier(self.base_estimator_, n_jobs=self.n_jobs)\n else:\n raise ValueError('Unknown multi-class mode %s' % self.multi_class)\n self.base_estimator_.fit(X, y)\n if self.n_classes_ > 2:\n self.log_marginal_likelihood_value_ = np.mean([estimator.log_marginal_likelihood() for estimator in self.base_estimator_.estimators_])\n else:\n self.log_marginal_likelihood_value_ = self.base_estimator_.log_marginal_likelihood()\n return self\n \n def predict(self, X):\n \"\"\"Perform classification on an array of test vectors X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features) or list of object\n Query points where the GP is evaluated for classification.\n\n Returns\n -------\n C : ndarray of shape (n_samples,)\n Predicted target values for X, values are from ``classes_``.\n \"\"\"\n check_is_fitted(self)\n if self.kernel is None or self.kernel.requires_vector_input:\n X = self._validate_data(X, ensure_2d=True, dtype='numeric', reset=False)\n else:\n X = self._validate_data(X, ensure_2d=False, dtype=None, reset=False)\n return self.base_estimator_.predict(X)\n \n def predict_proba(self, X):\n \"\"\"Return probability estimates for the test vector X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features) or list of object\n Query points where the GP is evaluated for classification.\n\n Returns\n -------\n C : array-like of shape (n_samples, n_classes)\n Returns the probability of the samples for each class in\n the model. The columns correspond to the classes in sorted\n order, as they appear in the attribute :term:`classes_`.\n \"\"\"\n check_is_fitted(self)\n if self.n_classes_ > 2 and self.multi_class == 'one_vs_one':\n raise ValueError('one_vs_one multi-class mode does not support predicting probability estimates. Use one_vs_rest mode instead.')\n if self.kernel is None or self.kernel.requires_vector_input:\n X = self._validate_data(X, ensure_2d=True, dtype='numeric', reset=False)\n else:\n X = self._validate_data(X, ensure_2d=False, dtype=None, reset=False)\n return self.base_estimator_.predict_proba(X)\n \n @property\n def kernel_(self):\n \"\"\"Return the kernel of the base estimator.\"\"\"\n if self.n_classes_ == 2:\n return self.base_estimator_.kernel_\n else:\n return CompoundKernel([estimator.kernel_ for estimator in self.base_estimator_.estimators_])\n \n def log_marginal_likelihood(self, theta=None, eval_gradient=False, clone_kernel=True):\n \"\"\"Return log-marginal likelihood of theta for training data.\n\n In the case of multi-class classification, the mean log-marginal\n likelihood of the one-versus-rest classifiers are returned.\n\n Parameters\n ----------\n theta : array-like of shape (n_kernel_params,), default=None\n Kernel hyperparameters for which the log-marginal likelihood is\n evaluated. In the case of multi-class classification, theta may\n be the hyperparameters of the compound kernel or of an individual\n kernel. In the latter case, all individual kernel get assigned the\n same theta values. If None, the precomputed log_marginal_likelihood\n of ``self.kernel_.theta`` is returned.\n\n eval_gradient : bool, default=False\n If True, the gradient of the log-marginal likelihood with respect\n to the kernel hyperparameters at position theta is returned\n additionally. Note that gradient computation is not supported\n for non-binary classification. If True, theta must not be None.\n\n clone_kernel : bool, default=True\n If True, the kernel attribute is copied. If False, the kernel\n attribute is modified, but may result in a performance improvement.\n\n Returns\n -------\n log_likelihood : float\n Log-marginal likelihood of theta for training data.\n\n log_likelihood_gradient : ndarray of shape (n_kernel_params,), optional\n Gradient of the log-marginal likelihood with respect to the kernel\n hyperparameters at position theta.\n Only returned when `eval_gradient` is True.\n \"\"\"\n check_is_fitted(self)\n if theta is None:\n if eval_gradient:\n raise ValueError('Gradient can only be evaluated for theta!=None')\n return self.log_marginal_likelihood_value_\n theta = np.asarray(theta)\n if self.n_classes_ == 2:\n return self.base_estimator_.log_marginal_likelihood(theta, eval_gradient, clone_kernel=clone_kernel)\n else:\n if eval_gradient:\n raise NotImplementedError('Gradient of log-marginal-likelihood not implemented for multi-class GPC.')\n estimators = self.base_estimator_.estimators_\n n_dims = estimators[0].kernel_.n_dims\n if theta.shape[0] == n_dims:\n return np.mean([estimator.log_marginal_likelihood(theta, clone_kernel=clone_kernel) for (i, estimator) in enumerate(estimators)])\n elif theta.shape[0] == n_dims * self.classes_.shape[0]:\n return np.mean([estimator.log_marginal_likelihood(theta[n_dims * i:n_dims * (i + 1)], clone_kernel=clone_kernel) for (i, estimator) in enumerate(estimators)])\n else:\n raise ValueError('Shape of theta must be either %d or %d. Obtained theta with shape %d.' % (n_dims, n_dims * self.classes_.shape[0], theta.shape[0]))\n" + "description": "Gaussian process classification (GPC) based on Laplace approximation.\n\nThe implementation is based on Algorithm 3.1, 3.2, and 5.1 of Gaussian Processes for Machine Learning (GPML) by Rasmussen and Williams. Internally, the Laplace approximation is used for approximating the non-Gaussian posterior by a Gaussian. Currently, the implementation is restricted to using the logistic link function. For multi-class classification, several binary one-versus rest classifiers are fitted. Note that this class thus does not implement a true multi-class Laplace approximation. Read more in the :ref:`User Guide `. .. versionadded:: 0.18", + "docstring": "Gaussian process classification (GPC) based on Laplace approximation.\n\n The implementation is based on Algorithm 3.1, 3.2, and 5.1 of\n Gaussian Processes for Machine Learning (GPML) by Rasmussen and\n Williams.\n\n Internally, the Laplace approximation is used for approximating the\n non-Gaussian posterior by a Gaussian.\n\n Currently, the implementation is restricted to using the logistic link\n function. For multi-class classification, several binary one-versus rest\n classifiers are fitted. Note that this class thus does not implement\n a true multi-class Laplace approximation.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.18\n\n Parameters\n ----------\n kernel : kernel instance, default=None\n The kernel specifying the covariance function of the GP. If None is\n passed, the kernel \"1.0 * RBF(1.0)\" is used as default. Note that\n the kernel's hyperparameters are optimized during fitting.\n\n optimizer : 'fmin_l_bfgs_b' or callable, default='fmin_l_bfgs_b'\n Can either be one of the internally supported optimizers for optimizing\n the kernel's parameters, specified by a string, or an externally\n defined optimizer passed as a callable. If a callable is passed, it\n must have the signature::\n\n def optimizer(obj_func, initial_theta, bounds):\n # * 'obj_func' is the objective function to be maximized, which\n # takes the hyperparameters theta as parameter and an\n # optional flag eval_gradient, which determines if the\n # gradient is returned additionally to the function value\n # * 'initial_theta': the initial value for theta, which can be\n # used by local optimizers\n # * 'bounds': the bounds on the values of theta\n ....\n # Returned are the best found hyperparameters theta and\n # the corresponding value of the target function.\n return theta_opt, func_min\n\n Per default, the 'L-BFGS-B' algorithm from scipy.optimize.minimize\n is used. If None is passed, the kernel's parameters are kept fixed.\n Available internal optimizers are::\n\n 'fmin_l_bfgs_b'\n\n n_restarts_optimizer : int, default=0\n The number of restarts of the optimizer for finding the kernel's\n parameters which maximize the log-marginal likelihood. The first run\n of the optimizer is performed from the kernel's initial parameters,\n the remaining ones (if any) from thetas sampled log-uniform randomly\n from the space of allowed theta-values. If greater than 0, all bounds\n must be finite. Note that n_restarts_optimizer=0 implies that one\n run is performed.\n\n max_iter_predict : int, default=100\n The maximum number of iterations in Newton's method for approximating\n the posterior during predict. Smaller values will reduce computation\n time at the cost of worse results.\n\n warm_start : bool, default=False\n If warm-starts are enabled, the solution of the last Newton iteration\n on the Laplace approximation of the posterior mode is used as\n initialization for the next call of _posterior_mode(). This can speed\n up convergence when _posterior_mode is called several times on similar\n problems as in hyperparameter optimization. See :term:`the Glossary\n `.\n\n copy_X_train : bool, default=True\n If True, a persistent copy of the training data is stored in the\n object. Otherwise, just a reference to the training data is stored,\n which might cause predictions to change if the data is modified\n externally.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation used to initialize the centers.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n multi_class : {'one_vs_rest', 'one_vs_one'}, default='one_vs_rest'\n Specifies how multi-class classification problems are handled.\n Supported are 'one_vs_rest' and 'one_vs_one'. In 'one_vs_rest',\n one binary Gaussian process classifier is fitted for each class, which\n is trained to separate this class from the rest. In 'one_vs_one', one\n binary Gaussian process classifier is fitted for each pair of classes,\n which is trained to separate these two classes. The predictions of\n these binary predictors are combined into multi-class predictions.\n Note that 'one_vs_one' does not support predicting probability\n estimates.\n\n n_jobs : int, default=None\n The number of jobs to use for the computation: the specified\n multiclass problems are computed in parallel.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n Attributes\n ----------\n base_estimator_ : ``Estimator`` instance\n The estimator instance that defines the likelihood function\n using the observed data.\n\n kernel_ : kernel instance\n The kernel used for prediction. In case of binary classification,\n the structure of the kernel is the same as the one passed as parameter\n but with optimized hyperparameters. In case of multi-class\n classification, a CompoundKernel is returned which consists of the\n different kernels used in the one-versus-rest classifiers.\n\n log_marginal_likelihood_value_ : float\n The log-marginal-likelihood of ``self.kernel_.theta``\n\n classes_ : array-like of shape (n_classes,)\n Unique class labels.\n\n n_classes_ : int\n The number of classes in the training data\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n GaussianProcessRegressor : Gaussian process regression (GPR).\n\n Examples\n --------\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.gaussian_process import GaussianProcessClassifier\n >>> from sklearn.gaussian_process.kernels import RBF\n >>> X, y = load_iris(return_X_y=True)\n >>> kernel = 1.0 * RBF(1.0)\n >>> gpc = GaussianProcessClassifier(kernel=kernel,\n ... random_state=0).fit(X, y)\n >>> gpc.score(X, y)\n 0.9866...\n >>> gpc.predict_proba(X[:2,:])\n array([[0.83548752, 0.03228706, 0.13222543],\n [0.79064206, 0.06525643, 0.14410151]])\n ", + "source_code": "\n\nclass GaussianProcessClassifier(ClassifierMixin, BaseEstimator):\n \"\"\"Gaussian process classification (GPC) based on Laplace approximation.\n\n The implementation is based on Algorithm 3.1, 3.2, and 5.1 of\n Gaussian Processes for Machine Learning (GPML) by Rasmussen and\n Williams.\n\n Internally, the Laplace approximation is used for approximating the\n non-Gaussian posterior by a Gaussian.\n\n Currently, the implementation is restricted to using the logistic link\n function. For multi-class classification, several binary one-versus rest\n classifiers are fitted. Note that this class thus does not implement\n a true multi-class Laplace approximation.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.18\n\n Parameters\n ----------\n kernel : kernel instance, default=None\n The kernel specifying the covariance function of the GP. If None is\n passed, the kernel \"1.0 * RBF(1.0)\" is used as default. Note that\n the kernel's hyperparameters are optimized during fitting.\n\n optimizer : 'fmin_l_bfgs_b' or callable, default='fmin_l_bfgs_b'\n Can either be one of the internally supported optimizers for optimizing\n the kernel's parameters, specified by a string, or an externally\n defined optimizer passed as a callable. If a callable is passed, it\n must have the signature::\n\n def optimizer(obj_func, initial_theta, bounds):\n # * 'obj_func' is the objective function to be maximized, which\n # takes the hyperparameters theta as parameter and an\n # optional flag eval_gradient, which determines if the\n # gradient is returned additionally to the function value\n # * 'initial_theta': the initial value for theta, which can be\n # used by local optimizers\n # * 'bounds': the bounds on the values of theta\n ....\n # Returned are the best found hyperparameters theta and\n # the corresponding value of the target function.\n return theta_opt, func_min\n\n Per default, the 'L-BFGS-B' algorithm from scipy.optimize.minimize\n is used. If None is passed, the kernel's parameters are kept fixed.\n Available internal optimizers are::\n\n 'fmin_l_bfgs_b'\n\n n_restarts_optimizer : int, default=0\n The number of restarts of the optimizer for finding the kernel's\n parameters which maximize the log-marginal likelihood. The first run\n of the optimizer is performed from the kernel's initial parameters,\n the remaining ones (if any) from thetas sampled log-uniform randomly\n from the space of allowed theta-values. If greater than 0, all bounds\n must be finite. Note that n_restarts_optimizer=0 implies that one\n run is performed.\n\n max_iter_predict : int, default=100\n The maximum number of iterations in Newton's method for approximating\n the posterior during predict. Smaller values will reduce computation\n time at the cost of worse results.\n\n warm_start : bool, default=False\n If warm-starts are enabled, the solution of the last Newton iteration\n on the Laplace approximation of the posterior mode is used as\n initialization for the next call of _posterior_mode(). This can speed\n up convergence when _posterior_mode is called several times on similar\n problems as in hyperparameter optimization. See :term:`the Glossary\n `.\n\n copy_X_train : bool, default=True\n If True, a persistent copy of the training data is stored in the\n object. Otherwise, just a reference to the training data is stored,\n which might cause predictions to change if the data is modified\n externally.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation used to initialize the centers.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n multi_class : {'one_vs_rest', 'one_vs_one'}, default='one_vs_rest'\n Specifies how multi-class classification problems are handled.\n Supported are 'one_vs_rest' and 'one_vs_one'. In 'one_vs_rest',\n one binary Gaussian process classifier is fitted for each class, which\n is trained to separate this class from the rest. In 'one_vs_one', one\n binary Gaussian process classifier is fitted for each pair of classes,\n which is trained to separate these two classes. The predictions of\n these binary predictors are combined into multi-class predictions.\n Note that 'one_vs_one' does not support predicting probability\n estimates.\n\n n_jobs : int, default=None\n The number of jobs to use for the computation: the specified\n multiclass problems are computed in parallel.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n Attributes\n ----------\n base_estimator_ : ``Estimator`` instance\n The estimator instance that defines the likelihood function\n using the observed data.\n\n kernel_ : kernel instance\n The kernel used for prediction. In case of binary classification,\n the structure of the kernel is the same as the one passed as parameter\n but with optimized hyperparameters. In case of multi-class\n classification, a CompoundKernel is returned which consists of the\n different kernels used in the one-versus-rest classifiers.\n\n log_marginal_likelihood_value_ : float\n The log-marginal-likelihood of ``self.kernel_.theta``\n\n classes_ : array-like of shape (n_classes,)\n Unique class labels.\n\n n_classes_ : int\n The number of classes in the training data\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n GaussianProcessRegressor : Gaussian process regression (GPR).\n\n Examples\n --------\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.gaussian_process import GaussianProcessClassifier\n >>> from sklearn.gaussian_process.kernels import RBF\n >>> X, y = load_iris(return_X_y=True)\n >>> kernel = 1.0 * RBF(1.0)\n >>> gpc = GaussianProcessClassifier(kernel=kernel,\n ... random_state=0).fit(X, y)\n >>> gpc.score(X, y)\n 0.9866...\n >>> gpc.predict_proba(X[:2,:])\n array([[0.83548752, 0.03228706, 0.13222543],\n [0.79064206, 0.06525643, 0.14410151]])\n \"\"\"\n \n def __init__(self, kernel=None, *, optimizer='fmin_l_bfgs_b', n_restarts_optimizer=0, max_iter_predict=100, warm_start=False, copy_X_train=True, random_state=None, multi_class='one_vs_rest', n_jobs=None):\n self.kernel = kernel\n self.optimizer = optimizer\n self.n_restarts_optimizer = n_restarts_optimizer\n self.max_iter_predict = max_iter_predict\n self.warm_start = warm_start\n self.copy_X_train = copy_X_train\n self.random_state = random_state\n self.multi_class = multi_class\n self.n_jobs = n_jobs\n \n def fit(self, X, y):\n \"\"\"Fit Gaussian process classification model.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features) or list of object\n Feature vectors or other representations of training data.\n\n y : array-like of shape (n_samples,)\n Target values, must be binary.\n\n Returns\n -------\n self : object\n Returns an instance of self.\n \"\"\"\n if self.kernel is None or self.kernel.requires_vector_input:\n (X, y) = self._validate_data(X, y, multi_output=False, ensure_2d=True, dtype='numeric')\n else:\n (X, y) = self._validate_data(X, y, multi_output=False, ensure_2d=False, dtype=None)\n self.base_estimator_ = _BinaryGaussianProcessClassifierLaplace(kernel=self.kernel, optimizer=self.optimizer, n_restarts_optimizer=self.n_restarts_optimizer, max_iter_predict=self.max_iter_predict, warm_start=self.warm_start, copy_X_train=self.copy_X_train, random_state=self.random_state)\n self.classes_ = np.unique(y)\n self.n_classes_ = self.classes_.size\n if self.n_classes_ == 1:\n raise ValueError('GaussianProcessClassifier requires 2 or more distinct classes; got %d class (only class %s is present)' % (self.n_classes_, self.classes_[0]))\n if self.n_classes_ > 2:\n if self.multi_class == 'one_vs_rest':\n self.base_estimator_ = OneVsRestClassifier(self.base_estimator_, n_jobs=self.n_jobs)\n elif self.multi_class == 'one_vs_one':\n self.base_estimator_ = OneVsOneClassifier(self.base_estimator_, n_jobs=self.n_jobs)\n else:\n raise ValueError('Unknown multi-class mode %s' % self.multi_class)\n self.base_estimator_.fit(X, y)\n if self.n_classes_ > 2:\n self.log_marginal_likelihood_value_ = np.mean([estimator.log_marginal_likelihood() for estimator in self.base_estimator_.estimators_])\n else:\n self.log_marginal_likelihood_value_ = self.base_estimator_.log_marginal_likelihood()\n return self\n \n def predict(self, X):\n \"\"\"Perform classification on an array of test vectors X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features) or list of object\n Query points where the GP is evaluated for classification.\n\n Returns\n -------\n C : ndarray of shape (n_samples,)\n Predicted target values for X, values are from ``classes_``.\n \"\"\"\n check_is_fitted(self)\n if self.kernel is None or self.kernel.requires_vector_input:\n X = self._validate_data(X, ensure_2d=True, dtype='numeric', reset=False)\n else:\n X = self._validate_data(X, ensure_2d=False, dtype=None, reset=False)\n return self.base_estimator_.predict(X)\n \n def predict_proba(self, X):\n \"\"\"Return probability estimates for the test vector X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features) or list of object\n Query points where the GP is evaluated for classification.\n\n Returns\n -------\n C : array-like of shape (n_samples, n_classes)\n Returns the probability of the samples for each class in\n the model. The columns correspond to the classes in sorted\n order, as they appear in the attribute :term:`classes_`.\n \"\"\"\n check_is_fitted(self)\n if self.n_classes_ > 2 and self.multi_class == 'one_vs_one':\n raise ValueError('one_vs_one multi-class mode does not support predicting probability estimates. Use one_vs_rest mode instead.')\n if self.kernel is None or self.kernel.requires_vector_input:\n X = self._validate_data(X, ensure_2d=True, dtype='numeric', reset=False)\n else:\n X = self._validate_data(X, ensure_2d=False, dtype=None, reset=False)\n return self.base_estimator_.predict_proba(X)\n \n @property\n def kernel_(self):\n \"\"\"Return the kernel of the base estimator.\"\"\"\n if self.n_classes_ == 2:\n return self.base_estimator_.kernel_\n else:\n return CompoundKernel([estimator.kernel_ for estimator in self.base_estimator_.estimators_])\n \n def log_marginal_likelihood(self, theta=None, eval_gradient=False, clone_kernel=True):\n \"\"\"Return log-marginal likelihood of theta for training data.\n\n In the case of multi-class classification, the mean log-marginal\n likelihood of the one-versus-rest classifiers are returned.\n\n Parameters\n ----------\n theta : array-like of shape (n_kernel_params,), default=None\n Kernel hyperparameters for which the log-marginal likelihood is\n evaluated. In the case of multi-class classification, theta may\n be the hyperparameters of the compound kernel or of an individual\n kernel. In the latter case, all individual kernel get assigned the\n same theta values. If None, the precomputed log_marginal_likelihood\n of ``self.kernel_.theta`` is returned.\n\n eval_gradient : bool, default=False\n If True, the gradient of the log-marginal likelihood with respect\n to the kernel hyperparameters at position theta is returned\n additionally. Note that gradient computation is not supported\n for non-binary classification. If True, theta must not be None.\n\n clone_kernel : bool, default=True\n If True, the kernel attribute is copied. If False, the kernel\n attribute is modified, but may result in a performance improvement.\n\n Returns\n -------\n log_likelihood : float\n Log-marginal likelihood of theta for training data.\n\n log_likelihood_gradient : ndarray of shape (n_kernel_params,), optional\n Gradient of the log-marginal likelihood with respect to the kernel\n hyperparameters at position theta.\n Only returned when `eval_gradient` is True.\n \"\"\"\n check_is_fitted(self)\n if theta is None:\n if eval_gradient:\n raise ValueError('Gradient can only be evaluated for theta!=None')\n return self.log_marginal_likelihood_value_\n theta = np.asarray(theta)\n if self.n_classes_ == 2:\n return self.base_estimator_.log_marginal_likelihood(theta, eval_gradient, clone_kernel=clone_kernel)\n else:\n if eval_gradient:\n raise NotImplementedError('Gradient of log-marginal-likelihood not implemented for multi-class GPC.')\n estimators = self.base_estimator_.estimators_\n n_dims = estimators[0].kernel_.n_dims\n if theta.shape[0] == n_dims:\n return np.mean([estimator.log_marginal_likelihood(theta, clone_kernel=clone_kernel) for (i, estimator) in enumerate(estimators)])\n elif theta.shape[0] == n_dims * self.classes_.shape[0]:\n return np.mean([estimator.log_marginal_likelihood(theta[n_dims * i:n_dims * (i + 1)], clone_kernel=clone_kernel) for (i, estimator) in enumerate(estimators)])\n else:\n raise ValueError('Shape of theta must be either %d or %d. Obtained theta with shape %d.' % (n_dims, n_dims * self.classes_.shape[0], theta.shape[0]))\n" }, { "name": "_BinaryGaussianProcessClassifierLaplace", @@ -22737,8 +22690,8 @@ ], "is_public": false, "description": "Binary Gaussian process classification based on Laplace approximation.\n\nThe implementation is based on Algorithm 3.1, 3.2, and 5.1 of ``Gaussian Processes for Machine Learning'' (GPML) by Rasmussen and Williams. Internally, the Laplace approximation is used for approximating the non-Gaussian posterior by a Gaussian. Currently, the implementation is restricted to using the logistic link function. .. versionadded:: 0.18", - "docstring": "Binary Gaussian process classification based on Laplace approximation.\n\n The implementation is based on Algorithm 3.1, 3.2, and 5.1 of\n ``Gaussian Processes for Machine Learning'' (GPML) by Rasmussen and\n Williams.\n\n Internally, the Laplace approximation is used for approximating the\n non-Gaussian posterior by a Gaussian.\n\n Currently, the implementation is restricted to using the logistic link\n function.\n\n .. versionadded:: 0.18\n\n Parameters\n ----------\n kernel : kernel instance, default=None\n The kernel specifying the covariance function of the GP. If None is\n passed, the kernel \"1.0 * RBF(1.0)\" is used as default. Note that\n the kernel's hyperparameters are optimized during fitting.\n\n optimizer : 'fmin_l_bfgs_b' or callable, default='fmin_l_bfgs_b'\n Can either be one of the internally supported optimizers for optimizing\n the kernel's parameters, specified by a string, or an externally\n defined optimizer passed as a callable. If a callable is passed, it\n must have the signature::\n\n def optimizer(obj_func, initial_theta, bounds):\n # * 'obj_func' is the objective function to be maximized, which\n # takes the hyperparameters theta as parameter and an\n # optional flag eval_gradient, which determines if the\n # gradient is returned additionally to the function value\n # * 'initial_theta': the initial value for theta, which can be\n # used by local optimizers\n # * 'bounds': the bounds on the values of theta\n ....\n # Returned are the best found hyperparameters theta and\n # the corresponding value of the target function.\n return theta_opt, func_min\n\n Per default, the 'L-BFGS-B' algorithm from scipy.optimize.minimize\n is used. If None is passed, the kernel's parameters are kept fixed.\n Available internal optimizers are::\n\n 'fmin_l_bfgs_b'\n\n n_restarts_optimizer : int, default=0\n The number of restarts of the optimizer for finding the kernel's\n parameters which maximize the log-marginal likelihood. The first run\n of the optimizer is performed from the kernel's initial parameters,\n the remaining ones (if any) from thetas sampled log-uniform randomly\n from the space of allowed theta-values. If greater than 0, all bounds\n must be finite. Note that n_restarts_optimizer=0 implies that one\n run is performed.\n\n max_iter_predict : int, default=100\n The maximum number of iterations in Newton's method for approximating\n the posterior during predict. Smaller values will reduce computation\n time at the cost of worse results.\n\n warm_start : bool, default=False\n If warm-starts are enabled, the solution of the last Newton iteration\n on the Laplace approximation of the posterior mode is used as\n initialization for the next call of _posterior_mode(). This can speed\n up convergence when _posterior_mode is called several times on similar\n problems as in hyperparameter optimization. See :term:`the Glossary\n `.\n\n copy_X_train : bool, default=True\n If True, a persistent copy of the training data is stored in the\n object. Otherwise, just a reference to the training data is stored,\n which might cause predictions to change if the data is modified\n externally.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation used to initialize the centers.\n Pass an int for reproducible results across multiple function calls.\n See :term: `Glossary `.\n\n Attributes\n ----------\n X_train_ : array-like of shape (n_samples, n_features) or list of object\n Feature vectors or other representations of training data (also\n required for prediction).\n\n y_train_ : array-like of shape (n_samples,)\n Target values in training data (also required for prediction)\n\n classes_ : array-like of shape (n_classes,)\n Unique class labels.\n\n kernel_ : kernl instance\n The kernel used for prediction. The structure of the kernel is the\n same as the one passed as parameter but with optimized hyperparameters\n\n L_ : array-like of shape (n_samples, n_samples)\n Lower-triangular Cholesky decomposition of the kernel in X_train_\n\n pi_ : array-like of shape (n_samples,)\n The probabilities of the positive class for the training points\n X_train_\n\n W_sr_ : array-like of shape (n_samples,)\n Square root of W, the Hessian of log-likelihood of the latent function\n values for the observed labels. Since W is diagonal, only the diagonal\n of sqrt(W) is stored.\n\n log_marginal_likelihood_value_ : float\n The log-marginal-likelihood of ``self.kernel_.theta``\n\n ", - "source_code": "\n\nclass _BinaryGaussianProcessClassifierLaplace(BaseEstimator):\n \"\"\"Binary Gaussian process classification based on Laplace approximation.\n\n The implementation is based on Algorithm 3.1, 3.2, and 5.1 of\n ``Gaussian Processes for Machine Learning'' (GPML) by Rasmussen and\n Williams.\n\n Internally, the Laplace approximation is used for approximating the\n non-Gaussian posterior by a Gaussian.\n\n Currently, the implementation is restricted to using the logistic link\n function.\n\n .. versionadded:: 0.18\n\n Parameters\n ----------\n kernel : kernel instance, default=None\n The kernel specifying the covariance function of the GP. If None is\n passed, the kernel \"1.0 * RBF(1.0)\" is used as default. Note that\n the kernel's hyperparameters are optimized during fitting.\n\n optimizer : 'fmin_l_bfgs_b' or callable, default='fmin_l_bfgs_b'\n Can either be one of the internally supported optimizers for optimizing\n the kernel's parameters, specified by a string, or an externally\n defined optimizer passed as a callable. If a callable is passed, it\n must have the signature::\n\n def optimizer(obj_func, initial_theta, bounds):\n # * 'obj_func' is the objective function to be maximized, which\n # takes the hyperparameters theta as parameter and an\n # optional flag eval_gradient, which determines if the\n # gradient is returned additionally to the function value\n # * 'initial_theta': the initial value for theta, which can be\n # used by local optimizers\n # * 'bounds': the bounds on the values of theta\n ....\n # Returned are the best found hyperparameters theta and\n # the corresponding value of the target function.\n return theta_opt, func_min\n\n Per default, the 'L-BFGS-B' algorithm from scipy.optimize.minimize\n is used. If None is passed, the kernel's parameters are kept fixed.\n Available internal optimizers are::\n\n 'fmin_l_bfgs_b'\n\n n_restarts_optimizer : int, default=0\n The number of restarts of the optimizer for finding the kernel's\n parameters which maximize the log-marginal likelihood. The first run\n of the optimizer is performed from the kernel's initial parameters,\n the remaining ones (if any) from thetas sampled log-uniform randomly\n from the space of allowed theta-values. If greater than 0, all bounds\n must be finite. Note that n_restarts_optimizer=0 implies that one\n run is performed.\n\n max_iter_predict : int, default=100\n The maximum number of iterations in Newton's method for approximating\n the posterior during predict. Smaller values will reduce computation\n time at the cost of worse results.\n\n warm_start : bool, default=False\n If warm-starts are enabled, the solution of the last Newton iteration\n on the Laplace approximation of the posterior mode is used as\n initialization for the next call of _posterior_mode(). This can speed\n up convergence when _posterior_mode is called several times on similar\n problems as in hyperparameter optimization. See :term:`the Glossary\n `.\n\n copy_X_train : bool, default=True\n If True, a persistent copy of the training data is stored in the\n object. Otherwise, just a reference to the training data is stored,\n which might cause predictions to change if the data is modified\n externally.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation used to initialize the centers.\n Pass an int for reproducible results across multiple function calls.\n See :term: `Glossary `.\n\n Attributes\n ----------\n X_train_ : array-like of shape (n_samples, n_features) or list of object\n Feature vectors or other representations of training data (also\n required for prediction).\n\n y_train_ : array-like of shape (n_samples,)\n Target values in training data (also required for prediction)\n\n classes_ : array-like of shape (n_classes,)\n Unique class labels.\n\n kernel_ : kernl instance\n The kernel used for prediction. The structure of the kernel is the\n same as the one passed as parameter but with optimized hyperparameters\n\n L_ : array-like of shape (n_samples, n_samples)\n Lower-triangular Cholesky decomposition of the kernel in X_train_\n\n pi_ : array-like of shape (n_samples,)\n The probabilities of the positive class for the training points\n X_train_\n\n W_sr_ : array-like of shape (n_samples,)\n Square root of W, the Hessian of log-likelihood of the latent function\n values for the observed labels. Since W is diagonal, only the diagonal\n of sqrt(W) is stored.\n\n log_marginal_likelihood_value_ : float\n The log-marginal-likelihood of ``self.kernel_.theta``\n\n \"\"\"\n \n def __init__(self, kernel=None, *, optimizer='fmin_l_bfgs_b', n_restarts_optimizer=0, max_iter_predict=100, warm_start=False, copy_X_train=True, random_state=None):\n self.kernel = kernel\n self.optimizer = optimizer\n self.n_restarts_optimizer = n_restarts_optimizer\n self.max_iter_predict = max_iter_predict\n self.warm_start = warm_start\n self.copy_X_train = copy_X_train\n self.random_state = random_state\n \n def fit(self, X, y):\n \"\"\"Fit Gaussian process classification model.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features) or list of object\n Feature vectors or other representations of training data.\n\n y : array-like of shape (n_samples,)\n Target values, must be binary.\n\n Returns\n -------\n self : returns an instance of self.\n \"\"\"\n if self.kernel is None:\n self.kernel_ = C(1.0, constant_value_bounds='fixed') * RBF(1.0, length_scale_bounds='fixed')\n else:\n self.kernel_ = clone(self.kernel)\n self.rng = check_random_state(self.random_state)\n self.X_train_ = np.copy(X) if self.copy_X_train else X\n label_encoder = LabelEncoder()\n self.y_train_ = label_encoder.fit_transform(y)\n self.classes_ = label_encoder.classes_\n if self.classes_.size > 2:\n raise ValueError('%s supports only binary classification. y contains classes %s' % (self.__class__.__name__, self.classes_))\n elif self.classes_.size == 1:\n raise ValueError('{0:s} requires 2 classes; got {1:d} class'.format(self.__class__.__name__, self.classes_.size))\n if self.optimizer is not None and self.kernel_.n_dims > 0:\n \n def obj_func(theta, eval_gradient=True):\n if eval_gradient:\n (lml, grad) = self.log_marginal_likelihood(theta, eval_gradient=True, clone_kernel=False)\n return -lml, -grad\n else:\n return -self.log_marginal_likelihood(theta, clone_kernel=False)\n optima = [self._constrained_optimization(obj_func, self.kernel_.theta, self.kernel_.bounds)]\n if self.n_restarts_optimizer > 0:\n if not np.isfinite(self.kernel_.bounds).all():\n raise ValueError('Multiple optimizer restarts (n_restarts_optimizer>0) requires that all bounds are finite.')\n bounds = self.kernel_.bounds\n for iteration in range(self.n_restarts_optimizer):\n theta_initial = np.exp(self.rng.uniform(bounds[:, 0], bounds[:, 1]))\n optima.append(self._constrained_optimization(obj_func, theta_initial, bounds))\n lml_values = list(map(itemgetter(1), optima))\n self.kernel_.theta = optima[np.argmin(lml_values)][0]\n self.kernel_._check_bounds_params()\n self.log_marginal_likelihood_value_ = -np.min(lml_values)\n else:\n self.log_marginal_likelihood_value_ = self.log_marginal_likelihood(self.kernel_.theta)\n K = self.kernel_(self.X_train_)\n (_, (self.pi_, self.W_sr_, self.L_, _, _)) = self._posterior_mode(K, return_temporaries=True)\n return self\n \n def predict(self, X):\n \"\"\"Perform classification on an array of test vectors X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features) or list of object\n Query points where the GP is evaluated for classification.\n\n Returns\n -------\n C : ndarray of shape (n_samples,)\n Predicted target values for X, values are from ``classes_``\n \"\"\"\n check_is_fitted(self)\n K_star = self.kernel_(self.X_train_, X)\n f_star = K_star.T.dot(self.y_train_ - self.pi_)\n return np.where(f_star > 0, self.classes_[1], self.classes_[0])\n \n def predict_proba(self, X):\n \"\"\"Return probability estimates for the test vector X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features) or list of object\n Query points where the GP is evaluated for classification.\n\n Returns\n -------\n C : array-like of shape (n_samples, n_classes)\n Returns the probability of the samples for each class in\n the model. The columns correspond to the classes in sorted\n order, as they appear in the attribute ``classes_``.\n \"\"\"\n check_is_fitted(self)\n K_star = self.kernel_(self.X_train_, X)\n f_star = K_star.T.dot(self.y_train_ - self.pi_)\n v = solve(self.L_, self.W_sr_[:, np.newaxis] * K_star)\n var_f_star = self.kernel_.diag(X) - np.einsum('ij,ij->j', v, v)\n alpha = 1 / (2 * var_f_star)\n gamma = LAMBDAS * f_star\n integrals = np.sqrt(np.pi / alpha) * erf(gamma * np.sqrt(alpha / (alpha + LAMBDAS**2))) / (2 * np.sqrt(var_f_star * 2 * np.pi))\n pi_star = (COEFS * integrals).sum(axis=0) + 0.5 * COEFS.sum()\n return np.vstack((1 - pi_star, pi_star)).T\n \n def log_marginal_likelihood(self, theta=None, eval_gradient=False, clone_kernel=True):\n \"\"\"Returns log-marginal likelihood of theta for training data.\n\n Parameters\n ----------\n theta : array-like of shape (n_kernel_params,), default=None\n Kernel hyperparameters for which the log-marginal likelihood is\n evaluated. If None, the precomputed log_marginal_likelihood\n of ``self.kernel_.theta`` is returned.\n\n eval_gradient : bool, default=False\n If True, the gradient of the log-marginal likelihood with respect\n to the kernel hyperparameters at position theta is returned\n additionally. If True, theta must not be None.\n\n clone_kernel : bool, default=True\n If True, the kernel attribute is copied. If False, the kernel\n attribute is modified, but may result in a performance improvement.\n\n Returns\n -------\n log_likelihood : float\n Log-marginal likelihood of theta for training data.\n\n log_likelihood_gradient : ndarray of shape (n_kernel_params,), optional\n Gradient of the log-marginal likelihood with respect to the kernel\n hyperparameters at position theta.\n Only returned when `eval_gradient` is True.\n \"\"\"\n if theta is None:\n if eval_gradient:\n raise ValueError('Gradient can only be evaluated for theta!=None')\n return self.log_marginal_likelihood_value_\n if clone_kernel:\n kernel = self.kernel_.clone_with_theta(theta)\n else:\n kernel = self.kernel_\n kernel.theta = theta\n if eval_gradient:\n (K, K_gradient) = kernel(self.X_train_, eval_gradient=True)\n else:\n K = kernel(self.X_train_)\n (Z, (pi, W_sr, L, b, a)) = self._posterior_mode(K, return_temporaries=True)\n if not eval_gradient:\n return Z\n d_Z = np.empty(theta.shape[0])\n R = W_sr[:, np.newaxis] * cho_solve((L, True), np.diag(W_sr))\n C = solve(L, W_sr[:, np.newaxis] * K)\n s_2 = -0.5 * (np.diag(K) - np.einsum('ij, ij -> j', C, C)) * (pi * (1 - pi) * (1 - 2 * pi))\n for j in range(d_Z.shape[0]):\n C = K_gradient[:, :, j]\n s_1 = 0.5 * a.T.dot(C).dot(a) - 0.5 * R.T.ravel().dot(C.ravel())\n b = C.dot(self.y_train_ - pi)\n s_3 = b - K.dot(R.dot(b))\n d_Z[j] = s_1 + s_2.T.dot(s_3)\n return Z, d_Z\n \n def _posterior_mode(self, K, return_temporaries=False):\n \"\"\"Mode-finding for binary Laplace GPC and fixed kernel.\n\n This approximates the posterior of the latent function values for given\n inputs and target observations with a Gaussian approximation and uses\n Newton's iteration to find the mode of this approximation.\n \"\"\"\n if self.warm_start and hasattr(self, 'f_cached') and self.f_cached.shape == self.y_train_.shape:\n f = self.f_cached\n else:\n f = np.zeros_like(self.y_train_, dtype=np.float64)\n log_marginal_likelihood = -np.inf\n for _ in range(self.max_iter_predict):\n pi = expit(f)\n W = pi * (1 - pi)\n W_sr = np.sqrt(W)\n W_sr_K = W_sr[:, np.newaxis] * K\n B = np.eye(W.shape[0]) + W_sr_K * W_sr\n L = cholesky(B, lower=True)\n b = W * f + (self.y_train_ - pi)\n a = b - W_sr * cho_solve((L, True), W_sr_K.dot(b))\n f = K.dot(a)\n lml = -0.5 * a.T.dot(f) - np.log1p(np.exp(-(self.y_train_ * 2 - 1) * f)).sum() - np.log(np.diag(L)).sum()\n if lml - log_marginal_likelihood < 1e-10:\n break\n log_marginal_likelihood = lml\n self.f_cached = f\n if return_temporaries:\n return log_marginal_likelihood, (pi, W_sr, L, b, a)\n else:\n return log_marginal_likelihood\n \n def _constrained_optimization(self, obj_func, initial_theta, bounds):\n if self.optimizer == 'fmin_l_bfgs_b':\n opt_res = scipy.optimize.minimize(obj_func, initial_theta, method='L-BFGS-B', jac=True, bounds=bounds)\n _check_optimize_result('lbfgs', opt_res)\n (theta_opt, func_min) = (opt_res.x, opt_res.fun)\n elif callable(self.optimizer):\n (theta_opt, func_min) = self.optimizer(obj_func, initial_theta, bounds=bounds)\n else:\n raise ValueError('Unknown optimizer %s.' % self.optimizer)\n return theta_opt, func_min\n" + "docstring": "Binary Gaussian process classification based on Laplace approximation.\n\n The implementation is based on Algorithm 3.1, 3.2, and 5.1 of\n ``Gaussian Processes for Machine Learning'' (GPML) by Rasmussen and\n Williams.\n\n Internally, the Laplace approximation is used for approximating the\n non-Gaussian posterior by a Gaussian.\n\n Currently, the implementation is restricted to using the logistic link\n function.\n\n .. versionadded:: 0.18\n\n Parameters\n ----------\n kernel : kernel instance, default=None\n The kernel specifying the covariance function of the GP. If None is\n passed, the kernel \"1.0 * RBF(1.0)\" is used as default. Note that\n the kernel's hyperparameters are optimized during fitting.\n\n optimizer : 'fmin_l_bfgs_b' or callable, default='fmin_l_bfgs_b'\n Can either be one of the internally supported optimizers for optimizing\n the kernel's parameters, specified by a string, or an externally\n defined optimizer passed as a callable. If a callable is passed, it\n must have the signature::\n\n def optimizer(obj_func, initial_theta, bounds):\n # * 'obj_func' is the objective function to be maximized, which\n # takes the hyperparameters theta as parameter and an\n # optional flag eval_gradient, which determines if the\n # gradient is returned additionally to the function value\n # * 'initial_theta': the initial value for theta, which can be\n # used by local optimizers\n # * 'bounds': the bounds on the values of theta\n ....\n # Returned are the best found hyperparameters theta and\n # the corresponding value of the target function.\n return theta_opt, func_min\n\n Per default, the 'L-BFGS-B' algorithm from scipy.optimize.minimize\n is used. If None is passed, the kernel's parameters are kept fixed.\n Available internal optimizers are::\n\n 'fmin_l_bfgs_b'\n\n n_restarts_optimizer : int, default=0\n The number of restarts of the optimizer for finding the kernel's\n parameters which maximize the log-marginal likelihood. The first run\n of the optimizer is performed from the kernel's initial parameters,\n the remaining ones (if any) from thetas sampled log-uniform randomly\n from the space of allowed theta-values. If greater than 0, all bounds\n must be finite. Note that n_restarts_optimizer=0 implies that one\n run is performed.\n\n max_iter_predict : int, default=100\n The maximum number of iterations in Newton's method for approximating\n the posterior during predict. Smaller values will reduce computation\n time at the cost of worse results.\n\n warm_start : bool, default=False\n If warm-starts are enabled, the solution of the last Newton iteration\n on the Laplace approximation of the posterior mode is used as\n initialization for the next call of _posterior_mode(). This can speed\n up convergence when _posterior_mode is called several times on similar\n problems as in hyperparameter optimization. See :term:`the Glossary\n `.\n\n copy_X_train : bool, default=True\n If True, a persistent copy of the training data is stored in the\n object. Otherwise, just a reference to the training data is stored,\n which might cause predictions to change if the data is modified\n externally.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation used to initialize the centers.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n Attributes\n ----------\n X_train_ : array-like of shape (n_samples, n_features) or list of object\n Feature vectors or other representations of training data (also\n required for prediction).\n\n y_train_ : array-like of shape (n_samples,)\n Target values in training data (also required for prediction)\n\n classes_ : array-like of shape (n_classes,)\n Unique class labels.\n\n kernel_ : kernl instance\n The kernel used for prediction. The structure of the kernel is the\n same as the one passed as parameter but with optimized hyperparameters\n\n L_ : array-like of shape (n_samples, n_samples)\n Lower-triangular Cholesky decomposition of the kernel in X_train_\n\n pi_ : array-like of shape (n_samples,)\n The probabilities of the positive class for the training points\n X_train_\n\n W_sr_ : array-like of shape (n_samples,)\n Square root of W, the Hessian of log-likelihood of the latent function\n values for the observed labels. Since W is diagonal, only the diagonal\n of sqrt(W) is stored.\n\n log_marginal_likelihood_value_ : float\n The log-marginal-likelihood of ``self.kernel_.theta``\n\n ", + "source_code": "\n\nclass _BinaryGaussianProcessClassifierLaplace(BaseEstimator):\n \"\"\"Binary Gaussian process classification based on Laplace approximation.\n\n The implementation is based on Algorithm 3.1, 3.2, and 5.1 of\n ``Gaussian Processes for Machine Learning'' (GPML) by Rasmussen and\n Williams.\n\n Internally, the Laplace approximation is used for approximating the\n non-Gaussian posterior by a Gaussian.\n\n Currently, the implementation is restricted to using the logistic link\n function.\n\n .. versionadded:: 0.18\n\n Parameters\n ----------\n kernel : kernel instance, default=None\n The kernel specifying the covariance function of the GP. If None is\n passed, the kernel \"1.0 * RBF(1.0)\" is used as default. Note that\n the kernel's hyperparameters are optimized during fitting.\n\n optimizer : 'fmin_l_bfgs_b' or callable, default='fmin_l_bfgs_b'\n Can either be one of the internally supported optimizers for optimizing\n the kernel's parameters, specified by a string, or an externally\n defined optimizer passed as a callable. If a callable is passed, it\n must have the signature::\n\n def optimizer(obj_func, initial_theta, bounds):\n # * 'obj_func' is the objective function to be maximized, which\n # takes the hyperparameters theta as parameter and an\n # optional flag eval_gradient, which determines if the\n # gradient is returned additionally to the function value\n # * 'initial_theta': the initial value for theta, which can be\n # used by local optimizers\n # * 'bounds': the bounds on the values of theta\n ....\n # Returned are the best found hyperparameters theta and\n # the corresponding value of the target function.\n return theta_opt, func_min\n\n Per default, the 'L-BFGS-B' algorithm from scipy.optimize.minimize\n is used. If None is passed, the kernel's parameters are kept fixed.\n Available internal optimizers are::\n\n 'fmin_l_bfgs_b'\n\n n_restarts_optimizer : int, default=0\n The number of restarts of the optimizer for finding the kernel's\n parameters which maximize the log-marginal likelihood. The first run\n of the optimizer is performed from the kernel's initial parameters,\n the remaining ones (if any) from thetas sampled log-uniform randomly\n from the space of allowed theta-values. If greater than 0, all bounds\n must be finite. Note that n_restarts_optimizer=0 implies that one\n run is performed.\n\n max_iter_predict : int, default=100\n The maximum number of iterations in Newton's method for approximating\n the posterior during predict. Smaller values will reduce computation\n time at the cost of worse results.\n\n warm_start : bool, default=False\n If warm-starts are enabled, the solution of the last Newton iteration\n on the Laplace approximation of the posterior mode is used as\n initialization for the next call of _posterior_mode(). This can speed\n up convergence when _posterior_mode is called several times on similar\n problems as in hyperparameter optimization. See :term:`the Glossary\n `.\n\n copy_X_train : bool, default=True\n If True, a persistent copy of the training data is stored in the\n object. Otherwise, just a reference to the training data is stored,\n which might cause predictions to change if the data is modified\n externally.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation used to initialize the centers.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n Attributes\n ----------\n X_train_ : array-like of shape (n_samples, n_features) or list of object\n Feature vectors or other representations of training data (also\n required for prediction).\n\n y_train_ : array-like of shape (n_samples,)\n Target values in training data (also required for prediction)\n\n classes_ : array-like of shape (n_classes,)\n Unique class labels.\n\n kernel_ : kernl instance\n The kernel used for prediction. The structure of the kernel is the\n same as the one passed as parameter but with optimized hyperparameters\n\n L_ : array-like of shape (n_samples, n_samples)\n Lower-triangular Cholesky decomposition of the kernel in X_train_\n\n pi_ : array-like of shape (n_samples,)\n The probabilities of the positive class for the training points\n X_train_\n\n W_sr_ : array-like of shape (n_samples,)\n Square root of W, the Hessian of log-likelihood of the latent function\n values for the observed labels. Since W is diagonal, only the diagonal\n of sqrt(W) is stored.\n\n log_marginal_likelihood_value_ : float\n The log-marginal-likelihood of ``self.kernel_.theta``\n\n \"\"\"\n \n def __init__(self, kernel=None, *, optimizer='fmin_l_bfgs_b', n_restarts_optimizer=0, max_iter_predict=100, warm_start=False, copy_X_train=True, random_state=None):\n self.kernel = kernel\n self.optimizer = optimizer\n self.n_restarts_optimizer = n_restarts_optimizer\n self.max_iter_predict = max_iter_predict\n self.warm_start = warm_start\n self.copy_X_train = copy_X_train\n self.random_state = random_state\n \n def fit(self, X, y):\n \"\"\"Fit Gaussian process classification model.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features) or list of object\n Feature vectors or other representations of training data.\n\n y : array-like of shape (n_samples,)\n Target values, must be binary.\n\n Returns\n -------\n self : returns an instance of self.\n \"\"\"\n if self.kernel is None:\n self.kernel_ = C(1.0, constant_value_bounds='fixed') * RBF(1.0, length_scale_bounds='fixed')\n else:\n self.kernel_ = clone(self.kernel)\n self.rng = check_random_state(self.random_state)\n self.X_train_ = np.copy(X) if self.copy_X_train else X\n label_encoder = LabelEncoder()\n self.y_train_ = label_encoder.fit_transform(y)\n self.classes_ = label_encoder.classes_\n if self.classes_.size > 2:\n raise ValueError('%s supports only binary classification. y contains classes %s' % (self.__class__.__name__, self.classes_))\n elif self.classes_.size == 1:\n raise ValueError('{0:s} requires 2 classes; got {1:d} class'.format(self.__class__.__name__, self.classes_.size))\n if self.optimizer is not None and self.kernel_.n_dims > 0:\n \n def obj_func(theta, eval_gradient=True):\n if eval_gradient:\n (lml, grad) = self.log_marginal_likelihood(theta, eval_gradient=True, clone_kernel=False)\n return -lml, -grad\n else:\n return -self.log_marginal_likelihood(theta, clone_kernel=False)\n optima = [self._constrained_optimization(obj_func, self.kernel_.theta, self.kernel_.bounds)]\n if self.n_restarts_optimizer > 0:\n if not np.isfinite(self.kernel_.bounds).all():\n raise ValueError('Multiple optimizer restarts (n_restarts_optimizer>0) requires that all bounds are finite.')\n bounds = self.kernel_.bounds\n for iteration in range(self.n_restarts_optimizer):\n theta_initial = np.exp(self.rng.uniform(bounds[:, 0], bounds[:, 1]))\n optima.append(self._constrained_optimization(obj_func, theta_initial, bounds))\n lml_values = list(map(itemgetter(1), optima))\n self.kernel_.theta = optima[np.argmin(lml_values)][0]\n self.kernel_._check_bounds_params()\n self.log_marginal_likelihood_value_ = -np.min(lml_values)\n else:\n self.log_marginal_likelihood_value_ = self.log_marginal_likelihood(self.kernel_.theta)\n K = self.kernel_(self.X_train_)\n (_, (self.pi_, self.W_sr_, self.L_, _, _)) = self._posterior_mode(K, return_temporaries=True)\n return self\n \n def predict(self, X):\n \"\"\"Perform classification on an array of test vectors X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features) or list of object\n Query points where the GP is evaluated for classification.\n\n Returns\n -------\n C : ndarray of shape (n_samples,)\n Predicted target values for X, values are from ``classes_``\n \"\"\"\n check_is_fitted(self)\n K_star = self.kernel_(self.X_train_, X)\n f_star = K_star.T.dot(self.y_train_ - self.pi_)\n return np.where(f_star > 0, self.classes_[1], self.classes_[0])\n \n def predict_proba(self, X):\n \"\"\"Return probability estimates for the test vector X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features) or list of object\n Query points where the GP is evaluated for classification.\n\n Returns\n -------\n C : array-like of shape (n_samples, n_classes)\n Returns the probability of the samples for each class in\n the model. The columns correspond to the classes in sorted\n order, as they appear in the attribute ``classes_``.\n \"\"\"\n check_is_fitted(self)\n K_star = self.kernel_(self.X_train_, X)\n f_star = K_star.T.dot(self.y_train_ - self.pi_)\n v = solve(self.L_, self.W_sr_[:, np.newaxis] * K_star)\n var_f_star = self.kernel_.diag(X) - np.einsum('ij,ij->j', v, v)\n alpha = 1 / (2 * var_f_star)\n gamma = LAMBDAS * f_star\n integrals = np.sqrt(np.pi / alpha) * erf(gamma * np.sqrt(alpha / (alpha + LAMBDAS**2))) / (2 * np.sqrt(var_f_star * 2 * np.pi))\n pi_star = (COEFS * integrals).sum(axis=0) + 0.5 * COEFS.sum()\n return np.vstack((1 - pi_star, pi_star)).T\n \n def log_marginal_likelihood(self, theta=None, eval_gradient=False, clone_kernel=True):\n \"\"\"Returns log-marginal likelihood of theta for training data.\n\n Parameters\n ----------\n theta : array-like of shape (n_kernel_params,), default=None\n Kernel hyperparameters for which the log-marginal likelihood is\n evaluated. If None, the precomputed log_marginal_likelihood\n of ``self.kernel_.theta`` is returned.\n\n eval_gradient : bool, default=False\n If True, the gradient of the log-marginal likelihood with respect\n to the kernel hyperparameters at position theta is returned\n additionally. If True, theta must not be None.\n\n clone_kernel : bool, default=True\n If True, the kernel attribute is copied. If False, the kernel\n attribute is modified, but may result in a performance improvement.\n\n Returns\n -------\n log_likelihood : float\n Log-marginal likelihood of theta for training data.\n\n log_likelihood_gradient : ndarray of shape (n_kernel_params,), optional\n Gradient of the log-marginal likelihood with respect to the kernel\n hyperparameters at position theta.\n Only returned when `eval_gradient` is True.\n \"\"\"\n if theta is None:\n if eval_gradient:\n raise ValueError('Gradient can only be evaluated for theta!=None')\n return self.log_marginal_likelihood_value_\n if clone_kernel:\n kernel = self.kernel_.clone_with_theta(theta)\n else:\n kernel = self.kernel_\n kernel.theta = theta\n if eval_gradient:\n (K, K_gradient) = kernel(self.X_train_, eval_gradient=True)\n else:\n K = kernel(self.X_train_)\n (Z, (pi, W_sr, L, b, a)) = self._posterior_mode(K, return_temporaries=True)\n if not eval_gradient:\n return Z\n d_Z = np.empty(theta.shape[0])\n R = W_sr[:, np.newaxis] * cho_solve((L, True), np.diag(W_sr))\n C = solve(L, W_sr[:, np.newaxis] * K)\n s_2 = -0.5 * (np.diag(K) - np.einsum('ij, ij -> j', C, C)) * (pi * (1 - pi) * (1 - 2 * pi))\n for j in range(d_Z.shape[0]):\n C = K_gradient[:, :, j]\n s_1 = 0.5 * a.T.dot(C).dot(a) - 0.5 * R.T.ravel().dot(C.ravel())\n b = C.dot(self.y_train_ - pi)\n s_3 = b - K.dot(R.dot(b))\n d_Z[j] = s_1 + s_2.T.dot(s_3)\n return Z, d_Z\n \n def _posterior_mode(self, K, return_temporaries=False):\n \"\"\"Mode-finding for binary Laplace GPC and fixed kernel.\n\n This approximates the posterior of the latent function values for given\n inputs and target observations with a Gaussian approximation and uses\n Newton's iteration to find the mode of this approximation.\n \"\"\"\n if self.warm_start and hasattr(self, 'f_cached') and self.f_cached.shape == self.y_train_.shape:\n f = self.f_cached\n else:\n f = np.zeros_like(self.y_train_, dtype=np.float64)\n log_marginal_likelihood = -np.inf\n for _ in range(self.max_iter_predict):\n pi = expit(f)\n W = pi * (1 - pi)\n W_sr = np.sqrt(W)\n W_sr_K = W_sr[:, np.newaxis] * K\n B = np.eye(W.shape[0]) + W_sr_K * W_sr\n L = cholesky(B, lower=True)\n b = W * f + (self.y_train_ - pi)\n a = b - W_sr * cho_solve((L, True), W_sr_K.dot(b))\n f = K.dot(a)\n lml = -0.5 * a.T.dot(f) - np.log1p(np.exp(-(self.y_train_ * 2 - 1) * f)).sum() - np.log(np.diag(L)).sum()\n if lml - log_marginal_likelihood < 1e-10:\n break\n log_marginal_likelihood = lml\n self.f_cached = f\n if return_temporaries:\n return log_marginal_likelihood, (pi, W_sr, L, b, a)\n else:\n return log_marginal_likelihood\n \n def _constrained_optimization(self, obj_func, initial_theta, bounds):\n if self.optimizer == 'fmin_l_bfgs_b':\n opt_res = scipy.optimize.minimize(obj_func, initial_theta, method='L-BFGS-B', jac=True, bounds=bounds)\n _check_optimize_result('lbfgs', opt_res)\n (theta_opt, func_min) = (opt_res.x, opt_res.fun)\n elif callable(self.optimizer):\n (theta_opt, func_min) = self.optimizer(obj_func, initial_theta, bounds=bounds)\n else:\n raise ValueError('Unknown optimizer %s.' % self.optimizer)\n return theta_opt, func_min\n" }, { "name": "GaussianProcessRegressor", @@ -22761,7 +22714,7 @@ "is_public": true, "description": "Gaussian process regression (GPR).\n\nThe implementation is based on Algorithm 2.1 of [1]_. In addition to standard scikit-learn estimator API, :class:`GaussianProcessRegressor`: * allows prediction without prior fitting (based on the GP prior) * provides an additional method `sample_y(X)`, which evaluates samples drawn from the GPR (prior or posterior) at given inputs * exposes a method `log_marginal_likelihood(theta)`, which can be used externally for other ways of selecting hyperparameters, e.g., via Markov chain Monte Carlo. Read more in the :ref:`User Guide `. .. versionadded:: 0.18", "docstring": "Gaussian process regression (GPR).\n\n The implementation is based on Algorithm 2.1 of [1]_.\n\n In addition to standard scikit-learn estimator API,\n :class:`GaussianProcessRegressor`:\n\n * allows prediction without prior fitting (based on the GP prior)\n * provides an additional method `sample_y(X)`, which evaluates samples\n drawn from the GPR (prior or posterior) at given inputs\n * exposes a method `log_marginal_likelihood(theta)`, which can be used\n externally for other ways of selecting hyperparameters, e.g., via\n Markov chain Monte Carlo.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.18\n\n Parameters\n ----------\n kernel : kernel instance, default=None\n The kernel specifying the covariance function of the GP. If None is\n passed, the kernel ``ConstantKernel(1.0, constant_value_bounds=\"fixed\"\n * RBF(1.0, length_scale_bounds=\"fixed\")`` is used as default. Note that\n the kernel hyperparameters are optimized during fitting unless the\n bounds are marked as \"fixed\".\n\n alpha : float or ndarray of shape (n_samples,), default=1e-10\n Value added to the diagonal of the kernel matrix during fitting.\n This can prevent a potential numerical issue during fitting, by\n ensuring that the calculated values form a positive definite matrix.\n It can also be interpreted as the variance of additional Gaussian\n measurement noise on the training observations. Note that this is\n different from using a `WhiteKernel`. If an array is passed, it must\n have the same number of entries as the data used for fitting and is\n used as datapoint-dependent noise level. Allowing to specify the\n noise level directly as a parameter is mainly for convenience and\n for consistency with :class:`~sklearn.linear_model.Ridge`.\n\n optimizer : \"fmin_l_bfgs_b\" or callable, default=\"fmin_l_bfgs_b\"\n Can either be one of the internally supported optimizers for optimizing\n the kernel's parameters, specified by a string, or an externally\n defined optimizer passed as a callable. If a callable is passed, it\n must have the signature::\n\n def optimizer(obj_func, initial_theta, bounds):\n # * 'obj_func': the objective function to be minimized, which\n # takes the hyperparameters theta as a parameter and an\n # optional flag eval_gradient, which determines if the\n # gradient is returned additionally to the function value\n # * 'initial_theta': the initial value for theta, which can be\n # used by local optimizers\n # * 'bounds': the bounds on the values of theta\n ....\n # Returned are the best found hyperparameters theta and\n # the corresponding value of the target function.\n return theta_opt, func_min\n\n Per default, the L-BFGS-B algorithm from `scipy.optimize.minimize`\n is used. If None is passed, the kernel's parameters are kept fixed.\n Available internal optimizers are: `{'fmin_l_bfgs_b'}`.\n\n n_restarts_optimizer : int, default=0\n The number of restarts of the optimizer for finding the kernel's\n parameters which maximize the log-marginal likelihood. The first run\n of the optimizer is performed from the kernel's initial parameters,\n the remaining ones (if any) from thetas sampled log-uniform randomly\n from the space of allowed theta-values. If greater than 0, all bounds\n must be finite. Note that `n_restarts_optimizer == 0` implies that one\n run is performed.\n\n normalize_y : bool, default=False\n Whether or not to normalized the target values `y` by removing the mean\n and scaling to unit-variance. This is recommended for cases where\n zero-mean, unit-variance priors are used. Note that, in this\n implementation, the normalisation is reversed before the GP predictions\n are reported.\n\n .. versionchanged:: 0.23\n\n copy_X_train : bool, default=True\n If True, a persistent copy of the training data is stored in the\n object. Otherwise, just a reference to the training data is stored,\n which might cause predictions to change if the data is modified\n externally.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation used to initialize the centers.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n Attributes\n ----------\n X_train_ : array-like of shape (n_samples, n_features) or list of object\n Feature vectors or other representations of training data (also\n required for prediction).\n\n y_train_ : array-like of shape (n_samples,) or (n_samples, n_targets)\n Target values in training data (also required for prediction).\n\n kernel_ : kernel instance\n The kernel used for prediction. The structure of the kernel is the\n same as the one passed as parameter but with optimized hyperparameters.\n\n L_ : array-like of shape (n_samples, n_samples)\n Lower-triangular Cholesky decomposition of the kernel in ``X_train_``.\n\n alpha_ : array-like of shape (n_samples,)\n Dual coefficients of training data points in kernel space.\n\n log_marginal_likelihood_value_ : float\n The log-marginal-likelihood of ``self.kernel_.theta``.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n GaussianProcessClassifier : Gaussian process classification (GPC)\n based on Laplace approximation.\n\n References\n ----------\n .. [1] `Rasmussen, Carl Edward.\n \"Gaussian processes in machine learning.\"\n Summer school on machine learning. Springer, Berlin, Heidelberg, 2003\n `_.\n\n Examples\n --------\n >>> from sklearn.datasets import make_friedman2\n >>> from sklearn.gaussian_process import GaussianProcessRegressor\n >>> from sklearn.gaussian_process.kernels import DotProduct, WhiteKernel\n >>> X, y = make_friedman2(n_samples=500, noise=0, random_state=0)\n >>> kernel = DotProduct() + WhiteKernel()\n >>> gpr = GaussianProcessRegressor(kernel=kernel,\n ... random_state=0).fit(X, y)\n >>> gpr.score(X, y)\n 0.3680...\n >>> gpr.predict(X[:2,:], return_std=True)\n (array([653.0..., 592.1...]), array([316.6..., 316.6...]))\n ", - "source_code": "\n\nclass GaussianProcessRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):\n \"\"\"Gaussian process regression (GPR).\n\n The implementation is based on Algorithm 2.1 of [1]_.\n\n In addition to standard scikit-learn estimator API,\n :class:`GaussianProcessRegressor`:\n\n * allows prediction without prior fitting (based on the GP prior)\n * provides an additional method `sample_y(X)`, which evaluates samples\n drawn from the GPR (prior or posterior) at given inputs\n * exposes a method `log_marginal_likelihood(theta)`, which can be used\n externally for other ways of selecting hyperparameters, e.g., via\n Markov chain Monte Carlo.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.18\n\n Parameters\n ----------\n kernel : kernel instance, default=None\n The kernel specifying the covariance function of the GP. If None is\n passed, the kernel ``ConstantKernel(1.0, constant_value_bounds=\"fixed\"\n * RBF(1.0, length_scale_bounds=\"fixed\")`` is used as default. Note that\n the kernel hyperparameters are optimized during fitting unless the\n bounds are marked as \"fixed\".\n\n alpha : float or ndarray of shape (n_samples,), default=1e-10\n Value added to the diagonal of the kernel matrix during fitting.\n This can prevent a potential numerical issue during fitting, by\n ensuring that the calculated values form a positive definite matrix.\n It can also be interpreted as the variance of additional Gaussian\n measurement noise on the training observations. Note that this is\n different from using a `WhiteKernel`. If an array is passed, it must\n have the same number of entries as the data used for fitting and is\n used as datapoint-dependent noise level. Allowing to specify the\n noise level directly as a parameter is mainly for convenience and\n for consistency with :class:`~sklearn.linear_model.Ridge`.\n\n optimizer : \"fmin_l_bfgs_b\" or callable, default=\"fmin_l_bfgs_b\"\n Can either be one of the internally supported optimizers for optimizing\n the kernel's parameters, specified by a string, or an externally\n defined optimizer passed as a callable. If a callable is passed, it\n must have the signature::\n\n def optimizer(obj_func, initial_theta, bounds):\n # * 'obj_func': the objective function to be minimized, which\n # takes the hyperparameters theta as a parameter and an\n # optional flag eval_gradient, which determines if the\n # gradient is returned additionally to the function value\n # * 'initial_theta': the initial value for theta, which can be\n # used by local optimizers\n # * 'bounds': the bounds on the values of theta\n ....\n # Returned are the best found hyperparameters theta and\n # the corresponding value of the target function.\n return theta_opt, func_min\n\n Per default, the L-BFGS-B algorithm from `scipy.optimize.minimize`\n is used. If None is passed, the kernel's parameters are kept fixed.\n Available internal optimizers are: `{'fmin_l_bfgs_b'}`.\n\n n_restarts_optimizer : int, default=0\n The number of restarts of the optimizer for finding the kernel's\n parameters which maximize the log-marginal likelihood. The first run\n of the optimizer is performed from the kernel's initial parameters,\n the remaining ones (if any) from thetas sampled log-uniform randomly\n from the space of allowed theta-values. If greater than 0, all bounds\n must be finite. Note that `n_restarts_optimizer == 0` implies that one\n run is performed.\n\n normalize_y : bool, default=False\n Whether or not to normalized the target values `y` by removing the mean\n and scaling to unit-variance. This is recommended for cases where\n zero-mean, unit-variance priors are used. Note that, in this\n implementation, the normalisation is reversed before the GP predictions\n are reported.\n\n .. versionchanged:: 0.23\n\n copy_X_train : bool, default=True\n If True, a persistent copy of the training data is stored in the\n object. Otherwise, just a reference to the training data is stored,\n which might cause predictions to change if the data is modified\n externally.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation used to initialize the centers.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n Attributes\n ----------\n X_train_ : array-like of shape (n_samples, n_features) or list of object\n Feature vectors or other representations of training data (also\n required for prediction).\n\n y_train_ : array-like of shape (n_samples,) or (n_samples, n_targets)\n Target values in training data (also required for prediction).\n\n kernel_ : kernel instance\n The kernel used for prediction. The structure of the kernel is the\n same as the one passed as parameter but with optimized hyperparameters.\n\n L_ : array-like of shape (n_samples, n_samples)\n Lower-triangular Cholesky decomposition of the kernel in ``X_train_``.\n\n alpha_ : array-like of shape (n_samples,)\n Dual coefficients of training data points in kernel space.\n\n log_marginal_likelihood_value_ : float\n The log-marginal-likelihood of ``self.kernel_.theta``.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n GaussianProcessClassifier : Gaussian process classification (GPC)\n based on Laplace approximation.\n\n References\n ----------\n .. [1] `Rasmussen, Carl Edward.\n \"Gaussian processes in machine learning.\"\n Summer school on machine learning. Springer, Berlin, Heidelberg, 2003\n `_.\n\n Examples\n --------\n >>> from sklearn.datasets import make_friedman2\n >>> from sklearn.gaussian_process import GaussianProcessRegressor\n >>> from sklearn.gaussian_process.kernels import DotProduct, WhiteKernel\n >>> X, y = make_friedman2(n_samples=500, noise=0, random_state=0)\n >>> kernel = DotProduct() + WhiteKernel()\n >>> gpr = GaussianProcessRegressor(kernel=kernel,\n ... random_state=0).fit(X, y)\n >>> gpr.score(X, y)\n 0.3680...\n >>> gpr.predict(X[:2,:], return_std=True)\n (array([653.0..., 592.1...]), array([316.6..., 316.6...]))\n \"\"\"\n \n def __init__(self, kernel=None, *, alpha=1e-10, optimizer='fmin_l_bfgs_b', n_restarts_optimizer=0, normalize_y=False, copy_X_train=True, random_state=None):\n self.kernel = kernel\n self.alpha = alpha\n self.optimizer = optimizer\n self.n_restarts_optimizer = n_restarts_optimizer\n self.normalize_y = normalize_y\n self.copy_X_train = copy_X_train\n self.random_state = random_state\n \n def fit(self, X, y):\n \"\"\"Fit Gaussian process regression model.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features) or list of object\n Feature vectors or other representations of training data.\n\n y : array-like of shape (n_samples,) or (n_samples, n_targets)\n Target values.\n\n Returns\n -------\n self : object\n GaussianProcessRegressor class instance.\n \"\"\"\n if self.kernel is None:\n self.kernel_ = C(1.0, constant_value_bounds='fixed') * RBF(1.0, length_scale_bounds='fixed')\n else:\n self.kernel_ = clone(self.kernel)\n self._rng = check_random_state(self.random_state)\n if self.kernel_.requires_vector_input:\n (dtype, ensure_2d) = ('numeric', True)\n else:\n (dtype, ensure_2d) = (None, False)\n (X, y) = self._validate_data(X, y, multi_output=True, y_numeric=True, ensure_2d=ensure_2d, dtype=dtype)\n if self.normalize_y:\n self._y_train_mean = np.mean(y, axis=0)\n self._y_train_std = _handle_zeros_in_scale(np.std(y, axis=0), copy=False)\n y = (y - self._y_train_mean) / self._y_train_std\n else:\n self._y_train_mean = np.zeros(1)\n self._y_train_std = 1\n if np.iterable(self.alpha) and self.alpha.shape[0] != y.shape[0]:\n if self.alpha.shape[0] == 1:\n self.alpha = self.alpha[0]\n else:\n raise ValueError(f'alpha must be a scalar or an array with same number of entries as y. ({self.alpha.shape[0]} != {y.shape[0]})')\n self.X_train_ = np.copy(X) if self.copy_X_train else X\n self.y_train_ = np.copy(y) if self.copy_X_train else y\n if self.optimizer is not None and self.kernel_.n_dims > 0:\n \n def obj_func(theta, eval_gradient=True):\n if eval_gradient:\n (lml, grad) = self.log_marginal_likelihood(theta, eval_gradient=True, clone_kernel=False)\n return -lml, -grad\n else:\n return -self.log_marginal_likelihood(theta, clone_kernel=False)\n optima = [self._constrained_optimization(obj_func, self.kernel_.theta, self.kernel_.bounds)]\n if self.n_restarts_optimizer > 0:\n if not np.isfinite(self.kernel_.bounds).all():\n raise ValueError('Multiple optimizer restarts (n_restarts_optimizer>0) requires that all bounds are finite.')\n bounds = self.kernel_.bounds\n for iteration in range(self.n_restarts_optimizer):\n theta_initial = self._rng.uniform(bounds[:, 0], bounds[:, 1])\n optima.append(self._constrained_optimization(obj_func, theta_initial, bounds))\n lml_values = list(map(itemgetter(1), optima))\n self.kernel_.theta = optima[np.argmin(lml_values)][0]\n self.kernel_._check_bounds_params()\n self.log_marginal_likelihood_value_ = -np.min(lml_values)\n else:\n self.log_marginal_likelihood_value_ = self.log_marginal_likelihood(self.kernel_.theta, clone_kernel=False)\n K = self.kernel_(self.X_train_)\n K[np.diag_indices_from(K)] += self.alpha\n try:\n self.L_ = cholesky(K, lower=GPR_CHOLESKY_LOWER, check_finite=False)\n except np.linalg.LinAlgError as exc:\n exc.args = (f\"The kernel, {self.kernel_}, is not returning a positive definite matrix. Try gradually increasing the 'alpha' parameter of your GaussianProcessRegressor estimator.\", ) + exc.args\n raise\n self.alpha_ = cho_solve((self.L_, GPR_CHOLESKY_LOWER), self.y_train_, check_finite=False)\n return self\n \n def predict(self, X, return_std=False, return_cov=False):\n \"\"\"Predict using the Gaussian process regression model.\n\n We can also predict based on an unfitted model by using the GP prior.\n In addition to the mean of the predictive distribution, optionally also\n returns its standard deviation (`return_std=True`) or covariance\n (`return_cov=True`). Note that at most one of the two can be requested.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features) or list of object\n Query points where the GP is evaluated.\n\n return_std : bool, default=False\n If True, the standard-deviation of the predictive distribution at\n the query points is returned along with the mean.\n\n return_cov : bool, default=False\n If True, the covariance of the joint predictive distribution at\n the query points is returned along with the mean.\n\n Returns\n -------\n y_mean : ndarray of shape (n_samples,) or (n_samples, n_targets)\n Mean of predictive distribution a query points.\n\n y_std : ndarray of shape (n_samples,), optional\n Standard deviation of predictive distribution at query points.\n Only returned when `return_std` is True.\n\n y_cov : ndarray of shape (n_samples, n_samples), optional\n Covariance of joint predictive distribution a query points.\n Only returned when `return_cov` is True.\n \"\"\"\n if return_std and return_cov:\n raise RuntimeError('At most one of return_std or return_cov can be requested.')\n if self.kernel is None or self.kernel.requires_vector_input:\n (dtype, ensure_2d) = ('numeric', True)\n else:\n (dtype, ensure_2d) = (None, False)\n X = self._validate_data(X, ensure_2d=ensure_2d, dtype=dtype, reset=False)\n if not hasattr(self, 'X_train_'):\n if self.kernel is None:\n kernel = C(1.0, constant_value_bounds='fixed') * RBF(1.0, length_scale_bounds='fixed')\n else:\n kernel = self.kernel\n y_mean = np.zeros(X.shape[0])\n if return_cov:\n y_cov = kernel(X)\n return y_mean, y_cov\n elif return_std:\n y_var = kernel.diag(X)\n return y_mean, np.sqrt(y_var)\n else:\n return y_mean\n else:\n K_trans = self.kernel_(X, self.X_train_)\n y_mean = K_trans @ self.alpha_\n y_mean = self._y_train_std * y_mean + self._y_train_mean\n V = solve_triangular(self.L_, K_trans.T, lower=GPR_CHOLESKY_LOWER, check_finite=False)\n if return_cov:\n y_cov = self.kernel_(X) - V.T @ V\n y_cov = y_cov * self._y_train_std**2\n return y_mean, y_cov\n elif return_std:\n y_var = self.kernel_.diag(X)\n y_var -= np.einsum('ij,ji->i', V.T, V)\n y_var_negative = y_var < 0\n if np.any(y_var_negative):\n warnings.warn('Predicted variances smaller than 0. Setting those variances to 0.')\n y_var[y_var_negative] = 0.0\n y_var = y_var * self._y_train_std**2\n return y_mean, np.sqrt(y_var)\n else:\n return y_mean\n \n def sample_y(self, X, n_samples=1, random_state=0):\n \"\"\"Draw samples from Gaussian process and evaluate at X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples_X, n_features) or list of object\n Query points where the GP is evaluated.\n\n n_samples : int, default=1\n Number of samples drawn from the Gaussian process per query point.\n\n random_state : int, RandomState instance or None, default=0\n Determines random number generation to randomly draw samples.\n Pass an int for reproducible results across multiple function\n calls.\n See :term:`Glossary `.\n\n Returns\n -------\n y_samples : ndarray of shape (n_samples_X, n_samples), or (n_samples_X, n_targets, n_samples)\n Values of n_samples samples drawn from Gaussian process and\n evaluated at query points.\n \"\"\"\n rng = check_random_state(random_state)\n (y_mean, y_cov) = self.predict(X, return_cov=True)\n if y_mean.ndim == 1:\n y_samples = rng.multivariate_normal(y_mean, y_cov, n_samples).T\n else:\n y_samples = [rng.multivariate_normal(y_mean[:, i], y_cov, n_samples).T[:, np.newaxis] for i in range(y_mean.shape[1])]\n y_samples = np.hstack(y_samples)\n return y_samples\n \n def log_marginal_likelihood(self, theta=None, eval_gradient=False, clone_kernel=True):\n \"\"\"Return log-marginal likelihood of theta for training data.\n\n Parameters\n ----------\n theta : array-like of shape (n_kernel_params,) default=None\n Kernel hyperparameters for which the log-marginal likelihood is\n evaluated. If None, the precomputed log_marginal_likelihood\n of ``self.kernel_.theta`` is returned.\n\n eval_gradient : bool, default=False\n If True, the gradient of the log-marginal likelihood with respect\n to the kernel hyperparameters at position theta is returned\n additionally. If True, theta must not be None.\n\n clone_kernel : bool, default=True\n If True, the kernel attribute is copied. If False, the kernel\n attribute is modified, but may result in a performance improvement.\n\n Returns\n -------\n log_likelihood : float\n Log-marginal likelihood of theta for training data.\n\n log_likelihood_gradient : ndarray of shape (n_kernel_params,), optional\n Gradient of the log-marginal likelihood with respect to the kernel\n hyperparameters at position theta.\n Only returned when eval_gradient is True.\n \"\"\"\n if theta is None:\n if eval_gradient:\n raise ValueError('Gradient can only be evaluated for theta!=None')\n return self.log_marginal_likelihood_value_\n if clone_kernel:\n kernel = self.kernel_.clone_with_theta(theta)\n else:\n kernel = self.kernel_\n kernel.theta = theta\n if eval_gradient:\n (K, K_gradient) = kernel(self.X_train_, eval_gradient=True)\n else:\n K = kernel(self.X_train_)\n K[np.diag_indices_from(K)] += self.alpha\n try:\n L = cholesky(K, lower=GPR_CHOLESKY_LOWER, check_finite=False)\n except np.linalg.LinAlgError:\n return (-np.inf, np.zeros_like(theta)) if eval_gradient else -np.inf\n y_train = self.y_train_\n if y_train.ndim == 1:\n y_train = y_train[:, np.newaxis]\n alpha = cho_solve((L, GPR_CHOLESKY_LOWER), y_train, check_finite=False)\n log_likelihood_dims = -0.5 * np.einsum('ik,ik->k', y_train, alpha)\n log_likelihood_dims -= np.log(np.diag(L)).sum()\n log_likelihood_dims -= K.shape[0] / 2 * np.log(2 * np.pi)\n log_likelihood = log_likelihood_dims.sum(axis=-1)\n if eval_gradient:\n inner_term = np.einsum('ik,jk->ijk', alpha, alpha)\n K_inv = cho_solve((L, GPR_CHOLESKY_LOWER), np.eye(K.shape[0]), check_finite=False)\n inner_term -= K_inv[..., np.newaxis]\n log_likelihood_gradient_dims = 0.5 * np.einsum('ijl,jik->kl', inner_term, K_gradient)\n log_likelihood_gradient = log_likelihood_gradient_dims.sum(axis=-1)\n if eval_gradient:\n return log_likelihood, log_likelihood_gradient\n else:\n return log_likelihood\n \n def _constrained_optimization(self, obj_func, initial_theta, bounds):\n if self.optimizer == 'fmin_l_bfgs_b':\n opt_res = scipy.optimize.minimize(obj_func, initial_theta, method='L-BFGS-B', jac=True, bounds=bounds)\n _check_optimize_result('lbfgs', opt_res)\n (theta_opt, func_min) = (opt_res.x, opt_res.fun)\n elif callable(self.optimizer):\n (theta_opt, func_min) = self.optimizer(obj_func, initial_theta, bounds=bounds)\n else:\n raise ValueError(f'Unknown optimizer {self.optimizer}.')\n return theta_opt, func_min\n \n def _more_tags(self):\n return {'requires_fit': False}\n" + "source_code": "\n\nclass GaussianProcessRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):\n \"\"\"Gaussian process regression (GPR).\n\n The implementation is based on Algorithm 2.1 of [1]_.\n\n In addition to standard scikit-learn estimator API,\n :class:`GaussianProcessRegressor`:\n\n * allows prediction without prior fitting (based on the GP prior)\n * provides an additional method `sample_y(X)`, which evaluates samples\n drawn from the GPR (prior or posterior) at given inputs\n * exposes a method `log_marginal_likelihood(theta)`, which can be used\n externally for other ways of selecting hyperparameters, e.g., via\n Markov chain Monte Carlo.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.18\n\n Parameters\n ----------\n kernel : kernel instance, default=None\n The kernel specifying the covariance function of the GP. If None is\n passed, the kernel ``ConstantKernel(1.0, constant_value_bounds=\"fixed\"\n * RBF(1.0, length_scale_bounds=\"fixed\")`` is used as default. Note that\n the kernel hyperparameters are optimized during fitting unless the\n bounds are marked as \"fixed\".\n\n alpha : float or ndarray of shape (n_samples,), default=1e-10\n Value added to the diagonal of the kernel matrix during fitting.\n This can prevent a potential numerical issue during fitting, by\n ensuring that the calculated values form a positive definite matrix.\n It can also be interpreted as the variance of additional Gaussian\n measurement noise on the training observations. Note that this is\n different from using a `WhiteKernel`. If an array is passed, it must\n have the same number of entries as the data used for fitting and is\n used as datapoint-dependent noise level. Allowing to specify the\n noise level directly as a parameter is mainly for convenience and\n for consistency with :class:`~sklearn.linear_model.Ridge`.\n\n optimizer : \"fmin_l_bfgs_b\" or callable, default=\"fmin_l_bfgs_b\"\n Can either be one of the internally supported optimizers for optimizing\n the kernel's parameters, specified by a string, or an externally\n defined optimizer passed as a callable. If a callable is passed, it\n must have the signature::\n\n def optimizer(obj_func, initial_theta, bounds):\n # * 'obj_func': the objective function to be minimized, which\n # takes the hyperparameters theta as a parameter and an\n # optional flag eval_gradient, which determines if the\n # gradient is returned additionally to the function value\n # * 'initial_theta': the initial value for theta, which can be\n # used by local optimizers\n # * 'bounds': the bounds on the values of theta\n ....\n # Returned are the best found hyperparameters theta and\n # the corresponding value of the target function.\n return theta_opt, func_min\n\n Per default, the L-BFGS-B algorithm from `scipy.optimize.minimize`\n is used. If None is passed, the kernel's parameters are kept fixed.\n Available internal optimizers are: `{'fmin_l_bfgs_b'}`.\n\n n_restarts_optimizer : int, default=0\n The number of restarts of the optimizer for finding the kernel's\n parameters which maximize the log-marginal likelihood. The first run\n of the optimizer is performed from the kernel's initial parameters,\n the remaining ones (if any) from thetas sampled log-uniform randomly\n from the space of allowed theta-values. If greater than 0, all bounds\n must be finite. Note that `n_restarts_optimizer == 0` implies that one\n run is performed.\n\n normalize_y : bool, default=False\n Whether or not to normalized the target values `y` by removing the mean\n and scaling to unit-variance. This is recommended for cases where\n zero-mean, unit-variance priors are used. Note that, in this\n implementation, the normalisation is reversed before the GP predictions\n are reported.\n\n .. versionchanged:: 0.23\n\n copy_X_train : bool, default=True\n If True, a persistent copy of the training data is stored in the\n object. Otherwise, just a reference to the training data is stored,\n which might cause predictions to change if the data is modified\n externally.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation used to initialize the centers.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n Attributes\n ----------\n X_train_ : array-like of shape (n_samples, n_features) or list of object\n Feature vectors or other representations of training data (also\n required for prediction).\n\n y_train_ : array-like of shape (n_samples,) or (n_samples, n_targets)\n Target values in training data (also required for prediction).\n\n kernel_ : kernel instance\n The kernel used for prediction. The structure of the kernel is the\n same as the one passed as parameter but with optimized hyperparameters.\n\n L_ : array-like of shape (n_samples, n_samples)\n Lower-triangular Cholesky decomposition of the kernel in ``X_train_``.\n\n alpha_ : array-like of shape (n_samples,)\n Dual coefficients of training data points in kernel space.\n\n log_marginal_likelihood_value_ : float\n The log-marginal-likelihood of ``self.kernel_.theta``.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n GaussianProcessClassifier : Gaussian process classification (GPC)\n based on Laplace approximation.\n\n References\n ----------\n .. [1] `Rasmussen, Carl Edward.\n \"Gaussian processes in machine learning.\"\n Summer school on machine learning. Springer, Berlin, Heidelberg, 2003\n `_.\n\n Examples\n --------\n >>> from sklearn.datasets import make_friedman2\n >>> from sklearn.gaussian_process import GaussianProcessRegressor\n >>> from sklearn.gaussian_process.kernels import DotProduct, WhiteKernel\n >>> X, y = make_friedman2(n_samples=500, noise=0, random_state=0)\n >>> kernel = DotProduct() + WhiteKernel()\n >>> gpr = GaussianProcessRegressor(kernel=kernel,\n ... random_state=0).fit(X, y)\n >>> gpr.score(X, y)\n 0.3680...\n >>> gpr.predict(X[:2,:], return_std=True)\n (array([653.0..., 592.1...]), array([316.6..., 316.6...]))\n \"\"\"\n \n def __init__(self, kernel=None, *, alpha=1e-10, optimizer='fmin_l_bfgs_b', n_restarts_optimizer=0, normalize_y=False, copy_X_train=True, random_state=None):\n self.kernel = kernel\n self.alpha = alpha\n self.optimizer = optimizer\n self.n_restarts_optimizer = n_restarts_optimizer\n self.normalize_y = normalize_y\n self.copy_X_train = copy_X_train\n self.random_state = random_state\n \n def fit(self, X, y):\n \"\"\"Fit Gaussian process regression model.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features) or list of object\n Feature vectors or other representations of training data.\n\n y : array-like of shape (n_samples,) or (n_samples, n_targets)\n Target values.\n\n Returns\n -------\n self : object\n GaussianProcessRegressor class instance.\n \"\"\"\n if self.kernel is None:\n self.kernel_ = C(1.0, constant_value_bounds='fixed') * RBF(1.0, length_scale_bounds='fixed')\n else:\n self.kernel_ = clone(self.kernel)\n self._rng = check_random_state(self.random_state)\n if self.kernel_.requires_vector_input:\n (dtype, ensure_2d) = ('numeric', True)\n else:\n (dtype, ensure_2d) = (None, False)\n (X, y) = self._validate_data(X, y, multi_output=True, y_numeric=True, ensure_2d=ensure_2d, dtype=dtype)\n if self.normalize_y:\n self._y_train_mean = np.mean(y, axis=0)\n self._y_train_std = _handle_zeros_in_scale(np.std(y, axis=0), copy=False)\n y = (y - self._y_train_mean) / self._y_train_std\n else:\n self._y_train_mean = np.zeros(1)\n self._y_train_std = 1\n if np.iterable(self.alpha) and self.alpha.shape[0] != y.shape[0]:\n if self.alpha.shape[0] == 1:\n self.alpha = self.alpha[0]\n else:\n raise ValueError(f'alpha must be a scalar or an array with same number of entries as y. ({self.alpha.shape[0]} != {y.shape[0]})')\n self.X_train_ = np.copy(X) if self.copy_X_train else X\n self.y_train_ = np.copy(y) if self.copy_X_train else y\n if self.optimizer is not None and self.kernel_.n_dims > 0:\n \n def obj_func(theta, eval_gradient=True):\n if eval_gradient:\n (lml, grad) = self.log_marginal_likelihood(theta, eval_gradient=True, clone_kernel=False)\n return -lml, -grad\n else:\n return -self.log_marginal_likelihood(theta, clone_kernel=False)\n optima = [self._constrained_optimization(obj_func, self.kernel_.theta, self.kernel_.bounds)]\n if self.n_restarts_optimizer > 0:\n if not np.isfinite(self.kernel_.bounds).all():\n raise ValueError('Multiple optimizer restarts (n_restarts_optimizer>0) requires that all bounds are finite.')\n bounds = self.kernel_.bounds\n for iteration in range(self.n_restarts_optimizer):\n theta_initial = self._rng.uniform(bounds[:, 0], bounds[:, 1])\n optima.append(self._constrained_optimization(obj_func, theta_initial, bounds))\n lml_values = list(map(itemgetter(1), optima))\n self.kernel_.theta = optima[np.argmin(lml_values)][0]\n self.kernel_._check_bounds_params()\n self.log_marginal_likelihood_value_ = -np.min(lml_values)\n else:\n self.log_marginal_likelihood_value_ = self.log_marginal_likelihood(self.kernel_.theta, clone_kernel=False)\n K = self.kernel_(self.X_train_)\n K[np.diag_indices_from(K)] += self.alpha\n try:\n self.L_ = cholesky(K, lower=GPR_CHOLESKY_LOWER, check_finite=False)\n except np.linalg.LinAlgError as exc:\n exc.args = (f\"The kernel, {self.kernel_}, is not returning a positive definite matrix. Try gradually increasing the 'alpha' parameter of your GaussianProcessRegressor estimator.\", ) + exc.args\n raise\n self.alpha_ = cho_solve((self.L_, GPR_CHOLESKY_LOWER), self.y_train_, check_finite=False)\n return self\n \n def predict(self, X, return_std=False, return_cov=False):\n \"\"\"Predict using the Gaussian process regression model.\n\n We can also predict based on an unfitted model by using the GP prior.\n In addition to the mean of the predictive distribution, optionally also\n returns its standard deviation (`return_std=True`) or covariance\n (`return_cov=True`). Note that at most one of the two can be requested.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features) or list of object\n Query points where the GP is evaluated.\n\n return_std : bool, default=False\n If True, the standard-deviation of the predictive distribution at\n the query points is returned along with the mean.\n\n return_cov : bool, default=False\n If True, the covariance of the joint predictive distribution at\n the query points is returned along with the mean.\n\n Returns\n -------\n y_mean : ndarray of shape (n_samples,) or (n_samples, n_targets)\n Mean of predictive distribution a query points.\n\n y_std : ndarray of shape (n_samples,) or (n_samples, n_targets), optional\n Standard deviation of predictive distribution at query points.\n Only returned when `return_std` is True.\n\n y_cov : ndarray of shape (n_samples, n_samples) or (n_samples, n_samples, n_targets), optional\n Covariance of joint predictive distribution a query points.\n Only returned when `return_cov` is True.\n \"\"\"\n if return_std and return_cov:\n raise RuntimeError('At most one of return_std or return_cov can be requested.')\n if self.kernel is None or self.kernel.requires_vector_input:\n (dtype, ensure_2d) = ('numeric', True)\n else:\n (dtype, ensure_2d) = (None, False)\n X = self._validate_data(X, ensure_2d=ensure_2d, dtype=dtype, reset=False)\n if not hasattr(self, 'X_train_'):\n if self.kernel is None:\n kernel = C(1.0, constant_value_bounds='fixed') * RBF(1.0, length_scale_bounds='fixed')\n else:\n kernel = self.kernel\n y_mean = np.zeros(X.shape[0])\n if return_cov:\n y_cov = kernel(X)\n return y_mean, y_cov\n elif return_std:\n y_var = kernel.diag(X)\n return y_mean, np.sqrt(y_var)\n else:\n return y_mean\n else:\n K_trans = self.kernel_(X, self.X_train_)\n y_mean = K_trans @ self.alpha_\n y_mean = self._y_train_std * y_mean + self._y_train_mean\n V = solve_triangular(self.L_, K_trans.T, lower=GPR_CHOLESKY_LOWER, check_finite=False)\n if return_cov:\n y_cov = self.kernel_(X) - V.T @ V\n y_cov = np.outer(y_cov, self._y_train_std**2).reshape(*y_cov.shape, -1)\n if y_cov.shape[2] == 1:\n y_cov = np.squeeze(y_cov, axis=2)\n return y_mean, y_cov\n elif return_std:\n y_var = self.kernel_.diag(X)\n y_var -= np.einsum('ij,ji->i', V.T, V)\n y_var_negative = y_var < 0\n if np.any(y_var_negative):\n warnings.warn('Predicted variances smaller than 0. Setting those variances to 0.')\n y_var[y_var_negative] = 0.0\n y_var = np.outer(y_var, self._y_train_std**2).reshape(*y_var.shape, -1)\n if y_var.shape[1] == 1:\n y_var = np.squeeze(y_var, axis=1)\n return y_mean, np.sqrt(y_var)\n else:\n return y_mean\n \n def sample_y(self, X, n_samples=1, random_state=0):\n \"\"\"Draw samples from Gaussian process and evaluate at X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples_X, n_features) or list of object\n Query points where the GP is evaluated.\n\n n_samples : int, default=1\n Number of samples drawn from the Gaussian process per query point.\n\n random_state : int, RandomState instance or None, default=0\n Determines random number generation to randomly draw samples.\n Pass an int for reproducible results across multiple function\n calls.\n See :term:`Glossary `.\n\n Returns\n -------\n y_samples : ndarray of shape (n_samples_X, n_samples), or (n_samples_X, n_targets, n_samples)\n Values of n_samples samples drawn from Gaussian process and\n evaluated at query points.\n \"\"\"\n rng = check_random_state(random_state)\n (y_mean, y_cov) = self.predict(X, return_cov=True)\n if y_mean.ndim == 1:\n y_samples = rng.multivariate_normal(y_mean, y_cov, n_samples).T\n else:\n y_samples = [rng.multivariate_normal(y_mean[:, i], y_cov, n_samples).T[:, np.newaxis] for i in range(y_mean.shape[1])]\n y_samples = np.hstack(y_samples)\n return y_samples\n \n def log_marginal_likelihood(self, theta=None, eval_gradient=False, clone_kernel=True):\n \"\"\"Return log-marginal likelihood of theta for training data.\n\n Parameters\n ----------\n theta : array-like of shape (n_kernel_params,) default=None\n Kernel hyperparameters for which the log-marginal likelihood is\n evaluated. If None, the precomputed log_marginal_likelihood\n of ``self.kernel_.theta`` is returned.\n\n eval_gradient : bool, default=False\n If True, the gradient of the log-marginal likelihood with respect\n to the kernel hyperparameters at position theta is returned\n additionally. If True, theta must not be None.\n\n clone_kernel : bool, default=True\n If True, the kernel attribute is copied. If False, the kernel\n attribute is modified, but may result in a performance improvement.\n\n Returns\n -------\n log_likelihood : float\n Log-marginal likelihood of theta for training data.\n\n log_likelihood_gradient : ndarray of shape (n_kernel_params,), optional\n Gradient of the log-marginal likelihood with respect to the kernel\n hyperparameters at position theta.\n Only returned when eval_gradient is True.\n \"\"\"\n if theta is None:\n if eval_gradient:\n raise ValueError('Gradient can only be evaluated for theta!=None')\n return self.log_marginal_likelihood_value_\n if clone_kernel:\n kernel = self.kernel_.clone_with_theta(theta)\n else:\n kernel = self.kernel_\n kernel.theta = theta\n if eval_gradient:\n (K, K_gradient) = kernel(self.X_train_, eval_gradient=True)\n else:\n K = kernel(self.X_train_)\n K[np.diag_indices_from(K)] += self.alpha\n try:\n L = cholesky(K, lower=GPR_CHOLESKY_LOWER, check_finite=False)\n except np.linalg.LinAlgError:\n return (-np.inf, np.zeros_like(theta)) if eval_gradient else -np.inf\n y_train = self.y_train_\n if y_train.ndim == 1:\n y_train = y_train[:, np.newaxis]\n alpha = cho_solve((L, GPR_CHOLESKY_LOWER), y_train, check_finite=False)\n log_likelihood_dims = -0.5 * np.einsum('ik,ik->k', y_train, alpha)\n log_likelihood_dims -= np.log(np.diag(L)).sum()\n log_likelihood_dims -= K.shape[0] / 2 * np.log(2 * np.pi)\n log_likelihood = log_likelihood_dims.sum(axis=-1)\n if eval_gradient:\n inner_term = np.einsum('ik,jk->ijk', alpha, alpha)\n K_inv = cho_solve((L, GPR_CHOLESKY_LOWER), np.eye(K.shape[0]), check_finite=False)\n inner_term -= K_inv[..., np.newaxis]\n log_likelihood_gradient_dims = 0.5 * np.einsum('ijl,jik->kl', inner_term, K_gradient)\n log_likelihood_gradient = log_likelihood_gradient_dims.sum(axis=-1)\n if eval_gradient:\n return log_likelihood, log_likelihood_gradient\n else:\n return log_likelihood\n \n def _constrained_optimization(self, obj_func, initial_theta, bounds):\n if self.optimizer == 'fmin_l_bfgs_b':\n opt_res = scipy.optimize.minimize(obj_func, initial_theta, method='L-BFGS-B', jac=True, bounds=bounds)\n _check_optimize_result('lbfgs', opt_res)\n (theta_opt, func_min) = (opt_res.x, opt_res.fun)\n elif callable(self.optimizer):\n (theta_opt, func_min) = self.optimizer(obj_func, initial_theta, bounds=bounds)\n else:\n raise ValueError(f'Unknown optimizer {self.optimizer}.')\n return theta_opt, func_min\n \n def _more_tags(self):\n return {'requires_fit': False}\n" }, { "name": "CompoundKernel", @@ -22771,13 +22724,13 @@ "methods": [ "sklearn.gaussian_process.kernels.CompoundKernel.__init__", "sklearn.gaussian_process.kernels.CompoundKernel.get_params", - "sklearn.gaussian_process.kernels.CompoundKernel.theta", - "sklearn.gaussian_process.kernels.CompoundKernel.theta", - "sklearn.gaussian_process.kernels.CompoundKernel.bounds", + "sklearn.gaussian_process.kernels.CompoundKernel.theta@getter", + "sklearn.gaussian_process.kernels.CompoundKernel.theta@setter", + "sklearn.gaussian_process.kernels.CompoundKernel.bounds@getter", "sklearn.gaussian_process.kernels.CompoundKernel.__call__", "sklearn.gaussian_process.kernels.CompoundKernel.__eq__", "sklearn.gaussian_process.kernels.CompoundKernel.is_stationary", - "sklearn.gaussian_process.kernels.CompoundKernel.requires_vector_input", + "sklearn.gaussian_process.kernels.CompoundKernel.requires_vector_input@getter", "sklearn.gaussian_process.kernels.CompoundKernel.diag" ], "is_public": true, @@ -22796,7 +22749,7 @@ ], "methods": [ "sklearn.gaussian_process.kernels.ConstantKernel.__init__", - "sklearn.gaussian_process.kernels.ConstantKernel.hyperparameter_constant_value", + "sklearn.gaussian_process.kernels.ConstantKernel.hyperparameter_constant_value@getter", "sklearn.gaussian_process.kernels.ConstantKernel.__call__", "sklearn.gaussian_process.kernels.ConstantKernel.diag", "sklearn.gaussian_process.kernels.ConstantKernel.__repr__" @@ -22813,7 +22766,7 @@ "superclasses": ["Kernel"], "methods": [ "sklearn.gaussian_process.kernels.DotProduct.__init__", - "sklearn.gaussian_process.kernels.DotProduct.hyperparameter_sigma_0", + "sklearn.gaussian_process.kernels.DotProduct.hyperparameter_sigma_0@getter", "sklearn.gaussian_process.kernels.DotProduct.__call__", "sklearn.gaussian_process.kernels.DotProduct.diag", "sklearn.gaussian_process.kernels.DotProduct.is_stationary", @@ -22835,8 +22788,8 @@ ], "methods": [ "sklearn.gaussian_process.kernels.ExpSineSquared.__init__", - "sklearn.gaussian_process.kernels.ExpSineSquared.hyperparameter_length_scale", - "sklearn.gaussian_process.kernels.ExpSineSquared.hyperparameter_periodicity", + "sklearn.gaussian_process.kernels.ExpSineSquared.hyperparameter_length_scale@getter", + "sklearn.gaussian_process.kernels.ExpSineSquared.hyperparameter_periodicity@getter", "sklearn.gaussian_process.kernels.ExpSineSquared.__call__", "sklearn.gaussian_process.kernels.ExpSineSquared.__repr__" ], @@ -22853,16 +22806,16 @@ "methods": [ "sklearn.gaussian_process.kernels.Exponentiation.__init__", "sklearn.gaussian_process.kernels.Exponentiation.get_params", - "sklearn.gaussian_process.kernels.Exponentiation.hyperparameters", - "sklearn.gaussian_process.kernels.Exponentiation.theta", - "sklearn.gaussian_process.kernels.Exponentiation.theta", - "sklearn.gaussian_process.kernels.Exponentiation.bounds", + "sklearn.gaussian_process.kernels.Exponentiation.hyperparameters@getter", + "sklearn.gaussian_process.kernels.Exponentiation.theta@getter", + "sklearn.gaussian_process.kernels.Exponentiation.theta@setter", + "sklearn.gaussian_process.kernels.Exponentiation.bounds@getter", "sklearn.gaussian_process.kernels.Exponentiation.__eq__", "sklearn.gaussian_process.kernels.Exponentiation.__call__", "sklearn.gaussian_process.kernels.Exponentiation.diag", "sklearn.gaussian_process.kernels.Exponentiation.__repr__", "sklearn.gaussian_process.kernels.Exponentiation.is_stationary", - "sklearn.gaussian_process.kernels.Exponentiation.requires_vector_input" + "sklearn.gaussian_process.kernels.Exponentiation.requires_vector_input@getter" ], "is_public": true, "description": "The Exponentiation kernel takes one base kernel and a scalar parameter :math:`p` and combines them via\n\n.. math:: k_{exp}(X, Y) = k(X, Y) ^p Note that the `__pow__` magic method is overridden, so `Exponentiation(RBF(), 2)` is equivalent to using the ** operator with `RBF() ** 2`. Read more in the :ref:`User Guide `. .. versionadded:: 0.18", @@ -22875,7 +22828,7 @@ "decorators": [], "superclasses": [], "methods": [ - "sklearn.gaussian_process.kernels.GenericKernelMixin.requires_vector_input" + "sklearn.gaussian_process.kernels.GenericKernelMixin.requires_vector_input@getter" ], "is_public": true, "description": "Mixin for kernels which operate on generic objects such as variable- length sequences, trees, and graphs.\n\n.. versionadded:: 0.22", @@ -22907,11 +22860,11 @@ "sklearn.gaussian_process.kernels.Kernel.get_params", "sklearn.gaussian_process.kernels.Kernel.set_params", "sklearn.gaussian_process.kernels.Kernel.clone_with_theta", - "sklearn.gaussian_process.kernels.Kernel.n_dims", - "sklearn.gaussian_process.kernels.Kernel.hyperparameters", - "sklearn.gaussian_process.kernels.Kernel.theta", - "sklearn.gaussian_process.kernels.Kernel.theta", - "sklearn.gaussian_process.kernels.Kernel.bounds", + "sklearn.gaussian_process.kernels.Kernel.n_dims@getter", + "sklearn.gaussian_process.kernels.Kernel.hyperparameters@getter", + "sklearn.gaussian_process.kernels.Kernel.theta@getter", + "sklearn.gaussian_process.kernels.Kernel.theta@setter", + "sklearn.gaussian_process.kernels.Kernel.bounds@getter", "sklearn.gaussian_process.kernels.Kernel.__add__", "sklearn.gaussian_process.kernels.Kernel.__radd__", "sklearn.gaussian_process.kernels.Kernel.__mul__", @@ -22922,7 +22875,7 @@ "sklearn.gaussian_process.kernels.Kernel.__call__", "sklearn.gaussian_process.kernels.Kernel.diag", "sklearn.gaussian_process.kernels.Kernel.is_stationary", - "sklearn.gaussian_process.kernels.Kernel.requires_vector_input", + "sklearn.gaussian_process.kernels.Kernel.requires_vector_input@getter", "sklearn.gaussian_process.kernels.Kernel._check_bounds_params" ], "is_public": true, @@ -22938,13 +22891,13 @@ "methods": [ "sklearn.gaussian_process.kernels.KernelOperator.__init__", "sklearn.gaussian_process.kernels.KernelOperator.get_params", - "sklearn.gaussian_process.kernels.KernelOperator.hyperparameters", - "sklearn.gaussian_process.kernels.KernelOperator.theta", - "sklearn.gaussian_process.kernels.KernelOperator.theta", - "sklearn.gaussian_process.kernels.KernelOperator.bounds", + "sklearn.gaussian_process.kernels.KernelOperator.hyperparameters@getter", + "sklearn.gaussian_process.kernels.KernelOperator.theta@getter", + "sklearn.gaussian_process.kernels.KernelOperator.theta@setter", + "sklearn.gaussian_process.kernels.KernelOperator.bounds@getter", "sklearn.gaussian_process.kernels.KernelOperator.__eq__", "sklearn.gaussian_process.kernels.KernelOperator.is_stationary", - "sklearn.gaussian_process.kernels.KernelOperator.requires_vector_input" + "sklearn.gaussian_process.kernels.KernelOperator.requires_vector_input@getter" ], "is_public": true, "description": "Base class for all kernel operators.\n\n.. versionadded:: 0.18", @@ -22986,7 +22939,7 @@ "superclasses": ["Kernel"], "methods": [ "sklearn.gaussian_process.kernels.PairwiseKernel.__init__", - "sklearn.gaussian_process.kernels.PairwiseKernel.hyperparameter_gamma", + "sklearn.gaussian_process.kernels.PairwiseKernel.hyperparameter_gamma@getter", "sklearn.gaussian_process.kernels.PairwiseKernel.__call__", "sklearn.gaussian_process.kernels.PairwiseKernel.diag", "sklearn.gaussian_process.kernels.PairwiseKernel.is_stationary", @@ -23023,8 +22976,8 @@ ], "methods": [ "sklearn.gaussian_process.kernels.RBF.__init__", - "sklearn.gaussian_process.kernels.RBF.anisotropic", - "sklearn.gaussian_process.kernels.RBF.hyperparameter_length_scale", + "sklearn.gaussian_process.kernels.RBF.anisotropic@getter", + "sklearn.gaussian_process.kernels.RBF.hyperparameter_length_scale@getter", "sklearn.gaussian_process.kernels.RBF.__call__", "sklearn.gaussian_process.kernels.RBF.__repr__" ], @@ -23044,15 +22997,15 @@ ], "methods": [ "sklearn.gaussian_process.kernels.RationalQuadratic.__init__", - "sklearn.gaussian_process.kernels.RationalQuadratic.hyperparameter_length_scale", - "sklearn.gaussian_process.kernels.RationalQuadratic.hyperparameter_alpha", + "sklearn.gaussian_process.kernels.RationalQuadratic.hyperparameter_length_scale@getter", + "sklearn.gaussian_process.kernels.RationalQuadratic.hyperparameter_alpha@getter", "sklearn.gaussian_process.kernels.RationalQuadratic.__call__", "sklearn.gaussian_process.kernels.RationalQuadratic.__repr__" ], "is_public": true, "description": "Rational Quadratic kernel.\n\nThe RationalQuadratic kernel can be seen as a scale mixture (an infinite sum) of RBF kernels with different characteristic length scales. It is parameterized by a length scale parameter :math:`l>0` and a scale mixture parameter :math:`\\alpha>0`. Only the isotropic variant where length_scale :math:`l` is a scalar is supported at the moment. The kernel is given by: .. math:: k(x_i, x_j) = \\left( 1 + \\frac{d(x_i, x_j)^2 }{ 2\\alpha l^2}\\right)^{-\\alpha} where :math:`\\alpha` is the scale mixture parameter, :math:`l` is the length scale of the kernel and :math:`d(\\cdot,\\cdot)` is the Euclidean distance. For advice on how to set the parameters, see e.g. [1]_. Read more in the :ref:`User Guide `. .. versionadded:: 0.18", - "docstring": "Rational Quadratic kernel.\n\n The RationalQuadratic kernel can be seen as a scale mixture (an infinite\n sum) of RBF kernels with different characteristic length scales. It is\n parameterized by a length scale parameter :math:`l>0` and a scale\n mixture parameter :math:`\\alpha>0`. Only the isotropic variant\n where length_scale :math:`l` is a scalar is supported at the moment.\n The kernel is given by:\n\n .. math::\n k(x_i, x_j) = \\left(\n 1 + \\frac{d(x_i, x_j)^2 }{ 2\\alpha l^2}\\right)^{-\\alpha}\n\n where :math:`\\alpha` is the scale mixture parameter, :math:`l` is\n the length scale of the kernel and :math:`d(\\cdot,\\cdot)` is the\n Euclidean distance.\n For advice on how to set the parameters, see e.g. [1]_.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.18\n\n Parameters\n ----------\n length_scale : float > 0, default=1.0\n The length scale of the kernel.\n\n alpha : float > 0, default=1.0\n Scale mixture parameter\n\n length_scale_bounds : pair of floats >= 0 or \"fixed\", default=(1e-5, 1e5)\n The lower and upper bound on 'length_scale'.\n If set to \"fixed\", 'length_scale' cannot be changed during\n hyperparameter tuning.\n\n alpha_bounds : pair of floats >= 0 or \"fixed\", default=(1e-5, 1e5)\n The lower and upper bound on 'alpha'.\n If set to \"fixed\", 'alpha' cannot be changed during\n hyperparameter tuning.\n\n References\n ----------\n .. [1] `David Duvenaud (2014). \"The Kernel Cookbook:\n Advice on Covariance functions\".\n `_\n\n Examples\n --------\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.gaussian_process import GaussianProcessClassifier\n >>> from sklearn.gaussian_process.kernels import Matern\n >>> X, y = load_iris(return_X_y=True)\n >>> kernel = RationalQuadratic(length_scale=1.0, alpha=1.5)\n >>> gpc = GaussianProcessClassifier(kernel=kernel,\n ... random_state=0).fit(X, y)\n >>> gpc.score(X, y)\n 0.9733...\n >>> gpc.predict_proba(X[:2,:])\n array([[0.8881..., 0.0566..., 0.05518...],\n [0.8678..., 0.0707... , 0.0614...]])\n ", - "source_code": "\n\nclass RationalQuadratic(StationaryKernelMixin, NormalizedKernelMixin, Kernel):\n \"\"\"Rational Quadratic kernel.\n\n The RationalQuadratic kernel can be seen as a scale mixture (an infinite\n sum) of RBF kernels with different characteristic length scales. It is\n parameterized by a length scale parameter :math:`l>0` and a scale\n mixture parameter :math:`\\alpha>0`. Only the isotropic variant\n where length_scale :math:`l` is a scalar is supported at the moment.\n The kernel is given by:\n\n .. math::\n k(x_i, x_j) = \\left(\n 1 + \\frac{d(x_i, x_j)^2 }{ 2\\alpha l^2}\\right)^{-\\alpha}\n\n where :math:`\\alpha` is the scale mixture parameter, :math:`l` is\n the length scale of the kernel and :math:`d(\\cdot,\\cdot)` is the\n Euclidean distance.\n For advice on how to set the parameters, see e.g. [1]_.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.18\n\n Parameters\n ----------\n length_scale : float > 0, default=1.0\n The length scale of the kernel.\n\n alpha : float > 0, default=1.0\n Scale mixture parameter\n\n length_scale_bounds : pair of floats >= 0 or \"fixed\", default=(1e-5, 1e5)\n The lower and upper bound on 'length_scale'.\n If set to \"fixed\", 'length_scale' cannot be changed during\n hyperparameter tuning.\n\n alpha_bounds : pair of floats >= 0 or \"fixed\", default=(1e-5, 1e5)\n The lower and upper bound on 'alpha'.\n If set to \"fixed\", 'alpha' cannot be changed during\n hyperparameter tuning.\n\n References\n ----------\n .. [1] `David Duvenaud (2014). \"The Kernel Cookbook:\n Advice on Covariance functions\".\n `_\n\n Examples\n --------\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.gaussian_process import GaussianProcessClassifier\n >>> from sklearn.gaussian_process.kernels import Matern\n >>> X, y = load_iris(return_X_y=True)\n >>> kernel = RationalQuadratic(length_scale=1.0, alpha=1.5)\n >>> gpc = GaussianProcessClassifier(kernel=kernel,\n ... random_state=0).fit(X, y)\n >>> gpc.score(X, y)\n 0.9733...\n >>> gpc.predict_proba(X[:2,:])\n array([[0.8881..., 0.0566..., 0.05518...],\n [0.8678..., 0.0707... , 0.0614...]])\n \"\"\"\n \n def __init__(self, length_scale=1.0, alpha=1.0, length_scale_bounds=(1e-05, 100000.0), alpha_bounds=(1e-05, 100000.0)):\n self.length_scale = length_scale\n self.alpha = alpha\n self.length_scale_bounds = length_scale_bounds\n self.alpha_bounds = alpha_bounds\n \n @property\n def hyperparameter_length_scale(self):\n return Hyperparameter('length_scale', 'numeric', self.length_scale_bounds)\n \n @property\n def hyperparameter_alpha(self):\n return Hyperparameter('alpha', 'numeric', self.alpha_bounds)\n \n def __call__(self, X, Y=None, eval_gradient=False):\n \"\"\"Return the kernel k(X, Y) and optionally its gradient.\n\n Parameters\n ----------\n X : ndarray of shape (n_samples_X, n_features)\n Left argument of the returned kernel k(X, Y)\n\n Y : ndarray of shape (n_samples_Y, n_features), default=None\n Right argument of the returned kernel k(X, Y). If None, k(X, X)\n if evaluated instead.\n\n eval_gradient : bool, default=False\n Determines whether the gradient with respect to the log of\n the kernel hyperparameter is computed.\n Only supported when Y is None.\n\n Returns\n -------\n K : ndarray of shape (n_samples_X, n_samples_Y)\n Kernel k(X, Y)\n\n K_gradient : ndarray of shape (n_samples_X, n_samples_X, n_dims)\n The gradient of the kernel k(X, X) with respect to the log of the\n hyperparameter of the kernel. Only returned when eval_gradient\n is True.\n \"\"\"\n if len(np.atleast_1d(self.length_scale)) > 1:\n raise AttributeError('RationalQuadratic kernel only supports isotropic version, please use a single scalar for length_scale')\n X = np.atleast_2d(X)\n if Y is None:\n dists = squareform(pdist(X, metric='sqeuclidean'))\n tmp = dists / (2 * self.alpha * self.length_scale**2)\n base = 1 + tmp\n K = base**(-self.alpha)\n np.fill_diagonal(K, 1)\n else:\n if eval_gradient:\n raise ValueError('Gradient can only be evaluated when Y is None.')\n dists = cdist(X, Y, metric='sqeuclidean')\n K = (1 + dists / (2 * self.alpha * self.length_scale**2))**(-self.alpha)\n if eval_gradient:\n if not self.hyperparameter_length_scale.fixed:\n length_scale_gradient = dists * K / (self.length_scale**2 * base)\n length_scale_gradient = length_scale_gradient[:, :, np.newaxis]\n else:\n length_scale_gradient = np.empty((K.shape[0], K.shape[1], 0))\n if not self.hyperparameter_alpha.fixed:\n alpha_gradient = K * (-self.alpha * np.log(base) + dists / (2 * self.length_scale**2 * base))\n alpha_gradient = alpha_gradient[:, :, np.newaxis]\n else:\n alpha_gradient = np.empty((K.shape[0], K.shape[1], 0))\n return K, np.dstack((alpha_gradient, length_scale_gradient))\n else:\n return K\n \n def __repr__(self):\n return '{0}(alpha={1:.3g}, length_scale={2:.3g})'.format(self.__class__.__name__, self.alpha, self.length_scale)\n" + "docstring": "Rational Quadratic kernel.\n\n The RationalQuadratic kernel can be seen as a scale mixture (an infinite\n sum) of RBF kernels with different characteristic length scales. It is\n parameterized by a length scale parameter :math:`l>0` and a scale\n mixture parameter :math:`\\alpha>0`. Only the isotropic variant\n where length_scale :math:`l` is a scalar is supported at the moment.\n The kernel is given by:\n\n .. math::\n k(x_i, x_j) = \\left(\n 1 + \\frac{d(x_i, x_j)^2 }{ 2\\alpha l^2}\\right)^{-\\alpha}\n\n where :math:`\\alpha` is the scale mixture parameter, :math:`l` is\n the length scale of the kernel and :math:`d(\\cdot,\\cdot)` is the\n Euclidean distance.\n For advice on how to set the parameters, see e.g. [1]_.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.18\n\n Parameters\n ----------\n length_scale : float > 0, default=1.0\n The length scale of the kernel.\n\n alpha : float > 0, default=1.0\n Scale mixture parameter\n\n length_scale_bounds : pair of floats >= 0 or \"fixed\", default=(1e-5, 1e5)\n The lower and upper bound on 'length_scale'.\n If set to \"fixed\", 'length_scale' cannot be changed during\n hyperparameter tuning.\n\n alpha_bounds : pair of floats >= 0 or \"fixed\", default=(1e-5, 1e5)\n The lower and upper bound on 'alpha'.\n If set to \"fixed\", 'alpha' cannot be changed during\n hyperparameter tuning.\n\n References\n ----------\n .. [1] `David Duvenaud (2014). \"The Kernel Cookbook:\n Advice on Covariance functions\".\n `_\n\n Examples\n --------\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.gaussian_process import GaussianProcessClassifier\n >>> from sklearn.gaussian_process.kernels import RationalQuadratic\n >>> X, y = load_iris(return_X_y=True)\n >>> kernel = RationalQuadratic(length_scale=1.0, alpha=1.5)\n >>> gpc = GaussianProcessClassifier(kernel=kernel,\n ... random_state=0).fit(X, y)\n >>> gpc.score(X, y)\n 0.9733...\n >>> gpc.predict_proba(X[:2,:])\n array([[0.8881..., 0.0566..., 0.05518...],\n [0.8678..., 0.0707... , 0.0614...]])\n ", + "source_code": "\n\nclass RationalQuadratic(StationaryKernelMixin, NormalizedKernelMixin, Kernel):\n \"\"\"Rational Quadratic kernel.\n\n The RationalQuadratic kernel can be seen as a scale mixture (an infinite\n sum) of RBF kernels with different characteristic length scales. It is\n parameterized by a length scale parameter :math:`l>0` and a scale\n mixture parameter :math:`\\alpha>0`. Only the isotropic variant\n where length_scale :math:`l` is a scalar is supported at the moment.\n The kernel is given by:\n\n .. math::\n k(x_i, x_j) = \\left(\n 1 + \\frac{d(x_i, x_j)^2 }{ 2\\alpha l^2}\\right)^{-\\alpha}\n\n where :math:`\\alpha` is the scale mixture parameter, :math:`l` is\n the length scale of the kernel and :math:`d(\\cdot,\\cdot)` is the\n Euclidean distance.\n For advice on how to set the parameters, see e.g. [1]_.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.18\n\n Parameters\n ----------\n length_scale : float > 0, default=1.0\n The length scale of the kernel.\n\n alpha : float > 0, default=1.0\n Scale mixture parameter\n\n length_scale_bounds : pair of floats >= 0 or \"fixed\", default=(1e-5, 1e5)\n The lower and upper bound on 'length_scale'.\n If set to \"fixed\", 'length_scale' cannot be changed during\n hyperparameter tuning.\n\n alpha_bounds : pair of floats >= 0 or \"fixed\", default=(1e-5, 1e5)\n The lower and upper bound on 'alpha'.\n If set to \"fixed\", 'alpha' cannot be changed during\n hyperparameter tuning.\n\n References\n ----------\n .. [1] `David Duvenaud (2014). \"The Kernel Cookbook:\n Advice on Covariance functions\".\n `_\n\n Examples\n --------\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.gaussian_process import GaussianProcessClassifier\n >>> from sklearn.gaussian_process.kernels import RationalQuadratic\n >>> X, y = load_iris(return_X_y=True)\n >>> kernel = RationalQuadratic(length_scale=1.0, alpha=1.5)\n >>> gpc = GaussianProcessClassifier(kernel=kernel,\n ... random_state=0).fit(X, y)\n >>> gpc.score(X, y)\n 0.9733...\n >>> gpc.predict_proba(X[:2,:])\n array([[0.8881..., 0.0566..., 0.05518...],\n [0.8678..., 0.0707... , 0.0614...]])\n \"\"\"\n \n def __init__(self, length_scale=1.0, alpha=1.0, length_scale_bounds=(1e-05, 100000.0), alpha_bounds=(1e-05, 100000.0)):\n self.length_scale = length_scale\n self.alpha = alpha\n self.length_scale_bounds = length_scale_bounds\n self.alpha_bounds = alpha_bounds\n \n @property\n def hyperparameter_length_scale(self):\n return Hyperparameter('length_scale', 'numeric', self.length_scale_bounds)\n \n @property\n def hyperparameter_alpha(self):\n return Hyperparameter('alpha', 'numeric', self.alpha_bounds)\n \n def __call__(self, X, Y=None, eval_gradient=False):\n \"\"\"Return the kernel k(X, Y) and optionally its gradient.\n\n Parameters\n ----------\n X : ndarray of shape (n_samples_X, n_features)\n Left argument of the returned kernel k(X, Y)\n\n Y : ndarray of shape (n_samples_Y, n_features), default=None\n Right argument of the returned kernel k(X, Y). If None, k(X, X)\n if evaluated instead.\n\n eval_gradient : bool, default=False\n Determines whether the gradient with respect to the log of\n the kernel hyperparameter is computed.\n Only supported when Y is None.\n\n Returns\n -------\n K : ndarray of shape (n_samples_X, n_samples_Y)\n Kernel k(X, Y)\n\n K_gradient : ndarray of shape (n_samples_X, n_samples_X, n_dims)\n The gradient of the kernel k(X, X) with respect to the log of the\n hyperparameter of the kernel. Only returned when eval_gradient\n is True.\n \"\"\"\n if len(np.atleast_1d(self.length_scale)) > 1:\n raise AttributeError('RationalQuadratic kernel only supports isotropic version, please use a single scalar for length_scale')\n X = np.atleast_2d(X)\n if Y is None:\n dists = squareform(pdist(X, metric='sqeuclidean'))\n tmp = dists / (2 * self.alpha * self.length_scale**2)\n base = 1 + tmp\n K = base**(-self.alpha)\n np.fill_diagonal(K, 1)\n else:\n if eval_gradient:\n raise ValueError('Gradient can only be evaluated when Y is None.')\n dists = cdist(X, Y, metric='sqeuclidean')\n K = (1 + dists / (2 * self.alpha * self.length_scale**2))**(-self.alpha)\n if eval_gradient:\n if not self.hyperparameter_length_scale.fixed:\n length_scale_gradient = dists * K / (self.length_scale**2 * base)\n length_scale_gradient = length_scale_gradient[:, :, np.newaxis]\n else:\n length_scale_gradient = np.empty((K.shape[0], K.shape[1], 0))\n if not self.hyperparameter_alpha.fixed:\n alpha_gradient = K * (-self.alpha * np.log(base) + dists / (2 * self.length_scale**2 * base))\n alpha_gradient = alpha_gradient[:, :, np.newaxis]\n else:\n alpha_gradient = np.empty((K.shape[0], K.shape[1], 0))\n return K, np.dstack((alpha_gradient, length_scale_gradient))\n else:\n return K\n \n def __repr__(self):\n return '{0}(alpha={1:.3g}, length_scale={2:.3g})'.format(self.__class__.__name__, self.alpha, self.length_scale)\n" }, { "name": "StationaryKernelMixin", @@ -23093,7 +23046,7 @@ ], "methods": [ "sklearn.gaussian_process.kernels.WhiteKernel.__init__", - "sklearn.gaussian_process.kernels.WhiteKernel.hyperparameter_noise_level", + "sklearn.gaussian_process.kernels.WhiteKernel.hyperparameter_noise_level@getter", "sklearn.gaussian_process.kernels.WhiteKernel.__call__", "sklearn.gaussian_process.kernels.WhiteKernel.diag", "sklearn.gaussian_process.kernels.WhiteKernel.__repr__" @@ -23120,8 +23073,8 @@ ], "is_public": true, "description": "Binary indicators for missing values.\n\nNote that this component typically should not be used in a vanilla :class:`Pipeline` consisting of transformers and a classifier, but rather could be added using a :class:`FeatureUnion` or :class:`ColumnTransformer`. Read more in the :ref:`User Guide `. .. versionadded:: 0.20", - "docstring": "Binary indicators for missing values.\n\n Note that this component typically should not be used in a vanilla\n :class:`Pipeline` consisting of transformers and a classifier, but rather\n could be added using a :class:`FeatureUnion` or :class:`ColumnTransformer`.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.20\n\n Parameters\n ----------\n missing_values : int, float, string, np.nan or None, default=np.nan\n The placeholder for the missing values. All occurrences of\n `missing_values` will be imputed. For pandas' dataframes with\n nullable integer dtypes with missing values, `missing_values`\n should be set to `np.nan`, since `pd.NA` will be converted to `np.nan`.\n\n features : {'missing-only', 'all'}, default='missing-only'\n Whether the imputer mask should represent all or a subset of\n features.\n\n - If 'missing-only' (default), the imputer mask will only represent\n features containing missing values during fit time.\n - If 'all', the imputer mask will represent all features.\n\n sparse : bool or 'auto', default='auto'\n Whether the imputer mask format should be sparse or dense.\n\n - If 'auto' (default), the imputer mask will be of same type as\n input.\n - If True, the imputer mask will be a sparse matrix.\n - If False, the imputer mask will be a numpy array.\n\n error_on_new : bool, default=True\n If True, transform will raise an error when there are features with\n missing values in transform that have no missing values in fit. This is\n applicable only when `features='missing-only'`.\n\n Attributes\n ----------\n features_ : ndarray, shape (n_missing_features,) or (n_features,)\n The features indices which will be returned when calling ``transform``.\n They are computed during ``fit``. For ``features='all'``, it is\n to ``range(n_features)``.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.impute import MissingIndicator\n >>> X1 = np.array([[np.nan, 1, 3],\n ... [4, 0, np.nan],\n ... [8, 1, 0]])\n >>> X2 = np.array([[5, 1, np.nan],\n ... [np.nan, 2, 3],\n ... [2, 4, 0]])\n >>> indicator = MissingIndicator()\n >>> indicator.fit(X1)\n MissingIndicator()\n >>> X2_tr = indicator.transform(X2)\n >>> X2_tr\n array([[False, True],\n [ True, False],\n [False, False]])\n\n ", - "source_code": "\n\nclass MissingIndicator(TransformerMixin, BaseEstimator):\n \"\"\"Binary indicators for missing values.\n\n Note that this component typically should not be used in a vanilla\n :class:`Pipeline` consisting of transformers and a classifier, but rather\n could be added using a :class:`FeatureUnion` or :class:`ColumnTransformer`.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.20\n\n Parameters\n ----------\n missing_values : int, float, string, np.nan or None, default=np.nan\n The placeholder for the missing values. All occurrences of\n `missing_values` will be imputed. For pandas' dataframes with\n nullable integer dtypes with missing values, `missing_values`\n should be set to `np.nan`, since `pd.NA` will be converted to `np.nan`.\n\n features : {'missing-only', 'all'}, default='missing-only'\n Whether the imputer mask should represent all or a subset of\n features.\n\n - If 'missing-only' (default), the imputer mask will only represent\n features containing missing values during fit time.\n - If 'all', the imputer mask will represent all features.\n\n sparse : bool or 'auto', default='auto'\n Whether the imputer mask format should be sparse or dense.\n\n - If 'auto' (default), the imputer mask will be of same type as\n input.\n - If True, the imputer mask will be a sparse matrix.\n - If False, the imputer mask will be a numpy array.\n\n error_on_new : bool, default=True\n If True, transform will raise an error when there are features with\n missing values in transform that have no missing values in fit. This is\n applicable only when `features='missing-only'`.\n\n Attributes\n ----------\n features_ : ndarray, shape (n_missing_features,) or (n_features,)\n The features indices which will be returned when calling ``transform``.\n They are computed during ``fit``. For ``features='all'``, it is\n to ``range(n_features)``.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.impute import MissingIndicator\n >>> X1 = np.array([[np.nan, 1, 3],\n ... [4, 0, np.nan],\n ... [8, 1, 0]])\n >>> X2 = np.array([[5, 1, np.nan],\n ... [np.nan, 2, 3],\n ... [2, 4, 0]])\n >>> indicator = MissingIndicator()\n >>> indicator.fit(X1)\n MissingIndicator()\n >>> X2_tr = indicator.transform(X2)\n >>> X2_tr\n array([[False, True],\n [ True, False],\n [False, False]])\n\n \"\"\"\n \n def __init__(self, *, missing_values=np.nan, features='missing-only', sparse='auto', error_on_new=True):\n self.missing_values = missing_values\n self.features = features\n self.sparse = sparse\n self.error_on_new = error_on_new\n \n def _get_missing_features_info(self, X):\n \"\"\"Compute the imputer mask and the indices of the features\n containing missing values.\n\n Parameters\n ----------\n X : {ndarray or sparse matrix}, shape (n_samples, n_features)\n The input data with missing values. Note that ``X`` has been\n checked in ``fit`` and ``transform`` before to call this function.\n\n Returns\n -------\n imputer_mask : {ndarray or sparse matrix}, shape (n_samples, n_features)\n The imputer mask of the original data.\n\n features_with_missing : ndarray, shape (n_features_with_missing)\n The features containing missing values.\n\n \"\"\"\n if not self._precomputed:\n imputer_mask = _get_mask(X, self.missing_values)\n else:\n imputer_mask = X\n if sp.issparse(X):\n imputer_mask.eliminate_zeros()\n if self.features == 'missing-only':\n n_missing = imputer_mask.getnnz(axis=0)\n if self.sparse is False:\n imputer_mask = imputer_mask.toarray()\n elif imputer_mask.format == 'csr':\n imputer_mask = imputer_mask.tocsc()\n else:\n if not self._precomputed:\n imputer_mask = _get_mask(X, self.missing_values)\n else:\n imputer_mask = X\n if self.features == 'missing-only':\n n_missing = imputer_mask.sum(axis=0)\n if self.sparse is True:\n imputer_mask = sp.csc_matrix(imputer_mask)\n if self.features == 'all':\n features_indices = np.arange(X.shape[1])\n else:\n features_indices = np.flatnonzero(n_missing)\n return imputer_mask, features_indices\n \n def _validate_input(self, X, in_fit):\n if not is_scalar_nan(self.missing_values):\n force_all_finite = True\n else:\n force_all_finite = 'allow-nan'\n X = self._validate_data(X, reset=in_fit, accept_sparse=('csc', 'csr'), dtype=None, force_all_finite=force_all_finite)\n _check_inputs_dtype(X, self.missing_values)\n if X.dtype.kind not in ('i', 'u', 'f', 'O'):\n raise ValueError('MissingIndicator does not support data with dtype {0}. Please provide either a numeric array (with a floating point or integer dtype) or categorical data represented either as an array with integer dtype or an array of string values with an object dtype.'.format(X.dtype))\n if sp.issparse(X) and self.missing_values == 0:\n raise ValueError('Sparse input with missing_values=0 is not supported. Provide a dense array instead.')\n return X\n \n def _fit(self, X, y=None, precomputed=False):\n \"\"\"Fit the transformer on X.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Input data, where ``n_samples`` is the number of samples and\n ``n_features`` is the number of features.\n If `precomputed` is True, then `X` is a mask of the\n input data.\n\n precomputed : bool\n Whether the input data is a mask.\n\n Returns\n -------\n imputer_mask : {ndarray or sparse matrix}, shape (n_samples, n_features)\n The imputer mask of the original data.\n\n \"\"\"\n if precomputed:\n if not (hasattr(X, 'dtype') and X.dtype.kind == 'b'):\n raise ValueError('precomputed is True but the input data is not a mask')\n self._precomputed = True\n else:\n self._precomputed = False\n if not self._precomputed:\n X = self._validate_input(X, in_fit=True)\n self._n_features = X.shape[1]\n if self.features not in ('missing-only', 'all'):\n raise ValueError(\"'features' has to be either 'missing-only' or 'all'. Got {} instead.\".format(self.features))\n if not (isinstance(self.sparse, str) and self.sparse == 'auto' or isinstance(self.sparse, bool)):\n raise ValueError(\"'sparse' has to be a boolean or 'auto'. Got {!r} instead.\".format(self.sparse))\n missing_features_info = self._get_missing_features_info(X)\n self.features_ = missing_features_info[1]\n return missing_features_info[0]\n \n def fit(self, X, y=None):\n \"\"\"Fit the transformer on X.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Input data, where ``n_samples`` is the number of samples and\n ``n_features`` is the number of features.\n\n Returns\n -------\n self : object\n Returns self.\n \"\"\"\n self._fit(X, y)\n return self\n \n def transform(self, X):\n \"\"\"Generate missing values indicator for X.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n The input data to complete.\n\n Returns\n -------\n Xt : {ndarray or sparse matrix}, shape (n_samples, n_features) or (n_samples, n_features_with_missing)\n The missing indicator for input data. The data type of ``Xt``\n will be boolean.\n\n \"\"\"\n check_is_fitted(self)\n if not self._precomputed:\n X = self._validate_input(X, in_fit=False)\n elif not (hasattr(X, 'dtype') and X.dtype.kind == 'b'):\n raise ValueError('precomputed is True but the input data is not a mask')\n (imputer_mask, features) = self._get_missing_features_info(X)\n if self.features == 'missing-only':\n features_diff_fit_trans = np.setdiff1d(features, self.features_)\n if self.error_on_new and features_diff_fit_trans.size > 0:\n raise ValueError('The features {} have missing values in transform but have no missing values in fit.'.format(features_diff_fit_trans))\n if self.features_.size < self._n_features:\n imputer_mask = imputer_mask[:, self.features_]\n return imputer_mask\n \n def fit_transform(self, X, y=None):\n \"\"\"Generate missing values indicator for X.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n The input data to complete.\n\n Returns\n -------\n Xt : {ndarray or sparse matrix}, shape (n_samples, n_features) or (n_samples, n_features_with_missing)\n The missing indicator for input data. The data type of ``Xt``\n will be boolean.\n\n \"\"\"\n imputer_mask = self._fit(X, y)\n if self.features_.size < self._n_features:\n imputer_mask = imputer_mask[:, self.features_]\n return imputer_mask\n \n def _more_tags(self):\n return {'allow_nan': True, 'X_types': ['2darray', 'string'], 'preserves_dtype': []}\n" + "docstring": "Binary indicators for missing values.\n\n Note that this component typically should not be used in a vanilla\n :class:`Pipeline` consisting of transformers and a classifier, but rather\n could be added using a :class:`FeatureUnion` or :class:`ColumnTransformer`.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.20\n\n Parameters\n ----------\n missing_values : int, float, str, np.nan or None, default=np.nan\n The placeholder for the missing values. All occurrences of\n `missing_values` will be imputed. For pandas' dataframes with\n nullable integer dtypes with missing values, `missing_values`\n should be set to `np.nan`, since `pd.NA` will be converted to `np.nan`.\n\n features : {'missing-only', 'all'}, default='missing-only'\n Whether the imputer mask should represent all or a subset of\n features.\n\n - If `'missing-only'` (default), the imputer mask will only represent\n features containing missing values during fit time.\n - If `'all'`, the imputer mask will represent all features.\n\n sparse : bool or 'auto', default='auto'\n Whether the imputer mask format should be sparse or dense.\n\n - If `'auto'` (default), the imputer mask will be of same type as\n input.\n - If `True`, the imputer mask will be a sparse matrix.\n - If `False`, the imputer mask will be a numpy array.\n\n error_on_new : bool, default=True\n If `True`, :meth:`transform` will raise an error when there are\n features with missing values that have no missing values in\n :meth:`fit`. This is applicable only when `features='missing-only'`.\n\n Attributes\n ----------\n features_ : ndarray of shape (n_missing_features,) or (n_features,)\n The features indices which will be returned when calling\n :meth:`transform`. They are computed during :meth:`fit`. If\n `features='all'`, `features_` is equal to `range(n_features)`.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n SimpleImputer : Univariate imputation of missing values.\n IterativeImputer : Multivariate imputation of missing values.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.impute import MissingIndicator\n >>> X1 = np.array([[np.nan, 1, 3],\n ... [4, 0, np.nan],\n ... [8, 1, 0]])\n >>> X2 = np.array([[5, 1, np.nan],\n ... [np.nan, 2, 3],\n ... [2, 4, 0]])\n >>> indicator = MissingIndicator()\n >>> indicator.fit(X1)\n MissingIndicator()\n >>> X2_tr = indicator.transform(X2)\n >>> X2_tr\n array([[False, True],\n [ True, False],\n [False, False]])\n ", + "source_code": "\n\nclass MissingIndicator(TransformerMixin, BaseEstimator):\n \"\"\"Binary indicators for missing values.\n\n Note that this component typically should not be used in a vanilla\n :class:`Pipeline` consisting of transformers and a classifier, but rather\n could be added using a :class:`FeatureUnion` or :class:`ColumnTransformer`.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.20\n\n Parameters\n ----------\n missing_values : int, float, str, np.nan or None, default=np.nan\n The placeholder for the missing values. All occurrences of\n `missing_values` will be imputed. For pandas' dataframes with\n nullable integer dtypes with missing values, `missing_values`\n should be set to `np.nan`, since `pd.NA` will be converted to `np.nan`.\n\n features : {'missing-only', 'all'}, default='missing-only'\n Whether the imputer mask should represent all or a subset of\n features.\n\n - If `'missing-only'` (default), the imputer mask will only represent\n features containing missing values during fit time.\n - If `'all'`, the imputer mask will represent all features.\n\n sparse : bool or 'auto', default='auto'\n Whether the imputer mask format should be sparse or dense.\n\n - If `'auto'` (default), the imputer mask will be of same type as\n input.\n - If `True`, the imputer mask will be a sparse matrix.\n - If `False`, the imputer mask will be a numpy array.\n\n error_on_new : bool, default=True\n If `True`, :meth:`transform` will raise an error when there are\n features with missing values that have no missing values in\n :meth:`fit`. This is applicable only when `features='missing-only'`.\n\n Attributes\n ----------\n features_ : ndarray of shape (n_missing_features,) or (n_features,)\n The features indices which will be returned when calling\n :meth:`transform`. They are computed during :meth:`fit`. If\n `features='all'`, `features_` is equal to `range(n_features)`.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n SimpleImputer : Univariate imputation of missing values.\n IterativeImputer : Multivariate imputation of missing values.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.impute import MissingIndicator\n >>> X1 = np.array([[np.nan, 1, 3],\n ... [4, 0, np.nan],\n ... [8, 1, 0]])\n >>> X2 = np.array([[5, 1, np.nan],\n ... [np.nan, 2, 3],\n ... [2, 4, 0]])\n >>> indicator = MissingIndicator()\n >>> indicator.fit(X1)\n MissingIndicator()\n >>> X2_tr = indicator.transform(X2)\n >>> X2_tr\n array([[False, True],\n [ True, False],\n [False, False]])\n \"\"\"\n \n def __init__(self, *, missing_values=np.nan, features='missing-only', sparse='auto', error_on_new=True):\n self.missing_values = missing_values\n self.features = features\n self.sparse = sparse\n self.error_on_new = error_on_new\n \n def _get_missing_features_info(self, X):\n \"\"\"Compute the imputer mask and the indices of the features\n containing missing values.\n\n Parameters\n ----------\n X : {ndarray, sparse matrix} of shape (n_samples, n_features)\n The input data with missing values. Note that `X` has been\n checked in :meth:`fit` and :meth:`transform` before to call this\n function.\n\n Returns\n -------\n imputer_mask : {ndarray, sparse matrix} of shape (n_samples, n_features)\n The imputer mask of the original data.\n\n features_with_missing : ndarray of shape (n_features_with_missing)\n The features containing missing values.\n \"\"\"\n if not self._precomputed:\n imputer_mask = _get_mask(X, self.missing_values)\n else:\n imputer_mask = X\n if sp.issparse(X):\n imputer_mask.eliminate_zeros()\n if self.features == 'missing-only':\n n_missing = imputer_mask.getnnz(axis=0)\n if self.sparse is False:\n imputer_mask = imputer_mask.toarray()\n elif imputer_mask.format == 'csr':\n imputer_mask = imputer_mask.tocsc()\n else:\n if not self._precomputed:\n imputer_mask = _get_mask(X, self.missing_values)\n else:\n imputer_mask = X\n if self.features == 'missing-only':\n n_missing = imputer_mask.sum(axis=0)\n if self.sparse is True:\n imputer_mask = sp.csc_matrix(imputer_mask)\n if self.features == 'all':\n features_indices = np.arange(X.shape[1])\n else:\n features_indices = np.flatnonzero(n_missing)\n return imputer_mask, features_indices\n \n def _validate_input(self, X, in_fit):\n if not is_scalar_nan(self.missing_values):\n force_all_finite = True\n else:\n force_all_finite = 'allow-nan'\n X = self._validate_data(X, reset=in_fit, accept_sparse=('csc', 'csr'), dtype=None, force_all_finite=force_all_finite)\n _check_inputs_dtype(X, self.missing_values)\n if X.dtype.kind not in ('i', 'u', 'f', 'O'):\n raise ValueError('MissingIndicator does not support data with dtype {0}. Please provide either a numeric array (with a floating point or integer dtype) or categorical data represented either as an array with integer dtype or an array of string values with an object dtype.'.format(X.dtype))\n if sp.issparse(X) and self.missing_values == 0:\n raise ValueError('Sparse input with missing_values=0 is not supported. Provide a dense array instead.')\n return X\n \n def _fit(self, X, y=None, precomputed=False):\n \"\"\"Fit the transformer on `X`.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input data, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n If `precomputed=True`, then `X` is a mask of the input data.\n\n precomputed : bool\n Whether the input data is a mask.\n\n Returns\n -------\n imputer_mask : {ndarray, sparse matrix} of shape (n_samples, n_features)\n The imputer mask of the original data.\n \"\"\"\n if precomputed:\n if not (hasattr(X, 'dtype') and X.dtype.kind == 'b'):\n raise ValueError('precomputed is True but the input data is not a mask')\n self._precomputed = True\n else:\n self._precomputed = False\n if not self._precomputed:\n X = self._validate_input(X, in_fit=True)\n self._n_features = X.shape[1]\n if self.features not in ('missing-only', 'all'):\n raise ValueError(\"'features' has to be either 'missing-only' or 'all'. Got {} instead.\".format(self.features))\n if not (isinstance(self.sparse, str) and self.sparse == 'auto' or isinstance(self.sparse, bool)):\n raise ValueError(\"'sparse' has to be a boolean or 'auto'. Got {!r} instead.\".format(self.sparse))\n missing_features_info = self._get_missing_features_info(X)\n self.features_ = missing_features_info[1]\n return missing_features_info[0]\n \n def fit(self, X, y=None):\n \"\"\"Fit the transformer on `X`.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input data, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n self._fit(X, y)\n return self\n \n def transform(self, X):\n \"\"\"Generate missing values indicator for `X`.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The input data to complete.\n\n Returns\n -------\n Xt : {ndarray, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_features_with_missing)\n The missing indicator for input data. The data type of `Xt`\n will be boolean.\n \"\"\"\n check_is_fitted(self)\n if not self._precomputed:\n X = self._validate_input(X, in_fit=False)\n elif not (hasattr(X, 'dtype') and X.dtype.kind == 'b'):\n raise ValueError('precomputed is True but the input data is not a mask')\n (imputer_mask, features) = self._get_missing_features_info(X)\n if self.features == 'missing-only':\n features_diff_fit_trans = np.setdiff1d(features, self.features_)\n if self.error_on_new and features_diff_fit_trans.size > 0:\n raise ValueError('The features {} have missing values in transform but have no missing values in fit.'.format(features_diff_fit_trans))\n if self.features_.size < self._n_features:\n imputer_mask = imputer_mask[:, self.features_]\n return imputer_mask\n \n def fit_transform(self, X, y=None):\n \"\"\"Generate missing values indicator for `X`.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The input data to complete.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n Xt : {ndarray, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_features_with_missing)\n The missing indicator for input data. The data type of `Xt`\n will be boolean.\n \"\"\"\n imputer_mask = self._fit(X, y)\n if self.features_.size < self._n_features:\n imputer_mask = imputer_mask[:, self.features_]\n return imputer_mask\n \n def _more_tags(self):\n return {'allow_nan': True, 'X_types': ['2darray', 'string'], 'preserves_dtype': []}\n" }, { "name": "SimpleImputer", @@ -23177,9 +23130,9 @@ "sklearn.impute._iterative.IterativeImputer.fit" ], "is_public": true, - "description": "Multivariate imputer that estimates each feature from all the others.\n\nA strategy for imputing missing values by modeling each feature with missing values as a function of other features in a round-robin fashion. Read more in the :ref:`User Guide `. .. versionadded:: 0.21 .. note:: This estimator is still **experimental** for now: the predictions and the API might change without any deprecation cycle. To use it, you need to explicitly import ``enable_iterative_imputer``:: >>> # explicitly require this experimental feature >>> from sklearn.experimental import enable_iterative_imputer # noqa >>> # now you can import normally from sklearn.impute >>> from sklearn.impute import IterativeImputer", - "docstring": "Multivariate imputer that estimates each feature from all the others.\n\n A strategy for imputing missing values by modeling each feature with\n missing values as a function of other features in a round-robin fashion.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.21\n\n .. note::\n\n This estimator is still **experimental** for now: the predictions\n and the API might change without any deprecation cycle. To use it,\n you need to explicitly import ``enable_iterative_imputer``::\n\n >>> # explicitly require this experimental feature\n >>> from sklearn.experimental import enable_iterative_imputer # noqa\n >>> # now you can import normally from sklearn.impute\n >>> from sklearn.impute import IterativeImputer\n\n Parameters\n ----------\n estimator : estimator object, default=BayesianRidge()\n The estimator to use at each step of the round-robin imputation.\n If ``sample_posterior`` is True, the estimator must support\n ``return_std`` in its ``predict`` method.\n\n missing_values : int, np.nan, default=np.nan\n The placeholder for the missing values. All occurrences of\n `missing_values` will be imputed. For pandas' dataframes with\n nullable integer dtypes with missing values, `missing_values`\n should be set to `np.nan`, since `pd.NA` will be converted to `np.nan`.\n\n sample_posterior : boolean, default=False\n Whether to sample from the (Gaussian) predictive posterior of the\n fitted estimator for each imputation. Estimator must support\n ``return_std`` in its ``predict`` method if set to ``True``. Set to\n ``True`` if using ``IterativeImputer`` for multiple imputations.\n\n max_iter : int, default=10\n Maximum number of imputation rounds to perform before returning the\n imputations computed during the final round. A round is a single\n imputation of each feature with missing values. The stopping criterion\n is met once `max(abs(X_t - X_{t-1}))/max(abs(X[known_vals])) < tol`,\n where `X_t` is `X` at iteration `t`. Note that early stopping is only\n applied if ``sample_posterior=False``.\n\n tol : float, default=1e-3\n Tolerance of the stopping condition.\n\n n_nearest_features : int, default=None\n Number of other features to use to estimate the missing values of\n each feature column. Nearness between features is measured using\n the absolute correlation coefficient between each feature pair (after\n initial imputation). To ensure coverage of features throughout the\n imputation process, the neighbor features are not necessarily nearest,\n but are drawn with probability proportional to correlation for each\n imputed target feature. Can provide significant speed-up when the\n number of features is huge. If ``None``, all features will be used.\n\n initial_strategy : str, default='mean'\n Which strategy to use to initialize the missing values. Same as the\n ``strategy`` parameter in :class:`~sklearn.impute.SimpleImputer`\n Valid values: {\"mean\", \"median\", \"most_frequent\", or \"constant\"}.\n\n imputation_order : str, default='ascending'\n The order in which the features will be imputed. Possible values:\n\n \"ascending\"\n From features with fewest missing values to most.\n \"descending\"\n From features with most missing values to fewest.\n \"roman\"\n Left to right.\n \"arabic\"\n Right to left.\n \"random\"\n A random order for each round.\n\n skip_complete : boolean, default=False\n If ``True`` then features with missing values during ``transform``\n which did not have any missing values during ``fit`` will be imputed\n with the initial imputation method only. Set to ``True`` if you have\n many features with no missing values at both ``fit`` and ``transform``\n time to save compute.\n\n min_value : float or array-like of shape (n_features,), default=-np.inf\n Minimum possible imputed value. Broadcast to shape (n_features,) if\n scalar. If array-like, expects shape (n_features,), one min value for\n each feature. The default is `-np.inf`.\n\n .. versionchanged:: 0.23\n Added support for array-like.\n\n max_value : float or array-like of shape (n_features,), default=np.inf\n Maximum possible imputed value. Broadcast to shape (n_features,) if\n scalar. If array-like, expects shape (n_features,), one max value for\n each feature. The default is `np.inf`.\n\n .. versionchanged:: 0.23\n Added support for array-like.\n\n verbose : int, default=0\n Verbosity flag, controls the debug messages that are issued\n as functions are evaluated. The higher, the more verbose. Can be 0, 1,\n or 2.\n\n random_state : int, RandomState instance or None, default=None\n The seed of the pseudo random number generator to use. Randomizes\n selection of estimator features if n_nearest_features is not None, the\n ``imputation_order`` if ``random``, and the sampling from posterior if\n ``sample_posterior`` is True. Use an integer for determinism.\n See :term:`the Glossary `.\n\n add_indicator : boolean, default=False\n If True, a :class:`MissingIndicator` transform will stack onto output\n of the imputer's transform. This allows a predictive estimator\n to account for missingness despite imputation. If a feature has no\n missing values at fit/train time, the feature won't appear on\n the missing indicator even if there are missing values at\n transform/test time.\n\n Attributes\n ----------\n initial_imputer_ : object of type :class:`~sklearn.impute.SimpleImputer`\n Imputer used to initialize the missing values.\n\n imputation_sequence_ : list of tuples\n Each tuple has ``(feat_idx, neighbor_feat_idx, estimator)``, where\n ``feat_idx`` is the current feature to be imputed,\n ``neighbor_feat_idx`` is the array of other features used to impute the\n current feature, and ``estimator`` is the trained estimator used for\n the imputation. Length is ``self.n_features_with_missing_ *\n self.n_iter_``.\n\n n_iter_ : int\n Number of iteration rounds that occurred. Will be less than\n ``self.max_iter`` if early stopping criterion was reached.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_features_with_missing_ : int\n Number of features with missing values.\n\n indicator_ : :class:`~sklearn.impute.MissingIndicator`\n Indicator used to add binary indicators for missing values.\n ``None`` if add_indicator is False.\n\n random_state_ : RandomState instance\n RandomState instance that is generated either from a seed, the random\n number generator or by `np.random`.\n\n See Also\n --------\n SimpleImputer : Univariate imputation of missing values.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.experimental import enable_iterative_imputer\n >>> from sklearn.impute import IterativeImputer\n >>> imp_mean = IterativeImputer(random_state=0)\n >>> imp_mean.fit([[7, 2, 3], [4, np.nan, 6], [10, 5, 9]])\n IterativeImputer(random_state=0)\n >>> X = [[np.nan, 2, 3], [4, np.nan, 6], [10, np.nan, 9]]\n >>> imp_mean.transform(X)\n array([[ 6.9584..., 2. , 3. ],\n [ 4. , 2.6000..., 6. ],\n [10. , 4.9999..., 9. ]])\n\n Notes\n -----\n To support imputation in inductive mode we store each feature's estimator\n during the ``fit`` phase, and predict without refitting (in order) during\n the ``transform`` phase.\n\n Features which contain all missing values at ``fit`` are discarded upon\n ``transform``.\n\n References\n ----------\n .. [1] `Stef van Buuren, Karin Groothuis-Oudshoorn (2011). \"mice:\n Multivariate Imputation by Chained Equations in R\". Journal of\n Statistical Software 45: 1-67.\n `_\n\n .. [2] `S. F. Buck, (1960). \"A Method of Estimation of Missing Values in\n Multivariate Data Suitable for use with an Electronic Computer\".\n Journal of the Royal Statistical Society 22(2): 302-306.\n `_\n ", - "source_code": "\n\nclass IterativeImputer(_BaseImputer):\n \"\"\"Multivariate imputer that estimates each feature from all the others.\n\n A strategy for imputing missing values by modeling each feature with\n missing values as a function of other features in a round-robin fashion.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.21\n\n .. note::\n\n This estimator is still **experimental** for now: the predictions\n and the API might change without any deprecation cycle. To use it,\n you need to explicitly import ``enable_iterative_imputer``::\n\n >>> # explicitly require this experimental feature\n >>> from sklearn.experimental import enable_iterative_imputer # noqa\n >>> # now you can import normally from sklearn.impute\n >>> from sklearn.impute import IterativeImputer\n\n Parameters\n ----------\n estimator : estimator object, default=BayesianRidge()\n The estimator to use at each step of the round-robin imputation.\n If ``sample_posterior`` is True, the estimator must support\n ``return_std`` in its ``predict`` method.\n\n missing_values : int, np.nan, default=np.nan\n The placeholder for the missing values. All occurrences of\n `missing_values` will be imputed. For pandas' dataframes with\n nullable integer dtypes with missing values, `missing_values`\n should be set to `np.nan`, since `pd.NA` will be converted to `np.nan`.\n\n sample_posterior : boolean, default=False\n Whether to sample from the (Gaussian) predictive posterior of the\n fitted estimator for each imputation. Estimator must support\n ``return_std`` in its ``predict`` method if set to ``True``. Set to\n ``True`` if using ``IterativeImputer`` for multiple imputations.\n\n max_iter : int, default=10\n Maximum number of imputation rounds to perform before returning the\n imputations computed during the final round. A round is a single\n imputation of each feature with missing values. The stopping criterion\n is met once `max(abs(X_t - X_{t-1}))/max(abs(X[known_vals])) < tol`,\n where `X_t` is `X` at iteration `t`. Note that early stopping is only\n applied if ``sample_posterior=False``.\n\n tol : float, default=1e-3\n Tolerance of the stopping condition.\n\n n_nearest_features : int, default=None\n Number of other features to use to estimate the missing values of\n each feature column. Nearness between features is measured using\n the absolute correlation coefficient between each feature pair (after\n initial imputation). To ensure coverage of features throughout the\n imputation process, the neighbor features are not necessarily nearest,\n but are drawn with probability proportional to correlation for each\n imputed target feature. Can provide significant speed-up when the\n number of features is huge. If ``None``, all features will be used.\n\n initial_strategy : str, default='mean'\n Which strategy to use to initialize the missing values. Same as the\n ``strategy`` parameter in :class:`~sklearn.impute.SimpleImputer`\n Valid values: {\"mean\", \"median\", \"most_frequent\", or \"constant\"}.\n\n imputation_order : str, default='ascending'\n The order in which the features will be imputed. Possible values:\n\n \"ascending\"\n From features with fewest missing values to most.\n \"descending\"\n From features with most missing values to fewest.\n \"roman\"\n Left to right.\n \"arabic\"\n Right to left.\n \"random\"\n A random order for each round.\n\n skip_complete : boolean, default=False\n If ``True`` then features with missing values during ``transform``\n which did not have any missing values during ``fit`` will be imputed\n with the initial imputation method only. Set to ``True`` if you have\n many features with no missing values at both ``fit`` and ``transform``\n time to save compute.\n\n min_value : float or array-like of shape (n_features,), default=-np.inf\n Minimum possible imputed value. Broadcast to shape (n_features,) if\n scalar. If array-like, expects shape (n_features,), one min value for\n each feature. The default is `-np.inf`.\n\n .. versionchanged:: 0.23\n Added support for array-like.\n\n max_value : float or array-like of shape (n_features,), default=np.inf\n Maximum possible imputed value. Broadcast to shape (n_features,) if\n scalar. If array-like, expects shape (n_features,), one max value for\n each feature. The default is `np.inf`.\n\n .. versionchanged:: 0.23\n Added support for array-like.\n\n verbose : int, default=0\n Verbosity flag, controls the debug messages that are issued\n as functions are evaluated. The higher, the more verbose. Can be 0, 1,\n or 2.\n\n random_state : int, RandomState instance or None, default=None\n The seed of the pseudo random number generator to use. Randomizes\n selection of estimator features if n_nearest_features is not None, the\n ``imputation_order`` if ``random``, and the sampling from posterior if\n ``sample_posterior`` is True. Use an integer for determinism.\n See :term:`the Glossary `.\n\n add_indicator : boolean, default=False\n If True, a :class:`MissingIndicator` transform will stack onto output\n of the imputer's transform. This allows a predictive estimator\n to account for missingness despite imputation. If a feature has no\n missing values at fit/train time, the feature won't appear on\n the missing indicator even if there are missing values at\n transform/test time.\n\n Attributes\n ----------\n initial_imputer_ : object of type :class:`~sklearn.impute.SimpleImputer`\n Imputer used to initialize the missing values.\n\n imputation_sequence_ : list of tuples\n Each tuple has ``(feat_idx, neighbor_feat_idx, estimator)``, where\n ``feat_idx`` is the current feature to be imputed,\n ``neighbor_feat_idx`` is the array of other features used to impute the\n current feature, and ``estimator`` is the trained estimator used for\n the imputation. Length is ``self.n_features_with_missing_ *\n self.n_iter_``.\n\n n_iter_ : int\n Number of iteration rounds that occurred. Will be less than\n ``self.max_iter`` if early stopping criterion was reached.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_features_with_missing_ : int\n Number of features with missing values.\n\n indicator_ : :class:`~sklearn.impute.MissingIndicator`\n Indicator used to add binary indicators for missing values.\n ``None`` if add_indicator is False.\n\n random_state_ : RandomState instance\n RandomState instance that is generated either from a seed, the random\n number generator or by `np.random`.\n\n See Also\n --------\n SimpleImputer : Univariate imputation of missing values.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.experimental import enable_iterative_imputer\n >>> from sklearn.impute import IterativeImputer\n >>> imp_mean = IterativeImputer(random_state=0)\n >>> imp_mean.fit([[7, 2, 3], [4, np.nan, 6], [10, 5, 9]])\n IterativeImputer(random_state=0)\n >>> X = [[np.nan, 2, 3], [4, np.nan, 6], [10, np.nan, 9]]\n >>> imp_mean.transform(X)\n array([[ 6.9584..., 2. , 3. ],\n [ 4. , 2.6000..., 6. ],\n [10. , 4.9999..., 9. ]])\n\n Notes\n -----\n To support imputation in inductive mode we store each feature's estimator\n during the ``fit`` phase, and predict without refitting (in order) during\n the ``transform`` phase.\n\n Features which contain all missing values at ``fit`` are discarded upon\n ``transform``.\n\n References\n ----------\n .. [1] `Stef van Buuren, Karin Groothuis-Oudshoorn (2011). \"mice:\n Multivariate Imputation by Chained Equations in R\". Journal of\n Statistical Software 45: 1-67.\n `_\n\n .. [2] `S. F. Buck, (1960). \"A Method of Estimation of Missing Values in\n Multivariate Data Suitable for use with an Electronic Computer\".\n Journal of the Royal Statistical Society 22(2): 302-306.\n `_\n \"\"\"\n \n def __init__(self, estimator=None, *, missing_values=np.nan, sample_posterior=False, max_iter=10, tol=0.001, n_nearest_features=None, initial_strategy='mean', imputation_order='ascending', skip_complete=False, min_value=-np.inf, max_value=np.inf, verbose=0, random_state=None, add_indicator=False):\n super().__init__(missing_values=missing_values, add_indicator=add_indicator)\n self.estimator = estimator\n self.sample_posterior = sample_posterior\n self.max_iter = max_iter\n self.tol = tol\n self.n_nearest_features = n_nearest_features\n self.initial_strategy = initial_strategy\n self.imputation_order = imputation_order\n self.skip_complete = skip_complete\n self.min_value = min_value\n self.max_value = max_value\n self.verbose = verbose\n self.random_state = random_state\n \n def _impute_one_feature(self, X_filled, mask_missing_values, feat_idx, neighbor_feat_idx, estimator=None, fit_mode=True):\n \"\"\"Impute a single feature from the others provided.\n\n This function predicts the missing values of one of the features using\n the current estimates of all the other features. The ``estimator`` must\n support ``return_std=True`` in its ``predict`` method for this function\n to work.\n\n Parameters\n ----------\n X_filled : ndarray\n Input data with the most recent imputations.\n\n mask_missing_values : ndarray\n Input data's missing indicator matrix.\n\n feat_idx : int\n Index of the feature currently being imputed.\n\n neighbor_feat_idx : ndarray\n Indices of the features to be used in imputing ``feat_idx``.\n\n estimator : object\n The estimator to use at this step of the round-robin imputation.\n If ``sample_posterior`` is True, the estimator must support\n ``return_std`` in its ``predict`` method.\n If None, it will be cloned from self._estimator.\n\n fit_mode : boolean, default=True\n Whether to fit and predict with the estimator or just predict.\n\n Returns\n -------\n X_filled : ndarray\n Input data with ``X_filled[missing_row_mask, feat_idx]`` updated.\n\n estimator : estimator with sklearn API\n The fitted estimator used to impute\n ``X_filled[missing_row_mask, feat_idx]``.\n \"\"\"\n if estimator is None and fit_mode is False:\n raise ValueError('If fit_mode is False, then an already-fitted estimator should be passed in.')\n if estimator is None:\n estimator = clone(self._estimator)\n missing_row_mask = mask_missing_values[:, feat_idx]\n if fit_mode:\n X_train = _safe_indexing(X_filled[:, neighbor_feat_idx], ~missing_row_mask)\n y_train = _safe_indexing(X_filled[:, feat_idx], ~missing_row_mask)\n estimator.fit(X_train, y_train)\n if np.sum(missing_row_mask) == 0:\n return X_filled, estimator\n X_test = _safe_indexing(X_filled[:, neighbor_feat_idx], missing_row_mask)\n if self.sample_posterior:\n (mus, sigmas) = estimator.predict(X_test, return_std=True)\n imputed_values = np.zeros(mus.shape, dtype=X_filled.dtype)\n positive_sigmas = sigmas > 0\n imputed_values[~positive_sigmas] = mus[~positive_sigmas]\n mus_too_low = mus < self._min_value[feat_idx]\n imputed_values[mus_too_low] = self._min_value[feat_idx]\n mus_too_high = mus > self._max_value[feat_idx]\n imputed_values[mus_too_high] = self._max_value[feat_idx]\n inrange_mask = positive_sigmas & ~mus_too_low & ~mus_too_high\n mus = mus[inrange_mask]\n sigmas = sigmas[inrange_mask]\n a = (self._min_value[feat_idx] - mus) / sigmas\n b = (self._max_value[feat_idx] - mus) / sigmas\n truncated_normal = stats.truncnorm(a=a, b=b, loc=mus, scale=sigmas)\n imputed_values[inrange_mask] = truncated_normal.rvs(random_state=self.random_state_)\n else:\n imputed_values = estimator.predict(X_test)\n imputed_values = np.clip(imputed_values, self._min_value[feat_idx], self._max_value[feat_idx])\n X_filled[missing_row_mask, feat_idx] = imputed_values\n return X_filled, estimator\n \n def _get_neighbor_feat_idx(self, n_features, feat_idx, abs_corr_mat):\n \"\"\"Get a list of other features to predict ``feat_idx``.\n\n If self.n_nearest_features is less than or equal to the total\n number of features, then use a probability proportional to the absolute\n correlation between ``feat_idx`` and each other feature to randomly\n choose a subsample of the other features (without replacement).\n\n Parameters\n ----------\n n_features : int\n Number of features in ``X``.\n\n feat_idx : int\n Index of the feature currently being imputed.\n\n abs_corr_mat : ndarray, shape (n_features, n_features)\n Absolute correlation matrix of ``X``. The diagonal has been zeroed\n out and each feature has been normalized to sum to 1. Can be None.\n\n Returns\n -------\n neighbor_feat_idx : array-like\n The features to use to impute ``feat_idx``.\n \"\"\"\n if self.n_nearest_features is not None and self.n_nearest_features < n_features:\n p = abs_corr_mat[:, feat_idx]\n neighbor_feat_idx = self.random_state_.choice(np.arange(n_features), self.n_nearest_features, replace=False, p=p)\n else:\n inds_left = np.arange(feat_idx)\n inds_right = np.arange(feat_idx + 1, n_features)\n neighbor_feat_idx = np.concatenate((inds_left, inds_right))\n return neighbor_feat_idx\n \n def _get_ordered_idx(self, mask_missing_values):\n \"\"\"Decide in what order we will update the features.\n\n As a homage to the MICE R package, we will have 4 main options of\n how to order the updates, and use a random order if anything else\n is specified.\n\n Also, this function skips features which have no missing values.\n\n Parameters\n ----------\n mask_missing_values : array-like, shape (n_samples, n_features)\n Input data's missing indicator matrix, where \"n_samples\" is the\n number of samples and \"n_features\" is the number of features.\n\n Returns\n -------\n ordered_idx : ndarray, shape (n_features,)\n The order in which to impute the features.\n \"\"\"\n frac_of_missing_values = mask_missing_values.mean(axis=0)\n if self.skip_complete:\n missing_values_idx = np.flatnonzero(frac_of_missing_values)\n else:\n missing_values_idx = np.arange(np.shape(frac_of_missing_values)[0])\n if self.imputation_order == 'roman':\n ordered_idx = missing_values_idx\n elif self.imputation_order == 'arabic':\n ordered_idx = missing_values_idx[::-1]\n elif self.imputation_order == 'ascending':\n n = len(frac_of_missing_values) - len(missing_values_idx)\n ordered_idx = np.argsort(frac_of_missing_values, kind='mergesort')[n:]\n elif self.imputation_order == 'descending':\n n = len(frac_of_missing_values) - len(missing_values_idx)\n ordered_idx = np.argsort(frac_of_missing_values, kind='mergesort')[n:][::-1]\n elif self.imputation_order == 'random':\n ordered_idx = missing_values_idx\n self.random_state_.shuffle(ordered_idx)\n else:\n raise ValueError(\"Got an invalid imputation order: '{0}'. It must be one of the following: 'roman', 'arabic', 'ascending', 'descending', or 'random'.\".format(self.imputation_order))\n return ordered_idx\n \n def _get_abs_corr_mat(self, X_filled, tolerance=1e-06):\n \"\"\"Get absolute correlation matrix between features.\n\n Parameters\n ----------\n X_filled : ndarray, shape (n_samples, n_features)\n Input data with the most recent imputations.\n\n tolerance : float, default=1e-6\n ``abs_corr_mat`` can have nans, which will be replaced\n with ``tolerance``.\n\n Returns\n -------\n abs_corr_mat : ndarray, shape (n_features, n_features)\n Absolute correlation matrix of ``X`` at the beginning of the\n current round. The diagonal has been zeroed out and each feature's\n absolute correlations with all others have been normalized to sum\n to 1.\n \"\"\"\n n_features = X_filled.shape[1]\n if self.n_nearest_features is None or self.n_nearest_features >= n_features:\n return None\n with np.errstate(invalid='ignore'):\n abs_corr_mat = np.abs(np.corrcoef(X_filled.T))\n abs_corr_mat[np.isnan(abs_corr_mat)] = tolerance\n np.clip(abs_corr_mat, tolerance, None, out=abs_corr_mat)\n np.fill_diagonal(abs_corr_mat, 0)\n abs_corr_mat = normalize(abs_corr_mat, norm='l1', axis=0, copy=False)\n return abs_corr_mat\n \n def _initial_imputation(self, X, in_fit=False):\n \"\"\"Perform initial imputation for input X.\n\n Parameters\n ----------\n X : ndarray, shape (n_samples, n_features)\n Input data, where \"n_samples\" is the number of samples and\n \"n_features\" is the number of features.\n\n in_fit : bool, default=False\n Whether function is called in fit.\n\n Returns\n -------\n Xt : ndarray, shape (n_samples, n_features)\n Input data, where \"n_samples\" is the number of samples and\n \"n_features\" is the number of features.\n\n X_filled : ndarray, shape (n_samples, n_features)\n Input data with the most recent imputations.\n\n mask_missing_values : ndarray, shape (n_samples, n_features)\n Input data's missing indicator matrix, where \"n_samples\" is the\n number of samples and \"n_features\" is the number of features.\n\n X_missing_mask : ndarray, shape (n_samples, n_features)\n Input data's mask matrix indicating missing datapoints, where\n \"n_samples\" is the number of samples and \"n_features\" is the\n number of features.\n \"\"\"\n if is_scalar_nan(self.missing_values):\n force_all_finite = 'allow-nan'\n else:\n force_all_finite = True\n X = self._validate_data(X, dtype=FLOAT_DTYPES, order='F', reset=in_fit, force_all_finite=force_all_finite)\n _check_inputs_dtype(X, self.missing_values)\n X_missing_mask = _get_mask(X, self.missing_values)\n mask_missing_values = X_missing_mask.copy()\n if self.initial_imputer_ is None:\n self.initial_imputer_ = SimpleImputer(missing_values=self.missing_values, strategy=self.initial_strategy)\n X_filled = self.initial_imputer_.fit_transform(X)\n else:\n X_filled = self.initial_imputer_.transform(X)\n valid_mask = np.flatnonzero(np.logical_not(np.isnan(self.initial_imputer_.statistics_)))\n Xt = X[:, valid_mask]\n mask_missing_values = mask_missing_values[:, valid_mask]\n return Xt, X_filled, mask_missing_values, X_missing_mask\n \n @staticmethod\n def _validate_limit(limit, limit_type, n_features):\n \"\"\"Validate the limits (min/max) of the feature values\n Converts scalar min/max limits to vectors of shape (n_features,)\n\n Parameters\n ----------\n limit: scalar or array-like\n The user-specified limit (i.e, min_value or max_value)\n limit_type: string, \"max\" or \"min\"\n n_features: Number of features in the dataset\n\n Returns\n -------\n limit: ndarray, shape(n_features,)\n Array of limits, one for each feature\n \"\"\"\n limit_bound = np.inf if limit_type == 'max' else -np.inf\n limit = limit_bound if limit is None else limit\n if np.isscalar(limit):\n limit = np.full(n_features, limit)\n limit = check_array(limit, force_all_finite=False, copy=False, ensure_2d=False)\n if not limit.shape[0] == n_features:\n raise ValueError(f\"'{limit_type}_value' should be of shape ({n_features},) when an array-like is provided. Got {limit.shape}, instead.\")\n return limit\n \n def fit_transform(self, X, y=None):\n \"\"\"Fits the imputer on X and return the transformed X.\n\n Parameters\n ----------\n X : array-like, shape (n_samples, n_features)\n Input data, where \"n_samples\" is the number of samples and\n \"n_features\" is the number of features.\n\n y : ignored.\n\n Returns\n -------\n Xt : array-like, shape (n_samples, n_features)\n The imputed input data.\n \"\"\"\n self.random_state_ = getattr(self, 'random_state_', check_random_state(self.random_state))\n if self.max_iter < 0:\n raise ValueError(\"'max_iter' should be a positive integer. Got {} instead.\".format(self.max_iter))\n if self.tol < 0:\n raise ValueError(\"'tol' should be a non-negative float. Got {} instead.\".format(self.tol))\n if self.estimator is None:\n from ..linear_model import BayesianRidge\n self._estimator = BayesianRidge()\n else:\n self._estimator = clone(self.estimator)\n self.imputation_sequence_ = []\n self.initial_imputer_ = None\n (X, Xt, mask_missing_values, complete_mask) = self._initial_imputation(X, in_fit=True)\n super()._fit_indicator(complete_mask)\n X_indicator = super()._transform_indicator(complete_mask)\n if self.max_iter == 0 or np.all(mask_missing_values):\n self.n_iter_ = 0\n return super()._concatenate_indicator(Xt, X_indicator)\n if Xt.shape[1] == 1:\n self.n_iter_ = 0\n return super()._concatenate_indicator(Xt, X_indicator)\n self._min_value = self._validate_limit(self.min_value, 'min', X.shape[1])\n self._max_value = self._validate_limit(self.max_value, 'max', X.shape[1])\n if not np.all(np.greater(self._max_value, self._min_value)):\n raise ValueError('One (or more) features have min_value >= max_value.')\n ordered_idx = self._get_ordered_idx(mask_missing_values)\n self.n_features_with_missing_ = len(ordered_idx)\n abs_corr_mat = self._get_abs_corr_mat(Xt)\n (n_samples, n_features) = Xt.shape\n if self.verbose > 0:\n print('[IterativeImputer] Completing matrix with shape %s' % (X.shape, ))\n start_t = time()\n if not self.sample_posterior:\n Xt_previous = Xt.copy()\n normalized_tol = self.tol * np.max(np.abs(X[~mask_missing_values]))\n for self.n_iter_ in range(1, self.max_iter + 1):\n if self.imputation_order == 'random':\n ordered_idx = self._get_ordered_idx(mask_missing_values)\n for feat_idx in ordered_idx:\n neighbor_feat_idx = self._get_neighbor_feat_idx(n_features, feat_idx, abs_corr_mat)\n (Xt, estimator) = self._impute_one_feature(Xt, mask_missing_values, feat_idx, neighbor_feat_idx, estimator=None, fit_mode=True)\n estimator_triplet = _ImputerTriplet(feat_idx, neighbor_feat_idx, estimator)\n self.imputation_sequence_.append(estimator_triplet)\n if self.verbose > 1:\n print('[IterativeImputer] Ending imputation round %d/%d, elapsed time %0.2f' % (self.n_iter_, self.max_iter, time() - start_t))\n if not self.sample_posterior:\n inf_norm = np.linalg.norm(Xt - Xt_previous, ord=np.inf, axis=None)\n if self.verbose > 0:\n print('[IterativeImputer] Change: {}, scaled tolerance: {} '.format(inf_norm, normalized_tol))\n if inf_norm < normalized_tol:\n if self.verbose > 0:\n print('[IterativeImputer] Early stopping criterion reached.')\n break\n Xt_previous = Xt.copy()\n else:\n if not self.sample_posterior:\n warnings.warn('[IterativeImputer] Early stopping criterion not reached.', ConvergenceWarning)\n Xt[~mask_missing_values] = X[~mask_missing_values]\n return super()._concatenate_indicator(Xt, X_indicator)\n \n def transform(self, X):\n \"\"\"Imputes all missing values in X.\n\n Note that this is stochastic, and that if random_state is not fixed,\n repeated calls, or permuted input, will yield different results.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The input data to complete.\n\n Returns\n -------\n Xt : array-like, shape (n_samples, n_features)\n The imputed input data.\n \"\"\"\n check_is_fitted(self)\n (X, Xt, mask_missing_values, complete_mask) = self._initial_imputation(X)\n X_indicator = super()._transform_indicator(complete_mask)\n if self.n_iter_ == 0 or np.all(mask_missing_values):\n return super()._concatenate_indicator(Xt, X_indicator)\n imputations_per_round = len(self.imputation_sequence_) // self.n_iter_\n i_rnd = 0\n if self.verbose > 0:\n print('[IterativeImputer] Completing matrix with shape %s' % (X.shape, ))\n start_t = time()\n for (it, estimator_triplet) in enumerate(self.imputation_sequence_):\n (Xt, _) = self._impute_one_feature(Xt, mask_missing_values, estimator_triplet.feat_idx, estimator_triplet.neighbor_feat_idx, estimator=estimator_triplet.estimator, fit_mode=False)\n if not (it + 1) % imputations_per_round:\n if self.verbose > 1:\n print('[IterativeImputer] Ending imputation round %d/%d, elapsed time %0.2f' % (i_rnd + 1, self.n_iter_, time() - start_t))\n i_rnd += 1\n Xt[~mask_missing_values] = X[~mask_missing_values]\n return super()._concatenate_indicator(Xt, X_indicator)\n \n def fit(self, X, y=None):\n \"\"\"Fits the imputer on X and return self.\n\n Parameters\n ----------\n X : array-like, shape (n_samples, n_features)\n Input data, where \"n_samples\" is the number of samples and\n \"n_features\" is the number of features.\n\n y : ignored\n\n Returns\n -------\n self : object\n Returns self.\n \"\"\"\n self.fit_transform(X)\n return self\n" + "description": "Multivariate imputer that estimates each feature from all the others.\n\nA strategy for imputing missing values by modeling each feature with missing values as a function of other features in a round-robin fashion. Read more in the :ref:`User Guide `. .. versionadded:: 0.21 .. note:: This estimator is still **experimental** for now: the predictions and the API might change without any deprecation cycle. To use it, you need to explicitly import `enable_iterative_imputer`:: >>> # explicitly require this experimental feature >>> from sklearn.experimental import enable_iterative_imputer # noqa >>> # now you can import normally from sklearn.impute >>> from sklearn.impute import IterativeImputer", + "docstring": "Multivariate imputer that estimates each feature from all the others.\n\n A strategy for imputing missing values by modeling each feature with\n missing values as a function of other features in a round-robin fashion.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.21\n\n .. note::\n\n This estimator is still **experimental** for now: the predictions\n and the API might change without any deprecation cycle. To use it,\n you need to explicitly import `enable_iterative_imputer`::\n\n >>> # explicitly require this experimental feature\n >>> from sklearn.experimental import enable_iterative_imputer # noqa\n >>> # now you can import normally from sklearn.impute\n >>> from sklearn.impute import IterativeImputer\n\n Parameters\n ----------\n estimator : estimator object, default=BayesianRidge()\n The estimator to use at each step of the round-robin imputation.\n If `sample_posterior=True`, the estimator must support\n `return_std` in its `predict` method.\n\n missing_values : int or np.nan, default=np.nan\n The placeholder for the missing values. All occurrences of\n `missing_values` will be imputed. For pandas' dataframes with\n nullable integer dtypes with missing values, `missing_values`\n should be set to `np.nan`, since `pd.NA` will be converted to `np.nan`.\n\n sample_posterior : bool, default=False\n Whether to sample from the (Gaussian) predictive posterior of the\n fitted estimator for each imputation. Estimator must support\n `return_std` in its `predict` method if set to `True`. Set to\n `True` if using `IterativeImputer` for multiple imputations.\n\n max_iter : int, default=10\n Maximum number of imputation rounds to perform before returning the\n imputations computed during the final round. A round is a single\n imputation of each feature with missing values. The stopping criterion\n is met once `max(abs(X_t - X_{t-1}))/max(abs(X[known_vals])) < tol`,\n where `X_t` is `X` at iteration `t`. Note that early stopping is only\n applied if `sample_posterior=False`.\n\n tol : float, default=1e-3\n Tolerance of the stopping condition.\n\n n_nearest_features : int, default=None\n Number of other features to use to estimate the missing values of\n each feature column. Nearness between features is measured using\n the absolute correlation coefficient between each feature pair (after\n initial imputation). To ensure coverage of features throughout the\n imputation process, the neighbor features are not necessarily nearest,\n but are drawn with probability proportional to correlation for each\n imputed target feature. Can provide significant speed-up when the\n number of features is huge. If `None`, all features will be used.\n\n initial_strategy : {'mean', 'median', 'most_frequent', 'constant'}, default='mean'\n Which strategy to use to initialize the missing values. Same as the\n `strategy` parameter in :class:`~sklearn.impute.SimpleImputer`.\n\n imputation_order : {'ascending', 'descending', 'roman', 'arabic', 'random'}, default='ascending'\n The order in which the features will be imputed. Possible values:\n\n - `'ascending'`: From features with fewest missing values to most.\n - `'descending'`: From features with most missing values to fewest.\n - `'roman'`: Left to right.\n - `'arabic'`: Right to left.\n - `'random'`: A random order for each round.\n\n skip_complete : bool, default=False\n If `True` then features with missing values during :meth:`transform`\n which did not have any missing values during :meth:`fit` will be\n imputed with the initial imputation method only. Set to `True` if you\n have many features with no missing values at both :meth:`fit` and\n :meth:`transform` time to save compute.\n\n min_value : float or array-like of shape (n_features,), default=-np.inf\n Minimum possible imputed value. Broadcast to shape `(n_features,)` if\n scalar. If array-like, expects shape `(n_features,)`, one min value for\n each feature. The default is `-np.inf`.\n\n .. versionchanged:: 0.23\n Added support for array-like.\n\n max_value : float or array-like of shape (n_features,), default=np.inf\n Maximum possible imputed value. Broadcast to shape `(n_features,)` if\n scalar. If array-like, expects shape `(n_features,)`, one max value for\n each feature. The default is `np.inf`.\n\n .. versionchanged:: 0.23\n Added support for array-like.\n\n verbose : int, default=0\n Verbosity flag, controls the debug messages that are issued\n as functions are evaluated. The higher, the more verbose. Can be 0, 1,\n or 2.\n\n random_state : int, RandomState instance or None, default=None\n The seed of the pseudo random number generator to use. Randomizes\n selection of estimator features if `n_nearest_features` is not `None`,\n the `imputation_order` if `random`, and the sampling from posterior if\n `sample_posterior=True`. Use an integer for determinism.\n See :term:`the Glossary `.\n\n add_indicator : bool, default=False\n If `True`, a :class:`MissingIndicator` transform will stack onto output\n of the imputer's transform. This allows a predictive estimator\n to account for missingness despite imputation. If a feature has no\n missing values at fit/train time, the feature won't appear on\n the missing indicator even if there are missing values at\n transform/test time.\n\n Attributes\n ----------\n initial_imputer_ : object of type :class:`~sklearn.impute.SimpleImputer`\n Imputer used to initialize the missing values.\n\n imputation_sequence_ : list of tuples\n Each tuple has `(feat_idx, neighbor_feat_idx, estimator)`, where\n `feat_idx` is the current feature to be imputed,\n `neighbor_feat_idx` is the array of other features used to impute the\n current feature, and `estimator` is the trained estimator used for\n the imputation. Length is `self.n_features_with_missing_ *\n self.n_iter_`.\n\n n_iter_ : int\n Number of iteration rounds that occurred. Will be less than\n `self.max_iter` if early stopping criterion was reached.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_features_with_missing_ : int\n Number of features with missing values.\n\n indicator_ : :class:`~sklearn.impute.MissingIndicator`\n Indicator used to add binary indicators for missing values.\n `None` if `add_indicator=False`.\n\n random_state_ : RandomState instance\n RandomState instance that is generated either from a seed, the random\n number generator or by `np.random`.\n\n See Also\n --------\n SimpleImputer : Univariate imputation of missing values.\n\n Notes\n -----\n To support imputation in inductive mode we store each feature's estimator\n during the :meth:`fit` phase, and predict without refitting (in order)\n during the :meth:`transform` phase.\n\n Features which contain all missing values at :meth:`fit` are discarded upon\n :meth:`transform`.\n\n References\n ----------\n .. [1] `Stef van Buuren, Karin Groothuis-Oudshoorn (2011). \"mice:\n Multivariate Imputation by Chained Equations in R\". Journal of\n Statistical Software 45: 1-67.\n `_\n\n .. [2] `S. F. Buck, (1960). \"A Method of Estimation of Missing Values in\n Multivariate Data Suitable for use with an Electronic Computer\".\n Journal of the Royal Statistical Society 22(2): 302-306.\n `_\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.experimental import enable_iterative_imputer\n >>> from sklearn.impute import IterativeImputer\n >>> imp_mean = IterativeImputer(random_state=0)\n >>> imp_mean.fit([[7, 2, 3], [4, np.nan, 6], [10, 5, 9]])\n IterativeImputer(random_state=0)\n >>> X = [[np.nan, 2, 3], [4, np.nan, 6], [10, np.nan, 9]]\n >>> imp_mean.transform(X)\n array([[ 6.9584..., 2. , 3. ],\n [ 4. , 2.6000..., 6. ],\n [10. , 4.9999..., 9. ]])\n ", + "source_code": "\n\nclass IterativeImputer(_BaseImputer):\n \"\"\"Multivariate imputer that estimates each feature from all the others.\n\n A strategy for imputing missing values by modeling each feature with\n missing values as a function of other features in a round-robin fashion.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.21\n\n .. note::\n\n This estimator is still **experimental** for now: the predictions\n and the API might change without any deprecation cycle. To use it,\n you need to explicitly import `enable_iterative_imputer`::\n\n >>> # explicitly require this experimental feature\n >>> from sklearn.experimental import enable_iterative_imputer # noqa\n >>> # now you can import normally from sklearn.impute\n >>> from sklearn.impute import IterativeImputer\n\n Parameters\n ----------\n estimator : estimator object, default=BayesianRidge()\n The estimator to use at each step of the round-robin imputation.\n If `sample_posterior=True`, the estimator must support\n `return_std` in its `predict` method.\n\n missing_values : int or np.nan, default=np.nan\n The placeholder for the missing values. All occurrences of\n `missing_values` will be imputed. For pandas' dataframes with\n nullable integer dtypes with missing values, `missing_values`\n should be set to `np.nan`, since `pd.NA` will be converted to `np.nan`.\n\n sample_posterior : bool, default=False\n Whether to sample from the (Gaussian) predictive posterior of the\n fitted estimator for each imputation. Estimator must support\n `return_std` in its `predict` method if set to `True`. Set to\n `True` if using `IterativeImputer` for multiple imputations.\n\n max_iter : int, default=10\n Maximum number of imputation rounds to perform before returning the\n imputations computed during the final round. A round is a single\n imputation of each feature with missing values. The stopping criterion\n is met once `max(abs(X_t - X_{t-1}))/max(abs(X[known_vals])) < tol`,\n where `X_t` is `X` at iteration `t`. Note that early stopping is only\n applied if `sample_posterior=False`.\n\n tol : float, default=1e-3\n Tolerance of the stopping condition.\n\n n_nearest_features : int, default=None\n Number of other features to use to estimate the missing values of\n each feature column. Nearness between features is measured using\n the absolute correlation coefficient between each feature pair (after\n initial imputation). To ensure coverage of features throughout the\n imputation process, the neighbor features are not necessarily nearest,\n but are drawn with probability proportional to correlation for each\n imputed target feature. Can provide significant speed-up when the\n number of features is huge. If `None`, all features will be used.\n\n initial_strategy : {'mean', 'median', 'most_frequent', 'constant'}, default='mean'\n Which strategy to use to initialize the missing values. Same as the\n `strategy` parameter in :class:`~sklearn.impute.SimpleImputer`.\n\n imputation_order : {'ascending', 'descending', 'roman', 'arabic', 'random'}, default='ascending'\n The order in which the features will be imputed. Possible values:\n\n - `'ascending'`: From features with fewest missing values to most.\n - `'descending'`: From features with most missing values to fewest.\n - `'roman'`: Left to right.\n - `'arabic'`: Right to left.\n - `'random'`: A random order for each round.\n\n skip_complete : bool, default=False\n If `True` then features with missing values during :meth:`transform`\n which did not have any missing values during :meth:`fit` will be\n imputed with the initial imputation method only. Set to `True` if you\n have many features with no missing values at both :meth:`fit` and\n :meth:`transform` time to save compute.\n\n min_value : float or array-like of shape (n_features,), default=-np.inf\n Minimum possible imputed value. Broadcast to shape `(n_features,)` if\n scalar. If array-like, expects shape `(n_features,)`, one min value for\n each feature. The default is `-np.inf`.\n\n .. versionchanged:: 0.23\n Added support for array-like.\n\n max_value : float or array-like of shape (n_features,), default=np.inf\n Maximum possible imputed value. Broadcast to shape `(n_features,)` if\n scalar. If array-like, expects shape `(n_features,)`, one max value for\n each feature. The default is `np.inf`.\n\n .. versionchanged:: 0.23\n Added support for array-like.\n\n verbose : int, default=0\n Verbosity flag, controls the debug messages that are issued\n as functions are evaluated. The higher, the more verbose. Can be 0, 1,\n or 2.\n\n random_state : int, RandomState instance or None, default=None\n The seed of the pseudo random number generator to use. Randomizes\n selection of estimator features if `n_nearest_features` is not `None`,\n the `imputation_order` if `random`, and the sampling from posterior if\n `sample_posterior=True`. Use an integer for determinism.\n See :term:`the Glossary `.\n\n add_indicator : bool, default=False\n If `True`, a :class:`MissingIndicator` transform will stack onto output\n of the imputer's transform. This allows a predictive estimator\n to account for missingness despite imputation. If a feature has no\n missing values at fit/train time, the feature won't appear on\n the missing indicator even if there are missing values at\n transform/test time.\n\n Attributes\n ----------\n initial_imputer_ : object of type :class:`~sklearn.impute.SimpleImputer`\n Imputer used to initialize the missing values.\n\n imputation_sequence_ : list of tuples\n Each tuple has `(feat_idx, neighbor_feat_idx, estimator)`, where\n `feat_idx` is the current feature to be imputed,\n `neighbor_feat_idx` is the array of other features used to impute the\n current feature, and `estimator` is the trained estimator used for\n the imputation. Length is `self.n_features_with_missing_ *\n self.n_iter_`.\n\n n_iter_ : int\n Number of iteration rounds that occurred. Will be less than\n `self.max_iter` if early stopping criterion was reached.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_features_with_missing_ : int\n Number of features with missing values.\n\n indicator_ : :class:`~sklearn.impute.MissingIndicator`\n Indicator used to add binary indicators for missing values.\n `None` if `add_indicator=False`.\n\n random_state_ : RandomState instance\n RandomState instance that is generated either from a seed, the random\n number generator or by `np.random`.\n\n See Also\n --------\n SimpleImputer : Univariate imputation of missing values.\n\n Notes\n -----\n To support imputation in inductive mode we store each feature's estimator\n during the :meth:`fit` phase, and predict without refitting (in order)\n during the :meth:`transform` phase.\n\n Features which contain all missing values at :meth:`fit` are discarded upon\n :meth:`transform`.\n\n References\n ----------\n .. [1] `Stef van Buuren, Karin Groothuis-Oudshoorn (2011). \"mice:\n Multivariate Imputation by Chained Equations in R\". Journal of\n Statistical Software 45: 1-67.\n `_\n\n .. [2] `S. F. Buck, (1960). \"A Method of Estimation of Missing Values in\n Multivariate Data Suitable for use with an Electronic Computer\".\n Journal of the Royal Statistical Society 22(2): 302-306.\n `_\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.experimental import enable_iterative_imputer\n >>> from sklearn.impute import IterativeImputer\n >>> imp_mean = IterativeImputer(random_state=0)\n >>> imp_mean.fit([[7, 2, 3], [4, np.nan, 6], [10, 5, 9]])\n IterativeImputer(random_state=0)\n >>> X = [[np.nan, 2, 3], [4, np.nan, 6], [10, np.nan, 9]]\n >>> imp_mean.transform(X)\n array([[ 6.9584..., 2. , 3. ],\n [ 4. , 2.6000..., 6. ],\n [10. , 4.9999..., 9. ]])\n \"\"\"\n \n def __init__(self, estimator=None, *, missing_values=np.nan, sample_posterior=False, max_iter=10, tol=0.001, n_nearest_features=None, initial_strategy='mean', imputation_order='ascending', skip_complete=False, min_value=-np.inf, max_value=np.inf, verbose=0, random_state=None, add_indicator=False):\n super().__init__(missing_values=missing_values, add_indicator=add_indicator)\n self.estimator = estimator\n self.sample_posterior = sample_posterior\n self.max_iter = max_iter\n self.tol = tol\n self.n_nearest_features = n_nearest_features\n self.initial_strategy = initial_strategy\n self.imputation_order = imputation_order\n self.skip_complete = skip_complete\n self.min_value = min_value\n self.max_value = max_value\n self.verbose = verbose\n self.random_state = random_state\n \n def _impute_one_feature(self, X_filled, mask_missing_values, feat_idx, neighbor_feat_idx, estimator=None, fit_mode=True):\n \"\"\"Impute a single feature from the others provided.\n\n This function predicts the missing values of one of the features using\n the current estimates of all the other features. The `estimator` must\n support `return_std=True` in its `predict` method for this function\n to work.\n\n Parameters\n ----------\n X_filled : ndarray\n Input data with the most recent imputations.\n\n mask_missing_values : ndarray\n Input data's missing indicator matrix.\n\n feat_idx : int\n Index of the feature currently being imputed.\n\n neighbor_feat_idx : ndarray\n Indices of the features to be used in imputing `feat_idx`.\n\n estimator : object\n The estimator to use at this step of the round-robin imputation.\n If `sample_posterior=True`, the estimator must support\n `return_std` in its `predict` method.\n If None, it will be cloned from self._estimator.\n\n fit_mode : boolean, default=True\n Whether to fit and predict with the estimator or just predict.\n\n Returns\n -------\n X_filled : ndarray\n Input data with `X_filled[missing_row_mask, feat_idx]` updated.\n\n estimator : estimator with sklearn API\n The fitted estimator used to impute\n `X_filled[missing_row_mask, feat_idx]`.\n \"\"\"\n if estimator is None and fit_mode is False:\n raise ValueError('If fit_mode is False, then an already-fitted estimator should be passed in.')\n if estimator is None:\n estimator = clone(self._estimator)\n missing_row_mask = mask_missing_values[:, feat_idx]\n if fit_mode:\n X_train = _safe_indexing(X_filled[:, neighbor_feat_idx], ~missing_row_mask)\n y_train = _safe_indexing(X_filled[:, feat_idx], ~missing_row_mask)\n estimator.fit(X_train, y_train)\n if np.sum(missing_row_mask) == 0:\n return X_filled, estimator\n X_test = _safe_indexing(X_filled[:, neighbor_feat_idx], missing_row_mask)\n if self.sample_posterior:\n (mus, sigmas) = estimator.predict(X_test, return_std=True)\n imputed_values = np.zeros(mus.shape, dtype=X_filled.dtype)\n positive_sigmas = sigmas > 0\n imputed_values[~positive_sigmas] = mus[~positive_sigmas]\n mus_too_low = mus < self._min_value[feat_idx]\n imputed_values[mus_too_low] = self._min_value[feat_idx]\n mus_too_high = mus > self._max_value[feat_idx]\n imputed_values[mus_too_high] = self._max_value[feat_idx]\n inrange_mask = positive_sigmas & ~mus_too_low & ~mus_too_high\n mus = mus[inrange_mask]\n sigmas = sigmas[inrange_mask]\n a = (self._min_value[feat_idx] - mus) / sigmas\n b = (self._max_value[feat_idx] - mus) / sigmas\n truncated_normal = stats.truncnorm(a=a, b=b, loc=mus, scale=sigmas)\n imputed_values[inrange_mask] = truncated_normal.rvs(random_state=self.random_state_)\n else:\n imputed_values = estimator.predict(X_test)\n imputed_values = np.clip(imputed_values, self._min_value[feat_idx], self._max_value[feat_idx])\n X_filled[missing_row_mask, feat_idx] = imputed_values\n return X_filled, estimator\n \n def _get_neighbor_feat_idx(self, n_features, feat_idx, abs_corr_mat):\n \"\"\"Get a list of other features to predict `feat_idx`.\n\n If `self.n_nearest_features` is less than or equal to the total\n number of features, then use a probability proportional to the absolute\n correlation between `feat_idx` and each other feature to randomly\n choose a subsample of the other features (without replacement).\n\n Parameters\n ----------\n n_features : int\n Number of features in `X`.\n\n feat_idx : int\n Index of the feature currently being imputed.\n\n abs_corr_mat : ndarray, shape (n_features, n_features)\n Absolute correlation matrix of `X`. The diagonal has been zeroed\n out and each feature has been normalized to sum to 1. Can be None.\n\n Returns\n -------\n neighbor_feat_idx : array-like\n The features to use to impute `feat_idx`.\n \"\"\"\n if self.n_nearest_features is not None and self.n_nearest_features < n_features:\n p = abs_corr_mat[:, feat_idx]\n neighbor_feat_idx = self.random_state_.choice(np.arange(n_features), self.n_nearest_features, replace=False, p=p)\n else:\n inds_left = np.arange(feat_idx)\n inds_right = np.arange(feat_idx + 1, n_features)\n neighbor_feat_idx = np.concatenate((inds_left, inds_right))\n return neighbor_feat_idx\n \n def _get_ordered_idx(self, mask_missing_values):\n \"\"\"Decide in what order we will update the features.\n\n As a homage to the MICE R package, we will have 4 main options of\n how to order the updates, and use a random order if anything else\n is specified.\n\n Also, this function skips features which have no missing values.\n\n Parameters\n ----------\n mask_missing_values : array-like, shape (n_samples, n_features)\n Input data's missing indicator matrix, where `n_samples` is the\n number of samples and `n_features` is the number of features.\n\n Returns\n -------\n ordered_idx : ndarray, shape (n_features,)\n The order in which to impute the features.\n \"\"\"\n frac_of_missing_values = mask_missing_values.mean(axis=0)\n if self.skip_complete:\n missing_values_idx = np.flatnonzero(frac_of_missing_values)\n else:\n missing_values_idx = np.arange(np.shape(frac_of_missing_values)[0])\n if self.imputation_order == 'roman':\n ordered_idx = missing_values_idx\n elif self.imputation_order == 'arabic':\n ordered_idx = missing_values_idx[::-1]\n elif self.imputation_order == 'ascending':\n n = len(frac_of_missing_values) - len(missing_values_idx)\n ordered_idx = np.argsort(frac_of_missing_values, kind='mergesort')[n:]\n elif self.imputation_order == 'descending':\n n = len(frac_of_missing_values) - len(missing_values_idx)\n ordered_idx = np.argsort(frac_of_missing_values, kind='mergesort')[n:][::-1]\n elif self.imputation_order == 'random':\n ordered_idx = missing_values_idx\n self.random_state_.shuffle(ordered_idx)\n else:\n raise ValueError(\"Got an invalid imputation order: '{0}'. It must be one of the following: 'roman', 'arabic', 'ascending', 'descending', or 'random'.\".format(self.imputation_order))\n return ordered_idx\n \n def _get_abs_corr_mat(self, X_filled, tolerance=1e-06):\n \"\"\"Get absolute correlation matrix between features.\n\n Parameters\n ----------\n X_filled : ndarray, shape (n_samples, n_features)\n Input data with the most recent imputations.\n\n tolerance : float, default=1e-6\n `abs_corr_mat` can have nans, which will be replaced\n with `tolerance`.\n\n Returns\n -------\n abs_corr_mat : ndarray, shape (n_features, n_features)\n Absolute correlation matrix of `X` at the beginning of the\n current round. The diagonal has been zeroed out and each feature's\n absolute correlations with all others have been normalized to sum\n to 1.\n \"\"\"\n n_features = X_filled.shape[1]\n if self.n_nearest_features is None or self.n_nearest_features >= n_features:\n return None\n with np.errstate(invalid='ignore'):\n abs_corr_mat = np.abs(np.corrcoef(X_filled.T))\n abs_corr_mat[np.isnan(abs_corr_mat)] = tolerance\n np.clip(abs_corr_mat, tolerance, None, out=abs_corr_mat)\n np.fill_diagonal(abs_corr_mat, 0)\n abs_corr_mat = normalize(abs_corr_mat, norm='l1', axis=0, copy=False)\n return abs_corr_mat\n \n def _initial_imputation(self, X, in_fit=False):\n \"\"\"Perform initial imputation for input `X`.\n\n Parameters\n ----------\n X : ndarray, shape (n_samples, n_features)\n Input data, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n in_fit : bool, default=False\n Whether function is called in :meth:`fit`.\n\n Returns\n -------\n Xt : ndarray, shape (n_samples, n_features)\n Input data, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n X_filled : ndarray, shape (n_samples, n_features)\n Input data with the most recent imputations.\n\n mask_missing_values : ndarray, shape (n_samples, n_features)\n Input data's missing indicator matrix, where `n_samples` is the\n number of samples and `n_features` is the number of features.\n\n X_missing_mask : ndarray, shape (n_samples, n_features)\n Input data's mask matrix indicating missing datapoints, where\n `n_samples` is the number of samples and `n_features` is the\n number of features.\n \"\"\"\n if is_scalar_nan(self.missing_values):\n force_all_finite = 'allow-nan'\n else:\n force_all_finite = True\n X = self._validate_data(X, dtype=FLOAT_DTYPES, order='F', reset=in_fit, force_all_finite=force_all_finite)\n _check_inputs_dtype(X, self.missing_values)\n X_missing_mask = _get_mask(X, self.missing_values)\n mask_missing_values = X_missing_mask.copy()\n if self.initial_imputer_ is None:\n self.initial_imputer_ = SimpleImputer(missing_values=self.missing_values, strategy=self.initial_strategy)\n X_filled = self.initial_imputer_.fit_transform(X)\n else:\n X_filled = self.initial_imputer_.transform(X)\n valid_mask = np.flatnonzero(np.logical_not(np.isnan(self.initial_imputer_.statistics_)))\n Xt = X[:, valid_mask]\n mask_missing_values = mask_missing_values[:, valid_mask]\n return Xt, X_filled, mask_missing_values, X_missing_mask\n \n @staticmethod\n def _validate_limit(limit, limit_type, n_features):\n \"\"\"Validate the limits (min/max) of the feature values.\n\n Converts scalar min/max limits to vectors of shape `(n_features,)`.\n\n Parameters\n ----------\n limit: scalar or array-like\n The user-specified limit (i.e, min_value or max_value).\n limit_type: {'max', 'min'}\n Type of limit to validate.\n n_features: int\n Number of features in the dataset.\n\n Returns\n -------\n limit: ndarray, shape(n_features,)\n Array of limits, one for each feature.\n \"\"\"\n limit_bound = np.inf if limit_type == 'max' else -np.inf\n limit = limit_bound if limit is None else limit\n if np.isscalar(limit):\n limit = np.full(n_features, limit)\n limit = check_array(limit, force_all_finite=False, copy=False, ensure_2d=False)\n if not limit.shape[0] == n_features:\n raise ValueError(f\"'{limit_type}_value' should be of shape ({n_features},) when an array-like is provided. Got {limit.shape}, instead.\")\n return limit\n \n def fit_transform(self, X, y=None):\n \"\"\"Fit the imputer on `X` and return the transformed `X`.\n\n Parameters\n ----------\n X : array-like, shape (n_samples, n_features)\n Input data, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n Xt : array-like, shape (n_samples, n_features)\n The imputed input data.\n \"\"\"\n self.random_state_ = getattr(self, 'random_state_', check_random_state(self.random_state))\n if self.max_iter < 0:\n raise ValueError(\"'max_iter' should be a positive integer. Got {} instead.\".format(self.max_iter))\n if self.tol < 0:\n raise ValueError(\"'tol' should be a non-negative float. Got {} instead.\".format(self.tol))\n if self.estimator is None:\n from ..linear_model import BayesianRidge\n self._estimator = BayesianRidge()\n else:\n self._estimator = clone(self.estimator)\n self.imputation_sequence_ = []\n self.initial_imputer_ = None\n (X, Xt, mask_missing_values, complete_mask) = self._initial_imputation(X, in_fit=True)\n super()._fit_indicator(complete_mask)\n X_indicator = super()._transform_indicator(complete_mask)\n if self.max_iter == 0 or np.all(mask_missing_values):\n self.n_iter_ = 0\n return super()._concatenate_indicator(Xt, X_indicator)\n if Xt.shape[1] == 1:\n self.n_iter_ = 0\n return super()._concatenate_indicator(Xt, X_indicator)\n self._min_value = self._validate_limit(self.min_value, 'min', X.shape[1])\n self._max_value = self._validate_limit(self.max_value, 'max', X.shape[1])\n if not np.all(np.greater(self._max_value, self._min_value)):\n raise ValueError('One (or more) features have min_value >= max_value.')\n ordered_idx = self._get_ordered_idx(mask_missing_values)\n self.n_features_with_missing_ = len(ordered_idx)\n abs_corr_mat = self._get_abs_corr_mat(Xt)\n (n_samples, n_features) = Xt.shape\n if self.verbose > 0:\n print('[IterativeImputer] Completing matrix with shape %s' % (X.shape, ))\n start_t = time()\n if not self.sample_posterior:\n Xt_previous = Xt.copy()\n normalized_tol = self.tol * np.max(np.abs(X[~mask_missing_values]))\n for self.n_iter_ in range(1, self.max_iter + 1):\n if self.imputation_order == 'random':\n ordered_idx = self._get_ordered_idx(mask_missing_values)\n for feat_idx in ordered_idx:\n neighbor_feat_idx = self._get_neighbor_feat_idx(n_features, feat_idx, abs_corr_mat)\n (Xt, estimator) = self._impute_one_feature(Xt, mask_missing_values, feat_idx, neighbor_feat_idx, estimator=None, fit_mode=True)\n estimator_triplet = _ImputerTriplet(feat_idx, neighbor_feat_idx, estimator)\n self.imputation_sequence_.append(estimator_triplet)\n if self.verbose > 1:\n print('[IterativeImputer] Ending imputation round %d/%d, elapsed time %0.2f' % (self.n_iter_, self.max_iter, time() - start_t))\n if not self.sample_posterior:\n inf_norm = np.linalg.norm(Xt - Xt_previous, ord=np.inf, axis=None)\n if self.verbose > 0:\n print('[IterativeImputer] Change: {}, scaled tolerance: {} '.format(inf_norm, normalized_tol))\n if inf_norm < normalized_tol:\n if self.verbose > 0:\n print('[IterativeImputer] Early stopping criterion reached.')\n break\n Xt_previous = Xt.copy()\n else:\n if not self.sample_posterior:\n warnings.warn('[IterativeImputer] Early stopping criterion not reached.', ConvergenceWarning)\n Xt[~mask_missing_values] = X[~mask_missing_values]\n return super()._concatenate_indicator(Xt, X_indicator)\n \n def transform(self, X):\n \"\"\"Impute all missing values in `X`.\n\n Note that this is stochastic, and that if `random_state` is not fixed,\n repeated calls, or permuted input, results will differ.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The input data to complete.\n\n Returns\n -------\n Xt : array-like, shape (n_samples, n_features)\n The imputed input data.\n \"\"\"\n check_is_fitted(self)\n (X, Xt, mask_missing_values, complete_mask) = self._initial_imputation(X)\n X_indicator = super()._transform_indicator(complete_mask)\n if self.n_iter_ == 0 or np.all(mask_missing_values):\n return super()._concatenate_indicator(Xt, X_indicator)\n imputations_per_round = len(self.imputation_sequence_) // self.n_iter_\n i_rnd = 0\n if self.verbose > 0:\n print('[IterativeImputer] Completing matrix with shape %s' % (X.shape, ))\n start_t = time()\n for (it, estimator_triplet) in enumerate(self.imputation_sequence_):\n (Xt, _) = self._impute_one_feature(Xt, mask_missing_values, estimator_triplet.feat_idx, estimator_triplet.neighbor_feat_idx, estimator=estimator_triplet.estimator, fit_mode=False)\n if not (it + 1) % imputations_per_round:\n if self.verbose > 1:\n print('[IterativeImputer] Ending imputation round %d/%d, elapsed time %0.2f' % (i_rnd + 1, self.n_iter_, time() - start_t))\n i_rnd += 1\n Xt[~mask_missing_values] = X[~mask_missing_values]\n return super()._concatenate_indicator(Xt, X_indicator)\n \n def fit(self, X, y=None):\n \"\"\"Fit the imputer on `X` and return self.\n\n Parameters\n ----------\n X : array-like, shape (n_samples, n_features)\n Input data, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n self.fit_transform(X)\n return self\n" }, { "name": "KNNImputer", @@ -23194,8 +23147,8 @@ ], "is_public": true, "description": "Imputation for completing missing values using k-Nearest Neighbors.\n\nEach sample's missing values are imputed using the mean value from `n_neighbors` nearest neighbors found in the training set. Two samples are close if the features that neither is missing are close. Read more in the :ref:`User Guide `. .. versionadded:: 0.22", - "docstring": "Imputation for completing missing values using k-Nearest Neighbors.\n\n Each sample's missing values are imputed using the mean value from\n `n_neighbors` nearest neighbors found in the training set. Two samples are\n close if the features that neither is missing are close.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.22\n\n Parameters\n ----------\n missing_values : int, float, str, np.nan or None, default=np.nan\n The placeholder for the missing values. All occurrences of\n `missing_values` will be imputed. For pandas' dataframes with\n nullable integer dtypes with missing values, `missing_values`\n should be set to np.nan, since `pd.NA` will be converted to np.nan.\n\n n_neighbors : int, default=5\n Number of neighboring samples to use for imputation.\n\n weights : {'uniform', 'distance'} or callable, default='uniform'\n Weight function used in prediction. Possible values:\n\n - 'uniform' : uniform weights. All points in each neighborhood are\n weighted equally.\n - 'distance' : weight points by the inverse of their distance.\n in this case, closer neighbors of a query point will have a\n greater influence than neighbors which are further away.\n - callable : a user-defined function which accepts an\n array of distances, and returns an array of the same shape\n containing the weights.\n\n metric : {'nan_euclidean'} or callable, default='nan_euclidean'\n Distance metric for searching neighbors. Possible values:\n\n - 'nan_euclidean'\n - callable : a user-defined function which conforms to the definition\n of ``_pairwise_callable(X, Y, metric, **kwds)``. The function\n accepts two arrays, X and Y, and a `missing_values` keyword in\n `kwds` and returns a scalar distance value.\n\n copy : bool, default=True\n If True, a copy of X will be created. If False, imputation will\n be done in-place whenever possible.\n\n add_indicator : bool, default=False\n If True, a :class:`MissingIndicator` transform will stack onto the\n output of the imputer's transform. This allows a predictive estimator\n to account for missingness despite imputation. If a feature has no\n missing values at fit/train time, the feature won't appear on the\n missing indicator even if there are missing values at transform/test\n time.\n\n Attributes\n ----------\n indicator_ : :class:`~sklearn.impute.MissingIndicator`\n Indicator used to add binary indicators for missing values.\n ``None`` if add_indicator is False.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n References\n ----------\n * Olga Troyanskaya, Michael Cantor, Gavin Sherlock, Pat Brown, Trevor\n Hastie, Robert Tibshirani, David Botstein and Russ B. Altman, Missing\n value estimation methods for DNA microarrays, BIOINFORMATICS Vol. 17\n no. 6, 2001 Pages 520-525.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.impute import KNNImputer\n >>> X = [[1, 2, np.nan], [3, 4, 3], [np.nan, 6, 5], [8, 8, 7]]\n >>> imputer = KNNImputer(n_neighbors=2)\n >>> imputer.fit_transform(X)\n array([[1. , 2. , 4. ],\n [3. , 4. , 3. ],\n [5.5, 6. , 5. ],\n [8. , 8. , 7. ]])\n ", - "source_code": "\n\nclass KNNImputer(_BaseImputer):\n \"\"\"Imputation for completing missing values using k-Nearest Neighbors.\n\n Each sample's missing values are imputed using the mean value from\n `n_neighbors` nearest neighbors found in the training set. Two samples are\n close if the features that neither is missing are close.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.22\n\n Parameters\n ----------\n missing_values : int, float, str, np.nan or None, default=np.nan\n The placeholder for the missing values. All occurrences of\n `missing_values` will be imputed. For pandas' dataframes with\n nullable integer dtypes with missing values, `missing_values`\n should be set to np.nan, since `pd.NA` will be converted to np.nan.\n\n n_neighbors : int, default=5\n Number of neighboring samples to use for imputation.\n\n weights : {'uniform', 'distance'} or callable, default='uniform'\n Weight function used in prediction. Possible values:\n\n - 'uniform' : uniform weights. All points in each neighborhood are\n weighted equally.\n - 'distance' : weight points by the inverse of their distance.\n in this case, closer neighbors of a query point will have a\n greater influence than neighbors which are further away.\n - callable : a user-defined function which accepts an\n array of distances, and returns an array of the same shape\n containing the weights.\n\n metric : {'nan_euclidean'} or callable, default='nan_euclidean'\n Distance metric for searching neighbors. Possible values:\n\n - 'nan_euclidean'\n - callable : a user-defined function which conforms to the definition\n of ``_pairwise_callable(X, Y, metric, **kwds)``. The function\n accepts two arrays, X and Y, and a `missing_values` keyword in\n `kwds` and returns a scalar distance value.\n\n copy : bool, default=True\n If True, a copy of X will be created. If False, imputation will\n be done in-place whenever possible.\n\n add_indicator : bool, default=False\n If True, a :class:`MissingIndicator` transform will stack onto the\n output of the imputer's transform. This allows a predictive estimator\n to account for missingness despite imputation. If a feature has no\n missing values at fit/train time, the feature won't appear on the\n missing indicator even if there are missing values at transform/test\n time.\n\n Attributes\n ----------\n indicator_ : :class:`~sklearn.impute.MissingIndicator`\n Indicator used to add binary indicators for missing values.\n ``None`` if add_indicator is False.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n References\n ----------\n * Olga Troyanskaya, Michael Cantor, Gavin Sherlock, Pat Brown, Trevor\n Hastie, Robert Tibshirani, David Botstein and Russ B. Altman, Missing\n value estimation methods for DNA microarrays, BIOINFORMATICS Vol. 17\n no. 6, 2001 Pages 520-525.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.impute import KNNImputer\n >>> X = [[1, 2, np.nan], [3, 4, 3], [np.nan, 6, 5], [8, 8, 7]]\n >>> imputer = KNNImputer(n_neighbors=2)\n >>> imputer.fit_transform(X)\n array([[1. , 2. , 4. ],\n [3. , 4. , 3. ],\n [5.5, 6. , 5. ],\n [8. , 8. , 7. ]])\n \"\"\"\n \n def __init__(self, *, missing_values=np.nan, n_neighbors=5, weights='uniform', metric='nan_euclidean', copy=True, add_indicator=False):\n super().__init__(missing_values=missing_values, add_indicator=add_indicator)\n self.n_neighbors = n_neighbors\n self.weights = weights\n self.metric = metric\n self.copy = copy\n \n def _calc_impute(self, dist_pot_donors, n_neighbors, fit_X_col, mask_fit_X_col):\n \"\"\"Helper function to impute a single column.\n\n Parameters\n ----------\n dist_pot_donors : ndarray of shape (n_receivers, n_potential_donors)\n Distance matrix between the receivers and potential donors from\n training set. There must be at least one non-nan distance between\n a receiver and a potential donor.\n\n n_neighbors : int\n Number of neighbors to consider.\n\n fit_X_col : ndarray of shape (n_potential_donors,)\n Column of potential donors from training set.\n\n mask_fit_X_col : ndarray of shape (n_potential_donors,)\n Missing mask for fit_X_col.\n\n Returns\n -------\n imputed_values: ndarray of shape (n_receivers,)\n Imputed values for receiver.\n \"\"\"\n donors_idx = np.argpartition(dist_pot_donors, n_neighbors - 1, axis=1)[:, :n_neighbors]\n donors_dist = dist_pot_donors[np.arange(donors_idx.shape[0])[:, None], donors_idx]\n weight_matrix = _get_weights(donors_dist, self.weights)\n if weight_matrix is not None:\n weight_matrix[np.isnan(weight_matrix)] = 0.0\n donors = fit_X_col.take(donors_idx)\n donors_mask = mask_fit_X_col.take(donors_idx)\n donors = np.ma.array(donors, mask=donors_mask)\n return np.ma.average(donors, axis=1, weights=weight_matrix).data\n \n def fit(self, X, y=None):\n \"\"\"Fit the imputer on X.\n\n Parameters\n ----------\n X : array-like shape of (n_samples, n_features)\n Input data, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n Returns\n -------\n self : object\n \"\"\"\n if not is_scalar_nan(self.missing_values):\n force_all_finite = True\n else:\n force_all_finite = 'allow-nan'\n if self.metric not in _NAN_METRICS and not callable(self.metric):\n raise ValueError('The selected metric does not support NaN values')\n if self.n_neighbors <= 0:\n raise ValueError('Expected n_neighbors > 0. Got {}'.format(self.n_neighbors))\n X = self._validate_data(X, accept_sparse=False, dtype=FLOAT_DTYPES, force_all_finite=force_all_finite, copy=self.copy)\n _check_weights(self.weights)\n self._fit_X = X\n self._mask_fit_X = _get_mask(self._fit_X, self.missing_values)\n super()._fit_indicator(self._mask_fit_X)\n return self\n \n def transform(self, X):\n \"\"\"Impute all missing values in X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The input data to complete.\n\n Returns\n -------\n X : array-like of shape (n_samples, n_output_features)\n The imputed dataset. `n_output_features` is the number of features\n that is not always missing during `fit`.\n \"\"\"\n check_is_fitted(self)\n if not is_scalar_nan(self.missing_values):\n force_all_finite = True\n else:\n force_all_finite = 'allow-nan'\n X = self._validate_data(X, accept_sparse=False, dtype=FLOAT_DTYPES, force_all_finite=force_all_finite, copy=self.copy, reset=False)\n mask = _get_mask(X, self.missing_values)\n mask_fit_X = self._mask_fit_X\n valid_mask = ~np.all(mask_fit_X, axis=0)\n X_indicator = super()._transform_indicator(mask)\n if not np.any(mask):\n return X[:, valid_mask]\n row_missing_idx = np.flatnonzero(mask.any(axis=1))\n non_missing_fix_X = np.logical_not(mask_fit_X)\n dist_idx_map = np.zeros(X.shape[0], dtype=int)\n dist_idx_map[row_missing_idx] = np.arange(row_missing_idx.shape[0])\n \n def process_chunk(dist_chunk, start):\n row_missing_chunk = row_missing_idx[start:start + len(dist_chunk)]\n for col in range(X.shape[1]):\n if not valid_mask[col]:\n continue\n col_mask = mask[row_missing_chunk, col]\n if not np.any(col_mask):\n continue\n (potential_donors_idx, ) = np.nonzero(non_missing_fix_X[:, col])\n receivers_idx = row_missing_chunk[np.flatnonzero(col_mask)]\n dist_subset = dist_chunk[dist_idx_map[receivers_idx] - start][:, potential_donors_idx]\n all_nan_dist_mask = np.isnan(dist_subset).all(axis=1)\n all_nan_receivers_idx = receivers_idx[all_nan_dist_mask]\n if all_nan_receivers_idx.size:\n col_mean = np.ma.array(self._fit_X[:, col], mask=mask_fit_X[:, col]).mean()\n X[all_nan_receivers_idx, col] = col_mean\n if len(all_nan_receivers_idx) == len(receivers_idx):\n continue\n receivers_idx = receivers_idx[~all_nan_dist_mask]\n dist_subset = dist_chunk[dist_idx_map[receivers_idx] - start][:, potential_donors_idx]\n n_neighbors = min(self.n_neighbors, len(potential_donors_idx))\n value = self._calc_impute(dist_subset, n_neighbors, self._fit_X[potential_donors_idx, col], mask_fit_X[potential_donors_idx, col])\n X[receivers_idx, col] = value\n gen = pairwise_distances_chunked(X[row_missing_idx, :], self._fit_X, metric=self.metric, missing_values=self.missing_values, force_all_finite=force_all_finite, reduce_func=process_chunk)\n for chunk in gen:\n pass\n return super()._concatenate_indicator(X[:, valid_mask], X_indicator)\n" + "docstring": "Imputation for completing missing values using k-Nearest Neighbors.\n\n Each sample's missing values are imputed using the mean value from\n `n_neighbors` nearest neighbors found in the training set. Two samples are\n close if the features that neither is missing are close.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.22\n\n Parameters\n ----------\n missing_values : int, float, str, np.nan or None, default=np.nan\n The placeholder for the missing values. All occurrences of\n `missing_values` will be imputed. For pandas' dataframes with\n nullable integer dtypes with missing values, `missing_values`\n should be set to np.nan, since `pd.NA` will be converted to np.nan.\n\n n_neighbors : int, default=5\n Number of neighboring samples to use for imputation.\n\n weights : {'uniform', 'distance'} or callable, default='uniform'\n Weight function used in prediction. Possible values:\n\n - 'uniform' : uniform weights. All points in each neighborhood are\n weighted equally.\n - 'distance' : weight points by the inverse of their distance.\n in this case, closer neighbors of a query point will have a\n greater influence than neighbors which are further away.\n - callable : a user-defined function which accepts an\n array of distances, and returns an array of the same shape\n containing the weights.\n\n metric : {'nan_euclidean'} or callable, default='nan_euclidean'\n Distance metric for searching neighbors. Possible values:\n\n - 'nan_euclidean'\n - callable : a user-defined function which conforms to the definition\n of ``_pairwise_callable(X, Y, metric, **kwds)``. The function\n accepts two arrays, X and Y, and a `missing_values` keyword in\n `kwds` and returns a scalar distance value.\n\n copy : bool, default=True\n If True, a copy of X will be created. If False, imputation will\n be done in-place whenever possible.\n\n add_indicator : bool, default=False\n If True, a :class:`MissingIndicator` transform will stack onto the\n output of the imputer's transform. This allows a predictive estimator\n to account for missingness despite imputation. If a feature has no\n missing values at fit/train time, the feature won't appear on the\n missing indicator even if there are missing values at transform/test\n time.\n\n Attributes\n ----------\n indicator_ : :class:`~sklearn.impute.MissingIndicator`\n Indicator used to add binary indicators for missing values.\n ``None`` if add_indicator is False.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n SimpleImputer : Imputation transformer for completing missing values\n with simple strategies.\n IterativeImputer : Multivariate imputer that estimates each feature\n from all the others.\n\n References\n ----------\n * Olga Troyanskaya, Michael Cantor, Gavin Sherlock, Pat Brown, Trevor\n Hastie, Robert Tibshirani, David Botstein and Russ B. Altman, Missing\n value estimation methods for DNA microarrays, BIOINFORMATICS Vol. 17\n no. 6, 2001 Pages 520-525.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.impute import KNNImputer\n >>> X = [[1, 2, np.nan], [3, 4, 3], [np.nan, 6, 5], [8, 8, 7]]\n >>> imputer = KNNImputer(n_neighbors=2)\n >>> imputer.fit_transform(X)\n array([[1. , 2. , 4. ],\n [3. , 4. , 3. ],\n [5.5, 6. , 5. ],\n [8. , 8. , 7. ]])\n ", + "source_code": "\n\nclass KNNImputer(_BaseImputer):\n \"\"\"Imputation for completing missing values using k-Nearest Neighbors.\n\n Each sample's missing values are imputed using the mean value from\n `n_neighbors` nearest neighbors found in the training set. Two samples are\n close if the features that neither is missing are close.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.22\n\n Parameters\n ----------\n missing_values : int, float, str, np.nan or None, default=np.nan\n The placeholder for the missing values. All occurrences of\n `missing_values` will be imputed. For pandas' dataframes with\n nullable integer dtypes with missing values, `missing_values`\n should be set to np.nan, since `pd.NA` will be converted to np.nan.\n\n n_neighbors : int, default=5\n Number of neighboring samples to use for imputation.\n\n weights : {'uniform', 'distance'} or callable, default='uniform'\n Weight function used in prediction. Possible values:\n\n - 'uniform' : uniform weights. All points in each neighborhood are\n weighted equally.\n - 'distance' : weight points by the inverse of their distance.\n in this case, closer neighbors of a query point will have a\n greater influence than neighbors which are further away.\n - callable : a user-defined function which accepts an\n array of distances, and returns an array of the same shape\n containing the weights.\n\n metric : {'nan_euclidean'} or callable, default='nan_euclidean'\n Distance metric for searching neighbors. Possible values:\n\n - 'nan_euclidean'\n - callable : a user-defined function which conforms to the definition\n of ``_pairwise_callable(X, Y, metric, **kwds)``. The function\n accepts two arrays, X and Y, and a `missing_values` keyword in\n `kwds` and returns a scalar distance value.\n\n copy : bool, default=True\n If True, a copy of X will be created. If False, imputation will\n be done in-place whenever possible.\n\n add_indicator : bool, default=False\n If True, a :class:`MissingIndicator` transform will stack onto the\n output of the imputer's transform. This allows a predictive estimator\n to account for missingness despite imputation. If a feature has no\n missing values at fit/train time, the feature won't appear on the\n missing indicator even if there are missing values at transform/test\n time.\n\n Attributes\n ----------\n indicator_ : :class:`~sklearn.impute.MissingIndicator`\n Indicator used to add binary indicators for missing values.\n ``None`` if add_indicator is False.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n SimpleImputer : Imputation transformer for completing missing values\n with simple strategies.\n IterativeImputer : Multivariate imputer that estimates each feature\n from all the others.\n\n References\n ----------\n * Olga Troyanskaya, Michael Cantor, Gavin Sherlock, Pat Brown, Trevor\n Hastie, Robert Tibshirani, David Botstein and Russ B. Altman, Missing\n value estimation methods for DNA microarrays, BIOINFORMATICS Vol. 17\n no. 6, 2001 Pages 520-525.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.impute import KNNImputer\n >>> X = [[1, 2, np.nan], [3, 4, 3], [np.nan, 6, 5], [8, 8, 7]]\n >>> imputer = KNNImputer(n_neighbors=2)\n >>> imputer.fit_transform(X)\n array([[1. , 2. , 4. ],\n [3. , 4. , 3. ],\n [5.5, 6. , 5. ],\n [8. , 8. , 7. ]])\n \"\"\"\n \n def __init__(self, *, missing_values=np.nan, n_neighbors=5, weights='uniform', metric='nan_euclidean', copy=True, add_indicator=False):\n super().__init__(missing_values=missing_values, add_indicator=add_indicator)\n self.n_neighbors = n_neighbors\n self.weights = weights\n self.metric = metric\n self.copy = copy\n \n def _calc_impute(self, dist_pot_donors, n_neighbors, fit_X_col, mask_fit_X_col):\n \"\"\"Helper function to impute a single column.\n\n Parameters\n ----------\n dist_pot_donors : ndarray of shape (n_receivers, n_potential_donors)\n Distance matrix between the receivers and potential donors from\n training set. There must be at least one non-nan distance between\n a receiver and a potential donor.\n\n n_neighbors : int\n Number of neighbors to consider.\n\n fit_X_col : ndarray of shape (n_potential_donors,)\n Column of potential donors from training set.\n\n mask_fit_X_col : ndarray of shape (n_potential_donors,)\n Missing mask for fit_X_col.\n\n Returns\n -------\n imputed_values: ndarray of shape (n_receivers,)\n Imputed values for receiver.\n \"\"\"\n donors_idx = np.argpartition(dist_pot_donors, n_neighbors - 1, axis=1)[:, :n_neighbors]\n donors_dist = dist_pot_donors[np.arange(donors_idx.shape[0])[:, None], donors_idx]\n weight_matrix = _get_weights(donors_dist, self.weights)\n if weight_matrix is not None:\n weight_matrix[np.isnan(weight_matrix)] = 0.0\n donors = fit_X_col.take(donors_idx)\n donors_mask = mask_fit_X_col.take(donors_idx)\n donors = np.ma.array(donors, mask=donors_mask)\n return np.ma.average(donors, axis=1, weights=weight_matrix).data\n \n def fit(self, X, y=None):\n \"\"\"Fit the imputer on X.\n\n Parameters\n ----------\n X : array-like shape of (n_samples, n_features)\n Input data, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self : object\n The fitted `KNNImputer` class instance.\n \"\"\"\n if not is_scalar_nan(self.missing_values):\n force_all_finite = True\n else:\n force_all_finite = 'allow-nan'\n if self.metric not in _NAN_METRICS and not callable(self.metric):\n raise ValueError('The selected metric does not support NaN values')\n if self.n_neighbors <= 0:\n raise ValueError('Expected n_neighbors > 0. Got {}'.format(self.n_neighbors))\n X = self._validate_data(X, accept_sparse=False, dtype=FLOAT_DTYPES, force_all_finite=force_all_finite, copy=self.copy)\n _check_weights(self.weights)\n self._fit_X = X\n self._mask_fit_X = _get_mask(self._fit_X, self.missing_values)\n super()._fit_indicator(self._mask_fit_X)\n return self\n \n def transform(self, X):\n \"\"\"Impute all missing values in X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The input data to complete.\n\n Returns\n -------\n X : array-like of shape (n_samples, n_output_features)\n The imputed dataset. `n_output_features` is the number of features\n that is not always missing during `fit`.\n \"\"\"\n check_is_fitted(self)\n if not is_scalar_nan(self.missing_values):\n force_all_finite = True\n else:\n force_all_finite = 'allow-nan'\n X = self._validate_data(X, accept_sparse=False, dtype=FLOAT_DTYPES, force_all_finite=force_all_finite, copy=self.copy, reset=False)\n mask = _get_mask(X, self.missing_values)\n mask_fit_X = self._mask_fit_X\n valid_mask = ~np.all(mask_fit_X, axis=0)\n X_indicator = super()._transform_indicator(mask)\n if not np.any(mask):\n return X[:, valid_mask]\n row_missing_idx = np.flatnonzero(mask.any(axis=1))\n non_missing_fix_X = np.logical_not(mask_fit_X)\n dist_idx_map = np.zeros(X.shape[0], dtype=int)\n dist_idx_map[row_missing_idx] = np.arange(row_missing_idx.shape[0])\n \n def process_chunk(dist_chunk, start):\n row_missing_chunk = row_missing_idx[start:start + len(dist_chunk)]\n for col in range(X.shape[1]):\n if not valid_mask[col]:\n continue\n col_mask = mask[row_missing_chunk, col]\n if not np.any(col_mask):\n continue\n (potential_donors_idx, ) = np.nonzero(non_missing_fix_X[:, col])\n receivers_idx = row_missing_chunk[np.flatnonzero(col_mask)]\n dist_subset = dist_chunk[dist_idx_map[receivers_idx] - start][:, potential_donors_idx]\n all_nan_dist_mask = np.isnan(dist_subset).all(axis=1)\n all_nan_receivers_idx = receivers_idx[all_nan_dist_mask]\n if all_nan_receivers_idx.size:\n col_mean = np.ma.array(self._fit_X[:, col], mask=mask_fit_X[:, col]).mean()\n X[all_nan_receivers_idx, col] = col_mean\n if len(all_nan_receivers_idx) == len(receivers_idx):\n continue\n receivers_idx = receivers_idx[~all_nan_dist_mask]\n dist_subset = dist_chunk[dist_idx_map[receivers_idx] - start][:, potential_donors_idx]\n n_neighbors = min(self.n_neighbors, len(potential_donors_idx))\n value = self._calc_impute(dist_subset, n_neighbors, self._fit_X[potential_donors_idx, col], mask_fit_X[potential_donors_idx, col])\n X[receivers_idx, col] = value\n gen = pairwise_distances_chunked(X[row_missing_idx, :], self._fit_X, metric=self.metric, missing_values=self.missing_values, force_all_finite=force_all_finite, reduce_func=process_chunk)\n for chunk in gen:\n pass\n return super()._concatenate_indicator(X[:, valid_mask], X_indicator)\n" }, { "name": "PartialDependenceDisplay", @@ -23336,14 +23289,14 @@ "sklearn.kernel_ridge.KernelRidge.__init__", "sklearn.kernel_ridge.KernelRidge._get_kernel", "sklearn.kernel_ridge.KernelRidge._more_tags", - "sklearn.kernel_ridge.KernelRidge._pairwise", + "sklearn.kernel_ridge.KernelRidge._pairwise@getter", "sklearn.kernel_ridge.KernelRidge.fit", "sklearn.kernel_ridge.KernelRidge.predict" ], "is_public": true, "description": "Kernel ridge regression.\n\nKernel ridge regression (KRR) combines ridge regression (linear least squares with l2-norm regularization) with the kernel trick. It thus learns a linear function in the space induced by the respective kernel and the data. For non-linear kernels, this corresponds to a non-linear function in the original space. The form of the model learned by KRR is identical to support vector regression (SVR). However, different loss functions are used: KRR uses squared error loss while support vector regression uses epsilon-insensitive loss, both combined with l2 regularization. In contrast to SVR, fitting a KRR model can be done in closed-form and is typically faster for medium-sized datasets. On the other hand, the learned model is non-sparse and thus slower than SVR, which learns a sparse model for epsilon > 0, at prediction-time. This estimator has built-in support for multi-variate regression (i.e., when y is a 2d-array of shape [n_samples, n_targets]). Read more in the :ref:`User Guide `.", - "docstring": "Kernel ridge regression.\n\n Kernel ridge regression (KRR) combines ridge regression (linear least\n squares with l2-norm regularization) with the kernel trick. It thus\n learns a linear function in the space induced by the respective kernel and\n the data. For non-linear kernels, this corresponds to a non-linear\n function in the original space.\n\n The form of the model learned by KRR is identical to support vector\n regression (SVR). However, different loss functions are used: KRR uses\n squared error loss while support vector regression uses epsilon-insensitive\n loss, both combined with l2 regularization. In contrast to SVR, fitting a\n KRR model can be done in closed-form and is typically faster for\n medium-sized datasets. On the other hand, the learned model is non-sparse\n and thus slower than SVR, which learns a sparse model for epsilon > 0, at\n prediction-time.\n\n This estimator has built-in support for multi-variate regression\n (i.e., when y is a 2d-array of shape [n_samples, n_targets]).\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n alpha : float or array-like of shape (n_targets,), default=1.0\n Regularization strength; must be a positive float. Regularization\n improves the conditioning of the problem and reduces the variance of\n the estimates. Larger values specify stronger regularization.\n Alpha corresponds to ``1 / (2C)`` in other linear models such as\n :class:`~sklearn.linear_model.LogisticRegression` or\n :class:`~sklearn.svm.LinearSVC`. If an array is passed, penalties are\n assumed to be specific to the targets. Hence they must correspond in\n number. See :ref:`ridge_regression` for formula.\n\n kernel : str or callable, default=\"linear\"\n Kernel mapping used internally. This parameter is directly passed to\n :class:`~sklearn.metrics.pairwise.pairwise_kernel`.\n If `kernel` is a string, it must be one of the metrics\n in `pairwise.PAIRWISE_KERNEL_FUNCTIONS`.\n If `kernel` is \"precomputed\", X is assumed to be a kernel matrix.\n Alternatively, if `kernel` is a callable function, it is called on\n each pair of instances (rows) and the resulting value recorded. The\n callable should take two rows from X as input and return the\n corresponding kernel value as a single number. This means that\n callables from :mod:`sklearn.metrics.pairwise` are not allowed, as\n they operate on matrices, not single samples. Use the string\n identifying the kernel instead.\n\n gamma : float, default=None\n Gamma parameter for the RBF, laplacian, polynomial, exponential chi2\n and sigmoid kernels. Interpretation of the default value is left to\n the kernel; see the documentation for sklearn.metrics.pairwise.\n Ignored by other kernels.\n\n degree : float, default=3\n Degree of the polynomial kernel. Ignored by other kernels.\n\n coef0 : float, default=1\n Zero coefficient for polynomial and sigmoid kernels.\n Ignored by other kernels.\n\n kernel_params : mapping of str to any, default=None\n Additional parameters (keyword arguments) for kernel function passed\n as callable object.\n\n Attributes\n ----------\n dual_coef_ : ndarray of shape (n_samples,) or (n_samples, n_targets)\n Representation of weight vector(s) in kernel space\n\n X_fit_ : {ndarray, sparse matrix} of shape (n_samples, n_features)\n Training data, which is also required for prediction. If\n kernel == \"precomputed\" this is instead the precomputed\n training matrix, of shape (n_samples, n_samples).\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n sklearn.gaussian_process.GaussianProcessRegressor : Gaussian\n Process regressor providing automatic kernel hyperparameters\n tuning and predictions uncertainty.\n sklearn.linear_model.Ridge : Linear ridge regression.\n sklearn.linear_model.RidgeCV : Ridge regression with built-in\n cross-validation.\n sklearn.svm.SVR : Support Vector Regression accepting a large variety\n of kernels.\n\n References\n ----------\n * Kevin P. Murphy\n \"Machine Learning: A Probabilistic Perspective\", The MIT Press\n chapter 14.4.3, pp. 492-493\n\n Examples\n --------\n >>> from sklearn.kernel_ridge import KernelRidge\n >>> import numpy as np\n >>> n_samples, n_features = 10, 5\n >>> rng = np.random.RandomState(0)\n >>> y = rng.randn(n_samples)\n >>> X = rng.randn(n_samples, n_features)\n >>> clf = KernelRidge(alpha=1.0)\n >>> clf.fit(X, y)\n KernelRidge(alpha=1.0)\n ", - "source_code": "\n\nclass KernelRidge(MultiOutputMixin, RegressorMixin, BaseEstimator):\n \"\"\"Kernel ridge regression.\n\n Kernel ridge regression (KRR) combines ridge regression (linear least\n squares with l2-norm regularization) with the kernel trick. It thus\n learns a linear function in the space induced by the respective kernel and\n the data. For non-linear kernels, this corresponds to a non-linear\n function in the original space.\n\n The form of the model learned by KRR is identical to support vector\n regression (SVR). However, different loss functions are used: KRR uses\n squared error loss while support vector regression uses epsilon-insensitive\n loss, both combined with l2 regularization. In contrast to SVR, fitting a\n KRR model can be done in closed-form and is typically faster for\n medium-sized datasets. On the other hand, the learned model is non-sparse\n and thus slower than SVR, which learns a sparse model for epsilon > 0, at\n prediction-time.\n\n This estimator has built-in support for multi-variate regression\n (i.e., when y is a 2d-array of shape [n_samples, n_targets]).\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n alpha : float or array-like of shape (n_targets,), default=1.0\n Regularization strength; must be a positive float. Regularization\n improves the conditioning of the problem and reduces the variance of\n the estimates. Larger values specify stronger regularization.\n Alpha corresponds to ``1 / (2C)`` in other linear models such as\n :class:`~sklearn.linear_model.LogisticRegression` or\n :class:`~sklearn.svm.LinearSVC`. If an array is passed, penalties are\n assumed to be specific to the targets. Hence they must correspond in\n number. See :ref:`ridge_regression` for formula.\n\n kernel : str or callable, default=\"linear\"\n Kernel mapping used internally. This parameter is directly passed to\n :class:`~sklearn.metrics.pairwise.pairwise_kernel`.\n If `kernel` is a string, it must be one of the metrics\n in `pairwise.PAIRWISE_KERNEL_FUNCTIONS`.\n If `kernel` is \"precomputed\", X is assumed to be a kernel matrix.\n Alternatively, if `kernel` is a callable function, it is called on\n each pair of instances (rows) and the resulting value recorded. The\n callable should take two rows from X as input and return the\n corresponding kernel value as a single number. This means that\n callables from :mod:`sklearn.metrics.pairwise` are not allowed, as\n they operate on matrices, not single samples. Use the string\n identifying the kernel instead.\n\n gamma : float, default=None\n Gamma parameter for the RBF, laplacian, polynomial, exponential chi2\n and sigmoid kernels. Interpretation of the default value is left to\n the kernel; see the documentation for sklearn.metrics.pairwise.\n Ignored by other kernels.\n\n degree : float, default=3\n Degree of the polynomial kernel. Ignored by other kernels.\n\n coef0 : float, default=1\n Zero coefficient for polynomial and sigmoid kernels.\n Ignored by other kernels.\n\n kernel_params : mapping of str to any, default=None\n Additional parameters (keyword arguments) for kernel function passed\n as callable object.\n\n Attributes\n ----------\n dual_coef_ : ndarray of shape (n_samples,) or (n_samples, n_targets)\n Representation of weight vector(s) in kernel space\n\n X_fit_ : {ndarray, sparse matrix} of shape (n_samples, n_features)\n Training data, which is also required for prediction. If\n kernel == \"precomputed\" this is instead the precomputed\n training matrix, of shape (n_samples, n_samples).\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n sklearn.gaussian_process.GaussianProcessRegressor : Gaussian\n Process regressor providing automatic kernel hyperparameters\n tuning and predictions uncertainty.\n sklearn.linear_model.Ridge : Linear ridge regression.\n sklearn.linear_model.RidgeCV : Ridge regression with built-in\n cross-validation.\n sklearn.svm.SVR : Support Vector Regression accepting a large variety\n of kernels.\n\n References\n ----------\n * Kevin P. Murphy\n \"Machine Learning: A Probabilistic Perspective\", The MIT Press\n chapter 14.4.3, pp. 492-493\n\n Examples\n --------\n >>> from sklearn.kernel_ridge import KernelRidge\n >>> import numpy as np\n >>> n_samples, n_features = 10, 5\n >>> rng = np.random.RandomState(0)\n >>> y = rng.randn(n_samples)\n >>> X = rng.randn(n_samples, n_features)\n >>> clf = KernelRidge(alpha=1.0)\n >>> clf.fit(X, y)\n KernelRidge(alpha=1.0)\n \"\"\"\n \n def __init__(self, alpha=1, *, kernel='linear', gamma=None, degree=3, coef0=1, kernel_params=None):\n self.alpha = alpha\n self.kernel = kernel\n self.gamma = gamma\n self.degree = degree\n self.coef0 = coef0\n self.kernel_params = kernel_params\n \n def _get_kernel(self, X, Y=None):\n if callable(self.kernel):\n params = self.kernel_params or {}\n else:\n params = {'gamma': self.gamma, 'degree': self.degree, 'coef0': self.coef0}\n return pairwise_kernels(X, Y, metric=self.kernel, filter_params=True, **params)\n \n def _more_tags(self):\n return {'pairwise': self.kernel == 'precomputed'}\n \n @deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def _pairwise(self):\n return self.kernel == 'precomputed'\n \n def fit(self, X, y, sample_weight=None):\n \"\"\"Fit Kernel Ridge regression model.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training data. If kernel == \"precomputed\" this is instead\n a precomputed kernel matrix, of shape (n_samples, n_samples).\n\n y : array-like of shape (n_samples,) or (n_samples, n_targets)\n Target values.\n\n sample_weight : float or array-like of shape (n_samples,), default=None\n Individual weights for each sample, ignored if None is passed.\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n (X, y) = self._validate_data(X, y, accept_sparse=('csr', 'csc'), multi_output=True, y_numeric=True)\n if sample_weight is not None and not isinstance(sample_weight, float):\n sample_weight = _check_sample_weight(sample_weight, X)\n K = self._get_kernel(X)\n alpha = np.atleast_1d(self.alpha)\n ravel = False\n if len(y.shape) == 1:\n y = y.reshape(-1, 1)\n ravel = True\n copy = self.kernel == 'precomputed'\n self.dual_coef_ = _solve_cholesky_kernel(K, y, alpha, sample_weight, copy)\n if ravel:\n self.dual_coef_ = self.dual_coef_.ravel()\n self.X_fit_ = X\n return self\n \n def predict(self, X):\n \"\"\"Predict using the kernel ridge model.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Samples. If kernel == \"precomputed\" this is instead a\n precomputed kernel matrix, shape = [n_samples,\n n_samples_fitted], where n_samples_fitted is the number of\n samples used in the fitting for this estimator.\n\n Returns\n -------\n C : ndarray of shape (n_samples,) or (n_samples, n_targets)\n Returns predicted values.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse=('csr', 'csc'), reset=False)\n K = self._get_kernel(X, self.X_fit_)\n return np.dot(K, self.dual_coef_)\n" + "docstring": "Kernel ridge regression.\n\n Kernel ridge regression (KRR) combines ridge regression (linear least\n squares with l2-norm regularization) with the kernel trick. It thus\n learns a linear function in the space induced by the respective kernel and\n the data. For non-linear kernels, this corresponds to a non-linear\n function in the original space.\n\n The form of the model learned by KRR is identical to support vector\n regression (SVR). However, different loss functions are used: KRR uses\n squared error loss while support vector regression uses epsilon-insensitive\n loss, both combined with l2 regularization. In contrast to SVR, fitting a\n KRR model can be done in closed-form and is typically faster for\n medium-sized datasets. On the other hand, the learned model is non-sparse\n and thus slower than SVR, which learns a sparse model for epsilon > 0, at\n prediction-time.\n\n This estimator has built-in support for multi-variate regression\n (i.e., when y is a 2d-array of shape [n_samples, n_targets]).\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n alpha : float or array-like of shape (n_targets,), default=1.0\n Regularization strength; must be a positive float. Regularization\n improves the conditioning of the problem and reduces the variance of\n the estimates. Larger values specify stronger regularization.\n Alpha corresponds to ``1 / (2C)`` in other linear models such as\n :class:`~sklearn.linear_model.LogisticRegression` or\n :class:`~sklearn.svm.LinearSVC`. If an array is passed, penalties are\n assumed to be specific to the targets. Hence they must correspond in\n number. See :ref:`ridge_regression` for formula.\n\n kernel : str or callable, default=\"linear\"\n Kernel mapping used internally. This parameter is directly passed to\n :class:`~sklearn.metrics.pairwise.pairwise_kernel`.\n If `kernel` is a string, it must be one of the metrics\n in `pairwise.PAIRWISE_KERNEL_FUNCTIONS`.\n If `kernel` is \"precomputed\", X is assumed to be a kernel matrix.\n Alternatively, if `kernel` is a callable function, it is called on\n each pair of instances (rows) and the resulting value recorded. The\n callable should take two rows from X as input and return the\n corresponding kernel value as a single number. This means that\n callables from :mod:`sklearn.metrics.pairwise` are not allowed, as\n they operate on matrices, not single samples. Use the string\n identifying the kernel instead.\n\n gamma : float, default=None\n Gamma parameter for the RBF, laplacian, polynomial, exponential chi2\n and sigmoid kernels. Interpretation of the default value is left to\n the kernel; see the documentation for sklearn.metrics.pairwise.\n Ignored by other kernels.\n\n degree : float, default=3\n Degree of the polynomial kernel. Ignored by other kernels.\n\n coef0 : float, default=1\n Zero coefficient for polynomial and sigmoid kernels.\n Ignored by other kernels.\n\n kernel_params : mapping of str to any, default=None\n Additional parameters (keyword arguments) for kernel function passed\n as callable object.\n\n Attributes\n ----------\n dual_coef_ : ndarray of shape (n_samples,) or (n_samples, n_targets)\n Representation of weight vector(s) in kernel space\n\n X_fit_ : {ndarray, sparse matrix} of shape (n_samples, n_features)\n Training data, which is also required for prediction. If\n kernel == \"precomputed\" this is instead the precomputed\n training matrix, of shape (n_samples, n_samples).\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n sklearn.gaussian_process.GaussianProcessRegressor : Gaussian\n Process regressor providing automatic kernel hyperparameters\n tuning and predictions uncertainty.\n sklearn.linear_model.Ridge : Linear ridge regression.\n sklearn.linear_model.RidgeCV : Ridge regression with built-in\n cross-validation.\n sklearn.svm.SVR : Support Vector Regression accepting a large variety\n of kernels.\n\n References\n ----------\n * Kevin P. Murphy\n \"Machine Learning: A Probabilistic Perspective\", The MIT Press\n chapter 14.4.3, pp. 492-493\n\n Examples\n --------\n >>> from sklearn.kernel_ridge import KernelRidge\n >>> import numpy as np\n >>> n_samples, n_features = 10, 5\n >>> rng = np.random.RandomState(0)\n >>> y = rng.randn(n_samples)\n >>> X = rng.randn(n_samples, n_features)\n >>> krr = KernelRidge(alpha=1.0)\n >>> krr.fit(X, y)\n KernelRidge(alpha=1.0)\n ", + "source_code": "\n\nclass KernelRidge(MultiOutputMixin, RegressorMixin, BaseEstimator):\n \"\"\"Kernel ridge regression.\n\n Kernel ridge regression (KRR) combines ridge regression (linear least\n squares with l2-norm regularization) with the kernel trick. It thus\n learns a linear function in the space induced by the respective kernel and\n the data. For non-linear kernels, this corresponds to a non-linear\n function in the original space.\n\n The form of the model learned by KRR is identical to support vector\n regression (SVR). However, different loss functions are used: KRR uses\n squared error loss while support vector regression uses epsilon-insensitive\n loss, both combined with l2 regularization. In contrast to SVR, fitting a\n KRR model can be done in closed-form and is typically faster for\n medium-sized datasets. On the other hand, the learned model is non-sparse\n and thus slower than SVR, which learns a sparse model for epsilon > 0, at\n prediction-time.\n\n This estimator has built-in support for multi-variate regression\n (i.e., when y is a 2d-array of shape [n_samples, n_targets]).\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n alpha : float or array-like of shape (n_targets,), default=1.0\n Regularization strength; must be a positive float. Regularization\n improves the conditioning of the problem and reduces the variance of\n the estimates. Larger values specify stronger regularization.\n Alpha corresponds to ``1 / (2C)`` in other linear models such as\n :class:`~sklearn.linear_model.LogisticRegression` or\n :class:`~sklearn.svm.LinearSVC`. If an array is passed, penalties are\n assumed to be specific to the targets. Hence they must correspond in\n number. See :ref:`ridge_regression` for formula.\n\n kernel : str or callable, default=\"linear\"\n Kernel mapping used internally. This parameter is directly passed to\n :class:`~sklearn.metrics.pairwise.pairwise_kernel`.\n If `kernel` is a string, it must be one of the metrics\n in `pairwise.PAIRWISE_KERNEL_FUNCTIONS`.\n If `kernel` is \"precomputed\", X is assumed to be a kernel matrix.\n Alternatively, if `kernel` is a callable function, it is called on\n each pair of instances (rows) and the resulting value recorded. The\n callable should take two rows from X as input and return the\n corresponding kernel value as a single number. This means that\n callables from :mod:`sklearn.metrics.pairwise` are not allowed, as\n they operate on matrices, not single samples. Use the string\n identifying the kernel instead.\n\n gamma : float, default=None\n Gamma parameter for the RBF, laplacian, polynomial, exponential chi2\n and sigmoid kernels. Interpretation of the default value is left to\n the kernel; see the documentation for sklearn.metrics.pairwise.\n Ignored by other kernels.\n\n degree : float, default=3\n Degree of the polynomial kernel. Ignored by other kernels.\n\n coef0 : float, default=1\n Zero coefficient for polynomial and sigmoid kernels.\n Ignored by other kernels.\n\n kernel_params : mapping of str to any, default=None\n Additional parameters (keyword arguments) for kernel function passed\n as callable object.\n\n Attributes\n ----------\n dual_coef_ : ndarray of shape (n_samples,) or (n_samples, n_targets)\n Representation of weight vector(s) in kernel space\n\n X_fit_ : {ndarray, sparse matrix} of shape (n_samples, n_features)\n Training data, which is also required for prediction. If\n kernel == \"precomputed\" this is instead the precomputed\n training matrix, of shape (n_samples, n_samples).\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n sklearn.gaussian_process.GaussianProcessRegressor : Gaussian\n Process regressor providing automatic kernel hyperparameters\n tuning and predictions uncertainty.\n sklearn.linear_model.Ridge : Linear ridge regression.\n sklearn.linear_model.RidgeCV : Ridge regression with built-in\n cross-validation.\n sklearn.svm.SVR : Support Vector Regression accepting a large variety\n of kernels.\n\n References\n ----------\n * Kevin P. Murphy\n \"Machine Learning: A Probabilistic Perspective\", The MIT Press\n chapter 14.4.3, pp. 492-493\n\n Examples\n --------\n >>> from sklearn.kernel_ridge import KernelRidge\n >>> import numpy as np\n >>> n_samples, n_features = 10, 5\n >>> rng = np.random.RandomState(0)\n >>> y = rng.randn(n_samples)\n >>> X = rng.randn(n_samples, n_features)\n >>> krr = KernelRidge(alpha=1.0)\n >>> krr.fit(X, y)\n KernelRidge(alpha=1.0)\n \"\"\"\n \n def __init__(self, alpha=1, *, kernel='linear', gamma=None, degree=3, coef0=1, kernel_params=None):\n self.alpha = alpha\n self.kernel = kernel\n self.gamma = gamma\n self.degree = degree\n self.coef0 = coef0\n self.kernel_params = kernel_params\n \n def _get_kernel(self, X, Y=None):\n if callable(self.kernel):\n params = self.kernel_params or {}\n else:\n params = {'gamma': self.gamma, 'degree': self.degree, 'coef0': self.coef0}\n return pairwise_kernels(X, Y, metric=self.kernel, filter_params=True, **params)\n \n def _more_tags(self):\n return {'pairwise': self.kernel == 'precomputed'}\n \n @deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def _pairwise(self):\n return self.kernel == 'precomputed'\n \n def fit(self, X, y, sample_weight=None):\n \"\"\"Fit Kernel Ridge regression model.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training data. If kernel == \"precomputed\" this is instead\n a precomputed kernel matrix, of shape (n_samples, n_samples).\n\n y : array-like of shape (n_samples,) or (n_samples, n_targets)\n Target values.\n\n sample_weight : float or array-like of shape (n_samples,), default=None\n Individual weights for each sample, ignored if None is passed.\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n (X, y) = self._validate_data(X, y, accept_sparse=('csr', 'csc'), multi_output=True, y_numeric=True)\n if sample_weight is not None and not isinstance(sample_weight, float):\n sample_weight = _check_sample_weight(sample_weight, X)\n K = self._get_kernel(X)\n alpha = np.atleast_1d(self.alpha)\n ravel = False\n if len(y.shape) == 1:\n y = y.reshape(-1, 1)\n ravel = True\n copy = self.kernel == 'precomputed'\n self.dual_coef_ = _solve_cholesky_kernel(K, y, alpha, sample_weight, copy)\n if ravel:\n self.dual_coef_ = self.dual_coef_.ravel()\n self.X_fit_ = X\n return self\n \n def predict(self, X):\n \"\"\"Predict using the kernel ridge model.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Samples. If kernel == \"precomputed\" this is instead a\n precomputed kernel matrix, shape = [n_samples,\n n_samples_fitted], where n_samples_fitted is the number of\n samples used in the fitting for this estimator.\n\n Returns\n -------\n C : ndarray of shape (n_samples,) or (n_samples, n_targets)\n Returns predicted values.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse=('csr', 'csc'), reset=False)\n K = self._get_kernel(X, self.X_fit_)\n return np.dot(K, self.dual_coef_)\n" }, { "name": "LinearClassifierMixin", @@ -23392,8 +23345,8 @@ ], "is_public": true, "description": "Ordinary least squares Linear Regression.\n\nLinearRegression fits a linear model with coefficients w = (w1, ..., wp) to minimize the residual sum of squares between the observed targets in the dataset, and the targets predicted by the linear approximation.", - "docstring": "\n Ordinary least squares Linear Regression.\n\n LinearRegression fits a linear model with coefficients w = (w1, ..., wp)\n to minimize the residual sum of squares between the observed targets in\n the dataset, and the targets predicted by the linear approximation.\n\n Parameters\n ----------\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to False, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=False\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n `normalize` was deprecated in version 1.0 and will be\n removed in 1.2.\n\n copy_X : bool, default=True\n If True, X will be copied; else, it may be overwritten.\n\n n_jobs : int, default=None\n The number of jobs to use for the computation. This will only provide\n speedup for n_targets > 1 and sufficient large problems.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n positive : bool, default=False\n When set to ``True``, forces the coefficients to be positive. This\n option is only supported for dense arrays.\n\n .. versionadded:: 0.24\n\n Attributes\n ----------\n coef_ : array of shape (n_features, ) or (n_targets, n_features)\n Estimated coefficients for the linear regression problem.\n If multiple targets are passed during the fit (y 2D), this\n is a 2D array of shape (n_targets, n_features), while if only\n one target is passed, this is a 1D array of length n_features.\n\n rank_ : int\n Rank of matrix `X`. Only available when `X` is dense.\n\n singular_ : array of shape (min(X, y),)\n Singular values of `X`. Only available when `X` is dense.\n\n intercept_ : float or array of shape (n_targets,)\n Independent term in the linear model. Set to 0.0 if\n `fit_intercept = False`.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n Ridge : Ridge regression addresses some of the\n problems of Ordinary Least Squares by imposing a penalty on the\n size of the coefficients with l2 regularization.\n Lasso : The Lasso is a linear model that estimates\n sparse coefficients with l1 regularization.\n ElasticNet : Elastic-Net is a linear regression\n model trained with both l1 and l2 -norm regularization of the\n coefficients.\n\n Notes\n -----\n From the implementation point of view, this is just plain Ordinary\n Least Squares (scipy.linalg.lstsq) or Non Negative Least Squares\n (scipy.optimize.nnls) wrapped as a predictor object.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.linear_model import LinearRegression\n >>> X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])\n >>> # y = 1 * x_0 + 2 * x_1 + 3\n >>> y = np.dot(X, np.array([1, 2])) + 3\n >>> reg = LinearRegression().fit(X, y)\n >>> reg.score(X, y)\n 1.0\n >>> reg.coef_\n array([1., 2.])\n >>> reg.intercept_\n 3.0...\n >>> reg.predict(np.array([[3, 5]]))\n array([16.])\n ", - "source_code": "\n\nclass LinearRegression(MultiOutputMixin, RegressorMixin, LinearModel):\n \"\"\"\n Ordinary least squares Linear Regression.\n\n LinearRegression fits a linear model with coefficients w = (w1, ..., wp)\n to minimize the residual sum of squares between the observed targets in\n the dataset, and the targets predicted by the linear approximation.\n\n Parameters\n ----------\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to False, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=False\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n `normalize` was deprecated in version 1.0 and will be\n removed in 1.2.\n\n copy_X : bool, default=True\n If True, X will be copied; else, it may be overwritten.\n\n n_jobs : int, default=None\n The number of jobs to use for the computation. This will only provide\n speedup for n_targets > 1 and sufficient large problems.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n positive : bool, default=False\n When set to ``True``, forces the coefficients to be positive. This\n option is only supported for dense arrays.\n\n .. versionadded:: 0.24\n\n Attributes\n ----------\n coef_ : array of shape (n_features, ) or (n_targets, n_features)\n Estimated coefficients for the linear regression problem.\n If multiple targets are passed during the fit (y 2D), this\n is a 2D array of shape (n_targets, n_features), while if only\n one target is passed, this is a 1D array of length n_features.\n\n rank_ : int\n Rank of matrix `X`. Only available when `X` is dense.\n\n singular_ : array of shape (min(X, y),)\n Singular values of `X`. Only available when `X` is dense.\n\n intercept_ : float or array of shape (n_targets,)\n Independent term in the linear model. Set to 0.0 if\n `fit_intercept = False`.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n Ridge : Ridge regression addresses some of the\n problems of Ordinary Least Squares by imposing a penalty on the\n size of the coefficients with l2 regularization.\n Lasso : The Lasso is a linear model that estimates\n sparse coefficients with l1 regularization.\n ElasticNet : Elastic-Net is a linear regression\n model trained with both l1 and l2 -norm regularization of the\n coefficients.\n\n Notes\n -----\n From the implementation point of view, this is just plain Ordinary\n Least Squares (scipy.linalg.lstsq) or Non Negative Least Squares\n (scipy.optimize.nnls) wrapped as a predictor object.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.linear_model import LinearRegression\n >>> X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])\n >>> # y = 1 * x_0 + 2 * x_1 + 3\n >>> y = np.dot(X, np.array([1, 2])) + 3\n >>> reg = LinearRegression().fit(X, y)\n >>> reg.score(X, y)\n 1.0\n >>> reg.coef_\n array([1., 2.])\n >>> reg.intercept_\n 3.0...\n >>> reg.predict(np.array([[3, 5]]))\n array([16.])\n \"\"\"\n \n def __init__(self, *, fit_intercept=True, normalize='deprecated', copy_X=True, n_jobs=None, positive=False):\n self.fit_intercept = fit_intercept\n self.normalize = normalize\n self.copy_X = copy_X\n self.n_jobs = n_jobs\n self.positive = positive\n \n def fit(self, X, y, sample_weight=None):\n \"\"\"\n Fit linear model.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training data.\n\n y : array-like of shape (n_samples,) or (n_samples, n_targets)\n Target values. Will be cast to X's dtype if necessary.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Individual weights for each sample.\n\n .. versionadded:: 0.17\n parameter *sample_weight* support to LinearRegression.\n\n Returns\n -------\n self : object\n Fitted Estimator.\n \"\"\"\n _normalize = _deprecate_normalize(self.normalize, default=False, estimator_name=self.__class__.__name__)\n n_jobs_ = self.n_jobs\n accept_sparse = False if self.positive else ['csr', 'csc', 'coo']\n (X, y) = self._validate_data(X, y, accept_sparse=accept_sparse, y_numeric=True, multi_output=True)\n if sample_weight is not None:\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n (X, y, X_offset, y_offset, X_scale) = self._preprocess_data(X, y, fit_intercept=self.fit_intercept, normalize=_normalize, copy=self.copy_X, sample_weight=sample_weight, return_mean=True)\n if sample_weight is not None:\n (X, y) = _rescale_data(X, y, sample_weight)\n if self.positive:\n if y.ndim < 2:\n (self.coef_, self._residues) = optimize.nnls(X, y)\n else:\n outs = Parallel(n_jobs=n_jobs_)((delayed(optimize.nnls)(X, y[:, j]) for j in range(y.shape[1])))\n (self.coef_, self._residues) = map(np.vstack, zip(*outs))\n elif sp.issparse(X):\n X_offset_scale = X_offset / X_scale\n \n def matvec(b):\n return X.dot(b) - b.dot(X_offset_scale)\n \n def rmatvec(b):\n return X.T.dot(b) - X_offset_scale * np.sum(b)\n X_centered = sparse.linalg.LinearOperator(shape=X.shape, matvec=matvec, rmatvec=rmatvec)\n if y.ndim < 2:\n out = sparse_lsqr(X_centered, y)\n self.coef_ = out[0]\n self._residues = out[3]\n else:\n outs = Parallel(n_jobs=n_jobs_)((delayed(sparse_lsqr)(X_centered, y[:, j].ravel()) for j in range(y.shape[1])))\n self.coef_ = np.vstack([out[0] for out in outs])\n self._residues = np.vstack([out[3] for out in outs])\n else:\n (self.coef_, self._residues, self.rank_, self.singular_) = linalg.lstsq(X, y)\n self.coef_ = self.coef_.T\n if y.ndim == 1:\n self.coef_ = np.ravel(self.coef_)\n self._set_intercept(X_offset, y_offset, X_scale)\n return self\n" + "docstring": "\n Ordinary least squares Linear Regression.\n\n LinearRegression fits a linear model with coefficients w = (w1, ..., wp)\n to minimize the residual sum of squares between the observed targets in\n the dataset, and the targets predicted by the linear approximation.\n\n Parameters\n ----------\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to False, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=False\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n `normalize` was deprecated in version 1.0 and will be\n removed in 1.2.\n\n copy_X : bool, default=True\n If True, X will be copied; else, it may be overwritten.\n\n n_jobs : int, default=None\n The number of jobs to use for the computation. This will only provide\n speedup in case of sufficiently large problems, that is if firstly\n `n_targets > 1` and secondly `X` is sparse or if `positive` is set\n to `True`. ``None`` means 1 unless in a\n :obj:`joblib.parallel_backend` context. ``-1`` means using all\n processors. See :term:`Glossary ` for more details.\n\n positive : bool, default=False\n When set to ``True``, forces the coefficients to be positive. This\n option is only supported for dense arrays.\n\n .. versionadded:: 0.24\n\n Attributes\n ----------\n coef_ : array of shape (n_features, ) or (n_targets, n_features)\n Estimated coefficients for the linear regression problem.\n If multiple targets are passed during the fit (y 2D), this\n is a 2D array of shape (n_targets, n_features), while if only\n one target is passed, this is a 1D array of length n_features.\n\n rank_ : int\n Rank of matrix `X`. Only available when `X` is dense.\n\n singular_ : array of shape (min(X, y),)\n Singular values of `X`. Only available when `X` is dense.\n\n intercept_ : float or array of shape (n_targets,)\n Independent term in the linear model. Set to 0.0 if\n `fit_intercept = False`.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n Ridge : Ridge regression addresses some of the\n problems of Ordinary Least Squares by imposing a penalty on the\n size of the coefficients with l2 regularization.\n Lasso : The Lasso is a linear model that estimates\n sparse coefficients with l1 regularization.\n ElasticNet : Elastic-Net is a linear regression\n model trained with both l1 and l2 -norm regularization of the\n coefficients.\n\n Notes\n -----\n From the implementation point of view, this is just plain Ordinary\n Least Squares (scipy.linalg.lstsq) or Non Negative Least Squares\n (scipy.optimize.nnls) wrapped as a predictor object.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.linear_model import LinearRegression\n >>> X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])\n >>> # y = 1 * x_0 + 2 * x_1 + 3\n >>> y = np.dot(X, np.array([1, 2])) + 3\n >>> reg = LinearRegression().fit(X, y)\n >>> reg.score(X, y)\n 1.0\n >>> reg.coef_\n array([1., 2.])\n >>> reg.intercept_\n 3.0...\n >>> reg.predict(np.array([[3, 5]]))\n array([16.])\n ", + "source_code": "\n\nclass LinearRegression(MultiOutputMixin, RegressorMixin, LinearModel):\n \"\"\"\n Ordinary least squares Linear Regression.\n\n LinearRegression fits a linear model with coefficients w = (w1, ..., wp)\n to minimize the residual sum of squares between the observed targets in\n the dataset, and the targets predicted by the linear approximation.\n\n Parameters\n ----------\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to False, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=False\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n `normalize` was deprecated in version 1.0 and will be\n removed in 1.2.\n\n copy_X : bool, default=True\n If True, X will be copied; else, it may be overwritten.\n\n n_jobs : int, default=None\n The number of jobs to use for the computation. This will only provide\n speedup in case of sufficiently large problems, that is if firstly\n `n_targets > 1` and secondly `X` is sparse or if `positive` is set\n to `True`. ``None`` means 1 unless in a\n :obj:`joblib.parallel_backend` context. ``-1`` means using all\n processors. See :term:`Glossary ` for more details.\n\n positive : bool, default=False\n When set to ``True``, forces the coefficients to be positive. This\n option is only supported for dense arrays.\n\n .. versionadded:: 0.24\n\n Attributes\n ----------\n coef_ : array of shape (n_features, ) or (n_targets, n_features)\n Estimated coefficients for the linear regression problem.\n If multiple targets are passed during the fit (y 2D), this\n is a 2D array of shape (n_targets, n_features), while if only\n one target is passed, this is a 1D array of length n_features.\n\n rank_ : int\n Rank of matrix `X`. Only available when `X` is dense.\n\n singular_ : array of shape (min(X, y),)\n Singular values of `X`. Only available when `X` is dense.\n\n intercept_ : float or array of shape (n_targets,)\n Independent term in the linear model. Set to 0.0 if\n `fit_intercept = False`.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n Ridge : Ridge regression addresses some of the\n problems of Ordinary Least Squares by imposing a penalty on the\n size of the coefficients with l2 regularization.\n Lasso : The Lasso is a linear model that estimates\n sparse coefficients with l1 regularization.\n ElasticNet : Elastic-Net is a linear regression\n model trained with both l1 and l2 -norm regularization of the\n coefficients.\n\n Notes\n -----\n From the implementation point of view, this is just plain Ordinary\n Least Squares (scipy.linalg.lstsq) or Non Negative Least Squares\n (scipy.optimize.nnls) wrapped as a predictor object.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.linear_model import LinearRegression\n >>> X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])\n >>> # y = 1 * x_0 + 2 * x_1 + 3\n >>> y = np.dot(X, np.array([1, 2])) + 3\n >>> reg = LinearRegression().fit(X, y)\n >>> reg.score(X, y)\n 1.0\n >>> reg.coef_\n array([1., 2.])\n >>> reg.intercept_\n 3.0...\n >>> reg.predict(np.array([[3, 5]]))\n array([16.])\n \"\"\"\n \n def __init__(self, *, fit_intercept=True, normalize='deprecated', copy_X=True, n_jobs=None, positive=False):\n self.fit_intercept = fit_intercept\n self.normalize = normalize\n self.copy_X = copy_X\n self.n_jobs = n_jobs\n self.positive = positive\n \n def fit(self, X, y, sample_weight=None):\n \"\"\"\n Fit linear model.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training data.\n\n y : array-like of shape (n_samples,) or (n_samples, n_targets)\n Target values. Will be cast to X's dtype if necessary.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Individual weights for each sample.\n\n .. versionadded:: 0.17\n parameter *sample_weight* support to LinearRegression.\n\n Returns\n -------\n self : object\n Fitted Estimator.\n \"\"\"\n _normalize = _deprecate_normalize(self.normalize, default=False, estimator_name=self.__class__.__name__)\n n_jobs_ = self.n_jobs\n accept_sparse = False if self.positive else ['csr', 'csc', 'coo']\n (X, y) = self._validate_data(X, y, accept_sparse=accept_sparse, y_numeric=True, multi_output=True)\n if sample_weight is not None:\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n (X, y, X_offset, y_offset, X_scale) = self._preprocess_data(X, y, fit_intercept=self.fit_intercept, normalize=_normalize, copy=self.copy_X, sample_weight=sample_weight, return_mean=True)\n if sample_weight is not None:\n (X, y) = _rescale_data(X, y, sample_weight)\n if self.positive:\n if y.ndim < 2:\n (self.coef_, self._residues) = optimize.nnls(X, y)\n else:\n outs = Parallel(n_jobs=n_jobs_)((delayed(optimize.nnls)(X, y[:, j]) for j in range(y.shape[1])))\n (self.coef_, self._residues) = map(np.vstack, zip(*outs))\n elif sp.issparse(X):\n X_offset_scale = X_offset / X_scale\n \n def matvec(b):\n return X.dot(b) - b.dot(X_offset_scale)\n \n def rmatvec(b):\n return X.T.dot(b) - X_offset_scale * np.sum(b)\n X_centered = sparse.linalg.LinearOperator(shape=X.shape, matvec=matvec, rmatvec=rmatvec)\n if y.ndim < 2:\n out = sparse_lsqr(X_centered, y)\n self.coef_ = out[0]\n self._residues = out[3]\n else:\n outs = Parallel(n_jobs=n_jobs_)((delayed(sparse_lsqr)(X_centered, y[:, j].ravel()) for j in range(y.shape[1])))\n self.coef_ = np.vstack([out[0] for out in outs])\n self._residues = np.vstack([out[3] for out in outs])\n else:\n (self.coef_, self._residues, self.rank_, self.singular_) = linalg.lstsq(X, y)\n self.coef_ = self.coef_.T\n if y.ndim == 1:\n self.coef_ = np.ravel(self.coef_)\n self._set_intercept(X_offset, y_offset, X_scale)\n return self\n" }, { "name": "SparseCoefMixin", @@ -23455,7 +23408,7 @@ "methods": [ "sklearn.linear_model._coordinate_descent.ElasticNet.__init__", "sklearn.linear_model._coordinate_descent.ElasticNet.fit", - "sklearn.linear_model._coordinate_descent.ElasticNet.sparse_coef_", + "sklearn.linear_model._coordinate_descent.ElasticNet.sparse_coef_@getter", "sklearn.linear_model._coordinate_descent.ElasticNet._decision_function" ], "is_public": true, @@ -23538,8 +23491,8 @@ ], "is_public": true, "description": "Multi-task ElasticNet model trained with L1/L2 mixed-norm as regularizer.\n\nThe optimization objective for MultiTaskElasticNet is:: (1 / (2 * n_samples)) * ||Y - XW||_Fro^2 + alpha * l1_ratio * ||W||_21 + 0.5 * alpha * (1 - l1_ratio) * ||W||_Fro^2 Where:: ||W||_21 = sum_i sqrt(sum_j W_ij ^ 2) i.e. the sum of norms of each row. Read more in the :ref:`User Guide `.", - "docstring": "Multi-task ElasticNet model trained with L1/L2 mixed-norm as\n regularizer.\n\n The optimization objective for MultiTaskElasticNet is::\n\n (1 / (2 * n_samples)) * ||Y - XW||_Fro^2\n + alpha * l1_ratio * ||W||_21\n + 0.5 * alpha * (1 - l1_ratio) * ||W||_Fro^2\n\n Where::\n\n ||W||_21 = sum_i sqrt(sum_j W_ij ^ 2)\n\n i.e. the sum of norms of each row.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n alpha : float, default=1.0\n Constant that multiplies the L1/L2 term. Defaults to 1.0.\n\n l1_ratio : float, default=0.5\n The ElasticNet mixing parameter, with 0 < l1_ratio <= 1.\n For l1_ratio = 1 the penalty is an L1/L2 penalty. For l1_ratio = 0 it\n is an L2 penalty.\n For ``0 < l1_ratio < 1``, the penalty is a combination of L1/L2 and L2.\n\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=False\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0 and will be removed in\n 1.2.\n\n copy_X : bool, default=True\n If ``True``, X will be copied; else, it may be overwritten.\n\n max_iter : int, default=1000\n The maximum number of iterations.\n\n tol : float, default=1e-4\n The tolerance for the optimization: if the updates are\n smaller than ``tol``, the optimization code checks the\n dual gap for optimality and continues until it is smaller\n than ``tol``.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n random_state : int, RandomState instance, default=None\n The seed of the pseudo random number generator that selects a random\n feature to update. Used when ``selection`` == 'random'.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n selection : {'cyclic', 'random'}, default='cyclic'\n If set to 'random', a random coefficient is updated every iteration\n rather than looping over features sequentially by default. This\n (setting to 'random') often leads to significantly faster convergence\n especially when tol is higher than 1e-4.\n\n Attributes\n ----------\n intercept_ : ndarray of shape (n_targets,)\n Independent term in decision function.\n\n coef_ : ndarray of shape (n_targets, n_features)\n Parameter vector (W in the cost function formula). If a 1D y is\n passed in at fit (non multi-task usage), ``coef_`` is then a 1D array.\n Note that ``coef_`` stores the transpose of ``W``, ``W.T``.\n\n n_iter_ : int\n Number of iterations run by the coordinate descent solver to reach\n the specified tolerance.\n\n dual_gap_ : float\n The dual gaps at the end of the optimization.\n\n eps_ : float\n The tolerance scaled scaled by the variance of the target `y`.\n\n sparse_coef_ : sparse matrix of shape (n_features,) or (n_targets, n_features)\n Sparse representation of the `coef_`.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn import linear_model\n >>> clf = linear_model.MultiTaskElasticNet(alpha=0.1)\n >>> clf.fit([[0,0], [1, 1], [2, 2]], [[0, 0], [1, 1], [2, 2]])\n MultiTaskElasticNet(alpha=0.1)\n >>> print(clf.coef_)\n [[0.45663524 0.45612256]\n [0.45663524 0.45612256]]\n >>> print(clf.intercept_)\n [0.0872422 0.0872422]\n\n See Also\n --------\n MultiTaskElasticNetCV : Multi-task L1/L2 ElasticNet with built-in\n cross-validation.\n ElasticNet\n MultiTaskLasso\n\n Notes\n -----\n The algorithm used to fit the model is coordinate descent.\n\n To avoid unnecessary memory duplication the X and y arguments of the fit\n method should be directly passed as Fortran-contiguous numpy arrays.\n ", - "source_code": "\n\nclass MultiTaskElasticNet(Lasso):\n \"\"\"Multi-task ElasticNet model trained with L1/L2 mixed-norm as\n regularizer.\n\n The optimization objective for MultiTaskElasticNet is::\n\n (1 / (2 * n_samples)) * ||Y - XW||_Fro^2\n + alpha * l1_ratio * ||W||_21\n + 0.5 * alpha * (1 - l1_ratio) * ||W||_Fro^2\n\n Where::\n\n ||W||_21 = sum_i sqrt(sum_j W_ij ^ 2)\n\n i.e. the sum of norms of each row.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n alpha : float, default=1.0\n Constant that multiplies the L1/L2 term. Defaults to 1.0.\n\n l1_ratio : float, default=0.5\n The ElasticNet mixing parameter, with 0 < l1_ratio <= 1.\n For l1_ratio = 1 the penalty is an L1/L2 penalty. For l1_ratio = 0 it\n is an L2 penalty.\n For ``0 < l1_ratio < 1``, the penalty is a combination of L1/L2 and L2.\n\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=False\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0 and will be removed in\n 1.2.\n\n copy_X : bool, default=True\n If ``True``, X will be copied; else, it may be overwritten.\n\n max_iter : int, default=1000\n The maximum number of iterations.\n\n tol : float, default=1e-4\n The tolerance for the optimization: if the updates are\n smaller than ``tol``, the optimization code checks the\n dual gap for optimality and continues until it is smaller\n than ``tol``.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n random_state : int, RandomState instance, default=None\n The seed of the pseudo random number generator that selects a random\n feature to update. Used when ``selection`` == 'random'.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n selection : {'cyclic', 'random'}, default='cyclic'\n If set to 'random', a random coefficient is updated every iteration\n rather than looping over features sequentially by default. This\n (setting to 'random') often leads to significantly faster convergence\n especially when tol is higher than 1e-4.\n\n Attributes\n ----------\n intercept_ : ndarray of shape (n_targets,)\n Independent term in decision function.\n\n coef_ : ndarray of shape (n_targets, n_features)\n Parameter vector (W in the cost function formula). If a 1D y is\n passed in at fit (non multi-task usage), ``coef_`` is then a 1D array.\n Note that ``coef_`` stores the transpose of ``W``, ``W.T``.\n\n n_iter_ : int\n Number of iterations run by the coordinate descent solver to reach\n the specified tolerance.\n\n dual_gap_ : float\n The dual gaps at the end of the optimization.\n\n eps_ : float\n The tolerance scaled scaled by the variance of the target `y`.\n\n sparse_coef_ : sparse matrix of shape (n_features,) or (n_targets, n_features)\n Sparse representation of the `coef_`.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn import linear_model\n >>> clf = linear_model.MultiTaskElasticNet(alpha=0.1)\n >>> clf.fit([[0,0], [1, 1], [2, 2]], [[0, 0], [1, 1], [2, 2]])\n MultiTaskElasticNet(alpha=0.1)\n >>> print(clf.coef_)\n [[0.45663524 0.45612256]\n [0.45663524 0.45612256]]\n >>> print(clf.intercept_)\n [0.0872422 0.0872422]\n\n See Also\n --------\n MultiTaskElasticNetCV : Multi-task L1/L2 ElasticNet with built-in\n cross-validation.\n ElasticNet\n MultiTaskLasso\n\n Notes\n -----\n The algorithm used to fit the model is coordinate descent.\n\n To avoid unnecessary memory duplication the X and y arguments of the fit\n method should be directly passed as Fortran-contiguous numpy arrays.\n \"\"\"\n \n def __init__(self, alpha=1.0, *, l1_ratio=0.5, fit_intercept=True, normalize='deprecated', copy_X=True, max_iter=1000, tol=0.0001, warm_start=False, random_state=None, selection='cyclic'):\n self.l1_ratio = l1_ratio\n self.alpha = alpha\n self.fit_intercept = fit_intercept\n self.normalize = normalize\n self.max_iter = max_iter\n self.copy_X = copy_X\n self.tol = tol\n self.warm_start = warm_start\n self.random_state = random_state\n self.selection = selection\n \n def fit(self, X, y):\n \"\"\"Fit MultiTaskElasticNet model with coordinate descent.\n\n Parameters\n ----------\n X : ndarray of shape (n_samples, n_features)\n Data.\n y : ndarray of shape (n_samples, n_targets)\n Target. Will be cast to X's dtype if necessary.\n\n Returns\n -------\n self : object\n\n Notes\n -----\n Coordinate descent is an algorithm that considers each column of\n data at a time hence it will automatically convert the X input\n as a Fortran-contiguous numpy array if necessary.\n\n To avoid memory re-allocation it is advised to allocate the\n initial data in memory directly using that format.\n \"\"\"\n _normalize = _deprecate_normalize(self.normalize, default=False, estimator_name=self.__class__.__name__)\n check_X_params = dict(dtype=[np.float64, np.float32], order='F', copy=self.copy_X and self.fit_intercept)\n check_y_params = dict(ensure_2d=False, order='F')\n (X, y) = self._validate_data(X, y, validate_separately=(check_X_params, check_y_params))\n check_consistent_length(X, y)\n y = y.astype(X.dtype)\n if hasattr(self, 'l1_ratio'):\n model_str = 'ElasticNet'\n else:\n model_str = 'Lasso'\n if y.ndim == 1:\n raise ValueError('For mono-task outputs, use %s' % model_str)\n (n_samples, n_features) = X.shape\n n_targets = y.shape[1]\n (X, y, X_offset, y_offset, X_scale) = _preprocess_data(X, y, self.fit_intercept, _normalize, copy=False)\n if not self.warm_start or not hasattr(self, 'coef_'):\n self.coef_ = np.zeros((n_targets, n_features), dtype=X.dtype.type, order='F')\n l1_reg = self.alpha * self.l1_ratio * n_samples\n l2_reg = self.alpha * (1.0 - self.l1_ratio) * n_samples\n self.coef_ = np.asfortranarray(self.coef_)\n if self.selection not in ['random', 'cyclic']:\n raise ValueError('selection should be either random or cyclic.')\n random = self.selection == 'random'\n (self.coef_, self.dual_gap_, self.eps_, self.n_iter_) = cd_fast.enet_coordinate_descent_multi_task(self.coef_, l1_reg, l2_reg, X, y, self.max_iter, self.tol, check_random_state(self.random_state), random)\n self.dual_gap_ /= n_samples\n self._set_intercept(X_offset, y_offset, X_scale)\n return self\n \n def _more_tags(self):\n return {'multioutput_only': True}\n" + "docstring": "Multi-task ElasticNet model trained with L1/L2 mixed-norm as regularizer.\n\n The optimization objective for MultiTaskElasticNet is::\n\n (1 / (2 * n_samples)) * ||Y - XW||_Fro^2\n + alpha * l1_ratio * ||W||_21\n + 0.5 * alpha * (1 - l1_ratio) * ||W||_Fro^2\n\n Where::\n\n ||W||_21 = sum_i sqrt(sum_j W_ij ^ 2)\n\n i.e. the sum of norms of each row.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n alpha : float, default=1.0\n Constant that multiplies the L1/L2 term. Defaults to 1.0.\n\n l1_ratio : float, default=0.5\n The ElasticNet mixing parameter, with 0 < l1_ratio <= 1.\n For l1_ratio = 1 the penalty is an L1/L2 penalty. For l1_ratio = 0 it\n is an L2 penalty.\n For ``0 < l1_ratio < 1``, the penalty is a combination of L1/L2 and L2.\n\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=False\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0 and will be removed in\n 1.2.\n\n copy_X : bool, default=True\n If ``True``, X will be copied; else, it may be overwritten.\n\n max_iter : int, default=1000\n The maximum number of iterations.\n\n tol : float, default=1e-4\n The tolerance for the optimization: if the updates are\n smaller than ``tol``, the optimization code checks the\n dual gap for optimality and continues until it is smaller\n than ``tol``.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n random_state : int, RandomState instance, default=None\n The seed of the pseudo random number generator that selects a random\n feature to update. Used when ``selection`` == 'random'.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n selection : {'cyclic', 'random'}, default='cyclic'\n If set to 'random', a random coefficient is updated every iteration\n rather than looping over features sequentially by default. This\n (setting to 'random') often leads to significantly faster convergence\n especially when tol is higher than 1e-4.\n\n Attributes\n ----------\n intercept_ : ndarray of shape (n_targets,)\n Independent term in decision function.\n\n coef_ : ndarray of shape (n_targets, n_features)\n Parameter vector (W in the cost function formula). If a 1D y is\n passed in at fit (non multi-task usage), ``coef_`` is then a 1D array.\n Note that ``coef_`` stores the transpose of ``W``, ``W.T``.\n\n n_iter_ : int\n Number of iterations run by the coordinate descent solver to reach\n the specified tolerance.\n\n dual_gap_ : float\n The dual gaps at the end of the optimization.\n\n eps_ : float\n The tolerance scaled scaled by the variance of the target `y`.\n\n sparse_coef_ : sparse matrix of shape (n_features,) or (n_targets, n_features)\n Sparse representation of the `coef_`.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n MultiTaskElasticNetCV : Multi-task L1/L2 ElasticNet with built-in\n cross-validation.\n ElasticNet : Linear regression with combined L1 and L2 priors as regularizer.\n MultiTaskLasso : Multi-task L1/L2 Lasso with built-in cross-validation.\n\n Notes\n -----\n The algorithm used to fit the model is coordinate descent.\n\n To avoid unnecessary memory duplication the X and y arguments of the fit\n method should be directly passed as Fortran-contiguous numpy arrays.\n\n Examples\n --------\n >>> from sklearn import linear_model\n >>> clf = linear_model.MultiTaskElasticNet(alpha=0.1)\n >>> clf.fit([[0,0], [1, 1], [2, 2]], [[0, 0], [1, 1], [2, 2]])\n MultiTaskElasticNet(alpha=0.1)\n >>> print(clf.coef_)\n [[0.45663524 0.45612256]\n [0.45663524 0.45612256]]\n >>> print(clf.intercept_)\n [0.0872422 0.0872422]\n ", + "source_code": "\n\nclass MultiTaskElasticNet(Lasso):\n \"\"\"Multi-task ElasticNet model trained with L1/L2 mixed-norm as regularizer.\n\n The optimization objective for MultiTaskElasticNet is::\n\n (1 / (2 * n_samples)) * ||Y - XW||_Fro^2\n + alpha * l1_ratio * ||W||_21\n + 0.5 * alpha * (1 - l1_ratio) * ||W||_Fro^2\n\n Where::\n\n ||W||_21 = sum_i sqrt(sum_j W_ij ^ 2)\n\n i.e. the sum of norms of each row.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n alpha : float, default=1.0\n Constant that multiplies the L1/L2 term. Defaults to 1.0.\n\n l1_ratio : float, default=0.5\n The ElasticNet mixing parameter, with 0 < l1_ratio <= 1.\n For l1_ratio = 1 the penalty is an L1/L2 penalty. For l1_ratio = 0 it\n is an L2 penalty.\n For ``0 < l1_ratio < 1``, the penalty is a combination of L1/L2 and L2.\n\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=False\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0 and will be removed in\n 1.2.\n\n copy_X : bool, default=True\n If ``True``, X will be copied; else, it may be overwritten.\n\n max_iter : int, default=1000\n The maximum number of iterations.\n\n tol : float, default=1e-4\n The tolerance for the optimization: if the updates are\n smaller than ``tol``, the optimization code checks the\n dual gap for optimality and continues until it is smaller\n than ``tol``.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n random_state : int, RandomState instance, default=None\n The seed of the pseudo random number generator that selects a random\n feature to update. Used when ``selection`` == 'random'.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n selection : {'cyclic', 'random'}, default='cyclic'\n If set to 'random', a random coefficient is updated every iteration\n rather than looping over features sequentially by default. This\n (setting to 'random') often leads to significantly faster convergence\n especially when tol is higher than 1e-4.\n\n Attributes\n ----------\n intercept_ : ndarray of shape (n_targets,)\n Independent term in decision function.\n\n coef_ : ndarray of shape (n_targets, n_features)\n Parameter vector (W in the cost function formula). If a 1D y is\n passed in at fit (non multi-task usage), ``coef_`` is then a 1D array.\n Note that ``coef_`` stores the transpose of ``W``, ``W.T``.\n\n n_iter_ : int\n Number of iterations run by the coordinate descent solver to reach\n the specified tolerance.\n\n dual_gap_ : float\n The dual gaps at the end of the optimization.\n\n eps_ : float\n The tolerance scaled scaled by the variance of the target `y`.\n\n sparse_coef_ : sparse matrix of shape (n_features,) or (n_targets, n_features)\n Sparse representation of the `coef_`.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n MultiTaskElasticNetCV : Multi-task L1/L2 ElasticNet with built-in\n cross-validation.\n ElasticNet : Linear regression with combined L1 and L2 priors as regularizer.\n MultiTaskLasso : Multi-task L1/L2 Lasso with built-in cross-validation.\n\n Notes\n -----\n The algorithm used to fit the model is coordinate descent.\n\n To avoid unnecessary memory duplication the X and y arguments of the fit\n method should be directly passed as Fortran-contiguous numpy arrays.\n\n Examples\n --------\n >>> from sklearn import linear_model\n >>> clf = linear_model.MultiTaskElasticNet(alpha=0.1)\n >>> clf.fit([[0,0], [1, 1], [2, 2]], [[0, 0], [1, 1], [2, 2]])\n MultiTaskElasticNet(alpha=0.1)\n >>> print(clf.coef_)\n [[0.45663524 0.45612256]\n [0.45663524 0.45612256]]\n >>> print(clf.intercept_)\n [0.0872422 0.0872422]\n \"\"\"\n \n def __init__(self, alpha=1.0, *, l1_ratio=0.5, fit_intercept=True, normalize='deprecated', copy_X=True, max_iter=1000, tol=0.0001, warm_start=False, random_state=None, selection='cyclic'):\n self.l1_ratio = l1_ratio\n self.alpha = alpha\n self.fit_intercept = fit_intercept\n self.normalize = normalize\n self.max_iter = max_iter\n self.copy_X = copy_X\n self.tol = tol\n self.warm_start = warm_start\n self.random_state = random_state\n self.selection = selection\n \n def fit(self, X, y):\n \"\"\"Fit MultiTaskElasticNet model with coordinate descent.\n\n Parameters\n ----------\n X : ndarray of shape (n_samples, n_features)\n Data.\n y : ndarray of shape (n_samples, n_targets)\n Target. Will be cast to X's dtype if necessary.\n\n Returns\n -------\n self : object\n Fitted estimator.\n\n Notes\n -----\n Coordinate descent is an algorithm that considers each column of\n data at a time hence it will automatically convert the X input\n as a Fortran-contiguous numpy array if necessary.\n\n To avoid memory re-allocation it is advised to allocate the\n initial data in memory directly using that format.\n \"\"\"\n _normalize = _deprecate_normalize(self.normalize, default=False, estimator_name=self.__class__.__name__)\n check_X_params = dict(dtype=[np.float64, np.float32], order='F', copy=self.copy_X and self.fit_intercept)\n check_y_params = dict(ensure_2d=False, order='F')\n (X, y) = self._validate_data(X, y, validate_separately=(check_X_params, check_y_params))\n check_consistent_length(X, y)\n y = y.astype(X.dtype)\n if hasattr(self, 'l1_ratio'):\n model_str = 'ElasticNet'\n else:\n model_str = 'Lasso'\n if y.ndim == 1:\n raise ValueError('For mono-task outputs, use %s' % model_str)\n (n_samples, n_features) = X.shape\n n_targets = y.shape[1]\n (X, y, X_offset, y_offset, X_scale) = _preprocess_data(X, y, self.fit_intercept, _normalize, copy=False)\n if not self.warm_start or not hasattr(self, 'coef_'):\n self.coef_ = np.zeros((n_targets, n_features), dtype=X.dtype.type, order='F')\n l1_reg = self.alpha * self.l1_ratio * n_samples\n l2_reg = self.alpha * (1.0 - self.l1_ratio) * n_samples\n self.coef_ = np.asfortranarray(self.coef_)\n if self.selection not in ['random', 'cyclic']:\n raise ValueError('selection should be either random or cyclic.')\n random = self.selection == 'random'\n (self.coef_, self.dual_gap_, self.eps_, self.n_iter_) = cd_fast.enet_coordinate_descent_multi_task(self.coef_, l1_reg, l2_reg, X, y, self.max_iter, self.tol, check_random_state(self.random_state), random)\n self.dual_gap_ /= n_samples\n self._set_intercept(X_offset, y_offset, X_scale)\n return self\n \n def _more_tags(self):\n return {'multioutput_only': True}\n" }, { "name": "MultiTaskElasticNetCV", @@ -23555,8 +23508,8 @@ ], "is_public": true, "description": "Multi-task L1/L2 ElasticNet with built-in cross-validation.\n\nSee glossary entry for :term:`cross-validation estimator`. The optimization objective for MultiTaskElasticNet is:: (1 / (2 * n_samples)) * ||Y - XW||^Fro_2 + alpha * l1_ratio * ||W||_21 + 0.5 * alpha * (1 - l1_ratio) * ||W||_Fro^2 Where:: ||W||_21 = \\sum_i \\sqrt{\\sum_j w_{ij}^2} i.e. the sum of norm of each row. Read more in the :ref:`User Guide `. .. versionadded:: 0.15", - "docstring": "Multi-task L1/L2 ElasticNet with built-in cross-validation.\n\n See glossary entry for :term:`cross-validation estimator`.\n\n The optimization objective for MultiTaskElasticNet is::\n\n (1 / (2 * n_samples)) * ||Y - XW||^Fro_2\n + alpha * l1_ratio * ||W||_21\n + 0.5 * alpha * (1 - l1_ratio) * ||W||_Fro^2\n\n Where::\n\n ||W||_21 = \\sum_i \\sqrt{\\sum_j w_{ij}^2}\n\n i.e. the sum of norm of each row.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.15\n\n Parameters\n ----------\n l1_ratio : float or list of float, default=0.5\n The ElasticNet mixing parameter, with 0 < l1_ratio <= 1.\n For l1_ratio = 1 the penalty is an L1/L2 penalty. For l1_ratio = 0 it\n is an L2 penalty.\n For ``0 < l1_ratio < 1``, the penalty is a combination of L1/L2 and L2.\n This parameter can be a list, in which case the different\n values are tested by cross-validation and the one giving the best\n prediction score is used. Note that a good choice of list of\n values for l1_ratio is often to put more values close to 1\n (i.e. Lasso) and less close to 0 (i.e. Ridge), as in ``[.1, .5, .7,\n .9, .95, .99, 1]``\n\n eps : float, default=1e-3\n Length of the path. ``eps=1e-3`` means that\n ``alpha_min / alpha_max = 1e-3``.\n\n n_alphas : int, default=100\n Number of alphas along the regularization path.\n\n alphas : array-like, default=None\n List of alphas where to compute the models.\n If not provided, set automatically.\n\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=False\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0 and will be removed in\n 1.2.\n\n max_iter : int, default=1000\n The maximum number of iterations.\n\n tol : float, default=1e-4\n The tolerance for the optimization: if the updates are\n smaller than ``tol``, the optimization code checks the\n dual gap for optimality and continues until it is smaller\n than ``tol``.\n\n cv : int, cross-validation generator or iterable, default=None\n Determines the cross-validation splitting strategy.\n Possible inputs for cv are:\n\n - None, to use the default 5-fold cross-validation,\n - int, to specify the number of folds.\n - :term:`CV splitter`,\n - An iterable yielding (train, test) splits as arrays of indices.\n\n For int/None inputs, :class:`KFold` is used.\n\n Refer :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n .. versionchanged:: 0.22\n ``cv`` default value if None changed from 3-fold to 5-fold.\n\n copy_X : bool, default=True\n If ``True``, X will be copied; else, it may be overwritten.\n\n verbose : bool or int, default=0\n Amount of verbosity.\n\n n_jobs : int, default=None\n Number of CPUs to use during the cross validation. Note that this is\n used only if multiple values for l1_ratio are given.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n random_state : int, RandomState instance, default=None\n The seed of the pseudo random number generator that selects a random\n feature to update. Used when ``selection`` == 'random'.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n selection : {'cyclic', 'random'}, default='cyclic'\n If set to 'random', a random coefficient is updated every iteration\n rather than looping over features sequentially by default. This\n (setting to 'random') often leads to significantly faster convergence\n especially when tol is higher than 1e-4.\n\n Attributes\n ----------\n intercept_ : ndarray of shape (n_targets,)\n Independent term in decision function.\n\n coef_ : ndarray of shape (n_targets, n_features)\n Parameter vector (W in the cost function formula).\n Note that ``coef_`` stores the transpose of ``W``, ``W.T``.\n\n alpha_ : float\n The amount of penalization chosen by cross validation.\n\n mse_path_ : ndarray of shape (n_alphas, n_folds) or (n_l1_ratio, n_alphas, n_folds)\n Mean square error for the test set on each fold, varying alpha.\n\n alphas_ : ndarray of shape (n_alphas,) or (n_l1_ratio, n_alphas)\n The grid of alphas used for fitting, for each l1_ratio.\n\n l1_ratio_ : float\n Best l1_ratio obtained by cross-validation.\n\n n_iter_ : int\n Number of iterations run by the coordinate descent solver to reach\n the specified tolerance for the optimal alpha.\n\n dual_gap_ : float\n The dual gap at the end of the optimization for the optimal alpha.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn import linear_model\n >>> clf = linear_model.MultiTaskElasticNetCV(cv=3)\n >>> clf.fit([[0,0], [1, 1], [2, 2]],\n ... [[0, 0], [1, 1], [2, 2]])\n MultiTaskElasticNetCV(cv=3)\n >>> print(clf.coef_)\n [[0.52875032 0.46958558]\n [0.52875032 0.46958558]]\n >>> print(clf.intercept_)\n [0.00166409 0.00166409]\n\n See Also\n --------\n MultiTaskElasticNet\n ElasticNetCV\n MultiTaskLassoCV\n\n Notes\n -----\n The algorithm used to fit the model is coordinate descent.\n\n To avoid unnecessary memory duplication the X and y arguments of the fit\n method should be directly passed as Fortran-contiguous numpy arrays.\n ", - "source_code": "\n\nclass MultiTaskElasticNetCV(RegressorMixin, LinearModelCV):\n \"\"\"Multi-task L1/L2 ElasticNet with built-in cross-validation.\n\n See glossary entry for :term:`cross-validation estimator`.\n\n The optimization objective for MultiTaskElasticNet is::\n\n (1 / (2 * n_samples)) * ||Y - XW||^Fro_2\n + alpha * l1_ratio * ||W||_21\n + 0.5 * alpha * (1 - l1_ratio) * ||W||_Fro^2\n\n Where::\n\n ||W||_21 = \\sum_i \\sqrt{\\sum_j w_{ij}^2}\n\n i.e. the sum of norm of each row.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.15\n\n Parameters\n ----------\n l1_ratio : float or list of float, default=0.5\n The ElasticNet mixing parameter, with 0 < l1_ratio <= 1.\n For l1_ratio = 1 the penalty is an L1/L2 penalty. For l1_ratio = 0 it\n is an L2 penalty.\n For ``0 < l1_ratio < 1``, the penalty is a combination of L1/L2 and L2.\n This parameter can be a list, in which case the different\n values are tested by cross-validation and the one giving the best\n prediction score is used. Note that a good choice of list of\n values for l1_ratio is often to put more values close to 1\n (i.e. Lasso) and less close to 0 (i.e. Ridge), as in ``[.1, .5, .7,\n .9, .95, .99, 1]``\n\n eps : float, default=1e-3\n Length of the path. ``eps=1e-3`` means that\n ``alpha_min / alpha_max = 1e-3``.\n\n n_alphas : int, default=100\n Number of alphas along the regularization path.\n\n alphas : array-like, default=None\n List of alphas where to compute the models.\n If not provided, set automatically.\n\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=False\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0 and will be removed in\n 1.2.\n\n max_iter : int, default=1000\n The maximum number of iterations.\n\n tol : float, default=1e-4\n The tolerance for the optimization: if the updates are\n smaller than ``tol``, the optimization code checks the\n dual gap for optimality and continues until it is smaller\n than ``tol``.\n\n cv : int, cross-validation generator or iterable, default=None\n Determines the cross-validation splitting strategy.\n Possible inputs for cv are:\n\n - None, to use the default 5-fold cross-validation,\n - int, to specify the number of folds.\n - :term:`CV splitter`,\n - An iterable yielding (train, test) splits as arrays of indices.\n\n For int/None inputs, :class:`KFold` is used.\n\n Refer :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n .. versionchanged:: 0.22\n ``cv`` default value if None changed from 3-fold to 5-fold.\n\n copy_X : bool, default=True\n If ``True``, X will be copied; else, it may be overwritten.\n\n verbose : bool or int, default=0\n Amount of verbosity.\n\n n_jobs : int, default=None\n Number of CPUs to use during the cross validation. Note that this is\n used only if multiple values for l1_ratio are given.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n random_state : int, RandomState instance, default=None\n The seed of the pseudo random number generator that selects a random\n feature to update. Used when ``selection`` == 'random'.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n selection : {'cyclic', 'random'}, default='cyclic'\n If set to 'random', a random coefficient is updated every iteration\n rather than looping over features sequentially by default. This\n (setting to 'random') often leads to significantly faster convergence\n especially when tol is higher than 1e-4.\n\n Attributes\n ----------\n intercept_ : ndarray of shape (n_targets,)\n Independent term in decision function.\n\n coef_ : ndarray of shape (n_targets, n_features)\n Parameter vector (W in the cost function formula).\n Note that ``coef_`` stores the transpose of ``W``, ``W.T``.\n\n alpha_ : float\n The amount of penalization chosen by cross validation.\n\n mse_path_ : ndarray of shape (n_alphas, n_folds) or (n_l1_ratio, n_alphas, n_folds)\n Mean square error for the test set on each fold, varying alpha.\n\n alphas_ : ndarray of shape (n_alphas,) or (n_l1_ratio, n_alphas)\n The grid of alphas used for fitting, for each l1_ratio.\n\n l1_ratio_ : float\n Best l1_ratio obtained by cross-validation.\n\n n_iter_ : int\n Number of iterations run by the coordinate descent solver to reach\n the specified tolerance for the optimal alpha.\n\n dual_gap_ : float\n The dual gap at the end of the optimization for the optimal alpha.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn import linear_model\n >>> clf = linear_model.MultiTaskElasticNetCV(cv=3)\n >>> clf.fit([[0,0], [1, 1], [2, 2]],\n ... [[0, 0], [1, 1], [2, 2]])\n MultiTaskElasticNetCV(cv=3)\n >>> print(clf.coef_)\n [[0.52875032 0.46958558]\n [0.52875032 0.46958558]]\n >>> print(clf.intercept_)\n [0.00166409 0.00166409]\n\n See Also\n --------\n MultiTaskElasticNet\n ElasticNetCV\n MultiTaskLassoCV\n\n Notes\n -----\n The algorithm used to fit the model is coordinate descent.\n\n To avoid unnecessary memory duplication the X and y arguments of the fit\n method should be directly passed as Fortran-contiguous numpy arrays.\n \"\"\"\n path = staticmethod(enet_path)\n \n def __init__(self, *, l1_ratio=0.5, eps=0.001, n_alphas=100, alphas=None, fit_intercept=True, normalize='deprecated', max_iter=1000, tol=0.0001, cv=None, copy_X=True, verbose=0, n_jobs=None, random_state=None, selection='cyclic'):\n self.l1_ratio = l1_ratio\n self.eps = eps\n self.n_alphas = n_alphas\n self.alphas = alphas\n self.fit_intercept = fit_intercept\n self.normalize = normalize\n self.max_iter = max_iter\n self.tol = tol\n self.cv = cv\n self.copy_X = copy_X\n self.verbose = verbose\n self.n_jobs = n_jobs\n self.random_state = random_state\n self.selection = selection\n \n def _get_estimator(self):\n return MultiTaskElasticNet()\n \n def _is_multitask(self):\n return True\n \n def _more_tags(self):\n return {'multioutput_only': True}\n \n def fit(self, X, y):\n \"\"\"Fit MultiTaskElasticNet model with coordinate descent.\n\n Fit is on grid of alphas and best alpha estimated by cross-validation.\n\n Parameters\n ----------\n X : ndarray of shape (n_samples, n_features)\n Data\n y : ndarray of shape (n_samples, n_targets)\n Target. Will be cast to X's dtype if necessary\n\n Returns\n -------\n self : object\n \"\"\"\n return super().fit(X, y)\n" + "docstring": "Multi-task L1/L2 ElasticNet with built-in cross-validation.\n\n See glossary entry for :term:`cross-validation estimator`.\n\n The optimization objective for MultiTaskElasticNet is::\n\n (1 / (2 * n_samples)) * ||Y - XW||^Fro_2\n + alpha * l1_ratio * ||W||_21\n + 0.5 * alpha * (1 - l1_ratio) * ||W||_Fro^2\n\n Where::\n\n ||W||_21 = \\sum_i \\sqrt{\\sum_j w_{ij}^2}\n\n i.e. the sum of norm of each row.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.15\n\n Parameters\n ----------\n l1_ratio : float or list of float, default=0.5\n The ElasticNet mixing parameter, with 0 < l1_ratio <= 1.\n For l1_ratio = 1 the penalty is an L1/L2 penalty. For l1_ratio = 0 it\n is an L2 penalty.\n For ``0 < l1_ratio < 1``, the penalty is a combination of L1/L2 and L2.\n This parameter can be a list, in which case the different\n values are tested by cross-validation and the one giving the best\n prediction score is used. Note that a good choice of list of\n values for l1_ratio is often to put more values close to 1\n (i.e. Lasso) and less close to 0 (i.e. Ridge), as in ``[.1, .5, .7,\n .9, .95, .99, 1]``.\n\n eps : float, default=1e-3\n Length of the path. ``eps=1e-3`` means that\n ``alpha_min / alpha_max = 1e-3``.\n\n n_alphas : int, default=100\n Number of alphas along the regularization path.\n\n alphas : array-like, default=None\n List of alphas where to compute the models.\n If not provided, set automatically.\n\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=False\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0 and will be removed in\n 1.2.\n\n max_iter : int, default=1000\n The maximum number of iterations.\n\n tol : float, default=1e-4\n The tolerance for the optimization: if the updates are\n smaller than ``tol``, the optimization code checks the\n dual gap for optimality and continues until it is smaller\n than ``tol``.\n\n cv : int, cross-validation generator or iterable, default=None\n Determines the cross-validation splitting strategy.\n Possible inputs for cv are:\n\n - None, to use the default 5-fold cross-validation,\n - int, to specify the number of folds.\n - :term:`CV splitter`,\n - An iterable yielding (train, test) splits as arrays of indices.\n\n For int/None inputs, :class:`KFold` is used.\n\n Refer :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n .. versionchanged:: 0.22\n ``cv`` default value if None changed from 3-fold to 5-fold.\n\n copy_X : bool, default=True\n If ``True``, X will be copied; else, it may be overwritten.\n\n verbose : bool or int, default=0\n Amount of verbosity.\n\n n_jobs : int, default=None\n Number of CPUs to use during the cross validation. Note that this is\n used only if multiple values for l1_ratio are given.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n random_state : int, RandomState instance, default=None\n The seed of the pseudo random number generator that selects a random\n feature to update. Used when ``selection`` == 'random'.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n selection : {'cyclic', 'random'}, default='cyclic'\n If set to 'random', a random coefficient is updated every iteration\n rather than looping over features sequentially by default. This\n (setting to 'random') often leads to significantly faster convergence\n especially when tol is higher than 1e-4.\n\n Attributes\n ----------\n intercept_ : ndarray of shape (n_targets,)\n Independent term in decision function.\n\n coef_ : ndarray of shape (n_targets, n_features)\n Parameter vector (W in the cost function formula).\n Note that ``coef_`` stores the transpose of ``W``, ``W.T``.\n\n alpha_ : float\n The amount of penalization chosen by cross validation.\n\n mse_path_ : ndarray of shape (n_alphas, n_folds) or (n_l1_ratio, n_alphas, n_folds)\n Mean square error for the test set on each fold, varying alpha.\n\n alphas_ : ndarray of shape (n_alphas,) or (n_l1_ratio, n_alphas)\n The grid of alphas used for fitting, for each l1_ratio.\n\n l1_ratio_ : float\n Best l1_ratio obtained by cross-validation.\n\n n_iter_ : int\n Number of iterations run by the coordinate descent solver to reach\n the specified tolerance for the optimal alpha.\n\n dual_gap_ : float\n The dual gap at the end of the optimization for the optimal alpha.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n MultiTaskElasticNet : Multi-task L1/L2 ElasticNet with built-in cross-validation.\n ElasticNetCV : Elastic net model with best model selection by\n cross-validation.\n MultiTaskLassoCV : Multi-task Lasso model trained with L1/L2\n mixed-norm as regularizer.\n\n Notes\n -----\n The algorithm used to fit the model is coordinate descent.\n\n To avoid unnecessary memory duplication the X and y arguments of the fit\n method should be directly passed as Fortran-contiguous numpy arrays.\n\n Examples\n --------\n >>> from sklearn import linear_model\n >>> clf = linear_model.MultiTaskElasticNetCV(cv=3)\n >>> clf.fit([[0,0], [1, 1], [2, 2]],\n ... [[0, 0], [1, 1], [2, 2]])\n MultiTaskElasticNetCV(cv=3)\n >>> print(clf.coef_)\n [[0.52875032 0.46958558]\n [0.52875032 0.46958558]]\n >>> print(clf.intercept_)\n [0.00166409 0.00166409]\n ", + "source_code": "\n\nclass MultiTaskElasticNetCV(RegressorMixin, LinearModelCV):\n \"\"\"Multi-task L1/L2 ElasticNet with built-in cross-validation.\n\n See glossary entry for :term:`cross-validation estimator`.\n\n The optimization objective for MultiTaskElasticNet is::\n\n (1 / (2 * n_samples)) * ||Y - XW||^Fro_2\n + alpha * l1_ratio * ||W||_21\n + 0.5 * alpha * (1 - l1_ratio) * ||W||_Fro^2\n\n Where::\n\n ||W||_21 = \\sum_i \\sqrt{\\sum_j w_{ij}^2}\n\n i.e. the sum of norm of each row.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.15\n\n Parameters\n ----------\n l1_ratio : float or list of float, default=0.5\n The ElasticNet mixing parameter, with 0 < l1_ratio <= 1.\n For l1_ratio = 1 the penalty is an L1/L2 penalty. For l1_ratio = 0 it\n is an L2 penalty.\n For ``0 < l1_ratio < 1``, the penalty is a combination of L1/L2 and L2.\n This parameter can be a list, in which case the different\n values are tested by cross-validation and the one giving the best\n prediction score is used. Note that a good choice of list of\n values for l1_ratio is often to put more values close to 1\n (i.e. Lasso) and less close to 0 (i.e. Ridge), as in ``[.1, .5, .7,\n .9, .95, .99, 1]``.\n\n eps : float, default=1e-3\n Length of the path. ``eps=1e-3`` means that\n ``alpha_min / alpha_max = 1e-3``.\n\n n_alphas : int, default=100\n Number of alphas along the regularization path.\n\n alphas : array-like, default=None\n List of alphas where to compute the models.\n If not provided, set automatically.\n\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=False\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0 and will be removed in\n 1.2.\n\n max_iter : int, default=1000\n The maximum number of iterations.\n\n tol : float, default=1e-4\n The tolerance for the optimization: if the updates are\n smaller than ``tol``, the optimization code checks the\n dual gap for optimality and continues until it is smaller\n than ``tol``.\n\n cv : int, cross-validation generator or iterable, default=None\n Determines the cross-validation splitting strategy.\n Possible inputs for cv are:\n\n - None, to use the default 5-fold cross-validation,\n - int, to specify the number of folds.\n - :term:`CV splitter`,\n - An iterable yielding (train, test) splits as arrays of indices.\n\n For int/None inputs, :class:`KFold` is used.\n\n Refer :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n .. versionchanged:: 0.22\n ``cv`` default value if None changed from 3-fold to 5-fold.\n\n copy_X : bool, default=True\n If ``True``, X will be copied; else, it may be overwritten.\n\n verbose : bool or int, default=0\n Amount of verbosity.\n\n n_jobs : int, default=None\n Number of CPUs to use during the cross validation. Note that this is\n used only if multiple values for l1_ratio are given.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n random_state : int, RandomState instance, default=None\n The seed of the pseudo random number generator that selects a random\n feature to update. Used when ``selection`` == 'random'.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n selection : {'cyclic', 'random'}, default='cyclic'\n If set to 'random', a random coefficient is updated every iteration\n rather than looping over features sequentially by default. This\n (setting to 'random') often leads to significantly faster convergence\n especially when tol is higher than 1e-4.\n\n Attributes\n ----------\n intercept_ : ndarray of shape (n_targets,)\n Independent term in decision function.\n\n coef_ : ndarray of shape (n_targets, n_features)\n Parameter vector (W in the cost function formula).\n Note that ``coef_`` stores the transpose of ``W``, ``W.T``.\n\n alpha_ : float\n The amount of penalization chosen by cross validation.\n\n mse_path_ : ndarray of shape (n_alphas, n_folds) or (n_l1_ratio, n_alphas, n_folds)\n Mean square error for the test set on each fold, varying alpha.\n\n alphas_ : ndarray of shape (n_alphas,) or (n_l1_ratio, n_alphas)\n The grid of alphas used for fitting, for each l1_ratio.\n\n l1_ratio_ : float\n Best l1_ratio obtained by cross-validation.\n\n n_iter_ : int\n Number of iterations run by the coordinate descent solver to reach\n the specified tolerance for the optimal alpha.\n\n dual_gap_ : float\n The dual gap at the end of the optimization for the optimal alpha.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n MultiTaskElasticNet : Multi-task L1/L2 ElasticNet with built-in cross-validation.\n ElasticNetCV : Elastic net model with best model selection by\n cross-validation.\n MultiTaskLassoCV : Multi-task Lasso model trained with L1/L2\n mixed-norm as regularizer.\n\n Notes\n -----\n The algorithm used to fit the model is coordinate descent.\n\n To avoid unnecessary memory duplication the X and y arguments of the fit\n method should be directly passed as Fortran-contiguous numpy arrays.\n\n Examples\n --------\n >>> from sklearn import linear_model\n >>> clf = linear_model.MultiTaskElasticNetCV(cv=3)\n >>> clf.fit([[0,0], [1, 1], [2, 2]],\n ... [[0, 0], [1, 1], [2, 2]])\n MultiTaskElasticNetCV(cv=3)\n >>> print(clf.coef_)\n [[0.52875032 0.46958558]\n [0.52875032 0.46958558]]\n >>> print(clf.intercept_)\n [0.00166409 0.00166409]\n \"\"\"\n path = staticmethod(enet_path)\n \n def __init__(self, *, l1_ratio=0.5, eps=0.001, n_alphas=100, alphas=None, fit_intercept=True, normalize='deprecated', max_iter=1000, tol=0.0001, cv=None, copy_X=True, verbose=0, n_jobs=None, random_state=None, selection='cyclic'):\n self.l1_ratio = l1_ratio\n self.eps = eps\n self.n_alphas = n_alphas\n self.alphas = alphas\n self.fit_intercept = fit_intercept\n self.normalize = normalize\n self.max_iter = max_iter\n self.tol = tol\n self.cv = cv\n self.copy_X = copy_X\n self.verbose = verbose\n self.n_jobs = n_jobs\n self.random_state = random_state\n self.selection = selection\n \n def _get_estimator(self):\n return MultiTaskElasticNet()\n \n def _is_multitask(self):\n return True\n \n def _more_tags(self):\n return {'multioutput_only': True}\n \n def fit(self, X, y):\n \"\"\"Fit MultiTaskElasticNet model with coordinate descent.\n\n Fit is on grid of alphas and best alpha estimated by cross-validation.\n\n Parameters\n ----------\n X : ndarray of shape (n_samples, n_features)\n Training data.\n y : ndarray of shape (n_samples, n_targets)\n Training target variable. Will be cast to X's dtype if necessary.\n\n Returns\n -------\n self : object\n Returns MultiTaskElasticNet instance.\n \"\"\"\n return super().fit(X, y)\n" }, { "name": "MultiTaskLasso", @@ -23568,8 +23521,8 @@ ], "is_public": true, "description": "Multi-task Lasso model trained with L1/L2 mixed-norm as regularizer.\n\nThe optimization objective for Lasso is:: (1 / (2 * n_samples)) * ||Y - XW||^2_Fro + alpha * ||W||_21 Where:: ||W||_21 = \\sum_i \\sqrt{\\sum_j w_{ij}^2} i.e. the sum of norm of each row. Read more in the :ref:`User Guide `.", - "docstring": "Multi-task Lasso model trained with L1/L2 mixed-norm as regularizer.\n\n The optimization objective for Lasso is::\n\n (1 / (2 * n_samples)) * ||Y - XW||^2_Fro + alpha * ||W||_21\n\n Where::\n\n ||W||_21 = \\sum_i \\sqrt{\\sum_j w_{ij}^2}\n\n i.e. the sum of norm of each row.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n alpha : float, default=1.0\n Constant that multiplies the L1/L2 term. Defaults to 1.0.\n\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=False\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0 and will be removed in\n 1.2.\n\n copy_X : bool, default=True\n If ``True``, X will be copied; else, it may be overwritten.\n\n max_iter : int, default=1000\n The maximum number of iterations.\n\n tol : float, default=1e-4\n The tolerance for the optimization: if the updates are\n smaller than ``tol``, the optimization code checks the\n dual gap for optimality and continues until it is smaller\n than ``tol``.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n random_state : int, RandomState instance, default=None\n The seed of the pseudo random number generator that selects a random\n feature to update. Used when ``selection`` == 'random'.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n selection : {'cyclic', 'random'}, default='cyclic'\n If set to 'random', a random coefficient is updated every iteration\n rather than looping over features sequentially by default. This\n (setting to 'random') often leads to significantly faster convergence\n especially when tol is higher than 1e-4\n\n Attributes\n ----------\n coef_ : ndarray of shape (n_targets, n_features)\n Parameter vector (W in the cost function formula).\n Note that ``coef_`` stores the transpose of ``W``, ``W.T``.\n\n intercept_ : ndarray of shape (n_targets,)\n Independent term in decision function.\n\n n_iter_ : int\n Number of iterations run by the coordinate descent solver to reach\n the specified tolerance.\n\n dual_gap_ : ndarray of shape (n_alphas,)\n The dual gaps at the end of the optimization for each alpha.\n\n eps_ : float\n The tolerance scaled scaled by the variance of the target `y`.\n\n sparse_coef_ : sparse matrix of shape (n_features,) or (n_targets, n_features)\n Sparse representation of the `coef_`.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn import linear_model\n >>> clf = linear_model.MultiTaskLasso(alpha=0.1)\n >>> clf.fit([[0, 1], [1, 2], [2, 4]], [[0, 0], [1, 1], [2, 3]])\n MultiTaskLasso(alpha=0.1)\n >>> print(clf.coef_)\n [[0. 0.60809415]\n [0. 0.94592424]]\n >>> print(clf.intercept_)\n [-0.41888636 -0.87382323]\n\n See Also\n --------\n MultiTaskLasso : Multi-task L1/L2 Lasso with built-in cross-validation\n Lasso\n MultiTaskElasticNet\n\n Notes\n -----\n The algorithm used to fit the model is coordinate descent.\n\n To avoid unnecessary memory duplication the X and y arguments of the fit\n method should be directly passed as Fortran-contiguous numpy arrays.\n ", - "source_code": "\n\nclass MultiTaskLasso(MultiTaskElasticNet):\n \"\"\"Multi-task Lasso model trained with L1/L2 mixed-norm as regularizer.\n\n The optimization objective for Lasso is::\n\n (1 / (2 * n_samples)) * ||Y - XW||^2_Fro + alpha * ||W||_21\n\n Where::\n\n ||W||_21 = \\sum_i \\sqrt{\\sum_j w_{ij}^2}\n\n i.e. the sum of norm of each row.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n alpha : float, default=1.0\n Constant that multiplies the L1/L2 term. Defaults to 1.0.\n\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=False\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0 and will be removed in\n 1.2.\n\n copy_X : bool, default=True\n If ``True``, X will be copied; else, it may be overwritten.\n\n max_iter : int, default=1000\n The maximum number of iterations.\n\n tol : float, default=1e-4\n The tolerance for the optimization: if the updates are\n smaller than ``tol``, the optimization code checks the\n dual gap for optimality and continues until it is smaller\n than ``tol``.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n random_state : int, RandomState instance, default=None\n The seed of the pseudo random number generator that selects a random\n feature to update. Used when ``selection`` == 'random'.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n selection : {'cyclic', 'random'}, default='cyclic'\n If set to 'random', a random coefficient is updated every iteration\n rather than looping over features sequentially by default. This\n (setting to 'random') often leads to significantly faster convergence\n especially when tol is higher than 1e-4\n\n Attributes\n ----------\n coef_ : ndarray of shape (n_targets, n_features)\n Parameter vector (W in the cost function formula).\n Note that ``coef_`` stores the transpose of ``W``, ``W.T``.\n\n intercept_ : ndarray of shape (n_targets,)\n Independent term in decision function.\n\n n_iter_ : int\n Number of iterations run by the coordinate descent solver to reach\n the specified tolerance.\n\n dual_gap_ : ndarray of shape (n_alphas,)\n The dual gaps at the end of the optimization for each alpha.\n\n eps_ : float\n The tolerance scaled scaled by the variance of the target `y`.\n\n sparse_coef_ : sparse matrix of shape (n_features,) or (n_targets, n_features)\n Sparse representation of the `coef_`.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn import linear_model\n >>> clf = linear_model.MultiTaskLasso(alpha=0.1)\n >>> clf.fit([[0, 1], [1, 2], [2, 4]], [[0, 0], [1, 1], [2, 3]])\n MultiTaskLasso(alpha=0.1)\n >>> print(clf.coef_)\n [[0. 0.60809415]\n [0. 0.94592424]]\n >>> print(clf.intercept_)\n [-0.41888636 -0.87382323]\n\n See Also\n --------\n MultiTaskLasso : Multi-task L1/L2 Lasso with built-in cross-validation\n Lasso\n MultiTaskElasticNet\n\n Notes\n -----\n The algorithm used to fit the model is coordinate descent.\n\n To avoid unnecessary memory duplication the X and y arguments of the fit\n method should be directly passed as Fortran-contiguous numpy arrays.\n \"\"\"\n \n def __init__(self, alpha=1.0, *, fit_intercept=True, normalize='deprecated', copy_X=True, max_iter=1000, tol=0.0001, warm_start=False, random_state=None, selection='cyclic'):\n self.alpha = alpha\n self.fit_intercept = fit_intercept\n self.normalize = normalize\n self.max_iter = max_iter\n self.copy_X = copy_X\n self.tol = tol\n self.warm_start = warm_start\n self.l1_ratio = 1.0\n self.random_state = random_state\n self.selection = selection\n" + "docstring": "Multi-task Lasso model trained with L1/L2 mixed-norm as regularizer.\n\n The optimization objective for Lasso is::\n\n (1 / (2 * n_samples)) * ||Y - XW||^2_Fro + alpha * ||W||_21\n\n Where::\n\n ||W||_21 = \\sum_i \\sqrt{\\sum_j w_{ij}^2}\n\n i.e. the sum of norm of each row.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n alpha : float, default=1.0\n Constant that multiplies the L1/L2 term. Defaults to 1.0.\n\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=False\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0 and will be removed in\n 1.2.\n\n copy_X : bool, default=True\n If ``True``, X will be copied; else, it may be overwritten.\n\n max_iter : int, default=1000\n The maximum number of iterations.\n\n tol : float, default=1e-4\n The tolerance for the optimization: if the updates are\n smaller than ``tol``, the optimization code checks the\n dual gap for optimality and continues until it is smaller\n than ``tol``.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n random_state : int, RandomState instance, default=None\n The seed of the pseudo random number generator that selects a random\n feature to update. Used when ``selection`` == 'random'.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n selection : {'cyclic', 'random'}, default='cyclic'\n If set to 'random', a random coefficient is updated every iteration\n rather than looping over features sequentially by default. This\n (setting to 'random') often leads to significantly faster convergence\n especially when tol is higher than 1e-4.\n\n Attributes\n ----------\n coef_ : ndarray of shape (n_targets, n_features)\n Parameter vector (W in the cost function formula).\n Note that ``coef_`` stores the transpose of ``W``, ``W.T``.\n\n intercept_ : ndarray of shape (n_targets,)\n Independent term in decision function.\n\n n_iter_ : int\n Number of iterations run by the coordinate descent solver to reach\n the specified tolerance.\n\n dual_gap_ : ndarray of shape (n_alphas,)\n The dual gaps at the end of the optimization for each alpha.\n\n eps_ : float\n The tolerance scaled scaled by the variance of the target `y`.\n\n sparse_coef_ : sparse matrix of shape (n_features,) or (n_targets, n_features)\n Sparse representation of the `coef_`.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n Lasso: Linear Model trained with L1 prior as regularizer (aka the Lasso).\n MultiTaskLasso: Multi-task L1/L2 Lasso with built-in cross-validation.\n MultiTaskElasticNet: Multi-task L1/L2 ElasticNet with built-in cross-validation.\n\n Notes\n -----\n The algorithm used to fit the model is coordinate descent.\n\n To avoid unnecessary memory duplication the X and y arguments of the fit\n method should be directly passed as Fortran-contiguous numpy arrays.\n\n Examples\n --------\n >>> from sklearn import linear_model\n >>> clf = linear_model.MultiTaskLasso(alpha=0.1)\n >>> clf.fit([[0, 1], [1, 2], [2, 4]], [[0, 0], [1, 1], [2, 3]])\n MultiTaskLasso(alpha=0.1)\n >>> print(clf.coef_)\n [[0. 0.60809415]\n [0. 0.94592424]]\n >>> print(clf.intercept_)\n [-0.41888636 -0.87382323]\n ", + "source_code": "\n\nclass MultiTaskLasso(MultiTaskElasticNet):\n \"\"\"Multi-task Lasso model trained with L1/L2 mixed-norm as regularizer.\n\n The optimization objective for Lasso is::\n\n (1 / (2 * n_samples)) * ||Y - XW||^2_Fro + alpha * ||W||_21\n\n Where::\n\n ||W||_21 = \\sum_i \\sqrt{\\sum_j w_{ij}^2}\n\n i.e. the sum of norm of each row.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n alpha : float, default=1.0\n Constant that multiplies the L1/L2 term. Defaults to 1.0.\n\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=False\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0 and will be removed in\n 1.2.\n\n copy_X : bool, default=True\n If ``True``, X will be copied; else, it may be overwritten.\n\n max_iter : int, default=1000\n The maximum number of iterations.\n\n tol : float, default=1e-4\n The tolerance for the optimization: if the updates are\n smaller than ``tol``, the optimization code checks the\n dual gap for optimality and continues until it is smaller\n than ``tol``.\n\n warm_start : bool, default=False\n When set to ``True``, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n random_state : int, RandomState instance, default=None\n The seed of the pseudo random number generator that selects a random\n feature to update. Used when ``selection`` == 'random'.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n selection : {'cyclic', 'random'}, default='cyclic'\n If set to 'random', a random coefficient is updated every iteration\n rather than looping over features sequentially by default. This\n (setting to 'random') often leads to significantly faster convergence\n especially when tol is higher than 1e-4.\n\n Attributes\n ----------\n coef_ : ndarray of shape (n_targets, n_features)\n Parameter vector (W in the cost function formula).\n Note that ``coef_`` stores the transpose of ``W``, ``W.T``.\n\n intercept_ : ndarray of shape (n_targets,)\n Independent term in decision function.\n\n n_iter_ : int\n Number of iterations run by the coordinate descent solver to reach\n the specified tolerance.\n\n dual_gap_ : ndarray of shape (n_alphas,)\n The dual gaps at the end of the optimization for each alpha.\n\n eps_ : float\n The tolerance scaled scaled by the variance of the target `y`.\n\n sparse_coef_ : sparse matrix of shape (n_features,) or (n_targets, n_features)\n Sparse representation of the `coef_`.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n Lasso: Linear Model trained with L1 prior as regularizer (aka the Lasso).\n MultiTaskLasso: Multi-task L1/L2 Lasso with built-in cross-validation.\n MultiTaskElasticNet: Multi-task L1/L2 ElasticNet with built-in cross-validation.\n\n Notes\n -----\n The algorithm used to fit the model is coordinate descent.\n\n To avoid unnecessary memory duplication the X and y arguments of the fit\n method should be directly passed as Fortran-contiguous numpy arrays.\n\n Examples\n --------\n >>> from sklearn import linear_model\n >>> clf = linear_model.MultiTaskLasso(alpha=0.1)\n >>> clf.fit([[0, 1], [1, 2], [2, 4]], [[0, 0], [1, 1], [2, 3]])\n MultiTaskLasso(alpha=0.1)\n >>> print(clf.coef_)\n [[0. 0.60809415]\n [0. 0.94592424]]\n >>> print(clf.intercept_)\n [-0.41888636 -0.87382323]\n \"\"\"\n \n def __init__(self, alpha=1.0, *, fit_intercept=True, normalize='deprecated', copy_X=True, max_iter=1000, tol=0.0001, warm_start=False, random_state=None, selection='cyclic'):\n self.alpha = alpha\n self.fit_intercept = fit_intercept\n self.normalize = normalize\n self.max_iter = max_iter\n self.copy_X = copy_X\n self.tol = tol\n self.warm_start = warm_start\n self.l1_ratio = 1.0\n self.random_state = random_state\n self.selection = selection\n" }, { "name": "MultiTaskLassoCV", @@ -23585,8 +23538,8 @@ ], "is_public": true, "description": "Multi-task Lasso model trained with L1/L2 mixed-norm as regularizer.\n\nSee glossary entry for :term:`cross-validation estimator`. The optimization objective for MultiTaskLasso is:: (1 / (2 * n_samples)) * ||Y - XW||^Fro_2 + alpha * ||W||_21 Where:: ||W||_21 = \\sum_i \\sqrt{\\sum_j w_{ij}^2} i.e. the sum of norm of each row. Read more in the :ref:`User Guide `. .. versionadded:: 0.15", - "docstring": "Multi-task Lasso model trained with L1/L2 mixed-norm as regularizer.\n\n See glossary entry for :term:`cross-validation estimator`.\n\n The optimization objective for MultiTaskLasso is::\n\n (1 / (2 * n_samples)) * ||Y - XW||^Fro_2 + alpha * ||W||_21\n\n Where::\n\n ||W||_21 = \\sum_i \\sqrt{\\sum_j w_{ij}^2}\n\n i.e. the sum of norm of each row.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.15\n\n Parameters\n ----------\n eps : float, default=1e-3\n Length of the path. ``eps=1e-3`` means that\n ``alpha_min / alpha_max = 1e-3``.\n\n n_alphas : int, default=100\n Number of alphas along the regularization path.\n\n alphas : array-like, default=None\n List of alphas where to compute the models.\n If not provided, set automatically.\n\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=False\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0 and will be removed in\n 1.2.\n\n max_iter : int, default=1000\n The maximum number of iterations.\n\n tol : float, default=1e-4\n The tolerance for the optimization: if the updates are\n smaller than ``tol``, the optimization code checks the\n dual gap for optimality and continues until it is smaller\n than ``tol``.\n\n copy_X : bool, default=True\n If ``True``, X will be copied; else, it may be overwritten.\n\n cv : int, cross-validation generator or iterable, default=None\n Determines the cross-validation splitting strategy.\n Possible inputs for cv are:\n\n - None, to use the default 5-fold cross-validation,\n - int, to specify the number of folds.\n - :term:`CV splitter`,\n - An iterable yielding (train, test) splits as arrays of indices.\n\n For int/None inputs, :class:`KFold` is used.\n\n Refer :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n .. versionchanged:: 0.22\n ``cv`` default value if None changed from 3-fold to 5-fold.\n\n verbose : bool or int, default=False\n Amount of verbosity.\n\n n_jobs : int, default=None\n Number of CPUs to use during the cross validation. Note that this is\n used only if multiple values for l1_ratio are given.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n random_state : int, RandomState instance, default=None\n The seed of the pseudo random number generator that selects a random\n feature to update. Used when ``selection`` == 'random'.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n selection : {'cyclic', 'random'}, default='cyclic'\n If set to 'random', a random coefficient is updated every iteration\n rather than looping over features sequentially by default. This\n (setting to 'random') often leads to significantly faster convergence\n especially when tol is higher than 1e-4.\n\n Attributes\n ----------\n intercept_ : ndarray of shape (n_targets,)\n Independent term in decision function.\n\n coef_ : ndarray of shape (n_targets, n_features)\n Parameter vector (W in the cost function formula).\n Note that ``coef_`` stores the transpose of ``W``, ``W.T``.\n\n alpha_ : float\n The amount of penalization chosen by cross validation.\n\n mse_path_ : ndarray of shape (n_alphas, n_folds)\n Mean square error for the test set on each fold, varying alpha.\n\n alphas_ : ndarray of shape (n_alphas,)\n The grid of alphas used for fitting.\n\n n_iter_ : int\n Number of iterations run by the coordinate descent solver to reach\n the specified tolerance for the optimal alpha.\n\n dual_gap_ : float\n The dual gap at the end of the optimization for the optimal alpha.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn.linear_model import MultiTaskLassoCV\n >>> from sklearn.datasets import make_regression\n >>> from sklearn.metrics import r2_score\n >>> X, y = make_regression(n_targets=2, noise=4, random_state=0)\n >>> reg = MultiTaskLassoCV(cv=5, random_state=0).fit(X, y)\n >>> r2_score(y, reg.predict(X))\n 0.9994...\n >>> reg.alpha_\n 0.5713...\n >>> reg.predict(X[:1,])\n array([[153.7971..., 94.9015...]])\n\n See Also\n --------\n MultiTaskElasticNet\n ElasticNetCV\n MultiTaskElasticNetCV\n\n Notes\n -----\n The algorithm used to fit the model is coordinate descent.\n\n To avoid unnecessary memory duplication the X and y arguments of the fit\n method should be directly passed as Fortran-contiguous numpy arrays.\n ", - "source_code": "\n\nclass MultiTaskLassoCV(RegressorMixin, LinearModelCV):\n \"\"\"Multi-task Lasso model trained with L1/L2 mixed-norm as regularizer.\n\n See glossary entry for :term:`cross-validation estimator`.\n\n The optimization objective for MultiTaskLasso is::\n\n (1 / (2 * n_samples)) * ||Y - XW||^Fro_2 + alpha * ||W||_21\n\n Where::\n\n ||W||_21 = \\sum_i \\sqrt{\\sum_j w_{ij}^2}\n\n i.e. the sum of norm of each row.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.15\n\n Parameters\n ----------\n eps : float, default=1e-3\n Length of the path. ``eps=1e-3`` means that\n ``alpha_min / alpha_max = 1e-3``.\n\n n_alphas : int, default=100\n Number of alphas along the regularization path.\n\n alphas : array-like, default=None\n List of alphas where to compute the models.\n If not provided, set automatically.\n\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=False\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0 and will be removed in\n 1.2.\n\n max_iter : int, default=1000\n The maximum number of iterations.\n\n tol : float, default=1e-4\n The tolerance for the optimization: if the updates are\n smaller than ``tol``, the optimization code checks the\n dual gap for optimality and continues until it is smaller\n than ``tol``.\n\n copy_X : bool, default=True\n If ``True``, X will be copied; else, it may be overwritten.\n\n cv : int, cross-validation generator or iterable, default=None\n Determines the cross-validation splitting strategy.\n Possible inputs for cv are:\n\n - None, to use the default 5-fold cross-validation,\n - int, to specify the number of folds.\n - :term:`CV splitter`,\n - An iterable yielding (train, test) splits as arrays of indices.\n\n For int/None inputs, :class:`KFold` is used.\n\n Refer :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n .. versionchanged:: 0.22\n ``cv`` default value if None changed from 3-fold to 5-fold.\n\n verbose : bool or int, default=False\n Amount of verbosity.\n\n n_jobs : int, default=None\n Number of CPUs to use during the cross validation. Note that this is\n used only if multiple values for l1_ratio are given.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n random_state : int, RandomState instance, default=None\n The seed of the pseudo random number generator that selects a random\n feature to update. Used when ``selection`` == 'random'.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n selection : {'cyclic', 'random'}, default='cyclic'\n If set to 'random', a random coefficient is updated every iteration\n rather than looping over features sequentially by default. This\n (setting to 'random') often leads to significantly faster convergence\n especially when tol is higher than 1e-4.\n\n Attributes\n ----------\n intercept_ : ndarray of shape (n_targets,)\n Independent term in decision function.\n\n coef_ : ndarray of shape (n_targets, n_features)\n Parameter vector (W in the cost function formula).\n Note that ``coef_`` stores the transpose of ``W``, ``W.T``.\n\n alpha_ : float\n The amount of penalization chosen by cross validation.\n\n mse_path_ : ndarray of shape (n_alphas, n_folds)\n Mean square error for the test set on each fold, varying alpha.\n\n alphas_ : ndarray of shape (n_alphas,)\n The grid of alphas used for fitting.\n\n n_iter_ : int\n Number of iterations run by the coordinate descent solver to reach\n the specified tolerance for the optimal alpha.\n\n dual_gap_ : float\n The dual gap at the end of the optimization for the optimal alpha.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn.linear_model import MultiTaskLassoCV\n >>> from sklearn.datasets import make_regression\n >>> from sklearn.metrics import r2_score\n >>> X, y = make_regression(n_targets=2, noise=4, random_state=0)\n >>> reg = MultiTaskLassoCV(cv=5, random_state=0).fit(X, y)\n >>> r2_score(y, reg.predict(X))\n 0.9994...\n >>> reg.alpha_\n 0.5713...\n >>> reg.predict(X[:1,])\n array([[153.7971..., 94.9015...]])\n\n See Also\n --------\n MultiTaskElasticNet\n ElasticNetCV\n MultiTaskElasticNetCV\n\n Notes\n -----\n The algorithm used to fit the model is coordinate descent.\n\n To avoid unnecessary memory duplication the X and y arguments of the fit\n method should be directly passed as Fortran-contiguous numpy arrays.\n \"\"\"\n path = staticmethod(lasso_path)\n \n def __init__(self, *, eps=0.001, n_alphas=100, alphas=None, fit_intercept=True, normalize='deprecated', max_iter=1000, tol=0.0001, copy_X=True, cv=None, verbose=False, n_jobs=None, random_state=None, selection='cyclic'):\n super().__init__(eps=eps, n_alphas=n_alphas, alphas=alphas, fit_intercept=fit_intercept, normalize=normalize, max_iter=max_iter, tol=tol, copy_X=copy_X, cv=cv, verbose=verbose, n_jobs=n_jobs, random_state=random_state, selection=selection)\n \n def _get_estimator(self):\n return MultiTaskLasso()\n \n def _is_multitask(self):\n return True\n \n def _more_tags(self):\n return {'multioutput_only': True}\n \n def fit(self, X, y):\n \"\"\"Fit MultiTaskLasso model with coordinate descent.\n\n Fit is on grid of alphas and best alpha estimated by cross-validation.\n\n Parameters\n ----------\n X : ndarray of shape (n_samples, n_features)\n Data.\n y : ndarray of shape (n_samples, n_targets)\n Target. Will be cast to X's dtype if necessary.\n\n Returns\n -------\n self : object\n Returns an instance of fitted model.\n \"\"\"\n return super().fit(X, y)\n" + "docstring": "Multi-task Lasso model trained with L1/L2 mixed-norm as regularizer.\n\n See glossary entry for :term:`cross-validation estimator`.\n\n The optimization objective for MultiTaskLasso is::\n\n (1 / (2 * n_samples)) * ||Y - XW||^Fro_2 + alpha * ||W||_21\n\n Where::\n\n ||W||_21 = \\sum_i \\sqrt{\\sum_j w_{ij}^2}\n\n i.e. the sum of norm of each row.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.15\n\n Parameters\n ----------\n eps : float, default=1e-3\n Length of the path. ``eps=1e-3`` means that\n ``alpha_min / alpha_max = 1e-3``.\n\n n_alphas : int, default=100\n Number of alphas along the regularization path.\n\n alphas : array-like, default=None\n List of alphas where to compute the models.\n If not provided, set automatically.\n\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=False\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0 and will be removed in\n 1.2.\n\n max_iter : int, default=1000\n The maximum number of iterations.\n\n tol : float, default=1e-4\n The tolerance for the optimization: if the updates are\n smaller than ``tol``, the optimization code checks the\n dual gap for optimality and continues until it is smaller\n than ``tol``.\n\n copy_X : bool, default=True\n If ``True``, X will be copied; else, it may be overwritten.\n\n cv : int, cross-validation generator or iterable, default=None\n Determines the cross-validation splitting strategy.\n Possible inputs for cv are:\n\n - None, to use the default 5-fold cross-validation,\n - int, to specify the number of folds.\n - :term:`CV splitter`,\n - An iterable yielding (train, test) splits as arrays of indices.\n\n For int/None inputs, :class:`KFold` is used.\n\n Refer :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n .. versionchanged:: 0.22\n ``cv`` default value if None changed from 3-fold to 5-fold.\n\n verbose : bool or int, default=False\n Amount of verbosity.\n\n n_jobs : int, default=None\n Number of CPUs to use during the cross validation. Note that this is\n used only if multiple values for l1_ratio are given.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n random_state : int, RandomState instance, default=None\n The seed of the pseudo random number generator that selects a random\n feature to update. Used when ``selection`` == 'random'.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n selection : {'cyclic', 'random'}, default='cyclic'\n If set to 'random', a random coefficient is updated every iteration\n rather than looping over features sequentially by default. This\n (setting to 'random') often leads to significantly faster convergence\n especially when tol is higher than 1e-4.\n\n Attributes\n ----------\n intercept_ : ndarray of shape (n_targets,)\n Independent term in decision function.\n\n coef_ : ndarray of shape (n_targets, n_features)\n Parameter vector (W in the cost function formula).\n Note that ``coef_`` stores the transpose of ``W``, ``W.T``.\n\n alpha_ : float\n The amount of penalization chosen by cross validation.\n\n mse_path_ : ndarray of shape (n_alphas, n_folds)\n Mean square error for the test set on each fold, varying alpha.\n\n alphas_ : ndarray of shape (n_alphas,)\n The grid of alphas used for fitting.\n\n n_iter_ : int\n Number of iterations run by the coordinate descent solver to reach\n the specified tolerance for the optimal alpha.\n\n dual_gap_ : float\n The dual gap at the end of the optimization for the optimal alpha.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n MultiTaskElasticNet : Multi-task ElasticNet model trained with L1/L2\n mixed-norm as regularizer.\n ElasticNetCV : Elastic net model with best model selection by\n cross-validation.\n MultiTaskElasticNetCV : Multi-task L1/L2 ElasticNet with built-in\n cross-validation.\n\n Notes\n -----\n The algorithm used to fit the model is coordinate descent.\n\n To avoid unnecessary memory duplication the X and y arguments of the fit\n method should be directly passed as Fortran-contiguous numpy arrays.\n\n Examples\n --------\n >>> from sklearn.linear_model import MultiTaskLassoCV\n >>> from sklearn.datasets import make_regression\n >>> from sklearn.metrics import r2_score\n >>> X, y = make_regression(n_targets=2, noise=4, random_state=0)\n >>> reg = MultiTaskLassoCV(cv=5, random_state=0).fit(X, y)\n >>> r2_score(y, reg.predict(X))\n 0.9994...\n >>> reg.alpha_\n 0.5713...\n >>> reg.predict(X[:1,])\n array([[153.7971..., 94.9015...]])\n ", + "source_code": "\n\nclass MultiTaskLassoCV(RegressorMixin, LinearModelCV):\n \"\"\"Multi-task Lasso model trained with L1/L2 mixed-norm as regularizer.\n\n See glossary entry for :term:`cross-validation estimator`.\n\n The optimization objective for MultiTaskLasso is::\n\n (1 / (2 * n_samples)) * ||Y - XW||^Fro_2 + alpha * ||W||_21\n\n Where::\n\n ||W||_21 = \\sum_i \\sqrt{\\sum_j w_{ij}^2}\n\n i.e. the sum of norm of each row.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.15\n\n Parameters\n ----------\n eps : float, default=1e-3\n Length of the path. ``eps=1e-3`` means that\n ``alpha_min / alpha_max = 1e-3``.\n\n n_alphas : int, default=100\n Number of alphas along the regularization path.\n\n alphas : array-like, default=None\n List of alphas where to compute the models.\n If not provided, set automatically.\n\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=False\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0 and will be removed in\n 1.2.\n\n max_iter : int, default=1000\n The maximum number of iterations.\n\n tol : float, default=1e-4\n The tolerance for the optimization: if the updates are\n smaller than ``tol``, the optimization code checks the\n dual gap for optimality and continues until it is smaller\n than ``tol``.\n\n copy_X : bool, default=True\n If ``True``, X will be copied; else, it may be overwritten.\n\n cv : int, cross-validation generator or iterable, default=None\n Determines the cross-validation splitting strategy.\n Possible inputs for cv are:\n\n - None, to use the default 5-fold cross-validation,\n - int, to specify the number of folds.\n - :term:`CV splitter`,\n - An iterable yielding (train, test) splits as arrays of indices.\n\n For int/None inputs, :class:`KFold` is used.\n\n Refer :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n .. versionchanged:: 0.22\n ``cv`` default value if None changed from 3-fold to 5-fold.\n\n verbose : bool or int, default=False\n Amount of verbosity.\n\n n_jobs : int, default=None\n Number of CPUs to use during the cross validation. Note that this is\n used only if multiple values for l1_ratio are given.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n random_state : int, RandomState instance, default=None\n The seed of the pseudo random number generator that selects a random\n feature to update. Used when ``selection`` == 'random'.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n selection : {'cyclic', 'random'}, default='cyclic'\n If set to 'random', a random coefficient is updated every iteration\n rather than looping over features sequentially by default. This\n (setting to 'random') often leads to significantly faster convergence\n especially when tol is higher than 1e-4.\n\n Attributes\n ----------\n intercept_ : ndarray of shape (n_targets,)\n Independent term in decision function.\n\n coef_ : ndarray of shape (n_targets, n_features)\n Parameter vector (W in the cost function formula).\n Note that ``coef_`` stores the transpose of ``W``, ``W.T``.\n\n alpha_ : float\n The amount of penalization chosen by cross validation.\n\n mse_path_ : ndarray of shape (n_alphas, n_folds)\n Mean square error for the test set on each fold, varying alpha.\n\n alphas_ : ndarray of shape (n_alphas,)\n The grid of alphas used for fitting.\n\n n_iter_ : int\n Number of iterations run by the coordinate descent solver to reach\n the specified tolerance for the optimal alpha.\n\n dual_gap_ : float\n The dual gap at the end of the optimization for the optimal alpha.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n MultiTaskElasticNet : Multi-task ElasticNet model trained with L1/L2\n mixed-norm as regularizer.\n ElasticNetCV : Elastic net model with best model selection by\n cross-validation.\n MultiTaskElasticNetCV : Multi-task L1/L2 ElasticNet with built-in\n cross-validation.\n\n Notes\n -----\n The algorithm used to fit the model is coordinate descent.\n\n To avoid unnecessary memory duplication the X and y arguments of the fit\n method should be directly passed as Fortran-contiguous numpy arrays.\n\n Examples\n --------\n >>> from sklearn.linear_model import MultiTaskLassoCV\n >>> from sklearn.datasets import make_regression\n >>> from sklearn.metrics import r2_score\n >>> X, y = make_regression(n_targets=2, noise=4, random_state=0)\n >>> reg = MultiTaskLassoCV(cv=5, random_state=0).fit(X, y)\n >>> r2_score(y, reg.predict(X))\n 0.9994...\n >>> reg.alpha_\n 0.5713...\n >>> reg.predict(X[:1,])\n array([[153.7971..., 94.9015...]])\n \"\"\"\n path = staticmethod(lasso_path)\n \n def __init__(self, *, eps=0.001, n_alphas=100, alphas=None, fit_intercept=True, normalize='deprecated', max_iter=1000, tol=0.0001, copy_X=True, cv=None, verbose=False, n_jobs=None, random_state=None, selection='cyclic'):\n super().__init__(eps=eps, n_alphas=n_alphas, alphas=alphas, fit_intercept=fit_intercept, normalize=normalize, max_iter=max_iter, tol=tol, copy_X=copy_X, cv=cv, verbose=verbose, n_jobs=n_jobs, random_state=random_state, selection=selection)\n \n def _get_estimator(self):\n return MultiTaskLasso()\n \n def _is_multitask(self):\n return True\n \n def _more_tags(self):\n return {'multioutput_only': True}\n \n def fit(self, X, y):\n \"\"\"Fit MultiTaskLasso model with coordinate descent.\n\n Fit is on grid of alphas and best alpha estimated by cross-validation.\n\n Parameters\n ----------\n X : ndarray of shape (n_samples, n_features)\n Data.\n y : ndarray of shape (n_samples, n_targets)\n Target. Will be cast to X's dtype if necessary.\n\n Returns\n -------\n self : object\n Returns an instance of fitted model.\n \"\"\"\n return super().fit(X, y)\n" }, { "name": "GammaRegressor", @@ -23595,8 +23548,8 @@ "superclasses": ["GeneralizedLinearRegressor"], "methods": [ "sklearn.linear_model._glm.glm.GammaRegressor.__init__", - "sklearn.linear_model._glm.glm.GammaRegressor.family", - "sklearn.linear_model._glm.glm.GammaRegressor.family" + "sklearn.linear_model._glm.glm.GammaRegressor.family@getter", + "sklearn.linear_model._glm.glm.GammaRegressor.family@setter" ], "is_public": true, "description": "Generalized Linear Model with a Gamma distribution.\n\nThis regressor uses the 'log' link function. Read more in the :ref:`User Guide `. .. versionadded:: 0.23", @@ -23628,8 +23581,8 @@ "superclasses": ["GeneralizedLinearRegressor"], "methods": [ "sklearn.linear_model._glm.glm.PoissonRegressor.__init__", - "sklearn.linear_model._glm.glm.PoissonRegressor.family", - "sklearn.linear_model._glm.glm.PoissonRegressor.family" + "sklearn.linear_model._glm.glm.PoissonRegressor.family@getter", + "sklearn.linear_model._glm.glm.PoissonRegressor.family@setter" ], "is_public": true, "description": "Generalized Linear Model with a Poisson distribution.\n\nThis regressor uses the 'log' link function. Read more in the :ref:`User Guide `. .. versionadded:: 0.23", @@ -23643,13 +23596,13 @@ "superclasses": ["GeneralizedLinearRegressor"], "methods": [ "sklearn.linear_model._glm.glm.TweedieRegressor.__init__", - "sklearn.linear_model._glm.glm.TweedieRegressor.family", - "sklearn.linear_model._glm.glm.TweedieRegressor.family" + "sklearn.linear_model._glm.glm.TweedieRegressor.family@getter", + "sklearn.linear_model._glm.glm.TweedieRegressor.family@setter" ], "is_public": true, "description": "Generalized Linear Model with a Tweedie distribution.\n\nThis estimator can be used to model different GLMs depending on the ``power`` parameter, which determines the underlying distribution. Read more in the :ref:`User Guide `. .. versionadded:: 0.23", - "docstring": "Generalized Linear Model with a Tweedie distribution.\n\n This estimator can be used to model different GLMs depending on the\n ``power`` parameter, which determines the underlying distribution.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.23\n\n Parameters\n ----------\n power : float, default=0\n The power determines the underlying target distribution according\n to the following table:\n\n +-------+------------------------+\n | Power | Distribution |\n +=======+========================+\n | 0 | Normal |\n +-------+------------------------+\n | 1 | Poisson |\n +-------+------------------------+\n | (1,2) | Compound Poisson Gamma |\n +-------+------------------------+\n | 2 | Gamma |\n +-------+------------------------+\n | 3 | Inverse Gaussian |\n +-------+------------------------+\n\n For ``0 < power < 1``, no distribution exists.\n\n alpha : float, default=1\n Constant that multiplies the penalty term and thus determines the\n regularization strength. ``alpha = 0`` is equivalent to unpenalized\n GLMs. In this case, the design matrix `X` must have full column rank\n (no collinearities).\n\n fit_intercept : bool, default=True\n Specifies if a constant (a.k.a. bias or intercept) should be\n added to the linear predictor (X @ coef + intercept).\n\n link : {'auto', 'identity', 'log'}, default='auto'\n The link function of the GLM, i.e. mapping from linear predictor\n `X @ coeff + intercept` to prediction `y_pred`. Option 'auto' sets\n the link depending on the chosen family as follows:\n\n - 'identity' for Normal distribution\n - 'log' for Poisson, Gamma and Inverse Gaussian distributions\n\n max_iter : int, default=100\n The maximal number of iterations for the solver.\n\n tol : float, default=1e-4\n Stopping criterion. For the lbfgs solver,\n the iteration will stop when ``max{|g_j|, j = 1, ..., d} <= tol``\n where ``g_j`` is the j-th component of the gradient (derivative) of\n the objective function.\n\n warm_start : bool, default=False\n If set to ``True``, reuse the solution of the previous call to ``fit``\n as initialization for ``coef_`` and ``intercept_`` .\n\n verbose : int, default=0\n For the lbfgs solver set verbose to any positive number for verbosity.\n\n Attributes\n ----------\n coef_ : array of shape (n_features,)\n Estimated coefficients for the linear predictor (`X @ coef_ +\n intercept_`) in the GLM.\n\n intercept_ : float\n Intercept (a.k.a. bias) added to linear predictor.\n\n n_iter_ : int\n Actual number of iterations used in the solver.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n ----------\n >>> from sklearn import linear_model\n >>> clf = linear_model.TweedieRegressor()\n >>> X = [[1, 2], [2, 3], [3, 4], [4, 3]]\n >>> y = [2, 3.5, 5, 5.5]\n >>> clf.fit(X, y)\n TweedieRegressor()\n >>> clf.score(X, y)\n 0.839...\n >>> clf.coef_\n array([0.599..., 0.299...])\n >>> clf.intercept_\n 1.600...\n >>> clf.predict([[1, 1], [3, 4]])\n array([2.500..., 4.599...])\n ", - "source_code": "\n\nclass TweedieRegressor(GeneralizedLinearRegressor):\n \"\"\"Generalized Linear Model with a Tweedie distribution.\n\n This estimator can be used to model different GLMs depending on the\n ``power`` parameter, which determines the underlying distribution.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.23\n\n Parameters\n ----------\n power : float, default=0\n The power determines the underlying target distribution according\n to the following table:\n\n +-------+------------------------+\n | Power | Distribution |\n +=======+========================+\n | 0 | Normal |\n +-------+------------------------+\n | 1 | Poisson |\n +-------+------------------------+\n | (1,2) | Compound Poisson Gamma |\n +-------+------------------------+\n | 2 | Gamma |\n +-------+------------------------+\n | 3 | Inverse Gaussian |\n +-------+------------------------+\n\n For ``0 < power < 1``, no distribution exists.\n\n alpha : float, default=1\n Constant that multiplies the penalty term and thus determines the\n regularization strength. ``alpha = 0`` is equivalent to unpenalized\n GLMs. In this case, the design matrix `X` must have full column rank\n (no collinearities).\n\n fit_intercept : bool, default=True\n Specifies if a constant (a.k.a. bias or intercept) should be\n added to the linear predictor (X @ coef + intercept).\n\n link : {'auto', 'identity', 'log'}, default='auto'\n The link function of the GLM, i.e. mapping from linear predictor\n `X @ coeff + intercept` to prediction `y_pred`. Option 'auto' sets\n the link depending on the chosen family as follows:\n\n - 'identity' for Normal distribution\n - 'log' for Poisson, Gamma and Inverse Gaussian distributions\n\n max_iter : int, default=100\n The maximal number of iterations for the solver.\n\n tol : float, default=1e-4\n Stopping criterion. For the lbfgs solver,\n the iteration will stop when ``max{|g_j|, j = 1, ..., d} <= tol``\n where ``g_j`` is the j-th component of the gradient (derivative) of\n the objective function.\n\n warm_start : bool, default=False\n If set to ``True``, reuse the solution of the previous call to ``fit``\n as initialization for ``coef_`` and ``intercept_`` .\n\n verbose : int, default=0\n For the lbfgs solver set verbose to any positive number for verbosity.\n\n Attributes\n ----------\n coef_ : array of shape (n_features,)\n Estimated coefficients for the linear predictor (`X @ coef_ +\n intercept_`) in the GLM.\n\n intercept_ : float\n Intercept (a.k.a. bias) added to linear predictor.\n\n n_iter_ : int\n Actual number of iterations used in the solver.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n ----------\n >>> from sklearn import linear_model\n >>> clf = linear_model.TweedieRegressor()\n >>> X = [[1, 2], [2, 3], [3, 4], [4, 3]]\n >>> y = [2, 3.5, 5, 5.5]\n >>> clf.fit(X, y)\n TweedieRegressor()\n >>> clf.score(X, y)\n 0.839...\n >>> clf.coef_\n array([0.599..., 0.299...])\n >>> clf.intercept_\n 1.600...\n >>> clf.predict([[1, 1], [3, 4]])\n array([2.500..., 4.599...])\n \"\"\"\n \n def __init__(self, *, power=0.0, alpha=1.0, fit_intercept=True, link='auto', max_iter=100, tol=0.0001, warm_start=False, verbose=0):\n super().__init__(alpha=alpha, fit_intercept=fit_intercept, family=TweedieDistribution(power=power), link=link, max_iter=max_iter, tol=tol, warm_start=warm_start, verbose=verbose)\n \n @property\n def family(self):\n dist = TweedieDistribution(power=self.power)\n return dist\n \n @family.setter\n def family(self, value):\n if isinstance(value, TweedieDistribution):\n self.power = value.power\n else:\n raise TypeError('TweedieRegressor.family must be of type TweedieDistribution!')\n" + "docstring": "Generalized Linear Model with a Tweedie distribution.\n\n This estimator can be used to model different GLMs depending on the\n ``power`` parameter, which determines the underlying distribution.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.23\n\n Parameters\n ----------\n power : float, default=0\n The power determines the underlying target distribution according\n to the following table:\n\n +-------+------------------------+\n | Power | Distribution |\n +=======+========================+\n | 0 | Normal |\n +-------+------------------------+\n | 1 | Poisson |\n +-------+------------------------+\n | (1,2) | Compound Poisson Gamma |\n +-------+------------------------+\n | 2 | Gamma |\n +-------+------------------------+\n | 3 | Inverse Gaussian |\n +-------+------------------------+\n\n For ``0 < power < 1``, no distribution exists.\n\n alpha : float, default=1\n Constant that multiplies the penalty term and thus determines the\n regularization strength. ``alpha = 0`` is equivalent to unpenalized\n GLMs. In this case, the design matrix `X` must have full column rank\n (no collinearities).\n\n fit_intercept : bool, default=True\n Specifies if a constant (a.k.a. bias or intercept) should be\n added to the linear predictor (X @ coef + intercept).\n\n link : {'auto', 'identity', 'log'}, default='auto'\n The link function of the GLM, i.e. mapping from linear predictor\n `X @ coeff + intercept` to prediction `y_pred`. Option 'auto' sets\n the link depending on the chosen family as follows:\n\n - 'identity' for Normal distribution\n - 'log' for Poisson, Gamma and Inverse Gaussian distributions\n\n max_iter : int, default=100\n The maximal number of iterations for the solver.\n\n tol : float, default=1e-4\n Stopping criterion. For the lbfgs solver,\n the iteration will stop when ``max{|g_j|, j = 1, ..., d} <= tol``\n where ``g_j`` is the j-th component of the gradient (derivative) of\n the objective function.\n\n warm_start : bool, default=False\n If set to ``True``, reuse the solution of the previous call to ``fit``\n as initialization for ``coef_`` and ``intercept_`` .\n\n verbose : int, default=0\n For the lbfgs solver set verbose to any positive number for verbosity.\n\n Attributes\n ----------\n coef_ : array of shape (n_features,)\n Estimated coefficients for the linear predictor (`X @ coef_ +\n intercept_`) in the GLM.\n\n intercept_ : float\n Intercept (a.k.a. bias) added to linear predictor.\n\n n_iter_ : int\n Actual number of iterations used in the solver.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n PoissonRegressor : Generalized Linear Model with a Poisson distribution.\n GammaRegressor : Generalized Linear Model with a Gamma distribution.\n\n Examples\n ----------\n >>> from sklearn import linear_model\n >>> clf = linear_model.TweedieRegressor()\n >>> X = [[1, 2], [2, 3], [3, 4], [4, 3]]\n >>> y = [2, 3.5, 5, 5.5]\n >>> clf.fit(X, y)\n TweedieRegressor()\n >>> clf.score(X, y)\n 0.839...\n >>> clf.coef_\n array([0.599..., 0.299...])\n >>> clf.intercept_\n 1.600...\n >>> clf.predict([[1, 1], [3, 4]])\n array([2.500..., 4.599...])\n ", + "source_code": "\n\nclass TweedieRegressor(GeneralizedLinearRegressor):\n \"\"\"Generalized Linear Model with a Tweedie distribution.\n\n This estimator can be used to model different GLMs depending on the\n ``power`` parameter, which determines the underlying distribution.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.23\n\n Parameters\n ----------\n power : float, default=0\n The power determines the underlying target distribution according\n to the following table:\n\n +-------+------------------------+\n | Power | Distribution |\n +=======+========================+\n | 0 | Normal |\n +-------+------------------------+\n | 1 | Poisson |\n +-------+------------------------+\n | (1,2) | Compound Poisson Gamma |\n +-------+------------------------+\n | 2 | Gamma |\n +-------+------------------------+\n | 3 | Inverse Gaussian |\n +-------+------------------------+\n\n For ``0 < power < 1``, no distribution exists.\n\n alpha : float, default=1\n Constant that multiplies the penalty term and thus determines the\n regularization strength. ``alpha = 0`` is equivalent to unpenalized\n GLMs. In this case, the design matrix `X` must have full column rank\n (no collinearities).\n\n fit_intercept : bool, default=True\n Specifies if a constant (a.k.a. bias or intercept) should be\n added to the linear predictor (X @ coef + intercept).\n\n link : {'auto', 'identity', 'log'}, default='auto'\n The link function of the GLM, i.e. mapping from linear predictor\n `X @ coeff + intercept` to prediction `y_pred`. Option 'auto' sets\n the link depending on the chosen family as follows:\n\n - 'identity' for Normal distribution\n - 'log' for Poisson, Gamma and Inverse Gaussian distributions\n\n max_iter : int, default=100\n The maximal number of iterations for the solver.\n\n tol : float, default=1e-4\n Stopping criterion. For the lbfgs solver,\n the iteration will stop when ``max{|g_j|, j = 1, ..., d} <= tol``\n where ``g_j`` is the j-th component of the gradient (derivative) of\n the objective function.\n\n warm_start : bool, default=False\n If set to ``True``, reuse the solution of the previous call to ``fit``\n as initialization for ``coef_`` and ``intercept_`` .\n\n verbose : int, default=0\n For the lbfgs solver set verbose to any positive number for verbosity.\n\n Attributes\n ----------\n coef_ : array of shape (n_features,)\n Estimated coefficients for the linear predictor (`X @ coef_ +\n intercept_`) in the GLM.\n\n intercept_ : float\n Intercept (a.k.a. bias) added to linear predictor.\n\n n_iter_ : int\n Actual number of iterations used in the solver.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n PoissonRegressor : Generalized Linear Model with a Poisson distribution.\n GammaRegressor : Generalized Linear Model with a Gamma distribution.\n\n Examples\n ----------\n >>> from sklearn import linear_model\n >>> clf = linear_model.TweedieRegressor()\n >>> X = [[1, 2], [2, 3], [3, 4], [4, 3]]\n >>> y = [2, 3.5, 5, 5.5]\n >>> clf.fit(X, y)\n TweedieRegressor()\n >>> clf.score(X, y)\n 0.839...\n >>> clf.coef_\n array([0.599..., 0.299...])\n >>> clf.intercept_\n 1.600...\n >>> clf.predict([[1, 1], [3, 4]])\n array([2.500..., 4.599...])\n \"\"\"\n \n def __init__(self, *, power=0.0, alpha=1.0, fit_intercept=True, link='auto', max_iter=100, tol=0.0001, warm_start=False, verbose=0):\n super().__init__(alpha=alpha, fit_intercept=fit_intercept, family=TweedieDistribution(power=power), link=link, max_iter=max_iter, tol=tol, warm_start=warm_start, verbose=verbose)\n \n @property\n def family(self):\n \"\"\"Return the family of the regressor.\"\"\"\n dist = TweedieDistribution(power=self.power)\n return dist\n \n @family.setter\n def family(self, value):\n if isinstance(value, TweedieDistribution):\n self.power = value.power\n else:\n raise TypeError('TweedieRegressor.family must be of type TweedieDistribution!')\n" }, { "name": "BaseLink", @@ -23821,7 +23774,7 @@ "is_public": true, "description": "Logistic Regression (aka logit, MaxEnt) classifier.\n\nIn the multiclass case, the training algorithm uses the one-vs-rest (OvR) scheme if the 'multi_class' option is set to 'ovr', and uses the cross-entropy loss if the 'multi_class' option is set to 'multinomial'. (Currently the 'multinomial' option is supported only by the 'lbfgs', 'sag', 'saga' and 'newton-cg' solvers.) This class implements regularized logistic regression using the 'liblinear' library, 'newton-cg', 'sag', 'saga' and 'lbfgs' solvers. **Note that regularization is applied by default**. It can handle both dense and sparse input. Use C-ordered arrays or CSR matrices containing 64-bit floats for optimal performance; any other input format will be converted (and copied). The 'newton-cg', 'sag', and 'lbfgs' solvers support only L2 regularization with primal formulation, or no regularization. The 'liblinear' solver supports both L1 and L2 regularization, with a dual formulation only for the L2 penalty. The Elastic-Net regularization is only supported by the 'saga' solver. Read more in the :ref:`User Guide `.", "docstring": "\n Logistic Regression (aka logit, MaxEnt) classifier.\n\n In the multiclass case, the training algorithm uses the one-vs-rest (OvR)\n scheme if the 'multi_class' option is set to 'ovr', and uses the\n cross-entropy loss if the 'multi_class' option is set to 'multinomial'.\n (Currently the 'multinomial' option is supported only by the 'lbfgs',\n 'sag', 'saga' and 'newton-cg' solvers.)\n\n This class implements regularized logistic regression using the\n 'liblinear' library, 'newton-cg', 'sag', 'saga' and 'lbfgs' solvers. **Note\n that regularization is applied by default**. It can handle both dense\n and sparse input. Use C-ordered arrays or CSR matrices containing 64-bit\n floats for optimal performance; any other input format will be converted\n (and copied).\n\n The 'newton-cg', 'sag', and 'lbfgs' solvers support only L2 regularization\n with primal formulation, or no regularization. The 'liblinear' solver\n supports both L1 and L2 regularization, with a dual formulation only for\n the L2 penalty. The Elastic-Net regularization is only supported by the\n 'saga' solver.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n penalty : {'l1', 'l2', 'elasticnet', 'none'}, default='l2'\n Specify the norm of the penalty:\n\n - `'none'`: no penalty is added;\n - `'l2'`: add a L2 penalty term and it is the default choice;\n - `'l1'`: add a L1 penalty term;\n - `'elasticnet'`: both L1 and L2 penalty terms are added.\n\n .. warning::\n Some penalties may not work with some solvers. See the parameter\n `solver` below, to know the compatibility between the penalty and\n solver.\n\n .. versionadded:: 0.19\n l1 penalty with SAGA solver (allowing 'multinomial' + L1)\n\n dual : bool, default=False\n Dual or primal formulation. Dual formulation is only implemented for\n l2 penalty with liblinear solver. Prefer dual=False when\n n_samples > n_features.\n\n tol : float, default=1e-4\n Tolerance for stopping criteria.\n\n C : float, default=1.0\n Inverse of regularization strength; must be a positive float.\n Like in support vector machines, smaller values specify stronger\n regularization.\n\n fit_intercept : bool, default=True\n Specifies if a constant (a.k.a. bias or intercept) should be\n added to the decision function.\n\n intercept_scaling : float, default=1\n Useful only when the solver 'liblinear' is used\n and self.fit_intercept is set to True. In this case, x becomes\n [x, self.intercept_scaling],\n i.e. a \"synthetic\" feature with constant value equal to\n intercept_scaling is appended to the instance vector.\n The intercept becomes ``intercept_scaling * synthetic_feature_weight``.\n\n Note! the synthetic feature weight is subject to l1/l2 regularization\n as all other features.\n To lessen the effect of regularization on synthetic feature weight\n (and therefore on the intercept) intercept_scaling has to be increased.\n\n class_weight : dict or 'balanced', default=None\n Weights associated with classes in the form ``{class_label: weight}``.\n If not given, all classes are supposed to have weight one.\n\n The \"balanced\" mode uses the values of y to automatically adjust\n weights inversely proportional to class frequencies in the input data\n as ``n_samples / (n_classes * np.bincount(y))``.\n\n Note that these weights will be multiplied with sample_weight (passed\n through the fit method) if sample_weight is specified.\n\n .. versionadded:: 0.17\n *class_weight='balanced'*\n\n random_state : int, RandomState instance, default=None\n Used when ``solver`` == 'sag', 'saga' or 'liblinear' to shuffle the\n data. See :term:`Glossary ` for details.\n\n solver : {'newton-cg', 'lbfgs', 'liblinear', 'sag', 'saga'}, default='lbfgs'\n\n Algorithm to use in the optimization problem. Default is 'lbfgs'.\n To choose a solver, you might want to consider the following aspects:\n\n - For small datasets, 'liblinear' is a good choice, whereas 'sag'\n and 'saga' are faster for large ones;\n - For multiclass problems, only 'newton-cg', 'sag', 'saga' and\n 'lbfgs' handle multinomial loss;\n - 'liblinear' is limited to one-versus-rest schemes.\n\n .. warning::\n The choice of the algorithm depends on the penalty chosen:\n Supported penalties by solver:\n\n - 'newton-cg' - ['l2', 'none']\n - 'lbfgs' - ['l2', 'none']\n - 'liblinear' - ['l1', 'l2']\n - 'sag' - ['l2', 'none']\n - 'saga' - ['elasticnet', 'l1', 'l2', 'none']\n\n .. note::\n 'sag' and 'saga' fast convergence is only guaranteed on\n features with approximately the same scale. You can\n preprocess the data with a scaler from :mod:`sklearn.preprocessing`.\n\n .. seealso::\n Refer to the User Guide for more information regarding\n :class:`LogisticRegression` and more specifically the\n `Table `_\n summarazing solver/penalty supports.\n \n\n .. versionadded:: 0.17\n Stochastic Average Gradient descent solver.\n .. versionadded:: 0.19\n SAGA solver.\n .. versionchanged:: 0.22\n The default solver changed from 'liblinear' to 'lbfgs' in 0.22.\n\n max_iter : int, default=100\n Maximum number of iterations taken for the solvers to converge.\n\n multi_class : {'auto', 'ovr', 'multinomial'}, default='auto'\n If the option chosen is 'ovr', then a binary problem is fit for each\n label. For 'multinomial' the loss minimised is the multinomial loss fit\n across the entire probability distribution, *even when the data is\n binary*. 'multinomial' is unavailable when solver='liblinear'.\n 'auto' selects 'ovr' if the data is binary, or if solver='liblinear',\n and otherwise selects 'multinomial'.\n\n .. versionadded:: 0.18\n Stochastic Average Gradient descent solver for 'multinomial' case.\n .. versionchanged:: 0.22\n Default changed from 'ovr' to 'auto' in 0.22.\n\n verbose : int, default=0\n For the liblinear and lbfgs solvers set verbose to any positive\n number for verbosity.\n\n warm_start : bool, default=False\n When set to True, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n Useless for liblinear solver. See :term:`the Glossary `.\n\n .. versionadded:: 0.17\n *warm_start* to support *lbfgs*, *newton-cg*, *sag*, *saga* solvers.\n\n n_jobs : int, default=None\n Number of CPU cores used when parallelizing over classes if\n multi_class='ovr'\". This parameter is ignored when the ``solver`` is\n set to 'liblinear' regardless of whether 'multi_class' is specified or\n not. ``None`` means 1 unless in a :obj:`joblib.parallel_backend`\n context. ``-1`` means using all processors.\n See :term:`Glossary ` for more details.\n\n l1_ratio : float, default=None\n The Elastic-Net mixing parameter, with ``0 <= l1_ratio <= 1``. Only\n used if ``penalty='elasticnet'``. Setting ``l1_ratio=0`` is equivalent\n to using ``penalty='l2'``, while setting ``l1_ratio=1`` is equivalent\n to using ``penalty='l1'``. For ``0 < l1_ratio <1``, the penalty is a\n combination of L1 and L2.\n\n Attributes\n ----------\n\n classes_ : ndarray of shape (n_classes, )\n A list of class labels known to the classifier.\n\n coef_ : ndarray of shape (1, n_features) or (n_classes, n_features)\n Coefficient of the features in the decision function.\n\n `coef_` is of shape (1, n_features) when the given problem is binary.\n In particular, when `multi_class='multinomial'`, `coef_` corresponds\n to outcome 1 (True) and `-coef_` corresponds to outcome 0 (False).\n\n intercept_ : ndarray of shape (1,) or (n_classes,)\n Intercept (a.k.a. bias) added to the decision function.\n\n If `fit_intercept` is set to False, the intercept is set to zero.\n `intercept_` is of shape (1,) when the given problem is binary.\n In particular, when `multi_class='multinomial'`, `intercept_`\n corresponds to outcome 1 (True) and `-intercept_` corresponds to\n outcome 0 (False).\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : ndarray of shape (n_classes,) or (1, )\n Actual number of iterations for all classes. If binary or multinomial,\n it returns only 1 element. For liblinear solver, only the maximum\n number of iteration across all classes is given.\n\n .. versionchanged:: 0.20\n\n In SciPy <= 1.0.0 the number of lbfgs iterations may exceed\n ``max_iter``. ``n_iter_`` will now report at most ``max_iter``.\n\n See Also\n --------\n SGDClassifier : Incrementally trained logistic regression (when given\n the parameter ``loss=\"log\"``).\n LogisticRegressionCV : Logistic regression with built-in cross validation.\n\n Notes\n -----\n The underlying C implementation uses a random number generator to\n select features when fitting the model. It is thus not uncommon,\n to have slightly different results for the same input data. If\n that happens, try with a smaller tol parameter.\n\n Predict output may not match that of standalone liblinear in certain\n cases. See :ref:`differences from liblinear `\n in the narrative documentation.\n\n References\n ----------\n\n L-BFGS-B -- Software for Large-scale Bound-constrained Optimization\n Ciyou Zhu, Richard Byrd, Jorge Nocedal and Jose Luis Morales.\n http://users.iems.northwestern.edu/~nocedal/lbfgsb.html\n\n LIBLINEAR -- A Library for Large Linear Classification\n https://www.csie.ntu.edu.tw/~cjlin/liblinear/\n\n SAG -- Mark Schmidt, Nicolas Le Roux, and Francis Bach\n Minimizing Finite Sums with the Stochastic Average Gradient\n https://hal.inria.fr/hal-00860051/document\n\n SAGA -- Defazio, A., Bach F. & Lacoste-Julien S. (2014).\n SAGA: A Fast Incremental Gradient Method With Support\n for Non-Strongly Convex Composite Objectives\n https://arxiv.org/abs/1407.0202\n\n Hsiang-Fu Yu, Fang-Lan Huang, Chih-Jen Lin (2011). Dual coordinate descent\n methods for logistic regression and maximum entropy models.\n Machine Learning 85(1-2):41-75.\n https://www.csie.ntu.edu.tw/~cjlin/papers/maxent_dual.pdf\n\n Examples\n --------\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.linear_model import LogisticRegression\n >>> X, y = load_iris(return_X_y=True)\n >>> clf = LogisticRegression(random_state=0).fit(X, y)\n >>> clf.predict(X[:2, :])\n array([0, 0])\n >>> clf.predict_proba(X[:2, :])\n array([[9.8...e-01, 1.8...e-02, 1.4...e-08],\n [9.7...e-01, 2.8...e-02, ...e-08]])\n >>> clf.score(X, y)\n 0.97...\n ", - "source_code": "\n\nclass LogisticRegression(LinearClassifierMixin, SparseCoefMixin, BaseEstimator):\n \"\"\"\n Logistic Regression (aka logit, MaxEnt) classifier.\n\n In the multiclass case, the training algorithm uses the one-vs-rest (OvR)\n scheme if the 'multi_class' option is set to 'ovr', and uses the\n cross-entropy loss if the 'multi_class' option is set to 'multinomial'.\n (Currently the 'multinomial' option is supported only by the 'lbfgs',\n 'sag', 'saga' and 'newton-cg' solvers.)\n\n This class implements regularized logistic regression using the\n 'liblinear' library, 'newton-cg', 'sag', 'saga' and 'lbfgs' solvers. **Note\n that regularization is applied by default**. It can handle both dense\n and sparse input. Use C-ordered arrays or CSR matrices containing 64-bit\n floats for optimal performance; any other input format will be converted\n (and copied).\n\n The 'newton-cg', 'sag', and 'lbfgs' solvers support only L2 regularization\n with primal formulation, or no regularization. The 'liblinear' solver\n supports both L1 and L2 regularization, with a dual formulation only for\n the L2 penalty. The Elastic-Net regularization is only supported by the\n 'saga' solver.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n penalty : {'l1', 'l2', 'elasticnet', 'none'}, default='l2'\n Specify the norm of the penalty:\n\n - `'none'`: no penalty is added;\n - `'l2'`: add a L2 penalty term and it is the default choice;\n - `'l1'`: add a L1 penalty term;\n - `'elasticnet'`: both L1 and L2 penalty terms are added.\n\n .. warning::\n Some penalties may not work with some solvers. See the parameter\n `solver` below, to know the compatibility between the penalty and\n solver.\n\n .. versionadded:: 0.19\n l1 penalty with SAGA solver (allowing 'multinomial' + L1)\n\n dual : bool, default=False\n Dual or primal formulation. Dual formulation is only implemented for\n l2 penalty with liblinear solver. Prefer dual=False when\n n_samples > n_features.\n\n tol : float, default=1e-4\n Tolerance for stopping criteria.\n\n C : float, default=1.0\n Inverse of regularization strength; must be a positive float.\n Like in support vector machines, smaller values specify stronger\n regularization.\n\n fit_intercept : bool, default=True\n Specifies if a constant (a.k.a. bias or intercept) should be\n added to the decision function.\n\n intercept_scaling : float, default=1\n Useful only when the solver 'liblinear' is used\n and self.fit_intercept is set to True. In this case, x becomes\n [x, self.intercept_scaling],\n i.e. a \"synthetic\" feature with constant value equal to\n intercept_scaling is appended to the instance vector.\n The intercept becomes ``intercept_scaling * synthetic_feature_weight``.\n\n Note! the synthetic feature weight is subject to l1/l2 regularization\n as all other features.\n To lessen the effect of regularization on synthetic feature weight\n (and therefore on the intercept) intercept_scaling has to be increased.\n\n class_weight : dict or 'balanced', default=None\n Weights associated with classes in the form ``{class_label: weight}``.\n If not given, all classes are supposed to have weight one.\n\n The \"balanced\" mode uses the values of y to automatically adjust\n weights inversely proportional to class frequencies in the input data\n as ``n_samples / (n_classes * np.bincount(y))``.\n\n Note that these weights will be multiplied with sample_weight (passed\n through the fit method) if sample_weight is specified.\n\n .. versionadded:: 0.17\n *class_weight='balanced'*\n\n random_state : int, RandomState instance, default=None\n Used when ``solver`` == 'sag', 'saga' or 'liblinear' to shuffle the\n data. See :term:`Glossary ` for details.\n\n solver : {'newton-cg', 'lbfgs', 'liblinear', 'sag', 'saga'}, default='lbfgs'\n\n Algorithm to use in the optimization problem. Default is 'lbfgs'.\n To choose a solver, you might want to consider the following aspects:\n\n - For small datasets, 'liblinear' is a good choice, whereas 'sag'\n and 'saga' are faster for large ones;\n - For multiclass problems, only 'newton-cg', 'sag', 'saga' and\n 'lbfgs' handle multinomial loss;\n - 'liblinear' is limited to one-versus-rest schemes.\n\n .. warning::\n The choice of the algorithm depends on the penalty chosen:\n Supported penalties by solver:\n\n - 'newton-cg' - ['l2', 'none']\n - 'lbfgs' - ['l2', 'none']\n - 'liblinear' - ['l1', 'l2']\n - 'sag' - ['l2', 'none']\n - 'saga' - ['elasticnet', 'l1', 'l2', 'none']\n\n .. note::\n 'sag' and 'saga' fast convergence is only guaranteed on\n features with approximately the same scale. You can\n preprocess the data with a scaler from :mod:`sklearn.preprocessing`.\n\n .. seealso::\n Refer to the User Guide for more information regarding\n :class:`LogisticRegression` and more specifically the\n `Table `_\n summarazing solver/penalty supports.\n \n\n .. versionadded:: 0.17\n Stochastic Average Gradient descent solver.\n .. versionadded:: 0.19\n SAGA solver.\n .. versionchanged:: 0.22\n The default solver changed from 'liblinear' to 'lbfgs' in 0.22.\n\n max_iter : int, default=100\n Maximum number of iterations taken for the solvers to converge.\n\n multi_class : {'auto', 'ovr', 'multinomial'}, default='auto'\n If the option chosen is 'ovr', then a binary problem is fit for each\n label. For 'multinomial' the loss minimised is the multinomial loss fit\n across the entire probability distribution, *even when the data is\n binary*. 'multinomial' is unavailable when solver='liblinear'.\n 'auto' selects 'ovr' if the data is binary, or if solver='liblinear',\n and otherwise selects 'multinomial'.\n\n .. versionadded:: 0.18\n Stochastic Average Gradient descent solver for 'multinomial' case.\n .. versionchanged:: 0.22\n Default changed from 'ovr' to 'auto' in 0.22.\n\n verbose : int, default=0\n For the liblinear and lbfgs solvers set verbose to any positive\n number for verbosity.\n\n warm_start : bool, default=False\n When set to True, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n Useless for liblinear solver. See :term:`the Glossary `.\n\n .. versionadded:: 0.17\n *warm_start* to support *lbfgs*, *newton-cg*, *sag*, *saga* solvers.\n\n n_jobs : int, default=None\n Number of CPU cores used when parallelizing over classes if\n multi_class='ovr'\". This parameter is ignored when the ``solver`` is\n set to 'liblinear' regardless of whether 'multi_class' is specified or\n not. ``None`` means 1 unless in a :obj:`joblib.parallel_backend`\n context. ``-1`` means using all processors.\n See :term:`Glossary ` for more details.\n\n l1_ratio : float, default=None\n The Elastic-Net mixing parameter, with ``0 <= l1_ratio <= 1``. Only\n used if ``penalty='elasticnet'``. Setting ``l1_ratio=0`` is equivalent\n to using ``penalty='l2'``, while setting ``l1_ratio=1`` is equivalent\n to using ``penalty='l1'``. For ``0 < l1_ratio <1``, the penalty is a\n combination of L1 and L2.\n\n Attributes\n ----------\n\n classes_ : ndarray of shape (n_classes, )\n A list of class labels known to the classifier.\n\n coef_ : ndarray of shape (1, n_features) or (n_classes, n_features)\n Coefficient of the features in the decision function.\n\n `coef_` is of shape (1, n_features) when the given problem is binary.\n In particular, when `multi_class='multinomial'`, `coef_` corresponds\n to outcome 1 (True) and `-coef_` corresponds to outcome 0 (False).\n\n intercept_ : ndarray of shape (1,) or (n_classes,)\n Intercept (a.k.a. bias) added to the decision function.\n\n If `fit_intercept` is set to False, the intercept is set to zero.\n `intercept_` is of shape (1,) when the given problem is binary.\n In particular, when `multi_class='multinomial'`, `intercept_`\n corresponds to outcome 1 (True) and `-intercept_` corresponds to\n outcome 0 (False).\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : ndarray of shape (n_classes,) or (1, )\n Actual number of iterations for all classes. If binary or multinomial,\n it returns only 1 element. For liblinear solver, only the maximum\n number of iteration across all classes is given.\n\n .. versionchanged:: 0.20\n\n In SciPy <= 1.0.0 the number of lbfgs iterations may exceed\n ``max_iter``. ``n_iter_`` will now report at most ``max_iter``.\n\n See Also\n --------\n SGDClassifier : Incrementally trained logistic regression (when given\n the parameter ``loss=\"log\"``).\n LogisticRegressionCV : Logistic regression with built-in cross validation.\n\n Notes\n -----\n The underlying C implementation uses a random number generator to\n select features when fitting the model. It is thus not uncommon,\n to have slightly different results for the same input data. If\n that happens, try with a smaller tol parameter.\n\n Predict output may not match that of standalone liblinear in certain\n cases. See :ref:`differences from liblinear `\n in the narrative documentation.\n\n References\n ----------\n\n L-BFGS-B -- Software for Large-scale Bound-constrained Optimization\n Ciyou Zhu, Richard Byrd, Jorge Nocedal and Jose Luis Morales.\n http://users.iems.northwestern.edu/~nocedal/lbfgsb.html\n\n LIBLINEAR -- A Library for Large Linear Classification\n https://www.csie.ntu.edu.tw/~cjlin/liblinear/\n\n SAG -- Mark Schmidt, Nicolas Le Roux, and Francis Bach\n Minimizing Finite Sums with the Stochastic Average Gradient\n https://hal.inria.fr/hal-00860051/document\n\n SAGA -- Defazio, A., Bach F. & Lacoste-Julien S. (2014).\n SAGA: A Fast Incremental Gradient Method With Support\n for Non-Strongly Convex Composite Objectives\n https://arxiv.org/abs/1407.0202\n\n Hsiang-Fu Yu, Fang-Lan Huang, Chih-Jen Lin (2011). Dual coordinate descent\n methods for logistic regression and maximum entropy models.\n Machine Learning 85(1-2):41-75.\n https://www.csie.ntu.edu.tw/~cjlin/papers/maxent_dual.pdf\n\n Examples\n --------\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.linear_model import LogisticRegression\n >>> X, y = load_iris(return_X_y=True)\n >>> clf = LogisticRegression(random_state=0).fit(X, y)\n >>> clf.predict(X[:2, :])\n array([0, 0])\n >>> clf.predict_proba(X[:2, :])\n array([[9.8...e-01, 1.8...e-02, 1.4...e-08],\n [9.7...e-01, 2.8...e-02, ...e-08]])\n >>> clf.score(X, y)\n 0.97...\n \"\"\"\n \n def __init__(self, penalty='l2', *, dual=False, tol=0.0001, C=1.0, fit_intercept=True, intercept_scaling=1, class_weight=None, random_state=None, solver='lbfgs', max_iter=100, multi_class='auto', verbose=0, warm_start=False, n_jobs=None, l1_ratio=None):\n self.penalty = penalty\n self.dual = dual\n self.tol = tol\n self.C = C\n self.fit_intercept = fit_intercept\n self.intercept_scaling = intercept_scaling\n self.class_weight = class_weight\n self.random_state = random_state\n self.solver = solver\n self.max_iter = max_iter\n self.multi_class = multi_class\n self.verbose = verbose\n self.warm_start = warm_start\n self.n_jobs = n_jobs\n self.l1_ratio = l1_ratio\n \n def fit(self, X, y, sample_weight=None):\n \"\"\"\n Fit the model according to the given training data.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target vector relative to X.\n\n sample_weight : array-like of shape (n_samples,) default=None\n Array of weights that are assigned to individual samples.\n If not provided, then each sample is given unit weight.\n\n .. versionadded:: 0.17\n *sample_weight* support to LogisticRegression.\n\n Returns\n -------\n self\n Fitted estimator.\n\n Notes\n -----\n The SAGA solver supports both float64 and float32 bit arrays.\n \"\"\"\n solver = _check_solver(self.solver, self.penalty, self.dual)\n if not isinstance(self.C, numbers.Number) or self.C < 0:\n raise ValueError('Penalty term must be positive; got (C=%r)' % self.C)\n if self.penalty == 'elasticnet':\n if not isinstance(self.l1_ratio, numbers.Number) or self.l1_ratio < 0 or self.l1_ratio > 1:\n raise ValueError('l1_ratio must be between 0 and 1; got (l1_ratio=%r)' % self.l1_ratio)\n elif self.l1_ratio is not None:\n warnings.warn(\"l1_ratio parameter is only used when penalty is 'elasticnet'. Got (penalty={})\".format(self.penalty))\n if self.penalty == 'none':\n if self.C != 1.0:\n warnings.warn(\"Setting penalty='none' will ignore the C and l1_ratio parameters\")\n C_ = np.inf\n penalty = 'l2'\n else:\n C_ = self.C\n penalty = self.penalty\n if not isinstance(self.max_iter, numbers.Number) or self.max_iter < 0:\n raise ValueError('Maximum number of iteration must be positive; got (max_iter=%r)' % self.max_iter)\n if not isinstance(self.tol, numbers.Number) or self.tol < 0:\n raise ValueError('Tolerance for stopping criteria must be positive; got (tol=%r)' % self.tol)\n if solver == 'lbfgs':\n _dtype = np.float64\n else:\n _dtype = [np.float64, np.float32]\n (X, y) = self._validate_data(X, y, accept_sparse='csr', dtype=_dtype, order='C', accept_large_sparse=solver != 'liblinear')\n check_classification_targets(y)\n self.classes_ = np.unique(y)\n multi_class = _check_multi_class(self.multi_class, solver, len(self.classes_))\n if solver == 'liblinear':\n if effective_n_jobs(self.n_jobs) != 1:\n warnings.warn(\"'n_jobs' > 1 does not have any effect when 'solver' is set to 'liblinear'. Got 'n_jobs' = {}.\".format(effective_n_jobs(self.n_jobs)))\n (self.coef_, self.intercept_, n_iter_) = _fit_liblinear(X, y, self.C, self.fit_intercept, self.intercept_scaling, self.class_weight, self.penalty, self.dual, self.verbose, self.max_iter, self.tol, self.random_state, sample_weight=sample_weight)\n self.n_iter_ = np.array([n_iter_])\n return self\n if solver in ['sag', 'saga']:\n max_squared_sum = row_norms(X, squared=True).max()\n else:\n max_squared_sum = None\n n_classes = len(self.classes_)\n classes_ = self.classes_\n if n_classes < 2:\n raise ValueError('This solver needs samples of at least 2 classes in the data, but the data contains only one class: %r' % classes_[0])\n if len(self.classes_) == 2:\n n_classes = 1\n classes_ = classes_[1:]\n if self.warm_start:\n warm_start_coef = getattr(self, 'coef_', None)\n else:\n warm_start_coef = None\n if warm_start_coef is not None and self.fit_intercept:\n warm_start_coef = np.append(warm_start_coef, self.intercept_[:, np.newaxis], axis=1)\n if multi_class == 'multinomial':\n classes_ = [None]\n warm_start_coef = [warm_start_coef]\n if warm_start_coef is None:\n warm_start_coef = [None] * n_classes\n path_func = delayed(_logistic_regression_path)\n if solver in ['sag', 'saga']:\n prefer = 'threads'\n else:\n prefer = 'processes'\n fold_coefs_ = Parallel(n_jobs=self.n_jobs, verbose=self.verbose, **_joblib_parallel_args(prefer=prefer))((path_func(X, y, pos_class=class_, Cs=[C_], l1_ratio=self.l1_ratio, fit_intercept=self.fit_intercept, tol=self.tol, verbose=self.verbose, solver=solver, multi_class=multi_class, max_iter=self.max_iter, class_weight=self.class_weight, check_input=False, random_state=self.random_state, coef=warm_start_coef_, penalty=penalty, max_squared_sum=max_squared_sum, sample_weight=sample_weight) for (class_, warm_start_coef_) in zip(classes_, warm_start_coef)))\n (fold_coefs_, _, n_iter_) = zip(*fold_coefs_)\n self.n_iter_ = np.asarray(n_iter_, dtype=np.int32)[:, 0]\n n_features = X.shape[1]\n if multi_class == 'multinomial':\n self.coef_ = fold_coefs_[0][0]\n else:\n self.coef_ = np.asarray(fold_coefs_)\n self.coef_ = self.coef_.reshape(n_classes, n_features + int(self.fit_intercept))\n if self.fit_intercept:\n self.intercept_ = self.coef_[:, -1]\n self.coef_ = self.coef_[:, :-1]\n else:\n self.intercept_ = np.zeros(n_classes)\n return self\n \n def predict_proba(self, X):\n \"\"\"\n Probability estimates.\n\n The returned estimates for all classes are ordered by the\n label of classes.\n\n For a multi_class problem, if multi_class is set to be \"multinomial\"\n the softmax function is used to find the predicted probability of\n each class.\n Else use a one-vs-rest approach, i.e calculate the probability\n of each class assuming it to be positive using the logistic function.\n and normalize these values across all the classes.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Vector to be scored, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n Returns\n -------\n T : array-like of shape (n_samples, n_classes)\n Returns the probability of the sample for each class in the model,\n where classes are ordered as they are in ``self.classes_``.\n \"\"\"\n check_is_fitted(self)\n ovr = self.multi_class in ['ovr', 'warn'] or self.multi_class == 'auto' and (self.classes_.size <= 2 or self.solver == 'liblinear')\n if ovr:\n return super()._predict_proba_lr(X)\n else:\n decision = self.decision_function(X)\n if decision.ndim == 1:\n decision_2d = np.c_[-decision, decision]\n else:\n decision_2d = decision\n return softmax(decision_2d, copy=False)\n \n def predict_log_proba(self, X):\n \"\"\"\n Predict logarithm of probability estimates.\n\n The returned estimates for all classes are ordered by the\n label of classes.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Vector to be scored, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n Returns\n -------\n T : array-like of shape (n_samples, n_classes)\n Returns the log-probability of the sample for each class in the\n model, where classes are ordered as they are in ``self.classes_``.\n \"\"\"\n return np.log(self.predict_proba(X))\n" + "source_code": "\n\nclass LogisticRegression(LinearClassifierMixin, SparseCoefMixin, BaseEstimator):\n \"\"\"\n Logistic Regression (aka logit, MaxEnt) classifier.\n\n In the multiclass case, the training algorithm uses the one-vs-rest (OvR)\n scheme if the 'multi_class' option is set to 'ovr', and uses the\n cross-entropy loss if the 'multi_class' option is set to 'multinomial'.\n (Currently the 'multinomial' option is supported only by the 'lbfgs',\n 'sag', 'saga' and 'newton-cg' solvers.)\n\n This class implements regularized logistic regression using the\n 'liblinear' library, 'newton-cg', 'sag', 'saga' and 'lbfgs' solvers. **Note\n that regularization is applied by default**. It can handle both dense\n and sparse input. Use C-ordered arrays or CSR matrices containing 64-bit\n floats for optimal performance; any other input format will be converted\n (and copied).\n\n The 'newton-cg', 'sag', and 'lbfgs' solvers support only L2 regularization\n with primal formulation, or no regularization. The 'liblinear' solver\n supports both L1 and L2 regularization, with a dual formulation only for\n the L2 penalty. The Elastic-Net regularization is only supported by the\n 'saga' solver.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n penalty : {'l1', 'l2', 'elasticnet', 'none'}, default='l2'\n Specify the norm of the penalty:\n\n - `'none'`: no penalty is added;\n - `'l2'`: add a L2 penalty term and it is the default choice;\n - `'l1'`: add a L1 penalty term;\n - `'elasticnet'`: both L1 and L2 penalty terms are added.\n\n .. warning::\n Some penalties may not work with some solvers. See the parameter\n `solver` below, to know the compatibility between the penalty and\n solver.\n\n .. versionadded:: 0.19\n l1 penalty with SAGA solver (allowing 'multinomial' + L1)\n\n dual : bool, default=False\n Dual or primal formulation. Dual formulation is only implemented for\n l2 penalty with liblinear solver. Prefer dual=False when\n n_samples > n_features.\n\n tol : float, default=1e-4\n Tolerance for stopping criteria.\n\n C : float, default=1.0\n Inverse of regularization strength; must be a positive float.\n Like in support vector machines, smaller values specify stronger\n regularization.\n\n fit_intercept : bool, default=True\n Specifies if a constant (a.k.a. bias or intercept) should be\n added to the decision function.\n\n intercept_scaling : float, default=1\n Useful only when the solver 'liblinear' is used\n and self.fit_intercept is set to True. In this case, x becomes\n [x, self.intercept_scaling],\n i.e. a \"synthetic\" feature with constant value equal to\n intercept_scaling is appended to the instance vector.\n The intercept becomes ``intercept_scaling * synthetic_feature_weight``.\n\n Note! the synthetic feature weight is subject to l1/l2 regularization\n as all other features.\n To lessen the effect of regularization on synthetic feature weight\n (and therefore on the intercept) intercept_scaling has to be increased.\n\n class_weight : dict or 'balanced', default=None\n Weights associated with classes in the form ``{class_label: weight}``.\n If not given, all classes are supposed to have weight one.\n\n The \"balanced\" mode uses the values of y to automatically adjust\n weights inversely proportional to class frequencies in the input data\n as ``n_samples / (n_classes * np.bincount(y))``.\n\n Note that these weights will be multiplied with sample_weight (passed\n through the fit method) if sample_weight is specified.\n\n .. versionadded:: 0.17\n *class_weight='balanced'*\n\n random_state : int, RandomState instance, default=None\n Used when ``solver`` == 'sag', 'saga' or 'liblinear' to shuffle the\n data. See :term:`Glossary ` for details.\n\n solver : {'newton-cg', 'lbfgs', 'liblinear', 'sag', 'saga'}, default='lbfgs'\n\n Algorithm to use in the optimization problem. Default is 'lbfgs'.\n To choose a solver, you might want to consider the following aspects:\n\n - For small datasets, 'liblinear' is a good choice, whereas 'sag'\n and 'saga' are faster for large ones;\n - For multiclass problems, only 'newton-cg', 'sag', 'saga' and\n 'lbfgs' handle multinomial loss;\n - 'liblinear' is limited to one-versus-rest schemes.\n\n .. warning::\n The choice of the algorithm depends on the penalty chosen:\n Supported penalties by solver:\n\n - 'newton-cg' - ['l2', 'none']\n - 'lbfgs' - ['l2', 'none']\n - 'liblinear' - ['l1', 'l2']\n - 'sag' - ['l2', 'none']\n - 'saga' - ['elasticnet', 'l1', 'l2', 'none']\n\n .. note::\n 'sag' and 'saga' fast convergence is only guaranteed on\n features with approximately the same scale. You can\n preprocess the data with a scaler from :mod:`sklearn.preprocessing`.\n\n .. seealso::\n Refer to the User Guide for more information regarding\n :class:`LogisticRegression` and more specifically the\n `Table `_\n summarazing solver/penalty supports.\n \n\n .. versionadded:: 0.17\n Stochastic Average Gradient descent solver.\n .. versionadded:: 0.19\n SAGA solver.\n .. versionchanged:: 0.22\n The default solver changed from 'liblinear' to 'lbfgs' in 0.22.\n\n max_iter : int, default=100\n Maximum number of iterations taken for the solvers to converge.\n\n multi_class : {'auto', 'ovr', 'multinomial'}, default='auto'\n If the option chosen is 'ovr', then a binary problem is fit for each\n label. For 'multinomial' the loss minimised is the multinomial loss fit\n across the entire probability distribution, *even when the data is\n binary*. 'multinomial' is unavailable when solver='liblinear'.\n 'auto' selects 'ovr' if the data is binary, or if solver='liblinear',\n and otherwise selects 'multinomial'.\n\n .. versionadded:: 0.18\n Stochastic Average Gradient descent solver for 'multinomial' case.\n .. versionchanged:: 0.22\n Default changed from 'ovr' to 'auto' in 0.22.\n\n verbose : int, default=0\n For the liblinear and lbfgs solvers set verbose to any positive\n number for verbosity.\n\n warm_start : bool, default=False\n When set to True, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n Useless for liblinear solver. See :term:`the Glossary `.\n\n .. versionadded:: 0.17\n *warm_start* to support *lbfgs*, *newton-cg*, *sag*, *saga* solvers.\n\n n_jobs : int, default=None\n Number of CPU cores used when parallelizing over classes if\n multi_class='ovr'\". This parameter is ignored when the ``solver`` is\n set to 'liblinear' regardless of whether 'multi_class' is specified or\n not. ``None`` means 1 unless in a :obj:`joblib.parallel_backend`\n context. ``-1`` means using all processors.\n See :term:`Glossary ` for more details.\n\n l1_ratio : float, default=None\n The Elastic-Net mixing parameter, with ``0 <= l1_ratio <= 1``. Only\n used if ``penalty='elasticnet'``. Setting ``l1_ratio=0`` is equivalent\n to using ``penalty='l2'``, while setting ``l1_ratio=1`` is equivalent\n to using ``penalty='l1'``. For ``0 < l1_ratio <1``, the penalty is a\n combination of L1 and L2.\n\n Attributes\n ----------\n\n classes_ : ndarray of shape (n_classes, )\n A list of class labels known to the classifier.\n\n coef_ : ndarray of shape (1, n_features) or (n_classes, n_features)\n Coefficient of the features in the decision function.\n\n `coef_` is of shape (1, n_features) when the given problem is binary.\n In particular, when `multi_class='multinomial'`, `coef_` corresponds\n to outcome 1 (True) and `-coef_` corresponds to outcome 0 (False).\n\n intercept_ : ndarray of shape (1,) or (n_classes,)\n Intercept (a.k.a. bias) added to the decision function.\n\n If `fit_intercept` is set to False, the intercept is set to zero.\n `intercept_` is of shape (1,) when the given problem is binary.\n In particular, when `multi_class='multinomial'`, `intercept_`\n corresponds to outcome 1 (True) and `-intercept_` corresponds to\n outcome 0 (False).\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : ndarray of shape (n_classes,) or (1, )\n Actual number of iterations for all classes. If binary or multinomial,\n it returns only 1 element. For liblinear solver, only the maximum\n number of iteration across all classes is given.\n\n .. versionchanged:: 0.20\n\n In SciPy <= 1.0.0 the number of lbfgs iterations may exceed\n ``max_iter``. ``n_iter_`` will now report at most ``max_iter``.\n\n See Also\n --------\n SGDClassifier : Incrementally trained logistic regression (when given\n the parameter ``loss=\"log\"``).\n LogisticRegressionCV : Logistic regression with built-in cross validation.\n\n Notes\n -----\n The underlying C implementation uses a random number generator to\n select features when fitting the model. It is thus not uncommon,\n to have slightly different results for the same input data. If\n that happens, try with a smaller tol parameter.\n\n Predict output may not match that of standalone liblinear in certain\n cases. See :ref:`differences from liblinear `\n in the narrative documentation.\n\n References\n ----------\n\n L-BFGS-B -- Software for Large-scale Bound-constrained Optimization\n Ciyou Zhu, Richard Byrd, Jorge Nocedal and Jose Luis Morales.\n http://users.iems.northwestern.edu/~nocedal/lbfgsb.html\n\n LIBLINEAR -- A Library for Large Linear Classification\n https://www.csie.ntu.edu.tw/~cjlin/liblinear/\n\n SAG -- Mark Schmidt, Nicolas Le Roux, and Francis Bach\n Minimizing Finite Sums with the Stochastic Average Gradient\n https://hal.inria.fr/hal-00860051/document\n\n SAGA -- Defazio, A., Bach F. & Lacoste-Julien S. (2014).\n SAGA: A Fast Incremental Gradient Method With Support\n for Non-Strongly Convex Composite Objectives\n https://arxiv.org/abs/1407.0202\n\n Hsiang-Fu Yu, Fang-Lan Huang, Chih-Jen Lin (2011). Dual coordinate descent\n methods for logistic regression and maximum entropy models.\n Machine Learning 85(1-2):41-75.\n https://www.csie.ntu.edu.tw/~cjlin/papers/maxent_dual.pdf\n\n Examples\n --------\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.linear_model import LogisticRegression\n >>> X, y = load_iris(return_X_y=True)\n >>> clf = LogisticRegression(random_state=0).fit(X, y)\n >>> clf.predict(X[:2, :])\n array([0, 0])\n >>> clf.predict_proba(X[:2, :])\n array([[9.8...e-01, 1.8...e-02, 1.4...e-08],\n [9.7...e-01, 2.8...e-02, ...e-08]])\n >>> clf.score(X, y)\n 0.97...\n \"\"\"\n \n def __init__(self, penalty='l2', *, dual=False, tol=0.0001, C=1.0, fit_intercept=True, intercept_scaling=1, class_weight=None, random_state=None, solver='lbfgs', max_iter=100, multi_class='auto', verbose=0, warm_start=False, n_jobs=None, l1_ratio=None):\n self.penalty = penalty\n self.dual = dual\n self.tol = tol\n self.C = C\n self.fit_intercept = fit_intercept\n self.intercept_scaling = intercept_scaling\n self.class_weight = class_weight\n self.random_state = random_state\n self.solver = solver\n self.max_iter = max_iter\n self.multi_class = multi_class\n self.verbose = verbose\n self.warm_start = warm_start\n self.n_jobs = n_jobs\n self.l1_ratio = l1_ratio\n \n def fit(self, X, y, sample_weight=None):\n \"\"\"\n Fit the model according to the given training data.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target vector relative to X.\n\n sample_weight : array-like of shape (n_samples,) default=None\n Array of weights that are assigned to individual samples.\n If not provided, then each sample is given unit weight.\n\n .. versionadded:: 0.17\n *sample_weight* support to LogisticRegression.\n\n Returns\n -------\n self\n Fitted estimator.\n\n Notes\n -----\n The SAGA solver supports both float64 and float32 bit arrays.\n \"\"\"\n solver = _check_solver(self.solver, self.penalty, self.dual)\n if not isinstance(self.C, numbers.Number) or self.C < 0:\n raise ValueError('Penalty term must be positive; got (C=%r)' % self.C)\n if self.penalty == 'elasticnet':\n if not isinstance(self.l1_ratio, numbers.Number) or self.l1_ratio < 0 or self.l1_ratio > 1:\n raise ValueError('l1_ratio must be between 0 and 1; got (l1_ratio=%r)' % self.l1_ratio)\n elif self.l1_ratio is not None:\n warnings.warn(\"l1_ratio parameter is only used when penalty is 'elasticnet'. Got (penalty={})\".format(self.penalty))\n if self.penalty == 'none':\n if self.C != 1.0:\n warnings.warn(\"Setting penalty='none' will ignore the C and l1_ratio parameters\")\n C_ = np.inf\n penalty = 'l2'\n else:\n C_ = self.C\n penalty = self.penalty\n if not isinstance(self.max_iter, numbers.Number) or self.max_iter < 0:\n raise ValueError('Maximum number of iteration must be positive; got (max_iter=%r)' % self.max_iter)\n if not isinstance(self.tol, numbers.Number) or self.tol < 0:\n raise ValueError('Tolerance for stopping criteria must be positive; got (tol=%r)' % self.tol)\n if solver == 'lbfgs':\n _dtype = np.float64\n else:\n _dtype = [np.float64, np.float32]\n (X, y) = self._validate_data(X, y, accept_sparse='csr', dtype=_dtype, order='C', accept_large_sparse=solver not in ['liblinear', 'sag', 'saga'])\n check_classification_targets(y)\n self.classes_ = np.unique(y)\n multi_class = _check_multi_class(self.multi_class, solver, len(self.classes_))\n if solver == 'liblinear':\n if effective_n_jobs(self.n_jobs) != 1:\n warnings.warn(\"'n_jobs' > 1 does not have any effect when 'solver' is set to 'liblinear'. Got 'n_jobs' = {}.\".format(effective_n_jobs(self.n_jobs)))\n (self.coef_, self.intercept_, n_iter_) = _fit_liblinear(X, y, self.C, self.fit_intercept, self.intercept_scaling, self.class_weight, self.penalty, self.dual, self.verbose, self.max_iter, self.tol, self.random_state, sample_weight=sample_weight)\n self.n_iter_ = np.array([n_iter_])\n return self\n if solver in ['sag', 'saga']:\n max_squared_sum = row_norms(X, squared=True).max()\n else:\n max_squared_sum = None\n n_classes = len(self.classes_)\n classes_ = self.classes_\n if n_classes < 2:\n raise ValueError('This solver needs samples of at least 2 classes in the data, but the data contains only one class: %r' % classes_[0])\n if len(self.classes_) == 2:\n n_classes = 1\n classes_ = classes_[1:]\n if self.warm_start:\n warm_start_coef = getattr(self, 'coef_', None)\n else:\n warm_start_coef = None\n if warm_start_coef is not None and self.fit_intercept:\n warm_start_coef = np.append(warm_start_coef, self.intercept_[:, np.newaxis], axis=1)\n if multi_class == 'multinomial':\n classes_ = [None]\n warm_start_coef = [warm_start_coef]\n if warm_start_coef is None:\n warm_start_coef = [None] * n_classes\n path_func = delayed(_logistic_regression_path)\n if solver in ['sag', 'saga']:\n prefer = 'threads'\n else:\n prefer = 'processes'\n fold_coefs_ = Parallel(n_jobs=self.n_jobs, verbose=self.verbose, **_joblib_parallel_args(prefer=prefer))((path_func(X, y, pos_class=class_, Cs=[C_], l1_ratio=self.l1_ratio, fit_intercept=self.fit_intercept, tol=self.tol, verbose=self.verbose, solver=solver, multi_class=multi_class, max_iter=self.max_iter, class_weight=self.class_weight, check_input=False, random_state=self.random_state, coef=warm_start_coef_, penalty=penalty, max_squared_sum=max_squared_sum, sample_weight=sample_weight) for (class_, warm_start_coef_) in zip(classes_, warm_start_coef)))\n (fold_coefs_, _, n_iter_) = zip(*fold_coefs_)\n self.n_iter_ = np.asarray(n_iter_, dtype=np.int32)[:, 0]\n n_features = X.shape[1]\n if multi_class == 'multinomial':\n self.coef_ = fold_coefs_[0][0]\n else:\n self.coef_ = np.asarray(fold_coefs_)\n self.coef_ = self.coef_.reshape(n_classes, n_features + int(self.fit_intercept))\n if self.fit_intercept:\n self.intercept_ = self.coef_[:, -1]\n self.coef_ = self.coef_[:, :-1]\n else:\n self.intercept_ = np.zeros(n_classes)\n return self\n \n def predict_proba(self, X):\n \"\"\"\n Probability estimates.\n\n The returned estimates for all classes are ordered by the\n label of classes.\n\n For a multi_class problem, if multi_class is set to be \"multinomial\"\n the softmax function is used to find the predicted probability of\n each class.\n Else use a one-vs-rest approach, i.e calculate the probability\n of each class assuming it to be positive using the logistic function.\n and normalize these values across all the classes.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Vector to be scored, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n Returns\n -------\n T : array-like of shape (n_samples, n_classes)\n Returns the probability of the sample for each class in the model,\n where classes are ordered as they are in ``self.classes_``.\n \"\"\"\n check_is_fitted(self)\n ovr = self.multi_class in ['ovr', 'warn'] or self.multi_class == 'auto' and (self.classes_.size <= 2 or self.solver == 'liblinear')\n if ovr:\n return super()._predict_proba_lr(X)\n else:\n decision = self.decision_function(X)\n if decision.ndim == 1:\n decision_2d = np.c_[-decision, decision]\n else:\n decision_2d = decision\n return softmax(decision_2d, copy=False)\n \n def predict_log_proba(self, X):\n \"\"\"\n Predict logarithm of probability estimates.\n\n The returned estimates for all classes are ordered by the\n label of classes.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Vector to be scored, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n Returns\n -------\n T : array-like of shape (n_samples, n_classes)\n Returns the log-probability of the sample for each class in the\n model, where classes are ordered as they are in ``self.classes_``.\n \"\"\"\n return np.log(self.predict_proba(X))\n" }, { "name": "LogisticRegressionCV", @@ -23841,7 +23794,7 @@ "is_public": true, "description": "Logistic Regression CV (aka logit, MaxEnt) classifier.\n\nSee glossary entry for :term:`cross-validation estimator`. This class implements logistic regression using liblinear, newton-cg, sag of lbfgs optimizer. The newton-cg, sag and lbfgs solvers support only L2 regularization with primal formulation. The liblinear solver supports both L1 and L2 regularization, with a dual formulation only for the L2 penalty. Elastic-Net penalty is only supported by the saga solver. For the grid of `Cs` values and `l1_ratios` values, the best hyperparameter is selected by the cross-validator :class:`~sklearn.model_selection.StratifiedKFold`, but it can be changed using the :term:`cv` parameter. The 'newton-cg', 'sag', 'saga' and 'lbfgs' solvers can warm-start the coefficients (see :term:`Glossary`). Read more in the :ref:`User Guide `.", "docstring": "Logistic Regression CV (aka logit, MaxEnt) classifier.\n\n See glossary entry for :term:`cross-validation estimator`.\n\n This class implements logistic regression using liblinear, newton-cg, sag\n of lbfgs optimizer. The newton-cg, sag and lbfgs solvers support only L2\n regularization with primal formulation. The liblinear solver supports both\n L1 and L2 regularization, with a dual formulation only for the L2 penalty.\n Elastic-Net penalty is only supported by the saga solver.\n\n For the grid of `Cs` values and `l1_ratios` values, the best hyperparameter\n is selected by the cross-validator\n :class:`~sklearn.model_selection.StratifiedKFold`, but it can be changed\n using the :term:`cv` parameter. The 'newton-cg', 'sag', 'saga' and 'lbfgs'\n solvers can warm-start the coefficients (see :term:`Glossary`).\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n Cs : int or list of floats, default=10\n Each of the values in Cs describes the inverse of regularization\n strength. If Cs is as an int, then a grid of Cs values are chosen\n in a logarithmic scale between 1e-4 and 1e4.\n Like in support vector machines, smaller values specify stronger\n regularization.\n\n fit_intercept : bool, default=True\n Specifies if a constant (a.k.a. bias or intercept) should be\n added to the decision function.\n\n cv : int or cross-validation generator, default=None\n The default cross-validation generator used is Stratified K-Folds.\n If an integer is provided, then it is the number of folds used.\n See the module :mod:`sklearn.model_selection` module for the\n list of possible cross-validation objects.\n\n .. versionchanged:: 0.22\n ``cv`` default value if None changed from 3-fold to 5-fold.\n\n dual : bool, default=False\n Dual or primal formulation. Dual formulation is only implemented for\n l2 penalty with liblinear solver. Prefer dual=False when\n n_samples > n_features.\n\n penalty : {'l1', 'l2', 'elasticnet'}, default='l2'\n Specify the norm of the penalty:\n\n - `'l2'`: add a L2 penalty term (used by default);\n - `'l1'`: add a L1 penalty term;\n - `'elasticnet'`: both L1 and L2 penalty terms are added.\n\n .. warning::\n Some penalties may not work with some solvers. See the parameter\n `solver` below, to know the compatibility between the penalty and\n solver.\n\n scoring : str or callable, default=None\n A string (see model evaluation documentation) or\n a scorer callable object / function with signature\n ``scorer(estimator, X, y)``. For a list of scoring functions\n that can be used, look at :mod:`sklearn.metrics`. The\n default scoring option used is 'accuracy'.\n\n solver : {'newton-cg', 'lbfgs', 'liblinear', 'sag', 'saga'}, default='lbfgs'\n\n Algorithm to use in the optimization problem. Default is 'lbfgs'.\n To choose a solver, you might want to consider the following aspects:\n\n - For small datasets, 'liblinear' is a good choice, whereas 'sag'\n and 'saga' are faster for large ones;\n - For multiclass problems, only 'newton-cg', 'sag', 'saga' and\n 'lbfgs' handle multinomial loss;\n - 'liblinear' might be slower in :class:`LogisticRegressionCV`\n because it does not handle warm-starting. 'liblinear' is\n limited to one-versus-rest schemes.\n\n .. warning::\n The choice of the algorithm depends on the penalty chosen:\n\n - 'newton-cg' - ['l2']\n - 'lbfgs' - ['l2']\n - 'liblinear' - ['l1', 'l2']\n - 'sag' - ['l2']\n - 'saga' - ['elasticnet', 'l1', 'l2']\n\n .. note::\n 'sag' and 'saga' fast convergence is only guaranteed on features\n with approximately the same scale. You can preprocess the data with\n a scaler from :mod:`sklearn.preprocessing`.\n\n .. versionadded:: 0.17\n Stochastic Average Gradient descent solver.\n .. versionadded:: 0.19\n SAGA solver.\n\n tol : float, default=1e-4\n Tolerance for stopping criteria.\n\n max_iter : int, default=100\n Maximum number of iterations of the optimization algorithm.\n\n class_weight : dict or 'balanced', default=None\n Weights associated with classes in the form ``{class_label: weight}``.\n If not given, all classes are supposed to have weight one.\n\n The \"balanced\" mode uses the values of y to automatically adjust\n weights inversely proportional to class frequencies in the input data\n as ``n_samples / (n_classes * np.bincount(y))``.\n\n Note that these weights will be multiplied with sample_weight (passed\n through the fit method) if sample_weight is specified.\n\n .. versionadded:: 0.17\n class_weight == 'balanced'\n\n n_jobs : int, default=None\n Number of CPU cores used during the cross-validation loop.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n verbose : int, default=0\n For the 'liblinear', 'sag' and 'lbfgs' solvers set verbose to any\n positive number for verbosity.\n\n refit : bool, default=True\n If set to True, the scores are averaged across all folds, and the\n coefs and the C that corresponds to the best score is taken, and a\n final refit is done using these parameters.\n Otherwise the coefs, intercepts and C that correspond to the\n best scores across folds are averaged.\n\n intercept_scaling : float, default=1\n Useful only when the solver 'liblinear' is used\n and self.fit_intercept is set to True. In this case, x becomes\n [x, self.intercept_scaling],\n i.e. a \"synthetic\" feature with constant value equal to\n intercept_scaling is appended to the instance vector.\n The intercept becomes ``intercept_scaling * synthetic_feature_weight``.\n\n Note! the synthetic feature weight is subject to l1/l2 regularization\n as all other features.\n To lessen the effect of regularization on synthetic feature weight\n (and therefore on the intercept) intercept_scaling has to be increased.\n\n multi_class : {'auto, 'ovr', 'multinomial'}, default='auto'\n If the option chosen is 'ovr', then a binary problem is fit for each\n label. For 'multinomial' the loss minimised is the multinomial loss fit\n across the entire probability distribution, *even when the data is\n binary*. 'multinomial' is unavailable when solver='liblinear'.\n 'auto' selects 'ovr' if the data is binary, or if solver='liblinear',\n and otherwise selects 'multinomial'.\n\n .. versionadded:: 0.18\n Stochastic Average Gradient descent solver for 'multinomial' case.\n .. versionchanged:: 0.22\n Default changed from 'ovr' to 'auto' in 0.22.\n\n random_state : int, RandomState instance, default=None\n Used when `solver='sag'`, 'saga' or 'liblinear' to shuffle the data.\n Note that this only applies to the solver and not the cross-validation\n generator. See :term:`Glossary ` for details.\n\n l1_ratios : list of float, default=None\n The list of Elastic-Net mixing parameter, with ``0 <= l1_ratio <= 1``.\n Only used if ``penalty='elasticnet'``. A value of 0 is equivalent to\n using ``penalty='l2'``, while 1 is equivalent to using\n ``penalty='l1'``. For ``0 < l1_ratio <1``, the penalty is a combination\n of L1 and L2.\n\n Attributes\n ----------\n classes_ : ndarray of shape (n_classes, )\n A list of class labels known to the classifier.\n\n coef_ : ndarray of shape (1, n_features) or (n_classes, n_features)\n Coefficient of the features in the decision function.\n\n `coef_` is of shape (1, n_features) when the given problem\n is binary.\n\n intercept_ : ndarray of shape (1,) or (n_classes,)\n Intercept (a.k.a. bias) added to the decision function.\n\n If `fit_intercept` is set to False, the intercept is set to zero.\n `intercept_` is of shape(1,) when the problem is binary.\n\n Cs_ : ndarray of shape (n_cs)\n Array of C i.e. inverse of regularization parameter values used\n for cross-validation.\n\n l1_ratios_ : ndarray of shape (n_l1_ratios)\n Array of l1_ratios used for cross-validation. If no l1_ratio is used\n (i.e. penalty is not 'elasticnet'), this is set to ``[None]``\n\n coefs_paths_ : ndarray of shape (n_folds, n_cs, n_features) or (n_folds, n_cs, n_features + 1)\n dict with classes as the keys, and the path of coefficients obtained\n during cross-validating across each fold and then across each Cs\n after doing an OvR for the corresponding class as values.\n If the 'multi_class' option is set to 'multinomial', then\n the coefs_paths are the coefficients corresponding to each class.\n Each dict value has shape ``(n_folds, n_cs, n_features)`` or\n ``(n_folds, n_cs, n_features + 1)`` depending on whether the\n intercept is fit or not. If ``penalty='elasticnet'``, the shape is\n ``(n_folds, n_cs, n_l1_ratios_, n_features)`` or\n ``(n_folds, n_cs, n_l1_ratios_, n_features + 1)``.\n\n scores_ : dict\n dict with classes as the keys, and the values as the\n grid of scores obtained during cross-validating each fold, after doing\n an OvR for the corresponding class. If the 'multi_class' option\n given is 'multinomial' then the same scores are repeated across\n all classes, since this is the multinomial class. Each dict value\n has shape ``(n_folds, n_cs`` or ``(n_folds, n_cs, n_l1_ratios)`` if\n ``penalty='elasticnet'``.\n\n C_ : ndarray of shape (n_classes,) or (n_classes - 1,)\n Array of C that maps to the best scores across every class. If refit is\n set to False, then for each class, the best C is the average of the\n C's that correspond to the best scores for each fold.\n `C_` is of shape(n_classes,) when the problem is binary.\n\n l1_ratio_ : ndarray of shape (n_classes,) or (n_classes - 1,)\n Array of l1_ratio that maps to the best scores across every class. If\n refit is set to False, then for each class, the best l1_ratio is the\n average of the l1_ratio's that correspond to the best scores for each\n fold. `l1_ratio_` is of shape(n_classes,) when the problem is binary.\n\n n_iter_ : ndarray of shape (n_classes, n_folds, n_cs) or (1, n_folds, n_cs)\n Actual number of iterations for all classes, folds and Cs.\n In the binary or multinomial cases, the first dimension is equal to 1.\n If ``penalty='elasticnet'``, the shape is ``(n_classes, n_folds,\n n_cs, n_l1_ratios)`` or ``(1, n_folds, n_cs, n_l1_ratios)``.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n LogisticRegression : Logistic regression without tuning the\n hyperparameter `C`.\n\n Examples\n --------\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.linear_model import LogisticRegressionCV\n >>> X, y = load_iris(return_X_y=True)\n >>> clf = LogisticRegressionCV(cv=5, random_state=0).fit(X, y)\n >>> clf.predict(X[:2, :])\n array([0, 0])\n >>> clf.predict_proba(X[:2, :]).shape\n (2, 3)\n >>> clf.score(X, y)\n 0.98...\n ", - "source_code": "\n\nclass LogisticRegressionCV(LogisticRegression, LinearClassifierMixin, BaseEstimator):\n \"\"\"Logistic Regression CV (aka logit, MaxEnt) classifier.\n\n See glossary entry for :term:`cross-validation estimator`.\n\n This class implements logistic regression using liblinear, newton-cg, sag\n of lbfgs optimizer. The newton-cg, sag and lbfgs solvers support only L2\n regularization with primal formulation. The liblinear solver supports both\n L1 and L2 regularization, with a dual formulation only for the L2 penalty.\n Elastic-Net penalty is only supported by the saga solver.\n\n For the grid of `Cs` values and `l1_ratios` values, the best hyperparameter\n is selected by the cross-validator\n :class:`~sklearn.model_selection.StratifiedKFold`, but it can be changed\n using the :term:`cv` parameter. The 'newton-cg', 'sag', 'saga' and 'lbfgs'\n solvers can warm-start the coefficients (see :term:`Glossary`).\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n Cs : int or list of floats, default=10\n Each of the values in Cs describes the inverse of regularization\n strength. If Cs is as an int, then a grid of Cs values are chosen\n in a logarithmic scale between 1e-4 and 1e4.\n Like in support vector machines, smaller values specify stronger\n regularization.\n\n fit_intercept : bool, default=True\n Specifies if a constant (a.k.a. bias or intercept) should be\n added to the decision function.\n\n cv : int or cross-validation generator, default=None\n The default cross-validation generator used is Stratified K-Folds.\n If an integer is provided, then it is the number of folds used.\n See the module :mod:`sklearn.model_selection` module for the\n list of possible cross-validation objects.\n\n .. versionchanged:: 0.22\n ``cv`` default value if None changed from 3-fold to 5-fold.\n\n dual : bool, default=False\n Dual or primal formulation. Dual formulation is only implemented for\n l2 penalty with liblinear solver. Prefer dual=False when\n n_samples > n_features.\n\n penalty : {'l1', 'l2', 'elasticnet'}, default='l2'\n Specify the norm of the penalty:\n\n - `'l2'`: add a L2 penalty term (used by default);\n - `'l1'`: add a L1 penalty term;\n - `'elasticnet'`: both L1 and L2 penalty terms are added.\n\n .. warning::\n Some penalties may not work with some solvers. See the parameter\n `solver` below, to know the compatibility between the penalty and\n solver.\n\n scoring : str or callable, default=None\n A string (see model evaluation documentation) or\n a scorer callable object / function with signature\n ``scorer(estimator, X, y)``. For a list of scoring functions\n that can be used, look at :mod:`sklearn.metrics`. The\n default scoring option used is 'accuracy'.\n\n solver : {'newton-cg', 'lbfgs', 'liblinear', 'sag', 'saga'}, default='lbfgs'\n\n Algorithm to use in the optimization problem. Default is 'lbfgs'.\n To choose a solver, you might want to consider the following aspects:\n\n - For small datasets, 'liblinear' is a good choice, whereas 'sag'\n and 'saga' are faster for large ones;\n - For multiclass problems, only 'newton-cg', 'sag', 'saga' and\n 'lbfgs' handle multinomial loss;\n - 'liblinear' might be slower in :class:`LogisticRegressionCV`\n because it does not handle warm-starting. 'liblinear' is\n limited to one-versus-rest schemes.\n\n .. warning::\n The choice of the algorithm depends on the penalty chosen:\n\n - 'newton-cg' - ['l2']\n - 'lbfgs' - ['l2']\n - 'liblinear' - ['l1', 'l2']\n - 'sag' - ['l2']\n - 'saga' - ['elasticnet', 'l1', 'l2']\n\n .. note::\n 'sag' and 'saga' fast convergence is only guaranteed on features\n with approximately the same scale. You can preprocess the data with\n a scaler from :mod:`sklearn.preprocessing`.\n\n .. versionadded:: 0.17\n Stochastic Average Gradient descent solver.\n .. versionadded:: 0.19\n SAGA solver.\n\n tol : float, default=1e-4\n Tolerance for stopping criteria.\n\n max_iter : int, default=100\n Maximum number of iterations of the optimization algorithm.\n\n class_weight : dict or 'balanced', default=None\n Weights associated with classes in the form ``{class_label: weight}``.\n If not given, all classes are supposed to have weight one.\n\n The \"balanced\" mode uses the values of y to automatically adjust\n weights inversely proportional to class frequencies in the input data\n as ``n_samples / (n_classes * np.bincount(y))``.\n\n Note that these weights will be multiplied with sample_weight (passed\n through the fit method) if sample_weight is specified.\n\n .. versionadded:: 0.17\n class_weight == 'balanced'\n\n n_jobs : int, default=None\n Number of CPU cores used during the cross-validation loop.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n verbose : int, default=0\n For the 'liblinear', 'sag' and 'lbfgs' solvers set verbose to any\n positive number for verbosity.\n\n refit : bool, default=True\n If set to True, the scores are averaged across all folds, and the\n coefs and the C that corresponds to the best score is taken, and a\n final refit is done using these parameters.\n Otherwise the coefs, intercepts and C that correspond to the\n best scores across folds are averaged.\n\n intercept_scaling : float, default=1\n Useful only when the solver 'liblinear' is used\n and self.fit_intercept is set to True. In this case, x becomes\n [x, self.intercept_scaling],\n i.e. a \"synthetic\" feature with constant value equal to\n intercept_scaling is appended to the instance vector.\n The intercept becomes ``intercept_scaling * synthetic_feature_weight``.\n\n Note! the synthetic feature weight is subject to l1/l2 regularization\n as all other features.\n To lessen the effect of regularization on synthetic feature weight\n (and therefore on the intercept) intercept_scaling has to be increased.\n\n multi_class : {'auto, 'ovr', 'multinomial'}, default='auto'\n If the option chosen is 'ovr', then a binary problem is fit for each\n label. For 'multinomial' the loss minimised is the multinomial loss fit\n across the entire probability distribution, *even when the data is\n binary*. 'multinomial' is unavailable when solver='liblinear'.\n 'auto' selects 'ovr' if the data is binary, or if solver='liblinear',\n and otherwise selects 'multinomial'.\n\n .. versionadded:: 0.18\n Stochastic Average Gradient descent solver for 'multinomial' case.\n .. versionchanged:: 0.22\n Default changed from 'ovr' to 'auto' in 0.22.\n\n random_state : int, RandomState instance, default=None\n Used when `solver='sag'`, 'saga' or 'liblinear' to shuffle the data.\n Note that this only applies to the solver and not the cross-validation\n generator. See :term:`Glossary ` for details.\n\n l1_ratios : list of float, default=None\n The list of Elastic-Net mixing parameter, with ``0 <= l1_ratio <= 1``.\n Only used if ``penalty='elasticnet'``. A value of 0 is equivalent to\n using ``penalty='l2'``, while 1 is equivalent to using\n ``penalty='l1'``. For ``0 < l1_ratio <1``, the penalty is a combination\n of L1 and L2.\n\n Attributes\n ----------\n classes_ : ndarray of shape (n_classes, )\n A list of class labels known to the classifier.\n\n coef_ : ndarray of shape (1, n_features) or (n_classes, n_features)\n Coefficient of the features in the decision function.\n\n `coef_` is of shape (1, n_features) when the given problem\n is binary.\n\n intercept_ : ndarray of shape (1,) or (n_classes,)\n Intercept (a.k.a. bias) added to the decision function.\n\n If `fit_intercept` is set to False, the intercept is set to zero.\n `intercept_` is of shape(1,) when the problem is binary.\n\n Cs_ : ndarray of shape (n_cs)\n Array of C i.e. inverse of regularization parameter values used\n for cross-validation.\n\n l1_ratios_ : ndarray of shape (n_l1_ratios)\n Array of l1_ratios used for cross-validation. If no l1_ratio is used\n (i.e. penalty is not 'elasticnet'), this is set to ``[None]``\n\n coefs_paths_ : ndarray of shape (n_folds, n_cs, n_features) or (n_folds, n_cs, n_features + 1)\n dict with classes as the keys, and the path of coefficients obtained\n during cross-validating across each fold and then across each Cs\n after doing an OvR for the corresponding class as values.\n If the 'multi_class' option is set to 'multinomial', then\n the coefs_paths are the coefficients corresponding to each class.\n Each dict value has shape ``(n_folds, n_cs, n_features)`` or\n ``(n_folds, n_cs, n_features + 1)`` depending on whether the\n intercept is fit or not. If ``penalty='elasticnet'``, the shape is\n ``(n_folds, n_cs, n_l1_ratios_, n_features)`` or\n ``(n_folds, n_cs, n_l1_ratios_, n_features + 1)``.\n\n scores_ : dict\n dict with classes as the keys, and the values as the\n grid of scores obtained during cross-validating each fold, after doing\n an OvR for the corresponding class. If the 'multi_class' option\n given is 'multinomial' then the same scores are repeated across\n all classes, since this is the multinomial class. Each dict value\n has shape ``(n_folds, n_cs`` or ``(n_folds, n_cs, n_l1_ratios)`` if\n ``penalty='elasticnet'``.\n\n C_ : ndarray of shape (n_classes,) or (n_classes - 1,)\n Array of C that maps to the best scores across every class. If refit is\n set to False, then for each class, the best C is the average of the\n C's that correspond to the best scores for each fold.\n `C_` is of shape(n_classes,) when the problem is binary.\n\n l1_ratio_ : ndarray of shape (n_classes,) or (n_classes - 1,)\n Array of l1_ratio that maps to the best scores across every class. If\n refit is set to False, then for each class, the best l1_ratio is the\n average of the l1_ratio's that correspond to the best scores for each\n fold. `l1_ratio_` is of shape(n_classes,) when the problem is binary.\n\n n_iter_ : ndarray of shape (n_classes, n_folds, n_cs) or (1, n_folds, n_cs)\n Actual number of iterations for all classes, folds and Cs.\n In the binary or multinomial cases, the first dimension is equal to 1.\n If ``penalty='elasticnet'``, the shape is ``(n_classes, n_folds,\n n_cs, n_l1_ratios)`` or ``(1, n_folds, n_cs, n_l1_ratios)``.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n LogisticRegression : Logistic regression without tuning the\n hyperparameter `C`.\n\n Examples\n --------\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.linear_model import LogisticRegressionCV\n >>> X, y = load_iris(return_X_y=True)\n >>> clf = LogisticRegressionCV(cv=5, random_state=0).fit(X, y)\n >>> clf.predict(X[:2, :])\n array([0, 0])\n >>> clf.predict_proba(X[:2, :]).shape\n (2, 3)\n >>> clf.score(X, y)\n 0.98...\n \"\"\"\n \n def __init__(self, *, Cs=10, fit_intercept=True, cv=None, dual=False, penalty='l2', scoring=None, solver='lbfgs', tol=0.0001, max_iter=100, class_weight=None, n_jobs=None, verbose=0, refit=True, intercept_scaling=1.0, multi_class='auto', random_state=None, l1_ratios=None):\n self.Cs = Cs\n self.fit_intercept = fit_intercept\n self.cv = cv\n self.dual = dual\n self.penalty = penalty\n self.scoring = scoring\n self.tol = tol\n self.max_iter = max_iter\n self.class_weight = class_weight\n self.n_jobs = n_jobs\n self.verbose = verbose\n self.solver = solver\n self.refit = refit\n self.intercept_scaling = intercept_scaling\n self.multi_class = multi_class\n self.random_state = random_state\n self.l1_ratios = l1_ratios\n \n def fit(self, X, y, sample_weight=None):\n \"\"\"Fit the model according to the given training data.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target vector relative to X.\n\n sample_weight : array-like of shape (n_samples,) default=None\n Array of weights that are assigned to individual samples.\n If not provided, then each sample is given unit weight.\n\n Returns\n -------\n self : object\n Fitted LogisticRegressionCV estimator.\n \"\"\"\n solver = _check_solver(self.solver, self.penalty, self.dual)\n if not isinstance(self.max_iter, numbers.Number) or self.max_iter < 0:\n raise ValueError('Maximum number of iteration must be positive; got (max_iter=%r)' % self.max_iter)\n if not isinstance(self.tol, numbers.Number) or self.tol < 0:\n raise ValueError('Tolerance for stopping criteria must be positive; got (tol=%r)' % self.tol)\n if self.penalty == 'elasticnet':\n if self.l1_ratios is None or len(self.l1_ratios) == 0 or any((not isinstance(l1_ratio, numbers.Number) or l1_ratio < 0 or l1_ratio > 1 for l1_ratio in self.l1_ratios)):\n raise ValueError('l1_ratios must be a list of numbers between 0 and 1; got (l1_ratios=%r)' % self.l1_ratios)\n l1_ratios_ = self.l1_ratios\n else:\n if self.l1_ratios is not None:\n warnings.warn(\"l1_ratios parameter is only used when penalty is 'elasticnet'. Got (penalty={})\".format(self.penalty))\n l1_ratios_ = [None]\n if self.penalty == 'none':\n raise ValueError(\"penalty='none' is not useful and not supported by LogisticRegressionCV.\")\n (X, y) = self._validate_data(X, y, accept_sparse='csr', dtype=np.float64, order='C', accept_large_sparse=solver != 'liblinear')\n check_classification_targets(y)\n class_weight = self.class_weight\n label_encoder = LabelEncoder().fit(y)\n y = label_encoder.transform(y)\n if isinstance(class_weight, dict):\n class_weight = {label_encoder.transform([cls])[0]: v for (cls, v) in class_weight.items()}\n classes = self.classes_ = label_encoder.classes_\n encoded_labels = label_encoder.transform(label_encoder.classes_)\n multi_class = _check_multi_class(self.multi_class, solver, len(classes))\n if solver in ['sag', 'saga']:\n max_squared_sum = row_norms(X, squared=True).max()\n else:\n max_squared_sum = None\n cv = check_cv(self.cv, y, classifier=True)\n folds = list(cv.split(X, y))\n n_classes = len(encoded_labels)\n if n_classes < 2:\n raise ValueError('This solver needs samples of at least 2 classes in the data, but the data contains only one class: %r' % classes[0])\n if n_classes == 2:\n n_classes = 1\n encoded_labels = encoded_labels[1:]\n classes = classes[1:]\n if multi_class == 'multinomial':\n iter_encoded_labels = iter_classes = [None]\n else:\n iter_encoded_labels = encoded_labels\n iter_classes = classes\n if class_weight == 'balanced':\n class_weight = compute_class_weight(class_weight, classes=np.arange(len(self.classes_)), y=y)\n class_weight = dict(enumerate(class_weight))\n path_func = delayed(_log_reg_scoring_path)\n if self.solver in ['sag', 'saga']:\n prefer = 'threads'\n else:\n prefer = 'processes'\n fold_coefs_ = Parallel(n_jobs=self.n_jobs, verbose=self.verbose, **_joblib_parallel_args(prefer=prefer))((path_func(X, y, train, test, pos_class=label, Cs=self.Cs, fit_intercept=self.fit_intercept, penalty=self.penalty, dual=self.dual, solver=solver, tol=self.tol, max_iter=self.max_iter, verbose=self.verbose, class_weight=class_weight, scoring=self.scoring, multi_class=multi_class, intercept_scaling=self.intercept_scaling, random_state=self.random_state, max_squared_sum=max_squared_sum, sample_weight=sample_weight, l1_ratio=l1_ratio) for label in iter_encoded_labels for (train, test) in folds for l1_ratio in l1_ratios_))\n (coefs_paths, Cs, scores, n_iter_) = zip(*fold_coefs_)\n self.Cs_ = Cs[0]\n if multi_class == 'multinomial':\n coefs_paths = np.reshape(coefs_paths, (len(folds), len(l1_ratios_) * len(self.Cs_), n_classes, -1))\n coefs_paths = np.swapaxes(coefs_paths, 0, 1)\n coefs_paths = np.swapaxes(coefs_paths, 0, 2)\n self.n_iter_ = np.reshape(n_iter_, (1, len(folds), len(self.Cs_) * len(l1_ratios_)))\n scores = np.tile(scores, (n_classes, 1, 1))\n else:\n coefs_paths = np.reshape(coefs_paths, (n_classes, len(folds), len(self.Cs_) * len(l1_ratios_), -1))\n self.n_iter_ = np.reshape(n_iter_, (n_classes, len(folds), len(self.Cs_) * len(l1_ratios_)))\n scores = np.reshape(scores, (n_classes, len(folds), -1))\n self.scores_ = dict(zip(classes, scores))\n self.coefs_paths_ = dict(zip(classes, coefs_paths))\n self.C_ = list()\n self.l1_ratio_ = list()\n self.coef_ = np.empty((n_classes, X.shape[1]))\n self.intercept_ = np.zeros(n_classes)\n for (index, (cls, encoded_label)) in enumerate(zip(iter_classes, iter_encoded_labels)):\n if multi_class == 'ovr':\n scores = self.scores_[cls]\n coefs_paths = self.coefs_paths_[cls]\n else:\n scores = scores[0]\n if self.refit:\n best_index = scores.sum(axis=0).argmax()\n best_index_C = best_index % len(self.Cs_)\n C_ = self.Cs_[best_index_C]\n self.C_.append(C_)\n best_index_l1 = best_index // len(self.Cs_)\n l1_ratio_ = l1_ratios_[best_index_l1]\n self.l1_ratio_.append(l1_ratio_)\n if multi_class == 'multinomial':\n coef_init = np.mean(coefs_paths[:, :, best_index, :], axis=1)\n else:\n coef_init = np.mean(coefs_paths[:, best_index, :], axis=0)\n (w, _, _) = _logistic_regression_path(X, y, pos_class=encoded_label, Cs=[C_], solver=solver, fit_intercept=self.fit_intercept, coef=coef_init, max_iter=self.max_iter, tol=self.tol, penalty=self.penalty, class_weight=class_weight, multi_class=multi_class, verbose=max(0, self.verbose - 1), random_state=self.random_state, check_input=False, max_squared_sum=max_squared_sum, sample_weight=sample_weight, l1_ratio=l1_ratio_)\n w = w[0]\n else:\n best_indices = np.argmax(scores, axis=1)\n if multi_class == 'ovr':\n w = np.mean([coefs_paths[i, best_indices[i], :] for i in range(len(folds))], axis=0)\n else:\n w = np.mean([coefs_paths[:, i, best_indices[i], :] for i in range(len(folds))], axis=0)\n best_indices_C = best_indices % len(self.Cs_)\n self.C_.append(np.mean(self.Cs_[best_indices_C]))\n if self.penalty == 'elasticnet':\n best_indices_l1 = best_indices // len(self.Cs_)\n self.l1_ratio_.append(np.mean(l1_ratios_[best_indices_l1]))\n else:\n self.l1_ratio_.append(None)\n if multi_class == 'multinomial':\n self.C_ = np.tile(self.C_, n_classes)\n self.l1_ratio_ = np.tile(self.l1_ratio_, n_classes)\n self.coef_ = w[:, :X.shape[1]]\n if self.fit_intercept:\n self.intercept_ = w[:, -1]\n else:\n self.coef_[index] = w[:X.shape[1]]\n if self.fit_intercept:\n self.intercept_[index] = w[-1]\n self.C_ = np.asarray(self.C_)\n self.l1_ratio_ = np.asarray(self.l1_ratio_)\n self.l1_ratios_ = np.asarray(l1_ratios_)\n if self.l1_ratios is not None:\n for (cls, coefs_path) in self.coefs_paths_.items():\n self.coefs_paths_[cls] = coefs_path.reshape((len(folds), self.l1_ratios_.size, self.Cs_.size, -1))\n self.coefs_paths_[cls] = np.transpose(self.coefs_paths_[cls], (0, 2, 1, 3))\n for (cls, score) in self.scores_.items():\n self.scores_[cls] = score.reshape((len(folds), self.l1_ratios_.size, self.Cs_.size))\n self.scores_[cls] = np.transpose(self.scores_[cls], (0, 2, 1))\n self.n_iter_ = self.n_iter_.reshape((-1, len(folds), self.l1_ratios_.size, self.Cs_.size))\n self.n_iter_ = np.transpose(self.n_iter_, (0, 1, 3, 2))\n return self\n \n def score(self, X, y, sample_weight=None):\n \"\"\"Score using the `scoring` option on the given test data and labels.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Test samples.\n\n y : array-like of shape (n_samples,)\n True labels for X.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights.\n\n Returns\n -------\n score : float\n Score of self.predict(X) wrt. y.\n \"\"\"\n scoring = self.scoring or 'accuracy'\n scoring = get_scorer(scoring)\n return scoring(self, X, y, sample_weight=sample_weight)\n \n def _more_tags(self):\n return {'_xfail_checks': {'check_sample_weights_invariance': 'zero sample_weight is not equivalent to removing samples'}}\n" + "source_code": "\n\nclass LogisticRegressionCV(LogisticRegression, LinearClassifierMixin, BaseEstimator):\n \"\"\"Logistic Regression CV (aka logit, MaxEnt) classifier.\n\n See glossary entry for :term:`cross-validation estimator`.\n\n This class implements logistic regression using liblinear, newton-cg, sag\n of lbfgs optimizer. The newton-cg, sag and lbfgs solvers support only L2\n regularization with primal formulation. The liblinear solver supports both\n L1 and L2 regularization, with a dual formulation only for the L2 penalty.\n Elastic-Net penalty is only supported by the saga solver.\n\n For the grid of `Cs` values and `l1_ratios` values, the best hyperparameter\n is selected by the cross-validator\n :class:`~sklearn.model_selection.StratifiedKFold`, but it can be changed\n using the :term:`cv` parameter. The 'newton-cg', 'sag', 'saga' and 'lbfgs'\n solvers can warm-start the coefficients (see :term:`Glossary`).\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n Cs : int or list of floats, default=10\n Each of the values in Cs describes the inverse of regularization\n strength. If Cs is as an int, then a grid of Cs values are chosen\n in a logarithmic scale between 1e-4 and 1e4.\n Like in support vector machines, smaller values specify stronger\n regularization.\n\n fit_intercept : bool, default=True\n Specifies if a constant (a.k.a. bias or intercept) should be\n added to the decision function.\n\n cv : int or cross-validation generator, default=None\n The default cross-validation generator used is Stratified K-Folds.\n If an integer is provided, then it is the number of folds used.\n See the module :mod:`sklearn.model_selection` module for the\n list of possible cross-validation objects.\n\n .. versionchanged:: 0.22\n ``cv`` default value if None changed from 3-fold to 5-fold.\n\n dual : bool, default=False\n Dual or primal formulation. Dual formulation is only implemented for\n l2 penalty with liblinear solver. Prefer dual=False when\n n_samples > n_features.\n\n penalty : {'l1', 'l2', 'elasticnet'}, default='l2'\n Specify the norm of the penalty:\n\n - `'l2'`: add a L2 penalty term (used by default);\n - `'l1'`: add a L1 penalty term;\n - `'elasticnet'`: both L1 and L2 penalty terms are added.\n\n .. warning::\n Some penalties may not work with some solvers. See the parameter\n `solver` below, to know the compatibility between the penalty and\n solver.\n\n scoring : str or callable, default=None\n A string (see model evaluation documentation) or\n a scorer callable object / function with signature\n ``scorer(estimator, X, y)``. For a list of scoring functions\n that can be used, look at :mod:`sklearn.metrics`. The\n default scoring option used is 'accuracy'.\n\n solver : {'newton-cg', 'lbfgs', 'liblinear', 'sag', 'saga'}, default='lbfgs'\n\n Algorithm to use in the optimization problem. Default is 'lbfgs'.\n To choose a solver, you might want to consider the following aspects:\n\n - For small datasets, 'liblinear' is a good choice, whereas 'sag'\n and 'saga' are faster for large ones;\n - For multiclass problems, only 'newton-cg', 'sag', 'saga' and\n 'lbfgs' handle multinomial loss;\n - 'liblinear' might be slower in :class:`LogisticRegressionCV`\n because it does not handle warm-starting. 'liblinear' is\n limited to one-versus-rest schemes.\n\n .. warning::\n The choice of the algorithm depends on the penalty chosen:\n\n - 'newton-cg' - ['l2']\n - 'lbfgs' - ['l2']\n - 'liblinear' - ['l1', 'l2']\n - 'sag' - ['l2']\n - 'saga' - ['elasticnet', 'l1', 'l2']\n\n .. note::\n 'sag' and 'saga' fast convergence is only guaranteed on features\n with approximately the same scale. You can preprocess the data with\n a scaler from :mod:`sklearn.preprocessing`.\n\n .. versionadded:: 0.17\n Stochastic Average Gradient descent solver.\n .. versionadded:: 0.19\n SAGA solver.\n\n tol : float, default=1e-4\n Tolerance for stopping criteria.\n\n max_iter : int, default=100\n Maximum number of iterations of the optimization algorithm.\n\n class_weight : dict or 'balanced', default=None\n Weights associated with classes in the form ``{class_label: weight}``.\n If not given, all classes are supposed to have weight one.\n\n The \"balanced\" mode uses the values of y to automatically adjust\n weights inversely proportional to class frequencies in the input data\n as ``n_samples / (n_classes * np.bincount(y))``.\n\n Note that these weights will be multiplied with sample_weight (passed\n through the fit method) if sample_weight is specified.\n\n .. versionadded:: 0.17\n class_weight == 'balanced'\n\n n_jobs : int, default=None\n Number of CPU cores used during the cross-validation loop.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n verbose : int, default=0\n For the 'liblinear', 'sag' and 'lbfgs' solvers set verbose to any\n positive number for verbosity.\n\n refit : bool, default=True\n If set to True, the scores are averaged across all folds, and the\n coefs and the C that corresponds to the best score is taken, and a\n final refit is done using these parameters.\n Otherwise the coefs, intercepts and C that correspond to the\n best scores across folds are averaged.\n\n intercept_scaling : float, default=1\n Useful only when the solver 'liblinear' is used\n and self.fit_intercept is set to True. In this case, x becomes\n [x, self.intercept_scaling],\n i.e. a \"synthetic\" feature with constant value equal to\n intercept_scaling is appended to the instance vector.\n The intercept becomes ``intercept_scaling * synthetic_feature_weight``.\n\n Note! the synthetic feature weight is subject to l1/l2 regularization\n as all other features.\n To lessen the effect of regularization on synthetic feature weight\n (and therefore on the intercept) intercept_scaling has to be increased.\n\n multi_class : {'auto, 'ovr', 'multinomial'}, default='auto'\n If the option chosen is 'ovr', then a binary problem is fit for each\n label. For 'multinomial' the loss minimised is the multinomial loss fit\n across the entire probability distribution, *even when the data is\n binary*. 'multinomial' is unavailable when solver='liblinear'.\n 'auto' selects 'ovr' if the data is binary, or if solver='liblinear',\n and otherwise selects 'multinomial'.\n\n .. versionadded:: 0.18\n Stochastic Average Gradient descent solver for 'multinomial' case.\n .. versionchanged:: 0.22\n Default changed from 'ovr' to 'auto' in 0.22.\n\n random_state : int, RandomState instance, default=None\n Used when `solver='sag'`, 'saga' or 'liblinear' to shuffle the data.\n Note that this only applies to the solver and not the cross-validation\n generator. See :term:`Glossary ` for details.\n\n l1_ratios : list of float, default=None\n The list of Elastic-Net mixing parameter, with ``0 <= l1_ratio <= 1``.\n Only used if ``penalty='elasticnet'``. A value of 0 is equivalent to\n using ``penalty='l2'``, while 1 is equivalent to using\n ``penalty='l1'``. For ``0 < l1_ratio <1``, the penalty is a combination\n of L1 and L2.\n\n Attributes\n ----------\n classes_ : ndarray of shape (n_classes, )\n A list of class labels known to the classifier.\n\n coef_ : ndarray of shape (1, n_features) or (n_classes, n_features)\n Coefficient of the features in the decision function.\n\n `coef_` is of shape (1, n_features) when the given problem\n is binary.\n\n intercept_ : ndarray of shape (1,) or (n_classes,)\n Intercept (a.k.a. bias) added to the decision function.\n\n If `fit_intercept` is set to False, the intercept is set to zero.\n `intercept_` is of shape(1,) when the problem is binary.\n\n Cs_ : ndarray of shape (n_cs)\n Array of C i.e. inverse of regularization parameter values used\n for cross-validation.\n\n l1_ratios_ : ndarray of shape (n_l1_ratios)\n Array of l1_ratios used for cross-validation. If no l1_ratio is used\n (i.e. penalty is not 'elasticnet'), this is set to ``[None]``\n\n coefs_paths_ : ndarray of shape (n_folds, n_cs, n_features) or (n_folds, n_cs, n_features + 1)\n dict with classes as the keys, and the path of coefficients obtained\n during cross-validating across each fold and then across each Cs\n after doing an OvR for the corresponding class as values.\n If the 'multi_class' option is set to 'multinomial', then\n the coefs_paths are the coefficients corresponding to each class.\n Each dict value has shape ``(n_folds, n_cs, n_features)`` or\n ``(n_folds, n_cs, n_features + 1)`` depending on whether the\n intercept is fit or not. If ``penalty='elasticnet'``, the shape is\n ``(n_folds, n_cs, n_l1_ratios_, n_features)`` or\n ``(n_folds, n_cs, n_l1_ratios_, n_features + 1)``.\n\n scores_ : dict\n dict with classes as the keys, and the values as the\n grid of scores obtained during cross-validating each fold, after doing\n an OvR for the corresponding class. If the 'multi_class' option\n given is 'multinomial' then the same scores are repeated across\n all classes, since this is the multinomial class. Each dict value\n has shape ``(n_folds, n_cs`` or ``(n_folds, n_cs, n_l1_ratios)`` if\n ``penalty='elasticnet'``.\n\n C_ : ndarray of shape (n_classes,) or (n_classes - 1,)\n Array of C that maps to the best scores across every class. If refit is\n set to False, then for each class, the best C is the average of the\n C's that correspond to the best scores for each fold.\n `C_` is of shape(n_classes,) when the problem is binary.\n\n l1_ratio_ : ndarray of shape (n_classes,) or (n_classes - 1,)\n Array of l1_ratio that maps to the best scores across every class. If\n refit is set to False, then for each class, the best l1_ratio is the\n average of the l1_ratio's that correspond to the best scores for each\n fold. `l1_ratio_` is of shape(n_classes,) when the problem is binary.\n\n n_iter_ : ndarray of shape (n_classes, n_folds, n_cs) or (1, n_folds, n_cs)\n Actual number of iterations for all classes, folds and Cs.\n In the binary or multinomial cases, the first dimension is equal to 1.\n If ``penalty='elasticnet'``, the shape is ``(n_classes, n_folds,\n n_cs, n_l1_ratios)`` or ``(1, n_folds, n_cs, n_l1_ratios)``.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n LogisticRegression : Logistic regression without tuning the\n hyperparameter `C`.\n\n Examples\n --------\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.linear_model import LogisticRegressionCV\n >>> X, y = load_iris(return_X_y=True)\n >>> clf = LogisticRegressionCV(cv=5, random_state=0).fit(X, y)\n >>> clf.predict(X[:2, :])\n array([0, 0])\n >>> clf.predict_proba(X[:2, :]).shape\n (2, 3)\n >>> clf.score(X, y)\n 0.98...\n \"\"\"\n \n def __init__(self, *, Cs=10, fit_intercept=True, cv=None, dual=False, penalty='l2', scoring=None, solver='lbfgs', tol=0.0001, max_iter=100, class_weight=None, n_jobs=None, verbose=0, refit=True, intercept_scaling=1.0, multi_class='auto', random_state=None, l1_ratios=None):\n self.Cs = Cs\n self.fit_intercept = fit_intercept\n self.cv = cv\n self.dual = dual\n self.penalty = penalty\n self.scoring = scoring\n self.tol = tol\n self.max_iter = max_iter\n self.class_weight = class_weight\n self.n_jobs = n_jobs\n self.verbose = verbose\n self.solver = solver\n self.refit = refit\n self.intercept_scaling = intercept_scaling\n self.multi_class = multi_class\n self.random_state = random_state\n self.l1_ratios = l1_ratios\n \n def fit(self, X, y, sample_weight=None):\n \"\"\"Fit the model according to the given training data.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target vector relative to X.\n\n sample_weight : array-like of shape (n_samples,) default=None\n Array of weights that are assigned to individual samples.\n If not provided, then each sample is given unit weight.\n\n Returns\n -------\n self : object\n Fitted LogisticRegressionCV estimator.\n \"\"\"\n solver = _check_solver(self.solver, self.penalty, self.dual)\n if not isinstance(self.max_iter, numbers.Number) or self.max_iter < 0:\n raise ValueError('Maximum number of iteration must be positive; got (max_iter=%r)' % self.max_iter)\n if not isinstance(self.tol, numbers.Number) or self.tol < 0:\n raise ValueError('Tolerance for stopping criteria must be positive; got (tol=%r)' % self.tol)\n if self.penalty == 'elasticnet':\n if self.l1_ratios is None or len(self.l1_ratios) == 0 or any((not isinstance(l1_ratio, numbers.Number) or l1_ratio < 0 or l1_ratio > 1 for l1_ratio in self.l1_ratios)):\n raise ValueError('l1_ratios must be a list of numbers between 0 and 1; got (l1_ratios=%r)' % self.l1_ratios)\n l1_ratios_ = self.l1_ratios\n else:\n if self.l1_ratios is not None:\n warnings.warn(\"l1_ratios parameter is only used when penalty is 'elasticnet'. Got (penalty={})\".format(self.penalty))\n l1_ratios_ = [None]\n if self.penalty == 'none':\n raise ValueError(\"penalty='none' is not useful and not supported by LogisticRegressionCV.\")\n (X, y) = self._validate_data(X, y, accept_sparse='csr', dtype=np.float64, order='C', accept_large_sparse=solver not in ['liblinear', 'sag', 'saga'])\n check_classification_targets(y)\n class_weight = self.class_weight\n label_encoder = LabelEncoder().fit(y)\n y = label_encoder.transform(y)\n if isinstance(class_weight, dict):\n class_weight = {label_encoder.transform([cls])[0]: v for (cls, v) in class_weight.items()}\n classes = self.classes_ = label_encoder.classes_\n encoded_labels = label_encoder.transform(label_encoder.classes_)\n multi_class = _check_multi_class(self.multi_class, solver, len(classes))\n if solver in ['sag', 'saga']:\n max_squared_sum = row_norms(X, squared=True).max()\n else:\n max_squared_sum = None\n cv = check_cv(self.cv, y, classifier=True)\n folds = list(cv.split(X, y))\n n_classes = len(encoded_labels)\n if n_classes < 2:\n raise ValueError('This solver needs samples of at least 2 classes in the data, but the data contains only one class: %r' % classes[0])\n if n_classes == 2:\n n_classes = 1\n encoded_labels = encoded_labels[1:]\n classes = classes[1:]\n if multi_class == 'multinomial':\n iter_encoded_labels = iter_classes = [None]\n else:\n iter_encoded_labels = encoded_labels\n iter_classes = classes\n if class_weight == 'balanced':\n class_weight = compute_class_weight(class_weight, classes=np.arange(len(self.classes_)), y=y)\n class_weight = dict(enumerate(class_weight))\n path_func = delayed(_log_reg_scoring_path)\n if self.solver in ['sag', 'saga']:\n prefer = 'threads'\n else:\n prefer = 'processes'\n fold_coefs_ = Parallel(n_jobs=self.n_jobs, verbose=self.verbose, **_joblib_parallel_args(prefer=prefer))((path_func(X, y, train, test, pos_class=label, Cs=self.Cs, fit_intercept=self.fit_intercept, penalty=self.penalty, dual=self.dual, solver=solver, tol=self.tol, max_iter=self.max_iter, verbose=self.verbose, class_weight=class_weight, scoring=self.scoring, multi_class=multi_class, intercept_scaling=self.intercept_scaling, random_state=self.random_state, max_squared_sum=max_squared_sum, sample_weight=sample_weight, l1_ratio=l1_ratio) for label in iter_encoded_labels for (train, test) in folds for l1_ratio in l1_ratios_))\n (coefs_paths, Cs, scores, n_iter_) = zip(*fold_coefs_)\n self.Cs_ = Cs[0]\n if multi_class == 'multinomial':\n coefs_paths = np.reshape(coefs_paths, (len(folds), len(l1_ratios_) * len(self.Cs_), n_classes, -1))\n coefs_paths = np.swapaxes(coefs_paths, 0, 1)\n coefs_paths = np.swapaxes(coefs_paths, 0, 2)\n self.n_iter_ = np.reshape(n_iter_, (1, len(folds), len(self.Cs_) * len(l1_ratios_)))\n scores = np.tile(scores, (n_classes, 1, 1))\n else:\n coefs_paths = np.reshape(coefs_paths, (n_classes, len(folds), len(self.Cs_) * len(l1_ratios_), -1))\n self.n_iter_ = np.reshape(n_iter_, (n_classes, len(folds), len(self.Cs_) * len(l1_ratios_)))\n scores = np.reshape(scores, (n_classes, len(folds), -1))\n self.scores_ = dict(zip(classes, scores))\n self.coefs_paths_ = dict(zip(classes, coefs_paths))\n self.C_ = list()\n self.l1_ratio_ = list()\n self.coef_ = np.empty((n_classes, X.shape[1]))\n self.intercept_ = np.zeros(n_classes)\n for (index, (cls, encoded_label)) in enumerate(zip(iter_classes, iter_encoded_labels)):\n if multi_class == 'ovr':\n scores = self.scores_[cls]\n coefs_paths = self.coefs_paths_[cls]\n else:\n scores = scores[0]\n if self.refit:\n best_index = scores.sum(axis=0).argmax()\n best_index_C = best_index % len(self.Cs_)\n C_ = self.Cs_[best_index_C]\n self.C_.append(C_)\n best_index_l1 = best_index // len(self.Cs_)\n l1_ratio_ = l1_ratios_[best_index_l1]\n self.l1_ratio_.append(l1_ratio_)\n if multi_class == 'multinomial':\n coef_init = np.mean(coefs_paths[:, :, best_index, :], axis=1)\n else:\n coef_init = np.mean(coefs_paths[:, best_index, :], axis=0)\n (w, _, _) = _logistic_regression_path(X, y, pos_class=encoded_label, Cs=[C_], solver=solver, fit_intercept=self.fit_intercept, coef=coef_init, max_iter=self.max_iter, tol=self.tol, penalty=self.penalty, class_weight=class_weight, multi_class=multi_class, verbose=max(0, self.verbose - 1), random_state=self.random_state, check_input=False, max_squared_sum=max_squared_sum, sample_weight=sample_weight, l1_ratio=l1_ratio_)\n w = w[0]\n else:\n best_indices = np.argmax(scores, axis=1)\n if multi_class == 'ovr':\n w = np.mean([coefs_paths[i, best_indices[i], :] for i in range(len(folds))], axis=0)\n else:\n w = np.mean([coefs_paths[:, i, best_indices[i], :] for i in range(len(folds))], axis=0)\n best_indices_C = best_indices % len(self.Cs_)\n self.C_.append(np.mean(self.Cs_[best_indices_C]))\n if self.penalty == 'elasticnet':\n best_indices_l1 = best_indices // len(self.Cs_)\n self.l1_ratio_.append(np.mean(l1_ratios_[best_indices_l1]))\n else:\n self.l1_ratio_.append(None)\n if multi_class == 'multinomial':\n self.C_ = np.tile(self.C_, n_classes)\n self.l1_ratio_ = np.tile(self.l1_ratio_, n_classes)\n self.coef_ = w[:, :X.shape[1]]\n if self.fit_intercept:\n self.intercept_ = w[:, -1]\n else:\n self.coef_[index] = w[:X.shape[1]]\n if self.fit_intercept:\n self.intercept_[index] = w[-1]\n self.C_ = np.asarray(self.C_)\n self.l1_ratio_ = np.asarray(self.l1_ratio_)\n self.l1_ratios_ = np.asarray(l1_ratios_)\n if self.l1_ratios is not None:\n for (cls, coefs_path) in self.coefs_paths_.items():\n self.coefs_paths_[cls] = coefs_path.reshape((len(folds), self.l1_ratios_.size, self.Cs_.size, -1))\n self.coefs_paths_[cls] = np.transpose(self.coefs_paths_[cls], (0, 2, 1, 3))\n for (cls, score) in self.scores_.items():\n self.scores_[cls] = score.reshape((len(folds), self.l1_ratios_.size, self.Cs_.size))\n self.scores_[cls] = np.transpose(self.scores_[cls], (0, 2, 1))\n self.n_iter_ = self.n_iter_.reshape((-1, len(folds), self.l1_ratios_.size, self.Cs_.size))\n self.n_iter_ = np.transpose(self.n_iter_, (0, 1, 3, 2))\n return self\n \n def score(self, X, y, sample_weight=None):\n \"\"\"Score using the `scoring` option on the given test data and labels.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Test samples.\n\n y : array-like of shape (n_samples,)\n True labels for X.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights.\n\n Returns\n -------\n score : float\n Score of self.predict(X) wrt. y.\n \"\"\"\n scoring = self.scoring or 'accuracy'\n scoring = get_scorer(scoring)\n return scoring(self, X, y, sample_weight=sample_weight)\n \n def _more_tags(self):\n return {'_xfail_checks': {'check_sample_weights_invariance': 'zero sample_weight is not equivalent to removing samples'}}\n" }, { "name": "OrthogonalMatchingPursuit", @@ -23858,8 +23811,8 @@ ], "is_public": true, "description": "Orthogonal Matching Pursuit model (OMP).\n\nRead more in the :ref:`User Guide `.", - "docstring": "Orthogonal Matching Pursuit model (OMP).\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_nonzero_coefs : int, default=None\n Desired number of non-zero entries in the solution. If None (by\n default) this value is set to 10% of n_features.\n\n tol : float, default=None\n Maximum norm of the residual. If not None, overrides n_nonzero_coefs.\n\n fit_intercept : bool, default=True\n whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=True\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0. It will default\n to False in 1.2 and be removed in 1.4.\n\n precompute : 'auto' or bool, default='auto'\n Whether to use a precomputed Gram and Xy matrix to speed up\n calculations. Improves performance when :term:`n_targets` or\n :term:`n_samples` is very large. Note that if you already have such\n matrices, you can pass them directly to the fit method.\n\n Attributes\n ----------\n coef_ : ndarray of shape (n_features,) or (n_targets, n_features)\n Parameter vector (w in the formula).\n\n intercept_ : float or ndarray of shape (n_targets,)\n Independent term in decision function.\n\n n_iter_ : int or array-like\n Number of active features across every target.\n\n n_nonzero_coefs_ : int\n The number of non-zero coefficients in the solution. If\n `n_nonzero_coefs` is None and `tol` is None this value is either set\n to 10% of `n_features` or 1, whichever is greater.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn.linear_model import OrthogonalMatchingPursuit\n >>> from sklearn.datasets import make_regression\n >>> X, y = make_regression(noise=4, random_state=0)\n >>> reg = OrthogonalMatchingPursuit(normalize=False).fit(X, y)\n >>> reg.score(X, y)\n 0.9991...\n >>> reg.predict(X[:1,])\n array([-78.3854...])\n\n Notes\n -----\n Orthogonal matching pursuit was introduced in G. Mallat, Z. Zhang,\n Matching pursuits with time-frequency dictionaries, IEEE Transactions on\n Signal Processing, Vol. 41, No. 12. (December 1993), pp. 3397-3415.\n (http://blanche.polytechnique.fr/~mallat/papiers/MallatPursuit93.pdf)\n\n This implementation is based on Rubinstein, R., Zibulevsky, M. and Elad,\n M., Efficient Implementation of the K-SVD Algorithm using Batch Orthogonal\n Matching Pursuit Technical Report - CS Technion, April 2008.\n https://www.cs.technion.ac.il/~ronrubin/Publications/KSVD-OMP-v2.pdf\n\n See Also\n --------\n orthogonal_mp\n orthogonal_mp_gram\n lars_path\n Lars\n LassoLars\n sklearn.decomposition.sparse_encode\n OrthogonalMatchingPursuitCV\n ", - "source_code": "\n\nclass OrthogonalMatchingPursuit(MultiOutputMixin, RegressorMixin, LinearModel):\n \"\"\"Orthogonal Matching Pursuit model (OMP).\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_nonzero_coefs : int, default=None\n Desired number of non-zero entries in the solution. If None (by\n default) this value is set to 10% of n_features.\n\n tol : float, default=None\n Maximum norm of the residual. If not None, overrides n_nonzero_coefs.\n\n fit_intercept : bool, default=True\n whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=True\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0. It will default\n to False in 1.2 and be removed in 1.4.\n\n precompute : 'auto' or bool, default='auto'\n Whether to use a precomputed Gram and Xy matrix to speed up\n calculations. Improves performance when :term:`n_targets` or\n :term:`n_samples` is very large. Note that if you already have such\n matrices, you can pass them directly to the fit method.\n\n Attributes\n ----------\n coef_ : ndarray of shape (n_features,) or (n_targets, n_features)\n Parameter vector (w in the formula).\n\n intercept_ : float or ndarray of shape (n_targets,)\n Independent term in decision function.\n\n n_iter_ : int or array-like\n Number of active features across every target.\n\n n_nonzero_coefs_ : int\n The number of non-zero coefficients in the solution. If\n `n_nonzero_coefs` is None and `tol` is None this value is either set\n to 10% of `n_features` or 1, whichever is greater.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn.linear_model import OrthogonalMatchingPursuit\n >>> from sklearn.datasets import make_regression\n >>> X, y = make_regression(noise=4, random_state=0)\n >>> reg = OrthogonalMatchingPursuit(normalize=False).fit(X, y)\n >>> reg.score(X, y)\n 0.9991...\n >>> reg.predict(X[:1,])\n array([-78.3854...])\n\n Notes\n -----\n Orthogonal matching pursuit was introduced in G. Mallat, Z. Zhang,\n Matching pursuits with time-frequency dictionaries, IEEE Transactions on\n Signal Processing, Vol. 41, No. 12. (December 1993), pp. 3397-3415.\n (http://blanche.polytechnique.fr/~mallat/papiers/MallatPursuit93.pdf)\n\n This implementation is based on Rubinstein, R., Zibulevsky, M. and Elad,\n M., Efficient Implementation of the K-SVD Algorithm using Batch Orthogonal\n Matching Pursuit Technical Report - CS Technion, April 2008.\n https://www.cs.technion.ac.il/~ronrubin/Publications/KSVD-OMP-v2.pdf\n\n See Also\n --------\n orthogonal_mp\n orthogonal_mp_gram\n lars_path\n Lars\n LassoLars\n sklearn.decomposition.sparse_encode\n OrthogonalMatchingPursuitCV\n \"\"\"\n \n def __init__(self, *, n_nonzero_coefs=None, tol=None, fit_intercept=True, normalize='deprecated', precompute='auto'):\n self.n_nonzero_coefs = n_nonzero_coefs\n self.tol = tol\n self.fit_intercept = fit_intercept\n self.normalize = normalize\n self.precompute = precompute\n \n def fit(self, X, y):\n \"\"\"Fit the model using X, y as training data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training data.\n\n y : array-like of shape (n_samples,) or (n_samples, n_targets)\n Target values. Will be cast to X's dtype if necessary\n\n\n Returns\n -------\n self : object\n returns an instance of self.\n \"\"\"\n _normalize = _deprecate_normalize(self.normalize, default=True, estimator_name=self.__class__.__name__)\n (X, y) = self._validate_data(X, y, multi_output=True, y_numeric=True)\n n_features = X.shape[1]\n (X, y, X_offset, y_offset, X_scale, Gram, Xy) = _pre_fit(X, y, None, self.precompute, _normalize, self.fit_intercept, copy=True)\n if y.ndim == 1:\n y = y[:, np.newaxis]\n if self.n_nonzero_coefs is None and self.tol is None:\n self.n_nonzero_coefs_ = max(int(0.1 * n_features), 1)\n else:\n self.n_nonzero_coefs_ = self.n_nonzero_coefs\n if Gram is False:\n (coef_, self.n_iter_) = orthogonal_mp(X, y, n_nonzero_coefs=self.n_nonzero_coefs_, tol=self.tol, precompute=False, copy_X=True, return_n_iter=True)\n else:\n norms_sq = np.sum(y**2, axis=0) if self.tol is not None else None\n (coef_, self.n_iter_) = orthogonal_mp_gram(Gram, Xy=Xy, n_nonzero_coefs=self.n_nonzero_coefs_, tol=self.tol, norms_squared=norms_sq, copy_Gram=True, copy_Xy=True, return_n_iter=True)\n self.coef_ = coef_.T\n self._set_intercept(X_offset, y_offset, X_scale)\n return self\n" + "docstring": "Orthogonal Matching Pursuit model (OMP).\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_nonzero_coefs : int, default=None\n Desired number of non-zero entries in the solution. If None (by\n default) this value is set to 10% of n_features.\n\n tol : float, default=None\n Maximum norm of the residual. If not None, overrides n_nonzero_coefs.\n\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=True\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0. It will default\n to False in 1.2 and be removed in 1.4.\n\n precompute : 'auto' or bool, default='auto'\n Whether to use a precomputed Gram and Xy matrix to speed up\n calculations. Improves performance when :term:`n_targets` or\n :term:`n_samples` is very large. Note that if you already have such\n matrices, you can pass them directly to the fit method.\n\n Attributes\n ----------\n coef_ : ndarray of shape (n_features,) or (n_targets, n_features)\n Parameter vector (w in the formula).\n\n intercept_ : float or ndarray of shape (n_targets,)\n Independent term in decision function.\n\n n_iter_ : int or array-like\n Number of active features across every target.\n\n n_nonzero_coefs_ : int\n The number of non-zero coefficients in the solution. If\n `n_nonzero_coefs` is None and `tol` is None this value is either set\n to 10% of `n_features` or 1, whichever is greater.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n orthogonal_mp : Solves n_targets Orthogonal Matching Pursuit problems.\n orthogonal_mp_gram : Solves n_targets Orthogonal Matching Pursuit\n problems using only the Gram matrix X.T * X and the product X.T * y.\n lars_path : Compute Least Angle Regression or Lasso path using LARS algorithm.\n Lars : Least Angle Regression model a.k.a. LAR.\n LassoLars : Lasso model fit with Least Angle Regression a.k.a. Lars.\n sklearn.decomposition.sparse_encode : Generic sparse coding.\n Each column of the result is the solution to a Lasso problem.\n OrthogonalMatchingPursuitCV : Cross-validated\n Orthogonal Matching Pursuit model (OMP).\n\n Notes\n -----\n Orthogonal matching pursuit was introduced in G. Mallat, Z. Zhang,\n Matching pursuits with time-frequency dictionaries, IEEE Transactions on\n Signal Processing, Vol. 41, No. 12. (December 1993), pp. 3397-3415.\n (http://blanche.polytechnique.fr/~mallat/papiers/MallatPursuit93.pdf)\n\n This implementation is based on Rubinstein, R., Zibulevsky, M. and Elad,\n M., Efficient Implementation of the K-SVD Algorithm using Batch Orthogonal\n Matching Pursuit Technical Report - CS Technion, April 2008.\n https://www.cs.technion.ac.il/~ronrubin/Publications/KSVD-OMP-v2.pdf\n\n Examples\n --------\n >>> from sklearn.linear_model import OrthogonalMatchingPursuit\n >>> from sklearn.datasets import make_regression\n >>> X, y = make_regression(noise=4, random_state=0)\n >>> reg = OrthogonalMatchingPursuit(normalize=False).fit(X, y)\n >>> reg.score(X, y)\n 0.9991...\n >>> reg.predict(X[:1,])\n array([-78.3854...])\n ", + "source_code": "\n\nclass OrthogonalMatchingPursuit(MultiOutputMixin, RegressorMixin, LinearModel):\n \"\"\"Orthogonal Matching Pursuit model (OMP).\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_nonzero_coefs : int, default=None\n Desired number of non-zero entries in the solution. If None (by\n default) this value is set to 10% of n_features.\n\n tol : float, default=None\n Maximum norm of the residual. If not None, overrides n_nonzero_coefs.\n\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=True\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0. It will default\n to False in 1.2 and be removed in 1.4.\n\n precompute : 'auto' or bool, default='auto'\n Whether to use a precomputed Gram and Xy matrix to speed up\n calculations. Improves performance when :term:`n_targets` or\n :term:`n_samples` is very large. Note that if you already have such\n matrices, you can pass them directly to the fit method.\n\n Attributes\n ----------\n coef_ : ndarray of shape (n_features,) or (n_targets, n_features)\n Parameter vector (w in the formula).\n\n intercept_ : float or ndarray of shape (n_targets,)\n Independent term in decision function.\n\n n_iter_ : int or array-like\n Number of active features across every target.\n\n n_nonzero_coefs_ : int\n The number of non-zero coefficients in the solution. If\n `n_nonzero_coefs` is None and `tol` is None this value is either set\n to 10% of `n_features` or 1, whichever is greater.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n orthogonal_mp : Solves n_targets Orthogonal Matching Pursuit problems.\n orthogonal_mp_gram : Solves n_targets Orthogonal Matching Pursuit\n problems using only the Gram matrix X.T * X and the product X.T * y.\n lars_path : Compute Least Angle Regression or Lasso path using LARS algorithm.\n Lars : Least Angle Regression model a.k.a. LAR.\n LassoLars : Lasso model fit with Least Angle Regression a.k.a. Lars.\n sklearn.decomposition.sparse_encode : Generic sparse coding.\n Each column of the result is the solution to a Lasso problem.\n OrthogonalMatchingPursuitCV : Cross-validated\n Orthogonal Matching Pursuit model (OMP).\n\n Notes\n -----\n Orthogonal matching pursuit was introduced in G. Mallat, Z. Zhang,\n Matching pursuits with time-frequency dictionaries, IEEE Transactions on\n Signal Processing, Vol. 41, No. 12. (December 1993), pp. 3397-3415.\n (http://blanche.polytechnique.fr/~mallat/papiers/MallatPursuit93.pdf)\n\n This implementation is based on Rubinstein, R., Zibulevsky, M. and Elad,\n M., Efficient Implementation of the K-SVD Algorithm using Batch Orthogonal\n Matching Pursuit Technical Report - CS Technion, April 2008.\n https://www.cs.technion.ac.il/~ronrubin/Publications/KSVD-OMP-v2.pdf\n\n Examples\n --------\n >>> from sklearn.linear_model import OrthogonalMatchingPursuit\n >>> from sklearn.datasets import make_regression\n >>> X, y = make_regression(noise=4, random_state=0)\n >>> reg = OrthogonalMatchingPursuit(normalize=False).fit(X, y)\n >>> reg.score(X, y)\n 0.9991...\n >>> reg.predict(X[:1,])\n array([-78.3854...])\n \"\"\"\n \n def __init__(self, *, n_nonzero_coefs=None, tol=None, fit_intercept=True, normalize='deprecated', precompute='auto'):\n self.n_nonzero_coefs = n_nonzero_coefs\n self.tol = tol\n self.fit_intercept = fit_intercept\n self.normalize = normalize\n self.precompute = precompute\n \n def fit(self, X, y):\n \"\"\"Fit the model using X, y as training data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training data.\n\n y : array-like of shape (n_samples,) or (n_samples, n_targets)\n Target values. Will be cast to X's dtype if necessary.\n\n Returns\n -------\n self : object\n Returns an instance of self.\n \"\"\"\n _normalize = _deprecate_normalize(self.normalize, default=True, estimator_name=self.__class__.__name__)\n (X, y) = self._validate_data(X, y, multi_output=True, y_numeric=True)\n n_features = X.shape[1]\n (X, y, X_offset, y_offset, X_scale, Gram, Xy) = _pre_fit(X, y, None, self.precompute, _normalize, self.fit_intercept, copy=True)\n if y.ndim == 1:\n y = y[:, np.newaxis]\n if self.n_nonzero_coefs is None and self.tol is None:\n self.n_nonzero_coefs_ = max(int(0.1 * n_features), 1)\n else:\n self.n_nonzero_coefs_ = self.n_nonzero_coefs\n if Gram is False:\n (coef_, self.n_iter_) = orthogonal_mp(X, y, n_nonzero_coefs=self.n_nonzero_coefs_, tol=self.tol, precompute=False, copy_X=True, return_n_iter=True)\n else:\n norms_sq = np.sum(y**2, axis=0) if self.tol is not None else None\n (coef_, self.n_iter_) = orthogonal_mp_gram(Gram, Xy=Xy, n_nonzero_coefs=self.n_nonzero_coefs_, tol=self.tol, norms_squared=norms_sq, copy_Gram=True, copy_Xy=True, return_n_iter=True)\n self.coef_ = coef_.T\n self._set_intercept(X_offset, y_offset, X_scale)\n return self\n" }, { "name": "OrthogonalMatchingPursuitCV", @@ -23872,8 +23825,8 @@ ], "is_public": true, "description": "Cross-validated Orthogonal Matching Pursuit model (OMP).\n\nSee glossary entry for :term:`cross-validation estimator`. Read more in the :ref:`User Guide `.", - "docstring": "Cross-validated Orthogonal Matching Pursuit model (OMP).\n\n See glossary entry for :term:`cross-validation estimator`.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n copy : bool, default=True\n Whether the design matrix X must be copied by the algorithm. A false\n value is only helpful if X is already Fortran-ordered, otherwise a\n copy is made anyway.\n\n fit_intercept : bool, default=True\n whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=True\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0. It will default\n to False in 1.2 and be removed in 1.4.\n\n max_iter : int, default=None\n Maximum numbers of iterations to perform, therefore maximum features\n to include. 10% of ``n_features`` but at least 5 if available.\n\n cv : int, cross-validation generator or iterable, default=None\n Determines the cross-validation splitting strategy.\n Possible inputs for cv are:\n\n - None, to use the default 5-fold cross-validation,\n - integer, to specify the number of folds.\n - :term:`CV splitter`,\n - An iterable yielding (train, test) splits as arrays of indices.\n\n For integer/None inputs, :class:`KFold` is used.\n\n Refer :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n .. versionchanged:: 0.22\n ``cv`` default value if None changed from 3-fold to 5-fold.\n\n n_jobs : int, default=None\n Number of CPUs to use during the cross validation.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n verbose : bool or int, default=False\n Sets the verbosity amount.\n\n Attributes\n ----------\n intercept_ : float or ndarray of shape (n_targets,)\n Independent term in decision function.\n\n coef_ : ndarray of shape (n_features,) or (n_targets, n_features)\n Parameter vector (w in the problem formulation).\n\n n_nonzero_coefs_ : int\n Estimated number of non-zero coefficients giving the best mean squared\n error over the cross-validation folds.\n\n n_iter_ : int or array-like\n Number of active features across every target for the model refit with\n the best hyperparameters got by cross-validating across all folds.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn.linear_model import OrthogonalMatchingPursuitCV\n >>> from sklearn.datasets import make_regression\n >>> X, y = make_regression(n_features=100, n_informative=10,\n ... noise=4, random_state=0)\n >>> reg = OrthogonalMatchingPursuitCV(cv=5, normalize=False).fit(X, y)\n >>> reg.score(X, y)\n 0.9991...\n >>> reg.n_nonzero_coefs_\n 10\n >>> reg.predict(X[:1,])\n array([-78.3854...])\n\n See Also\n --------\n orthogonal_mp\n orthogonal_mp_gram\n lars_path\n Lars\n LassoLars\n OrthogonalMatchingPursuit\n LarsCV\n LassoLarsCV\n sklearn.decomposition.sparse_encode\n\n ", - "source_code": "\n\nclass OrthogonalMatchingPursuitCV(RegressorMixin, LinearModel):\n \"\"\"Cross-validated Orthogonal Matching Pursuit model (OMP).\n\n See glossary entry for :term:`cross-validation estimator`.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n copy : bool, default=True\n Whether the design matrix X must be copied by the algorithm. A false\n value is only helpful if X is already Fortran-ordered, otherwise a\n copy is made anyway.\n\n fit_intercept : bool, default=True\n whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=True\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0. It will default\n to False in 1.2 and be removed in 1.4.\n\n max_iter : int, default=None\n Maximum numbers of iterations to perform, therefore maximum features\n to include. 10% of ``n_features`` but at least 5 if available.\n\n cv : int, cross-validation generator or iterable, default=None\n Determines the cross-validation splitting strategy.\n Possible inputs for cv are:\n\n - None, to use the default 5-fold cross-validation,\n - integer, to specify the number of folds.\n - :term:`CV splitter`,\n - An iterable yielding (train, test) splits as arrays of indices.\n\n For integer/None inputs, :class:`KFold` is used.\n\n Refer :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n .. versionchanged:: 0.22\n ``cv`` default value if None changed from 3-fold to 5-fold.\n\n n_jobs : int, default=None\n Number of CPUs to use during the cross validation.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n verbose : bool or int, default=False\n Sets the verbosity amount.\n\n Attributes\n ----------\n intercept_ : float or ndarray of shape (n_targets,)\n Independent term in decision function.\n\n coef_ : ndarray of shape (n_features,) or (n_targets, n_features)\n Parameter vector (w in the problem formulation).\n\n n_nonzero_coefs_ : int\n Estimated number of non-zero coefficients giving the best mean squared\n error over the cross-validation folds.\n\n n_iter_ : int or array-like\n Number of active features across every target for the model refit with\n the best hyperparameters got by cross-validating across all folds.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn.linear_model import OrthogonalMatchingPursuitCV\n >>> from sklearn.datasets import make_regression\n >>> X, y = make_regression(n_features=100, n_informative=10,\n ... noise=4, random_state=0)\n >>> reg = OrthogonalMatchingPursuitCV(cv=5, normalize=False).fit(X, y)\n >>> reg.score(X, y)\n 0.9991...\n >>> reg.n_nonzero_coefs_\n 10\n >>> reg.predict(X[:1,])\n array([-78.3854...])\n\n See Also\n --------\n orthogonal_mp\n orthogonal_mp_gram\n lars_path\n Lars\n LassoLars\n OrthogonalMatchingPursuit\n LarsCV\n LassoLarsCV\n sklearn.decomposition.sparse_encode\n\n \"\"\"\n \n def __init__(self, *, copy=True, fit_intercept=True, normalize='deprecated', max_iter=None, cv=None, n_jobs=None, verbose=False):\n self.copy = copy\n self.fit_intercept = fit_intercept\n self.normalize = normalize\n self.max_iter = max_iter\n self.cv = cv\n self.n_jobs = n_jobs\n self.verbose = verbose\n \n def fit(self, X, y):\n \"\"\"Fit the model using X, y as training data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training data.\n\n y : array-like of shape (n_samples,)\n Target values. Will be cast to X's dtype if necessary.\n\n Returns\n -------\n self : object\n returns an instance of self.\n \"\"\"\n _normalize = _deprecate_normalize(self.normalize, default=True, estimator_name=self.__class__.__name__)\n (X, y) = self._validate_data(X, y, y_numeric=True, ensure_min_features=2, estimator=self)\n X = as_float_array(X, copy=False, force_all_finite=False)\n cv = check_cv(self.cv, classifier=False)\n max_iter = min(max(int(0.1 * X.shape[1]), 5), X.shape[1]) if not self.max_iter else self.max_iter\n cv_paths = Parallel(n_jobs=self.n_jobs, verbose=self.verbose)((delayed(_omp_path_residues)(X[train], y[train], X[test], y[test], self.copy, self.fit_intercept, _normalize, max_iter) for (train, test) in cv.split(X)))\n min_early_stop = min((fold.shape[0] for fold in cv_paths))\n mse_folds = np.array([(fold[:min_early_stop]**2).mean(axis=1) for fold in cv_paths])\n best_n_nonzero_coefs = np.argmin(mse_folds.mean(axis=0)) + 1\n self.n_nonzero_coefs_ = best_n_nonzero_coefs\n omp = OrthogonalMatchingPursuit(n_nonzero_coefs=best_n_nonzero_coefs, fit_intercept=self.fit_intercept, normalize=_normalize)\n omp.fit(X, y)\n self.coef_ = omp.coef_\n self.intercept_ = omp.intercept_\n self.n_iter_ = omp.n_iter_\n return self\n" + "docstring": "Cross-validated Orthogonal Matching Pursuit model (OMP).\n\n See glossary entry for :term:`cross-validation estimator`.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n copy : bool, default=True\n Whether the design matrix X must be copied by the algorithm. A false\n value is only helpful if X is already Fortran-ordered, otherwise a\n copy is made anyway.\n\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=True\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0. It will default\n to False in 1.2 and be removed in 1.4.\n\n max_iter : int, default=None\n Maximum numbers of iterations to perform, therefore maximum features\n to include. 10% of ``n_features`` but at least 5 if available.\n\n cv : int, cross-validation generator or iterable, default=None\n Determines the cross-validation splitting strategy.\n Possible inputs for cv are:\n\n - None, to use the default 5-fold cross-validation,\n - integer, to specify the number of folds.\n - :term:`CV splitter`,\n - An iterable yielding (train, test) splits as arrays of indices.\n\n For integer/None inputs, :class:`KFold` is used.\n\n Refer :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n .. versionchanged:: 0.22\n ``cv`` default value if None changed from 3-fold to 5-fold.\n\n n_jobs : int, default=None\n Number of CPUs to use during the cross validation.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n verbose : bool or int, default=False\n Sets the verbosity amount.\n\n Attributes\n ----------\n intercept_ : float or ndarray of shape (n_targets,)\n Independent term in decision function.\n\n coef_ : ndarray of shape (n_features,) or (n_targets, n_features)\n Parameter vector (w in the problem formulation).\n\n n_nonzero_coefs_ : int\n Estimated number of non-zero coefficients giving the best mean squared\n error over the cross-validation folds.\n\n n_iter_ : int or array-like\n Number of active features across every target for the model refit with\n the best hyperparameters got by cross-validating across all folds.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n orthogonal_mp : Solves n_targets Orthogonal Matching Pursuit problems.\n orthogonal_mp_gram : Solves n_targets Orthogonal Matching Pursuit\n problems using only the Gram matrix X.T * X and the product X.T * y.\n lars_path : Compute Least Angle Regression or Lasso path using LARS algorithm.\n Lars : Least Angle Regression model a.k.a. LAR.\n LassoLars : Lasso model fit with Least Angle Regression a.k.a. Lars.\n OrthogonalMatchingPursuit : Orthogonal Matching Pursuit model (OMP).\n LarsCV : Cross-validated Least Angle Regression model.\n LassoLarsCV : Cross-validated Lasso model fit with Least Angle Regression.\n sklearn.decomposition.sparse_encode : Generic sparse coding.\n Each column of the result is the solution to a Lasso problem.\n\n Examples\n --------\n >>> from sklearn.linear_model import OrthogonalMatchingPursuitCV\n >>> from sklearn.datasets import make_regression\n >>> X, y = make_regression(n_features=100, n_informative=10,\n ... noise=4, random_state=0)\n >>> reg = OrthogonalMatchingPursuitCV(cv=5, normalize=False).fit(X, y)\n >>> reg.score(X, y)\n 0.9991...\n >>> reg.n_nonzero_coefs_\n 10\n >>> reg.predict(X[:1,])\n array([-78.3854...])\n ", + "source_code": "\n\nclass OrthogonalMatchingPursuitCV(RegressorMixin, LinearModel):\n \"\"\"Cross-validated Orthogonal Matching Pursuit model (OMP).\n\n See glossary entry for :term:`cross-validation estimator`.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n copy : bool, default=True\n Whether the design matrix X must be copied by the algorithm. A false\n value is only helpful if X is already Fortran-ordered, otherwise a\n copy is made anyway.\n\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. data is expected to be centered).\n\n normalize : bool, default=True\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0. It will default\n to False in 1.2 and be removed in 1.4.\n\n max_iter : int, default=None\n Maximum numbers of iterations to perform, therefore maximum features\n to include. 10% of ``n_features`` but at least 5 if available.\n\n cv : int, cross-validation generator or iterable, default=None\n Determines the cross-validation splitting strategy.\n Possible inputs for cv are:\n\n - None, to use the default 5-fold cross-validation,\n - integer, to specify the number of folds.\n - :term:`CV splitter`,\n - An iterable yielding (train, test) splits as arrays of indices.\n\n For integer/None inputs, :class:`KFold` is used.\n\n Refer :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n .. versionchanged:: 0.22\n ``cv`` default value if None changed from 3-fold to 5-fold.\n\n n_jobs : int, default=None\n Number of CPUs to use during the cross validation.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n verbose : bool or int, default=False\n Sets the verbosity amount.\n\n Attributes\n ----------\n intercept_ : float or ndarray of shape (n_targets,)\n Independent term in decision function.\n\n coef_ : ndarray of shape (n_features,) or (n_targets, n_features)\n Parameter vector (w in the problem formulation).\n\n n_nonzero_coefs_ : int\n Estimated number of non-zero coefficients giving the best mean squared\n error over the cross-validation folds.\n\n n_iter_ : int or array-like\n Number of active features across every target for the model refit with\n the best hyperparameters got by cross-validating across all folds.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n orthogonal_mp : Solves n_targets Orthogonal Matching Pursuit problems.\n orthogonal_mp_gram : Solves n_targets Orthogonal Matching Pursuit\n problems using only the Gram matrix X.T * X and the product X.T * y.\n lars_path : Compute Least Angle Regression or Lasso path using LARS algorithm.\n Lars : Least Angle Regression model a.k.a. LAR.\n LassoLars : Lasso model fit with Least Angle Regression a.k.a. Lars.\n OrthogonalMatchingPursuit : Orthogonal Matching Pursuit model (OMP).\n LarsCV : Cross-validated Least Angle Regression model.\n LassoLarsCV : Cross-validated Lasso model fit with Least Angle Regression.\n sklearn.decomposition.sparse_encode : Generic sparse coding.\n Each column of the result is the solution to a Lasso problem.\n\n Examples\n --------\n >>> from sklearn.linear_model import OrthogonalMatchingPursuitCV\n >>> from sklearn.datasets import make_regression\n >>> X, y = make_regression(n_features=100, n_informative=10,\n ... noise=4, random_state=0)\n >>> reg = OrthogonalMatchingPursuitCV(cv=5, normalize=False).fit(X, y)\n >>> reg.score(X, y)\n 0.9991...\n >>> reg.n_nonzero_coefs_\n 10\n >>> reg.predict(X[:1,])\n array([-78.3854...])\n \"\"\"\n \n def __init__(self, *, copy=True, fit_intercept=True, normalize='deprecated', max_iter=None, cv=None, n_jobs=None, verbose=False):\n self.copy = copy\n self.fit_intercept = fit_intercept\n self.normalize = normalize\n self.max_iter = max_iter\n self.cv = cv\n self.n_jobs = n_jobs\n self.verbose = verbose\n \n def fit(self, X, y):\n \"\"\"Fit the model using X, y as training data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training data.\n\n y : array-like of shape (n_samples,)\n Target values. Will be cast to X's dtype if necessary.\n\n Returns\n -------\n self : object\n Returns an instance of self.\n \"\"\"\n _normalize = _deprecate_normalize(self.normalize, default=True, estimator_name=self.__class__.__name__)\n (X, y) = self._validate_data(X, y, y_numeric=True, ensure_min_features=2, estimator=self)\n X = as_float_array(X, copy=False, force_all_finite=False)\n cv = check_cv(self.cv, classifier=False)\n max_iter = min(max(int(0.1 * X.shape[1]), 5), X.shape[1]) if not self.max_iter else self.max_iter\n cv_paths = Parallel(n_jobs=self.n_jobs, verbose=self.verbose)((delayed(_omp_path_residues)(X[train], y[train], X[test], y[test], self.copy, self.fit_intercept, _normalize, max_iter) for (train, test) in cv.split(X)))\n min_early_stop = min((fold.shape[0] for fold in cv_paths))\n mse_folds = np.array([(fold[:min_early_stop]**2).mean(axis=1) for fold in cv_paths])\n best_n_nonzero_coefs = np.argmin(mse_folds.mean(axis=0)) + 1\n self.n_nonzero_coefs_ = best_n_nonzero_coefs\n omp = OrthogonalMatchingPursuit(n_nonzero_coefs=best_n_nonzero_coefs, fit_intercept=self.fit_intercept, normalize=_normalize)\n omp.fit(X, y)\n self.coef_ = omp.coef_\n self.intercept_ = omp.intercept_\n self.n_iter_ = omp.n_iter_\n return self\n" }, { "name": "PassiveAggressiveClassifier", @@ -23886,9 +23839,9 @@ "sklearn.linear_model._passive_aggressive.PassiveAggressiveClassifier.fit" ], "is_public": true, - "description": "Passive Aggressive Classifier\n\nRead more in the :ref:`User Guide `.", - "docstring": "Passive Aggressive Classifier\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n\n C : float, default=1.0\n Maximum step size (regularization). Defaults to 1.0.\n\n fit_intercept : bool, default=True\n Whether the intercept should be estimated or not. If False, the\n data is assumed to be already centered.\n\n max_iter : int, default=1000\n The maximum number of passes over the training data (aka epochs).\n It only impacts the behavior in the ``fit`` method, and not the\n :meth:`partial_fit` method.\n\n .. versionadded:: 0.19\n\n tol : float or None, default=1e-3\n The stopping criterion. If it is not None, the iterations will stop\n when (loss > previous_loss - tol).\n\n .. versionadded:: 0.19\n\n early_stopping : bool, default=False\n Whether to use early stopping to terminate training when validation.\n score is not improving. If set to True, it will automatically set aside\n a stratified fraction of training data as validation and terminate\n training when validation score is not improving by at least tol for\n n_iter_no_change consecutive epochs.\n\n .. versionadded:: 0.20\n\n validation_fraction : float, default=0.1\n The proportion of training data to set aside as validation set for\n early stopping. Must be between 0 and 1.\n Only used if early_stopping is True.\n\n .. versionadded:: 0.20\n\n n_iter_no_change : int, default=5\n Number of iterations with no improvement to wait before early stopping.\n\n .. versionadded:: 0.20\n\n shuffle : bool, default=True\n Whether or not the training data should be shuffled after each epoch.\n\n verbose : integer, default=0\n The verbosity level\n\n loss : string, default=\"hinge\"\n The loss function to be used:\n hinge: equivalent to PA-I in the reference paper.\n squared_hinge: equivalent to PA-II in the reference paper.\n\n n_jobs : int or None, default=None\n The number of CPUs to use to do the OVA (One Versus All, for\n multi-class problems) computation.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n random_state : int, RandomState instance, default=None\n Used to shuffle the training data, when ``shuffle`` is set to\n ``True``. Pass an int for reproducible output across multiple\n function calls.\n See :term:`Glossary `.\n\n warm_start : bool, default=False\n When set to True, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n Repeatedly calling fit or partial_fit when warm_start is True can\n result in a different solution than when calling fit a single time\n because of the way the data is shuffled.\n\n class_weight : dict, {class_label: weight} or \"balanced\" or None, default=None\n Preset for the class_weight fit parameter.\n\n Weights associated with classes. If not given, all classes\n are supposed to have weight one.\n\n The \"balanced\" mode uses the values of y to automatically adjust\n weights inversely proportional to class frequencies in the input data\n as ``n_samples / (n_classes * np.bincount(y))``\n\n .. versionadded:: 0.17\n parameter *class_weight* to automatically weight samples.\n\n average : bool or int, default=False\n When set to True, computes the averaged SGD weights and stores the\n result in the ``coef_`` attribute. If set to an int greater than 1,\n averaging will begin once the total number of samples seen reaches\n average. So average=10 will begin averaging after seeing 10 samples.\n\n .. versionadded:: 0.19\n parameter *average* to use weights averaging in SGD\n\n Attributes\n ----------\n coef_ : array, shape = [1, n_features] if n_classes == 2 else [n_classes, n_features]\n Weights assigned to the features.\n\n intercept_ : array, shape = [1] if n_classes == 2 else [n_classes]\n Constants in decision function.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n The actual number of iterations to reach the stopping criterion.\n For multiclass fits, it is the maximum over every binary fit.\n\n classes_ : array of shape (n_classes,)\n The unique classes labels.\n\n t_ : int\n Number of weight updates performed during training.\n Same as ``(n_iter_ * n_samples)``.\n\n loss_function_ : callable\n Loss function used by the algorithm.\n\n Examples\n --------\n >>> from sklearn.linear_model import PassiveAggressiveClassifier\n >>> from sklearn.datasets import make_classification\n\n >>> X, y = make_classification(n_features=4, random_state=0)\n >>> clf = PassiveAggressiveClassifier(max_iter=1000, random_state=0,\n ... tol=1e-3)\n >>> clf.fit(X, y)\n PassiveAggressiveClassifier(random_state=0)\n >>> print(clf.coef_)\n [[0.26642044 0.45070924 0.67251877 0.64185414]]\n >>> print(clf.intercept_)\n [1.84127814]\n >>> print(clf.predict([[0, 0, 0, 0]]))\n [1]\n\n See Also\n --------\n SGDClassifier\n Perceptron\n\n References\n ----------\n Online Passive-Aggressive Algorithms\n \n K. Crammer, O. Dekel, J. Keshat, S. Shalev-Shwartz, Y. Singer - JMLR (2006)\n\n ", - "source_code": "\n\nclass PassiveAggressiveClassifier(BaseSGDClassifier):\n \"\"\"Passive Aggressive Classifier\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n\n C : float, default=1.0\n Maximum step size (regularization). Defaults to 1.0.\n\n fit_intercept : bool, default=True\n Whether the intercept should be estimated or not. If False, the\n data is assumed to be already centered.\n\n max_iter : int, default=1000\n The maximum number of passes over the training data (aka epochs).\n It only impacts the behavior in the ``fit`` method, and not the\n :meth:`partial_fit` method.\n\n .. versionadded:: 0.19\n\n tol : float or None, default=1e-3\n The stopping criterion. If it is not None, the iterations will stop\n when (loss > previous_loss - tol).\n\n .. versionadded:: 0.19\n\n early_stopping : bool, default=False\n Whether to use early stopping to terminate training when validation.\n score is not improving. If set to True, it will automatically set aside\n a stratified fraction of training data as validation and terminate\n training when validation score is not improving by at least tol for\n n_iter_no_change consecutive epochs.\n\n .. versionadded:: 0.20\n\n validation_fraction : float, default=0.1\n The proportion of training data to set aside as validation set for\n early stopping. Must be between 0 and 1.\n Only used if early_stopping is True.\n\n .. versionadded:: 0.20\n\n n_iter_no_change : int, default=5\n Number of iterations with no improvement to wait before early stopping.\n\n .. versionadded:: 0.20\n\n shuffle : bool, default=True\n Whether or not the training data should be shuffled after each epoch.\n\n verbose : integer, default=0\n The verbosity level\n\n loss : string, default=\"hinge\"\n The loss function to be used:\n hinge: equivalent to PA-I in the reference paper.\n squared_hinge: equivalent to PA-II in the reference paper.\n\n n_jobs : int or None, default=None\n The number of CPUs to use to do the OVA (One Versus All, for\n multi-class problems) computation.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n random_state : int, RandomState instance, default=None\n Used to shuffle the training data, when ``shuffle`` is set to\n ``True``. Pass an int for reproducible output across multiple\n function calls.\n See :term:`Glossary `.\n\n warm_start : bool, default=False\n When set to True, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n Repeatedly calling fit or partial_fit when warm_start is True can\n result in a different solution than when calling fit a single time\n because of the way the data is shuffled.\n\n class_weight : dict, {class_label: weight} or \"balanced\" or None, default=None\n Preset for the class_weight fit parameter.\n\n Weights associated with classes. If not given, all classes\n are supposed to have weight one.\n\n The \"balanced\" mode uses the values of y to automatically adjust\n weights inversely proportional to class frequencies in the input data\n as ``n_samples / (n_classes * np.bincount(y))``\n\n .. versionadded:: 0.17\n parameter *class_weight* to automatically weight samples.\n\n average : bool or int, default=False\n When set to True, computes the averaged SGD weights and stores the\n result in the ``coef_`` attribute. If set to an int greater than 1,\n averaging will begin once the total number of samples seen reaches\n average. So average=10 will begin averaging after seeing 10 samples.\n\n .. versionadded:: 0.19\n parameter *average* to use weights averaging in SGD\n\n Attributes\n ----------\n coef_ : array, shape = [1, n_features] if n_classes == 2 else [n_classes, n_features]\n Weights assigned to the features.\n\n intercept_ : array, shape = [1] if n_classes == 2 else [n_classes]\n Constants in decision function.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n The actual number of iterations to reach the stopping criterion.\n For multiclass fits, it is the maximum over every binary fit.\n\n classes_ : array of shape (n_classes,)\n The unique classes labels.\n\n t_ : int\n Number of weight updates performed during training.\n Same as ``(n_iter_ * n_samples)``.\n\n loss_function_ : callable\n Loss function used by the algorithm.\n\n Examples\n --------\n >>> from sklearn.linear_model import PassiveAggressiveClassifier\n >>> from sklearn.datasets import make_classification\n\n >>> X, y = make_classification(n_features=4, random_state=0)\n >>> clf = PassiveAggressiveClassifier(max_iter=1000, random_state=0,\n ... tol=1e-3)\n >>> clf.fit(X, y)\n PassiveAggressiveClassifier(random_state=0)\n >>> print(clf.coef_)\n [[0.26642044 0.45070924 0.67251877 0.64185414]]\n >>> print(clf.intercept_)\n [1.84127814]\n >>> print(clf.predict([[0, 0, 0, 0]]))\n [1]\n\n See Also\n --------\n SGDClassifier\n Perceptron\n\n References\n ----------\n Online Passive-Aggressive Algorithms\n \n K. Crammer, O. Dekel, J. Keshat, S. Shalev-Shwartz, Y. Singer - JMLR (2006)\n\n \"\"\"\n \n def __init__(self, *, C=1.0, fit_intercept=True, max_iter=1000, tol=0.001, early_stopping=False, validation_fraction=0.1, n_iter_no_change=5, shuffle=True, verbose=0, loss='hinge', n_jobs=None, random_state=None, warm_start=False, class_weight=None, average=False):\n super().__init__(penalty=None, fit_intercept=fit_intercept, max_iter=max_iter, tol=tol, early_stopping=early_stopping, validation_fraction=validation_fraction, n_iter_no_change=n_iter_no_change, shuffle=shuffle, verbose=verbose, random_state=random_state, eta0=1.0, warm_start=warm_start, class_weight=class_weight, average=average, n_jobs=n_jobs)\n self.C = C\n self.loss = loss\n \n def partial_fit(self, X, y, classes=None):\n \"\"\"Fit linear model with Passive Aggressive algorithm.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Subset of the training data\n\n y : numpy array of shape [n_samples]\n Subset of the target values\n\n classes : array, shape = [n_classes]\n Classes across all calls to partial_fit.\n Can be obtained by via `np.unique(y_all)`, where y_all is the\n target vector of the entire dataset.\n This argument is required for the first call to partial_fit\n and can be omitted in the subsequent calls.\n Note that y doesn't need to contain all labels in `classes`.\n\n Returns\n -------\n self : returns an instance of self.\n \"\"\"\n self._validate_params(for_partial_fit=True)\n if self.class_weight == 'balanced':\n raise ValueError(\"class_weight 'balanced' is not supported for partial_fit. For 'balanced' weights, use `sklearn.utils.compute_class_weight` with `class_weight='balanced'`. In place of y you can use a large enough subset of the full training set target to properly estimate the class frequency distributions. Pass the resulting weights as the class_weight parameter.\")\n lr = 'pa1' if self.loss == 'hinge' else 'pa2'\n return self._partial_fit(X, y, alpha=1.0, C=self.C, loss='hinge', learning_rate=lr, max_iter=1, classes=classes, sample_weight=None, coef_init=None, intercept_init=None)\n \n def fit(self, X, y, coef_init=None, intercept_init=None):\n \"\"\"Fit linear model with Passive Aggressive algorithm.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training data\n\n y : numpy array of shape [n_samples]\n Target values\n\n coef_init : array, shape = [n_classes,n_features]\n The initial coefficients to warm-start the optimization.\n\n intercept_init : array, shape = [n_classes]\n The initial intercept to warm-start the optimization.\n\n Returns\n -------\n self : returns an instance of self.\n \"\"\"\n self._validate_params()\n lr = 'pa1' if self.loss == 'hinge' else 'pa2'\n return self._fit(X, y, alpha=1.0, C=self.C, loss='hinge', learning_rate=lr, coef_init=coef_init, intercept_init=intercept_init)\n" + "description": "Passive Aggressive Classifier.\n\nRead more in the :ref:`User Guide `.", + "docstring": "Passive Aggressive Classifier.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n C : float, default=1.0\n Maximum step size (regularization). Defaults to 1.0.\n\n fit_intercept : bool, default=True\n Whether the intercept should be estimated or not. If False, the\n data is assumed to be already centered.\n\n max_iter : int, default=1000\n The maximum number of passes over the training data (aka epochs).\n It only impacts the behavior in the ``fit`` method, and not the\n :meth:`partial_fit` method.\n\n .. versionadded:: 0.19\n\n tol : float or None, default=1e-3\n The stopping criterion. If it is not None, the iterations will stop\n when (loss > previous_loss - tol).\n\n .. versionadded:: 0.19\n\n early_stopping : bool, default=False\n Whether to use early stopping to terminate training when validation.\n score is not improving. If set to True, it will automatically set aside\n a stratified fraction of training data as validation and terminate\n training when validation score is not improving by at least tol for\n n_iter_no_change consecutive epochs.\n\n .. versionadded:: 0.20\n\n validation_fraction : float, default=0.1\n The proportion of training data to set aside as validation set for\n early stopping. Must be between 0 and 1.\n Only used if early_stopping is True.\n\n .. versionadded:: 0.20\n\n n_iter_no_change : int, default=5\n Number of iterations with no improvement to wait before early stopping.\n\n .. versionadded:: 0.20\n\n shuffle : bool, default=True\n Whether or not the training data should be shuffled after each epoch.\n\n verbose : int, default=0\n The verbosity level.\n\n loss : str, default=\"hinge\"\n The loss function to be used:\n hinge: equivalent to PA-I in the reference paper.\n squared_hinge: equivalent to PA-II in the reference paper.\n\n n_jobs : int or None, default=None\n The number of CPUs to use to do the OVA (One Versus All, for\n multi-class problems) computation.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n random_state : int, RandomState instance, default=None\n Used to shuffle the training data, when ``shuffle`` is set to\n ``True``. Pass an int for reproducible output across multiple\n function calls.\n See :term:`Glossary `.\n\n warm_start : bool, default=False\n When set to True, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n Repeatedly calling fit or partial_fit when warm_start is True can\n result in a different solution than when calling fit a single time\n because of the way the data is shuffled.\n\n class_weight : dict, {class_label: weight} or \"balanced\" or None, default=None\n Preset for the class_weight fit parameter.\n\n Weights associated with classes. If not given, all classes\n are supposed to have weight one.\n\n The \"balanced\" mode uses the values of y to automatically adjust\n weights inversely proportional to class frequencies in the input data\n as ``n_samples / (n_classes * np.bincount(y))``.\n\n .. versionadded:: 0.17\n parameter *class_weight* to automatically weight samples.\n\n average : bool or int, default=False\n When set to True, computes the averaged SGD weights and stores the\n result in the ``coef_`` attribute. If set to an int greater than 1,\n averaging will begin once the total number of samples seen reaches\n average. So average=10 will begin averaging after seeing 10 samples.\n\n .. versionadded:: 0.19\n parameter *average* to use weights averaging in SGD.\n\n Attributes\n ----------\n coef_ : ndarray of shape (1, n_features) if n_classes == 2 else (n_classes, n_features)\n Weights assigned to the features.\n\n intercept_ : ndarray of shape (1,) if n_classes == 2 else (n_classes,)\n Constants in decision function.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n The actual number of iterations to reach the stopping criterion.\n For multiclass fits, it is the maximum over every binary fit.\n\n classes_ : ndarray of shape (n_classes,)\n The unique classes labels.\n\n t_ : int\n Number of weight updates performed during training.\n Same as ``(n_iter_ * n_samples)``.\n\n loss_function_ : callable\n Loss function used by the algorithm.\n\n See Also\n --------\n SGDClassifier : Incrementally trained logistic regression.\n Perceptron : Linear perceptron classifier.\n\n References\n ----------\n Online Passive-Aggressive Algorithms\n \n K. Crammer, O. Dekel, J. Keshat, S. Shalev-Shwartz, Y. Singer - JMLR (2006)\n\n Examples\n --------\n >>> from sklearn.linear_model import PassiveAggressiveClassifier\n >>> from sklearn.datasets import make_classification\n >>> X, y = make_classification(n_features=4, random_state=0)\n >>> clf = PassiveAggressiveClassifier(max_iter=1000, random_state=0,\n ... tol=1e-3)\n >>> clf.fit(X, y)\n PassiveAggressiveClassifier(random_state=0)\n >>> print(clf.coef_)\n [[0.26642044 0.45070924 0.67251877 0.64185414]]\n >>> print(clf.intercept_)\n [1.84127814]\n >>> print(clf.predict([[0, 0, 0, 0]]))\n [1]\n ", + "source_code": "\n\nclass PassiveAggressiveClassifier(BaseSGDClassifier):\n \"\"\"Passive Aggressive Classifier.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n C : float, default=1.0\n Maximum step size (regularization). Defaults to 1.0.\n\n fit_intercept : bool, default=True\n Whether the intercept should be estimated or not. If False, the\n data is assumed to be already centered.\n\n max_iter : int, default=1000\n The maximum number of passes over the training data (aka epochs).\n It only impacts the behavior in the ``fit`` method, and not the\n :meth:`partial_fit` method.\n\n .. versionadded:: 0.19\n\n tol : float or None, default=1e-3\n The stopping criterion. If it is not None, the iterations will stop\n when (loss > previous_loss - tol).\n\n .. versionadded:: 0.19\n\n early_stopping : bool, default=False\n Whether to use early stopping to terminate training when validation.\n score is not improving. If set to True, it will automatically set aside\n a stratified fraction of training data as validation and terminate\n training when validation score is not improving by at least tol for\n n_iter_no_change consecutive epochs.\n\n .. versionadded:: 0.20\n\n validation_fraction : float, default=0.1\n The proportion of training data to set aside as validation set for\n early stopping. Must be between 0 and 1.\n Only used if early_stopping is True.\n\n .. versionadded:: 0.20\n\n n_iter_no_change : int, default=5\n Number of iterations with no improvement to wait before early stopping.\n\n .. versionadded:: 0.20\n\n shuffle : bool, default=True\n Whether or not the training data should be shuffled after each epoch.\n\n verbose : int, default=0\n The verbosity level.\n\n loss : str, default=\"hinge\"\n The loss function to be used:\n hinge: equivalent to PA-I in the reference paper.\n squared_hinge: equivalent to PA-II in the reference paper.\n\n n_jobs : int or None, default=None\n The number of CPUs to use to do the OVA (One Versus All, for\n multi-class problems) computation.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n random_state : int, RandomState instance, default=None\n Used to shuffle the training data, when ``shuffle`` is set to\n ``True``. Pass an int for reproducible output across multiple\n function calls.\n See :term:`Glossary `.\n\n warm_start : bool, default=False\n When set to True, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n Repeatedly calling fit or partial_fit when warm_start is True can\n result in a different solution than when calling fit a single time\n because of the way the data is shuffled.\n\n class_weight : dict, {class_label: weight} or \"balanced\" or None, default=None\n Preset for the class_weight fit parameter.\n\n Weights associated with classes. If not given, all classes\n are supposed to have weight one.\n\n The \"balanced\" mode uses the values of y to automatically adjust\n weights inversely proportional to class frequencies in the input data\n as ``n_samples / (n_classes * np.bincount(y))``.\n\n .. versionadded:: 0.17\n parameter *class_weight* to automatically weight samples.\n\n average : bool or int, default=False\n When set to True, computes the averaged SGD weights and stores the\n result in the ``coef_`` attribute. If set to an int greater than 1,\n averaging will begin once the total number of samples seen reaches\n average. So average=10 will begin averaging after seeing 10 samples.\n\n .. versionadded:: 0.19\n parameter *average* to use weights averaging in SGD.\n\n Attributes\n ----------\n coef_ : ndarray of shape (1, n_features) if n_classes == 2 else (n_classes, n_features)\n Weights assigned to the features.\n\n intercept_ : ndarray of shape (1,) if n_classes == 2 else (n_classes,)\n Constants in decision function.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n The actual number of iterations to reach the stopping criterion.\n For multiclass fits, it is the maximum over every binary fit.\n\n classes_ : ndarray of shape (n_classes,)\n The unique classes labels.\n\n t_ : int\n Number of weight updates performed during training.\n Same as ``(n_iter_ * n_samples)``.\n\n loss_function_ : callable\n Loss function used by the algorithm.\n\n See Also\n --------\n SGDClassifier : Incrementally trained logistic regression.\n Perceptron : Linear perceptron classifier.\n\n References\n ----------\n Online Passive-Aggressive Algorithms\n \n K. Crammer, O. Dekel, J. Keshat, S. Shalev-Shwartz, Y. Singer - JMLR (2006)\n\n Examples\n --------\n >>> from sklearn.linear_model import PassiveAggressiveClassifier\n >>> from sklearn.datasets import make_classification\n >>> X, y = make_classification(n_features=4, random_state=0)\n >>> clf = PassiveAggressiveClassifier(max_iter=1000, random_state=0,\n ... tol=1e-3)\n >>> clf.fit(X, y)\n PassiveAggressiveClassifier(random_state=0)\n >>> print(clf.coef_)\n [[0.26642044 0.45070924 0.67251877 0.64185414]]\n >>> print(clf.intercept_)\n [1.84127814]\n >>> print(clf.predict([[0, 0, 0, 0]]))\n [1]\n \"\"\"\n \n def __init__(self, *, C=1.0, fit_intercept=True, max_iter=1000, tol=0.001, early_stopping=False, validation_fraction=0.1, n_iter_no_change=5, shuffle=True, verbose=0, loss='hinge', n_jobs=None, random_state=None, warm_start=False, class_weight=None, average=False):\n super().__init__(penalty=None, fit_intercept=fit_intercept, max_iter=max_iter, tol=tol, early_stopping=early_stopping, validation_fraction=validation_fraction, n_iter_no_change=n_iter_no_change, shuffle=shuffle, verbose=verbose, random_state=random_state, eta0=1.0, warm_start=warm_start, class_weight=class_weight, average=average, n_jobs=n_jobs)\n self.C = C\n self.loss = loss\n \n def partial_fit(self, X, y, classes=None):\n \"\"\"Fit linear model with Passive Aggressive algorithm.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Subset of the training data.\n\n y : array-like of shape (n_samples,)\n Subset of the target values.\n\n classes : ndarray of shape (n_classes,)\n Classes across all calls to partial_fit.\n Can be obtained by via `np.unique(y_all)`, where y_all is the\n target vector of the entire dataset.\n This argument is required for the first call to partial_fit\n and can be omitted in the subsequent calls.\n Note that y doesn't need to contain all labels in `classes`.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n self._validate_params(for_partial_fit=True)\n if self.class_weight == 'balanced':\n raise ValueError(\"class_weight 'balanced' is not supported for partial_fit. For 'balanced' weights, use `sklearn.utils.compute_class_weight` with `class_weight='balanced'`. In place of y you can use a large enough subset of the full training set target to properly estimate the class frequency distributions. Pass the resulting weights as the class_weight parameter.\")\n lr = 'pa1' if self.loss == 'hinge' else 'pa2'\n return self._partial_fit(X, y, alpha=1.0, C=self.C, loss='hinge', learning_rate=lr, max_iter=1, classes=classes, sample_weight=None, coef_init=None, intercept_init=None)\n \n def fit(self, X, y, coef_init=None, intercept_init=None):\n \"\"\"Fit linear model with Passive Aggressive algorithm.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training data.\n\n y : array-like of shape (n_samples,)\n Target values.\n\n coef_init : ndarray of shape (n_classes, n_features)\n The initial coefficients to warm-start the optimization.\n\n intercept_init : ndarray of shape (n_classes,)\n The initial intercept to warm-start the optimization.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n self._validate_params()\n lr = 'pa1' if self.loss == 'hinge' else 'pa2'\n return self._fit(X, y, alpha=1.0, C=self.C, loss='hinge', learning_rate=lr, coef_init=coef_init, intercept_init=intercept_init)\n" }, { "name": "PassiveAggressiveRegressor", @@ -23901,9 +23854,9 @@ "sklearn.linear_model._passive_aggressive.PassiveAggressiveRegressor.fit" ], "is_public": true, - "description": "Passive Aggressive Regressor\n\nRead more in the :ref:`User Guide `.", - "docstring": "Passive Aggressive Regressor\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n\n C : float, default=1.0\n Maximum step size (regularization). Defaults to 1.0.\n\n fit_intercept : bool, default=True\n Whether the intercept should be estimated or not. If False, the\n data is assumed to be already centered. Defaults to True.\n\n max_iter : int, default=1000\n The maximum number of passes over the training data (aka epochs).\n It only impacts the behavior in the ``fit`` method, and not the\n :meth:`partial_fit` method.\n\n .. versionadded:: 0.19\n\n tol : float or None, default=1e-3\n The stopping criterion. If it is not None, the iterations will stop\n when (loss > previous_loss - tol).\n\n .. versionadded:: 0.19\n\n early_stopping : bool, default=False\n Whether to use early stopping to terminate training when validation.\n score is not improving. If set to True, it will automatically set aside\n a fraction of training data as validation and terminate\n training when validation score is not improving by at least tol for\n n_iter_no_change consecutive epochs.\n\n .. versionadded:: 0.20\n\n validation_fraction : float, default=0.1\n The proportion of training data to set aside as validation set for\n early stopping. Must be between 0 and 1.\n Only used if early_stopping is True.\n\n .. versionadded:: 0.20\n\n n_iter_no_change : int, default=5\n Number of iterations with no improvement to wait before early stopping.\n\n .. versionadded:: 0.20\n\n shuffle : bool, default=True\n Whether or not the training data should be shuffled after each epoch.\n\n verbose : integer, default=0\n The verbosity level\n\n loss : string, default=\"epsilon_insensitive\"\n The loss function to be used:\n epsilon_insensitive: equivalent to PA-I in the reference paper.\n squared_epsilon_insensitive: equivalent to PA-II in the reference\n paper.\n\n epsilon : float, default=0.1\n If the difference between the current prediction and the correct label\n is below this threshold, the model is not updated.\n\n random_state : int, RandomState instance, default=None\n Used to shuffle the training data, when ``shuffle`` is set to\n ``True``. Pass an int for reproducible output across multiple\n function calls.\n See :term:`Glossary `.\n\n warm_start : bool, default=False\n When set to True, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n Repeatedly calling fit or partial_fit when warm_start is True can\n result in a different solution than when calling fit a single time\n because of the way the data is shuffled.\n\n average : bool or int, default=False\n When set to True, computes the averaged SGD weights and stores the\n result in the ``coef_`` attribute. If set to an int greater than 1,\n averaging will begin once the total number of samples seen reaches\n average. So average=10 will begin averaging after seeing 10 samples.\n\n .. versionadded:: 0.19\n parameter *average* to use weights averaging in SGD\n\n Attributes\n ----------\n coef_ : array, shape = [1, n_features] if n_classes == 2 else [n_classes, n_features]\n Weights assigned to the features.\n\n intercept_ : array, shape = [1] if n_classes == 2 else [n_classes]\n Constants in decision function.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n The actual number of iterations to reach the stopping criterion.\n\n t_ : int\n Number of weight updates performed during training.\n Same as ``(n_iter_ * n_samples)``.\n\n Examples\n --------\n >>> from sklearn.linear_model import PassiveAggressiveRegressor\n >>> from sklearn.datasets import make_regression\n\n >>> X, y = make_regression(n_features=4, random_state=0)\n >>> regr = PassiveAggressiveRegressor(max_iter=100, random_state=0,\n ... tol=1e-3)\n >>> regr.fit(X, y)\n PassiveAggressiveRegressor(max_iter=100, random_state=0)\n >>> print(regr.coef_)\n [20.48736655 34.18818427 67.59122734 87.94731329]\n >>> print(regr.intercept_)\n [-0.02306214]\n >>> print(regr.predict([[0, 0, 0, 0]]))\n [-0.02306214]\n\n See Also\n --------\n SGDRegressor\n\n References\n ----------\n Online Passive-Aggressive Algorithms\n \n K. Crammer, O. Dekel, J. Keshat, S. Shalev-Shwartz, Y. Singer - JMLR (2006)\n\n ", - "source_code": "\n\nclass PassiveAggressiveRegressor(BaseSGDRegressor):\n \"\"\"Passive Aggressive Regressor\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n\n C : float, default=1.0\n Maximum step size (regularization). Defaults to 1.0.\n\n fit_intercept : bool, default=True\n Whether the intercept should be estimated or not. If False, the\n data is assumed to be already centered. Defaults to True.\n\n max_iter : int, default=1000\n The maximum number of passes over the training data (aka epochs).\n It only impacts the behavior in the ``fit`` method, and not the\n :meth:`partial_fit` method.\n\n .. versionadded:: 0.19\n\n tol : float or None, default=1e-3\n The stopping criterion. If it is not None, the iterations will stop\n when (loss > previous_loss - tol).\n\n .. versionadded:: 0.19\n\n early_stopping : bool, default=False\n Whether to use early stopping to terminate training when validation.\n score is not improving. If set to True, it will automatically set aside\n a fraction of training data as validation and terminate\n training when validation score is not improving by at least tol for\n n_iter_no_change consecutive epochs.\n\n .. versionadded:: 0.20\n\n validation_fraction : float, default=0.1\n The proportion of training data to set aside as validation set for\n early stopping. Must be between 0 and 1.\n Only used if early_stopping is True.\n\n .. versionadded:: 0.20\n\n n_iter_no_change : int, default=5\n Number of iterations with no improvement to wait before early stopping.\n\n .. versionadded:: 0.20\n\n shuffle : bool, default=True\n Whether or not the training data should be shuffled after each epoch.\n\n verbose : integer, default=0\n The verbosity level\n\n loss : string, default=\"epsilon_insensitive\"\n The loss function to be used:\n epsilon_insensitive: equivalent to PA-I in the reference paper.\n squared_epsilon_insensitive: equivalent to PA-II in the reference\n paper.\n\n epsilon : float, default=0.1\n If the difference between the current prediction and the correct label\n is below this threshold, the model is not updated.\n\n random_state : int, RandomState instance, default=None\n Used to shuffle the training data, when ``shuffle`` is set to\n ``True``. Pass an int for reproducible output across multiple\n function calls.\n See :term:`Glossary `.\n\n warm_start : bool, default=False\n When set to True, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n Repeatedly calling fit or partial_fit when warm_start is True can\n result in a different solution than when calling fit a single time\n because of the way the data is shuffled.\n\n average : bool or int, default=False\n When set to True, computes the averaged SGD weights and stores the\n result in the ``coef_`` attribute. If set to an int greater than 1,\n averaging will begin once the total number of samples seen reaches\n average. So average=10 will begin averaging after seeing 10 samples.\n\n .. versionadded:: 0.19\n parameter *average* to use weights averaging in SGD\n\n Attributes\n ----------\n coef_ : array, shape = [1, n_features] if n_classes == 2 else [n_classes, n_features]\n Weights assigned to the features.\n\n intercept_ : array, shape = [1] if n_classes == 2 else [n_classes]\n Constants in decision function.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n The actual number of iterations to reach the stopping criterion.\n\n t_ : int\n Number of weight updates performed during training.\n Same as ``(n_iter_ * n_samples)``.\n\n Examples\n --------\n >>> from sklearn.linear_model import PassiveAggressiveRegressor\n >>> from sklearn.datasets import make_regression\n\n >>> X, y = make_regression(n_features=4, random_state=0)\n >>> regr = PassiveAggressiveRegressor(max_iter=100, random_state=0,\n ... tol=1e-3)\n >>> regr.fit(X, y)\n PassiveAggressiveRegressor(max_iter=100, random_state=0)\n >>> print(regr.coef_)\n [20.48736655 34.18818427 67.59122734 87.94731329]\n >>> print(regr.intercept_)\n [-0.02306214]\n >>> print(regr.predict([[0, 0, 0, 0]]))\n [-0.02306214]\n\n See Also\n --------\n SGDRegressor\n\n References\n ----------\n Online Passive-Aggressive Algorithms\n \n K. Crammer, O. Dekel, J. Keshat, S. Shalev-Shwartz, Y. Singer - JMLR (2006)\n\n \"\"\"\n \n def __init__(self, *, C=1.0, fit_intercept=True, max_iter=1000, tol=0.001, early_stopping=False, validation_fraction=0.1, n_iter_no_change=5, shuffle=True, verbose=0, loss='epsilon_insensitive', epsilon=DEFAULT_EPSILON, random_state=None, warm_start=False, average=False):\n super().__init__(penalty=None, l1_ratio=0, epsilon=epsilon, eta0=1.0, fit_intercept=fit_intercept, max_iter=max_iter, tol=tol, early_stopping=early_stopping, validation_fraction=validation_fraction, n_iter_no_change=n_iter_no_change, shuffle=shuffle, verbose=verbose, random_state=random_state, warm_start=warm_start, average=average)\n self.C = C\n self.loss = loss\n \n def partial_fit(self, X, y):\n \"\"\"Fit linear model with Passive Aggressive algorithm.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Subset of training data\n\n y : numpy array of shape [n_samples]\n Subset of target values\n\n Returns\n -------\n self : returns an instance of self.\n \"\"\"\n self._validate_params(for_partial_fit=True)\n lr = 'pa1' if self.loss == 'epsilon_insensitive' else 'pa2'\n return self._partial_fit(X, y, alpha=1.0, C=self.C, loss='epsilon_insensitive', learning_rate=lr, max_iter=1, sample_weight=None, coef_init=None, intercept_init=None)\n \n def fit(self, X, y, coef_init=None, intercept_init=None):\n \"\"\"Fit linear model with Passive Aggressive algorithm.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training data\n\n y : numpy array of shape [n_samples]\n Target values\n\n coef_init : array, shape = [n_features]\n The initial coefficients to warm-start the optimization.\n\n intercept_init : array, shape = [1]\n The initial intercept to warm-start the optimization.\n\n Returns\n -------\n self : returns an instance of self.\n \"\"\"\n self._validate_params()\n lr = 'pa1' if self.loss == 'epsilon_insensitive' else 'pa2'\n return self._fit(X, y, alpha=1.0, C=self.C, loss='epsilon_insensitive', learning_rate=lr, coef_init=coef_init, intercept_init=intercept_init)\n" + "description": "Passive Aggressive Regressor.\n\nRead more in the :ref:`User Guide `.", + "docstring": "Passive Aggressive Regressor.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n\n C : float, default=1.0\n Maximum step size (regularization). Defaults to 1.0.\n\n fit_intercept : bool, default=True\n Whether the intercept should be estimated or not. If False, the\n data is assumed to be already centered. Defaults to True.\n\n max_iter : int, default=1000\n The maximum number of passes over the training data (aka epochs).\n It only impacts the behavior in the ``fit`` method, and not the\n :meth:`partial_fit` method.\n\n .. versionadded:: 0.19\n\n tol : float or None, default=1e-3\n The stopping criterion. If it is not None, the iterations will stop\n when (loss > previous_loss - tol).\n\n .. versionadded:: 0.19\n\n early_stopping : bool, default=False\n Whether to use early stopping to terminate training when validation.\n score is not improving. If set to True, it will automatically set aside\n a fraction of training data as validation and terminate\n training when validation score is not improving by at least tol for\n n_iter_no_change consecutive epochs.\n\n .. versionadded:: 0.20\n\n validation_fraction : float, default=0.1\n The proportion of training data to set aside as validation set for\n early stopping. Must be between 0 and 1.\n Only used if early_stopping is True.\n\n .. versionadded:: 0.20\n\n n_iter_no_change : int, default=5\n Number of iterations with no improvement to wait before early stopping.\n\n .. versionadded:: 0.20\n\n shuffle : bool, default=True\n Whether or not the training data should be shuffled after each epoch.\n\n verbose : int, default=0\n The verbosity level.\n\n loss : str, default=\"epsilon_insensitive\"\n The loss function to be used:\n epsilon_insensitive: equivalent to PA-I in the reference paper.\n squared_epsilon_insensitive: equivalent to PA-II in the reference\n paper.\n\n epsilon : float, default=0.1\n If the difference between the current prediction and the correct label\n is below this threshold, the model is not updated.\n\n random_state : int, RandomState instance, default=None\n Used to shuffle the training data, when ``shuffle`` is set to\n ``True``. Pass an int for reproducible output across multiple\n function calls.\n See :term:`Glossary `.\n\n warm_start : bool, default=False\n When set to True, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n Repeatedly calling fit or partial_fit when warm_start is True can\n result in a different solution than when calling fit a single time\n because of the way the data is shuffled.\n\n average : bool or int, default=False\n When set to True, computes the averaged SGD weights and stores the\n result in the ``coef_`` attribute. If set to an int greater than 1,\n averaging will begin once the total number of samples seen reaches\n average. So average=10 will begin averaging after seeing 10 samples.\n\n .. versionadded:: 0.19\n parameter *average* to use weights averaging in SGD.\n\n Attributes\n ----------\n coef_ : array, shape = [1, n_features] if n_classes == 2 else [n_classes, n_features]\n Weights assigned to the features.\n\n intercept_ : array, shape = [1] if n_classes == 2 else [n_classes]\n Constants in decision function.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n The actual number of iterations to reach the stopping criterion.\n\n t_ : int\n Number of weight updates performed during training.\n Same as ``(n_iter_ * n_samples)``.\n\n See Also\n --------\n SGDRegressor : Linear model fitted by minimizing a regularized\n empirical loss with SGD.\n\n References\n ----------\n Online Passive-Aggressive Algorithms\n \n K. Crammer, O. Dekel, J. Keshat, S. Shalev-Shwartz, Y. Singer - JMLR (2006).\n\n Examples\n --------\n >>> from sklearn.linear_model import PassiveAggressiveRegressor\n >>> from sklearn.datasets import make_regression\n\n >>> X, y = make_regression(n_features=4, random_state=0)\n >>> regr = PassiveAggressiveRegressor(max_iter=100, random_state=0,\n ... tol=1e-3)\n >>> regr.fit(X, y)\n PassiveAggressiveRegressor(max_iter=100, random_state=0)\n >>> print(regr.coef_)\n [20.48736655 34.18818427 67.59122734 87.94731329]\n >>> print(regr.intercept_)\n [-0.02306214]\n >>> print(regr.predict([[0, 0, 0, 0]]))\n [-0.02306214]\n ", + "source_code": "\n\nclass PassiveAggressiveRegressor(BaseSGDRegressor):\n \"\"\"Passive Aggressive Regressor.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n\n C : float, default=1.0\n Maximum step size (regularization). Defaults to 1.0.\n\n fit_intercept : bool, default=True\n Whether the intercept should be estimated or not. If False, the\n data is assumed to be already centered. Defaults to True.\n\n max_iter : int, default=1000\n The maximum number of passes over the training data (aka epochs).\n It only impacts the behavior in the ``fit`` method, and not the\n :meth:`partial_fit` method.\n\n .. versionadded:: 0.19\n\n tol : float or None, default=1e-3\n The stopping criterion. If it is not None, the iterations will stop\n when (loss > previous_loss - tol).\n\n .. versionadded:: 0.19\n\n early_stopping : bool, default=False\n Whether to use early stopping to terminate training when validation.\n score is not improving. If set to True, it will automatically set aside\n a fraction of training data as validation and terminate\n training when validation score is not improving by at least tol for\n n_iter_no_change consecutive epochs.\n\n .. versionadded:: 0.20\n\n validation_fraction : float, default=0.1\n The proportion of training data to set aside as validation set for\n early stopping. Must be between 0 and 1.\n Only used if early_stopping is True.\n\n .. versionadded:: 0.20\n\n n_iter_no_change : int, default=5\n Number of iterations with no improvement to wait before early stopping.\n\n .. versionadded:: 0.20\n\n shuffle : bool, default=True\n Whether or not the training data should be shuffled after each epoch.\n\n verbose : int, default=0\n The verbosity level.\n\n loss : str, default=\"epsilon_insensitive\"\n The loss function to be used:\n epsilon_insensitive: equivalent to PA-I in the reference paper.\n squared_epsilon_insensitive: equivalent to PA-II in the reference\n paper.\n\n epsilon : float, default=0.1\n If the difference between the current prediction and the correct label\n is below this threshold, the model is not updated.\n\n random_state : int, RandomState instance, default=None\n Used to shuffle the training data, when ``shuffle`` is set to\n ``True``. Pass an int for reproducible output across multiple\n function calls.\n See :term:`Glossary `.\n\n warm_start : bool, default=False\n When set to True, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n Repeatedly calling fit or partial_fit when warm_start is True can\n result in a different solution than when calling fit a single time\n because of the way the data is shuffled.\n\n average : bool or int, default=False\n When set to True, computes the averaged SGD weights and stores the\n result in the ``coef_`` attribute. If set to an int greater than 1,\n averaging will begin once the total number of samples seen reaches\n average. So average=10 will begin averaging after seeing 10 samples.\n\n .. versionadded:: 0.19\n parameter *average* to use weights averaging in SGD.\n\n Attributes\n ----------\n coef_ : array, shape = [1, n_features] if n_classes == 2 else [n_classes, n_features]\n Weights assigned to the features.\n\n intercept_ : array, shape = [1] if n_classes == 2 else [n_classes]\n Constants in decision function.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n The actual number of iterations to reach the stopping criterion.\n\n t_ : int\n Number of weight updates performed during training.\n Same as ``(n_iter_ * n_samples)``.\n\n See Also\n --------\n SGDRegressor : Linear model fitted by minimizing a regularized\n empirical loss with SGD.\n\n References\n ----------\n Online Passive-Aggressive Algorithms\n \n K. Crammer, O. Dekel, J. Keshat, S. Shalev-Shwartz, Y. Singer - JMLR (2006).\n\n Examples\n --------\n >>> from sklearn.linear_model import PassiveAggressiveRegressor\n >>> from sklearn.datasets import make_regression\n\n >>> X, y = make_regression(n_features=4, random_state=0)\n >>> regr = PassiveAggressiveRegressor(max_iter=100, random_state=0,\n ... tol=1e-3)\n >>> regr.fit(X, y)\n PassiveAggressiveRegressor(max_iter=100, random_state=0)\n >>> print(regr.coef_)\n [20.48736655 34.18818427 67.59122734 87.94731329]\n >>> print(regr.intercept_)\n [-0.02306214]\n >>> print(regr.predict([[0, 0, 0, 0]]))\n [-0.02306214]\n \"\"\"\n \n def __init__(self, *, C=1.0, fit_intercept=True, max_iter=1000, tol=0.001, early_stopping=False, validation_fraction=0.1, n_iter_no_change=5, shuffle=True, verbose=0, loss='epsilon_insensitive', epsilon=DEFAULT_EPSILON, random_state=None, warm_start=False, average=False):\n super().__init__(penalty=None, l1_ratio=0, epsilon=epsilon, eta0=1.0, fit_intercept=fit_intercept, max_iter=max_iter, tol=tol, early_stopping=early_stopping, validation_fraction=validation_fraction, n_iter_no_change=n_iter_no_change, shuffle=shuffle, verbose=verbose, random_state=random_state, warm_start=warm_start, average=average)\n self.C = C\n self.loss = loss\n \n def partial_fit(self, X, y):\n \"\"\"Fit linear model with Passive Aggressive algorithm.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Subset of training data.\n\n y : numpy array of shape [n_samples]\n Subset of target values.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n self._validate_params(for_partial_fit=True)\n lr = 'pa1' if self.loss == 'epsilon_insensitive' else 'pa2'\n return self._partial_fit(X, y, alpha=1.0, C=self.C, loss='epsilon_insensitive', learning_rate=lr, max_iter=1, sample_weight=None, coef_init=None, intercept_init=None)\n \n def fit(self, X, y, coef_init=None, intercept_init=None):\n \"\"\"Fit linear model with Passive Aggressive algorithm.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training data.\n\n y : numpy array of shape [n_samples]\n Target values.\n\n coef_init : array, shape = [n_features]\n The initial coefficients to warm-start the optimization.\n\n intercept_init : array, shape = [1]\n The initial intercept to warm-start the optimization.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n self._validate_params()\n lr = 'pa1' if self.loss == 'epsilon_insensitive' else 'pa2'\n return self._fit(X, y, alpha=1.0, C=self.C, loss='epsilon_insensitive', learning_rate=lr, coef_init=coef_init, intercept_init=intercept_init)\n" }, { "name": "Perceptron", @@ -23968,7 +23921,7 @@ "is_public": true, "description": "Linear least squares with l2 regularization.\n\nMinimizes the objective function:: ||y - Xw||^2_2 + alpha * ||w||^2_2 This model solves a regression model where the loss function is the linear least squares function and regularization is given by the l2-norm. Also known as Ridge Regression or Tikhonov regularization. This estimator has built-in support for multi-variate regression (i.e., when y is a 2d-array of shape (n_samples, n_targets)). Read more in the :ref:`User Guide `.", "docstring": "Linear least squares with l2 regularization.\n\n Minimizes the objective function::\n\n ||y - Xw||^2_2 + alpha * ||w||^2_2\n\n This model solves a regression model where the loss function is\n the linear least squares function and regularization is given by\n the l2-norm. Also known as Ridge Regression or Tikhonov regularization.\n This estimator has built-in support for multi-variate regression\n (i.e., when y is a 2d-array of shape (n_samples, n_targets)).\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n alpha : {float, ndarray of shape (n_targets,)}, default=1.0\n Regularization strength; must be a positive float. Regularization\n improves the conditioning of the problem and reduces the variance of\n the estimates. Larger values specify stronger regularization.\n Alpha corresponds to ``1 / (2C)`` in other linear models such as\n :class:`~sklearn.linear_model.LogisticRegression` or\n :class:`~sklearn.svm.LinearSVC`. If an array is passed, penalties are\n assumed to be specific to the targets. Hence they must correspond in\n number.\n\n fit_intercept : bool, default=True\n Whether to fit the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. ``X`` and ``y`` are expected to be centered).\n\n normalize : bool, default=False\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0 and\n will be removed in 1.2.\n\n copy_X : bool, default=True\n If True, X will be copied; else, it may be overwritten.\n\n max_iter : int, default=None\n Maximum number of iterations for conjugate gradient solver.\n For 'sparse_cg' and 'lsqr' solvers, the default value is determined\n by scipy.sparse.linalg. For 'sag' solver, the default value is 1000.\n For 'lbfgs' solver, the default value is 15000.\n\n tol : float, default=1e-3\n Precision of the solution.\n\n solver : {'auto', 'svd', 'cholesky', 'lsqr', 'sparse_cg', 'sag', 'saga', 'lbfgs'}, default='auto'\n Solver to use in the computational routines:\n\n - 'auto' chooses the solver automatically based on the type of data.\n\n - 'svd' uses a Singular Value Decomposition of X to compute the Ridge\n coefficients. More stable for singular matrices than 'cholesky'.\n\n - 'cholesky' uses the standard scipy.linalg.solve function to\n obtain a closed-form solution.\n\n - 'sparse_cg' uses the conjugate gradient solver as found in\n scipy.sparse.linalg.cg. As an iterative algorithm, this solver is\n more appropriate than 'cholesky' for large-scale data\n (possibility to set `tol` and `max_iter`).\n\n - 'lsqr' uses the dedicated regularized least-squares routine\n scipy.sparse.linalg.lsqr. It is the fastest and uses an iterative\n procedure.\n\n - 'sag' uses a Stochastic Average Gradient descent, and 'saga' uses\n its improved, unbiased version named SAGA. Both methods also use an\n iterative procedure, and are often faster than other solvers when\n both n_samples and n_features are large. Note that 'sag' and\n 'saga' fast convergence is only guaranteed on features with\n approximately the same scale. You can preprocess the data with a\n scaler from sklearn.preprocessing.\n\n - 'lbfgs' uses L-BFGS-B algorithm implemented in\n `scipy.optimize.minimize`. It can be used only when `positive`\n is True.\n\n All last six solvers support both dense and sparse data. However, only\n 'sag', 'sparse_cg', and 'lbfgs' support sparse input when `fit_intercept`\n is True.\n\n .. versionadded:: 0.17\n Stochastic Average Gradient descent solver.\n .. versionadded:: 0.19\n SAGA solver.\n\n positive : bool, default=False\n When set to ``True``, forces the coefficients to be positive.\n Only 'lbfgs' solver is supported in this case.\n\n random_state : int, RandomState instance, default=None\n Used when ``solver`` == 'sag' or 'saga' to shuffle the data.\n See :term:`Glossary ` for details.\n\n .. versionadded:: 0.17\n `random_state` to support Stochastic Average Gradient.\n\n Attributes\n ----------\n coef_ : ndarray of shape (n_features,) or (n_targets, n_features)\n Weight vector(s).\n\n intercept_ : float or ndarray of shape (n_targets,)\n Independent term in decision function. Set to 0.0 if\n ``fit_intercept = False``.\n\n n_iter_ : None or ndarray of shape (n_targets,)\n Actual number of iterations for each target. Available only for\n sag and lsqr solvers. Other solvers will return None.\n\n .. versionadded:: 0.17\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n RidgeClassifier : Ridge classifier.\n RidgeCV : Ridge regression with built-in cross validation.\n :class:`~sklearn.kernel_ridge.KernelRidge` : Kernel ridge regression\n combines ridge regression with the kernel trick.\n\n Examples\n --------\n >>> from sklearn.linear_model import Ridge\n >>> import numpy as np\n >>> n_samples, n_features = 10, 5\n >>> rng = np.random.RandomState(0)\n >>> y = rng.randn(n_samples)\n >>> X = rng.randn(n_samples, n_features)\n >>> clf = Ridge(alpha=1.0)\n >>> clf.fit(X, y)\n Ridge()\n ", - "source_code": "\n\nclass Ridge(MultiOutputMixin, RegressorMixin, _BaseRidge):\n \"\"\"Linear least squares with l2 regularization.\n\n Minimizes the objective function::\n\n ||y - Xw||^2_2 + alpha * ||w||^2_2\n\n This model solves a regression model where the loss function is\n the linear least squares function and regularization is given by\n the l2-norm. Also known as Ridge Regression or Tikhonov regularization.\n This estimator has built-in support for multi-variate regression\n (i.e., when y is a 2d-array of shape (n_samples, n_targets)).\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n alpha : {float, ndarray of shape (n_targets,)}, default=1.0\n Regularization strength; must be a positive float. Regularization\n improves the conditioning of the problem and reduces the variance of\n the estimates. Larger values specify stronger regularization.\n Alpha corresponds to ``1 / (2C)`` in other linear models such as\n :class:`~sklearn.linear_model.LogisticRegression` or\n :class:`~sklearn.svm.LinearSVC`. If an array is passed, penalties are\n assumed to be specific to the targets. Hence they must correspond in\n number.\n\n fit_intercept : bool, default=True\n Whether to fit the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. ``X`` and ``y`` are expected to be centered).\n\n normalize : bool, default=False\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0 and\n will be removed in 1.2.\n\n copy_X : bool, default=True\n If True, X will be copied; else, it may be overwritten.\n\n max_iter : int, default=None\n Maximum number of iterations for conjugate gradient solver.\n For 'sparse_cg' and 'lsqr' solvers, the default value is determined\n by scipy.sparse.linalg. For 'sag' solver, the default value is 1000.\n For 'lbfgs' solver, the default value is 15000.\n\n tol : float, default=1e-3\n Precision of the solution.\n\n solver : {'auto', 'svd', 'cholesky', 'lsqr', 'sparse_cg', 'sag', 'saga', 'lbfgs'}, default='auto'\n Solver to use in the computational routines:\n\n - 'auto' chooses the solver automatically based on the type of data.\n\n - 'svd' uses a Singular Value Decomposition of X to compute the Ridge\n coefficients. More stable for singular matrices than 'cholesky'.\n\n - 'cholesky' uses the standard scipy.linalg.solve function to\n obtain a closed-form solution.\n\n - 'sparse_cg' uses the conjugate gradient solver as found in\n scipy.sparse.linalg.cg. As an iterative algorithm, this solver is\n more appropriate than 'cholesky' for large-scale data\n (possibility to set `tol` and `max_iter`).\n\n - 'lsqr' uses the dedicated regularized least-squares routine\n scipy.sparse.linalg.lsqr. It is the fastest and uses an iterative\n procedure.\n\n - 'sag' uses a Stochastic Average Gradient descent, and 'saga' uses\n its improved, unbiased version named SAGA. Both methods also use an\n iterative procedure, and are often faster than other solvers when\n both n_samples and n_features are large. Note that 'sag' and\n 'saga' fast convergence is only guaranteed on features with\n approximately the same scale. You can preprocess the data with a\n scaler from sklearn.preprocessing.\n\n - 'lbfgs' uses L-BFGS-B algorithm implemented in\n `scipy.optimize.minimize`. It can be used only when `positive`\n is True.\n\n All last six solvers support both dense and sparse data. However, only\n 'sag', 'sparse_cg', and 'lbfgs' support sparse input when `fit_intercept`\n is True.\n\n .. versionadded:: 0.17\n Stochastic Average Gradient descent solver.\n .. versionadded:: 0.19\n SAGA solver.\n\n positive : bool, default=False\n When set to ``True``, forces the coefficients to be positive.\n Only 'lbfgs' solver is supported in this case.\n\n random_state : int, RandomState instance, default=None\n Used when ``solver`` == 'sag' or 'saga' to shuffle the data.\n See :term:`Glossary ` for details.\n\n .. versionadded:: 0.17\n `random_state` to support Stochastic Average Gradient.\n\n Attributes\n ----------\n coef_ : ndarray of shape (n_features,) or (n_targets, n_features)\n Weight vector(s).\n\n intercept_ : float or ndarray of shape (n_targets,)\n Independent term in decision function. Set to 0.0 if\n ``fit_intercept = False``.\n\n n_iter_ : None or ndarray of shape (n_targets,)\n Actual number of iterations for each target. Available only for\n sag and lsqr solvers. Other solvers will return None.\n\n .. versionadded:: 0.17\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n RidgeClassifier : Ridge classifier.\n RidgeCV : Ridge regression with built-in cross validation.\n :class:`~sklearn.kernel_ridge.KernelRidge` : Kernel ridge regression\n combines ridge regression with the kernel trick.\n\n Examples\n --------\n >>> from sklearn.linear_model import Ridge\n >>> import numpy as np\n >>> n_samples, n_features = 10, 5\n >>> rng = np.random.RandomState(0)\n >>> y = rng.randn(n_samples)\n >>> X = rng.randn(n_samples, n_features)\n >>> clf = Ridge(alpha=1.0)\n >>> clf.fit(X, y)\n Ridge()\n \"\"\"\n \n def __init__(self, alpha=1.0, *, fit_intercept=True, normalize='deprecated', copy_X=True, max_iter=None, tol=0.001, solver='auto', positive=False, random_state=None):\n super().__init__(alpha=alpha, fit_intercept=fit_intercept, normalize=normalize, copy_X=copy_X, max_iter=max_iter, tol=tol, solver=solver, positive=positive, random_state=random_state)\n \n def fit(self, X, y, sample_weight=None):\n \"\"\"Fit Ridge regression model.\n\n Parameters\n ----------\n X : {ndarray, sparse matrix} of shape (n_samples, n_features)\n Training data.\n\n y : ndarray of shape (n_samples,) or (n_samples, n_targets)\n Target values.\n\n sample_weight : float or ndarray of shape (n_samples,), default=None\n Individual weights for each sample. If given a float, every sample\n will have the same weight.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n return super().fit(X, y, sample_weight=sample_weight)\n" + "source_code": "\n\nclass Ridge(MultiOutputMixin, RegressorMixin, _BaseRidge):\n \"\"\"Linear least squares with l2 regularization.\n\n Minimizes the objective function::\n\n ||y - Xw||^2_2 + alpha * ||w||^2_2\n\n This model solves a regression model where the loss function is\n the linear least squares function and regularization is given by\n the l2-norm. Also known as Ridge Regression or Tikhonov regularization.\n This estimator has built-in support for multi-variate regression\n (i.e., when y is a 2d-array of shape (n_samples, n_targets)).\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n alpha : {float, ndarray of shape (n_targets,)}, default=1.0\n Regularization strength; must be a positive float. Regularization\n improves the conditioning of the problem and reduces the variance of\n the estimates. Larger values specify stronger regularization.\n Alpha corresponds to ``1 / (2C)`` in other linear models such as\n :class:`~sklearn.linear_model.LogisticRegression` or\n :class:`~sklearn.svm.LinearSVC`. If an array is passed, penalties are\n assumed to be specific to the targets. Hence they must correspond in\n number.\n\n fit_intercept : bool, default=True\n Whether to fit the intercept for this model. If set\n to false, no intercept will be used in calculations\n (i.e. ``X`` and ``y`` are expected to be centered).\n\n normalize : bool, default=False\n This parameter is ignored when ``fit_intercept`` is set to False.\n If True, the regressors X will be normalized before regression by\n subtracting the mean and dividing by the l2-norm.\n If you wish to standardize, please use\n :class:`~sklearn.preprocessing.StandardScaler` before calling ``fit``\n on an estimator with ``normalize=False``.\n\n .. deprecated:: 1.0\n ``normalize`` was deprecated in version 1.0 and\n will be removed in 1.2.\n\n copy_X : bool, default=True\n If True, X will be copied; else, it may be overwritten.\n\n max_iter : int, default=None\n Maximum number of iterations for conjugate gradient solver.\n For 'sparse_cg' and 'lsqr' solvers, the default value is determined\n by scipy.sparse.linalg. For 'sag' solver, the default value is 1000.\n For 'lbfgs' solver, the default value is 15000.\n\n tol : float, default=1e-3\n Precision of the solution.\n\n solver : {'auto', 'svd', 'cholesky', 'lsqr', 'sparse_cg', 'sag', 'saga', 'lbfgs'}, default='auto'\n Solver to use in the computational routines:\n\n - 'auto' chooses the solver automatically based on the type of data.\n\n - 'svd' uses a Singular Value Decomposition of X to compute the Ridge\n coefficients. More stable for singular matrices than 'cholesky'.\n\n - 'cholesky' uses the standard scipy.linalg.solve function to\n obtain a closed-form solution.\n\n - 'sparse_cg' uses the conjugate gradient solver as found in\n scipy.sparse.linalg.cg. As an iterative algorithm, this solver is\n more appropriate than 'cholesky' for large-scale data\n (possibility to set `tol` and `max_iter`).\n\n - 'lsqr' uses the dedicated regularized least-squares routine\n scipy.sparse.linalg.lsqr. It is the fastest and uses an iterative\n procedure.\n\n - 'sag' uses a Stochastic Average Gradient descent, and 'saga' uses\n its improved, unbiased version named SAGA. Both methods also use an\n iterative procedure, and are often faster than other solvers when\n both n_samples and n_features are large. Note that 'sag' and\n 'saga' fast convergence is only guaranteed on features with\n approximately the same scale. You can preprocess the data with a\n scaler from sklearn.preprocessing.\n\n - 'lbfgs' uses L-BFGS-B algorithm implemented in\n `scipy.optimize.minimize`. It can be used only when `positive`\n is True.\n\n All last six solvers support both dense and sparse data. However, only\n 'sag', 'sparse_cg', and 'lbfgs' support sparse input when `fit_intercept`\n is True.\n\n .. versionadded:: 0.17\n Stochastic Average Gradient descent solver.\n .. versionadded:: 0.19\n SAGA solver.\n\n positive : bool, default=False\n When set to ``True``, forces the coefficients to be positive.\n Only 'lbfgs' solver is supported in this case.\n\n random_state : int, RandomState instance, default=None\n Used when ``solver`` == 'sag' or 'saga' to shuffle the data.\n See :term:`Glossary ` for details.\n\n .. versionadded:: 0.17\n `random_state` to support Stochastic Average Gradient.\n\n Attributes\n ----------\n coef_ : ndarray of shape (n_features,) or (n_targets, n_features)\n Weight vector(s).\n\n intercept_ : float or ndarray of shape (n_targets,)\n Independent term in decision function. Set to 0.0 if\n ``fit_intercept = False``.\n\n n_iter_ : None or ndarray of shape (n_targets,)\n Actual number of iterations for each target. Available only for\n sag and lsqr solvers. Other solvers will return None.\n\n .. versionadded:: 0.17\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n RidgeClassifier : Ridge classifier.\n RidgeCV : Ridge regression with built-in cross validation.\n :class:`~sklearn.kernel_ridge.KernelRidge` : Kernel ridge regression\n combines ridge regression with the kernel trick.\n\n Examples\n --------\n >>> from sklearn.linear_model import Ridge\n >>> import numpy as np\n >>> n_samples, n_features = 10, 5\n >>> rng = np.random.RandomState(0)\n >>> y = rng.randn(n_samples)\n >>> X = rng.randn(n_samples, n_features)\n >>> clf = Ridge(alpha=1.0)\n >>> clf.fit(X, y)\n Ridge()\n \"\"\"\n \n def __init__(self, alpha=1.0, *, fit_intercept=True, normalize='deprecated', copy_X=True, max_iter=None, tol=0.001, solver='auto', positive=False, random_state=None):\n super().__init__(alpha=alpha, fit_intercept=fit_intercept, normalize=normalize, copy_X=copy_X, max_iter=max_iter, tol=tol, solver=solver, positive=positive, random_state=random_state)\n \n def fit(self, X, y, sample_weight=None):\n \"\"\"Fit Ridge regression model.\n\n Parameters\n ----------\n X : {ndarray, sparse matrix} of shape (n_samples, n_features)\n Training data.\n\n y : ndarray of shape (n_samples,) or (n_samples, n_targets)\n Target values.\n\n sample_weight : float or ndarray of shape (n_samples,), default=None\n Individual weights for each sample. If given a float, every sample\n will have the same weight.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n _accept_sparse = _get_valid_accept_sparse(sparse.issparse(X), self.solver)\n (X, y) = self._validate_data(X, y, accept_sparse=_accept_sparse, dtype=[np.float64, np.float32], multi_output=True, y_numeric=True)\n return super().fit(X, y, sample_weight=sample_weight)\n" }, { "name": "RidgeCV", @@ -23993,7 +23946,7 @@ "methods": [ "sklearn.linear_model._ridge.RidgeClassifier.__init__", "sklearn.linear_model._ridge.RidgeClassifier.fit", - "sklearn.linear_model._ridge.RidgeClassifier.classes_" + "sklearn.linear_model._ridge.RidgeClassifier.classes_@getter" ], "is_public": true, "description": "Classifier using Ridge regression.\n\nThis classifier first converts the target values into ``{-1, 1}`` and then treats the problem as a regression task (multi-output regression in the multiclass case). Read more in the :ref:`User Guide `.", @@ -24008,7 +23961,7 @@ "methods": [ "sklearn.linear_model._ridge.RidgeClassifierCV.__init__", "sklearn.linear_model._ridge.RidgeClassifierCV.fit", - "sklearn.linear_model._ridge.RidgeClassifierCV.classes_", + "sklearn.linear_model._ridge.RidgeClassifierCV.classes_@getter", "sklearn.linear_model._ridge.RidgeClassifierCV._more_tags" ], "is_public": true, @@ -24028,7 +23981,7 @@ "is_public": false, "description": "", "docstring": null, - "source_code": "\n\nclass _BaseRidge(LinearModel, metaclass=ABCMeta):\n \n @abstractmethod\n def __init__(self, alpha=1.0, *, fit_intercept=True, normalize='deprecated', copy_X=True, max_iter=None, tol=0.001, solver='auto', positive=False, random_state=None):\n self.alpha = alpha\n self.fit_intercept = fit_intercept\n self.normalize = normalize\n self.copy_X = copy_X\n self.max_iter = max_iter\n self.tol = tol\n self.solver = solver\n self.positive = positive\n self.random_state = random_state\n \n def fit(self, X, y, sample_weight=None):\n self._normalize = _deprecate_normalize(self.normalize, default=False, estimator_name=self.__class__.__name__)\n _dtype = [np.float64, np.float32]\n _accept_sparse = _get_valid_accept_sparse(sparse.issparse(X), self.solver)\n (X, y) = self._validate_data(X, y, accept_sparse=_accept_sparse, dtype=_dtype, multi_output=True, y_numeric=True)\n if self.solver == 'lbfgs' and not self.positive:\n raise ValueError(\"'lbfgs' solver can be used only when positive=True. Please use another solver.\")\n if self.positive:\n if self.solver not in ['auto', 'lbfgs']:\n raise ValueError(f\"solver='{self.solver}' does not support positive fitting. Please set the solver to 'auto' or 'lbfgs', or set `positive=False`\")\n else:\n solver = self.solver\n elif sparse.issparse(X) and self.fit_intercept:\n if self.solver not in ['auto', 'sparse_cg', 'sag', 'lbfgs']:\n raise ValueError(\"solver='{}' does not support fitting the intercept on sparse data. Please set the solver to 'auto' or 'sparse_cg', 'sag', 'lbfgs' or set `fit_intercept=False`\".format(self.solver))\n if self.solver == 'lbfgs':\n solver = 'lbfgs'\n elif self.solver == 'sag' and self.max_iter is None and self.tol > 0.0001:\n warnings.warn('\"sag\" solver requires many iterations to fit an intercept with sparse inputs. Either set the solver to \"auto\" or \"sparse_cg\", or set a low \"tol\" and a high \"max_iter\" (especially if inputs are not standardized).')\n solver = 'sag'\n else:\n solver = 'sparse_cg'\n else:\n solver = self.solver\n if sample_weight is not None:\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n (X, y, X_offset, y_offset, X_scale) = self._preprocess_data(X, y, self.fit_intercept, self._normalize, self.copy_X, sample_weight=sample_weight, return_mean=True)\n if solver == 'sag' and sparse.issparse(X) and self.fit_intercept:\n (self.coef_, self.n_iter_, self.intercept_) = _ridge_regression(X, y, alpha=self.alpha, sample_weight=sample_weight, max_iter=self.max_iter, tol=self.tol, solver='sag', positive=self.positive, random_state=self.random_state, return_n_iter=True, return_intercept=True, check_input=False)\n self.intercept_ += y_offset\n else:\n if sparse.issparse(X) and self.fit_intercept:\n params = {'X_offset': X_offset, 'X_scale': X_scale}\n else:\n params = {}\n (self.coef_, self.n_iter_) = _ridge_regression(X, y, alpha=self.alpha, sample_weight=sample_weight, max_iter=self.max_iter, tol=self.tol, solver=solver, positive=self.positive, random_state=self.random_state, return_n_iter=True, return_intercept=False, check_input=False, **params)\n self._set_intercept(X_offset, y_offset, X_scale)\n return self\n" + "source_code": "\n\nclass _BaseRidge(LinearModel, metaclass=ABCMeta):\n \n @abstractmethod\n def __init__(self, alpha=1.0, *, fit_intercept=True, normalize='deprecated', copy_X=True, max_iter=None, tol=0.001, solver='auto', positive=False, random_state=None):\n self.alpha = alpha\n self.fit_intercept = fit_intercept\n self.normalize = normalize\n self.copy_X = copy_X\n self.max_iter = max_iter\n self.tol = tol\n self.solver = solver\n self.positive = positive\n self.random_state = random_state\n \n def fit(self, X, y, sample_weight=None):\n self._normalize = _deprecate_normalize(self.normalize, default=False, estimator_name=self.__class__.__name__)\n if self.solver == 'lbfgs' and not self.positive:\n raise ValueError(\"'lbfgs' solver can be used only when positive=True. Please use another solver.\")\n if self.positive:\n if self.solver not in ['auto', 'lbfgs']:\n raise ValueError(f\"solver='{self.solver}' does not support positive fitting. Please set the solver to 'auto' or 'lbfgs', or set `positive=False`\")\n else:\n solver = self.solver\n elif sparse.issparse(X) and self.fit_intercept:\n if self.solver not in ['auto', 'sparse_cg', 'sag', 'lbfgs']:\n raise ValueError(\"solver='{}' does not support fitting the intercept on sparse data. Please set the solver to 'auto' or 'sparse_cg', 'sag', 'lbfgs' or set `fit_intercept=False`\".format(self.solver))\n if self.solver == 'lbfgs':\n solver = 'lbfgs'\n elif self.solver == 'sag' and self.max_iter is None and self.tol > 0.0001:\n warnings.warn('\"sag\" solver requires many iterations to fit an intercept with sparse inputs. Either set the solver to \"auto\" or \"sparse_cg\", or set a low \"tol\" and a high \"max_iter\" (especially if inputs are not standardized).')\n solver = 'sag'\n else:\n solver = 'sparse_cg'\n else:\n solver = self.solver\n if sample_weight is not None:\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n (X, y, X_offset, y_offset, X_scale) = self._preprocess_data(X, y, self.fit_intercept, self._normalize, self.copy_X, sample_weight=sample_weight, return_mean=True)\n if solver == 'sag' and sparse.issparse(X) and self.fit_intercept:\n (self.coef_, self.n_iter_, self.intercept_) = _ridge_regression(X, y, alpha=self.alpha, sample_weight=sample_weight, max_iter=self.max_iter, tol=self.tol, solver='sag', positive=self.positive, random_state=self.random_state, return_n_iter=True, return_intercept=True, check_input=False)\n self.intercept_ += y_offset\n else:\n if sparse.issparse(X) and self.fit_intercept:\n params = {'X_offset': X_offset, 'X_scale': X_scale}\n else:\n params = {}\n (self.coef_, self.n_iter_) = _ridge_regression(X, y, alpha=self.alpha, sample_weight=sample_weight, max_iter=self.max_iter, tol=self.tol, solver=solver, positive=self.positive, random_state=self.random_state, return_n_iter=True, return_intercept=False, check_input=False, **params)\n self._set_intercept(X_offset, y_offset, X_scale)\n return self\n" }, { "name": "_BaseRidgeCV", @@ -24168,7 +24121,7 @@ "is_public": false, "description": "", "docstring": null, - "source_code": "\n\nclass BaseSGDClassifier(LinearClassifierMixin, BaseSGD, metaclass=ABCMeta):\n loss_functions = {'hinge': (Hinge, 1.0), 'squared_hinge': (SquaredHinge, 1.0), 'perceptron': (Hinge, 0.0), 'log': (Log, ), 'modified_huber': (ModifiedHuber, ), 'squared_error': (SquaredLoss, ), 'squared_loss': (SquaredLoss, ), 'huber': (Huber, DEFAULT_EPSILON), 'epsilon_insensitive': (EpsilonInsensitive, DEFAULT_EPSILON), 'squared_epsilon_insensitive': (SquaredEpsilonInsensitive, DEFAULT_EPSILON)}\n \n @abstractmethod\n def __init__(self, loss='hinge', *, penalty='l2', alpha=0.0001, l1_ratio=0.15, fit_intercept=True, max_iter=1000, tol=0.001, shuffle=True, verbose=0, epsilon=DEFAULT_EPSILON, n_jobs=None, random_state=None, learning_rate='optimal', eta0=0.0, power_t=0.5, early_stopping=False, validation_fraction=0.1, n_iter_no_change=5, class_weight=None, warm_start=False, average=False):\n super().__init__(loss=loss, penalty=penalty, alpha=alpha, l1_ratio=l1_ratio, fit_intercept=fit_intercept, max_iter=max_iter, tol=tol, shuffle=shuffle, verbose=verbose, epsilon=epsilon, random_state=random_state, learning_rate=learning_rate, eta0=eta0, power_t=power_t, early_stopping=early_stopping, validation_fraction=validation_fraction, n_iter_no_change=n_iter_no_change, warm_start=warm_start, average=average)\n self.class_weight = class_weight\n self.n_jobs = n_jobs\n \n def _partial_fit(self, X, y, alpha, C, loss, learning_rate, max_iter, classes, sample_weight, coef_init, intercept_init):\n first_call = not hasattr(self, 'classes_')\n (X, y) = self._validate_data(X, y, accept_sparse='csr', dtype=np.float64, order='C', accept_large_sparse=False, reset=first_call)\n (n_samples, n_features) = X.shape\n _check_partial_fit_first_call(self, classes)\n n_classes = self.classes_.shape[0]\n self._expanded_class_weight = compute_class_weight(self.class_weight, classes=self.classes_, y=y)\n sample_weight = _check_sample_weight(sample_weight, X)\n if getattr(self, 'coef_', None) is None or coef_init is not None:\n self._allocate_parameter_mem(n_classes, n_features, coef_init, intercept_init)\n elif n_features != self.coef_.shape[-1]:\n raise ValueError('Number of features %d does not match previous data %d.' % (n_features, self.coef_.shape[-1]))\n self.loss_function_ = self._get_loss_function(loss)\n if not hasattr(self, 't_'):\n self.t_ = 1.0\n if n_classes > 2:\n self._fit_multiclass(X, y, alpha=alpha, C=C, learning_rate=learning_rate, sample_weight=sample_weight, max_iter=max_iter)\n elif n_classes == 2:\n self._fit_binary(X, y, alpha=alpha, C=C, learning_rate=learning_rate, sample_weight=sample_weight, max_iter=max_iter)\n else:\n raise ValueError('The number of classes has to be greater than one; got %d class' % n_classes)\n return self\n \n def _fit(self, X, y, alpha, C, loss, learning_rate, coef_init=None, intercept_init=None, sample_weight=None):\n self._validate_params()\n if hasattr(self, 'classes_'):\n self.classes_ = None\n (X, y) = self._validate_data(X, y, accept_sparse='csr', dtype=np.float64, order='C', accept_large_sparse=False)\n classes = np.unique(y)\n if self.warm_start and hasattr(self, 'coef_'):\n if coef_init is None:\n coef_init = self.coef_\n if intercept_init is None:\n intercept_init = self.intercept_\n else:\n self.coef_ = None\n self.intercept_ = None\n if self.average > 0:\n self._standard_coef = self.coef_\n self._standard_intercept = self.intercept_\n self._average_coef = None\n self._average_intercept = None\n self.t_ = 1.0\n self._partial_fit(X, y, alpha, C, loss, learning_rate, self.max_iter, classes, sample_weight, coef_init, intercept_init)\n if self.tol is not None and self.tol > -np.inf and self.n_iter_ == self.max_iter:\n warnings.warn('Maximum number of iteration reached before convergence. Consider increasing max_iter to improve the fit.', ConvergenceWarning)\n return self\n \n def _fit_binary(self, X, y, alpha, C, sample_weight, learning_rate, max_iter):\n \"\"\"Fit a binary classifier on X and y.\"\"\"\n (coef, intercept, n_iter_) = fit_binary(self, 1, X, y, alpha, C, learning_rate, max_iter, self._expanded_class_weight[1], self._expanded_class_weight[0], sample_weight, random_state=self.random_state)\n self.t_ += n_iter_ * X.shape[0]\n self.n_iter_ = n_iter_\n if self.average > 0:\n if self.average <= self.t_ - 1:\n self.coef_ = self._average_coef.reshape(1, -1)\n self.intercept_ = self._average_intercept\n else:\n self.coef_ = self._standard_coef.reshape(1, -1)\n self._standard_intercept = np.atleast_1d(intercept)\n self.intercept_ = self._standard_intercept\n else:\n self.coef_ = coef.reshape(1, -1)\n self.intercept_ = np.atleast_1d(intercept)\n \n def _fit_multiclass(self, X, y, alpha, C, learning_rate, sample_weight, max_iter):\n \"\"\"Fit a multi-class classifier by combining binary classifiers\n\n Each binary classifier predicts one class versus all others. This\n strategy is called OvA (One versus All) or OvR (One versus Rest).\n \"\"\"\n validation_mask = self._make_validation_split(y)\n random_state = check_random_state(self.random_state)\n seeds = random_state.randint(MAX_INT, size=len(self.classes_))\n result = Parallel(n_jobs=self.n_jobs, verbose=self.verbose, **_joblib_parallel_args(require='sharedmem'))((delayed(fit_binary)(self, i, X, y, alpha, C, learning_rate, max_iter, self._expanded_class_weight[i], 1.0, sample_weight, validation_mask=validation_mask, random_state=seed) for (i, seed) in enumerate(seeds)))\n n_iter_ = 0.0\n for (i, (_, intercept, n_iter_i)) in enumerate(result):\n self.intercept_[i] = intercept\n n_iter_ = max(n_iter_, n_iter_i)\n self.t_ += n_iter_ * X.shape[0]\n self.n_iter_ = n_iter_\n if self.average > 0:\n if self.average <= self.t_ - 1.0:\n self.coef_ = self._average_coef\n self.intercept_ = self._average_intercept\n else:\n self.coef_ = self._standard_coef\n self._standard_intercept = np.atleast_1d(self.intercept_)\n self.intercept_ = self._standard_intercept\n \n def partial_fit(self, X, y, classes=None, sample_weight=None):\n \"\"\"Perform one epoch of stochastic gradient descent on given samples.\n\n Internally, this method uses ``max_iter = 1``. Therefore, it is not\n guaranteed that a minimum of the cost function is reached after calling\n it once. Matters such as objective convergence, early stopping, and\n learning rate adjustments should be handled by the user.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Subset of the training data.\n\n y : ndarray of shape (n_samples,)\n Subset of the target values.\n\n classes : ndarray of shape (n_classes,), default=None\n Classes across all calls to partial_fit.\n Can be obtained by via `np.unique(y_all)`, where y_all is the\n target vector of the entire dataset.\n This argument is required for the first call to partial_fit\n and can be omitted in the subsequent calls.\n Note that y doesn't need to contain all labels in `classes`.\n\n sample_weight : array-like, shape (n_samples,), default=None\n Weights applied to individual samples.\n If not provided, uniform weights are assumed.\n\n Returns\n -------\n self : object\n Returns an instance of self.\n \"\"\"\n self._validate_params(for_partial_fit=True)\n if self.class_weight in ['balanced']:\n raise ValueError(\"class_weight '{0}' is not supported for partial_fit. In order to use 'balanced' weights, use compute_class_weight('{0}', classes=classes, y=y). In place of y you can us a large enough sample of the full training set target to properly estimate the class frequency distributions. Pass the resulting weights as the class_weight parameter.\".format(self.class_weight))\n return self._partial_fit(X, y, alpha=self.alpha, C=1.0, loss=self.loss, learning_rate=self.learning_rate, max_iter=1, classes=classes, sample_weight=sample_weight, coef_init=None, intercept_init=None)\n \n def fit(self, X, y, coef_init=None, intercept_init=None, sample_weight=None):\n \"\"\"Fit linear model with Stochastic Gradient Descent.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Training data.\n\n y : ndarray of shape (n_samples,)\n Target values.\n\n coef_init : ndarray of shape (n_classes, n_features), default=None\n The initial coefficients to warm-start the optimization.\n\n intercept_init : ndarray of shape (n_classes,), default=None\n The initial intercept to warm-start the optimization.\n\n sample_weight : array-like, shape (n_samples,), default=None\n Weights applied to individual samples.\n If not provided, uniform weights are assumed. These weights will\n be multiplied with class_weight (passed through the\n constructor) if class_weight is specified.\n\n Returns\n -------\n self : object\n Returns an instance of self.\n \"\"\"\n return self._fit(X, y, alpha=self.alpha, C=1.0, loss=self.loss, learning_rate=self.learning_rate, coef_init=coef_init, intercept_init=intercept_init, sample_weight=sample_weight)\n" + "source_code": "\n\nclass BaseSGDClassifier(LinearClassifierMixin, BaseSGD, metaclass=ABCMeta):\n loss_functions = {'hinge': (Hinge, 1.0), 'squared_hinge': (SquaredHinge, 1.0), 'perceptron': (Hinge, 0.0), 'log': (Log, ), 'modified_huber': (ModifiedHuber, ), 'squared_error': (SquaredLoss, ), 'squared_loss': (SquaredLoss, ), 'huber': (Huber, DEFAULT_EPSILON), 'epsilon_insensitive': (EpsilonInsensitive, DEFAULT_EPSILON), 'squared_epsilon_insensitive': (SquaredEpsilonInsensitive, DEFAULT_EPSILON)}\n \n @abstractmethod\n def __init__(self, loss='hinge', *, penalty='l2', alpha=0.0001, l1_ratio=0.15, fit_intercept=True, max_iter=1000, tol=0.001, shuffle=True, verbose=0, epsilon=DEFAULT_EPSILON, n_jobs=None, random_state=None, learning_rate='optimal', eta0=0.0, power_t=0.5, early_stopping=False, validation_fraction=0.1, n_iter_no_change=5, class_weight=None, warm_start=False, average=False):\n super().__init__(loss=loss, penalty=penalty, alpha=alpha, l1_ratio=l1_ratio, fit_intercept=fit_intercept, max_iter=max_iter, tol=tol, shuffle=shuffle, verbose=verbose, epsilon=epsilon, random_state=random_state, learning_rate=learning_rate, eta0=eta0, power_t=power_t, early_stopping=early_stopping, validation_fraction=validation_fraction, n_iter_no_change=n_iter_no_change, warm_start=warm_start, average=average)\n self.class_weight = class_weight\n self.n_jobs = n_jobs\n \n def _partial_fit(self, X, y, alpha, C, loss, learning_rate, max_iter, classes, sample_weight, coef_init, intercept_init):\n first_call = not hasattr(self, 'classes_')\n (X, y) = self._validate_data(X, y, accept_sparse='csr', dtype=np.float64, order='C', accept_large_sparse=False, reset=first_call)\n (n_samples, n_features) = X.shape\n _check_partial_fit_first_call(self, classes)\n n_classes = self.classes_.shape[0]\n self._expanded_class_weight = compute_class_weight(self.class_weight, classes=self.classes_, y=y)\n sample_weight = _check_sample_weight(sample_weight, X)\n if getattr(self, 'coef_', None) is None or coef_init is not None:\n self._allocate_parameter_mem(n_classes, n_features, coef_init, intercept_init)\n elif n_features != self.coef_.shape[-1]:\n raise ValueError('Number of features %d does not match previous data %d.' % (n_features, self.coef_.shape[-1]))\n self.loss_function_ = self._get_loss_function(loss)\n if not hasattr(self, 't_'):\n self.t_ = 1.0\n if n_classes > 2:\n self._fit_multiclass(X, y, alpha=alpha, C=C, learning_rate=learning_rate, sample_weight=sample_weight, max_iter=max_iter)\n elif n_classes == 2:\n self._fit_binary(X, y, alpha=alpha, C=C, learning_rate=learning_rate, sample_weight=sample_weight, max_iter=max_iter)\n else:\n raise ValueError('The number of classes has to be greater than one; got %d class' % n_classes)\n return self\n \n def _fit(self, X, y, alpha, C, loss, learning_rate, coef_init=None, intercept_init=None, sample_weight=None):\n self._validate_params()\n if hasattr(self, 'classes_'):\n delattr(self, 'classes_')\n y = self._validate_data(y=y)\n classes = np.unique(y)\n if self.warm_start and hasattr(self, 'coef_'):\n if coef_init is None:\n coef_init = self.coef_\n if intercept_init is None:\n intercept_init = self.intercept_\n else:\n self.coef_ = None\n self.intercept_ = None\n if self.average > 0:\n self._standard_coef = self.coef_\n self._standard_intercept = self.intercept_\n self._average_coef = None\n self._average_intercept = None\n self.t_ = 1.0\n self._partial_fit(X, y, alpha, C, loss, learning_rate, self.max_iter, classes, sample_weight, coef_init, intercept_init)\n if self.tol is not None and self.tol > -np.inf and self.n_iter_ == self.max_iter:\n warnings.warn('Maximum number of iteration reached before convergence. Consider increasing max_iter to improve the fit.', ConvergenceWarning)\n return self\n \n def _fit_binary(self, X, y, alpha, C, sample_weight, learning_rate, max_iter):\n \"\"\"Fit a binary classifier on X and y.\"\"\"\n (coef, intercept, n_iter_) = fit_binary(self, 1, X, y, alpha, C, learning_rate, max_iter, self._expanded_class_weight[1], self._expanded_class_weight[0], sample_weight, random_state=self.random_state)\n self.t_ += n_iter_ * X.shape[0]\n self.n_iter_ = n_iter_\n if self.average > 0:\n if self.average <= self.t_ - 1:\n self.coef_ = self._average_coef.reshape(1, -1)\n self.intercept_ = self._average_intercept\n else:\n self.coef_ = self._standard_coef.reshape(1, -1)\n self._standard_intercept = np.atleast_1d(intercept)\n self.intercept_ = self._standard_intercept\n else:\n self.coef_ = coef.reshape(1, -1)\n self.intercept_ = np.atleast_1d(intercept)\n \n def _fit_multiclass(self, X, y, alpha, C, learning_rate, sample_weight, max_iter):\n \"\"\"Fit a multi-class classifier by combining binary classifiers\n\n Each binary classifier predicts one class versus all others. This\n strategy is called OvA (One versus All) or OvR (One versus Rest).\n \"\"\"\n validation_mask = self._make_validation_split(y)\n random_state = check_random_state(self.random_state)\n seeds = random_state.randint(MAX_INT, size=len(self.classes_))\n result = Parallel(n_jobs=self.n_jobs, verbose=self.verbose, **_joblib_parallel_args(require='sharedmem'))((delayed(fit_binary)(self, i, X, y, alpha, C, learning_rate, max_iter, self._expanded_class_weight[i], 1.0, sample_weight, validation_mask=validation_mask, random_state=seed) for (i, seed) in enumerate(seeds)))\n n_iter_ = 0.0\n for (i, (_, intercept, n_iter_i)) in enumerate(result):\n self.intercept_[i] = intercept\n n_iter_ = max(n_iter_, n_iter_i)\n self.t_ += n_iter_ * X.shape[0]\n self.n_iter_ = n_iter_\n if self.average > 0:\n if self.average <= self.t_ - 1.0:\n self.coef_ = self._average_coef\n self.intercept_ = self._average_intercept\n else:\n self.coef_ = self._standard_coef\n self._standard_intercept = np.atleast_1d(self.intercept_)\n self.intercept_ = self._standard_intercept\n \n def partial_fit(self, X, y, classes=None, sample_weight=None):\n \"\"\"Perform one epoch of stochastic gradient descent on given samples.\n\n Internally, this method uses ``max_iter = 1``. Therefore, it is not\n guaranteed that a minimum of the cost function is reached after calling\n it once. Matters such as objective convergence, early stopping, and\n learning rate adjustments should be handled by the user.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Subset of the training data.\n\n y : ndarray of shape (n_samples,)\n Subset of the target values.\n\n classes : ndarray of shape (n_classes,), default=None\n Classes across all calls to partial_fit.\n Can be obtained by via `np.unique(y_all)`, where y_all is the\n target vector of the entire dataset.\n This argument is required for the first call to partial_fit\n and can be omitted in the subsequent calls.\n Note that y doesn't need to contain all labels in `classes`.\n\n sample_weight : array-like, shape (n_samples,), default=None\n Weights applied to individual samples.\n If not provided, uniform weights are assumed.\n\n Returns\n -------\n self : object\n Returns an instance of self.\n \"\"\"\n self._validate_params(for_partial_fit=True)\n if self.class_weight in ['balanced']:\n raise ValueError(\"class_weight '{0}' is not supported for partial_fit. In order to use 'balanced' weights, use compute_class_weight('{0}', classes=classes, y=y). In place of y you can us a large enough sample of the full training set target to properly estimate the class frequency distributions. Pass the resulting weights as the class_weight parameter.\".format(self.class_weight))\n return self._partial_fit(X, y, alpha=self.alpha, C=1.0, loss=self.loss, learning_rate=self.learning_rate, max_iter=1, classes=classes, sample_weight=sample_weight, coef_init=None, intercept_init=None)\n \n def fit(self, X, y, coef_init=None, intercept_init=None, sample_weight=None):\n \"\"\"Fit linear model with Stochastic Gradient Descent.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Training data.\n\n y : ndarray of shape (n_samples,)\n Target values.\n\n coef_init : ndarray of shape (n_classes, n_features), default=None\n The initial coefficients to warm-start the optimization.\n\n intercept_init : ndarray of shape (n_classes,), default=None\n The initial intercept to warm-start the optimization.\n\n sample_weight : array-like, shape (n_samples,), default=None\n Weights applied to individual samples.\n If not provided, uniform weights are assumed. These weights will\n be multiplied with class_weight (passed through the\n constructor) if class_weight is specified.\n\n Returns\n -------\n self : object\n Returns an instance of self.\n \"\"\"\n return self._fit(X, y, alpha=self.alpha, C=1.0, loss=self.loss, learning_rate=self.learning_rate, coef_init=coef_init, intercept_init=intercept_init, sample_weight=sample_weight)\n" }, { "name": "BaseSGDRegressor", @@ -24188,7 +24141,7 @@ "is_public": false, "description": "", "docstring": null, - "source_code": "\n\nclass BaseSGDRegressor(RegressorMixin, BaseSGD):\n loss_functions = {'squared_error': (SquaredLoss, ), 'squared_loss': (SquaredLoss, ), 'huber': (Huber, DEFAULT_EPSILON), 'epsilon_insensitive': (EpsilonInsensitive, DEFAULT_EPSILON), 'squared_epsilon_insensitive': (SquaredEpsilonInsensitive, DEFAULT_EPSILON)}\n \n @abstractmethod\n def __init__(self, loss='squared_error', *, penalty='l2', alpha=0.0001, l1_ratio=0.15, fit_intercept=True, max_iter=1000, tol=0.001, shuffle=True, verbose=0, epsilon=DEFAULT_EPSILON, random_state=None, learning_rate='invscaling', eta0=0.01, power_t=0.25, early_stopping=False, validation_fraction=0.1, n_iter_no_change=5, warm_start=False, average=False):\n super().__init__(loss=loss, penalty=penalty, alpha=alpha, l1_ratio=l1_ratio, fit_intercept=fit_intercept, max_iter=max_iter, tol=tol, shuffle=shuffle, verbose=verbose, epsilon=epsilon, random_state=random_state, learning_rate=learning_rate, eta0=eta0, power_t=power_t, early_stopping=early_stopping, validation_fraction=validation_fraction, n_iter_no_change=n_iter_no_change, warm_start=warm_start, average=average)\n \n def _partial_fit(self, X, y, alpha, C, loss, learning_rate, max_iter, sample_weight, coef_init, intercept_init):\n first_call = getattr(self, 'coef_', None) is None\n (X, y) = self._validate_data(X, y, accept_sparse='csr', copy=False, order='C', dtype=np.float64, accept_large_sparse=False, reset=first_call)\n y = y.astype(np.float64, copy=False)\n (n_samples, n_features) = X.shape\n sample_weight = _check_sample_weight(sample_weight, X)\n if first_call:\n self._allocate_parameter_mem(1, n_features, coef_init, intercept_init)\n if self.average > 0 and getattr(self, '_average_coef', None) is None:\n self._average_coef = np.zeros(n_features, dtype=np.float64, order='C')\n self._average_intercept = np.zeros(1, dtype=np.float64, order='C')\n self._fit_regressor(X, y, alpha, C, loss, learning_rate, sample_weight, max_iter)\n return self\n \n def partial_fit(self, X, y, sample_weight=None):\n \"\"\"Perform one epoch of stochastic gradient descent on given samples.\n\n Internally, this method uses ``max_iter = 1``. Therefore, it is not\n guaranteed that a minimum of the cost function is reached after calling\n it once. Matters such as objective convergence and early stopping\n should be handled by the user.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Subset of training data\n\n y : numpy array of shape (n_samples,)\n Subset of target values\n\n sample_weight : array-like, shape (n_samples,), default=None\n Weights applied to individual samples.\n If not provided, uniform weights are assumed.\n\n Returns\n -------\n self : returns an instance of self.\n \"\"\"\n self._validate_params(for_partial_fit=True)\n return self._partial_fit(X, y, self.alpha, C=1.0, loss=self.loss, learning_rate=self.learning_rate, max_iter=1, sample_weight=sample_weight, coef_init=None, intercept_init=None)\n \n def _fit(self, X, y, alpha, C, loss, learning_rate, coef_init=None, intercept_init=None, sample_weight=None):\n self._validate_params()\n if self.warm_start and getattr(self, 'coef_', None) is not None:\n if coef_init is None:\n coef_init = self.coef_\n if intercept_init is None:\n intercept_init = self.intercept_\n else:\n self.coef_ = None\n self.intercept_ = None\n self.t_ = 1.0\n self._partial_fit(X, y, alpha, C, loss, learning_rate, self.max_iter, sample_weight, coef_init, intercept_init)\n if self.tol is not None and self.tol > -np.inf and self.n_iter_ == self.max_iter:\n warnings.warn('Maximum number of iteration reached before convergence. Consider increasing max_iter to improve the fit.', ConvergenceWarning)\n return self\n \n def fit(self, X, y, coef_init=None, intercept_init=None, sample_weight=None):\n \"\"\"Fit linear model with Stochastic Gradient Descent.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Training data\n\n y : ndarray of shape (n_samples,)\n Target values\n\n coef_init : ndarray of shape (n_features,), default=None\n The initial coefficients to warm-start the optimization.\n\n intercept_init : ndarray of shape (1,), default=None\n The initial intercept to warm-start the optimization.\n\n sample_weight : array-like, shape (n_samples,), default=None\n Weights applied to individual samples (1. for unweighted).\n\n Returns\n -------\n self : returns an instance of self.\n \"\"\"\n return self._fit(X, y, alpha=self.alpha, C=1.0, loss=self.loss, learning_rate=self.learning_rate, coef_init=coef_init, intercept_init=intercept_init, sample_weight=sample_weight)\n \n def _decision_function(self, X):\n \"\"\"Predict using the linear model\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n\n Returns\n -------\n ndarray of shape (n_samples,)\n Predicted target values per element in X.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse='csr', reset=False)\n scores = safe_sparse_dot(X, self.coef_.T, dense_output=True) + self.intercept_\n return scores.ravel()\n \n def predict(self, X):\n \"\"\"Predict using the linear model\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n\n Returns\n -------\n ndarray of shape (n_samples,)\n Predicted target values per element in X.\n \"\"\"\n return self._decision_function(X)\n \n def _fit_regressor(self, X, y, alpha, C, loss, learning_rate, sample_weight, max_iter):\n (dataset, intercept_decay) = make_dataset(X, y, sample_weight)\n loss_function = self._get_loss_function(loss)\n penalty_type = self._get_penalty_type(self.penalty)\n learning_rate_type = self._get_learning_rate_type(learning_rate)\n if not hasattr(self, 't_'):\n self.t_ = 1.0\n validation_mask = self._make_validation_split(y)\n validation_score_cb = self._make_validation_score_cb(validation_mask, X, y, sample_weight)\n random_state = check_random_state(self.random_state)\n seed = random_state.randint(0, np.iinfo(np.int32).max)\n tol = self.tol if self.tol is not None else -np.inf\n if self.average:\n coef = self._standard_coef\n intercept = self._standard_intercept\n average_coef = self._average_coef\n average_intercept = self._average_intercept\n else:\n coef = self.coef_\n intercept = self.intercept_\n average_coef = None\n average_intercept = [0]\n (coef, intercept, average_coef, average_intercept, self.n_iter_) = _plain_sgd(coef, intercept[0], average_coef, average_intercept[0], loss_function, penalty_type, alpha, C, self.l1_ratio, dataset, validation_mask, self.early_stopping, validation_score_cb, int(self.n_iter_no_change), max_iter, tol, int(self.fit_intercept), int(self.verbose), int(self.shuffle), seed, 1.0, 1.0, learning_rate_type, self.eta0, self.power_t, 0, self.t_, intercept_decay, self.average)\n self.t_ += self.n_iter_ * X.shape[0]\n if self.average > 0:\n self._average_intercept = np.atleast_1d(average_intercept)\n self._standard_intercept = np.atleast_1d(intercept)\n if self.average <= self.t_ - 1.0:\n self.coef_ = average_coef\n self.intercept_ = np.atleast_1d(average_intercept)\n else:\n self.coef_ = coef\n self.intercept_ = np.atleast_1d(intercept)\n else:\n self.intercept_ = np.atleast_1d(intercept)\n" + "source_code": "\n\nclass BaseSGDRegressor(RegressorMixin, BaseSGD):\n loss_functions = {'squared_error': (SquaredLoss, ), 'squared_loss': (SquaredLoss, ), 'huber': (Huber, DEFAULT_EPSILON), 'epsilon_insensitive': (EpsilonInsensitive, DEFAULT_EPSILON), 'squared_epsilon_insensitive': (SquaredEpsilonInsensitive, DEFAULT_EPSILON)}\n \n @abstractmethod\n def __init__(self, loss='squared_error', *, penalty='l2', alpha=0.0001, l1_ratio=0.15, fit_intercept=True, max_iter=1000, tol=0.001, shuffle=True, verbose=0, epsilon=DEFAULT_EPSILON, random_state=None, learning_rate='invscaling', eta0=0.01, power_t=0.25, early_stopping=False, validation_fraction=0.1, n_iter_no_change=5, warm_start=False, average=False):\n super().__init__(loss=loss, penalty=penalty, alpha=alpha, l1_ratio=l1_ratio, fit_intercept=fit_intercept, max_iter=max_iter, tol=tol, shuffle=shuffle, verbose=verbose, epsilon=epsilon, random_state=random_state, learning_rate=learning_rate, eta0=eta0, power_t=power_t, early_stopping=early_stopping, validation_fraction=validation_fraction, n_iter_no_change=n_iter_no_change, warm_start=warm_start, average=average)\n \n def _partial_fit(self, X, y, alpha, C, loss, learning_rate, max_iter, sample_weight, coef_init, intercept_init):\n first_call = getattr(self, 'coef_', None) is None\n (X, y) = self._validate_data(X, y, accept_sparse='csr', copy=False, order='C', dtype=np.float64, accept_large_sparse=False, reset=first_call)\n y = y.astype(np.float64, copy=False)\n (n_samples, n_features) = X.shape\n sample_weight = _check_sample_weight(sample_weight, X)\n if first_call:\n self._allocate_parameter_mem(1, n_features, coef_init, intercept_init)\n if self.average > 0 and getattr(self, '_average_coef', None) is None:\n self._average_coef = np.zeros(n_features, dtype=np.float64, order='C')\n self._average_intercept = np.zeros(1, dtype=np.float64, order='C')\n self._fit_regressor(X, y, alpha, C, loss, learning_rate, sample_weight, max_iter)\n return self\n \n def partial_fit(self, X, y, sample_weight=None):\n \"\"\"Perform one epoch of stochastic gradient descent on given samples.\n\n Internally, this method uses ``max_iter = 1``. Therefore, it is not\n guaranteed that a minimum of the cost function is reached after calling\n it once. Matters such as objective convergence and early stopping\n should be handled by the user.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Subset of training data.\n\n y : numpy array of shape (n_samples,)\n Subset of target values.\n\n sample_weight : array-like, shape (n_samples,), default=None\n Weights applied to individual samples.\n If not provided, uniform weights are assumed.\n\n Returns\n -------\n self : object\n Returns an instance of self.\n \"\"\"\n self._validate_params(for_partial_fit=True)\n return self._partial_fit(X, y, self.alpha, C=1.0, loss=self.loss, learning_rate=self.learning_rate, max_iter=1, sample_weight=sample_weight, coef_init=None, intercept_init=None)\n \n def _fit(self, X, y, alpha, C, loss, learning_rate, coef_init=None, intercept_init=None, sample_weight=None):\n self._validate_params()\n if self.warm_start and getattr(self, 'coef_', None) is not None:\n if coef_init is None:\n coef_init = self.coef_\n if intercept_init is None:\n intercept_init = self.intercept_\n else:\n self.coef_ = None\n self.intercept_ = None\n self.t_ = 1.0\n self._partial_fit(X, y, alpha, C, loss, learning_rate, self.max_iter, sample_weight, coef_init, intercept_init)\n if self.tol is not None and self.tol > -np.inf and self.n_iter_ == self.max_iter:\n warnings.warn('Maximum number of iteration reached before convergence. Consider increasing max_iter to improve the fit.', ConvergenceWarning)\n return self\n \n def fit(self, X, y, coef_init=None, intercept_init=None, sample_weight=None):\n \"\"\"Fit linear model with Stochastic Gradient Descent.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Training data.\n\n y : ndarray of shape (n_samples,)\n Target values.\n\n coef_init : ndarray of shape (n_features,), default=None\n The initial coefficients to warm-start the optimization.\n\n intercept_init : ndarray of shape (1,), default=None\n The initial intercept to warm-start the optimization.\n\n sample_weight : array-like, shape (n_samples,), default=None\n Weights applied to individual samples (1. for unweighted).\n\n Returns\n -------\n self : object\n Fitted `SGDRegressor` estimator.\n \"\"\"\n return self._fit(X, y, alpha=self.alpha, C=1.0, loss=self.loss, learning_rate=self.learning_rate, coef_init=coef_init, intercept_init=intercept_init, sample_weight=sample_weight)\n \n def _decision_function(self, X):\n \"\"\"Predict using the linear model\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n\n Returns\n -------\n ndarray of shape (n_samples,)\n Predicted target values per element in X.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse='csr', reset=False)\n scores = safe_sparse_dot(X, self.coef_.T, dense_output=True) + self.intercept_\n return scores.ravel()\n \n def predict(self, X):\n \"\"\"Predict using the linear model.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Input data.\n\n Returns\n -------\n ndarray of shape (n_samples,)\n Predicted target values per element in X.\n \"\"\"\n return self._decision_function(X)\n \n def _fit_regressor(self, X, y, alpha, C, loss, learning_rate, sample_weight, max_iter):\n (dataset, intercept_decay) = make_dataset(X, y, sample_weight)\n loss_function = self._get_loss_function(loss)\n penalty_type = self._get_penalty_type(self.penalty)\n learning_rate_type = self._get_learning_rate_type(learning_rate)\n if not hasattr(self, 't_'):\n self.t_ = 1.0\n validation_mask = self._make_validation_split(y)\n validation_score_cb = self._make_validation_score_cb(validation_mask, X, y, sample_weight)\n random_state = check_random_state(self.random_state)\n seed = random_state.randint(0, np.iinfo(np.int32).max)\n tol = self.tol if self.tol is not None else -np.inf\n if self.average:\n coef = self._standard_coef\n intercept = self._standard_intercept\n average_coef = self._average_coef\n average_intercept = self._average_intercept\n else:\n coef = self.coef_\n intercept = self.intercept_\n average_coef = None\n average_intercept = [0]\n (coef, intercept, average_coef, average_intercept, self.n_iter_) = _plain_sgd(coef, intercept[0], average_coef, average_intercept[0], loss_function, penalty_type, alpha, C, self.l1_ratio, dataset, validation_mask, self.early_stopping, validation_score_cb, int(self.n_iter_no_change), max_iter, tol, int(self.fit_intercept), int(self.verbose), int(self.shuffle), seed, 1.0, 1.0, learning_rate_type, self.eta0, self.power_t, 0, self.t_, intercept_decay, self.average)\n self.t_ += self.n_iter_ * X.shape[0]\n if self.average > 0:\n self._average_intercept = np.atleast_1d(average_intercept)\n self._standard_intercept = np.atleast_1d(intercept)\n if self.average <= self.t_ - 1.0:\n self.coef_ = average_coef\n self.intercept_ = np.atleast_1d(average_intercept)\n else:\n self.coef_ = coef\n self.intercept_ = np.atleast_1d(intercept)\n else:\n self.intercept_ = np.atleast_1d(intercept)\n" }, { "name": "SGDClassifier", @@ -24205,7 +24158,7 @@ "is_public": true, "description": "Linear classifiers (SVM, logistic regression, etc.) with SGD training.\n\nThis estimator implements regularized linear models with stochastic gradient descent (SGD) learning: the gradient of the loss is estimated each sample at a time and the model is updated along the way with a decreasing strength schedule (aka learning rate). SGD allows minibatch (online/out-of-core) learning via the `partial_fit` method. For best results using the default learning rate schedule, the data should have zero mean and unit variance. This implementation works with data represented as dense or sparse arrays of floating point values for the features. The model it fits can be controlled with the loss parameter; by default, it fits a linear support vector machine (SVM). The regularizer is a penalty added to the loss function that shrinks model parameters towards the zero vector using either the squared euclidean norm L2 or the absolute norm L1 or a combination of both (Elastic Net). If the parameter update crosses the 0.0 value because of the regularizer, the update is truncated to 0.0 to allow for learning sparse models and achieve online feature selection. Read more in the :ref:`User Guide `.", "docstring": "Linear classifiers (SVM, logistic regression, etc.) with SGD training.\n\n This estimator implements regularized linear models with stochastic\n gradient descent (SGD) learning: the gradient of the loss is estimated\n each sample at a time and the model is updated along the way with a\n decreasing strength schedule (aka learning rate). SGD allows minibatch\n (online/out-of-core) learning via the `partial_fit` method.\n For best results using the default learning rate schedule, the data should\n have zero mean and unit variance.\n\n This implementation works with data represented as dense or sparse arrays\n of floating point values for the features. The model it fits can be\n controlled with the loss parameter; by default, it fits a linear support\n vector machine (SVM).\n\n The regularizer is a penalty added to the loss function that shrinks model\n parameters towards the zero vector using either the squared euclidean norm\n L2 or the absolute norm L1 or a combination of both (Elastic Net). If the\n parameter update crosses the 0.0 value because of the regularizer, the\n update is truncated to 0.0 to allow for learning sparse models and achieve\n online feature selection.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n loss : str, default='hinge'\n The loss function to be used. Defaults to 'hinge', which gives a\n linear SVM.\n\n The possible options are 'hinge', 'log', 'modified_huber',\n 'squared_hinge', 'perceptron', or a regression loss: 'squared_error',\n 'huber', 'epsilon_insensitive', or 'squared_epsilon_insensitive'.\n\n The 'log' loss gives logistic regression, a probabilistic classifier.\n 'modified_huber' is another smooth loss that brings tolerance to\n outliers as well as probability estimates.\n 'squared_hinge' is like hinge but is quadratically penalized.\n 'perceptron' is the linear loss used by the perceptron algorithm.\n The other losses are designed for regression but can be useful in\n classification as well; see\n :class:`~sklearn.linear_model.SGDRegressor` for a description.\n\n More details about the losses formulas can be found in the\n :ref:`User Guide `.\n\n .. deprecated:: 1.0\n The loss 'squared_loss' was deprecated in v1.0 and will be removed\n in version 1.2. Use `loss='squared_error'` which is equivalent.\n\n penalty : {'l2', 'l1', 'elasticnet'}, default='l2'\n The penalty (aka regularization term) to be used. Defaults to 'l2'\n which is the standard regularizer for linear SVM models. 'l1' and\n 'elasticnet' might bring sparsity to the model (feature selection)\n not achievable with 'l2'.\n\n alpha : float, default=0.0001\n Constant that multiplies the regularization term. The higher the\n value, the stronger the regularization.\n Also used to compute the learning rate when set to `learning_rate` is\n set to 'optimal'.\n\n l1_ratio : float, default=0.15\n The Elastic Net mixing parameter, with 0 <= l1_ratio <= 1.\n l1_ratio=0 corresponds to L2 penalty, l1_ratio=1 to L1.\n Only used if `penalty` is 'elasticnet'.\n\n fit_intercept : bool, default=True\n Whether the intercept should be estimated or not. If False, the\n data is assumed to be already centered.\n\n max_iter : int, default=1000\n The maximum number of passes over the training data (aka epochs).\n It only impacts the behavior in the ``fit`` method, and not the\n :meth:`partial_fit` method.\n\n .. versionadded:: 0.19\n\n tol : float, default=1e-3\n The stopping criterion. If it is not None, training will stop\n when (loss > best_loss - tol) for ``n_iter_no_change`` consecutive\n epochs.\n Convergence is checked against the training loss or the\n validation loss depending on the `early_stopping` parameter.\n\n .. versionadded:: 0.19\n\n shuffle : bool, default=True\n Whether or not the training data should be shuffled after each epoch.\n\n verbose : int, default=0\n The verbosity level.\n\n epsilon : float, default=0.1\n Epsilon in the epsilon-insensitive loss functions; only if `loss` is\n 'huber', 'epsilon_insensitive', or 'squared_epsilon_insensitive'.\n For 'huber', determines the threshold at which it becomes less\n important to get the prediction exactly right.\n For epsilon-insensitive, any differences between the current prediction\n and the correct label are ignored if they are less than this threshold.\n\n n_jobs : int, default=None\n The number of CPUs to use to do the OVA (One Versus All, for\n multi-class problems) computation.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n random_state : int, RandomState instance, default=None\n Used for shuffling the data, when ``shuffle`` is set to ``True``.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n learning_rate : str, default='optimal'\n The learning rate schedule:\n\n - 'constant': `eta = eta0`\n - 'optimal': `eta = 1.0 / (alpha * (t + t0))`\n where t0 is chosen by a heuristic proposed by Leon Bottou.\n - 'invscaling': `eta = eta0 / pow(t, power_t)`\n - 'adaptive': eta = eta0, as long as the training keeps decreasing.\n Each time n_iter_no_change consecutive epochs fail to decrease the\n training loss by tol or fail to increase validation score by tol if\n early_stopping is True, the current learning rate is divided by 5.\n\n .. versionadded:: 0.20\n Added 'adaptive' option\n\n eta0 : double, default=0.0\n The initial learning rate for the 'constant', 'invscaling' or\n 'adaptive' schedules. The default value is 0.0 as eta0 is not used by\n the default schedule 'optimal'.\n\n power_t : double, default=0.5\n The exponent for inverse scaling learning rate [default 0.5].\n\n early_stopping : bool, default=False\n Whether to use early stopping to terminate training when validation\n score is not improving. If set to True, it will automatically set aside\n a stratified fraction of training data as validation and terminate\n training when validation score returned by the `score` method is not\n improving by at least tol for n_iter_no_change consecutive epochs.\n\n .. versionadded:: 0.20\n Added 'early_stopping' option\n\n validation_fraction : float, default=0.1\n The proportion of training data to set aside as validation set for\n early stopping. Must be between 0 and 1.\n Only used if `early_stopping` is True.\n\n .. versionadded:: 0.20\n Added 'validation_fraction' option\n\n n_iter_no_change : int, default=5\n Number of iterations with no improvement to wait before stopping\n fitting.\n Convergence is checked against the training loss or the\n validation loss depending on the `early_stopping` parameter.\n\n .. versionadded:: 0.20\n Added 'n_iter_no_change' option\n\n class_weight : dict, {class_label: weight} or \"balanced\", default=None\n Preset for the class_weight fit parameter.\n\n Weights associated with classes. If not given, all classes\n are supposed to have weight one.\n\n The \"balanced\" mode uses the values of y to automatically adjust\n weights inversely proportional to class frequencies in the input data\n as ``n_samples / (n_classes * np.bincount(y))``.\n\n warm_start : bool, default=False\n When set to True, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n Repeatedly calling fit or partial_fit when warm_start is True can\n result in a different solution than when calling fit a single time\n because of the way the data is shuffled.\n If a dynamic learning rate is used, the learning rate is adapted\n depending on the number of samples already seen. Calling ``fit`` resets\n this counter, while ``partial_fit`` will result in increasing the\n existing counter.\n\n average : bool or int, default=False\n When set to True, computes the averaged SGD weights across all\n updates and stores the result in the ``coef_`` attribute. If set to\n an int greater than 1, averaging will begin once the total number of\n samples seen reaches `average`. So ``average=10`` will begin\n averaging after seeing 10 samples.\n\n Attributes\n ----------\n coef_ : ndarray of shape (1, n_features) if n_classes == 2 else (n_classes, n_features)\n Weights assigned to the features.\n\n intercept_ : ndarray of shape (1,) if n_classes == 2 else (n_classes,)\n Constants in decision function.\n\n n_iter_ : int\n The actual number of iterations before reaching the stopping criterion.\n For multiclass fits, it is the maximum over every binary fit.\n\n loss_function_ : concrete ``LossFunction``\n\n classes_ : array of shape (n_classes,)\n\n t_ : int\n Number of weight updates performed during training.\n Same as ``(n_iter_ * n_samples)``.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n sklearn.svm.LinearSVC : Linear support vector classification.\n LogisticRegression : Logistic regression.\n Perceptron : Inherits from SGDClassifier. ``Perceptron()`` is equivalent to\n ``SGDClassifier(loss=\"perceptron\", eta0=1, learning_rate=\"constant\",\n penalty=None)``.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.linear_model import SGDClassifier\n >>> from sklearn.preprocessing import StandardScaler\n >>> from sklearn.pipeline import make_pipeline\n >>> X = np.array([[-1, -1], [-2, -1], [1, 1], [2, 1]])\n >>> Y = np.array([1, 1, 2, 2])\n >>> # Always scale the input. The most convenient way is to use a pipeline.\n >>> clf = make_pipeline(StandardScaler(),\n ... SGDClassifier(max_iter=1000, tol=1e-3))\n >>> clf.fit(X, Y)\n Pipeline(steps=[('standardscaler', StandardScaler()),\n ('sgdclassifier', SGDClassifier())])\n >>> print(clf.predict([[-0.8, -1]]))\n [1]\n ", - "source_code": "\n\nclass SGDClassifier(BaseSGDClassifier):\n \"\"\"Linear classifiers (SVM, logistic regression, etc.) with SGD training.\n\n This estimator implements regularized linear models with stochastic\n gradient descent (SGD) learning: the gradient of the loss is estimated\n each sample at a time and the model is updated along the way with a\n decreasing strength schedule (aka learning rate). SGD allows minibatch\n (online/out-of-core) learning via the `partial_fit` method.\n For best results using the default learning rate schedule, the data should\n have zero mean and unit variance.\n\n This implementation works with data represented as dense or sparse arrays\n of floating point values for the features. The model it fits can be\n controlled with the loss parameter; by default, it fits a linear support\n vector machine (SVM).\n\n The regularizer is a penalty added to the loss function that shrinks model\n parameters towards the zero vector using either the squared euclidean norm\n L2 or the absolute norm L1 or a combination of both (Elastic Net). If the\n parameter update crosses the 0.0 value because of the regularizer, the\n update is truncated to 0.0 to allow for learning sparse models and achieve\n online feature selection.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n loss : str, default='hinge'\n The loss function to be used. Defaults to 'hinge', which gives a\n linear SVM.\n\n The possible options are 'hinge', 'log', 'modified_huber',\n 'squared_hinge', 'perceptron', or a regression loss: 'squared_error',\n 'huber', 'epsilon_insensitive', or 'squared_epsilon_insensitive'.\n\n The 'log' loss gives logistic regression, a probabilistic classifier.\n 'modified_huber' is another smooth loss that brings tolerance to\n outliers as well as probability estimates.\n 'squared_hinge' is like hinge but is quadratically penalized.\n 'perceptron' is the linear loss used by the perceptron algorithm.\n The other losses are designed for regression but can be useful in\n classification as well; see\n :class:`~sklearn.linear_model.SGDRegressor` for a description.\n\n More details about the losses formulas can be found in the\n :ref:`User Guide `.\n\n .. deprecated:: 1.0\n The loss 'squared_loss' was deprecated in v1.0 and will be removed\n in version 1.2. Use `loss='squared_error'` which is equivalent.\n\n penalty : {'l2', 'l1', 'elasticnet'}, default='l2'\n The penalty (aka regularization term) to be used. Defaults to 'l2'\n which is the standard regularizer for linear SVM models. 'l1' and\n 'elasticnet' might bring sparsity to the model (feature selection)\n not achievable with 'l2'.\n\n alpha : float, default=0.0001\n Constant that multiplies the regularization term. The higher the\n value, the stronger the regularization.\n Also used to compute the learning rate when set to `learning_rate` is\n set to 'optimal'.\n\n l1_ratio : float, default=0.15\n The Elastic Net mixing parameter, with 0 <= l1_ratio <= 1.\n l1_ratio=0 corresponds to L2 penalty, l1_ratio=1 to L1.\n Only used if `penalty` is 'elasticnet'.\n\n fit_intercept : bool, default=True\n Whether the intercept should be estimated or not. If False, the\n data is assumed to be already centered.\n\n max_iter : int, default=1000\n The maximum number of passes over the training data (aka epochs).\n It only impacts the behavior in the ``fit`` method, and not the\n :meth:`partial_fit` method.\n\n .. versionadded:: 0.19\n\n tol : float, default=1e-3\n The stopping criterion. If it is not None, training will stop\n when (loss > best_loss - tol) for ``n_iter_no_change`` consecutive\n epochs.\n Convergence is checked against the training loss or the\n validation loss depending on the `early_stopping` parameter.\n\n .. versionadded:: 0.19\n\n shuffle : bool, default=True\n Whether or not the training data should be shuffled after each epoch.\n\n verbose : int, default=0\n The verbosity level.\n\n epsilon : float, default=0.1\n Epsilon in the epsilon-insensitive loss functions; only if `loss` is\n 'huber', 'epsilon_insensitive', or 'squared_epsilon_insensitive'.\n For 'huber', determines the threshold at which it becomes less\n important to get the prediction exactly right.\n For epsilon-insensitive, any differences between the current prediction\n and the correct label are ignored if they are less than this threshold.\n\n n_jobs : int, default=None\n The number of CPUs to use to do the OVA (One Versus All, for\n multi-class problems) computation.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n random_state : int, RandomState instance, default=None\n Used for shuffling the data, when ``shuffle`` is set to ``True``.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n learning_rate : str, default='optimal'\n The learning rate schedule:\n\n - 'constant': `eta = eta0`\n - 'optimal': `eta = 1.0 / (alpha * (t + t0))`\n where t0 is chosen by a heuristic proposed by Leon Bottou.\n - 'invscaling': `eta = eta0 / pow(t, power_t)`\n - 'adaptive': eta = eta0, as long as the training keeps decreasing.\n Each time n_iter_no_change consecutive epochs fail to decrease the\n training loss by tol or fail to increase validation score by tol if\n early_stopping is True, the current learning rate is divided by 5.\n\n .. versionadded:: 0.20\n Added 'adaptive' option\n\n eta0 : double, default=0.0\n The initial learning rate for the 'constant', 'invscaling' or\n 'adaptive' schedules. The default value is 0.0 as eta0 is not used by\n the default schedule 'optimal'.\n\n power_t : double, default=0.5\n The exponent for inverse scaling learning rate [default 0.5].\n\n early_stopping : bool, default=False\n Whether to use early stopping to terminate training when validation\n score is not improving. If set to True, it will automatically set aside\n a stratified fraction of training data as validation and terminate\n training when validation score returned by the `score` method is not\n improving by at least tol for n_iter_no_change consecutive epochs.\n\n .. versionadded:: 0.20\n Added 'early_stopping' option\n\n validation_fraction : float, default=0.1\n The proportion of training data to set aside as validation set for\n early stopping. Must be between 0 and 1.\n Only used if `early_stopping` is True.\n\n .. versionadded:: 0.20\n Added 'validation_fraction' option\n\n n_iter_no_change : int, default=5\n Number of iterations with no improvement to wait before stopping\n fitting.\n Convergence is checked against the training loss or the\n validation loss depending on the `early_stopping` parameter.\n\n .. versionadded:: 0.20\n Added 'n_iter_no_change' option\n\n class_weight : dict, {class_label: weight} or \"balanced\", default=None\n Preset for the class_weight fit parameter.\n\n Weights associated with classes. If not given, all classes\n are supposed to have weight one.\n\n The \"balanced\" mode uses the values of y to automatically adjust\n weights inversely proportional to class frequencies in the input data\n as ``n_samples / (n_classes * np.bincount(y))``.\n\n warm_start : bool, default=False\n When set to True, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n Repeatedly calling fit or partial_fit when warm_start is True can\n result in a different solution than when calling fit a single time\n because of the way the data is shuffled.\n If a dynamic learning rate is used, the learning rate is adapted\n depending on the number of samples already seen. Calling ``fit`` resets\n this counter, while ``partial_fit`` will result in increasing the\n existing counter.\n\n average : bool or int, default=False\n When set to True, computes the averaged SGD weights across all\n updates and stores the result in the ``coef_`` attribute. If set to\n an int greater than 1, averaging will begin once the total number of\n samples seen reaches `average`. So ``average=10`` will begin\n averaging after seeing 10 samples.\n\n Attributes\n ----------\n coef_ : ndarray of shape (1, n_features) if n_classes == 2 else (n_classes, n_features)\n Weights assigned to the features.\n\n intercept_ : ndarray of shape (1,) if n_classes == 2 else (n_classes,)\n Constants in decision function.\n\n n_iter_ : int\n The actual number of iterations before reaching the stopping criterion.\n For multiclass fits, it is the maximum over every binary fit.\n\n loss_function_ : concrete ``LossFunction``\n\n classes_ : array of shape (n_classes,)\n\n t_ : int\n Number of weight updates performed during training.\n Same as ``(n_iter_ * n_samples)``.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n sklearn.svm.LinearSVC : Linear support vector classification.\n LogisticRegression : Logistic regression.\n Perceptron : Inherits from SGDClassifier. ``Perceptron()`` is equivalent to\n ``SGDClassifier(loss=\"perceptron\", eta0=1, learning_rate=\"constant\",\n penalty=None)``.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.linear_model import SGDClassifier\n >>> from sklearn.preprocessing import StandardScaler\n >>> from sklearn.pipeline import make_pipeline\n >>> X = np.array([[-1, -1], [-2, -1], [1, 1], [2, 1]])\n >>> Y = np.array([1, 1, 2, 2])\n >>> # Always scale the input. The most convenient way is to use a pipeline.\n >>> clf = make_pipeline(StandardScaler(),\n ... SGDClassifier(max_iter=1000, tol=1e-3))\n >>> clf.fit(X, Y)\n Pipeline(steps=[('standardscaler', StandardScaler()),\n ('sgdclassifier', SGDClassifier())])\n >>> print(clf.predict([[-0.8, -1]]))\n [1]\n \"\"\"\n \n def __init__(self, loss='hinge', *, penalty='l2', alpha=0.0001, l1_ratio=0.15, fit_intercept=True, max_iter=1000, tol=0.001, shuffle=True, verbose=0, epsilon=DEFAULT_EPSILON, n_jobs=None, random_state=None, learning_rate='optimal', eta0=0.0, power_t=0.5, early_stopping=False, validation_fraction=0.1, n_iter_no_change=5, class_weight=None, warm_start=False, average=False):\n super().__init__(loss=loss, penalty=penalty, alpha=alpha, l1_ratio=l1_ratio, fit_intercept=fit_intercept, max_iter=max_iter, tol=tol, shuffle=shuffle, verbose=verbose, epsilon=epsilon, n_jobs=n_jobs, random_state=random_state, learning_rate=learning_rate, eta0=eta0, power_t=power_t, early_stopping=early_stopping, validation_fraction=validation_fraction, n_iter_no_change=n_iter_no_change, class_weight=class_weight, warm_start=warm_start, average=average)\n \n def _check_proba(self):\n if self.loss not in ('log', 'modified_huber'):\n raise AttributeError('probability estimates are not available for loss=%r' % self.loss)\n return True\n \n @available_if(_check_proba)\n def predict_proba(self, X):\n \"\"\"Probability estimates.\n\n This method is only available for log loss and modified Huber loss.\n\n Multiclass probability estimates are derived from binary (one-vs.-rest)\n estimates by simple normalization, as recommended by Zadrozny and\n Elkan.\n\n Binary probability estimates for loss=\"modified_huber\" are given by\n (clip(decision_function(X), -1, 1) + 1) / 2. For other loss functions\n it is necessary to perform proper probability calibration by wrapping\n the classifier with\n :class:`~sklearn.calibration.CalibratedClassifierCV` instead.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Input data for prediction.\n\n Returns\n -------\n ndarray of shape (n_samples, n_classes)\n Returns the probability of the sample for each class in the model,\n where classes are ordered as they are in `self.classes_`.\n\n References\n ----------\n Zadrozny and Elkan, \"Transforming classifier scores into multiclass\n probability estimates\", SIGKDD'02,\n http://www.research.ibm.com/people/z/zadrozny/kdd2002-Transf.pdf\n\n The justification for the formula in the loss=\"modified_huber\"\n case is in the appendix B in:\n http://jmlr.csail.mit.edu/papers/volume2/zhang02c/zhang02c.pdf\n \"\"\"\n check_is_fitted(self)\n if self.loss == 'log':\n return self._predict_proba_lr(X)\n elif self.loss == 'modified_huber':\n binary = len(self.classes_) == 2\n scores = self.decision_function(X)\n if binary:\n prob2 = np.ones((scores.shape[0], 2))\n prob = prob2[:, 1]\n else:\n prob = scores\n np.clip(scores, -1, 1, prob)\n prob += 1.0\n prob /= 2.0\n if binary:\n prob2[:, 0] -= prob\n prob = prob2\n else:\n prob_sum = prob.sum(axis=1)\n all_zero = prob_sum == 0\n if np.any(all_zero):\n prob[all_zero, :] = 1\n prob_sum[all_zero] = len(self.classes_)\n prob /= prob_sum.reshape((prob.shape[0], -1))\n return prob\n else:\n raise NotImplementedError(\"predict_(log_)proba only supported when loss='log' or loss='modified_huber' (%r given)\" % self.loss)\n \n @available_if(_check_proba)\n def predict_log_proba(self, X):\n \"\"\"Log of probability estimates.\n\n This method is only available for log loss and modified Huber loss.\n\n When loss=\"modified_huber\", probability estimates may be hard zeros\n and ones, so taking the logarithm is not possible.\n\n See ``predict_proba`` for details.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input data for prediction.\n\n Returns\n -------\n T : array-like, shape (n_samples, n_classes)\n Returns the log-probability of the sample for each class in the\n model, where classes are ordered as they are in\n `self.classes_`.\n \"\"\"\n return np.log(self.predict_proba(X))\n \n def _more_tags(self):\n return {'_xfail_checks': {'check_sample_weights_invariance': 'zero sample_weight is not equivalent to removing samples'}}\n" + "source_code": "\n\nclass SGDClassifier(BaseSGDClassifier):\n \"\"\"Linear classifiers (SVM, logistic regression, etc.) with SGD training.\n\n This estimator implements regularized linear models with stochastic\n gradient descent (SGD) learning: the gradient of the loss is estimated\n each sample at a time and the model is updated along the way with a\n decreasing strength schedule (aka learning rate). SGD allows minibatch\n (online/out-of-core) learning via the `partial_fit` method.\n For best results using the default learning rate schedule, the data should\n have zero mean and unit variance.\n\n This implementation works with data represented as dense or sparse arrays\n of floating point values for the features. The model it fits can be\n controlled with the loss parameter; by default, it fits a linear support\n vector machine (SVM).\n\n The regularizer is a penalty added to the loss function that shrinks model\n parameters towards the zero vector using either the squared euclidean norm\n L2 or the absolute norm L1 or a combination of both (Elastic Net). If the\n parameter update crosses the 0.0 value because of the regularizer, the\n update is truncated to 0.0 to allow for learning sparse models and achieve\n online feature selection.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n loss : str, default='hinge'\n The loss function to be used. Defaults to 'hinge', which gives a\n linear SVM.\n\n The possible options are 'hinge', 'log', 'modified_huber',\n 'squared_hinge', 'perceptron', or a regression loss: 'squared_error',\n 'huber', 'epsilon_insensitive', or 'squared_epsilon_insensitive'.\n\n The 'log' loss gives logistic regression, a probabilistic classifier.\n 'modified_huber' is another smooth loss that brings tolerance to\n outliers as well as probability estimates.\n 'squared_hinge' is like hinge but is quadratically penalized.\n 'perceptron' is the linear loss used by the perceptron algorithm.\n The other losses are designed for regression but can be useful in\n classification as well; see\n :class:`~sklearn.linear_model.SGDRegressor` for a description.\n\n More details about the losses formulas can be found in the\n :ref:`User Guide `.\n\n .. deprecated:: 1.0\n The loss 'squared_loss' was deprecated in v1.0 and will be removed\n in version 1.2. Use `loss='squared_error'` which is equivalent.\n\n penalty : {'l2', 'l1', 'elasticnet'}, default='l2'\n The penalty (aka regularization term) to be used. Defaults to 'l2'\n which is the standard regularizer for linear SVM models. 'l1' and\n 'elasticnet' might bring sparsity to the model (feature selection)\n not achievable with 'l2'.\n\n alpha : float, default=0.0001\n Constant that multiplies the regularization term. The higher the\n value, the stronger the regularization.\n Also used to compute the learning rate when set to `learning_rate` is\n set to 'optimal'.\n\n l1_ratio : float, default=0.15\n The Elastic Net mixing parameter, with 0 <= l1_ratio <= 1.\n l1_ratio=0 corresponds to L2 penalty, l1_ratio=1 to L1.\n Only used if `penalty` is 'elasticnet'.\n\n fit_intercept : bool, default=True\n Whether the intercept should be estimated or not. If False, the\n data is assumed to be already centered.\n\n max_iter : int, default=1000\n The maximum number of passes over the training data (aka epochs).\n It only impacts the behavior in the ``fit`` method, and not the\n :meth:`partial_fit` method.\n\n .. versionadded:: 0.19\n\n tol : float, default=1e-3\n The stopping criterion. If it is not None, training will stop\n when (loss > best_loss - tol) for ``n_iter_no_change`` consecutive\n epochs.\n Convergence is checked against the training loss or the\n validation loss depending on the `early_stopping` parameter.\n\n .. versionadded:: 0.19\n\n shuffle : bool, default=True\n Whether or not the training data should be shuffled after each epoch.\n\n verbose : int, default=0\n The verbosity level.\n\n epsilon : float, default=0.1\n Epsilon in the epsilon-insensitive loss functions; only if `loss` is\n 'huber', 'epsilon_insensitive', or 'squared_epsilon_insensitive'.\n For 'huber', determines the threshold at which it becomes less\n important to get the prediction exactly right.\n For epsilon-insensitive, any differences between the current prediction\n and the correct label are ignored if they are less than this threshold.\n\n n_jobs : int, default=None\n The number of CPUs to use to do the OVA (One Versus All, for\n multi-class problems) computation.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n random_state : int, RandomState instance, default=None\n Used for shuffling the data, when ``shuffle`` is set to ``True``.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n learning_rate : str, default='optimal'\n The learning rate schedule:\n\n - 'constant': `eta = eta0`\n - 'optimal': `eta = 1.0 / (alpha * (t + t0))`\n where t0 is chosen by a heuristic proposed by Leon Bottou.\n - 'invscaling': `eta = eta0 / pow(t, power_t)`\n - 'adaptive': eta = eta0, as long as the training keeps decreasing.\n Each time n_iter_no_change consecutive epochs fail to decrease the\n training loss by tol or fail to increase validation score by tol if\n early_stopping is True, the current learning rate is divided by 5.\n\n .. versionadded:: 0.20\n Added 'adaptive' option\n\n eta0 : double, default=0.0\n The initial learning rate for the 'constant', 'invscaling' or\n 'adaptive' schedules. The default value is 0.0 as eta0 is not used by\n the default schedule 'optimal'.\n\n power_t : double, default=0.5\n The exponent for inverse scaling learning rate [default 0.5].\n\n early_stopping : bool, default=False\n Whether to use early stopping to terminate training when validation\n score is not improving. If set to True, it will automatically set aside\n a stratified fraction of training data as validation and terminate\n training when validation score returned by the `score` method is not\n improving by at least tol for n_iter_no_change consecutive epochs.\n\n .. versionadded:: 0.20\n Added 'early_stopping' option\n\n validation_fraction : float, default=0.1\n The proportion of training data to set aside as validation set for\n early stopping. Must be between 0 and 1.\n Only used if `early_stopping` is True.\n\n .. versionadded:: 0.20\n Added 'validation_fraction' option\n\n n_iter_no_change : int, default=5\n Number of iterations with no improvement to wait before stopping\n fitting.\n Convergence is checked against the training loss or the\n validation loss depending on the `early_stopping` parameter.\n\n .. versionadded:: 0.20\n Added 'n_iter_no_change' option\n\n class_weight : dict, {class_label: weight} or \"balanced\", default=None\n Preset for the class_weight fit parameter.\n\n Weights associated with classes. If not given, all classes\n are supposed to have weight one.\n\n The \"balanced\" mode uses the values of y to automatically adjust\n weights inversely proportional to class frequencies in the input data\n as ``n_samples / (n_classes * np.bincount(y))``.\n\n warm_start : bool, default=False\n When set to True, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n Repeatedly calling fit or partial_fit when warm_start is True can\n result in a different solution than when calling fit a single time\n because of the way the data is shuffled.\n If a dynamic learning rate is used, the learning rate is adapted\n depending on the number of samples already seen. Calling ``fit`` resets\n this counter, while ``partial_fit`` will result in increasing the\n existing counter.\n\n average : bool or int, default=False\n When set to True, computes the averaged SGD weights across all\n updates and stores the result in the ``coef_`` attribute. If set to\n an int greater than 1, averaging will begin once the total number of\n samples seen reaches `average`. So ``average=10`` will begin\n averaging after seeing 10 samples.\n\n Attributes\n ----------\n coef_ : ndarray of shape (1, n_features) if n_classes == 2 else (n_classes, n_features)\n Weights assigned to the features.\n\n intercept_ : ndarray of shape (1,) if n_classes == 2 else (n_classes,)\n Constants in decision function.\n\n n_iter_ : int\n The actual number of iterations before reaching the stopping criterion.\n For multiclass fits, it is the maximum over every binary fit.\n\n loss_function_ : concrete ``LossFunction``\n\n classes_ : array of shape (n_classes,)\n\n t_ : int\n Number of weight updates performed during training.\n Same as ``(n_iter_ * n_samples)``.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n sklearn.svm.LinearSVC : Linear support vector classification.\n LogisticRegression : Logistic regression.\n Perceptron : Inherits from SGDClassifier. ``Perceptron()`` is equivalent to\n ``SGDClassifier(loss=\"perceptron\", eta0=1, learning_rate=\"constant\",\n penalty=None)``.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.linear_model import SGDClassifier\n >>> from sklearn.preprocessing import StandardScaler\n >>> from sklearn.pipeline import make_pipeline\n >>> X = np.array([[-1, -1], [-2, -1], [1, 1], [2, 1]])\n >>> Y = np.array([1, 1, 2, 2])\n >>> # Always scale the input. The most convenient way is to use a pipeline.\n >>> clf = make_pipeline(StandardScaler(),\n ... SGDClassifier(max_iter=1000, tol=1e-3))\n >>> clf.fit(X, Y)\n Pipeline(steps=[('standardscaler', StandardScaler()),\n ('sgdclassifier', SGDClassifier())])\n >>> print(clf.predict([[-0.8, -1]]))\n [1]\n \"\"\"\n \n def __init__(self, loss='hinge', *, penalty='l2', alpha=0.0001, l1_ratio=0.15, fit_intercept=True, max_iter=1000, tol=0.001, shuffle=True, verbose=0, epsilon=DEFAULT_EPSILON, n_jobs=None, random_state=None, learning_rate='optimal', eta0=0.0, power_t=0.5, early_stopping=False, validation_fraction=0.1, n_iter_no_change=5, class_weight=None, warm_start=False, average=False):\n super().__init__(loss=loss, penalty=penalty, alpha=alpha, l1_ratio=l1_ratio, fit_intercept=fit_intercept, max_iter=max_iter, tol=tol, shuffle=shuffle, verbose=verbose, epsilon=epsilon, n_jobs=n_jobs, random_state=random_state, learning_rate=learning_rate, eta0=eta0, power_t=power_t, early_stopping=early_stopping, validation_fraction=validation_fraction, n_iter_no_change=n_iter_no_change, class_weight=class_weight, warm_start=warm_start, average=average)\n \n def _check_proba(self):\n if self.loss not in ('log', 'modified_huber'):\n raise AttributeError('probability estimates are not available for loss=%r' % self.loss)\n return True\n \n @available_if(_check_proba)\n def predict_proba(self, X):\n \"\"\"Probability estimates.\n\n This method is only available for log loss and modified Huber loss.\n\n Multiclass probability estimates are derived from binary (one-vs.-rest)\n estimates by simple normalization, as recommended by Zadrozny and\n Elkan.\n\n Binary probability estimates for loss=\"modified_huber\" are given by\n (clip(decision_function(X), -1, 1) + 1) / 2. For other loss functions\n it is necessary to perform proper probability calibration by wrapping\n the classifier with\n :class:`~sklearn.calibration.CalibratedClassifierCV` instead.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Input data for prediction.\n\n Returns\n -------\n ndarray of shape (n_samples, n_classes)\n Returns the probability of the sample for each class in the model,\n where classes are ordered as they are in `self.classes_`.\n\n References\n ----------\n Zadrozny and Elkan, \"Transforming classifier scores into multiclass\n probability estimates\", SIGKDD'02,\n https://dl.acm.org/doi/pdf/10.1145/775047.775151\n\n The justification for the formula in the loss=\"modified_huber\"\n case is in the appendix B in:\n http://jmlr.csail.mit.edu/papers/volume2/zhang02c/zhang02c.pdf\n \"\"\"\n check_is_fitted(self)\n if self.loss == 'log':\n return self._predict_proba_lr(X)\n elif self.loss == 'modified_huber':\n binary = len(self.classes_) == 2\n scores = self.decision_function(X)\n if binary:\n prob2 = np.ones((scores.shape[0], 2))\n prob = prob2[:, 1]\n else:\n prob = scores\n np.clip(scores, -1, 1, prob)\n prob += 1.0\n prob /= 2.0\n if binary:\n prob2[:, 0] -= prob\n prob = prob2\n else:\n prob_sum = prob.sum(axis=1)\n all_zero = prob_sum == 0\n if np.any(all_zero):\n prob[all_zero, :] = 1\n prob_sum[all_zero] = len(self.classes_)\n prob /= prob_sum.reshape((prob.shape[0], -1))\n return prob\n else:\n raise NotImplementedError(\"predict_(log_)proba only supported when loss='log' or loss='modified_huber' (%r given)\" % self.loss)\n \n @available_if(_check_proba)\n def predict_log_proba(self, X):\n \"\"\"Log of probability estimates.\n\n This method is only available for log loss and modified Huber loss.\n\n When loss=\"modified_huber\", probability estimates may be hard zeros\n and ones, so taking the logarithm is not possible.\n\n See ``predict_proba`` for details.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input data for prediction.\n\n Returns\n -------\n T : array-like, shape (n_samples, n_classes)\n Returns the log-probability of the sample for each class in the\n model, where classes are ordered as they are in\n `self.classes_`.\n \"\"\"\n return np.log(self.predict_proba(X))\n \n def _more_tags(self):\n return {'_xfail_checks': {'check_sample_weights_invariance': 'zero sample_weight is not equivalent to removing samples'}}\n" }, { "name": "SGDOneClassSVM", @@ -24227,8 +24180,8 @@ ], "is_public": true, "description": "Solves linear One-Class SVM using Stochastic Gradient Descent.\n\nThis implementation is meant to be used with a kernel approximation technique (e.g. `sklearn.kernel_approximation.Nystroem`) to obtain results similar to `sklearn.svm.OneClassSVM` which uses a Gaussian kernel by default. Read more in the :ref:`User Guide `. .. versionadded:: 1.0", - "docstring": "Solves linear One-Class SVM using Stochastic Gradient Descent.\n\n This implementation is meant to be used with a kernel approximation\n technique (e.g. `sklearn.kernel_approximation.Nystroem`) to obtain results\n similar to `sklearn.svm.OneClassSVM` which uses a Gaussian kernel by\n default.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 1.0\n\n Parameters\n ----------\n nu : float, optional\n The nu parameter of the One Class SVM: an upper bound on the\n fraction of training errors and a lower bound of the fraction of\n support vectors. Should be in the interval (0, 1]. By default 0.5\n will be taken.\n\n fit_intercept : bool\n Whether the intercept should be estimated or not. Defaults to True.\n\n max_iter : int, optional\n The maximum number of passes over the training data (aka epochs).\n It only impacts the behavior in the ``fit`` method, and not the\n `partial_fit`. Defaults to 1000.\n\n tol : float or None, optional\n The stopping criterion. If it is not None, the iterations will stop\n when (loss > previous_loss - tol). Defaults to 1e-3.\n\n shuffle : bool, optional\n Whether or not the training data should be shuffled after each epoch.\n Defaults to True.\n\n verbose : integer, optional\n The verbosity level\n\n random_state : int, RandomState instance or None, optional (default=None)\n The seed of the pseudo random number generator to use when shuffling\n the data. If int, random_state is the seed used by the random number\n generator; If RandomState instance, random_state is the random number\n generator; If None, the random number generator is the RandomState\n instance used by `np.random`.\n\n learning_rate : string, optional\n The learning rate schedule to use with `fit`. (If using `partial_fit`,\n learning rate must be controlled directly).\n\n 'constant':\n eta = eta0\n 'optimal': [default]\n eta = 1.0 / (alpha * (t + t0))\n where t0 is chosen by a heuristic proposed by Leon Bottou.\n 'invscaling':\n eta = eta0 / pow(t, power_t)\n 'adaptive':\n eta = eta0, as long as the training keeps decreasing.\n Each time n_iter_no_change consecutive epochs fail to decrease the\n training loss by tol or fail to increase validation score by tol if\n early_stopping is True, the current learning rate is divided by 5.\n\n eta0 : double\n The initial learning rate for the 'constant', 'invscaling' or\n 'adaptive' schedules. The default value is 0.0 as eta0 is not used by\n the default schedule 'optimal'.\n\n power_t : double\n The exponent for inverse scaling learning rate [default 0.5].\n\n warm_start : bool, optional\n When set to True, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n Repeatedly calling fit or partial_fit when warm_start is True can\n result in a different solution than when calling fit a single time\n because of the way the data is shuffled.\n If a dynamic learning rate is used, the learning rate is adapted\n depending on the number of samples already seen. Calling ``fit`` resets\n this counter, while ``partial_fit`` will result in increasing the\n existing counter.\n\n average : bool or int, optional\n When set to True, computes the averaged SGD weights and stores the\n result in the ``coef_`` attribute. If set to an int greater than 1,\n averaging will begin once the total number of samples seen reaches\n average. So ``average=10`` will begin averaging after seeing 10\n samples.\n\n Attributes\n ----------\n coef_ : array, shape (1, n_features)\n Weights assigned to the features.\n\n offset_ : array, shape (1,)\n Offset used to define the decision function from the raw scores.\n We have the relation: decision_function = score_samples - offset.\n\n n_iter_ : int\n The actual number of iterations to reach the stopping criterion.\n\n t_ : int\n Number of weight updates performed during training.\n Same as ``(n_iter_ * n_samples)``.\n\n loss_function_ : concrete ``LossFunction``\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn import linear_model\n >>> X = np.array([[-1, -1], [-2, -1], [1, 1], [2, 1]])\n >>> clf = linear_model.SGDOneClassSVM(random_state=42)\n >>> clf.fit(X)\n SGDOneClassSVM(random_state=42)\n\n >>> print(clf.predict([[4, 4]]))\n [1]\n\n See also\n --------\n sklearn.svm.OneClassSVM\n\n Notes\n -----\n This estimator has a linear complexity in the number of training samples\n and is thus better suited than the `sklearn.svm.OneClassSVM`\n implementation for datasets with a large number of training samples (say\n > 10,000).\n ", - "source_code": "\n\nclass SGDOneClassSVM(BaseSGD, OutlierMixin):\n \"\"\"Solves linear One-Class SVM using Stochastic Gradient Descent.\n\n This implementation is meant to be used with a kernel approximation\n technique (e.g. `sklearn.kernel_approximation.Nystroem`) to obtain results\n similar to `sklearn.svm.OneClassSVM` which uses a Gaussian kernel by\n default.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 1.0\n\n Parameters\n ----------\n nu : float, optional\n The nu parameter of the One Class SVM: an upper bound on the\n fraction of training errors and a lower bound of the fraction of\n support vectors. Should be in the interval (0, 1]. By default 0.5\n will be taken.\n\n fit_intercept : bool\n Whether the intercept should be estimated or not. Defaults to True.\n\n max_iter : int, optional\n The maximum number of passes over the training data (aka epochs).\n It only impacts the behavior in the ``fit`` method, and not the\n `partial_fit`. Defaults to 1000.\n\n tol : float or None, optional\n The stopping criterion. If it is not None, the iterations will stop\n when (loss > previous_loss - tol). Defaults to 1e-3.\n\n shuffle : bool, optional\n Whether or not the training data should be shuffled after each epoch.\n Defaults to True.\n\n verbose : integer, optional\n The verbosity level\n\n random_state : int, RandomState instance or None, optional (default=None)\n The seed of the pseudo random number generator to use when shuffling\n the data. If int, random_state is the seed used by the random number\n generator; If RandomState instance, random_state is the random number\n generator; If None, the random number generator is the RandomState\n instance used by `np.random`.\n\n learning_rate : string, optional\n The learning rate schedule to use with `fit`. (If using `partial_fit`,\n learning rate must be controlled directly).\n\n 'constant':\n eta = eta0\n 'optimal': [default]\n eta = 1.0 / (alpha * (t + t0))\n where t0 is chosen by a heuristic proposed by Leon Bottou.\n 'invscaling':\n eta = eta0 / pow(t, power_t)\n 'adaptive':\n eta = eta0, as long as the training keeps decreasing.\n Each time n_iter_no_change consecutive epochs fail to decrease the\n training loss by tol or fail to increase validation score by tol if\n early_stopping is True, the current learning rate is divided by 5.\n\n eta0 : double\n The initial learning rate for the 'constant', 'invscaling' or\n 'adaptive' schedules. The default value is 0.0 as eta0 is not used by\n the default schedule 'optimal'.\n\n power_t : double\n The exponent for inverse scaling learning rate [default 0.5].\n\n warm_start : bool, optional\n When set to True, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n Repeatedly calling fit or partial_fit when warm_start is True can\n result in a different solution than when calling fit a single time\n because of the way the data is shuffled.\n If a dynamic learning rate is used, the learning rate is adapted\n depending on the number of samples already seen. Calling ``fit`` resets\n this counter, while ``partial_fit`` will result in increasing the\n existing counter.\n\n average : bool or int, optional\n When set to True, computes the averaged SGD weights and stores the\n result in the ``coef_`` attribute. If set to an int greater than 1,\n averaging will begin once the total number of samples seen reaches\n average. So ``average=10`` will begin averaging after seeing 10\n samples.\n\n Attributes\n ----------\n coef_ : array, shape (1, n_features)\n Weights assigned to the features.\n\n offset_ : array, shape (1,)\n Offset used to define the decision function from the raw scores.\n We have the relation: decision_function = score_samples - offset.\n\n n_iter_ : int\n The actual number of iterations to reach the stopping criterion.\n\n t_ : int\n Number of weight updates performed during training.\n Same as ``(n_iter_ * n_samples)``.\n\n loss_function_ : concrete ``LossFunction``\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn import linear_model\n >>> X = np.array([[-1, -1], [-2, -1], [1, 1], [2, 1]])\n >>> clf = linear_model.SGDOneClassSVM(random_state=42)\n >>> clf.fit(X)\n SGDOneClassSVM(random_state=42)\n\n >>> print(clf.predict([[4, 4]]))\n [1]\n\n See also\n --------\n sklearn.svm.OneClassSVM\n\n Notes\n -----\n This estimator has a linear complexity in the number of training samples\n and is thus better suited than the `sklearn.svm.OneClassSVM`\n implementation for datasets with a large number of training samples (say\n > 10,000).\n \"\"\"\n loss_functions = {'hinge': (Hinge, 1.0)}\n \n def __init__(self, nu=0.5, fit_intercept=True, max_iter=1000, tol=0.001, shuffle=True, verbose=0, random_state=None, learning_rate='optimal', eta0=0.0, power_t=0.5, warm_start=False, average=False):\n alpha = nu / 2\n self.nu = nu\n super(SGDOneClassSVM, self).__init__(loss='hinge', penalty='l2', alpha=alpha, C=1.0, l1_ratio=0, fit_intercept=fit_intercept, max_iter=max_iter, tol=tol, shuffle=shuffle, verbose=verbose, epsilon=DEFAULT_EPSILON, random_state=random_state, learning_rate=learning_rate, eta0=eta0, power_t=power_t, early_stopping=False, validation_fraction=0.1, n_iter_no_change=5, warm_start=warm_start, average=average)\n \n def _validate_params(self, for_partial_fit=False):\n \"\"\"Validate input params.\"\"\"\n if not 0 < self.nu <= 1:\n raise ValueError('nu must be in (0, 1], got nu=%f' % self.nu)\n super(SGDOneClassSVM, self)._validate_params(for_partial_fit=for_partial_fit)\n \n def _fit_one_class(self, X, alpha, C, sample_weight, learning_rate, max_iter):\n \"\"\"Uses SGD implementation with X and y=np.ones(n_samples).\"\"\"\n n_samples = X.shape[0]\n y = np.ones(n_samples, dtype=np.float64, order='C')\n (dataset, offset_decay) = make_dataset(X, y, sample_weight)\n penalty_type = self._get_penalty_type(self.penalty)\n learning_rate_type = self._get_learning_rate_type(learning_rate)\n validation_mask = self._make_validation_split(y)\n validation_score_cb = self._make_validation_score_cb(validation_mask, X, y, sample_weight)\n random_state = check_random_state(self.random_state)\n seed = random_state.randint(0, np.iinfo(np.int32).max)\n tol = self.tol if self.tol is not None else -np.inf\n one_class = 1\n pos_weight = 1\n neg_weight = 1\n if self.average:\n coef = self._standard_coef\n intercept = self._standard_intercept\n average_coef = self._average_coef\n average_intercept = self._average_intercept\n else:\n coef = self.coef_\n intercept = 1 - self.offset_\n average_coef = None\n average_intercept = [0]\n (coef, intercept, average_coef, average_intercept, self.n_iter_) = _plain_sgd(coef, intercept[0], average_coef, average_intercept[0], self.loss_function_, penalty_type, alpha, C, self.l1_ratio, dataset, validation_mask, self.early_stopping, validation_score_cb, int(self.n_iter_no_change), max_iter, tol, int(self.fit_intercept), int(self.verbose), int(self.shuffle), seed, neg_weight, pos_weight, learning_rate_type, self.eta0, self.power_t, one_class, self.t_, offset_decay, self.average)\n self.t_ += self.n_iter_ * n_samples\n if self.average > 0:\n self._average_intercept = np.atleast_1d(average_intercept)\n self._standard_intercept = np.atleast_1d(intercept)\n if self.average <= self.t_ - 1.0:\n self.coef_ = average_coef\n self.offset_ = 1 - np.atleast_1d(average_intercept)\n else:\n self.coef_ = coef\n self.offset_ = 1 - np.atleast_1d(intercept)\n else:\n self.offset_ = 1 - np.atleast_1d(intercept)\n \n def _partial_fit(self, X, alpha, C, loss, learning_rate, max_iter, sample_weight, coef_init, offset_init):\n first_call = getattr(self, 'coef_', None) is None\n X = self._validate_data(X, None, accept_sparse='csr', dtype=np.float64, order='C', accept_large_sparse=False, reset=first_call)\n n_features = X.shape[1]\n sample_weight = _check_sample_weight(sample_weight, X)\n if getattr(self, 'coef_', None) is None or coef_init is not None:\n self._allocate_parameter_mem(1, n_features, coef_init, offset_init, 1)\n elif n_features != self.coef_.shape[-1]:\n raise ValueError('Number of features %d does not match previous data %d.' % (n_features, self.coef_.shape[-1]))\n if self.average and getattr(self, '_average_coef', None) is None:\n self._average_coef = np.zeros(n_features, dtype=np.float64, order='C')\n self._average_intercept = np.zeros(1, dtype=np.float64, order='C')\n self.loss_function_ = self._get_loss_function(loss)\n if not hasattr(self, 't_'):\n self.t_ = 1.0\n self._fit_one_class(X, alpha=alpha, C=C, learning_rate=learning_rate, sample_weight=sample_weight, max_iter=max_iter)\n return self\n \n def partial_fit(self, X, y=None, sample_weight=None):\n \"\"\"Fit linear One-Class SVM with Stochastic Gradient Descent.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Subset of the training data.\n\n sample_weight : array-like, shape (n_samples,), optional\n Weights applied to individual samples.\n If not provided, uniform weights are assumed.\n\n Returns\n -------\n self : returns an instance of self.\n \"\"\"\n alpha = self.nu / 2\n self._validate_params(for_partial_fit=True)\n return self._partial_fit(X, alpha, C=1.0, loss=self.loss, learning_rate=self.learning_rate, max_iter=1, sample_weight=sample_weight, coef_init=None, offset_init=None)\n \n def _fit(self, X, alpha, C, loss, learning_rate, coef_init=None, offset_init=None, sample_weight=None):\n self._validate_params()\n if self.warm_start and hasattr(self, 'coef_'):\n if coef_init is None:\n coef_init = self.coef_\n if offset_init is None:\n offset_init = self.offset_\n else:\n self.coef_ = None\n self.offset_ = None\n self.t_ = 1.0\n self._partial_fit(X, alpha, C, loss, learning_rate, self.max_iter, sample_weight, coef_init, offset_init)\n if self.tol is not None and self.tol > -np.inf and self.n_iter_ == self.max_iter:\n warnings.warn('Maximum number of iteration reached before convergence. Consider increasing max_iter to improve the fit.', ConvergenceWarning)\n return self\n \n def fit(self, X, y=None, coef_init=None, offset_init=None, sample_weight=None):\n \"\"\"Fit linear One-Class SVM with Stochastic Gradient Descent.\n\n This solves an equivalent optimization problem of the\n One-Class SVM primal optimization problem and returns a weight vector\n w and an offset rho such that the decision function is given by\n - rho.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Training data.\n\n coef_init : array, shape (n_classes, n_features)\n The initial coefficients to warm-start the optimization.\n\n offset_init : array, shape (n_classes,)\n The initial offset to warm-start the optimization.\n\n sample_weight : array-like, shape (n_samples,), optional\n Weights applied to individual samples.\n If not provided, uniform weights are assumed. These weights will\n be multiplied with class_weight (passed through the\n constructor) if class_weight is specified.\n\n Returns\n -------\n self : returns an instance of self.\n \"\"\"\n alpha = self.nu / 2\n self._fit(X, alpha=alpha, C=1.0, loss=self.loss, learning_rate=self.learning_rate, coef_init=coef_init, offset_init=offset_init, sample_weight=sample_weight)\n return self\n \n def decision_function(self, X):\n \"\"\"Signed distance to the separating hyperplane.\n\n Signed distance is positive for an inlier and negative for an\n outlier.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Testing data.\n\n Returns\n -------\n dec : array-like, shape (n_samples,)\n Decision function values of the samples.\n \"\"\"\n check_is_fitted(self, 'coef_')\n X = self._validate_data(X, accept_sparse='csr', reset=False)\n decisions = safe_sparse_dot(X, self.coef_.T, dense_output=True) - self.offset_\n return decisions.ravel()\n \n def score_samples(self, X):\n \"\"\"Raw scoring function of the samples.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Testing data.\n\n Returns\n -------\n score_samples : array-like, shape (n_samples,)\n Unshiffted scoring function values of the samples.\n \"\"\"\n score_samples = self.decision_function(X) + self.offset_\n return score_samples\n \n def predict(self, X):\n \"\"\"Return labels (1 inlier, -1 outlier) of the samples.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Testing data.\n\n Returns\n -------\n y : array, shape (n_samples,)\n Labels of the samples.\n \"\"\"\n y = (self.decision_function(X) >= 0).astype(np.int32)\n y[y == 0] = -1\n return y\n \n def _more_tags(self):\n return {'_xfail_checks': {'check_sample_weights_invariance': 'zero sample_weight is not equivalent to removing samples'}}\n" + "docstring": "Solves linear One-Class SVM using Stochastic Gradient Descent.\n\n This implementation is meant to be used with a kernel approximation\n technique (e.g. `sklearn.kernel_approximation.Nystroem`) to obtain results\n similar to `sklearn.svm.OneClassSVM` which uses a Gaussian kernel by\n default.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 1.0\n\n Parameters\n ----------\n nu : float, optional\n The nu parameter of the One Class SVM: an upper bound on the\n fraction of training errors and a lower bound of the fraction of\n support vectors. Should be in the interval (0, 1]. By default 0.5\n will be taken.\n\n fit_intercept : bool\n Whether the intercept should be estimated or not. Defaults to True.\n\n max_iter : int, optional\n The maximum number of passes over the training data (aka epochs).\n It only impacts the behavior in the ``fit`` method, and not the\n `partial_fit`. Defaults to 1000.\n\n tol : float or None, optional\n The stopping criterion. If it is not None, the iterations will stop\n when (loss > previous_loss - tol). Defaults to 1e-3.\n\n shuffle : bool, optional\n Whether or not the training data should be shuffled after each epoch.\n Defaults to True.\n\n verbose : int, optional\n The verbosity level.\n\n random_state : int, RandomState instance or None, optional (default=None)\n The seed of the pseudo random number generator to use when shuffling\n the data. If int, random_state is the seed used by the random number\n generator; If RandomState instance, random_state is the random number\n generator; If None, the random number generator is the RandomState\n instance used by `np.random`.\n\n learning_rate : str, optional\n The learning rate schedule to use with `fit`. (If using `partial_fit`,\n learning rate must be controlled directly).\n\n 'constant':\n eta = eta0\n 'optimal': [default]\n eta = 1.0 / (alpha * (t + t0))\n where t0 is chosen by a heuristic proposed by Leon Bottou.\n 'invscaling':\n eta = eta0 / pow(t, power_t)\n 'adaptive':\n eta = eta0, as long as the training keeps decreasing.\n Each time n_iter_no_change consecutive epochs fail to decrease the\n training loss by tol or fail to increase validation score by tol if\n early_stopping is True, the current learning rate is divided by 5.\n\n eta0 : double\n The initial learning rate for the 'constant', 'invscaling' or\n 'adaptive' schedules. The default value is 0.0 as eta0 is not used by\n the default schedule 'optimal'.\n\n power_t : double\n The exponent for inverse scaling learning rate [default 0.5].\n\n warm_start : bool, optional\n When set to True, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n Repeatedly calling fit or partial_fit when warm_start is True can\n result in a different solution than when calling fit a single time\n because of the way the data is shuffled.\n If a dynamic learning rate is used, the learning rate is adapted\n depending on the number of samples already seen. Calling ``fit`` resets\n this counter, while ``partial_fit`` will result in increasing the\n existing counter.\n\n average : bool or int, optional\n When set to True, computes the averaged SGD weights and stores the\n result in the ``coef_`` attribute. If set to an int greater than 1,\n averaging will begin once the total number of samples seen reaches\n average. So ``average=10`` will begin averaging after seeing 10\n samples.\n\n Attributes\n ----------\n coef_ : array, shape (1, n_features)\n Weights assigned to the features.\n\n offset_ : array, shape (1,)\n Offset used to define the decision function from the raw scores.\n We have the relation: decision_function = score_samples - offset.\n\n n_iter_ : int\n The actual number of iterations to reach the stopping criterion.\n\n t_ : int\n Number of weight updates performed during training.\n Same as ``(n_iter_ * n_samples)``.\n\n loss_function_ : concrete ``LossFunction``\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n sklearn.svm.OneClassSVM : Unsupervised Outlier Detection.\n\n Notes\n -----\n This estimator has a linear complexity in the number of training samples\n and is thus better suited than the `sklearn.svm.OneClassSVM`\n implementation for datasets with a large number of training samples (say\n > 10,000).\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn import linear_model\n >>> X = np.array([[-1, -1], [-2, -1], [1, 1], [2, 1]])\n >>> clf = linear_model.SGDOneClassSVM(random_state=42)\n >>> clf.fit(X)\n SGDOneClassSVM(random_state=42)\n\n >>> print(clf.predict([[4, 4]]))\n [1]\n ", + "source_code": "\n\nclass SGDOneClassSVM(BaseSGD, OutlierMixin):\n \"\"\"Solves linear One-Class SVM using Stochastic Gradient Descent.\n\n This implementation is meant to be used with a kernel approximation\n technique (e.g. `sklearn.kernel_approximation.Nystroem`) to obtain results\n similar to `sklearn.svm.OneClassSVM` which uses a Gaussian kernel by\n default.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 1.0\n\n Parameters\n ----------\n nu : float, optional\n The nu parameter of the One Class SVM: an upper bound on the\n fraction of training errors and a lower bound of the fraction of\n support vectors. Should be in the interval (0, 1]. By default 0.5\n will be taken.\n\n fit_intercept : bool\n Whether the intercept should be estimated or not. Defaults to True.\n\n max_iter : int, optional\n The maximum number of passes over the training data (aka epochs).\n It only impacts the behavior in the ``fit`` method, and not the\n `partial_fit`. Defaults to 1000.\n\n tol : float or None, optional\n The stopping criterion. If it is not None, the iterations will stop\n when (loss > previous_loss - tol). Defaults to 1e-3.\n\n shuffle : bool, optional\n Whether or not the training data should be shuffled after each epoch.\n Defaults to True.\n\n verbose : int, optional\n The verbosity level.\n\n random_state : int, RandomState instance or None, optional (default=None)\n The seed of the pseudo random number generator to use when shuffling\n the data. If int, random_state is the seed used by the random number\n generator; If RandomState instance, random_state is the random number\n generator; If None, the random number generator is the RandomState\n instance used by `np.random`.\n\n learning_rate : str, optional\n The learning rate schedule to use with `fit`. (If using `partial_fit`,\n learning rate must be controlled directly).\n\n 'constant':\n eta = eta0\n 'optimal': [default]\n eta = 1.0 / (alpha * (t + t0))\n where t0 is chosen by a heuristic proposed by Leon Bottou.\n 'invscaling':\n eta = eta0 / pow(t, power_t)\n 'adaptive':\n eta = eta0, as long as the training keeps decreasing.\n Each time n_iter_no_change consecutive epochs fail to decrease the\n training loss by tol or fail to increase validation score by tol if\n early_stopping is True, the current learning rate is divided by 5.\n\n eta0 : double\n The initial learning rate for the 'constant', 'invscaling' or\n 'adaptive' schedules. The default value is 0.0 as eta0 is not used by\n the default schedule 'optimal'.\n\n power_t : double\n The exponent for inverse scaling learning rate [default 0.5].\n\n warm_start : bool, optional\n When set to True, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n Repeatedly calling fit or partial_fit when warm_start is True can\n result in a different solution than when calling fit a single time\n because of the way the data is shuffled.\n If a dynamic learning rate is used, the learning rate is adapted\n depending on the number of samples already seen. Calling ``fit`` resets\n this counter, while ``partial_fit`` will result in increasing the\n existing counter.\n\n average : bool or int, optional\n When set to True, computes the averaged SGD weights and stores the\n result in the ``coef_`` attribute. If set to an int greater than 1,\n averaging will begin once the total number of samples seen reaches\n average. So ``average=10`` will begin averaging after seeing 10\n samples.\n\n Attributes\n ----------\n coef_ : array, shape (1, n_features)\n Weights assigned to the features.\n\n offset_ : array, shape (1,)\n Offset used to define the decision function from the raw scores.\n We have the relation: decision_function = score_samples - offset.\n\n n_iter_ : int\n The actual number of iterations to reach the stopping criterion.\n\n t_ : int\n Number of weight updates performed during training.\n Same as ``(n_iter_ * n_samples)``.\n\n loss_function_ : concrete ``LossFunction``\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n sklearn.svm.OneClassSVM : Unsupervised Outlier Detection.\n\n Notes\n -----\n This estimator has a linear complexity in the number of training samples\n and is thus better suited than the `sklearn.svm.OneClassSVM`\n implementation for datasets with a large number of training samples (say\n > 10,000).\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn import linear_model\n >>> X = np.array([[-1, -1], [-2, -1], [1, 1], [2, 1]])\n >>> clf = linear_model.SGDOneClassSVM(random_state=42)\n >>> clf.fit(X)\n SGDOneClassSVM(random_state=42)\n\n >>> print(clf.predict([[4, 4]]))\n [1]\n \"\"\"\n loss_functions = {'hinge': (Hinge, 1.0)}\n \n def __init__(self, nu=0.5, fit_intercept=True, max_iter=1000, tol=0.001, shuffle=True, verbose=0, random_state=None, learning_rate='optimal', eta0=0.0, power_t=0.5, warm_start=False, average=False):\n alpha = nu / 2\n self.nu = nu\n super(SGDOneClassSVM, self).__init__(loss='hinge', penalty='l2', alpha=alpha, C=1.0, l1_ratio=0, fit_intercept=fit_intercept, max_iter=max_iter, tol=tol, shuffle=shuffle, verbose=verbose, epsilon=DEFAULT_EPSILON, random_state=random_state, learning_rate=learning_rate, eta0=eta0, power_t=power_t, early_stopping=False, validation_fraction=0.1, n_iter_no_change=5, warm_start=warm_start, average=average)\n \n def _validate_params(self, for_partial_fit=False):\n \"\"\"Validate input params.\"\"\"\n if not 0 < self.nu <= 1:\n raise ValueError('nu must be in (0, 1], got nu=%f' % self.nu)\n super(SGDOneClassSVM, self)._validate_params(for_partial_fit=for_partial_fit)\n \n def _fit_one_class(self, X, alpha, C, sample_weight, learning_rate, max_iter):\n \"\"\"Uses SGD implementation with X and y=np.ones(n_samples).\"\"\"\n n_samples = X.shape[0]\n y = np.ones(n_samples, dtype=np.float64, order='C')\n (dataset, offset_decay) = make_dataset(X, y, sample_weight)\n penalty_type = self._get_penalty_type(self.penalty)\n learning_rate_type = self._get_learning_rate_type(learning_rate)\n validation_mask = self._make_validation_split(y)\n validation_score_cb = self._make_validation_score_cb(validation_mask, X, y, sample_weight)\n random_state = check_random_state(self.random_state)\n seed = random_state.randint(0, np.iinfo(np.int32).max)\n tol = self.tol if self.tol is not None else -np.inf\n one_class = 1\n pos_weight = 1\n neg_weight = 1\n if self.average:\n coef = self._standard_coef\n intercept = self._standard_intercept\n average_coef = self._average_coef\n average_intercept = self._average_intercept\n else:\n coef = self.coef_\n intercept = 1 - self.offset_\n average_coef = None\n average_intercept = [0]\n (coef, intercept, average_coef, average_intercept, self.n_iter_) = _plain_sgd(coef, intercept[0], average_coef, average_intercept[0], self.loss_function_, penalty_type, alpha, C, self.l1_ratio, dataset, validation_mask, self.early_stopping, validation_score_cb, int(self.n_iter_no_change), max_iter, tol, int(self.fit_intercept), int(self.verbose), int(self.shuffle), seed, neg_weight, pos_weight, learning_rate_type, self.eta0, self.power_t, one_class, self.t_, offset_decay, self.average)\n self.t_ += self.n_iter_ * n_samples\n if self.average > 0:\n self._average_intercept = np.atleast_1d(average_intercept)\n self._standard_intercept = np.atleast_1d(intercept)\n if self.average <= self.t_ - 1.0:\n self.coef_ = average_coef\n self.offset_ = 1 - np.atleast_1d(average_intercept)\n else:\n self.coef_ = coef\n self.offset_ = 1 - np.atleast_1d(intercept)\n else:\n self.offset_ = 1 - np.atleast_1d(intercept)\n \n def _partial_fit(self, X, alpha, C, loss, learning_rate, max_iter, sample_weight, coef_init, offset_init):\n first_call = getattr(self, 'coef_', None) is None\n X = self._validate_data(X, None, accept_sparse='csr', dtype=np.float64, order='C', accept_large_sparse=False, reset=first_call)\n n_features = X.shape[1]\n sample_weight = _check_sample_weight(sample_weight, X)\n if getattr(self, 'coef_', None) is None or coef_init is not None:\n self._allocate_parameter_mem(1, n_features, coef_init, offset_init, 1)\n elif n_features != self.coef_.shape[-1]:\n raise ValueError('Number of features %d does not match previous data %d.' % (n_features, self.coef_.shape[-1]))\n if self.average and getattr(self, '_average_coef', None) is None:\n self._average_coef = np.zeros(n_features, dtype=np.float64, order='C')\n self._average_intercept = np.zeros(1, dtype=np.float64, order='C')\n self.loss_function_ = self._get_loss_function(loss)\n if not hasattr(self, 't_'):\n self.t_ = 1.0\n self._fit_one_class(X, alpha=alpha, C=C, learning_rate=learning_rate, sample_weight=sample_weight, max_iter=max_iter)\n return self\n \n def partial_fit(self, X, y=None, sample_weight=None):\n \"\"\"Fit linear One-Class SVM with Stochastic Gradient Descent.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Subset of the training data.\n y : Ignored\n Not used, present for API consistency by convention.\n\n sample_weight : array-like, shape (n_samples,), optional\n Weights applied to individual samples.\n If not provided, uniform weights are assumed.\n\n Returns\n -------\n self : object\n Returns a fitted instance of self.\n \"\"\"\n alpha = self.nu / 2\n self._validate_params(for_partial_fit=True)\n return self._partial_fit(X, alpha, C=1.0, loss=self.loss, learning_rate=self.learning_rate, max_iter=1, sample_weight=sample_weight, coef_init=None, offset_init=None)\n \n def _fit(self, X, alpha, C, loss, learning_rate, coef_init=None, offset_init=None, sample_weight=None):\n self._validate_params()\n if self.warm_start and hasattr(self, 'coef_'):\n if coef_init is None:\n coef_init = self.coef_\n if offset_init is None:\n offset_init = self.offset_\n else:\n self.coef_ = None\n self.offset_ = None\n self.t_ = 1.0\n self._partial_fit(X, alpha, C, loss, learning_rate, self.max_iter, sample_weight, coef_init, offset_init)\n if self.tol is not None and self.tol > -np.inf and self.n_iter_ == self.max_iter:\n warnings.warn('Maximum number of iteration reached before convergence. Consider increasing max_iter to improve the fit.', ConvergenceWarning)\n return self\n \n def fit(self, X, y=None, coef_init=None, offset_init=None, sample_weight=None):\n \"\"\"Fit linear One-Class SVM with Stochastic Gradient Descent.\n\n This solves an equivalent optimization problem of the\n One-Class SVM primal optimization problem and returns a weight vector\n w and an offset rho such that the decision function is given by\n - rho.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Training data.\n y : Ignored\n Not used, present for API consistency by convention.\n\n coef_init : array, shape (n_classes, n_features)\n The initial coefficients to warm-start the optimization.\n\n offset_init : array, shape (n_classes,)\n The initial offset to warm-start the optimization.\n\n sample_weight : array-like, shape (n_samples,), optional\n Weights applied to individual samples.\n If not provided, uniform weights are assumed. These weights will\n be multiplied with class_weight (passed through the\n constructor) if class_weight is specified.\n\n Returns\n -------\n self : object\n Returns a fitted instance of self.\n \"\"\"\n alpha = self.nu / 2\n self._fit(X, alpha=alpha, C=1.0, loss=self.loss, learning_rate=self.learning_rate, coef_init=coef_init, offset_init=offset_init, sample_weight=sample_weight)\n return self\n \n def decision_function(self, X):\n \"\"\"Signed distance to the separating hyperplane.\n\n Signed distance is positive for an inlier and negative for an\n outlier.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Testing data.\n\n Returns\n -------\n dec : array-like, shape (n_samples,)\n Decision function values of the samples.\n \"\"\"\n check_is_fitted(self, 'coef_')\n X = self._validate_data(X, accept_sparse='csr', reset=False)\n decisions = safe_sparse_dot(X, self.coef_.T, dense_output=True) - self.offset_\n return decisions.ravel()\n \n def score_samples(self, X):\n \"\"\"Raw scoring function of the samples.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Testing data.\n\n Returns\n -------\n score_samples : array-like, shape (n_samples,)\n Unshiffted scoring function values of the samples.\n \"\"\"\n score_samples = self.decision_function(X) + self.offset_\n return score_samples\n \n def predict(self, X):\n \"\"\"Return labels (1 inlier, -1 outlier) of the samples.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Testing data.\n\n Returns\n -------\n y : array, shape (n_samples,)\n Labels of the samples.\n \"\"\"\n y = (self.decision_function(X) >= 0).astype(np.int32)\n y[y == 0] = -1\n return y\n \n def _more_tags(self):\n return {'_xfail_checks': {'check_sample_weights_invariance': 'zero sample_weight is not equivalent to removing samples'}}\n" }, { "name": "SGDRegressor", @@ -24240,9 +24193,9 @@ "sklearn.linear_model._stochastic_gradient.SGDRegressor._more_tags" ], "is_public": true, - "description": "Linear model fitted by minimizing a regularized empirical loss with SGD\n\nSGD stands for Stochastic Gradient Descent: the gradient of the loss is estimated each sample at a time and the model is updated along the way with a decreasing strength schedule (aka learning rate). The regularizer is a penalty added to the loss function that shrinks model parameters towards the zero vector using either the squared euclidean norm L2 or the absolute norm L1 or a combination of both (Elastic Net). If the parameter update crosses the 0.0 value because of the regularizer, the update is truncated to 0.0 to allow for learning sparse models and achieve online feature selection. This implementation works with data represented as dense numpy arrays of floating point values for the features. Read more in the :ref:`User Guide `.", - "docstring": "Linear model fitted by minimizing a regularized empirical loss with SGD\n\n SGD stands for Stochastic Gradient Descent: the gradient of the loss is\n estimated each sample at a time and the model is updated along the way with\n a decreasing strength schedule (aka learning rate).\n\n The regularizer is a penalty added to the loss function that shrinks model\n parameters towards the zero vector using either the squared euclidean norm\n L2 or the absolute norm L1 or a combination of both (Elastic Net). If the\n parameter update crosses the 0.0 value because of the regularizer, the\n update is truncated to 0.0 to allow for learning sparse models and achieve\n online feature selection.\n\n This implementation works with data represented as dense numpy arrays of\n floating point values for the features.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n loss : str, default='squared_error'\n The loss function to be used. The possible values are 'squared_error',\n 'huber', 'epsilon_insensitive', or 'squared_epsilon_insensitive'\n\n The 'squared_error' refers to the ordinary least squares fit.\n 'huber' modifies 'squared_error' to focus less on getting outliers\n correct by switching from squared to linear loss past a distance of\n epsilon. 'epsilon_insensitive' ignores errors less than epsilon and is\n linear past that; this is the loss function used in SVR.\n 'squared_epsilon_insensitive' is the same but becomes squared loss past\n a tolerance of epsilon.\n\n More details about the losses formulas can be found in the\n :ref:`User Guide `.\n\n .. deprecated:: 1.0\n The loss 'squared_loss' was deprecated in v1.0 and will be removed\n in version 1.2. Use `loss='squared_error'` which is equivalent.\n\n penalty : {'l2', 'l1', 'elasticnet'}, default='l2'\n The penalty (aka regularization term) to be used. Defaults to 'l2'\n which is the standard regularizer for linear SVM models. 'l1' and\n 'elasticnet' might bring sparsity to the model (feature selection)\n not achievable with 'l2'.\n\n alpha : float, default=0.0001\n Constant that multiplies the regularization term. The higher the\n value, the stronger the regularization.\n Also used to compute the learning rate when set to `learning_rate` is\n set to 'optimal'.\n\n l1_ratio : float, default=0.15\n The Elastic Net mixing parameter, with 0 <= l1_ratio <= 1.\n l1_ratio=0 corresponds to L2 penalty, l1_ratio=1 to L1.\n Only used if `penalty` is 'elasticnet'.\n\n fit_intercept : bool, default=True\n Whether the intercept should be estimated or not. If False, the\n data is assumed to be already centered.\n\n max_iter : int, default=1000\n The maximum number of passes over the training data (aka epochs).\n It only impacts the behavior in the ``fit`` method, and not the\n :meth:`partial_fit` method.\n\n .. versionadded:: 0.19\n\n tol : float, default=1e-3\n The stopping criterion. If it is not None, training will stop\n when (loss > best_loss - tol) for ``n_iter_no_change`` consecutive\n epochs.\n Convergence is checked against the training loss or the\n validation loss depending on the `early_stopping` parameter.\n\n .. versionadded:: 0.19\n\n shuffle : bool, default=True\n Whether or not the training data should be shuffled after each epoch.\n\n verbose : int, default=0\n The verbosity level.\n\n epsilon : float, default=0.1\n Epsilon in the epsilon-insensitive loss functions; only if `loss` is\n 'huber', 'epsilon_insensitive', or 'squared_epsilon_insensitive'.\n For 'huber', determines the threshold at which it becomes less\n important to get the prediction exactly right.\n For epsilon-insensitive, any differences between the current prediction\n and the correct label are ignored if they are less than this threshold.\n\n random_state : int, RandomState instance, default=None\n Used for shuffling the data, when ``shuffle`` is set to ``True``.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n learning_rate : string, default='invscaling'\n The learning rate schedule:\n\n - 'constant': `eta = eta0`\n - 'optimal': `eta = 1.0 / (alpha * (t + t0))`\n where t0 is chosen by a heuristic proposed by Leon Bottou.\n - 'invscaling': `eta = eta0 / pow(t, power_t)`\n - 'adaptive': eta = eta0, as long as the training keeps decreasing.\n Each time n_iter_no_change consecutive epochs fail to decrease the\n training loss by tol or fail to increase validation score by tol if\n early_stopping is True, the current learning rate is divided by 5.\n\n .. versionadded:: 0.20\n Added 'adaptive' option\n\n eta0 : double, default=0.01\n The initial learning rate for the 'constant', 'invscaling' or\n 'adaptive' schedules. The default value is 0.01.\n\n power_t : double, default=0.25\n The exponent for inverse scaling learning rate.\n\n early_stopping : bool, default=False\n Whether to use early stopping to terminate training when validation\n score is not improving. If set to True, it will automatically set aside\n a fraction of training data as validation and terminate\n training when validation score returned by the `score` method is not\n improving by at least `tol` for `n_iter_no_change` consecutive\n epochs.\n\n .. versionadded:: 0.20\n Added 'early_stopping' option\n\n validation_fraction : float, default=0.1\n The proportion of training data to set aside as validation set for\n early stopping. Must be between 0 and 1.\n Only used if `early_stopping` is True.\n\n .. versionadded:: 0.20\n Added 'validation_fraction' option\n\n n_iter_no_change : int, default=5\n Number of iterations with no improvement to wait before stopping\n fitting.\n Convergence is checked against the training loss or the\n validation loss depending on the `early_stopping` parameter.\n\n .. versionadded:: 0.20\n Added 'n_iter_no_change' option\n\n warm_start : bool, default=False\n When set to True, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n Repeatedly calling fit or partial_fit when warm_start is True can\n result in a different solution than when calling fit a single time\n because of the way the data is shuffled.\n If a dynamic learning rate is used, the learning rate is adapted\n depending on the number of samples already seen. Calling ``fit`` resets\n this counter, while ``partial_fit`` will result in increasing the\n existing counter.\n\n average : bool or int, default=False\n When set to True, computes the averaged SGD weights across all\n updates and stores the result in the ``coef_`` attribute. If set to\n an int greater than 1, averaging will begin once the total number of\n samples seen reaches `average`. So ``average=10`` will begin\n averaging after seeing 10 samples.\n\n Attributes\n ----------\n coef_ : ndarray of shape (n_features,)\n Weights assigned to the features.\n\n intercept_ : ndarray of shape (1,)\n The intercept term.\n\n n_iter_ : int\n The actual number of iterations before reaching the stopping criterion.\n\n t_ : int\n Number of weight updates performed during training.\n Same as ``(n_iter_ * n_samples)``.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.linear_model import SGDRegressor\n >>> from sklearn.pipeline import make_pipeline\n >>> from sklearn.preprocessing import StandardScaler\n >>> n_samples, n_features = 10, 5\n >>> rng = np.random.RandomState(0)\n >>> y = rng.randn(n_samples)\n >>> X = rng.randn(n_samples, n_features)\n >>> # Always scale the input. The most convenient way is to use a pipeline.\n >>> reg = make_pipeline(StandardScaler(),\n ... SGDRegressor(max_iter=1000, tol=1e-3))\n >>> reg.fit(X, y)\n Pipeline(steps=[('standardscaler', StandardScaler()),\n ('sgdregressor', SGDRegressor())])\n\n See Also\n --------\n Ridge, ElasticNet, Lasso, sklearn.svm.SVR\n\n ", - "source_code": "\n\nclass SGDRegressor(BaseSGDRegressor):\n \"\"\"Linear model fitted by minimizing a regularized empirical loss with SGD\n\n SGD stands for Stochastic Gradient Descent: the gradient of the loss is\n estimated each sample at a time and the model is updated along the way with\n a decreasing strength schedule (aka learning rate).\n\n The regularizer is a penalty added to the loss function that shrinks model\n parameters towards the zero vector using either the squared euclidean norm\n L2 or the absolute norm L1 or a combination of both (Elastic Net). If the\n parameter update crosses the 0.0 value because of the regularizer, the\n update is truncated to 0.0 to allow for learning sparse models and achieve\n online feature selection.\n\n This implementation works with data represented as dense numpy arrays of\n floating point values for the features.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n loss : str, default='squared_error'\n The loss function to be used. The possible values are 'squared_error',\n 'huber', 'epsilon_insensitive', or 'squared_epsilon_insensitive'\n\n The 'squared_error' refers to the ordinary least squares fit.\n 'huber' modifies 'squared_error' to focus less on getting outliers\n correct by switching from squared to linear loss past a distance of\n epsilon. 'epsilon_insensitive' ignores errors less than epsilon and is\n linear past that; this is the loss function used in SVR.\n 'squared_epsilon_insensitive' is the same but becomes squared loss past\n a tolerance of epsilon.\n\n More details about the losses formulas can be found in the\n :ref:`User Guide `.\n\n .. deprecated:: 1.0\n The loss 'squared_loss' was deprecated in v1.0 and will be removed\n in version 1.2. Use `loss='squared_error'` which is equivalent.\n\n penalty : {'l2', 'l1', 'elasticnet'}, default='l2'\n The penalty (aka regularization term) to be used. Defaults to 'l2'\n which is the standard regularizer for linear SVM models. 'l1' and\n 'elasticnet' might bring sparsity to the model (feature selection)\n not achievable with 'l2'.\n\n alpha : float, default=0.0001\n Constant that multiplies the regularization term. The higher the\n value, the stronger the regularization.\n Also used to compute the learning rate when set to `learning_rate` is\n set to 'optimal'.\n\n l1_ratio : float, default=0.15\n The Elastic Net mixing parameter, with 0 <= l1_ratio <= 1.\n l1_ratio=0 corresponds to L2 penalty, l1_ratio=1 to L1.\n Only used if `penalty` is 'elasticnet'.\n\n fit_intercept : bool, default=True\n Whether the intercept should be estimated or not. If False, the\n data is assumed to be already centered.\n\n max_iter : int, default=1000\n The maximum number of passes over the training data (aka epochs).\n It only impacts the behavior in the ``fit`` method, and not the\n :meth:`partial_fit` method.\n\n .. versionadded:: 0.19\n\n tol : float, default=1e-3\n The stopping criterion. If it is not None, training will stop\n when (loss > best_loss - tol) for ``n_iter_no_change`` consecutive\n epochs.\n Convergence is checked against the training loss or the\n validation loss depending on the `early_stopping` parameter.\n\n .. versionadded:: 0.19\n\n shuffle : bool, default=True\n Whether or not the training data should be shuffled after each epoch.\n\n verbose : int, default=0\n The verbosity level.\n\n epsilon : float, default=0.1\n Epsilon in the epsilon-insensitive loss functions; only if `loss` is\n 'huber', 'epsilon_insensitive', or 'squared_epsilon_insensitive'.\n For 'huber', determines the threshold at which it becomes less\n important to get the prediction exactly right.\n For epsilon-insensitive, any differences between the current prediction\n and the correct label are ignored if they are less than this threshold.\n\n random_state : int, RandomState instance, default=None\n Used for shuffling the data, when ``shuffle`` is set to ``True``.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n learning_rate : string, default='invscaling'\n The learning rate schedule:\n\n - 'constant': `eta = eta0`\n - 'optimal': `eta = 1.0 / (alpha * (t + t0))`\n where t0 is chosen by a heuristic proposed by Leon Bottou.\n - 'invscaling': `eta = eta0 / pow(t, power_t)`\n - 'adaptive': eta = eta0, as long as the training keeps decreasing.\n Each time n_iter_no_change consecutive epochs fail to decrease the\n training loss by tol or fail to increase validation score by tol if\n early_stopping is True, the current learning rate is divided by 5.\n\n .. versionadded:: 0.20\n Added 'adaptive' option\n\n eta0 : double, default=0.01\n The initial learning rate for the 'constant', 'invscaling' or\n 'adaptive' schedules. The default value is 0.01.\n\n power_t : double, default=0.25\n The exponent for inverse scaling learning rate.\n\n early_stopping : bool, default=False\n Whether to use early stopping to terminate training when validation\n score is not improving. If set to True, it will automatically set aside\n a fraction of training data as validation and terminate\n training when validation score returned by the `score` method is not\n improving by at least `tol` for `n_iter_no_change` consecutive\n epochs.\n\n .. versionadded:: 0.20\n Added 'early_stopping' option\n\n validation_fraction : float, default=0.1\n The proportion of training data to set aside as validation set for\n early stopping. Must be between 0 and 1.\n Only used if `early_stopping` is True.\n\n .. versionadded:: 0.20\n Added 'validation_fraction' option\n\n n_iter_no_change : int, default=5\n Number of iterations with no improvement to wait before stopping\n fitting.\n Convergence is checked against the training loss or the\n validation loss depending on the `early_stopping` parameter.\n\n .. versionadded:: 0.20\n Added 'n_iter_no_change' option\n\n warm_start : bool, default=False\n When set to True, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n Repeatedly calling fit or partial_fit when warm_start is True can\n result in a different solution than when calling fit a single time\n because of the way the data is shuffled.\n If a dynamic learning rate is used, the learning rate is adapted\n depending on the number of samples already seen. Calling ``fit`` resets\n this counter, while ``partial_fit`` will result in increasing the\n existing counter.\n\n average : bool or int, default=False\n When set to True, computes the averaged SGD weights across all\n updates and stores the result in the ``coef_`` attribute. If set to\n an int greater than 1, averaging will begin once the total number of\n samples seen reaches `average`. So ``average=10`` will begin\n averaging after seeing 10 samples.\n\n Attributes\n ----------\n coef_ : ndarray of shape (n_features,)\n Weights assigned to the features.\n\n intercept_ : ndarray of shape (1,)\n The intercept term.\n\n n_iter_ : int\n The actual number of iterations before reaching the stopping criterion.\n\n t_ : int\n Number of weight updates performed during training.\n Same as ``(n_iter_ * n_samples)``.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.linear_model import SGDRegressor\n >>> from sklearn.pipeline import make_pipeline\n >>> from sklearn.preprocessing import StandardScaler\n >>> n_samples, n_features = 10, 5\n >>> rng = np.random.RandomState(0)\n >>> y = rng.randn(n_samples)\n >>> X = rng.randn(n_samples, n_features)\n >>> # Always scale the input. The most convenient way is to use a pipeline.\n >>> reg = make_pipeline(StandardScaler(),\n ... SGDRegressor(max_iter=1000, tol=1e-3))\n >>> reg.fit(X, y)\n Pipeline(steps=[('standardscaler', StandardScaler()),\n ('sgdregressor', SGDRegressor())])\n\n See Also\n --------\n Ridge, ElasticNet, Lasso, sklearn.svm.SVR\n\n \"\"\"\n \n def __init__(self, loss='squared_error', *, penalty='l2', alpha=0.0001, l1_ratio=0.15, fit_intercept=True, max_iter=1000, tol=0.001, shuffle=True, verbose=0, epsilon=DEFAULT_EPSILON, random_state=None, learning_rate='invscaling', eta0=0.01, power_t=0.25, early_stopping=False, validation_fraction=0.1, n_iter_no_change=5, warm_start=False, average=False):\n super().__init__(loss=loss, penalty=penalty, alpha=alpha, l1_ratio=l1_ratio, fit_intercept=fit_intercept, max_iter=max_iter, tol=tol, shuffle=shuffle, verbose=verbose, epsilon=epsilon, random_state=random_state, learning_rate=learning_rate, eta0=eta0, power_t=power_t, early_stopping=early_stopping, validation_fraction=validation_fraction, n_iter_no_change=n_iter_no_change, warm_start=warm_start, average=average)\n \n def _more_tags(self):\n return {'_xfail_checks': {'check_sample_weights_invariance': 'zero sample_weight is not equivalent to removing samples'}}\n" + "description": "Linear model fitted by minimizing a regularized empirical loss with SGD.\n\nSGD stands for Stochastic Gradient Descent: the gradient of the loss is estimated each sample at a time and the model is updated along the way with a decreasing strength schedule (aka learning rate). The regularizer is a penalty added to the loss function that shrinks model parameters towards the zero vector using either the squared euclidean norm L2 or the absolute norm L1 or a combination of both (Elastic Net). If the parameter update crosses the 0.0 value because of the regularizer, the update is truncated to 0.0 to allow for learning sparse models and achieve online feature selection. This implementation works with data represented as dense numpy arrays of floating point values for the features. Read more in the :ref:`User Guide `.", + "docstring": "Linear model fitted by minimizing a regularized empirical loss with SGD.\n\n SGD stands for Stochastic Gradient Descent: the gradient of the loss is\n estimated each sample at a time and the model is updated along the way with\n a decreasing strength schedule (aka learning rate).\n\n The regularizer is a penalty added to the loss function that shrinks model\n parameters towards the zero vector using either the squared euclidean norm\n L2 or the absolute norm L1 or a combination of both (Elastic Net). If the\n parameter update crosses the 0.0 value because of the regularizer, the\n update is truncated to 0.0 to allow for learning sparse models and achieve\n online feature selection.\n\n This implementation works with data represented as dense numpy arrays of\n floating point values for the features.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n loss : str, default='squared_error'\n The loss function to be used. The possible values are 'squared_error',\n 'huber', 'epsilon_insensitive', or 'squared_epsilon_insensitive'\n\n The 'squared_error' refers to the ordinary least squares fit.\n 'huber' modifies 'squared_error' to focus less on getting outliers\n correct by switching from squared to linear loss past a distance of\n epsilon. 'epsilon_insensitive' ignores errors less than epsilon and is\n linear past that; this is the loss function used in SVR.\n 'squared_epsilon_insensitive' is the same but becomes squared loss past\n a tolerance of epsilon.\n\n More details about the losses formulas can be found in the\n :ref:`User Guide `.\n\n .. deprecated:: 1.0\n The loss 'squared_loss' was deprecated in v1.0 and will be removed\n in version 1.2. Use `loss='squared_error'` which is equivalent.\n\n penalty : {'l2', 'l1', 'elasticnet'}, default='l2'\n The penalty (aka regularization term) to be used. Defaults to 'l2'\n which is the standard regularizer for linear SVM models. 'l1' and\n 'elasticnet' might bring sparsity to the model (feature selection)\n not achievable with 'l2'.\n\n alpha : float, default=0.0001\n Constant that multiplies the regularization term. The higher the\n value, the stronger the regularization.\n Also used to compute the learning rate when set to `learning_rate` is\n set to 'optimal'.\n\n l1_ratio : float, default=0.15\n The Elastic Net mixing parameter, with 0 <= l1_ratio <= 1.\n l1_ratio=0 corresponds to L2 penalty, l1_ratio=1 to L1.\n Only used if `penalty` is 'elasticnet'.\n\n fit_intercept : bool, default=True\n Whether the intercept should be estimated or not. If False, the\n data is assumed to be already centered.\n\n max_iter : int, default=1000\n The maximum number of passes over the training data (aka epochs).\n It only impacts the behavior in the ``fit`` method, and not the\n :meth:`partial_fit` method.\n\n .. versionadded:: 0.19\n\n tol : float, default=1e-3\n The stopping criterion. If it is not None, training will stop\n when (loss > best_loss - tol) for ``n_iter_no_change`` consecutive\n epochs.\n Convergence is checked against the training loss or the\n validation loss depending on the `early_stopping` parameter.\n\n .. versionadded:: 0.19\n\n shuffle : bool, default=True\n Whether or not the training data should be shuffled after each epoch.\n\n verbose : int, default=0\n The verbosity level.\n\n epsilon : float, default=0.1\n Epsilon in the epsilon-insensitive loss functions; only if `loss` is\n 'huber', 'epsilon_insensitive', or 'squared_epsilon_insensitive'.\n For 'huber', determines the threshold at which it becomes less\n important to get the prediction exactly right.\n For epsilon-insensitive, any differences between the current prediction\n and the correct label are ignored if they are less than this threshold.\n\n random_state : int, RandomState instance, default=None\n Used for shuffling the data, when ``shuffle`` is set to ``True``.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n learning_rate : str, default='invscaling'\n The learning rate schedule:\n\n - 'constant': `eta = eta0`\n - 'optimal': `eta = 1.0 / (alpha * (t + t0))`\n where t0 is chosen by a heuristic proposed by Leon Bottou.\n - 'invscaling': `eta = eta0 / pow(t, power_t)`\n - 'adaptive': eta = eta0, as long as the training keeps decreasing.\n Each time n_iter_no_change consecutive epochs fail to decrease the\n training loss by tol or fail to increase validation score by tol if\n early_stopping is True, the current learning rate is divided by 5.\n\n .. versionadded:: 0.20\n Added 'adaptive' option\n\n eta0 : double, default=0.01\n The initial learning rate for the 'constant', 'invscaling' or\n 'adaptive' schedules. The default value is 0.01.\n\n power_t : double, default=0.25\n The exponent for inverse scaling learning rate.\n\n early_stopping : bool, default=False\n Whether to use early stopping to terminate training when validation\n score is not improving. If set to True, it will automatically set aside\n a fraction of training data as validation and terminate\n training when validation score returned by the `score` method is not\n improving by at least `tol` for `n_iter_no_change` consecutive\n epochs.\n\n .. versionadded:: 0.20\n Added 'early_stopping' option\n\n validation_fraction : float, default=0.1\n The proportion of training data to set aside as validation set for\n early stopping. Must be between 0 and 1.\n Only used if `early_stopping` is True.\n\n .. versionadded:: 0.20\n Added 'validation_fraction' option\n\n n_iter_no_change : int, default=5\n Number of iterations with no improvement to wait before stopping\n fitting.\n Convergence is checked against the training loss or the\n validation loss depending on the `early_stopping` parameter.\n\n .. versionadded:: 0.20\n Added 'n_iter_no_change' option\n\n warm_start : bool, default=False\n When set to True, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n Repeatedly calling fit or partial_fit when warm_start is True can\n result in a different solution than when calling fit a single time\n because of the way the data is shuffled.\n If a dynamic learning rate is used, the learning rate is adapted\n depending on the number of samples already seen. Calling ``fit`` resets\n this counter, while ``partial_fit`` will result in increasing the\n existing counter.\n\n average : bool or int, default=False\n When set to True, computes the averaged SGD weights across all\n updates and stores the result in the ``coef_`` attribute. If set to\n an int greater than 1, averaging will begin once the total number of\n samples seen reaches `average`. So ``average=10`` will begin\n averaging after seeing 10 samples.\n\n Attributes\n ----------\n coef_ : ndarray of shape (n_features,)\n Weights assigned to the features.\n\n intercept_ : ndarray of shape (1,)\n The intercept term.\n\n n_iter_ : int\n The actual number of iterations before reaching the stopping criterion.\n\n t_ : int\n Number of weight updates performed during training.\n Same as ``(n_iter_ * n_samples)``.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n HuberRegressor : Linear regression model that is robust to outliers.\n Lars : Least Angle Regression model.\n Lasso : Linear Model trained with L1 prior as regularizer.\n RANSACRegressor : RANSAC (RANdom SAmple Consensus) algorithm.\n Ridge : Linear least squares with l2 regularization.\n sklearn.svm.SVR : Epsilon-Support Vector Regression.\n TheilSenRegressor : Theil-Sen Estimator robust multivariate regression model.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.linear_model import SGDRegressor\n >>> from sklearn.pipeline import make_pipeline\n >>> from sklearn.preprocessing import StandardScaler\n >>> n_samples, n_features = 10, 5\n >>> rng = np.random.RandomState(0)\n >>> y = rng.randn(n_samples)\n >>> X = rng.randn(n_samples, n_features)\n >>> # Always scale the input. The most convenient way is to use a pipeline.\n >>> reg = make_pipeline(StandardScaler(),\n ... SGDRegressor(max_iter=1000, tol=1e-3))\n >>> reg.fit(X, y)\n Pipeline(steps=[('standardscaler', StandardScaler()),\n ('sgdregressor', SGDRegressor())])\n ", + "source_code": "\n\nclass SGDRegressor(BaseSGDRegressor):\n \"\"\"Linear model fitted by minimizing a regularized empirical loss with SGD.\n\n SGD stands for Stochastic Gradient Descent: the gradient of the loss is\n estimated each sample at a time and the model is updated along the way with\n a decreasing strength schedule (aka learning rate).\n\n The regularizer is a penalty added to the loss function that shrinks model\n parameters towards the zero vector using either the squared euclidean norm\n L2 or the absolute norm L1 or a combination of both (Elastic Net). If the\n parameter update crosses the 0.0 value because of the regularizer, the\n update is truncated to 0.0 to allow for learning sparse models and achieve\n online feature selection.\n\n This implementation works with data represented as dense numpy arrays of\n floating point values for the features.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n loss : str, default='squared_error'\n The loss function to be used. The possible values are 'squared_error',\n 'huber', 'epsilon_insensitive', or 'squared_epsilon_insensitive'\n\n The 'squared_error' refers to the ordinary least squares fit.\n 'huber' modifies 'squared_error' to focus less on getting outliers\n correct by switching from squared to linear loss past a distance of\n epsilon. 'epsilon_insensitive' ignores errors less than epsilon and is\n linear past that; this is the loss function used in SVR.\n 'squared_epsilon_insensitive' is the same but becomes squared loss past\n a tolerance of epsilon.\n\n More details about the losses formulas can be found in the\n :ref:`User Guide `.\n\n .. deprecated:: 1.0\n The loss 'squared_loss' was deprecated in v1.0 and will be removed\n in version 1.2. Use `loss='squared_error'` which is equivalent.\n\n penalty : {'l2', 'l1', 'elasticnet'}, default='l2'\n The penalty (aka regularization term) to be used. Defaults to 'l2'\n which is the standard regularizer for linear SVM models. 'l1' and\n 'elasticnet' might bring sparsity to the model (feature selection)\n not achievable with 'l2'.\n\n alpha : float, default=0.0001\n Constant that multiplies the regularization term. The higher the\n value, the stronger the regularization.\n Also used to compute the learning rate when set to `learning_rate` is\n set to 'optimal'.\n\n l1_ratio : float, default=0.15\n The Elastic Net mixing parameter, with 0 <= l1_ratio <= 1.\n l1_ratio=0 corresponds to L2 penalty, l1_ratio=1 to L1.\n Only used if `penalty` is 'elasticnet'.\n\n fit_intercept : bool, default=True\n Whether the intercept should be estimated or not. If False, the\n data is assumed to be already centered.\n\n max_iter : int, default=1000\n The maximum number of passes over the training data (aka epochs).\n It only impacts the behavior in the ``fit`` method, and not the\n :meth:`partial_fit` method.\n\n .. versionadded:: 0.19\n\n tol : float, default=1e-3\n The stopping criterion. If it is not None, training will stop\n when (loss > best_loss - tol) for ``n_iter_no_change`` consecutive\n epochs.\n Convergence is checked against the training loss or the\n validation loss depending on the `early_stopping` parameter.\n\n .. versionadded:: 0.19\n\n shuffle : bool, default=True\n Whether or not the training data should be shuffled after each epoch.\n\n verbose : int, default=0\n The verbosity level.\n\n epsilon : float, default=0.1\n Epsilon in the epsilon-insensitive loss functions; only if `loss` is\n 'huber', 'epsilon_insensitive', or 'squared_epsilon_insensitive'.\n For 'huber', determines the threshold at which it becomes less\n important to get the prediction exactly right.\n For epsilon-insensitive, any differences between the current prediction\n and the correct label are ignored if they are less than this threshold.\n\n random_state : int, RandomState instance, default=None\n Used for shuffling the data, when ``shuffle`` is set to ``True``.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n learning_rate : str, default='invscaling'\n The learning rate schedule:\n\n - 'constant': `eta = eta0`\n - 'optimal': `eta = 1.0 / (alpha * (t + t0))`\n where t0 is chosen by a heuristic proposed by Leon Bottou.\n - 'invscaling': `eta = eta0 / pow(t, power_t)`\n - 'adaptive': eta = eta0, as long as the training keeps decreasing.\n Each time n_iter_no_change consecutive epochs fail to decrease the\n training loss by tol or fail to increase validation score by tol if\n early_stopping is True, the current learning rate is divided by 5.\n\n .. versionadded:: 0.20\n Added 'adaptive' option\n\n eta0 : double, default=0.01\n The initial learning rate for the 'constant', 'invscaling' or\n 'adaptive' schedules. The default value is 0.01.\n\n power_t : double, default=0.25\n The exponent for inverse scaling learning rate.\n\n early_stopping : bool, default=False\n Whether to use early stopping to terminate training when validation\n score is not improving. If set to True, it will automatically set aside\n a fraction of training data as validation and terminate\n training when validation score returned by the `score` method is not\n improving by at least `tol` for `n_iter_no_change` consecutive\n epochs.\n\n .. versionadded:: 0.20\n Added 'early_stopping' option\n\n validation_fraction : float, default=0.1\n The proportion of training data to set aside as validation set for\n early stopping. Must be between 0 and 1.\n Only used if `early_stopping` is True.\n\n .. versionadded:: 0.20\n Added 'validation_fraction' option\n\n n_iter_no_change : int, default=5\n Number of iterations with no improvement to wait before stopping\n fitting.\n Convergence is checked against the training loss or the\n validation loss depending on the `early_stopping` parameter.\n\n .. versionadded:: 0.20\n Added 'n_iter_no_change' option\n\n warm_start : bool, default=False\n When set to True, reuse the solution of the previous call to fit as\n initialization, otherwise, just erase the previous solution.\n See :term:`the Glossary `.\n\n Repeatedly calling fit or partial_fit when warm_start is True can\n result in a different solution than when calling fit a single time\n because of the way the data is shuffled.\n If a dynamic learning rate is used, the learning rate is adapted\n depending on the number of samples already seen. Calling ``fit`` resets\n this counter, while ``partial_fit`` will result in increasing the\n existing counter.\n\n average : bool or int, default=False\n When set to True, computes the averaged SGD weights across all\n updates and stores the result in the ``coef_`` attribute. If set to\n an int greater than 1, averaging will begin once the total number of\n samples seen reaches `average`. So ``average=10`` will begin\n averaging after seeing 10 samples.\n\n Attributes\n ----------\n coef_ : ndarray of shape (n_features,)\n Weights assigned to the features.\n\n intercept_ : ndarray of shape (1,)\n The intercept term.\n\n n_iter_ : int\n The actual number of iterations before reaching the stopping criterion.\n\n t_ : int\n Number of weight updates performed during training.\n Same as ``(n_iter_ * n_samples)``.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n HuberRegressor : Linear regression model that is robust to outliers.\n Lars : Least Angle Regression model.\n Lasso : Linear Model trained with L1 prior as regularizer.\n RANSACRegressor : RANSAC (RANdom SAmple Consensus) algorithm.\n Ridge : Linear least squares with l2 regularization.\n sklearn.svm.SVR : Epsilon-Support Vector Regression.\n TheilSenRegressor : Theil-Sen Estimator robust multivariate regression model.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.linear_model import SGDRegressor\n >>> from sklearn.pipeline import make_pipeline\n >>> from sklearn.preprocessing import StandardScaler\n >>> n_samples, n_features = 10, 5\n >>> rng = np.random.RandomState(0)\n >>> y = rng.randn(n_samples)\n >>> X = rng.randn(n_samples, n_features)\n >>> # Always scale the input. The most convenient way is to use a pipeline.\n >>> reg = make_pipeline(StandardScaler(),\n ... SGDRegressor(max_iter=1000, tol=1e-3))\n >>> reg.fit(X, y)\n Pipeline(steps=[('standardscaler', StandardScaler()),\n ('sgdregressor', SGDRegressor())])\n \"\"\"\n \n def __init__(self, loss='squared_error', *, penalty='l2', alpha=0.0001, l1_ratio=0.15, fit_intercept=True, max_iter=1000, tol=0.001, shuffle=True, verbose=0, epsilon=DEFAULT_EPSILON, random_state=None, learning_rate='invscaling', eta0=0.01, power_t=0.25, early_stopping=False, validation_fraction=0.1, n_iter_no_change=5, warm_start=False, average=False):\n super().__init__(loss=loss, penalty=penalty, alpha=alpha, l1_ratio=l1_ratio, fit_intercept=fit_intercept, max_iter=max_iter, tol=tol, shuffle=shuffle, verbose=verbose, epsilon=epsilon, random_state=random_state, learning_rate=learning_rate, eta0=eta0, power_t=power_t, early_stopping=early_stopping, validation_fraction=validation_fraction, n_iter_no_change=n_iter_no_change, warm_start=warm_start, average=average)\n \n def _more_tags(self):\n return {'_xfail_checks': {'check_sample_weights_invariance': 'zero sample_weight is not equivalent to removing samples'}}\n" }, { "name": "_ValidationScoreCallback", @@ -24270,8 +24223,8 @@ ], "is_public": true, "description": "Theil-Sen Estimator: robust multivariate regression model.\n\nThe algorithm calculates least square solutions on subsets with size n_subsamples of the samples in X. Any value of n_subsamples between the number of features and samples leads to an estimator with a compromise between robustness and efficiency. Since the number of least square solutions is \"n_samples choose n_subsamples\", it can be extremely large and can therefore be limited with max_subpopulation. If this limit is reached, the subsets are chosen randomly. In a final step, the spatial median (or L1 median) is calculated of all least square solutions. Read more in the :ref:`User Guide `.", - "docstring": "Theil-Sen Estimator: robust multivariate regression model.\n\n The algorithm calculates least square solutions on subsets with size\n n_subsamples of the samples in X. Any value of n_subsamples between the\n number of features and samples leads to an estimator with a compromise\n between robustness and efficiency. Since the number of least square\n solutions is \"n_samples choose n_subsamples\", it can be extremely large\n and can therefore be limited with max_subpopulation. If this limit is\n reached, the subsets are chosen randomly. In a final step, the spatial\n median (or L1 median) is calculated of all least square solutions.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations.\n\n copy_X : bool, default=True\n If True, X will be copied; else, it may be overwritten.\n\n max_subpopulation : int, default=1e4\n Instead of computing with a set of cardinality 'n choose k', where n is\n the number of samples and k is the number of subsamples (at least\n number of features), consider only a stochastic subpopulation of a\n given maximal size if 'n choose k' is larger than max_subpopulation.\n For other than small problem sizes this parameter will determine\n memory usage and runtime if n_subsamples is not changed.\n\n n_subsamples : int, default=None\n Number of samples to calculate the parameters. This is at least the\n number of features (plus 1 if fit_intercept=True) and the number of\n samples as a maximum. A lower number leads to a higher breakdown\n point and a low efficiency while a high number leads to a low\n breakdown point and a high efficiency. If None, take the\n minimum number of subsamples leading to maximal robustness.\n If n_subsamples is set to n_samples, Theil-Sen is identical to least\n squares.\n\n max_iter : int, default=300\n Maximum number of iterations for the calculation of spatial median.\n\n tol : float, default=1.e-3\n Tolerance when calculating spatial median.\n\n random_state : int, RandomState instance or None, default=None\n A random number generator instance to define the state of the random\n permutations generator. Pass an int for reproducible output across\n multiple function calls.\n See :term:`Glossary `\n\n n_jobs : int, default=None\n Number of CPUs to use during the cross validation.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n verbose : bool, default=False\n Verbose mode when fitting the model.\n\n Attributes\n ----------\n coef_ : ndarray of shape (n_features,)\n Coefficients of the regression model (median of distribution).\n\n intercept_ : float\n Estimated intercept of regression model.\n\n breakdown_ : float\n Approximated breakdown point.\n\n n_iter_ : int\n Number of iterations needed for the spatial median.\n\n n_subpopulation_ : int\n Number of combinations taken into account from 'n choose k', where n is\n the number of samples and k is the number of subsamples.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn.linear_model import TheilSenRegressor\n >>> from sklearn.datasets import make_regression\n >>> X, y = make_regression(\n ... n_samples=200, n_features=2, noise=4.0, random_state=0)\n >>> reg = TheilSenRegressor(random_state=0).fit(X, y)\n >>> reg.score(X, y)\n 0.9884...\n >>> reg.predict(X[:1,])\n array([-31.5871...])\n\n References\n ----------\n - Theil-Sen Estimators in a Multiple Linear Regression Model, 2009\n Xin Dang, Hanxiang Peng, Xueqin Wang and Heping Zhang\n http://home.olemiss.edu/~xdang/papers/MTSE.pdf\n ", - "source_code": "\n\nclass TheilSenRegressor(RegressorMixin, LinearModel):\n \"\"\"Theil-Sen Estimator: robust multivariate regression model.\n\n The algorithm calculates least square solutions on subsets with size\n n_subsamples of the samples in X. Any value of n_subsamples between the\n number of features and samples leads to an estimator with a compromise\n between robustness and efficiency. Since the number of least square\n solutions is \"n_samples choose n_subsamples\", it can be extremely large\n and can therefore be limited with max_subpopulation. If this limit is\n reached, the subsets are chosen randomly. In a final step, the spatial\n median (or L1 median) is calculated of all least square solutions.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations.\n\n copy_X : bool, default=True\n If True, X will be copied; else, it may be overwritten.\n\n max_subpopulation : int, default=1e4\n Instead of computing with a set of cardinality 'n choose k', where n is\n the number of samples and k is the number of subsamples (at least\n number of features), consider only a stochastic subpopulation of a\n given maximal size if 'n choose k' is larger than max_subpopulation.\n For other than small problem sizes this parameter will determine\n memory usage and runtime if n_subsamples is not changed.\n\n n_subsamples : int, default=None\n Number of samples to calculate the parameters. This is at least the\n number of features (plus 1 if fit_intercept=True) and the number of\n samples as a maximum. A lower number leads to a higher breakdown\n point and a low efficiency while a high number leads to a low\n breakdown point and a high efficiency. If None, take the\n minimum number of subsamples leading to maximal robustness.\n If n_subsamples is set to n_samples, Theil-Sen is identical to least\n squares.\n\n max_iter : int, default=300\n Maximum number of iterations for the calculation of spatial median.\n\n tol : float, default=1.e-3\n Tolerance when calculating spatial median.\n\n random_state : int, RandomState instance or None, default=None\n A random number generator instance to define the state of the random\n permutations generator. Pass an int for reproducible output across\n multiple function calls.\n See :term:`Glossary `\n\n n_jobs : int, default=None\n Number of CPUs to use during the cross validation.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n verbose : bool, default=False\n Verbose mode when fitting the model.\n\n Attributes\n ----------\n coef_ : ndarray of shape (n_features,)\n Coefficients of the regression model (median of distribution).\n\n intercept_ : float\n Estimated intercept of regression model.\n\n breakdown_ : float\n Approximated breakdown point.\n\n n_iter_ : int\n Number of iterations needed for the spatial median.\n\n n_subpopulation_ : int\n Number of combinations taken into account from 'n choose k', where n is\n the number of samples and k is the number of subsamples.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn.linear_model import TheilSenRegressor\n >>> from sklearn.datasets import make_regression\n >>> X, y = make_regression(\n ... n_samples=200, n_features=2, noise=4.0, random_state=0)\n >>> reg = TheilSenRegressor(random_state=0).fit(X, y)\n >>> reg.score(X, y)\n 0.9884...\n >>> reg.predict(X[:1,])\n array([-31.5871...])\n\n References\n ----------\n - Theil-Sen Estimators in a Multiple Linear Regression Model, 2009\n Xin Dang, Hanxiang Peng, Xueqin Wang and Heping Zhang\n http://home.olemiss.edu/~xdang/papers/MTSE.pdf\n \"\"\"\n \n def __init__(self, *, fit_intercept=True, copy_X=True, max_subpopulation=10000.0, n_subsamples=None, max_iter=300, tol=0.001, random_state=None, n_jobs=None, verbose=False):\n self.fit_intercept = fit_intercept\n self.copy_X = copy_X\n self.max_subpopulation = int(max_subpopulation)\n self.n_subsamples = n_subsamples\n self.max_iter = max_iter\n self.tol = tol\n self.random_state = random_state\n self.n_jobs = n_jobs\n self.verbose = verbose\n \n def _check_subparams(self, n_samples, n_features):\n n_subsamples = self.n_subsamples\n if self.fit_intercept:\n n_dim = n_features + 1\n else:\n n_dim = n_features\n if n_subsamples is not None:\n if n_subsamples > n_samples:\n raise ValueError('Invalid parameter since n_subsamples > n_samples ({0} > {1}).'.format(n_subsamples, n_samples))\n if n_samples >= n_features:\n if n_dim > n_subsamples:\n plus_1 = '+1' if self.fit_intercept else ''\n raise ValueError('Invalid parameter since n_features{0} > n_subsamples ({1} > {2}).'.format(plus_1, n_dim, n_samples))\n elif n_subsamples != n_samples:\n raise ValueError('Invalid parameter since n_subsamples != n_samples ({0} != {1}) while n_samples < n_features.'.format(n_subsamples, n_samples))\n else:\n n_subsamples = min(n_dim, n_samples)\n if self.max_subpopulation <= 0:\n raise ValueError('Subpopulation must be strictly positive ({0} <= 0).'.format(self.max_subpopulation))\n all_combinations = max(1, np.rint(binom(n_samples, n_subsamples)))\n n_subpopulation = int(min(self.max_subpopulation, all_combinations))\n return n_subsamples, n_subpopulation\n \n def fit(self, X, y):\n \"\"\"Fit linear model.\n\n Parameters\n ----------\n X : ndarray of shape (n_samples, n_features)\n Training data.\n y : ndarray of shape (n_samples,)\n Target values.\n\n Returns\n -------\n self : returns an instance of self.\n \"\"\"\n random_state = check_random_state(self.random_state)\n (X, y) = self._validate_data(X, y, y_numeric=True)\n (n_samples, n_features) = X.shape\n (n_subsamples, self.n_subpopulation_) = self._check_subparams(n_samples, n_features)\n self.breakdown_ = _breakdown_point(n_samples, n_subsamples)\n if self.verbose:\n print('Breakdown point: {0}'.format(self.breakdown_))\n print('Number of samples: {0}'.format(n_samples))\n tol_outliers = int(self.breakdown_ * n_samples)\n print('Tolerable outliers: {0}'.format(tol_outliers))\n print('Number of subpopulations: {0}'.format(self.n_subpopulation_))\n if np.rint(binom(n_samples, n_subsamples)) <= self.max_subpopulation:\n indices = list(combinations(range(n_samples), n_subsamples))\n else:\n indices = [random_state.choice(n_samples, size=n_subsamples, replace=False) for _ in range(self.n_subpopulation_)]\n n_jobs = effective_n_jobs(self.n_jobs)\n index_list = np.array_split(indices, n_jobs)\n weights = Parallel(n_jobs=n_jobs, verbose=self.verbose)((delayed(_lstsq)(X, y, index_list[job], self.fit_intercept) for job in range(n_jobs)))\n weights = np.vstack(weights)\n (self.n_iter_, coefs) = _spatial_median(weights, max_iter=self.max_iter, tol=self.tol)\n if self.fit_intercept:\n self.intercept_ = coefs[0]\n self.coef_ = coefs[1:]\n else:\n self.intercept_ = 0.0\n self.coef_ = coefs\n return self\n" + "docstring": "Theil-Sen Estimator: robust multivariate regression model.\n\n The algorithm calculates least square solutions on subsets with size\n n_subsamples of the samples in X. Any value of n_subsamples between the\n number of features and samples leads to an estimator with a compromise\n between robustness and efficiency. Since the number of least square\n solutions is \"n_samples choose n_subsamples\", it can be extremely large\n and can therefore be limited with max_subpopulation. If this limit is\n reached, the subsets are chosen randomly. In a final step, the spatial\n median (or L1 median) is calculated of all least square solutions.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations.\n\n copy_X : bool, default=True\n If True, X will be copied; else, it may be overwritten.\n\n max_subpopulation : int, default=1e4\n Instead of computing with a set of cardinality 'n choose k', where n is\n the number of samples and k is the number of subsamples (at least\n number of features), consider only a stochastic subpopulation of a\n given maximal size if 'n choose k' is larger than max_subpopulation.\n For other than small problem sizes this parameter will determine\n memory usage and runtime if n_subsamples is not changed.\n\n n_subsamples : int, default=None\n Number of samples to calculate the parameters. This is at least the\n number of features (plus 1 if fit_intercept=True) and the number of\n samples as a maximum. A lower number leads to a higher breakdown\n point and a low efficiency while a high number leads to a low\n breakdown point and a high efficiency. If None, take the\n minimum number of subsamples leading to maximal robustness.\n If n_subsamples is set to n_samples, Theil-Sen is identical to least\n squares.\n\n max_iter : int, default=300\n Maximum number of iterations for the calculation of spatial median.\n\n tol : float, default=1.e-3\n Tolerance when calculating spatial median.\n\n random_state : int, RandomState instance or None, default=None\n A random number generator instance to define the state of the random\n permutations generator. Pass an int for reproducible output across\n multiple function calls.\n See :term:`Glossary `.\n\n n_jobs : int, default=None\n Number of CPUs to use during the cross validation.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n verbose : bool, default=False\n Verbose mode when fitting the model.\n\n Attributes\n ----------\n coef_ : ndarray of shape (n_features,)\n Coefficients of the regression model (median of distribution).\n\n intercept_ : float\n Estimated intercept of regression model.\n\n breakdown_ : float\n Approximated breakdown point.\n\n n_iter_ : int\n Number of iterations needed for the spatial median.\n\n n_subpopulation_ : int\n Number of combinations taken into account from 'n choose k', where n is\n the number of samples and k is the number of subsamples.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n HuberRegressor : Linear regression model that is robust to outliers.\n RANSACRegressor : RANSAC (RANdom SAmple Consensus) algorithm.\n SGDRegressor : Fitted by minimizing a regularized empirical loss with SGD.\n\n References\n ----------\n - Theil-Sen Estimators in a Multiple Linear Regression Model, 2009\n Xin Dang, Hanxiang Peng, Xueqin Wang and Heping Zhang\n http://home.olemiss.edu/~xdang/papers/MTSE.pdf\n\n Examples\n --------\n >>> from sklearn.linear_model import TheilSenRegressor\n >>> from sklearn.datasets import make_regression\n >>> X, y = make_regression(\n ... n_samples=200, n_features=2, noise=4.0, random_state=0)\n >>> reg = TheilSenRegressor(random_state=0).fit(X, y)\n >>> reg.score(X, y)\n 0.9884...\n >>> reg.predict(X[:1,])\n array([-31.5871...])\n ", + "source_code": "\n\nclass TheilSenRegressor(RegressorMixin, LinearModel):\n \"\"\"Theil-Sen Estimator: robust multivariate regression model.\n\n The algorithm calculates least square solutions on subsets with size\n n_subsamples of the samples in X. Any value of n_subsamples between the\n number of features and samples leads to an estimator with a compromise\n between robustness and efficiency. Since the number of least square\n solutions is \"n_samples choose n_subsamples\", it can be extremely large\n and can therefore be limited with max_subpopulation. If this limit is\n reached, the subsets are chosen randomly. In a final step, the spatial\n median (or L1 median) is calculated of all least square solutions.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n fit_intercept : bool, default=True\n Whether to calculate the intercept for this model. If set\n to false, no intercept will be used in calculations.\n\n copy_X : bool, default=True\n If True, X will be copied; else, it may be overwritten.\n\n max_subpopulation : int, default=1e4\n Instead of computing with a set of cardinality 'n choose k', where n is\n the number of samples and k is the number of subsamples (at least\n number of features), consider only a stochastic subpopulation of a\n given maximal size if 'n choose k' is larger than max_subpopulation.\n For other than small problem sizes this parameter will determine\n memory usage and runtime if n_subsamples is not changed.\n\n n_subsamples : int, default=None\n Number of samples to calculate the parameters. This is at least the\n number of features (plus 1 if fit_intercept=True) and the number of\n samples as a maximum. A lower number leads to a higher breakdown\n point and a low efficiency while a high number leads to a low\n breakdown point and a high efficiency. If None, take the\n minimum number of subsamples leading to maximal robustness.\n If n_subsamples is set to n_samples, Theil-Sen is identical to least\n squares.\n\n max_iter : int, default=300\n Maximum number of iterations for the calculation of spatial median.\n\n tol : float, default=1.e-3\n Tolerance when calculating spatial median.\n\n random_state : int, RandomState instance or None, default=None\n A random number generator instance to define the state of the random\n permutations generator. Pass an int for reproducible output across\n multiple function calls.\n See :term:`Glossary `.\n\n n_jobs : int, default=None\n Number of CPUs to use during the cross validation.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n verbose : bool, default=False\n Verbose mode when fitting the model.\n\n Attributes\n ----------\n coef_ : ndarray of shape (n_features,)\n Coefficients of the regression model (median of distribution).\n\n intercept_ : float\n Estimated intercept of regression model.\n\n breakdown_ : float\n Approximated breakdown point.\n\n n_iter_ : int\n Number of iterations needed for the spatial median.\n\n n_subpopulation_ : int\n Number of combinations taken into account from 'n choose k', where n is\n the number of samples and k is the number of subsamples.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n HuberRegressor : Linear regression model that is robust to outliers.\n RANSACRegressor : RANSAC (RANdom SAmple Consensus) algorithm.\n SGDRegressor : Fitted by minimizing a regularized empirical loss with SGD.\n\n References\n ----------\n - Theil-Sen Estimators in a Multiple Linear Regression Model, 2009\n Xin Dang, Hanxiang Peng, Xueqin Wang and Heping Zhang\n http://home.olemiss.edu/~xdang/papers/MTSE.pdf\n\n Examples\n --------\n >>> from sklearn.linear_model import TheilSenRegressor\n >>> from sklearn.datasets import make_regression\n >>> X, y = make_regression(\n ... n_samples=200, n_features=2, noise=4.0, random_state=0)\n >>> reg = TheilSenRegressor(random_state=0).fit(X, y)\n >>> reg.score(X, y)\n 0.9884...\n >>> reg.predict(X[:1,])\n array([-31.5871...])\n \"\"\"\n \n def __init__(self, *, fit_intercept=True, copy_X=True, max_subpopulation=10000.0, n_subsamples=None, max_iter=300, tol=0.001, random_state=None, n_jobs=None, verbose=False):\n self.fit_intercept = fit_intercept\n self.copy_X = copy_X\n self.max_subpopulation = int(max_subpopulation)\n self.n_subsamples = n_subsamples\n self.max_iter = max_iter\n self.tol = tol\n self.random_state = random_state\n self.n_jobs = n_jobs\n self.verbose = verbose\n \n def _check_subparams(self, n_samples, n_features):\n n_subsamples = self.n_subsamples\n if self.fit_intercept:\n n_dim = n_features + 1\n else:\n n_dim = n_features\n if n_subsamples is not None:\n if n_subsamples > n_samples:\n raise ValueError('Invalid parameter since n_subsamples > n_samples ({0} > {1}).'.format(n_subsamples, n_samples))\n if n_samples >= n_features:\n if n_dim > n_subsamples:\n plus_1 = '+1' if self.fit_intercept else ''\n raise ValueError('Invalid parameter since n_features{0} > n_subsamples ({1} > {2}).'.format(plus_1, n_dim, n_samples))\n elif n_subsamples != n_samples:\n raise ValueError('Invalid parameter since n_subsamples != n_samples ({0} != {1}) while n_samples < n_features.'.format(n_subsamples, n_samples))\n else:\n n_subsamples = min(n_dim, n_samples)\n if self.max_subpopulation <= 0:\n raise ValueError('Subpopulation must be strictly positive ({0} <= 0).'.format(self.max_subpopulation))\n all_combinations = max(1, np.rint(binom(n_samples, n_subsamples)))\n n_subpopulation = int(min(self.max_subpopulation, all_combinations))\n return n_subsamples, n_subpopulation\n \n def fit(self, X, y):\n \"\"\"Fit linear model.\n\n Parameters\n ----------\n X : ndarray of shape (n_samples, n_features)\n Training data.\n y : ndarray of shape (n_samples,)\n Target values.\n\n Returns\n -------\n self : returns an instance of self.\n Fitted `TheilSenRegressor` estimator.\n \"\"\"\n random_state = check_random_state(self.random_state)\n (X, y) = self._validate_data(X, y, y_numeric=True)\n (n_samples, n_features) = X.shape\n (n_subsamples, self.n_subpopulation_) = self._check_subparams(n_samples, n_features)\n self.breakdown_ = _breakdown_point(n_samples, n_subsamples)\n if self.verbose:\n print('Breakdown point: {0}'.format(self.breakdown_))\n print('Number of samples: {0}'.format(n_samples))\n tol_outliers = int(self.breakdown_ * n_samples)\n print('Tolerable outliers: {0}'.format(tol_outliers))\n print('Number of subpopulations: {0}'.format(self.n_subpopulation_))\n if np.rint(binom(n_samples, n_subsamples)) <= self.max_subpopulation:\n indices = list(combinations(range(n_samples), n_subsamples))\n else:\n indices = [random_state.choice(n_samples, size=n_subsamples, replace=False) for _ in range(self.n_subpopulation_)]\n n_jobs = effective_n_jobs(self.n_jobs)\n index_list = np.array_split(indices, n_jobs)\n weights = Parallel(n_jobs=n_jobs, verbose=self.verbose)((delayed(_lstsq)(X, y, index_list[job], self.fit_intercept) for job in range(n_jobs)))\n weights = np.vstack(weights)\n (self.n_iter_, coefs) = _spatial_median(weights, max_iter=self.max_iter, tol=self.tol)\n if self.fit_intercept:\n self.intercept_ = coefs[0]\n self.coef_ = coefs[1:]\n else:\n self.intercept_ = 0.0\n self.coef_ = coefs\n return self\n" }, { "name": "Isomap", @@ -24308,9 +24261,9 @@ "sklearn.manifold._locally_linear.LocallyLinearEmbedding.transform" ], "is_public": true, - "description": "Locally Linear Embedding\n\nRead more in the :ref:`User Guide `.", - "docstring": "Locally Linear Embedding\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_neighbors : int, default=5\n number of neighbors to consider for each point.\n\n n_components : int, default=2\n number of coordinates for the manifold\n\n reg : float, default=1e-3\n regularization constant, multiplies the trace of the local covariance\n matrix of the distances.\n\n eigen_solver : {'auto', 'arpack', 'dense'}, default='auto'\n auto : algorithm will attempt to choose the best method for input data\n\n arpack : use arnoldi iteration in shift-invert mode.\n For this method, M may be a dense matrix, sparse matrix,\n or general linear operator.\n Warning: ARPACK can be unstable for some problems. It is\n best to try several random seeds in order to check results.\n\n dense : use standard dense matrix operations for the eigenvalue\n decomposition. For this method, M must be an array\n or matrix type. This method should be avoided for\n large problems.\n\n tol : float, default=1e-6\n Tolerance for 'arpack' method\n Not used if eigen_solver=='dense'.\n\n max_iter : int, default=100\n maximum number of iterations for the arpack solver.\n Not used if eigen_solver=='dense'.\n\n method : {'standard', 'hessian', 'modified', 'ltsa'}, default='standard'\n - `standard`: use the standard locally linear embedding algorithm. see\n reference [1]_\n - `hessian`: use the Hessian eigenmap method. This method requires\n ``n_neighbors > n_components * (1 + (n_components + 1) / 2``. see\n reference [2]_\n - `modified`: use the modified locally linear embedding algorithm.\n see reference [3]_\n - `ltsa`: use local tangent space alignment algorithm. see\n reference [4]_\n\n hessian_tol : float, default=1e-4\n Tolerance for Hessian eigenmapping method.\n Only used if ``method == 'hessian'``\n\n modified_tol : float, default=1e-12\n Tolerance for modified LLE method.\n Only used if ``method == 'modified'``\n\n neighbors_algorithm : {'auto', 'brute', 'kd_tree', 'ball_tree'}, default='auto'\n algorithm to use for nearest neighbors search,\n passed to neighbors.NearestNeighbors instance\n\n random_state : int, RandomState instance, default=None\n Determines the random number generator when\n ``eigen_solver`` == 'arpack'. Pass an int for reproducible results\n across multiple function calls. See :term: `Glossary `.\n\n n_jobs : int or None, default=None\n The number of parallel jobs to run.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n Attributes\n ----------\n embedding_ : array-like, shape [n_samples, n_components]\n Stores the embedding vectors\n\n reconstruction_error_ : float\n Reconstruction error associated with `embedding_`\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n nbrs_ : NearestNeighbors object\n Stores nearest neighbors instance, including BallTree or KDtree\n if applicable.\n\n Examples\n --------\n >>> from sklearn.datasets import load_digits\n >>> from sklearn.manifold import LocallyLinearEmbedding\n >>> X, _ = load_digits(return_X_y=True)\n >>> X.shape\n (1797, 64)\n >>> embedding = LocallyLinearEmbedding(n_components=2)\n >>> X_transformed = embedding.fit_transform(X[:100])\n >>> X_transformed.shape\n (100, 2)\n\n References\n ----------\n\n .. [1] Roweis, S. & Saul, L. Nonlinear dimensionality reduction\n by locally linear embedding. Science 290:2323 (2000).\n .. [2] Donoho, D. & Grimes, C. Hessian eigenmaps: Locally\n linear embedding techniques for high-dimensional data.\n Proc Natl Acad Sci U S A. 100:5591 (2003).\n .. [3] Zhang, Z. & Wang, J. MLLE: Modified Locally Linear\n Embedding Using Multiple Weights.\n http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.70.382\n .. [4] Zhang, Z. & Zha, H. Principal manifolds and nonlinear\n dimensionality reduction via tangent space alignment.\n Journal of Shanghai Univ. 8:406 (2004)\n ", - "source_code": "\n\nclass LocallyLinearEmbedding(TransformerMixin, _UnstableArchMixin, BaseEstimator):\n \"\"\"Locally Linear Embedding\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_neighbors : int, default=5\n number of neighbors to consider for each point.\n\n n_components : int, default=2\n number of coordinates for the manifold\n\n reg : float, default=1e-3\n regularization constant, multiplies the trace of the local covariance\n matrix of the distances.\n\n eigen_solver : {'auto', 'arpack', 'dense'}, default='auto'\n auto : algorithm will attempt to choose the best method for input data\n\n arpack : use arnoldi iteration in shift-invert mode.\n For this method, M may be a dense matrix, sparse matrix,\n or general linear operator.\n Warning: ARPACK can be unstable for some problems. It is\n best to try several random seeds in order to check results.\n\n dense : use standard dense matrix operations for the eigenvalue\n decomposition. For this method, M must be an array\n or matrix type. This method should be avoided for\n large problems.\n\n tol : float, default=1e-6\n Tolerance for 'arpack' method\n Not used if eigen_solver=='dense'.\n\n max_iter : int, default=100\n maximum number of iterations for the arpack solver.\n Not used if eigen_solver=='dense'.\n\n method : {'standard', 'hessian', 'modified', 'ltsa'}, default='standard'\n - `standard`: use the standard locally linear embedding algorithm. see\n reference [1]_\n - `hessian`: use the Hessian eigenmap method. This method requires\n ``n_neighbors > n_components * (1 + (n_components + 1) / 2``. see\n reference [2]_\n - `modified`: use the modified locally linear embedding algorithm.\n see reference [3]_\n - `ltsa`: use local tangent space alignment algorithm. see\n reference [4]_\n\n hessian_tol : float, default=1e-4\n Tolerance for Hessian eigenmapping method.\n Only used if ``method == 'hessian'``\n\n modified_tol : float, default=1e-12\n Tolerance for modified LLE method.\n Only used if ``method == 'modified'``\n\n neighbors_algorithm : {'auto', 'brute', 'kd_tree', 'ball_tree'}, default='auto'\n algorithm to use for nearest neighbors search,\n passed to neighbors.NearestNeighbors instance\n\n random_state : int, RandomState instance, default=None\n Determines the random number generator when\n ``eigen_solver`` == 'arpack'. Pass an int for reproducible results\n across multiple function calls. See :term: `Glossary `.\n\n n_jobs : int or None, default=None\n The number of parallel jobs to run.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n Attributes\n ----------\n embedding_ : array-like, shape [n_samples, n_components]\n Stores the embedding vectors\n\n reconstruction_error_ : float\n Reconstruction error associated with `embedding_`\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n nbrs_ : NearestNeighbors object\n Stores nearest neighbors instance, including BallTree or KDtree\n if applicable.\n\n Examples\n --------\n >>> from sklearn.datasets import load_digits\n >>> from sklearn.manifold import LocallyLinearEmbedding\n >>> X, _ = load_digits(return_X_y=True)\n >>> X.shape\n (1797, 64)\n >>> embedding = LocallyLinearEmbedding(n_components=2)\n >>> X_transformed = embedding.fit_transform(X[:100])\n >>> X_transformed.shape\n (100, 2)\n\n References\n ----------\n\n .. [1] Roweis, S. & Saul, L. Nonlinear dimensionality reduction\n by locally linear embedding. Science 290:2323 (2000).\n .. [2] Donoho, D. & Grimes, C. Hessian eigenmaps: Locally\n linear embedding techniques for high-dimensional data.\n Proc Natl Acad Sci U S A. 100:5591 (2003).\n .. [3] Zhang, Z. & Wang, J. MLLE: Modified Locally Linear\n Embedding Using Multiple Weights.\n http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.70.382\n .. [4] Zhang, Z. & Zha, H. Principal manifolds and nonlinear\n dimensionality reduction via tangent space alignment.\n Journal of Shanghai Univ. 8:406 (2004)\n \"\"\"\n \n def __init__(self, *, n_neighbors=5, n_components=2, reg=0.001, eigen_solver='auto', tol=1e-06, max_iter=100, method='standard', hessian_tol=0.0001, modified_tol=1e-12, neighbors_algorithm='auto', random_state=None, n_jobs=None):\n self.n_neighbors = n_neighbors\n self.n_components = n_components\n self.reg = reg\n self.eigen_solver = eigen_solver\n self.tol = tol\n self.max_iter = max_iter\n self.method = method\n self.hessian_tol = hessian_tol\n self.modified_tol = modified_tol\n self.random_state = random_state\n self.neighbors_algorithm = neighbors_algorithm\n self.n_jobs = n_jobs\n \n def _fit_transform(self, X):\n self.nbrs_ = NearestNeighbors(n_neighbors=self.n_neighbors, algorithm=self.neighbors_algorithm, n_jobs=self.n_jobs)\n random_state = check_random_state(self.random_state)\n X = self._validate_data(X, dtype=float)\n self.nbrs_.fit(X)\n (self.embedding_, self.reconstruction_error_) = locally_linear_embedding(X=self.nbrs_, n_neighbors=self.n_neighbors, n_components=self.n_components, eigen_solver=self.eigen_solver, tol=self.tol, max_iter=self.max_iter, method=self.method, hessian_tol=self.hessian_tol, modified_tol=self.modified_tol, random_state=random_state, reg=self.reg, n_jobs=self.n_jobs)\n \n def fit(self, X, y=None):\n \"\"\"Compute the embedding vectors for data X\n\n Parameters\n ----------\n X : array-like of shape [n_samples, n_features]\n training set.\n\n y : Ignored\n\n Returns\n -------\n self : returns an instance of self.\n \"\"\"\n self._fit_transform(X)\n return self\n \n def fit_transform(self, X, y=None):\n \"\"\"Compute the embedding vectors for data X and transform X.\n\n Parameters\n ----------\n X : array-like of shape [n_samples, n_features]\n training set.\n\n y : Ignored\n\n Returns\n -------\n X_new : array-like, shape (n_samples, n_components)\n \"\"\"\n self._fit_transform(X)\n return self.embedding_\n \n def transform(self, X):\n \"\"\"\n Transform new points into embedding space.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n\n Returns\n -------\n X_new : array, shape = [n_samples, n_components]\n\n Notes\n -----\n Because of scaling performed by this method, it is discouraged to use\n it together with methods that are not scale-invariant (like SVMs)\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, reset=False)\n ind = self.nbrs_.kneighbors(X, n_neighbors=self.n_neighbors, return_distance=False)\n weights = barycenter_weights(X, self.nbrs_._fit_X, ind, reg=self.reg)\n X_new = np.empty((X.shape[0], self.n_components))\n for i in range(X.shape[0]):\n X_new[i] = np.dot(self.embedding_[ind[i]].T, weights[i])\n return X_new\n" + "description": "Locally Linear Embedding.\n\nRead more in the :ref:`User Guide `.", + "docstring": "Locally Linear Embedding.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_neighbors : int, default=5\n Number of neighbors to consider for each point.\n\n n_components : int, default=2\n Number of coordinates for the manifold.\n\n reg : float, default=1e-3\n Regularization constant, multiplies the trace of the local covariance\n matrix of the distances.\n\n eigen_solver : {'auto', 'arpack', 'dense'}, default='auto'\n The solver used to compute the eigenvectors. The available options are:\n\n - `'auto'` : algorithm will attempt to choose the best method for input\n data.\n - `'arpack'` : use arnoldi iteration in shift-invert mode. For this\n method, M may be a dense matrix, sparse matrix, or general linear\n operator.\n - `'dense'` : use standard dense matrix operations for the eigenvalue\n decomposition. For this method, M must be an array or matrix type.\n This method should be avoided for large problems.\n\n .. warning::\n ARPACK can be unstable for some problems. It is best to try several\n random seeds in order to check results.\n\n tol : float, default=1e-6\n Tolerance for 'arpack' method\n Not used if eigen_solver=='dense'.\n\n max_iter : int, default=100\n Maximum number of iterations for the arpack solver.\n Not used if eigen_solver=='dense'.\n\n method : {'standard', 'hessian', 'modified', 'ltsa'}, default='standard'\n - `standard`: use the standard locally linear embedding algorithm. see\n reference [1]_\n - `hessian`: use the Hessian eigenmap method. This method requires\n ``n_neighbors > n_components * (1 + (n_components + 1) / 2``. see\n reference [2]_\n - `modified`: use the modified locally linear embedding algorithm.\n see reference [3]_\n - `ltsa`: use local tangent space alignment algorithm. see\n reference [4]_\n\n hessian_tol : float, default=1e-4\n Tolerance for Hessian eigenmapping method.\n Only used if ``method == 'hessian'``.\n\n modified_tol : float, default=1e-12\n Tolerance for modified LLE method.\n Only used if ``method == 'modified'``.\n\n neighbors_algorithm : {'auto', 'brute', 'kd_tree', 'ball_tree'}, default='auto'\n Algorithm to use for nearest neighbors search, passed to\n :class:`~sklearn.neighbors.NearestNeighbors` instance.\n\n random_state : int, RandomState instance, default=None\n Determines the random number generator when\n ``eigen_solver`` == 'arpack'. Pass an int for reproducible results\n across multiple function calls. See :term:`Glossary `.\n\n n_jobs : int or None, default=None\n The number of parallel jobs to run.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n Attributes\n ----------\n embedding_ : array-like, shape [n_samples, n_components]\n Stores the embedding vectors\n\n reconstruction_error_ : float\n Reconstruction error associated with `embedding_`\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n nbrs_ : NearestNeighbors object\n Stores nearest neighbors instance, including BallTree or KDtree\n if applicable.\n\n See Also\n --------\n SpectralEmbedding : Spectral embedding for non-linear dimensionality\n reduction.\n TSNE : Distributed Stochastic Neighbor Embedding.\n\n References\n ----------\n\n .. [1] Roweis, S. & Saul, L. Nonlinear dimensionality reduction\n by locally linear embedding. Science 290:2323 (2000).\n .. [2] Donoho, D. & Grimes, C. Hessian eigenmaps: Locally\n linear embedding techniques for high-dimensional data.\n Proc Natl Acad Sci U S A. 100:5591 (2003).\n .. [3] Zhang, Z. & Wang, J. MLLE: Modified Locally Linear\n Embedding Using Multiple Weights.\n http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.70.382\n .. [4] Zhang, Z. & Zha, H. Principal manifolds and nonlinear\n dimensionality reduction via tangent space alignment.\n Journal of Shanghai Univ. 8:406 (2004)\n\n Examples\n --------\n >>> from sklearn.datasets import load_digits\n >>> from sklearn.manifold import LocallyLinearEmbedding\n >>> X, _ = load_digits(return_X_y=True)\n >>> X.shape\n (1797, 64)\n >>> embedding = LocallyLinearEmbedding(n_components=2)\n >>> X_transformed = embedding.fit_transform(X[:100])\n >>> X_transformed.shape\n (100, 2)\n ", + "source_code": "\n\nclass LocallyLinearEmbedding(TransformerMixin, _UnstableArchMixin, BaseEstimator):\n \"\"\"Locally Linear Embedding.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_neighbors : int, default=5\n Number of neighbors to consider for each point.\n\n n_components : int, default=2\n Number of coordinates for the manifold.\n\n reg : float, default=1e-3\n Regularization constant, multiplies the trace of the local covariance\n matrix of the distances.\n\n eigen_solver : {'auto', 'arpack', 'dense'}, default='auto'\n The solver used to compute the eigenvectors. The available options are:\n\n - `'auto'` : algorithm will attempt to choose the best method for input\n data.\n - `'arpack'` : use arnoldi iteration in shift-invert mode. For this\n method, M may be a dense matrix, sparse matrix, or general linear\n operator.\n - `'dense'` : use standard dense matrix operations for the eigenvalue\n decomposition. For this method, M must be an array or matrix type.\n This method should be avoided for large problems.\n\n .. warning::\n ARPACK can be unstable for some problems. It is best to try several\n random seeds in order to check results.\n\n tol : float, default=1e-6\n Tolerance for 'arpack' method\n Not used if eigen_solver=='dense'.\n\n max_iter : int, default=100\n Maximum number of iterations for the arpack solver.\n Not used if eigen_solver=='dense'.\n\n method : {'standard', 'hessian', 'modified', 'ltsa'}, default='standard'\n - `standard`: use the standard locally linear embedding algorithm. see\n reference [1]_\n - `hessian`: use the Hessian eigenmap method. This method requires\n ``n_neighbors > n_components * (1 + (n_components + 1) / 2``. see\n reference [2]_\n - `modified`: use the modified locally linear embedding algorithm.\n see reference [3]_\n - `ltsa`: use local tangent space alignment algorithm. see\n reference [4]_\n\n hessian_tol : float, default=1e-4\n Tolerance for Hessian eigenmapping method.\n Only used if ``method == 'hessian'``.\n\n modified_tol : float, default=1e-12\n Tolerance for modified LLE method.\n Only used if ``method == 'modified'``.\n\n neighbors_algorithm : {'auto', 'brute', 'kd_tree', 'ball_tree'}, default='auto'\n Algorithm to use for nearest neighbors search, passed to\n :class:`~sklearn.neighbors.NearestNeighbors` instance.\n\n random_state : int, RandomState instance, default=None\n Determines the random number generator when\n ``eigen_solver`` == 'arpack'. Pass an int for reproducible results\n across multiple function calls. See :term:`Glossary `.\n\n n_jobs : int or None, default=None\n The number of parallel jobs to run.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n Attributes\n ----------\n embedding_ : array-like, shape [n_samples, n_components]\n Stores the embedding vectors\n\n reconstruction_error_ : float\n Reconstruction error associated with `embedding_`\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n nbrs_ : NearestNeighbors object\n Stores nearest neighbors instance, including BallTree or KDtree\n if applicable.\n\n See Also\n --------\n SpectralEmbedding : Spectral embedding for non-linear dimensionality\n reduction.\n TSNE : Distributed Stochastic Neighbor Embedding.\n\n References\n ----------\n\n .. [1] Roweis, S. & Saul, L. Nonlinear dimensionality reduction\n by locally linear embedding. Science 290:2323 (2000).\n .. [2] Donoho, D. & Grimes, C. Hessian eigenmaps: Locally\n linear embedding techniques for high-dimensional data.\n Proc Natl Acad Sci U S A. 100:5591 (2003).\n .. [3] Zhang, Z. & Wang, J. MLLE: Modified Locally Linear\n Embedding Using Multiple Weights.\n http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.70.382\n .. [4] Zhang, Z. & Zha, H. Principal manifolds and nonlinear\n dimensionality reduction via tangent space alignment.\n Journal of Shanghai Univ. 8:406 (2004)\n\n Examples\n --------\n >>> from sklearn.datasets import load_digits\n >>> from sklearn.manifold import LocallyLinearEmbedding\n >>> X, _ = load_digits(return_X_y=True)\n >>> X.shape\n (1797, 64)\n >>> embedding = LocallyLinearEmbedding(n_components=2)\n >>> X_transformed = embedding.fit_transform(X[:100])\n >>> X_transformed.shape\n (100, 2)\n \"\"\"\n \n def __init__(self, *, n_neighbors=5, n_components=2, reg=0.001, eigen_solver='auto', tol=1e-06, max_iter=100, method='standard', hessian_tol=0.0001, modified_tol=1e-12, neighbors_algorithm='auto', random_state=None, n_jobs=None):\n self.n_neighbors = n_neighbors\n self.n_components = n_components\n self.reg = reg\n self.eigen_solver = eigen_solver\n self.tol = tol\n self.max_iter = max_iter\n self.method = method\n self.hessian_tol = hessian_tol\n self.modified_tol = modified_tol\n self.random_state = random_state\n self.neighbors_algorithm = neighbors_algorithm\n self.n_jobs = n_jobs\n \n def _fit_transform(self, X):\n self.nbrs_ = NearestNeighbors(n_neighbors=self.n_neighbors, algorithm=self.neighbors_algorithm, n_jobs=self.n_jobs)\n random_state = check_random_state(self.random_state)\n X = self._validate_data(X, dtype=float)\n self.nbrs_.fit(X)\n (self.embedding_, self.reconstruction_error_) = locally_linear_embedding(X=self.nbrs_, n_neighbors=self.n_neighbors, n_components=self.n_components, eigen_solver=self.eigen_solver, tol=self.tol, max_iter=self.max_iter, method=self.method, hessian_tol=self.hessian_tol, modified_tol=self.modified_tol, random_state=random_state, reg=self.reg, n_jobs=self.n_jobs)\n \n def fit(self, X, y=None):\n \"\"\"Compute the embedding vectors for data X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training set.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self : object\n Fitted `LocallyLinearEmbedding` class instance.\n \"\"\"\n self._fit_transform(X)\n return self\n \n def fit_transform(self, X, y=None):\n \"\"\"Compute the embedding vectors for data X and transform X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training set.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n X_new : array-like, shape (n_samples, n_components)\n Returns the instance itself.\n \"\"\"\n self._fit_transform(X)\n return self.embedding_\n \n def transform(self, X):\n \"\"\"\n Transform new points into embedding space.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training set.\n\n Returns\n -------\n X_new : ndarray of shape (n_samples, n_components)\n Returns the instance itself.\n\n Notes\n -----\n Because of scaling performed by this method, it is discouraged to use\n it together with methods that are not scale-invariant (like SVMs).\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, reset=False)\n ind = self.nbrs_.kneighbors(X, n_neighbors=self.n_neighbors, return_distance=False)\n weights = barycenter_weights(X, self.nbrs_._fit_X, ind, reg=self.reg)\n X_new = np.empty((X.shape[0], self.n_components))\n for i in range(X.shape[0]):\n X_new[i] = np.dot(self.embedding_[ind[i]].T, weights[i])\n return X_new\n" }, { "name": "MDS", @@ -24320,14 +24273,14 @@ "methods": [ "sklearn.manifold._mds.MDS.__init__", "sklearn.manifold._mds.MDS._more_tags", - "sklearn.manifold._mds.MDS._pairwise", + "sklearn.manifold._mds.MDS._pairwise@getter", "sklearn.manifold._mds.MDS.fit", "sklearn.manifold._mds.MDS.fit_transform" ], "is_public": true, "description": "Multidimensional scaling.\n\nRead more in the :ref:`User Guide `.", - "docstring": "Multidimensional scaling.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_components : int, default=2\n Number of dimensions in which to immerse the dissimilarities.\n\n metric : bool, default=True\n If ``True``, perform metric MDS; otherwise, perform nonmetric MDS.\n\n n_init : int, default=4\n Number of times the SMACOF algorithm will be run with different\n initializations. The final results will be the best output of the runs,\n determined by the run with the smallest final stress.\n\n max_iter : int, default=300\n Maximum number of iterations of the SMACOF algorithm for a single run.\n\n verbose : int, default=0\n Level of verbosity.\n\n eps : float, default=1e-3\n Relative tolerance with respect to stress at which to declare\n convergence.\n\n n_jobs : int, default=None\n The number of jobs to use for the computation. If multiple\n initializations are used (``n_init``), each run of the algorithm is\n computed in parallel.\n\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n random_state : int, RandomState instance or None, default=None\n Determines the random number generator used to initialize the centers.\n Pass an int for reproducible results across multiple function calls.\n See :term: `Glossary `.\n\n dissimilarity : {'euclidean', 'precomputed'}, default='euclidean'\n Dissimilarity measure to use:\n\n - 'euclidean':\n Pairwise Euclidean distances between points in the dataset.\n\n - 'precomputed':\n Pre-computed dissimilarities are passed directly to ``fit`` and\n ``fit_transform``.\n\n Attributes\n ----------\n embedding_ : ndarray of shape (n_samples, n_components)\n Stores the position of the dataset in the embedding space.\n\n stress_ : float\n The final value of the stress (sum of squared distance of the\n disparities and the distances for all constrained points).\n\n dissimilarity_matrix_ : ndarray of shape (n_samples, n_samples)\n Pairwise dissimilarities between the points. Symmetric matrix that:\n\n - either uses a custom dissimilarity matrix by setting `dissimilarity`\n to 'precomputed';\n - or constructs a dissimilarity matrix from data using\n Euclidean distances.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n The number of iterations corresponding to the best stress.\n\n See Also\n --------\n sklearn.decomposition.PCA : Principal component analysis that is a linear\n dimensionality reduction method.\n sklearn.decomposition.KernelPCA : Non-linear dimensionality reduction using\n kernels and PCA.\n TSNE : T-distributed Stochastic Neighbor Embedding.\n Isomap : Manifold learning based on Isometric Mapping.\n LocallyLinearEmbedding : Manifold learning using Locally Linear Embedding.\n SpectralEmbedding : Spectral embedding for non-linear dimensionality.\n\n References\n ----------\n \"Modern Multidimensional Scaling - Theory and Applications\" Borg, I.;\n Groenen P. Springer Series in Statistics (1997)\n\n \"Nonmetric multidimensional scaling: a numerical method\" Kruskal, J.\n Psychometrika, 29 (1964)\n\n \"Multidimensional scaling by optimizing goodness of fit to a nonmetric\n hypothesis\" Kruskal, J. Psychometrika, 29, (1964)\n\n Examples\n --------\n >>> from sklearn.datasets import load_digits\n >>> from sklearn.manifold import MDS\n >>> X, _ = load_digits(return_X_y=True)\n >>> X.shape\n (1797, 64)\n >>> embedding = MDS(n_components=2)\n >>> X_transformed = embedding.fit_transform(X[:100])\n >>> X_transformed.shape\n (100, 2)\n ", - "source_code": "\n\nclass MDS(BaseEstimator):\n \"\"\"Multidimensional scaling.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_components : int, default=2\n Number of dimensions in which to immerse the dissimilarities.\n\n metric : bool, default=True\n If ``True``, perform metric MDS; otherwise, perform nonmetric MDS.\n\n n_init : int, default=4\n Number of times the SMACOF algorithm will be run with different\n initializations. The final results will be the best output of the runs,\n determined by the run with the smallest final stress.\n\n max_iter : int, default=300\n Maximum number of iterations of the SMACOF algorithm for a single run.\n\n verbose : int, default=0\n Level of verbosity.\n\n eps : float, default=1e-3\n Relative tolerance with respect to stress at which to declare\n convergence.\n\n n_jobs : int, default=None\n The number of jobs to use for the computation. If multiple\n initializations are used (``n_init``), each run of the algorithm is\n computed in parallel.\n\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n random_state : int, RandomState instance or None, default=None\n Determines the random number generator used to initialize the centers.\n Pass an int for reproducible results across multiple function calls.\n See :term: `Glossary `.\n\n dissimilarity : {'euclidean', 'precomputed'}, default='euclidean'\n Dissimilarity measure to use:\n\n - 'euclidean':\n Pairwise Euclidean distances between points in the dataset.\n\n - 'precomputed':\n Pre-computed dissimilarities are passed directly to ``fit`` and\n ``fit_transform``.\n\n Attributes\n ----------\n embedding_ : ndarray of shape (n_samples, n_components)\n Stores the position of the dataset in the embedding space.\n\n stress_ : float\n The final value of the stress (sum of squared distance of the\n disparities and the distances for all constrained points).\n\n dissimilarity_matrix_ : ndarray of shape (n_samples, n_samples)\n Pairwise dissimilarities between the points. Symmetric matrix that:\n\n - either uses a custom dissimilarity matrix by setting `dissimilarity`\n to 'precomputed';\n - or constructs a dissimilarity matrix from data using\n Euclidean distances.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n The number of iterations corresponding to the best stress.\n\n See Also\n --------\n sklearn.decomposition.PCA : Principal component analysis that is a linear\n dimensionality reduction method.\n sklearn.decomposition.KernelPCA : Non-linear dimensionality reduction using\n kernels and PCA.\n TSNE : T-distributed Stochastic Neighbor Embedding.\n Isomap : Manifold learning based on Isometric Mapping.\n LocallyLinearEmbedding : Manifold learning using Locally Linear Embedding.\n SpectralEmbedding : Spectral embedding for non-linear dimensionality.\n\n References\n ----------\n \"Modern Multidimensional Scaling - Theory and Applications\" Borg, I.;\n Groenen P. Springer Series in Statistics (1997)\n\n \"Nonmetric multidimensional scaling: a numerical method\" Kruskal, J.\n Psychometrika, 29 (1964)\n\n \"Multidimensional scaling by optimizing goodness of fit to a nonmetric\n hypothesis\" Kruskal, J. Psychometrika, 29, (1964)\n\n Examples\n --------\n >>> from sklearn.datasets import load_digits\n >>> from sklearn.manifold import MDS\n >>> X, _ = load_digits(return_X_y=True)\n >>> X.shape\n (1797, 64)\n >>> embedding = MDS(n_components=2)\n >>> X_transformed = embedding.fit_transform(X[:100])\n >>> X_transformed.shape\n (100, 2)\n \"\"\"\n \n def __init__(self, n_components=2, *, metric=True, n_init=4, max_iter=300, verbose=0, eps=0.001, n_jobs=None, random_state=None, dissimilarity='euclidean'):\n self.n_components = n_components\n self.dissimilarity = dissimilarity\n self.metric = metric\n self.n_init = n_init\n self.max_iter = max_iter\n self.eps = eps\n self.verbose = verbose\n self.n_jobs = n_jobs\n self.random_state = random_state\n \n def _more_tags(self):\n return {'pairwise': self.dissimilarity == 'precomputed'}\n \n @deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def _pairwise(self):\n return self.dissimilarity == 'precomputed'\n \n def fit(self, X, y=None, init=None):\n \"\"\"\n Compute the position of the points in the embedding space.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features) or (n_samples, n_samples)\n Input data. If ``dissimilarity=='precomputed'``, the input should\n be the dissimilarity matrix.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n init : ndarray of shape (n_samples,), default=None\n Starting configuration of the embedding to initialize the SMACOF\n algorithm. By default, the algorithm is initialized with a randomly\n chosen array.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n self.fit_transform(X, init=init)\n return self\n \n def fit_transform(self, X, y=None, init=None):\n \"\"\"\n Fit the data from `X`, and returns the embedded coordinates.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features) or (n_samples, n_samples)\n Input data. If ``dissimilarity=='precomputed'``, the input should\n be the dissimilarity matrix.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n init : ndarray of shape (n_samples,), default=None\n Starting configuration of the embedding to initialize the SMACOF\n algorithm. By default, the algorithm is initialized with a randomly\n chosen array.\n\n Returns\n -------\n X_new : ndarray of shape (n_samples, n_components)\n X transformed in the new space.\n \"\"\"\n X = self._validate_data(X)\n if X.shape[0] == X.shape[1] and self.dissimilarity != 'precomputed':\n warnings.warn(\"The MDS API has changed. ``fit`` now constructs an dissimilarity matrix from data. To use a custom dissimilarity matrix, set ``dissimilarity='precomputed'``.\")\n if self.dissimilarity == 'precomputed':\n self.dissimilarity_matrix_ = X\n elif self.dissimilarity == 'euclidean':\n self.dissimilarity_matrix_ = euclidean_distances(X)\n else:\n raise ValueError(\"Proximity must be 'precomputed' or 'euclidean'. Got %s instead\" % str(self.dissimilarity))\n (self.embedding_, self.stress_, self.n_iter_) = smacof(self.dissimilarity_matrix_, metric=self.metric, n_components=self.n_components, init=init, n_init=self.n_init, n_jobs=self.n_jobs, max_iter=self.max_iter, verbose=self.verbose, eps=self.eps, random_state=self.random_state, return_n_iter=True)\n return self.embedding_\n" + "docstring": "Multidimensional scaling.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_components : int, default=2\n Number of dimensions in which to immerse the dissimilarities.\n\n metric : bool, default=True\n If ``True``, perform metric MDS; otherwise, perform nonmetric MDS.\n\n n_init : int, default=4\n Number of times the SMACOF algorithm will be run with different\n initializations. The final results will be the best output of the runs,\n determined by the run with the smallest final stress.\n\n max_iter : int, default=300\n Maximum number of iterations of the SMACOF algorithm for a single run.\n\n verbose : int, default=0\n Level of verbosity.\n\n eps : float, default=1e-3\n Relative tolerance with respect to stress at which to declare\n convergence.\n\n n_jobs : int, default=None\n The number of jobs to use for the computation. If multiple\n initializations are used (``n_init``), each run of the algorithm is\n computed in parallel.\n\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n random_state : int, RandomState instance or None, default=None\n Determines the random number generator used to initialize the centers.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n dissimilarity : {'euclidean', 'precomputed'}, default='euclidean'\n Dissimilarity measure to use:\n\n - 'euclidean':\n Pairwise Euclidean distances between points in the dataset.\n\n - 'precomputed':\n Pre-computed dissimilarities are passed directly to ``fit`` and\n ``fit_transform``.\n\n Attributes\n ----------\n embedding_ : ndarray of shape (n_samples, n_components)\n Stores the position of the dataset in the embedding space.\n\n stress_ : float\n The final value of the stress (sum of squared distance of the\n disparities and the distances for all constrained points).\n\n dissimilarity_matrix_ : ndarray of shape (n_samples, n_samples)\n Pairwise dissimilarities between the points. Symmetric matrix that:\n\n - either uses a custom dissimilarity matrix by setting `dissimilarity`\n to 'precomputed';\n - or constructs a dissimilarity matrix from data using\n Euclidean distances.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n The number of iterations corresponding to the best stress.\n\n See Also\n --------\n sklearn.decomposition.PCA : Principal component analysis that is a linear\n dimensionality reduction method.\n sklearn.decomposition.KernelPCA : Non-linear dimensionality reduction using\n kernels and PCA.\n TSNE : T-distributed Stochastic Neighbor Embedding.\n Isomap : Manifold learning based on Isometric Mapping.\n LocallyLinearEmbedding : Manifold learning using Locally Linear Embedding.\n SpectralEmbedding : Spectral embedding for non-linear dimensionality.\n\n References\n ----------\n \"Modern Multidimensional Scaling - Theory and Applications\" Borg, I.;\n Groenen P. Springer Series in Statistics (1997)\n\n \"Nonmetric multidimensional scaling: a numerical method\" Kruskal, J.\n Psychometrika, 29 (1964)\n\n \"Multidimensional scaling by optimizing goodness of fit to a nonmetric\n hypothesis\" Kruskal, J. Psychometrika, 29, (1964)\n\n Examples\n --------\n >>> from sklearn.datasets import load_digits\n >>> from sklearn.manifold import MDS\n >>> X, _ = load_digits(return_X_y=True)\n >>> X.shape\n (1797, 64)\n >>> embedding = MDS(n_components=2)\n >>> X_transformed = embedding.fit_transform(X[:100])\n >>> X_transformed.shape\n (100, 2)\n ", + "source_code": "\n\nclass MDS(BaseEstimator):\n \"\"\"Multidimensional scaling.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_components : int, default=2\n Number of dimensions in which to immerse the dissimilarities.\n\n metric : bool, default=True\n If ``True``, perform metric MDS; otherwise, perform nonmetric MDS.\n\n n_init : int, default=4\n Number of times the SMACOF algorithm will be run with different\n initializations. The final results will be the best output of the runs,\n determined by the run with the smallest final stress.\n\n max_iter : int, default=300\n Maximum number of iterations of the SMACOF algorithm for a single run.\n\n verbose : int, default=0\n Level of verbosity.\n\n eps : float, default=1e-3\n Relative tolerance with respect to stress at which to declare\n convergence.\n\n n_jobs : int, default=None\n The number of jobs to use for the computation. If multiple\n initializations are used (``n_init``), each run of the algorithm is\n computed in parallel.\n\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n random_state : int, RandomState instance or None, default=None\n Determines the random number generator used to initialize the centers.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n dissimilarity : {'euclidean', 'precomputed'}, default='euclidean'\n Dissimilarity measure to use:\n\n - 'euclidean':\n Pairwise Euclidean distances between points in the dataset.\n\n - 'precomputed':\n Pre-computed dissimilarities are passed directly to ``fit`` and\n ``fit_transform``.\n\n Attributes\n ----------\n embedding_ : ndarray of shape (n_samples, n_components)\n Stores the position of the dataset in the embedding space.\n\n stress_ : float\n The final value of the stress (sum of squared distance of the\n disparities and the distances for all constrained points).\n\n dissimilarity_matrix_ : ndarray of shape (n_samples, n_samples)\n Pairwise dissimilarities between the points. Symmetric matrix that:\n\n - either uses a custom dissimilarity matrix by setting `dissimilarity`\n to 'precomputed';\n - or constructs a dissimilarity matrix from data using\n Euclidean distances.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n The number of iterations corresponding to the best stress.\n\n See Also\n --------\n sklearn.decomposition.PCA : Principal component analysis that is a linear\n dimensionality reduction method.\n sklearn.decomposition.KernelPCA : Non-linear dimensionality reduction using\n kernels and PCA.\n TSNE : T-distributed Stochastic Neighbor Embedding.\n Isomap : Manifold learning based on Isometric Mapping.\n LocallyLinearEmbedding : Manifold learning using Locally Linear Embedding.\n SpectralEmbedding : Spectral embedding for non-linear dimensionality.\n\n References\n ----------\n \"Modern Multidimensional Scaling - Theory and Applications\" Borg, I.;\n Groenen P. Springer Series in Statistics (1997)\n\n \"Nonmetric multidimensional scaling: a numerical method\" Kruskal, J.\n Psychometrika, 29 (1964)\n\n \"Multidimensional scaling by optimizing goodness of fit to a nonmetric\n hypothesis\" Kruskal, J. Psychometrika, 29, (1964)\n\n Examples\n --------\n >>> from sklearn.datasets import load_digits\n >>> from sklearn.manifold import MDS\n >>> X, _ = load_digits(return_X_y=True)\n >>> X.shape\n (1797, 64)\n >>> embedding = MDS(n_components=2)\n >>> X_transformed = embedding.fit_transform(X[:100])\n >>> X_transformed.shape\n (100, 2)\n \"\"\"\n \n def __init__(self, n_components=2, *, metric=True, n_init=4, max_iter=300, verbose=0, eps=0.001, n_jobs=None, random_state=None, dissimilarity='euclidean'):\n self.n_components = n_components\n self.dissimilarity = dissimilarity\n self.metric = metric\n self.n_init = n_init\n self.max_iter = max_iter\n self.eps = eps\n self.verbose = verbose\n self.n_jobs = n_jobs\n self.random_state = random_state\n \n def _more_tags(self):\n return {'pairwise': self.dissimilarity == 'precomputed'}\n \n @deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def _pairwise(self):\n return self.dissimilarity == 'precomputed'\n \n def fit(self, X, y=None, init=None):\n \"\"\"\n Compute the position of the points in the embedding space.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features) or (n_samples, n_samples)\n Input data. If ``dissimilarity=='precomputed'``, the input should\n be the dissimilarity matrix.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n init : ndarray of shape (n_samples,), default=None\n Starting configuration of the embedding to initialize the SMACOF\n algorithm. By default, the algorithm is initialized with a randomly\n chosen array.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n self.fit_transform(X, init=init)\n return self\n \n def fit_transform(self, X, y=None, init=None):\n \"\"\"\n Fit the data from `X`, and returns the embedded coordinates.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features) or (n_samples, n_samples)\n Input data. If ``dissimilarity=='precomputed'``, the input should\n be the dissimilarity matrix.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n init : ndarray of shape (n_samples,), default=None\n Starting configuration of the embedding to initialize the SMACOF\n algorithm. By default, the algorithm is initialized with a randomly\n chosen array.\n\n Returns\n -------\n X_new : ndarray of shape (n_samples, n_components)\n X transformed in the new space.\n \"\"\"\n X = self._validate_data(X)\n if X.shape[0] == X.shape[1] and self.dissimilarity != 'precomputed':\n warnings.warn(\"The MDS API has changed. ``fit`` now constructs an dissimilarity matrix from data. To use a custom dissimilarity matrix, set ``dissimilarity='precomputed'``.\")\n if self.dissimilarity == 'precomputed':\n self.dissimilarity_matrix_ = X\n elif self.dissimilarity == 'euclidean':\n self.dissimilarity_matrix_ = euclidean_distances(X)\n else:\n raise ValueError(\"Proximity must be 'precomputed' or 'euclidean'. Got %s instead\" % str(self.dissimilarity))\n (self.embedding_, self.stress_, self.n_iter_) = smacof(self.dissimilarity_matrix_, metric=self.metric, n_components=self.n_components, init=init, n_init=self.n_init, n_jobs=self.n_jobs, max_iter=self.max_iter, verbose=self.verbose, eps=self.eps, random_state=self.random_state, return_n_iter=True)\n return self.embedding_\n" }, { "name": "SpectralEmbedding", @@ -24337,7 +24290,7 @@ "methods": [ "sklearn.manifold._spectral_embedding.SpectralEmbedding.__init__", "sklearn.manifold._spectral_embedding.SpectralEmbedding._more_tags", - "sklearn.manifold._spectral_embedding.SpectralEmbedding._pairwise", + "sklearn.manifold._spectral_embedding.SpectralEmbedding._pairwise@getter", "sklearn.manifold._spectral_embedding.SpectralEmbedding._get_affinity_matrix", "sklearn.manifold._spectral_embedding.SpectralEmbedding.fit", "sklearn.manifold._spectral_embedding.SpectralEmbedding.fit_transform" @@ -24361,8 +24314,8 @@ ], "is_public": true, "description": "T-distributed Stochastic Neighbor Embedding.\n\nt-SNE [1] is a tool to visualize high-dimensional data. It converts similarities between data points to joint probabilities and tries to minimize the Kullback-Leibler divergence between the joint probabilities of the low-dimensional embedding and the high-dimensional data. t-SNE has a cost function that is not convex, i.e. with different initializations we can get different results. It is highly recommended to use another dimensionality reduction method (e.g. PCA for dense data or TruncatedSVD for sparse data) to reduce the number of dimensions to a reasonable amount (e.g. 50) if the number of features is very high. This will suppress some noise and speed up the computation of pairwise distances between samples. For more tips see Laurens van der Maaten's FAQ [2]. Read more in the :ref:`User Guide `.", - "docstring": "T-distributed Stochastic Neighbor Embedding.\n\n t-SNE [1] is a tool to visualize high-dimensional data. It converts\n similarities between data points to joint probabilities and tries\n to minimize the Kullback-Leibler divergence between the joint\n probabilities of the low-dimensional embedding and the\n high-dimensional data. t-SNE has a cost function that is not convex,\n i.e. with different initializations we can get different results.\n\n It is highly recommended to use another dimensionality reduction\n method (e.g. PCA for dense data or TruncatedSVD for sparse data)\n to reduce the number of dimensions to a reasonable amount (e.g. 50)\n if the number of features is very high. This will suppress some\n noise and speed up the computation of pairwise distances between\n samples. For more tips see Laurens van der Maaten's FAQ [2].\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_components : int, default=2\n Dimension of the embedded space.\n\n perplexity : float, default=30.0\n The perplexity is related to the number of nearest neighbors that\n is used in other manifold learning algorithms. Larger datasets\n usually require a larger perplexity. Consider selecting a value\n between 5 and 50. Different values can result in significantly\n different results.\n\n early_exaggeration : float, default=12.0\n Controls how tight natural clusters in the original space are in\n the embedded space and how much space will be between them. For\n larger values, the space between natural clusters will be larger\n in the embedded space. Again, the choice of this parameter is not\n very critical. If the cost function increases during initial\n optimization, the early exaggeration factor or the learning rate\n might be too high.\n\n learning_rate : float or 'auto', default=200.0\n The learning rate for t-SNE is usually in the range [10.0, 1000.0]. If\n the learning rate is too high, the data may look like a 'ball' with any\n point approximately equidistant from its nearest neighbours. If the\n learning rate is too low, most points may look compressed in a dense\n cloud with few outliers. If the cost function gets stuck in a bad local\n minimum increasing the learning rate may help.\n Note that many other t-SNE implementations (bhtsne, FIt-SNE, openTSNE,\n etc.) use a definition of learning_rate that is 4 times smaller than\n ours. So our learning_rate=200 corresponds to learning_rate=800 in\n those other implementations. The 'auto' option sets the learning_rate\n to `max(N / early_exaggeration / 4, 50)` where N is the sample size,\n following [4] and [5]. This will become default in 1.2.\n\n n_iter : int, default=1000\n Maximum number of iterations for the optimization. Should be at\n least 250.\n\n n_iter_without_progress : int, default=300\n Maximum number of iterations without progress before we abort the\n optimization, used after 250 initial iterations with early\n exaggeration. Note that progress is only checked every 50 iterations so\n this value is rounded to the next multiple of 50.\n\n .. versionadded:: 0.17\n parameter *n_iter_without_progress* to control stopping criteria.\n\n min_grad_norm : float, default=1e-7\n If the gradient norm is below this threshold, the optimization will\n be stopped.\n\n metric : str or callable, default='euclidean'\n The metric to use when calculating distance between instances in a\n feature array. If metric is a string, it must be one of the options\n allowed by scipy.spatial.distance.pdist for its metric parameter, or\n a metric listed in pairwise.PAIRWISE_DISTANCE_FUNCTIONS.\n If metric is \"precomputed\", X is assumed to be a distance matrix.\n Alternatively, if metric is a callable function, it is called on each\n pair of instances (rows) and the resulting value recorded. The callable\n should take two arrays from X as input and return a value indicating\n the distance between them. The default is \"euclidean\" which is\n interpreted as squared euclidean distance.\n\n init : {'random', 'pca'} or ndarray of shape (n_samples, n_components), default='random'\n Initialization of embedding. Possible options are 'random', 'pca',\n and a numpy array of shape (n_samples, n_components).\n PCA initialization cannot be used with precomputed distances and is\n usually more globally stable than random initialization. `init='pca'`\n will become default in 1.2.\n\n verbose : int, default=0\n Verbosity level.\n\n random_state : int, RandomState instance or None, default=None\n Determines the random number generator. Pass an int for reproducible\n results across multiple function calls. Note that different\n initializations might result in different local minima of the cost\n function. See :term: `Glossary `.\n\n method : str, default='barnes_hut'\n By default the gradient calculation algorithm uses Barnes-Hut\n approximation running in O(NlogN) time. method='exact'\n will run on the slower, but exact, algorithm in O(N^2) time. The\n exact algorithm should be used when nearest-neighbor errors need\n to be better than 3%. However, the exact method cannot scale to\n millions of examples.\n\n .. versionadded:: 0.17\n Approximate optimization *method* via the Barnes-Hut.\n\n angle : float, default=0.5\n Only used if method='barnes_hut'\n This is the trade-off between speed and accuracy for Barnes-Hut T-SNE.\n 'angle' is the angular size (referred to as theta in [3]) of a distant\n node as measured from a point. If this size is below 'angle' then it is\n used as a summary node of all points contained within it.\n This method is not very sensitive to changes in this parameter\n in the range of 0.2 - 0.8. Angle less than 0.2 has quickly increasing\n computation time and angle greater 0.8 has quickly increasing error.\n\n n_jobs : int, default=None\n The number of parallel jobs to run for neighbors search. This parameter\n has no impact when ``metric=\"precomputed\"`` or\n (``metric=\"euclidean\"`` and ``method=\"exact\"``).\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n .. versionadded:: 0.22\n\n square_distances : True or 'legacy', default='legacy'\n Whether TSNE should square the distance values. ``'legacy'`` means\n that distance values are squared only when ``metric=\"euclidean\"``.\n ``True`` means that distance values are squared for all metrics.\n\n .. versionadded:: 0.24\n Added to provide backward compatibility during deprecation of\n legacy squaring behavior.\n .. deprecated:: 0.24\n Legacy squaring behavior was deprecated in 0.24. The ``'legacy'``\n value will be removed in 1.1 (renaming of 0.26), at which point the\n default value will change to ``True``.\n\n Attributes\n ----------\n embedding_ : array-like of shape (n_samples, n_components)\n Stores the embedding vectors.\n\n kl_divergence_ : float\n Kullback-Leibler divergence after optimization.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n Number of iterations run.\n\n See Also\n --------\n sklearn.decomposition.PCA : Principal component analysis that is a linear\n dimensionality reduction method.\n sklearn.decomposition.KernelPCA : Non-linear dimensionality reduction using\n kernels and PCA.\n MDS : Manifold learning using multidimensional scaling.\n Isomap : Manifold learning based on Isometric Mapping.\n LocallyLinearEmbedding : Manifold learning using Locally Linear Embedding.\n SpectralEmbedding : Spectral embedding for non-linear dimensionality.\n\n References\n ----------\n\n [1] van der Maaten, L.J.P.; Hinton, G.E. Visualizing High-Dimensional Data\n Using t-SNE. Journal of Machine Learning Research 9:2579-2605, 2008.\n\n [2] van der Maaten, L.J.P. t-Distributed Stochastic Neighbor Embedding\n https://lvdmaaten.github.io/tsne/\n\n [3] L.J.P. van der Maaten. Accelerating t-SNE using Tree-Based Algorithms.\n Journal of Machine Learning Research 15(Oct):3221-3245, 2014.\n https://lvdmaaten.github.io/publications/papers/JMLR_2014.pdf\n\n [4] Belkina, A. C., Ciccolella, C. O., Anno, R., Halpert, R., Spidlen, J.,\n & Snyder-Cappione, J. E. (2019). Automated optimized parameters for\n T-distributed stochastic neighbor embedding improve visualization\n and analysis of large datasets. Nature Communications, 10(1), 1-12.\n\n [5] Kobak, D., & Berens, P. (2019). The art of using t-SNE for single-cell\n transcriptomics. Nature Communications, 10(1), 1-14.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.manifold import TSNE\n >>> X = np.array([[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 1]])\n >>> X_embedded = TSNE(n_components=2, learning_rate='auto',\n ... init='random').fit_transform(X)\n >>> X_embedded.shape\n (4, 2)\n ", - "source_code": "\n\nclass TSNE(BaseEstimator):\n \"\"\"T-distributed Stochastic Neighbor Embedding.\n\n t-SNE [1] is a tool to visualize high-dimensional data. It converts\n similarities between data points to joint probabilities and tries\n to minimize the Kullback-Leibler divergence between the joint\n probabilities of the low-dimensional embedding and the\n high-dimensional data. t-SNE has a cost function that is not convex,\n i.e. with different initializations we can get different results.\n\n It is highly recommended to use another dimensionality reduction\n method (e.g. PCA for dense data or TruncatedSVD for sparse data)\n to reduce the number of dimensions to a reasonable amount (e.g. 50)\n if the number of features is very high. This will suppress some\n noise and speed up the computation of pairwise distances between\n samples. For more tips see Laurens van der Maaten's FAQ [2].\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_components : int, default=2\n Dimension of the embedded space.\n\n perplexity : float, default=30.0\n The perplexity is related to the number of nearest neighbors that\n is used in other manifold learning algorithms. Larger datasets\n usually require a larger perplexity. Consider selecting a value\n between 5 and 50. Different values can result in significantly\n different results.\n\n early_exaggeration : float, default=12.0\n Controls how tight natural clusters in the original space are in\n the embedded space and how much space will be between them. For\n larger values, the space between natural clusters will be larger\n in the embedded space. Again, the choice of this parameter is not\n very critical. If the cost function increases during initial\n optimization, the early exaggeration factor or the learning rate\n might be too high.\n\n learning_rate : float or 'auto', default=200.0\n The learning rate for t-SNE is usually in the range [10.0, 1000.0]. If\n the learning rate is too high, the data may look like a 'ball' with any\n point approximately equidistant from its nearest neighbours. If the\n learning rate is too low, most points may look compressed in a dense\n cloud with few outliers. If the cost function gets stuck in a bad local\n minimum increasing the learning rate may help.\n Note that many other t-SNE implementations (bhtsne, FIt-SNE, openTSNE,\n etc.) use a definition of learning_rate that is 4 times smaller than\n ours. So our learning_rate=200 corresponds to learning_rate=800 in\n those other implementations. The 'auto' option sets the learning_rate\n to `max(N / early_exaggeration / 4, 50)` where N is the sample size,\n following [4] and [5]. This will become default in 1.2.\n\n n_iter : int, default=1000\n Maximum number of iterations for the optimization. Should be at\n least 250.\n\n n_iter_without_progress : int, default=300\n Maximum number of iterations without progress before we abort the\n optimization, used after 250 initial iterations with early\n exaggeration. Note that progress is only checked every 50 iterations so\n this value is rounded to the next multiple of 50.\n\n .. versionadded:: 0.17\n parameter *n_iter_without_progress* to control stopping criteria.\n\n min_grad_norm : float, default=1e-7\n If the gradient norm is below this threshold, the optimization will\n be stopped.\n\n metric : str or callable, default='euclidean'\n The metric to use when calculating distance between instances in a\n feature array. If metric is a string, it must be one of the options\n allowed by scipy.spatial.distance.pdist for its metric parameter, or\n a metric listed in pairwise.PAIRWISE_DISTANCE_FUNCTIONS.\n If metric is \"precomputed\", X is assumed to be a distance matrix.\n Alternatively, if metric is a callable function, it is called on each\n pair of instances (rows) and the resulting value recorded. The callable\n should take two arrays from X as input and return a value indicating\n the distance between them. The default is \"euclidean\" which is\n interpreted as squared euclidean distance.\n\n init : {'random', 'pca'} or ndarray of shape (n_samples, n_components), default='random'\n Initialization of embedding. Possible options are 'random', 'pca',\n and a numpy array of shape (n_samples, n_components).\n PCA initialization cannot be used with precomputed distances and is\n usually more globally stable than random initialization. `init='pca'`\n will become default in 1.2.\n\n verbose : int, default=0\n Verbosity level.\n\n random_state : int, RandomState instance or None, default=None\n Determines the random number generator. Pass an int for reproducible\n results across multiple function calls. Note that different\n initializations might result in different local minima of the cost\n function. See :term: `Glossary `.\n\n method : str, default='barnes_hut'\n By default the gradient calculation algorithm uses Barnes-Hut\n approximation running in O(NlogN) time. method='exact'\n will run on the slower, but exact, algorithm in O(N^2) time. The\n exact algorithm should be used when nearest-neighbor errors need\n to be better than 3%. However, the exact method cannot scale to\n millions of examples.\n\n .. versionadded:: 0.17\n Approximate optimization *method* via the Barnes-Hut.\n\n angle : float, default=0.5\n Only used if method='barnes_hut'\n This is the trade-off between speed and accuracy for Barnes-Hut T-SNE.\n 'angle' is the angular size (referred to as theta in [3]) of a distant\n node as measured from a point. If this size is below 'angle' then it is\n used as a summary node of all points contained within it.\n This method is not very sensitive to changes in this parameter\n in the range of 0.2 - 0.8. Angle less than 0.2 has quickly increasing\n computation time and angle greater 0.8 has quickly increasing error.\n\n n_jobs : int, default=None\n The number of parallel jobs to run for neighbors search. This parameter\n has no impact when ``metric=\"precomputed\"`` or\n (``metric=\"euclidean\"`` and ``method=\"exact\"``).\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n .. versionadded:: 0.22\n\n square_distances : True or 'legacy', default='legacy'\n Whether TSNE should square the distance values. ``'legacy'`` means\n that distance values are squared only when ``metric=\"euclidean\"``.\n ``True`` means that distance values are squared for all metrics.\n\n .. versionadded:: 0.24\n Added to provide backward compatibility during deprecation of\n legacy squaring behavior.\n .. deprecated:: 0.24\n Legacy squaring behavior was deprecated in 0.24. The ``'legacy'``\n value will be removed in 1.1 (renaming of 0.26), at which point the\n default value will change to ``True``.\n\n Attributes\n ----------\n embedding_ : array-like of shape (n_samples, n_components)\n Stores the embedding vectors.\n\n kl_divergence_ : float\n Kullback-Leibler divergence after optimization.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n Number of iterations run.\n\n See Also\n --------\n sklearn.decomposition.PCA : Principal component analysis that is a linear\n dimensionality reduction method.\n sklearn.decomposition.KernelPCA : Non-linear dimensionality reduction using\n kernels and PCA.\n MDS : Manifold learning using multidimensional scaling.\n Isomap : Manifold learning based on Isometric Mapping.\n LocallyLinearEmbedding : Manifold learning using Locally Linear Embedding.\n SpectralEmbedding : Spectral embedding for non-linear dimensionality.\n\n References\n ----------\n\n [1] van der Maaten, L.J.P.; Hinton, G.E. Visualizing High-Dimensional Data\n Using t-SNE. Journal of Machine Learning Research 9:2579-2605, 2008.\n\n [2] van der Maaten, L.J.P. t-Distributed Stochastic Neighbor Embedding\n https://lvdmaaten.github.io/tsne/\n\n [3] L.J.P. van der Maaten. Accelerating t-SNE using Tree-Based Algorithms.\n Journal of Machine Learning Research 15(Oct):3221-3245, 2014.\n https://lvdmaaten.github.io/publications/papers/JMLR_2014.pdf\n\n [4] Belkina, A. C., Ciccolella, C. O., Anno, R., Halpert, R., Spidlen, J.,\n & Snyder-Cappione, J. E. (2019). Automated optimized parameters for\n T-distributed stochastic neighbor embedding improve visualization\n and analysis of large datasets. Nature Communications, 10(1), 1-12.\n\n [5] Kobak, D., & Berens, P. (2019). The art of using t-SNE for single-cell\n transcriptomics. Nature Communications, 10(1), 1-14.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.manifold import TSNE\n >>> X = np.array([[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 1]])\n >>> X_embedded = TSNE(n_components=2, learning_rate='auto',\n ... init='random').fit_transform(X)\n >>> X_embedded.shape\n (4, 2)\n \"\"\"\n _EXPLORATION_N_ITER = 250\n _N_ITER_CHECK = 50\n \n def __init__(self, n_components=2, *, perplexity=30.0, early_exaggeration=12.0, learning_rate='warn', n_iter=1000, n_iter_without_progress=300, min_grad_norm=1e-07, metric='euclidean', init='warn', verbose=0, random_state=None, method='barnes_hut', angle=0.5, n_jobs=None, square_distances='legacy'):\n self.n_components = n_components\n self.perplexity = perplexity\n self.early_exaggeration = early_exaggeration\n self.learning_rate = learning_rate\n self.n_iter = n_iter\n self.n_iter_without_progress = n_iter_without_progress\n self.min_grad_norm = min_grad_norm\n self.metric = metric\n self.init = init\n self.verbose = verbose\n self.random_state = random_state\n self.method = method\n self.angle = angle\n self.n_jobs = n_jobs\n self.square_distances = square_distances\n \n def _fit(self, X, skip_num_points=0):\n \"\"\"Private function to fit the model using X as training data.\"\"\"\n if isinstance(self.init, str) and self.init == 'warn':\n warnings.warn(\"The default initialization in TSNE will change from 'random' to 'pca' in 1.2.\", FutureWarning)\n self._init = 'random'\n else:\n self._init = self.init\n if self.learning_rate == 'warn':\n warnings.warn(\"The default learning rate in TSNE will change from 200.0 to 'auto' in 1.2.\", FutureWarning)\n self._learning_rate = 200.0\n else:\n self._learning_rate = self.learning_rate\n if isinstance(self._init, str) and self._init == 'pca' and issparse(X):\n raise TypeError('PCA initialization is currently not supported with the sparse input matrix. Use init=\"random\" instead.')\n if self.method not in ['barnes_hut', 'exact']:\n raise ValueError(\"'method' must be 'barnes_hut' or 'exact'\")\n if self.angle < 0.0 or self.angle > 1.0:\n raise ValueError(\"'angle' must be between 0.0 - 1.0\")\n if self.square_distances not in [True, 'legacy']:\n raise ValueError(\"'square_distances' must be True or 'legacy'.\")\n if self._learning_rate == 'auto':\n self._learning_rate = X.shape[0] / self.early_exaggeration / 4\n self._learning_rate = np.maximum(self._learning_rate, 50)\n elif not self._learning_rate > 0:\n raise ValueError(\"'learning_rate' must be a positive number or 'auto'.\")\n if self.metric != 'euclidean' and self.square_distances is not True:\n warnings.warn(\"'square_distances' has been introduced in 0.24 to help phase out legacy squaring behavior. The 'legacy' setting will be removed in 1.1 (renaming of 0.26), and the default setting will be changed to True. In 1.3, 'square_distances' will be removed altogether, and distances will be squared by default. Set 'square_distances'=True to silence this warning.\", FutureWarning)\n if self.method == 'barnes_hut':\n X = self._validate_data(X, accept_sparse=['csr'], ensure_min_samples=2, dtype=[np.float32, np.float64])\n else:\n X = self._validate_data(X, accept_sparse=['csr', 'csc', 'coo'], dtype=[np.float32, np.float64])\n if self.metric == 'precomputed':\n if isinstance(self._init, str) and self._init == 'pca':\n raise ValueError('The parameter init=\"pca\" cannot be used with metric=\"precomputed\".')\n if X.shape[0] != X.shape[1]:\n raise ValueError('X should be a square distance matrix')\n check_non_negative(X, \"TSNE.fit(). With metric='precomputed', X should contain positive distances.\")\n if self.method == 'exact' and issparse(X):\n raise TypeError('TSNE with method=\"exact\" does not accept sparse precomputed distance matrix. Use method=\"barnes_hut\" or provide the dense distance matrix.')\n if self.method == 'barnes_hut' and self.n_components > 3:\n raise ValueError(\"'n_components' should be inferior to 4 for the barnes_hut algorithm as it relies on quad-tree or oct-tree.\")\n random_state = check_random_state(self.random_state)\n if self.early_exaggeration < 1.0:\n raise ValueError('early_exaggeration must be at least 1, but is {}'.format(self.early_exaggeration))\n if self.n_iter < 250:\n raise ValueError('n_iter should be at least 250')\n n_samples = X.shape[0]\n neighbors_nn = None\n if self.method == 'exact':\n if self.metric == 'precomputed':\n distances = X\n else:\n if self.verbose:\n print('[t-SNE] Computing pairwise distances...')\n if self.metric == 'euclidean':\n distances = pairwise_distances(X, metric=self.metric, squared=True)\n else:\n distances = pairwise_distances(X, metric=self.metric, n_jobs=self.n_jobs)\n if np.any(distances < 0):\n raise ValueError('All distances should be positive, the metric given is not correct')\n if self.metric != 'euclidean' and self.square_distances is True:\n distances **= 2\n P = _joint_probabilities(distances, self.perplexity, self.verbose)\n assert np.all(np.isfinite(P)), 'All probabilities should be finite'\n assert np.all(P >= 0), 'All probabilities should be non-negative'\n assert np.all(P <= 1), 'All probabilities should be less or then equal to one'\n else:\n n_neighbors = min(n_samples - 1, int(3.0 * self.perplexity + 1))\n if self.verbose:\n print('[t-SNE] Computing {} nearest neighbors...'.format(n_neighbors))\n knn = NearestNeighbors(algorithm='auto', n_jobs=self.n_jobs, n_neighbors=n_neighbors, metric=self.metric)\n t0 = time()\n knn.fit(X)\n duration = time() - t0\n if self.verbose:\n print('[t-SNE] Indexed {} samples in {:.3f}s...'.format(n_samples, duration))\n t0 = time()\n distances_nn = knn.kneighbors_graph(mode='distance')\n duration = time() - t0\n if self.verbose:\n print('[t-SNE] Computed neighbors for {} samples in {:.3f}s...'.format(n_samples, duration))\n del knn\n if self.square_distances is True or self.metric == 'euclidean':\n distances_nn.data **= 2\n P = _joint_probabilities_nn(distances_nn, self.perplexity, self.verbose)\n if isinstance(self._init, np.ndarray):\n X_embedded = self._init\n elif self._init == 'pca':\n pca = PCA(n_components=self.n_components, svd_solver='randomized', random_state=random_state)\n X_embedded = pca.fit_transform(X).astype(np.float32, copy=False)\n warnings.warn('The PCA initialization in TSNE will change to have the standard deviation of PC1 equal to 1e-4 in 1.2. This will ensure better convergence.', FutureWarning)\n elif self._init == 'random':\n X_embedded = 0.0001 * random_state.randn(n_samples, self.n_components).astype(np.float32)\n else:\n raise ValueError(\"'init' must be 'pca', 'random', or a numpy array\")\n degrees_of_freedom = max(self.n_components - 1, 1)\n return self._tsne(P, degrees_of_freedom, n_samples, X_embedded=X_embedded, neighbors=neighbors_nn, skip_num_points=skip_num_points)\n \n def _tsne(self, P, degrees_of_freedom, n_samples, X_embedded, neighbors=None, skip_num_points=0):\n \"\"\"Runs t-SNE.\"\"\"\n params = X_embedded.ravel()\n opt_args = {'it': 0, 'n_iter_check': self._N_ITER_CHECK, 'min_grad_norm': self.min_grad_norm, 'learning_rate': self._learning_rate, 'verbose': self.verbose, 'kwargs': dict(skip_num_points=skip_num_points), 'args': [P, degrees_of_freedom, n_samples, self.n_components], 'n_iter_without_progress': self._EXPLORATION_N_ITER, 'n_iter': self._EXPLORATION_N_ITER, 'momentum': 0.5}\n if self.method == 'barnes_hut':\n obj_func = _kl_divergence_bh\n opt_args['kwargs']['angle'] = self.angle\n opt_args['kwargs']['verbose'] = self.verbose\n opt_args['kwargs']['num_threads'] = _openmp_effective_n_threads()\n else:\n obj_func = _kl_divergence\n P *= self.early_exaggeration\n (params, kl_divergence, it) = _gradient_descent(obj_func, params, **opt_args)\n if self.verbose:\n print('[t-SNE] KL divergence after %d iterations with early exaggeration: %f' % (it + 1, kl_divergence))\n P /= self.early_exaggeration\n remaining = self.n_iter - self._EXPLORATION_N_ITER\n if it < self._EXPLORATION_N_ITER or remaining > 0:\n opt_args['n_iter'] = self.n_iter\n opt_args['it'] = it + 1\n opt_args['momentum'] = 0.8\n opt_args['n_iter_without_progress'] = self.n_iter_without_progress\n (params, kl_divergence, it) = _gradient_descent(obj_func, params, **opt_args)\n self.n_iter_ = it\n if self.verbose:\n print('[t-SNE] KL divergence after %d iterations: %f' % (it + 1, kl_divergence))\n X_embedded = params.reshape(n_samples, self.n_components)\n self.kl_divergence_ = kl_divergence\n return X_embedded\n \n def fit_transform(self, X, y=None):\n \"\"\"Fit X into an embedded space and return that transformed output.\n\n Parameters\n ----------\n X : ndarray of shape (n_samples, n_features) or (n_samples, n_samples)\n If the metric is 'precomputed' X must be a square distance\n matrix. Otherwise it contains a sample per row. If the method\n is 'exact', X may be a sparse matrix of type 'csr', 'csc'\n or 'coo'. If the method is 'barnes_hut' and the metric is\n 'precomputed', X may be a precomputed sparse graph.\n\n y : None\n Ignored.\n\n Returns\n -------\n X_new : ndarray of shape (n_samples, n_components)\n Embedding of the training data in low-dimensional space.\n \"\"\"\n embedding = self._fit(X)\n self.embedding_ = embedding\n return self.embedding_\n \n def fit(self, X, y=None):\n \"\"\"Fit X into an embedded space.\n\n Parameters\n ----------\n X : ndarray of shape (n_samples, n_features) or (n_samples, n_samples)\n If the metric is 'precomputed' X must be a square distance\n matrix. Otherwise it contains a sample per row. If the method\n is 'exact', X may be a sparse matrix of type 'csr', 'csc'\n or 'coo'. If the method is 'barnes_hut' and the metric is\n 'precomputed', X may be a precomputed sparse graph.\n\n y : None\n Ignored.\n\n Returns\n -------\n X_new : array of shape (n_samples, n_components)\n Embedding of the training data in low-dimensional space.\n \"\"\"\n self.fit_transform(X)\n return self\n" + "docstring": "T-distributed Stochastic Neighbor Embedding.\n\n t-SNE [1] is a tool to visualize high-dimensional data. It converts\n similarities between data points to joint probabilities and tries\n to minimize the Kullback-Leibler divergence between the joint\n probabilities of the low-dimensional embedding and the\n high-dimensional data. t-SNE has a cost function that is not convex,\n i.e. with different initializations we can get different results.\n\n It is highly recommended to use another dimensionality reduction\n method (e.g. PCA for dense data or TruncatedSVD for sparse data)\n to reduce the number of dimensions to a reasonable amount (e.g. 50)\n if the number of features is very high. This will suppress some\n noise and speed up the computation of pairwise distances between\n samples. For more tips see Laurens van der Maaten's FAQ [2].\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_components : int, default=2\n Dimension of the embedded space.\n\n perplexity : float, default=30.0\n The perplexity is related to the number of nearest neighbors that\n is used in other manifold learning algorithms. Larger datasets\n usually require a larger perplexity. Consider selecting a value\n between 5 and 50. Different values can result in significantly\n different results.\n\n early_exaggeration : float, default=12.0\n Controls how tight natural clusters in the original space are in\n the embedded space and how much space will be between them. For\n larger values, the space between natural clusters will be larger\n in the embedded space. Again, the choice of this parameter is not\n very critical. If the cost function increases during initial\n optimization, the early exaggeration factor or the learning rate\n might be too high.\n\n learning_rate : float or 'auto', default=200.0\n The learning rate for t-SNE is usually in the range [10.0, 1000.0]. If\n the learning rate is too high, the data may look like a 'ball' with any\n point approximately equidistant from its nearest neighbours. If the\n learning rate is too low, most points may look compressed in a dense\n cloud with few outliers. If the cost function gets stuck in a bad local\n minimum increasing the learning rate may help.\n Note that many other t-SNE implementations (bhtsne, FIt-SNE, openTSNE,\n etc.) use a definition of learning_rate that is 4 times smaller than\n ours. So our learning_rate=200 corresponds to learning_rate=800 in\n those other implementations. The 'auto' option sets the learning_rate\n to `max(N / early_exaggeration / 4, 50)` where N is the sample size,\n following [4] and [5]. This will become default in 1.2.\n\n n_iter : int, default=1000\n Maximum number of iterations for the optimization. Should be at\n least 250.\n\n n_iter_without_progress : int, default=300\n Maximum number of iterations without progress before we abort the\n optimization, used after 250 initial iterations with early\n exaggeration. Note that progress is only checked every 50 iterations so\n this value is rounded to the next multiple of 50.\n\n .. versionadded:: 0.17\n parameter *n_iter_without_progress* to control stopping criteria.\n\n min_grad_norm : float, default=1e-7\n If the gradient norm is below this threshold, the optimization will\n be stopped.\n\n metric : str or callable, default='euclidean'\n The metric to use when calculating distance between instances in a\n feature array. If metric is a string, it must be one of the options\n allowed by scipy.spatial.distance.pdist for its metric parameter, or\n a metric listed in pairwise.PAIRWISE_DISTANCE_FUNCTIONS.\n If metric is \"precomputed\", X is assumed to be a distance matrix.\n Alternatively, if metric is a callable function, it is called on each\n pair of instances (rows) and the resulting value recorded. The callable\n should take two arrays from X as input and return a value indicating\n the distance between them. The default is \"euclidean\" which is\n interpreted as squared euclidean distance.\n\n init : {'random', 'pca'} or ndarray of shape (n_samples, n_components), default='random'\n Initialization of embedding. Possible options are 'random', 'pca',\n and a numpy array of shape (n_samples, n_components).\n PCA initialization cannot be used with precomputed distances and is\n usually more globally stable than random initialization. `init='pca'`\n will become default in 1.2.\n\n verbose : int, default=0\n Verbosity level.\n\n random_state : int, RandomState instance or None, default=None\n Determines the random number generator. Pass an int for reproducible\n results across multiple function calls. Note that different\n initializations might result in different local minima of the cost\n function. See :term:`Glossary `.\n\n method : str, default='barnes_hut'\n By default the gradient calculation algorithm uses Barnes-Hut\n approximation running in O(NlogN) time. method='exact'\n will run on the slower, but exact, algorithm in O(N^2) time. The\n exact algorithm should be used when nearest-neighbor errors need\n to be better than 3%. However, the exact method cannot scale to\n millions of examples.\n\n .. versionadded:: 0.17\n Approximate optimization *method* via the Barnes-Hut.\n\n angle : float, default=0.5\n Only used if method='barnes_hut'\n This is the trade-off between speed and accuracy for Barnes-Hut T-SNE.\n 'angle' is the angular size (referred to as theta in [3]) of a distant\n node as measured from a point. If this size is below 'angle' then it is\n used as a summary node of all points contained within it.\n This method is not very sensitive to changes in this parameter\n in the range of 0.2 - 0.8. Angle less than 0.2 has quickly increasing\n computation time and angle greater 0.8 has quickly increasing error.\n\n n_jobs : int, default=None\n The number of parallel jobs to run for neighbors search. This parameter\n has no impact when ``metric=\"precomputed\"`` or\n (``metric=\"euclidean\"`` and ``method=\"exact\"``).\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n .. versionadded:: 0.22\n\n square_distances : True or 'legacy', default='legacy'\n Whether TSNE should square the distance values. ``'legacy'`` means\n that distance values are squared only when ``metric=\"euclidean\"``.\n ``True`` means that distance values are squared for all metrics.\n\n .. versionadded:: 0.24\n Added to provide backward compatibility during deprecation of\n legacy squaring behavior.\n .. deprecated:: 0.24\n Legacy squaring behavior was deprecated in 0.24. The ``'legacy'``\n value will be removed in 1.1 (renaming of 0.26), at which point the\n default value will change to ``True``.\n\n Attributes\n ----------\n embedding_ : array-like of shape (n_samples, n_components)\n Stores the embedding vectors.\n\n kl_divergence_ : float\n Kullback-Leibler divergence after optimization.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n Number of iterations run.\n\n See Also\n --------\n sklearn.decomposition.PCA : Principal component analysis that is a linear\n dimensionality reduction method.\n sklearn.decomposition.KernelPCA : Non-linear dimensionality reduction using\n kernels and PCA.\n MDS : Manifold learning using multidimensional scaling.\n Isomap : Manifold learning based on Isometric Mapping.\n LocallyLinearEmbedding : Manifold learning using Locally Linear Embedding.\n SpectralEmbedding : Spectral embedding for non-linear dimensionality.\n\n References\n ----------\n\n [1] van der Maaten, L.J.P.; Hinton, G.E. Visualizing High-Dimensional Data\n Using t-SNE. Journal of Machine Learning Research 9:2579-2605, 2008.\n\n [2] van der Maaten, L.J.P. t-Distributed Stochastic Neighbor Embedding\n https://lvdmaaten.github.io/tsne/\n\n [3] L.J.P. van der Maaten. Accelerating t-SNE using Tree-Based Algorithms.\n Journal of Machine Learning Research 15(Oct):3221-3245, 2014.\n https://lvdmaaten.github.io/publications/papers/JMLR_2014.pdf\n\n [4] Belkina, A. C., Ciccolella, C. O., Anno, R., Halpert, R., Spidlen, J.,\n & Snyder-Cappione, J. E. (2019). Automated optimized parameters for\n T-distributed stochastic neighbor embedding improve visualization\n and analysis of large datasets. Nature Communications, 10(1), 1-12.\n\n [5] Kobak, D., & Berens, P. (2019). The art of using t-SNE for single-cell\n transcriptomics. Nature Communications, 10(1), 1-14.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.manifold import TSNE\n >>> X = np.array([[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 1]])\n >>> X_embedded = TSNE(n_components=2, learning_rate='auto',\n ... init='random').fit_transform(X)\n >>> X_embedded.shape\n (4, 2)\n ", + "source_code": "\n\nclass TSNE(BaseEstimator):\n \"\"\"T-distributed Stochastic Neighbor Embedding.\n\n t-SNE [1] is a tool to visualize high-dimensional data. It converts\n similarities between data points to joint probabilities and tries\n to minimize the Kullback-Leibler divergence between the joint\n probabilities of the low-dimensional embedding and the\n high-dimensional data. t-SNE has a cost function that is not convex,\n i.e. with different initializations we can get different results.\n\n It is highly recommended to use another dimensionality reduction\n method (e.g. PCA for dense data or TruncatedSVD for sparse data)\n to reduce the number of dimensions to a reasonable amount (e.g. 50)\n if the number of features is very high. This will suppress some\n noise and speed up the computation of pairwise distances between\n samples. For more tips see Laurens van der Maaten's FAQ [2].\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_components : int, default=2\n Dimension of the embedded space.\n\n perplexity : float, default=30.0\n The perplexity is related to the number of nearest neighbors that\n is used in other manifold learning algorithms. Larger datasets\n usually require a larger perplexity. Consider selecting a value\n between 5 and 50. Different values can result in significantly\n different results.\n\n early_exaggeration : float, default=12.0\n Controls how tight natural clusters in the original space are in\n the embedded space and how much space will be between them. For\n larger values, the space between natural clusters will be larger\n in the embedded space. Again, the choice of this parameter is not\n very critical. If the cost function increases during initial\n optimization, the early exaggeration factor or the learning rate\n might be too high.\n\n learning_rate : float or 'auto', default=200.0\n The learning rate for t-SNE is usually in the range [10.0, 1000.0]. If\n the learning rate is too high, the data may look like a 'ball' with any\n point approximately equidistant from its nearest neighbours. If the\n learning rate is too low, most points may look compressed in a dense\n cloud with few outliers. If the cost function gets stuck in a bad local\n minimum increasing the learning rate may help.\n Note that many other t-SNE implementations (bhtsne, FIt-SNE, openTSNE,\n etc.) use a definition of learning_rate that is 4 times smaller than\n ours. So our learning_rate=200 corresponds to learning_rate=800 in\n those other implementations. The 'auto' option sets the learning_rate\n to `max(N / early_exaggeration / 4, 50)` where N is the sample size,\n following [4] and [5]. This will become default in 1.2.\n\n n_iter : int, default=1000\n Maximum number of iterations for the optimization. Should be at\n least 250.\n\n n_iter_without_progress : int, default=300\n Maximum number of iterations without progress before we abort the\n optimization, used after 250 initial iterations with early\n exaggeration. Note that progress is only checked every 50 iterations so\n this value is rounded to the next multiple of 50.\n\n .. versionadded:: 0.17\n parameter *n_iter_without_progress* to control stopping criteria.\n\n min_grad_norm : float, default=1e-7\n If the gradient norm is below this threshold, the optimization will\n be stopped.\n\n metric : str or callable, default='euclidean'\n The metric to use when calculating distance between instances in a\n feature array. If metric is a string, it must be one of the options\n allowed by scipy.spatial.distance.pdist for its metric parameter, or\n a metric listed in pairwise.PAIRWISE_DISTANCE_FUNCTIONS.\n If metric is \"precomputed\", X is assumed to be a distance matrix.\n Alternatively, if metric is a callable function, it is called on each\n pair of instances (rows) and the resulting value recorded. The callable\n should take two arrays from X as input and return a value indicating\n the distance between them. The default is \"euclidean\" which is\n interpreted as squared euclidean distance.\n\n init : {'random', 'pca'} or ndarray of shape (n_samples, n_components), default='random'\n Initialization of embedding. Possible options are 'random', 'pca',\n and a numpy array of shape (n_samples, n_components).\n PCA initialization cannot be used with precomputed distances and is\n usually more globally stable than random initialization. `init='pca'`\n will become default in 1.2.\n\n verbose : int, default=0\n Verbosity level.\n\n random_state : int, RandomState instance or None, default=None\n Determines the random number generator. Pass an int for reproducible\n results across multiple function calls. Note that different\n initializations might result in different local minima of the cost\n function. See :term:`Glossary `.\n\n method : str, default='barnes_hut'\n By default the gradient calculation algorithm uses Barnes-Hut\n approximation running in O(NlogN) time. method='exact'\n will run on the slower, but exact, algorithm in O(N^2) time. The\n exact algorithm should be used when nearest-neighbor errors need\n to be better than 3%. However, the exact method cannot scale to\n millions of examples.\n\n .. versionadded:: 0.17\n Approximate optimization *method* via the Barnes-Hut.\n\n angle : float, default=0.5\n Only used if method='barnes_hut'\n This is the trade-off between speed and accuracy for Barnes-Hut T-SNE.\n 'angle' is the angular size (referred to as theta in [3]) of a distant\n node as measured from a point. If this size is below 'angle' then it is\n used as a summary node of all points contained within it.\n This method is not very sensitive to changes in this parameter\n in the range of 0.2 - 0.8. Angle less than 0.2 has quickly increasing\n computation time and angle greater 0.8 has quickly increasing error.\n\n n_jobs : int, default=None\n The number of parallel jobs to run for neighbors search. This parameter\n has no impact when ``metric=\"precomputed\"`` or\n (``metric=\"euclidean\"`` and ``method=\"exact\"``).\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n .. versionadded:: 0.22\n\n square_distances : True or 'legacy', default='legacy'\n Whether TSNE should square the distance values. ``'legacy'`` means\n that distance values are squared only when ``metric=\"euclidean\"``.\n ``True`` means that distance values are squared for all metrics.\n\n .. versionadded:: 0.24\n Added to provide backward compatibility during deprecation of\n legacy squaring behavior.\n .. deprecated:: 0.24\n Legacy squaring behavior was deprecated in 0.24. The ``'legacy'``\n value will be removed in 1.1 (renaming of 0.26), at which point the\n default value will change to ``True``.\n\n Attributes\n ----------\n embedding_ : array-like of shape (n_samples, n_components)\n Stores the embedding vectors.\n\n kl_divergence_ : float\n Kullback-Leibler divergence after optimization.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n Number of iterations run.\n\n See Also\n --------\n sklearn.decomposition.PCA : Principal component analysis that is a linear\n dimensionality reduction method.\n sklearn.decomposition.KernelPCA : Non-linear dimensionality reduction using\n kernels and PCA.\n MDS : Manifold learning using multidimensional scaling.\n Isomap : Manifold learning based on Isometric Mapping.\n LocallyLinearEmbedding : Manifold learning using Locally Linear Embedding.\n SpectralEmbedding : Spectral embedding for non-linear dimensionality.\n\n References\n ----------\n\n [1] van der Maaten, L.J.P.; Hinton, G.E. Visualizing High-Dimensional Data\n Using t-SNE. Journal of Machine Learning Research 9:2579-2605, 2008.\n\n [2] van der Maaten, L.J.P. t-Distributed Stochastic Neighbor Embedding\n https://lvdmaaten.github.io/tsne/\n\n [3] L.J.P. van der Maaten. Accelerating t-SNE using Tree-Based Algorithms.\n Journal of Machine Learning Research 15(Oct):3221-3245, 2014.\n https://lvdmaaten.github.io/publications/papers/JMLR_2014.pdf\n\n [4] Belkina, A. C., Ciccolella, C. O., Anno, R., Halpert, R., Spidlen, J.,\n & Snyder-Cappione, J. E. (2019). Automated optimized parameters for\n T-distributed stochastic neighbor embedding improve visualization\n and analysis of large datasets. Nature Communications, 10(1), 1-12.\n\n [5] Kobak, D., & Berens, P. (2019). The art of using t-SNE for single-cell\n transcriptomics. Nature Communications, 10(1), 1-14.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.manifold import TSNE\n >>> X = np.array([[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 1]])\n >>> X_embedded = TSNE(n_components=2, learning_rate='auto',\n ... init='random').fit_transform(X)\n >>> X_embedded.shape\n (4, 2)\n \"\"\"\n _EXPLORATION_N_ITER = 250\n _N_ITER_CHECK = 50\n \n def __init__(self, n_components=2, *, perplexity=30.0, early_exaggeration=12.0, learning_rate='warn', n_iter=1000, n_iter_without_progress=300, min_grad_norm=1e-07, metric='euclidean', init='warn', verbose=0, random_state=None, method='barnes_hut', angle=0.5, n_jobs=None, square_distances='legacy'):\n self.n_components = n_components\n self.perplexity = perplexity\n self.early_exaggeration = early_exaggeration\n self.learning_rate = learning_rate\n self.n_iter = n_iter\n self.n_iter_without_progress = n_iter_without_progress\n self.min_grad_norm = min_grad_norm\n self.metric = metric\n self.init = init\n self.verbose = verbose\n self.random_state = random_state\n self.method = method\n self.angle = angle\n self.n_jobs = n_jobs\n self.square_distances = square_distances\n \n def _fit(self, X, skip_num_points=0):\n \"\"\"Private function to fit the model using X as training data.\"\"\"\n if isinstance(self.init, str) and self.init == 'warn':\n warnings.warn(\"The default initialization in TSNE will change from 'random' to 'pca' in 1.2.\", FutureWarning)\n self._init = 'random'\n else:\n self._init = self.init\n if self.learning_rate == 'warn':\n warnings.warn(\"The default learning rate in TSNE will change from 200.0 to 'auto' in 1.2.\", FutureWarning)\n self._learning_rate = 200.0\n else:\n self._learning_rate = self.learning_rate\n if isinstance(self._init, str) and self._init == 'pca' and issparse(X):\n raise TypeError('PCA initialization is currently not supported with the sparse input matrix. Use init=\"random\" instead.')\n if self.method not in ['barnes_hut', 'exact']:\n raise ValueError(\"'method' must be 'barnes_hut' or 'exact'\")\n if self.angle < 0.0 or self.angle > 1.0:\n raise ValueError(\"'angle' must be between 0.0 - 1.0\")\n if self.square_distances not in [True, 'legacy']:\n raise ValueError(\"'square_distances' must be True or 'legacy'.\")\n if self._learning_rate == 'auto':\n self._learning_rate = X.shape[0] / self.early_exaggeration / 4\n self._learning_rate = np.maximum(self._learning_rate, 50)\n elif not self._learning_rate > 0:\n raise ValueError(\"'learning_rate' must be a positive number or 'auto'.\")\n if self.metric != 'euclidean' and self.square_distances is not True:\n warnings.warn(\"'square_distances' has been introduced in 0.24 to help phase out legacy squaring behavior. The 'legacy' setting will be removed in 1.1 (renaming of 0.26), and the default setting will be changed to True. In 1.3, 'square_distances' will be removed altogether, and distances will be squared by default. Set 'square_distances'=True to silence this warning.\", FutureWarning)\n if self.method == 'barnes_hut':\n X = self._validate_data(X, accept_sparse=['csr'], ensure_min_samples=2, dtype=[np.float32, np.float64])\n else:\n X = self._validate_data(X, accept_sparse=['csr', 'csc', 'coo'], dtype=[np.float32, np.float64])\n if self.metric == 'precomputed':\n if isinstance(self._init, str) and self._init == 'pca':\n raise ValueError('The parameter init=\"pca\" cannot be used with metric=\"precomputed\".')\n if X.shape[0] != X.shape[1]:\n raise ValueError('X should be a square distance matrix')\n check_non_negative(X, \"TSNE.fit(). With metric='precomputed', X should contain positive distances.\")\n if self.method == 'exact' and issparse(X):\n raise TypeError('TSNE with method=\"exact\" does not accept sparse precomputed distance matrix. Use method=\"barnes_hut\" or provide the dense distance matrix.')\n if self.method == 'barnes_hut' and self.n_components > 3:\n raise ValueError(\"'n_components' should be inferior to 4 for the barnes_hut algorithm as it relies on quad-tree or oct-tree.\")\n random_state = check_random_state(self.random_state)\n if self.early_exaggeration < 1.0:\n raise ValueError('early_exaggeration must be at least 1, but is {}'.format(self.early_exaggeration))\n if self.n_iter < 250:\n raise ValueError('n_iter should be at least 250')\n n_samples = X.shape[0]\n neighbors_nn = None\n if self.method == 'exact':\n if self.metric == 'precomputed':\n distances = X\n else:\n if self.verbose:\n print('[t-SNE] Computing pairwise distances...')\n if self.metric == 'euclidean':\n distances = pairwise_distances(X, metric=self.metric, squared=True)\n else:\n distances = pairwise_distances(X, metric=self.metric, n_jobs=self.n_jobs)\n if np.any(distances < 0):\n raise ValueError('All distances should be positive, the metric given is not correct')\n if self.metric != 'euclidean' and self.square_distances is True:\n distances **= 2\n P = _joint_probabilities(distances, self.perplexity, self.verbose)\n assert np.all(np.isfinite(P)), 'All probabilities should be finite'\n assert np.all(P >= 0), 'All probabilities should be non-negative'\n assert np.all(P <= 1), 'All probabilities should be less or then equal to one'\n else:\n n_neighbors = min(n_samples - 1, int(3.0 * self.perplexity + 1))\n if self.verbose:\n print('[t-SNE] Computing {} nearest neighbors...'.format(n_neighbors))\n knn = NearestNeighbors(algorithm='auto', n_jobs=self.n_jobs, n_neighbors=n_neighbors, metric=self.metric)\n t0 = time()\n knn.fit(X)\n duration = time() - t0\n if self.verbose:\n print('[t-SNE] Indexed {} samples in {:.3f}s...'.format(n_samples, duration))\n t0 = time()\n distances_nn = knn.kneighbors_graph(mode='distance')\n duration = time() - t0\n if self.verbose:\n print('[t-SNE] Computed neighbors for {} samples in {:.3f}s...'.format(n_samples, duration))\n del knn\n if self.square_distances is True or self.metric == 'euclidean':\n distances_nn.data **= 2\n P = _joint_probabilities_nn(distances_nn, self.perplexity, self.verbose)\n if isinstance(self._init, np.ndarray):\n X_embedded = self._init\n elif self._init == 'pca':\n pca = PCA(n_components=self.n_components, svd_solver='randomized', random_state=random_state)\n X_embedded = pca.fit_transform(X).astype(np.float32, copy=False)\n warnings.warn('The PCA initialization in TSNE will change to have the standard deviation of PC1 equal to 1e-4 in 1.2. This will ensure better convergence.', FutureWarning)\n elif self._init == 'random':\n X_embedded = 0.0001 * random_state.randn(n_samples, self.n_components).astype(np.float32)\n else:\n raise ValueError(\"'init' must be 'pca', 'random', or a numpy array\")\n degrees_of_freedom = max(self.n_components - 1, 1)\n return self._tsne(P, degrees_of_freedom, n_samples, X_embedded=X_embedded, neighbors=neighbors_nn, skip_num_points=skip_num_points)\n \n def _tsne(self, P, degrees_of_freedom, n_samples, X_embedded, neighbors=None, skip_num_points=0):\n \"\"\"Runs t-SNE.\"\"\"\n params = X_embedded.ravel()\n opt_args = {'it': 0, 'n_iter_check': self._N_ITER_CHECK, 'min_grad_norm': self.min_grad_norm, 'learning_rate': self._learning_rate, 'verbose': self.verbose, 'kwargs': dict(skip_num_points=skip_num_points), 'args': [P, degrees_of_freedom, n_samples, self.n_components], 'n_iter_without_progress': self._EXPLORATION_N_ITER, 'n_iter': self._EXPLORATION_N_ITER, 'momentum': 0.5}\n if self.method == 'barnes_hut':\n obj_func = _kl_divergence_bh\n opt_args['kwargs']['angle'] = self.angle\n opt_args['kwargs']['verbose'] = self.verbose\n opt_args['kwargs']['num_threads'] = _openmp_effective_n_threads()\n else:\n obj_func = _kl_divergence\n P *= self.early_exaggeration\n (params, kl_divergence, it) = _gradient_descent(obj_func, params, **opt_args)\n if self.verbose:\n print('[t-SNE] KL divergence after %d iterations with early exaggeration: %f' % (it + 1, kl_divergence))\n P /= self.early_exaggeration\n remaining = self.n_iter - self._EXPLORATION_N_ITER\n if it < self._EXPLORATION_N_ITER or remaining > 0:\n opt_args['n_iter'] = self.n_iter\n opt_args['it'] = it + 1\n opt_args['momentum'] = 0.8\n opt_args['n_iter_without_progress'] = self.n_iter_without_progress\n (params, kl_divergence, it) = _gradient_descent(obj_func, params, **opt_args)\n self.n_iter_ = it\n if self.verbose:\n print('[t-SNE] KL divergence after %d iterations: %f' % (it + 1, kl_divergence))\n X_embedded = params.reshape(n_samples, self.n_components)\n self.kl_divergence_ = kl_divergence\n return X_embedded\n \n def fit_transform(self, X, y=None):\n \"\"\"Fit X into an embedded space and return that transformed output.\n\n Parameters\n ----------\n X : ndarray of shape (n_samples, n_features) or (n_samples, n_samples)\n If the metric is 'precomputed' X must be a square distance\n matrix. Otherwise it contains a sample per row. If the method\n is 'exact', X may be a sparse matrix of type 'csr', 'csc'\n or 'coo'. If the method is 'barnes_hut' and the metric is\n 'precomputed', X may be a precomputed sparse graph.\n\n y : None\n Ignored.\n\n Returns\n -------\n X_new : ndarray of shape (n_samples, n_components)\n Embedding of the training data in low-dimensional space.\n \"\"\"\n embedding = self._fit(X)\n self.embedding_ = embedding\n return self.embedding_\n \n def fit(self, X, y=None):\n \"\"\"Fit X into an embedded space.\n\n Parameters\n ----------\n X : ndarray of shape (n_samples, n_features) or (n_samples, n_samples)\n If the metric is 'precomputed' X must be a square distance\n matrix. Otherwise it contains a sample per row. If the method\n is 'exact', X may be a sparse matrix of type 'csr', 'csc'\n or 'coo'. If the method is 'barnes_hut' and the metric is\n 'precomputed', X may be a precomputed sparse graph.\n\n y : None\n Ignored.\n\n Returns\n -------\n X_new : array of shape (n_samples, n_components)\n Embedding of the training data in low-dimensional space.\n \"\"\"\n self.fit_transform(X)\n return self\n" }, { "name": "ConfusionMatrixDisplay", @@ -24598,9 +24551,9 @@ "superclasses": ["MetaEstimatorMixin", "BaseEstimator"], "methods": [ "sklearn.model_selection._search.BaseSearchCV.__init__", - "sklearn.model_selection._search.BaseSearchCV._estimator_type", + "sklearn.model_selection._search.BaseSearchCV._estimator_type@getter", "sklearn.model_selection._search.BaseSearchCV._more_tags", - "sklearn.model_selection._search.BaseSearchCV._pairwise", + "sklearn.model_selection._search.BaseSearchCV._pairwise@getter", "sklearn.model_selection._search.BaseSearchCV.score", "sklearn.model_selection._search.BaseSearchCV.score_samples", "sklearn.model_selection._search.BaseSearchCV.predict", @@ -24609,8 +24562,8 @@ "sklearn.model_selection._search.BaseSearchCV.decision_function", "sklearn.model_selection._search.BaseSearchCV.transform", "sklearn.model_selection._search.BaseSearchCV.inverse_transform", - "sklearn.model_selection._search.BaseSearchCV.n_features_in_", - "sklearn.model_selection._search.BaseSearchCV.classes_", + "sklearn.model_selection._search.BaseSearchCV.n_features_in_@getter", + "sklearn.model_selection._search.BaseSearchCV.classes_@getter", "sklearn.model_selection._search.BaseSearchCV._run_search", "sklearn.model_selection._search.BaseSearchCV._check_refit_for_multimetric", "sklearn.model_selection._search.BaseSearchCV._select_best_index", @@ -24679,8 +24632,8 @@ ], "is_public": true, "description": "Randomized search on hyper parameters.\n\nRandomizedSearchCV implements a \"fit\" and a \"score\" method. It also implements \"score_samples\", \"predict\", \"predict_proba\", \"decision_function\", \"transform\" and \"inverse_transform\" if they are implemented in the estimator used. The parameters of the estimator used to apply these methods are optimized by cross-validated search over parameter settings. In contrast to GridSearchCV, not all parameter values are tried out, but rather a fixed number of parameter settings is sampled from the specified distributions. The number of parameter settings that are tried is given by n_iter. If all parameters are presented as a list, sampling without replacement is performed. If at least one parameter is given as a distribution, sampling with replacement is used. It is highly recommended to use continuous distributions for continuous parameters. Read more in the :ref:`User Guide `. .. versionadded:: 0.14", - "docstring": "Randomized search on hyper parameters.\n\n RandomizedSearchCV implements a \"fit\" and a \"score\" method.\n It also implements \"score_samples\", \"predict\", \"predict_proba\",\n \"decision_function\", \"transform\" and \"inverse_transform\" if they are\n implemented in the estimator used.\n\n The parameters of the estimator used to apply these methods are optimized\n by cross-validated search over parameter settings.\n\n In contrast to GridSearchCV, not all parameter values are tried out, but\n rather a fixed number of parameter settings is sampled from the specified\n distributions. The number of parameter settings that are tried is\n given by n_iter.\n\n If all parameters are presented as a list,\n sampling without replacement is performed. If at least one parameter\n is given as a distribution, sampling with replacement is used.\n It is highly recommended to use continuous distributions for continuous\n parameters.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.14\n\n Parameters\n ----------\n estimator : estimator object.\n A object of that type is instantiated for each grid point.\n This is assumed to implement the scikit-learn estimator interface.\n Either estimator needs to provide a ``score`` function,\n or ``scoring`` must be passed.\n\n param_distributions : dict or list of dicts\n Dictionary with parameters names (`str`) as keys and distributions\n or lists of parameters to try. Distributions must provide a ``rvs``\n method for sampling (such as those from scipy.stats.distributions).\n If a list is given, it is sampled uniformly.\n If a list of dicts is given, first a dict is sampled uniformly, and\n then a parameter is sampled using that dict as above.\n\n n_iter : int, default=10\n Number of parameter settings that are sampled. n_iter trades\n off runtime vs quality of the solution.\n\n scoring : str, callable, list, tuple or dict, default=None\n Strategy to evaluate the performance of the cross-validated model on\n the test set.\n\n If `scoring` represents a single score, one can use:\n\n - a single string (see :ref:`scoring_parameter`);\n - a callable (see :ref:`scoring`) that returns a single value.\n\n If `scoring` represents multiple scores, one can use:\n\n - a list or tuple of unique strings;\n - a callable returning a dictionary where the keys are the metric\n names and the values are the metric scores;\n - a dictionary with metric names as keys and callables a values.\n\n See :ref:`multimetric_grid_search` for an example.\n\n If None, the estimator's score method is used.\n\n n_jobs : int, default=None\n Number of jobs to run in parallel.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n .. versionchanged:: v0.20\n `n_jobs` default changed from 1 to None\n\n refit : bool, str, or callable, default=True\n Refit an estimator using the best found parameters on the whole\n dataset.\n\n For multiple metric evaluation, this needs to be a `str` denoting the\n scorer that would be used to find the best parameters for refitting\n the estimator at the end.\n\n Where there are considerations other than maximum score in\n choosing a best estimator, ``refit`` can be set to a function which\n returns the selected ``best_index_`` given the ``cv_results``. In that\n case, the ``best_estimator_`` and ``best_params_`` will be set\n according to the returned ``best_index_`` while the ``best_score_``\n attribute will not be available.\n\n The refitted estimator is made available at the ``best_estimator_``\n attribute and permits using ``predict`` directly on this\n ``RandomizedSearchCV`` instance.\n\n Also for multiple metric evaluation, the attributes ``best_index_``,\n ``best_score_`` and ``best_params_`` will only be available if\n ``refit`` is set and all of them will be determined w.r.t this specific\n scorer.\n\n See ``scoring`` parameter to know more about multiple metric\n evaluation.\n\n .. versionchanged:: 0.20\n Support for callable added.\n\n cv : int, cross-validation generator or an iterable, default=None\n Determines the cross-validation splitting strategy.\n Possible inputs for cv are:\n\n - None, to use the default 5-fold cross validation,\n - integer, to specify the number of folds in a `(Stratified)KFold`,\n - :term:`CV splitter`,\n - An iterable yielding (train, test) splits as arrays of indices.\n\n For integer/None inputs, if the estimator is a classifier and ``y`` is\n either binary or multiclass, :class:`StratifiedKFold` is used. In all\n other cases, :class:`KFold` is used. These splitters are instantiated\n with `shuffle=False` so the splits will be the same across calls.\n\n Refer :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n .. versionchanged:: 0.22\n ``cv`` default value if None changed from 3-fold to 5-fold.\n\n verbose : int\n Controls the verbosity: the higher, the more messages.\n\n pre_dispatch : int, or str, default='2*n_jobs'\n Controls the number of jobs that get dispatched during parallel\n execution. Reducing this number can be useful to avoid an\n explosion of memory consumption when more jobs get dispatched\n than CPUs can process. This parameter can be:\n\n - None, in which case all the jobs are immediately\n created and spawned. Use this for lightweight and\n fast-running jobs, to avoid delays due to on-demand\n spawning of the jobs\n\n - An int, giving the exact number of total jobs that are\n spawned\n\n - A str, giving an expression as a function of n_jobs,\n as in '2*n_jobs'\n\n random_state : int, RandomState instance or None, default=None\n Pseudo random number generator state used for random uniform sampling\n from lists of possible values instead of scipy.stats distributions.\n Pass an int for reproducible output across multiple\n function calls.\n See :term:`Glossary `.\n\n error_score : 'raise' or numeric, default=np.nan\n Value to assign to the score if an error occurs in estimator fitting.\n If set to 'raise', the error is raised. If a numeric value is given,\n FitFailedWarning is raised. This parameter does not affect the refit\n step, which will always raise the error.\n\n return_train_score : bool, default=False\n If ``False``, the ``cv_results_`` attribute will not include training\n scores.\n Computing training scores is used to get insights on how different\n parameter settings impact the overfitting/underfitting trade-off.\n However computing the scores on the training set can be computationally\n expensive and is not strictly required to select the parameters that\n yield the best generalization performance.\n\n .. versionadded:: 0.19\n\n .. versionchanged:: 0.21\n Default value was changed from ``True`` to ``False``\n\n Attributes\n ----------\n cv_results_ : dict of numpy (masked) ndarrays\n A dict with keys as column headers and values as columns, that can be\n imported into a pandas ``DataFrame``.\n\n For instance the below given table\n\n +--------------+-------------+-------------------+---+---------------+\n | param_kernel | param_gamma | split0_test_score |...|rank_test_score|\n +==============+=============+===================+===+===============+\n | 'rbf' | 0.1 | 0.80 |...| 1 |\n +--------------+-------------+-------------------+---+---------------+\n | 'rbf' | 0.2 | 0.84 |...| 3 |\n +--------------+-------------+-------------------+---+---------------+\n | 'rbf' | 0.3 | 0.70 |...| 2 |\n +--------------+-------------+-------------------+---+---------------+\n\n will be represented by a ``cv_results_`` dict of::\n\n {\n 'param_kernel' : masked_array(data = ['rbf', 'rbf', 'rbf'],\n mask = False),\n 'param_gamma' : masked_array(data = [0.1 0.2 0.3], mask = False),\n 'split0_test_score' : [0.80, 0.84, 0.70],\n 'split1_test_score' : [0.82, 0.50, 0.70],\n 'mean_test_score' : [0.81, 0.67, 0.70],\n 'std_test_score' : [0.01, 0.24, 0.00],\n 'rank_test_score' : [1, 3, 2],\n 'split0_train_score' : [0.80, 0.92, 0.70],\n 'split1_train_score' : [0.82, 0.55, 0.70],\n 'mean_train_score' : [0.81, 0.74, 0.70],\n 'std_train_score' : [0.01, 0.19, 0.00],\n 'mean_fit_time' : [0.73, 0.63, 0.43],\n 'std_fit_time' : [0.01, 0.02, 0.01],\n 'mean_score_time' : [0.01, 0.06, 0.04],\n 'std_score_time' : [0.00, 0.00, 0.00],\n 'params' : [{'kernel' : 'rbf', 'gamma' : 0.1}, ...],\n }\n\n NOTE\n\n The key ``'params'`` is used to store a list of parameter\n settings dicts for all the parameter candidates.\n\n The ``mean_fit_time``, ``std_fit_time``, ``mean_score_time`` and\n ``std_score_time`` are all in seconds.\n\n For multi-metric evaluation, the scores for all the scorers are\n available in the ``cv_results_`` dict at the keys ending with that\n scorer's name (``'_'``) instead of ``'_score'`` shown\n above. ('split0_test_precision', 'mean_train_precision' etc.)\n\n best_estimator_ : estimator\n Estimator that was chosen by the search, i.e. estimator\n which gave highest score (or smallest loss if specified)\n on the left out data. Not available if ``refit=False``.\n\n For multi-metric evaluation, this attribute is present only if\n ``refit`` is specified.\n\n See ``refit`` parameter for more information on allowed values.\n\n best_score_ : float\n Mean cross-validated score of the best_estimator.\n\n For multi-metric evaluation, this is not available if ``refit`` is\n ``False``. See ``refit`` parameter for more information.\n\n This attribute is not available if ``refit`` is a function.\n\n best_params_ : dict\n Parameter setting that gave the best results on the hold out data.\n\n For multi-metric evaluation, this is not available if ``refit`` is\n ``False``. See ``refit`` parameter for more information.\n\n best_index_ : int\n The index (of the ``cv_results_`` arrays) which corresponds to the best\n candidate parameter setting.\n\n The dict at ``search.cv_results_['params'][search.best_index_]`` gives\n the parameter setting for the best model, that gives the highest\n mean score (``search.best_score_``).\n\n For multi-metric evaluation, this is not available if ``refit`` is\n ``False``. See ``refit`` parameter for more information.\n\n scorer_ : function or a dict\n Scorer function used on the held out data to choose the best\n parameters for the model.\n\n For multi-metric evaluation, this attribute holds the validated\n ``scoring`` dict which maps the scorer key to the scorer callable.\n\n n_splits_ : int\n The number of cross-validation splits (folds/iterations).\n\n refit_time_ : float\n Seconds used for refitting the best model on the whole dataset.\n\n This is present only if ``refit`` is not False.\n\n .. versionadded:: 0.20\n\n multimetric_ : bool\n Whether or not the scorers compute several metrics.\n\n classes_ : ndarray of shape (n_classes,)\n The classes labels. This is present only if ``refit`` is specified and\n the underlying estimator is a classifier.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`. Only defined if\n `best_estimator_` is defined (see the documentation for the `refit`\n parameter for more details) and that `best_estimator_` exposes\n `n_features_in_` when fit.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Only defined if\n `best_estimator_` is defined (see the documentation for the `refit`\n parameter for more details) and that `best_estimator_` exposes\n `feature_names_in_` when fit.\n\n .. versionadded:: 1.0\n\n Notes\n -----\n The parameters selected are those that maximize the score of the held-out\n data, according to the scoring parameter.\n\n If `n_jobs` was set to a value higher than one, the data is copied for each\n parameter setting(and not `n_jobs` times). This is done for efficiency\n reasons if individual jobs take very little time, but may raise errors if\n the dataset is large and not enough memory is available. A workaround in\n this case is to set `pre_dispatch`. Then, the memory is copied only\n `pre_dispatch` many times. A reasonable value for `pre_dispatch` is `2 *\n n_jobs`.\n\n See Also\n --------\n GridSearchCV : Does exhaustive search over a grid of parameters.\n ParameterSampler : A generator over parameter settings, constructed from\n param_distributions.\n\n Examples\n --------\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.linear_model import LogisticRegression\n >>> from sklearn.model_selection import RandomizedSearchCV\n >>> from scipy.stats import uniform\n >>> iris = load_iris()\n >>> logistic = LogisticRegression(solver='saga', tol=1e-2, max_iter=200,\n ... random_state=0)\n >>> distributions = dict(C=uniform(loc=0, scale=4),\n ... penalty=['l2', 'l1'])\n >>> clf = RandomizedSearchCV(logistic, distributions, random_state=0)\n >>> search = clf.fit(iris.data, iris.target)\n >>> search.best_params_\n {'C': 2..., 'penalty': 'l1'}\n ", - "source_code": "\n\nclass RandomizedSearchCV(BaseSearchCV):\n \"\"\"Randomized search on hyper parameters.\n\n RandomizedSearchCV implements a \"fit\" and a \"score\" method.\n It also implements \"score_samples\", \"predict\", \"predict_proba\",\n \"decision_function\", \"transform\" and \"inverse_transform\" if they are\n implemented in the estimator used.\n\n The parameters of the estimator used to apply these methods are optimized\n by cross-validated search over parameter settings.\n\n In contrast to GridSearchCV, not all parameter values are tried out, but\n rather a fixed number of parameter settings is sampled from the specified\n distributions. The number of parameter settings that are tried is\n given by n_iter.\n\n If all parameters are presented as a list,\n sampling without replacement is performed. If at least one parameter\n is given as a distribution, sampling with replacement is used.\n It is highly recommended to use continuous distributions for continuous\n parameters.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.14\n\n Parameters\n ----------\n estimator : estimator object.\n A object of that type is instantiated for each grid point.\n This is assumed to implement the scikit-learn estimator interface.\n Either estimator needs to provide a ``score`` function,\n or ``scoring`` must be passed.\n\n param_distributions : dict or list of dicts\n Dictionary with parameters names (`str`) as keys and distributions\n or lists of parameters to try. Distributions must provide a ``rvs``\n method for sampling (such as those from scipy.stats.distributions).\n If a list is given, it is sampled uniformly.\n If a list of dicts is given, first a dict is sampled uniformly, and\n then a parameter is sampled using that dict as above.\n\n n_iter : int, default=10\n Number of parameter settings that are sampled. n_iter trades\n off runtime vs quality of the solution.\n\n scoring : str, callable, list, tuple or dict, default=None\n Strategy to evaluate the performance of the cross-validated model on\n the test set.\n\n If `scoring` represents a single score, one can use:\n\n - a single string (see :ref:`scoring_parameter`);\n - a callable (see :ref:`scoring`) that returns a single value.\n\n If `scoring` represents multiple scores, one can use:\n\n - a list or tuple of unique strings;\n - a callable returning a dictionary where the keys are the metric\n names and the values are the metric scores;\n - a dictionary with metric names as keys and callables a values.\n\n See :ref:`multimetric_grid_search` for an example.\n\n If None, the estimator's score method is used.\n\n n_jobs : int, default=None\n Number of jobs to run in parallel.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n .. versionchanged:: v0.20\n `n_jobs` default changed from 1 to None\n\n refit : bool, str, or callable, default=True\n Refit an estimator using the best found parameters on the whole\n dataset.\n\n For multiple metric evaluation, this needs to be a `str` denoting the\n scorer that would be used to find the best parameters for refitting\n the estimator at the end.\n\n Where there are considerations other than maximum score in\n choosing a best estimator, ``refit`` can be set to a function which\n returns the selected ``best_index_`` given the ``cv_results``. In that\n case, the ``best_estimator_`` and ``best_params_`` will be set\n according to the returned ``best_index_`` while the ``best_score_``\n attribute will not be available.\n\n The refitted estimator is made available at the ``best_estimator_``\n attribute and permits using ``predict`` directly on this\n ``RandomizedSearchCV`` instance.\n\n Also for multiple metric evaluation, the attributes ``best_index_``,\n ``best_score_`` and ``best_params_`` will only be available if\n ``refit`` is set and all of them will be determined w.r.t this specific\n scorer.\n\n See ``scoring`` parameter to know more about multiple metric\n evaluation.\n\n .. versionchanged:: 0.20\n Support for callable added.\n\n cv : int, cross-validation generator or an iterable, default=None\n Determines the cross-validation splitting strategy.\n Possible inputs for cv are:\n\n - None, to use the default 5-fold cross validation,\n - integer, to specify the number of folds in a `(Stratified)KFold`,\n - :term:`CV splitter`,\n - An iterable yielding (train, test) splits as arrays of indices.\n\n For integer/None inputs, if the estimator is a classifier and ``y`` is\n either binary or multiclass, :class:`StratifiedKFold` is used. In all\n other cases, :class:`KFold` is used. These splitters are instantiated\n with `shuffle=False` so the splits will be the same across calls.\n\n Refer :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n .. versionchanged:: 0.22\n ``cv`` default value if None changed from 3-fold to 5-fold.\n\n verbose : int\n Controls the verbosity: the higher, the more messages.\n\n pre_dispatch : int, or str, default='2*n_jobs'\n Controls the number of jobs that get dispatched during parallel\n execution. Reducing this number can be useful to avoid an\n explosion of memory consumption when more jobs get dispatched\n than CPUs can process. This parameter can be:\n\n - None, in which case all the jobs are immediately\n created and spawned. Use this for lightweight and\n fast-running jobs, to avoid delays due to on-demand\n spawning of the jobs\n\n - An int, giving the exact number of total jobs that are\n spawned\n\n - A str, giving an expression as a function of n_jobs,\n as in '2*n_jobs'\n\n random_state : int, RandomState instance or None, default=None\n Pseudo random number generator state used for random uniform sampling\n from lists of possible values instead of scipy.stats distributions.\n Pass an int for reproducible output across multiple\n function calls.\n See :term:`Glossary `.\n\n error_score : 'raise' or numeric, default=np.nan\n Value to assign to the score if an error occurs in estimator fitting.\n If set to 'raise', the error is raised. If a numeric value is given,\n FitFailedWarning is raised. This parameter does not affect the refit\n step, which will always raise the error.\n\n return_train_score : bool, default=False\n If ``False``, the ``cv_results_`` attribute will not include training\n scores.\n Computing training scores is used to get insights on how different\n parameter settings impact the overfitting/underfitting trade-off.\n However computing the scores on the training set can be computationally\n expensive and is not strictly required to select the parameters that\n yield the best generalization performance.\n\n .. versionadded:: 0.19\n\n .. versionchanged:: 0.21\n Default value was changed from ``True`` to ``False``\n\n Attributes\n ----------\n cv_results_ : dict of numpy (masked) ndarrays\n A dict with keys as column headers and values as columns, that can be\n imported into a pandas ``DataFrame``.\n\n For instance the below given table\n\n +--------------+-------------+-------------------+---+---------------+\n | param_kernel | param_gamma | split0_test_score |...|rank_test_score|\n +==============+=============+===================+===+===============+\n | 'rbf' | 0.1 | 0.80 |...| 1 |\n +--------------+-------------+-------------------+---+---------------+\n | 'rbf' | 0.2 | 0.84 |...| 3 |\n +--------------+-------------+-------------------+---+---------------+\n | 'rbf' | 0.3 | 0.70 |...| 2 |\n +--------------+-------------+-------------------+---+---------------+\n\n will be represented by a ``cv_results_`` dict of::\n\n {\n 'param_kernel' : masked_array(data = ['rbf', 'rbf', 'rbf'],\n mask = False),\n 'param_gamma' : masked_array(data = [0.1 0.2 0.3], mask = False),\n 'split0_test_score' : [0.80, 0.84, 0.70],\n 'split1_test_score' : [0.82, 0.50, 0.70],\n 'mean_test_score' : [0.81, 0.67, 0.70],\n 'std_test_score' : [0.01, 0.24, 0.00],\n 'rank_test_score' : [1, 3, 2],\n 'split0_train_score' : [0.80, 0.92, 0.70],\n 'split1_train_score' : [0.82, 0.55, 0.70],\n 'mean_train_score' : [0.81, 0.74, 0.70],\n 'std_train_score' : [0.01, 0.19, 0.00],\n 'mean_fit_time' : [0.73, 0.63, 0.43],\n 'std_fit_time' : [0.01, 0.02, 0.01],\n 'mean_score_time' : [0.01, 0.06, 0.04],\n 'std_score_time' : [0.00, 0.00, 0.00],\n 'params' : [{'kernel' : 'rbf', 'gamma' : 0.1}, ...],\n }\n\n NOTE\n\n The key ``'params'`` is used to store a list of parameter\n settings dicts for all the parameter candidates.\n\n The ``mean_fit_time``, ``std_fit_time``, ``mean_score_time`` and\n ``std_score_time`` are all in seconds.\n\n For multi-metric evaluation, the scores for all the scorers are\n available in the ``cv_results_`` dict at the keys ending with that\n scorer's name (``'_'``) instead of ``'_score'`` shown\n above. ('split0_test_precision', 'mean_train_precision' etc.)\n\n best_estimator_ : estimator\n Estimator that was chosen by the search, i.e. estimator\n which gave highest score (or smallest loss if specified)\n on the left out data. Not available if ``refit=False``.\n\n For multi-metric evaluation, this attribute is present only if\n ``refit`` is specified.\n\n See ``refit`` parameter for more information on allowed values.\n\n best_score_ : float\n Mean cross-validated score of the best_estimator.\n\n For multi-metric evaluation, this is not available if ``refit`` is\n ``False``. See ``refit`` parameter for more information.\n\n This attribute is not available if ``refit`` is a function.\n\n best_params_ : dict\n Parameter setting that gave the best results on the hold out data.\n\n For multi-metric evaluation, this is not available if ``refit`` is\n ``False``. See ``refit`` parameter for more information.\n\n best_index_ : int\n The index (of the ``cv_results_`` arrays) which corresponds to the best\n candidate parameter setting.\n\n The dict at ``search.cv_results_['params'][search.best_index_]`` gives\n the parameter setting for the best model, that gives the highest\n mean score (``search.best_score_``).\n\n For multi-metric evaluation, this is not available if ``refit`` is\n ``False``. See ``refit`` parameter for more information.\n\n scorer_ : function or a dict\n Scorer function used on the held out data to choose the best\n parameters for the model.\n\n For multi-metric evaluation, this attribute holds the validated\n ``scoring`` dict which maps the scorer key to the scorer callable.\n\n n_splits_ : int\n The number of cross-validation splits (folds/iterations).\n\n refit_time_ : float\n Seconds used for refitting the best model on the whole dataset.\n\n This is present only if ``refit`` is not False.\n\n .. versionadded:: 0.20\n\n multimetric_ : bool\n Whether or not the scorers compute several metrics.\n\n classes_ : ndarray of shape (n_classes,)\n The classes labels. This is present only if ``refit`` is specified and\n the underlying estimator is a classifier.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`. Only defined if\n `best_estimator_` is defined (see the documentation for the `refit`\n parameter for more details) and that `best_estimator_` exposes\n `n_features_in_` when fit.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Only defined if\n `best_estimator_` is defined (see the documentation for the `refit`\n parameter for more details) and that `best_estimator_` exposes\n `feature_names_in_` when fit.\n\n .. versionadded:: 1.0\n\n Notes\n -----\n The parameters selected are those that maximize the score of the held-out\n data, according to the scoring parameter.\n\n If `n_jobs` was set to a value higher than one, the data is copied for each\n parameter setting(and not `n_jobs` times). This is done for efficiency\n reasons if individual jobs take very little time, but may raise errors if\n the dataset is large and not enough memory is available. A workaround in\n this case is to set `pre_dispatch`. Then, the memory is copied only\n `pre_dispatch` many times. A reasonable value for `pre_dispatch` is `2 *\n n_jobs`.\n\n See Also\n --------\n GridSearchCV : Does exhaustive search over a grid of parameters.\n ParameterSampler : A generator over parameter settings, constructed from\n param_distributions.\n\n Examples\n --------\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.linear_model import LogisticRegression\n >>> from sklearn.model_selection import RandomizedSearchCV\n >>> from scipy.stats import uniform\n >>> iris = load_iris()\n >>> logistic = LogisticRegression(solver='saga', tol=1e-2, max_iter=200,\n ... random_state=0)\n >>> distributions = dict(C=uniform(loc=0, scale=4),\n ... penalty=['l2', 'l1'])\n >>> clf = RandomizedSearchCV(logistic, distributions, random_state=0)\n >>> search = clf.fit(iris.data, iris.target)\n >>> search.best_params_\n {'C': 2..., 'penalty': 'l1'}\n \"\"\"\n _required_parameters = ['estimator', 'param_distributions']\n \n def __init__(self, estimator, param_distributions, *, n_iter=10, scoring=None, n_jobs=None, refit=True, cv=None, verbose=0, pre_dispatch='2*n_jobs', random_state=None, error_score=np.nan, return_train_score=False):\n self.param_distributions = param_distributions\n self.n_iter = n_iter\n self.random_state = random_state\n super().__init__(estimator=estimator, scoring=scoring, n_jobs=n_jobs, refit=refit, cv=cv, verbose=verbose, pre_dispatch=pre_dispatch, error_score=error_score, return_train_score=return_train_score)\n \n def _run_search(self, evaluate_candidates):\n \"\"\"Search n_iter candidates from param_distributions\"\"\"\n evaluate_candidates(ParameterSampler(self.param_distributions, self.n_iter, random_state=self.random_state))\n" + "docstring": "Randomized search on hyper parameters.\n\n RandomizedSearchCV implements a \"fit\" and a \"score\" method.\n It also implements \"score_samples\", \"predict\", \"predict_proba\",\n \"decision_function\", \"transform\" and \"inverse_transform\" if they are\n implemented in the estimator used.\n\n The parameters of the estimator used to apply these methods are optimized\n by cross-validated search over parameter settings.\n\n In contrast to GridSearchCV, not all parameter values are tried out, but\n rather a fixed number of parameter settings is sampled from the specified\n distributions. The number of parameter settings that are tried is\n given by n_iter.\n\n If all parameters are presented as a list,\n sampling without replacement is performed. If at least one parameter\n is given as a distribution, sampling with replacement is used.\n It is highly recommended to use continuous distributions for continuous\n parameters.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.14\n\n Parameters\n ----------\n estimator : estimator object\n A object of that type is instantiated for each grid point.\n This is assumed to implement the scikit-learn estimator interface.\n Either estimator needs to provide a ``score`` function,\n or ``scoring`` must be passed.\n\n param_distributions : dict or list of dicts\n Dictionary with parameters names (`str`) as keys and distributions\n or lists of parameters to try. Distributions must provide a ``rvs``\n method for sampling (such as those from scipy.stats.distributions).\n If a list is given, it is sampled uniformly.\n If a list of dicts is given, first a dict is sampled uniformly, and\n then a parameter is sampled using that dict as above.\n\n n_iter : int, default=10\n Number of parameter settings that are sampled. n_iter trades\n off runtime vs quality of the solution.\n\n scoring : str, callable, list, tuple or dict, default=None\n Strategy to evaluate the performance of the cross-validated model on\n the test set.\n\n If `scoring` represents a single score, one can use:\n\n - a single string (see :ref:`scoring_parameter`);\n - a callable (see :ref:`scoring`) that returns a single value.\n\n If `scoring` represents multiple scores, one can use:\n\n - a list or tuple of unique strings;\n - a callable returning a dictionary where the keys are the metric\n names and the values are the metric scores;\n - a dictionary with metric names as keys and callables a values.\n\n See :ref:`multimetric_grid_search` for an example.\n\n If None, the estimator's score method is used.\n\n n_jobs : int, default=None\n Number of jobs to run in parallel.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n .. versionchanged:: v0.20\n `n_jobs` default changed from 1 to None\n\n refit : bool, str, or callable, default=True\n Refit an estimator using the best found parameters on the whole\n dataset.\n\n For multiple metric evaluation, this needs to be a `str` denoting the\n scorer that would be used to find the best parameters for refitting\n the estimator at the end.\n\n Where there are considerations other than maximum score in\n choosing a best estimator, ``refit`` can be set to a function which\n returns the selected ``best_index_`` given the ``cv_results``. In that\n case, the ``best_estimator_`` and ``best_params_`` will be set\n according to the returned ``best_index_`` while the ``best_score_``\n attribute will not be available.\n\n The refitted estimator is made available at the ``best_estimator_``\n attribute and permits using ``predict`` directly on this\n ``RandomizedSearchCV`` instance.\n\n Also for multiple metric evaluation, the attributes ``best_index_``,\n ``best_score_`` and ``best_params_`` will only be available if\n ``refit`` is set and all of them will be determined w.r.t this specific\n scorer.\n\n See ``scoring`` parameter to know more about multiple metric\n evaluation.\n\n .. versionchanged:: 0.20\n Support for callable added.\n\n cv : int, cross-validation generator or an iterable, default=None\n Determines the cross-validation splitting strategy.\n Possible inputs for cv are:\n\n - None, to use the default 5-fold cross validation,\n - integer, to specify the number of folds in a `(Stratified)KFold`,\n - :term:`CV splitter`,\n - An iterable yielding (train, test) splits as arrays of indices.\n\n For integer/None inputs, if the estimator is a classifier and ``y`` is\n either binary or multiclass, :class:`StratifiedKFold` is used. In all\n other cases, :class:`KFold` is used. These splitters are instantiated\n with `shuffle=False` so the splits will be the same across calls.\n\n Refer :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n .. versionchanged:: 0.22\n ``cv`` default value if None changed from 3-fold to 5-fold.\n\n verbose : int\n Controls the verbosity: the higher, the more messages.\n\n pre_dispatch : int, or str, default='2*n_jobs'\n Controls the number of jobs that get dispatched during parallel\n execution. Reducing this number can be useful to avoid an\n explosion of memory consumption when more jobs get dispatched\n than CPUs can process. This parameter can be:\n\n - None, in which case all the jobs are immediately\n created and spawned. Use this for lightweight and\n fast-running jobs, to avoid delays due to on-demand\n spawning of the jobs\n\n - An int, giving the exact number of total jobs that are\n spawned\n\n - A str, giving an expression as a function of n_jobs,\n as in '2*n_jobs'\n\n random_state : int, RandomState instance or None, default=None\n Pseudo random number generator state used for random uniform sampling\n from lists of possible values instead of scipy.stats distributions.\n Pass an int for reproducible output across multiple\n function calls.\n See :term:`Glossary `.\n\n error_score : 'raise' or numeric, default=np.nan\n Value to assign to the score if an error occurs in estimator fitting.\n If set to 'raise', the error is raised. If a numeric value is given,\n FitFailedWarning is raised. This parameter does not affect the refit\n step, which will always raise the error.\n\n return_train_score : bool, default=False\n If ``False``, the ``cv_results_`` attribute will not include training\n scores.\n Computing training scores is used to get insights on how different\n parameter settings impact the overfitting/underfitting trade-off.\n However computing the scores on the training set can be computationally\n expensive and is not strictly required to select the parameters that\n yield the best generalization performance.\n\n .. versionadded:: 0.19\n\n .. versionchanged:: 0.21\n Default value was changed from ``True`` to ``False``\n\n Attributes\n ----------\n cv_results_ : dict of numpy (masked) ndarrays\n A dict with keys as column headers and values as columns, that can be\n imported into a pandas ``DataFrame``.\n\n For instance the below given table\n\n +--------------+-------------+-------------------+---+---------------+\n | param_kernel | param_gamma | split0_test_score |...|rank_test_score|\n +==============+=============+===================+===+===============+\n | 'rbf' | 0.1 | 0.80 |...| 1 |\n +--------------+-------------+-------------------+---+---------------+\n | 'rbf' | 0.2 | 0.84 |...| 3 |\n +--------------+-------------+-------------------+---+---------------+\n | 'rbf' | 0.3 | 0.70 |...| 2 |\n +--------------+-------------+-------------------+---+---------------+\n\n will be represented by a ``cv_results_`` dict of::\n\n {\n 'param_kernel' : masked_array(data = ['rbf', 'rbf', 'rbf'],\n mask = False),\n 'param_gamma' : masked_array(data = [0.1 0.2 0.3], mask = False),\n 'split0_test_score' : [0.80, 0.84, 0.70],\n 'split1_test_score' : [0.82, 0.50, 0.70],\n 'mean_test_score' : [0.81, 0.67, 0.70],\n 'std_test_score' : [0.01, 0.24, 0.00],\n 'rank_test_score' : [1, 3, 2],\n 'split0_train_score' : [0.80, 0.92, 0.70],\n 'split1_train_score' : [0.82, 0.55, 0.70],\n 'mean_train_score' : [0.81, 0.74, 0.70],\n 'std_train_score' : [0.01, 0.19, 0.00],\n 'mean_fit_time' : [0.73, 0.63, 0.43],\n 'std_fit_time' : [0.01, 0.02, 0.01],\n 'mean_score_time' : [0.01, 0.06, 0.04],\n 'std_score_time' : [0.00, 0.00, 0.00],\n 'params' : [{'kernel' : 'rbf', 'gamma' : 0.1}, ...],\n }\n\n NOTE\n\n The key ``'params'`` is used to store a list of parameter\n settings dicts for all the parameter candidates.\n\n The ``mean_fit_time``, ``std_fit_time``, ``mean_score_time`` and\n ``std_score_time`` are all in seconds.\n\n For multi-metric evaluation, the scores for all the scorers are\n available in the ``cv_results_`` dict at the keys ending with that\n scorer's name (``'_'``) instead of ``'_score'`` shown\n above. ('split0_test_precision', 'mean_train_precision' etc.)\n\n best_estimator_ : estimator\n Estimator that was chosen by the search, i.e. estimator\n which gave highest score (or smallest loss if specified)\n on the left out data. Not available if ``refit=False``.\n\n For multi-metric evaluation, this attribute is present only if\n ``refit`` is specified.\n\n See ``refit`` parameter for more information on allowed values.\n\n best_score_ : float\n Mean cross-validated score of the best_estimator.\n\n For multi-metric evaluation, this is not available if ``refit`` is\n ``False``. See ``refit`` parameter for more information.\n\n This attribute is not available if ``refit`` is a function.\n\n best_params_ : dict\n Parameter setting that gave the best results on the hold out data.\n\n For multi-metric evaluation, this is not available if ``refit`` is\n ``False``. See ``refit`` parameter for more information.\n\n best_index_ : int\n The index (of the ``cv_results_`` arrays) which corresponds to the best\n candidate parameter setting.\n\n The dict at ``search.cv_results_['params'][search.best_index_]`` gives\n the parameter setting for the best model, that gives the highest\n mean score (``search.best_score_``).\n\n For multi-metric evaluation, this is not available if ``refit`` is\n ``False``. See ``refit`` parameter for more information.\n\n scorer_ : function or a dict\n Scorer function used on the held out data to choose the best\n parameters for the model.\n\n For multi-metric evaluation, this attribute holds the validated\n ``scoring`` dict which maps the scorer key to the scorer callable.\n\n n_splits_ : int\n The number of cross-validation splits (folds/iterations).\n\n refit_time_ : float\n Seconds used for refitting the best model on the whole dataset.\n\n This is present only if ``refit`` is not False.\n\n .. versionadded:: 0.20\n\n multimetric_ : bool\n Whether or not the scorers compute several metrics.\n\n classes_ : ndarray of shape (n_classes,)\n The classes labels. This is present only if ``refit`` is specified and\n the underlying estimator is a classifier.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`. Only defined if\n `best_estimator_` is defined (see the documentation for the `refit`\n parameter for more details) and that `best_estimator_` exposes\n `n_features_in_` when fit.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Only defined if\n `best_estimator_` is defined (see the documentation for the `refit`\n parameter for more details) and that `best_estimator_` exposes\n `feature_names_in_` when fit.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n GridSearchCV : Does exhaustive search over a grid of parameters.\n ParameterSampler : A generator over parameter settings, constructed from\n param_distributions.\n\n Notes\n -----\n The parameters selected are those that maximize the score of the held-out\n data, according to the scoring parameter.\n\n If `n_jobs` was set to a value higher than one, the data is copied for each\n parameter setting(and not `n_jobs` times). This is done for efficiency\n reasons if individual jobs take very little time, but may raise errors if\n the dataset is large and not enough memory is available. A workaround in\n this case is to set `pre_dispatch`. Then, the memory is copied only\n `pre_dispatch` many times. A reasonable value for `pre_dispatch` is `2 *\n n_jobs`.\n\n Examples\n --------\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.linear_model import LogisticRegression\n >>> from sklearn.model_selection import RandomizedSearchCV\n >>> from scipy.stats import uniform\n >>> iris = load_iris()\n >>> logistic = LogisticRegression(solver='saga', tol=1e-2, max_iter=200,\n ... random_state=0)\n >>> distributions = dict(C=uniform(loc=0, scale=4),\n ... penalty=['l2', 'l1'])\n >>> clf = RandomizedSearchCV(logistic, distributions, random_state=0)\n >>> search = clf.fit(iris.data, iris.target)\n >>> search.best_params_\n {'C': 2..., 'penalty': 'l1'}\n ", + "source_code": "\n\nclass RandomizedSearchCV(BaseSearchCV):\n \"\"\"Randomized search on hyper parameters.\n\n RandomizedSearchCV implements a \"fit\" and a \"score\" method.\n It also implements \"score_samples\", \"predict\", \"predict_proba\",\n \"decision_function\", \"transform\" and \"inverse_transform\" if they are\n implemented in the estimator used.\n\n The parameters of the estimator used to apply these methods are optimized\n by cross-validated search over parameter settings.\n\n In contrast to GridSearchCV, not all parameter values are tried out, but\n rather a fixed number of parameter settings is sampled from the specified\n distributions. The number of parameter settings that are tried is\n given by n_iter.\n\n If all parameters are presented as a list,\n sampling without replacement is performed. If at least one parameter\n is given as a distribution, sampling with replacement is used.\n It is highly recommended to use continuous distributions for continuous\n parameters.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.14\n\n Parameters\n ----------\n estimator : estimator object\n A object of that type is instantiated for each grid point.\n This is assumed to implement the scikit-learn estimator interface.\n Either estimator needs to provide a ``score`` function,\n or ``scoring`` must be passed.\n\n param_distributions : dict or list of dicts\n Dictionary with parameters names (`str`) as keys and distributions\n or lists of parameters to try. Distributions must provide a ``rvs``\n method for sampling (such as those from scipy.stats.distributions).\n If a list is given, it is sampled uniformly.\n If a list of dicts is given, first a dict is sampled uniformly, and\n then a parameter is sampled using that dict as above.\n\n n_iter : int, default=10\n Number of parameter settings that are sampled. n_iter trades\n off runtime vs quality of the solution.\n\n scoring : str, callable, list, tuple or dict, default=None\n Strategy to evaluate the performance of the cross-validated model on\n the test set.\n\n If `scoring` represents a single score, one can use:\n\n - a single string (see :ref:`scoring_parameter`);\n - a callable (see :ref:`scoring`) that returns a single value.\n\n If `scoring` represents multiple scores, one can use:\n\n - a list or tuple of unique strings;\n - a callable returning a dictionary where the keys are the metric\n names and the values are the metric scores;\n - a dictionary with metric names as keys and callables a values.\n\n See :ref:`multimetric_grid_search` for an example.\n\n If None, the estimator's score method is used.\n\n n_jobs : int, default=None\n Number of jobs to run in parallel.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n .. versionchanged:: v0.20\n `n_jobs` default changed from 1 to None\n\n refit : bool, str, or callable, default=True\n Refit an estimator using the best found parameters on the whole\n dataset.\n\n For multiple metric evaluation, this needs to be a `str` denoting the\n scorer that would be used to find the best parameters for refitting\n the estimator at the end.\n\n Where there are considerations other than maximum score in\n choosing a best estimator, ``refit`` can be set to a function which\n returns the selected ``best_index_`` given the ``cv_results``. In that\n case, the ``best_estimator_`` and ``best_params_`` will be set\n according to the returned ``best_index_`` while the ``best_score_``\n attribute will not be available.\n\n The refitted estimator is made available at the ``best_estimator_``\n attribute and permits using ``predict`` directly on this\n ``RandomizedSearchCV`` instance.\n\n Also for multiple metric evaluation, the attributes ``best_index_``,\n ``best_score_`` and ``best_params_`` will only be available if\n ``refit`` is set and all of them will be determined w.r.t this specific\n scorer.\n\n See ``scoring`` parameter to know more about multiple metric\n evaluation.\n\n .. versionchanged:: 0.20\n Support for callable added.\n\n cv : int, cross-validation generator or an iterable, default=None\n Determines the cross-validation splitting strategy.\n Possible inputs for cv are:\n\n - None, to use the default 5-fold cross validation,\n - integer, to specify the number of folds in a `(Stratified)KFold`,\n - :term:`CV splitter`,\n - An iterable yielding (train, test) splits as arrays of indices.\n\n For integer/None inputs, if the estimator is a classifier and ``y`` is\n either binary or multiclass, :class:`StratifiedKFold` is used. In all\n other cases, :class:`KFold` is used. These splitters are instantiated\n with `shuffle=False` so the splits will be the same across calls.\n\n Refer :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n .. versionchanged:: 0.22\n ``cv`` default value if None changed from 3-fold to 5-fold.\n\n verbose : int\n Controls the verbosity: the higher, the more messages.\n\n pre_dispatch : int, or str, default='2*n_jobs'\n Controls the number of jobs that get dispatched during parallel\n execution. Reducing this number can be useful to avoid an\n explosion of memory consumption when more jobs get dispatched\n than CPUs can process. This parameter can be:\n\n - None, in which case all the jobs are immediately\n created and spawned. Use this for lightweight and\n fast-running jobs, to avoid delays due to on-demand\n spawning of the jobs\n\n - An int, giving the exact number of total jobs that are\n spawned\n\n - A str, giving an expression as a function of n_jobs,\n as in '2*n_jobs'\n\n random_state : int, RandomState instance or None, default=None\n Pseudo random number generator state used for random uniform sampling\n from lists of possible values instead of scipy.stats distributions.\n Pass an int for reproducible output across multiple\n function calls.\n See :term:`Glossary `.\n\n error_score : 'raise' or numeric, default=np.nan\n Value to assign to the score if an error occurs in estimator fitting.\n If set to 'raise', the error is raised. If a numeric value is given,\n FitFailedWarning is raised. This parameter does not affect the refit\n step, which will always raise the error.\n\n return_train_score : bool, default=False\n If ``False``, the ``cv_results_`` attribute will not include training\n scores.\n Computing training scores is used to get insights on how different\n parameter settings impact the overfitting/underfitting trade-off.\n However computing the scores on the training set can be computationally\n expensive and is not strictly required to select the parameters that\n yield the best generalization performance.\n\n .. versionadded:: 0.19\n\n .. versionchanged:: 0.21\n Default value was changed from ``True`` to ``False``\n\n Attributes\n ----------\n cv_results_ : dict of numpy (masked) ndarrays\n A dict with keys as column headers and values as columns, that can be\n imported into a pandas ``DataFrame``.\n\n For instance the below given table\n\n +--------------+-------------+-------------------+---+---------------+\n | param_kernel | param_gamma | split0_test_score |...|rank_test_score|\n +==============+=============+===================+===+===============+\n | 'rbf' | 0.1 | 0.80 |...| 1 |\n +--------------+-------------+-------------------+---+---------------+\n | 'rbf' | 0.2 | 0.84 |...| 3 |\n +--------------+-------------+-------------------+---+---------------+\n | 'rbf' | 0.3 | 0.70 |...| 2 |\n +--------------+-------------+-------------------+---+---------------+\n\n will be represented by a ``cv_results_`` dict of::\n\n {\n 'param_kernel' : masked_array(data = ['rbf', 'rbf', 'rbf'],\n mask = False),\n 'param_gamma' : masked_array(data = [0.1 0.2 0.3], mask = False),\n 'split0_test_score' : [0.80, 0.84, 0.70],\n 'split1_test_score' : [0.82, 0.50, 0.70],\n 'mean_test_score' : [0.81, 0.67, 0.70],\n 'std_test_score' : [0.01, 0.24, 0.00],\n 'rank_test_score' : [1, 3, 2],\n 'split0_train_score' : [0.80, 0.92, 0.70],\n 'split1_train_score' : [0.82, 0.55, 0.70],\n 'mean_train_score' : [0.81, 0.74, 0.70],\n 'std_train_score' : [0.01, 0.19, 0.00],\n 'mean_fit_time' : [0.73, 0.63, 0.43],\n 'std_fit_time' : [0.01, 0.02, 0.01],\n 'mean_score_time' : [0.01, 0.06, 0.04],\n 'std_score_time' : [0.00, 0.00, 0.00],\n 'params' : [{'kernel' : 'rbf', 'gamma' : 0.1}, ...],\n }\n\n NOTE\n\n The key ``'params'`` is used to store a list of parameter\n settings dicts for all the parameter candidates.\n\n The ``mean_fit_time``, ``std_fit_time``, ``mean_score_time`` and\n ``std_score_time`` are all in seconds.\n\n For multi-metric evaluation, the scores for all the scorers are\n available in the ``cv_results_`` dict at the keys ending with that\n scorer's name (``'_'``) instead of ``'_score'`` shown\n above. ('split0_test_precision', 'mean_train_precision' etc.)\n\n best_estimator_ : estimator\n Estimator that was chosen by the search, i.e. estimator\n which gave highest score (or smallest loss if specified)\n on the left out data. Not available if ``refit=False``.\n\n For multi-metric evaluation, this attribute is present only if\n ``refit`` is specified.\n\n See ``refit`` parameter for more information on allowed values.\n\n best_score_ : float\n Mean cross-validated score of the best_estimator.\n\n For multi-metric evaluation, this is not available if ``refit`` is\n ``False``. See ``refit`` parameter for more information.\n\n This attribute is not available if ``refit`` is a function.\n\n best_params_ : dict\n Parameter setting that gave the best results on the hold out data.\n\n For multi-metric evaluation, this is not available if ``refit`` is\n ``False``. See ``refit`` parameter for more information.\n\n best_index_ : int\n The index (of the ``cv_results_`` arrays) which corresponds to the best\n candidate parameter setting.\n\n The dict at ``search.cv_results_['params'][search.best_index_]`` gives\n the parameter setting for the best model, that gives the highest\n mean score (``search.best_score_``).\n\n For multi-metric evaluation, this is not available if ``refit`` is\n ``False``. See ``refit`` parameter for more information.\n\n scorer_ : function or a dict\n Scorer function used on the held out data to choose the best\n parameters for the model.\n\n For multi-metric evaluation, this attribute holds the validated\n ``scoring`` dict which maps the scorer key to the scorer callable.\n\n n_splits_ : int\n The number of cross-validation splits (folds/iterations).\n\n refit_time_ : float\n Seconds used for refitting the best model on the whole dataset.\n\n This is present only if ``refit`` is not False.\n\n .. versionadded:: 0.20\n\n multimetric_ : bool\n Whether or not the scorers compute several metrics.\n\n classes_ : ndarray of shape (n_classes,)\n The classes labels. This is present only if ``refit`` is specified and\n the underlying estimator is a classifier.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`. Only defined if\n `best_estimator_` is defined (see the documentation for the `refit`\n parameter for more details) and that `best_estimator_` exposes\n `n_features_in_` when fit.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Only defined if\n `best_estimator_` is defined (see the documentation for the `refit`\n parameter for more details) and that `best_estimator_` exposes\n `feature_names_in_` when fit.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n GridSearchCV : Does exhaustive search over a grid of parameters.\n ParameterSampler : A generator over parameter settings, constructed from\n param_distributions.\n\n Notes\n -----\n The parameters selected are those that maximize the score of the held-out\n data, according to the scoring parameter.\n\n If `n_jobs` was set to a value higher than one, the data is copied for each\n parameter setting(and not `n_jobs` times). This is done for efficiency\n reasons if individual jobs take very little time, but may raise errors if\n the dataset is large and not enough memory is available. A workaround in\n this case is to set `pre_dispatch`. Then, the memory is copied only\n `pre_dispatch` many times. A reasonable value for `pre_dispatch` is `2 *\n n_jobs`.\n\n Examples\n --------\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.linear_model import LogisticRegression\n >>> from sklearn.model_selection import RandomizedSearchCV\n >>> from scipy.stats import uniform\n >>> iris = load_iris()\n >>> logistic = LogisticRegression(solver='saga', tol=1e-2, max_iter=200,\n ... random_state=0)\n >>> distributions = dict(C=uniform(loc=0, scale=4),\n ... penalty=['l2', 'l1'])\n >>> clf = RandomizedSearchCV(logistic, distributions, random_state=0)\n >>> search = clf.fit(iris.data, iris.target)\n >>> search.best_params_\n {'C': 2..., 'penalty': 'l1'}\n \"\"\"\n _required_parameters = ['estimator', 'param_distributions']\n \n def __init__(self, estimator, param_distributions, *, n_iter=10, scoring=None, n_jobs=None, refit=True, cv=None, verbose=0, pre_dispatch='2*n_jobs', random_state=None, error_score=np.nan, return_train_score=False):\n self.param_distributions = param_distributions\n self.n_iter = n_iter\n self.random_state = random_state\n super().__init__(estimator=estimator, scoring=scoring, n_jobs=n_jobs, refit=refit, cv=cv, verbose=verbose, pre_dispatch=pre_dispatch, error_score=error_score, return_train_score=return_train_score)\n \n def _run_search(self, evaluate_candidates):\n \"\"\"Search n_iter candidates from param_distributions\"\"\"\n evaluate_candidates(ParameterSampler(self.param_distributions, self.n_iter, random_state=self.random_state))\n" }, { "name": "BaseSuccessiveHalving", @@ -24726,8 +24679,8 @@ ], "is_public": true, "description": "Randomized search on hyper parameters.\n\nThe search strategy starts evaluating all the candidates with a small amount of resources and iteratively selects the best candidates, using more and more resources. The candidates are sampled at random from the parameter space and the number of sampled candidates is determined by ``n_candidates``. Read more in the :ref:`User guide`. .. note:: This estimator is still **experimental** for now: the predictions and the API might change without any deprecation cycle. To use it, you need to explicitly import ``enable_halving_search_cv``:: >>> # explicitly require this experimental feature >>> from sklearn.experimental import enable_halving_search_cv # noqa >>> # now you can import normally from model_selection >>> from sklearn.model_selection import HalvingRandomSearchCV", - "docstring": "Randomized search on hyper parameters.\n\n The search strategy starts evaluating all the candidates with a small\n amount of resources and iteratively selects the best candidates, using more\n and more resources.\n\n The candidates are sampled at random from the parameter space and the\n number of sampled candidates is determined by ``n_candidates``.\n\n Read more in the :ref:`User guide`.\n\n .. note::\n\n This estimator is still **experimental** for now: the predictions\n and the API might change without any deprecation cycle. To use it,\n you need to explicitly import ``enable_halving_search_cv``::\n\n >>> # explicitly require this experimental feature\n >>> from sklearn.experimental import enable_halving_search_cv # noqa\n >>> # now you can import normally from model_selection\n >>> from sklearn.model_selection import HalvingRandomSearchCV\n\n Parameters\n ----------\n estimator : estimator object\n This is assumed to implement the scikit-learn estimator interface.\n Either estimator needs to provide a ``score`` function,\n or ``scoring`` must be passed.\n\n param_distributions : dict\n Dictionary with parameters names (string) as keys and distributions\n or lists of parameters to try. Distributions must provide a ``rvs``\n method for sampling (such as those from scipy.stats.distributions).\n If a list is given, it is sampled uniformly.\n\n n_candidates : int, default='exhaust'\n The number of candidate parameters to sample, at the first\n iteration. Using 'exhaust' will sample enough candidates so that the\n last iteration uses as many resources as possible, based on\n `min_resources`, `max_resources` and `factor`. In this case,\n `min_resources` cannot be 'exhaust'.\n\n factor : int or float, default=3\n The 'halving' parameter, which determines the proportion of candidates\n that are selected for each subsequent iteration. For example,\n ``factor=3`` means that only one third of the candidates are selected.\n\n resource : ``'n_samples'`` or str, default='n_samples'\n Defines the resource that increases with each iteration. By default,\n the resource is the number of samples. It can also be set to any\n parameter of the base estimator that accepts positive integer\n values, e.g. 'n_iterations' or 'n_estimators' for a gradient\n boosting estimator. In this case ``max_resources`` cannot be 'auto'\n and must be set explicitly.\n\n max_resources : int, default='auto'\n The maximum number of resources that any candidate is allowed to use\n for a given iteration. By default, this is set ``n_samples`` when\n ``resource='n_samples'`` (default), else an error is raised.\n\n min_resources : {'exhaust', 'smallest'} or int, default='smallest'\n The minimum amount of resource that any candidate is allowed to use\n for a given iteration. Equivalently, this defines the amount of\n resources `r0` that are allocated for each candidate at the first\n iteration.\n\n - 'smallest' is a heuristic that sets `r0` to a small value:\n\n - ``n_splits * 2`` when ``resource='n_samples'`` for a regression\n problem\n - ``n_classes * n_splits * 2`` when ``resource='n_samples'`` for a\n classification problem\n - ``1`` when ``resource != 'n_samples'``\n\n - 'exhaust' will set `r0` such that the **last** iteration uses as\n much resources as possible. Namely, the last iteration will use the\n highest value smaller than ``max_resources`` that is a multiple of\n both ``min_resources`` and ``factor``. In general, using 'exhaust'\n leads to a more accurate estimator, but is slightly more time\n consuming. 'exhaust' isn't available when `n_candidates='exhaust'`.\n\n Note that the amount of resources used at each iteration is always a\n multiple of ``min_resources``.\n\n aggressive_elimination : bool, default=False\n This is only relevant in cases where there isn't enough resources to\n reduce the remaining candidates to at most `factor` after the last\n iteration. If ``True``, then the search process will 'replay' the\n first iteration for as long as needed until the number of candidates\n is small enough. This is ``False`` by default, which means that the\n last iteration may evaluate more than ``factor`` candidates. See\n :ref:`aggressive_elimination` for more details.\n\n cv : int, cross-validation generator or an iterable, default=5\n Determines the cross-validation splitting strategy.\n Possible inputs for cv are:\n\n - integer, to specify the number of folds in a `(Stratified)KFold`,\n - :term:`CV splitter`,\n - An iterable yielding (train, test) splits as arrays of indices.\n\n For integer/None inputs, if the estimator is a classifier and ``y`` is\n either binary or multiclass, :class:`StratifiedKFold` is used. In all\n other cases, :class:`KFold` is used. These splitters are instantiated\n with `shuffle=False` so the splits will be the same across calls.\n\n Refer :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n .. note::\n Due to implementation details, the folds produced by `cv` must be\n the same across multiple calls to `cv.split()`. For\n built-in `scikit-learn` iterators, this can be achieved by\n deactivating shuffling (`shuffle=False`), or by setting the\n `cv`'s `random_state` parameter to an integer.\n\n scoring : str, callable, or None, default=None\n A single string (see :ref:`scoring_parameter`) or a callable\n (see :ref:`scoring`) to evaluate the predictions on the test set.\n If None, the estimator's score method is used.\n\n refit : bool, default=True\n If True, refit an estimator using the best found parameters on the\n whole dataset.\n\n The refitted estimator is made available at the ``best_estimator_``\n attribute and permits using ``predict`` directly on this\n ``HalvingRandomSearchCV`` instance.\n\n error_score : 'raise' or numeric\n Value to assign to the score if an error occurs in estimator fitting.\n If set to 'raise', the error is raised. If a numeric value is given,\n FitFailedWarning is raised. This parameter does not affect the refit\n step, which will always raise the error. Default is ``np.nan``.\n\n return_train_score : bool, default=False\n If ``False``, the ``cv_results_`` attribute will not include training\n scores.\n Computing training scores is used to get insights on how different\n parameter settings impact the overfitting/underfitting trade-off.\n However computing the scores on the training set can be computationally\n expensive and is not strictly required to select the parameters that\n yield the best generalization performance.\n\n random_state : int, RandomState instance or None, default=None\n Pseudo random number generator state used for subsampling the dataset\n when `resources != 'n_samples'`. Also used for random uniform\n sampling from lists of possible values instead of scipy.stats\n distributions.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n n_jobs : int or None, default=None\n Number of jobs to run in parallel.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n verbose : int\n Controls the verbosity: the higher, the more messages.\n\n Attributes\n ----------\n n_resources_ : list of int\n The amount of resources used at each iteration.\n\n n_candidates_ : list of int\n The number of candidate parameters that were evaluated at each\n iteration.\n\n n_remaining_candidates_ : int\n The number of candidate parameters that are left after the last\n iteration. It corresponds to `ceil(n_candidates[-1] / factor)`\n\n max_resources_ : int\n The maximum number of resources that any candidate is allowed to use\n for a given iteration. Note that since the number of resources used at\n each iteration must be a multiple of ``min_resources_``, the actual\n number of resources used at the last iteration may be smaller than\n ``max_resources_``.\n\n min_resources_ : int\n The amount of resources that are allocated for each candidate at the\n first iteration.\n\n n_iterations_ : int\n The actual number of iterations that were run. This is equal to\n ``n_required_iterations_`` if ``aggressive_elimination`` is ``True``.\n Else, this is equal to ``min(n_possible_iterations_,\n n_required_iterations_)``.\n\n n_possible_iterations_ : int\n The number of iterations that are possible starting with\n ``min_resources_`` resources and without exceeding\n ``max_resources_``.\n\n n_required_iterations_ : int\n The number of iterations that are required to end up with less than\n ``factor`` candidates at the last iteration, starting with\n ``min_resources_`` resources. This will be smaller than\n ``n_possible_iterations_`` when there isn't enough resources.\n\n cv_results_ : dict of numpy (masked) ndarrays\n A dict with keys as column headers and values as columns, that can be\n imported into a pandas ``DataFrame``. It contains lots of information\n for analysing the results of a search.\n Please refer to the :ref:`User guide`\n for details.\n\n best_estimator_ : estimator or dict\n Estimator that was chosen by the search, i.e. estimator\n which gave highest score (or smallest loss if specified)\n on the left out data. Not available if ``refit=False``.\n\n best_score_ : float\n Mean cross-validated score of the best_estimator.\n\n best_params_ : dict\n Parameter setting that gave the best results on the hold out data.\n\n best_index_ : int\n The index (of the ``cv_results_`` arrays) which corresponds to the best\n candidate parameter setting.\n\n The dict at ``search.cv_results_['params'][search.best_index_]`` gives\n the parameter setting for the best model, that gives the highest\n mean score (``search.best_score_``).\n\n scorer_ : function or a dict\n Scorer function used on the held out data to choose the best\n parameters for the model.\n\n n_splits_ : int\n The number of cross-validation splits (folds/iterations).\n\n refit_time_ : float\n Seconds used for refitting the best model on the whole dataset.\n\n This is present only if ``refit`` is not False.\n\n multimetric_ : bool\n Whether or not the scorers compute several metrics.\n\n classes_ : ndarray of shape (n_classes,)\n The classes labels. This is present only if ``refit`` is specified and\n the underlying estimator is a classifier.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`. Only defined if\n `best_estimator_` is defined (see the documentation for the `refit`\n parameter for more details) and that `best_estimator_` exposes\n `n_features_in_` when fit.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Only defined if\n `best_estimator_` is defined (see the documentation for the `refit`\n parameter for more details) and that `best_estimator_` exposes\n `feature_names_in_` when fit.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n :class:`HalvingGridSearchCV`:\n Search over a grid of parameters using successive halving.\n\n Notes\n -----\n The parameters selected are those that maximize the score of the held-out\n data, according to the scoring parameter.\n\n Examples\n --------\n\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.ensemble import RandomForestClassifier\n >>> from sklearn.experimental import enable_halving_search_cv # noqa\n >>> from sklearn.model_selection import HalvingRandomSearchCV\n >>> from scipy.stats import randint\n ...\n >>> X, y = load_iris(return_X_y=True)\n >>> clf = RandomForestClassifier(random_state=0)\n >>> np.random.seed(0)\n ...\n >>> param_distributions = {\"max_depth\": [3, None],\n ... \"min_samples_split\": randint(2, 11)}\n >>> search = HalvingRandomSearchCV(clf, param_distributions,\n ... resource='n_estimators',\n ... max_resources=10,\n ... random_state=0).fit(X, y)\n >>> search.best_params_ # doctest: +SKIP\n {'max_depth': None, 'min_samples_split': 10, 'n_estimators': 9}\n ", - "source_code": "\n\nclass HalvingRandomSearchCV(BaseSuccessiveHalving):\n \"\"\"Randomized search on hyper parameters.\n\n The search strategy starts evaluating all the candidates with a small\n amount of resources and iteratively selects the best candidates, using more\n and more resources.\n\n The candidates are sampled at random from the parameter space and the\n number of sampled candidates is determined by ``n_candidates``.\n\n Read more in the :ref:`User guide`.\n\n .. note::\n\n This estimator is still **experimental** for now: the predictions\n and the API might change without any deprecation cycle. To use it,\n you need to explicitly import ``enable_halving_search_cv``::\n\n >>> # explicitly require this experimental feature\n >>> from sklearn.experimental import enable_halving_search_cv # noqa\n >>> # now you can import normally from model_selection\n >>> from sklearn.model_selection import HalvingRandomSearchCV\n\n Parameters\n ----------\n estimator : estimator object\n This is assumed to implement the scikit-learn estimator interface.\n Either estimator needs to provide a ``score`` function,\n or ``scoring`` must be passed.\n\n param_distributions : dict\n Dictionary with parameters names (string) as keys and distributions\n or lists of parameters to try. Distributions must provide a ``rvs``\n method for sampling (such as those from scipy.stats.distributions).\n If a list is given, it is sampled uniformly.\n\n n_candidates : int, default='exhaust'\n The number of candidate parameters to sample, at the first\n iteration. Using 'exhaust' will sample enough candidates so that the\n last iteration uses as many resources as possible, based on\n `min_resources`, `max_resources` and `factor`. In this case,\n `min_resources` cannot be 'exhaust'.\n\n factor : int or float, default=3\n The 'halving' parameter, which determines the proportion of candidates\n that are selected for each subsequent iteration. For example,\n ``factor=3`` means that only one third of the candidates are selected.\n\n resource : ``'n_samples'`` or str, default='n_samples'\n Defines the resource that increases with each iteration. By default,\n the resource is the number of samples. It can also be set to any\n parameter of the base estimator that accepts positive integer\n values, e.g. 'n_iterations' or 'n_estimators' for a gradient\n boosting estimator. In this case ``max_resources`` cannot be 'auto'\n and must be set explicitly.\n\n max_resources : int, default='auto'\n The maximum number of resources that any candidate is allowed to use\n for a given iteration. By default, this is set ``n_samples`` when\n ``resource='n_samples'`` (default), else an error is raised.\n\n min_resources : {'exhaust', 'smallest'} or int, default='smallest'\n The minimum amount of resource that any candidate is allowed to use\n for a given iteration. Equivalently, this defines the amount of\n resources `r0` that are allocated for each candidate at the first\n iteration.\n\n - 'smallest' is a heuristic that sets `r0` to a small value:\n\n - ``n_splits * 2`` when ``resource='n_samples'`` for a regression\n problem\n - ``n_classes * n_splits * 2`` when ``resource='n_samples'`` for a\n classification problem\n - ``1`` when ``resource != 'n_samples'``\n\n - 'exhaust' will set `r0` such that the **last** iteration uses as\n much resources as possible. Namely, the last iteration will use the\n highest value smaller than ``max_resources`` that is a multiple of\n both ``min_resources`` and ``factor``. In general, using 'exhaust'\n leads to a more accurate estimator, but is slightly more time\n consuming. 'exhaust' isn't available when `n_candidates='exhaust'`.\n\n Note that the amount of resources used at each iteration is always a\n multiple of ``min_resources``.\n\n aggressive_elimination : bool, default=False\n This is only relevant in cases where there isn't enough resources to\n reduce the remaining candidates to at most `factor` after the last\n iteration. If ``True``, then the search process will 'replay' the\n first iteration for as long as needed until the number of candidates\n is small enough. This is ``False`` by default, which means that the\n last iteration may evaluate more than ``factor`` candidates. See\n :ref:`aggressive_elimination` for more details.\n\n cv : int, cross-validation generator or an iterable, default=5\n Determines the cross-validation splitting strategy.\n Possible inputs for cv are:\n\n - integer, to specify the number of folds in a `(Stratified)KFold`,\n - :term:`CV splitter`,\n - An iterable yielding (train, test) splits as arrays of indices.\n\n For integer/None inputs, if the estimator is a classifier and ``y`` is\n either binary or multiclass, :class:`StratifiedKFold` is used. In all\n other cases, :class:`KFold` is used. These splitters are instantiated\n with `shuffle=False` so the splits will be the same across calls.\n\n Refer :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n .. note::\n Due to implementation details, the folds produced by `cv` must be\n the same across multiple calls to `cv.split()`. For\n built-in `scikit-learn` iterators, this can be achieved by\n deactivating shuffling (`shuffle=False`), or by setting the\n `cv`'s `random_state` parameter to an integer.\n\n scoring : str, callable, or None, default=None\n A single string (see :ref:`scoring_parameter`) or a callable\n (see :ref:`scoring`) to evaluate the predictions on the test set.\n If None, the estimator's score method is used.\n\n refit : bool, default=True\n If True, refit an estimator using the best found parameters on the\n whole dataset.\n\n The refitted estimator is made available at the ``best_estimator_``\n attribute and permits using ``predict`` directly on this\n ``HalvingRandomSearchCV`` instance.\n\n error_score : 'raise' or numeric\n Value to assign to the score if an error occurs in estimator fitting.\n If set to 'raise', the error is raised. If a numeric value is given,\n FitFailedWarning is raised. This parameter does not affect the refit\n step, which will always raise the error. Default is ``np.nan``.\n\n return_train_score : bool, default=False\n If ``False``, the ``cv_results_`` attribute will not include training\n scores.\n Computing training scores is used to get insights on how different\n parameter settings impact the overfitting/underfitting trade-off.\n However computing the scores on the training set can be computationally\n expensive and is not strictly required to select the parameters that\n yield the best generalization performance.\n\n random_state : int, RandomState instance or None, default=None\n Pseudo random number generator state used for subsampling the dataset\n when `resources != 'n_samples'`. Also used for random uniform\n sampling from lists of possible values instead of scipy.stats\n distributions.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n n_jobs : int or None, default=None\n Number of jobs to run in parallel.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n verbose : int\n Controls the verbosity: the higher, the more messages.\n\n Attributes\n ----------\n n_resources_ : list of int\n The amount of resources used at each iteration.\n\n n_candidates_ : list of int\n The number of candidate parameters that were evaluated at each\n iteration.\n\n n_remaining_candidates_ : int\n The number of candidate parameters that are left after the last\n iteration. It corresponds to `ceil(n_candidates[-1] / factor)`\n\n max_resources_ : int\n The maximum number of resources that any candidate is allowed to use\n for a given iteration. Note that since the number of resources used at\n each iteration must be a multiple of ``min_resources_``, the actual\n number of resources used at the last iteration may be smaller than\n ``max_resources_``.\n\n min_resources_ : int\n The amount of resources that are allocated for each candidate at the\n first iteration.\n\n n_iterations_ : int\n The actual number of iterations that were run. This is equal to\n ``n_required_iterations_`` if ``aggressive_elimination`` is ``True``.\n Else, this is equal to ``min(n_possible_iterations_,\n n_required_iterations_)``.\n\n n_possible_iterations_ : int\n The number of iterations that are possible starting with\n ``min_resources_`` resources and without exceeding\n ``max_resources_``.\n\n n_required_iterations_ : int\n The number of iterations that are required to end up with less than\n ``factor`` candidates at the last iteration, starting with\n ``min_resources_`` resources. This will be smaller than\n ``n_possible_iterations_`` when there isn't enough resources.\n\n cv_results_ : dict of numpy (masked) ndarrays\n A dict with keys as column headers and values as columns, that can be\n imported into a pandas ``DataFrame``. It contains lots of information\n for analysing the results of a search.\n Please refer to the :ref:`User guide`\n for details.\n\n best_estimator_ : estimator or dict\n Estimator that was chosen by the search, i.e. estimator\n which gave highest score (or smallest loss if specified)\n on the left out data. Not available if ``refit=False``.\n\n best_score_ : float\n Mean cross-validated score of the best_estimator.\n\n best_params_ : dict\n Parameter setting that gave the best results on the hold out data.\n\n best_index_ : int\n The index (of the ``cv_results_`` arrays) which corresponds to the best\n candidate parameter setting.\n\n The dict at ``search.cv_results_['params'][search.best_index_]`` gives\n the parameter setting for the best model, that gives the highest\n mean score (``search.best_score_``).\n\n scorer_ : function or a dict\n Scorer function used on the held out data to choose the best\n parameters for the model.\n\n n_splits_ : int\n The number of cross-validation splits (folds/iterations).\n\n refit_time_ : float\n Seconds used for refitting the best model on the whole dataset.\n\n This is present only if ``refit`` is not False.\n\n multimetric_ : bool\n Whether or not the scorers compute several metrics.\n\n classes_ : ndarray of shape (n_classes,)\n The classes labels. This is present only if ``refit`` is specified and\n the underlying estimator is a classifier.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`. Only defined if\n `best_estimator_` is defined (see the documentation for the `refit`\n parameter for more details) and that `best_estimator_` exposes\n `n_features_in_` when fit.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Only defined if\n `best_estimator_` is defined (see the documentation for the `refit`\n parameter for more details) and that `best_estimator_` exposes\n `feature_names_in_` when fit.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n :class:`HalvingGridSearchCV`:\n Search over a grid of parameters using successive halving.\n\n Notes\n -----\n The parameters selected are those that maximize the score of the held-out\n data, according to the scoring parameter.\n\n Examples\n --------\n\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.ensemble import RandomForestClassifier\n >>> from sklearn.experimental import enable_halving_search_cv # noqa\n >>> from sklearn.model_selection import HalvingRandomSearchCV\n >>> from scipy.stats import randint\n ...\n >>> X, y = load_iris(return_X_y=True)\n >>> clf = RandomForestClassifier(random_state=0)\n >>> np.random.seed(0)\n ...\n >>> param_distributions = {\"max_depth\": [3, None],\n ... \"min_samples_split\": randint(2, 11)}\n >>> search = HalvingRandomSearchCV(clf, param_distributions,\n ... resource='n_estimators',\n ... max_resources=10,\n ... random_state=0).fit(X, y)\n >>> search.best_params_ # doctest: +SKIP\n {'max_depth': None, 'min_samples_split': 10, 'n_estimators': 9}\n \"\"\"\n _required_parameters = ['estimator', 'param_distributions']\n \n def __init__(self, estimator, param_distributions, *, n_candidates='exhaust', factor=3, resource='n_samples', max_resources='auto', min_resources='smallest', aggressive_elimination=False, cv=5, scoring=None, refit=True, error_score=np.nan, return_train_score=True, random_state=None, n_jobs=None, verbose=0):\n super().__init__(estimator, scoring=scoring, n_jobs=n_jobs, refit=refit, verbose=verbose, cv=cv, random_state=random_state, error_score=error_score, return_train_score=return_train_score, max_resources=max_resources, resource=resource, factor=factor, min_resources=min_resources, aggressive_elimination=aggressive_elimination)\n self.param_distributions = param_distributions\n self.n_candidates = n_candidates\n \n def _generate_candidate_params(self):\n n_candidates_first_iter = self.n_candidates\n if n_candidates_first_iter == 'exhaust':\n n_candidates_first_iter = self.max_resources_ // self.min_resources_\n return ParameterSampler(self.param_distributions, n_candidates_first_iter, random_state=self.random_state)\n" + "docstring": "Randomized search on hyper parameters.\n\n The search strategy starts evaluating all the candidates with a small\n amount of resources and iteratively selects the best candidates, using more\n and more resources.\n\n The candidates are sampled at random from the parameter space and the\n number of sampled candidates is determined by ``n_candidates``.\n\n Read more in the :ref:`User guide`.\n\n .. note::\n\n This estimator is still **experimental** for now: the predictions\n and the API might change without any deprecation cycle. To use it,\n you need to explicitly import ``enable_halving_search_cv``::\n\n >>> # explicitly require this experimental feature\n >>> from sklearn.experimental import enable_halving_search_cv # noqa\n >>> # now you can import normally from model_selection\n >>> from sklearn.model_selection import HalvingRandomSearchCV\n\n Parameters\n ----------\n estimator : estimator object\n This is assumed to implement the scikit-learn estimator interface.\n Either estimator needs to provide a ``score`` function,\n or ``scoring`` must be passed.\n\n param_distributions : dict\n Dictionary with parameters names (string) as keys and distributions\n or lists of parameters to try. Distributions must provide a ``rvs``\n method for sampling (such as those from scipy.stats.distributions).\n If a list is given, it is sampled uniformly.\n\n n_candidates : int, default='exhaust'\n The number of candidate parameters to sample, at the first\n iteration. Using 'exhaust' will sample enough candidates so that the\n last iteration uses as many resources as possible, based on\n `min_resources`, `max_resources` and `factor`. In this case,\n `min_resources` cannot be 'exhaust'.\n\n factor : int or float, default=3\n The 'halving' parameter, which determines the proportion of candidates\n that are selected for each subsequent iteration. For example,\n ``factor=3`` means that only one third of the candidates are selected.\n\n resource : ``'n_samples'`` or str, default='n_samples'\n Defines the resource that increases with each iteration. By default,\n the resource is the number of samples. It can also be set to any\n parameter of the base estimator that accepts positive integer\n values, e.g. 'n_iterations' or 'n_estimators' for a gradient\n boosting estimator. In this case ``max_resources`` cannot be 'auto'\n and must be set explicitly.\n\n max_resources : int, default='auto'\n The maximum number of resources that any candidate is allowed to use\n for a given iteration. By default, this is set ``n_samples`` when\n ``resource='n_samples'`` (default), else an error is raised.\n\n min_resources : {'exhaust', 'smallest'} or int, default='smallest'\n The minimum amount of resource that any candidate is allowed to use\n for a given iteration. Equivalently, this defines the amount of\n resources `r0` that are allocated for each candidate at the first\n iteration.\n\n - 'smallest' is a heuristic that sets `r0` to a small value:\n\n - ``n_splits * 2`` when ``resource='n_samples'`` for a regression\n problem\n - ``n_classes * n_splits * 2`` when ``resource='n_samples'`` for a\n classification problem\n - ``1`` when ``resource != 'n_samples'``\n\n - 'exhaust' will set `r0` such that the **last** iteration uses as\n much resources as possible. Namely, the last iteration will use the\n highest value smaller than ``max_resources`` that is a multiple of\n both ``min_resources`` and ``factor``. In general, using 'exhaust'\n leads to a more accurate estimator, but is slightly more time\n consuming. 'exhaust' isn't available when `n_candidates='exhaust'`.\n\n Note that the amount of resources used at each iteration is always a\n multiple of ``min_resources``.\n\n aggressive_elimination : bool, default=False\n This is only relevant in cases where there isn't enough resources to\n reduce the remaining candidates to at most `factor` after the last\n iteration. If ``True``, then the search process will 'replay' the\n first iteration for as long as needed until the number of candidates\n is small enough. This is ``False`` by default, which means that the\n last iteration may evaluate more than ``factor`` candidates. See\n :ref:`aggressive_elimination` for more details.\n\n cv : int, cross-validation generator or an iterable, default=5\n Determines the cross-validation splitting strategy.\n Possible inputs for cv are:\n\n - integer, to specify the number of folds in a `(Stratified)KFold`,\n - :term:`CV splitter`,\n - An iterable yielding (train, test) splits as arrays of indices.\n\n For integer/None inputs, if the estimator is a classifier and ``y`` is\n either binary or multiclass, :class:`StratifiedKFold` is used. In all\n other cases, :class:`KFold` is used. These splitters are instantiated\n with `shuffle=False` so the splits will be the same across calls.\n\n Refer :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n .. note::\n Due to implementation details, the folds produced by `cv` must be\n the same across multiple calls to `cv.split()`. For\n built-in `scikit-learn` iterators, this can be achieved by\n deactivating shuffling (`shuffle=False`), or by setting the\n `cv`'s `random_state` parameter to an integer.\n\n scoring : str, callable, or None, default=None\n A single string (see :ref:`scoring_parameter`) or a callable\n (see :ref:`scoring`) to evaluate the predictions on the test set.\n If None, the estimator's score method is used.\n\n refit : bool, default=True\n If True, refit an estimator using the best found parameters on the\n whole dataset.\n\n The refitted estimator is made available at the ``best_estimator_``\n attribute and permits using ``predict`` directly on this\n ``HalvingRandomSearchCV`` instance.\n\n error_score : 'raise' or numeric\n Value to assign to the score if an error occurs in estimator fitting.\n If set to 'raise', the error is raised. If a numeric value is given,\n FitFailedWarning is raised. This parameter does not affect the refit\n step, which will always raise the error. Default is ``np.nan``.\n\n return_train_score : bool, default=False\n If ``False``, the ``cv_results_`` attribute will not include training\n scores.\n Computing training scores is used to get insights on how different\n parameter settings impact the overfitting/underfitting trade-off.\n However computing the scores on the training set can be computationally\n expensive and is not strictly required to select the parameters that\n yield the best generalization performance.\n\n random_state : int, RandomState instance or None, default=None\n Pseudo random number generator state used for subsampling the dataset\n when `resources != 'n_samples'`. Also used for random uniform\n sampling from lists of possible values instead of scipy.stats\n distributions.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n n_jobs : int or None, default=None\n Number of jobs to run in parallel.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n verbose : int\n Controls the verbosity: the higher, the more messages.\n\n Attributes\n ----------\n n_resources_ : list of int\n The amount of resources used at each iteration.\n\n n_candidates_ : list of int\n The number of candidate parameters that were evaluated at each\n iteration.\n\n n_remaining_candidates_ : int\n The number of candidate parameters that are left after the last\n iteration. It corresponds to `ceil(n_candidates[-1] / factor)`\n\n max_resources_ : int\n The maximum number of resources that any candidate is allowed to use\n for a given iteration. Note that since the number of resources used at\n each iteration must be a multiple of ``min_resources_``, the actual\n number of resources used at the last iteration may be smaller than\n ``max_resources_``.\n\n min_resources_ : int\n The amount of resources that are allocated for each candidate at the\n first iteration.\n\n n_iterations_ : int\n The actual number of iterations that were run. This is equal to\n ``n_required_iterations_`` if ``aggressive_elimination`` is ``True``.\n Else, this is equal to ``min(n_possible_iterations_,\n n_required_iterations_)``.\n\n n_possible_iterations_ : int\n The number of iterations that are possible starting with\n ``min_resources_`` resources and without exceeding\n ``max_resources_``.\n\n n_required_iterations_ : int\n The number of iterations that are required to end up with less than\n ``factor`` candidates at the last iteration, starting with\n ``min_resources_`` resources. This will be smaller than\n ``n_possible_iterations_`` when there isn't enough resources.\n\n cv_results_ : dict of numpy (masked) ndarrays\n A dict with keys as column headers and values as columns, that can be\n imported into a pandas ``DataFrame``. It contains lots of information\n for analysing the results of a search.\n Please refer to the :ref:`User guide`\n for details.\n\n best_estimator_ : estimator or dict\n Estimator that was chosen by the search, i.e. estimator\n which gave highest score (or smallest loss if specified)\n on the left out data. Not available if ``refit=False``.\n\n best_score_ : float\n Mean cross-validated score of the best_estimator.\n\n best_params_ : dict\n Parameter setting that gave the best results on the hold out data.\n\n best_index_ : int\n The index (of the ``cv_results_`` arrays) which corresponds to the best\n candidate parameter setting.\n\n The dict at ``search.cv_results_['params'][search.best_index_]`` gives\n the parameter setting for the best model, that gives the highest\n mean score (``search.best_score_``).\n\n scorer_ : function or a dict\n Scorer function used on the held out data to choose the best\n parameters for the model.\n\n n_splits_ : int\n The number of cross-validation splits (folds/iterations).\n\n refit_time_ : float\n Seconds used for refitting the best model on the whole dataset.\n\n This is present only if ``refit`` is not False.\n\n multimetric_ : bool\n Whether or not the scorers compute several metrics.\n\n classes_ : ndarray of shape (n_classes,)\n The classes labels. This is present only if ``refit`` is specified and\n the underlying estimator is a classifier.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`. Only defined if\n `best_estimator_` is defined (see the documentation for the `refit`\n parameter for more details) and that `best_estimator_` exposes\n `n_features_in_` when fit.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Only defined if\n `best_estimator_` is defined (see the documentation for the `refit`\n parameter for more details) and that `best_estimator_` exposes\n `feature_names_in_` when fit.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n :class:`HalvingGridSearchCV`:\n Search over a grid of parameters using successive halving.\n\n Notes\n -----\n The parameters selected are those that maximize the score of the held-out\n data, according to the scoring parameter.\n\n Examples\n --------\n\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.ensemble import RandomForestClassifier\n >>> from sklearn.experimental import enable_halving_search_cv # noqa\n >>> from sklearn.model_selection import HalvingRandomSearchCV\n >>> from scipy.stats import randint\n >>> import numpy as np\n ...\n >>> X, y = load_iris(return_X_y=True)\n >>> clf = RandomForestClassifier(random_state=0)\n >>> np.random.seed(0)\n ...\n >>> param_distributions = {\"max_depth\": [3, None],\n ... \"min_samples_split\": randint(2, 11)}\n >>> search = HalvingRandomSearchCV(clf, param_distributions,\n ... resource='n_estimators',\n ... max_resources=10,\n ... random_state=0).fit(X, y)\n >>> search.best_params_ # doctest: +SKIP\n {'max_depth': None, 'min_samples_split': 10, 'n_estimators': 9}\n ", + "source_code": "\n\nclass HalvingRandomSearchCV(BaseSuccessiveHalving):\n \"\"\"Randomized search on hyper parameters.\n\n The search strategy starts evaluating all the candidates with a small\n amount of resources and iteratively selects the best candidates, using more\n and more resources.\n\n The candidates are sampled at random from the parameter space and the\n number of sampled candidates is determined by ``n_candidates``.\n\n Read more in the :ref:`User guide`.\n\n .. note::\n\n This estimator is still **experimental** for now: the predictions\n and the API might change without any deprecation cycle. To use it,\n you need to explicitly import ``enable_halving_search_cv``::\n\n >>> # explicitly require this experimental feature\n >>> from sklearn.experimental import enable_halving_search_cv # noqa\n >>> # now you can import normally from model_selection\n >>> from sklearn.model_selection import HalvingRandomSearchCV\n\n Parameters\n ----------\n estimator : estimator object\n This is assumed to implement the scikit-learn estimator interface.\n Either estimator needs to provide a ``score`` function,\n or ``scoring`` must be passed.\n\n param_distributions : dict\n Dictionary with parameters names (string) as keys and distributions\n or lists of parameters to try. Distributions must provide a ``rvs``\n method for sampling (such as those from scipy.stats.distributions).\n If a list is given, it is sampled uniformly.\n\n n_candidates : int, default='exhaust'\n The number of candidate parameters to sample, at the first\n iteration. Using 'exhaust' will sample enough candidates so that the\n last iteration uses as many resources as possible, based on\n `min_resources`, `max_resources` and `factor`. In this case,\n `min_resources` cannot be 'exhaust'.\n\n factor : int or float, default=3\n The 'halving' parameter, which determines the proportion of candidates\n that are selected for each subsequent iteration. For example,\n ``factor=3`` means that only one third of the candidates are selected.\n\n resource : ``'n_samples'`` or str, default='n_samples'\n Defines the resource that increases with each iteration. By default,\n the resource is the number of samples. It can also be set to any\n parameter of the base estimator that accepts positive integer\n values, e.g. 'n_iterations' or 'n_estimators' for a gradient\n boosting estimator. In this case ``max_resources`` cannot be 'auto'\n and must be set explicitly.\n\n max_resources : int, default='auto'\n The maximum number of resources that any candidate is allowed to use\n for a given iteration. By default, this is set ``n_samples`` when\n ``resource='n_samples'`` (default), else an error is raised.\n\n min_resources : {'exhaust', 'smallest'} or int, default='smallest'\n The minimum amount of resource that any candidate is allowed to use\n for a given iteration. Equivalently, this defines the amount of\n resources `r0` that are allocated for each candidate at the first\n iteration.\n\n - 'smallest' is a heuristic that sets `r0` to a small value:\n\n - ``n_splits * 2`` when ``resource='n_samples'`` for a regression\n problem\n - ``n_classes * n_splits * 2`` when ``resource='n_samples'`` for a\n classification problem\n - ``1`` when ``resource != 'n_samples'``\n\n - 'exhaust' will set `r0` such that the **last** iteration uses as\n much resources as possible. Namely, the last iteration will use the\n highest value smaller than ``max_resources`` that is a multiple of\n both ``min_resources`` and ``factor``. In general, using 'exhaust'\n leads to a more accurate estimator, but is slightly more time\n consuming. 'exhaust' isn't available when `n_candidates='exhaust'`.\n\n Note that the amount of resources used at each iteration is always a\n multiple of ``min_resources``.\n\n aggressive_elimination : bool, default=False\n This is only relevant in cases where there isn't enough resources to\n reduce the remaining candidates to at most `factor` after the last\n iteration. If ``True``, then the search process will 'replay' the\n first iteration for as long as needed until the number of candidates\n is small enough. This is ``False`` by default, which means that the\n last iteration may evaluate more than ``factor`` candidates. See\n :ref:`aggressive_elimination` for more details.\n\n cv : int, cross-validation generator or an iterable, default=5\n Determines the cross-validation splitting strategy.\n Possible inputs for cv are:\n\n - integer, to specify the number of folds in a `(Stratified)KFold`,\n - :term:`CV splitter`,\n - An iterable yielding (train, test) splits as arrays of indices.\n\n For integer/None inputs, if the estimator is a classifier and ``y`` is\n either binary or multiclass, :class:`StratifiedKFold` is used. In all\n other cases, :class:`KFold` is used. These splitters are instantiated\n with `shuffle=False` so the splits will be the same across calls.\n\n Refer :ref:`User Guide ` for the various\n cross-validation strategies that can be used here.\n\n .. note::\n Due to implementation details, the folds produced by `cv` must be\n the same across multiple calls to `cv.split()`. For\n built-in `scikit-learn` iterators, this can be achieved by\n deactivating shuffling (`shuffle=False`), or by setting the\n `cv`'s `random_state` parameter to an integer.\n\n scoring : str, callable, or None, default=None\n A single string (see :ref:`scoring_parameter`) or a callable\n (see :ref:`scoring`) to evaluate the predictions on the test set.\n If None, the estimator's score method is used.\n\n refit : bool, default=True\n If True, refit an estimator using the best found parameters on the\n whole dataset.\n\n The refitted estimator is made available at the ``best_estimator_``\n attribute and permits using ``predict`` directly on this\n ``HalvingRandomSearchCV`` instance.\n\n error_score : 'raise' or numeric\n Value to assign to the score if an error occurs in estimator fitting.\n If set to 'raise', the error is raised. If a numeric value is given,\n FitFailedWarning is raised. This parameter does not affect the refit\n step, which will always raise the error. Default is ``np.nan``.\n\n return_train_score : bool, default=False\n If ``False``, the ``cv_results_`` attribute will not include training\n scores.\n Computing training scores is used to get insights on how different\n parameter settings impact the overfitting/underfitting trade-off.\n However computing the scores on the training set can be computationally\n expensive and is not strictly required to select the parameters that\n yield the best generalization performance.\n\n random_state : int, RandomState instance or None, default=None\n Pseudo random number generator state used for subsampling the dataset\n when `resources != 'n_samples'`. Also used for random uniform\n sampling from lists of possible values instead of scipy.stats\n distributions.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n n_jobs : int or None, default=None\n Number of jobs to run in parallel.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n verbose : int\n Controls the verbosity: the higher, the more messages.\n\n Attributes\n ----------\n n_resources_ : list of int\n The amount of resources used at each iteration.\n\n n_candidates_ : list of int\n The number of candidate parameters that were evaluated at each\n iteration.\n\n n_remaining_candidates_ : int\n The number of candidate parameters that are left after the last\n iteration. It corresponds to `ceil(n_candidates[-1] / factor)`\n\n max_resources_ : int\n The maximum number of resources that any candidate is allowed to use\n for a given iteration. Note that since the number of resources used at\n each iteration must be a multiple of ``min_resources_``, the actual\n number of resources used at the last iteration may be smaller than\n ``max_resources_``.\n\n min_resources_ : int\n The amount of resources that are allocated for each candidate at the\n first iteration.\n\n n_iterations_ : int\n The actual number of iterations that were run. This is equal to\n ``n_required_iterations_`` if ``aggressive_elimination`` is ``True``.\n Else, this is equal to ``min(n_possible_iterations_,\n n_required_iterations_)``.\n\n n_possible_iterations_ : int\n The number of iterations that are possible starting with\n ``min_resources_`` resources and without exceeding\n ``max_resources_``.\n\n n_required_iterations_ : int\n The number of iterations that are required to end up with less than\n ``factor`` candidates at the last iteration, starting with\n ``min_resources_`` resources. This will be smaller than\n ``n_possible_iterations_`` when there isn't enough resources.\n\n cv_results_ : dict of numpy (masked) ndarrays\n A dict with keys as column headers and values as columns, that can be\n imported into a pandas ``DataFrame``. It contains lots of information\n for analysing the results of a search.\n Please refer to the :ref:`User guide`\n for details.\n\n best_estimator_ : estimator or dict\n Estimator that was chosen by the search, i.e. estimator\n which gave highest score (or smallest loss if specified)\n on the left out data. Not available if ``refit=False``.\n\n best_score_ : float\n Mean cross-validated score of the best_estimator.\n\n best_params_ : dict\n Parameter setting that gave the best results on the hold out data.\n\n best_index_ : int\n The index (of the ``cv_results_`` arrays) which corresponds to the best\n candidate parameter setting.\n\n The dict at ``search.cv_results_['params'][search.best_index_]`` gives\n the parameter setting for the best model, that gives the highest\n mean score (``search.best_score_``).\n\n scorer_ : function or a dict\n Scorer function used on the held out data to choose the best\n parameters for the model.\n\n n_splits_ : int\n The number of cross-validation splits (folds/iterations).\n\n refit_time_ : float\n Seconds used for refitting the best model on the whole dataset.\n\n This is present only if ``refit`` is not False.\n\n multimetric_ : bool\n Whether or not the scorers compute several metrics.\n\n classes_ : ndarray of shape (n_classes,)\n The classes labels. This is present only if ``refit`` is specified and\n the underlying estimator is a classifier.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`. Only defined if\n `best_estimator_` is defined (see the documentation for the `refit`\n parameter for more details) and that `best_estimator_` exposes\n `n_features_in_` when fit.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Only defined if\n `best_estimator_` is defined (see the documentation for the `refit`\n parameter for more details) and that `best_estimator_` exposes\n `feature_names_in_` when fit.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n :class:`HalvingGridSearchCV`:\n Search over a grid of parameters using successive halving.\n\n Notes\n -----\n The parameters selected are those that maximize the score of the held-out\n data, according to the scoring parameter.\n\n Examples\n --------\n\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.ensemble import RandomForestClassifier\n >>> from sklearn.experimental import enable_halving_search_cv # noqa\n >>> from sklearn.model_selection import HalvingRandomSearchCV\n >>> from scipy.stats import randint\n >>> import numpy as np\n ...\n >>> X, y = load_iris(return_X_y=True)\n >>> clf = RandomForestClassifier(random_state=0)\n >>> np.random.seed(0)\n ...\n >>> param_distributions = {\"max_depth\": [3, None],\n ... \"min_samples_split\": randint(2, 11)}\n >>> search = HalvingRandomSearchCV(clf, param_distributions,\n ... resource='n_estimators',\n ... max_resources=10,\n ... random_state=0).fit(X, y)\n >>> search.best_params_ # doctest: +SKIP\n {'max_depth': None, 'min_samples_split': 10, 'n_estimators': 9}\n \"\"\"\n _required_parameters = ['estimator', 'param_distributions']\n \n def __init__(self, estimator, param_distributions, *, n_candidates='exhaust', factor=3, resource='n_samples', max_resources='auto', min_resources='smallest', aggressive_elimination=False, cv=5, scoring=None, refit=True, error_score=np.nan, return_train_score=True, random_state=None, n_jobs=None, verbose=0):\n super().__init__(estimator, scoring=scoring, n_jobs=n_jobs, refit=refit, verbose=verbose, cv=cv, random_state=random_state, error_score=error_score, return_train_score=return_train_score, max_resources=max_resources, resource=resource, factor=factor, min_resources=min_resources, aggressive_elimination=aggressive_elimination)\n self.param_distributions = param_distributions\n self.n_candidates = n_candidates\n \n def _generate_candidate_params(self):\n n_candidates_first_iter = self.n_candidates\n if n_candidates_first_iter == 'exhaust':\n n_candidates_first_iter = self.max_resources_ // self.min_resources_\n return ParameterSampler(self.param_distributions, n_candidates_first_iter, random_state=self.random_state)\n" }, { "name": "_SubsampleMetaSplitter", @@ -25058,8 +25011,8 @@ "sklearn.multiclass.OneVsOneClassifier.partial_fit", "sklearn.multiclass.OneVsOneClassifier.predict", "sklearn.multiclass.OneVsOneClassifier.decision_function", - "sklearn.multiclass.OneVsOneClassifier.n_classes_", - "sklearn.multiclass.OneVsOneClassifier._pairwise", + "sklearn.multiclass.OneVsOneClassifier.n_classes_@getter", + "sklearn.multiclass.OneVsOneClassifier._pairwise@getter", "sklearn.multiclass.OneVsOneClassifier._more_tags" ], "is_public": true, @@ -25084,11 +25037,11 @@ "sklearn.multiclass.OneVsRestClassifier.predict", "sklearn.multiclass.OneVsRestClassifier.predict_proba", "sklearn.multiclass.OneVsRestClassifier.decision_function", - "sklearn.multiclass.OneVsRestClassifier.multilabel_", - "sklearn.multiclass.OneVsRestClassifier.n_classes_", - "sklearn.multiclass.OneVsRestClassifier.coef_", - "sklearn.multiclass.OneVsRestClassifier.intercept_", - "sklearn.multiclass.OneVsRestClassifier._pairwise", + "sklearn.multiclass.OneVsRestClassifier.multilabel_@getter", + "sklearn.multiclass.OneVsRestClassifier.n_classes_@getter", + "sklearn.multiclass.OneVsRestClassifier.coef_@getter", + "sklearn.multiclass.OneVsRestClassifier.intercept_@getter", + "sklearn.multiclass.OneVsRestClassifier._pairwise@getter", "sklearn.multiclass.OneVsRestClassifier._more_tags" ], "is_public": true, @@ -25304,12 +25257,12 @@ "sklearn.naive_bayes.GaussianNB.partial_fit", "sklearn.naive_bayes.GaussianNB._partial_fit", "sklearn.naive_bayes.GaussianNB._joint_log_likelihood", - "sklearn.naive_bayes.GaussianNB.sigma_" + "sklearn.naive_bayes.GaussianNB.sigma_@getter" ], "is_public": true, "description": "Gaussian Naive Bayes (GaussianNB).\n\nCan perform online updates to model parameters via :meth:`partial_fit`. For details on algorithm used to update feature means and variance online, see Stanford CS tech report STAN-CS-79-773 by Chan, Golub, and LeVeque: http://i.stanford.edu/pub/cstr/reports/cs/tr/79/773/CS-TR-79-773.pdf Read more in the :ref:`User Guide `.", "docstring": "\n Gaussian Naive Bayes (GaussianNB).\n\n Can perform online updates to model parameters via :meth:`partial_fit`.\n For details on algorithm used to update feature means and variance online,\n see Stanford CS tech report STAN-CS-79-773 by Chan, Golub, and LeVeque:\n\n http://i.stanford.edu/pub/cstr/reports/cs/tr/79/773/CS-TR-79-773.pdf\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n priors : array-like of shape (n_classes,)\n Prior probabilities of the classes. If specified the priors are not\n adjusted according to the data.\n\n var_smoothing : float, default=1e-9\n Portion of the largest variance of all features that is added to\n variances for calculation stability.\n\n .. versionadded:: 0.20\n\n Attributes\n ----------\n class_count_ : ndarray of shape (n_classes,)\n number of training samples observed in each class.\n\n class_prior_ : ndarray of shape (n_classes,)\n probability of each class.\n\n classes_ : ndarray of shape (n_classes,)\n class labels known to the classifier.\n\n epsilon_ : float\n absolute additive value to variances.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n sigma_ : ndarray of shape (n_classes, n_features)\n Variance of each feature per class.\n\n .. deprecated:: 1.0\n `sigma_` is deprecated in 1.0 and will be removed in 1.2.\n Use `var_` instead.\n\n var_ : ndarray of shape (n_classes, n_features)\n Variance of each feature per class.\n\n .. versionadded:: 1.0\n\n theta_ : ndarray of shape (n_classes, n_features)\n mean of each feature per class.\n\n See Also\n --------\n BernoulliNB : Naive Bayes classifier for multivariate Bernoulli models.\n CategoricalNB : Naive Bayes classifier for categorical features.\n ComplementNB : Complement Naive Bayes classifier.\n MultinomialNB : Naive Bayes classifier for multinomial models.\n\n Examples\n --------\n >>> import numpy as np\n >>> X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])\n >>> Y = np.array([1, 1, 1, 2, 2, 2])\n >>> from sklearn.naive_bayes import GaussianNB\n >>> clf = GaussianNB()\n >>> clf.fit(X, Y)\n GaussianNB()\n >>> print(clf.predict([[-0.8, -1]]))\n [1]\n >>> clf_pf = GaussianNB()\n >>> clf_pf.partial_fit(X, Y, np.unique(Y))\n GaussianNB()\n >>> print(clf_pf.predict([[-0.8, -1]]))\n [1]\n ", - "source_code": "\n\nclass GaussianNB(_BaseNB):\n \"\"\"\n Gaussian Naive Bayes (GaussianNB).\n\n Can perform online updates to model parameters via :meth:`partial_fit`.\n For details on algorithm used to update feature means and variance online,\n see Stanford CS tech report STAN-CS-79-773 by Chan, Golub, and LeVeque:\n\n http://i.stanford.edu/pub/cstr/reports/cs/tr/79/773/CS-TR-79-773.pdf\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n priors : array-like of shape (n_classes,)\n Prior probabilities of the classes. If specified the priors are not\n adjusted according to the data.\n\n var_smoothing : float, default=1e-9\n Portion of the largest variance of all features that is added to\n variances for calculation stability.\n\n .. versionadded:: 0.20\n\n Attributes\n ----------\n class_count_ : ndarray of shape (n_classes,)\n number of training samples observed in each class.\n\n class_prior_ : ndarray of shape (n_classes,)\n probability of each class.\n\n classes_ : ndarray of shape (n_classes,)\n class labels known to the classifier.\n\n epsilon_ : float\n absolute additive value to variances.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n sigma_ : ndarray of shape (n_classes, n_features)\n Variance of each feature per class.\n\n .. deprecated:: 1.0\n `sigma_` is deprecated in 1.0 and will be removed in 1.2.\n Use `var_` instead.\n\n var_ : ndarray of shape (n_classes, n_features)\n Variance of each feature per class.\n\n .. versionadded:: 1.0\n\n theta_ : ndarray of shape (n_classes, n_features)\n mean of each feature per class.\n\n See Also\n --------\n BernoulliNB : Naive Bayes classifier for multivariate Bernoulli models.\n CategoricalNB : Naive Bayes classifier for categorical features.\n ComplementNB : Complement Naive Bayes classifier.\n MultinomialNB : Naive Bayes classifier for multinomial models.\n\n Examples\n --------\n >>> import numpy as np\n >>> X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])\n >>> Y = np.array([1, 1, 1, 2, 2, 2])\n >>> from sklearn.naive_bayes import GaussianNB\n >>> clf = GaussianNB()\n >>> clf.fit(X, Y)\n GaussianNB()\n >>> print(clf.predict([[-0.8, -1]]))\n [1]\n >>> clf_pf = GaussianNB()\n >>> clf_pf.partial_fit(X, Y, np.unique(Y))\n GaussianNB()\n >>> print(clf_pf.predict([[-0.8, -1]]))\n [1]\n \"\"\"\n \n def __init__(self, *, priors=None, var_smoothing=1e-09):\n self.priors = priors\n self.var_smoothing = var_smoothing\n \n def fit(self, X, y, sample_weight=None):\n \"\"\"Fit Gaussian Naive Bayes according to X, y.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples\n and `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target values.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Weights applied to individual samples (1. for unweighted).\n\n .. versionadded:: 0.17\n Gaussian Naive Bayes supports fitting with *sample_weight*.\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n (X, y) = self._validate_data(X, y)\n return self._partial_fit(X, y, np.unique(y), _refit=True, sample_weight=sample_weight)\n \n def _check_X(self, X):\n \"\"\"Validate X, used only in predict* methods.\"\"\"\n return self._validate_data(X, reset=False)\n \n @staticmethod\n def _update_mean_variance(n_past, mu, var, X, sample_weight=None):\n \"\"\"Compute online update of Gaussian mean and variance.\n\n Given starting sample count, mean, and variance, a new set of\n points X, and optionally sample weights, return the updated mean and\n variance. (NB - each dimension (column) in X is treated as independent\n -- you get variance, not covariance).\n\n Can take scalar mean and variance, or vector mean and variance to\n simultaneously update a number of independent Gaussians.\n\n See Stanford CS tech report STAN-CS-79-773 by Chan, Golub, and LeVeque:\n\n http://i.stanford.edu/pub/cstr/reports/cs/tr/79/773/CS-TR-79-773.pdf\n\n Parameters\n ----------\n n_past : int\n Number of samples represented in old mean and variance. If sample\n weights were given, this should contain the sum of sample\n weights represented in old mean and variance.\n\n mu : array-like of shape (number of Gaussians,)\n Means for Gaussians in original set.\n\n var : array-like of shape (number of Gaussians,)\n Variances for Gaussians in original set.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Weights applied to individual samples (1. for unweighted).\n\n Returns\n -------\n total_mu : array-like of shape (number of Gaussians,)\n Updated mean for each Gaussian over the combined set.\n\n total_var : array-like of shape (number of Gaussians,)\n Updated variance for each Gaussian over the combined set.\n \"\"\"\n if X.shape[0] == 0:\n return mu, var\n if sample_weight is not None:\n n_new = float(sample_weight.sum())\n new_mu = np.average(X, axis=0, weights=sample_weight)\n new_var = np.average((X - new_mu)**2, axis=0, weights=sample_weight)\n else:\n n_new = X.shape[0]\n new_var = np.var(X, axis=0)\n new_mu = np.mean(X, axis=0)\n if n_past == 0:\n return new_mu, new_var\n n_total = float(n_past + n_new)\n total_mu = (n_new * new_mu + n_past * mu) / n_total\n old_ssd = n_past * var\n new_ssd = n_new * new_var\n total_ssd = old_ssd + new_ssd + n_new * n_past / n_total * (mu - new_mu)**2\n total_var = total_ssd / n_total\n return total_mu, total_var\n \n def partial_fit(self, X, y, classes=None, sample_weight=None):\n \"\"\"Incremental fit on a batch of samples.\n\n This method is expected to be called several times consecutively\n on different chunks of a dataset so as to implement out-of-core\n or online learning.\n\n This is especially useful when the whole dataset is too big to fit in\n memory at once.\n\n This method has some performance and numerical stability overhead,\n hence it is better to call partial_fit on chunks of data that are\n as large as possible (as long as fitting in the memory budget) to\n hide the overhead.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target values.\n\n classes : array-like of shape (n_classes,), default=None\n List of all the classes that can possibly appear in the y vector.\n\n Must be provided at the first call to partial_fit, can be omitted\n in subsequent calls.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Weights applied to individual samples (1. for unweighted).\n\n .. versionadded:: 0.17\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n return self._partial_fit(X, y, classes, _refit=False, sample_weight=sample_weight)\n \n def _partial_fit(self, X, y, classes=None, _refit=False, sample_weight=None):\n \"\"\"Actual implementation of Gaussian NB fitting.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target values.\n\n classes : array-like of shape (n_classes,), default=None\n List of all the classes that can possibly appear in the y vector.\n\n Must be provided at the first call to partial_fit, can be omitted\n in subsequent calls.\n\n _refit : bool, default=False\n If true, act as though this were the first time we called\n _partial_fit (ie, throw away any past fitting and start over).\n\n sample_weight : array-like of shape (n_samples,), default=None\n Weights applied to individual samples (1. for unweighted).\n\n Returns\n -------\n self : object\n \"\"\"\n if _refit:\n self.classes_ = None\n first_call = _check_partial_fit_first_call(self, classes)\n (X, y) = self._validate_data(X, y, reset=first_call)\n if sample_weight is not None:\n sample_weight = _check_sample_weight(sample_weight, X)\n self.epsilon_ = self.var_smoothing * np.var(X, axis=0).max()\n if first_call:\n n_features = X.shape[1]\n n_classes = len(self.classes_)\n self.theta_ = np.zeros((n_classes, n_features))\n self.var_ = np.zeros((n_classes, n_features))\n self.class_count_ = np.zeros(n_classes, dtype=np.float64)\n if self.priors is not None:\n priors = np.asarray(self.priors)\n if len(priors) != n_classes:\n raise ValueError('Number of priors must match number of classes.')\n if not np.isclose(priors.sum(), 1.0):\n raise ValueError('The sum of the priors should be 1.')\n if (priors < 0).any():\n raise ValueError('Priors must be non-negative.')\n self.class_prior_ = priors\n else:\n self.class_prior_ = np.zeros(len(self.classes_), dtype=np.float64)\n else:\n if X.shape[1] != self.theta_.shape[1]:\n msg = 'Number of features %d does not match previous data %d.'\n raise ValueError(msg % (X.shape[1], self.theta_.shape[1]))\n self.var_[:, :] -= self.epsilon_\n classes = self.classes_\n unique_y = np.unique(y)\n unique_y_in_classes = np.in1d(unique_y, classes)\n if not np.all(unique_y_in_classes):\n raise ValueError('The target label(s) %s in y do not exist in the initial classes %s' % (unique_y[~unique_y_in_classes], classes))\n for y_i in unique_y:\n i = classes.searchsorted(y_i)\n X_i = X[y == y_i, :]\n if sample_weight is not None:\n sw_i = sample_weight[y == y_i]\n N_i = sw_i.sum()\n else:\n sw_i = None\n N_i = X_i.shape[0]\n (new_theta, new_sigma) = self._update_mean_variance(self.class_count_[i], self.theta_[i, :], self.var_[i, :], X_i, sw_i)\n self.theta_[i, :] = new_theta\n self.var_[i, :] = new_sigma\n self.class_count_[i] += N_i\n self.var_[:, :] += self.epsilon_\n if self.priors is None:\n self.class_prior_ = self.class_count_ / self.class_count_.sum()\n return self\n \n def _joint_log_likelihood(self, X):\n joint_log_likelihood = []\n for i in range(np.size(self.classes_)):\n jointi = np.log(self.class_prior_[i])\n n_ij = -0.5 * np.sum(np.log(2.0 * np.pi * self.var_[i, :]))\n n_ij -= 0.5 * np.sum((X - self.theta_[i, :])**2 / self.var_[i, :], 1)\n joint_log_likelihood.append(jointi + n_ij)\n joint_log_likelihood = np.array(joint_log_likelihood).T\n return joint_log_likelihood\n \n @deprecated('Attribute `sigma_` was deprecated in 1.0 and will be removed in1.2. Use `var_` instead.')\n @property\n def sigma_(self):\n return self.var_\n" + "source_code": "\n\nclass GaussianNB(_BaseNB):\n \"\"\"\n Gaussian Naive Bayes (GaussianNB).\n\n Can perform online updates to model parameters via :meth:`partial_fit`.\n For details on algorithm used to update feature means and variance online,\n see Stanford CS tech report STAN-CS-79-773 by Chan, Golub, and LeVeque:\n\n http://i.stanford.edu/pub/cstr/reports/cs/tr/79/773/CS-TR-79-773.pdf\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n priors : array-like of shape (n_classes,)\n Prior probabilities of the classes. If specified the priors are not\n adjusted according to the data.\n\n var_smoothing : float, default=1e-9\n Portion of the largest variance of all features that is added to\n variances for calculation stability.\n\n .. versionadded:: 0.20\n\n Attributes\n ----------\n class_count_ : ndarray of shape (n_classes,)\n number of training samples observed in each class.\n\n class_prior_ : ndarray of shape (n_classes,)\n probability of each class.\n\n classes_ : ndarray of shape (n_classes,)\n class labels known to the classifier.\n\n epsilon_ : float\n absolute additive value to variances.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n sigma_ : ndarray of shape (n_classes, n_features)\n Variance of each feature per class.\n\n .. deprecated:: 1.0\n `sigma_` is deprecated in 1.0 and will be removed in 1.2.\n Use `var_` instead.\n\n var_ : ndarray of shape (n_classes, n_features)\n Variance of each feature per class.\n\n .. versionadded:: 1.0\n\n theta_ : ndarray of shape (n_classes, n_features)\n mean of each feature per class.\n\n See Also\n --------\n BernoulliNB : Naive Bayes classifier for multivariate Bernoulli models.\n CategoricalNB : Naive Bayes classifier for categorical features.\n ComplementNB : Complement Naive Bayes classifier.\n MultinomialNB : Naive Bayes classifier for multinomial models.\n\n Examples\n --------\n >>> import numpy as np\n >>> X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])\n >>> Y = np.array([1, 1, 1, 2, 2, 2])\n >>> from sklearn.naive_bayes import GaussianNB\n >>> clf = GaussianNB()\n >>> clf.fit(X, Y)\n GaussianNB()\n >>> print(clf.predict([[-0.8, -1]]))\n [1]\n >>> clf_pf = GaussianNB()\n >>> clf_pf.partial_fit(X, Y, np.unique(Y))\n GaussianNB()\n >>> print(clf_pf.predict([[-0.8, -1]]))\n [1]\n \"\"\"\n \n def __init__(self, *, priors=None, var_smoothing=1e-09):\n self.priors = priors\n self.var_smoothing = var_smoothing\n \n def fit(self, X, y, sample_weight=None):\n \"\"\"Fit Gaussian Naive Bayes according to X, y.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples\n and `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target values.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Weights applied to individual samples (1. for unweighted).\n\n .. versionadded:: 0.17\n Gaussian Naive Bayes supports fitting with *sample_weight*.\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n y = self._validate_data(y=y)\n return self._partial_fit(X, y, np.unique(y), _refit=True, sample_weight=sample_weight)\n \n def _check_X(self, X):\n \"\"\"Validate X, used only in predict* methods.\"\"\"\n return self._validate_data(X, reset=False)\n \n @staticmethod\n def _update_mean_variance(n_past, mu, var, X, sample_weight=None):\n \"\"\"Compute online update of Gaussian mean and variance.\n\n Given starting sample count, mean, and variance, a new set of\n points X, and optionally sample weights, return the updated mean and\n variance. (NB - each dimension (column) in X is treated as independent\n -- you get variance, not covariance).\n\n Can take scalar mean and variance, or vector mean and variance to\n simultaneously update a number of independent Gaussians.\n\n See Stanford CS tech report STAN-CS-79-773 by Chan, Golub, and LeVeque:\n\n http://i.stanford.edu/pub/cstr/reports/cs/tr/79/773/CS-TR-79-773.pdf\n\n Parameters\n ----------\n n_past : int\n Number of samples represented in old mean and variance. If sample\n weights were given, this should contain the sum of sample\n weights represented in old mean and variance.\n\n mu : array-like of shape (number of Gaussians,)\n Means for Gaussians in original set.\n\n var : array-like of shape (number of Gaussians,)\n Variances for Gaussians in original set.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Weights applied to individual samples (1. for unweighted).\n\n Returns\n -------\n total_mu : array-like of shape (number of Gaussians,)\n Updated mean for each Gaussian over the combined set.\n\n total_var : array-like of shape (number of Gaussians,)\n Updated variance for each Gaussian over the combined set.\n \"\"\"\n if X.shape[0] == 0:\n return mu, var\n if sample_weight is not None:\n n_new = float(sample_weight.sum())\n new_mu = np.average(X, axis=0, weights=sample_weight)\n new_var = np.average((X - new_mu)**2, axis=0, weights=sample_weight)\n else:\n n_new = X.shape[0]\n new_var = np.var(X, axis=0)\n new_mu = np.mean(X, axis=0)\n if n_past == 0:\n return new_mu, new_var\n n_total = float(n_past + n_new)\n total_mu = (n_new * new_mu + n_past * mu) / n_total\n old_ssd = n_past * var\n new_ssd = n_new * new_var\n total_ssd = old_ssd + new_ssd + n_new * n_past / n_total * (mu - new_mu)**2\n total_var = total_ssd / n_total\n return total_mu, total_var\n \n def partial_fit(self, X, y, classes=None, sample_weight=None):\n \"\"\"Incremental fit on a batch of samples.\n\n This method is expected to be called several times consecutively\n on different chunks of a dataset so as to implement out-of-core\n or online learning.\n\n This is especially useful when the whole dataset is too big to fit in\n memory at once.\n\n This method has some performance and numerical stability overhead,\n hence it is better to call partial_fit on chunks of data that are\n as large as possible (as long as fitting in the memory budget) to\n hide the overhead.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target values.\n\n classes : array-like of shape (n_classes,), default=None\n List of all the classes that can possibly appear in the y vector.\n\n Must be provided at the first call to partial_fit, can be omitted\n in subsequent calls.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Weights applied to individual samples (1. for unweighted).\n\n .. versionadded:: 0.17\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n return self._partial_fit(X, y, classes, _refit=False, sample_weight=sample_weight)\n \n def _partial_fit(self, X, y, classes=None, _refit=False, sample_weight=None):\n \"\"\"Actual implementation of Gaussian NB fitting.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target values.\n\n classes : array-like of shape (n_classes,), default=None\n List of all the classes that can possibly appear in the y vector.\n\n Must be provided at the first call to partial_fit, can be omitted\n in subsequent calls.\n\n _refit : bool, default=False\n If true, act as though this were the first time we called\n _partial_fit (ie, throw away any past fitting and start over).\n\n sample_weight : array-like of shape (n_samples,), default=None\n Weights applied to individual samples (1. for unweighted).\n\n Returns\n -------\n self : object\n \"\"\"\n if _refit:\n self.classes_ = None\n first_call = _check_partial_fit_first_call(self, classes)\n (X, y) = self._validate_data(X, y, reset=first_call)\n if sample_weight is not None:\n sample_weight = _check_sample_weight(sample_weight, X)\n self.epsilon_ = self.var_smoothing * np.var(X, axis=0).max()\n if first_call:\n n_features = X.shape[1]\n n_classes = len(self.classes_)\n self.theta_ = np.zeros((n_classes, n_features))\n self.var_ = np.zeros((n_classes, n_features))\n self.class_count_ = np.zeros(n_classes, dtype=np.float64)\n if self.priors is not None:\n priors = np.asarray(self.priors)\n if len(priors) != n_classes:\n raise ValueError('Number of priors must match number of classes.')\n if not np.isclose(priors.sum(), 1.0):\n raise ValueError('The sum of the priors should be 1.')\n if (priors < 0).any():\n raise ValueError('Priors must be non-negative.')\n self.class_prior_ = priors\n else:\n self.class_prior_ = np.zeros(len(self.classes_), dtype=np.float64)\n else:\n if X.shape[1] != self.theta_.shape[1]:\n msg = 'Number of features %d does not match previous data %d.'\n raise ValueError(msg % (X.shape[1], self.theta_.shape[1]))\n self.var_[:, :] -= self.epsilon_\n classes = self.classes_\n unique_y = np.unique(y)\n unique_y_in_classes = np.in1d(unique_y, classes)\n if not np.all(unique_y_in_classes):\n raise ValueError('The target label(s) %s in y do not exist in the initial classes %s' % (unique_y[~unique_y_in_classes], classes))\n for y_i in unique_y:\n i = classes.searchsorted(y_i)\n X_i = X[y == y_i, :]\n if sample_weight is not None:\n sw_i = sample_weight[y == y_i]\n N_i = sw_i.sum()\n else:\n sw_i = None\n N_i = X_i.shape[0]\n (new_theta, new_sigma) = self._update_mean_variance(self.class_count_[i], self.theta_[i, :], self.var_[i, :], X_i, sw_i)\n self.theta_[i, :] = new_theta\n self.var_[i, :] = new_sigma\n self.class_count_[i] += N_i\n self.var_[:, :] += self.epsilon_\n if self.priors is None:\n self.class_prior_ = self.class_count_ / self.class_count_.sum()\n return self\n \n def _joint_log_likelihood(self, X):\n joint_log_likelihood = []\n for i in range(np.size(self.classes_)):\n jointi = np.log(self.class_prior_[i])\n n_ij = -0.5 * np.sum(np.log(2.0 * np.pi * self.var_[i, :]))\n n_ij -= 0.5 * np.sum((X - self.theta_[i, :])**2 / self.var_[i, :], 1)\n joint_log_likelihood.append(jointi + n_ij)\n joint_log_likelihood = np.array(joint_log_likelihood).T\n return joint_log_likelihood\n \n @deprecated('Attribute `sigma_` was deprecated in 1.0 and will be removed in1.2. Use `var_` instead.')\n @property\n def sigma_(self):\n return self.var_\n" }, { "name": "MultinomialNB", @@ -25341,10 +25294,10 @@ "sklearn.naive_bayes._BaseDiscreteNB.partial_fit", "sklearn.naive_bayes._BaseDiscreteNB.fit", "sklearn.naive_bayes._BaseDiscreteNB._init_counters", - "sklearn.naive_bayes._BaseDiscreteNB.coef_", - "sklearn.naive_bayes._BaseDiscreteNB.intercept_", + "sklearn.naive_bayes._BaseDiscreteNB.coef_@getter", + "sklearn.naive_bayes._BaseDiscreteNB.intercept_@getter", "sklearn.naive_bayes._BaseDiscreteNB._more_tags", - "sklearn.naive_bayes._BaseDiscreteNB.n_features_" + "sklearn.naive_bayes._BaseDiscreteNB.n_features_@getter" ], "is_public": false, "description": "Abstract base class for naive Bayes on discrete/categorical data\n\nAny estimator based on this class should provide: __init__ _joint_log_likelihood(X) as per _BaseNB", @@ -25393,7 +25346,7 @@ "sklearn.neighbors._base.NeighborsBase._check_algorithm_metric", "sklearn.neighbors._base.NeighborsBase._fit", "sklearn.neighbors._base.NeighborsBase._more_tags", - "sklearn.neighbors._base.NeighborsBase._pairwise" + "sklearn.neighbors._base.NeighborsBase._pairwise@getter" ], "is_public": false, "description": "Base class for nearest neighbors estimators.", @@ -25434,7 +25387,7 @@ "is_public": true, "description": "Classifier implementing the k-nearest neighbors vote.\n\nRead more in the :ref:`User Guide `.", "docstring": "Classifier implementing the k-nearest neighbors vote.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_neighbors : int, default=5\n Number of neighbors to use by default for :meth:`kneighbors` queries.\n\n weights : {'uniform', 'distance'} or callable, default='uniform'\n Weight function used in prediction. Possible values:\n\n - 'uniform' : uniform weights. All points in each neighborhood\n are weighted equally.\n - 'distance' : weight points by the inverse of their distance.\n in this case, closer neighbors of a query point will have a\n greater influence than neighbors which are further away.\n - [callable] : a user-defined function which accepts an\n array of distances, and returns an array of the same shape\n containing the weights.\n\n algorithm : {'auto', 'ball_tree', 'kd_tree', 'brute'}, default='auto'\n Algorithm used to compute the nearest neighbors:\n\n - 'ball_tree' will use :class:`BallTree`\n - 'kd_tree' will use :class:`KDTree`\n - 'brute' will use a brute-force search.\n - 'auto' will attempt to decide the most appropriate algorithm\n based on the values passed to :meth:`fit` method.\n\n Note: fitting on sparse input will override the setting of\n this parameter, using brute force.\n\n leaf_size : int, default=30\n Leaf size passed to BallTree or KDTree. This can affect the\n speed of the construction and query, as well as the memory\n required to store the tree. The optimal value depends on the\n nature of the problem.\n\n p : int, default=2\n Power parameter for the Minkowski metric. When p = 1, this is\n equivalent to using manhattan_distance (l1), and euclidean_distance\n (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used.\n\n metric : str or callable, default='minkowski'\n The distance metric to use for the tree. The default metric is\n minkowski, and with p=2 is equivalent to the standard Euclidean\n metric. See the documentation of :class:`DistanceMetric` for a\n list of available metrics.\n If metric is \"precomputed\", X is assumed to be a distance matrix and\n must be square during fit. X may be a :term:`sparse graph`,\n in which case only \"nonzero\" elements may be considered neighbors.\n\n metric_params : dict, default=None\n Additional keyword arguments for the metric function.\n\n n_jobs : int, default=None\n The number of parallel jobs to run for neighbors search.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n Doesn't affect :meth:`fit` method.\n\n Attributes\n ----------\n classes_ : array of shape (n_classes,)\n Class labels known to the classifier\n\n effective_metric_ : str or callble\n The distance metric used. It will be same as the `metric` parameter\n or a synonym of it, e.g. 'euclidean' if the `metric` parameter set to\n 'minkowski' and `p` parameter set to 2.\n\n effective_metric_params_ : dict\n Additional keyword arguments for the metric function. For most metrics\n will be same with `metric_params` parameter, but may also contain the\n `p` parameter value if the `effective_metric_` attribute is set to\n 'minkowski'.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_samples_fit_ : int\n Number of samples in the fitted data.\n\n outputs_2d_ : bool\n False when `y`'s shape is (n_samples, ) or (n_samples, 1) during fit\n otherwise True.\n\n See Also\n --------\n RadiusNeighborsClassifier: Classifier based on neighbors within a fixed radius.\n KNeighborsRegressor: Regression based on k-nearest neighbors.\n RadiusNeighborsRegressor: Regression based on neighbors within a fixed radius.\n NearestNeighbors: Unsupervised learner for implementing neighbor searches.\n\n Notes\n -----\n See :ref:`Nearest Neighbors ` in the online documentation\n for a discussion of the choice of ``algorithm`` and ``leaf_size``.\n\n .. warning::\n\n Regarding the Nearest Neighbors algorithms, if it is found that two\n neighbors, neighbor `k+1` and `k`, have identical distances\n but different labels, the results will depend on the ordering of the\n training data.\n\n https://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm\n\n Examples\n --------\n >>> X = [[0], [1], [2], [3]]\n >>> y = [0, 0, 1, 1]\n >>> from sklearn.neighbors import KNeighborsClassifier\n >>> neigh = KNeighborsClassifier(n_neighbors=3)\n >>> neigh.fit(X, y)\n KNeighborsClassifier(...)\n >>> print(neigh.predict([[1.1]]))\n [0]\n >>> print(neigh.predict_proba([[0.9]]))\n [[0.666... 0.333...]]\n ", - "source_code": "\n\nclass KNeighborsClassifier(KNeighborsMixin, ClassifierMixin, NeighborsBase):\n \"\"\"Classifier implementing the k-nearest neighbors vote.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_neighbors : int, default=5\n Number of neighbors to use by default for :meth:`kneighbors` queries.\n\n weights : {'uniform', 'distance'} or callable, default='uniform'\n Weight function used in prediction. Possible values:\n\n - 'uniform' : uniform weights. All points in each neighborhood\n are weighted equally.\n - 'distance' : weight points by the inverse of their distance.\n in this case, closer neighbors of a query point will have a\n greater influence than neighbors which are further away.\n - [callable] : a user-defined function which accepts an\n array of distances, and returns an array of the same shape\n containing the weights.\n\n algorithm : {'auto', 'ball_tree', 'kd_tree', 'brute'}, default='auto'\n Algorithm used to compute the nearest neighbors:\n\n - 'ball_tree' will use :class:`BallTree`\n - 'kd_tree' will use :class:`KDTree`\n - 'brute' will use a brute-force search.\n - 'auto' will attempt to decide the most appropriate algorithm\n based on the values passed to :meth:`fit` method.\n\n Note: fitting on sparse input will override the setting of\n this parameter, using brute force.\n\n leaf_size : int, default=30\n Leaf size passed to BallTree or KDTree. This can affect the\n speed of the construction and query, as well as the memory\n required to store the tree. The optimal value depends on the\n nature of the problem.\n\n p : int, default=2\n Power parameter for the Minkowski metric. When p = 1, this is\n equivalent to using manhattan_distance (l1), and euclidean_distance\n (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used.\n\n metric : str or callable, default='minkowski'\n The distance metric to use for the tree. The default metric is\n minkowski, and with p=2 is equivalent to the standard Euclidean\n metric. See the documentation of :class:`DistanceMetric` for a\n list of available metrics.\n If metric is \"precomputed\", X is assumed to be a distance matrix and\n must be square during fit. X may be a :term:`sparse graph`,\n in which case only \"nonzero\" elements may be considered neighbors.\n\n metric_params : dict, default=None\n Additional keyword arguments for the metric function.\n\n n_jobs : int, default=None\n The number of parallel jobs to run for neighbors search.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n Doesn't affect :meth:`fit` method.\n\n Attributes\n ----------\n classes_ : array of shape (n_classes,)\n Class labels known to the classifier\n\n effective_metric_ : str or callble\n The distance metric used. It will be same as the `metric` parameter\n or a synonym of it, e.g. 'euclidean' if the `metric` parameter set to\n 'minkowski' and `p` parameter set to 2.\n\n effective_metric_params_ : dict\n Additional keyword arguments for the metric function. For most metrics\n will be same with `metric_params` parameter, but may also contain the\n `p` parameter value if the `effective_metric_` attribute is set to\n 'minkowski'.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_samples_fit_ : int\n Number of samples in the fitted data.\n\n outputs_2d_ : bool\n False when `y`'s shape is (n_samples, ) or (n_samples, 1) during fit\n otherwise True.\n\n See Also\n --------\n RadiusNeighborsClassifier: Classifier based on neighbors within a fixed radius.\n KNeighborsRegressor: Regression based on k-nearest neighbors.\n RadiusNeighborsRegressor: Regression based on neighbors within a fixed radius.\n NearestNeighbors: Unsupervised learner for implementing neighbor searches.\n\n Notes\n -----\n See :ref:`Nearest Neighbors ` in the online documentation\n for a discussion of the choice of ``algorithm`` and ``leaf_size``.\n\n .. warning::\n\n Regarding the Nearest Neighbors algorithms, if it is found that two\n neighbors, neighbor `k+1` and `k`, have identical distances\n but different labels, the results will depend on the ordering of the\n training data.\n\n https://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm\n\n Examples\n --------\n >>> X = [[0], [1], [2], [3]]\n >>> y = [0, 0, 1, 1]\n >>> from sklearn.neighbors import KNeighborsClassifier\n >>> neigh = KNeighborsClassifier(n_neighbors=3)\n >>> neigh.fit(X, y)\n KNeighborsClassifier(...)\n >>> print(neigh.predict([[1.1]]))\n [0]\n >>> print(neigh.predict_proba([[0.9]]))\n [[0.666... 0.333...]]\n \"\"\"\n \n def __init__(self, n_neighbors=5, *, weights='uniform', algorithm='auto', leaf_size=30, p=2, metric='minkowski', metric_params=None, n_jobs=None):\n super().__init__(n_neighbors=n_neighbors, algorithm=algorithm, leaf_size=leaf_size, metric=metric, p=p, metric_params=metric_params, n_jobs=n_jobs)\n self.weights = weights\n \n def fit(self, X, y):\n \"\"\"Fit the k-nearest neighbors classifier from the training dataset.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples) if metric='precomputed'\n Training data.\n\n y : {array-like, sparse matrix} of shape (n_samples,) or (n_samples, n_outputs)\n Target values.\n\n Returns\n -------\n self : KNeighborsClassifier\n The fitted k-nearest neighbors classifier.\n \"\"\"\n self.weights = _check_weights(self.weights)\n return self._fit(X, y)\n \n def predict(self, X):\n \"\"\"Predict the class labels for the provided data.\n\n Parameters\n ----------\n X : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\n Returns\n -------\n y : ndarray of shape (n_queries,) or (n_queries, n_outputs)\n Class labels for each data sample.\n \"\"\"\n X = self._validate_data(X, accept_sparse='csr', reset=False)\n (neigh_dist, neigh_ind) = self.kneighbors(X)\n classes_ = self.classes_\n _y = self._y\n if not self.outputs_2d_:\n _y = self._y.reshape((-1, 1))\n classes_ = [self.classes_]\n n_outputs = len(classes_)\n n_queries = _num_samples(X)\n weights = _get_weights(neigh_dist, self.weights)\n y_pred = np.empty((n_queries, n_outputs), dtype=classes_[0].dtype)\n for (k, classes_k) in enumerate(classes_):\n if weights is None:\n (mode, _) = stats.mode(_y[neigh_ind, k], axis=1)\n else:\n (mode, _) = weighted_mode(_y[neigh_ind, k], weights, axis=1)\n mode = np.asarray(mode.ravel(), dtype=np.intp)\n y_pred[:, k] = classes_k.take(mode)\n if not self.outputs_2d_:\n y_pred = y_pred.ravel()\n return y_pred\n \n def predict_proba(self, X):\n \"\"\"Return probability estimates for the test data X.\n\n Parameters\n ----------\n X : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\n Returns\n -------\n p : ndarray of shape (n_queries, n_classes), or a list of n_outputs of such arrays if n_outputs > 1.\n The class probabilities of the input samples. Classes are ordered\n by lexicographic order.\n \"\"\"\n X = self._validate_data(X, accept_sparse='csr', reset=False)\n (neigh_dist, neigh_ind) = self.kneighbors(X)\n classes_ = self.classes_\n _y = self._y\n if not self.outputs_2d_:\n _y = self._y.reshape((-1, 1))\n classes_ = [self.classes_]\n n_queries = _num_samples(X)\n weights = _get_weights(neigh_dist, self.weights)\n if weights is None:\n weights = np.ones_like(neigh_ind)\n all_rows = np.arange(X.shape[0])\n probabilities = []\n for (k, classes_k) in enumerate(classes_):\n pred_labels = _y[:, k][neigh_ind]\n proba_k = np.zeros((n_queries, classes_k.size))\n for (i, idx) in enumerate(pred_labels.T):\n proba_k[all_rows, idx] += weights[:, i]\n normalizer = proba_k.sum(axis=1)[:, np.newaxis]\n normalizer[normalizer == 0.0] = 1.0\n proba_k /= normalizer\n probabilities.append(proba_k)\n if not self.outputs_2d_:\n probabilities = probabilities[0]\n return probabilities\n \n def _more_tags(self):\n return {'multilabel': True}\n" + "source_code": "\n\nclass KNeighborsClassifier(KNeighborsMixin, ClassifierMixin, NeighborsBase):\n \"\"\"Classifier implementing the k-nearest neighbors vote.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_neighbors : int, default=5\n Number of neighbors to use by default for :meth:`kneighbors` queries.\n\n weights : {'uniform', 'distance'} or callable, default='uniform'\n Weight function used in prediction. Possible values:\n\n - 'uniform' : uniform weights. All points in each neighborhood\n are weighted equally.\n - 'distance' : weight points by the inverse of their distance.\n in this case, closer neighbors of a query point will have a\n greater influence than neighbors which are further away.\n - [callable] : a user-defined function which accepts an\n array of distances, and returns an array of the same shape\n containing the weights.\n\n algorithm : {'auto', 'ball_tree', 'kd_tree', 'brute'}, default='auto'\n Algorithm used to compute the nearest neighbors:\n\n - 'ball_tree' will use :class:`BallTree`\n - 'kd_tree' will use :class:`KDTree`\n - 'brute' will use a brute-force search.\n - 'auto' will attempt to decide the most appropriate algorithm\n based on the values passed to :meth:`fit` method.\n\n Note: fitting on sparse input will override the setting of\n this parameter, using brute force.\n\n leaf_size : int, default=30\n Leaf size passed to BallTree or KDTree. This can affect the\n speed of the construction and query, as well as the memory\n required to store the tree. The optimal value depends on the\n nature of the problem.\n\n p : int, default=2\n Power parameter for the Minkowski metric. When p = 1, this is\n equivalent to using manhattan_distance (l1), and euclidean_distance\n (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used.\n\n metric : str or callable, default='minkowski'\n The distance metric to use for the tree. The default metric is\n minkowski, and with p=2 is equivalent to the standard Euclidean\n metric. See the documentation of :class:`DistanceMetric` for a\n list of available metrics.\n If metric is \"precomputed\", X is assumed to be a distance matrix and\n must be square during fit. X may be a :term:`sparse graph`,\n in which case only \"nonzero\" elements may be considered neighbors.\n\n metric_params : dict, default=None\n Additional keyword arguments for the metric function.\n\n n_jobs : int, default=None\n The number of parallel jobs to run for neighbors search.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n Doesn't affect :meth:`fit` method.\n\n Attributes\n ----------\n classes_ : array of shape (n_classes,)\n Class labels known to the classifier\n\n effective_metric_ : str or callble\n The distance metric used. It will be same as the `metric` parameter\n or a synonym of it, e.g. 'euclidean' if the `metric` parameter set to\n 'minkowski' and `p` parameter set to 2.\n\n effective_metric_params_ : dict\n Additional keyword arguments for the metric function. For most metrics\n will be same with `metric_params` parameter, but may also contain the\n `p` parameter value if the `effective_metric_` attribute is set to\n 'minkowski'.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_samples_fit_ : int\n Number of samples in the fitted data.\n\n outputs_2d_ : bool\n False when `y`'s shape is (n_samples, ) or (n_samples, 1) during fit\n otherwise True.\n\n See Also\n --------\n RadiusNeighborsClassifier: Classifier based on neighbors within a fixed radius.\n KNeighborsRegressor: Regression based on k-nearest neighbors.\n RadiusNeighborsRegressor: Regression based on neighbors within a fixed radius.\n NearestNeighbors: Unsupervised learner for implementing neighbor searches.\n\n Notes\n -----\n See :ref:`Nearest Neighbors ` in the online documentation\n for a discussion of the choice of ``algorithm`` and ``leaf_size``.\n\n .. warning::\n\n Regarding the Nearest Neighbors algorithms, if it is found that two\n neighbors, neighbor `k+1` and `k`, have identical distances\n but different labels, the results will depend on the ordering of the\n training data.\n\n https://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm\n\n Examples\n --------\n >>> X = [[0], [1], [2], [3]]\n >>> y = [0, 0, 1, 1]\n >>> from sklearn.neighbors import KNeighborsClassifier\n >>> neigh = KNeighborsClassifier(n_neighbors=3)\n >>> neigh.fit(X, y)\n KNeighborsClassifier(...)\n >>> print(neigh.predict([[1.1]]))\n [0]\n >>> print(neigh.predict_proba([[0.9]]))\n [[0.666... 0.333...]]\n \"\"\"\n \n def __init__(self, n_neighbors=5, *, weights='uniform', algorithm='auto', leaf_size=30, p=2, metric='minkowski', metric_params=None, n_jobs=None):\n super().__init__(n_neighbors=n_neighbors, algorithm=algorithm, leaf_size=leaf_size, metric=metric, p=p, metric_params=metric_params, n_jobs=n_jobs)\n self.weights = weights\n \n def fit(self, X, y):\n \"\"\"Fit the k-nearest neighbors classifier from the training dataset.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples) if metric='precomputed'\n Training data.\n\n y : {array-like, sparse matrix} of shape (n_samples,) or (n_samples, n_outputs)\n Target values.\n\n Returns\n -------\n self : KNeighborsClassifier\n The fitted k-nearest neighbors classifier.\n \"\"\"\n self.weights = _check_weights(self.weights)\n return self._fit(X, y)\n \n def predict(self, X):\n \"\"\"Predict the class labels for the provided data.\n\n Parameters\n ----------\n X : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\n Returns\n -------\n y : ndarray of shape (n_queries,) or (n_queries, n_outputs)\n Class labels for each data sample.\n \"\"\"\n (neigh_dist, neigh_ind) = self.kneighbors(X)\n classes_ = self.classes_\n _y = self._y\n if not self.outputs_2d_:\n _y = self._y.reshape((-1, 1))\n classes_ = [self.classes_]\n n_outputs = len(classes_)\n n_queries = _num_samples(X)\n weights = _get_weights(neigh_dist, self.weights)\n y_pred = np.empty((n_queries, n_outputs), dtype=classes_[0].dtype)\n for (k, classes_k) in enumerate(classes_):\n if weights is None:\n (mode, _) = stats.mode(_y[neigh_ind, k], axis=1)\n else:\n (mode, _) = weighted_mode(_y[neigh_ind, k], weights, axis=1)\n mode = np.asarray(mode.ravel(), dtype=np.intp)\n y_pred[:, k] = classes_k.take(mode)\n if not self.outputs_2d_:\n y_pred = y_pred.ravel()\n return y_pred\n \n def predict_proba(self, X):\n \"\"\"Return probability estimates for the test data X.\n\n Parameters\n ----------\n X : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\n Returns\n -------\n p : ndarray of shape (n_queries, n_classes), or a list of n_outputs of such arrays if n_outputs > 1.\n The class probabilities of the input samples. Classes are ordered\n by lexicographic order.\n \"\"\"\n (neigh_dist, neigh_ind) = self.kneighbors(X)\n classes_ = self.classes_\n _y = self._y\n if not self.outputs_2d_:\n _y = self._y.reshape((-1, 1))\n classes_ = [self.classes_]\n n_queries = _num_samples(X)\n weights = _get_weights(neigh_dist, self.weights)\n if weights is None:\n weights = np.ones_like(neigh_ind)\n all_rows = np.arange(n_queries)\n probabilities = []\n for (k, classes_k) in enumerate(classes_):\n pred_labels = _y[:, k][neigh_ind]\n proba_k = np.zeros((n_queries, classes_k.size))\n for (i, idx) in enumerate(pred_labels.T):\n proba_k[all_rows, idx] += weights[:, i]\n normalizer = proba_k.sum(axis=1)[:, np.newaxis]\n normalizer[normalizer == 0.0] = 1.0\n proba_k /= normalizer\n probabilities.append(proba_k)\n if not self.outputs_2d_:\n probabilities = probabilities[0]\n return probabilities\n \n def _more_tags(self):\n return {'multilabel': True}\n" }, { "name": "RadiusNeighborsClassifier", @@ -25455,7 +25408,7 @@ "is_public": true, "description": "Classifier implementing a vote among neighbors within a given radius.\n\nRead more in the :ref:`User Guide `.", "docstring": "Classifier implementing a vote among neighbors within a given radius.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n radius : float, default=1.0\n Range of parameter space to use by default for :meth:`radius_neighbors`\n queries.\n\n weights : {'uniform', 'distance'} or callable, default='uniform'\n Weight function used in prediction. Possible values:\n\n - 'uniform' : uniform weights. All points in each neighborhood\n are weighted equally.\n - 'distance' : weight points by the inverse of their distance.\n in this case, closer neighbors of a query point will have a\n greater influence than neighbors which are further away.\n - [callable] : a user-defined function which accepts an\n array of distances, and returns an array of the same shape\n containing the weights.\n\n Uniform weights are used by default.\n\n algorithm : {'auto', 'ball_tree', 'kd_tree', 'brute'}, default='auto'\n Algorithm used to compute the nearest neighbors:\n\n - 'ball_tree' will use :class:`BallTree`\n - 'kd_tree' will use :class:`KDTree`\n - 'brute' will use a brute-force search.\n - 'auto' will attempt to decide the most appropriate algorithm\n based on the values passed to :meth:`fit` method.\n\n Note: fitting on sparse input will override the setting of\n this parameter, using brute force.\n\n leaf_size : int, default=30\n Leaf size passed to BallTree or KDTree. This can affect the\n speed of the construction and query, as well as the memory\n required to store the tree. The optimal value depends on the\n nature of the problem.\n\n p : int, default=2\n Power parameter for the Minkowski metric. When p = 1, this is\n equivalent to using manhattan_distance (l1), and euclidean_distance\n (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used.\n\n metric : str or callable, default='minkowski'\n Distance metric to use for the tree. The default metric is\n minkowski, and with p=2 is equivalent to the standard Euclidean\n metric. See the documentation of :class:`DistanceMetric` for a\n list of available metrics.\n If metric is \"precomputed\", X is assumed to be a distance matrix and\n must be square during fit. X may be a :term:`sparse graph`,\n in which case only \"nonzero\" elements may be considered neighbors.\n\n outlier_label : {manual label, 'most_frequent'}, default=None\n Label for outlier samples (samples with no neighbors in given radius).\n\n - manual label: str or int label (should be the same type as y)\n or list of manual labels if multi-output is used.\n - 'most_frequent' : assign the most frequent label of y to outliers.\n - None : when any outlier is detected, ValueError will be raised.\n\n metric_params : dict, default=None\n Additional keyword arguments for the metric function.\n\n n_jobs : int, default=None\n The number of parallel jobs to run for neighbors search.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n **kwargs : dict\n Additional keyword arguments passed to the constructor.\n\n .. deprecated:: 1.0\n The RadiusNeighborsClassifier class will not longer accept extra\n keyword parameters in 1.2 since they are unused.\n\n Attributes\n ----------\n classes_ : ndarray of shape (n_classes,)\n Class labels known to the classifier.\n\n effective_metric_ : str or callable\n The distance metric used. It will be same as the `metric` parameter\n or a synonym of it, e.g. 'euclidean' if the `metric` parameter set to\n 'minkowski' and `p` parameter set to 2.\n\n effective_metric_params_ : dict\n Additional keyword arguments for the metric function. For most metrics\n will be same with `metric_params` parameter, but may also contain the\n `p` parameter value if the `effective_metric_` attribute is set to\n 'minkowski'.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_samples_fit_ : int\n Number of samples in the fitted data.\n\n outlier_label_ : int or array-like of shape (n_class,)\n Label which is given for outlier samples (samples with no neighbors\n on given radius).\n\n outputs_2d_ : bool\n False when `y`'s shape is (n_samples, ) or (n_samples, 1) during fit\n otherwise True.\n\n See Also\n --------\n KNeighborsClassifier : Classifier implementing the k-nearest neighbors\n vote.\n RadiusNeighborsRegressor : Regression based on neighbors within a\n fixed radius.\n KNeighborsRegressor : Regression based on k-nearest neighbors.\n NearestNeighbors : Unsupervised learner for implementing neighbor\n searches.\n\n Notes\n -----\n See :ref:`Nearest Neighbors ` in the online documentation\n for a discussion of the choice of ``algorithm`` and ``leaf_size``.\n\n https://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm\n\n Examples\n --------\n >>> X = [[0], [1], [2], [3]]\n >>> y = [0, 0, 1, 1]\n >>> from sklearn.neighbors import RadiusNeighborsClassifier\n >>> neigh = RadiusNeighborsClassifier(radius=1.0)\n >>> neigh.fit(X, y)\n RadiusNeighborsClassifier(...)\n >>> print(neigh.predict([[1.5]]))\n [0]\n >>> print(neigh.predict_proba([[1.0]]))\n [[0.66666667 0.33333333]]\n ", - "source_code": "\n\nclass RadiusNeighborsClassifier(RadiusNeighborsMixin, ClassifierMixin, NeighborsBase):\n \"\"\"Classifier implementing a vote among neighbors within a given radius.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n radius : float, default=1.0\n Range of parameter space to use by default for :meth:`radius_neighbors`\n queries.\n\n weights : {'uniform', 'distance'} or callable, default='uniform'\n Weight function used in prediction. Possible values:\n\n - 'uniform' : uniform weights. All points in each neighborhood\n are weighted equally.\n - 'distance' : weight points by the inverse of their distance.\n in this case, closer neighbors of a query point will have a\n greater influence than neighbors which are further away.\n - [callable] : a user-defined function which accepts an\n array of distances, and returns an array of the same shape\n containing the weights.\n\n Uniform weights are used by default.\n\n algorithm : {'auto', 'ball_tree', 'kd_tree', 'brute'}, default='auto'\n Algorithm used to compute the nearest neighbors:\n\n - 'ball_tree' will use :class:`BallTree`\n - 'kd_tree' will use :class:`KDTree`\n - 'brute' will use a brute-force search.\n - 'auto' will attempt to decide the most appropriate algorithm\n based on the values passed to :meth:`fit` method.\n\n Note: fitting on sparse input will override the setting of\n this parameter, using brute force.\n\n leaf_size : int, default=30\n Leaf size passed to BallTree or KDTree. This can affect the\n speed of the construction and query, as well as the memory\n required to store the tree. The optimal value depends on the\n nature of the problem.\n\n p : int, default=2\n Power parameter for the Minkowski metric. When p = 1, this is\n equivalent to using manhattan_distance (l1), and euclidean_distance\n (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used.\n\n metric : str or callable, default='minkowski'\n Distance metric to use for the tree. The default metric is\n minkowski, and with p=2 is equivalent to the standard Euclidean\n metric. See the documentation of :class:`DistanceMetric` for a\n list of available metrics.\n If metric is \"precomputed\", X is assumed to be a distance matrix and\n must be square during fit. X may be a :term:`sparse graph`,\n in which case only \"nonzero\" elements may be considered neighbors.\n\n outlier_label : {manual label, 'most_frequent'}, default=None\n Label for outlier samples (samples with no neighbors in given radius).\n\n - manual label: str or int label (should be the same type as y)\n or list of manual labels if multi-output is used.\n - 'most_frequent' : assign the most frequent label of y to outliers.\n - None : when any outlier is detected, ValueError will be raised.\n\n metric_params : dict, default=None\n Additional keyword arguments for the metric function.\n\n n_jobs : int, default=None\n The number of parallel jobs to run for neighbors search.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n **kwargs : dict\n Additional keyword arguments passed to the constructor.\n\n .. deprecated:: 1.0\n The RadiusNeighborsClassifier class will not longer accept extra\n keyword parameters in 1.2 since they are unused.\n\n Attributes\n ----------\n classes_ : ndarray of shape (n_classes,)\n Class labels known to the classifier.\n\n effective_metric_ : str or callable\n The distance metric used. It will be same as the `metric` parameter\n or a synonym of it, e.g. 'euclidean' if the `metric` parameter set to\n 'minkowski' and `p` parameter set to 2.\n\n effective_metric_params_ : dict\n Additional keyword arguments for the metric function. For most metrics\n will be same with `metric_params` parameter, but may also contain the\n `p` parameter value if the `effective_metric_` attribute is set to\n 'minkowski'.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_samples_fit_ : int\n Number of samples in the fitted data.\n\n outlier_label_ : int or array-like of shape (n_class,)\n Label which is given for outlier samples (samples with no neighbors\n on given radius).\n\n outputs_2d_ : bool\n False when `y`'s shape is (n_samples, ) or (n_samples, 1) during fit\n otherwise True.\n\n See Also\n --------\n KNeighborsClassifier : Classifier implementing the k-nearest neighbors\n vote.\n RadiusNeighborsRegressor : Regression based on neighbors within a\n fixed radius.\n KNeighborsRegressor : Regression based on k-nearest neighbors.\n NearestNeighbors : Unsupervised learner for implementing neighbor\n searches.\n\n Notes\n -----\n See :ref:`Nearest Neighbors ` in the online documentation\n for a discussion of the choice of ``algorithm`` and ``leaf_size``.\n\n https://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm\n\n Examples\n --------\n >>> X = [[0], [1], [2], [3]]\n >>> y = [0, 0, 1, 1]\n >>> from sklearn.neighbors import RadiusNeighborsClassifier\n >>> neigh = RadiusNeighborsClassifier(radius=1.0)\n >>> neigh.fit(X, y)\n RadiusNeighborsClassifier(...)\n >>> print(neigh.predict([[1.5]]))\n [0]\n >>> print(neigh.predict_proba([[1.0]]))\n [[0.66666667 0.33333333]]\n \"\"\"\n \n def __init__(self, radius=1.0, *, weights='uniform', algorithm='auto', leaf_size=30, p=2, metric='minkowski', outlier_label=None, metric_params=None, n_jobs=None, **kwargs):\n if len(kwargs) > 0:\n warnings.warn(f'Passing additional keyword parameters has no effect and is deprecated in 1.0. An error will be raised from 1.2 and beyond. The ignored keyword parameter(s) are: {kwargs.keys()}.', FutureWarning)\n super().__init__(radius=radius, algorithm=algorithm, leaf_size=leaf_size, metric=metric, p=p, metric_params=metric_params, n_jobs=n_jobs)\n self.weights = weights\n self.outlier_label = outlier_label\n \n def fit(self, X, y):\n \"\"\"Fit the radius neighbors classifier from the training dataset.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples) if metric='precomputed'\n Training data.\n\n y : {array-like, sparse matrix} of shape (n_samples,) or (n_samples, n_outputs)\n Target values.\n\n Returns\n -------\n self : RadiusNeighborsClassifier\n The fitted radius neighbors classifier.\n \"\"\"\n self.weights = _check_weights(self.weights)\n self._fit(X, y)\n classes_ = self.classes_\n _y = self._y\n if not self.outputs_2d_:\n _y = self._y.reshape((-1, 1))\n classes_ = [self.classes_]\n if self.outlier_label is None:\n outlier_label_ = None\n elif self.outlier_label == 'most_frequent':\n outlier_label_ = []\n for (k, classes_k) in enumerate(classes_):\n label_count = np.bincount(_y[:, k])\n outlier_label_.append(classes_k[label_count.argmax()])\n else:\n if _is_arraylike(self.outlier_label) and not isinstance(self.outlier_label, str):\n if len(self.outlier_label) != len(classes_):\n raise ValueError('The length of outlier_label: {} is inconsistent with the output length: {}'.format(self.outlier_label, len(classes_)))\n outlier_label_ = self.outlier_label\n else:\n outlier_label_ = [self.outlier_label] * len(classes_)\n for (classes, label) in zip(classes_, outlier_label_):\n if _is_arraylike(label) and not isinstance(label, str):\n raise TypeError('The outlier_label of classes {} is supposed to be a scalar, got {}.'.format(classes, label))\n if np.append(classes, label).dtype != classes.dtype:\n raise TypeError('The dtype of outlier_label {} is inconsistent with classes {} in y.'.format(label, classes))\n self.outlier_label_ = outlier_label_\n return self\n \n def predict(self, X):\n \"\"\"Predict the class labels for the provided data.\n\n Parameters\n ----------\n X : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\n Returns\n -------\n y : ndarray of shape (n_queries,) or (n_queries, n_outputs)\n Class labels for each data sample.\n \"\"\"\n probs = self.predict_proba(X)\n classes_ = self.classes_\n if not self.outputs_2d_:\n probs = [probs]\n classes_ = [self.classes_]\n n_outputs = len(classes_)\n n_queries = probs[0].shape[0]\n y_pred = np.empty((n_queries, n_outputs), dtype=classes_[0].dtype)\n for (k, prob) in enumerate(probs):\n max_prob_index = prob.argmax(axis=1)\n y_pred[:, k] = classes_[k].take(max_prob_index)\n outlier_zero_probs = (prob == 0).all(axis=1)\n if outlier_zero_probs.any():\n zero_prob_index = np.flatnonzero(outlier_zero_probs)\n y_pred[zero_prob_index, k] = self.outlier_label_[k]\n if not self.outputs_2d_:\n y_pred = y_pred.ravel()\n return y_pred\n \n def predict_proba(self, X):\n \"\"\"Return probability estimates for the test data X.\n\n Parameters\n ----------\n X : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\n Returns\n -------\n p : ndarray of shape (n_queries, n_classes), or a list of n_outputs of such arrays if n_outputs > 1.\n The class probabilities of the input samples. Classes are ordered\n by lexicographic order.\n \"\"\"\n X = self._validate_data(X, accept_sparse='csr', reset=False)\n n_queries = _num_samples(X)\n (neigh_dist, neigh_ind) = self.radius_neighbors(X)\n outlier_mask = np.zeros(n_queries, dtype=bool)\n outlier_mask[:] = [len(nind) == 0 for nind in neigh_ind]\n outliers = np.flatnonzero(outlier_mask)\n inliers = np.flatnonzero(~outlier_mask)\n classes_ = self.classes_\n _y = self._y\n if not self.outputs_2d_:\n _y = self._y.reshape((-1, 1))\n classes_ = [self.classes_]\n if self.outlier_label_ is None and outliers.size > 0:\n raise ValueError('No neighbors found for test samples %r, you can try using larger radius, giving a label for outliers, or considering removing them from your dataset.' % outliers)\n weights = _get_weights(neigh_dist, self.weights)\n if weights is not None:\n weights = weights[inliers]\n probabilities = []\n for (k, classes_k) in enumerate(classes_):\n pred_labels = np.zeros(len(neigh_ind), dtype=object)\n pred_labels[:] = [_y[ind, k] for ind in neigh_ind]\n proba_k = np.zeros((n_queries, classes_k.size))\n proba_inl = np.zeros((len(inliers), classes_k.size))\n if weights is None:\n for (i, idx) in enumerate(pred_labels[inliers]):\n proba_inl[i, :] = np.bincount(idx, minlength=classes_k.size)\n else:\n for (i, idx) in enumerate(pred_labels[inliers]):\n proba_inl[i, :] = np.bincount(idx, weights[i], minlength=classes_k.size)\n proba_k[inliers, :] = proba_inl\n if outliers.size > 0:\n _outlier_label = self.outlier_label_[k]\n label_index = np.flatnonzero(classes_k == _outlier_label)\n if label_index.size == 1:\n proba_k[outliers, label_index[0]] = 1.0\n else:\n warnings.warn('Outlier label {} is not in training classes. All class probabilities of outliers will be assigned with 0.'.format(self.outlier_label_[k]))\n normalizer = proba_k.sum(axis=1)[:, np.newaxis]\n normalizer[normalizer == 0.0] = 1.0\n proba_k /= normalizer\n probabilities.append(proba_k)\n if not self.outputs_2d_:\n probabilities = probabilities[0]\n return probabilities\n \n def _more_tags(self):\n return {'multilabel': True}\n" + "source_code": "\n\nclass RadiusNeighborsClassifier(RadiusNeighborsMixin, ClassifierMixin, NeighborsBase):\n \"\"\"Classifier implementing a vote among neighbors within a given radius.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n radius : float, default=1.0\n Range of parameter space to use by default for :meth:`radius_neighbors`\n queries.\n\n weights : {'uniform', 'distance'} or callable, default='uniform'\n Weight function used in prediction. Possible values:\n\n - 'uniform' : uniform weights. All points in each neighborhood\n are weighted equally.\n - 'distance' : weight points by the inverse of their distance.\n in this case, closer neighbors of a query point will have a\n greater influence than neighbors which are further away.\n - [callable] : a user-defined function which accepts an\n array of distances, and returns an array of the same shape\n containing the weights.\n\n Uniform weights are used by default.\n\n algorithm : {'auto', 'ball_tree', 'kd_tree', 'brute'}, default='auto'\n Algorithm used to compute the nearest neighbors:\n\n - 'ball_tree' will use :class:`BallTree`\n - 'kd_tree' will use :class:`KDTree`\n - 'brute' will use a brute-force search.\n - 'auto' will attempt to decide the most appropriate algorithm\n based on the values passed to :meth:`fit` method.\n\n Note: fitting on sparse input will override the setting of\n this parameter, using brute force.\n\n leaf_size : int, default=30\n Leaf size passed to BallTree or KDTree. This can affect the\n speed of the construction and query, as well as the memory\n required to store the tree. The optimal value depends on the\n nature of the problem.\n\n p : int, default=2\n Power parameter for the Minkowski metric. When p = 1, this is\n equivalent to using manhattan_distance (l1), and euclidean_distance\n (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used.\n\n metric : str or callable, default='minkowski'\n Distance metric to use for the tree. The default metric is\n minkowski, and with p=2 is equivalent to the standard Euclidean\n metric. See the documentation of :class:`DistanceMetric` for a\n list of available metrics.\n If metric is \"precomputed\", X is assumed to be a distance matrix and\n must be square during fit. X may be a :term:`sparse graph`,\n in which case only \"nonzero\" elements may be considered neighbors.\n\n outlier_label : {manual label, 'most_frequent'}, default=None\n Label for outlier samples (samples with no neighbors in given radius).\n\n - manual label: str or int label (should be the same type as y)\n or list of manual labels if multi-output is used.\n - 'most_frequent' : assign the most frequent label of y to outliers.\n - None : when any outlier is detected, ValueError will be raised.\n\n metric_params : dict, default=None\n Additional keyword arguments for the metric function.\n\n n_jobs : int, default=None\n The number of parallel jobs to run for neighbors search.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n **kwargs : dict\n Additional keyword arguments passed to the constructor.\n\n .. deprecated:: 1.0\n The RadiusNeighborsClassifier class will not longer accept extra\n keyword parameters in 1.2 since they are unused.\n\n Attributes\n ----------\n classes_ : ndarray of shape (n_classes,)\n Class labels known to the classifier.\n\n effective_metric_ : str or callable\n The distance metric used. It will be same as the `metric` parameter\n or a synonym of it, e.g. 'euclidean' if the `metric` parameter set to\n 'minkowski' and `p` parameter set to 2.\n\n effective_metric_params_ : dict\n Additional keyword arguments for the metric function. For most metrics\n will be same with `metric_params` parameter, but may also contain the\n `p` parameter value if the `effective_metric_` attribute is set to\n 'minkowski'.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_samples_fit_ : int\n Number of samples in the fitted data.\n\n outlier_label_ : int or array-like of shape (n_class,)\n Label which is given for outlier samples (samples with no neighbors\n on given radius).\n\n outputs_2d_ : bool\n False when `y`'s shape is (n_samples, ) or (n_samples, 1) during fit\n otherwise True.\n\n See Also\n --------\n KNeighborsClassifier : Classifier implementing the k-nearest neighbors\n vote.\n RadiusNeighborsRegressor : Regression based on neighbors within a\n fixed radius.\n KNeighborsRegressor : Regression based on k-nearest neighbors.\n NearestNeighbors : Unsupervised learner for implementing neighbor\n searches.\n\n Notes\n -----\n See :ref:`Nearest Neighbors ` in the online documentation\n for a discussion of the choice of ``algorithm`` and ``leaf_size``.\n\n https://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm\n\n Examples\n --------\n >>> X = [[0], [1], [2], [3]]\n >>> y = [0, 0, 1, 1]\n >>> from sklearn.neighbors import RadiusNeighborsClassifier\n >>> neigh = RadiusNeighborsClassifier(radius=1.0)\n >>> neigh.fit(X, y)\n RadiusNeighborsClassifier(...)\n >>> print(neigh.predict([[1.5]]))\n [0]\n >>> print(neigh.predict_proba([[1.0]]))\n [[0.66666667 0.33333333]]\n \"\"\"\n \n def __init__(self, radius=1.0, *, weights='uniform', algorithm='auto', leaf_size=30, p=2, metric='minkowski', outlier_label=None, metric_params=None, n_jobs=None, **kwargs):\n if len(kwargs) > 0:\n warnings.warn(f'Passing additional keyword parameters has no effect and is deprecated in 1.0. An error will be raised from 1.2 and beyond. The ignored keyword parameter(s) are: {kwargs.keys()}.', FutureWarning)\n super().__init__(radius=radius, algorithm=algorithm, leaf_size=leaf_size, metric=metric, p=p, metric_params=metric_params, n_jobs=n_jobs)\n self.weights = weights\n self.outlier_label = outlier_label\n \n def fit(self, X, y):\n \"\"\"Fit the radius neighbors classifier from the training dataset.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples) if metric='precomputed'\n Training data.\n\n y : {array-like, sparse matrix} of shape (n_samples,) or (n_samples, n_outputs)\n Target values.\n\n Returns\n -------\n self : RadiusNeighborsClassifier\n The fitted radius neighbors classifier.\n \"\"\"\n self.weights = _check_weights(self.weights)\n self._fit(X, y)\n classes_ = self.classes_\n _y = self._y\n if not self.outputs_2d_:\n _y = self._y.reshape((-1, 1))\n classes_ = [self.classes_]\n if self.outlier_label is None:\n outlier_label_ = None\n elif self.outlier_label == 'most_frequent':\n outlier_label_ = []\n for (k, classes_k) in enumerate(classes_):\n label_count = np.bincount(_y[:, k])\n outlier_label_.append(classes_k[label_count.argmax()])\n else:\n if _is_arraylike(self.outlier_label) and not isinstance(self.outlier_label, str):\n if len(self.outlier_label) != len(classes_):\n raise ValueError('The length of outlier_label: {} is inconsistent with the output length: {}'.format(self.outlier_label, len(classes_)))\n outlier_label_ = self.outlier_label\n else:\n outlier_label_ = [self.outlier_label] * len(classes_)\n for (classes, label) in zip(classes_, outlier_label_):\n if _is_arraylike(label) and not isinstance(label, str):\n raise TypeError('The outlier_label of classes {} is supposed to be a scalar, got {}.'.format(classes, label))\n if np.append(classes, label).dtype != classes.dtype:\n raise TypeError('The dtype of outlier_label {} is inconsistent with classes {} in y.'.format(label, classes))\n self.outlier_label_ = outlier_label_\n return self\n \n def predict(self, X):\n \"\"\"Predict the class labels for the provided data.\n\n Parameters\n ----------\n X : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\n Returns\n -------\n y : ndarray of shape (n_queries,) or (n_queries, n_outputs)\n Class labels for each data sample.\n \"\"\"\n probs = self.predict_proba(X)\n classes_ = self.classes_\n if not self.outputs_2d_:\n probs = [probs]\n classes_ = [self.classes_]\n n_outputs = len(classes_)\n n_queries = probs[0].shape[0]\n y_pred = np.empty((n_queries, n_outputs), dtype=classes_[0].dtype)\n for (k, prob) in enumerate(probs):\n max_prob_index = prob.argmax(axis=1)\n y_pred[:, k] = classes_[k].take(max_prob_index)\n outlier_zero_probs = (prob == 0).all(axis=1)\n if outlier_zero_probs.any():\n zero_prob_index = np.flatnonzero(outlier_zero_probs)\n y_pred[zero_prob_index, k] = self.outlier_label_[k]\n if not self.outputs_2d_:\n y_pred = y_pred.ravel()\n return y_pred\n \n def predict_proba(self, X):\n \"\"\"Return probability estimates for the test data X.\n\n Parameters\n ----------\n X : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\n Returns\n -------\n p : ndarray of shape (n_queries, n_classes), or a list of n_outputs of such arrays if n_outputs > 1.\n The class probabilities of the input samples. Classes are ordered\n by lexicographic order.\n \"\"\"\n n_queries = _num_samples(X)\n (neigh_dist, neigh_ind) = self.radius_neighbors(X)\n outlier_mask = np.zeros(n_queries, dtype=bool)\n outlier_mask[:] = [len(nind) == 0 for nind in neigh_ind]\n outliers = np.flatnonzero(outlier_mask)\n inliers = np.flatnonzero(~outlier_mask)\n classes_ = self.classes_\n _y = self._y\n if not self.outputs_2d_:\n _y = self._y.reshape((-1, 1))\n classes_ = [self.classes_]\n if self.outlier_label_ is None and outliers.size > 0:\n raise ValueError('No neighbors found for test samples %r, you can try using larger radius, giving a label for outliers, or considering removing them from your dataset.' % outliers)\n weights = _get_weights(neigh_dist, self.weights)\n if weights is not None:\n weights = weights[inliers]\n probabilities = []\n for (k, classes_k) in enumerate(classes_):\n pred_labels = np.zeros(len(neigh_ind), dtype=object)\n pred_labels[:] = [_y[ind, k] for ind in neigh_ind]\n proba_k = np.zeros((n_queries, classes_k.size))\n proba_inl = np.zeros((len(inliers), classes_k.size))\n if weights is None:\n for (i, idx) in enumerate(pred_labels[inliers]):\n proba_inl[i, :] = np.bincount(idx, minlength=classes_k.size)\n else:\n for (i, idx) in enumerate(pred_labels[inliers]):\n proba_inl[i, :] = np.bincount(idx, weights[i], minlength=classes_k.size)\n proba_k[inliers, :] = proba_inl\n if outliers.size > 0:\n _outlier_label = self.outlier_label_[k]\n label_index = np.flatnonzero(classes_k == _outlier_label)\n if label_index.size == 1:\n proba_k[outliers, label_index[0]] = 1.0\n else:\n warnings.warn('Outlier label {} is not in training classes. All class probabilities of outliers will be assigned with 0.'.format(self.outlier_label_[k]))\n normalizer = proba_k.sum(axis=1)[:, np.newaxis]\n normalizer[normalizer == 0.0] = 1.0\n proba_k /= normalizer\n probabilities.append(proba_k)\n if not self.outputs_2d_:\n probabilities = probabilities[0]\n return probabilities\n \n def _more_tags(self):\n return {'multilabel': True}\n" }, { "name": "KNeighborsTransformer", @@ -25515,8 +25468,8 @@ ], "is_public": true, "description": "Kernel Density Estimation.\n\nRead more in the :ref:`User Guide `.", - "docstring": "Kernel Density Estimation.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n bandwidth : float, default=1.0\n The bandwidth of the kernel.\n\n algorithm : {'kd_tree', 'ball_tree', 'auto'}, default='auto'\n The tree algorithm to use.\n\n kernel : {'gaussian', 'tophat', 'epanechnikov', 'exponential', 'linear', 'cosine'}, default='gaussian'\n The kernel to use.\n\n metric : str, default='euclidean'\n The distance metric to use. Note that not all metrics are\n valid with all algorithms. Refer to the documentation of\n :class:`BallTree` and :class:`KDTree` for a description of\n available algorithms. Note that the normalization of the density\n output is correct only for the Euclidean distance metric. Default\n is 'euclidean'.\n\n atol : float, default=0\n The desired absolute tolerance of the result. A larger tolerance will\n generally lead to faster execution.\n\n rtol : float, default=0\n The desired relative tolerance of the result. A larger tolerance will\n generally lead to faster execution.\n\n breadth_first : bool, default=True\n If true (default), use a breadth-first approach to the problem.\n Otherwise use a depth-first approach.\n\n leaf_size : int, default=40\n Specify the leaf size of the underlying tree. See :class:`BallTree`\n or :class:`KDTree` for details.\n\n metric_params : dict, default=None\n Additional parameters to be passed to the tree for use with the\n metric. For more information, see the documentation of\n :class:`BallTree` or :class:`KDTree`.\n\n Attributes\n ----------\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n tree_ : ``BinaryTree`` instance\n The tree algorithm for fast generalized N-point problems.\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n sklearn.neighbors.KDTree : K-dimensional tree for fast generalized N-point\n problems.\n sklearn.neighbors.BallTree : Ball tree for fast generalized N-point\n problems.\n\n Examples\n --------\n Compute a gaussian kernel density estimate with a fixed bandwidth.\n\n >>> import numpy as np\n >>> rng = np.random.RandomState(42)\n >>> X = rng.random_sample((100, 3))\n >>> kde = KernelDensity(kernel='gaussian', bandwidth=0.5).fit(X)\n >>> log_density = kde.score_samples(X[:3])\n >>> log_density\n array([-1.52955942, -1.51462041, -1.60244657])\n ", - "source_code": "\n\nclass KernelDensity(BaseEstimator):\n \"\"\"Kernel Density Estimation.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n bandwidth : float, default=1.0\n The bandwidth of the kernel.\n\n algorithm : {'kd_tree', 'ball_tree', 'auto'}, default='auto'\n The tree algorithm to use.\n\n kernel : {'gaussian', 'tophat', 'epanechnikov', 'exponential', 'linear', 'cosine'}, default='gaussian'\n The kernel to use.\n\n metric : str, default='euclidean'\n The distance metric to use. Note that not all metrics are\n valid with all algorithms. Refer to the documentation of\n :class:`BallTree` and :class:`KDTree` for a description of\n available algorithms. Note that the normalization of the density\n output is correct only for the Euclidean distance metric. Default\n is 'euclidean'.\n\n atol : float, default=0\n The desired absolute tolerance of the result. A larger tolerance will\n generally lead to faster execution.\n\n rtol : float, default=0\n The desired relative tolerance of the result. A larger tolerance will\n generally lead to faster execution.\n\n breadth_first : bool, default=True\n If true (default), use a breadth-first approach to the problem.\n Otherwise use a depth-first approach.\n\n leaf_size : int, default=40\n Specify the leaf size of the underlying tree. See :class:`BallTree`\n or :class:`KDTree` for details.\n\n metric_params : dict, default=None\n Additional parameters to be passed to the tree for use with the\n metric. For more information, see the documentation of\n :class:`BallTree` or :class:`KDTree`.\n\n Attributes\n ----------\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n tree_ : ``BinaryTree`` instance\n The tree algorithm for fast generalized N-point problems.\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n sklearn.neighbors.KDTree : K-dimensional tree for fast generalized N-point\n problems.\n sklearn.neighbors.BallTree : Ball tree for fast generalized N-point\n problems.\n\n Examples\n --------\n Compute a gaussian kernel density estimate with a fixed bandwidth.\n\n >>> import numpy as np\n >>> rng = np.random.RandomState(42)\n >>> X = rng.random_sample((100, 3))\n >>> kde = KernelDensity(kernel='gaussian', bandwidth=0.5).fit(X)\n >>> log_density = kde.score_samples(X[:3])\n >>> log_density\n array([-1.52955942, -1.51462041, -1.60244657])\n \"\"\"\n \n def __init__(self, *, bandwidth=1.0, algorithm='auto', kernel='gaussian', metric='euclidean', atol=0, rtol=0, breadth_first=True, leaf_size=40, metric_params=None):\n self.algorithm = algorithm\n self.bandwidth = bandwidth\n self.kernel = kernel\n self.metric = metric\n self.atol = atol\n self.rtol = rtol\n self.breadth_first = breadth_first\n self.leaf_size = leaf_size\n self.metric_params = metric_params\n self._choose_algorithm(self.algorithm, self.metric)\n if bandwidth <= 0:\n raise ValueError('bandwidth must be positive')\n if kernel not in VALID_KERNELS:\n raise ValueError(\"invalid kernel: '{0}'\".format(kernel))\n \n def _choose_algorithm(self, algorithm, metric):\n if algorithm == 'auto':\n if metric in KDTree.valid_metrics:\n return 'kd_tree'\n elif metric in BallTree.valid_metrics:\n return 'ball_tree'\n else:\n raise ValueError(\"invalid metric: '{0}'\".format(metric))\n elif algorithm in TREE_DICT:\n if metric not in TREE_DICT[algorithm].valid_metrics:\n raise ValueError(\"invalid metric for {0}: '{1}'\".format(TREE_DICT[algorithm], metric))\n return algorithm\n else:\n raise ValueError(\"invalid algorithm: '{0}'\".format(algorithm))\n \n def fit(self, X, y=None, sample_weight=None):\n \"\"\"Fit the Kernel Density model on the data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n List of n_features-dimensional data points. Each row\n corresponds to a single data point.\n\n y : None\n Ignored. This parameter exists only for compatibility with\n :class:`~sklearn.pipeline.Pipeline`.\n\n sample_weight : array-like of shape (n_samples,), default=None\n List of sample weights attached to the data X.\n\n .. versionadded:: 0.20\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n algorithm = self._choose_algorithm(self.algorithm, self.metric)\n X = self._validate_data(X, order='C', dtype=DTYPE)\n if sample_weight is not None:\n sample_weight = _check_sample_weight(sample_weight, X, DTYPE)\n if sample_weight.min() <= 0:\n raise ValueError('sample_weight must have positive values')\n kwargs = self.metric_params\n if kwargs is None:\n kwargs = {}\n self.tree_ = TREE_DICT[algorithm](X, metric=self.metric, leaf_size=self.leaf_size, sample_weight=sample_weight, **kwargs)\n return self\n \n def score_samples(self, X):\n \"\"\"Compute the log-likelihood of each sample under the model.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n An array of points to query. Last dimension should match dimension\n of training data (n_features).\n\n Returns\n -------\n density : ndarray of shape (n_samples,)\n Log-likelihood of each sample in `X`. These are normalized to be\n probability densities, so values will be low for high-dimensional\n data.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, order='C', dtype=DTYPE, reset=False)\n if self.tree_.sample_weight is None:\n N = self.tree_.data.shape[0]\n else:\n N = self.tree_.sum_weight\n atol_N = self.atol * N\n log_density = self.tree_.kernel_density(X, h=self.bandwidth, kernel=self.kernel, atol=atol_N, rtol=self.rtol, breadth_first=self.breadth_first, return_log=True)\n log_density -= np.log(N)\n return log_density\n \n def score(self, X, y=None):\n \"\"\"Compute the total log-likelihood under the model.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n List of n_features-dimensional data points. Each row\n corresponds to a single data point.\n\n y : None\n Ignored. This parameter exists only for compatibility with\n :class:`~sklearn.pipeline.Pipeline`.\n\n Returns\n -------\n logprob : float\n Total log-likelihood of the data in X. This is normalized to be a\n probability density, so the value will be low for high-dimensional\n data.\n \"\"\"\n return np.sum(self.score_samples(X))\n \n def sample(self, n_samples=1, random_state=None):\n \"\"\"Generate random samples from the model.\n\n Currently, this is implemented only for gaussian and tophat kernels.\n\n Parameters\n ----------\n n_samples : int, default=1\n Number of samples to generate.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation used to generate\n random samples. Pass an int for reproducible results\n across multiple function calls.\n See :term: `Glossary `.\n\n Returns\n -------\n X : array-like of shape (n_samples, n_features)\n List of samples.\n \"\"\"\n check_is_fitted(self)\n if self.kernel not in ['gaussian', 'tophat']:\n raise NotImplementedError()\n data = np.asarray(self.tree_.data)\n rng = check_random_state(random_state)\n u = rng.uniform(0, 1, size=n_samples)\n if self.tree_.sample_weight is None:\n i = (u * data.shape[0]).astype(np.int64)\n else:\n cumsum_weight = np.cumsum(np.asarray(self.tree_.sample_weight))\n sum_weight = cumsum_weight[-1]\n i = np.searchsorted(cumsum_weight, u * sum_weight)\n if self.kernel == 'gaussian':\n return np.atleast_2d(rng.normal(data[i], self.bandwidth))\n elif self.kernel == 'tophat':\n dim = data.shape[1]\n X = rng.normal(size=(n_samples, dim))\n s_sq = row_norms(X, squared=True)\n correction = gammainc(0.5 * dim, 0.5 * s_sq)**(1.0 / dim) * self.bandwidth / np.sqrt(s_sq)\n return data[i] + X * correction[:, np.newaxis]\n \n def _more_tags(self):\n return {'_xfail_checks': {'check_sample_weights_invariance': 'sample_weight must have positive values'}}\n" + "docstring": "Kernel Density Estimation.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n bandwidth : float, default=1.0\n The bandwidth of the kernel.\n\n algorithm : {'kd_tree', 'ball_tree', 'auto'}, default='auto'\n The tree algorithm to use.\n\n kernel : {'gaussian', 'tophat', 'epanechnikov', 'exponential', 'linear', 'cosine'}, default='gaussian'\n The kernel to use.\n\n metric : str, default='euclidean'\n The distance metric to use. Note that not all metrics are\n valid with all algorithms. Refer to the documentation of\n :class:`BallTree` and :class:`KDTree` for a description of\n available algorithms. Note that the normalization of the density\n output is correct only for the Euclidean distance metric. Default\n is 'euclidean'.\n\n atol : float, default=0\n The desired absolute tolerance of the result. A larger tolerance will\n generally lead to faster execution.\n\n rtol : float, default=0\n The desired relative tolerance of the result. A larger tolerance will\n generally lead to faster execution.\n\n breadth_first : bool, default=True\n If true (default), use a breadth-first approach to the problem.\n Otherwise use a depth-first approach.\n\n leaf_size : int, default=40\n Specify the leaf size of the underlying tree. See :class:`BallTree`\n or :class:`KDTree` for details.\n\n metric_params : dict, default=None\n Additional parameters to be passed to the tree for use with the\n metric. For more information, see the documentation of\n :class:`BallTree` or :class:`KDTree`.\n\n Attributes\n ----------\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n tree_ : ``BinaryTree`` instance\n The tree algorithm for fast generalized N-point problems.\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n sklearn.neighbors.KDTree : K-dimensional tree for fast generalized N-point\n problems.\n sklearn.neighbors.BallTree : Ball tree for fast generalized N-point\n problems.\n\n Examples\n --------\n Compute a gaussian kernel density estimate with a fixed bandwidth.\n\n >>> from sklearn.neighbors import KernelDensity\n >>> import numpy as np\n >>> rng = np.random.RandomState(42)\n >>> X = rng.random_sample((100, 3))\n >>> kde = KernelDensity(kernel='gaussian', bandwidth=0.5).fit(X)\n >>> log_density = kde.score_samples(X[:3])\n >>> log_density\n array([-1.52955942, -1.51462041, -1.60244657])\n ", + "source_code": "\n\nclass KernelDensity(BaseEstimator):\n \"\"\"Kernel Density Estimation.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n bandwidth : float, default=1.0\n The bandwidth of the kernel.\n\n algorithm : {'kd_tree', 'ball_tree', 'auto'}, default='auto'\n The tree algorithm to use.\n\n kernel : {'gaussian', 'tophat', 'epanechnikov', 'exponential', 'linear', 'cosine'}, default='gaussian'\n The kernel to use.\n\n metric : str, default='euclidean'\n The distance metric to use. Note that not all metrics are\n valid with all algorithms. Refer to the documentation of\n :class:`BallTree` and :class:`KDTree` for a description of\n available algorithms. Note that the normalization of the density\n output is correct only for the Euclidean distance metric. Default\n is 'euclidean'.\n\n atol : float, default=0\n The desired absolute tolerance of the result. A larger tolerance will\n generally lead to faster execution.\n\n rtol : float, default=0\n The desired relative tolerance of the result. A larger tolerance will\n generally lead to faster execution.\n\n breadth_first : bool, default=True\n If true (default), use a breadth-first approach to the problem.\n Otherwise use a depth-first approach.\n\n leaf_size : int, default=40\n Specify the leaf size of the underlying tree. See :class:`BallTree`\n or :class:`KDTree` for details.\n\n metric_params : dict, default=None\n Additional parameters to be passed to the tree for use with the\n metric. For more information, see the documentation of\n :class:`BallTree` or :class:`KDTree`.\n\n Attributes\n ----------\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n tree_ : ``BinaryTree`` instance\n The tree algorithm for fast generalized N-point problems.\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n sklearn.neighbors.KDTree : K-dimensional tree for fast generalized N-point\n problems.\n sklearn.neighbors.BallTree : Ball tree for fast generalized N-point\n problems.\n\n Examples\n --------\n Compute a gaussian kernel density estimate with a fixed bandwidth.\n\n >>> from sklearn.neighbors import KernelDensity\n >>> import numpy as np\n >>> rng = np.random.RandomState(42)\n >>> X = rng.random_sample((100, 3))\n >>> kde = KernelDensity(kernel='gaussian', bandwidth=0.5).fit(X)\n >>> log_density = kde.score_samples(X[:3])\n >>> log_density\n array([-1.52955942, -1.51462041, -1.60244657])\n \"\"\"\n \n def __init__(self, *, bandwidth=1.0, algorithm='auto', kernel='gaussian', metric='euclidean', atol=0, rtol=0, breadth_first=True, leaf_size=40, metric_params=None):\n self.algorithm = algorithm\n self.bandwidth = bandwidth\n self.kernel = kernel\n self.metric = metric\n self.atol = atol\n self.rtol = rtol\n self.breadth_first = breadth_first\n self.leaf_size = leaf_size\n self.metric_params = metric_params\n self._choose_algorithm(self.algorithm, self.metric)\n if bandwidth <= 0:\n raise ValueError('bandwidth must be positive')\n if kernel not in VALID_KERNELS:\n raise ValueError(\"invalid kernel: '{0}'\".format(kernel))\n \n def _choose_algorithm(self, algorithm, metric):\n if algorithm == 'auto':\n if metric in KDTree.valid_metrics:\n return 'kd_tree'\n elif metric in BallTree.valid_metrics:\n return 'ball_tree'\n else:\n raise ValueError(\"invalid metric: '{0}'\".format(metric))\n elif algorithm in TREE_DICT:\n if metric not in TREE_DICT[algorithm].valid_metrics:\n raise ValueError(\"invalid metric for {0}: '{1}'\".format(TREE_DICT[algorithm], metric))\n return algorithm\n else:\n raise ValueError(\"invalid algorithm: '{0}'\".format(algorithm))\n \n def fit(self, X, y=None, sample_weight=None):\n \"\"\"Fit the Kernel Density model on the data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n List of n_features-dimensional data points. Each row\n corresponds to a single data point.\n\n y : None\n Ignored. This parameter exists only for compatibility with\n :class:`~sklearn.pipeline.Pipeline`.\n\n sample_weight : array-like of shape (n_samples,), default=None\n List of sample weights attached to the data X.\n\n .. versionadded:: 0.20\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n algorithm = self._choose_algorithm(self.algorithm, self.metric)\n X = self._validate_data(X, order='C', dtype=DTYPE)\n if sample_weight is not None:\n sample_weight = _check_sample_weight(sample_weight, X, DTYPE)\n if sample_weight.min() <= 0:\n raise ValueError('sample_weight must have positive values')\n kwargs = self.metric_params\n if kwargs is None:\n kwargs = {}\n self.tree_ = TREE_DICT[algorithm](X, metric=self.metric, leaf_size=self.leaf_size, sample_weight=sample_weight, **kwargs)\n return self\n \n def score_samples(self, X):\n \"\"\"Compute the log-likelihood of each sample under the model.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n An array of points to query. Last dimension should match dimension\n of training data (n_features).\n\n Returns\n -------\n density : ndarray of shape (n_samples,)\n Log-likelihood of each sample in `X`. These are normalized to be\n probability densities, so values will be low for high-dimensional\n data.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, order='C', dtype=DTYPE, reset=False)\n if self.tree_.sample_weight is None:\n N = self.tree_.data.shape[0]\n else:\n N = self.tree_.sum_weight\n atol_N = self.atol * N\n log_density = self.tree_.kernel_density(X, h=self.bandwidth, kernel=self.kernel, atol=atol_N, rtol=self.rtol, breadth_first=self.breadth_first, return_log=True)\n log_density -= np.log(N)\n return log_density\n \n def score(self, X, y=None):\n \"\"\"Compute the total log-likelihood under the model.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n List of n_features-dimensional data points. Each row\n corresponds to a single data point.\n\n y : None\n Ignored. This parameter exists only for compatibility with\n :class:`~sklearn.pipeline.Pipeline`.\n\n Returns\n -------\n logprob : float\n Total log-likelihood of the data in X. This is normalized to be a\n probability density, so the value will be low for high-dimensional\n data.\n \"\"\"\n return np.sum(self.score_samples(X))\n \n def sample(self, n_samples=1, random_state=None):\n \"\"\"Generate random samples from the model.\n\n Currently, this is implemented only for gaussian and tophat kernels.\n\n Parameters\n ----------\n n_samples : int, default=1\n Number of samples to generate.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation used to generate\n random samples. Pass an int for reproducible results\n across multiple function calls.\n See :term:`Glossary `.\n\n Returns\n -------\n X : array-like of shape (n_samples, n_features)\n List of samples.\n \"\"\"\n check_is_fitted(self)\n if self.kernel not in ['gaussian', 'tophat']:\n raise NotImplementedError()\n data = np.asarray(self.tree_.data)\n rng = check_random_state(random_state)\n u = rng.uniform(0, 1, size=n_samples)\n if self.tree_.sample_weight is None:\n i = (u * data.shape[0]).astype(np.int64)\n else:\n cumsum_weight = np.cumsum(np.asarray(self.tree_.sample_weight))\n sum_weight = cumsum_weight[-1]\n i = np.searchsorted(cumsum_weight, u * sum_weight)\n if self.kernel == 'gaussian':\n return np.atleast_2d(rng.normal(data[i], self.bandwidth))\n elif self.kernel == 'tophat':\n dim = data.shape[1]\n X = rng.normal(size=(n_samples, dim))\n s_sq = row_norms(X, squared=True)\n correction = gammainc(0.5 * dim, 0.5 * s_sq)**(1.0 / dim) * self.bandwidth / np.sqrt(s_sq)\n return data[i] + X * correction[:, np.newaxis]\n \n def _more_tags(self):\n return {'_xfail_checks': {'check_sample_weights_invariance': 'sample_weight must have positive values'}}\n" }, { "name": "LocalOutlierFactor", @@ -25542,9 +25495,9 @@ "sklearn.neighbors._lof.LocalOutlierFactor._local_reachability_density" ], "is_public": true, - "description": "Unsupervised Outlier Detection using Local Outlier Factor (LOF)\n\nThe anomaly score of each sample is called Local Outlier Factor. It measures the local deviation of density of a given sample with respect to its neighbors. It is local in that the anomaly score depends on how isolated the object is with respect to the surrounding neighborhood. More precisely, locality is given by k-nearest neighbors, whose distance is used to estimate the local density. By comparing the local density of a sample to the local densities of its neighbors, one can identify samples that have a substantially lower density than their neighbors. These are considered outliers. .. versionadded:: 0.19", - "docstring": "Unsupervised Outlier Detection using Local Outlier Factor (LOF)\n\n The anomaly score of each sample is called Local Outlier Factor.\n It measures the local deviation of density of a given sample with\n respect to its neighbors.\n It is local in that the anomaly score depends on how isolated the object\n is with respect to the surrounding neighborhood.\n More precisely, locality is given by k-nearest neighbors, whose distance\n is used to estimate the local density.\n By comparing the local density of a sample to the local densities of\n its neighbors, one can identify samples that have a substantially lower\n density than their neighbors. These are considered outliers.\n\n .. versionadded:: 0.19\n\n Parameters\n ----------\n n_neighbors : int, default=20\n Number of neighbors to use by default for :meth:`kneighbors` queries.\n If n_neighbors is larger than the number of samples provided,\n all samples will be used.\n\n algorithm : {'auto', 'ball_tree', 'kd_tree', 'brute'}, default='auto'\n Algorithm used to compute the nearest neighbors:\n\n - 'ball_tree' will use :class:`BallTree`\n - 'kd_tree' will use :class:`KDTree`\n - 'brute' will use a brute-force search.\n - 'auto' will attempt to decide the most appropriate algorithm\n based on the values passed to :meth:`fit` method.\n\n Note: fitting on sparse input will override the setting of\n this parameter, using brute force.\n\n leaf_size : int, default=30\n Leaf size passed to :class:`BallTree` or :class:`KDTree`. This can\n affect the speed of the construction and query, as well as the memory\n required to store the tree. The optimal value depends on the\n nature of the problem.\n\n metric : str or callable, default='minkowski'\n metric used for the distance computation. Any metric from scikit-learn\n or scipy.spatial.distance can be used.\n\n If metric is \"precomputed\", X is assumed to be a distance matrix and\n must be square. X may be a sparse matrix, in which case only \"nonzero\"\n elements may be considered neighbors.\n\n If metric is a callable function, it is called on each\n pair of instances (rows) and the resulting value recorded. The callable\n should take two arrays as input and return one value indicating the\n distance between them. This works for Scipy's metrics, but is less\n efficient than passing the metric name as a string.\n\n Valid values for metric are:\n\n - from scikit-learn: ['cityblock', 'cosine', 'euclidean', 'l1', 'l2',\n 'manhattan']\n\n - from scipy.spatial.distance: ['braycurtis', 'canberra', 'chebyshev',\n 'correlation', 'dice', 'hamming', 'jaccard', 'kulsinski',\n 'mahalanobis', 'minkowski', 'rogerstanimoto', 'russellrao',\n 'seuclidean', 'sokalmichener', 'sokalsneath', 'sqeuclidean',\n 'yule']\n\n See the documentation for scipy.spatial.distance for details on these\n metrics:\n https://docs.scipy.org/doc/scipy/reference/spatial.distance.html\n\n p : int, default=2\n Parameter for the Minkowski metric from\n :func:`sklearn.metrics.pairwise.pairwise_distances`. When p = 1, this\n is equivalent to using manhattan_distance (l1), and euclidean_distance\n (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used.\n\n metric_params : dict, default=None\n Additional keyword arguments for the metric function.\n\n contamination : 'auto' or float, default='auto'\n The amount of contamination of the data set, i.e. the proportion\n of outliers in the data set. When fitting this is used to define the\n threshold on the scores of the samples.\n\n - if 'auto', the threshold is determined as in the\n original paper,\n - if a float, the contamination should be in the range (0, 0.5].\n\n .. versionchanged:: 0.22\n The default value of ``contamination`` changed from 0.1\n to ``'auto'``.\n\n novelty : bool, default=False\n By default, LocalOutlierFactor is only meant to be used for outlier\n detection (novelty=False). Set novelty to True if you want to use\n LocalOutlierFactor for novelty detection. In this case be aware that\n you should only use predict, decision_function and score_samples\n on new unseen data and not on the training set.\n\n .. versionadded:: 0.20\n\n n_jobs : int, default=None\n The number of parallel jobs to run for neighbors search.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n Attributes\n ----------\n negative_outlier_factor_ : ndarray of shape (n_samples,)\n The opposite LOF of the training samples. The higher, the more normal.\n Inliers tend to have a LOF score close to 1\n (``negative_outlier_factor_`` close to -1), while outliers tend to have\n a larger LOF score.\n\n The local outlier factor (LOF) of a sample captures its\n supposed 'degree of abnormality'.\n It is the average of the ratio of the local reachability density of\n a sample and those of its k-nearest neighbors.\n\n n_neighbors_ : int\n The actual number of neighbors used for :meth:`kneighbors` queries.\n\n offset_ : float\n Offset used to obtain binary labels from the raw scores.\n Observations having a negative_outlier_factor smaller than `offset_`\n are detected as abnormal.\n The offset is set to -1.5 (inliers score around -1), except when a\n contamination parameter different than \"auto\" is provided. In that\n case, the offset is defined in such a way we obtain the expected\n number of outliers in training.\n\n .. versionadded:: 0.20\n\n effective_metric_ : str\n The effective metric used for the distance computation.\n\n effective_metric_params_ : dict\n The effective additional keyword arguments for the metric function.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_samples_fit_ : int\n It is the number of samples in the fitted data.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.neighbors import LocalOutlierFactor\n >>> X = [[-1.1], [0.2], [101.1], [0.3]]\n >>> clf = LocalOutlierFactor(n_neighbors=2)\n >>> clf.fit_predict(X)\n array([ 1, 1, -1, 1])\n >>> clf.negative_outlier_factor_\n array([ -0.9821..., -1.0370..., -73.3697..., -0.9821...])\n\n References\n ----------\n .. [1] Breunig, M. M., Kriegel, H. P., Ng, R. T., & Sander, J. (2000, May).\n LOF: identifying density-based local outliers. In ACM sigmod record.\n ", - "source_code": "\n\nclass LocalOutlierFactor(KNeighborsMixin, OutlierMixin, NeighborsBase):\n \"\"\"Unsupervised Outlier Detection using Local Outlier Factor (LOF)\n\n The anomaly score of each sample is called Local Outlier Factor.\n It measures the local deviation of density of a given sample with\n respect to its neighbors.\n It is local in that the anomaly score depends on how isolated the object\n is with respect to the surrounding neighborhood.\n More precisely, locality is given by k-nearest neighbors, whose distance\n is used to estimate the local density.\n By comparing the local density of a sample to the local densities of\n its neighbors, one can identify samples that have a substantially lower\n density than their neighbors. These are considered outliers.\n\n .. versionadded:: 0.19\n\n Parameters\n ----------\n n_neighbors : int, default=20\n Number of neighbors to use by default for :meth:`kneighbors` queries.\n If n_neighbors is larger than the number of samples provided,\n all samples will be used.\n\n algorithm : {'auto', 'ball_tree', 'kd_tree', 'brute'}, default='auto'\n Algorithm used to compute the nearest neighbors:\n\n - 'ball_tree' will use :class:`BallTree`\n - 'kd_tree' will use :class:`KDTree`\n - 'brute' will use a brute-force search.\n - 'auto' will attempt to decide the most appropriate algorithm\n based on the values passed to :meth:`fit` method.\n\n Note: fitting on sparse input will override the setting of\n this parameter, using brute force.\n\n leaf_size : int, default=30\n Leaf size passed to :class:`BallTree` or :class:`KDTree`. This can\n affect the speed of the construction and query, as well as the memory\n required to store the tree. The optimal value depends on the\n nature of the problem.\n\n metric : str or callable, default='minkowski'\n metric used for the distance computation. Any metric from scikit-learn\n or scipy.spatial.distance can be used.\n\n If metric is \"precomputed\", X is assumed to be a distance matrix and\n must be square. X may be a sparse matrix, in which case only \"nonzero\"\n elements may be considered neighbors.\n\n If metric is a callable function, it is called on each\n pair of instances (rows) and the resulting value recorded. The callable\n should take two arrays as input and return one value indicating the\n distance between them. This works for Scipy's metrics, but is less\n efficient than passing the metric name as a string.\n\n Valid values for metric are:\n\n - from scikit-learn: ['cityblock', 'cosine', 'euclidean', 'l1', 'l2',\n 'manhattan']\n\n - from scipy.spatial.distance: ['braycurtis', 'canberra', 'chebyshev',\n 'correlation', 'dice', 'hamming', 'jaccard', 'kulsinski',\n 'mahalanobis', 'minkowski', 'rogerstanimoto', 'russellrao',\n 'seuclidean', 'sokalmichener', 'sokalsneath', 'sqeuclidean',\n 'yule']\n\n See the documentation for scipy.spatial.distance for details on these\n metrics:\n https://docs.scipy.org/doc/scipy/reference/spatial.distance.html\n\n p : int, default=2\n Parameter for the Minkowski metric from\n :func:`sklearn.metrics.pairwise.pairwise_distances`. When p = 1, this\n is equivalent to using manhattan_distance (l1), and euclidean_distance\n (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used.\n\n metric_params : dict, default=None\n Additional keyword arguments for the metric function.\n\n contamination : 'auto' or float, default='auto'\n The amount of contamination of the data set, i.e. the proportion\n of outliers in the data set. When fitting this is used to define the\n threshold on the scores of the samples.\n\n - if 'auto', the threshold is determined as in the\n original paper,\n - if a float, the contamination should be in the range (0, 0.5].\n\n .. versionchanged:: 0.22\n The default value of ``contamination`` changed from 0.1\n to ``'auto'``.\n\n novelty : bool, default=False\n By default, LocalOutlierFactor is only meant to be used for outlier\n detection (novelty=False). Set novelty to True if you want to use\n LocalOutlierFactor for novelty detection. In this case be aware that\n you should only use predict, decision_function and score_samples\n on new unseen data and not on the training set.\n\n .. versionadded:: 0.20\n\n n_jobs : int, default=None\n The number of parallel jobs to run for neighbors search.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n Attributes\n ----------\n negative_outlier_factor_ : ndarray of shape (n_samples,)\n The opposite LOF of the training samples. The higher, the more normal.\n Inliers tend to have a LOF score close to 1\n (``negative_outlier_factor_`` close to -1), while outliers tend to have\n a larger LOF score.\n\n The local outlier factor (LOF) of a sample captures its\n supposed 'degree of abnormality'.\n It is the average of the ratio of the local reachability density of\n a sample and those of its k-nearest neighbors.\n\n n_neighbors_ : int\n The actual number of neighbors used for :meth:`kneighbors` queries.\n\n offset_ : float\n Offset used to obtain binary labels from the raw scores.\n Observations having a negative_outlier_factor smaller than `offset_`\n are detected as abnormal.\n The offset is set to -1.5 (inliers score around -1), except when a\n contamination parameter different than \"auto\" is provided. In that\n case, the offset is defined in such a way we obtain the expected\n number of outliers in training.\n\n .. versionadded:: 0.20\n\n effective_metric_ : str\n The effective metric used for the distance computation.\n\n effective_metric_params_ : dict\n The effective additional keyword arguments for the metric function.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_samples_fit_ : int\n It is the number of samples in the fitted data.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.neighbors import LocalOutlierFactor\n >>> X = [[-1.1], [0.2], [101.1], [0.3]]\n >>> clf = LocalOutlierFactor(n_neighbors=2)\n >>> clf.fit_predict(X)\n array([ 1, 1, -1, 1])\n >>> clf.negative_outlier_factor_\n array([ -0.9821..., -1.0370..., -73.3697..., -0.9821...])\n\n References\n ----------\n .. [1] Breunig, M. M., Kriegel, H. P., Ng, R. T., & Sander, J. (2000, May).\n LOF: identifying density-based local outliers. In ACM sigmod record.\n \"\"\"\n \n def __init__(self, n_neighbors=20, *, algorithm='auto', leaf_size=30, metric='minkowski', p=2, metric_params=None, contamination='auto', novelty=False, n_jobs=None):\n super().__init__(n_neighbors=n_neighbors, algorithm=algorithm, leaf_size=leaf_size, metric=metric, p=p, metric_params=metric_params, n_jobs=n_jobs)\n self.contamination = contamination\n self.novelty = novelty\n \n def _check_novelty_fit_predict(self):\n if self.novelty:\n msg = 'fit_predict is not available when novelty=True. Use novelty=False if you want to predict on the training set.'\n raise AttributeError(msg)\n return True\n \n @available_if(_check_novelty_fit_predict)\n def fit_predict(self, X, y=None):\n \"\"\"Fits the model to the training set X and returns the labels.\n\n **Not available for novelty detection (when novelty is set to True).**\n Label is 1 for an inlier and -1 for an outlier according to the LOF\n score and the contamination parameter.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features), default=None\n The query sample or samples to compute the Local Outlier Factor\n w.r.t. to the training samples.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n is_inlier : ndarray of shape (n_samples,)\n Returns -1 for anomalies/outliers and 1 for inliers.\n \"\"\"\n return self.fit(X)._predict()\n \n def fit(self, X, y=None):\n \"\"\"Fit the local outlier factor detector from the training dataset.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples) if metric='precomputed'\n Training data.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n self : LocalOutlierFactor\n The fitted local outlier factor detector.\n \"\"\"\n self._fit(X)\n if self.contamination != 'auto':\n if not 0.0 < self.contamination <= 0.5:\n raise ValueError('contamination must be in (0, 0.5], got: %f' % self.contamination)\n n_samples = self.n_samples_fit_\n if self.n_neighbors > n_samples:\n warnings.warn('n_neighbors (%s) is greater than the total number of samples (%s). n_neighbors will be set to (n_samples - 1) for estimation.' % (self.n_neighbors, n_samples))\n self.n_neighbors_ = max(1, min(self.n_neighbors, n_samples - 1))\n (self._distances_fit_X_, _neighbors_indices_fit_X_) = self.kneighbors(n_neighbors=self.n_neighbors_)\n self._lrd = self._local_reachability_density(self._distances_fit_X_, _neighbors_indices_fit_X_)\n lrd_ratios_array = self._lrd[_neighbors_indices_fit_X_] / self._lrd[:, np.newaxis]\n self.negative_outlier_factor_ = -np.mean(lrd_ratios_array, axis=1)\n if self.contamination == 'auto':\n self.offset_ = -1.5\n else:\n self.offset_ = np.percentile(self.negative_outlier_factor_, 100.0 * self.contamination)\n return self\n \n def _check_novelty_predict(self):\n if not self.novelty:\n msg = 'predict is not available when novelty=False, use fit_predict if you want to predict on training data. Use novelty=True if you want to use LOF for novelty detection and predict on new unseen data.'\n raise AttributeError(msg)\n return True\n \n @available_if(_check_novelty_predict)\n def predict(self, X=None):\n \"\"\"Predict the labels (1 inlier, -1 outlier) of X according to LOF.\n\n **Only available for novelty detection (when novelty is set to True).**\n This method allows to generalize prediction to *new observations* (not\n in the training set).\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The query sample or samples to compute the Local Outlier Factor\n w.r.t. to the training samples.\n\n Returns\n -------\n is_inlier : ndarray of shape (n_samples,)\n Returns -1 for anomalies/outliers and +1 for inliers.\n \"\"\"\n return self._predict(X)\n \n def _predict(self, X=None):\n \"\"\"Predict the labels (1 inlier, -1 outlier) of X according to LOF.\n\n If X is None, returns the same as fit_predict(X_train).\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features), default=None\n The query sample or samples to compute the Local Outlier Factor\n w.r.t. to the training samples. If None, makes prediction on the\n training data without considering them as their own neighbors.\n\n Returns\n -------\n is_inlier : ndarray of shape (n_samples,)\n Returns -1 for anomalies/outliers and +1 for inliers.\n \"\"\"\n check_is_fitted(self)\n if X is not None:\n X = check_array(X, accept_sparse='csr')\n is_inlier = np.ones(X.shape[0], dtype=int)\n is_inlier[self.decision_function(X) < 0] = -1\n else:\n is_inlier = np.ones(self.n_samples_fit_, dtype=int)\n is_inlier[self.negative_outlier_factor_ < self.offset_] = -1\n return is_inlier\n \n def _check_novelty_decision_function(self):\n if not self.novelty:\n msg = 'decision_function is not available when novelty=False. Use novelty=True if you want to use LOF for novelty detection and compute decision_function for new unseen data. Note that the opposite LOF of the training samples is always available by considering the negative_outlier_factor_ attribute.'\n raise AttributeError(msg)\n return True\n \n @available_if(_check_novelty_decision_function)\n def decision_function(self, X):\n \"\"\"Shifted opposite of the Local Outlier Factor of X.\n\n Bigger is better, i.e. large values correspond to inliers.\n\n **Only available for novelty detection (when novelty is set to True).**\n The shift offset allows a zero threshold for being an outlier.\n The argument X is supposed to contain *new data*: if X contains a\n point from training, it considers the later in its own neighborhood.\n Also, the samples in X are not considered in the neighborhood of any\n point.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The query sample or samples to compute the Local Outlier Factor\n w.r.t. the training samples.\n\n Returns\n -------\n shifted_opposite_lof_scores : ndarray of shape (n_samples,)\n The shifted opposite of the Local Outlier Factor of each input\n samples. The lower, the more abnormal. Negative scores represent\n outliers, positive scores represent inliers.\n \"\"\"\n return self.score_samples(X) - self.offset_\n \n def _check_novelty_score_samples(self):\n if not self.novelty:\n msg = 'score_samples is not available when novelty=False. The scores of the training samples are always available through the negative_outlier_factor_ attribute. Use novelty=True if you want to use LOF for novelty detection and compute score_samples for new unseen data.'\n raise AttributeError(msg)\n return True\n \n @available_if(_check_novelty_score_samples)\n def score_samples(self, X):\n \"\"\"Opposite of the Local Outlier Factor of X.\n\n It is the opposite as bigger is better, i.e. large values correspond\n to inliers.\n\n **Only available for novelty detection (when novelty is set to True).**\n The argument X is supposed to contain *new data*: if X contains a\n point from training, it considers the later in its own neighborhood.\n Also, the samples in X are not considered in the neighborhood of any\n point.\n The score_samples on training data is available by considering the\n the ``negative_outlier_factor_`` attribute.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The query sample or samples to compute the Local Outlier Factor\n w.r.t. the training samples.\n\n Returns\n -------\n opposite_lof_scores : ndarray of shape (n_samples,)\n The opposite of the Local Outlier Factor of each input samples.\n The lower, the more abnormal.\n \"\"\"\n check_is_fitted(self)\n X = check_array(X, accept_sparse='csr')\n (distances_X, neighbors_indices_X) = self.kneighbors(X, n_neighbors=self.n_neighbors_)\n X_lrd = self._local_reachability_density(distances_X, neighbors_indices_X)\n lrd_ratios_array = self._lrd[neighbors_indices_X] / X_lrd[:, np.newaxis]\n return -np.mean(lrd_ratios_array, axis=1)\n \n def _local_reachability_density(self, distances_X, neighbors_indices):\n \"\"\"The local reachability density (LRD)\n\n The LRD of a sample is the inverse of the average reachability\n distance of its k-nearest neighbors.\n\n Parameters\n ----------\n distances_X : ndarray of shape (n_queries, self.n_neighbors)\n Distances to the neighbors (in the training samples `self._fit_X`)\n of each query point to compute the LRD.\n\n neighbors_indices : ndarray of shape (n_queries, self.n_neighbors)\n Neighbors indices (of each query point) among training samples\n self._fit_X.\n\n Returns\n -------\n local_reachability_density : ndarray of shape (n_queries,)\n The local reachability density of each sample.\n \"\"\"\n dist_k = self._distances_fit_X_[neighbors_indices, self.n_neighbors_ - 1]\n reach_dist_array = np.maximum(distances_X, dist_k)\n return 1.0 / (np.mean(reach_dist_array, axis=1) + 1e-10)\n" + "description": "Unsupervised Outlier Detection using the Local Outlier Factor (LOF).\n\nThe anomaly score of each sample is called the Local Outlier Factor. It measures the local deviation of the density of a given sample with respect to its neighbors. It is local in that the anomaly score depends on how isolated the object is with respect to the surrounding neighborhood. More precisely, locality is given by k-nearest neighbors, whose distance is used to estimate the local density. By comparing the local density of a sample to the local densities of its neighbors, one can identify samples that have a substantially lower density than their neighbors. These are considered outliers. .. versionadded:: 0.19", + "docstring": "Unsupervised Outlier Detection using the Local Outlier Factor (LOF).\n\n The anomaly score of each sample is called the Local Outlier Factor.\n It measures the local deviation of the density of a given sample with respect\n to its neighbors.\n It is local in that the anomaly score depends on how isolated the object\n is with respect to the surrounding neighborhood.\n More precisely, locality is given by k-nearest neighbors, whose distance\n is used to estimate the local density.\n By comparing the local density of a sample to the local densities of its\n neighbors, one can identify samples that have a substantially lower density\n than their neighbors. These are considered outliers.\n\n .. versionadded:: 0.19\n\n Parameters\n ----------\n n_neighbors : int, default=20\n Number of neighbors to use by default for :meth:`kneighbors` queries.\n If n_neighbors is larger than the number of samples provided,\n all samples will be used.\n\n algorithm : {'auto', 'ball_tree', 'kd_tree', 'brute'}, default='auto'\n Algorithm used to compute the nearest neighbors:\n\n - 'ball_tree' will use :class:`BallTree`\n - 'kd_tree' will use :class:`KDTree`\n - 'brute' will use a brute-force search.\n - 'auto' will attempt to decide the most appropriate algorithm\n based on the values passed to :meth:`fit` method.\n\n Note: fitting on sparse input will override the setting of\n this parameter, using brute force.\n\n leaf_size : int, default=30\n Leaf is size passed to :class:`BallTree` or :class:`KDTree`. This can\n affect the speed of the construction and query, as well as the memory\n required to store the tree. The optimal value depends on the\n nature of the problem.\n\n metric : str or callable, default='minkowski'\n The metric is used for distance computation. Any metric from scikit-learn\n or scipy.spatial.distance can be used.\n\n If metric is \"precomputed\", X is assumed to be a distance matrix and\n must be square. X may be a sparse matrix, in which case only \"nonzero\"\n elements may be considered neighbors.\n\n If metric is a callable function, it is called on each\n pair of instances (rows) and the resulting value recorded. The callable\n should take two arrays as input and return one value indicating the\n distance between them. This works for Scipy's metrics, but is less\n efficient than passing the metric name as a string.\n\n Valid values for metric are:\n\n - from scikit-learn: ['cityblock', 'cosine', 'euclidean', 'l1', 'l2',\n 'manhattan']\n\n - from scipy.spatial.distance: ['braycurtis', 'canberra', 'chebyshev',\n 'correlation', 'dice', 'hamming', 'jaccard', 'kulsinski',\n 'mahalanobis', 'minkowski', 'rogerstanimoto', 'russellrao',\n 'seuclidean', 'sokalmichener', 'sokalsneath', 'sqeuclidean',\n 'yule']\n\n See the documentation for scipy.spatial.distance for details on these\n metrics:\n https://docs.scipy.org/doc/scipy/reference/spatial.distance.html.\n\n p : int, default=2\n Parameter for the Minkowski metric from\n :func:`sklearn.metrics.pairwise.pairwise_distances`. When p = 1, this\n is equivalent to using manhattan_distance (l1), and euclidean_distance\n (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used.\n\n metric_params : dict, default=None\n Additional keyword arguments for the metric function.\n\n contamination : 'auto' or float, default='auto'\n The amount of contamination of the data set, i.e. the proportion\n of outliers in the data set. When fitting this is used to define the\n threshold on the scores of the samples.\n\n - if 'auto', the threshold is determined as in the\n original paper,\n - if a float, the contamination should be in the range (0, 0.5].\n\n .. versionchanged:: 0.22\n The default value of ``contamination`` changed from 0.1\n to ``'auto'``.\n\n novelty : bool, default=False\n By default, LocalOutlierFactor is only meant to be used for outlier\n detection (novelty=False). Set novelty to True if you want to use\n LocalOutlierFactor for novelty detection. In this case be aware that\n you should only use predict, decision_function and score_samples\n on new unseen data and not on the training set.\n\n .. versionadded:: 0.20\n\n n_jobs : int, default=None\n The number of parallel jobs to run for neighbors search.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n Attributes\n ----------\n negative_outlier_factor_ : ndarray of shape (n_samples,)\n The opposite LOF of the training samples. The higher, the more normal.\n Inliers tend to have a LOF score close to 1\n (``negative_outlier_factor_`` close to -1), while outliers tend to have\n a larger LOF score.\n\n The local outlier factor (LOF) of a sample captures its\n supposed 'degree of abnormality'.\n It is the average of the ratio of the local reachability density of\n a sample and those of its k-nearest neighbors.\n\n n_neighbors_ : int\n The actual number of neighbors used for :meth:`kneighbors` queries.\n\n offset_ : float\n Offset used to obtain binary labels from the raw scores.\n Observations having a negative_outlier_factor smaller than `offset_`\n are detected as abnormal.\n The offset is set to -1.5 (inliers score around -1), except when a\n contamination parameter different than \"auto\" is provided. In that\n case, the offset is defined in such a way we obtain the expected\n number of outliers in training.\n\n .. versionadded:: 0.20\n\n effective_metric_ : str\n The effective metric used for the distance computation.\n\n effective_metric_params_ : dict\n The effective additional keyword arguments for the metric function.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_samples_fit_ : int\n It is the number of samples in the fitted data.\n\n See also\n ----------\n sklearn.svm.OneClassSVM: Unsupervised Outlier Detection using\n Support Vector Machine.\n\n References\n ----------\n .. [1] Breunig, M. M., Kriegel, H. P., Ng, R. T., & Sander, J. (2000, May).\n LOF: identifying density-based local outliers. In ACM sigmod record.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.neighbors import LocalOutlierFactor\n >>> X = [[-1.1], [0.2], [101.1], [0.3]]\n >>> clf = LocalOutlierFactor(n_neighbors=2)\n >>> clf.fit_predict(X)\n array([ 1, 1, -1, 1])\n >>> clf.negative_outlier_factor_\n array([ -0.9821..., -1.0370..., -73.3697..., -0.9821...])\n ", + "source_code": "\n\nclass LocalOutlierFactor(KNeighborsMixin, OutlierMixin, NeighborsBase):\n \"\"\"Unsupervised Outlier Detection using the Local Outlier Factor (LOF).\n\n The anomaly score of each sample is called the Local Outlier Factor.\n It measures the local deviation of the density of a given sample with respect\n to its neighbors.\n It is local in that the anomaly score depends on how isolated the object\n is with respect to the surrounding neighborhood.\n More precisely, locality is given by k-nearest neighbors, whose distance\n is used to estimate the local density.\n By comparing the local density of a sample to the local densities of its\n neighbors, one can identify samples that have a substantially lower density\n than their neighbors. These are considered outliers.\n\n .. versionadded:: 0.19\n\n Parameters\n ----------\n n_neighbors : int, default=20\n Number of neighbors to use by default for :meth:`kneighbors` queries.\n If n_neighbors is larger than the number of samples provided,\n all samples will be used.\n\n algorithm : {'auto', 'ball_tree', 'kd_tree', 'brute'}, default='auto'\n Algorithm used to compute the nearest neighbors:\n\n - 'ball_tree' will use :class:`BallTree`\n - 'kd_tree' will use :class:`KDTree`\n - 'brute' will use a brute-force search.\n - 'auto' will attempt to decide the most appropriate algorithm\n based on the values passed to :meth:`fit` method.\n\n Note: fitting on sparse input will override the setting of\n this parameter, using brute force.\n\n leaf_size : int, default=30\n Leaf is size passed to :class:`BallTree` or :class:`KDTree`. This can\n affect the speed of the construction and query, as well as the memory\n required to store the tree. The optimal value depends on the\n nature of the problem.\n\n metric : str or callable, default='minkowski'\n The metric is used for distance computation. Any metric from scikit-learn\n or scipy.spatial.distance can be used.\n\n If metric is \"precomputed\", X is assumed to be a distance matrix and\n must be square. X may be a sparse matrix, in which case only \"nonzero\"\n elements may be considered neighbors.\n\n If metric is a callable function, it is called on each\n pair of instances (rows) and the resulting value recorded. The callable\n should take two arrays as input and return one value indicating the\n distance between them. This works for Scipy's metrics, but is less\n efficient than passing the metric name as a string.\n\n Valid values for metric are:\n\n - from scikit-learn: ['cityblock', 'cosine', 'euclidean', 'l1', 'l2',\n 'manhattan']\n\n - from scipy.spatial.distance: ['braycurtis', 'canberra', 'chebyshev',\n 'correlation', 'dice', 'hamming', 'jaccard', 'kulsinski',\n 'mahalanobis', 'minkowski', 'rogerstanimoto', 'russellrao',\n 'seuclidean', 'sokalmichener', 'sokalsneath', 'sqeuclidean',\n 'yule']\n\n See the documentation for scipy.spatial.distance for details on these\n metrics:\n https://docs.scipy.org/doc/scipy/reference/spatial.distance.html.\n\n p : int, default=2\n Parameter for the Minkowski metric from\n :func:`sklearn.metrics.pairwise.pairwise_distances`. When p = 1, this\n is equivalent to using manhattan_distance (l1), and euclidean_distance\n (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used.\n\n metric_params : dict, default=None\n Additional keyword arguments for the metric function.\n\n contamination : 'auto' or float, default='auto'\n The amount of contamination of the data set, i.e. the proportion\n of outliers in the data set. When fitting this is used to define the\n threshold on the scores of the samples.\n\n - if 'auto', the threshold is determined as in the\n original paper,\n - if a float, the contamination should be in the range (0, 0.5].\n\n .. versionchanged:: 0.22\n The default value of ``contamination`` changed from 0.1\n to ``'auto'``.\n\n novelty : bool, default=False\n By default, LocalOutlierFactor is only meant to be used for outlier\n detection (novelty=False). Set novelty to True if you want to use\n LocalOutlierFactor for novelty detection. In this case be aware that\n you should only use predict, decision_function and score_samples\n on new unseen data and not on the training set.\n\n .. versionadded:: 0.20\n\n n_jobs : int, default=None\n The number of parallel jobs to run for neighbors search.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n Attributes\n ----------\n negative_outlier_factor_ : ndarray of shape (n_samples,)\n The opposite LOF of the training samples. The higher, the more normal.\n Inliers tend to have a LOF score close to 1\n (``negative_outlier_factor_`` close to -1), while outliers tend to have\n a larger LOF score.\n\n The local outlier factor (LOF) of a sample captures its\n supposed 'degree of abnormality'.\n It is the average of the ratio of the local reachability density of\n a sample and those of its k-nearest neighbors.\n\n n_neighbors_ : int\n The actual number of neighbors used for :meth:`kneighbors` queries.\n\n offset_ : float\n Offset used to obtain binary labels from the raw scores.\n Observations having a negative_outlier_factor smaller than `offset_`\n are detected as abnormal.\n The offset is set to -1.5 (inliers score around -1), except when a\n contamination parameter different than \"auto\" is provided. In that\n case, the offset is defined in such a way we obtain the expected\n number of outliers in training.\n\n .. versionadded:: 0.20\n\n effective_metric_ : str\n The effective metric used for the distance computation.\n\n effective_metric_params_ : dict\n The effective additional keyword arguments for the metric function.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_samples_fit_ : int\n It is the number of samples in the fitted data.\n\n See also\n ----------\n sklearn.svm.OneClassSVM: Unsupervised Outlier Detection using\n Support Vector Machine.\n\n References\n ----------\n .. [1] Breunig, M. M., Kriegel, H. P., Ng, R. T., & Sander, J. (2000, May).\n LOF: identifying density-based local outliers. In ACM sigmod record.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.neighbors import LocalOutlierFactor\n >>> X = [[-1.1], [0.2], [101.1], [0.3]]\n >>> clf = LocalOutlierFactor(n_neighbors=2)\n >>> clf.fit_predict(X)\n array([ 1, 1, -1, 1])\n >>> clf.negative_outlier_factor_\n array([ -0.9821..., -1.0370..., -73.3697..., -0.9821...])\n \"\"\"\n \n def __init__(self, n_neighbors=20, *, algorithm='auto', leaf_size=30, metric='minkowski', p=2, metric_params=None, contamination='auto', novelty=False, n_jobs=None):\n super().__init__(n_neighbors=n_neighbors, algorithm=algorithm, leaf_size=leaf_size, metric=metric, p=p, metric_params=metric_params, n_jobs=n_jobs)\n self.contamination = contamination\n self.novelty = novelty\n \n def _check_novelty_fit_predict(self):\n if self.novelty:\n msg = 'fit_predict is not available when novelty=True. Use novelty=False if you want to predict on the training set.'\n raise AttributeError(msg)\n return True\n \n @available_if(_check_novelty_fit_predict)\n def fit_predict(self, X, y=None):\n \"\"\"Fit the model to the training set X and return the labels.\n\n **Not available for novelty detection (when novelty is set to True).**\n Label is 1 for an inlier and -1 for an outlier according to the LOF\n score and the contamination parameter.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features), default=None\n The query sample or samples to compute the Local Outlier Factor\n w.r.t. to the training samples.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n is_inlier : ndarray of shape (n_samples,)\n Returns -1 for anomalies/outliers and 1 for inliers.\n \"\"\"\n return self.fit(X)._predict()\n \n def fit(self, X, y=None):\n \"\"\"Fit the local outlier factor detector from the training dataset.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples) if metric='precomputed'\n Training data.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n self : LocalOutlierFactor\n The fitted local outlier factor detector.\n \"\"\"\n self._fit(X)\n if self.contamination != 'auto':\n if not 0.0 < self.contamination <= 0.5:\n raise ValueError('contamination must be in (0, 0.5], got: %f' % self.contamination)\n n_samples = self.n_samples_fit_\n if self.n_neighbors > n_samples:\n warnings.warn('n_neighbors (%s) is greater than the total number of samples (%s). n_neighbors will be set to (n_samples - 1) for estimation.' % (self.n_neighbors, n_samples))\n self.n_neighbors_ = max(1, min(self.n_neighbors, n_samples - 1))\n (self._distances_fit_X_, _neighbors_indices_fit_X_) = self.kneighbors(n_neighbors=self.n_neighbors_)\n self._lrd = self._local_reachability_density(self._distances_fit_X_, _neighbors_indices_fit_X_)\n lrd_ratios_array = self._lrd[_neighbors_indices_fit_X_] / self._lrd[:, np.newaxis]\n self.negative_outlier_factor_ = -np.mean(lrd_ratios_array, axis=1)\n if self.contamination == 'auto':\n self.offset_ = -1.5\n else:\n self.offset_ = np.percentile(self.negative_outlier_factor_, 100.0 * self.contamination)\n return self\n \n def _check_novelty_predict(self):\n if not self.novelty:\n msg = 'predict is not available when novelty=False, use fit_predict if you want to predict on training data. Use novelty=True if you want to use LOF for novelty detection and predict on new unseen data.'\n raise AttributeError(msg)\n return True\n \n @available_if(_check_novelty_predict)\n def predict(self, X=None):\n \"\"\"Predict the labels (1 inlier, -1 outlier) of X according to LOF.\n\n **Only available for novelty detection (when novelty is set to True).**\n This method allows to generalize prediction to *new observations* (not\n in the training set).\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The query sample or samples to compute the Local Outlier Factor\n w.r.t. to the training samples.\n\n Returns\n -------\n is_inlier : ndarray of shape (n_samples,)\n Returns -1 for anomalies/outliers and +1 for inliers.\n \"\"\"\n return self._predict(X)\n \n def _predict(self, X=None):\n \"\"\"Predict the labels (1 inlier, -1 outlier) of X according to LOF.\n\n If X is None, returns the same as fit_predict(X_train).\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features), default=None\n The query sample or samples to compute the Local Outlier Factor\n w.r.t. to the training samples. If None, makes prediction on the\n training data without considering them as their own neighbors.\n\n Returns\n -------\n is_inlier : ndarray of shape (n_samples,)\n Returns -1 for anomalies/outliers and +1 for inliers.\n \"\"\"\n check_is_fitted(self)\n if X is not None:\n X = check_array(X, accept_sparse='csr')\n is_inlier = np.ones(X.shape[0], dtype=int)\n is_inlier[self.decision_function(X) < 0] = -1\n else:\n is_inlier = np.ones(self.n_samples_fit_, dtype=int)\n is_inlier[self.negative_outlier_factor_ < self.offset_] = -1\n return is_inlier\n \n def _check_novelty_decision_function(self):\n if not self.novelty:\n msg = 'decision_function is not available when novelty=False. Use novelty=True if you want to use LOF for novelty detection and compute decision_function for new unseen data. Note that the opposite LOF of the training samples is always available by considering the negative_outlier_factor_ attribute.'\n raise AttributeError(msg)\n return True\n \n @available_if(_check_novelty_decision_function)\n def decision_function(self, X):\n \"\"\"Shifted opposite of the Local Outlier Factor of X.\n\n Bigger is better, i.e. large values correspond to inliers.\n\n **Only available for novelty detection (when novelty is set to True).**\n The shift offset allows a zero threshold for being an outlier.\n The argument X is supposed to contain *new data*: if X contains a\n point from training, it considers the later in its own neighborhood.\n Also, the samples in X are not considered in the neighborhood of any\n point.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The query sample or samples to compute the Local Outlier Factor\n w.r.t. the training samples.\n\n Returns\n -------\n shifted_opposite_lof_scores : ndarray of shape (n_samples,)\n The shifted opposite of the Local Outlier Factor of each input\n samples. The lower, the more abnormal. Negative scores represent\n outliers, positive scores represent inliers.\n \"\"\"\n return self.score_samples(X) - self.offset_\n \n def _check_novelty_score_samples(self):\n if not self.novelty:\n msg = 'score_samples is not available when novelty=False. The scores of the training samples are always available through the negative_outlier_factor_ attribute. Use novelty=True if you want to use LOF for novelty detection and compute score_samples for new unseen data.'\n raise AttributeError(msg)\n return True\n \n @available_if(_check_novelty_score_samples)\n def score_samples(self, X):\n \"\"\"Opposite of the Local Outlier Factor of X.\n\n It is the opposite as bigger is better, i.e. large values correspond\n to inliers.\n\n **Only available for novelty detection (when novelty is set to True).**\n The argument X is supposed to contain *new data*: if X contains a\n point from training, it considers the later in its own neighborhood.\n Also, the samples in X are not considered in the neighborhood of any\n point.\n The score_samples on training data is available by considering the\n the ``negative_outlier_factor_`` attribute.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The query sample or samples to compute the Local Outlier Factor\n w.r.t. the training samples.\n\n Returns\n -------\n opposite_lof_scores : ndarray of shape (n_samples,)\n The opposite of the Local Outlier Factor of each input samples.\n The lower, the more abnormal.\n \"\"\"\n check_is_fitted(self)\n X = check_array(X, accept_sparse='csr')\n (distances_X, neighbors_indices_X) = self.kneighbors(X, n_neighbors=self.n_neighbors_)\n X_lrd = self._local_reachability_density(distances_X, neighbors_indices_X)\n lrd_ratios_array = self._lrd[neighbors_indices_X] / X_lrd[:, np.newaxis]\n return -np.mean(lrd_ratios_array, axis=1)\n \n def _local_reachability_density(self, distances_X, neighbors_indices):\n \"\"\"The local reachability density (LRD)\n\n The LRD of a sample is the inverse of the average reachability\n distance of its k-nearest neighbors.\n\n Parameters\n ----------\n distances_X : ndarray of shape (n_queries, self.n_neighbors)\n Distances to the neighbors (in the training samples `self._fit_X`)\n of each query point to compute the LRD.\n\n neighbors_indices : ndarray of shape (n_queries, self.n_neighbors)\n Neighbors indices (of each query point) among training samples\n self._fit_X.\n\n Returns\n -------\n local_reachability_density : ndarray of shape (n_queries,)\n The local reachability density of each sample.\n \"\"\"\n dist_k = self._distances_fit_X_[neighbors_indices, self.n_neighbors_ - 1]\n reach_dist_array = np.maximum(distances_X, dist_k)\n return 1.0 / (np.mean(reach_dist_array, axis=1) + 1e-10)\n" }, { "name": "NeighborhoodComponentsAnalysis", @@ -25562,9 +25515,9 @@ "sklearn.neighbors._nca.NeighborhoodComponentsAnalysis._more_tags" ], "is_public": true, - "description": "Neighborhood Components Analysis\n\nNeighborhood Component Analysis (NCA) is a machine learning algorithm for metric learning. It learns a linear transformation in a supervised fashion to improve the classification accuracy of a stochastic nearest neighbors rule in the transformed space. Read more in the :ref:`User Guide `.", - "docstring": "Neighborhood Components Analysis\n\n Neighborhood Component Analysis (NCA) is a machine learning algorithm for\n metric learning. It learns a linear transformation in a supervised fashion\n to improve the classification accuracy of a stochastic nearest neighbors\n rule in the transformed space.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_components : int, default=None\n Preferred dimensionality of the projected space.\n If None it will be set to ``n_features``.\n\n init : {'auto', 'pca', 'lda', 'identity', 'random'} or ndarray of shape (n_features_a, n_features_b), default='auto'\n Initialization of the linear transformation. Possible options are\n 'auto', 'pca', 'lda', 'identity', 'random', and a numpy array of shape\n (n_features_a, n_features_b).\n\n 'auto'\n Depending on ``n_components``, the most reasonable initialization\n will be chosen. If ``n_components <= n_classes`` we use 'lda', as\n it uses labels information. If not, but\n ``n_components < min(n_features, n_samples)``, we use 'pca', as\n it projects data in meaningful directions (those of higher\n variance). Otherwise, we just use 'identity'.\n\n 'pca'\n ``n_components`` principal components of the inputs passed\n to :meth:`fit` will be used to initialize the transformation.\n (See :class:`~sklearn.decomposition.PCA`)\n\n 'lda'\n ``min(n_components, n_classes)`` most discriminative\n components of the inputs passed to :meth:`fit` will be used to\n initialize the transformation. (If ``n_components > n_classes``,\n the rest of the components will be zero.) (See\n :class:`~sklearn.discriminant_analysis.LinearDiscriminantAnalysis`)\n\n 'identity'\n If ``n_components`` is strictly smaller than the\n dimensionality of the inputs passed to :meth:`fit`, the identity\n matrix will be truncated to the first ``n_components`` rows.\n\n 'random'\n The initial transformation will be a random array of shape\n `(n_components, n_features)`. Each value is sampled from the\n standard normal distribution.\n\n numpy array\n n_features_b must match the dimensionality of the inputs passed to\n :meth:`fit` and n_features_a must be less than or equal to that.\n If ``n_components`` is not None, n_features_a must match it.\n\n warm_start : bool, default=False\n If True and :meth:`fit` has been called before, the solution of the\n previous call to :meth:`fit` is used as the initial linear\n transformation (``n_components`` and ``init`` will be ignored).\n\n max_iter : int, default=50\n Maximum number of iterations in the optimization.\n\n tol : float, default=1e-5\n Convergence tolerance for the optimization.\n\n callback : callable, default=None\n If not None, this function is called after every iteration of the\n optimizer, taking as arguments the current solution (flattened\n transformation matrix) and the number of iterations. This might be\n useful in case one wants to examine or store the transformation\n found after each iteration.\n\n verbose : int, default=0\n If 0, no progress messages will be printed.\n If 1, progress messages will be printed to stdout.\n If > 1, progress messages will be printed and the ``disp``\n parameter of :func:`scipy.optimize.minimize` will be set to\n ``verbose - 2``.\n\n random_state : int or numpy.RandomState, default=None\n A pseudo random number generator object or a seed for it if int. If\n ``init='random'``, ``random_state`` is used to initialize the random\n transformation. If ``init='pca'``, ``random_state`` is passed as an\n argument to PCA when initializing the transformation. Pass an int\n for reproducible results across multiple function calls.\n See :term: `Glossary `.\n\n Attributes\n ----------\n components_ : ndarray of shape (n_components, n_features)\n The linear transformation learned during fitting.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n n_iter_ : int\n Counts the number of iterations performed by the optimizer.\n\n random_state_ : numpy.RandomState\n Pseudo random number generator object used during initialization.\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn.neighbors import NeighborhoodComponentsAnalysis\n >>> from sklearn.neighbors import KNeighborsClassifier\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.model_selection import train_test_split\n >>> X, y = load_iris(return_X_y=True)\n >>> X_train, X_test, y_train, y_test = train_test_split(X, y,\n ... stratify=y, test_size=0.7, random_state=42)\n >>> nca = NeighborhoodComponentsAnalysis(random_state=42)\n >>> nca.fit(X_train, y_train)\n NeighborhoodComponentsAnalysis(...)\n >>> knn = KNeighborsClassifier(n_neighbors=3)\n >>> knn.fit(X_train, y_train)\n KNeighborsClassifier(...)\n >>> print(knn.score(X_test, y_test))\n 0.933333...\n >>> knn.fit(nca.transform(X_train), y_train)\n KNeighborsClassifier(...)\n >>> print(knn.score(nca.transform(X_test), y_test))\n 0.961904...\n\n References\n ----------\n .. [1] J. Goldberger, G. Hinton, S. Roweis, R. Salakhutdinov.\n \"Neighbourhood Components Analysis\". Advances in Neural Information\n Processing Systems. 17, 513-520, 2005.\n http://www.cs.nyu.edu/~roweis/papers/ncanips.pdf\n\n .. [2] Wikipedia entry on Neighborhood Components Analysis\n https://en.wikipedia.org/wiki/Neighbourhood_components_analysis\n\n ", - "source_code": "\n\nclass NeighborhoodComponentsAnalysis(TransformerMixin, BaseEstimator):\n \"\"\"Neighborhood Components Analysis\n\n Neighborhood Component Analysis (NCA) is a machine learning algorithm for\n metric learning. It learns a linear transformation in a supervised fashion\n to improve the classification accuracy of a stochastic nearest neighbors\n rule in the transformed space.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_components : int, default=None\n Preferred dimensionality of the projected space.\n If None it will be set to ``n_features``.\n\n init : {'auto', 'pca', 'lda', 'identity', 'random'} or ndarray of shape (n_features_a, n_features_b), default='auto'\n Initialization of the linear transformation. Possible options are\n 'auto', 'pca', 'lda', 'identity', 'random', and a numpy array of shape\n (n_features_a, n_features_b).\n\n 'auto'\n Depending on ``n_components``, the most reasonable initialization\n will be chosen. If ``n_components <= n_classes`` we use 'lda', as\n it uses labels information. If not, but\n ``n_components < min(n_features, n_samples)``, we use 'pca', as\n it projects data in meaningful directions (those of higher\n variance). Otherwise, we just use 'identity'.\n\n 'pca'\n ``n_components`` principal components of the inputs passed\n to :meth:`fit` will be used to initialize the transformation.\n (See :class:`~sklearn.decomposition.PCA`)\n\n 'lda'\n ``min(n_components, n_classes)`` most discriminative\n components of the inputs passed to :meth:`fit` will be used to\n initialize the transformation. (If ``n_components > n_classes``,\n the rest of the components will be zero.) (See\n :class:`~sklearn.discriminant_analysis.LinearDiscriminantAnalysis`)\n\n 'identity'\n If ``n_components`` is strictly smaller than the\n dimensionality of the inputs passed to :meth:`fit`, the identity\n matrix will be truncated to the first ``n_components`` rows.\n\n 'random'\n The initial transformation will be a random array of shape\n `(n_components, n_features)`. Each value is sampled from the\n standard normal distribution.\n\n numpy array\n n_features_b must match the dimensionality of the inputs passed to\n :meth:`fit` and n_features_a must be less than or equal to that.\n If ``n_components`` is not None, n_features_a must match it.\n\n warm_start : bool, default=False\n If True and :meth:`fit` has been called before, the solution of the\n previous call to :meth:`fit` is used as the initial linear\n transformation (``n_components`` and ``init`` will be ignored).\n\n max_iter : int, default=50\n Maximum number of iterations in the optimization.\n\n tol : float, default=1e-5\n Convergence tolerance for the optimization.\n\n callback : callable, default=None\n If not None, this function is called after every iteration of the\n optimizer, taking as arguments the current solution (flattened\n transformation matrix) and the number of iterations. This might be\n useful in case one wants to examine or store the transformation\n found after each iteration.\n\n verbose : int, default=0\n If 0, no progress messages will be printed.\n If 1, progress messages will be printed to stdout.\n If > 1, progress messages will be printed and the ``disp``\n parameter of :func:`scipy.optimize.minimize` will be set to\n ``verbose - 2``.\n\n random_state : int or numpy.RandomState, default=None\n A pseudo random number generator object or a seed for it if int. If\n ``init='random'``, ``random_state`` is used to initialize the random\n transformation. If ``init='pca'``, ``random_state`` is passed as an\n argument to PCA when initializing the transformation. Pass an int\n for reproducible results across multiple function calls.\n See :term: `Glossary `.\n\n Attributes\n ----------\n components_ : ndarray of shape (n_components, n_features)\n The linear transformation learned during fitting.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n n_iter_ : int\n Counts the number of iterations performed by the optimizer.\n\n random_state_ : numpy.RandomState\n Pseudo random number generator object used during initialization.\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn.neighbors import NeighborhoodComponentsAnalysis\n >>> from sklearn.neighbors import KNeighborsClassifier\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.model_selection import train_test_split\n >>> X, y = load_iris(return_X_y=True)\n >>> X_train, X_test, y_train, y_test = train_test_split(X, y,\n ... stratify=y, test_size=0.7, random_state=42)\n >>> nca = NeighborhoodComponentsAnalysis(random_state=42)\n >>> nca.fit(X_train, y_train)\n NeighborhoodComponentsAnalysis(...)\n >>> knn = KNeighborsClassifier(n_neighbors=3)\n >>> knn.fit(X_train, y_train)\n KNeighborsClassifier(...)\n >>> print(knn.score(X_test, y_test))\n 0.933333...\n >>> knn.fit(nca.transform(X_train), y_train)\n KNeighborsClassifier(...)\n >>> print(knn.score(nca.transform(X_test), y_test))\n 0.961904...\n\n References\n ----------\n .. [1] J. Goldberger, G. Hinton, S. Roweis, R. Salakhutdinov.\n \"Neighbourhood Components Analysis\". Advances in Neural Information\n Processing Systems. 17, 513-520, 2005.\n http://www.cs.nyu.edu/~roweis/papers/ncanips.pdf\n\n .. [2] Wikipedia entry on Neighborhood Components Analysis\n https://en.wikipedia.org/wiki/Neighbourhood_components_analysis\n\n \"\"\"\n \n def __init__(self, n_components=None, *, init='auto', warm_start=False, max_iter=50, tol=1e-05, callback=None, verbose=0, random_state=None):\n self.n_components = n_components\n self.init = init\n self.warm_start = warm_start\n self.max_iter = max_iter\n self.tol = tol\n self.callback = callback\n self.verbose = verbose\n self.random_state = random_state\n \n def fit(self, X, y):\n \"\"\"Fit the model according to the given training data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The training samples.\n\n y : array-like of shape (n_samples,)\n The corresponding training labels.\n\n Returns\n -------\n self : object\n returns a trained NeighborhoodComponentsAnalysis model.\n \"\"\"\n (X, y, init) = self._validate_params(X, y)\n self.random_state_ = check_random_state(self.random_state)\n t_train = time.time()\n same_class_mask = y[:, np.newaxis] == y[np.newaxis, :]\n transformation = self._initialize(X, y, init)\n disp = self.verbose - 2 if self.verbose > 1 else -1\n optimizer_params = {'method': 'L-BFGS-B', 'fun': self._loss_grad_lbfgs, 'args': (X, same_class_mask, -1.0), 'jac': True, 'x0': transformation, 'tol': self.tol, 'options': dict(maxiter=self.max_iter, disp=disp), 'callback': self._callback}\n self.n_iter_ = 0\n opt_result = minimize(**optimizer_params)\n self.components_ = opt_result.x.reshape(-1, X.shape[1])\n t_train = time.time() - t_train\n if self.verbose:\n cls_name = self.__class__.__name__\n if not opt_result.success:\n warn('[{}] NCA did not converge: {}'.format(cls_name, opt_result.message), ConvergenceWarning)\n print('[{}] Training took {:8.2f}s.'.format(cls_name, t_train))\n return self\n \n def transform(self, X):\n \"\"\"Applies the learned transformation to the given data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Data samples.\n\n Returns\n -------\n X_embedded: ndarray of shape (n_samples, n_components)\n The data samples transformed.\n\n Raises\n ------\n NotFittedError\n If :meth:`fit` has not been called before.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, reset=False)\n return np.dot(X, self.components_.T)\n \n def _validate_params(self, X, y):\n \"\"\"Validate parameters as soon as :meth:`fit` is called.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The training samples.\n\n y : array-like of shape (n_samples,)\n The corresponding training labels.\n\n Returns\n -------\n X : ndarray of shape (n_samples, n_features)\n The validated training samples.\n\n y : ndarray of shape (n_samples,)\n The validated training labels, encoded to be integers in\n the range(0, n_classes).\n\n init : str or ndarray of shape (n_features_a, n_features_b)\n The validated initialization of the linear transformation.\n\n Raises\n -------\n TypeError\n If a parameter is not an instance of the desired type.\n\n ValueError\n If a parameter's value violates its legal value range or if the\n combination of two or more given parameters is incompatible.\n \"\"\"\n (X, y) = self._validate_data(X, y, ensure_min_samples=2)\n check_classification_targets(y)\n y = LabelEncoder().fit_transform(y)\n if self.n_components is not None:\n check_scalar(self.n_components, 'n_components', numbers.Integral, min_val=1)\n if self.n_components > X.shape[1]:\n raise ValueError('The preferred dimensionality of the projected space `n_components` ({}) cannot be greater than the given data dimensionality ({})!'.format(self.n_components, X.shape[1]))\n check_scalar(self.warm_start, 'warm_start', bool)\n if self.warm_start and hasattr(self, 'components_'):\n if self.components_.shape[1] != X.shape[1]:\n raise ValueError('The new inputs dimensionality ({}) does not match the input dimensionality of the previously learned transformation ({}).'.format(X.shape[1], self.components_.shape[1]))\n check_scalar(self.max_iter, 'max_iter', numbers.Integral, min_val=1)\n check_scalar(self.tol, 'tol', numbers.Real, min_val=0.0)\n check_scalar(self.verbose, 'verbose', numbers.Integral, min_val=0)\n if self.callback is not None:\n if not callable(self.callback):\n raise ValueError('`callback` is not callable.')\n init = self.init\n if isinstance(init, np.ndarray):\n init = check_array(init)\n if init.shape[1] != X.shape[1]:\n raise ValueError('The input dimensionality ({}) of the given linear transformation `init` must match the dimensionality of the given inputs `X` ({}).'.format(init.shape[1], X.shape[1]))\n if init.shape[0] > init.shape[1]:\n raise ValueError('The output dimensionality ({}) of the given linear transformation `init` cannot be greater than its input dimensionality ({}).'.format(init.shape[0], init.shape[1]))\n if self.n_components is not None:\n if self.n_components != init.shape[0]:\n raise ValueError('The preferred dimensionality of the projected space `n_components` ({}) does not match the output dimensionality of the given linear transformation `init` ({})!'.format(self.n_components, init.shape[0]))\n elif init in ['auto', 'pca', 'lda', 'identity', 'random']:\n pass\n else:\n raise ValueError(\"`init` must be 'auto', 'pca', 'lda', 'identity', 'random' or a numpy array of shape (n_components, n_features).\")\n return X, y, init\n \n def _initialize(self, X, y, init):\n \"\"\"Initialize the transformation.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The training samples.\n\n y : array-like of shape (n_samples,)\n The training labels.\n\n init : str or ndarray of shape (n_features_a, n_features_b)\n The validated initialization of the linear transformation.\n\n Returns\n -------\n transformation : ndarray of shape (n_components, n_features)\n The initialized linear transformation.\n\n \"\"\"\n transformation = init\n if self.warm_start and hasattr(self, 'components_'):\n transformation = self.components_\n elif isinstance(init, np.ndarray):\n pass\n else:\n (n_samples, n_features) = X.shape\n n_components = self.n_components or n_features\n if init == 'auto':\n n_classes = len(np.unique(y))\n if n_components <= min(n_features, n_classes - 1):\n init = 'lda'\n elif n_components < min(n_features, n_samples):\n init = 'pca'\n else:\n init = 'identity'\n if init == 'identity':\n transformation = np.eye(n_components, X.shape[1])\n elif init == 'random':\n transformation = self.random_state_.randn(n_components, X.shape[1])\n elif init in {'pca', 'lda'}:\n init_time = time.time()\n if init == 'pca':\n pca = PCA(n_components=n_components, random_state=self.random_state_)\n if self.verbose:\n print('Finding principal components... ', end='')\n sys.stdout.flush()\n pca.fit(X)\n transformation = pca.components_\n elif init == 'lda':\n from ..discriminant_analysis import LinearDiscriminantAnalysis\n lda = LinearDiscriminantAnalysis(n_components=n_components)\n if self.verbose:\n print('Finding most discriminative components... ', end='')\n sys.stdout.flush()\n lda.fit(X, y)\n transformation = lda.scalings_.T[:n_components]\n if self.verbose:\n print('done in {:5.2f}s'.format(time.time() - init_time))\n return transformation\n \n def _callback(self, transformation):\n \"\"\"Called after each iteration of the optimizer.\n\n Parameters\n ----------\n transformation : ndarray of shape (n_components * n_features,)\n The solution computed by the optimizer in this iteration.\n \"\"\"\n if self.callback is not None:\n self.callback(transformation, self.n_iter_)\n self.n_iter_ += 1\n \n def _loss_grad_lbfgs(self, transformation, X, same_class_mask, sign=1.0):\n \"\"\"Compute the loss and the loss gradient w.r.t. ``transformation``.\n\n Parameters\n ----------\n transformation : ndarray of shape (n_components * n_features,)\n The raveled linear transformation on which to compute loss and\n evaluate gradient.\n\n X : ndarray of shape (n_samples, n_features)\n The training samples.\n\n same_class_mask : ndarray of shape (n_samples, n_samples)\n A mask where ``mask[i, j] == 1`` if ``X[i]`` and ``X[j]`` belong\n to the same class, and ``0`` otherwise.\n\n Returns\n -------\n loss : float\n The loss computed for the given transformation.\n\n gradient : ndarray of shape (n_components * n_features,)\n The new (flattened) gradient of the loss.\n \"\"\"\n if self.n_iter_ == 0:\n self.n_iter_ += 1\n if self.verbose:\n header_fields = ['Iteration', 'Objective Value', 'Time(s)']\n header_fmt = '{:>10} {:>20} {:>10}'\n header = header_fmt.format(*header_fields)\n cls_name = self.__class__.__name__\n print('[{}]'.format(cls_name))\n print('[{}] {}\\n[{}] {}'.format(cls_name, header, cls_name, '-' * len(header)))\n t_funcall = time.time()\n transformation = transformation.reshape(-1, X.shape[1])\n X_embedded = np.dot(X, transformation.T)\n p_ij = pairwise_distances(X_embedded, squared=True)\n np.fill_diagonal(p_ij, np.inf)\n p_ij = softmax(-p_ij)\n masked_p_ij = p_ij * same_class_mask\n p = np.sum(masked_p_ij, axis=1, keepdims=True)\n loss = np.sum(p)\n weighted_p_ij = masked_p_ij - p_ij * p\n weighted_p_ij_sym = weighted_p_ij + weighted_p_ij.T\n np.fill_diagonal(weighted_p_ij_sym, -weighted_p_ij.sum(axis=0))\n gradient = 2 * X_embedded.T.dot(weighted_p_ij_sym).dot(X)\n if self.verbose:\n t_funcall = time.time() - t_funcall\n values_fmt = '[{}] {:>10} {:>20.6e} {:>10.2f}'\n print(values_fmt.format(self.__class__.__name__, self.n_iter_, loss, t_funcall))\n sys.stdout.flush()\n return sign * loss, sign * gradient.ravel()\n \n def _more_tags(self):\n return {'requires_y': True}\n" + "description": "Neighborhood Components Analysis.\n\nNeighborhood Component Analysis (NCA) is a machine learning algorithm for metric learning. It learns a linear transformation in a supervised fashion to improve the classification accuracy of a stochastic nearest neighbors rule in the transformed space. Read more in the :ref:`User Guide `.", + "docstring": "Neighborhood Components Analysis.\n\n Neighborhood Component Analysis (NCA) is a machine learning algorithm for\n metric learning. It learns a linear transformation in a supervised fashion\n to improve the classification accuracy of a stochastic nearest neighbors\n rule in the transformed space.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_components : int, default=None\n Preferred dimensionality of the projected space.\n If None it will be set to `n_features`.\n\n init : {'auto', 'pca', 'lda', 'identity', 'random'} or ndarray of shape (n_features_a, n_features_b), default='auto'\n Initialization of the linear transformation. Possible options are\n `'auto'`, `'pca'`, `'lda'`, `'identity'`, `'random'`, and a numpy\n array of shape `(n_features_a, n_features_b)`.\n\n - `'auto'`\n Depending on `n_components`, the most reasonable initialization\n will be chosen. If `n_components <= n_classes` we use `'lda'`, as\n it uses labels information. If not, but\n `n_components < min(n_features, n_samples)`, we use `'pca'`, as\n it projects data in meaningful directions (those of higher\n variance). Otherwise, we just use `'identity'`.\n\n - `'pca'`\n `n_components` principal components of the inputs passed\n to :meth:`fit` will be used to initialize the transformation.\n (See :class:`~sklearn.decomposition.PCA`)\n\n - `'lda'`\n `min(n_components, n_classes)` most discriminative\n components of the inputs passed to :meth:`fit` will be used to\n initialize the transformation. (If `n_components > n_classes`,\n the rest of the components will be zero.) (See\n :class:`~sklearn.discriminant_analysis.LinearDiscriminantAnalysis`)\n\n - `'identity'`\n If `n_components` is strictly smaller than the\n dimensionality of the inputs passed to :meth:`fit`, the identity\n matrix will be truncated to the first `n_components` rows.\n\n - `'random'`\n The initial transformation will be a random array of shape\n `(n_components, n_features)`. Each value is sampled from the\n standard normal distribution.\n\n - numpy array\n `n_features_b` must match the dimensionality of the inputs passed\n to :meth:`fit` and n_features_a must be less than or equal to that.\n If `n_components` is not `None`, `n_features_a` must match it.\n\n warm_start : bool, default=False\n If `True` and :meth:`fit` has been called before, the solution of the\n previous call to :meth:`fit` is used as the initial linear\n transformation (`n_components` and `init` will be ignored).\n\n max_iter : int, default=50\n Maximum number of iterations in the optimization.\n\n tol : float, default=1e-5\n Convergence tolerance for the optimization.\n\n callback : callable, default=None\n If not `None`, this function is called after every iteration of the\n optimizer, taking as arguments the current solution (flattened\n transformation matrix) and the number of iterations. This might be\n useful in case one wants to examine or store the transformation\n found after each iteration.\n\n verbose : int, default=0\n If 0, no progress messages will be printed.\n If 1, progress messages will be printed to stdout.\n If > 1, progress messages will be printed and the `disp`\n parameter of :func:`scipy.optimize.minimize` will be set to\n `verbose - 2`.\n\n random_state : int or numpy.RandomState, default=None\n A pseudo random number generator object or a seed for it if int. If\n `init='random'`, `random_state` is used to initialize the random\n transformation. If `init='pca'`, `random_state` is passed as an\n argument to PCA when initializing the transformation. Pass an int\n for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n Attributes\n ----------\n components_ : ndarray of shape (n_components, n_features)\n The linear transformation learned during fitting.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n n_iter_ : int\n Counts the number of iterations performed by the optimizer.\n\n random_state_ : numpy.RandomState\n Pseudo random number generator object used during initialization.\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n sklearn.discriminant_analysis.LinearDiscriminantAnalysis : Linear\n Discriminant Analysis.\n sklearn.decomposition.PCA : Principal component analysis (PCA).\n\n References\n ----------\n .. [1] J. Goldberger, G. Hinton, S. Roweis, R. Salakhutdinov.\n \"Neighbourhood Components Analysis\". Advances in Neural Information\n Processing Systems. 17, 513-520, 2005.\n http://www.cs.nyu.edu/~roweis/papers/ncanips.pdf\n\n .. [2] Wikipedia entry on Neighborhood Components Analysis\n https://en.wikipedia.org/wiki/Neighbourhood_components_analysis\n\n Examples\n --------\n >>> from sklearn.neighbors import NeighborhoodComponentsAnalysis\n >>> from sklearn.neighbors import KNeighborsClassifier\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.model_selection import train_test_split\n >>> X, y = load_iris(return_X_y=True)\n >>> X_train, X_test, y_train, y_test = train_test_split(X, y,\n ... stratify=y, test_size=0.7, random_state=42)\n >>> nca = NeighborhoodComponentsAnalysis(random_state=42)\n >>> nca.fit(X_train, y_train)\n NeighborhoodComponentsAnalysis(...)\n >>> knn = KNeighborsClassifier(n_neighbors=3)\n >>> knn.fit(X_train, y_train)\n KNeighborsClassifier(...)\n >>> print(knn.score(X_test, y_test))\n 0.933333...\n >>> knn.fit(nca.transform(X_train), y_train)\n KNeighborsClassifier(...)\n >>> print(knn.score(nca.transform(X_test), y_test))\n 0.961904...\n ", + "source_code": "\n\nclass NeighborhoodComponentsAnalysis(TransformerMixin, BaseEstimator):\n \"\"\"Neighborhood Components Analysis.\n\n Neighborhood Component Analysis (NCA) is a machine learning algorithm for\n metric learning. It learns a linear transformation in a supervised fashion\n to improve the classification accuracy of a stochastic nearest neighbors\n rule in the transformed space.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_components : int, default=None\n Preferred dimensionality of the projected space.\n If None it will be set to `n_features`.\n\n init : {'auto', 'pca', 'lda', 'identity', 'random'} or ndarray of shape (n_features_a, n_features_b), default='auto'\n Initialization of the linear transformation. Possible options are\n `'auto'`, `'pca'`, `'lda'`, `'identity'`, `'random'`, and a numpy\n array of shape `(n_features_a, n_features_b)`.\n\n - `'auto'`\n Depending on `n_components`, the most reasonable initialization\n will be chosen. If `n_components <= n_classes` we use `'lda'`, as\n it uses labels information. If not, but\n `n_components < min(n_features, n_samples)`, we use `'pca'`, as\n it projects data in meaningful directions (those of higher\n variance). Otherwise, we just use `'identity'`.\n\n - `'pca'`\n `n_components` principal components of the inputs passed\n to :meth:`fit` will be used to initialize the transformation.\n (See :class:`~sklearn.decomposition.PCA`)\n\n - `'lda'`\n `min(n_components, n_classes)` most discriminative\n components of the inputs passed to :meth:`fit` will be used to\n initialize the transformation. (If `n_components > n_classes`,\n the rest of the components will be zero.) (See\n :class:`~sklearn.discriminant_analysis.LinearDiscriminantAnalysis`)\n\n - `'identity'`\n If `n_components` is strictly smaller than the\n dimensionality of the inputs passed to :meth:`fit`, the identity\n matrix will be truncated to the first `n_components` rows.\n\n - `'random'`\n The initial transformation will be a random array of shape\n `(n_components, n_features)`. Each value is sampled from the\n standard normal distribution.\n\n - numpy array\n `n_features_b` must match the dimensionality of the inputs passed\n to :meth:`fit` and n_features_a must be less than or equal to that.\n If `n_components` is not `None`, `n_features_a` must match it.\n\n warm_start : bool, default=False\n If `True` and :meth:`fit` has been called before, the solution of the\n previous call to :meth:`fit` is used as the initial linear\n transformation (`n_components` and `init` will be ignored).\n\n max_iter : int, default=50\n Maximum number of iterations in the optimization.\n\n tol : float, default=1e-5\n Convergence tolerance for the optimization.\n\n callback : callable, default=None\n If not `None`, this function is called after every iteration of the\n optimizer, taking as arguments the current solution (flattened\n transformation matrix) and the number of iterations. This might be\n useful in case one wants to examine or store the transformation\n found after each iteration.\n\n verbose : int, default=0\n If 0, no progress messages will be printed.\n If 1, progress messages will be printed to stdout.\n If > 1, progress messages will be printed and the `disp`\n parameter of :func:`scipy.optimize.minimize` will be set to\n `verbose - 2`.\n\n random_state : int or numpy.RandomState, default=None\n A pseudo random number generator object or a seed for it if int. If\n `init='random'`, `random_state` is used to initialize the random\n transformation. If `init='pca'`, `random_state` is passed as an\n argument to PCA when initializing the transformation. Pass an int\n for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n Attributes\n ----------\n components_ : ndarray of shape (n_components, n_features)\n The linear transformation learned during fitting.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n n_iter_ : int\n Counts the number of iterations performed by the optimizer.\n\n random_state_ : numpy.RandomState\n Pseudo random number generator object used during initialization.\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n sklearn.discriminant_analysis.LinearDiscriminantAnalysis : Linear\n Discriminant Analysis.\n sklearn.decomposition.PCA : Principal component analysis (PCA).\n\n References\n ----------\n .. [1] J. Goldberger, G. Hinton, S. Roweis, R. Salakhutdinov.\n \"Neighbourhood Components Analysis\". Advances in Neural Information\n Processing Systems. 17, 513-520, 2005.\n http://www.cs.nyu.edu/~roweis/papers/ncanips.pdf\n\n .. [2] Wikipedia entry on Neighborhood Components Analysis\n https://en.wikipedia.org/wiki/Neighbourhood_components_analysis\n\n Examples\n --------\n >>> from sklearn.neighbors import NeighborhoodComponentsAnalysis\n >>> from sklearn.neighbors import KNeighborsClassifier\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.model_selection import train_test_split\n >>> X, y = load_iris(return_X_y=True)\n >>> X_train, X_test, y_train, y_test = train_test_split(X, y,\n ... stratify=y, test_size=0.7, random_state=42)\n >>> nca = NeighborhoodComponentsAnalysis(random_state=42)\n >>> nca.fit(X_train, y_train)\n NeighborhoodComponentsAnalysis(...)\n >>> knn = KNeighborsClassifier(n_neighbors=3)\n >>> knn.fit(X_train, y_train)\n KNeighborsClassifier(...)\n >>> print(knn.score(X_test, y_test))\n 0.933333...\n >>> knn.fit(nca.transform(X_train), y_train)\n KNeighborsClassifier(...)\n >>> print(knn.score(nca.transform(X_test), y_test))\n 0.961904...\n \"\"\"\n \n def __init__(self, n_components=None, *, init='auto', warm_start=False, max_iter=50, tol=1e-05, callback=None, verbose=0, random_state=None):\n self.n_components = n_components\n self.init = init\n self.warm_start = warm_start\n self.max_iter = max_iter\n self.tol = tol\n self.callback = callback\n self.verbose = verbose\n self.random_state = random_state\n \n def fit(self, X, y):\n \"\"\"Fit the model according to the given training data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The training samples.\n\n y : array-like of shape (n_samples,)\n The corresponding training labels.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n (X, y, init) = self._validate_params(X, y)\n self.random_state_ = check_random_state(self.random_state)\n t_train = time.time()\n same_class_mask = y[:, np.newaxis] == y[np.newaxis, :]\n transformation = self._initialize(X, y, init)\n disp = self.verbose - 2 if self.verbose > 1 else -1\n optimizer_params = {'method': 'L-BFGS-B', 'fun': self._loss_grad_lbfgs, 'args': (X, same_class_mask, -1.0), 'jac': True, 'x0': transformation, 'tol': self.tol, 'options': dict(maxiter=self.max_iter, disp=disp), 'callback': self._callback}\n self.n_iter_ = 0\n opt_result = minimize(**optimizer_params)\n self.components_ = opt_result.x.reshape(-1, X.shape[1])\n t_train = time.time() - t_train\n if self.verbose:\n cls_name = self.__class__.__name__\n if not opt_result.success:\n warn('[{}] NCA did not converge: {}'.format(cls_name, opt_result.message), ConvergenceWarning)\n print('[{}] Training took {:8.2f}s.'.format(cls_name, t_train))\n return self\n \n def transform(self, X):\n \"\"\"Apply the learned transformation to the given data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Data samples.\n\n Returns\n -------\n X_embedded: ndarray of shape (n_samples, n_components)\n The data samples transformed.\n\n Raises\n ------\n NotFittedError\n If :meth:`fit` has not been called before.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, reset=False)\n return np.dot(X, self.components_.T)\n \n def _validate_params(self, X, y):\n \"\"\"Validate parameters as soon as :meth:`fit` is called.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The training samples.\n\n y : array-like of shape (n_samples,)\n The corresponding training labels.\n\n Returns\n -------\n X : ndarray of shape (n_samples, n_features)\n The validated training samples.\n\n y : ndarray of shape (n_samples,)\n The validated training labels, encoded to be integers in\n the `range(0, n_classes)`.\n\n init : str or ndarray of shape (n_features_a, n_features_b)\n The validated initialization of the linear transformation.\n\n Raises\n -------\n TypeError\n If a parameter is not an instance of the desired type.\n\n ValueError\n If a parameter's value violates its legal value range or if the\n combination of two or more given parameters is incompatible.\n \"\"\"\n (X, y) = self._validate_data(X, y, ensure_min_samples=2)\n check_classification_targets(y)\n y = LabelEncoder().fit_transform(y)\n if self.n_components is not None:\n check_scalar(self.n_components, 'n_components', numbers.Integral, min_val=1)\n if self.n_components > X.shape[1]:\n raise ValueError('The preferred dimensionality of the projected space `n_components` ({}) cannot be greater than the given data dimensionality ({})!'.format(self.n_components, X.shape[1]))\n check_scalar(self.warm_start, 'warm_start', bool)\n if self.warm_start and hasattr(self, 'components_'):\n if self.components_.shape[1] != X.shape[1]:\n raise ValueError('The new inputs dimensionality ({}) does not match the input dimensionality of the previously learned transformation ({}).'.format(X.shape[1], self.components_.shape[1]))\n check_scalar(self.max_iter, 'max_iter', numbers.Integral, min_val=1)\n check_scalar(self.tol, 'tol', numbers.Real, min_val=0.0)\n check_scalar(self.verbose, 'verbose', numbers.Integral, min_val=0)\n if self.callback is not None:\n if not callable(self.callback):\n raise ValueError('`callback` is not callable.')\n init = self.init\n if isinstance(init, np.ndarray):\n init = check_array(init)\n if init.shape[1] != X.shape[1]:\n raise ValueError('The input dimensionality ({}) of the given linear transformation `init` must match the dimensionality of the given inputs `X` ({}).'.format(init.shape[1], X.shape[1]))\n if init.shape[0] > init.shape[1]:\n raise ValueError('The output dimensionality ({}) of the given linear transformation `init` cannot be greater than its input dimensionality ({}).'.format(init.shape[0], init.shape[1]))\n if self.n_components is not None:\n if self.n_components != init.shape[0]:\n raise ValueError('The preferred dimensionality of the projected space `n_components` ({}) does not match the output dimensionality of the given linear transformation `init` ({})!'.format(self.n_components, init.shape[0]))\n elif init in ['auto', 'pca', 'lda', 'identity', 'random']:\n pass\n else:\n raise ValueError(\"`init` must be 'auto', 'pca', 'lda', 'identity', 'random' or a numpy array of shape (n_components, n_features).\")\n return X, y, init\n \n def _initialize(self, X, y, init):\n \"\"\"Initialize the transformation.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The training samples.\n\n y : array-like of shape (n_samples,)\n The training labels.\n\n init : str or ndarray of shape (n_features_a, n_features_b)\n The validated initialization of the linear transformation.\n\n Returns\n -------\n transformation : ndarray of shape (n_components, n_features)\n The initialized linear transformation.\n\n \"\"\"\n transformation = init\n if self.warm_start and hasattr(self, 'components_'):\n transformation = self.components_\n elif isinstance(init, np.ndarray):\n pass\n else:\n (n_samples, n_features) = X.shape\n n_components = self.n_components or n_features\n if init == 'auto':\n n_classes = len(np.unique(y))\n if n_components <= min(n_features, n_classes - 1):\n init = 'lda'\n elif n_components < min(n_features, n_samples):\n init = 'pca'\n else:\n init = 'identity'\n if init == 'identity':\n transformation = np.eye(n_components, X.shape[1])\n elif init == 'random':\n transformation = self.random_state_.randn(n_components, X.shape[1])\n elif init in {'pca', 'lda'}:\n init_time = time.time()\n if init == 'pca':\n pca = PCA(n_components=n_components, random_state=self.random_state_)\n if self.verbose:\n print('Finding principal components... ', end='')\n sys.stdout.flush()\n pca.fit(X)\n transformation = pca.components_\n elif init == 'lda':\n from ..discriminant_analysis import LinearDiscriminantAnalysis\n lda = LinearDiscriminantAnalysis(n_components=n_components)\n if self.verbose:\n print('Finding most discriminative components... ', end='')\n sys.stdout.flush()\n lda.fit(X, y)\n transformation = lda.scalings_.T[:n_components]\n if self.verbose:\n print('done in {:5.2f}s'.format(time.time() - init_time))\n return transformation\n \n def _callback(self, transformation):\n \"\"\"Called after each iteration of the optimizer.\n\n Parameters\n ----------\n transformation : ndarray of shape (n_components * n_features,)\n The solution computed by the optimizer in this iteration.\n \"\"\"\n if self.callback is not None:\n self.callback(transformation, self.n_iter_)\n self.n_iter_ += 1\n \n def _loss_grad_lbfgs(self, transformation, X, same_class_mask, sign=1.0):\n \"\"\"Compute the loss and the loss gradient w.r.t. `transformation`.\n\n Parameters\n ----------\n transformation : ndarray of shape (n_components * n_features,)\n The raveled linear transformation on which to compute loss and\n evaluate gradient.\n\n X : ndarray of shape (n_samples, n_features)\n The training samples.\n\n same_class_mask : ndarray of shape (n_samples, n_samples)\n A mask where `mask[i, j] == 1` if `X[i]` and `X[j]` belong\n to the same class, and `0` otherwise.\n\n Returns\n -------\n loss : float\n The loss computed for the given transformation.\n\n gradient : ndarray of shape (n_components * n_features,)\n The new (flattened) gradient of the loss.\n \"\"\"\n if self.n_iter_ == 0:\n self.n_iter_ += 1\n if self.verbose:\n header_fields = ['Iteration', 'Objective Value', 'Time(s)']\n header_fmt = '{:>10} {:>20} {:>10}'\n header = header_fmt.format(*header_fields)\n cls_name = self.__class__.__name__\n print('[{}]'.format(cls_name))\n print('[{}] {}\\n[{}] {}'.format(cls_name, header, cls_name, '-' * len(header)))\n t_funcall = time.time()\n transformation = transformation.reshape(-1, X.shape[1])\n X_embedded = np.dot(X, transformation.T)\n p_ij = pairwise_distances(X_embedded, squared=True)\n np.fill_diagonal(p_ij, np.inf)\n p_ij = softmax(-p_ij)\n masked_p_ij = p_ij * same_class_mask\n p = np.sum(masked_p_ij, axis=1, keepdims=True)\n loss = np.sum(p)\n weighted_p_ij = masked_p_ij - p_ij * p\n weighted_p_ij_sym = weighted_p_ij + weighted_p_ij.T\n np.fill_diagonal(weighted_p_ij_sym, -weighted_p_ij.sum(axis=0))\n gradient = 2 * X_embedded.T.dot(weighted_p_ij_sym).dot(X)\n if self.verbose:\n t_funcall = time.time() - t_funcall\n values_fmt = '[{}] {:>10} {:>20.6e} {:>10.2f}'\n print(values_fmt.format(self.__class__.__name__, self.n_iter_, loss, t_funcall))\n sys.stdout.flush()\n return sign * loss, sign * gradient.ravel()\n \n def _more_tags(self):\n return {'requires_y': True}\n" }, { "name": "NearestCentroid", @@ -25578,8 +25531,8 @@ ], "is_public": true, "description": "Nearest centroid classifier.\n\nEach class is represented by its centroid, with test samples classified to the class with the nearest centroid. Read more in the :ref:`User Guide `.", - "docstring": "Nearest centroid classifier.\n\n Each class is represented by its centroid, with test samples classified to\n the class with the nearest centroid.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n metric : str or callable\n The metric to use when calculating distance between instances in a\n feature array. If metric is a string or callable, it must be one of\n the options allowed by metrics.pairwise.pairwise_distances for its\n metric parameter.\n The centroids for the samples corresponding to each class is the point\n from which the sum of the distances (according to the metric) of all\n samples that belong to that particular class are minimized.\n If the \"manhattan\" metric is provided, this centroid is the median and\n for all other metrics, the centroid is now set to be the mean.\n\n .. versionchanged:: 0.19\n ``metric='precomputed'`` was deprecated and now raises an error\n\n shrink_threshold : float, default=None\n Threshold for shrinking centroids to remove features.\n\n Attributes\n ----------\n centroids_ : array-like of shape (n_classes, n_features)\n Centroid of each class.\n\n classes_ : array of shape (n_classes,)\n The unique classes labels.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn.neighbors import NearestCentroid\n >>> import numpy as np\n >>> X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])\n >>> y = np.array([1, 1, 1, 2, 2, 2])\n >>> clf = NearestCentroid()\n >>> clf.fit(X, y)\n NearestCentroid()\n >>> print(clf.predict([[-0.8, -1]]))\n [1]\n\n See Also\n --------\n KNeighborsClassifier : Nearest neighbors classifier.\n\n Notes\n -----\n When used for text classification with tf-idf vectors, this classifier is\n also known as the Rocchio classifier.\n\n References\n ----------\n Tibshirani, R., Hastie, T., Narasimhan, B., & Chu, G. (2002). Diagnosis of\n multiple cancer types by shrunken centroids of gene expression. Proceedings\n of the National Academy of Sciences of the United States of America,\n 99(10), 6567-6572. The National Academy of Sciences.\n\n ", - "source_code": "\n\nclass NearestCentroid(ClassifierMixin, BaseEstimator):\n \"\"\"Nearest centroid classifier.\n\n Each class is represented by its centroid, with test samples classified to\n the class with the nearest centroid.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n metric : str or callable\n The metric to use when calculating distance between instances in a\n feature array. If metric is a string or callable, it must be one of\n the options allowed by metrics.pairwise.pairwise_distances for its\n metric parameter.\n The centroids for the samples corresponding to each class is the point\n from which the sum of the distances (according to the metric) of all\n samples that belong to that particular class are minimized.\n If the \"manhattan\" metric is provided, this centroid is the median and\n for all other metrics, the centroid is now set to be the mean.\n\n .. versionchanged:: 0.19\n ``metric='precomputed'`` was deprecated and now raises an error\n\n shrink_threshold : float, default=None\n Threshold for shrinking centroids to remove features.\n\n Attributes\n ----------\n centroids_ : array-like of shape (n_classes, n_features)\n Centroid of each class.\n\n classes_ : array of shape (n_classes,)\n The unique classes labels.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn.neighbors import NearestCentroid\n >>> import numpy as np\n >>> X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])\n >>> y = np.array([1, 1, 1, 2, 2, 2])\n >>> clf = NearestCentroid()\n >>> clf.fit(X, y)\n NearestCentroid()\n >>> print(clf.predict([[-0.8, -1]]))\n [1]\n\n See Also\n --------\n KNeighborsClassifier : Nearest neighbors classifier.\n\n Notes\n -----\n When used for text classification with tf-idf vectors, this classifier is\n also known as the Rocchio classifier.\n\n References\n ----------\n Tibshirani, R., Hastie, T., Narasimhan, B., & Chu, G. (2002). Diagnosis of\n multiple cancer types by shrunken centroids of gene expression. Proceedings\n of the National Academy of Sciences of the United States of America,\n 99(10), 6567-6572. The National Academy of Sciences.\n\n \"\"\"\n \n def __init__(self, metric='euclidean', *, shrink_threshold=None):\n self.metric = metric\n self.shrink_threshold = shrink_threshold\n \n def fit(self, X, y):\n \"\"\"\n Fit the NearestCentroid model according to the given training data.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n Note that centroid shrinking cannot be used with sparse matrices.\n y : array-like of shape (n_samples,)\n Target values (integers)\n \"\"\"\n if self.metric == 'precomputed':\n raise ValueError('Precomputed is not supported.')\n if self.metric == 'manhattan':\n (X, y) = self._validate_data(X, y, accept_sparse=['csc'])\n else:\n (X, y) = self._validate_data(X, y, accept_sparse=['csr', 'csc'])\n is_X_sparse = sp.issparse(X)\n if is_X_sparse and self.shrink_threshold:\n raise ValueError('threshold shrinking not supported for sparse input')\n check_classification_targets(y)\n (n_samples, n_features) = X.shape\n le = LabelEncoder()\n y_ind = le.fit_transform(y)\n self.classes_ = classes = le.classes_\n n_classes = classes.size\n if n_classes < 2:\n raise ValueError('The number of classes has to be greater than one; got %d class' % n_classes)\n self.centroids_ = np.empty((n_classes, n_features), dtype=np.float64)\n nk = np.zeros(n_classes)\n for cur_class in range(n_classes):\n center_mask = y_ind == cur_class\n nk[cur_class] = np.sum(center_mask)\n if is_X_sparse:\n center_mask = np.where(center_mask)[0]\n if self.metric == 'manhattan':\n if not is_X_sparse:\n self.centroids_[cur_class] = np.median(X[center_mask], axis=0)\n else:\n self.centroids_[cur_class] = csc_median_axis_0(X[center_mask])\n else:\n if self.metric != 'euclidean':\n warnings.warn('Averaging for metrics other than euclidean and manhattan not supported. The average is set to be the mean.')\n self.centroids_[cur_class] = X[center_mask].mean(axis=0)\n if self.shrink_threshold:\n if np.all(np.ptp(X, axis=0) == 0):\n raise ValueError('All features have zero variance. Division by zero.')\n dataset_centroid_ = np.mean(X, axis=0)\n m = np.sqrt(1.0 / nk - 1.0 / n_samples)\n variance = (X - self.centroids_[y_ind])**2\n variance = variance.sum(axis=0)\n s = np.sqrt(variance / (n_samples - n_classes))\n s += np.median(s)\n mm = m.reshape(len(m), 1)\n ms = mm * s\n deviation = (self.centroids_ - dataset_centroid_) / ms\n signs = np.sign(deviation)\n deviation = np.abs(deviation) - self.shrink_threshold\n np.clip(deviation, 0, None, out=deviation)\n deviation *= signs\n msd = ms * deviation\n self.centroids_ = dataset_centroid_[np.newaxis, :] + msd\n return self\n \n def predict(self, X):\n \"\"\"Perform classification on an array of test vectors X.\n\n The predicted class C for each sample in X is returned.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n\n Returns\n -------\n C : ndarray of shape (n_samples,)\n\n Notes\n -----\n If the metric constructor parameter is \"precomputed\", X is assumed to\n be the distance matrix between the data to be predicted and\n ``self.centroids_``.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse='csr', reset=False)\n return self.classes_[pairwise_distances(X, self.centroids_, metric=self.metric).argmin(axis=1)]\n" + "docstring": "Nearest centroid classifier.\n\n Each class is represented by its centroid, with test samples classified to\n the class with the nearest centroid.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n metric : str or callable\n The metric to use when calculating distance between instances in a\n feature array. If metric is a string or callable, it must be one of\n the options allowed by\n :func:`~sklearn.metrics.pairwise_distances` for its metric\n parameter. The centroids for the samples corresponding to each class is\n the point from which the sum of the distances (according to the metric)\n of all samples that belong to that particular class are minimized.\n If the `\"manhattan\"` metric is provided, this centroid is the median\n and for all other metrics, the centroid is now set to be the mean.\n\n .. versionchanged:: 0.19\n `metric='precomputed'` was deprecated and now raises an error\n\n shrink_threshold : float, default=None\n Threshold for shrinking centroids to remove features.\n\n Attributes\n ----------\n centroids_ : array-like of shape (n_classes, n_features)\n Centroid of each class.\n\n classes_ : array of shape (n_classes,)\n The unique classes labels.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n KNeighborsClassifier : Nearest neighbors classifier.\n\n Notes\n -----\n When used for text classification with tf-idf vectors, this classifier is\n also known as the Rocchio classifier.\n\n References\n ----------\n Tibshirani, R., Hastie, T., Narasimhan, B., & Chu, G. (2002). Diagnosis of\n multiple cancer types by shrunken centroids of gene expression. Proceedings\n of the National Academy of Sciences of the United States of America,\n 99(10), 6567-6572. The National Academy of Sciences.\n\n Examples\n --------\n >>> from sklearn.neighbors import NearestCentroid\n >>> import numpy as np\n >>> X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])\n >>> y = np.array([1, 1, 1, 2, 2, 2])\n >>> clf = NearestCentroid()\n >>> clf.fit(X, y)\n NearestCentroid()\n >>> print(clf.predict([[-0.8, -1]]))\n [1]\n ", + "source_code": "\n\nclass NearestCentroid(ClassifierMixin, BaseEstimator):\n \"\"\"Nearest centroid classifier.\n\n Each class is represented by its centroid, with test samples classified to\n the class with the nearest centroid.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n metric : str or callable\n The metric to use when calculating distance between instances in a\n feature array. If metric is a string or callable, it must be one of\n the options allowed by\n :func:`~sklearn.metrics.pairwise_distances` for its metric\n parameter. The centroids for the samples corresponding to each class is\n the point from which the sum of the distances (according to the metric)\n of all samples that belong to that particular class are minimized.\n If the `\"manhattan\"` metric is provided, this centroid is the median\n and for all other metrics, the centroid is now set to be the mean.\n\n .. versionchanged:: 0.19\n `metric='precomputed'` was deprecated and now raises an error\n\n shrink_threshold : float, default=None\n Threshold for shrinking centroids to remove features.\n\n Attributes\n ----------\n centroids_ : array-like of shape (n_classes, n_features)\n Centroid of each class.\n\n classes_ : array of shape (n_classes,)\n The unique classes labels.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n KNeighborsClassifier : Nearest neighbors classifier.\n\n Notes\n -----\n When used for text classification with tf-idf vectors, this classifier is\n also known as the Rocchio classifier.\n\n References\n ----------\n Tibshirani, R., Hastie, T., Narasimhan, B., & Chu, G. (2002). Diagnosis of\n multiple cancer types by shrunken centroids of gene expression. Proceedings\n of the National Academy of Sciences of the United States of America,\n 99(10), 6567-6572. The National Academy of Sciences.\n\n Examples\n --------\n >>> from sklearn.neighbors import NearestCentroid\n >>> import numpy as np\n >>> X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])\n >>> y = np.array([1, 1, 1, 2, 2, 2])\n >>> clf = NearestCentroid()\n >>> clf.fit(X, y)\n NearestCentroid()\n >>> print(clf.predict([[-0.8, -1]]))\n [1]\n \"\"\"\n \n def __init__(self, metric='euclidean', *, shrink_threshold=None):\n self.metric = metric\n self.shrink_threshold = shrink_threshold\n \n def fit(self, X, y):\n \"\"\"\n Fit the NearestCentroid model according to the given training data.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n Note that centroid shrinking cannot be used with sparse matrices.\n y : array-like of shape (n_samples,)\n Target values.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n if self.metric == 'precomputed':\n raise ValueError('Precomputed is not supported.')\n if self.metric == 'manhattan':\n (X, y) = self._validate_data(X, y, accept_sparse=['csc'])\n else:\n (X, y) = self._validate_data(X, y, accept_sparse=['csr', 'csc'])\n is_X_sparse = sp.issparse(X)\n if is_X_sparse and self.shrink_threshold:\n raise ValueError('threshold shrinking not supported for sparse input')\n check_classification_targets(y)\n (n_samples, n_features) = X.shape\n le = LabelEncoder()\n y_ind = le.fit_transform(y)\n self.classes_ = classes = le.classes_\n n_classes = classes.size\n if n_classes < 2:\n raise ValueError('The number of classes has to be greater than one; got %d class' % n_classes)\n self.centroids_ = np.empty((n_classes, n_features), dtype=np.float64)\n nk = np.zeros(n_classes)\n for cur_class in range(n_classes):\n center_mask = y_ind == cur_class\n nk[cur_class] = np.sum(center_mask)\n if is_X_sparse:\n center_mask = np.where(center_mask)[0]\n if self.metric == 'manhattan':\n if not is_X_sparse:\n self.centroids_[cur_class] = np.median(X[center_mask], axis=0)\n else:\n self.centroids_[cur_class] = csc_median_axis_0(X[center_mask])\n else:\n if self.metric != 'euclidean':\n warnings.warn('Averaging for metrics other than euclidean and manhattan not supported. The average is set to be the mean.')\n self.centroids_[cur_class] = X[center_mask].mean(axis=0)\n if self.shrink_threshold:\n if np.all(np.ptp(X, axis=0) == 0):\n raise ValueError('All features have zero variance. Division by zero.')\n dataset_centroid_ = np.mean(X, axis=0)\n m = np.sqrt(1.0 / nk - 1.0 / n_samples)\n variance = (X - self.centroids_[y_ind])**2\n variance = variance.sum(axis=0)\n s = np.sqrt(variance / (n_samples - n_classes))\n s += np.median(s)\n mm = m.reshape(len(m), 1)\n ms = mm * s\n deviation = (self.centroids_ - dataset_centroid_) / ms\n signs = np.sign(deviation)\n deviation = np.abs(deviation) - self.shrink_threshold\n np.clip(deviation, 0, None, out=deviation)\n deviation *= signs\n msd = ms * deviation\n self.centroids_ = dataset_centroid_[np.newaxis, :] + msd\n return self\n \n def predict(self, X):\n \"\"\"Perform classification on an array of test vectors `X`.\n\n The predicted class `C` for each sample in `X` is returned.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Test samples.\n\n Returns\n -------\n C : ndarray of shape (n_samples,)\n The predicted classes.\n\n Notes\n -----\n If the metric constructor parameter is `\"precomputed\"`, `X` is assumed\n to be the distance matrix between the data to be predicted and\n `self.centroids_`.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse='csr', reset=False)\n return self.classes_[pairwise_distances(X, self.centroids_, metric=self.metric).argmin(axis=1)]\n" }, { "name": "KNeighborsRegressor", @@ -25593,14 +25546,14 @@ "methods": [ "sklearn.neighbors._regression.KNeighborsRegressor.__init__", "sklearn.neighbors._regression.KNeighborsRegressor._more_tags", - "sklearn.neighbors._regression.KNeighborsRegressor._pairwise", + "sklearn.neighbors._regression.KNeighborsRegressor._pairwise@getter", "sklearn.neighbors._regression.KNeighborsRegressor.fit", "sklearn.neighbors._regression.KNeighborsRegressor.predict" ], "is_public": true, "description": "Regression based on k-nearest neighbors.\n\nThe target is predicted by local interpolation of the targets associated of the nearest neighbors in the training set. Read more in the :ref:`User Guide `. .. versionadded:: 0.9", "docstring": "Regression based on k-nearest neighbors.\n\n The target is predicted by local interpolation of the targets\n associated of the nearest neighbors in the training set.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.9\n\n Parameters\n ----------\n n_neighbors : int, default=5\n Number of neighbors to use by default for :meth:`kneighbors` queries.\n\n weights : {'uniform', 'distance'} or callable, default='uniform'\n Weight function used in prediction. Possible values:\n\n - 'uniform' : uniform weights. All points in each neighborhood\n are weighted equally.\n - 'distance' : weight points by the inverse of their distance.\n in this case, closer neighbors of a query point will have a\n greater influence than neighbors which are further away.\n - [callable] : a user-defined function which accepts an\n array of distances, and returns an array of the same shape\n containing the weights.\n\n Uniform weights are used by default.\n\n algorithm : {'auto', 'ball_tree', 'kd_tree', 'brute'}, default='auto'\n Algorithm used to compute the nearest neighbors:\n\n - 'ball_tree' will use :class:`BallTree`\n - 'kd_tree' will use :class:`KDTree`\n - 'brute' will use a brute-force search.\n - 'auto' will attempt to decide the most appropriate algorithm\n based on the values passed to :meth:`fit` method.\n\n Note: fitting on sparse input will override the setting of\n this parameter, using brute force.\n\n leaf_size : int, default=30\n Leaf size passed to BallTree or KDTree. This can affect the\n speed of the construction and query, as well as the memory\n required to store the tree. The optimal value depends on the\n nature of the problem.\n\n p : int, default=2\n Power parameter for the Minkowski metric. When p = 1, this is\n equivalent to using manhattan_distance (l1), and euclidean_distance\n (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used.\n\n metric : str or callable, default='minkowski'\n The distance metric to use for the tree. The default metric is\n minkowski, and with p=2 is equivalent to the standard Euclidean\n metric. See the documentation of :class:`DistanceMetric` for a\n list of available metrics.\n If metric is \"precomputed\", X is assumed to be a distance matrix and\n must be square during fit. X may be a :term:`sparse graph`,\n in which case only \"nonzero\" elements may be considered neighbors.\n\n metric_params : dict, default=None\n Additional keyword arguments for the metric function.\n\n n_jobs : int, default=None\n The number of parallel jobs to run for neighbors search.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n Doesn't affect :meth:`fit` method.\n\n Attributes\n ----------\n effective_metric_ : str or callable\n The distance metric to use. It will be same as the `metric` parameter\n or a synonym of it, e.g. 'euclidean' if the `metric` parameter set to\n 'minkowski' and `p` parameter set to 2.\n\n effective_metric_params_ : dict\n Additional keyword arguments for the metric function. For most metrics\n will be same with `metric_params` parameter, but may also contain the\n `p` parameter value if the `effective_metric_` attribute is set to\n 'minkowski'.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_samples_fit_ : int\n Number of samples in the fitted data.\n\n See Also\n --------\n NearestNeighbors : Unsupervised learner for implementing neighbor searches.\n RadiusNeighborsRegressor : Regression based on neighbors within a fixed radius.\n KNeighborsClassifier : Classifier implementing the k-nearest neighbors vote.\n RadiusNeighborsClassifier : Classifier implementing\n a vote among neighbors within a given radius.\n\n Notes\n -----\n See :ref:`Nearest Neighbors ` in the online documentation\n for a discussion of the choice of ``algorithm`` and ``leaf_size``.\n\n .. warning::\n\n Regarding the Nearest Neighbors algorithms, if it is found that two\n neighbors, neighbor `k+1` and `k`, have identical distances but\n different labels, the results will depend on the ordering of the\n training data.\n\n https://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm\n\n Examples\n --------\n >>> X = [[0], [1], [2], [3]]\n >>> y = [0, 0, 1, 1]\n >>> from sklearn.neighbors import KNeighborsRegressor\n >>> neigh = KNeighborsRegressor(n_neighbors=2)\n >>> neigh.fit(X, y)\n KNeighborsRegressor(...)\n >>> print(neigh.predict([[1.5]]))\n [0.5]\n ", - "source_code": "\n\nclass KNeighborsRegressor(KNeighborsMixin, RegressorMixin, NeighborsBase):\n \"\"\"Regression based on k-nearest neighbors.\n\n The target is predicted by local interpolation of the targets\n associated of the nearest neighbors in the training set.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.9\n\n Parameters\n ----------\n n_neighbors : int, default=5\n Number of neighbors to use by default for :meth:`kneighbors` queries.\n\n weights : {'uniform', 'distance'} or callable, default='uniform'\n Weight function used in prediction. Possible values:\n\n - 'uniform' : uniform weights. All points in each neighborhood\n are weighted equally.\n - 'distance' : weight points by the inverse of their distance.\n in this case, closer neighbors of a query point will have a\n greater influence than neighbors which are further away.\n - [callable] : a user-defined function which accepts an\n array of distances, and returns an array of the same shape\n containing the weights.\n\n Uniform weights are used by default.\n\n algorithm : {'auto', 'ball_tree', 'kd_tree', 'brute'}, default='auto'\n Algorithm used to compute the nearest neighbors:\n\n - 'ball_tree' will use :class:`BallTree`\n - 'kd_tree' will use :class:`KDTree`\n - 'brute' will use a brute-force search.\n - 'auto' will attempt to decide the most appropriate algorithm\n based on the values passed to :meth:`fit` method.\n\n Note: fitting on sparse input will override the setting of\n this parameter, using brute force.\n\n leaf_size : int, default=30\n Leaf size passed to BallTree or KDTree. This can affect the\n speed of the construction and query, as well as the memory\n required to store the tree. The optimal value depends on the\n nature of the problem.\n\n p : int, default=2\n Power parameter for the Minkowski metric. When p = 1, this is\n equivalent to using manhattan_distance (l1), and euclidean_distance\n (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used.\n\n metric : str or callable, default='minkowski'\n The distance metric to use for the tree. The default metric is\n minkowski, and with p=2 is equivalent to the standard Euclidean\n metric. See the documentation of :class:`DistanceMetric` for a\n list of available metrics.\n If metric is \"precomputed\", X is assumed to be a distance matrix and\n must be square during fit. X may be a :term:`sparse graph`,\n in which case only \"nonzero\" elements may be considered neighbors.\n\n metric_params : dict, default=None\n Additional keyword arguments for the metric function.\n\n n_jobs : int, default=None\n The number of parallel jobs to run for neighbors search.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n Doesn't affect :meth:`fit` method.\n\n Attributes\n ----------\n effective_metric_ : str or callable\n The distance metric to use. It will be same as the `metric` parameter\n or a synonym of it, e.g. 'euclidean' if the `metric` parameter set to\n 'minkowski' and `p` parameter set to 2.\n\n effective_metric_params_ : dict\n Additional keyword arguments for the metric function. For most metrics\n will be same with `metric_params` parameter, but may also contain the\n `p` parameter value if the `effective_metric_` attribute is set to\n 'minkowski'.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_samples_fit_ : int\n Number of samples in the fitted data.\n\n See Also\n --------\n NearestNeighbors : Unsupervised learner for implementing neighbor searches.\n RadiusNeighborsRegressor : Regression based on neighbors within a fixed radius.\n KNeighborsClassifier : Classifier implementing the k-nearest neighbors vote.\n RadiusNeighborsClassifier : Classifier implementing\n a vote among neighbors within a given radius.\n\n Notes\n -----\n See :ref:`Nearest Neighbors ` in the online documentation\n for a discussion of the choice of ``algorithm`` and ``leaf_size``.\n\n .. warning::\n\n Regarding the Nearest Neighbors algorithms, if it is found that two\n neighbors, neighbor `k+1` and `k`, have identical distances but\n different labels, the results will depend on the ordering of the\n training data.\n\n https://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm\n\n Examples\n --------\n >>> X = [[0], [1], [2], [3]]\n >>> y = [0, 0, 1, 1]\n >>> from sklearn.neighbors import KNeighborsRegressor\n >>> neigh = KNeighborsRegressor(n_neighbors=2)\n >>> neigh.fit(X, y)\n KNeighborsRegressor(...)\n >>> print(neigh.predict([[1.5]]))\n [0.5]\n \"\"\"\n \n def __init__(self, n_neighbors=5, *, weights='uniform', algorithm='auto', leaf_size=30, p=2, metric='minkowski', metric_params=None, n_jobs=None):\n super().__init__(n_neighbors=n_neighbors, algorithm=algorithm, leaf_size=leaf_size, metric=metric, p=p, metric_params=metric_params, n_jobs=n_jobs)\n self.weights = weights\n \n def _more_tags(self):\n return {'pairwise': self.metric == 'precomputed'}\n \n @deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def _pairwise(self):\n return self.metric == 'precomputed'\n \n def fit(self, X, y):\n \"\"\"Fit the k-nearest neighbors regressor from the training dataset.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples) if metric='precomputed'\n Training data.\n\n y : {array-like, sparse matrix} of shape (n_samples,) or (n_samples, n_outputs)\n Target values.\n\n Returns\n -------\n self : KNeighborsRegressor\n The fitted k-nearest neighbors regressor.\n \"\"\"\n self.weights = _check_weights(self.weights)\n return self._fit(X, y)\n \n def predict(self, X):\n \"\"\"Predict the target for the provided data.\n\n Parameters\n ----------\n X : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\n Returns\n -------\n y : ndarray of shape (n_queries,) or (n_queries, n_outputs), dtype=int\n Target values.\n \"\"\"\n X = self._validate_data(X, accept_sparse='csr', reset=False)\n (neigh_dist, neigh_ind) = self.kneighbors(X)\n weights = _get_weights(neigh_dist, self.weights)\n _y = self._y\n if _y.ndim == 1:\n _y = _y.reshape((-1, 1))\n if weights is None:\n y_pred = np.mean(_y[neigh_ind], axis=1)\n else:\n y_pred = np.empty((X.shape[0], _y.shape[1]), dtype=np.float64)\n denom = np.sum(weights, axis=1)\n for j in range(_y.shape[1]):\n num = np.sum(_y[neigh_ind, j] * weights, axis=1)\n y_pred[:, j] = num / denom\n if self._y.ndim == 1:\n y_pred = y_pred.ravel()\n return y_pred\n" + "source_code": "\n\nclass KNeighborsRegressor(KNeighborsMixin, RegressorMixin, NeighborsBase):\n \"\"\"Regression based on k-nearest neighbors.\n\n The target is predicted by local interpolation of the targets\n associated of the nearest neighbors in the training set.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.9\n\n Parameters\n ----------\n n_neighbors : int, default=5\n Number of neighbors to use by default for :meth:`kneighbors` queries.\n\n weights : {'uniform', 'distance'} or callable, default='uniform'\n Weight function used in prediction. Possible values:\n\n - 'uniform' : uniform weights. All points in each neighborhood\n are weighted equally.\n - 'distance' : weight points by the inverse of their distance.\n in this case, closer neighbors of a query point will have a\n greater influence than neighbors which are further away.\n - [callable] : a user-defined function which accepts an\n array of distances, and returns an array of the same shape\n containing the weights.\n\n Uniform weights are used by default.\n\n algorithm : {'auto', 'ball_tree', 'kd_tree', 'brute'}, default='auto'\n Algorithm used to compute the nearest neighbors:\n\n - 'ball_tree' will use :class:`BallTree`\n - 'kd_tree' will use :class:`KDTree`\n - 'brute' will use a brute-force search.\n - 'auto' will attempt to decide the most appropriate algorithm\n based on the values passed to :meth:`fit` method.\n\n Note: fitting on sparse input will override the setting of\n this parameter, using brute force.\n\n leaf_size : int, default=30\n Leaf size passed to BallTree or KDTree. This can affect the\n speed of the construction and query, as well as the memory\n required to store the tree. The optimal value depends on the\n nature of the problem.\n\n p : int, default=2\n Power parameter for the Minkowski metric. When p = 1, this is\n equivalent to using manhattan_distance (l1), and euclidean_distance\n (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used.\n\n metric : str or callable, default='minkowski'\n The distance metric to use for the tree. The default metric is\n minkowski, and with p=2 is equivalent to the standard Euclidean\n metric. See the documentation of :class:`DistanceMetric` for a\n list of available metrics.\n If metric is \"precomputed\", X is assumed to be a distance matrix and\n must be square during fit. X may be a :term:`sparse graph`,\n in which case only \"nonzero\" elements may be considered neighbors.\n\n metric_params : dict, default=None\n Additional keyword arguments for the metric function.\n\n n_jobs : int, default=None\n The number of parallel jobs to run for neighbors search.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n Doesn't affect :meth:`fit` method.\n\n Attributes\n ----------\n effective_metric_ : str or callable\n The distance metric to use. It will be same as the `metric` parameter\n or a synonym of it, e.g. 'euclidean' if the `metric` parameter set to\n 'minkowski' and `p` parameter set to 2.\n\n effective_metric_params_ : dict\n Additional keyword arguments for the metric function. For most metrics\n will be same with `metric_params` parameter, but may also contain the\n `p` parameter value if the `effective_metric_` attribute is set to\n 'minkowski'.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_samples_fit_ : int\n Number of samples in the fitted data.\n\n See Also\n --------\n NearestNeighbors : Unsupervised learner for implementing neighbor searches.\n RadiusNeighborsRegressor : Regression based on neighbors within a fixed radius.\n KNeighborsClassifier : Classifier implementing the k-nearest neighbors vote.\n RadiusNeighborsClassifier : Classifier implementing\n a vote among neighbors within a given radius.\n\n Notes\n -----\n See :ref:`Nearest Neighbors ` in the online documentation\n for a discussion of the choice of ``algorithm`` and ``leaf_size``.\n\n .. warning::\n\n Regarding the Nearest Neighbors algorithms, if it is found that two\n neighbors, neighbor `k+1` and `k`, have identical distances but\n different labels, the results will depend on the ordering of the\n training data.\n\n https://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm\n\n Examples\n --------\n >>> X = [[0], [1], [2], [3]]\n >>> y = [0, 0, 1, 1]\n >>> from sklearn.neighbors import KNeighborsRegressor\n >>> neigh = KNeighborsRegressor(n_neighbors=2)\n >>> neigh.fit(X, y)\n KNeighborsRegressor(...)\n >>> print(neigh.predict([[1.5]]))\n [0.5]\n \"\"\"\n \n def __init__(self, n_neighbors=5, *, weights='uniform', algorithm='auto', leaf_size=30, p=2, metric='minkowski', metric_params=None, n_jobs=None):\n super().__init__(n_neighbors=n_neighbors, algorithm=algorithm, leaf_size=leaf_size, metric=metric, p=p, metric_params=metric_params, n_jobs=n_jobs)\n self.weights = weights\n \n def _more_tags(self):\n return {'pairwise': self.metric == 'precomputed'}\n \n @deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def _pairwise(self):\n return self.metric == 'precomputed'\n \n def fit(self, X, y):\n \"\"\"Fit the k-nearest neighbors regressor from the training dataset.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples) if metric='precomputed'\n Training data.\n\n y : {array-like, sparse matrix} of shape (n_samples,) or (n_samples, n_outputs)\n Target values.\n\n Returns\n -------\n self : KNeighborsRegressor\n The fitted k-nearest neighbors regressor.\n \"\"\"\n self.weights = _check_weights(self.weights)\n return self._fit(X, y)\n \n def predict(self, X):\n \"\"\"Predict the target for the provided data.\n\n Parameters\n ----------\n X : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\n Returns\n -------\n y : ndarray of shape (n_queries,) or (n_queries, n_outputs), dtype=int\n Target values.\n \"\"\"\n (neigh_dist, neigh_ind) = self.kneighbors(X)\n weights = _get_weights(neigh_dist, self.weights)\n _y = self._y\n if _y.ndim == 1:\n _y = _y.reshape((-1, 1))\n if weights is None:\n y_pred = np.mean(_y[neigh_ind], axis=1)\n else:\n y_pred = np.empty((X.shape[0], _y.shape[1]), dtype=np.float64)\n denom = np.sum(weights, axis=1)\n for j in range(_y.shape[1]):\n num = np.sum(_y[neigh_ind, j] * weights, axis=1)\n y_pred[:, j] = num / denom\n if self._y.ndim == 1:\n y_pred = y_pred.ravel()\n return y_pred\n" }, { "name": "RadiusNeighborsRegressor", @@ -25619,7 +25572,7 @@ "is_public": true, "description": "Regression based on neighbors within a fixed radius.\n\nThe target is predicted by local interpolation of the targets associated of the nearest neighbors in the training set. Read more in the :ref:`User Guide `. .. versionadded:: 0.9", "docstring": "Regression based on neighbors within a fixed radius.\n\n The target is predicted by local interpolation of the targets\n associated of the nearest neighbors in the training set.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.9\n\n Parameters\n ----------\n radius : float, default=1.0\n Range of parameter space to use by default for :meth:`radius_neighbors`\n queries.\n\n weights : {'uniform', 'distance'} or callable, default='uniform'\n Weight function used in prediction. Possible values:\n\n - 'uniform' : uniform weights. All points in each neighborhood\n are weighted equally.\n - 'distance' : weight points by the inverse of their distance.\n in this case, closer neighbors of a query point will have a\n greater influence than neighbors which are further away.\n - [callable] : a user-defined function which accepts an\n array of distances, and returns an array of the same shape\n containing the weights.\n\n Uniform weights are used by default.\n\n algorithm : {'auto', 'ball_tree', 'kd_tree', 'brute'}, default='auto'\n Algorithm used to compute the nearest neighbors:\n\n - 'ball_tree' will use :class:`BallTree`\n - 'kd_tree' will use :class:`KDTree`\n - 'brute' will use a brute-force search.\n - 'auto' will attempt to decide the most appropriate algorithm\n based on the values passed to :meth:`fit` method.\n\n Note: fitting on sparse input will override the setting of\n this parameter, using brute force.\n\n leaf_size : int, default=30\n Leaf size passed to BallTree or KDTree. This can affect the\n speed of the construction and query, as well as the memory\n required to store the tree. The optimal value depends on the\n nature of the problem.\n\n p : int, default=2\n Power parameter for the Minkowski metric. When p = 1, this is\n equivalent to using manhattan_distance (l1), and euclidean_distance\n (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used.\n\n metric : str or callable, default='minkowski'\n The distance metric to use for the tree. The default metric is\n minkowski, and with p=2 is equivalent to the standard Euclidean\n metric. See the documentation of :class:`DistanceMetric` for a\n list of available metrics.\n If metric is \"precomputed\", X is assumed to be a distance matrix and\n must be square during fit. X may be a :term:`sparse graph`,\n in which case only \"nonzero\" elements may be considered neighbors.\n\n metric_params : dict, default=None\n Additional keyword arguments for the metric function.\n\n n_jobs : int, default=None\n The number of parallel jobs to run for neighbors search.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n Attributes\n ----------\n effective_metric_ : str or callable\n The distance metric to use. It will be same as the `metric` parameter\n or a synonym of it, e.g. 'euclidean' if the `metric` parameter set to\n 'minkowski' and `p` parameter set to 2.\n\n effective_metric_params_ : dict\n Additional keyword arguments for the metric function. For most metrics\n will be same with `metric_params` parameter, but may also contain the\n `p` parameter value if the `effective_metric_` attribute is set to\n 'minkowski'.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_samples_fit_ : int\n Number of samples in the fitted data.\n\n See Also\n --------\n NearestNeighbors : Regression based on nearest neighbors.\n KNeighborsRegressor : Regression based on k-nearest neighbors.\n KNeighborsClassifier : Classifier based on the k-nearest neighbors.\n RadiusNeighborsClassifier : Classifier based on neighbors within a given radius.\n\n Notes\n -----\n See :ref:`Nearest Neighbors ` in the online documentation\n for a discussion of the choice of ``algorithm`` and ``leaf_size``.\n\n https://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm\n\n Examples\n --------\n >>> X = [[0], [1], [2], [3]]\n >>> y = [0, 0, 1, 1]\n >>> from sklearn.neighbors import RadiusNeighborsRegressor\n >>> neigh = RadiusNeighborsRegressor(radius=1.0)\n >>> neigh.fit(X, y)\n RadiusNeighborsRegressor(...)\n >>> print(neigh.predict([[1.5]]))\n [0.5]\n ", - "source_code": "\n\nclass RadiusNeighborsRegressor(RadiusNeighborsMixin, RegressorMixin, NeighborsBase):\n \"\"\"Regression based on neighbors within a fixed radius.\n\n The target is predicted by local interpolation of the targets\n associated of the nearest neighbors in the training set.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.9\n\n Parameters\n ----------\n radius : float, default=1.0\n Range of parameter space to use by default for :meth:`radius_neighbors`\n queries.\n\n weights : {'uniform', 'distance'} or callable, default='uniform'\n Weight function used in prediction. Possible values:\n\n - 'uniform' : uniform weights. All points in each neighborhood\n are weighted equally.\n - 'distance' : weight points by the inverse of their distance.\n in this case, closer neighbors of a query point will have a\n greater influence than neighbors which are further away.\n - [callable] : a user-defined function which accepts an\n array of distances, and returns an array of the same shape\n containing the weights.\n\n Uniform weights are used by default.\n\n algorithm : {'auto', 'ball_tree', 'kd_tree', 'brute'}, default='auto'\n Algorithm used to compute the nearest neighbors:\n\n - 'ball_tree' will use :class:`BallTree`\n - 'kd_tree' will use :class:`KDTree`\n - 'brute' will use a brute-force search.\n - 'auto' will attempt to decide the most appropriate algorithm\n based on the values passed to :meth:`fit` method.\n\n Note: fitting on sparse input will override the setting of\n this parameter, using brute force.\n\n leaf_size : int, default=30\n Leaf size passed to BallTree or KDTree. This can affect the\n speed of the construction and query, as well as the memory\n required to store the tree. The optimal value depends on the\n nature of the problem.\n\n p : int, default=2\n Power parameter for the Minkowski metric. When p = 1, this is\n equivalent to using manhattan_distance (l1), and euclidean_distance\n (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used.\n\n metric : str or callable, default='minkowski'\n The distance metric to use for the tree. The default metric is\n minkowski, and with p=2 is equivalent to the standard Euclidean\n metric. See the documentation of :class:`DistanceMetric` for a\n list of available metrics.\n If metric is \"precomputed\", X is assumed to be a distance matrix and\n must be square during fit. X may be a :term:`sparse graph`,\n in which case only \"nonzero\" elements may be considered neighbors.\n\n metric_params : dict, default=None\n Additional keyword arguments for the metric function.\n\n n_jobs : int, default=None\n The number of parallel jobs to run for neighbors search.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n Attributes\n ----------\n effective_metric_ : str or callable\n The distance metric to use. It will be same as the `metric` parameter\n or a synonym of it, e.g. 'euclidean' if the `metric` parameter set to\n 'minkowski' and `p` parameter set to 2.\n\n effective_metric_params_ : dict\n Additional keyword arguments for the metric function. For most metrics\n will be same with `metric_params` parameter, but may also contain the\n `p` parameter value if the `effective_metric_` attribute is set to\n 'minkowski'.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_samples_fit_ : int\n Number of samples in the fitted data.\n\n See Also\n --------\n NearestNeighbors : Regression based on nearest neighbors.\n KNeighborsRegressor : Regression based on k-nearest neighbors.\n KNeighborsClassifier : Classifier based on the k-nearest neighbors.\n RadiusNeighborsClassifier : Classifier based on neighbors within a given radius.\n\n Notes\n -----\n See :ref:`Nearest Neighbors ` in the online documentation\n for a discussion of the choice of ``algorithm`` and ``leaf_size``.\n\n https://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm\n\n Examples\n --------\n >>> X = [[0], [1], [2], [3]]\n >>> y = [0, 0, 1, 1]\n >>> from sklearn.neighbors import RadiusNeighborsRegressor\n >>> neigh = RadiusNeighborsRegressor(radius=1.0)\n >>> neigh.fit(X, y)\n RadiusNeighborsRegressor(...)\n >>> print(neigh.predict([[1.5]]))\n [0.5]\n \"\"\"\n \n def __init__(self, radius=1.0, *, weights='uniform', algorithm='auto', leaf_size=30, p=2, metric='minkowski', metric_params=None, n_jobs=None):\n super().__init__(radius=radius, algorithm=algorithm, leaf_size=leaf_size, p=p, metric=metric, metric_params=metric_params, n_jobs=n_jobs)\n self.weights = weights\n \n def fit(self, X, y):\n \"\"\"Fit the radius neighbors regressor from the training dataset.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples) if metric='precomputed'\n Training data.\n\n y : {array-like, sparse matrix} of shape (n_samples,) or (n_samples, n_outputs)\n Target values.\n\n Returns\n -------\n self : RadiusNeighborsRegressor\n The fitted radius neighbors regressor.\n \"\"\"\n self.weights = _check_weights(self.weights)\n return self._fit(X, y)\n \n def predict(self, X):\n \"\"\"Predict the target for the provided data.\n\n Parameters\n ----------\n X : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\n Returns\n -------\n y : ndarray of shape (n_queries,) or (n_queries, n_outputs), dtype=double\n Target values.\n \"\"\"\n X = self._validate_data(X, accept_sparse='csr', reset=False)\n (neigh_dist, neigh_ind) = self.radius_neighbors(X)\n weights = _get_weights(neigh_dist, self.weights)\n _y = self._y\n if _y.ndim == 1:\n _y = _y.reshape((-1, 1))\n empty_obs = np.full_like(_y[0], np.nan)\n if weights is None:\n y_pred = np.array([np.mean(_y[ind, :], axis=0) if len(ind) else empty_obs for (i, ind) in enumerate(neigh_ind)])\n else:\n y_pred = np.array([np.average(_y[ind, :], axis=0, weights=weights[i]) if len(ind) else empty_obs for (i, ind) in enumerate(neigh_ind)])\n if np.any(np.isnan(y_pred)):\n empty_warning_msg = 'One or more samples have no neighbors within specified radius; predicting NaN.'\n warnings.warn(empty_warning_msg)\n if self._y.ndim == 1:\n y_pred = y_pred.ravel()\n return y_pred\n" + "source_code": "\n\nclass RadiusNeighborsRegressor(RadiusNeighborsMixin, RegressorMixin, NeighborsBase):\n \"\"\"Regression based on neighbors within a fixed radius.\n\n The target is predicted by local interpolation of the targets\n associated of the nearest neighbors in the training set.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.9\n\n Parameters\n ----------\n radius : float, default=1.0\n Range of parameter space to use by default for :meth:`radius_neighbors`\n queries.\n\n weights : {'uniform', 'distance'} or callable, default='uniform'\n Weight function used in prediction. Possible values:\n\n - 'uniform' : uniform weights. All points in each neighborhood\n are weighted equally.\n - 'distance' : weight points by the inverse of their distance.\n in this case, closer neighbors of a query point will have a\n greater influence than neighbors which are further away.\n - [callable] : a user-defined function which accepts an\n array of distances, and returns an array of the same shape\n containing the weights.\n\n Uniform weights are used by default.\n\n algorithm : {'auto', 'ball_tree', 'kd_tree', 'brute'}, default='auto'\n Algorithm used to compute the nearest neighbors:\n\n - 'ball_tree' will use :class:`BallTree`\n - 'kd_tree' will use :class:`KDTree`\n - 'brute' will use a brute-force search.\n - 'auto' will attempt to decide the most appropriate algorithm\n based on the values passed to :meth:`fit` method.\n\n Note: fitting on sparse input will override the setting of\n this parameter, using brute force.\n\n leaf_size : int, default=30\n Leaf size passed to BallTree or KDTree. This can affect the\n speed of the construction and query, as well as the memory\n required to store the tree. The optimal value depends on the\n nature of the problem.\n\n p : int, default=2\n Power parameter for the Minkowski metric. When p = 1, this is\n equivalent to using manhattan_distance (l1), and euclidean_distance\n (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used.\n\n metric : str or callable, default='minkowski'\n The distance metric to use for the tree. The default metric is\n minkowski, and with p=2 is equivalent to the standard Euclidean\n metric. See the documentation of :class:`DistanceMetric` for a\n list of available metrics.\n If metric is \"precomputed\", X is assumed to be a distance matrix and\n must be square during fit. X may be a :term:`sparse graph`,\n in which case only \"nonzero\" elements may be considered neighbors.\n\n metric_params : dict, default=None\n Additional keyword arguments for the metric function.\n\n n_jobs : int, default=None\n The number of parallel jobs to run for neighbors search.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n Attributes\n ----------\n effective_metric_ : str or callable\n The distance metric to use. It will be same as the `metric` parameter\n or a synonym of it, e.g. 'euclidean' if the `metric` parameter set to\n 'minkowski' and `p` parameter set to 2.\n\n effective_metric_params_ : dict\n Additional keyword arguments for the metric function. For most metrics\n will be same with `metric_params` parameter, but may also contain the\n `p` parameter value if the `effective_metric_` attribute is set to\n 'minkowski'.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_samples_fit_ : int\n Number of samples in the fitted data.\n\n See Also\n --------\n NearestNeighbors : Regression based on nearest neighbors.\n KNeighborsRegressor : Regression based on k-nearest neighbors.\n KNeighborsClassifier : Classifier based on the k-nearest neighbors.\n RadiusNeighborsClassifier : Classifier based on neighbors within a given radius.\n\n Notes\n -----\n See :ref:`Nearest Neighbors ` in the online documentation\n for a discussion of the choice of ``algorithm`` and ``leaf_size``.\n\n https://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm\n\n Examples\n --------\n >>> X = [[0], [1], [2], [3]]\n >>> y = [0, 0, 1, 1]\n >>> from sklearn.neighbors import RadiusNeighborsRegressor\n >>> neigh = RadiusNeighborsRegressor(radius=1.0)\n >>> neigh.fit(X, y)\n RadiusNeighborsRegressor(...)\n >>> print(neigh.predict([[1.5]]))\n [0.5]\n \"\"\"\n \n def __init__(self, radius=1.0, *, weights='uniform', algorithm='auto', leaf_size=30, p=2, metric='minkowski', metric_params=None, n_jobs=None):\n super().__init__(radius=radius, algorithm=algorithm, leaf_size=leaf_size, p=p, metric=metric, metric_params=metric_params, n_jobs=n_jobs)\n self.weights = weights\n \n def fit(self, X, y):\n \"\"\"Fit the radius neighbors regressor from the training dataset.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples) if metric='precomputed'\n Training data.\n\n y : {array-like, sparse matrix} of shape (n_samples,) or (n_samples, n_outputs)\n Target values.\n\n Returns\n -------\n self : RadiusNeighborsRegressor\n The fitted radius neighbors regressor.\n \"\"\"\n self.weights = _check_weights(self.weights)\n return self._fit(X, y)\n \n def predict(self, X):\n \"\"\"Predict the target for the provided data.\n\n Parameters\n ----------\n X : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\n Returns\n -------\n y : ndarray of shape (n_queries,) or (n_queries, n_outputs), dtype=double\n Target values.\n \"\"\"\n (neigh_dist, neigh_ind) = self.radius_neighbors(X)\n weights = _get_weights(neigh_dist, self.weights)\n _y = self._y\n if _y.ndim == 1:\n _y = _y.reshape((-1, 1))\n empty_obs = np.full_like(_y[0], np.nan)\n if weights is None:\n y_pred = np.array([np.mean(_y[ind, :], axis=0) if len(ind) else empty_obs for (i, ind) in enumerate(neigh_ind)])\n else:\n y_pred = np.array([np.average(_y[ind, :], axis=0, weights=weights[i]) if len(ind) else empty_obs for (i, ind) in enumerate(neigh_ind)])\n if np.any(np.isnan(y_pred)):\n empty_warning_msg = 'One or more samples have no neighbors within specified radius; predicting NaN.'\n warnings.warn(empty_warning_msg)\n if self._y.ndim == 1:\n y_pred = y_pred.ravel()\n return y_pred\n" }, { "name": "NearestNeighbors", @@ -25793,7 +25746,7 @@ "sklearn.pipeline.FeatureUnion.transform", "sklearn.pipeline.FeatureUnion._hstack", "sklearn.pipeline.FeatureUnion._update_transformer_list", - "sklearn.pipeline.FeatureUnion.n_features_in_", + "sklearn.pipeline.FeatureUnion.n_features_in_@getter", "sklearn.pipeline.FeatureUnion._sk_visual_block_" ], "is_public": true, @@ -25814,9 +25767,9 @@ "sklearn.pipeline.Pipeline._iter", "sklearn.pipeline.Pipeline.__len__", "sklearn.pipeline.Pipeline.__getitem__", - "sklearn.pipeline.Pipeline._estimator_type", - "sklearn.pipeline.Pipeline.named_steps", - "sklearn.pipeline.Pipeline._final_estimator", + "sklearn.pipeline.Pipeline._estimator_type@getter", + "sklearn.pipeline.Pipeline.named_steps@getter", + "sklearn.pipeline.Pipeline._final_estimator@getter", "sklearn.pipeline.Pipeline._log_message", "sklearn.pipeline.Pipeline._check_fit_params", "sklearn.pipeline.Pipeline._fit", @@ -25833,19 +25786,19 @@ "sklearn.pipeline.Pipeline._can_inverse_transform", "sklearn.pipeline.Pipeline.inverse_transform", "sklearn.pipeline.Pipeline.score", - "sklearn.pipeline.Pipeline.classes_", + "sklearn.pipeline.Pipeline.classes_@getter", "sklearn.pipeline.Pipeline._more_tags", - "sklearn.pipeline.Pipeline._pairwise", + "sklearn.pipeline.Pipeline._pairwise@getter", "sklearn.pipeline.Pipeline.get_feature_names_out", - "sklearn.pipeline.Pipeline.n_features_in_", - "sklearn.pipeline.Pipeline.feature_names_in_", + "sklearn.pipeline.Pipeline.n_features_in_@getter", + "sklearn.pipeline.Pipeline.feature_names_in_@getter", "sklearn.pipeline.Pipeline.__sklearn_is_fitted__", "sklearn.pipeline.Pipeline._sk_visual_block_" ], "is_public": true, "description": "Pipeline of transforms with a final estimator.\n\nSequentially apply a list of transforms and a final estimator. Intermediate steps of the pipeline must be 'transforms', that is, they must implement `fit` and `transform` methods. The final estimator only needs to implement `fit`. The transformers in the pipeline can be cached using ``memory`` argument. The purpose of the pipeline is to assemble several steps that can be cross-validated together while setting different parameters. For this, it enables setting parameters of the various steps using their names and the parameter name separated by a `'__'`, as in the example below. A step's estimator may be replaced entirely by setting the parameter with its name to another estimator, or a transformer removed by setting it to `'passthrough'` or `None`. Read more in the :ref:`User Guide `. .. versionadded:: 0.5", "docstring": "\n Pipeline of transforms with a final estimator.\n\n Sequentially apply a list of transforms and a final estimator.\n Intermediate steps of the pipeline must be 'transforms', that is, they\n must implement `fit` and `transform` methods.\n The final estimator only needs to implement `fit`.\n The transformers in the pipeline can be cached using ``memory`` argument.\n\n The purpose of the pipeline is to assemble several steps that can be\n cross-validated together while setting different parameters. For this, it\n enables setting parameters of the various steps using their names and the\n parameter name separated by a `'__'`, as in the example below. A step's\n estimator may be replaced entirely by setting the parameter with its name\n to another estimator, or a transformer removed by setting it to\n `'passthrough'` or `None`.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.5\n\n Parameters\n ----------\n steps : list of tuple\n List of (name, transform) tuples (implementing `fit`/`transform`) that\n are chained, in the order in which they are chained, with the last\n object an estimator.\n\n memory : str or object with the joblib.Memory interface, default=None\n Used to cache the fitted transformers of the pipeline. By default,\n no caching is performed. If a string is given, it is the path to\n the caching directory. Enabling caching triggers a clone of\n the transformers before fitting. Therefore, the transformer\n instance given to the pipeline cannot be inspected\n directly. Use the attribute ``named_steps`` or ``steps`` to\n inspect estimators within the pipeline. Caching the\n transformers is advantageous when fitting is time consuming.\n\n verbose : bool, default=False\n If True, the time elapsed while fitting each step will be printed as it\n is completed.\n\n Attributes\n ----------\n named_steps : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n Read-only attribute to access any step parameter by user given name.\n Keys are step names and values are steps parameters.\n\n classes_ : ndarray of shape (n_classes,)\n The classes labels. Only exist if the last step of the pipeline is a\n classifier.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`. Only defined if the\n underlying first estimator in `steps` exposes such an attribute\n when fit.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Only defined if the\n underlying estimator exposes such an attribute when fit.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n make_pipeline : Convenience function for simplified pipeline construction.\n\n Examples\n --------\n >>> from sklearn.svm import SVC\n >>> from sklearn.preprocessing import StandardScaler\n >>> from sklearn.datasets import make_classification\n >>> from sklearn.model_selection import train_test_split\n >>> from sklearn.pipeline import Pipeline\n >>> X, y = make_classification(random_state=0)\n >>> X_train, X_test, y_train, y_test = train_test_split(X, y,\n ... random_state=0)\n >>> pipe = Pipeline([('scaler', StandardScaler()), ('svc', SVC())])\n >>> # The pipeline can be used as any other estimator\n >>> # and avoids leaking the test set into the train set\n >>> pipe.fit(X_train, y_train)\n Pipeline(steps=[('scaler', StandardScaler()), ('svc', SVC())])\n >>> pipe.score(X_test, y_test)\n 0.88\n ", - "source_code": "\n\nclass Pipeline(_BaseComposition):\n \"\"\"\n Pipeline of transforms with a final estimator.\n\n Sequentially apply a list of transforms and a final estimator.\n Intermediate steps of the pipeline must be 'transforms', that is, they\n must implement `fit` and `transform` methods.\n The final estimator only needs to implement `fit`.\n The transformers in the pipeline can be cached using ``memory`` argument.\n\n The purpose of the pipeline is to assemble several steps that can be\n cross-validated together while setting different parameters. For this, it\n enables setting parameters of the various steps using their names and the\n parameter name separated by a `'__'`, as in the example below. A step's\n estimator may be replaced entirely by setting the parameter with its name\n to another estimator, or a transformer removed by setting it to\n `'passthrough'` or `None`.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.5\n\n Parameters\n ----------\n steps : list of tuple\n List of (name, transform) tuples (implementing `fit`/`transform`) that\n are chained, in the order in which they are chained, with the last\n object an estimator.\n\n memory : str or object with the joblib.Memory interface, default=None\n Used to cache the fitted transformers of the pipeline. By default,\n no caching is performed. If a string is given, it is the path to\n the caching directory. Enabling caching triggers a clone of\n the transformers before fitting. Therefore, the transformer\n instance given to the pipeline cannot be inspected\n directly. Use the attribute ``named_steps`` or ``steps`` to\n inspect estimators within the pipeline. Caching the\n transformers is advantageous when fitting is time consuming.\n\n verbose : bool, default=False\n If True, the time elapsed while fitting each step will be printed as it\n is completed.\n\n Attributes\n ----------\n named_steps : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n Read-only attribute to access any step parameter by user given name.\n Keys are step names and values are steps parameters.\n\n classes_ : ndarray of shape (n_classes,)\n The classes labels. Only exist if the last step of the pipeline is a\n classifier.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`. Only defined if the\n underlying first estimator in `steps` exposes such an attribute\n when fit.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Only defined if the\n underlying estimator exposes such an attribute when fit.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n make_pipeline : Convenience function for simplified pipeline construction.\n\n Examples\n --------\n >>> from sklearn.svm import SVC\n >>> from sklearn.preprocessing import StandardScaler\n >>> from sklearn.datasets import make_classification\n >>> from sklearn.model_selection import train_test_split\n >>> from sklearn.pipeline import Pipeline\n >>> X, y = make_classification(random_state=0)\n >>> X_train, X_test, y_train, y_test = train_test_split(X, y,\n ... random_state=0)\n >>> pipe = Pipeline([('scaler', StandardScaler()), ('svc', SVC())])\n >>> # The pipeline can be used as any other estimator\n >>> # and avoids leaking the test set into the train set\n >>> pipe.fit(X_train, y_train)\n Pipeline(steps=[('scaler', StandardScaler()), ('svc', SVC())])\n >>> pipe.score(X_test, y_test)\n 0.88\n \"\"\"\n _required_parameters = ['steps']\n \n def __init__(self, steps, *, memory=None, verbose=False):\n self.steps = steps\n self.memory = memory\n self.verbose = verbose\n self._validate_steps()\n \n def get_params(self, deep=True):\n \"\"\"Get parameters for this estimator.\n\n Returns the parameters given in the constructor as well as the\n estimators contained within the `steps` of the `Pipeline`.\n\n Parameters\n ----------\n deep : bool, default=True\n If True, will return the parameters for this estimator and\n contained subobjects that are estimators.\n\n Returns\n -------\n params : mapping of string to any\n Parameter names mapped to their values.\n \"\"\"\n return self._get_params('steps', deep=deep)\n \n def set_params(self, **kwargs):\n \"\"\"Set the parameters of this estimator.\n\n Valid parameter keys can be listed with ``get_params()``. Note that\n you can directly set the parameters of the estimators contained in\n `steps`.\n\n Parameters\n ----------\n **kwargs : dict\n Parameters of this estimator or parameters of estimators contained\n in `steps`. Parameters of the steps may be set using its name and\n the parameter name separated by a '__'.\n\n Returns\n -------\n self : object\n Pipeline class instance.\n \"\"\"\n self._set_params('steps', **kwargs)\n return self\n \n def _validate_steps(self):\n (names, estimators) = zip(*self.steps)\n self._validate_names(names)\n transformers = estimators[:-1]\n estimator = estimators[-1]\n for t in transformers:\n if t is None or t == 'passthrough':\n continue\n if not (hasattr(t, 'fit') or hasattr(t, 'fit_transform')) or not hasattr(t, 'transform'):\n raise TypeError(\"All intermediate steps should be transformers and implement fit and transform or be the string 'passthrough' '%s' (type %s) doesn't\" % (t, type(t)))\n if estimator is not None and estimator != 'passthrough' and not hasattr(estimator, 'fit'):\n raise TypeError(\"Last step of Pipeline should implement fit or be the string 'passthrough'. '%s' (type %s) doesn't\" % (estimator, type(estimator)))\n \n def _iter(self, with_final=True, filter_passthrough=True):\n \"\"\"\n Generate (idx, (name, trans)) tuples from self.steps\n\n When filter_passthrough is True, 'passthrough' and None transformers\n are filtered out.\n \"\"\"\n stop = len(self.steps)\n if not with_final:\n stop -= 1\n for (idx, (name, trans)) in enumerate(islice(self.steps, 0, stop)):\n if not filter_passthrough:\n yield (idx, name, trans)\n elif trans is not None and trans != 'passthrough':\n yield (idx, name, trans)\n \n def __len__(self):\n \"\"\"\n Returns the length of the Pipeline\n \"\"\"\n return len(self.steps)\n \n def __getitem__(self, ind):\n \"\"\"Returns a sub-pipeline or a single estimator in the pipeline\n\n Indexing with an integer will return an estimator; using a slice\n returns another Pipeline instance which copies a slice of this\n Pipeline. This copy is shallow: modifying (or fitting) estimators in\n the sub-pipeline will affect the larger pipeline and vice-versa.\n However, replacing a value in `step` will not affect a copy.\n \"\"\"\n if isinstance(ind, slice):\n if ind.step not in (1, None):\n raise ValueError('Pipeline slicing only supports a step of 1')\n return self.__class__(self.steps[ind], memory=self.memory, verbose=self.verbose)\n try:\n (name, est) = self.steps[ind]\n except TypeError:\n return self.named_steps[ind]\n return est\n \n @property\n def _estimator_type(self):\n return self.steps[-1][1]._estimator_type\n \n @property\n def named_steps(self):\n \"\"\"Access the steps by name.\n\n Read-only attribute to access any step by given name.\n Keys are steps names and values are the steps objects.\"\"\"\n return Bunch(**dict(self.steps))\n \n @property\n def _final_estimator(self):\n estimator = self.steps[-1][1]\n return 'passthrough' if estimator is None else estimator\n \n def _log_message(self, step_idx):\n if not self.verbose:\n return None\n (name, _) = self.steps[step_idx]\n return '(step %d of %d) Processing %s' % (step_idx + 1, len(self.steps), name)\n \n def _check_fit_params(self, **fit_params):\n fit_params_steps = {name: {} for (name, step) in self.steps if step is not None}\n for (pname, pval) in fit_params.items():\n if '__' not in pname:\n raise ValueError('Pipeline.fit does not accept the {} parameter. You can pass parameters to specific steps of your pipeline using the stepname__parameter format, e.g. `Pipeline.fit(X, y, logisticregression__sample_weight=sample_weight)`.'.format(pname))\n (step, param) = pname.split('__', 1)\n fit_params_steps[step][param] = pval\n return fit_params_steps\n \n def _fit(self, X, y=None, **fit_params_steps):\n self.steps = list(self.steps)\n self._validate_steps()\n memory = check_memory(self.memory)\n fit_transform_one_cached = memory.cache(_fit_transform_one)\n for (step_idx, name, transformer) in self._iter(with_final=False, filter_passthrough=False):\n if transformer is None or transformer == 'passthrough':\n with _print_elapsed_time('Pipeline', self._log_message(step_idx)):\n continue\n if hasattr(memory, 'location'):\n if memory.location is None:\n cloned_transformer = transformer\n else:\n cloned_transformer = clone(transformer)\n elif hasattr(memory, 'cachedir'):\n if memory.cachedir is None:\n cloned_transformer = transformer\n else:\n cloned_transformer = clone(transformer)\n else:\n cloned_transformer = clone(transformer)\n (X, fitted_transformer) = fit_transform_one_cached(cloned_transformer, X, y, None, message_clsname='Pipeline', message=self._log_message(step_idx), **fit_params_steps[name])\n self.steps[step_idx] = (name, fitted_transformer)\n return X\n \n def fit(self, X, y=None, **fit_params):\n \"\"\"Fit the model.\n\n Fit all the transformers one after the other and transform the\n data. Finally, fit the transformed data using the final estimator.\n\n Parameters\n ----------\n X : iterable\n Training data. Must fulfill input requirements of first step of the\n pipeline.\n\n y : iterable, default=None\n Training targets. Must fulfill label requirements for all steps of\n the pipeline.\n\n **fit_params : dict of string -> object\n Parameters passed to the ``fit`` method of each step, where\n each parameter name is prefixed such that parameter ``p`` for step\n ``s`` has key ``s__p``.\n\n Returns\n -------\n self : object\n Pipeline with fitted steps.\n \"\"\"\n fit_params_steps = self._check_fit_params(**fit_params)\n Xt = self._fit(X, y, **fit_params_steps)\n with _print_elapsed_time('Pipeline', self._log_message(len(self.steps) - 1)):\n if self._final_estimator != 'passthrough':\n fit_params_last_step = fit_params_steps[self.steps[-1][0]]\n self._final_estimator.fit(Xt, y, **fit_params_last_step)\n return self\n \n def fit_transform(self, X, y=None, **fit_params):\n \"\"\"Fit the model and transform with the final estimator.\n\n Fits all the transformers one after the other and transform the\n data. Then uses `fit_transform` on transformed data with the final\n estimator.\n\n Parameters\n ----------\n X : iterable\n Training data. Must fulfill input requirements of first step of the\n pipeline.\n\n y : iterable, default=None\n Training targets. Must fulfill label requirements for all steps of\n the pipeline.\n\n **fit_params : dict of string -> object\n Parameters passed to the ``fit`` method of each step, where\n each parameter name is prefixed such that parameter ``p`` for step\n ``s`` has key ``s__p``.\n\n Returns\n -------\n Xt : ndarray of shape (n_samples, n_transformed_features)\n Transformed samples.\n \"\"\"\n fit_params_steps = self._check_fit_params(**fit_params)\n Xt = self._fit(X, y, **fit_params_steps)\n last_step = self._final_estimator\n with _print_elapsed_time('Pipeline', self._log_message(len(self.steps) - 1)):\n if last_step == 'passthrough':\n return Xt\n fit_params_last_step = fit_params_steps[self.steps[-1][0]]\n if hasattr(last_step, 'fit_transform'):\n return last_step.fit_transform(Xt, y, **fit_params_last_step)\n else:\n return last_step.fit(Xt, y, **fit_params_last_step).transform(Xt)\n \n @available_if(_final_estimator_has('predict'))\n def predict(self, X, **predict_params):\n \"\"\"Transform the data, and apply `predict` with the final estimator.\n\n Call `transform` of each transformer in the pipeline. The transformed\n data are finally passed to the final estimator that calls `predict`\n method. Only valid if the final estimator implements `predict`.\n\n Parameters\n ----------\n X : iterable\n Data to predict on. Must fulfill input requirements of first step\n of the pipeline.\n\n **predict_params : dict of string -> object\n Parameters to the ``predict`` called at the end of all\n transformations in the pipeline. Note that while this may be\n used to return uncertainties from some models with return_std\n or return_cov, uncertainties that are generated by the\n transformations in the pipeline are not propagated to the\n final estimator.\n\n .. versionadded:: 0.20\n\n Returns\n -------\n y_pred : ndarray\n Result of calling `predict` on the final estimator.\n \"\"\"\n Xt = X\n for (_, name, transform) in self._iter(with_final=False):\n Xt = transform.transform(Xt)\n return self.steps[-1][1].predict(Xt, **predict_params)\n \n @available_if(_final_estimator_has('fit_predict'))\n def fit_predict(self, X, y=None, **fit_params):\n \"\"\"Transform the data, and apply `fit_predict` with the final estimator.\n\n Call `fit_transform` of each transformer in the pipeline. The\n transformed data are finally passed to the final estimator that calls\n `fit_predict` method. Only valid if the final estimator implements\n `fit_predict`.\n\n Parameters\n ----------\n X : iterable\n Training data. Must fulfill input requirements of first step of\n the pipeline.\n\n y : iterable, default=None\n Training targets. Must fulfill label requirements for all steps\n of the pipeline.\n\n **fit_params : dict of string -> object\n Parameters passed to the ``fit`` method of each step, where\n each parameter name is prefixed such that parameter ``p`` for step\n ``s`` has key ``s__p``.\n\n Returns\n -------\n y_pred : ndarray\n Result of calling `fit_predict` on the final estimator.\n \"\"\"\n fit_params_steps = self._check_fit_params(**fit_params)\n Xt = self._fit(X, y, **fit_params_steps)\n fit_params_last_step = fit_params_steps[self.steps[-1][0]]\n with _print_elapsed_time('Pipeline', self._log_message(len(self.steps) - 1)):\n y_pred = self.steps[-1][1].fit_predict(Xt, y, **fit_params_last_step)\n return y_pred\n \n @available_if(_final_estimator_has('predict_proba'))\n def predict_proba(self, X, **predict_proba_params):\n \"\"\"Transform the data, and apply `predict_proba` with the final estimator.\n\n Call `transform` of each transformer in the pipeline. The transformed\n data are finally passed to the final estimator that calls\n `predict_proba` method. Only valid if the final estimator implements\n `predict_proba`.\n\n Parameters\n ----------\n X : iterable\n Data to predict on. Must fulfill input requirements of first step\n of the pipeline.\n\n **predict_proba_params : dict of string -> object\n Parameters to the `predict_proba` called at the end of all\n transformations in the pipeline.\n\n Returns\n -------\n y_proba : ndarray of shape (n_samples, n_classes)\n Result of calling `predict_proba` on the final estimator.\n \"\"\"\n Xt = X\n for (_, name, transform) in self._iter(with_final=False):\n Xt = transform.transform(Xt)\n return self.steps[-1][1].predict_proba(Xt, **predict_proba_params)\n \n @available_if(_final_estimator_has('decision_function'))\n def decision_function(self, X):\n \"\"\"Transform the data, and apply `decision_function` with the final estimator.\n\n Call `transform` of each transformer in the pipeline. The transformed\n data are finally passed to the final estimator that calls\n `decision_function` method. Only valid if the final estimator\n implements `decision_function`.\n\n Parameters\n ----------\n X : iterable\n Data to predict on. Must fulfill input requirements of first step\n of the pipeline.\n\n Returns\n -------\n y_score : ndarray of shape (n_samples, n_classes)\n Result of calling `decision_function` on the final estimator.\n \"\"\"\n Xt = X\n for (_, name, transform) in self._iter(with_final=False):\n Xt = transform.transform(Xt)\n return self.steps[-1][1].decision_function(Xt)\n \n @available_if(_final_estimator_has('score_samples'))\n def score_samples(self, X):\n \"\"\"Transform the data, and apply `score_samples` with the final estimator.\n\n Call `transform` of each transformer in the pipeline. The transformed\n data are finally passed to the final estimator that calls\n `score_samples` method. Only valid if the final estimator implements\n `score_samples`.\n\n Parameters\n ----------\n X : iterable\n Data to predict on. Must fulfill input requirements of first step\n of the pipeline.\n\n Returns\n -------\n y_score : ndarray of shape (n_samples,)\n Result of calling `score_samples` on the final estimator.\n \"\"\"\n Xt = X\n for (_, _, transformer) in self._iter(with_final=False):\n Xt = transformer.transform(Xt)\n return self.steps[-1][1].score_samples(Xt)\n \n @available_if(_final_estimator_has('predict_log_proba'))\n def predict_log_proba(self, X, **predict_log_proba_params):\n \"\"\"Transform the data, and apply `predict_log_proba` with the final estimator.\n\n Call `transform` of each transformer in the pipeline. The transformed\n data are finally passed to the final estimator that calls\n `predict_log_proba` method. Only valid if the final estimator\n implements `predict_log_proba`.\n\n Parameters\n ----------\n X : iterable\n Data to predict on. Must fulfill input requirements of first step\n of the pipeline.\n\n **predict_log_proba_params : dict of string -> object\n Parameters to the ``predict_log_proba`` called at the end of all\n transformations in the pipeline.\n\n Returns\n -------\n y_log_proba : ndarray of shape (n_samples, n_classes)\n Result of calling `predict_log_proba` on the final estimator.\n \"\"\"\n Xt = X\n for (_, name, transform) in self._iter(with_final=False):\n Xt = transform.transform(Xt)\n return self.steps[-1][1].predict_log_proba(Xt, **predict_log_proba_params)\n \n def _can_transform(self):\n return self._final_estimator == 'passthrough' or hasattr(self._final_estimator, 'transform')\n \n @available_if(_can_transform)\n def transform(self, X):\n \"\"\"Transform the data, and apply `transform` with the final estimator.\n\n Call `transform` of each transformer in the pipeline. The transformed\n data are finally passed to the final estimator that calls\n `transform` method. Only valid if the final estimator\n implements `transform`.\n\n This also works where final estimator is `None` in which case all prior\n transformations are applied.\n\n Parameters\n ----------\n X : iterable\n Data to transform. Must fulfill input requirements of first step\n of the pipeline.\n\n Returns\n -------\n Xt : ndarray of shape (n_samples, n_transformed_features)\n Transformed data.\n \"\"\"\n Xt = X\n for (_, _, transform) in self._iter():\n Xt = transform.transform(Xt)\n return Xt\n \n def _can_inverse_transform(self):\n return all((hasattr(t, 'inverse_transform') for (_, _, t) in self._iter()))\n \n @available_if(_can_inverse_transform)\n def inverse_transform(self, Xt):\n \"\"\"Apply `inverse_transform` for each step in a reverse order.\n\n All estimators in the pipeline must support `inverse_transform`.\n\n Parameters\n ----------\n Xt : array-like of shape (n_samples, n_transformed_features)\n Data samples, where ``n_samples`` is the number of samples and\n ``n_features`` is the number of features. Must fulfill\n input requirements of last step of pipeline's\n ``inverse_transform`` method.\n\n Returns\n -------\n Xt : ndarray of shape (n_samples, n_features)\n Inverse transformed data, that is, data in the original feature\n space.\n \"\"\"\n reverse_iter = reversed(list(self._iter()))\n for (_, _, transform) in reverse_iter:\n Xt = transform.inverse_transform(Xt)\n return Xt\n \n @available_if(_final_estimator_has('score'))\n def score(self, X, y=None, sample_weight=None):\n \"\"\"Transform the data, and apply `score` with the final estimator.\n\n Call `transform` of each transformer in the pipeline. The transformed\n data are finally passed to the final estimator that calls\n `score` method. Only valid if the final estimator implements `score`.\n\n Parameters\n ----------\n X : iterable\n Data to predict on. Must fulfill input requirements of first step\n of the pipeline.\n\n y : iterable, default=None\n Targets used for scoring. Must fulfill label requirements for all\n steps of the pipeline.\n\n sample_weight : array-like, default=None\n If not None, this argument is passed as ``sample_weight`` keyword\n argument to the ``score`` method of the final estimator.\n\n Returns\n -------\n score : float\n Result of calling `score` on the final estimator.\n \"\"\"\n Xt = X\n for (_, name, transform) in self._iter(with_final=False):\n Xt = transform.transform(Xt)\n score_params = {}\n if sample_weight is not None:\n score_params['sample_weight'] = sample_weight\n return self.steps[-1][1].score(Xt, y, **score_params)\n \n @property\n def classes_(self):\n \"\"\"The classes labels. Only exist if the last step is a classifier.\"\"\"\n return self.steps[-1][1].classes_\n \n def _more_tags(self):\n return {'pairwise': _safe_tags(self.steps[0][1], 'pairwise')}\n \n @deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def _pairwise(self):\n return getattr(self.steps[0][1], '_pairwise', False)\n \n def get_feature_names_out(self, input_features=None):\n \"\"\"Get output feature names for transformation.\n\n Transform input features using the pipeline.\n\n Parameters\n ----------\n input_features : array-like of str or None, default=None\n Input features.\n\n Returns\n -------\n feature_names_out : ndarray of str objects\n Transformed feature names.\n \"\"\"\n for (_, name, transform) in self._iter():\n if not hasattr(transform, 'get_feature_names_out'):\n raise AttributeError('Estimator {} does not provide get_feature_names_out. Did you mean to call pipeline[:-1].get_feature_names_out()?'.format(name))\n feature_names = transform.get_feature_names_out(input_features)\n return feature_names\n \n @property\n def n_features_in_(self):\n \"\"\"Number of features seen during first step `fit` method.\"\"\"\n return self.steps[0][1].n_features_in_\n \n @property\n def feature_names_in_(self):\n \"\"\"Names of features seen during first step `fit` method.\"\"\"\n return self.steps[0][1].feature_names_in_\n \n def __sklearn_is_fitted__(self):\n \"\"\"Indicate whether pipeline has been fit.\"\"\"\n try:\n check_is_fitted(self.steps[-1][1])\n return True\n except NotFittedError:\n return False\n \n def _sk_visual_block_(self):\n (_, estimators) = zip(*self.steps)\n \n def _get_name(name, est):\n if est is None or est == 'passthrough':\n return f'{name}: passthrough'\n return f'{name}: {est.__class__.__name__}'\n names = [_get_name(name, est) for (name, est) in self.steps]\n name_details = [str(est) for est in estimators]\n return _VisualBlock('serial', estimators, names=names, name_details=name_details, dash_wrapped=False)\n" + "source_code": "\n\nclass Pipeline(_BaseComposition):\n \"\"\"\n Pipeline of transforms with a final estimator.\n\n Sequentially apply a list of transforms and a final estimator.\n Intermediate steps of the pipeline must be 'transforms', that is, they\n must implement `fit` and `transform` methods.\n The final estimator only needs to implement `fit`.\n The transformers in the pipeline can be cached using ``memory`` argument.\n\n The purpose of the pipeline is to assemble several steps that can be\n cross-validated together while setting different parameters. For this, it\n enables setting parameters of the various steps using their names and the\n parameter name separated by a `'__'`, as in the example below. A step's\n estimator may be replaced entirely by setting the parameter with its name\n to another estimator, or a transformer removed by setting it to\n `'passthrough'` or `None`.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.5\n\n Parameters\n ----------\n steps : list of tuple\n List of (name, transform) tuples (implementing `fit`/`transform`) that\n are chained, in the order in which they are chained, with the last\n object an estimator.\n\n memory : str or object with the joblib.Memory interface, default=None\n Used to cache the fitted transformers of the pipeline. By default,\n no caching is performed. If a string is given, it is the path to\n the caching directory. Enabling caching triggers a clone of\n the transformers before fitting. Therefore, the transformer\n instance given to the pipeline cannot be inspected\n directly. Use the attribute ``named_steps`` or ``steps`` to\n inspect estimators within the pipeline. Caching the\n transformers is advantageous when fitting is time consuming.\n\n verbose : bool, default=False\n If True, the time elapsed while fitting each step will be printed as it\n is completed.\n\n Attributes\n ----------\n named_steps : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n Read-only attribute to access any step parameter by user given name.\n Keys are step names and values are steps parameters.\n\n classes_ : ndarray of shape (n_classes,)\n The classes labels. Only exist if the last step of the pipeline is a\n classifier.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`. Only defined if the\n underlying first estimator in `steps` exposes such an attribute\n when fit.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Only defined if the\n underlying estimator exposes such an attribute when fit.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n make_pipeline : Convenience function for simplified pipeline construction.\n\n Examples\n --------\n >>> from sklearn.svm import SVC\n >>> from sklearn.preprocessing import StandardScaler\n >>> from sklearn.datasets import make_classification\n >>> from sklearn.model_selection import train_test_split\n >>> from sklearn.pipeline import Pipeline\n >>> X, y = make_classification(random_state=0)\n >>> X_train, X_test, y_train, y_test = train_test_split(X, y,\n ... random_state=0)\n >>> pipe = Pipeline([('scaler', StandardScaler()), ('svc', SVC())])\n >>> # The pipeline can be used as any other estimator\n >>> # and avoids leaking the test set into the train set\n >>> pipe.fit(X_train, y_train)\n Pipeline(steps=[('scaler', StandardScaler()), ('svc', SVC())])\n >>> pipe.score(X_test, y_test)\n 0.88\n \"\"\"\n _required_parameters = ['steps']\n \n def __init__(self, steps, *, memory=None, verbose=False):\n self.steps = steps\n self.memory = memory\n self.verbose = verbose\n self._validate_steps()\n \n def get_params(self, deep=True):\n \"\"\"Get parameters for this estimator.\n\n Returns the parameters given in the constructor as well as the\n estimators contained within the `steps` of the `Pipeline`.\n\n Parameters\n ----------\n deep : bool, default=True\n If True, will return the parameters for this estimator and\n contained subobjects that are estimators.\n\n Returns\n -------\n params : mapping of string to any\n Parameter names mapped to their values.\n \"\"\"\n return self._get_params('steps', deep=deep)\n \n def set_params(self, **kwargs):\n \"\"\"Set the parameters of this estimator.\n\n Valid parameter keys can be listed with ``get_params()``. Note that\n you can directly set the parameters of the estimators contained in\n `steps`.\n\n Parameters\n ----------\n **kwargs : dict\n Parameters of this estimator or parameters of estimators contained\n in `steps`. Parameters of the steps may be set using its name and\n the parameter name separated by a '__'.\n\n Returns\n -------\n self : object\n Pipeline class instance.\n \"\"\"\n self._set_params('steps', **kwargs)\n return self\n \n def _validate_steps(self):\n (names, estimators) = zip(*self.steps)\n self._validate_names(names)\n transformers = estimators[:-1]\n estimator = estimators[-1]\n for t in transformers:\n if t is None or t == 'passthrough':\n continue\n if not (hasattr(t, 'fit') or hasattr(t, 'fit_transform')) or not hasattr(t, 'transform'):\n raise TypeError(\"All intermediate steps should be transformers and implement fit and transform or be the string 'passthrough' '%s' (type %s) doesn't\" % (t, type(t)))\n if estimator is not None and estimator != 'passthrough' and not hasattr(estimator, 'fit'):\n raise TypeError(\"Last step of Pipeline should implement fit or be the string 'passthrough'. '%s' (type %s) doesn't\" % (estimator, type(estimator)))\n \n def _iter(self, with_final=True, filter_passthrough=True):\n \"\"\"\n Generate (idx, (name, trans)) tuples from self.steps\n\n When filter_passthrough is True, 'passthrough' and None transformers\n are filtered out.\n \"\"\"\n stop = len(self.steps)\n if not with_final:\n stop -= 1\n for (idx, (name, trans)) in enumerate(islice(self.steps, 0, stop)):\n if not filter_passthrough:\n yield (idx, name, trans)\n elif trans is not None and trans != 'passthrough':\n yield (idx, name, trans)\n \n def __len__(self):\n \"\"\"\n Returns the length of the Pipeline\n \"\"\"\n return len(self.steps)\n \n def __getitem__(self, ind):\n \"\"\"Returns a sub-pipeline or a single estimator in the pipeline\n\n Indexing with an integer will return an estimator; using a slice\n returns another Pipeline instance which copies a slice of this\n Pipeline. This copy is shallow: modifying (or fitting) estimators in\n the sub-pipeline will affect the larger pipeline and vice-versa.\n However, replacing a value in `step` will not affect a copy.\n \"\"\"\n if isinstance(ind, slice):\n if ind.step not in (1, None):\n raise ValueError('Pipeline slicing only supports a step of 1')\n return self.__class__(self.steps[ind], memory=self.memory, verbose=self.verbose)\n try:\n (name, est) = self.steps[ind]\n except TypeError:\n return self.named_steps[ind]\n return est\n \n @property\n def _estimator_type(self):\n return self.steps[-1][1]._estimator_type\n \n @property\n def named_steps(self):\n \"\"\"Access the steps by name.\n\n Read-only attribute to access any step by given name.\n Keys are steps names and values are the steps objects.\"\"\"\n return Bunch(**dict(self.steps))\n \n @property\n def _final_estimator(self):\n estimator = self.steps[-1][1]\n return 'passthrough' if estimator is None else estimator\n \n def _log_message(self, step_idx):\n if not self.verbose:\n return None\n (name, _) = self.steps[step_idx]\n return '(step %d of %d) Processing %s' % (step_idx + 1, len(self.steps), name)\n \n def _check_fit_params(self, **fit_params):\n fit_params_steps = {name: {} for (name, step) in self.steps if step is not None}\n for (pname, pval) in fit_params.items():\n if '__' not in pname:\n raise ValueError('Pipeline.fit does not accept the {} parameter. You can pass parameters to specific steps of your pipeline using the stepname__parameter format, e.g. `Pipeline.fit(X, y, logisticregression__sample_weight=sample_weight)`.'.format(pname))\n (step, param) = pname.split('__', 1)\n fit_params_steps[step][param] = pval\n return fit_params_steps\n \n def _fit(self, X, y=None, **fit_params_steps):\n self.steps = list(self.steps)\n self._validate_steps()\n memory = check_memory(self.memory)\n fit_transform_one_cached = memory.cache(_fit_transform_one)\n for (step_idx, name, transformer) in self._iter(with_final=False, filter_passthrough=False):\n if transformer is None or transformer == 'passthrough':\n with _print_elapsed_time('Pipeline', self._log_message(step_idx)):\n continue\n if hasattr(memory, 'location'):\n if memory.location is None:\n cloned_transformer = transformer\n else:\n cloned_transformer = clone(transformer)\n elif hasattr(memory, 'cachedir'):\n if memory.cachedir is None:\n cloned_transformer = transformer\n else:\n cloned_transformer = clone(transformer)\n else:\n cloned_transformer = clone(transformer)\n (X, fitted_transformer) = fit_transform_one_cached(cloned_transformer, X, y, None, message_clsname='Pipeline', message=self._log_message(step_idx), **fit_params_steps[name])\n self.steps[step_idx] = (name, fitted_transformer)\n return X\n \n def fit(self, X, y=None, **fit_params):\n \"\"\"Fit the model.\n\n Fit all the transformers one after the other and transform the\n data. Finally, fit the transformed data using the final estimator.\n\n Parameters\n ----------\n X : iterable\n Training data. Must fulfill input requirements of first step of the\n pipeline.\n\n y : iterable, default=None\n Training targets. Must fulfill label requirements for all steps of\n the pipeline.\n\n **fit_params : dict of string -> object\n Parameters passed to the ``fit`` method of each step, where\n each parameter name is prefixed such that parameter ``p`` for step\n ``s`` has key ``s__p``.\n\n Returns\n -------\n self : object\n Pipeline with fitted steps.\n \"\"\"\n fit_params_steps = self._check_fit_params(**fit_params)\n Xt = self._fit(X, y, **fit_params_steps)\n with _print_elapsed_time('Pipeline', self._log_message(len(self.steps) - 1)):\n if self._final_estimator != 'passthrough':\n fit_params_last_step = fit_params_steps[self.steps[-1][0]]\n self._final_estimator.fit(Xt, y, **fit_params_last_step)\n return self\n \n def fit_transform(self, X, y=None, **fit_params):\n \"\"\"Fit the model and transform with the final estimator.\n\n Fits all the transformers one after the other and transform the\n data. Then uses `fit_transform` on transformed data with the final\n estimator.\n\n Parameters\n ----------\n X : iterable\n Training data. Must fulfill input requirements of first step of the\n pipeline.\n\n y : iterable, default=None\n Training targets. Must fulfill label requirements for all steps of\n the pipeline.\n\n **fit_params : dict of string -> object\n Parameters passed to the ``fit`` method of each step, where\n each parameter name is prefixed such that parameter ``p`` for step\n ``s`` has key ``s__p``.\n\n Returns\n -------\n Xt : ndarray of shape (n_samples, n_transformed_features)\n Transformed samples.\n \"\"\"\n fit_params_steps = self._check_fit_params(**fit_params)\n Xt = self._fit(X, y, **fit_params_steps)\n last_step = self._final_estimator\n with _print_elapsed_time('Pipeline', self._log_message(len(self.steps) - 1)):\n if last_step == 'passthrough':\n return Xt\n fit_params_last_step = fit_params_steps[self.steps[-1][0]]\n if hasattr(last_step, 'fit_transform'):\n return last_step.fit_transform(Xt, y, **fit_params_last_step)\n else:\n return last_step.fit(Xt, y, **fit_params_last_step).transform(Xt)\n \n @available_if(_final_estimator_has('predict'))\n def predict(self, X, **predict_params):\n \"\"\"Transform the data, and apply `predict` with the final estimator.\n\n Call `transform` of each transformer in the pipeline. The transformed\n data are finally passed to the final estimator that calls `predict`\n method. Only valid if the final estimator implements `predict`.\n\n Parameters\n ----------\n X : iterable\n Data to predict on. Must fulfill input requirements of first step\n of the pipeline.\n\n **predict_params : dict of string -> object\n Parameters to the ``predict`` called at the end of all\n transformations in the pipeline. Note that while this may be\n used to return uncertainties from some models with return_std\n or return_cov, uncertainties that are generated by the\n transformations in the pipeline are not propagated to the\n final estimator.\n\n .. versionadded:: 0.20\n\n Returns\n -------\n y_pred : ndarray\n Result of calling `predict` on the final estimator.\n \"\"\"\n Xt = X\n for (_, name, transform) in self._iter(with_final=False):\n Xt = transform.transform(Xt)\n return self.steps[-1][1].predict(Xt, **predict_params)\n \n @available_if(_final_estimator_has('fit_predict'))\n def fit_predict(self, X, y=None, **fit_params):\n \"\"\"Transform the data, and apply `fit_predict` with the final estimator.\n\n Call `fit_transform` of each transformer in the pipeline. The\n transformed data are finally passed to the final estimator that calls\n `fit_predict` method. Only valid if the final estimator implements\n `fit_predict`.\n\n Parameters\n ----------\n X : iterable\n Training data. Must fulfill input requirements of first step of\n the pipeline.\n\n y : iterable, default=None\n Training targets. Must fulfill label requirements for all steps\n of the pipeline.\n\n **fit_params : dict of string -> object\n Parameters passed to the ``fit`` method of each step, where\n each parameter name is prefixed such that parameter ``p`` for step\n ``s`` has key ``s__p``.\n\n Returns\n -------\n y_pred : ndarray\n Result of calling `fit_predict` on the final estimator.\n \"\"\"\n fit_params_steps = self._check_fit_params(**fit_params)\n Xt = self._fit(X, y, **fit_params_steps)\n fit_params_last_step = fit_params_steps[self.steps[-1][0]]\n with _print_elapsed_time('Pipeline', self._log_message(len(self.steps) - 1)):\n y_pred = self.steps[-1][1].fit_predict(Xt, y, **fit_params_last_step)\n return y_pred\n \n @available_if(_final_estimator_has('predict_proba'))\n def predict_proba(self, X, **predict_proba_params):\n \"\"\"Transform the data, and apply `predict_proba` with the final estimator.\n\n Call `transform` of each transformer in the pipeline. The transformed\n data are finally passed to the final estimator that calls\n `predict_proba` method. Only valid if the final estimator implements\n `predict_proba`.\n\n Parameters\n ----------\n X : iterable\n Data to predict on. Must fulfill input requirements of first step\n of the pipeline.\n\n **predict_proba_params : dict of string -> object\n Parameters to the `predict_proba` called at the end of all\n transformations in the pipeline.\n\n Returns\n -------\n y_proba : ndarray of shape (n_samples, n_classes)\n Result of calling `predict_proba` on the final estimator.\n \"\"\"\n Xt = X\n for (_, name, transform) in self._iter(with_final=False):\n Xt = transform.transform(Xt)\n return self.steps[-1][1].predict_proba(Xt, **predict_proba_params)\n \n @available_if(_final_estimator_has('decision_function'))\n def decision_function(self, X):\n \"\"\"Transform the data, and apply `decision_function` with the final estimator.\n\n Call `transform` of each transformer in the pipeline. The transformed\n data are finally passed to the final estimator that calls\n `decision_function` method. Only valid if the final estimator\n implements `decision_function`.\n\n Parameters\n ----------\n X : iterable\n Data to predict on. Must fulfill input requirements of first step\n of the pipeline.\n\n Returns\n -------\n y_score : ndarray of shape (n_samples, n_classes)\n Result of calling `decision_function` on the final estimator.\n \"\"\"\n Xt = X\n for (_, name, transform) in self._iter(with_final=False):\n Xt = transform.transform(Xt)\n return self.steps[-1][1].decision_function(Xt)\n \n @available_if(_final_estimator_has('score_samples'))\n def score_samples(self, X):\n \"\"\"Transform the data, and apply `score_samples` with the final estimator.\n\n Call `transform` of each transformer in the pipeline. The transformed\n data are finally passed to the final estimator that calls\n `score_samples` method. Only valid if the final estimator implements\n `score_samples`.\n\n Parameters\n ----------\n X : iterable\n Data to predict on. Must fulfill input requirements of first step\n of the pipeline.\n\n Returns\n -------\n y_score : ndarray of shape (n_samples,)\n Result of calling `score_samples` on the final estimator.\n \"\"\"\n Xt = X\n for (_, _, transformer) in self._iter(with_final=False):\n Xt = transformer.transform(Xt)\n return self.steps[-1][1].score_samples(Xt)\n \n @available_if(_final_estimator_has('predict_log_proba'))\n def predict_log_proba(self, X, **predict_log_proba_params):\n \"\"\"Transform the data, and apply `predict_log_proba` with the final estimator.\n\n Call `transform` of each transformer in the pipeline. The transformed\n data are finally passed to the final estimator that calls\n `predict_log_proba` method. Only valid if the final estimator\n implements `predict_log_proba`.\n\n Parameters\n ----------\n X : iterable\n Data to predict on. Must fulfill input requirements of first step\n of the pipeline.\n\n **predict_log_proba_params : dict of string -> object\n Parameters to the ``predict_log_proba`` called at the end of all\n transformations in the pipeline.\n\n Returns\n -------\n y_log_proba : ndarray of shape (n_samples, n_classes)\n Result of calling `predict_log_proba` on the final estimator.\n \"\"\"\n Xt = X\n for (_, name, transform) in self._iter(with_final=False):\n Xt = transform.transform(Xt)\n return self.steps[-1][1].predict_log_proba(Xt, **predict_log_proba_params)\n \n def _can_transform(self):\n return self._final_estimator == 'passthrough' or hasattr(self._final_estimator, 'transform')\n \n @available_if(_can_transform)\n def transform(self, X):\n \"\"\"Transform the data, and apply `transform` with the final estimator.\n\n Call `transform` of each transformer in the pipeline. The transformed\n data are finally passed to the final estimator that calls\n `transform` method. Only valid if the final estimator\n implements `transform`.\n\n This also works where final estimator is `None` in which case all prior\n transformations are applied.\n\n Parameters\n ----------\n X : iterable\n Data to transform. Must fulfill input requirements of first step\n of the pipeline.\n\n Returns\n -------\n Xt : ndarray of shape (n_samples, n_transformed_features)\n Transformed data.\n \"\"\"\n Xt = X\n for (_, _, transform) in self._iter():\n Xt = transform.transform(Xt)\n return Xt\n \n def _can_inverse_transform(self):\n return all((hasattr(t, 'inverse_transform') for (_, _, t) in self._iter()))\n \n @available_if(_can_inverse_transform)\n def inverse_transform(self, Xt):\n \"\"\"Apply `inverse_transform` for each step in a reverse order.\n\n All estimators in the pipeline must support `inverse_transform`.\n\n Parameters\n ----------\n Xt : array-like of shape (n_samples, n_transformed_features)\n Data samples, where ``n_samples`` is the number of samples and\n ``n_features`` is the number of features. Must fulfill\n input requirements of last step of pipeline's\n ``inverse_transform`` method.\n\n Returns\n -------\n Xt : ndarray of shape (n_samples, n_features)\n Inverse transformed data, that is, data in the original feature\n space.\n \"\"\"\n reverse_iter = reversed(list(self._iter()))\n for (_, _, transform) in reverse_iter:\n Xt = transform.inverse_transform(Xt)\n return Xt\n \n @available_if(_final_estimator_has('score'))\n def score(self, X, y=None, sample_weight=None):\n \"\"\"Transform the data, and apply `score` with the final estimator.\n\n Call `transform` of each transformer in the pipeline. The transformed\n data are finally passed to the final estimator that calls\n `score` method. Only valid if the final estimator implements `score`.\n\n Parameters\n ----------\n X : iterable\n Data to predict on. Must fulfill input requirements of first step\n of the pipeline.\n\n y : iterable, default=None\n Targets used for scoring. Must fulfill label requirements for all\n steps of the pipeline.\n\n sample_weight : array-like, default=None\n If not None, this argument is passed as ``sample_weight`` keyword\n argument to the ``score`` method of the final estimator.\n\n Returns\n -------\n score : float\n Result of calling `score` on the final estimator.\n \"\"\"\n Xt = X\n for (_, name, transform) in self._iter(with_final=False):\n Xt = transform.transform(Xt)\n score_params = {}\n if sample_weight is not None:\n score_params['sample_weight'] = sample_weight\n return self.steps[-1][1].score(Xt, y, **score_params)\n \n @property\n def classes_(self):\n \"\"\"The classes labels. Only exist if the last step is a classifier.\"\"\"\n return self.steps[-1][1].classes_\n \n def _more_tags(self):\n return {'pairwise': _safe_tags(self.steps[0][1], 'pairwise')}\n \n @deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def _pairwise(self):\n return getattr(self.steps[0][1], '_pairwise', False)\n \n def get_feature_names_out(self, input_features=None):\n \"\"\"Get output feature names for transformation.\n\n Transform input features using the pipeline.\n\n Parameters\n ----------\n input_features : array-like of str or None, default=None\n Input features.\n\n Returns\n -------\n feature_names_out : ndarray of str objects\n Transformed feature names.\n \"\"\"\n feature_names_out = input_features\n for (_, name, transform) in self._iter():\n if not hasattr(transform, 'get_feature_names_out'):\n raise AttributeError('Estimator {} does not provide get_feature_names_out. Did you mean to call pipeline[:-1].get_feature_names_out()?'.format(name))\n feature_names_out = transform.get_feature_names_out(feature_names_out)\n return feature_names_out\n \n @property\n def n_features_in_(self):\n \"\"\"Number of features seen during first step `fit` method.\"\"\"\n return self.steps[0][1].n_features_in_\n \n @property\n def feature_names_in_(self):\n \"\"\"Names of features seen during first step `fit` method.\"\"\"\n return self.steps[0][1].feature_names_in_\n \n def __sklearn_is_fitted__(self):\n \"\"\"Indicate whether pipeline has been fit.\"\"\"\n try:\n check_is_fitted(self.steps[-1][1])\n return True\n except NotFittedError:\n return False\n \n def _sk_visual_block_(self):\n (_, estimators) = zip(*self.steps)\n \n def _get_name(name, est):\n if est is None or est == 'passthrough':\n return f'{name}: passthrough'\n return f'{name}: {est.__class__.__name__}'\n names = [_get_name(name, est) for (name, est) in self.steps]\n name_details = [str(est) for est in estimators]\n return _VisualBlock('serial', estimators, names=names, name_details=name_details, dash_wrapped=False)\n" }, { "name": "Binarizer", @@ -25873,7 +25826,7 @@ "sklearn.preprocessing._data.KernelCenterer.fit", "sklearn.preprocessing._data.KernelCenterer.transform", "sklearn.preprocessing._data.KernelCenterer._more_tags", - "sklearn.preprocessing._data.KernelCenterer._pairwise" + "sklearn.preprocessing._data.KernelCenterer._pairwise@getter" ], "is_public": true, "description": "Center an arbitrary kernel matrix :math:`K`.\n\nLet define a kernel :math:`K` such that: .. math:: K(X, Y) = \\phi(X) . \\phi(Y)^{T} :math:`\\phi(X)` is a function mapping of rows of :math:`X` to a Hilbert space and :math:`K` is of shape `(n_samples, n_samples)`. This class allows to compute :math:`\\tilde{K}(X, Y)` such that: .. math:: \\tilde{K(X, Y)} = \\tilde{\\phi}(X) . \\tilde{\\phi}(Y)^{T} :math:`\\tilde{\\phi}(X)` is the centered mapped data in the Hilbert space. `KernelCenterer` centers the features without explicitly computing the mapping :math:`\\phi(\\cdot)`. Working with centered kernels is sometime expected when dealing with algebra computation such as eigendecomposition for :class:`~sklearn.decomposition.KernelPCA` for instance. Read more in the :ref:`User Guide `.", @@ -26014,9 +25967,9 @@ "sklearn.preprocessing._data.RobustScaler._more_tags" ], "is_public": true, - "description": "Scale features using statistics that are robust to outliers.\n\nThis Scaler removes the median and scales the data according to the quantile range (defaults to IQR: Interquartile Range). The IQR is the range between the 1st quartile (25th quantile) and the 3rd quartile (75th quantile). Centering and scaling happen independently on each feature by computing the relevant statistics on the samples in the training set. Median and interquartile range are then stored to be used on later data using the ``transform`` method. Standardization of a dataset is a common requirement for many machine learning estimators. Typically this is done by removing the mean and scaling to unit variance. However, outliers can often influence the sample mean / variance in a negative way. In such cases, the median and the interquartile range often give better results. .. versionadded:: 0.17 Read more in the :ref:`User Guide `.", - "docstring": "Scale features using statistics that are robust to outliers.\n\n This Scaler removes the median and scales the data according to\n the quantile range (defaults to IQR: Interquartile Range).\n The IQR is the range between the 1st quartile (25th quantile)\n and the 3rd quartile (75th quantile).\n\n Centering and scaling happen independently on each feature by\n computing the relevant statistics on the samples in the training\n set. Median and interquartile range are then stored to be used on\n later data using the ``transform`` method.\n\n Standardization of a dataset is a common requirement for many\n machine learning estimators. Typically this is done by removing the mean\n and scaling to unit variance. However, outliers can often influence the\n sample mean / variance in a negative way. In such cases, the median and\n the interquartile range often give better results.\n\n .. versionadded:: 0.17\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n with_centering : bool, default=True\n If True, center the data before scaling.\n This will cause ``transform`` to raise an exception when attempted on\n sparse matrices, because centering them entails building a dense\n matrix which in common use cases is likely to be too large to fit in\n memory.\n\n with_scaling : bool, default=True\n If True, scale the data to interquartile range.\n\n quantile_range : tuple (q_min, q_max), 0.0 < q_min < q_max < 100.0, default=(25.0, 75.0), == (1st quantile, 3rd quantile), == IQR\n Quantile range used to calculate ``scale_``.\n\n .. versionadded:: 0.18\n\n copy : bool, default=True\n If False, try to avoid a copy and do inplace scaling instead.\n This is not guaranteed to always work inplace; e.g. if the data is\n not a NumPy array or scipy.sparse CSR matrix, a copy may still be\n returned.\n\n unit_variance : bool, default=False\n If True, scale data so that normally distributed features have a\n variance of 1. In general, if the difference between the x-values of\n ``q_max`` and ``q_min`` for a standard normal distribution is greater\n than 1, the dataset will be scaled down. If less than 1, the dataset\n will be scaled up.\n\n .. versionadded:: 0.24\n\n Attributes\n ----------\n center_ : array of floats\n The median value for each feature in the training set.\n\n scale_ : array of floats\n The (scaled) interquartile range for each feature in the training set.\n\n .. versionadded:: 0.17\n *scale_* attribute.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn.preprocessing import RobustScaler\n >>> X = [[ 1., -2., 2.],\n ... [ -2., 1., 3.],\n ... [ 4., 1., -2.]]\n >>> transformer = RobustScaler().fit(X)\n >>> transformer\n RobustScaler()\n >>> transformer.transform(X)\n array([[ 0. , -2. , 0. ],\n [-1. , 0. , 0.4],\n [ 1. , 0. , -1.6]])\n\n See Also\n --------\n robust_scale : Equivalent function without the estimator API.\n\n :class:`~sklearn.decomposition.PCA`\n Further removes the linear correlation across features with\n 'whiten=True'.\n\n Notes\n -----\n For a comparison of the different scalers, transformers, and normalizers,\n see :ref:`examples/preprocessing/plot_all_scaling.py\n `.\n\n https://en.wikipedia.org/wiki/Median\n https://en.wikipedia.org/wiki/Interquartile_range\n ", - "source_code": "\n\nclass RobustScaler(_OneToOneFeatureMixin, TransformerMixin, BaseEstimator):\n \"\"\"Scale features using statistics that are robust to outliers.\n\n This Scaler removes the median and scales the data according to\n the quantile range (defaults to IQR: Interquartile Range).\n The IQR is the range between the 1st quartile (25th quantile)\n and the 3rd quartile (75th quantile).\n\n Centering and scaling happen independently on each feature by\n computing the relevant statistics on the samples in the training\n set. Median and interquartile range are then stored to be used on\n later data using the ``transform`` method.\n\n Standardization of a dataset is a common requirement for many\n machine learning estimators. Typically this is done by removing the mean\n and scaling to unit variance. However, outliers can often influence the\n sample mean / variance in a negative way. In such cases, the median and\n the interquartile range often give better results.\n\n .. versionadded:: 0.17\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n with_centering : bool, default=True\n If True, center the data before scaling.\n This will cause ``transform`` to raise an exception when attempted on\n sparse matrices, because centering them entails building a dense\n matrix which in common use cases is likely to be too large to fit in\n memory.\n\n with_scaling : bool, default=True\n If True, scale the data to interquartile range.\n\n quantile_range : tuple (q_min, q_max), 0.0 < q_min < q_max < 100.0, default=(25.0, 75.0), == (1st quantile, 3rd quantile), == IQR\n Quantile range used to calculate ``scale_``.\n\n .. versionadded:: 0.18\n\n copy : bool, default=True\n If False, try to avoid a copy and do inplace scaling instead.\n This is not guaranteed to always work inplace; e.g. if the data is\n not a NumPy array or scipy.sparse CSR matrix, a copy may still be\n returned.\n\n unit_variance : bool, default=False\n If True, scale data so that normally distributed features have a\n variance of 1. In general, if the difference between the x-values of\n ``q_max`` and ``q_min`` for a standard normal distribution is greater\n than 1, the dataset will be scaled down. If less than 1, the dataset\n will be scaled up.\n\n .. versionadded:: 0.24\n\n Attributes\n ----------\n center_ : array of floats\n The median value for each feature in the training set.\n\n scale_ : array of floats\n The (scaled) interquartile range for each feature in the training set.\n\n .. versionadded:: 0.17\n *scale_* attribute.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> from sklearn.preprocessing import RobustScaler\n >>> X = [[ 1., -2., 2.],\n ... [ -2., 1., 3.],\n ... [ 4., 1., -2.]]\n >>> transformer = RobustScaler().fit(X)\n >>> transformer\n RobustScaler()\n >>> transformer.transform(X)\n array([[ 0. , -2. , 0. ],\n [-1. , 0. , 0.4],\n [ 1. , 0. , -1.6]])\n\n See Also\n --------\n robust_scale : Equivalent function without the estimator API.\n\n :class:`~sklearn.decomposition.PCA`\n Further removes the linear correlation across features with\n 'whiten=True'.\n\n Notes\n -----\n For a comparison of the different scalers, transformers, and normalizers,\n see :ref:`examples/preprocessing/plot_all_scaling.py\n `.\n\n https://en.wikipedia.org/wiki/Median\n https://en.wikipedia.org/wiki/Interquartile_range\n \"\"\"\n \n def __init__(self, *, with_centering=True, with_scaling=True, quantile_range=(25.0, 75.0), copy=True, unit_variance=False):\n self.with_centering = with_centering\n self.with_scaling = with_scaling\n self.quantile_range = quantile_range\n self.unit_variance = unit_variance\n self.copy = copy\n \n def fit(self, X, y=None):\n \"\"\"Compute the median and quantiles to be used for scaling.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The data used to compute the median and quantiles\n used for later scaling along the features axis.\n\n y : None\n Ignored.\n\n Returns\n -------\n self : object\n Fitted scaler.\n \"\"\"\n X = self._validate_data(X, accept_sparse='csc', estimator=self, dtype=FLOAT_DTYPES, force_all_finite='allow-nan')\n (q_min, q_max) = self.quantile_range\n if not 0 <= q_min <= q_max <= 100:\n raise ValueError('Invalid quantile range: %s' % str(self.quantile_range))\n if self.with_centering:\n if sparse.issparse(X):\n raise ValueError('Cannot center sparse matrices: use `with_centering=False` instead. See docstring for motivation and alternatives.')\n self.center_ = np.nanmedian(X, axis=0)\n else:\n self.center_ = None\n if self.with_scaling:\n quantiles = []\n for feature_idx in range(X.shape[1]):\n if sparse.issparse(X):\n column_nnz_data = X.data[X.indptr[feature_idx]:X.indptr[feature_idx + 1]]\n column_data = np.zeros(shape=X.shape[0], dtype=X.dtype)\n column_data[:len(column_nnz_data)] = column_nnz_data\n else:\n column_data = X[:, feature_idx]\n quantiles.append(np.nanpercentile(column_data, self.quantile_range))\n quantiles = np.transpose(quantiles)\n self.scale_ = quantiles[1] - quantiles[0]\n self.scale_ = _handle_zeros_in_scale(self.scale_, copy=False)\n if self.unit_variance:\n adjust = stats.norm.ppf(q_max / 100.0) - stats.norm.ppf(q_min / 100.0)\n self.scale_ = self.scale_ / adjust\n else:\n self.scale_ = None\n return self\n \n def transform(self, X):\n \"\"\"Center and scale the data.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The data used to scale along the specified axis.\n\n Returns\n -------\n X_tr : {ndarray, sparse matrix} of shape (n_samples, n_features)\n Transformed array.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse=('csr', 'csc'), copy=self.copy, estimator=self, dtype=FLOAT_DTYPES, reset=False, force_all_finite='allow-nan')\n if sparse.issparse(X):\n if self.with_scaling:\n inplace_column_scale(X, 1.0 / self.scale_)\n else:\n if self.with_centering:\n X -= self.center_\n if self.with_scaling:\n X /= self.scale_\n return X\n \n def inverse_transform(self, X):\n \"\"\"Scale back the data to the original representation.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The rescaled data to be transformed back.\n\n Returns\n -------\n X_tr : {ndarray, sparse matrix} of shape (n_samples, n_features)\n Transformed array.\n \"\"\"\n check_is_fitted(self)\n X = check_array(X, accept_sparse=('csr', 'csc'), copy=self.copy, estimator=self, dtype=FLOAT_DTYPES, force_all_finite='allow-nan')\n if sparse.issparse(X):\n if self.with_scaling:\n inplace_column_scale(X, self.scale_)\n else:\n if self.with_scaling:\n X *= self.scale_\n if self.with_centering:\n X += self.center_\n return X\n \n def _more_tags(self):\n return {'allow_nan': True}\n" + "description": "Scale features using statistics that are robust to outliers.\n\nThis Scaler removes the median and scales the data according to the quantile range (defaults to IQR: Interquartile Range). The IQR is the range between the 1st quartile (25th quantile) and the 3rd quartile (75th quantile). Centering and scaling happen independently on each feature by computing the relevant statistics on the samples in the training set. Median and interquartile range are then stored to be used on later data using the :meth:`transform` method. Standardization of a dataset is a common requirement for many machine learning estimators. Typically this is done by removing the mean and scaling to unit variance. However, outliers can often influence the sample mean / variance in a negative way. In such cases, the median and the interquartile range often give better results. .. versionadded:: 0.17 Read more in the :ref:`User Guide `.", + "docstring": "Scale features using statistics that are robust to outliers.\n\n This Scaler removes the median and scales the data according to\n the quantile range (defaults to IQR: Interquartile Range).\n The IQR is the range between the 1st quartile (25th quantile)\n and the 3rd quartile (75th quantile).\n\n Centering and scaling happen independently on each feature by\n computing the relevant statistics on the samples in the training\n set. Median and interquartile range are then stored to be used on\n later data using the :meth:`transform` method.\n\n Standardization of a dataset is a common requirement for many\n machine learning estimators. Typically this is done by removing the mean\n and scaling to unit variance. However, outliers can often influence the\n sample mean / variance in a negative way. In such cases, the median and\n the interquartile range often give better results.\n\n .. versionadded:: 0.17\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n with_centering : bool, default=True\n If `True`, center the data before scaling.\n This will cause :meth:`transform` to raise an exception when attempted\n on sparse matrices, because centering them entails building a dense\n matrix which in common use cases is likely to be too large to fit in\n memory.\n\n with_scaling : bool, default=True\n If `True`, scale the data to interquartile range.\n\n quantile_range : tuple (q_min, q_max), 0.0 < q_min < q_max < 100.0, default=(25.0, 75.0)\n Quantile range used to calculate `scale_`. By default this is equal to\n the IQR, i.e., `q_min` is the first quantile and `q_max` is the third\n quantile.\n\n .. versionadded:: 0.18\n\n copy : bool, default=True\n If `False`, try to avoid a copy and do inplace scaling instead.\n This is not guaranteed to always work inplace; e.g. if the data is\n not a NumPy array or scipy.sparse CSR matrix, a copy may still be\n returned.\n\n unit_variance : bool, default=False\n If `True`, scale data so that normally distributed features have a\n variance of 1. In general, if the difference between the x-values of\n `q_max` and `q_min` for a standard normal distribution is greater\n than 1, the dataset will be scaled down. If less than 1, the dataset\n will be scaled up.\n\n .. versionadded:: 0.24\n\n Attributes\n ----------\n center_ : array of floats\n The median value for each feature in the training set.\n\n scale_ : array of floats\n The (scaled) interquartile range for each feature in the training set.\n\n .. versionadded:: 0.17\n *scale_* attribute.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n robust_scale : Equivalent function without the estimator API.\n sklearn.decomposition.PCA : Further removes the linear correlation across\n features with 'whiten=True'.\n\n Notes\n -----\n For a comparison of the different scalers, transformers, and normalizers,\n see :ref:`examples/preprocessing/plot_all_scaling.py\n `.\n\n https://en.wikipedia.org/wiki/Median\n https://en.wikipedia.org/wiki/Interquartile_range\n\n Examples\n --------\n >>> from sklearn.preprocessing import RobustScaler\n >>> X = [[ 1., -2., 2.],\n ... [ -2., 1., 3.],\n ... [ 4., 1., -2.]]\n >>> transformer = RobustScaler().fit(X)\n >>> transformer\n RobustScaler()\n >>> transformer.transform(X)\n array([[ 0. , -2. , 0. ],\n [-1. , 0. , 0.4],\n [ 1. , 0. , -1.6]])\n ", + "source_code": "\n\nclass RobustScaler(_OneToOneFeatureMixin, TransformerMixin, BaseEstimator):\n \"\"\"Scale features using statistics that are robust to outliers.\n\n This Scaler removes the median and scales the data according to\n the quantile range (defaults to IQR: Interquartile Range).\n The IQR is the range between the 1st quartile (25th quantile)\n and the 3rd quartile (75th quantile).\n\n Centering and scaling happen independently on each feature by\n computing the relevant statistics on the samples in the training\n set. Median and interquartile range are then stored to be used on\n later data using the :meth:`transform` method.\n\n Standardization of a dataset is a common requirement for many\n machine learning estimators. Typically this is done by removing the mean\n and scaling to unit variance. However, outliers can often influence the\n sample mean / variance in a negative way. In such cases, the median and\n the interquartile range often give better results.\n\n .. versionadded:: 0.17\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n with_centering : bool, default=True\n If `True`, center the data before scaling.\n This will cause :meth:`transform` to raise an exception when attempted\n on sparse matrices, because centering them entails building a dense\n matrix which in common use cases is likely to be too large to fit in\n memory.\n\n with_scaling : bool, default=True\n If `True`, scale the data to interquartile range.\n\n quantile_range : tuple (q_min, q_max), 0.0 < q_min < q_max < 100.0, default=(25.0, 75.0)\n Quantile range used to calculate `scale_`. By default this is equal to\n the IQR, i.e., `q_min` is the first quantile and `q_max` is the third\n quantile.\n\n .. versionadded:: 0.18\n\n copy : bool, default=True\n If `False`, try to avoid a copy and do inplace scaling instead.\n This is not guaranteed to always work inplace; e.g. if the data is\n not a NumPy array or scipy.sparse CSR matrix, a copy may still be\n returned.\n\n unit_variance : bool, default=False\n If `True`, scale data so that normally distributed features have a\n variance of 1. In general, if the difference between the x-values of\n `q_max` and `q_min` for a standard normal distribution is greater\n than 1, the dataset will be scaled down. If less than 1, the dataset\n will be scaled up.\n\n .. versionadded:: 0.24\n\n Attributes\n ----------\n center_ : array of floats\n The median value for each feature in the training set.\n\n scale_ : array of floats\n The (scaled) interquartile range for each feature in the training set.\n\n .. versionadded:: 0.17\n *scale_* attribute.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n robust_scale : Equivalent function without the estimator API.\n sklearn.decomposition.PCA : Further removes the linear correlation across\n features with 'whiten=True'.\n\n Notes\n -----\n For a comparison of the different scalers, transformers, and normalizers,\n see :ref:`examples/preprocessing/plot_all_scaling.py\n `.\n\n https://en.wikipedia.org/wiki/Median\n https://en.wikipedia.org/wiki/Interquartile_range\n\n Examples\n --------\n >>> from sklearn.preprocessing import RobustScaler\n >>> X = [[ 1., -2., 2.],\n ... [ -2., 1., 3.],\n ... [ 4., 1., -2.]]\n >>> transformer = RobustScaler().fit(X)\n >>> transformer\n RobustScaler()\n >>> transformer.transform(X)\n array([[ 0. , -2. , 0. ],\n [-1. , 0. , 0.4],\n [ 1. , 0. , -1.6]])\n \"\"\"\n \n def __init__(self, *, with_centering=True, with_scaling=True, quantile_range=(25.0, 75.0), copy=True, unit_variance=False):\n self.with_centering = with_centering\n self.with_scaling = with_scaling\n self.quantile_range = quantile_range\n self.unit_variance = unit_variance\n self.copy = copy\n \n def fit(self, X, y=None):\n \"\"\"Compute the median and quantiles to be used for scaling.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The data used to compute the median and quantiles\n used for later scaling along the features axis.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self : object\n Fitted scaler.\n \"\"\"\n X = self._validate_data(X, accept_sparse='csc', estimator=self, dtype=FLOAT_DTYPES, force_all_finite='allow-nan')\n (q_min, q_max) = self.quantile_range\n if not 0 <= q_min <= q_max <= 100:\n raise ValueError('Invalid quantile range: %s' % str(self.quantile_range))\n if self.with_centering:\n if sparse.issparse(X):\n raise ValueError('Cannot center sparse matrices: use `with_centering=False` instead. See docstring for motivation and alternatives.')\n self.center_ = np.nanmedian(X, axis=0)\n else:\n self.center_ = None\n if self.with_scaling:\n quantiles = []\n for feature_idx in range(X.shape[1]):\n if sparse.issparse(X):\n column_nnz_data = X.data[X.indptr[feature_idx]:X.indptr[feature_idx + 1]]\n column_data = np.zeros(shape=X.shape[0], dtype=X.dtype)\n column_data[:len(column_nnz_data)] = column_nnz_data\n else:\n column_data = X[:, feature_idx]\n quantiles.append(np.nanpercentile(column_data, self.quantile_range))\n quantiles = np.transpose(quantiles)\n self.scale_ = quantiles[1] - quantiles[0]\n self.scale_ = _handle_zeros_in_scale(self.scale_, copy=False)\n if self.unit_variance:\n adjust = stats.norm.ppf(q_max / 100.0) - stats.norm.ppf(q_min / 100.0)\n self.scale_ = self.scale_ / adjust\n else:\n self.scale_ = None\n return self\n \n def transform(self, X):\n \"\"\"Center and scale the data.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The data used to scale along the specified axis.\n\n Returns\n -------\n X_tr : {ndarray, sparse matrix} of shape (n_samples, n_features)\n Transformed array.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse=('csr', 'csc'), copy=self.copy, estimator=self, dtype=FLOAT_DTYPES, reset=False, force_all_finite='allow-nan')\n if sparse.issparse(X):\n if self.with_scaling:\n inplace_column_scale(X, 1.0 / self.scale_)\n else:\n if self.with_centering:\n X -= self.center_\n if self.with_scaling:\n X /= self.scale_\n return X\n \n def inverse_transform(self, X):\n \"\"\"Scale back the data to the original representation.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The rescaled data to be transformed back.\n\n Returns\n -------\n X_tr : {ndarray, sparse matrix} of shape (n_samples, n_features)\n Transformed array.\n \"\"\"\n check_is_fitted(self)\n X = check_array(X, accept_sparse=('csr', 'csc'), copy=self.copy, estimator=self, dtype=FLOAT_DTYPES, force_all_finite='allow-nan')\n if sparse.issparse(X):\n if self.with_scaling:\n inplace_column_scale(X, self.scale_)\n else:\n if self.with_scaling:\n X *= self.scale_\n if self.with_centering:\n X += self.center_\n return X\n \n def _more_tags(self):\n return {'allow_nan': True}\n" }, { "name": "StandardScaler", @@ -26056,8 +26009,8 @@ ], "is_public": true, "description": "Bin continuous data into intervals.\n\nRead more in the :ref:`User Guide `. .. versionadded:: 0.20", - "docstring": "\n Bin continuous data into intervals.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.20\n\n Parameters\n ----------\n n_bins : int or array-like of shape (n_features,), default=5\n The number of bins to produce. Raises ValueError if ``n_bins < 2``.\n\n encode : {'onehot', 'onehot-dense', 'ordinal'}, default='onehot'\n Method used to encode the transformed result.\n\n onehot\n Encode the transformed result with one-hot encoding\n and return a sparse matrix. Ignored features are always\n stacked to the right.\n onehot-dense\n Encode the transformed result with one-hot encoding\n and return a dense array. Ignored features are always\n stacked to the right.\n ordinal\n Return the bin identifier encoded as an integer value.\n\n strategy : {'uniform', 'quantile', 'kmeans'}, default='quantile'\n Strategy used to define the widths of the bins.\n\n uniform\n All bins in each feature have identical widths.\n quantile\n All bins in each feature have the same number of points.\n kmeans\n Values in each bin have the same nearest center of a 1D k-means\n cluster.\n\n dtype : {np.float32, np.float64}, default=None\n The desired data-type for the output. If None, output dtype is\n consistent with input dtype. Only np.float32 and np.float64 are\n supported.\n\n .. versionadded:: 0.24\n\n Attributes\n ----------\n bin_edges_ : ndarray of ndarray of shape (n_features,)\n The edges of each bin. Contain arrays of varying shapes ``(n_bins_, )``\n Ignored features will have empty arrays.\n\n n_bins_ : ndarray of shape (n_features,), dtype=np.int_\n Number of bins per feature. Bins whose width are too small\n (i.e., <= 1e-8) are removed with a warning.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n Binarizer : Class used to bin values as ``0`` or\n ``1`` based on a parameter ``threshold``.\n\n Notes\n -----\n In bin edges for feature ``i``, the first and last values are used only for\n ``inverse_transform``. During transform, bin edges are extended to::\n\n np.concatenate([-np.inf, bin_edges_[i][1:-1], np.inf])\n\n You can combine ``KBinsDiscretizer`` with\n :class:`~sklearn.compose.ColumnTransformer` if you only want to preprocess\n part of the features.\n\n ``KBinsDiscretizer`` might produce constant features (e.g., when\n ``encode = 'onehot'`` and certain bins do not contain any data).\n These features can be removed with feature selection algorithms\n (e.g., :class:`~sklearn.feature_selection.VarianceThreshold`).\n\n Examples\n --------\n >>> X = [[-2, 1, -4, -1],\n ... [-1, 2, -3, -0.5],\n ... [ 0, 3, -2, 0.5],\n ... [ 1, 4, -1, 2]]\n >>> est = KBinsDiscretizer(n_bins=3, encode='ordinal', strategy='uniform')\n >>> est.fit(X)\n KBinsDiscretizer(...)\n >>> Xt = est.transform(X)\n >>> Xt # doctest: +SKIP\n array([[ 0., 0., 0., 0.],\n [ 1., 1., 1., 0.],\n [ 2., 2., 2., 1.],\n [ 2., 2., 2., 2.]])\n\n Sometimes it may be useful to convert the data back into the original\n feature space. The ``inverse_transform`` function converts the binned\n data into the original feature space. Each value will be equal to the mean\n of the two bin edges.\n\n >>> est.bin_edges_[0]\n array([-2., -1., 0., 1.])\n >>> est.inverse_transform(Xt)\n array([[-1.5, 1.5, -3.5, -0.5],\n [-0.5, 2.5, -2.5, -0.5],\n [ 0.5, 3.5, -1.5, 0.5],\n [ 0.5, 3.5, -1.5, 1.5]])\n ", - "source_code": "\n\nclass KBinsDiscretizer(TransformerMixin, BaseEstimator):\n \"\"\"\n Bin continuous data into intervals.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.20\n\n Parameters\n ----------\n n_bins : int or array-like of shape (n_features,), default=5\n The number of bins to produce. Raises ValueError if ``n_bins < 2``.\n\n encode : {'onehot', 'onehot-dense', 'ordinal'}, default='onehot'\n Method used to encode the transformed result.\n\n onehot\n Encode the transformed result with one-hot encoding\n and return a sparse matrix. Ignored features are always\n stacked to the right.\n onehot-dense\n Encode the transformed result with one-hot encoding\n and return a dense array. Ignored features are always\n stacked to the right.\n ordinal\n Return the bin identifier encoded as an integer value.\n\n strategy : {'uniform', 'quantile', 'kmeans'}, default='quantile'\n Strategy used to define the widths of the bins.\n\n uniform\n All bins in each feature have identical widths.\n quantile\n All bins in each feature have the same number of points.\n kmeans\n Values in each bin have the same nearest center of a 1D k-means\n cluster.\n\n dtype : {np.float32, np.float64}, default=None\n The desired data-type for the output. If None, output dtype is\n consistent with input dtype. Only np.float32 and np.float64 are\n supported.\n\n .. versionadded:: 0.24\n\n Attributes\n ----------\n bin_edges_ : ndarray of ndarray of shape (n_features,)\n The edges of each bin. Contain arrays of varying shapes ``(n_bins_, )``\n Ignored features will have empty arrays.\n\n n_bins_ : ndarray of shape (n_features,), dtype=np.int_\n Number of bins per feature. Bins whose width are too small\n (i.e., <= 1e-8) are removed with a warning.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n Binarizer : Class used to bin values as ``0`` or\n ``1`` based on a parameter ``threshold``.\n\n Notes\n -----\n In bin edges for feature ``i``, the first and last values are used only for\n ``inverse_transform``. During transform, bin edges are extended to::\n\n np.concatenate([-np.inf, bin_edges_[i][1:-1], np.inf])\n\n You can combine ``KBinsDiscretizer`` with\n :class:`~sklearn.compose.ColumnTransformer` if you only want to preprocess\n part of the features.\n\n ``KBinsDiscretizer`` might produce constant features (e.g., when\n ``encode = 'onehot'`` and certain bins do not contain any data).\n These features can be removed with feature selection algorithms\n (e.g., :class:`~sklearn.feature_selection.VarianceThreshold`).\n\n Examples\n --------\n >>> X = [[-2, 1, -4, -1],\n ... [-1, 2, -3, -0.5],\n ... [ 0, 3, -2, 0.5],\n ... [ 1, 4, -1, 2]]\n >>> est = KBinsDiscretizer(n_bins=3, encode='ordinal', strategy='uniform')\n >>> est.fit(X)\n KBinsDiscretizer(...)\n >>> Xt = est.transform(X)\n >>> Xt # doctest: +SKIP\n array([[ 0., 0., 0., 0.],\n [ 1., 1., 1., 0.],\n [ 2., 2., 2., 1.],\n [ 2., 2., 2., 2.]])\n\n Sometimes it may be useful to convert the data back into the original\n feature space. The ``inverse_transform`` function converts the binned\n data into the original feature space. Each value will be equal to the mean\n of the two bin edges.\n\n >>> est.bin_edges_[0]\n array([-2., -1., 0., 1.])\n >>> est.inverse_transform(Xt)\n array([[-1.5, 1.5, -3.5, -0.5],\n [-0.5, 2.5, -2.5, -0.5],\n [ 0.5, 3.5, -1.5, 0.5],\n [ 0.5, 3.5, -1.5, 1.5]])\n \"\"\"\n \n def __init__(self, n_bins=5, *, encode='onehot', strategy='quantile', dtype=None):\n self.n_bins = n_bins\n self.encode = encode\n self.strategy = strategy\n self.dtype = dtype\n \n def fit(self, X, y=None):\n \"\"\"\n Fit the estimator.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Data to be discretized.\n\n y : None\n Ignored. This parameter exists only for compatibility with\n :class:`~sklearn.pipeline.Pipeline`.\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n X = self._validate_data(X, dtype='numeric')\n supported_dtype = (np.float64, np.float32)\n if self.dtype in supported_dtype:\n output_dtype = self.dtype\n elif self.dtype is None:\n output_dtype = X.dtype\n else:\n raise ValueError(f\"Valid options for 'dtype' are {supported_dtype + (None, )}. Got dtype={self.dtype} instead.\")\n valid_encode = ('onehot', 'onehot-dense', 'ordinal')\n if self.encode not in valid_encode:\n raise ValueError(\"Valid options for 'encode' are {}. Got encode={!r} instead.\".format(valid_encode, self.encode))\n valid_strategy = ('uniform', 'quantile', 'kmeans')\n if self.strategy not in valid_strategy:\n raise ValueError(\"Valid options for 'strategy' are {}. Got strategy={!r} instead.\".format(valid_strategy, self.strategy))\n n_features = X.shape[1]\n n_bins = self._validate_n_bins(n_features)\n bin_edges = np.zeros(n_features, dtype=object)\n for jj in range(n_features):\n column = X[:, jj]\n (col_min, col_max) = (column.min(), column.max())\n if col_min == col_max:\n warnings.warn('Feature %d is constant and will be replaced with 0.' % jj)\n n_bins[jj] = 1\n bin_edges[jj] = np.array([-np.inf, np.inf])\n continue\n if self.strategy == 'uniform':\n bin_edges[jj] = np.linspace(col_min, col_max, n_bins[jj] + 1)\n elif self.strategy == 'quantile':\n quantiles = np.linspace(0, 100, n_bins[jj] + 1)\n bin_edges[jj] = np.asarray(np.percentile(column, quantiles))\n elif self.strategy == 'kmeans':\n from ..cluster import KMeans\n uniform_edges = np.linspace(col_min, col_max, n_bins[jj] + 1)\n init = (uniform_edges[1:] + uniform_edges[:-1])[:, None] * 0.5\n km = KMeans(n_clusters=n_bins[jj], init=init, n_init=1, algorithm='full')\n centers = km.fit(column[:, None]).cluster_centers_[:, 0]\n centers.sort()\n bin_edges[jj] = (centers[1:] + centers[:-1]) * 0.5\n bin_edges[jj] = np.r_[col_min, bin_edges[jj], col_max]\n if self.strategy in ('quantile', 'kmeans'):\n mask = np.ediff1d(bin_edges[jj], to_begin=np.inf) > 1e-08\n bin_edges[jj] = bin_edges[jj][mask]\n if len(bin_edges[jj]) - 1 != n_bins[jj]:\n warnings.warn('Bins whose width are too small (i.e., <= 1e-8) in feature %d are removed. Consider decreasing the number of bins.' % jj)\n n_bins[jj] = len(bin_edges[jj]) - 1\n self.bin_edges_ = bin_edges\n self.n_bins_ = n_bins\n if 'onehot' in self.encode:\n self._encoder = OneHotEncoder(categories=[np.arange(i) for i in self.n_bins_], sparse=self.encode == 'onehot', dtype=output_dtype)\n self._encoder.fit(np.zeros((1, len(self.n_bins_))))\n return self\n \n def _validate_n_bins(self, n_features):\n \"\"\"Returns n_bins_, the number of bins per feature.\"\"\"\n orig_bins = self.n_bins\n if isinstance(orig_bins, numbers.Number):\n if not isinstance(orig_bins, numbers.Integral):\n raise ValueError('{} received an invalid n_bins type. Received {}, expected int.'.format(KBinsDiscretizer.__name__, type(orig_bins).__name__))\n if orig_bins < 2:\n raise ValueError('{} received an invalid number of bins. Received {}, expected at least 2.'.format(KBinsDiscretizer.__name__, orig_bins))\n return np.full(n_features, orig_bins, dtype=int)\n n_bins = check_array(orig_bins, dtype=int, copy=True, ensure_2d=False)\n if n_bins.ndim > 1 or n_bins.shape[0] != n_features:\n raise ValueError('n_bins must be a scalar or array of shape (n_features,).')\n bad_nbins_value = (n_bins < 2) | (n_bins != orig_bins)\n violating_indices = np.where(bad_nbins_value)[0]\n if violating_indices.shape[0] > 0:\n indices = ', '.join((str(i) for i in violating_indices))\n raise ValueError('{} received an invalid number of bins at indices {}. Number of bins must be at least 2, and must be an int.'.format(KBinsDiscretizer.__name__, indices))\n return n_bins\n \n def transform(self, X):\n \"\"\"\n Discretize the data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Data to be discretized.\n\n Returns\n -------\n Xt : {ndarray, sparse matrix}, dtype={np.float32, np.float64}\n Data in the binned space. Will be a sparse matrix if\n `self.encode='onehot'` and ndarray otherwise.\n \"\"\"\n check_is_fitted(self)\n dtype = (np.float64, np.float32) if self.dtype is None else self.dtype\n Xt = self._validate_data(X, copy=True, dtype=dtype, reset=False)\n bin_edges = self.bin_edges_\n for jj in range(Xt.shape[1]):\n rtol = 1e-05\n atol = 1e-08\n eps = atol + rtol * np.abs(Xt[:, jj])\n Xt[:, jj] = np.digitize(Xt[:, jj] + eps, bin_edges[jj][1:])\n np.clip(Xt, 0, self.n_bins_ - 1, out=Xt)\n if self.encode == 'ordinal':\n return Xt\n dtype_init = None\n if 'onehot' in self.encode:\n dtype_init = self._encoder.dtype\n self._encoder.dtype = Xt.dtype\n try:\n Xt_enc = self._encoder.transform(Xt)\n finally:\n self._encoder.dtype = dtype_init\n return Xt_enc\n \n def inverse_transform(self, Xt):\n \"\"\"\n Transform discretized data back to original feature space.\n\n Note that this function does not regenerate the original data\n due to discretization rounding.\n\n Parameters\n ----------\n Xt : array-like of shape (n_samples, n_features)\n Transformed data in the binned space.\n\n Returns\n -------\n Xinv : ndarray, dtype={np.float32, np.float64}\n Data in the original feature space.\n \"\"\"\n check_is_fitted(self)\n if 'onehot' in self.encode:\n Xt = self._encoder.inverse_transform(Xt)\n Xinv = check_array(Xt, copy=True, dtype=(np.float64, np.float32))\n n_features = self.n_bins_.shape[0]\n if Xinv.shape[1] != n_features:\n raise ValueError('Incorrect number of features. Expecting {}, received {}.'.format(n_features, Xinv.shape[1]))\n for jj in range(n_features):\n bin_edges = self.bin_edges_[jj]\n bin_centers = (bin_edges[1:] + bin_edges[:-1]) * 0.5\n Xinv[:, jj] = bin_centers[np.int_(Xinv[:, jj])]\n return Xinv\n \n def get_feature_names_out(self, input_features=None):\n \"\"\"Get output feature names.\n\n Parameters\n ----------\n input_features : array-like of str or None, default=None\n Input features.\n\n - If `input_features` is `None`, then `feature_names_in_` is\n used as feature names in. If `feature_names_in_` is not defined,\n then names are generated: `[x0, x1, ..., x(n_features_in_)]`.\n - If `input_features` is an array-like, then `input_features` must\n match `feature_names_in_` if `feature_names_in_` is defined.\n\n Returns\n -------\n feature_names_out : ndarray of str objects\n Transformed feature names.\n \"\"\"\n input_features = _check_feature_names_in(self, input_features)\n return self._encoder.get_feature_names_out(input_features)\n" + "docstring": "\n Bin continuous data into intervals.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.20\n\n Parameters\n ----------\n n_bins : int or array-like of shape (n_features,), default=5\n The number of bins to produce. Raises ValueError if ``n_bins < 2``.\n\n encode : {'onehot', 'onehot-dense', 'ordinal'}, default='onehot'\n Method used to encode the transformed result.\n\n onehot\n Encode the transformed result with one-hot encoding\n and return a sparse matrix. Ignored features are always\n stacked to the right.\n onehot-dense\n Encode the transformed result with one-hot encoding\n and return a dense array. Ignored features are always\n stacked to the right.\n ordinal\n Return the bin identifier encoded as an integer value.\n\n strategy : {'uniform', 'quantile', 'kmeans'}, default='quantile'\n Strategy used to define the widths of the bins.\n\n uniform\n All bins in each feature have identical widths.\n quantile\n All bins in each feature have the same number of points.\n kmeans\n Values in each bin have the same nearest center of a 1D k-means\n cluster.\n\n dtype : {np.float32, np.float64}, default=None\n The desired data-type for the output. If None, output dtype is\n consistent with input dtype. Only np.float32 and np.float64 are\n supported.\n\n .. versionadded:: 0.24\n\n Attributes\n ----------\n bin_edges_ : ndarray of ndarray of shape (n_features,)\n The edges of each bin. Contain arrays of varying shapes ``(n_bins_, )``\n Ignored features will have empty arrays.\n\n n_bins_ : ndarray of shape (n_features,), dtype=np.int_\n Number of bins per feature. Bins whose width are too small\n (i.e., <= 1e-8) are removed with a warning.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n Binarizer : Class used to bin values as ``0`` or\n ``1`` based on a parameter ``threshold``.\n\n Notes\n -----\n In bin edges for feature ``i``, the first and last values are used only for\n ``inverse_transform``. During transform, bin edges are extended to::\n\n np.concatenate([-np.inf, bin_edges_[i][1:-1], np.inf])\n\n You can combine ``KBinsDiscretizer`` with\n :class:`~sklearn.compose.ColumnTransformer` if you only want to preprocess\n part of the features.\n\n ``KBinsDiscretizer`` might produce constant features (e.g., when\n ``encode = 'onehot'`` and certain bins do not contain any data).\n These features can be removed with feature selection algorithms\n (e.g., :class:`~sklearn.feature_selection.VarianceThreshold`).\n\n Examples\n --------\n >>> from sklearn.preprocessing import KBinsDiscretizer\n >>> X = [[-2, 1, -4, -1],\n ... [-1, 2, -3, -0.5],\n ... [ 0, 3, -2, 0.5],\n ... [ 1, 4, -1, 2]]\n >>> est = KBinsDiscretizer(n_bins=3, encode='ordinal', strategy='uniform')\n >>> est.fit(X)\n KBinsDiscretizer(...)\n >>> Xt = est.transform(X)\n >>> Xt # doctest: +SKIP\n array([[ 0., 0., 0., 0.],\n [ 1., 1., 1., 0.],\n [ 2., 2., 2., 1.],\n [ 2., 2., 2., 2.]])\n\n Sometimes it may be useful to convert the data back into the original\n feature space. The ``inverse_transform`` function converts the binned\n data into the original feature space. Each value will be equal to the mean\n of the two bin edges.\n\n >>> est.bin_edges_[0]\n array([-2., -1., 0., 1.])\n >>> est.inverse_transform(Xt)\n array([[-1.5, 1.5, -3.5, -0.5],\n [-0.5, 2.5, -2.5, -0.5],\n [ 0.5, 3.5, -1.5, 0.5],\n [ 0.5, 3.5, -1.5, 1.5]])\n ", + "source_code": "\n\nclass KBinsDiscretizer(TransformerMixin, BaseEstimator):\n \"\"\"\n Bin continuous data into intervals.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.20\n\n Parameters\n ----------\n n_bins : int or array-like of shape (n_features,), default=5\n The number of bins to produce. Raises ValueError if ``n_bins < 2``.\n\n encode : {'onehot', 'onehot-dense', 'ordinal'}, default='onehot'\n Method used to encode the transformed result.\n\n onehot\n Encode the transformed result with one-hot encoding\n and return a sparse matrix. Ignored features are always\n stacked to the right.\n onehot-dense\n Encode the transformed result with one-hot encoding\n and return a dense array. Ignored features are always\n stacked to the right.\n ordinal\n Return the bin identifier encoded as an integer value.\n\n strategy : {'uniform', 'quantile', 'kmeans'}, default='quantile'\n Strategy used to define the widths of the bins.\n\n uniform\n All bins in each feature have identical widths.\n quantile\n All bins in each feature have the same number of points.\n kmeans\n Values in each bin have the same nearest center of a 1D k-means\n cluster.\n\n dtype : {np.float32, np.float64}, default=None\n The desired data-type for the output. If None, output dtype is\n consistent with input dtype. Only np.float32 and np.float64 are\n supported.\n\n .. versionadded:: 0.24\n\n Attributes\n ----------\n bin_edges_ : ndarray of ndarray of shape (n_features,)\n The edges of each bin. Contain arrays of varying shapes ``(n_bins_, )``\n Ignored features will have empty arrays.\n\n n_bins_ : ndarray of shape (n_features,), dtype=np.int_\n Number of bins per feature. Bins whose width are too small\n (i.e., <= 1e-8) are removed with a warning.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n Binarizer : Class used to bin values as ``0`` or\n ``1`` based on a parameter ``threshold``.\n\n Notes\n -----\n In bin edges for feature ``i``, the first and last values are used only for\n ``inverse_transform``. During transform, bin edges are extended to::\n\n np.concatenate([-np.inf, bin_edges_[i][1:-1], np.inf])\n\n You can combine ``KBinsDiscretizer`` with\n :class:`~sklearn.compose.ColumnTransformer` if you only want to preprocess\n part of the features.\n\n ``KBinsDiscretizer`` might produce constant features (e.g., when\n ``encode = 'onehot'`` and certain bins do not contain any data).\n These features can be removed with feature selection algorithms\n (e.g., :class:`~sklearn.feature_selection.VarianceThreshold`).\n\n Examples\n --------\n >>> from sklearn.preprocessing import KBinsDiscretizer\n >>> X = [[-2, 1, -4, -1],\n ... [-1, 2, -3, -0.5],\n ... [ 0, 3, -2, 0.5],\n ... [ 1, 4, -1, 2]]\n >>> est = KBinsDiscretizer(n_bins=3, encode='ordinal', strategy='uniform')\n >>> est.fit(X)\n KBinsDiscretizer(...)\n >>> Xt = est.transform(X)\n >>> Xt # doctest: +SKIP\n array([[ 0., 0., 0., 0.],\n [ 1., 1., 1., 0.],\n [ 2., 2., 2., 1.],\n [ 2., 2., 2., 2.]])\n\n Sometimes it may be useful to convert the data back into the original\n feature space. The ``inverse_transform`` function converts the binned\n data into the original feature space. Each value will be equal to the mean\n of the two bin edges.\n\n >>> est.bin_edges_[0]\n array([-2., -1., 0., 1.])\n >>> est.inverse_transform(Xt)\n array([[-1.5, 1.5, -3.5, -0.5],\n [-0.5, 2.5, -2.5, -0.5],\n [ 0.5, 3.5, -1.5, 0.5],\n [ 0.5, 3.5, -1.5, 1.5]])\n \"\"\"\n \n def __init__(self, n_bins=5, *, encode='onehot', strategy='quantile', dtype=None):\n self.n_bins = n_bins\n self.encode = encode\n self.strategy = strategy\n self.dtype = dtype\n \n def fit(self, X, y=None):\n \"\"\"\n Fit the estimator.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Data to be discretized.\n\n y : None\n Ignored. This parameter exists only for compatibility with\n :class:`~sklearn.pipeline.Pipeline`.\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n X = self._validate_data(X, dtype='numeric')\n supported_dtype = (np.float64, np.float32)\n if self.dtype in supported_dtype:\n output_dtype = self.dtype\n elif self.dtype is None:\n output_dtype = X.dtype\n else:\n raise ValueError(f\"Valid options for 'dtype' are {supported_dtype + (None, )}. Got dtype={self.dtype} instead.\")\n valid_encode = ('onehot', 'onehot-dense', 'ordinal')\n if self.encode not in valid_encode:\n raise ValueError(\"Valid options for 'encode' are {}. Got encode={!r} instead.\".format(valid_encode, self.encode))\n valid_strategy = ('uniform', 'quantile', 'kmeans')\n if self.strategy not in valid_strategy:\n raise ValueError(\"Valid options for 'strategy' are {}. Got strategy={!r} instead.\".format(valid_strategy, self.strategy))\n n_features = X.shape[1]\n n_bins = self._validate_n_bins(n_features)\n bin_edges = np.zeros(n_features, dtype=object)\n for jj in range(n_features):\n column = X[:, jj]\n (col_min, col_max) = (column.min(), column.max())\n if col_min == col_max:\n warnings.warn('Feature %d is constant and will be replaced with 0.' % jj)\n n_bins[jj] = 1\n bin_edges[jj] = np.array([-np.inf, np.inf])\n continue\n if self.strategy == 'uniform':\n bin_edges[jj] = np.linspace(col_min, col_max, n_bins[jj] + 1)\n elif self.strategy == 'quantile':\n quantiles = np.linspace(0, 100, n_bins[jj] + 1)\n bin_edges[jj] = np.asarray(np.percentile(column, quantiles))\n elif self.strategy == 'kmeans':\n from ..cluster import KMeans\n uniform_edges = np.linspace(col_min, col_max, n_bins[jj] + 1)\n init = (uniform_edges[1:] + uniform_edges[:-1])[:, None] * 0.5\n km = KMeans(n_clusters=n_bins[jj], init=init, n_init=1, algorithm='full')\n centers = km.fit(column[:, None]).cluster_centers_[:, 0]\n centers.sort()\n bin_edges[jj] = (centers[1:] + centers[:-1]) * 0.5\n bin_edges[jj] = np.r_[col_min, bin_edges[jj], col_max]\n if self.strategy in ('quantile', 'kmeans'):\n mask = np.ediff1d(bin_edges[jj], to_begin=np.inf) > 1e-08\n bin_edges[jj] = bin_edges[jj][mask]\n if len(bin_edges[jj]) - 1 != n_bins[jj]:\n warnings.warn('Bins whose width are too small (i.e., <= 1e-8) in feature %d are removed. Consider decreasing the number of bins.' % jj)\n n_bins[jj] = len(bin_edges[jj]) - 1\n self.bin_edges_ = bin_edges\n self.n_bins_ = n_bins\n if 'onehot' in self.encode:\n self._encoder = OneHotEncoder(categories=[np.arange(i) for i in self.n_bins_], sparse=self.encode == 'onehot', dtype=output_dtype)\n self._encoder.fit(np.zeros((1, len(self.n_bins_))))\n return self\n \n def _validate_n_bins(self, n_features):\n \"\"\"Returns n_bins_, the number of bins per feature.\"\"\"\n orig_bins = self.n_bins\n if isinstance(orig_bins, numbers.Number):\n if not isinstance(orig_bins, numbers.Integral):\n raise ValueError('{} received an invalid n_bins type. Received {}, expected int.'.format(KBinsDiscretizer.__name__, type(orig_bins).__name__))\n if orig_bins < 2:\n raise ValueError('{} received an invalid number of bins. Received {}, expected at least 2.'.format(KBinsDiscretizer.__name__, orig_bins))\n return np.full(n_features, orig_bins, dtype=int)\n n_bins = check_array(orig_bins, dtype=int, copy=True, ensure_2d=False)\n if n_bins.ndim > 1 or n_bins.shape[0] != n_features:\n raise ValueError('n_bins must be a scalar or array of shape (n_features,).')\n bad_nbins_value = (n_bins < 2) | (n_bins != orig_bins)\n violating_indices = np.where(bad_nbins_value)[0]\n if violating_indices.shape[0] > 0:\n indices = ', '.join((str(i) for i in violating_indices))\n raise ValueError('{} received an invalid number of bins at indices {}. Number of bins must be at least 2, and must be an int.'.format(KBinsDiscretizer.__name__, indices))\n return n_bins\n \n def transform(self, X):\n \"\"\"\n Discretize the data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Data to be discretized.\n\n Returns\n -------\n Xt : {ndarray, sparse matrix}, dtype={np.float32, np.float64}\n Data in the binned space. Will be a sparse matrix if\n `self.encode='onehot'` and ndarray otherwise.\n \"\"\"\n check_is_fitted(self)\n dtype = (np.float64, np.float32) if self.dtype is None else self.dtype\n Xt = self._validate_data(X, copy=True, dtype=dtype, reset=False)\n bin_edges = self.bin_edges_\n for jj in range(Xt.shape[1]):\n rtol = 1e-05\n atol = 1e-08\n eps = atol + rtol * np.abs(Xt[:, jj])\n Xt[:, jj] = np.digitize(Xt[:, jj] + eps, bin_edges[jj][1:])\n np.clip(Xt, 0, self.n_bins_ - 1, out=Xt)\n if self.encode == 'ordinal':\n return Xt\n dtype_init = None\n if 'onehot' in self.encode:\n dtype_init = self._encoder.dtype\n self._encoder.dtype = Xt.dtype\n try:\n Xt_enc = self._encoder.transform(Xt)\n finally:\n self._encoder.dtype = dtype_init\n return Xt_enc\n \n def inverse_transform(self, Xt):\n \"\"\"\n Transform discretized data back to original feature space.\n\n Note that this function does not regenerate the original data\n due to discretization rounding.\n\n Parameters\n ----------\n Xt : array-like of shape (n_samples, n_features)\n Transformed data in the binned space.\n\n Returns\n -------\n Xinv : ndarray, dtype={np.float32, np.float64}\n Data in the original feature space.\n \"\"\"\n check_is_fitted(self)\n if 'onehot' in self.encode:\n Xt = self._encoder.inverse_transform(Xt)\n Xinv = check_array(Xt, copy=True, dtype=(np.float64, np.float32))\n n_features = self.n_bins_.shape[0]\n if Xinv.shape[1] != n_features:\n raise ValueError('Incorrect number of features. Expecting {}, received {}.'.format(n_features, Xinv.shape[1]))\n for jj in range(n_features):\n bin_edges = self.bin_edges_[jj]\n bin_centers = (bin_edges[1:] + bin_edges[:-1]) * 0.5\n Xinv[:, jj] = bin_centers[np.int_(Xinv[:, jj])]\n return Xinv\n \n def get_feature_names_out(self, input_features=None):\n \"\"\"Get output feature names.\n\n Parameters\n ----------\n input_features : array-like of str or None, default=None\n Input features.\n\n - If `input_features` is `None`, then `feature_names_in_` is\n used as feature names in. If `feature_names_in_` is not defined,\n then names are generated: `[x0, x1, ..., x(n_features_in_)]`.\n - If `input_features` is an array-like, then `input_features` must\n match `feature_names_in_` if `feature_names_in_` is defined.\n\n Returns\n -------\n feature_names_out : ndarray of str objects\n Transformed feature names.\n \"\"\"\n input_features = _check_feature_names_in(self, input_features)\n return self._encoder.get_feature_names_out(input_features)\n" }, { "name": "OneHotEncoder", @@ -26078,7 +26031,7 @@ "is_public": true, "description": "Encode categorical features as a one-hot numeric array.\n\nThe input to this transformer should be an array-like of integers or strings, denoting the values taken on by categorical (discrete) features. The features are encoded using a one-hot (aka 'one-of-K' or 'dummy') encoding scheme. This creates a binary column for each category and returns a sparse matrix or dense array (depending on the ``sparse`` parameter) By default, the encoder derives the categories based on the unique values in each feature. Alternatively, you can also specify the `categories` manually. This encoding is needed for feeding categorical data to many scikit-learn estimators, notably linear models and SVMs with the standard kernels. Note: a one-hot encoding of y labels should use a LabelBinarizer instead. Read more in the :ref:`User Guide `.", "docstring": "\n Encode categorical features as a one-hot numeric array.\n\n The input to this transformer should be an array-like of integers or\n strings, denoting the values taken on by categorical (discrete) features.\n The features are encoded using a one-hot (aka 'one-of-K' or 'dummy')\n encoding scheme. This creates a binary column for each category and\n returns a sparse matrix or dense array (depending on the ``sparse``\n parameter)\n\n By default, the encoder derives the categories based on the unique values\n in each feature. Alternatively, you can also specify the `categories`\n manually.\n\n This encoding is needed for feeding categorical data to many scikit-learn\n estimators, notably linear models and SVMs with the standard kernels.\n\n Note: a one-hot encoding of y labels should use a LabelBinarizer\n instead.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n categories : 'auto' or a list of array-like, default='auto'\n Categories (unique values) per feature:\n\n - 'auto' : Determine categories automatically from the training data.\n - list : ``categories[i]`` holds the categories expected in the ith\n column. The passed categories should not mix strings and numeric\n values within a single feature, and should be sorted in case of\n numeric values.\n\n The used categories can be found in the ``categories_`` attribute.\n\n .. versionadded:: 0.20\n\n drop : {'first', 'if_binary'} or a array-like of shape (n_features,), default=None\n Specifies a methodology to use to drop one of the categories per\n feature. This is useful in situations where perfectly collinear\n features cause problems, such as when feeding the resulting data\n into a neural network or an unregularized regression.\n\n However, dropping one category breaks the symmetry of the original\n representation and can therefore induce a bias in downstream models,\n for instance for penalized linear classification or regression models.\n\n - None : retain all features (the default).\n - 'first' : drop the first category in each feature. If only one\n category is present, the feature will be dropped entirely.\n - 'if_binary' : drop the first category in each feature with two\n categories. Features with 1 or more than 2 categories are\n left intact.\n - array : ``drop[i]`` is the category in feature ``X[:, i]`` that\n should be dropped.\n\n .. versionadded:: 0.21\n The parameter `drop` was added in 0.21.\n\n .. versionchanged:: 0.23\n The option `drop='if_binary'` was added in 0.23.\n\n sparse : bool, default=True\n Will return sparse matrix if set True else will return an array.\n\n dtype : number type, default=float\n Desired dtype of output.\n\n handle_unknown : {'error', 'ignore'}, default='error'\n Whether to raise an error or ignore if an unknown categorical feature\n is present during transform (default is to raise). When this parameter\n is set to 'ignore' and an unknown category is encountered during\n transform, the resulting one-hot encoded columns for this feature\n will be all zeros. In the inverse transform, an unknown category\n will be denoted as None.\n\n Attributes\n ----------\n categories_ : list of arrays\n The categories of each feature determined during fitting\n (in order of the features in X and corresponding with the output\n of ``transform``). This includes the category specified in ``drop``\n (if any).\n\n drop_idx_ : array of shape (n_features,)\n - ``drop_idx_[i]`` is\u00a0the index in ``categories_[i]`` of the category\n to be dropped for each feature.\n - ``drop_idx_[i] = None`` if no category is to be dropped from the\n feature with index ``i``, e.g. when `drop='if_binary'` and the\n feature isn't binary.\n - ``drop_idx_ = None`` if all the transformed features will be\n retained.\n\n .. versionchanged:: 0.23\n Added the possibility to contain `None` values.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 1.0\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n OrdinalEncoder : Performs an ordinal (integer)\n encoding of the categorical features.\n sklearn.feature_extraction.DictVectorizer : Performs a one-hot encoding of\n dictionary items (also handles string-valued features).\n sklearn.feature_extraction.FeatureHasher : Performs an approximate one-hot\n encoding of dictionary items or strings.\n LabelBinarizer : Binarizes labels in a one-vs-all\n fashion.\n MultiLabelBinarizer : Transforms between iterable of\n iterables and a multilabel format, e.g. a (samples x classes) binary\n matrix indicating the presence of a class label.\n\n Examples\n --------\n Given a dataset with two features, we let the encoder find the unique\n values per feature and transform the data to a binary one-hot encoding.\n\n >>> from sklearn.preprocessing import OneHotEncoder\n\n One can discard categories not seen during `fit`:\n\n >>> enc = OneHotEncoder(handle_unknown='ignore')\n >>> X = [['Male', 1], ['Female', 3], ['Female', 2]]\n >>> enc.fit(X)\n OneHotEncoder(handle_unknown='ignore')\n >>> enc.categories_\n [array(['Female', 'Male'], dtype=object), array([1, 2, 3], dtype=object)]\n >>> enc.transform([['Female', 1], ['Male', 4]]).toarray()\n array([[1., 0., 1., 0., 0.],\n [0., 1., 0., 0., 0.]])\n >>> enc.inverse_transform([[0, 1, 1, 0, 0], [0, 0, 0, 1, 0]])\n array([['Male', 1],\n [None, 2]], dtype=object)\n >>> enc.get_feature_names_out(['gender', 'group'])\n array(['gender_Female', 'gender_Male', 'group_1', 'group_2', 'group_3'], ...)\n\n One can always drop the first column for each feature:\n\n >>> drop_enc = OneHotEncoder(drop='first').fit(X)\n >>> drop_enc.categories_\n [array(['Female', 'Male'], dtype=object), array([1, 2, 3], dtype=object)]\n >>> drop_enc.transform([['Female', 1], ['Male', 2]]).toarray()\n array([[0., 0., 0.],\n [1., 1., 0.]])\n\n Or drop a column for feature only having 2 categories:\n\n >>> drop_binary_enc = OneHotEncoder(drop='if_binary').fit(X)\n >>> drop_binary_enc.transform([['Female', 1], ['Male', 2]]).toarray()\n array([[0., 1., 0., 0.],\n [1., 0., 1., 0.]])\n ", - "source_code": "\n\nclass OneHotEncoder(_BaseEncoder):\n \"\"\"\n Encode categorical features as a one-hot numeric array.\n\n The input to this transformer should be an array-like of integers or\n strings, denoting the values taken on by categorical (discrete) features.\n The features are encoded using a one-hot (aka 'one-of-K' or 'dummy')\n encoding scheme. This creates a binary column for each category and\n returns a sparse matrix or dense array (depending on the ``sparse``\n parameter)\n\n By default, the encoder derives the categories based on the unique values\n in each feature. Alternatively, you can also specify the `categories`\n manually.\n\n This encoding is needed for feeding categorical data to many scikit-learn\n estimators, notably linear models and SVMs with the standard kernels.\n\n Note: a one-hot encoding of y labels should use a LabelBinarizer\n instead.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n categories : 'auto' or a list of array-like, default='auto'\n Categories (unique values) per feature:\n\n - 'auto' : Determine categories automatically from the training data.\n - list : ``categories[i]`` holds the categories expected in the ith\n column. The passed categories should not mix strings and numeric\n values within a single feature, and should be sorted in case of\n numeric values.\n\n The used categories can be found in the ``categories_`` attribute.\n\n .. versionadded:: 0.20\n\n drop : {'first', 'if_binary'} or a array-like of shape (n_features,), default=None\n Specifies a methodology to use to drop one of the categories per\n feature. This is useful in situations where perfectly collinear\n features cause problems, such as when feeding the resulting data\n into a neural network or an unregularized regression.\n\n However, dropping one category breaks the symmetry of the original\n representation and can therefore induce a bias in downstream models,\n for instance for penalized linear classification or regression models.\n\n - None : retain all features (the default).\n - 'first' : drop the first category in each feature. If only one\n category is present, the feature will be dropped entirely.\n - 'if_binary' : drop the first category in each feature with two\n categories. Features with 1 or more than 2 categories are\n left intact.\n - array : ``drop[i]`` is the category in feature ``X[:, i]`` that\n should be dropped.\n\n .. versionadded:: 0.21\n The parameter `drop` was added in 0.21.\n\n .. versionchanged:: 0.23\n The option `drop='if_binary'` was added in 0.23.\n\n sparse : bool, default=True\n Will return sparse matrix if set True else will return an array.\n\n dtype : number type, default=float\n Desired dtype of output.\n\n handle_unknown : {'error', 'ignore'}, default='error'\n Whether to raise an error or ignore if an unknown categorical feature\n is present during transform (default is to raise). When this parameter\n is set to 'ignore' and an unknown category is encountered during\n transform, the resulting one-hot encoded columns for this feature\n will be all zeros. In the inverse transform, an unknown category\n will be denoted as None.\n\n Attributes\n ----------\n categories_ : list of arrays\n The categories of each feature determined during fitting\n (in order of the features in X and corresponding with the output\n of ``transform``). This includes the category specified in ``drop``\n (if any).\n\n drop_idx_ : array of shape (n_features,)\n - ``drop_idx_[i]`` is\u00a0the index in ``categories_[i]`` of the category\n to be dropped for each feature.\n - ``drop_idx_[i] = None`` if no category is to be dropped from the\n feature with index ``i``, e.g. when `drop='if_binary'` and the\n feature isn't binary.\n - ``drop_idx_ = None`` if all the transformed features will be\n retained.\n\n .. versionchanged:: 0.23\n Added the possibility to contain `None` values.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 1.0\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n OrdinalEncoder : Performs an ordinal (integer)\n encoding of the categorical features.\n sklearn.feature_extraction.DictVectorizer : Performs a one-hot encoding of\n dictionary items (also handles string-valued features).\n sklearn.feature_extraction.FeatureHasher : Performs an approximate one-hot\n encoding of dictionary items or strings.\n LabelBinarizer : Binarizes labels in a one-vs-all\n fashion.\n MultiLabelBinarizer : Transforms between iterable of\n iterables and a multilabel format, e.g. a (samples x classes) binary\n matrix indicating the presence of a class label.\n\n Examples\n --------\n Given a dataset with two features, we let the encoder find the unique\n values per feature and transform the data to a binary one-hot encoding.\n\n >>> from sklearn.preprocessing import OneHotEncoder\n\n One can discard categories not seen during `fit`:\n\n >>> enc = OneHotEncoder(handle_unknown='ignore')\n >>> X = [['Male', 1], ['Female', 3], ['Female', 2]]\n >>> enc.fit(X)\n OneHotEncoder(handle_unknown='ignore')\n >>> enc.categories_\n [array(['Female', 'Male'], dtype=object), array([1, 2, 3], dtype=object)]\n >>> enc.transform([['Female', 1], ['Male', 4]]).toarray()\n array([[1., 0., 1., 0., 0.],\n [0., 1., 0., 0., 0.]])\n >>> enc.inverse_transform([[0, 1, 1, 0, 0], [0, 0, 0, 1, 0]])\n array([['Male', 1],\n [None, 2]], dtype=object)\n >>> enc.get_feature_names_out(['gender', 'group'])\n array(['gender_Female', 'gender_Male', 'group_1', 'group_2', 'group_3'], ...)\n\n One can always drop the first column for each feature:\n\n >>> drop_enc = OneHotEncoder(drop='first').fit(X)\n >>> drop_enc.categories_\n [array(['Female', 'Male'], dtype=object), array([1, 2, 3], dtype=object)]\n >>> drop_enc.transform([['Female', 1], ['Male', 2]]).toarray()\n array([[0., 0., 0.],\n [1., 1., 0.]])\n\n Or drop a column for feature only having 2 categories:\n\n >>> drop_binary_enc = OneHotEncoder(drop='if_binary').fit(X)\n >>> drop_binary_enc.transform([['Female', 1], ['Male', 2]]).toarray()\n array([[0., 1., 0., 0.],\n [1., 0., 1., 0.]])\n \"\"\"\n \n def __init__(self, *, categories='auto', drop=None, sparse=True, dtype=np.float64, handle_unknown='error'):\n self.categories = categories\n self.sparse = sparse\n self.dtype = dtype\n self.handle_unknown = handle_unknown\n self.drop = drop\n \n def _validate_keywords(self):\n if self.handle_unknown not in ('error', 'ignore'):\n msg = \"handle_unknown should be either 'error' or 'ignore', got {0}.\".format(self.handle_unknown)\n raise ValueError(msg)\n \n def _compute_drop_idx(self):\n if self.drop is None:\n return None\n elif isinstance(self.drop, str):\n if self.drop == 'first':\n return np.zeros(len(self.categories_), dtype=object)\n elif self.drop == 'if_binary':\n return np.array([0 if len(cats) == 2 else None for cats in self.categories_], dtype=object)\n else:\n msg = \"Wrong input for parameter `drop`. Expected 'first', 'if_binary', None or array of objects, got {}\"\n raise ValueError(msg.format(type(self.drop)))\n else:\n try:\n drop_array = np.asarray(self.drop, dtype=object)\n droplen = len(drop_array)\n except (ValueError, TypeError):\n msg = \"Wrong input for parameter `drop`. Expected 'first', 'if_binary', None or array of objects, got {}\"\n raise ValueError(msg.format(type(drop_array)))\n if droplen != len(self.categories_):\n msg = '`drop` should have length equal to the number of features ({}), got {}'\n raise ValueError(msg.format(len(self.categories_), droplen))\n missing_drops = []\n drop_indices = []\n for (col_idx, (val, cat_list)) in enumerate(zip(drop_array, self.categories_)):\n if not is_scalar_nan(val):\n drop_idx = np.where(cat_list == val)[0]\n if drop_idx.size:\n drop_indices.append(drop_idx[0])\n else:\n missing_drops.append((col_idx, val))\n continue\n for (cat_idx, cat) in enumerate(cat_list):\n if is_scalar_nan(cat):\n drop_indices.append(cat_idx)\n break\n else:\n missing_drops.append((col_idx, val))\n if any(missing_drops):\n msg = 'The following categories were supposed to be dropped, but were not found in the training data.\\n{}'.format('\\n'.join(['Category: {}, Feature: {}'.format(c, v) for (c, v) in missing_drops]))\n raise ValueError(msg)\n return np.array(drop_indices, dtype=object)\n \n def fit(self, X, y=None):\n \"\"\"\n Fit OneHotEncoder to X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data to determine the categories of each feature.\n\n y : None\n Ignored. This parameter exists only for compatibility with\n :class:`~sklearn.pipeline.Pipeline`.\n\n Returns\n -------\n self\n Fitted encoder.\n \"\"\"\n self._validate_keywords()\n self._fit(X, handle_unknown=self.handle_unknown, force_all_finite='allow-nan')\n self.drop_idx_ = self._compute_drop_idx()\n return self\n \n def fit_transform(self, X, y=None):\n \"\"\"\n Fit OneHotEncoder to X, then transform X.\n\n Equivalent to fit(X).transform(X) but more convenient.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data to encode.\n\n y : None\n Ignored. This parameter exists only for compatibility with\n :class:`~sklearn.pipeline.Pipeline`.\n\n Returns\n -------\n X_out : {ndarray, sparse matrix} of shape (n_samples, n_encoded_features)\n Transformed input. If `sparse=True`, a sparse matrix will be\n returned.\n \"\"\"\n self._validate_keywords()\n return super().fit_transform(X, y)\n \n def transform(self, X):\n \"\"\"\n Transform X using one-hot encoding.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data to encode.\n\n Returns\n -------\n X_out : {ndarray, sparse matrix} of shape (n_samples, n_encoded_features)\n Transformed input. If `sparse=True`, a sparse matrix will be\n returned.\n \"\"\"\n check_is_fitted(self)\n warn_on_unknown = self.handle_unknown == 'ignore' and self.drop is not None\n (X_int, X_mask) = self._transform(X, handle_unknown=self.handle_unknown, force_all_finite='allow-nan', warn_on_unknown=warn_on_unknown)\n (n_samples, n_features) = X_int.shape\n if self.drop_idx_ is not None:\n to_drop = self.drop_idx_.copy()\n keep_cells = X_int != to_drop\n n_values = []\n for (i, cats) in enumerate(self.categories_):\n n_cats = len(cats)\n if to_drop[i] is None:\n to_drop[i] = n_cats\n n_values.append(n_cats)\n else:\n n_values.append(n_cats - 1)\n to_drop = to_drop.reshape(1, -1)\n X_int[X_int > to_drop] -= 1\n X_mask &= keep_cells\n else:\n n_values = [len(cats) for cats in self.categories_]\n mask = X_mask.ravel()\n feature_indices = np.cumsum([0] + n_values)\n indices = (X_int + feature_indices[:-1]).ravel()[mask]\n indptr = np.empty(n_samples + 1, dtype=int)\n indptr[0] = 0\n np.sum(X_mask, axis=1, out=indptr[1:])\n np.cumsum(indptr[1:], out=indptr[1:])\n data = np.ones(indptr[-1])\n out = sparse.csr_matrix((data, indices, indptr), shape=(n_samples, feature_indices[-1]), dtype=self.dtype)\n if not self.sparse:\n return out.toarray()\n else:\n return out\n \n def inverse_transform(self, X):\n \"\"\"\n Convert the data back to the original representation.\n\n When unknown categories are encountered (all zeros in the\n one-hot encoding), ``None`` is used to represent this category. If the\n feature with the unknown category has a dropped caregory, the dropped\n category will be its inverse.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_encoded_features)\n The transformed data.\n\n Returns\n -------\n X_tr : ndarray of shape (n_samples, n_features)\n Inverse transformed array.\n \"\"\"\n check_is_fitted(self)\n X = check_array(X, accept_sparse='csr')\n (n_samples, _) = X.shape\n n_features = len(self.categories_)\n if self.drop_idx_ is None:\n n_transformed_features = sum((len(cats) for cats in self.categories_))\n else:\n n_transformed_features = sum((len(cats) - 1 if to_drop is not None else len(cats) for (cats, to_drop) in zip(self.categories_, self.drop_idx_)))\n msg = 'Shape of the passed X data is not correct. Expected {0} columns, got {1}.'\n if X.shape[1] != n_transformed_features:\n raise ValueError(msg.format(n_transformed_features, X.shape[1]))\n dt = np.find_common_type([cat.dtype for cat in self.categories_], [])\n X_tr = np.empty((n_samples, n_features), dtype=dt)\n j = 0\n found_unknown = {}\n for i in range(n_features):\n if self.drop_idx_ is None or self.drop_idx_[i] is None:\n cats = self.categories_[i]\n else:\n cats = np.delete(self.categories_[i], self.drop_idx_[i])\n n_categories = len(cats)\n if n_categories == 0:\n X_tr[:, i] = self.categories_[i][self.drop_idx_[i]]\n j += n_categories\n continue\n sub = X[:, j:j + n_categories]\n labels = np.asarray(sub.argmax(axis=1)).flatten()\n X_tr[:, i] = cats[labels]\n if self.handle_unknown == 'ignore':\n unknown = np.asarray(sub.sum(axis=1) == 0).flatten()\n if unknown.any():\n if self.drop_idx_ is None or self.drop_idx_[i] is None:\n found_unknown[i] = unknown\n else:\n X_tr[unknown, i] = self.categories_[i][self.drop_idx_[i]]\n else:\n dropped = np.asarray(sub.sum(axis=1) == 0).flatten()\n if dropped.any():\n if self.drop_idx_ is None:\n all_zero_samples = np.flatnonzero(dropped)\n raise ValueError(f\"Samples {all_zero_samples} can not be inverted when drop=None and handle_unknown='error' because they contain all zeros\")\n X_tr[dropped, i] = self.categories_[i][self.drop_idx_[i]]\n j += n_categories\n if found_unknown:\n if X_tr.dtype != object:\n X_tr = X_tr.astype(object)\n for (idx, mask) in found_unknown.items():\n X_tr[mask, idx] = None\n return X_tr\n \n @deprecated('get_feature_names is deprecated in 1.0 and will be removed in 1.2. Please use get_feature_names_out instead.')\n def get_feature_names(self, input_features=None):\n \"\"\"Return feature names for output features.\n\n Parameters\n ----------\n input_features : list of str of shape (n_features,)\n String names for input features if available. By default,\n \"x0\", \"x1\", ... \"xn_features\" is used.\n\n Returns\n -------\n output_feature_names : ndarray of shape (n_output_features,)\n Array of feature names.\n \"\"\"\n check_is_fitted(self)\n cats = self.categories_\n if input_features is None:\n input_features = ['x%d' % i for i in range(len(cats))]\n elif len(input_features) != len(self.categories_):\n raise ValueError('input_features should have length equal to number of features ({}), got {}'.format(len(self.categories_), len(input_features)))\n feature_names = []\n for i in range(len(cats)):\n names = [input_features[i] + '_' + str(t) for t in cats[i]]\n if self.drop_idx_ is not None and self.drop_idx_[i] is not None:\n names.pop(self.drop_idx_[i])\n feature_names.extend(names)\n return np.array(feature_names, dtype=object)\n \n def get_feature_names_out(self, input_features=None):\n \"\"\"Get output feature names for transformation.\n\n Returns `input_features` as this transformation doesn't add or drop\n features.\n\n Parameters\n ----------\n input_features : array-like of str or None, default=None\n Input features.\n\n - If `input_features` is `None`, then `feature_names_in_` is\n used as feature names in. If `feature_names_in_` is not defined,\n then names are generated: `[x0, x1, ..., x(n_features_in_)]`.\n - If `input_features` is an array-like, then `input_features` must\n match `feature_names_in_` if `feature_names_in_` is defined.\n\n Returns\n -------\n feature_names_out : ndarray of str objects\n Transformed feature names.\n \"\"\"\n check_is_fitted(self)\n cats = self.categories_\n input_features = _check_feature_names_in(self, input_features)\n feature_names = []\n for i in range(len(cats)):\n names = [input_features[i] + '_' + str(t) for t in cats[i]]\n if self.drop_idx_ is not None and self.drop_idx_[i] is not None:\n names.pop(self.drop_idx_[i])\n feature_names.extend(names)\n return np.asarray(feature_names, dtype=object)\n" + "source_code": "\n\nclass OneHotEncoder(_BaseEncoder):\n \"\"\"\n Encode categorical features as a one-hot numeric array.\n\n The input to this transformer should be an array-like of integers or\n strings, denoting the values taken on by categorical (discrete) features.\n The features are encoded using a one-hot (aka 'one-of-K' or 'dummy')\n encoding scheme. This creates a binary column for each category and\n returns a sparse matrix or dense array (depending on the ``sparse``\n parameter)\n\n By default, the encoder derives the categories based on the unique values\n in each feature. Alternatively, you can also specify the `categories`\n manually.\n\n This encoding is needed for feeding categorical data to many scikit-learn\n estimators, notably linear models and SVMs with the standard kernels.\n\n Note: a one-hot encoding of y labels should use a LabelBinarizer\n instead.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n categories : 'auto' or a list of array-like, default='auto'\n Categories (unique values) per feature:\n\n - 'auto' : Determine categories automatically from the training data.\n - list : ``categories[i]`` holds the categories expected in the ith\n column. The passed categories should not mix strings and numeric\n values within a single feature, and should be sorted in case of\n numeric values.\n\n The used categories can be found in the ``categories_`` attribute.\n\n .. versionadded:: 0.20\n\n drop : {'first', 'if_binary'} or a array-like of shape (n_features,), default=None\n Specifies a methodology to use to drop one of the categories per\n feature. This is useful in situations where perfectly collinear\n features cause problems, such as when feeding the resulting data\n into a neural network or an unregularized regression.\n\n However, dropping one category breaks the symmetry of the original\n representation and can therefore induce a bias in downstream models,\n for instance for penalized linear classification or regression models.\n\n - None : retain all features (the default).\n - 'first' : drop the first category in each feature. If only one\n category is present, the feature will be dropped entirely.\n - 'if_binary' : drop the first category in each feature with two\n categories. Features with 1 or more than 2 categories are\n left intact.\n - array : ``drop[i]`` is the category in feature ``X[:, i]`` that\n should be dropped.\n\n .. versionadded:: 0.21\n The parameter `drop` was added in 0.21.\n\n .. versionchanged:: 0.23\n The option `drop='if_binary'` was added in 0.23.\n\n sparse : bool, default=True\n Will return sparse matrix if set True else will return an array.\n\n dtype : number type, default=float\n Desired dtype of output.\n\n handle_unknown : {'error', 'ignore'}, default='error'\n Whether to raise an error or ignore if an unknown categorical feature\n is present during transform (default is to raise). When this parameter\n is set to 'ignore' and an unknown category is encountered during\n transform, the resulting one-hot encoded columns for this feature\n will be all zeros. In the inverse transform, an unknown category\n will be denoted as None.\n\n Attributes\n ----------\n categories_ : list of arrays\n The categories of each feature determined during fitting\n (in order of the features in X and corresponding with the output\n of ``transform``). This includes the category specified in ``drop``\n (if any).\n\n drop_idx_ : array of shape (n_features,)\n - ``drop_idx_[i]`` is\u00a0the index in ``categories_[i]`` of the category\n to be dropped for each feature.\n - ``drop_idx_[i] = None`` if no category is to be dropped from the\n feature with index ``i``, e.g. when `drop='if_binary'` and the\n feature isn't binary.\n - ``drop_idx_ = None`` if all the transformed features will be\n retained.\n\n .. versionchanged:: 0.23\n Added the possibility to contain `None` values.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 1.0\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n OrdinalEncoder : Performs an ordinal (integer)\n encoding of the categorical features.\n sklearn.feature_extraction.DictVectorizer : Performs a one-hot encoding of\n dictionary items (also handles string-valued features).\n sklearn.feature_extraction.FeatureHasher : Performs an approximate one-hot\n encoding of dictionary items or strings.\n LabelBinarizer : Binarizes labels in a one-vs-all\n fashion.\n MultiLabelBinarizer : Transforms between iterable of\n iterables and a multilabel format, e.g. a (samples x classes) binary\n matrix indicating the presence of a class label.\n\n Examples\n --------\n Given a dataset with two features, we let the encoder find the unique\n values per feature and transform the data to a binary one-hot encoding.\n\n >>> from sklearn.preprocessing import OneHotEncoder\n\n One can discard categories not seen during `fit`:\n\n >>> enc = OneHotEncoder(handle_unknown='ignore')\n >>> X = [['Male', 1], ['Female', 3], ['Female', 2]]\n >>> enc.fit(X)\n OneHotEncoder(handle_unknown='ignore')\n >>> enc.categories_\n [array(['Female', 'Male'], dtype=object), array([1, 2, 3], dtype=object)]\n >>> enc.transform([['Female', 1], ['Male', 4]]).toarray()\n array([[1., 0., 1., 0., 0.],\n [0., 1., 0., 0., 0.]])\n >>> enc.inverse_transform([[0, 1, 1, 0, 0], [0, 0, 0, 1, 0]])\n array([['Male', 1],\n [None, 2]], dtype=object)\n >>> enc.get_feature_names_out(['gender', 'group'])\n array(['gender_Female', 'gender_Male', 'group_1', 'group_2', 'group_3'], ...)\n\n One can always drop the first column for each feature:\n\n >>> drop_enc = OneHotEncoder(drop='first').fit(X)\n >>> drop_enc.categories_\n [array(['Female', 'Male'], dtype=object), array([1, 2, 3], dtype=object)]\n >>> drop_enc.transform([['Female', 1], ['Male', 2]]).toarray()\n array([[0., 0., 0.],\n [1., 1., 0.]])\n\n Or drop a column for feature only having 2 categories:\n\n >>> drop_binary_enc = OneHotEncoder(drop='if_binary').fit(X)\n >>> drop_binary_enc.transform([['Female', 1], ['Male', 2]]).toarray()\n array([[0., 1., 0., 0.],\n [1., 0., 1., 0.]])\n \"\"\"\n \n def __init__(self, *, categories='auto', drop=None, sparse=True, dtype=np.float64, handle_unknown='error'):\n self.categories = categories\n self.sparse = sparse\n self.dtype = dtype\n self.handle_unknown = handle_unknown\n self.drop = drop\n \n def _validate_keywords(self):\n if self.handle_unknown not in ('error', 'ignore'):\n msg = \"handle_unknown should be either 'error' or 'ignore', got {0}.\".format(self.handle_unknown)\n raise ValueError(msg)\n \n def _compute_drop_idx(self):\n if self.drop is None:\n return None\n elif isinstance(self.drop, str):\n if self.drop == 'first':\n return np.zeros(len(self.categories_), dtype=object)\n elif self.drop == 'if_binary':\n return np.array([0 if len(cats) == 2 else None for cats in self.categories_], dtype=object)\n else:\n msg = \"Wrong input for parameter `drop`. Expected 'first', 'if_binary', None or array of objects, got {}\"\n raise ValueError(msg.format(type(self.drop)))\n else:\n try:\n drop_array = np.asarray(self.drop, dtype=object)\n droplen = len(drop_array)\n except (ValueError, TypeError):\n msg = \"Wrong input for parameter `drop`. Expected 'first', 'if_binary', None or array of objects, got {}\"\n raise ValueError(msg.format(type(drop_array)))\n if droplen != len(self.categories_):\n msg = '`drop` should have length equal to the number of features ({}), got {}'\n raise ValueError(msg.format(len(self.categories_), droplen))\n missing_drops = []\n drop_indices = []\n for (col_idx, (val, cat_list)) in enumerate(zip(drop_array, self.categories_)):\n if not is_scalar_nan(val):\n drop_idx = np.where(cat_list == val)[0]\n if drop_idx.size:\n drop_indices.append(drop_idx[0])\n else:\n missing_drops.append((col_idx, val))\n continue\n for (cat_idx, cat) in enumerate(cat_list):\n if is_scalar_nan(cat):\n drop_indices.append(cat_idx)\n break\n else:\n missing_drops.append((col_idx, val))\n if any(missing_drops):\n msg = 'The following categories were supposed to be dropped, but were not found in the training data.\\n{}'.format('\\n'.join(['Category: {}, Feature: {}'.format(c, v) for (c, v) in missing_drops]))\n raise ValueError(msg)\n return np.array(drop_indices, dtype=object)\n \n def fit(self, X, y=None):\n \"\"\"\n Fit OneHotEncoder to X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data to determine the categories of each feature.\n\n y : None\n Ignored. This parameter exists only for compatibility with\n :class:`~sklearn.pipeline.Pipeline`.\n\n Returns\n -------\n self\n Fitted encoder.\n \"\"\"\n self._validate_keywords()\n self._fit(X, handle_unknown=self.handle_unknown, force_all_finite='allow-nan')\n self.drop_idx_ = self._compute_drop_idx()\n return self\n \n def fit_transform(self, X, y=None):\n \"\"\"\n Fit OneHotEncoder to X, then transform X.\n\n Equivalent to fit(X).transform(X) but more convenient.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data to encode.\n\n y : None\n Ignored. This parameter exists only for compatibility with\n :class:`~sklearn.pipeline.Pipeline`.\n\n Returns\n -------\n X_out : {ndarray, sparse matrix} of shape (n_samples, n_encoded_features)\n Transformed input. If `sparse=True`, a sparse matrix will be\n returned.\n \"\"\"\n self._validate_keywords()\n return super().fit_transform(X, y)\n \n def transform(self, X):\n \"\"\"\n Transform X using one-hot encoding.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data to encode.\n\n Returns\n -------\n X_out : {ndarray, sparse matrix} of shape (n_samples, n_encoded_features)\n Transformed input. If `sparse=True`, a sparse matrix will be\n returned.\n \"\"\"\n check_is_fitted(self)\n warn_on_unknown = self.handle_unknown == 'ignore' and self.drop is not None\n (X_int, X_mask) = self._transform(X, handle_unknown=self.handle_unknown, force_all_finite='allow-nan', warn_on_unknown=warn_on_unknown)\n (n_samples, n_features) = X_int.shape\n if self.drop_idx_ is not None:\n to_drop = self.drop_idx_.copy()\n keep_cells = X_int != to_drop\n n_values = []\n for (i, cats) in enumerate(self.categories_):\n n_cats = len(cats)\n if to_drop[i] is None:\n to_drop[i] = n_cats\n n_values.append(n_cats)\n else:\n n_values.append(n_cats - 1)\n to_drop = to_drop.reshape(1, -1)\n X_int[X_int > to_drop] -= 1\n X_mask &= keep_cells\n else:\n n_values = [len(cats) for cats in self.categories_]\n mask = X_mask.ravel()\n feature_indices = np.cumsum([0] + n_values)\n indices = (X_int + feature_indices[:-1]).ravel()[mask]\n indptr = np.empty(n_samples + 1, dtype=int)\n indptr[0] = 0\n np.sum(X_mask, axis=1, out=indptr[1:])\n np.cumsum(indptr[1:], out=indptr[1:])\n data = np.ones(indptr[-1])\n out = sparse.csr_matrix((data, indices, indptr), shape=(n_samples, feature_indices[-1]), dtype=self.dtype)\n if not self.sparse:\n return out.toarray()\n else:\n return out\n \n def inverse_transform(self, X):\n \"\"\"\n Convert the data back to the original representation.\n\n When unknown categories are encountered (all zeros in the\n one-hot encoding), ``None`` is used to represent this category. If the\n feature with the unknown category has a dropped caregory, the dropped\n category will be its inverse.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_encoded_features)\n The transformed data.\n\n Returns\n -------\n X_tr : ndarray of shape (n_samples, n_features)\n Inverse transformed array.\n \"\"\"\n check_is_fitted(self)\n X = check_array(X, accept_sparse='csr')\n (n_samples, _) = X.shape\n n_features = len(self.categories_)\n if self.drop_idx_ is None:\n n_transformed_features = sum((len(cats) for cats in self.categories_))\n else:\n n_transformed_features = sum((len(cats) - 1 if to_drop is not None else len(cats) for (cats, to_drop) in zip(self.categories_, self.drop_idx_)))\n msg = 'Shape of the passed X data is not correct. Expected {0} columns, got {1}.'\n if X.shape[1] != n_transformed_features:\n raise ValueError(msg.format(n_transformed_features, X.shape[1]))\n dt = np.find_common_type([cat.dtype for cat in self.categories_], [])\n X_tr = np.empty((n_samples, n_features), dtype=dt)\n j = 0\n found_unknown = {}\n for i in range(n_features):\n if self.drop_idx_ is None or self.drop_idx_[i] is None:\n cats = self.categories_[i]\n else:\n cats = np.delete(self.categories_[i], self.drop_idx_[i])\n n_categories = len(cats)\n if n_categories == 0:\n X_tr[:, i] = self.categories_[i][self.drop_idx_[i]]\n j += n_categories\n continue\n sub = X[:, j:j + n_categories]\n labels = np.asarray(sub.argmax(axis=1)).flatten()\n X_tr[:, i] = cats[labels]\n if self.handle_unknown == 'ignore':\n unknown = np.asarray(sub.sum(axis=1) == 0).flatten()\n if unknown.any():\n if self.drop_idx_ is None or self.drop_idx_[i] is None:\n found_unknown[i] = unknown\n else:\n X_tr[unknown, i] = self.categories_[i][self.drop_idx_[i]]\n else:\n dropped = np.asarray(sub.sum(axis=1) == 0).flatten()\n if dropped.any():\n if self.drop_idx_ is None:\n all_zero_samples = np.flatnonzero(dropped)\n raise ValueError(f\"Samples {all_zero_samples} can not be inverted when drop=None and handle_unknown='error' because they contain all zeros\")\n X_tr[dropped, i] = self.categories_[i][self.drop_idx_[i]]\n j += n_categories\n if found_unknown:\n if X_tr.dtype != object:\n X_tr = X_tr.astype(object)\n for (idx, mask) in found_unknown.items():\n X_tr[mask, idx] = None\n return X_tr\n \n @deprecated('get_feature_names is deprecated in 1.0 and will be removed in 1.2. Please use get_feature_names_out instead.')\n def get_feature_names(self, input_features=None):\n \"\"\"Return feature names for output features.\n\n Parameters\n ----------\n input_features : list of str of shape (n_features,)\n String names for input features if available. By default,\n \"x0\", \"x1\", ... \"xn_features\" is used.\n\n Returns\n -------\n output_feature_names : ndarray of shape (n_output_features,)\n Array of feature names.\n \"\"\"\n check_is_fitted(self)\n cats = self.categories_\n if input_features is None:\n input_features = ['x%d' % i for i in range(len(cats))]\n elif len(input_features) != len(self.categories_):\n raise ValueError('input_features should have length equal to number of features ({}), got {}'.format(len(self.categories_), len(input_features)))\n feature_names = []\n for i in range(len(cats)):\n names = [input_features[i] + '_' + str(t) for t in cats[i]]\n if self.drop_idx_ is not None and self.drop_idx_[i] is not None:\n names.pop(self.drop_idx_[i])\n feature_names.extend(names)\n return np.array(feature_names, dtype=object)\n \n def get_feature_names_out(self, input_features=None):\n \"\"\"Get output feature names for transformation.\n\n Parameters\n ----------\n input_features : array-like of str or None, default=None\n Input features.\n\n - If `input_features` is `None`, then `feature_names_in_` is\n used as feature names in. If `feature_names_in_` is not defined,\n then names are generated: `[x0, x1, ..., x(n_features_in_)]`.\n - If `input_features` is an array-like, then `input_features` must\n match `feature_names_in_` if `feature_names_in_` is defined.\n\n Returns\n -------\n feature_names_out : ndarray of str objects\n Transformed feature names.\n \"\"\"\n check_is_fitted(self)\n cats = self.categories_\n input_features = _check_feature_names_in(self, input_features)\n feature_names = []\n for i in range(len(cats)):\n names = [input_features[i] + '_' + str(t) for t in cats[i]]\n if self.drop_idx_ is not None and self.drop_idx_[i] is not None:\n names.pop(self.drop_idx_[i])\n feature_names.extend(names)\n return np.asarray(feature_names, dtype=object)\n" }, { "name": "OrdinalEncoder", @@ -26131,8 +26084,8 @@ ], "is_public": true, "description": "Constructs a transformer from an arbitrary callable.\n\nA FunctionTransformer forwards its X (and optionally y) arguments to a user-defined function or function object and returns the result of this function. This is useful for stateless transformations such as taking the log of frequencies, doing custom scaling, etc. Note: If a lambda is used as the function, then the resulting transformer will not be pickleable. .. versionadded:: 0.17 Read more in the :ref:`User Guide `.", - "docstring": "Constructs a transformer from an arbitrary callable.\n\n A FunctionTransformer forwards its X (and optionally y) arguments to a\n user-defined function or function object and returns the result of this\n function. This is useful for stateless transformations such as taking the\n log of frequencies, doing custom scaling, etc.\n\n Note: If a lambda is used as the function, then the resulting\n transformer will not be pickleable.\n\n .. versionadded:: 0.17\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n func : callable, default=None\n The callable to use for the transformation. This will be passed\n the same arguments as transform, with args and kwargs forwarded.\n If func is None, then func will be the identity function.\n\n inverse_func : callable, default=None\n The callable to use for the inverse transformation. This will be\n passed the same arguments as inverse transform, with args and\n kwargs forwarded. If inverse_func is None, then inverse_func\n will be the identity function.\n\n validate : bool, default=False\n Indicate that the input X array should be checked before calling\n ``func``. The possibilities are:\n\n - If False, there is no input validation.\n - If True, then X will be converted to a 2-dimensional NumPy array or\n sparse matrix. If the conversion is not possible an exception is\n raised.\n\n .. versionchanged:: 0.22\n The default of ``validate`` changed from True to False.\n\n accept_sparse : bool, default=False\n Indicate that func accepts a sparse matrix as input. If validate is\n False, this has no effect. Otherwise, if accept_sparse is false,\n sparse matrix inputs will cause an exception to be raised.\n\n check_inverse : bool, default=True\n Whether to check that or ``func`` followed by ``inverse_func`` leads to\n the original inputs. It can be used for a sanity check, raising a\n warning when the condition is not fulfilled.\n\n .. versionadded:: 0.20\n\n kw_args : dict, default=None\n Dictionary of additional keyword arguments to pass to func.\n\n .. versionadded:: 0.18\n\n inv_kw_args : dict, default=None\n Dictionary of additional keyword arguments to pass to inverse_func.\n\n .. versionadded:: 0.18\n\n Attributes\n ----------\n n_features_in_ : int\n Number of features seen during :term:`fit`. Defined only when\n `validate=True`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `validate=True`\n and `X` has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n MaxAbsScaler : Scale each feature by its maximum absolute value.\n StandardScaler : Standardize features by removing the mean and\n scaling to unit variance.\n LabelBinarizer : Binarize labels in a one-vs-all fashion.\n MultilabelBinarizer : Transform between iterable of iterables\n and a multilabel format.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.preprocessing import FunctionTransformer\n >>> transformer = FunctionTransformer(np.log1p)\n >>> X = np.array([[0, 1], [2, 3]])\n >>> transformer.transform(X)\n array([[0. , 0.6931...],\n [1.0986..., 1.3862...]])\n ", - "source_code": "\n\nclass FunctionTransformer(TransformerMixin, BaseEstimator):\n \"\"\"Constructs a transformer from an arbitrary callable.\n\n A FunctionTransformer forwards its X (and optionally y) arguments to a\n user-defined function or function object and returns the result of this\n function. This is useful for stateless transformations such as taking the\n log of frequencies, doing custom scaling, etc.\n\n Note: If a lambda is used as the function, then the resulting\n transformer will not be pickleable.\n\n .. versionadded:: 0.17\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n func : callable, default=None\n The callable to use for the transformation. This will be passed\n the same arguments as transform, with args and kwargs forwarded.\n If func is None, then func will be the identity function.\n\n inverse_func : callable, default=None\n The callable to use for the inverse transformation. This will be\n passed the same arguments as inverse transform, with args and\n kwargs forwarded. If inverse_func is None, then inverse_func\n will be the identity function.\n\n validate : bool, default=False\n Indicate that the input X array should be checked before calling\n ``func``. The possibilities are:\n\n - If False, there is no input validation.\n - If True, then X will be converted to a 2-dimensional NumPy array or\n sparse matrix. If the conversion is not possible an exception is\n raised.\n\n .. versionchanged:: 0.22\n The default of ``validate`` changed from True to False.\n\n accept_sparse : bool, default=False\n Indicate that func accepts a sparse matrix as input. If validate is\n False, this has no effect. Otherwise, if accept_sparse is false,\n sparse matrix inputs will cause an exception to be raised.\n\n check_inverse : bool, default=True\n Whether to check that or ``func`` followed by ``inverse_func`` leads to\n the original inputs. It can be used for a sanity check, raising a\n warning when the condition is not fulfilled.\n\n .. versionadded:: 0.20\n\n kw_args : dict, default=None\n Dictionary of additional keyword arguments to pass to func.\n\n .. versionadded:: 0.18\n\n inv_kw_args : dict, default=None\n Dictionary of additional keyword arguments to pass to inverse_func.\n\n .. versionadded:: 0.18\n\n Attributes\n ----------\n n_features_in_ : int\n Number of features seen during :term:`fit`. Defined only when\n `validate=True`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `validate=True`\n and `X` has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n MaxAbsScaler : Scale each feature by its maximum absolute value.\n StandardScaler : Standardize features by removing the mean and\n scaling to unit variance.\n LabelBinarizer : Binarize labels in a one-vs-all fashion.\n MultilabelBinarizer : Transform between iterable of iterables\n and a multilabel format.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.preprocessing import FunctionTransformer\n >>> transformer = FunctionTransformer(np.log1p)\n >>> X = np.array([[0, 1], [2, 3]])\n >>> transformer.transform(X)\n array([[0. , 0.6931...],\n [1.0986..., 1.3862...]])\n \"\"\"\n \n def __init__(self, func=None, inverse_func=None, *, validate=False, accept_sparse=False, check_inverse=True, kw_args=None, inv_kw_args=None):\n self.func = func\n self.inverse_func = inverse_func\n self.validate = validate\n self.accept_sparse = accept_sparse\n self.check_inverse = check_inverse\n self.kw_args = kw_args\n self.inv_kw_args = inv_kw_args\n \n def _check_input(self, X, *, reset):\n if self.validate:\n return self._validate_data(X, accept_sparse=self.accept_sparse, reset=reset)\n return X\n \n def _check_inverse_transform(self, X):\n \"\"\"Check that func and inverse_func are the inverse.\"\"\"\n idx_selected = slice(None, None, max(1, X.shape[0] // 100))\n X_round_trip = self.inverse_transform(self.transform(X[idx_selected]))\n if not _allclose_dense_sparse(X[idx_selected], X_round_trip):\n warnings.warn(\"The provided functions are not strictly inverse of each other. If you are sure you want to proceed regardless, set 'check_inverse=False'.\", UserWarning)\n \n def fit(self, X, y=None):\n \"\"\"Fit transformer by checking X.\n\n If ``validate`` is ``True``, ``X`` will be checked.\n\n Parameters\n ----------\n X : array-like, shape (n_samples, n_features)\n Input array.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self : object\n FunctionTransformer class instance.\n \"\"\"\n X = self._check_input(X, reset=True)\n if self.check_inverse and not (self.func is None or self.inverse_func is None):\n self._check_inverse_transform(X)\n return self\n \n def transform(self, X):\n \"\"\"Transform X using the forward function.\n\n Parameters\n ----------\n X : array-like, shape (n_samples, n_features)\n Input array.\n\n Returns\n -------\n X_out : array-like, shape (n_samples, n_features)\n Transformed input.\n \"\"\"\n X = self._check_input(X, reset=False)\n return self._transform(X, func=self.func, kw_args=self.kw_args)\n \n def inverse_transform(self, X):\n \"\"\"Transform X using the inverse function.\n\n Parameters\n ----------\n X : array-like, shape (n_samples, n_features)\n Input array.\n\n Returns\n -------\n X_out : array-like, shape (n_samples, n_features)\n Transformed input.\n \"\"\"\n if self.validate:\n X = check_array(X, accept_sparse=self.accept_sparse)\n return self._transform(X, func=self.inverse_func, kw_args=self.inv_kw_args)\n \n def _transform(self, X, func=None, kw_args=None):\n if func is None:\n func = _identity\n return func(X, **kw_args if kw_args else {})\n \n def __sklearn_is_fitted__(self):\n \"\"\"Return True since FunctionTransfomer is stateless.\"\"\"\n return True\n \n def _more_tags(self):\n return {'no_validation': not self.validate, 'stateless': True}\n" + "docstring": "Constructs a transformer from an arbitrary callable.\n\n A FunctionTransformer forwards its X (and optionally y) arguments to a\n user-defined function or function object and returns the result of this\n function. This is useful for stateless transformations such as taking the\n log of frequencies, doing custom scaling, etc.\n\n Note: If a lambda is used as the function, then the resulting\n transformer will not be pickleable.\n\n .. versionadded:: 0.17\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n func : callable, default=None\n The callable to use for the transformation. This will be passed\n the same arguments as transform, with args and kwargs forwarded.\n If func is None, then func will be the identity function.\n\n inverse_func : callable, default=None\n The callable to use for the inverse transformation. This will be\n passed the same arguments as inverse transform, with args and\n kwargs forwarded. If inverse_func is None, then inverse_func\n will be the identity function.\n\n validate : bool, default=False\n Indicate that the input X array should be checked before calling\n ``func``. The possibilities are:\n\n - If False, there is no input validation.\n - If True, then X will be converted to a 2-dimensional NumPy array or\n sparse matrix. If the conversion is not possible an exception is\n raised.\n\n .. versionchanged:: 0.22\n The default of ``validate`` changed from True to False.\n\n accept_sparse : bool, default=False\n Indicate that func accepts a sparse matrix as input. If validate is\n False, this has no effect. Otherwise, if accept_sparse is false,\n sparse matrix inputs will cause an exception to be raised.\n\n check_inverse : bool, default=True\n Whether to check that or ``func`` followed by ``inverse_func`` leads to\n the original inputs. It can be used for a sanity check, raising a\n warning when the condition is not fulfilled.\n\n .. versionadded:: 0.20\n\n kw_args : dict, default=None\n Dictionary of additional keyword arguments to pass to func.\n\n .. versionadded:: 0.18\n\n inv_kw_args : dict, default=None\n Dictionary of additional keyword arguments to pass to inverse_func.\n\n .. versionadded:: 0.18\n\n Attributes\n ----------\n n_features_in_ : int\n Number of features seen during :term:`fit`. Defined only when\n `validate=True`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `validate=True`\n and `X` has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n MaxAbsScaler : Scale each feature by its maximum absolute value.\n StandardScaler : Standardize features by removing the mean and\n scaling to unit variance.\n LabelBinarizer : Binarize labels in a one-vs-all fashion.\n MultiLabelBinarizer : Transform between iterable of iterables\n and a multilabel format.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.preprocessing import FunctionTransformer\n >>> transformer = FunctionTransformer(np.log1p)\n >>> X = np.array([[0, 1], [2, 3]])\n >>> transformer.transform(X)\n array([[0. , 0.6931...],\n [1.0986..., 1.3862...]])\n ", + "source_code": "\n\nclass FunctionTransformer(TransformerMixin, BaseEstimator):\n \"\"\"Constructs a transformer from an arbitrary callable.\n\n A FunctionTransformer forwards its X (and optionally y) arguments to a\n user-defined function or function object and returns the result of this\n function. This is useful for stateless transformations such as taking the\n log of frequencies, doing custom scaling, etc.\n\n Note: If a lambda is used as the function, then the resulting\n transformer will not be pickleable.\n\n .. versionadded:: 0.17\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n func : callable, default=None\n The callable to use for the transformation. This will be passed\n the same arguments as transform, with args and kwargs forwarded.\n If func is None, then func will be the identity function.\n\n inverse_func : callable, default=None\n The callable to use for the inverse transformation. This will be\n passed the same arguments as inverse transform, with args and\n kwargs forwarded. If inverse_func is None, then inverse_func\n will be the identity function.\n\n validate : bool, default=False\n Indicate that the input X array should be checked before calling\n ``func``. The possibilities are:\n\n - If False, there is no input validation.\n - If True, then X will be converted to a 2-dimensional NumPy array or\n sparse matrix. If the conversion is not possible an exception is\n raised.\n\n .. versionchanged:: 0.22\n The default of ``validate`` changed from True to False.\n\n accept_sparse : bool, default=False\n Indicate that func accepts a sparse matrix as input. If validate is\n False, this has no effect. Otherwise, if accept_sparse is false,\n sparse matrix inputs will cause an exception to be raised.\n\n check_inverse : bool, default=True\n Whether to check that or ``func`` followed by ``inverse_func`` leads to\n the original inputs. It can be used for a sanity check, raising a\n warning when the condition is not fulfilled.\n\n .. versionadded:: 0.20\n\n kw_args : dict, default=None\n Dictionary of additional keyword arguments to pass to func.\n\n .. versionadded:: 0.18\n\n inv_kw_args : dict, default=None\n Dictionary of additional keyword arguments to pass to inverse_func.\n\n .. versionadded:: 0.18\n\n Attributes\n ----------\n n_features_in_ : int\n Number of features seen during :term:`fit`. Defined only when\n `validate=True`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `validate=True`\n and `X` has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n MaxAbsScaler : Scale each feature by its maximum absolute value.\n StandardScaler : Standardize features by removing the mean and\n scaling to unit variance.\n LabelBinarizer : Binarize labels in a one-vs-all fashion.\n MultiLabelBinarizer : Transform between iterable of iterables\n and a multilabel format.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.preprocessing import FunctionTransformer\n >>> transformer = FunctionTransformer(np.log1p)\n >>> X = np.array([[0, 1], [2, 3]])\n >>> transformer.transform(X)\n array([[0. , 0.6931...],\n [1.0986..., 1.3862...]])\n \"\"\"\n \n def __init__(self, func=None, inverse_func=None, *, validate=False, accept_sparse=False, check_inverse=True, kw_args=None, inv_kw_args=None):\n self.func = func\n self.inverse_func = inverse_func\n self.validate = validate\n self.accept_sparse = accept_sparse\n self.check_inverse = check_inverse\n self.kw_args = kw_args\n self.inv_kw_args = inv_kw_args\n \n def _check_input(self, X, *, reset):\n if self.validate:\n return self._validate_data(X, accept_sparse=self.accept_sparse, reset=reset)\n return X\n \n def _check_inverse_transform(self, X):\n \"\"\"Check that func and inverse_func are the inverse.\"\"\"\n idx_selected = slice(None, None, max(1, X.shape[0] // 100))\n X_round_trip = self.inverse_transform(self.transform(X[idx_selected]))\n if not _allclose_dense_sparse(X[idx_selected], X_round_trip):\n warnings.warn(\"The provided functions are not strictly inverse of each other. If you are sure you want to proceed regardless, set 'check_inverse=False'.\", UserWarning)\n \n def fit(self, X, y=None):\n \"\"\"Fit transformer by checking X.\n\n If ``validate`` is ``True``, ``X`` will be checked.\n\n Parameters\n ----------\n X : array-like, shape (n_samples, n_features)\n Input array.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self : object\n FunctionTransformer class instance.\n \"\"\"\n X = self._check_input(X, reset=True)\n if self.check_inverse and not (self.func is None or self.inverse_func is None):\n self._check_inverse_transform(X)\n return self\n \n def transform(self, X):\n \"\"\"Transform X using the forward function.\n\n Parameters\n ----------\n X : array-like, shape (n_samples, n_features)\n Input array.\n\n Returns\n -------\n X_out : array-like, shape (n_samples, n_features)\n Transformed input.\n \"\"\"\n X = self._check_input(X, reset=False)\n return self._transform(X, func=self.func, kw_args=self.kw_args)\n \n def inverse_transform(self, X):\n \"\"\"Transform X using the inverse function.\n\n Parameters\n ----------\n X : array-like, shape (n_samples, n_features)\n Input array.\n\n Returns\n -------\n X_out : array-like, shape (n_samples, n_features)\n Transformed input.\n \"\"\"\n if self.validate:\n X = check_array(X, accept_sparse=self.accept_sparse)\n return self._transform(X, func=self.inverse_func, kw_args=self.inv_kw_args)\n \n def _transform(self, X, func=None, kw_args=None):\n if func is None:\n func = _identity\n return func(X, **kw_args if kw_args else {})\n \n def __sklearn_is_fitted__(self):\n \"\"\"Return True since FunctionTransfomer is stateless.\"\"\"\n return True\n \n def _more_tags(self):\n return {'no_validation': not self.validate, 'stateless': True}\n" }, { "name": "LabelBinarizer", @@ -26186,8 +26139,8 @@ ], "is_public": true, "description": "Transform between iterable of iterables and a multilabel format.\n\nAlthough a list of sets or tuples is a very intuitive format for multilabel data, it is unwieldy to process. This transformer converts between this intuitive format and the supported multilabel format: a (samples x classes) binary matrix indicating the presence of a class label.", - "docstring": "Transform between iterable of iterables and a multilabel format.\n\n Although a list of sets or tuples is a very intuitive format for multilabel\n data, it is unwieldy to process. This transformer converts between this\n intuitive format and the supported multilabel format: a (samples x classes)\n binary matrix indicating the presence of a class label.\n\n Parameters\n ----------\n classes : array-like of shape (n_classes,), default=None\n Indicates an ordering for the class labels.\n All entries should be unique (cannot contain duplicate classes).\n\n sparse_output : bool, default=False\n Set to True if output binary array is desired in CSR sparse format.\n\n Attributes\n ----------\n classes_ : ndarray of shape (n_classes,)\n A copy of the `classes` parameter when provided.\n Otherwise it corresponds to the sorted set of classes found\n when fitting.\n\n Examples\n --------\n >>> from sklearn.preprocessing import MultiLabelBinarizer\n >>> mlb = MultiLabelBinarizer()\n >>> mlb.fit_transform([(1, 2), (3,)])\n array([[1, 1, 0],\n [0, 0, 1]])\n >>> mlb.classes_\n array([1, 2, 3])\n\n >>> mlb.fit_transform([{'sci-fi', 'thriller'}, {'comedy'}])\n array([[0, 1, 1],\n [1, 0, 0]])\n >>> list(mlb.classes_)\n ['comedy', 'sci-fi', 'thriller']\n\n A common mistake is to pass in a list, which leads to the following issue:\n\n >>> mlb = MultiLabelBinarizer()\n >>> mlb.fit(['sci-fi', 'thriller', 'comedy'])\n MultiLabelBinarizer()\n >>> mlb.classes_\n array(['-', 'c', 'd', 'e', 'f', 'h', 'i', 'l', 'm', 'o', 'r', 's', 't',\n 'y'], dtype=object)\n\n To correct this, the list of labels should be passed in as:\n\n >>> mlb = MultiLabelBinarizer()\n >>> mlb.fit([['sci-fi', 'thriller', 'comedy']])\n MultiLabelBinarizer()\n >>> mlb.classes_\n array(['comedy', 'sci-fi', 'thriller'], dtype=object)\n\n See Also\n --------\n OneHotEncoder : Encode categorical features using a one-hot aka one-of-K\n scheme.\n ", - "source_code": "\n\nclass MultiLabelBinarizer(TransformerMixin, BaseEstimator):\n \"\"\"Transform between iterable of iterables and a multilabel format.\n\n Although a list of sets or tuples is a very intuitive format for multilabel\n data, it is unwieldy to process. This transformer converts between this\n intuitive format and the supported multilabel format: a (samples x classes)\n binary matrix indicating the presence of a class label.\n\n Parameters\n ----------\n classes : array-like of shape (n_classes,), default=None\n Indicates an ordering for the class labels.\n All entries should be unique (cannot contain duplicate classes).\n\n sparse_output : bool, default=False\n Set to True if output binary array is desired in CSR sparse format.\n\n Attributes\n ----------\n classes_ : ndarray of shape (n_classes,)\n A copy of the `classes` parameter when provided.\n Otherwise it corresponds to the sorted set of classes found\n when fitting.\n\n Examples\n --------\n >>> from sklearn.preprocessing import MultiLabelBinarizer\n >>> mlb = MultiLabelBinarizer()\n >>> mlb.fit_transform([(1, 2), (3,)])\n array([[1, 1, 0],\n [0, 0, 1]])\n >>> mlb.classes_\n array([1, 2, 3])\n\n >>> mlb.fit_transform([{'sci-fi', 'thriller'}, {'comedy'}])\n array([[0, 1, 1],\n [1, 0, 0]])\n >>> list(mlb.classes_)\n ['comedy', 'sci-fi', 'thriller']\n\n A common mistake is to pass in a list, which leads to the following issue:\n\n >>> mlb = MultiLabelBinarizer()\n >>> mlb.fit(['sci-fi', 'thriller', 'comedy'])\n MultiLabelBinarizer()\n >>> mlb.classes_\n array(['-', 'c', 'd', 'e', 'f', 'h', 'i', 'l', 'm', 'o', 'r', 's', 't',\n 'y'], dtype=object)\n\n To correct this, the list of labels should be passed in as:\n\n >>> mlb = MultiLabelBinarizer()\n >>> mlb.fit([['sci-fi', 'thriller', 'comedy']])\n MultiLabelBinarizer()\n >>> mlb.classes_\n array(['comedy', 'sci-fi', 'thriller'], dtype=object)\n\n See Also\n --------\n OneHotEncoder : Encode categorical features using a one-hot aka one-of-K\n scheme.\n \"\"\"\n \n def __init__(self, *, classes=None, sparse_output=False):\n self.classes = classes\n self.sparse_output = sparse_output\n \n def fit(self, y):\n \"\"\"Fit the label sets binarizer, storing :term:`classes_`.\n\n Parameters\n ----------\n y : iterable of iterables\n A set of labels (any orderable and hashable object) for each\n sample. If the `classes` parameter is set, `y` will not be\n iterated.\n\n Returns\n -------\n self : returns this MultiLabelBinarizer instance\n \"\"\"\n self._cached_dict = None\n if self.classes is None:\n classes = sorted(set(itertools.chain.from_iterable(y)))\n elif len(set(self.classes)) < len(self.classes):\n raise ValueError('The classes argument contains duplicate classes. Remove these duplicates before passing them to MultiLabelBinarizer.')\n else:\n classes = self.classes\n dtype = int if all((isinstance(c, int) for c in classes)) else object\n self.classes_ = np.empty(len(classes), dtype=dtype)\n self.classes_[:] = classes\n return self\n \n def fit_transform(self, y):\n \"\"\"Fit the label sets binarizer and transform the given label sets.\n\n Parameters\n ----------\n y : iterable of iterables\n A set of labels (any orderable and hashable object) for each\n sample. If the `classes` parameter is set, `y` will not be\n iterated.\n\n Returns\n -------\n y_indicator : {ndarray, sparse matrix} of shape (n_samples, n_classes)\n A matrix such that `y_indicator[i, j] = 1` i.f.f. `classes_[j]`\n is in `y[i]`, and 0 otherwise. Sparse matrix will be of CSR\n format.\n \"\"\"\n self._cached_dict = None\n if self.classes is not None:\n return self.fit(y).transform(y)\n class_mapping = defaultdict(int)\n class_mapping.default_factory = class_mapping.__len__\n yt = self._transform(y, class_mapping)\n tmp = sorted(class_mapping, key=class_mapping.get)\n dtype = int if all((isinstance(c, int) for c in tmp)) else object\n class_mapping = np.empty(len(tmp), dtype=dtype)\n class_mapping[:] = tmp\n (self.classes_, inverse) = np.unique(class_mapping, return_inverse=True)\n yt.indices = np.array(inverse[yt.indices], dtype=yt.indices.dtype, copy=False)\n if not self.sparse_output:\n yt = yt.toarray()\n return yt\n \n def transform(self, y):\n \"\"\"Transform the given label sets.\n\n Parameters\n ----------\n y : iterable of iterables\n A set of labels (any orderable and hashable object) for each\n sample. If the `classes` parameter is set, `y` will not be\n iterated.\n\n Returns\n -------\n y_indicator : array or CSR matrix, shape (n_samples, n_classes)\n A matrix such that `y_indicator[i, j] = 1` iff `classes_[j]` is in\n `y[i]`, and 0 otherwise.\n \"\"\"\n check_is_fitted(self)\n class_to_index = self._build_cache()\n yt = self._transform(y, class_to_index)\n if not self.sparse_output:\n yt = yt.toarray()\n return yt\n \n def _build_cache(self):\n if self._cached_dict is None:\n self._cached_dict = dict(zip(self.classes_, range(len(self.classes_))))\n return self._cached_dict\n \n def _transform(self, y, class_mapping):\n \"\"\"Transforms the label sets with a given mapping.\n\n Parameters\n ----------\n y : iterable of iterables\n class_mapping : Mapping\n Maps from label to column index in label indicator matrix.\n\n Returns\n -------\n y_indicator : sparse matrix of shape (n_samples, n_classes)\n Label indicator matrix. Will be of CSR format.\n \"\"\"\n indices = array.array('i')\n indptr = array.array('i', [0])\n unknown = set()\n for labels in y:\n index = set()\n for label in labels:\n try:\n index.add(class_mapping[label])\n except KeyError:\n unknown.add(label)\n indices.extend(index)\n indptr.append(len(indices))\n if unknown:\n warnings.warn('unknown class(es) {0} will be ignored'.format(sorted(unknown, key=str)))\n data = np.ones(len(indices), dtype=int)\n return sp.csr_matrix((data, indices, indptr), shape=(len(indptr) - 1, len(class_mapping)))\n \n def inverse_transform(self, yt):\n \"\"\"Transform the given indicator matrix into label sets.\n\n Parameters\n ----------\n yt : {ndarray, sparse matrix} of shape (n_samples, n_classes)\n A matrix containing only 1s ands 0s.\n\n Returns\n -------\n y : list of tuples\n The set of labels for each sample such that `y[i]` consists of\n `classes_[j]` for each `yt[i, j] == 1`.\n \"\"\"\n check_is_fitted(self)\n if yt.shape[1] != len(self.classes_):\n raise ValueError('Expected indicator for {0} classes, but got {1}'.format(len(self.classes_), yt.shape[1]))\n if sp.issparse(yt):\n yt = yt.tocsr()\n if len(yt.data) != 0 and len(np.setdiff1d(yt.data, [0, 1])) > 0:\n raise ValueError('Expected only 0s and 1s in label indicator.')\n return [tuple(self.classes_.take(yt.indices[start:end])) for (start, end) in zip(yt.indptr[:-1], yt.indptr[1:])]\n else:\n unexpected = np.setdiff1d(yt, [0, 1])\n if len(unexpected) > 0:\n raise ValueError('Expected only 0s and 1s in label indicator. Also got {0}'.format(unexpected))\n return [tuple(self.classes_.compress(indicators)) for indicators in yt]\n \n def _more_tags(self):\n return {'X_types': ['2dlabels']}\n" + "docstring": "Transform between iterable of iterables and a multilabel format.\n\n Although a list of sets or tuples is a very intuitive format for multilabel\n data, it is unwieldy to process. This transformer converts between this\n intuitive format and the supported multilabel format: a (samples x classes)\n binary matrix indicating the presence of a class label.\n\n Parameters\n ----------\n classes : array-like of shape (n_classes,), default=None\n Indicates an ordering for the class labels.\n All entries should be unique (cannot contain duplicate classes).\n\n sparse_output : bool, default=False\n Set to True if output binary array is desired in CSR sparse format.\n\n Attributes\n ----------\n classes_ : ndarray of shape (n_classes,)\n A copy of the `classes` parameter when provided.\n Otherwise it corresponds to the sorted set of classes found\n when fitting.\n\n See Also\n --------\n OneHotEncoder : Encode categorical features using a one-hot aka one-of-K\n scheme.\n\n Examples\n --------\n >>> from sklearn.preprocessing import MultiLabelBinarizer\n >>> mlb = MultiLabelBinarizer()\n >>> mlb.fit_transform([(1, 2), (3,)])\n array([[1, 1, 0],\n [0, 0, 1]])\n >>> mlb.classes_\n array([1, 2, 3])\n\n >>> mlb.fit_transform([{'sci-fi', 'thriller'}, {'comedy'}])\n array([[0, 1, 1],\n [1, 0, 0]])\n >>> list(mlb.classes_)\n ['comedy', 'sci-fi', 'thriller']\n\n A common mistake is to pass in a list, which leads to the following issue:\n\n >>> mlb = MultiLabelBinarizer()\n >>> mlb.fit(['sci-fi', 'thriller', 'comedy'])\n MultiLabelBinarizer()\n >>> mlb.classes_\n array(['-', 'c', 'd', 'e', 'f', 'h', 'i', 'l', 'm', 'o', 'r', 's', 't',\n 'y'], dtype=object)\n\n To correct this, the list of labels should be passed in as:\n\n >>> mlb = MultiLabelBinarizer()\n >>> mlb.fit([['sci-fi', 'thriller', 'comedy']])\n MultiLabelBinarizer()\n >>> mlb.classes_\n array(['comedy', 'sci-fi', 'thriller'], dtype=object)\n ", + "source_code": "\n\nclass MultiLabelBinarizer(TransformerMixin, BaseEstimator):\n \"\"\"Transform between iterable of iterables and a multilabel format.\n\n Although a list of sets or tuples is a very intuitive format for multilabel\n data, it is unwieldy to process. This transformer converts between this\n intuitive format and the supported multilabel format: a (samples x classes)\n binary matrix indicating the presence of a class label.\n\n Parameters\n ----------\n classes : array-like of shape (n_classes,), default=None\n Indicates an ordering for the class labels.\n All entries should be unique (cannot contain duplicate classes).\n\n sparse_output : bool, default=False\n Set to True if output binary array is desired in CSR sparse format.\n\n Attributes\n ----------\n classes_ : ndarray of shape (n_classes,)\n A copy of the `classes` parameter when provided.\n Otherwise it corresponds to the sorted set of classes found\n when fitting.\n\n See Also\n --------\n OneHotEncoder : Encode categorical features using a one-hot aka one-of-K\n scheme.\n\n Examples\n --------\n >>> from sklearn.preprocessing import MultiLabelBinarizer\n >>> mlb = MultiLabelBinarizer()\n >>> mlb.fit_transform([(1, 2), (3,)])\n array([[1, 1, 0],\n [0, 0, 1]])\n >>> mlb.classes_\n array([1, 2, 3])\n\n >>> mlb.fit_transform([{'sci-fi', 'thriller'}, {'comedy'}])\n array([[0, 1, 1],\n [1, 0, 0]])\n >>> list(mlb.classes_)\n ['comedy', 'sci-fi', 'thriller']\n\n A common mistake is to pass in a list, which leads to the following issue:\n\n >>> mlb = MultiLabelBinarizer()\n >>> mlb.fit(['sci-fi', 'thriller', 'comedy'])\n MultiLabelBinarizer()\n >>> mlb.classes_\n array(['-', 'c', 'd', 'e', 'f', 'h', 'i', 'l', 'm', 'o', 'r', 's', 't',\n 'y'], dtype=object)\n\n To correct this, the list of labels should be passed in as:\n\n >>> mlb = MultiLabelBinarizer()\n >>> mlb.fit([['sci-fi', 'thriller', 'comedy']])\n MultiLabelBinarizer()\n >>> mlb.classes_\n array(['comedy', 'sci-fi', 'thriller'], dtype=object)\n \"\"\"\n \n def __init__(self, *, classes=None, sparse_output=False):\n self.classes = classes\n self.sparse_output = sparse_output\n \n def fit(self, y):\n \"\"\"Fit the label sets binarizer, storing :term:`classes_`.\n\n Parameters\n ----------\n y : iterable of iterables\n A set of labels (any orderable and hashable object) for each\n sample. If the `classes` parameter is set, `y` will not be\n iterated.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n self._cached_dict = None\n if self.classes is None:\n classes = sorted(set(itertools.chain.from_iterable(y)))\n elif len(set(self.classes)) < len(self.classes):\n raise ValueError('The classes argument contains duplicate classes. Remove these duplicates before passing them to MultiLabelBinarizer.')\n else:\n classes = self.classes\n dtype = int if all((isinstance(c, int) for c in classes)) else object\n self.classes_ = np.empty(len(classes), dtype=dtype)\n self.classes_[:] = classes\n return self\n \n def fit_transform(self, y):\n \"\"\"Fit the label sets binarizer and transform the given label sets.\n\n Parameters\n ----------\n y : iterable of iterables\n A set of labels (any orderable and hashable object) for each\n sample. If the `classes` parameter is set, `y` will not be\n iterated.\n\n Returns\n -------\n y_indicator : {ndarray, sparse matrix} of shape (n_samples, n_classes)\n A matrix such that `y_indicator[i, j] = 1` iff `classes_[j]`\n is in `y[i]`, and 0 otherwise. Sparse matrix will be of CSR\n format.\n \"\"\"\n self._cached_dict = None\n if self.classes is not None:\n return self.fit(y).transform(y)\n class_mapping = defaultdict(int)\n class_mapping.default_factory = class_mapping.__len__\n yt = self._transform(y, class_mapping)\n tmp = sorted(class_mapping, key=class_mapping.get)\n dtype = int if all((isinstance(c, int) for c in tmp)) else object\n class_mapping = np.empty(len(tmp), dtype=dtype)\n class_mapping[:] = tmp\n (self.classes_, inverse) = np.unique(class_mapping, return_inverse=True)\n yt.indices = np.array(inverse[yt.indices], dtype=yt.indices.dtype, copy=False)\n if not self.sparse_output:\n yt = yt.toarray()\n return yt\n \n def transform(self, y):\n \"\"\"Transform the given label sets.\n\n Parameters\n ----------\n y : iterable of iterables\n A set of labels (any orderable and hashable object) for each\n sample. If the `classes` parameter is set, `y` will not be\n iterated.\n\n Returns\n -------\n y_indicator : array or CSR matrix, shape (n_samples, n_classes)\n A matrix such that `y_indicator[i, j] = 1` iff `classes_[j]` is in\n `y[i]`, and 0 otherwise.\n \"\"\"\n check_is_fitted(self)\n class_to_index = self._build_cache()\n yt = self._transform(y, class_to_index)\n if not self.sparse_output:\n yt = yt.toarray()\n return yt\n \n def _build_cache(self):\n if self._cached_dict is None:\n self._cached_dict = dict(zip(self.classes_, range(len(self.classes_))))\n return self._cached_dict\n \n def _transform(self, y, class_mapping):\n \"\"\"Transforms the label sets with a given mapping.\n\n Parameters\n ----------\n y : iterable of iterables\n A set of labels (any orderable and hashable object) for each\n sample. If the `classes` parameter is set, `y` will not be\n iterated.\n\n class_mapping : Mapping\n Maps from label to column index in label indicator matrix.\n\n Returns\n -------\n y_indicator : sparse matrix of shape (n_samples, n_classes)\n Label indicator matrix. Will be of CSR format.\n \"\"\"\n indices = array.array('i')\n indptr = array.array('i', [0])\n unknown = set()\n for labels in y:\n index = set()\n for label in labels:\n try:\n index.add(class_mapping[label])\n except KeyError:\n unknown.add(label)\n indices.extend(index)\n indptr.append(len(indices))\n if unknown:\n warnings.warn('unknown class(es) {0} will be ignored'.format(sorted(unknown, key=str)))\n data = np.ones(len(indices), dtype=int)\n return sp.csr_matrix((data, indices, indptr), shape=(len(indptr) - 1, len(class_mapping)))\n \n def inverse_transform(self, yt):\n \"\"\"Transform the given indicator matrix into label sets.\n\n Parameters\n ----------\n yt : {ndarray, sparse matrix} of shape (n_samples, n_classes)\n A matrix containing only 1s ands 0s.\n\n Returns\n -------\n y : list of tuples\n The set of labels for each sample such that `y[i]` consists of\n `classes_[j]` for each `yt[i, j] == 1`.\n \"\"\"\n check_is_fitted(self)\n if yt.shape[1] != len(self.classes_):\n raise ValueError('Expected indicator for {0} classes, but got {1}'.format(len(self.classes_), yt.shape[1]))\n if sp.issparse(yt):\n yt = yt.tocsr()\n if len(yt.data) != 0 and len(np.setdiff1d(yt.data, [0, 1])) > 0:\n raise ValueError('Expected only 0s and 1s in label indicator.')\n return [tuple(self.classes_.take(yt.indices[start:end])) for (start, end) in zip(yt.indptr[:-1], yt.indptr[1:])]\n else:\n unexpected = np.setdiff1d(yt, [0, 1])\n if len(unexpected) > 0:\n raise ValueError('Expected only 0s and 1s in label indicator. Also got {0}'.format(unexpected))\n return [tuple(self.classes_.compress(indicators)) for indicators in yt]\n \n def _more_tags(self):\n return {'X_types': ['2dlabels']}\n" }, { "name": "PolynomialFeatures", @@ -26198,17 +26151,17 @@ "sklearn.preprocessing._polynomial.PolynomialFeatures.__init__", "sklearn.preprocessing._polynomial.PolynomialFeatures._combinations", "sklearn.preprocessing._polynomial.PolynomialFeatures._num_combinations", - "sklearn.preprocessing._polynomial.PolynomialFeatures.powers_", + "sklearn.preprocessing._polynomial.PolynomialFeatures.powers_@getter", "sklearn.preprocessing._polynomial.PolynomialFeatures.get_feature_names", "sklearn.preprocessing._polynomial.PolynomialFeatures.get_feature_names_out", "sklearn.preprocessing._polynomial.PolynomialFeatures.fit", "sklearn.preprocessing._polynomial.PolynomialFeatures.transform", - "sklearn.preprocessing._polynomial.PolynomialFeatures.n_input_features_" + "sklearn.preprocessing._polynomial.PolynomialFeatures.n_input_features_@getter" ], "is_public": true, "description": "Generate polynomial and interaction features.\n\nGenerate a new feature matrix consisting of all polynomial combinations of the features with degree less than or equal to the specified degree. For example, if an input sample is two dimensional and of the form [a, b], the degree-2 polynomial features are [1, a, b, a^2, ab, b^2]. Read more in the :ref:`User Guide `.", - "docstring": "Generate polynomial and interaction features.\n\n Generate a new feature matrix consisting of all polynomial combinations\n of the features with degree less than or equal to the specified degree.\n For example, if an input sample is two dimensional and of the form\n [a, b], the degree-2 polynomial features are [1, a, b, a^2, ab, b^2].\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n degree : int or tuple (min_degree, max_degree), default=2\n If a single int is given, it specifies the maximal degree of the\n polynomial features. If a tuple ``(min_degree, max_degree)`` is\n passed, then ``min_degree`` is the minimum and ``max_degree`` is the\n maximum polynomial degree of the generated features. Note that\n min_degree=0 and 1 are equivalent as outputting the degree zero term\n is determined by ``include_bias``.\n\n interaction_only : bool, default=False\n If true, only interaction features are produced: features that are\n products of at most ``degree`` *distinct* input features, i.e. terms\n with power of 2 or higher of the same input feature are excluded:\n\n - included: ``x[0]``, `x[1]`, ``x[0] * x[1]``, etc.\n - excluded: ``x[0] ** 2``, ``x[0] ** 2 * x[1]``, etc.\n\n include_bias : bool, default=True\n If True (default), then include a bias column, the feature in which\n all polynomial powers are zero (i.e. a column of ones - acts as an\n intercept term in a linear model).\n\n order : {'C', 'F'}, default='C'\n Order of output array in the dense case. 'F' order is faster to\n compute, but may slow down subsequent estimators.\n\n .. versionadded:: 0.21\n\n Attributes\n ----------\n powers_ : ndarray of shape (`n_output_features_`, `n_features_in_`)\n powers_[i, j] is the exponent of the jth input in the ith output.\n\n n_input_features_ : int\n The total number of input features.\n\n .. deprecated:: 1.0\n This attribute is deprecated in 1.0 and will be removed in 1.2.\n Refer to `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_output_features_ : int\n The total number of polynomial output features. The number of output\n features is computed by iterating over all suitably sized combinations\n of input features.\n\n See Also\n --------\n SplineTransformer : Transformer that generates univariate B-spline bases\n for features\n\n Notes\n -----\n Be aware that the number of features in the output array scales\n polynomially in the number of features of the input array, and\n exponentially in the degree. High degrees can cause overfitting.\n\n See :ref:`examples/linear_model/plot_polynomial_interpolation.py\n `\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.preprocessing import PolynomialFeatures\n >>> X = np.arange(6).reshape(3, 2)\n >>> X\n array([[0, 1],\n [2, 3],\n [4, 5]])\n >>> poly = PolynomialFeatures(2)\n >>> poly.fit_transform(X)\n array([[ 1., 0., 1., 0., 0., 1.],\n [ 1., 2., 3., 4., 6., 9.],\n [ 1., 4., 5., 16., 20., 25.]])\n >>> poly = PolynomialFeatures(interaction_only=True)\n >>> poly.fit_transform(X)\n array([[ 1., 0., 1., 0.],\n [ 1., 2., 3., 6.],\n [ 1., 4., 5., 20.]])\n ", - "source_code": "\n\nclass PolynomialFeatures(TransformerMixin, BaseEstimator):\n \"\"\"Generate polynomial and interaction features.\n\n Generate a new feature matrix consisting of all polynomial combinations\n of the features with degree less than or equal to the specified degree.\n For example, if an input sample is two dimensional and of the form\n [a, b], the degree-2 polynomial features are [1, a, b, a^2, ab, b^2].\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n degree : int or tuple (min_degree, max_degree), default=2\n If a single int is given, it specifies the maximal degree of the\n polynomial features. If a tuple ``(min_degree, max_degree)`` is\n passed, then ``min_degree`` is the minimum and ``max_degree`` is the\n maximum polynomial degree of the generated features. Note that\n min_degree=0 and 1 are equivalent as outputting the degree zero term\n is determined by ``include_bias``.\n\n interaction_only : bool, default=False\n If true, only interaction features are produced: features that are\n products of at most ``degree`` *distinct* input features, i.e. terms\n with power of 2 or higher of the same input feature are excluded:\n\n - included: ``x[0]``, `x[1]`, ``x[0] * x[1]``, etc.\n - excluded: ``x[0] ** 2``, ``x[0] ** 2 * x[1]``, etc.\n\n include_bias : bool, default=True\n If True (default), then include a bias column, the feature in which\n all polynomial powers are zero (i.e. a column of ones - acts as an\n intercept term in a linear model).\n\n order : {'C', 'F'}, default='C'\n Order of output array in the dense case. 'F' order is faster to\n compute, but may slow down subsequent estimators.\n\n .. versionadded:: 0.21\n\n Attributes\n ----------\n powers_ : ndarray of shape (`n_output_features_`, `n_features_in_`)\n powers_[i, j] is the exponent of the jth input in the ith output.\n\n n_input_features_ : int\n The total number of input features.\n\n .. deprecated:: 1.0\n This attribute is deprecated in 1.0 and will be removed in 1.2.\n Refer to `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_output_features_ : int\n The total number of polynomial output features. The number of output\n features is computed by iterating over all suitably sized combinations\n of input features.\n\n See Also\n --------\n SplineTransformer : Transformer that generates univariate B-spline bases\n for features\n\n Notes\n -----\n Be aware that the number of features in the output array scales\n polynomially in the number of features of the input array, and\n exponentially in the degree. High degrees can cause overfitting.\n\n See :ref:`examples/linear_model/plot_polynomial_interpolation.py\n `\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.preprocessing import PolynomialFeatures\n >>> X = np.arange(6).reshape(3, 2)\n >>> X\n array([[0, 1],\n [2, 3],\n [4, 5]])\n >>> poly = PolynomialFeatures(2)\n >>> poly.fit_transform(X)\n array([[ 1., 0., 1., 0., 0., 1.],\n [ 1., 2., 3., 4., 6., 9.],\n [ 1., 4., 5., 16., 20., 25.]])\n >>> poly = PolynomialFeatures(interaction_only=True)\n >>> poly.fit_transform(X)\n array([[ 1., 0., 1., 0.],\n [ 1., 2., 3., 6.],\n [ 1., 4., 5., 20.]])\n \"\"\"\n \n def __init__(self, degree=2, *, interaction_only=False, include_bias=True, order='C'):\n self.degree = degree\n self.interaction_only = interaction_only\n self.include_bias = include_bias\n self.order = order\n \n @staticmethod\n def _combinations(n_features, min_degree, max_degree, interaction_only, include_bias):\n comb = combinations if interaction_only else combinations_w_r\n start = max(1, min_degree)\n iter = chain.from_iterable((comb(range(n_features), i) for i in range(start, max_degree + 1)))\n if include_bias:\n iter = chain(comb(range(n_features), 0), iter)\n return iter\n \n @staticmethod\n def _num_combinations(n_features, min_degree, max_degree, interaction_only, include_bias):\n \"\"\"Calculate number of terms in polynomial expansion\n\n This should be equivalent to counting the number of terms returned by\n _combinations(...) but much faster.\n \"\"\"\n if interaction_only:\n combinations = sum([comb(n_features, i, exact=True) for i in range(max(1, min_degree), min(max_degree, n_features) + 1)])\n else:\n combinations = comb(n_features + max_degree, max_degree, exact=True) - 1\n if min_degree > 0:\n d = min_degree - 1\n combinations -= comb(n_features + d, d, exact=True) - 1\n if include_bias:\n combinations += 1\n return combinations\n \n @property\n def powers_(self):\n check_is_fitted(self)\n combinations = self._combinations(n_features=self.n_features_in_, min_degree=self._min_degree, max_degree=self._max_degree, interaction_only=self.interaction_only, include_bias=self.include_bias)\n return np.vstack([np.bincount(c, minlength=self.n_features_in_) for c in combinations])\n \n @deprecated('get_feature_names is deprecated in 1.0 and will be removed in 1.2. Please use get_feature_names_out instead.')\n def get_feature_names(self, input_features=None):\n \"\"\"\n Return feature names for output features\n\n Parameters\n ----------\n input_features : list of str of shape (n_features,), default=None\n String names for input features if available. By default,\n \"x0\", \"x1\", ... \"xn_features\" is used.\n\n Returns\n -------\n output_feature_names : list of str of shape (n_output_features,)\n \"\"\"\n powers = self.powers_\n if input_features is None:\n input_features = ['x%d' % i for i in range(powers.shape[1])]\n feature_names = []\n for row in powers:\n inds = np.where(row)[0]\n if len(inds):\n name = ' '.join(('%s^%d' % (input_features[ind], exp) if exp != 1 else input_features[ind] for (ind, exp) in zip(inds, row[inds])))\n else:\n name = '1'\n feature_names.append(name)\n return feature_names\n \n def get_feature_names_out(self, input_features=None):\n \"\"\"Get output feature names for transformation.\n\n Parameters\n ----------\n input_features : array-like of str or None, default=None\n Input features.\n\n - If `input_features` is `None`, then `feature_names_in_` is\n used as feature names in. If `feature_names_in_` is not defined,\n then names are generated: `[x0, x1, ..., x(n_features_in_)]`.\n - If `input_features` is an array-like, then `input_features` must\n match `feature_names_in_` if `feature_names_in_` is defined.\n\n Returns\n -------\n feature_names_out : ndarray of str objects\n Transformed feature names.\n \"\"\"\n powers = self.powers_\n input_features = _check_feature_names_in(self, input_features)\n feature_names = []\n for row in powers:\n inds = np.where(row)[0]\n if len(inds):\n name = ' '.join(('%s^%d' % (input_features[ind], exp) if exp != 1 else input_features[ind] for (ind, exp) in zip(inds, row[inds])))\n else:\n name = '1'\n feature_names.append(name)\n return np.asarray(feature_names, dtype=object)\n \n def fit(self, X, y=None):\n \"\"\"\n Compute number of output features.\n\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The data.\n\n y : None\n Ignored.\n\n Returns\n -------\n self : object\n Fitted transformer.\n \"\"\"\n (_, n_features) = self._validate_data(X, accept_sparse=True).shape\n if isinstance(self.degree, numbers.Integral):\n if self.degree < 0:\n raise ValueError(f'degree must be a non-negative integer, got {self.degree}.')\n self._min_degree = 0\n self._max_degree = self.degree\n elif isinstance(self.degree, collections.abc.Iterable) and len(self.degree) == 2:\n (self._min_degree, self._max_degree) = self.degree\n if not (isinstance(self._min_degree, numbers.Integral) and isinstance(self._max_degree, numbers.Integral) and self._min_degree >= 0 and self._min_degree <= self._max_degree):\n raise ValueError(f'degree=(min_degree, max_degree) must be non-negative integers that fulfil min_degree <= max_degree, got {self.degree}.')\n else:\n raise ValueError(f'degree must be a non-negative int or tuple (min_degree, max_degree), got {self.degree}.')\n self.n_output_features_ = self._num_combinations(n_features=n_features, min_degree=self._min_degree, max_degree=self._max_degree, interaction_only=self.interaction_only, include_bias=self.include_bias)\n self._n_out_full = self._num_combinations(n_features=n_features, min_degree=0, max_degree=self._max_degree, interaction_only=self.interaction_only, include_bias=self.include_bias)\n return self\n \n def transform(self, X):\n \"\"\"Transform data to polynomial features.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The data to transform, row by row.\n\n Prefer CSR over CSC for sparse input (for speed), but CSC is\n required if the degree is 4 or higher. If the degree is less than\n 4 and the input format is CSC, it will be converted to CSR, have\n its polynomial features generated, then converted back to CSC.\n\n If the degree is 2 or 3, the method described in \"Leveraging\n Sparsity to Speed Up Polynomial Feature Expansions of CSR Matrices\n Using K-Simplex Numbers\" by Andrew Nystrom and John Hughes is\n used, which is much faster than the method used on CSC input. For\n this reason, a CSC input will be converted to CSR, and the output\n will be converted back to CSC prior to being returned, hence the\n preference of CSR.\n\n Returns\n -------\n XP : {ndarray, sparse matrix} of shape (n_samples, NP)\n The matrix of features, where NP is the number of polynomial\n features generated from the combination of inputs. If a sparse\n matrix is provided, it will be converted into a sparse\n ``csr_matrix``.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, order='F', dtype=FLOAT_DTYPES, reset=False, accept_sparse=('csr', 'csc'))\n (n_samples, n_features) = X.shape\n if sparse.isspmatrix_csr(X):\n if self._max_degree > 3:\n return self.transform(X.tocsc()).tocsr()\n to_stack = []\n if self.include_bias:\n to_stack.append(sparse.csc_matrix(np.ones(shape=(n_samples, 1), dtype=X.dtype)))\n if self._min_degree <= 1:\n to_stack.append(X)\n for deg in range(max(2, self._min_degree), self._max_degree + 1):\n Xp_next = _csr_polynomial_expansion(X.data, X.indices, X.indptr, X.shape[1], self.interaction_only, deg)\n if Xp_next is None:\n break\n to_stack.append(Xp_next)\n if len(to_stack) == 0:\n XP = sparse.csr_matrix((n_samples, 0), dtype=X.dtype)\n else:\n XP = sparse.hstack(to_stack, format='csr')\n elif sparse.isspmatrix_csc(X) and self._max_degree < 4:\n return self.transform(X.tocsr()).tocsc()\n elif sparse.isspmatrix(X):\n combinations = self._combinations(n_features=n_features, min_degree=self._min_degree, max_degree=self._max_degree, interaction_only=self.interaction_only, include_bias=self.include_bias)\n columns = []\n for combi in combinations:\n if combi:\n out_col = 1\n for col_idx in combi:\n out_col = X[:, col_idx].multiply(out_col)\n columns.append(out_col)\n else:\n bias = sparse.csc_matrix(np.ones((X.shape[0], 1)))\n columns.append(bias)\n XP = sparse.hstack(columns, dtype=X.dtype).tocsc()\n else:\n XP = np.empty(shape=(n_samples, self._n_out_full), dtype=X.dtype, order=self.order)\n if self.include_bias:\n XP[:, 0] = 1\n current_col = 1\n else:\n current_col = 0\n XP[:, current_col:current_col + n_features] = X\n index = list(range(current_col, current_col + n_features))\n current_col += n_features\n index.append(current_col)\n for _ in range(2, self._max_degree + 1):\n new_index = []\n end = index[-1]\n for feature_idx in range(n_features):\n start = index[feature_idx]\n new_index.append(current_col)\n if self.interaction_only:\n start += index[feature_idx + 1] - index[feature_idx]\n next_col = current_col + end - start\n if next_col <= current_col:\n break\n np.multiply(XP[:, start:end], X[:, feature_idx:feature_idx + 1], out=XP[:, current_col:next_col], casting='no')\n current_col = next_col\n new_index.append(current_col)\n index = new_index\n if self._min_degree > 1:\n (n_XP, n_Xout) = (self._n_out_full, self.n_output_features_)\n if self.include_bias:\n Xout = np.empty(shape=(n_samples, n_Xout), dtype=XP.dtype, order=self.order)\n Xout[:, 0] = 1\n Xout[:, 1:] = XP[:, n_XP - n_Xout + 1:]\n else:\n Xout = XP[:, n_XP - n_Xout:].copy()\n XP = Xout\n return XP\n \n @deprecated('The attribute `n_input_features_` was deprecated in version 1.0 and will be removed in 1.2.')\n @property\n def n_input_features_(self):\n return self.n_features_in_\n" + "docstring": "Generate polynomial and interaction features.\n\n Generate a new feature matrix consisting of all polynomial combinations\n of the features with degree less than or equal to the specified degree.\n For example, if an input sample is two dimensional and of the form\n [a, b], the degree-2 polynomial features are [1, a, b, a^2, ab, b^2].\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n degree : int or tuple (min_degree, max_degree), default=2\n If a single int is given, it specifies the maximal degree of the\n polynomial features. If a tuple `(min_degree, max_degree)` is passed,\n then `min_degree` is the minimum and `max_degree` is the maximum\n polynomial degree of the generated features. Note that `min_degree=0`\n and `min_degree=1` are equivalent as outputting the degree zero term is\n determined by `include_bias`.\n\n interaction_only : bool, default=False\n If `True`, only interaction features are produced: features that are\n products of at most `degree` *distinct* input features, i.e. terms with\n power of 2 or higher of the same input feature are excluded:\n\n - included: `x[0]`, `x[1]`, `x[0] * x[1]`, etc.\n - excluded: `x[0] ** 2`, `x[0] ** 2 * x[1]`, etc.\n\n include_bias : bool, default=True\n If `True` (default), then include a bias column, the feature in which\n all polynomial powers are zero (i.e. a column of ones - acts as an\n intercept term in a linear model).\n\n order : {'C', 'F'}, default='C'\n Order of output array in the dense case. `'F'` order is faster to\n compute, but may slow down subsequent estimators.\n\n .. versionadded:: 0.21\n\n Attributes\n ----------\n powers_ : ndarray of shape (`n_output_features_`, `n_features_in_`)\n `powers_[i, j]` is the exponent of the jth input in the ith output.\n\n n_input_features_ : int\n The total number of input features.\n\n .. deprecated:: 1.0\n This attribute is deprecated in 1.0 and will be removed in 1.2.\n Refer to `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_output_features_ : int\n The total number of polynomial output features. The number of output\n features is computed by iterating over all suitably sized combinations\n of input features.\n\n See Also\n --------\n SplineTransformer : Transformer that generates univariate B-spline bases\n for features.\n\n Notes\n -----\n Be aware that the number of features in the output array scales\n polynomially in the number of features of the input array, and\n exponentially in the degree. High degrees can cause overfitting.\n\n See :ref:`examples/linear_model/plot_polynomial_interpolation.py\n `\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.preprocessing import PolynomialFeatures\n >>> X = np.arange(6).reshape(3, 2)\n >>> X\n array([[0, 1],\n [2, 3],\n [4, 5]])\n >>> poly = PolynomialFeatures(2)\n >>> poly.fit_transform(X)\n array([[ 1., 0., 1., 0., 0., 1.],\n [ 1., 2., 3., 4., 6., 9.],\n [ 1., 4., 5., 16., 20., 25.]])\n >>> poly = PolynomialFeatures(interaction_only=True)\n >>> poly.fit_transform(X)\n array([[ 1., 0., 1., 0.],\n [ 1., 2., 3., 6.],\n [ 1., 4., 5., 20.]])\n ", + "source_code": "\n\nclass PolynomialFeatures(TransformerMixin, BaseEstimator):\n \"\"\"Generate polynomial and interaction features.\n\n Generate a new feature matrix consisting of all polynomial combinations\n of the features with degree less than or equal to the specified degree.\n For example, if an input sample is two dimensional and of the form\n [a, b], the degree-2 polynomial features are [1, a, b, a^2, ab, b^2].\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n degree : int or tuple (min_degree, max_degree), default=2\n If a single int is given, it specifies the maximal degree of the\n polynomial features. If a tuple `(min_degree, max_degree)` is passed,\n then `min_degree` is the minimum and `max_degree` is the maximum\n polynomial degree of the generated features. Note that `min_degree=0`\n and `min_degree=1` are equivalent as outputting the degree zero term is\n determined by `include_bias`.\n\n interaction_only : bool, default=False\n If `True`, only interaction features are produced: features that are\n products of at most `degree` *distinct* input features, i.e. terms with\n power of 2 or higher of the same input feature are excluded:\n\n - included: `x[0]`, `x[1]`, `x[0] * x[1]`, etc.\n - excluded: `x[0] ** 2`, `x[0] ** 2 * x[1]`, etc.\n\n include_bias : bool, default=True\n If `True` (default), then include a bias column, the feature in which\n all polynomial powers are zero (i.e. a column of ones - acts as an\n intercept term in a linear model).\n\n order : {'C', 'F'}, default='C'\n Order of output array in the dense case. `'F'` order is faster to\n compute, but may slow down subsequent estimators.\n\n .. versionadded:: 0.21\n\n Attributes\n ----------\n powers_ : ndarray of shape (`n_output_features_`, `n_features_in_`)\n `powers_[i, j]` is the exponent of the jth input in the ith output.\n\n n_input_features_ : int\n The total number of input features.\n\n .. deprecated:: 1.0\n This attribute is deprecated in 1.0 and will be removed in 1.2.\n Refer to `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_output_features_ : int\n The total number of polynomial output features. The number of output\n features is computed by iterating over all suitably sized combinations\n of input features.\n\n See Also\n --------\n SplineTransformer : Transformer that generates univariate B-spline bases\n for features.\n\n Notes\n -----\n Be aware that the number of features in the output array scales\n polynomially in the number of features of the input array, and\n exponentially in the degree. High degrees can cause overfitting.\n\n See :ref:`examples/linear_model/plot_polynomial_interpolation.py\n `\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.preprocessing import PolynomialFeatures\n >>> X = np.arange(6).reshape(3, 2)\n >>> X\n array([[0, 1],\n [2, 3],\n [4, 5]])\n >>> poly = PolynomialFeatures(2)\n >>> poly.fit_transform(X)\n array([[ 1., 0., 1., 0., 0., 1.],\n [ 1., 2., 3., 4., 6., 9.],\n [ 1., 4., 5., 16., 20., 25.]])\n >>> poly = PolynomialFeatures(interaction_only=True)\n >>> poly.fit_transform(X)\n array([[ 1., 0., 1., 0.],\n [ 1., 2., 3., 6.],\n [ 1., 4., 5., 20.]])\n \"\"\"\n \n def __init__(self, degree=2, *, interaction_only=False, include_bias=True, order='C'):\n self.degree = degree\n self.interaction_only = interaction_only\n self.include_bias = include_bias\n self.order = order\n \n @staticmethod\n def _combinations(n_features, min_degree, max_degree, interaction_only, include_bias):\n comb = combinations if interaction_only else combinations_w_r\n start = max(1, min_degree)\n iter = chain.from_iterable((comb(range(n_features), i) for i in range(start, max_degree + 1)))\n if include_bias:\n iter = chain(comb(range(n_features), 0), iter)\n return iter\n \n @staticmethod\n def _num_combinations(n_features, min_degree, max_degree, interaction_only, include_bias):\n \"\"\"Calculate number of terms in polynomial expansion\n\n This should be equivalent to counting the number of terms returned by\n _combinations(...) but much faster.\n \"\"\"\n if interaction_only:\n combinations = sum([comb(n_features, i, exact=True) for i in range(max(1, min_degree), min(max_degree, n_features) + 1)])\n else:\n combinations = comb(n_features + max_degree, max_degree, exact=True) - 1\n if min_degree > 0:\n d = min_degree - 1\n combinations -= comb(n_features + d, d, exact=True) - 1\n if include_bias:\n combinations += 1\n return combinations\n \n @property\n def powers_(self):\n \"\"\"Exponent for each of the inputs in the output.\"\"\"\n check_is_fitted(self)\n combinations = self._combinations(n_features=self.n_features_in_, min_degree=self._min_degree, max_degree=self._max_degree, interaction_only=self.interaction_only, include_bias=self.include_bias)\n return np.vstack([np.bincount(c, minlength=self.n_features_in_) for c in combinations])\n \n @deprecated('get_feature_names is deprecated in 1.0 and will be removed in 1.2. Please use get_feature_names_out instead.')\n def get_feature_names(self, input_features=None):\n \"\"\"Return feature names for output features.\n\n Parameters\n ----------\n input_features : list of str of shape (n_features,), default=None\n String names for input features if available. By default,\n \"x0\", \"x1\", ... \"xn_features\" is used.\n\n Returns\n -------\n output_feature_names : list of str of shape (n_output_features,)\n Transformed feature names.\n \"\"\"\n powers = self.powers_\n if input_features is None:\n input_features = ['x%d' % i for i in range(powers.shape[1])]\n feature_names = []\n for row in powers:\n inds = np.where(row)[0]\n if len(inds):\n name = ' '.join(('%s^%d' % (input_features[ind], exp) if exp != 1 else input_features[ind] for (ind, exp) in zip(inds, row[inds])))\n else:\n name = '1'\n feature_names.append(name)\n return feature_names\n \n def get_feature_names_out(self, input_features=None):\n \"\"\"Get output feature names for transformation.\n\n Parameters\n ----------\n input_features : array-like of str or None, default=None\n Input features.\n\n - If `input_features is None`, then `feature_names_in_` is\n used as feature names in. If `feature_names_in_` is not defined,\n then names are generated: `[x0, x1, ..., x(n_features_in_)]`.\n - If `input_features` is an array-like, then `input_features` must\n match `feature_names_in_` if `feature_names_in_` is defined.\n\n Returns\n -------\n feature_names_out : ndarray of str objects\n Transformed feature names.\n \"\"\"\n powers = self.powers_\n input_features = _check_feature_names_in(self, input_features)\n feature_names = []\n for row in powers:\n inds = np.where(row)[0]\n if len(inds):\n name = ' '.join(('%s^%d' % (input_features[ind], exp) if exp != 1 else input_features[ind] for (ind, exp) in zip(inds, row[inds])))\n else:\n name = '1'\n feature_names.append(name)\n return np.asarray(feature_names, dtype=object)\n \n def fit(self, X, y=None):\n \"\"\"\n Compute number of output features.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The data.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self : object\n Fitted transformer.\n \"\"\"\n (_, n_features) = self._validate_data(X, accept_sparse=True).shape\n if isinstance(self.degree, numbers.Integral):\n if self.degree < 0:\n raise ValueError(f'degree must be a non-negative integer, got {self.degree}.')\n self._min_degree = 0\n self._max_degree = self.degree\n elif isinstance(self.degree, collections.abc.Iterable) and len(self.degree) == 2:\n (self._min_degree, self._max_degree) = self.degree\n if not (isinstance(self._min_degree, numbers.Integral) and isinstance(self._max_degree, numbers.Integral) and self._min_degree >= 0 and self._min_degree <= self._max_degree):\n raise ValueError(f'degree=(min_degree, max_degree) must be non-negative integers that fulfil min_degree <= max_degree, got {self.degree}.')\n else:\n raise ValueError(f'degree must be a non-negative int or tuple (min_degree, max_degree), got {self.degree}.')\n self.n_output_features_ = self._num_combinations(n_features=n_features, min_degree=self._min_degree, max_degree=self._max_degree, interaction_only=self.interaction_only, include_bias=self.include_bias)\n self._n_out_full = self._num_combinations(n_features=n_features, min_degree=0, max_degree=self._max_degree, interaction_only=self.interaction_only, include_bias=self.include_bias)\n return self\n \n def transform(self, X):\n \"\"\"Transform data to polynomial features.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The data to transform, row by row.\n\n Prefer CSR over CSC for sparse input (for speed), but CSC is\n required if the degree is 4 or higher. If the degree is less than\n 4 and the input format is CSC, it will be converted to CSR, have\n its polynomial features generated, then converted back to CSC.\n\n If the degree is 2 or 3, the method described in \"Leveraging\n Sparsity to Speed Up Polynomial Feature Expansions of CSR Matrices\n Using K-Simplex Numbers\" by Andrew Nystrom and John Hughes is\n used, which is much faster than the method used on CSC input. For\n this reason, a CSC input will be converted to CSR, and the output\n will be converted back to CSC prior to being returned, hence the\n preference of CSR.\n\n Returns\n -------\n XP : {ndarray, sparse matrix} of shape (n_samples, NP)\n The matrix of features, where `NP` is the number of polynomial\n features generated from the combination of inputs. If a sparse\n matrix is provided, it will be converted into a sparse\n `csr_matrix`.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, order='F', dtype=FLOAT_DTYPES, reset=False, accept_sparse=('csr', 'csc'))\n (n_samples, n_features) = X.shape\n if sparse.isspmatrix_csr(X):\n if self._max_degree > 3:\n return self.transform(X.tocsc()).tocsr()\n to_stack = []\n if self.include_bias:\n to_stack.append(sparse.csc_matrix(np.ones(shape=(n_samples, 1), dtype=X.dtype)))\n if self._min_degree <= 1:\n to_stack.append(X)\n for deg in range(max(2, self._min_degree), self._max_degree + 1):\n Xp_next = _csr_polynomial_expansion(X.data, X.indices, X.indptr, X.shape[1], self.interaction_only, deg)\n if Xp_next is None:\n break\n to_stack.append(Xp_next)\n if len(to_stack) == 0:\n XP = sparse.csr_matrix((n_samples, 0), dtype=X.dtype)\n else:\n XP = sparse.hstack(to_stack, format='csr')\n elif sparse.isspmatrix_csc(X) and self._max_degree < 4:\n return self.transform(X.tocsr()).tocsc()\n elif sparse.isspmatrix(X):\n combinations = self._combinations(n_features=n_features, min_degree=self._min_degree, max_degree=self._max_degree, interaction_only=self.interaction_only, include_bias=self.include_bias)\n columns = []\n for combi in combinations:\n if combi:\n out_col = 1\n for col_idx in combi:\n out_col = X[:, col_idx].multiply(out_col)\n columns.append(out_col)\n else:\n bias = sparse.csc_matrix(np.ones((X.shape[0], 1)))\n columns.append(bias)\n XP = sparse.hstack(columns, dtype=X.dtype).tocsc()\n else:\n XP = np.empty(shape=(n_samples, self._n_out_full), dtype=X.dtype, order=self.order)\n if self.include_bias:\n XP[:, 0] = 1\n current_col = 1\n else:\n current_col = 0\n XP[:, current_col:current_col + n_features] = X\n index = list(range(current_col, current_col + n_features))\n current_col += n_features\n index.append(current_col)\n for _ in range(2, self._max_degree + 1):\n new_index = []\n end = index[-1]\n for feature_idx in range(n_features):\n start = index[feature_idx]\n new_index.append(current_col)\n if self.interaction_only:\n start += index[feature_idx + 1] - index[feature_idx]\n next_col = current_col + end - start\n if next_col <= current_col:\n break\n np.multiply(XP[:, start:end], X[:, feature_idx:feature_idx + 1], out=XP[:, current_col:next_col], casting='no')\n current_col = next_col\n new_index.append(current_col)\n index = new_index\n if self._min_degree > 1:\n (n_XP, n_Xout) = (self._n_out_full, self.n_output_features_)\n if self.include_bias:\n Xout = np.empty(shape=(n_samples, n_Xout), dtype=XP.dtype, order=self.order)\n Xout[:, 0] = 1\n Xout[:, 1:] = XP[:, n_XP - n_Xout + 1:]\n else:\n Xout = XP[:, n_XP - n_Xout:].copy()\n XP = Xout\n return XP\n \n @deprecated('The attribute `n_input_features_` was deprecated in version 1.0 and will be removed in 1.2.')\n @property\n def n_input_features_(self):\n return self.n_features_in_\n" }, { "name": "SplineTransformer", @@ -26226,7 +26179,7 @@ "is_public": true, "description": "Generate univariate B-spline bases for features.\n\nGenerate a new feature matrix consisting of `n_splines=n_knots + degree - 1` (`n_knots - 1` for `extrapolation=\"periodic\"`) spline basis functions (B-splines) of polynomial order=`degree` for each feature. Read more in the :ref:`User Guide `. .. versionadded:: 1.0", "docstring": "Generate univariate B-spline bases for features.\n\n Generate a new feature matrix consisting of\n `n_splines=n_knots + degree - 1` (`n_knots - 1` for\n `extrapolation=\"periodic\"`) spline basis functions\n (B-splines) of polynomial order=`degree` for each feature.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 1.0\n\n Parameters\n ----------\n n_knots : int, default=5\n Number of knots of the splines if `knots` equals one of\n {'uniform', 'quantile'}. Must be larger or equal 2. Ignored if `knots`\n is array-like.\n\n degree : int, default=3\n The polynomial degree of the spline basis. Must be a non-negative\n integer.\n\n knots : {'uniform', 'quantile'} or array-like of shape (n_knots, n_features), default='uniform'\n Set knot positions such that first knot <= features <= last knot.\n\n - If 'uniform', `n_knots` number of knots are distributed uniformly\n from min to max values of the features.\n - If 'quantile', they are distributed uniformly along the quantiles of\n the features.\n - If an array-like is given, it directly specifies the sorted knot\n positions including the boundary knots. Note that, internally,\n `degree` number of knots are added before the first knot, the same\n after the last knot.\n\n extrapolation : {'error', 'constant', 'linear', 'continue', 'periodic'}, default='constant'\n If 'error', values outside the min and max values of the training\n features raises a `ValueError`. If 'constant', the value of the\n splines at minimum and maximum value of the features is used as\n constant extrapolation. If 'linear', a linear extrapolation is used.\n If 'continue', the splines are extrapolated as is, i.e. option\n `extrapolate=True` in :class:`scipy.interpolate.BSpline`. If\n 'periodic', periodic splines with a periodicity equal to the distance\n between the first and last knot are used. Periodic splines enforce\n equal function values and derivatives at the first and last knot.\n For example, this makes it possible to avoid introducing an arbitrary\n jump between Dec 31st and Jan 1st in spline features derived from a\n naturally periodic \"day-of-year\" input feature. In this case it is\n recommended to manually set the knot values to control the period.\n\n include_bias : bool, default=True\n If True (default), then the last spline element inside the data range\n of a feature is dropped. As B-splines sum to one over the spline basis\n functions for each data point, they implicitly include a bias term,\n i.e. a column of ones. It acts as an intercept term in a linear models.\n\n order : {'C', 'F'}, default='C'\n Order of output array. 'F' order is faster to compute, but may slow\n down subsequent estimators.\n\n Attributes\n ----------\n bsplines_ : list of shape (n_features,)\n List of BSplines objects, one for each feature.\n\n n_features_in_ : int\n The total number of input features.\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_features_out_ : int\n The total number of output features, which is computed as\n `n_features * n_splines`, where `n_splines` is\n the number of bases elements of the B-splines,\n `n_knots + degree - 1` for non-periodic splines and\n `n_knots - 1` for periodic ones.\n If `include_bias=False`, then it is only\n `n_features * (n_splines - 1)`.\n\n See Also\n --------\n KBinsDiscretizer : Transformer that bins continuous data into intervals.\n\n PolynomialFeatures : Transformer that generates polynomial and interaction\n features.\n\n Notes\n -----\n High degrees and a high number of knots can cause overfitting.\n\n See :ref:`examples/linear_model/plot_polynomial_interpolation.py\n `.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.preprocessing import SplineTransformer\n >>> X = np.arange(6).reshape(6, 1)\n >>> spline = SplineTransformer(degree=2, n_knots=3)\n >>> spline.fit_transform(X)\n array([[0.5 , 0.5 , 0. , 0. ],\n [0.18, 0.74, 0.08, 0. ],\n [0.02, 0.66, 0.32, 0. ],\n [0. , 0.32, 0.66, 0.02],\n [0. , 0.08, 0.74, 0.18],\n [0. , 0. , 0.5 , 0.5 ]])\n ", - "source_code": "\n\nclass SplineTransformer(TransformerMixin, BaseEstimator):\n \"\"\"Generate univariate B-spline bases for features.\n\n Generate a new feature matrix consisting of\n `n_splines=n_knots + degree - 1` (`n_knots - 1` for\n `extrapolation=\"periodic\"`) spline basis functions\n (B-splines) of polynomial order=`degree` for each feature.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 1.0\n\n Parameters\n ----------\n n_knots : int, default=5\n Number of knots of the splines if `knots` equals one of\n {'uniform', 'quantile'}. Must be larger or equal 2. Ignored if `knots`\n is array-like.\n\n degree : int, default=3\n The polynomial degree of the spline basis. Must be a non-negative\n integer.\n\n knots : {'uniform', 'quantile'} or array-like of shape (n_knots, n_features), default='uniform'\n Set knot positions such that first knot <= features <= last knot.\n\n - If 'uniform', `n_knots` number of knots are distributed uniformly\n from min to max values of the features.\n - If 'quantile', they are distributed uniformly along the quantiles of\n the features.\n - If an array-like is given, it directly specifies the sorted knot\n positions including the boundary knots. Note that, internally,\n `degree` number of knots are added before the first knot, the same\n after the last knot.\n\n extrapolation : {'error', 'constant', 'linear', 'continue', 'periodic'}, default='constant'\n If 'error', values outside the min and max values of the training\n features raises a `ValueError`. If 'constant', the value of the\n splines at minimum and maximum value of the features is used as\n constant extrapolation. If 'linear', a linear extrapolation is used.\n If 'continue', the splines are extrapolated as is, i.e. option\n `extrapolate=True` in :class:`scipy.interpolate.BSpline`. If\n 'periodic', periodic splines with a periodicity equal to the distance\n between the first and last knot are used. Periodic splines enforce\n equal function values and derivatives at the first and last knot.\n For example, this makes it possible to avoid introducing an arbitrary\n jump between Dec 31st and Jan 1st in spline features derived from a\n naturally periodic \"day-of-year\" input feature. In this case it is\n recommended to manually set the knot values to control the period.\n\n include_bias : bool, default=True\n If True (default), then the last spline element inside the data range\n of a feature is dropped. As B-splines sum to one over the spline basis\n functions for each data point, they implicitly include a bias term,\n i.e. a column of ones. It acts as an intercept term in a linear models.\n\n order : {'C', 'F'}, default='C'\n Order of output array. 'F' order is faster to compute, but may slow\n down subsequent estimators.\n\n Attributes\n ----------\n bsplines_ : list of shape (n_features,)\n List of BSplines objects, one for each feature.\n\n n_features_in_ : int\n The total number of input features.\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_features_out_ : int\n The total number of output features, which is computed as\n `n_features * n_splines`, where `n_splines` is\n the number of bases elements of the B-splines,\n `n_knots + degree - 1` for non-periodic splines and\n `n_knots - 1` for periodic ones.\n If `include_bias=False`, then it is only\n `n_features * (n_splines - 1)`.\n\n See Also\n --------\n KBinsDiscretizer : Transformer that bins continuous data into intervals.\n\n PolynomialFeatures : Transformer that generates polynomial and interaction\n features.\n\n Notes\n -----\n High degrees and a high number of knots can cause overfitting.\n\n See :ref:`examples/linear_model/plot_polynomial_interpolation.py\n `.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.preprocessing import SplineTransformer\n >>> X = np.arange(6).reshape(6, 1)\n >>> spline = SplineTransformer(degree=2, n_knots=3)\n >>> spline.fit_transform(X)\n array([[0.5 , 0.5 , 0. , 0. ],\n [0.18, 0.74, 0.08, 0. ],\n [0.02, 0.66, 0.32, 0. ],\n [0. , 0.32, 0.66, 0.02],\n [0. , 0.08, 0.74, 0.18],\n [0. , 0. , 0.5 , 0.5 ]])\n \"\"\"\n \n def __init__(self, n_knots=5, degree=3, *, knots='uniform', extrapolation='constant', include_bias=True, order='C'):\n self.n_knots = n_knots\n self.degree = degree\n self.knots = knots\n self.extrapolation = extrapolation\n self.include_bias = include_bias\n self.order = order\n \n @staticmethod\n def _get_base_knot_positions(X, n_knots=10, knots='uniform', sample_weight=None):\n \"\"\"Calculate base knot positions.\n\n Base knots such that first knot <= feature <= last knot. For the\n B-spline construction with scipy.interpolate.BSpline, 2*degree knots\n beyond the base interval are added.\n\n Returns\n -------\n knots : ndarray of shape (n_knots, n_features), dtype=np.float64\n Knot positions (points) of base interval.\n \"\"\"\n if knots == 'quantile':\n percentiles = 100 * np.linspace(start=0, stop=1, num=n_knots, dtype=np.float64)\n if sample_weight is None:\n knots = np.percentile(X, percentiles, axis=0)\n else:\n knots = np.array([_weighted_percentile(X, sample_weight, percentile) for percentile in percentiles])\n else:\n mask = slice(None, None, 1) if sample_weight is None else sample_weight > 0\n x_min = np.amin(X[mask], axis=0)\n x_max = np.amax(X[mask], axis=0)\n knots = linspace(start=x_min, stop=x_max, num=n_knots, endpoint=True, dtype=np.float64)\n return knots\n \n @deprecated('get_feature_names is deprecated in 1.0 and will be removed in 1.2. Please use get_feature_names_out instead.')\n def get_feature_names(self, input_features=None):\n \"\"\"Return feature names for output features.\n\n Parameters\n ----------\n input_features : list of str of shape (n_features,), default=None\n String names for input features if available. By default,\n \"x0\", \"x1\", ... \"xn_features\" is used.\n\n Returns\n -------\n output_feature_names : list of str of shape (n_output_features,)\n \"\"\"\n n_splines = self.bsplines_[0].c.shape[0]\n if input_features is None:\n input_features = ['x%d' % i for i in range(self.n_features_in_)]\n feature_names = []\n for i in range(self.n_features_in_):\n for j in range(n_splines - 1 + self.include_bias):\n feature_names.append(f'{input_features[i]}_sp_{j}')\n return feature_names\n \n def get_feature_names_out(self, input_features=None):\n \"\"\"Get output feature names for transformation.\n\n Parameters\n ----------\n input_features : array-like of str or None, default=None\n Input features.\n\n - If `input_features` is `None`, then `feature_names_in_` is\n used as feature names in. If `feature_names_in_` is not defined,\n then names are generated: `[x0, x1, ..., x(n_features_in_)]`.\n - If `input_features` is an array-like, then `input_features` must\n match `feature_names_in_` if `feature_names_in_` is defined.\n\n Returns\n -------\n feature_names_out : ndarray of str objects\n Transformed feature names.\n \"\"\"\n n_splines = self.bsplines_[0].c.shape[0]\n input_features = _check_feature_names_in(self, input_features)\n feature_names = []\n for i in range(self.n_features_in_):\n for j in range(n_splines - 1 + self.include_bias):\n feature_names.append(f'{input_features[i]}_sp_{j}')\n return np.asarray(feature_names, dtype=object)\n \n def fit(self, X, y=None, sample_weight=None):\n \"\"\"Compute knot positions of splines.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data.\n\n y : None\n Ignored.\n\n sample_weight : array-like of shape (n_samples,), default = None\n Individual weights for each sample. Used to calculate quantiles if\n `knots=\"quantile\"`. For `knots=\"uniform\"`, zero weighted\n observations are ignored for finding the min and max of `X`.\n\n Returns\n -------\n self : object\n Fitted transformer.\n \"\"\"\n X = self._validate_data(X, reset=True, accept_sparse=False, ensure_min_samples=2, ensure_2d=True)\n if sample_weight is not None:\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n (_, n_features) = X.shape\n if not (isinstance(self.degree, numbers.Integral) and self.degree >= 0):\n raise ValueError(f'degree must be a non-negative integer, got {self.degree}.')\n if isinstance(self.knots, str) and self.knots in ['uniform', 'quantile']:\n if not (isinstance(self.n_knots, numbers.Integral) and self.n_knots >= 2):\n raise ValueError(f'n_knots must be a positive integer >= 2, got: {self.n_knots}')\n base_knots = self._get_base_knot_positions(X, n_knots=self.n_knots, knots=self.knots, sample_weight=sample_weight)\n else:\n base_knots = check_array(self.knots, dtype=np.float64)\n if base_knots.shape[0] < 2:\n raise ValueError('Number of knots, knots.shape[0], must be >= 2.')\n elif base_knots.shape[1] != n_features:\n raise ValueError('knots.shape[1] == n_features is violated.')\n elif not np.all(np.diff(base_knots, axis=0) > 0):\n raise ValueError('knots must be sorted without duplicates.')\n if self.extrapolation not in ('error', 'constant', 'linear', 'continue', 'periodic'):\n raise ValueError(\"extrapolation must be one of 'error', 'constant', 'linear', 'continue' or 'periodic'.\")\n if not isinstance(self.include_bias, (bool, np.bool_)):\n raise ValueError('include_bias must be bool.')\n n_knots = base_knots.shape[0]\n if self.extrapolation == 'periodic' and n_knots <= self.degree:\n raise ValueError(f'Periodic splines require degree < n_knots. Got n_knots={n_knots} and degree={self.degree}.')\n if self.extrapolation != 'periodic':\n n_splines = n_knots + self.degree - 1\n else:\n n_splines = n_knots - 1\n degree = self.degree\n n_out = n_features * n_splines\n if self.extrapolation == 'periodic':\n period = base_knots[-1] - base_knots[0]\n knots = np.r_[base_knots[-(degree + 1):-1] - period, base_knots, base_knots[1:degree + 1] + period]\n else:\n dist_min = base_knots[1] - base_knots[0]\n dist_max = base_knots[-1] - base_knots[-2]\n knots = np.r_[linspace(base_knots[0] - degree * dist_min, base_knots[0] - dist_min, num=degree), base_knots, linspace(base_knots[-1] + dist_max, base_knots[-1] + degree * dist_max, num=degree)]\n coef = np.eye(n_splines, dtype=np.float64)\n if self.extrapolation == 'periodic':\n coef = np.concatenate((coef, coef[:degree, :]))\n extrapolate = self.extrapolation in ['periodic', 'continue']\n bsplines = [BSpline.construct_fast(knots[:, i], coef, self.degree, extrapolate=extrapolate) for i in range(n_features)]\n self.bsplines_ = bsplines\n self.n_features_out_ = n_out - n_features * (1 - self.include_bias)\n return self\n \n def transform(self, X):\n \"\"\"Transform each feature data to B-splines.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data to transform.\n\n Returns\n -------\n XBS : ndarray of shape (n_samples, n_features * n_splines)\n The matrix of features, where n_splines is the number of bases\n elements of the B-splines, n_knots + degree - 1.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, reset=False, accept_sparse=False, ensure_2d=True)\n (n_samples, n_features) = X.shape\n n_splines = self.bsplines_[0].c.shape[1]\n degree = self.degree\n n_out = self.n_features_out_ + n_features * (1 - self.include_bias)\n if X.dtype in FLOAT_DTYPES:\n dtype = X.dtype\n else:\n dtype = np.float64\n XBS = np.zeros((n_samples, n_out), dtype=dtype, order=self.order)\n for i in range(n_features):\n spl = self.bsplines_[i]\n if self.extrapolation in ('continue', 'error', 'periodic'):\n if self.extrapolation == 'periodic':\n n = spl.t.size - spl.k - 1\n x = spl.t[spl.k] + (X[:, i] - spl.t[spl.k]) % (spl.t[n] - spl.t[spl.k])\n else:\n x = X[:, i]\n XBS[:, i * n_splines:(i + 1) * n_splines] = spl(x)\n else:\n xmin = spl.t[degree]\n xmax = spl.t[-degree - 1]\n mask = (xmin <= X[:, i]) & (X[:, i] <= xmax)\n XBS[mask, i * n_splines:(i + 1) * n_splines] = spl(X[mask, i])\n if self.extrapolation == 'error':\n if np.any(np.isnan(XBS[:, i * n_splines:(i + 1) * n_splines])):\n raise ValueError('X contains values beyond the limits of the knots.')\n elif self.extrapolation == 'constant':\n f_min = spl(xmin)\n f_max = spl(xmax)\n mask = X[:, i] < xmin\n if np.any(mask):\n XBS[mask, i * n_splines:i * n_splines + degree] = f_min[:degree]\n mask = X[:, i] > xmax\n if np.any(mask):\n XBS[mask, (i + 1) * n_splines - degree:(i + 1) * n_splines] = f_max[-degree:]\n elif self.extrapolation == 'linear':\n (f_min, f_max) = (spl(xmin), spl(xmax))\n (fp_min, fp_max) = (spl(xmin, nu=1), spl(xmax, nu=1))\n if degree <= 1:\n degree += 1\n for j in range(degree):\n mask = X[:, i] < xmin\n if np.any(mask):\n XBS[mask, i * n_splines + j] = f_min[j] + (X[mask, i] - xmin) * fp_min[j]\n mask = X[:, i] > xmax\n if np.any(mask):\n k = n_splines - 1 - j\n XBS[mask, i * n_splines + k] = f_max[k] + (X[mask, i] - xmax) * fp_max[k]\n if self.include_bias:\n return XBS\n else:\n indices = [j for j in range(XBS.shape[1]) if (j + 1) % n_splines != 0]\n return XBS[:, indices]\n" + "source_code": "\n\nclass SplineTransformer(TransformerMixin, BaseEstimator):\n \"\"\"Generate univariate B-spline bases for features.\n\n Generate a new feature matrix consisting of\n `n_splines=n_knots + degree - 1` (`n_knots - 1` for\n `extrapolation=\"periodic\"`) spline basis functions\n (B-splines) of polynomial order=`degree` for each feature.\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 1.0\n\n Parameters\n ----------\n n_knots : int, default=5\n Number of knots of the splines if `knots` equals one of\n {'uniform', 'quantile'}. Must be larger or equal 2. Ignored if `knots`\n is array-like.\n\n degree : int, default=3\n The polynomial degree of the spline basis. Must be a non-negative\n integer.\n\n knots : {'uniform', 'quantile'} or array-like of shape (n_knots, n_features), default='uniform'\n Set knot positions such that first knot <= features <= last knot.\n\n - If 'uniform', `n_knots` number of knots are distributed uniformly\n from min to max values of the features.\n - If 'quantile', they are distributed uniformly along the quantiles of\n the features.\n - If an array-like is given, it directly specifies the sorted knot\n positions including the boundary knots. Note that, internally,\n `degree` number of knots are added before the first knot, the same\n after the last knot.\n\n extrapolation : {'error', 'constant', 'linear', 'continue', 'periodic'}, default='constant'\n If 'error', values outside the min and max values of the training\n features raises a `ValueError`. If 'constant', the value of the\n splines at minimum and maximum value of the features is used as\n constant extrapolation. If 'linear', a linear extrapolation is used.\n If 'continue', the splines are extrapolated as is, i.e. option\n `extrapolate=True` in :class:`scipy.interpolate.BSpline`. If\n 'periodic', periodic splines with a periodicity equal to the distance\n between the first and last knot are used. Periodic splines enforce\n equal function values and derivatives at the first and last knot.\n For example, this makes it possible to avoid introducing an arbitrary\n jump between Dec 31st and Jan 1st in spline features derived from a\n naturally periodic \"day-of-year\" input feature. In this case it is\n recommended to manually set the knot values to control the period.\n\n include_bias : bool, default=True\n If True (default), then the last spline element inside the data range\n of a feature is dropped. As B-splines sum to one over the spline basis\n functions for each data point, they implicitly include a bias term,\n i.e. a column of ones. It acts as an intercept term in a linear models.\n\n order : {'C', 'F'}, default='C'\n Order of output array. 'F' order is faster to compute, but may slow\n down subsequent estimators.\n\n Attributes\n ----------\n bsplines_ : list of shape (n_features,)\n List of BSplines objects, one for each feature.\n\n n_features_in_ : int\n The total number of input features.\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_features_out_ : int\n The total number of output features, which is computed as\n `n_features * n_splines`, where `n_splines` is\n the number of bases elements of the B-splines,\n `n_knots + degree - 1` for non-periodic splines and\n `n_knots - 1` for periodic ones.\n If `include_bias=False`, then it is only\n `n_features * (n_splines - 1)`.\n\n See Also\n --------\n KBinsDiscretizer : Transformer that bins continuous data into intervals.\n\n PolynomialFeatures : Transformer that generates polynomial and interaction\n features.\n\n Notes\n -----\n High degrees and a high number of knots can cause overfitting.\n\n See :ref:`examples/linear_model/plot_polynomial_interpolation.py\n `.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.preprocessing import SplineTransformer\n >>> X = np.arange(6).reshape(6, 1)\n >>> spline = SplineTransformer(degree=2, n_knots=3)\n >>> spline.fit_transform(X)\n array([[0.5 , 0.5 , 0. , 0. ],\n [0.18, 0.74, 0.08, 0. ],\n [0.02, 0.66, 0.32, 0. ],\n [0. , 0.32, 0.66, 0.02],\n [0. , 0.08, 0.74, 0.18],\n [0. , 0. , 0.5 , 0.5 ]])\n \"\"\"\n \n def __init__(self, n_knots=5, degree=3, *, knots='uniform', extrapolation='constant', include_bias=True, order='C'):\n self.n_knots = n_knots\n self.degree = degree\n self.knots = knots\n self.extrapolation = extrapolation\n self.include_bias = include_bias\n self.order = order\n \n @staticmethod\n def _get_base_knot_positions(X, n_knots=10, knots='uniform', sample_weight=None):\n \"\"\"Calculate base knot positions.\n\n Base knots such that first knot <= feature <= last knot. For the\n B-spline construction with scipy.interpolate.BSpline, 2*degree knots\n beyond the base interval are added.\n\n Returns\n -------\n knots : ndarray of shape (n_knots, n_features), dtype=np.float64\n Knot positions (points) of base interval.\n \"\"\"\n if knots == 'quantile':\n percentiles = 100 * np.linspace(start=0, stop=1, num=n_knots, dtype=np.float64)\n if sample_weight is None:\n knots = np.percentile(X, percentiles, axis=0)\n else:\n knots = np.array([_weighted_percentile(X, sample_weight, percentile) for percentile in percentiles])\n else:\n mask = slice(None, None, 1) if sample_weight is None else sample_weight > 0\n x_min = np.amin(X[mask], axis=0)\n x_max = np.amax(X[mask], axis=0)\n knots = linspace(start=x_min, stop=x_max, num=n_knots, endpoint=True, dtype=np.float64)\n return knots\n \n @deprecated('get_feature_names is deprecated in 1.0 and will be removed in 1.2. Please use get_feature_names_out instead.')\n def get_feature_names(self, input_features=None):\n \"\"\"Return feature names for output features.\n\n Parameters\n ----------\n input_features : list of str of shape (n_features,), default=None\n String names for input features if available. By default,\n \"x0\", \"x1\", ... \"xn_features\" is used.\n\n Returns\n -------\n output_feature_names : list of str of shape (n_output_features,)\n Transformed feature names.\n \"\"\"\n n_splines = self.bsplines_[0].c.shape[0]\n if input_features is None:\n input_features = ['x%d' % i for i in range(self.n_features_in_)]\n feature_names = []\n for i in range(self.n_features_in_):\n for j in range(n_splines - 1 + self.include_bias):\n feature_names.append(f'{input_features[i]}_sp_{j}')\n return feature_names\n \n def get_feature_names_out(self, input_features=None):\n \"\"\"Get output feature names for transformation.\n\n Parameters\n ----------\n input_features : array-like of str or None, default=None\n Input features.\n\n - If `input_features` is `None`, then `feature_names_in_` is\n used as feature names in. If `feature_names_in_` is not defined,\n then names are generated: `[x0, x1, ..., x(n_features_in_)]`.\n - If `input_features` is an array-like, then `input_features` must\n match `feature_names_in_` if `feature_names_in_` is defined.\n\n Returns\n -------\n feature_names_out : ndarray of str objects\n Transformed feature names.\n \"\"\"\n n_splines = self.bsplines_[0].c.shape[0]\n input_features = _check_feature_names_in(self, input_features)\n feature_names = []\n for i in range(self.n_features_in_):\n for j in range(n_splines - 1 + self.include_bias):\n feature_names.append(f'{input_features[i]}_sp_{j}')\n return np.asarray(feature_names, dtype=object)\n \n def fit(self, X, y=None, sample_weight=None):\n \"\"\"Compute knot positions of splines.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data.\n\n y : None\n Ignored.\n\n sample_weight : array-like of shape (n_samples,), default = None\n Individual weights for each sample. Used to calculate quantiles if\n `knots=\"quantile\"`. For `knots=\"uniform\"`, zero weighted\n observations are ignored for finding the min and max of `X`.\n\n Returns\n -------\n self : object\n Fitted transformer.\n \"\"\"\n X = self._validate_data(X, reset=True, accept_sparse=False, ensure_min_samples=2, ensure_2d=True)\n if sample_weight is not None:\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n (_, n_features) = X.shape\n if not (isinstance(self.degree, numbers.Integral) and self.degree >= 0):\n raise ValueError(f'degree must be a non-negative integer, got {self.degree}.')\n if isinstance(self.knots, str) and self.knots in ['uniform', 'quantile']:\n if not (isinstance(self.n_knots, numbers.Integral) and self.n_knots >= 2):\n raise ValueError(f'n_knots must be a positive integer >= 2, got: {self.n_knots}')\n base_knots = self._get_base_knot_positions(X, n_knots=self.n_knots, knots=self.knots, sample_weight=sample_weight)\n else:\n base_knots = check_array(self.knots, dtype=np.float64)\n if base_knots.shape[0] < 2:\n raise ValueError('Number of knots, knots.shape[0], must be >= 2.')\n elif base_knots.shape[1] != n_features:\n raise ValueError('knots.shape[1] == n_features is violated.')\n elif not np.all(np.diff(base_knots, axis=0) > 0):\n raise ValueError('knots must be sorted without duplicates.')\n if self.extrapolation not in ('error', 'constant', 'linear', 'continue', 'periodic'):\n raise ValueError(\"extrapolation must be one of 'error', 'constant', 'linear', 'continue' or 'periodic'.\")\n if not isinstance(self.include_bias, (bool, np.bool_)):\n raise ValueError('include_bias must be bool.')\n n_knots = base_knots.shape[0]\n if self.extrapolation == 'periodic' and n_knots <= self.degree:\n raise ValueError(f'Periodic splines require degree < n_knots. Got n_knots={n_knots} and degree={self.degree}.')\n if self.extrapolation != 'periodic':\n n_splines = n_knots + self.degree - 1\n else:\n n_splines = n_knots - 1\n degree = self.degree\n n_out = n_features * n_splines\n if self.extrapolation == 'periodic':\n period = base_knots[-1] - base_knots[0]\n knots = np.r_[base_knots[-(degree + 1):-1] - period, base_knots, base_knots[1:degree + 1] + period]\n else:\n dist_min = base_knots[1] - base_knots[0]\n dist_max = base_knots[-1] - base_knots[-2]\n knots = np.r_[linspace(base_knots[0] - degree * dist_min, base_knots[0] - dist_min, num=degree), base_knots, linspace(base_knots[-1] + dist_max, base_knots[-1] + degree * dist_max, num=degree)]\n coef = np.eye(n_splines, dtype=np.float64)\n if self.extrapolation == 'periodic':\n coef = np.concatenate((coef, coef[:degree, :]))\n extrapolate = self.extrapolation in ['periodic', 'continue']\n bsplines = [BSpline.construct_fast(knots[:, i], coef, self.degree, extrapolate=extrapolate) for i in range(n_features)]\n self.bsplines_ = bsplines\n self.n_features_out_ = n_out - n_features * (1 - self.include_bias)\n return self\n \n def transform(self, X):\n \"\"\"Transform each feature data to B-splines.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data to transform.\n\n Returns\n -------\n XBS : ndarray of shape (n_samples, n_features * n_splines)\n The matrix of features, where n_splines is the number of bases\n elements of the B-splines, n_knots + degree - 1.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, reset=False, accept_sparse=False, ensure_2d=True)\n (n_samples, n_features) = X.shape\n n_splines = self.bsplines_[0].c.shape[1]\n degree = self.degree\n n_out = self.n_features_out_ + n_features * (1 - self.include_bias)\n if X.dtype in FLOAT_DTYPES:\n dtype = X.dtype\n else:\n dtype = np.float64\n XBS = np.zeros((n_samples, n_out), dtype=dtype, order=self.order)\n for i in range(n_features):\n spl = self.bsplines_[i]\n if self.extrapolation in ('continue', 'error', 'periodic'):\n if self.extrapolation == 'periodic':\n n = spl.t.size - spl.k - 1\n x = spl.t[spl.k] + (X[:, i] - spl.t[spl.k]) % (spl.t[n] - spl.t[spl.k])\n else:\n x = X[:, i]\n XBS[:, i * n_splines:(i + 1) * n_splines] = spl(x)\n else:\n xmin = spl.t[degree]\n xmax = spl.t[-degree - 1]\n mask = (xmin <= X[:, i]) & (X[:, i] <= xmax)\n XBS[mask, i * n_splines:(i + 1) * n_splines] = spl(X[mask, i])\n if self.extrapolation == 'error':\n if np.any(np.isnan(XBS[:, i * n_splines:(i + 1) * n_splines])):\n raise ValueError('X contains values beyond the limits of the knots.')\n elif self.extrapolation == 'constant':\n f_min = spl(xmin)\n f_max = spl(xmax)\n mask = X[:, i] < xmin\n if np.any(mask):\n XBS[mask, i * n_splines:i * n_splines + degree] = f_min[:degree]\n mask = X[:, i] > xmax\n if np.any(mask):\n XBS[mask, (i + 1) * n_splines - degree:(i + 1) * n_splines] = f_max[-degree:]\n elif self.extrapolation == 'linear':\n (f_min, f_max) = (spl(xmin), spl(xmax))\n (fp_min, fp_max) = (spl(xmin, nu=1), spl(xmax, nu=1))\n if degree <= 1:\n degree += 1\n for j in range(degree):\n mask = X[:, i] < xmin\n if np.any(mask):\n XBS[mask, i * n_splines + j] = f_min[j] + (X[mask, i] - xmin) * fp_min[j]\n mask = X[:, i] > xmax\n if np.any(mask):\n k = n_splines - 1 - j\n XBS[mask, i * n_splines + k] = f_max[k] + (X[mask, i] - xmax) * fp_max[k]\n if self.include_bias:\n return XBS\n else:\n indices = [j for j in range(XBS.shape[1]) if (j + 1) % n_splines != 0]\n return XBS[:, indices]\n" }, { "name": "BaseRandomProjection", @@ -26269,8 +26222,8 @@ ], "is_public": true, "description": "Reduce dimensionality through sparse random projection.\n\nSparse random matrix is an alternative to dense random projection matrix that guarantees similar embedding quality while being much more memory efficient and allowing faster computation of the projected data. If we note `s = 1 / density` the components of the random matrix are drawn from: - -sqrt(s) / sqrt(n_components) with probability 1 / 2s - 0 with probability 1 - 1 / s - +sqrt(s) / sqrt(n_components) with probability 1 / 2s Read more in the :ref:`User Guide `. .. versionadded:: 0.13", - "docstring": "Reduce dimensionality through sparse random projection.\n\n Sparse random matrix is an alternative to dense random\n projection matrix that guarantees similar embedding quality while being\n much more memory efficient and allowing faster computation of the\n projected data.\n\n If we note `s = 1 / density` the components of the random matrix are\n drawn from:\n\n - -sqrt(s) / sqrt(n_components) with probability 1 / 2s\n - 0 with probability 1 - 1 / s\n - +sqrt(s) / sqrt(n_components) with probability 1 / 2s\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.13\n\n Parameters\n ----------\n n_components : int or 'auto', default='auto'\n Dimensionality of the target projection space.\n\n n_components can be automatically adjusted according to the\n number of samples in the dataset and the bound given by the\n Johnson-Lindenstrauss lemma. In that case the quality of the\n embedding is controlled by the ``eps`` parameter.\n\n It should be noted that Johnson-Lindenstrauss lemma can yield\n very conservative estimated of the required number of components\n as it makes no assumption on the structure of the dataset.\n\n density : float or 'auto', default='auto'\n Ratio in the range (0, 1] of non-zero component in the random\n projection matrix.\n\n If density = 'auto', the value is set to the minimum density\n as recommended by Ping Li et al.: 1 / sqrt(n_features).\n\n Use density = 1 / 3.0 if you want to reproduce the results from\n Achlioptas, 2001.\n\n eps : float, default=0.1\n Parameter to control the quality of the embedding according to\n the Johnson-Lindenstrauss lemma when n_components is set to\n 'auto'. This value should be strictly positive.\n\n Smaller values lead to better embedding and higher number of\n dimensions (n_components) in the target projection space.\n\n dense_output : bool, default=False\n If True, ensure that the output of the random projection is a\n dense numpy array even if the input and random projection matrix\n are both sparse. In practice, if the number of components is\n small the number of zero components in the projected data will\n be very small and it will be more CPU and memory efficient to\n use a dense representation.\n\n If False, the projected data uses a sparse representation if\n the input is sparse.\n\n random_state : int, RandomState instance or None, default=None\n Controls the pseudo random number generator used to generate the\n projection matrix at fit time.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n Attributes\n ----------\n n_components_ : int\n Concrete number of components computed when n_components=\"auto\".\n\n components_ : sparse matrix of shape (n_components, n_features)\n Random matrix used for the projection. Sparse matrix will be of CSR\n format.\n\n density_ : float in range 0.0 - 1.0\n Concrete density computed from when density = \"auto\".\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.random_projection import SparseRandomProjection\n >>> rng = np.random.RandomState(42)\n >>> X = rng.rand(100, 10000)\n >>> transformer = SparseRandomProjection(random_state=rng)\n >>> X_new = transformer.fit_transform(X)\n >>> X_new.shape\n (100, 3947)\n >>> # very few components are non-zero\n >>> np.mean(transformer.components_ != 0)\n 0.0100...\n\n See Also\n --------\n GaussianRandomProjection\n\n References\n ----------\n\n .. [1] Ping Li, T. Hastie and K. W. Church, 2006,\n \"Very Sparse Random Projections\".\n https://web.stanford.edu/~hastie/Papers/Ping/KDD06_rp.pdf\n\n .. [2] D. Achlioptas, 2001, \"Database-friendly random projections\",\n https://users.soe.ucsc.edu/~optas/papers/jl.pdf\n\n ", - "source_code": "\n\nclass SparseRandomProjection(BaseRandomProjection):\n \"\"\"Reduce dimensionality through sparse random projection.\n\n Sparse random matrix is an alternative to dense random\n projection matrix that guarantees similar embedding quality while being\n much more memory efficient and allowing faster computation of the\n projected data.\n\n If we note `s = 1 / density` the components of the random matrix are\n drawn from:\n\n - -sqrt(s) / sqrt(n_components) with probability 1 / 2s\n - 0 with probability 1 - 1 / s\n - +sqrt(s) / sqrt(n_components) with probability 1 / 2s\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.13\n\n Parameters\n ----------\n n_components : int or 'auto', default='auto'\n Dimensionality of the target projection space.\n\n n_components can be automatically adjusted according to the\n number of samples in the dataset and the bound given by the\n Johnson-Lindenstrauss lemma. In that case the quality of the\n embedding is controlled by the ``eps`` parameter.\n\n It should be noted that Johnson-Lindenstrauss lemma can yield\n very conservative estimated of the required number of components\n as it makes no assumption on the structure of the dataset.\n\n density : float or 'auto', default='auto'\n Ratio in the range (0, 1] of non-zero component in the random\n projection matrix.\n\n If density = 'auto', the value is set to the minimum density\n as recommended by Ping Li et al.: 1 / sqrt(n_features).\n\n Use density = 1 / 3.0 if you want to reproduce the results from\n Achlioptas, 2001.\n\n eps : float, default=0.1\n Parameter to control the quality of the embedding according to\n the Johnson-Lindenstrauss lemma when n_components is set to\n 'auto'. This value should be strictly positive.\n\n Smaller values lead to better embedding and higher number of\n dimensions (n_components) in the target projection space.\n\n dense_output : bool, default=False\n If True, ensure that the output of the random projection is a\n dense numpy array even if the input and random projection matrix\n are both sparse. In practice, if the number of components is\n small the number of zero components in the projected data will\n be very small and it will be more CPU and memory efficient to\n use a dense representation.\n\n If False, the projected data uses a sparse representation if\n the input is sparse.\n\n random_state : int, RandomState instance or None, default=None\n Controls the pseudo random number generator used to generate the\n projection matrix at fit time.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n Attributes\n ----------\n n_components_ : int\n Concrete number of components computed when n_components=\"auto\".\n\n components_ : sparse matrix of shape (n_components, n_features)\n Random matrix used for the projection. Sparse matrix will be of CSR\n format.\n\n density_ : float in range 0.0 - 1.0\n Concrete density computed from when density = \"auto\".\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.random_projection import SparseRandomProjection\n >>> rng = np.random.RandomState(42)\n >>> X = rng.rand(100, 10000)\n >>> transformer = SparseRandomProjection(random_state=rng)\n >>> X_new = transformer.fit_transform(X)\n >>> X_new.shape\n (100, 3947)\n >>> # very few components are non-zero\n >>> np.mean(transformer.components_ != 0)\n 0.0100...\n\n See Also\n --------\n GaussianRandomProjection\n\n References\n ----------\n\n .. [1] Ping Li, T. Hastie and K. W. Church, 2006,\n \"Very Sparse Random Projections\".\n https://web.stanford.edu/~hastie/Papers/Ping/KDD06_rp.pdf\n\n .. [2] D. Achlioptas, 2001, \"Database-friendly random projections\",\n https://users.soe.ucsc.edu/~optas/papers/jl.pdf\n\n \"\"\"\n \n def __init__(self, n_components='auto', *, density='auto', eps=0.1, dense_output=False, random_state=None):\n super().__init__(n_components=n_components, eps=eps, dense_output=dense_output, random_state=random_state)\n self.density = density\n \n def _make_random_matrix(self, n_components, n_features):\n \"\"\" Generate the random projection matrix\n\n Parameters\n ----------\n n_components : int\n Dimensionality of the target projection space.\n\n n_features : int\n Dimensionality of the original source space.\n\n Returns\n -------\n components : {ndarray, sparse matrix} of shape (n_components, n_features)\n The generated random matrix. Sparse matrix will be of CSR format.\n\n \"\"\"\n random_state = check_random_state(self.random_state)\n self.density_ = _check_density(self.density, n_features)\n return _sparse_random_matrix(n_components, n_features, density=self.density_, random_state=random_state)\n" + "docstring": "Reduce dimensionality through sparse random projection.\n\n Sparse random matrix is an alternative to dense random\n projection matrix that guarantees similar embedding quality while being\n much more memory efficient and allowing faster computation of the\n projected data.\n\n If we note `s = 1 / density` the components of the random matrix are\n drawn from:\n\n - -sqrt(s) / sqrt(n_components) with probability 1 / 2s\n - 0 with probability 1 - 1 / s\n - +sqrt(s) / sqrt(n_components) with probability 1 / 2s\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.13\n\n Parameters\n ----------\n n_components : int or 'auto', default='auto'\n Dimensionality of the target projection space.\n\n n_components can be automatically adjusted according to the\n number of samples in the dataset and the bound given by the\n Johnson-Lindenstrauss lemma. In that case the quality of the\n embedding is controlled by the ``eps`` parameter.\n\n It should be noted that Johnson-Lindenstrauss lemma can yield\n very conservative estimated of the required number of components\n as it makes no assumption on the structure of the dataset.\n\n density : float or 'auto', default='auto'\n Ratio in the range (0, 1] of non-zero component in the random\n projection matrix.\n\n If density = 'auto', the value is set to the minimum density\n as recommended by Ping Li et al.: 1 / sqrt(n_features).\n\n Use density = 1 / 3.0 if you want to reproduce the results from\n Achlioptas, 2001.\n\n eps : float, default=0.1\n Parameter to control the quality of the embedding according to\n the Johnson-Lindenstrauss lemma when n_components is set to\n 'auto'. This value should be strictly positive.\n\n Smaller values lead to better embedding and higher number of\n dimensions (n_components) in the target projection space.\n\n dense_output : bool, default=False\n If True, ensure that the output of the random projection is a\n dense numpy array even if the input and random projection matrix\n are both sparse. In practice, if the number of components is\n small the number of zero components in the projected data will\n be very small and it will be more CPU and memory efficient to\n use a dense representation.\n\n If False, the projected data uses a sparse representation if\n the input is sparse.\n\n random_state : int, RandomState instance or None, default=None\n Controls the pseudo random number generator used to generate the\n projection matrix at fit time.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n Attributes\n ----------\n n_components_ : int\n Concrete number of components computed when n_components=\"auto\".\n\n components_ : sparse matrix of shape (n_components, n_features)\n Random matrix used for the projection. Sparse matrix will be of CSR\n format.\n\n density_ : float in range 0.0 - 1.0\n Concrete density computed from when density = \"auto\".\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n GaussianRandomProjection : Reduce dimensionality through Gaussian\n random projection.\n\n References\n ----------\n\n .. [1] Ping Li, T. Hastie and K. W. Church, 2006,\n \"Very Sparse Random Projections\".\n https://web.stanford.edu/~hastie/Papers/Ping/KDD06_rp.pdf\n\n .. [2] D. Achlioptas, 2001, \"Database-friendly random projections\",\n https://users.soe.ucsc.edu/~optas/papers/jl.pdf\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.random_projection import SparseRandomProjection\n >>> rng = np.random.RandomState(42)\n >>> X = rng.rand(100, 10000)\n >>> transformer = SparseRandomProjection(random_state=rng)\n >>> X_new = transformer.fit_transform(X)\n >>> X_new.shape\n (100, 3947)\n >>> # very few components are non-zero\n >>> np.mean(transformer.components_ != 0)\n 0.0100...\n ", + "source_code": "\n\nclass SparseRandomProjection(BaseRandomProjection):\n \"\"\"Reduce dimensionality through sparse random projection.\n\n Sparse random matrix is an alternative to dense random\n projection matrix that guarantees similar embedding quality while being\n much more memory efficient and allowing faster computation of the\n projected data.\n\n If we note `s = 1 / density` the components of the random matrix are\n drawn from:\n\n - -sqrt(s) / sqrt(n_components) with probability 1 / 2s\n - 0 with probability 1 - 1 / s\n - +sqrt(s) / sqrt(n_components) with probability 1 / 2s\n\n Read more in the :ref:`User Guide `.\n\n .. versionadded:: 0.13\n\n Parameters\n ----------\n n_components : int or 'auto', default='auto'\n Dimensionality of the target projection space.\n\n n_components can be automatically adjusted according to the\n number of samples in the dataset and the bound given by the\n Johnson-Lindenstrauss lemma. In that case the quality of the\n embedding is controlled by the ``eps`` parameter.\n\n It should be noted that Johnson-Lindenstrauss lemma can yield\n very conservative estimated of the required number of components\n as it makes no assumption on the structure of the dataset.\n\n density : float or 'auto', default='auto'\n Ratio in the range (0, 1] of non-zero component in the random\n projection matrix.\n\n If density = 'auto', the value is set to the minimum density\n as recommended by Ping Li et al.: 1 / sqrt(n_features).\n\n Use density = 1 / 3.0 if you want to reproduce the results from\n Achlioptas, 2001.\n\n eps : float, default=0.1\n Parameter to control the quality of the embedding according to\n the Johnson-Lindenstrauss lemma when n_components is set to\n 'auto'. This value should be strictly positive.\n\n Smaller values lead to better embedding and higher number of\n dimensions (n_components) in the target projection space.\n\n dense_output : bool, default=False\n If True, ensure that the output of the random projection is a\n dense numpy array even if the input and random projection matrix\n are both sparse. In practice, if the number of components is\n small the number of zero components in the projected data will\n be very small and it will be more CPU and memory efficient to\n use a dense representation.\n\n If False, the projected data uses a sparse representation if\n the input is sparse.\n\n random_state : int, RandomState instance or None, default=None\n Controls the pseudo random number generator used to generate the\n projection matrix at fit time.\n Pass an int for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n Attributes\n ----------\n n_components_ : int\n Concrete number of components computed when n_components=\"auto\".\n\n components_ : sparse matrix of shape (n_components, n_features)\n Random matrix used for the projection. Sparse matrix will be of CSR\n format.\n\n density_ : float in range 0.0 - 1.0\n Concrete density computed from when density = \"auto\".\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n See Also\n --------\n GaussianRandomProjection : Reduce dimensionality through Gaussian\n random projection.\n\n References\n ----------\n\n .. [1] Ping Li, T. Hastie and K. W. Church, 2006,\n \"Very Sparse Random Projections\".\n https://web.stanford.edu/~hastie/Papers/Ping/KDD06_rp.pdf\n\n .. [2] D. Achlioptas, 2001, \"Database-friendly random projections\",\n https://users.soe.ucsc.edu/~optas/papers/jl.pdf\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.random_projection import SparseRandomProjection\n >>> rng = np.random.RandomState(42)\n >>> X = rng.rand(100, 10000)\n >>> transformer = SparseRandomProjection(random_state=rng)\n >>> X_new = transformer.fit_transform(X)\n >>> X_new.shape\n (100, 3947)\n >>> # very few components are non-zero\n >>> np.mean(transformer.components_ != 0)\n 0.0100...\n \"\"\"\n \n def __init__(self, n_components='auto', *, density='auto', eps=0.1, dense_output=False, random_state=None):\n super().__init__(n_components=n_components, eps=eps, dense_output=dense_output, random_state=random_state)\n self.density = density\n \n def _make_random_matrix(self, n_components, n_features):\n \"\"\" Generate the random projection matrix\n\n Parameters\n ----------\n n_components : int\n Dimensionality of the target projection space.\n\n n_features : int\n Dimensionality of the original source space.\n\n Returns\n -------\n components : {ndarray, sparse matrix} of shape (n_components, n_features)\n The generated random matrix. Sparse matrix will be of CSR format.\n\n \"\"\"\n random_state = check_random_state(self.random_state)\n self.density_ = _check_density(self.density, n_features)\n return _sparse_random_matrix(n_components, n_features, density=self.density_, random_state=random_state)\n" }, { "name": "BaseLabelPropagation", @@ -26288,7 +26241,7 @@ "is_public": false, "description": "Base class for label propagation module.", "docstring": "Base class for label propagation module.\n\n Parameters\n ----------\n kernel : {'knn', 'rbf'} or callable, default='rbf'\n String identifier for kernel function to use or the kernel function\n itself. Only 'rbf' and 'knn' strings are valid inputs. The function\n passed should take two inputs, each of shape (n_samples, n_features),\n and return a (n_samples, n_samples) shaped weight matrix.\n\n gamma : float, default=20\n Parameter for rbf kernel.\n\n n_neighbors : int, default=7\n Parameter for knn kernel. Need to be strictly positive.\n\n alpha : float, default=1.0\n Clamping factor.\n\n max_iter : int, default=30\n Change maximum number of iterations allowed.\n\n tol : float, default=1e-3\n Convergence tolerance: threshold to consider the system at steady\n state.\n\n n_jobs : int, default=None\n The number of parallel jobs to run.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n ", - "source_code": "\n\nclass BaseLabelPropagation(ClassifierMixin, BaseEstimator, metaclass=ABCMeta):\n \"\"\"Base class for label propagation module.\n\n Parameters\n ----------\n kernel : {'knn', 'rbf'} or callable, default='rbf'\n String identifier for kernel function to use or the kernel function\n itself. Only 'rbf' and 'knn' strings are valid inputs. The function\n passed should take two inputs, each of shape (n_samples, n_features),\n and return a (n_samples, n_samples) shaped weight matrix.\n\n gamma : float, default=20\n Parameter for rbf kernel.\n\n n_neighbors : int, default=7\n Parameter for knn kernel. Need to be strictly positive.\n\n alpha : float, default=1.0\n Clamping factor.\n\n max_iter : int, default=30\n Change maximum number of iterations allowed.\n\n tol : float, default=1e-3\n Convergence tolerance: threshold to consider the system at steady\n state.\n\n n_jobs : int, default=None\n The number of parallel jobs to run.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n \"\"\"\n \n def __init__(self, kernel='rbf', *, gamma=20, n_neighbors=7, alpha=1, max_iter=30, tol=0.001, n_jobs=None):\n self.max_iter = max_iter\n self.tol = tol\n self.kernel = kernel\n self.gamma = gamma\n self.n_neighbors = n_neighbors\n self.alpha = alpha\n self.n_jobs = n_jobs\n \n def _get_kernel(self, X, y=None):\n if self.kernel == 'rbf':\n if y is None:\n return rbf_kernel(X, X, gamma=self.gamma)\n else:\n return rbf_kernel(X, y, gamma=self.gamma)\n elif self.kernel == 'knn':\n if self.nn_fit is None:\n self.nn_fit = NearestNeighbors(n_neighbors=self.n_neighbors, n_jobs=self.n_jobs).fit(X)\n if y is None:\n return self.nn_fit.kneighbors_graph(self.nn_fit._fit_X, self.n_neighbors, mode='connectivity')\n else:\n return self.nn_fit.kneighbors(y, return_distance=False)\n elif callable(self.kernel):\n if y is None:\n return self.kernel(X, X)\n else:\n return self.kernel(X, y)\n else:\n raise ValueError('%s is not a valid kernel. Only rbf and knn or an explicit function are supported at this time.' % self.kernel)\n \n @abstractmethod\n def _build_graph(self):\n raise NotImplementedError('Graph construction must be implemented to fit a label propagation model.')\n \n def predict(self, X):\n \"\"\"Performs inductive inference across the model.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data matrix.\n\n Returns\n -------\n y : ndarray of shape (n_samples,)\n Predictions for input data.\n \"\"\"\n probas = self.predict_proba(X)\n return self.classes_[np.argmax(probas, axis=1)].ravel()\n \n def predict_proba(self, X):\n \"\"\"Predict probability for each possible outcome.\n\n Compute the probability estimates for each single sample in X\n and each possible outcome seen during training (categorical\n distribution).\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data matrix.\n\n Returns\n -------\n probabilities : ndarray of shape (n_samples, n_classes)\n Normalized probability distributions across\n class labels.\n \"\"\"\n check_is_fitted(self)\n X_2d = self._validate_data(X, accept_sparse=['csc', 'csr', 'coo', 'dok', 'bsr', 'lil', 'dia'], reset=False)\n weight_matrices = self._get_kernel(self.X_, X_2d)\n if self.kernel == 'knn':\n probabilities = np.array([np.sum(self.label_distributions_[weight_matrix], axis=0) for weight_matrix in weight_matrices])\n else:\n weight_matrices = weight_matrices.T\n probabilities = safe_sparse_dot(weight_matrices, self.label_distributions_)\n normalizer = np.atleast_2d(np.sum(probabilities, axis=1)).T\n probabilities /= normalizer\n return probabilities\n \n def fit(self, X, y):\n \"\"\"Fit a semi-supervised label propagation model based\n\n All the input data is provided matrix X (labeled and unlabeled)\n and corresponding label matrix y with a dedicated marker value for\n unlabeled samples.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n A matrix of shape (n_samples, n_samples) will be created from this.\n\n y : array-like of shape (n_samples,)\n `n_labeled_samples` (unlabeled points are marked as -1)\n All unlabeled samples will be transductively assigned labels.\n\n Returns\n -------\n self : object\n \"\"\"\n (X, y) = self._validate_data(X, y)\n self.X_ = X\n check_classification_targets(y)\n graph_matrix = self._build_graph()\n classes = np.unique(y)\n classes = classes[classes != -1]\n self.classes_ = classes\n (n_samples, n_classes) = (len(y), len(classes))\n alpha = self.alpha\n if self._variant == 'spreading' and (alpha is None or alpha <= 0.0 or alpha >= 1.0):\n raise ValueError('alpha=%s is invalid: it must be inside the open interval (0, 1)' % alpha)\n y = np.asarray(y)\n unlabeled = y == -1\n self.label_distributions_ = np.zeros((n_samples, n_classes))\n for label in classes:\n self.label_distributions_[y == label, classes == label] = 1\n y_static = np.copy(self.label_distributions_)\n if self._variant == 'propagation':\n y_static[unlabeled] = 0\n else:\n y_static *= 1 - alpha\n l_previous = np.zeros((self.X_.shape[0], n_classes))\n unlabeled = unlabeled[:, np.newaxis]\n if sparse.isspmatrix(graph_matrix):\n graph_matrix = graph_matrix.tocsr()\n for self.n_iter_ in range(self.max_iter):\n if np.abs(self.label_distributions_ - l_previous).sum() < self.tol:\n break\n l_previous = self.label_distributions_\n self.label_distributions_ = safe_sparse_dot(graph_matrix, self.label_distributions_)\n if self._variant == 'propagation':\n normalizer = np.sum(self.label_distributions_, axis=1)[:, np.newaxis]\n normalizer[normalizer == 0] = 1\n self.label_distributions_ /= normalizer\n self.label_distributions_ = np.where(unlabeled, self.label_distributions_, y_static)\n else:\n self.label_distributions_ = np.multiply(alpha, self.label_distributions_) + y_static\n else:\n warnings.warn('max_iter=%d was reached without convergence.' % self.max_iter, category=ConvergenceWarning)\n self.n_iter_ += 1\n normalizer = np.sum(self.label_distributions_, axis=1)[:, np.newaxis]\n normalizer[normalizer == 0] = 1\n self.label_distributions_ /= normalizer\n transduction = self.classes_[np.argmax(self.label_distributions_, axis=1)]\n self.transduction_ = transduction.ravel()\n return self\n" + "source_code": "\n\nclass BaseLabelPropagation(ClassifierMixin, BaseEstimator, metaclass=ABCMeta):\n \"\"\"Base class for label propagation module.\n\n Parameters\n ----------\n kernel : {'knn', 'rbf'} or callable, default='rbf'\n String identifier for kernel function to use or the kernel function\n itself. Only 'rbf' and 'knn' strings are valid inputs. The function\n passed should take two inputs, each of shape (n_samples, n_features),\n and return a (n_samples, n_samples) shaped weight matrix.\n\n gamma : float, default=20\n Parameter for rbf kernel.\n\n n_neighbors : int, default=7\n Parameter for knn kernel. Need to be strictly positive.\n\n alpha : float, default=1.0\n Clamping factor.\n\n max_iter : int, default=30\n Change maximum number of iterations allowed.\n\n tol : float, default=1e-3\n Convergence tolerance: threshold to consider the system at steady\n state.\n\n n_jobs : int, default=None\n The number of parallel jobs to run.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n \"\"\"\n \n def __init__(self, kernel='rbf', *, gamma=20, n_neighbors=7, alpha=1, max_iter=30, tol=0.001, n_jobs=None):\n self.max_iter = max_iter\n self.tol = tol\n self.kernel = kernel\n self.gamma = gamma\n self.n_neighbors = n_neighbors\n self.alpha = alpha\n self.n_jobs = n_jobs\n \n def _get_kernel(self, X, y=None):\n if self.kernel == 'rbf':\n if y is None:\n return rbf_kernel(X, X, gamma=self.gamma)\n else:\n return rbf_kernel(X, y, gamma=self.gamma)\n elif self.kernel == 'knn':\n if self.nn_fit is None:\n self.nn_fit = NearestNeighbors(n_neighbors=self.n_neighbors, n_jobs=self.n_jobs).fit(X)\n if y is None:\n return self.nn_fit.kneighbors_graph(self.nn_fit._fit_X, self.n_neighbors, mode='connectivity')\n else:\n return self.nn_fit.kneighbors(y, return_distance=False)\n elif callable(self.kernel):\n if y is None:\n return self.kernel(X, X)\n else:\n return self.kernel(X, y)\n else:\n raise ValueError('%s is not a valid kernel. Only rbf and knn or an explicit function are supported at this time.' % self.kernel)\n \n @abstractmethod\n def _build_graph(self):\n raise NotImplementedError('Graph construction must be implemented to fit a label propagation model.')\n \n def predict(self, X):\n \"\"\"Perform inductive inference across the model.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data matrix.\n\n Returns\n -------\n y : ndarray of shape (n_samples,)\n Predictions for input data.\n \"\"\"\n probas = self.predict_proba(X)\n return self.classes_[np.argmax(probas, axis=1)].ravel()\n \n def predict_proba(self, X):\n \"\"\"Predict probability for each possible outcome.\n\n Compute the probability estimates for each single sample in X\n and each possible outcome seen during training (categorical\n distribution).\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data matrix.\n\n Returns\n -------\n probabilities : ndarray of shape (n_samples, n_classes)\n Normalized probability distributions across\n class labels.\n \"\"\"\n check_is_fitted(self)\n X_2d = self._validate_data(X, accept_sparse=['csc', 'csr', 'coo', 'dok', 'bsr', 'lil', 'dia'], reset=False)\n weight_matrices = self._get_kernel(self.X_, X_2d)\n if self.kernel == 'knn':\n probabilities = np.array([np.sum(self.label_distributions_[weight_matrix], axis=0) for weight_matrix in weight_matrices])\n else:\n weight_matrices = weight_matrices.T\n probabilities = safe_sparse_dot(weight_matrices, self.label_distributions_)\n normalizer = np.atleast_2d(np.sum(probabilities, axis=1)).T\n probabilities /= normalizer\n return probabilities\n \n def fit(self, X, y):\n \"\"\"Fit a semi-supervised label propagation model to X.\n\n The input samples (labeled and unlabeled) are provided by matrix X,\n and target labels are provided by matrix y. We conventionally apply the\n label -1 to unlabeled samples in matrix y in a semi-supervised\n classification.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training data, where `n_samples` is the number of samples\n and `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target class values with unlabeled points marked as -1.\n All unlabeled samples will be transductively assigned labels\n internally.\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n (X, y) = self._validate_data(X, y)\n self.X_ = X\n check_classification_targets(y)\n graph_matrix = self._build_graph()\n classes = np.unique(y)\n classes = classes[classes != -1]\n self.classes_ = classes\n (n_samples, n_classes) = (len(y), len(classes))\n alpha = self.alpha\n if self._variant == 'spreading' and (alpha is None or alpha <= 0.0 or alpha >= 1.0):\n raise ValueError('alpha=%s is invalid: it must be inside the open interval (0, 1)' % alpha)\n y = np.asarray(y)\n unlabeled = y == -1\n self.label_distributions_ = np.zeros((n_samples, n_classes))\n for label in classes:\n self.label_distributions_[y == label, classes == label] = 1\n y_static = np.copy(self.label_distributions_)\n if self._variant == 'propagation':\n y_static[unlabeled] = 0\n else:\n y_static *= 1 - alpha\n l_previous = np.zeros((self.X_.shape[0], n_classes))\n unlabeled = unlabeled[:, np.newaxis]\n if sparse.isspmatrix(graph_matrix):\n graph_matrix = graph_matrix.tocsr()\n for self.n_iter_ in range(self.max_iter):\n if np.abs(self.label_distributions_ - l_previous).sum() < self.tol:\n break\n l_previous = self.label_distributions_\n self.label_distributions_ = safe_sparse_dot(graph_matrix, self.label_distributions_)\n if self._variant == 'propagation':\n normalizer = np.sum(self.label_distributions_, axis=1)[:, np.newaxis]\n normalizer[normalizer == 0] = 1\n self.label_distributions_ /= normalizer\n self.label_distributions_ = np.where(unlabeled, self.label_distributions_, y_static)\n else:\n self.label_distributions_ = np.multiply(alpha, self.label_distributions_) + y_static\n else:\n warnings.warn('max_iter=%d was reached without convergence.' % self.max_iter, category=ConvergenceWarning)\n self.n_iter_ += 1\n normalizer = np.sum(self.label_distributions_, axis=1)[:, np.newaxis]\n normalizer[normalizer == 0] = 1\n self.label_distributions_ /= normalizer\n transduction = self.classes_[np.argmax(self.label_distributions_, axis=1)]\n self.transduction_ = transduction.ravel()\n return self\n" }, { "name": "LabelPropagation", @@ -26301,9 +26254,9 @@ "sklearn.semi_supervised._label_propagation.LabelPropagation.fit" ], "is_public": true, - "description": "Label Propagation classifier\n\nRead more in the :ref:`User Guide `.", - "docstring": "Label Propagation classifier\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n kernel : {'knn', 'rbf'} or callable, default='rbf'\n String identifier for kernel function to use or the kernel function\n itself. Only 'rbf' and 'knn' strings are valid inputs. The function\n passed should take two inputs, each of shape (n_samples, n_features),\n and return a (n_samples, n_samples) shaped weight matrix.\n\n gamma : float, default=20\n Parameter for rbf kernel.\n\n n_neighbors : int, default=7\n Parameter for knn kernel which need to be strictly positive.\n\n max_iter : int, default=1000\n Change maximum number of iterations allowed.\n\n tol : float, 1e-3\n Convergence tolerance: threshold to consider the system at steady\n state.\n\n n_jobs : int, default=None\n The number of parallel jobs to run.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n Attributes\n ----------\n X_ : ndarray of shape (n_samples, n_features)\n Input array.\n\n classes_ : ndarray of shape (n_classes,)\n The distinct labels used in classifying instances.\n\n label_distributions_ : ndarray of shape (n_samples, n_classes)\n Categorical distribution for each item.\n\n transduction_ : ndarray of shape (n_samples)\n Label assigned to each item via the transduction.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n Number of iterations run.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn import datasets\n >>> from sklearn.semi_supervised import LabelPropagation\n >>> label_prop_model = LabelPropagation()\n >>> iris = datasets.load_iris()\n >>> rng = np.random.RandomState(42)\n >>> random_unlabeled_points = rng.rand(len(iris.target)) < 0.3\n >>> labels = np.copy(iris.target)\n >>> labels[random_unlabeled_points] = -1\n >>> label_prop_model.fit(iris.data, labels)\n LabelPropagation(...)\n\n References\n ----------\n Xiaojin Zhu and Zoubin Ghahramani. Learning from labeled and unlabeled data\n with label propagation. Technical Report CMU-CALD-02-107, Carnegie Mellon\n University, 2002 http://pages.cs.wisc.edu/~jerryzhu/pub/CMU-CALD-02-107.pdf\n\n See Also\n --------\n LabelSpreading : Alternate label propagation strategy more robust to noise.\n ", - "source_code": "\n\nclass LabelPropagation(BaseLabelPropagation):\n \"\"\"Label Propagation classifier\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n kernel : {'knn', 'rbf'} or callable, default='rbf'\n String identifier for kernel function to use or the kernel function\n itself. Only 'rbf' and 'knn' strings are valid inputs. The function\n passed should take two inputs, each of shape (n_samples, n_features),\n and return a (n_samples, n_samples) shaped weight matrix.\n\n gamma : float, default=20\n Parameter for rbf kernel.\n\n n_neighbors : int, default=7\n Parameter for knn kernel which need to be strictly positive.\n\n max_iter : int, default=1000\n Change maximum number of iterations allowed.\n\n tol : float, 1e-3\n Convergence tolerance: threshold to consider the system at steady\n state.\n\n n_jobs : int, default=None\n The number of parallel jobs to run.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n Attributes\n ----------\n X_ : ndarray of shape (n_samples, n_features)\n Input array.\n\n classes_ : ndarray of shape (n_classes,)\n The distinct labels used in classifying instances.\n\n label_distributions_ : ndarray of shape (n_samples, n_classes)\n Categorical distribution for each item.\n\n transduction_ : ndarray of shape (n_samples)\n Label assigned to each item via the transduction.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n Number of iterations run.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn import datasets\n >>> from sklearn.semi_supervised import LabelPropagation\n >>> label_prop_model = LabelPropagation()\n >>> iris = datasets.load_iris()\n >>> rng = np.random.RandomState(42)\n >>> random_unlabeled_points = rng.rand(len(iris.target)) < 0.3\n >>> labels = np.copy(iris.target)\n >>> labels[random_unlabeled_points] = -1\n >>> label_prop_model.fit(iris.data, labels)\n LabelPropagation(...)\n\n References\n ----------\n Xiaojin Zhu and Zoubin Ghahramani. Learning from labeled and unlabeled data\n with label propagation. Technical Report CMU-CALD-02-107, Carnegie Mellon\n University, 2002 http://pages.cs.wisc.edu/~jerryzhu/pub/CMU-CALD-02-107.pdf\n\n See Also\n --------\n LabelSpreading : Alternate label propagation strategy more robust to noise.\n \"\"\"\n _variant = 'propagation'\n \n def __init__(self, kernel='rbf', *, gamma=20, n_neighbors=7, max_iter=1000, tol=0.001, n_jobs=None):\n super().__init__(kernel=kernel, gamma=gamma, n_neighbors=n_neighbors, max_iter=max_iter, tol=tol, n_jobs=n_jobs, alpha=None)\n \n def _build_graph(self):\n \"\"\"Matrix representing a fully connected graph between each sample\n\n This basic implementation creates a non-stochastic affinity matrix, so\n class distributions will exceed 1 (normalization may be desired).\n \"\"\"\n if self.kernel == 'knn':\n self.nn_fit = None\n affinity_matrix = self._get_kernel(self.X_)\n normalizer = affinity_matrix.sum(axis=0)\n if sparse.isspmatrix(affinity_matrix):\n affinity_matrix.data /= np.diag(np.array(normalizer))\n else:\n affinity_matrix /= normalizer[:, np.newaxis]\n return affinity_matrix\n \n def fit(self, X, y):\n return super().fit(X, y)\n" + "description": "Label Propagation classifier.\n\nRead more in the :ref:`User Guide `.", + "docstring": "Label Propagation classifier.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n kernel : {'knn', 'rbf'} or callable, default='rbf'\n String identifier for kernel function to use or the kernel function\n itself. Only 'rbf' and 'knn' strings are valid inputs. The function\n passed should take two inputs, each of shape (n_samples, n_features),\n and return a (n_samples, n_samples) shaped weight matrix.\n\n gamma : float, default=20\n Parameter for rbf kernel.\n\n n_neighbors : int, default=7\n Parameter for knn kernel which need to be strictly positive.\n\n max_iter : int, default=1000\n Change maximum number of iterations allowed.\n\n tol : float, 1e-3\n Convergence tolerance: threshold to consider the system at steady\n state.\n\n n_jobs : int, default=None\n The number of parallel jobs to run.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n Attributes\n ----------\n X_ : ndarray of shape (n_samples, n_features)\n Input array.\n\n classes_ : ndarray of shape (n_classes,)\n The distinct labels used in classifying instances.\n\n label_distributions_ : ndarray of shape (n_samples, n_classes)\n Categorical distribution for each item.\n\n transduction_ : ndarray of shape (n_samples)\n Label assigned to each item via the transduction.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n Number of iterations run.\n\n See Also\n --------\n BaseLabelPropagation : Base class for label propagation module.\n LabelSpreading : Alternate label propagation strategy more robust to noise.\n\n References\n ----------\n Xiaojin Zhu and Zoubin Ghahramani. Learning from labeled and unlabeled data\n with label propagation. Technical Report CMU-CALD-02-107, Carnegie Mellon\n University, 2002 http://pages.cs.wisc.edu/~jerryzhu/pub/CMU-CALD-02-107.pdf\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn import datasets\n >>> from sklearn.semi_supervised import LabelPropagation\n >>> label_prop_model = LabelPropagation()\n >>> iris = datasets.load_iris()\n >>> rng = np.random.RandomState(42)\n >>> random_unlabeled_points = rng.rand(len(iris.target)) < 0.3\n >>> labels = np.copy(iris.target)\n >>> labels[random_unlabeled_points] = -1\n >>> label_prop_model.fit(iris.data, labels)\n LabelPropagation(...)\n ", + "source_code": "\n\nclass LabelPropagation(BaseLabelPropagation):\n \"\"\"Label Propagation classifier.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n kernel : {'knn', 'rbf'} or callable, default='rbf'\n String identifier for kernel function to use or the kernel function\n itself. Only 'rbf' and 'knn' strings are valid inputs. The function\n passed should take two inputs, each of shape (n_samples, n_features),\n and return a (n_samples, n_samples) shaped weight matrix.\n\n gamma : float, default=20\n Parameter for rbf kernel.\n\n n_neighbors : int, default=7\n Parameter for knn kernel which need to be strictly positive.\n\n max_iter : int, default=1000\n Change maximum number of iterations allowed.\n\n tol : float, 1e-3\n Convergence tolerance: threshold to consider the system at steady\n state.\n\n n_jobs : int, default=None\n The number of parallel jobs to run.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n Attributes\n ----------\n X_ : ndarray of shape (n_samples, n_features)\n Input array.\n\n classes_ : ndarray of shape (n_classes,)\n The distinct labels used in classifying instances.\n\n label_distributions_ : ndarray of shape (n_samples, n_classes)\n Categorical distribution for each item.\n\n transduction_ : ndarray of shape (n_samples)\n Label assigned to each item via the transduction.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n Number of iterations run.\n\n See Also\n --------\n BaseLabelPropagation : Base class for label propagation module.\n LabelSpreading : Alternate label propagation strategy more robust to noise.\n\n References\n ----------\n Xiaojin Zhu and Zoubin Ghahramani. Learning from labeled and unlabeled data\n with label propagation. Technical Report CMU-CALD-02-107, Carnegie Mellon\n University, 2002 http://pages.cs.wisc.edu/~jerryzhu/pub/CMU-CALD-02-107.pdf\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn import datasets\n >>> from sklearn.semi_supervised import LabelPropagation\n >>> label_prop_model = LabelPropagation()\n >>> iris = datasets.load_iris()\n >>> rng = np.random.RandomState(42)\n >>> random_unlabeled_points = rng.rand(len(iris.target)) < 0.3\n >>> labels = np.copy(iris.target)\n >>> labels[random_unlabeled_points] = -1\n >>> label_prop_model.fit(iris.data, labels)\n LabelPropagation(...)\n \"\"\"\n _variant = 'propagation'\n \n def __init__(self, kernel='rbf', *, gamma=20, n_neighbors=7, max_iter=1000, tol=0.001, n_jobs=None):\n super().__init__(kernel=kernel, gamma=gamma, n_neighbors=n_neighbors, max_iter=max_iter, tol=tol, n_jobs=n_jobs, alpha=None)\n \n def _build_graph(self):\n \"\"\"Matrix representing a fully connected graph between each sample\n\n This basic implementation creates a non-stochastic affinity matrix, so\n class distributions will exceed 1 (normalization may be desired).\n \"\"\"\n if self.kernel == 'knn':\n self.nn_fit = None\n affinity_matrix = self._get_kernel(self.X_)\n normalizer = affinity_matrix.sum(axis=0)\n if sparse.isspmatrix(affinity_matrix):\n affinity_matrix.data /= np.diag(np.array(normalizer))\n else:\n affinity_matrix /= normalizer[:, np.newaxis]\n return affinity_matrix\n \n def fit(self, X, y):\n \"\"\"Fit a semi-supervised label propagation model to X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training data, where `n_samples` is the number of samples\n and `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target class values with unlabeled points marked as -1.\n All unlabeled samples will be transductively assigned labels\n internally.\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n return super().fit(X, y)\n" }, { "name": "LabelSpreading", @@ -26315,9 +26268,9 @@ "sklearn.semi_supervised._label_propagation.LabelSpreading._build_graph" ], "is_public": true, - "description": "LabelSpreading model for semi-supervised learning\n\nThis model is similar to the basic Label Propagation algorithm, but uses affinity matrix based on the normalized graph Laplacian and soft clamping across the labels. Read more in the :ref:`User Guide `.", - "docstring": "LabelSpreading model for semi-supervised learning\n\n This model is similar to the basic Label Propagation algorithm,\n but uses affinity matrix based on the normalized graph Laplacian\n and soft clamping across the labels.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n kernel : {'knn', 'rbf'} or callable, default='rbf'\n String identifier for kernel function to use or the kernel function\n itself. Only 'rbf' and 'knn' strings are valid inputs. The function\n passed should take two inputs, each of shape (n_samples, n_features),\n and return a (n_samples, n_samples) shaped weight matrix.\n\n gamma : float, default=20\n Parameter for rbf kernel.\n\n n_neighbors : int, default=7\n Parameter for knn kernel which is a strictly positive integer.\n\n alpha : float, default=0.2\n Clamping factor. A value in (0, 1) that specifies the relative amount\n that an instance should adopt the information from its neighbors as\n opposed to its initial label.\n alpha=0 means keeping the initial label information; alpha=1 means\n replacing all initial information.\n\n max_iter : int, default=30\n Maximum number of iterations allowed.\n\n tol : float, default=1e-3\n Convergence tolerance: threshold to consider the system at steady\n state.\n\n n_jobs : int, default=None\n The number of parallel jobs to run.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n Attributes\n ----------\n X_ : ndarray of shape (n_samples, n_features)\n Input array.\n\n classes_ : ndarray of shape (n_classes,)\n The distinct labels used in classifying instances.\n\n label_distributions_ : ndarray of shape (n_samples, n_classes)\n Categorical distribution for each item.\n\n transduction_ : ndarray of shape (n_samples,)\n Label assigned to each item via the transduction.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n Number of iterations run.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn import datasets\n >>> from sklearn.semi_supervised import LabelSpreading\n >>> label_prop_model = LabelSpreading()\n >>> iris = datasets.load_iris()\n >>> rng = np.random.RandomState(42)\n >>> random_unlabeled_points = rng.rand(len(iris.target)) < 0.3\n >>> labels = np.copy(iris.target)\n >>> labels[random_unlabeled_points] = -1\n >>> label_prop_model.fit(iris.data, labels)\n LabelSpreading(...)\n\n References\n ----------\n Dengyong Zhou, Olivier Bousquet, Thomas Navin Lal, Jason Weston,\n Bernhard Schoelkopf. Learning with local and global consistency (2004)\n http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.115.3219\n\n See Also\n --------\n LabelPropagation : Unregularized graph based semi-supervised learning.\n ", - "source_code": "\n\nclass LabelSpreading(BaseLabelPropagation):\n \"\"\"LabelSpreading model for semi-supervised learning\n\n This model is similar to the basic Label Propagation algorithm,\n but uses affinity matrix based on the normalized graph Laplacian\n and soft clamping across the labels.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n kernel : {'knn', 'rbf'} or callable, default='rbf'\n String identifier for kernel function to use or the kernel function\n itself. Only 'rbf' and 'knn' strings are valid inputs. The function\n passed should take two inputs, each of shape (n_samples, n_features),\n and return a (n_samples, n_samples) shaped weight matrix.\n\n gamma : float, default=20\n Parameter for rbf kernel.\n\n n_neighbors : int, default=7\n Parameter for knn kernel which is a strictly positive integer.\n\n alpha : float, default=0.2\n Clamping factor. A value in (0, 1) that specifies the relative amount\n that an instance should adopt the information from its neighbors as\n opposed to its initial label.\n alpha=0 means keeping the initial label information; alpha=1 means\n replacing all initial information.\n\n max_iter : int, default=30\n Maximum number of iterations allowed.\n\n tol : float, default=1e-3\n Convergence tolerance: threshold to consider the system at steady\n state.\n\n n_jobs : int, default=None\n The number of parallel jobs to run.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n Attributes\n ----------\n X_ : ndarray of shape (n_samples, n_features)\n Input array.\n\n classes_ : ndarray of shape (n_classes,)\n The distinct labels used in classifying instances.\n\n label_distributions_ : ndarray of shape (n_samples, n_classes)\n Categorical distribution for each item.\n\n transduction_ : ndarray of shape (n_samples,)\n Label assigned to each item via the transduction.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n Number of iterations run.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn import datasets\n >>> from sklearn.semi_supervised import LabelSpreading\n >>> label_prop_model = LabelSpreading()\n >>> iris = datasets.load_iris()\n >>> rng = np.random.RandomState(42)\n >>> random_unlabeled_points = rng.rand(len(iris.target)) < 0.3\n >>> labels = np.copy(iris.target)\n >>> labels[random_unlabeled_points] = -1\n >>> label_prop_model.fit(iris.data, labels)\n LabelSpreading(...)\n\n References\n ----------\n Dengyong Zhou, Olivier Bousquet, Thomas Navin Lal, Jason Weston,\n Bernhard Schoelkopf. Learning with local and global consistency (2004)\n http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.115.3219\n\n See Also\n --------\n LabelPropagation : Unregularized graph based semi-supervised learning.\n \"\"\"\n _variant = 'spreading'\n \n def __init__(self, kernel='rbf', *, gamma=20, n_neighbors=7, alpha=0.2, max_iter=30, tol=0.001, n_jobs=None):\n super().__init__(kernel=kernel, gamma=gamma, n_neighbors=n_neighbors, alpha=alpha, max_iter=max_iter, tol=tol, n_jobs=n_jobs)\n \n def _build_graph(self):\n \"\"\"Graph matrix for Label Spreading computes the graph laplacian\"\"\"\n if self.kernel == 'knn':\n self.nn_fit = None\n n_samples = self.X_.shape[0]\n affinity_matrix = self._get_kernel(self.X_)\n laplacian = csgraph.laplacian(affinity_matrix, normed=True)\n laplacian = -laplacian\n if sparse.isspmatrix(laplacian):\n diag_mask = laplacian.row == laplacian.col\n laplacian.data[diag_mask] = 0.0\n else:\n laplacian.flat[::n_samples + 1] = 0.0\n return laplacian\n" + "description": "LabelSpreading model for semi-supervised learning.\n\nThis model is similar to the basic Label Propagation algorithm, but uses affinity matrix based on the normalized graph Laplacian and soft clamping across the labels. Read more in the :ref:`User Guide `.", + "docstring": "LabelSpreading model for semi-supervised learning.\n\n This model is similar to the basic Label Propagation algorithm,\n but uses affinity matrix based on the normalized graph Laplacian\n and soft clamping across the labels.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n kernel : {'knn', 'rbf'} or callable, default='rbf'\n String identifier for kernel function to use or the kernel function\n itself. Only 'rbf' and 'knn' strings are valid inputs. The function\n passed should take two inputs, each of shape (n_samples, n_features),\n and return a (n_samples, n_samples) shaped weight matrix.\n\n gamma : float, default=20\n Parameter for rbf kernel.\n\n n_neighbors : int, default=7\n Parameter for knn kernel which is a strictly positive integer.\n\n alpha : float, default=0.2\n Clamping factor. A value in (0, 1) that specifies the relative amount\n that an instance should adopt the information from its neighbors as\n opposed to its initial label.\n alpha=0 means keeping the initial label information; alpha=1 means\n replacing all initial information.\n\n max_iter : int, default=30\n Maximum number of iterations allowed.\n\n tol : float, default=1e-3\n Convergence tolerance: threshold to consider the system at steady\n state.\n\n n_jobs : int, default=None\n The number of parallel jobs to run.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n Attributes\n ----------\n X_ : ndarray of shape (n_samples, n_features)\n Input array.\n\n classes_ : ndarray of shape (n_classes,)\n The distinct labels used in classifying instances.\n\n label_distributions_ : ndarray of shape (n_samples, n_classes)\n Categorical distribution for each item.\n\n transduction_ : ndarray of shape (n_samples,)\n Label assigned to each item via the transduction.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n Number of iterations run.\n\n See Also\n --------\n LabelPropagation : Unregularized graph based semi-supervised learning.\n\n References\n ----------\n Dengyong Zhou, Olivier Bousquet, Thomas Navin Lal, Jason Weston,\n Bernhard Schoelkopf. Learning with local and global consistency (2004)\n http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.115.3219\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn import datasets\n >>> from sklearn.semi_supervised import LabelSpreading\n >>> label_prop_model = LabelSpreading()\n >>> iris = datasets.load_iris()\n >>> rng = np.random.RandomState(42)\n >>> random_unlabeled_points = rng.rand(len(iris.target)) < 0.3\n >>> labels = np.copy(iris.target)\n >>> labels[random_unlabeled_points] = -1\n >>> label_prop_model.fit(iris.data, labels)\n LabelSpreading(...)\n ", + "source_code": "\n\nclass LabelSpreading(BaseLabelPropagation):\n \"\"\"LabelSpreading model for semi-supervised learning.\n\n This model is similar to the basic Label Propagation algorithm,\n but uses affinity matrix based on the normalized graph Laplacian\n and soft clamping across the labels.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n kernel : {'knn', 'rbf'} or callable, default='rbf'\n String identifier for kernel function to use or the kernel function\n itself. Only 'rbf' and 'knn' strings are valid inputs. The function\n passed should take two inputs, each of shape (n_samples, n_features),\n and return a (n_samples, n_samples) shaped weight matrix.\n\n gamma : float, default=20\n Parameter for rbf kernel.\n\n n_neighbors : int, default=7\n Parameter for knn kernel which is a strictly positive integer.\n\n alpha : float, default=0.2\n Clamping factor. A value in (0, 1) that specifies the relative amount\n that an instance should adopt the information from its neighbors as\n opposed to its initial label.\n alpha=0 means keeping the initial label information; alpha=1 means\n replacing all initial information.\n\n max_iter : int, default=30\n Maximum number of iterations allowed.\n\n tol : float, default=1e-3\n Convergence tolerance: threshold to consider the system at steady\n state.\n\n n_jobs : int, default=None\n The number of parallel jobs to run.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n Attributes\n ----------\n X_ : ndarray of shape (n_samples, n_features)\n Input array.\n\n classes_ : ndarray of shape (n_classes,)\n The distinct labels used in classifying instances.\n\n label_distributions_ : ndarray of shape (n_samples, n_classes)\n Categorical distribution for each item.\n\n transduction_ : ndarray of shape (n_samples,)\n Label assigned to each item via the transduction.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n Number of iterations run.\n\n See Also\n --------\n LabelPropagation : Unregularized graph based semi-supervised learning.\n\n References\n ----------\n Dengyong Zhou, Olivier Bousquet, Thomas Navin Lal, Jason Weston,\n Bernhard Schoelkopf. Learning with local and global consistency (2004)\n http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.115.3219\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn import datasets\n >>> from sklearn.semi_supervised import LabelSpreading\n >>> label_prop_model = LabelSpreading()\n >>> iris = datasets.load_iris()\n >>> rng = np.random.RandomState(42)\n >>> random_unlabeled_points = rng.rand(len(iris.target)) < 0.3\n >>> labels = np.copy(iris.target)\n >>> labels[random_unlabeled_points] = -1\n >>> label_prop_model.fit(iris.data, labels)\n LabelSpreading(...)\n \"\"\"\n _variant = 'spreading'\n \n def __init__(self, kernel='rbf', *, gamma=20, n_neighbors=7, alpha=0.2, max_iter=30, tol=0.001, n_jobs=None):\n super().__init__(kernel=kernel, gamma=gamma, n_neighbors=n_neighbors, alpha=alpha, max_iter=max_iter, tol=tol, n_jobs=n_jobs)\n \n def _build_graph(self):\n \"\"\"Graph matrix for Label Spreading computes the graph laplacian\"\"\"\n if self.kernel == 'knn':\n self.nn_fit = None\n n_samples = self.X_.shape[0]\n affinity_matrix = self._get_kernel(self.X_)\n laplacian = csgraph.laplacian(affinity_matrix, normed=True)\n laplacian = -laplacian\n if sparse.isspmatrix(laplacian):\n diag_mask = laplacian.row == laplacian.col\n laplacian.data[diag_mask] = 0.0\n else:\n laplacian.flat[::n_samples + 1] = 0.0\n return laplacian\n" }, { "name": "SelfTrainingClassifier", @@ -26335,8 +26288,8 @@ ], "is_public": true, "description": "Self-training classifier.\n\nThis class allows a given supervised classifier to function as a semi-supervised classifier, allowing it to learn from unlabeled data. It does this by iteratively predicting pseudo-labels for the unlabeled data and adding them to the training set. The classifier will continue iterating until either max_iter is reached, or no pseudo-labels were added to the training set in the previous iteration. Read more in the :ref:`User Guide `.", - "docstring": "Self-training classifier.\n\n This class allows a given supervised classifier to function as a\n semi-supervised classifier, allowing it to learn from unlabeled data. It\n does this by iteratively predicting pseudo-labels for the unlabeled data\n and adding them to the training set.\n\n The classifier will continue iterating until either max_iter is reached, or\n no pseudo-labels were added to the training set in the previous iteration.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n base_estimator : estimator object\n An estimator object implementing ``fit`` and ``predict_proba``.\n Invoking the ``fit`` method will fit a clone of the passed estimator,\n which will be stored in the ``base_estimator_`` attribute.\n\n threshold : float, default=0.75\n The decision threshold for use with `criterion='threshold'`.\n Should be in [0, 1). When using the 'threshold' criterion, a\n :ref:`well calibrated classifier ` should be used.\n\n criterion : {'threshold', 'k_best'}, default='threshold'\n The selection criterion used to select which labels to add to the\n training set. If 'threshold', pseudo-labels with prediction\n probabilities above `threshold` are added to the dataset. If 'k_best',\n the `k_best` pseudo-labels with highest prediction probabilities are\n added to the dataset. When using the 'threshold' criterion, a\n :ref:`well calibrated classifier ` should be used.\n\n k_best : int, default=10\n The amount of samples to add in each iteration. Only used when\n `criterion` is k_best'.\n\n max_iter : int or None, default=10\n Maximum number of iterations allowed. Should be greater than or equal\n to 0. If it is ``None``, the classifier will continue to predict labels\n until no new pseudo-labels are added, or all unlabeled samples have\n been labeled.\n\n verbose : bool, default=False\n Enable verbose output.\n\n Attributes\n ----------\n base_estimator_ : estimator object\n The fitted estimator.\n\n classes_ : ndarray or list of ndarray of shape (n_classes,)\n Class labels for each output. (Taken from the trained\n ``base_estimator_``).\n\n transduction_ : ndarray of shape (n_samples,)\n The labels used for the final fit of the classifier, including\n pseudo-labels added during fit.\n\n labeled_iter_ : ndarray of shape (n_samples,)\n The iteration in which each sample was labeled. When a sample has\n iteration 0, the sample was already labeled in the original dataset.\n When a sample has iteration -1, the sample was not labeled in any\n iteration.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n The number of rounds of self-training, that is the number of times the\n base estimator is fitted on relabeled variants of the training set.\n\n termination_condition_ : {'max_iter', 'no_change', 'all_labeled'}\n The reason that fitting was stopped.\n\n - 'max_iter': `n_iter_` reached `max_iter`.\n - 'no_change': no new labels were predicted.\n - 'all_labeled': all unlabeled samples were labeled before `max_iter`\n was reached.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn import datasets\n >>> from sklearn.semi_supervised import SelfTrainingClassifier\n >>> from sklearn.svm import SVC\n >>> rng = np.random.RandomState(42)\n >>> iris = datasets.load_iris()\n >>> random_unlabeled_points = rng.rand(iris.target.shape[0]) < 0.3\n >>> iris.target[random_unlabeled_points] = -1\n >>> svc = SVC(probability=True, gamma=\"auto\")\n >>> self_training_model = SelfTrainingClassifier(svc)\n >>> self_training_model.fit(iris.data, iris.target)\n SelfTrainingClassifier(...)\n\n References\n ----------\n David Yarowsky. 1995. Unsupervised word sense disambiguation rivaling\n supervised methods. In Proceedings of the 33rd annual meeting on\n Association for Computational Linguistics (ACL '95). Association for\n Computational Linguistics, Stroudsburg, PA, USA, 189-196. DOI:\n https://doi.org/10.3115/981658.981684\n ", - "source_code": "\n\nclass SelfTrainingClassifier(MetaEstimatorMixin, BaseEstimator):\n \"\"\"Self-training classifier.\n\n This class allows a given supervised classifier to function as a\n semi-supervised classifier, allowing it to learn from unlabeled data. It\n does this by iteratively predicting pseudo-labels for the unlabeled data\n and adding them to the training set.\n\n The classifier will continue iterating until either max_iter is reached, or\n no pseudo-labels were added to the training set in the previous iteration.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n base_estimator : estimator object\n An estimator object implementing ``fit`` and ``predict_proba``.\n Invoking the ``fit`` method will fit a clone of the passed estimator,\n which will be stored in the ``base_estimator_`` attribute.\n\n threshold : float, default=0.75\n The decision threshold for use with `criterion='threshold'`.\n Should be in [0, 1). When using the 'threshold' criterion, a\n :ref:`well calibrated classifier ` should be used.\n\n criterion : {'threshold', 'k_best'}, default='threshold'\n The selection criterion used to select which labels to add to the\n training set. If 'threshold', pseudo-labels with prediction\n probabilities above `threshold` are added to the dataset. If 'k_best',\n the `k_best` pseudo-labels with highest prediction probabilities are\n added to the dataset. When using the 'threshold' criterion, a\n :ref:`well calibrated classifier ` should be used.\n\n k_best : int, default=10\n The amount of samples to add in each iteration. Only used when\n `criterion` is k_best'.\n\n max_iter : int or None, default=10\n Maximum number of iterations allowed. Should be greater than or equal\n to 0. If it is ``None``, the classifier will continue to predict labels\n until no new pseudo-labels are added, or all unlabeled samples have\n been labeled.\n\n verbose : bool, default=False\n Enable verbose output.\n\n Attributes\n ----------\n base_estimator_ : estimator object\n The fitted estimator.\n\n classes_ : ndarray or list of ndarray of shape (n_classes,)\n Class labels for each output. (Taken from the trained\n ``base_estimator_``).\n\n transduction_ : ndarray of shape (n_samples,)\n The labels used for the final fit of the classifier, including\n pseudo-labels added during fit.\n\n labeled_iter_ : ndarray of shape (n_samples,)\n The iteration in which each sample was labeled. When a sample has\n iteration 0, the sample was already labeled in the original dataset.\n When a sample has iteration -1, the sample was not labeled in any\n iteration.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n The number of rounds of self-training, that is the number of times the\n base estimator is fitted on relabeled variants of the training set.\n\n termination_condition_ : {'max_iter', 'no_change', 'all_labeled'}\n The reason that fitting was stopped.\n\n - 'max_iter': `n_iter_` reached `max_iter`.\n - 'no_change': no new labels were predicted.\n - 'all_labeled': all unlabeled samples were labeled before `max_iter`\n was reached.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn import datasets\n >>> from sklearn.semi_supervised import SelfTrainingClassifier\n >>> from sklearn.svm import SVC\n >>> rng = np.random.RandomState(42)\n >>> iris = datasets.load_iris()\n >>> random_unlabeled_points = rng.rand(iris.target.shape[0]) < 0.3\n >>> iris.target[random_unlabeled_points] = -1\n >>> svc = SVC(probability=True, gamma=\"auto\")\n >>> self_training_model = SelfTrainingClassifier(svc)\n >>> self_training_model.fit(iris.data, iris.target)\n SelfTrainingClassifier(...)\n\n References\n ----------\n David Yarowsky. 1995. Unsupervised word sense disambiguation rivaling\n supervised methods. In Proceedings of the 33rd annual meeting on\n Association for Computational Linguistics (ACL '95). Association for\n Computational Linguistics, Stroudsburg, PA, USA, 189-196. DOI:\n https://doi.org/10.3115/981658.981684\n \"\"\"\n _estimator_type = 'classifier'\n \n def __init__(self, base_estimator, threshold=0.75, criterion='threshold', k_best=10, max_iter=10, verbose=False):\n self.base_estimator = base_estimator\n self.threshold = threshold\n self.criterion = criterion\n self.k_best = k_best\n self.max_iter = max_iter\n self.verbose = verbose\n \n def fit(self, X, y):\n \"\"\"\n Fits this ``SelfTrainingClassifier`` to a dataset.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\n y : {array-like, sparse matrix} of shape (n_samples,)\n Array representing the labels. Unlabeled samples should have the\n label -1.\n\n Returns\n -------\n self : object\n Returns an instance of self.\n \"\"\"\n (X, y) = self._validate_data(X, y, accept_sparse=['csr', 'csc', 'lil', 'dok'], force_all_finite=False)\n if self.base_estimator is None:\n raise ValueError('base_estimator cannot be None!')\n self.base_estimator_ = clone(self.base_estimator)\n if self.max_iter is not None and self.max_iter < 0:\n raise ValueError(f'max_iter must be >= 0 or None, got {self.max_iter}')\n if not 0 <= self.threshold < 1:\n raise ValueError(f'threshold must be in [0,1), got {self.threshold}')\n if self.criterion not in ['threshold', 'k_best']:\n raise ValueError(f\"criterion must be either 'threshold' or 'k_best', got {self.criterion}.\")\n if y.dtype.kind in ['U', 'S']:\n raise ValueError('y has dtype string. If you wish to predict on string targets, use dtype object, and use -1 as the label for unlabeled samples.')\n has_label = y != -1\n if np.all(has_label):\n warnings.warn('y contains no unlabeled samples', UserWarning)\n if self.criterion == 'k_best' and self.k_best > X.shape[0] - np.sum(has_label):\n warnings.warn('k_best is larger than the amount of unlabeled samples. All unlabeled samples will be labeled in the first iteration', UserWarning)\n self.transduction_ = np.copy(y)\n self.labeled_iter_ = np.full_like(y, -1)\n self.labeled_iter_[has_label] = 0\n self.n_iter_ = 0\n while not np.all(has_label) and (self.max_iter is None or self.n_iter_ < self.max_iter):\n self.n_iter_ += 1\n self.base_estimator_.fit(X[safe_mask(X, has_label)], self.transduction_[has_label])\n _validate_estimator(self.base_estimator_)\n prob = self.base_estimator_.predict_proba(X[safe_mask(X, ~has_label)])\n pred = self.base_estimator_.classes_[np.argmax(prob, axis=1)]\n max_proba = np.max(prob, axis=1)\n if self.criterion == 'threshold':\n selected = max_proba > self.threshold\n else:\n n_to_select = min(self.k_best, max_proba.shape[0])\n if n_to_select == max_proba.shape[0]:\n selected = np.ones_like(max_proba, dtype=bool)\n else:\n selected = np.argpartition(-max_proba, n_to_select)[:n_to_select]\n selected_full = np.nonzero(~has_label)[0][selected]\n self.transduction_[selected_full] = pred[selected]\n has_label[selected_full] = True\n self.labeled_iter_[selected_full] = self.n_iter_\n if selected_full.shape[0] == 0:\n self.termination_condition_ = 'no_change'\n break\n if self.verbose:\n print(f'End of iteration {self.n_iter_}, added {selected_full.shape[0]} new labels.')\n if self.n_iter_ == self.max_iter:\n self.termination_condition_ = 'max_iter'\n if np.all(has_label):\n self.termination_condition_ = 'all_labeled'\n self.base_estimator_.fit(X[safe_mask(X, has_label)], self.transduction_[has_label])\n self.classes_ = self.base_estimator_.classes_\n return self\n \n @if_delegate_has_method(delegate='base_estimator')\n def predict(self, X):\n \"\"\"Predict the classes of X.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\n Returns\n -------\n y : ndarray of shape (n_samples,)\n Array with predicted labels.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse=True, force_all_finite=False, reset=False)\n return self.base_estimator_.predict(X)\n \n def predict_proba(self, X):\n \"\"\"Predict probability for each possible outcome.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\n Returns\n -------\n y : ndarray of shape (n_samples, n_features)\n Array with prediction probabilities.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse=True, force_all_finite=False, reset=False)\n return self.base_estimator_.predict_proba(X)\n \n @if_delegate_has_method(delegate='base_estimator')\n def decision_function(self, X):\n \"\"\"Calls decision function of the `base_estimator`.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\n Returns\n -------\n y : ndarray of shape (n_samples, n_features)\n Result of the decision function of the `base_estimator`.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse=True, force_all_finite=False, reset=False)\n return self.base_estimator_.decision_function(X)\n \n @if_delegate_has_method(delegate='base_estimator')\n def predict_log_proba(self, X):\n \"\"\"Predict log probability for each possible outcome.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\n Returns\n -------\n y : ndarray of shape (n_samples, n_features)\n Array with log prediction probabilities.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse=True, force_all_finite=False, reset=False)\n return self.base_estimator_.predict_log_proba(X)\n \n @if_delegate_has_method(delegate='base_estimator')\n def score(self, X, y):\n \"\"\"Calls score on the `base_estimator`.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\n y : array-like of shape (n_samples,)\n Array representing the labels.\n\n Returns\n -------\n score : float\n Result of calling score on the `base_estimator`.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse=True, force_all_finite=False, reset=False)\n return self.base_estimator_.score(X, y)\n" + "docstring": "Self-training classifier.\n\n This class allows a given supervised classifier to function as a\n semi-supervised classifier, allowing it to learn from unlabeled data. It\n does this by iteratively predicting pseudo-labels for the unlabeled data\n and adding them to the training set.\n\n The classifier will continue iterating until either max_iter is reached, or\n no pseudo-labels were added to the training set in the previous iteration.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n base_estimator : estimator object\n An estimator object implementing `fit` and `predict_proba`.\n Invoking the `fit` method will fit a clone of the passed estimator,\n which will be stored in the `base_estimator_` attribute.\n\n threshold : float, default=0.75\n The decision threshold for use with `criterion='threshold'`.\n Should be in [0, 1). When using the `'threshold'` criterion, a\n :ref:`well calibrated classifier ` should be used.\n\n criterion : {'threshold', 'k_best'}, default='threshold'\n The selection criterion used to select which labels to add to the\n training set. If `'threshold'`, pseudo-labels with prediction\n probabilities above `threshold` are added to the dataset. If `'k_best'`,\n the `k_best` pseudo-labels with highest prediction probabilities are\n added to the dataset. When using the 'threshold' criterion, a\n :ref:`well calibrated classifier ` should be used.\n\n k_best : int, default=10\n The amount of samples to add in each iteration. Only used when\n `criterion='k_best'`.\n\n max_iter : int or None, default=10\n Maximum number of iterations allowed. Should be greater than or equal\n to 0. If it is `None`, the classifier will continue to predict labels\n until no new pseudo-labels are added, or all unlabeled samples have\n been labeled.\n\n verbose : bool, default=False\n Enable verbose output.\n\n Attributes\n ----------\n base_estimator_ : estimator object\n The fitted estimator.\n\n classes_ : ndarray or list of ndarray of shape (n_classes,)\n Class labels for each output. (Taken from the trained\n `base_estimator_`).\n\n transduction_ : ndarray of shape (n_samples,)\n The labels used for the final fit of the classifier, including\n pseudo-labels added during fit.\n\n labeled_iter_ : ndarray of shape (n_samples,)\n The iteration in which each sample was labeled. When a sample has\n iteration 0, the sample was already labeled in the original dataset.\n When a sample has iteration -1, the sample was not labeled in any\n iteration.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n The number of rounds of self-training, that is the number of times the\n base estimator is fitted on relabeled variants of the training set.\n\n termination_condition_ : {'max_iter', 'no_change', 'all_labeled'}\n The reason that fitting was stopped.\n\n - `'max_iter'`: `n_iter_` reached `max_iter`.\n - `'no_change'`: no new labels were predicted.\n - `'all_labeled'`: all unlabeled samples were labeled before `max_iter`\n was reached.\n\n See Also\n --------\n LabelPropagation : Label propagation classifier.\n LabelSpreading : Label spreading model for semi-supervised learning.\n\n References\n ----------\n David Yarowsky. 1995. Unsupervised word sense disambiguation rivaling\n supervised methods. In Proceedings of the 33rd annual meeting on\n Association for Computational Linguistics (ACL '95). Association for\n Computational Linguistics, Stroudsburg, PA, USA, 189-196. DOI:\n https://doi.org/10.3115/981658.981684\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn import datasets\n >>> from sklearn.semi_supervised import SelfTrainingClassifier\n >>> from sklearn.svm import SVC\n >>> rng = np.random.RandomState(42)\n >>> iris = datasets.load_iris()\n >>> random_unlabeled_points = rng.rand(iris.target.shape[0]) < 0.3\n >>> iris.target[random_unlabeled_points] = -1\n >>> svc = SVC(probability=True, gamma=\"auto\")\n >>> self_training_model = SelfTrainingClassifier(svc)\n >>> self_training_model.fit(iris.data, iris.target)\n SelfTrainingClassifier(...)\n ", + "source_code": "\n\nclass SelfTrainingClassifier(MetaEstimatorMixin, BaseEstimator):\n \"\"\"Self-training classifier.\n\n This class allows a given supervised classifier to function as a\n semi-supervised classifier, allowing it to learn from unlabeled data. It\n does this by iteratively predicting pseudo-labels for the unlabeled data\n and adding them to the training set.\n\n The classifier will continue iterating until either max_iter is reached, or\n no pseudo-labels were added to the training set in the previous iteration.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n base_estimator : estimator object\n An estimator object implementing `fit` and `predict_proba`.\n Invoking the `fit` method will fit a clone of the passed estimator,\n which will be stored in the `base_estimator_` attribute.\n\n threshold : float, default=0.75\n The decision threshold for use with `criterion='threshold'`.\n Should be in [0, 1). When using the `'threshold'` criterion, a\n :ref:`well calibrated classifier ` should be used.\n\n criterion : {'threshold', 'k_best'}, default='threshold'\n The selection criterion used to select which labels to add to the\n training set. If `'threshold'`, pseudo-labels with prediction\n probabilities above `threshold` are added to the dataset. If `'k_best'`,\n the `k_best` pseudo-labels with highest prediction probabilities are\n added to the dataset. When using the 'threshold' criterion, a\n :ref:`well calibrated classifier ` should be used.\n\n k_best : int, default=10\n The amount of samples to add in each iteration. Only used when\n `criterion='k_best'`.\n\n max_iter : int or None, default=10\n Maximum number of iterations allowed. Should be greater than or equal\n to 0. If it is `None`, the classifier will continue to predict labels\n until no new pseudo-labels are added, or all unlabeled samples have\n been labeled.\n\n verbose : bool, default=False\n Enable verbose output.\n\n Attributes\n ----------\n base_estimator_ : estimator object\n The fitted estimator.\n\n classes_ : ndarray or list of ndarray of shape (n_classes,)\n Class labels for each output. (Taken from the trained\n `base_estimator_`).\n\n transduction_ : ndarray of shape (n_samples,)\n The labels used for the final fit of the classifier, including\n pseudo-labels added during fit.\n\n labeled_iter_ : ndarray of shape (n_samples,)\n The iteration in which each sample was labeled. When a sample has\n iteration 0, the sample was already labeled in the original dataset.\n When a sample has iteration -1, the sample was not labeled in any\n iteration.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_iter_ : int\n The number of rounds of self-training, that is the number of times the\n base estimator is fitted on relabeled variants of the training set.\n\n termination_condition_ : {'max_iter', 'no_change', 'all_labeled'}\n The reason that fitting was stopped.\n\n - `'max_iter'`: `n_iter_` reached `max_iter`.\n - `'no_change'`: no new labels were predicted.\n - `'all_labeled'`: all unlabeled samples were labeled before `max_iter`\n was reached.\n\n See Also\n --------\n LabelPropagation : Label propagation classifier.\n LabelSpreading : Label spreading model for semi-supervised learning.\n\n References\n ----------\n David Yarowsky. 1995. Unsupervised word sense disambiguation rivaling\n supervised methods. In Proceedings of the 33rd annual meeting on\n Association for Computational Linguistics (ACL '95). Association for\n Computational Linguistics, Stroudsburg, PA, USA, 189-196. DOI:\n https://doi.org/10.3115/981658.981684\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn import datasets\n >>> from sklearn.semi_supervised import SelfTrainingClassifier\n >>> from sklearn.svm import SVC\n >>> rng = np.random.RandomState(42)\n >>> iris = datasets.load_iris()\n >>> random_unlabeled_points = rng.rand(iris.target.shape[0]) < 0.3\n >>> iris.target[random_unlabeled_points] = -1\n >>> svc = SVC(probability=True, gamma=\"auto\")\n >>> self_training_model = SelfTrainingClassifier(svc)\n >>> self_training_model.fit(iris.data, iris.target)\n SelfTrainingClassifier(...)\n \"\"\"\n _estimator_type = 'classifier'\n \n def __init__(self, base_estimator, threshold=0.75, criterion='threshold', k_best=10, max_iter=10, verbose=False):\n self.base_estimator = base_estimator\n self.threshold = threshold\n self.criterion = criterion\n self.k_best = k_best\n self.max_iter = max_iter\n self.verbose = verbose\n \n def fit(self, X, y):\n \"\"\"\n Fit self-training classifier using `X`, `y` as training data.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\n y : {array-like, sparse matrix} of shape (n_samples,)\n Array representing the labels. Unlabeled samples should have the\n label -1.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n (X, y) = self._validate_data(X, y, accept_sparse=['csr', 'csc', 'lil', 'dok'], force_all_finite=False)\n if self.base_estimator is None:\n raise ValueError('base_estimator cannot be None!')\n self.base_estimator_ = clone(self.base_estimator)\n if self.max_iter is not None and self.max_iter < 0:\n raise ValueError(f'max_iter must be >= 0 or None, got {self.max_iter}')\n if not 0 <= self.threshold < 1:\n raise ValueError(f'threshold must be in [0,1), got {self.threshold}')\n if self.criterion not in ['threshold', 'k_best']:\n raise ValueError(f\"criterion must be either 'threshold' or 'k_best', got {self.criterion}.\")\n if y.dtype.kind in ['U', 'S']:\n raise ValueError('y has dtype string. If you wish to predict on string targets, use dtype object, and use -1 as the label for unlabeled samples.')\n has_label = y != -1\n if np.all(has_label):\n warnings.warn('y contains no unlabeled samples', UserWarning)\n if self.criterion == 'k_best' and self.k_best > X.shape[0] - np.sum(has_label):\n warnings.warn('k_best is larger than the amount of unlabeled samples. All unlabeled samples will be labeled in the first iteration', UserWarning)\n self.transduction_ = np.copy(y)\n self.labeled_iter_ = np.full_like(y, -1)\n self.labeled_iter_[has_label] = 0\n self.n_iter_ = 0\n while not np.all(has_label) and (self.max_iter is None or self.n_iter_ < self.max_iter):\n self.n_iter_ += 1\n self.base_estimator_.fit(X[safe_mask(X, has_label)], self.transduction_[has_label])\n _validate_estimator(self.base_estimator_)\n prob = self.base_estimator_.predict_proba(X[safe_mask(X, ~has_label)])\n pred = self.base_estimator_.classes_[np.argmax(prob, axis=1)]\n max_proba = np.max(prob, axis=1)\n if self.criterion == 'threshold':\n selected = max_proba > self.threshold\n else:\n n_to_select = min(self.k_best, max_proba.shape[0])\n if n_to_select == max_proba.shape[0]:\n selected = np.ones_like(max_proba, dtype=bool)\n else:\n selected = np.argpartition(-max_proba, n_to_select)[:n_to_select]\n selected_full = np.nonzero(~has_label)[0][selected]\n self.transduction_[selected_full] = pred[selected]\n has_label[selected_full] = True\n self.labeled_iter_[selected_full] = self.n_iter_\n if selected_full.shape[0] == 0:\n self.termination_condition_ = 'no_change'\n break\n if self.verbose:\n print(f'End of iteration {self.n_iter_}, added {selected_full.shape[0]} new labels.')\n if self.n_iter_ == self.max_iter:\n self.termination_condition_ = 'max_iter'\n if np.all(has_label):\n self.termination_condition_ = 'all_labeled'\n self.base_estimator_.fit(X[safe_mask(X, has_label)], self.transduction_[has_label])\n self.classes_ = self.base_estimator_.classes_\n return self\n \n @if_delegate_has_method(delegate='base_estimator')\n def predict(self, X):\n \"\"\"Predict the classes of `X`.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\n Returns\n -------\n y : ndarray of shape (n_samples,)\n Array with predicted labels.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse=True, force_all_finite=False, reset=False)\n return self.base_estimator_.predict(X)\n \n def predict_proba(self, X):\n \"\"\"Predict probability for each possible outcome.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\n Returns\n -------\n y : ndarray of shape (n_samples, n_features)\n Array with prediction probabilities.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse=True, force_all_finite=False, reset=False)\n return self.base_estimator_.predict_proba(X)\n \n @if_delegate_has_method(delegate='base_estimator')\n def decision_function(self, X):\n \"\"\"Call decision function of the `base_estimator`.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\n Returns\n -------\n y : ndarray of shape (n_samples, n_features)\n Result of the decision function of the `base_estimator`.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse=True, force_all_finite=False, reset=False)\n return self.base_estimator_.decision_function(X)\n \n @if_delegate_has_method(delegate='base_estimator')\n def predict_log_proba(self, X):\n \"\"\"Predict log probability for each possible outcome.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\n Returns\n -------\n y : ndarray of shape (n_samples, n_features)\n Array with log prediction probabilities.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse=True, force_all_finite=False, reset=False)\n return self.base_estimator_.predict_log_proba(X)\n \n @if_delegate_has_method(delegate='base_estimator')\n def score(self, X, y):\n \"\"\"Call score on the `base_estimator`.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\n y : array-like of shape (n_samples,)\n Array representing the labels.\n\n Returns\n -------\n score : float\n Result of calling score on the `base_estimator`.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse=True, force_all_finite=False, reset=False)\n return self.base_estimator_.score(X, y)\n" }, { "name": "BaseLibSVM", @@ -26346,7 +26299,7 @@ "methods": [ "sklearn.svm._base.BaseLibSVM.__init__", "sklearn.svm._base.BaseLibSVM._more_tags", - "sklearn.svm._base.BaseLibSVM._pairwise", + "sklearn.svm._base.BaseLibSVM._pairwise@getter", "sklearn.svm._base.BaseLibSVM.fit", "sklearn.svm._base.BaseLibSVM._validate_targets", "sklearn.svm._base.BaseLibSVM._warn_from_fit_status", @@ -26360,14 +26313,14 @@ "sklearn.svm._base.BaseLibSVM._dense_decision_function", "sklearn.svm._base.BaseLibSVM._sparse_decision_function", "sklearn.svm._base.BaseLibSVM._validate_for_predict", - "sklearn.svm._base.BaseLibSVM.coef_", + "sklearn.svm._base.BaseLibSVM.coef_@getter", "sklearn.svm._base.BaseLibSVM._get_coef", - "sklearn.svm._base.BaseLibSVM.n_support_" + "sklearn.svm._base.BaseLibSVM.n_support_@getter" ], "is_public": false, "description": "Base class for estimators that use libsvm as backing library.\n\nThis implements support vector machine classification and regression. Parameter documentation is in the derived `SVC` class.", "docstring": "Base class for estimators that use libsvm as backing library.\n\n This implements support vector machine classification and regression.\n\n Parameter documentation is in the derived `SVC` class.\n ", - "source_code": "\n\nclass BaseLibSVM(BaseEstimator, metaclass=ABCMeta):\n \"\"\"Base class for estimators that use libsvm as backing library.\n\n This implements support vector machine classification and regression.\n\n Parameter documentation is in the derived `SVC` class.\n \"\"\"\n _sparse_kernels = ['linear', 'poly', 'rbf', 'sigmoid', 'precomputed']\n \n @abstractmethod\n def __init__(self, kernel, degree, gamma, coef0, tol, C, nu, epsilon, shrinking, probability, cache_size, class_weight, verbose, max_iter, random_state):\n if self._impl not in LIBSVM_IMPL:\n raise ValueError('impl should be one of %s, %s was given' % (LIBSVM_IMPL, self._impl))\n if gamma == 0:\n msg = \"The gamma value of 0.0 is invalid. Use 'auto' to set gamma to a value of 1 / n_features.\"\n raise ValueError(msg)\n self.kernel = kernel\n self.degree = degree\n self.gamma = gamma\n self.coef0 = coef0\n self.tol = tol\n self.C = C\n self.nu = nu\n self.epsilon = epsilon\n self.shrinking = shrinking\n self.probability = probability\n self.cache_size = cache_size\n self.class_weight = class_weight\n self.verbose = verbose\n self.max_iter = max_iter\n self.random_state = random_state\n \n def _more_tags(self):\n return {'pairwise': self.kernel == 'precomputed'}\n \n @deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def _pairwise(self):\n return self.kernel == 'precomputed'\n \n def fit(self, X, y, sample_weight=None):\n \"\"\"Fit the SVM model according to the given training data.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples)\n Training vectors, where `n_samples` is the number of samples\n and `n_features` is the number of features.\n For kernel=\"precomputed\", the expected shape of X is\n (n_samples, n_samples).\n\n y : array-like of shape (n_samples,)\n Target values (class labels in classification, real numbers in\n regression).\n\n sample_weight : array-like of shape (n_samples,), default=None\n Per-sample weights. Rescale C per sample. Higher weights\n force the classifier to put more emphasis on these points.\n\n Returns\n -------\n self : object\n Fitted estimator.\n\n Notes\n -----\n If X and y are not C-ordered and contiguous arrays of np.float64 and\n X is not a scipy.sparse.csr_matrix, X and/or y may be copied.\n\n If X is a dense array, then the other methods will not support sparse\n matrices as input.\n \"\"\"\n rnd = check_random_state(self.random_state)\n sparse = sp.isspmatrix(X)\n if sparse and self.kernel == 'precomputed':\n raise TypeError('Sparse precomputed kernels are not supported.')\n self._sparse = sparse and not callable(self.kernel)\n if hasattr(self, 'decision_function_shape'):\n if self.decision_function_shape not in ('ovr', 'ovo'):\n raise ValueError(f\"decision_function_shape must be either 'ovr' or 'ovo', got {self.decision_function_shape}.\")\n if callable(self.kernel):\n check_consistent_length(X, y)\n else:\n (X, y) = self._validate_data(X, y, dtype=np.float64, order='C', accept_sparse='csr', accept_large_sparse=False)\n y = self._validate_targets(y)\n sample_weight = np.asarray([] if sample_weight is None else sample_weight, dtype=np.float64)\n solver_type = LIBSVM_IMPL.index(self._impl)\n n_samples = _num_samples(X)\n if solver_type != 2 and n_samples != y.shape[0]:\n raise ValueError('X and y have incompatible shapes.\\n' + 'X has %s samples, but y has %s.' % (n_samples, y.shape[0]))\n if self.kernel == 'precomputed' and n_samples != X.shape[1]:\n raise ValueError('Precomputed matrix must be a square matrix. Input is a {}x{} matrix.'.format(X.shape[0], X.shape[1]))\n if sample_weight.shape[0] > 0 and sample_weight.shape[0] != n_samples:\n raise ValueError('sample_weight and X have incompatible shapes: %r vs %r\\nNote: Sparse matrices cannot be indexed w/boolean masks (use `indices=True` in CV).' % (sample_weight.shape, X.shape))\n kernel = 'precomputed' if callable(self.kernel) else self.kernel\n if kernel == 'precomputed':\n self._gamma = 0.0\n elif isinstance(self.gamma, str):\n if self.gamma == 'scale':\n X_var = X.multiply(X).mean() - X.mean()**2 if sparse else X.var()\n self._gamma = 1.0 / (X.shape[1] * X_var) if X_var != 0 else 1.0\n elif self.gamma == 'auto':\n self._gamma = 1.0 / X.shape[1]\n else:\n raise ValueError(\"When 'gamma' is a string, it should be either 'scale' or 'auto'. Got '{}' instead.\".format(self.gamma))\n else:\n self._gamma = self.gamma\n fit = self._sparse_fit if self._sparse else self._dense_fit\n if self.verbose:\n print('[LibSVM]', end='')\n seed = rnd.randint(np.iinfo('i').max)\n fit(X, y, sample_weight, solver_type, kernel, random_seed=seed)\n self.shape_fit_ = X.shape if hasattr(X, 'shape') else (n_samples, )\n self._intercept_ = self.intercept_.copy()\n self._dual_coef_ = self.dual_coef_\n if self._impl in ['c_svc', 'nu_svc'] and len(self.classes_) == 2:\n self.intercept_ *= -1\n self.dual_coef_ = -self.dual_coef_\n return self\n \n def _validate_targets(self, y):\n \"\"\"Validation of y and class_weight.\n\n Default implementation for SVR and one-class; overridden in BaseSVC.\n \"\"\"\n self.class_weight_ = np.empty(0)\n return column_or_1d(y, warn=True).astype(np.float64, copy=False)\n \n def _warn_from_fit_status(self):\n assert self.fit_status_ in (0, 1)\n if self.fit_status_ == 1:\n warnings.warn('Solver terminated early (max_iter=%i). Consider pre-processing your data with StandardScaler or MinMaxScaler.' % self.max_iter, ConvergenceWarning)\n \n def _dense_fit(self, X, y, sample_weight, solver_type, kernel, random_seed):\n if callable(self.kernel):\n self.__Xfit = X\n X = self._compute_kernel(X)\n if X.shape[0] != X.shape[1]:\n raise ValueError('X.shape[0] should be equal to X.shape[1]')\n libsvm.set_verbosity_wrap(self.verbose)\n (self.support_, self.support_vectors_, self._n_support, self.dual_coef_, self.intercept_, self._probA, self._probB, self.fit_status_) = libsvm.fit(X, y, svm_type=solver_type, sample_weight=sample_weight, class_weight=self.class_weight_, kernel=kernel, C=self.C, nu=self.nu, probability=self.probability, degree=self.degree, shrinking=self.shrinking, tol=self.tol, cache_size=self.cache_size, coef0=self.coef0, gamma=self._gamma, epsilon=self.epsilon, max_iter=self.max_iter, random_seed=random_seed)\n self._warn_from_fit_status()\n \n def _sparse_fit(self, X, y, sample_weight, solver_type, kernel, random_seed):\n X.data = np.asarray(X.data, dtype=np.float64, order='C')\n X.sort_indices()\n kernel_type = self._sparse_kernels.index(kernel)\n libsvm_sparse.set_verbosity_wrap(self.verbose)\n (self.support_, self.support_vectors_, dual_coef_data, self.intercept_, self._n_support, self._probA, self._probB, self.fit_status_) = libsvm_sparse.libsvm_sparse_train(X.shape[1], X.data, X.indices, X.indptr, y, solver_type, kernel_type, self.degree, self._gamma, self.coef0, self.tol, self.C, self.class_weight_, sample_weight, self.nu, self.cache_size, self.epsilon, int(self.shrinking), int(self.probability), self.max_iter, random_seed)\n self._warn_from_fit_status()\n if hasattr(self, 'classes_'):\n n_class = len(self.classes_) - 1\n else:\n n_class = 1\n n_SV = self.support_vectors_.shape[0]\n dual_coef_indices = np.tile(np.arange(n_SV), n_class)\n if not n_SV:\n self.dual_coef_ = sp.csr_matrix([])\n else:\n dual_coef_indptr = np.arange(0, dual_coef_indices.size + 1, dual_coef_indices.size / n_class)\n self.dual_coef_ = sp.csr_matrix((dual_coef_data, dual_coef_indices, dual_coef_indptr), (n_class, n_SV))\n \n def predict(self, X):\n \"\"\"Perform regression on samples in X.\n\n For an one-class model, +1 (inlier) or -1 (outlier) is returned.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n For kernel=\"precomputed\", the expected shape of X is\n (n_samples_test, n_samples_train).\n\n Returns\n -------\n y_pred : ndarray of shape (n_samples,)\n The predicted values.\n \"\"\"\n X = self._validate_for_predict(X)\n predict = self._sparse_predict if self._sparse else self._dense_predict\n return predict(X)\n \n def _dense_predict(self, X):\n X = self._compute_kernel(X)\n if X.ndim == 1:\n X = check_array(X, order='C', accept_large_sparse=False)\n kernel = self.kernel\n if callable(self.kernel):\n kernel = 'precomputed'\n if X.shape[1] != self.shape_fit_[0]:\n raise ValueError('X.shape[1] = %d should be equal to %d, the number of samples at training time' % (X.shape[1], self.shape_fit_[0]))\n svm_type = LIBSVM_IMPL.index(self._impl)\n return libsvm.predict(X, self.support_, self.support_vectors_, self._n_support, self._dual_coef_, self._intercept_, self._probA, self._probB, svm_type=svm_type, kernel=kernel, degree=self.degree, coef0=self.coef0, gamma=self._gamma, cache_size=self.cache_size)\n \n def _sparse_predict(self, X):\n kernel = self.kernel\n if callable(kernel):\n kernel = 'precomputed'\n kernel_type = self._sparse_kernels.index(kernel)\n C = 0.0\n return libsvm_sparse.libsvm_sparse_predict(X.data, X.indices, X.indptr, self.support_vectors_.data, self.support_vectors_.indices, self.support_vectors_.indptr, self._dual_coef_.data, self._intercept_, LIBSVM_IMPL.index(self._impl), kernel_type, self.degree, self._gamma, self.coef0, self.tol, C, self.class_weight_, self.nu, self.epsilon, self.shrinking, self.probability, self._n_support, self._probA, self._probB)\n \n def _compute_kernel(self, X):\n \"\"\"Return the data transformed by a callable kernel\"\"\"\n if callable(self.kernel):\n kernel = self.kernel(X, self.__Xfit)\n if sp.issparse(kernel):\n kernel = kernel.toarray()\n X = np.asarray(kernel, dtype=np.float64, order='C')\n return X\n \n def _decision_function(self, X):\n \"\"\"Evaluates the decision function for the samples in X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n\n Returns\n -------\n X : array-like of shape (n_samples, n_class * (n_class-1) / 2)\n Returns the decision function of the sample for each class\n in the model.\n \"\"\"\n X = self._validate_for_predict(X)\n X = self._compute_kernel(X)\n if self._sparse:\n dec_func = self._sparse_decision_function(X)\n else:\n dec_func = self._dense_decision_function(X)\n if self._impl in ['c_svc', 'nu_svc'] and len(self.classes_) == 2:\n return -dec_func.ravel()\n return dec_func\n \n def _dense_decision_function(self, X):\n X = check_array(X, dtype=np.float64, order='C', accept_large_sparse=False)\n kernel = self.kernel\n if callable(kernel):\n kernel = 'precomputed'\n return libsvm.decision_function(X, self.support_, self.support_vectors_, self._n_support, self._dual_coef_, self._intercept_, self._probA, self._probB, svm_type=LIBSVM_IMPL.index(self._impl), kernel=kernel, degree=self.degree, cache_size=self.cache_size, coef0=self.coef0, gamma=self._gamma)\n \n def _sparse_decision_function(self, X):\n X.data = np.asarray(X.data, dtype=np.float64, order='C')\n kernel = self.kernel\n if hasattr(kernel, '__call__'):\n kernel = 'precomputed'\n kernel_type = self._sparse_kernels.index(kernel)\n return libsvm_sparse.libsvm_sparse_decision_function(X.data, X.indices, X.indptr, self.support_vectors_.data, self.support_vectors_.indices, self.support_vectors_.indptr, self._dual_coef_.data, self._intercept_, LIBSVM_IMPL.index(self._impl), kernel_type, self.degree, self._gamma, self.coef0, self.tol, self.C, self.class_weight_, self.nu, self.epsilon, self.shrinking, self.probability, self._n_support, self._probA, self._probB)\n \n def _validate_for_predict(self, X):\n check_is_fitted(self)\n if not callable(self.kernel):\n X = self._validate_data(X, accept_sparse='csr', dtype=np.float64, order='C', accept_large_sparse=False, reset=False)\n if self._sparse and not sp.isspmatrix(X):\n X = sp.csr_matrix(X)\n if self._sparse:\n X.sort_indices()\n if sp.issparse(X) and not self._sparse and not callable(self.kernel):\n raise ValueError('cannot use sparse input in %r trained on dense data' % type(self).__name__)\n if self.kernel == 'precomputed':\n if X.shape[1] != self.shape_fit_[0]:\n raise ValueError('X.shape[1] = %d should be equal to %d, the number of samples at training time' % (X.shape[1], self.shape_fit_[0]))\n return X\n \n @property\n def coef_(self):\n \"\"\"Weights assigned to the features when `kernel=\"linear\"`.\n\n Returns\n -------\n ndarray of shape (n_features, n_classes)\n \"\"\"\n if self.kernel != 'linear':\n raise AttributeError('coef_ is only available when using a linear kernel')\n coef = self._get_coef()\n if sp.issparse(coef):\n coef.data.flags.writeable = False\n else:\n coef.flags.writeable = False\n return coef\n \n def _get_coef(self):\n return safe_sparse_dot(self._dual_coef_, self.support_vectors_)\n \n @property\n def n_support_(self):\n \"\"\"Number of support vectors for each class.\"\"\"\n try:\n check_is_fitted(self)\n except NotFittedError:\n raise AttributeError\n svm_type = LIBSVM_IMPL.index(self._impl)\n if svm_type in (0, 1):\n return self._n_support\n else:\n return np.array([self._n_support[0]])\n" + "source_code": "\n\nclass BaseLibSVM(BaseEstimator, metaclass=ABCMeta):\n \"\"\"Base class for estimators that use libsvm as backing library.\n\n This implements support vector machine classification and regression.\n\n Parameter documentation is in the derived `SVC` class.\n \"\"\"\n _sparse_kernels = ['linear', 'poly', 'rbf', 'sigmoid', 'precomputed']\n \n @abstractmethod\n def __init__(self, kernel, degree, gamma, coef0, tol, C, nu, epsilon, shrinking, probability, cache_size, class_weight, verbose, max_iter, random_state):\n if self._impl not in LIBSVM_IMPL:\n raise ValueError('impl should be one of %s, %s was given' % (LIBSVM_IMPL, self._impl))\n if gamma == 0:\n msg = \"The gamma value of 0.0 is invalid. Use 'auto' to set gamma to a value of 1 / n_features.\"\n raise ValueError(msg)\n self.kernel = kernel\n self.degree = degree\n self.gamma = gamma\n self.coef0 = coef0\n self.tol = tol\n self.C = C\n self.nu = nu\n self.epsilon = epsilon\n self.shrinking = shrinking\n self.probability = probability\n self.cache_size = cache_size\n self.class_weight = class_weight\n self.verbose = verbose\n self.max_iter = max_iter\n self.random_state = random_state\n \n def _more_tags(self):\n return {'pairwise': self.kernel == 'precomputed'}\n \n @deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')\n @property\n def _pairwise(self):\n return self.kernel == 'precomputed'\n \n def fit(self, X, y, sample_weight=None):\n \"\"\"Fit the SVM model according to the given training data.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples)\n Training vectors, where `n_samples` is the number of samples\n and `n_features` is the number of features.\n For kernel=\"precomputed\", the expected shape of X is\n (n_samples, n_samples).\n\n y : array-like of shape (n_samples,)\n Target values (class labels in classification, real numbers in\n regression).\n\n sample_weight : array-like of shape (n_samples,), default=None\n Per-sample weights. Rescale C per sample. Higher weights\n force the classifier to put more emphasis on these points.\n\n Returns\n -------\n self : object\n Fitted estimator.\n\n Notes\n -----\n If X and y are not C-ordered and contiguous arrays of np.float64 and\n X is not a scipy.sparse.csr_matrix, X and/or y may be copied.\n\n If X is a dense array, then the other methods will not support sparse\n matrices as input.\n \"\"\"\n rnd = check_random_state(self.random_state)\n sparse = sp.isspmatrix(X)\n if sparse and self.kernel == 'precomputed':\n raise TypeError('Sparse precomputed kernels are not supported.')\n self._sparse = sparse and not callable(self.kernel)\n if hasattr(self, 'decision_function_shape'):\n if self.decision_function_shape not in ('ovr', 'ovo'):\n raise ValueError(f\"decision_function_shape must be either 'ovr' or 'ovo', got {self.decision_function_shape}.\")\n if callable(self.kernel):\n check_consistent_length(X, y)\n else:\n (X, y) = self._validate_data(X, y, dtype=np.float64, order='C', accept_sparse='csr', accept_large_sparse=False)\n y = self._validate_targets(y)\n sample_weight = np.asarray([] if sample_weight is None else sample_weight, dtype=np.float64)\n solver_type = LIBSVM_IMPL.index(self._impl)\n n_samples = _num_samples(X)\n if solver_type != 2 and n_samples != y.shape[0]:\n raise ValueError('X and y have incompatible shapes.\\n' + 'X has %s samples, but y has %s.' % (n_samples, y.shape[0]))\n if self.kernel == 'precomputed' and n_samples != X.shape[1]:\n raise ValueError('Precomputed matrix must be a square matrix. Input is a {}x{} matrix.'.format(X.shape[0], X.shape[1]))\n if sample_weight.shape[0] > 0 and sample_weight.shape[0] != n_samples:\n raise ValueError('sample_weight and X have incompatible shapes: %r vs %r\\nNote: Sparse matrices cannot be indexed w/boolean masks (use `indices=True` in CV).' % (sample_weight.shape, X.shape))\n kernel = 'precomputed' if callable(self.kernel) else self.kernel\n if kernel == 'precomputed':\n self._gamma = 0.0\n elif isinstance(self.gamma, str):\n if self.gamma == 'scale':\n X_var = X.multiply(X).mean() - X.mean()**2 if sparse else X.var()\n self._gamma = 1.0 / (X.shape[1] * X_var) if X_var != 0 else 1.0\n elif self.gamma == 'auto':\n self._gamma = 1.0 / X.shape[1]\n else:\n raise ValueError(\"When 'gamma' is a string, it should be either 'scale' or 'auto'. Got '{}' instead.\".format(self.gamma))\n else:\n self._gamma = self.gamma\n fit = self._sparse_fit if self._sparse else self._dense_fit\n if self.verbose:\n print('[LibSVM]', end='')\n seed = rnd.randint(np.iinfo('i').max)\n fit(X, y, sample_weight, solver_type, kernel, random_seed=seed)\n self.shape_fit_ = X.shape if hasattr(X, 'shape') else (n_samples, )\n self._intercept_ = self.intercept_.copy()\n self._dual_coef_ = self.dual_coef_\n if self._impl in ['c_svc', 'nu_svc'] and len(self.classes_) == 2:\n self.intercept_ *= -1\n self.dual_coef_ = -self.dual_coef_\n return self\n \n def _validate_targets(self, y):\n \"\"\"Validation of y and class_weight.\n\n Default implementation for SVR and one-class; overridden in BaseSVC.\n \"\"\"\n self.class_weight_ = np.empty(0)\n return column_or_1d(y, warn=True).astype(np.float64, copy=False)\n \n def _warn_from_fit_status(self):\n assert self.fit_status_ in (0, 1)\n if self.fit_status_ == 1:\n warnings.warn('Solver terminated early (max_iter=%i). Consider pre-processing your data with StandardScaler or MinMaxScaler.' % self.max_iter, ConvergenceWarning)\n \n def _dense_fit(self, X, y, sample_weight, solver_type, kernel, random_seed):\n if callable(self.kernel):\n self.__Xfit = X\n X = self._compute_kernel(X)\n if X.shape[0] != X.shape[1]:\n raise ValueError('X.shape[0] should be equal to X.shape[1]')\n libsvm.set_verbosity_wrap(self.verbose)\n (self.support_, self.support_vectors_, self._n_support, self.dual_coef_, self.intercept_, self._probA, self._probB, self.fit_status_) = libsvm.fit(X, y, svm_type=solver_type, sample_weight=sample_weight, class_weight=self.class_weight_, kernel=kernel, C=self.C, nu=self.nu, probability=self.probability, degree=self.degree, shrinking=self.shrinking, tol=self.tol, cache_size=self.cache_size, coef0=self.coef0, gamma=self._gamma, epsilon=self.epsilon, max_iter=self.max_iter, random_seed=random_seed)\n self._warn_from_fit_status()\n \n def _sparse_fit(self, X, y, sample_weight, solver_type, kernel, random_seed):\n X.data = np.asarray(X.data, dtype=np.float64, order='C')\n X.sort_indices()\n kernel_type = self._sparse_kernels.index(kernel)\n libsvm_sparse.set_verbosity_wrap(self.verbose)\n (self.support_, self.support_vectors_, dual_coef_data, self.intercept_, self._n_support, self._probA, self._probB, self.fit_status_) = libsvm_sparse.libsvm_sparse_train(X.shape[1], X.data, X.indices, X.indptr, y, solver_type, kernel_type, self.degree, self._gamma, self.coef0, self.tol, self.C, self.class_weight_, sample_weight, self.nu, self.cache_size, self.epsilon, int(self.shrinking), int(self.probability), self.max_iter, random_seed)\n self._warn_from_fit_status()\n if hasattr(self, 'classes_'):\n n_class = len(self.classes_) - 1\n else:\n n_class = 1\n n_SV = self.support_vectors_.shape[0]\n dual_coef_indices = np.tile(np.arange(n_SV), n_class)\n if not n_SV:\n self.dual_coef_ = sp.csr_matrix([])\n else:\n dual_coef_indptr = np.arange(0, dual_coef_indices.size + 1, dual_coef_indices.size / n_class)\n self.dual_coef_ = sp.csr_matrix((dual_coef_data, dual_coef_indices, dual_coef_indptr), (n_class, n_SV))\n \n def predict(self, X):\n \"\"\"Perform regression on samples in X.\n\n For an one-class model, +1 (inlier) or -1 (outlier) is returned.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n For kernel=\"precomputed\", the expected shape of X is\n (n_samples_test, n_samples_train).\n\n Returns\n -------\n y_pred : ndarray of shape (n_samples,)\n The predicted values.\n \"\"\"\n X = self._validate_for_predict(X)\n predict = self._sparse_predict if self._sparse else self._dense_predict\n return predict(X)\n \n def _dense_predict(self, X):\n X = self._compute_kernel(X)\n if X.ndim == 1:\n X = check_array(X, order='C', accept_large_sparse=False)\n kernel = self.kernel\n if callable(self.kernel):\n kernel = 'precomputed'\n if X.shape[1] != self.shape_fit_[0]:\n raise ValueError('X.shape[1] = %d should be equal to %d, the number of samples at training time' % (X.shape[1], self.shape_fit_[0]))\n svm_type = LIBSVM_IMPL.index(self._impl)\n return libsvm.predict(X, self.support_, self.support_vectors_, self._n_support, self._dual_coef_, self._intercept_, self._probA, self._probB, svm_type=svm_type, kernel=kernel, degree=self.degree, coef0=self.coef0, gamma=self._gamma, cache_size=self.cache_size)\n \n def _sparse_predict(self, X):\n kernel = self.kernel\n if callable(kernel):\n kernel = 'precomputed'\n kernel_type = self._sparse_kernels.index(kernel)\n C = 0.0\n return libsvm_sparse.libsvm_sparse_predict(X.data, X.indices, X.indptr, self.support_vectors_.data, self.support_vectors_.indices, self.support_vectors_.indptr, self._dual_coef_.data, self._intercept_, LIBSVM_IMPL.index(self._impl), kernel_type, self.degree, self._gamma, self.coef0, self.tol, C, self.class_weight_, self.nu, self.epsilon, self.shrinking, self.probability, self._n_support, self._probA, self._probB)\n \n def _compute_kernel(self, X):\n \"\"\"Return the data transformed by a callable kernel\"\"\"\n if callable(self.kernel):\n kernel = self.kernel(X, self.__Xfit)\n if sp.issparse(kernel):\n kernel = kernel.toarray()\n X = np.asarray(kernel, dtype=np.float64, order='C')\n return X\n \n def _decision_function(self, X):\n \"\"\"Evaluates the decision function for the samples in X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n\n Returns\n -------\n X : array-like of shape (n_samples, n_class * (n_class-1) / 2)\n Returns the decision function of the sample for each class\n in the model.\n \"\"\"\n X = self._validate_for_predict(X)\n X = self._compute_kernel(X)\n if self._sparse:\n dec_func = self._sparse_decision_function(X)\n else:\n dec_func = self._dense_decision_function(X)\n if self._impl in ['c_svc', 'nu_svc'] and len(self.classes_) == 2:\n return -dec_func.ravel()\n return dec_func\n \n def _dense_decision_function(self, X):\n X = check_array(X, dtype=np.float64, order='C', accept_large_sparse=False)\n kernel = self.kernel\n if callable(kernel):\n kernel = 'precomputed'\n return libsvm.decision_function(X, self.support_, self.support_vectors_, self._n_support, self._dual_coef_, self._intercept_, self._probA, self._probB, svm_type=LIBSVM_IMPL.index(self._impl), kernel=kernel, degree=self.degree, cache_size=self.cache_size, coef0=self.coef0, gamma=self._gamma)\n \n def _sparse_decision_function(self, X):\n X.data = np.asarray(X.data, dtype=np.float64, order='C')\n kernel = self.kernel\n if hasattr(kernel, '__call__'):\n kernel = 'precomputed'\n kernel_type = self._sparse_kernels.index(kernel)\n return libsvm_sparse.libsvm_sparse_decision_function(X.data, X.indices, X.indptr, self.support_vectors_.data, self.support_vectors_.indices, self.support_vectors_.indptr, self._dual_coef_.data, self._intercept_, LIBSVM_IMPL.index(self._impl), kernel_type, self.degree, self._gamma, self.coef0, self.tol, self.C, self.class_weight_, self.nu, self.epsilon, self.shrinking, self.probability, self._n_support, self._probA, self._probB)\n \n def _validate_for_predict(self, X):\n check_is_fitted(self)\n if not callable(self.kernel):\n X = self._validate_data(X, accept_sparse='csr', dtype=np.float64, order='C', accept_large_sparse=False, reset=False)\n if self._sparse and not sp.isspmatrix(X):\n X = sp.csr_matrix(X)\n if self._sparse:\n X.sort_indices()\n if sp.issparse(X) and not self._sparse and not callable(self.kernel):\n raise ValueError('cannot use sparse input in %r trained on dense data' % type(self).__name__)\n if self.kernel == 'precomputed':\n if X.shape[1] != self.shape_fit_[0]:\n raise ValueError('X.shape[1] = %d should be equal to %d, the number of samples at training time' % (X.shape[1], self.shape_fit_[0]))\n sv = self.support_vectors_\n if not self._sparse and sv.size > 0 and self.n_support_.sum() != sv.shape[0]:\n raise ValueError(f'The internal representation of {self.__class__.__name__} was altered')\n return X\n \n @property\n def coef_(self):\n \"\"\"Weights assigned to the features when `kernel=\"linear\"`.\n\n Returns\n -------\n ndarray of shape (n_features, n_classes)\n \"\"\"\n if self.kernel != 'linear':\n raise AttributeError('coef_ is only available when using a linear kernel')\n coef = self._get_coef()\n if sp.issparse(coef):\n coef.data.flags.writeable = False\n else:\n coef.flags.writeable = False\n return coef\n \n def _get_coef(self):\n return safe_sparse_dot(self._dual_coef_, self.support_vectors_)\n \n @property\n def n_support_(self):\n \"\"\"Number of support vectors for each class.\"\"\"\n try:\n check_is_fitted(self)\n except NotFittedError:\n raise AttributeError\n svm_type = LIBSVM_IMPL.index(self._impl)\n if svm_type in (0, 1):\n return self._n_support\n else:\n return np.array([self._n_support[0]])\n" }, { "name": "BaseSVC", @@ -26385,8 +26338,8 @@ "sklearn.svm._base.BaseSVC._dense_predict_proba", "sklearn.svm._base.BaseSVC._sparse_predict_proba", "sklearn.svm._base.BaseSVC._get_coef", - "sklearn.svm._base.BaseSVC.probA_", - "sklearn.svm._base.BaseSVC.probB_" + "sklearn.svm._base.BaseSVC.probA_@getter", + "sklearn.svm._base.BaseSVC.probB_@getter" ], "is_public": false, "description": "ABC for LibSVM-based classifiers.", @@ -26517,7 +26470,7 @@ "sklearn.tree._classes.BaseDecisionTree.decision_path", "sklearn.tree._classes.BaseDecisionTree._prune_tree", "sklearn.tree._classes.BaseDecisionTree.cost_complexity_pruning_path", - "sklearn.tree._classes.BaseDecisionTree.feature_importances_" + "sklearn.tree._classes.BaseDecisionTree.feature_importances_@getter" ], "is_public": true, "description": "Base class for decision trees.\n\nWarning: This class should not be used directly. Use derived classes instead.", @@ -26534,7 +26487,7 @@ "sklearn.tree._classes.DecisionTreeClassifier.fit", "sklearn.tree._classes.DecisionTreeClassifier.predict_proba", "sklearn.tree._classes.DecisionTreeClassifier.predict_log_proba", - "sklearn.tree._classes.DecisionTreeClassifier.n_features_", + "sklearn.tree._classes.DecisionTreeClassifier.n_features_@getter", "sklearn.tree._classes.DecisionTreeClassifier._more_tags" ], "is_public": true, @@ -26551,12 +26504,12 @@ "sklearn.tree._classes.DecisionTreeRegressor.__init__", "sklearn.tree._classes.DecisionTreeRegressor.fit", "sklearn.tree._classes.DecisionTreeRegressor._compute_partial_dependence_recursion", - "sklearn.tree._classes.DecisionTreeRegressor.n_features_" + "sklearn.tree._classes.DecisionTreeRegressor.n_features_@getter" ], "is_public": true, "description": "A decision tree regressor.\n\nRead more in the :ref:`User Guide `.", - "docstring": "A decision tree regressor.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n criterion : {\"squared_error\", \"mse\", \"friedman_mse\", \"absolute_error\", \"mae\", \"poisson\"}, default=\"squared_error\"\n The function to measure the quality of a split. Supported criteria\n are \"squared_error\" for the mean squared error, which is equal to\n variance reduction as feature selection criterion and minimizes the L2\n loss using the mean of each terminal node, \"friedman_mse\", which uses\n mean squared error with Friedman's improvement score for potential\n splits, \"absolute_error\" for the mean absolute error, which minimizes\n the L1 loss using the median of each terminal node, and \"poisson\" which\n uses reduction in Poisson deviance to find splits.\n\n .. versionadded:: 0.18\n Mean Absolute Error (MAE) criterion.\n\n .. versionadded:: 0.24\n Poisson deviance criterion.\n\n .. deprecated:: 1.0\n Criterion \"mse\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"squared_error\"` which is equivalent.\n\n .. deprecated:: 1.0\n Criterion \"mae\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"absolute_error\"` which is equivalent.\n\n splitter : {\"best\", \"random\"}, default=\"best\"\n The strategy used to choose the split at each node. Supported\n strategies are \"best\" to choose the best split and \"random\" to choose\n the best random split.\n\n max_depth : int, default=None\n The maximum depth of the tree. If None, then nodes are expanded until\n all leaves are pure or until all leaves contain less than\n min_samples_split samples.\n\n min_samples_split : int or float, default=2\n The minimum number of samples required to split an internal node:\n\n - If int, then consider `min_samples_split` as the minimum number.\n - If float, then `min_samples_split` is a fraction and\n `ceil(min_samples_split * n_samples)` are the minimum\n number of samples for each split.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_samples_leaf : int or float, default=1\n The minimum number of samples required to be at a leaf node.\n A split point at any depth will only be considered if it leaves at\n least ``min_samples_leaf`` training samples in each of the left and\n right branches. This may have the effect of smoothing the model,\n especially in regression.\n\n - If int, then consider `min_samples_leaf` as the minimum number.\n - If float, then `min_samples_leaf` is a fraction and\n `ceil(min_samples_leaf * n_samples)` are the minimum\n number of samples for each node.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_weight_fraction_leaf : float, default=0.0\n The minimum weighted fraction of the sum total of weights (of all\n the input samples) required to be at a leaf node. Samples have\n equal weight when sample_weight is not provided.\n\n max_features : int, float or {\"auto\", \"sqrt\", \"log2\"}, default=None\n The number of features to consider when looking for the best split:\n\n - If int, then consider `max_features` features at each split.\n - If float, then `max_features` is a fraction and\n `int(max_features * n_features)` features are considered at each\n split.\n - If \"auto\", then `max_features=n_features`.\n - If \"sqrt\", then `max_features=sqrt(n_features)`.\n - If \"log2\", then `max_features=log2(n_features)`.\n - If None, then `max_features=n_features`.\n\n Note: the search for a split does not stop until at least one\n valid partition of the node samples is found, even if it requires to\n effectively inspect more than ``max_features`` features.\n\n random_state : int, RandomState instance or None, default=None\n Controls the randomness of the estimator. The features are always\n randomly permuted at each split, even if ``splitter`` is set to\n ``\"best\"``. When ``max_features < n_features``, the algorithm will\n select ``max_features`` at random at each split before finding the best\n split among them. But the best found split may vary across different\n runs, even if ``max_features=n_features``. That is the case, if the\n improvement of the criterion is identical for several splits and one\n split has to be selected at random. To obtain a deterministic behaviour\n during fitting, ``random_state`` has to be fixed to an integer.\n See :term:`Glossary ` for details.\n\n max_leaf_nodes : int, default=None\n Grow a tree with ``max_leaf_nodes`` in best-first fashion.\n Best nodes are defined as relative reduction in impurity.\n If None then unlimited number of leaf nodes.\n\n min_impurity_decrease : float, default=0.0\n A node will be split if this split induces a decrease of the impurity\n greater than or equal to this value.\n\n The weighted impurity decrease equation is the following::\n\n N_t / N * (impurity - N_t_R / N_t * right_impurity\n - N_t_L / N_t * left_impurity)\n\n where ``N`` is the total number of samples, ``N_t`` is the number of\n samples at the current node, ``N_t_L`` is the number of samples in the\n left child, and ``N_t_R`` is the number of samples in the right child.\n\n ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n if ``sample_weight`` is passed.\n\n .. versionadded:: 0.19\n\n ccp_alpha : non-negative float, default=0.0\n Complexity parameter used for Minimal Cost-Complexity Pruning. The\n subtree with the largest cost complexity that is smaller than\n ``ccp_alpha`` will be chosen. By default, no pruning is performed. See\n :ref:`minimal_cost_complexity_pruning` for details.\n\n .. versionadded:: 0.22\n\n Attributes\n ----------\n feature_importances_ : ndarray of shape (n_features,)\n The feature importances.\n The higher, the more important the feature.\n The importance of a feature is computed as the\n (normalized) total reduction of the criterion brought\n by that feature. It is also known as the Gini importance [4]_.\n\n Warning: impurity-based feature importances can be misleading for\n high cardinality features (many unique values). See\n :func:`sklearn.inspection.permutation_importance` as an alternative.\n\n max_features_ : int\n The inferred value of max_features.\n\n n_features_ : int\n The number of features when ``fit`` is performed.\n\n .. deprecated:: 1.0\n `n_features_` is deprecated in 1.0 and will be removed in\n 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_outputs_ : int\n The number of outputs when ``fit`` is performed.\n\n tree_ : Tree instance\n The underlying Tree object. Please refer to\n ``help(sklearn.tree._tree.Tree)`` for attributes of Tree object and\n :ref:`sphx_glr_auto_examples_tree_plot_unveil_tree_structure.py`\n for basic usage of these attributes.\n\n See Also\n --------\n DecisionTreeClassifier : A decision tree classifier.\n\n Notes\n -----\n The default values for the parameters controlling the size of the trees\n (e.g. ``max_depth``, ``min_samples_leaf``, etc.) lead to fully grown and\n unpruned trees which can potentially be very large on some data sets. To\n reduce memory consumption, the complexity and size of the trees should be\n controlled by setting those parameter values.\n\n References\n ----------\n\n .. [1] https://en.wikipedia.org/wiki/Decision_tree_learning\n\n .. [2] L. Breiman, J. Friedman, R. Olshen, and C. Stone, \"Classification\n and Regression Trees\", Wadsworth, Belmont, CA, 1984.\n\n .. [3] T. Hastie, R. Tibshirani and J. Friedman. \"Elements of Statistical\n Learning\", Springer, 2009.\n\n .. [4] L. Breiman, and A. Cutler, \"Random Forests\",\n https://www.stat.berkeley.edu/~breiman/RandomForests/cc_home.htm\n\n Examples\n --------\n >>> from sklearn.datasets import load_diabetes\n >>> from sklearn.model_selection import cross_val_score\n >>> from sklearn.tree import DecisionTreeRegressor\n >>> X, y = load_diabetes(return_X_y=True)\n >>> regressor = DecisionTreeRegressor(random_state=0)\n >>> cross_val_score(regressor, X, y, cv=10)\n ... # doctest: +SKIP\n ...\n array([-0.39..., -0.46..., 0.02..., 0.06..., -0.50...,\n 0.16..., 0.11..., -0.73..., -0.30..., -0.00...])\n ", - "source_code": "\n\nclass DecisionTreeRegressor(RegressorMixin, BaseDecisionTree):\n \"\"\"A decision tree regressor.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n criterion : {\"squared_error\", \"mse\", \"friedman_mse\", \"absolute_error\", \"mae\", \"poisson\"}, default=\"squared_error\"\n The function to measure the quality of a split. Supported criteria\n are \"squared_error\" for the mean squared error, which is equal to\n variance reduction as feature selection criterion and minimizes the L2\n loss using the mean of each terminal node, \"friedman_mse\", which uses\n mean squared error with Friedman's improvement score for potential\n splits, \"absolute_error\" for the mean absolute error, which minimizes\n the L1 loss using the median of each terminal node, and \"poisson\" which\n uses reduction in Poisson deviance to find splits.\n\n .. versionadded:: 0.18\n Mean Absolute Error (MAE) criterion.\n\n .. versionadded:: 0.24\n Poisson deviance criterion.\n\n .. deprecated:: 1.0\n Criterion \"mse\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"squared_error\"` which is equivalent.\n\n .. deprecated:: 1.0\n Criterion \"mae\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"absolute_error\"` which is equivalent.\n\n splitter : {\"best\", \"random\"}, default=\"best\"\n The strategy used to choose the split at each node. Supported\n strategies are \"best\" to choose the best split and \"random\" to choose\n the best random split.\n\n max_depth : int, default=None\n The maximum depth of the tree. If None, then nodes are expanded until\n all leaves are pure or until all leaves contain less than\n min_samples_split samples.\n\n min_samples_split : int or float, default=2\n The minimum number of samples required to split an internal node:\n\n - If int, then consider `min_samples_split` as the minimum number.\n - If float, then `min_samples_split` is a fraction and\n `ceil(min_samples_split * n_samples)` are the minimum\n number of samples for each split.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_samples_leaf : int or float, default=1\n The minimum number of samples required to be at a leaf node.\n A split point at any depth will only be considered if it leaves at\n least ``min_samples_leaf`` training samples in each of the left and\n right branches. This may have the effect of smoothing the model,\n especially in regression.\n\n - If int, then consider `min_samples_leaf` as the minimum number.\n - If float, then `min_samples_leaf` is a fraction and\n `ceil(min_samples_leaf * n_samples)` are the minimum\n number of samples for each node.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_weight_fraction_leaf : float, default=0.0\n The minimum weighted fraction of the sum total of weights (of all\n the input samples) required to be at a leaf node. Samples have\n equal weight when sample_weight is not provided.\n\n max_features : int, float or {\"auto\", \"sqrt\", \"log2\"}, default=None\n The number of features to consider when looking for the best split:\n\n - If int, then consider `max_features` features at each split.\n - If float, then `max_features` is a fraction and\n `int(max_features * n_features)` features are considered at each\n split.\n - If \"auto\", then `max_features=n_features`.\n - If \"sqrt\", then `max_features=sqrt(n_features)`.\n - If \"log2\", then `max_features=log2(n_features)`.\n - If None, then `max_features=n_features`.\n\n Note: the search for a split does not stop until at least one\n valid partition of the node samples is found, even if it requires to\n effectively inspect more than ``max_features`` features.\n\n random_state : int, RandomState instance or None, default=None\n Controls the randomness of the estimator. The features are always\n randomly permuted at each split, even if ``splitter`` is set to\n ``\"best\"``. When ``max_features < n_features``, the algorithm will\n select ``max_features`` at random at each split before finding the best\n split among them. But the best found split may vary across different\n runs, even if ``max_features=n_features``. That is the case, if the\n improvement of the criterion is identical for several splits and one\n split has to be selected at random. To obtain a deterministic behaviour\n during fitting, ``random_state`` has to be fixed to an integer.\n See :term:`Glossary ` for details.\n\n max_leaf_nodes : int, default=None\n Grow a tree with ``max_leaf_nodes`` in best-first fashion.\n Best nodes are defined as relative reduction in impurity.\n If None then unlimited number of leaf nodes.\n\n min_impurity_decrease : float, default=0.0\n A node will be split if this split induces a decrease of the impurity\n greater than or equal to this value.\n\n The weighted impurity decrease equation is the following::\n\n N_t / N * (impurity - N_t_R / N_t * right_impurity\n - N_t_L / N_t * left_impurity)\n\n where ``N`` is the total number of samples, ``N_t`` is the number of\n samples at the current node, ``N_t_L`` is the number of samples in the\n left child, and ``N_t_R`` is the number of samples in the right child.\n\n ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n if ``sample_weight`` is passed.\n\n .. versionadded:: 0.19\n\n ccp_alpha : non-negative float, default=0.0\n Complexity parameter used for Minimal Cost-Complexity Pruning. The\n subtree with the largest cost complexity that is smaller than\n ``ccp_alpha`` will be chosen. By default, no pruning is performed. See\n :ref:`minimal_cost_complexity_pruning` for details.\n\n .. versionadded:: 0.22\n\n Attributes\n ----------\n feature_importances_ : ndarray of shape (n_features,)\n The feature importances.\n The higher, the more important the feature.\n The importance of a feature is computed as the\n (normalized) total reduction of the criterion brought\n by that feature. It is also known as the Gini importance [4]_.\n\n Warning: impurity-based feature importances can be misleading for\n high cardinality features (many unique values). See\n :func:`sklearn.inspection.permutation_importance` as an alternative.\n\n max_features_ : int\n The inferred value of max_features.\n\n n_features_ : int\n The number of features when ``fit`` is performed.\n\n .. deprecated:: 1.0\n `n_features_` is deprecated in 1.0 and will be removed in\n 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_outputs_ : int\n The number of outputs when ``fit`` is performed.\n\n tree_ : Tree instance\n The underlying Tree object. Please refer to\n ``help(sklearn.tree._tree.Tree)`` for attributes of Tree object and\n :ref:`sphx_glr_auto_examples_tree_plot_unveil_tree_structure.py`\n for basic usage of these attributes.\n\n See Also\n --------\n DecisionTreeClassifier : A decision tree classifier.\n\n Notes\n -----\n The default values for the parameters controlling the size of the trees\n (e.g. ``max_depth``, ``min_samples_leaf``, etc.) lead to fully grown and\n unpruned trees which can potentially be very large on some data sets. To\n reduce memory consumption, the complexity and size of the trees should be\n controlled by setting those parameter values.\n\n References\n ----------\n\n .. [1] https://en.wikipedia.org/wiki/Decision_tree_learning\n\n .. [2] L. Breiman, J. Friedman, R. Olshen, and C. Stone, \"Classification\n and Regression Trees\", Wadsworth, Belmont, CA, 1984.\n\n .. [3] T. Hastie, R. Tibshirani and J. Friedman. \"Elements of Statistical\n Learning\", Springer, 2009.\n\n .. [4] L. Breiman, and A. Cutler, \"Random Forests\",\n https://www.stat.berkeley.edu/~breiman/RandomForests/cc_home.htm\n\n Examples\n --------\n >>> from sklearn.datasets import load_diabetes\n >>> from sklearn.model_selection import cross_val_score\n >>> from sklearn.tree import DecisionTreeRegressor\n >>> X, y = load_diabetes(return_X_y=True)\n >>> regressor = DecisionTreeRegressor(random_state=0)\n >>> cross_val_score(regressor, X, y, cv=10)\n ... # doctest: +SKIP\n ...\n array([-0.39..., -0.46..., 0.02..., 0.06..., -0.50...,\n 0.16..., 0.11..., -0.73..., -0.30..., -0.00...])\n \"\"\"\n \n def __init__(self, *, criterion='squared_error', splitter='best', max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features=None, random_state=None, max_leaf_nodes=None, min_impurity_decrease=0.0, ccp_alpha=0.0):\n super().__init__(criterion=criterion, splitter=splitter, max_depth=max_depth, min_samples_split=min_samples_split, min_samples_leaf=min_samples_leaf, min_weight_fraction_leaf=min_weight_fraction_leaf, max_features=max_features, max_leaf_nodes=max_leaf_nodes, random_state=random_state, min_impurity_decrease=min_impurity_decrease, ccp_alpha=ccp_alpha)\n \n def fit(self, X, y, sample_weight=None, check_input=True, X_idx_sorted='deprecated'):\n \"\"\"Build a decision tree regressor from the training set (X, y).\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Internally, it will be converted to\n ``dtype=np.float32`` and if a sparse matrix is provided\n to a sparse ``csc_matrix``.\n\n y : array-like of shape (n_samples,) or (n_samples, n_outputs)\n The target values (real numbers). Use ``dtype=np.float64`` and\n ``order='C'`` for maximum efficiency.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted. Splits\n that would create child nodes with net zero or negative weight are\n ignored while searching for a split in each node.\n\n check_input : bool, default=True\n Allow to bypass several input checking.\n Don't use this parameter unless you know what you do.\n\n X_idx_sorted : deprecated, default=\"deprecated\"\n This parameter is deprecated and has no effect.\n It will be removed in 1.1 (renaming of 0.26).\n\n .. deprecated:: 0.24\n\n Returns\n -------\n self : DecisionTreeRegressor\n Fitted estimator.\n \"\"\"\n super().fit(X, y, sample_weight=sample_weight, check_input=check_input, X_idx_sorted=X_idx_sorted)\n return self\n \n def _compute_partial_dependence_recursion(self, grid, target_features):\n \"\"\"Fast partial dependence computation.\n\n Parameters\n ----------\n grid : ndarray of shape (n_samples, n_target_features)\n The grid points on which the partial dependence should be\n evaluated.\n target_features : ndarray of shape (n_target_features)\n The set of target features for which the partial dependence\n should be evaluated.\n\n Returns\n -------\n averaged_predictions : ndarray of shape (n_samples,)\n The value of the partial dependence function on each grid point.\n \"\"\"\n grid = np.asarray(grid, dtype=DTYPE, order='C')\n averaged_predictions = np.zeros(shape=grid.shape[0], dtype=np.float64, order='C')\n self.tree_.compute_partial_dependence(grid, target_features, averaged_predictions)\n return averaged_predictions\n \n @deprecated('The attribute `n_features_` is deprecated in 1.0 and will be removed in 1.2. Use `n_features_in_` instead.')\n @property\n def n_features_(self):\n return self.n_features_in_\n" + "docstring": "A decision tree regressor.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n criterion : {\"squared_error\", \"friedman_mse\", \"absolute_error\", \"poisson\"}, default=\"squared_error\"\n The function to measure the quality of a split. Supported criteria\n are \"squared_error\" for the mean squared error, which is equal to\n variance reduction as feature selection criterion and minimizes the L2\n loss using the mean of each terminal node, \"friedman_mse\", which uses\n mean squared error with Friedman's improvement score for potential\n splits, \"absolute_error\" for the mean absolute error, which minimizes\n the L1 loss using the median of each terminal node, and \"poisson\" which\n uses reduction in Poisson deviance to find splits.\n\n .. versionadded:: 0.18\n Mean Absolute Error (MAE) criterion.\n\n .. versionadded:: 0.24\n Poisson deviance criterion.\n\n .. deprecated:: 1.0\n Criterion \"mse\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"squared_error\"` which is equivalent.\n\n .. deprecated:: 1.0\n Criterion \"mae\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"absolute_error\"` which is equivalent.\n\n splitter : {\"best\", \"random\"}, default=\"best\"\n The strategy used to choose the split at each node. Supported\n strategies are \"best\" to choose the best split and \"random\" to choose\n the best random split.\n\n max_depth : int, default=None\n The maximum depth of the tree. If None, then nodes are expanded until\n all leaves are pure or until all leaves contain less than\n min_samples_split samples.\n\n min_samples_split : int or float, default=2\n The minimum number of samples required to split an internal node:\n\n - If int, then consider `min_samples_split` as the minimum number.\n - If float, then `min_samples_split` is a fraction and\n `ceil(min_samples_split * n_samples)` are the minimum\n number of samples for each split.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_samples_leaf : int or float, default=1\n The minimum number of samples required to be at a leaf node.\n A split point at any depth will only be considered if it leaves at\n least ``min_samples_leaf`` training samples in each of the left and\n right branches. This may have the effect of smoothing the model,\n especially in regression.\n\n - If int, then consider `min_samples_leaf` as the minimum number.\n - If float, then `min_samples_leaf` is a fraction and\n `ceil(min_samples_leaf * n_samples)` are the minimum\n number of samples for each node.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_weight_fraction_leaf : float, default=0.0\n The minimum weighted fraction of the sum total of weights (of all\n the input samples) required to be at a leaf node. Samples have\n equal weight when sample_weight is not provided.\n\n max_features : int, float or {\"auto\", \"sqrt\", \"log2\"}, default=None\n The number of features to consider when looking for the best split:\n\n - If int, then consider `max_features` features at each split.\n - If float, then `max_features` is a fraction and\n `int(max_features * n_features)` features are considered at each\n split.\n - If \"auto\", then `max_features=n_features`.\n - If \"sqrt\", then `max_features=sqrt(n_features)`.\n - If \"log2\", then `max_features=log2(n_features)`.\n - If None, then `max_features=n_features`.\n\n Note: the search for a split does not stop until at least one\n valid partition of the node samples is found, even if it requires to\n effectively inspect more than ``max_features`` features.\n\n random_state : int, RandomState instance or None, default=None\n Controls the randomness of the estimator. The features are always\n randomly permuted at each split, even if ``splitter`` is set to\n ``\"best\"``. When ``max_features < n_features``, the algorithm will\n select ``max_features`` at random at each split before finding the best\n split among them. But the best found split may vary across different\n runs, even if ``max_features=n_features``. That is the case, if the\n improvement of the criterion is identical for several splits and one\n split has to be selected at random. To obtain a deterministic behaviour\n during fitting, ``random_state`` has to be fixed to an integer.\n See :term:`Glossary ` for details.\n\n max_leaf_nodes : int, default=None\n Grow a tree with ``max_leaf_nodes`` in best-first fashion.\n Best nodes are defined as relative reduction in impurity.\n If None then unlimited number of leaf nodes.\n\n min_impurity_decrease : float, default=0.0\n A node will be split if this split induces a decrease of the impurity\n greater than or equal to this value.\n\n The weighted impurity decrease equation is the following::\n\n N_t / N * (impurity - N_t_R / N_t * right_impurity\n - N_t_L / N_t * left_impurity)\n\n where ``N`` is the total number of samples, ``N_t`` is the number of\n samples at the current node, ``N_t_L`` is the number of samples in the\n left child, and ``N_t_R`` is the number of samples in the right child.\n\n ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n if ``sample_weight`` is passed.\n\n .. versionadded:: 0.19\n\n ccp_alpha : non-negative float, default=0.0\n Complexity parameter used for Minimal Cost-Complexity Pruning. The\n subtree with the largest cost complexity that is smaller than\n ``ccp_alpha`` will be chosen. By default, no pruning is performed. See\n :ref:`minimal_cost_complexity_pruning` for details.\n\n .. versionadded:: 0.22\n\n Attributes\n ----------\n feature_importances_ : ndarray of shape (n_features,)\n The feature importances.\n The higher, the more important the feature.\n The importance of a feature is computed as the\n (normalized) total reduction of the criterion brought\n by that feature. It is also known as the Gini importance [4]_.\n\n Warning: impurity-based feature importances can be misleading for\n high cardinality features (many unique values). See\n :func:`sklearn.inspection.permutation_importance` as an alternative.\n\n max_features_ : int\n The inferred value of max_features.\n\n n_features_ : int\n The number of features when ``fit`` is performed.\n\n .. deprecated:: 1.0\n `n_features_` is deprecated in 1.0 and will be removed in\n 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_outputs_ : int\n The number of outputs when ``fit`` is performed.\n\n tree_ : Tree instance\n The underlying Tree object. Please refer to\n ``help(sklearn.tree._tree.Tree)`` for attributes of Tree object and\n :ref:`sphx_glr_auto_examples_tree_plot_unveil_tree_structure.py`\n for basic usage of these attributes.\n\n See Also\n --------\n DecisionTreeClassifier : A decision tree classifier.\n\n Notes\n -----\n The default values for the parameters controlling the size of the trees\n (e.g. ``max_depth``, ``min_samples_leaf``, etc.) lead to fully grown and\n unpruned trees which can potentially be very large on some data sets. To\n reduce memory consumption, the complexity and size of the trees should be\n controlled by setting those parameter values.\n\n References\n ----------\n\n .. [1] https://en.wikipedia.org/wiki/Decision_tree_learning\n\n .. [2] L. Breiman, J. Friedman, R. Olshen, and C. Stone, \"Classification\n and Regression Trees\", Wadsworth, Belmont, CA, 1984.\n\n .. [3] T. Hastie, R. Tibshirani and J. Friedman. \"Elements of Statistical\n Learning\", Springer, 2009.\n\n .. [4] L. Breiman, and A. Cutler, \"Random Forests\",\n https://www.stat.berkeley.edu/~breiman/RandomForests/cc_home.htm\n\n Examples\n --------\n >>> from sklearn.datasets import load_diabetes\n >>> from sklearn.model_selection import cross_val_score\n >>> from sklearn.tree import DecisionTreeRegressor\n >>> X, y = load_diabetes(return_X_y=True)\n >>> regressor = DecisionTreeRegressor(random_state=0)\n >>> cross_val_score(regressor, X, y, cv=10)\n ... # doctest: +SKIP\n ...\n array([-0.39..., -0.46..., 0.02..., 0.06..., -0.50...,\n 0.16..., 0.11..., -0.73..., -0.30..., -0.00...])\n ", + "source_code": "\n\nclass DecisionTreeRegressor(RegressorMixin, BaseDecisionTree):\n \"\"\"A decision tree regressor.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n criterion : {\"squared_error\", \"friedman_mse\", \"absolute_error\", \"poisson\"}, default=\"squared_error\"\n The function to measure the quality of a split. Supported criteria\n are \"squared_error\" for the mean squared error, which is equal to\n variance reduction as feature selection criterion and minimizes the L2\n loss using the mean of each terminal node, \"friedman_mse\", which uses\n mean squared error with Friedman's improvement score for potential\n splits, \"absolute_error\" for the mean absolute error, which minimizes\n the L1 loss using the median of each terminal node, and \"poisson\" which\n uses reduction in Poisson deviance to find splits.\n\n .. versionadded:: 0.18\n Mean Absolute Error (MAE) criterion.\n\n .. versionadded:: 0.24\n Poisson deviance criterion.\n\n .. deprecated:: 1.0\n Criterion \"mse\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"squared_error\"` which is equivalent.\n\n .. deprecated:: 1.0\n Criterion \"mae\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"absolute_error\"` which is equivalent.\n\n splitter : {\"best\", \"random\"}, default=\"best\"\n The strategy used to choose the split at each node. Supported\n strategies are \"best\" to choose the best split and \"random\" to choose\n the best random split.\n\n max_depth : int, default=None\n The maximum depth of the tree. If None, then nodes are expanded until\n all leaves are pure or until all leaves contain less than\n min_samples_split samples.\n\n min_samples_split : int or float, default=2\n The minimum number of samples required to split an internal node:\n\n - If int, then consider `min_samples_split` as the minimum number.\n - If float, then `min_samples_split` is a fraction and\n `ceil(min_samples_split * n_samples)` are the minimum\n number of samples for each split.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_samples_leaf : int or float, default=1\n The minimum number of samples required to be at a leaf node.\n A split point at any depth will only be considered if it leaves at\n least ``min_samples_leaf`` training samples in each of the left and\n right branches. This may have the effect of smoothing the model,\n especially in regression.\n\n - If int, then consider `min_samples_leaf` as the minimum number.\n - If float, then `min_samples_leaf` is a fraction and\n `ceil(min_samples_leaf * n_samples)` are the minimum\n number of samples for each node.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_weight_fraction_leaf : float, default=0.0\n The minimum weighted fraction of the sum total of weights (of all\n the input samples) required to be at a leaf node. Samples have\n equal weight when sample_weight is not provided.\n\n max_features : int, float or {\"auto\", \"sqrt\", \"log2\"}, default=None\n The number of features to consider when looking for the best split:\n\n - If int, then consider `max_features` features at each split.\n - If float, then `max_features` is a fraction and\n `int(max_features * n_features)` features are considered at each\n split.\n - If \"auto\", then `max_features=n_features`.\n - If \"sqrt\", then `max_features=sqrt(n_features)`.\n - If \"log2\", then `max_features=log2(n_features)`.\n - If None, then `max_features=n_features`.\n\n Note: the search for a split does not stop until at least one\n valid partition of the node samples is found, even if it requires to\n effectively inspect more than ``max_features`` features.\n\n random_state : int, RandomState instance or None, default=None\n Controls the randomness of the estimator. The features are always\n randomly permuted at each split, even if ``splitter`` is set to\n ``\"best\"``. When ``max_features < n_features``, the algorithm will\n select ``max_features`` at random at each split before finding the best\n split among them. But the best found split may vary across different\n runs, even if ``max_features=n_features``. That is the case, if the\n improvement of the criterion is identical for several splits and one\n split has to be selected at random. To obtain a deterministic behaviour\n during fitting, ``random_state`` has to be fixed to an integer.\n See :term:`Glossary ` for details.\n\n max_leaf_nodes : int, default=None\n Grow a tree with ``max_leaf_nodes`` in best-first fashion.\n Best nodes are defined as relative reduction in impurity.\n If None then unlimited number of leaf nodes.\n\n min_impurity_decrease : float, default=0.0\n A node will be split if this split induces a decrease of the impurity\n greater than or equal to this value.\n\n The weighted impurity decrease equation is the following::\n\n N_t / N * (impurity - N_t_R / N_t * right_impurity\n - N_t_L / N_t * left_impurity)\n\n where ``N`` is the total number of samples, ``N_t`` is the number of\n samples at the current node, ``N_t_L`` is the number of samples in the\n left child, and ``N_t_R`` is the number of samples in the right child.\n\n ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n if ``sample_weight`` is passed.\n\n .. versionadded:: 0.19\n\n ccp_alpha : non-negative float, default=0.0\n Complexity parameter used for Minimal Cost-Complexity Pruning. The\n subtree with the largest cost complexity that is smaller than\n ``ccp_alpha`` will be chosen. By default, no pruning is performed. See\n :ref:`minimal_cost_complexity_pruning` for details.\n\n .. versionadded:: 0.22\n\n Attributes\n ----------\n feature_importances_ : ndarray of shape (n_features,)\n The feature importances.\n The higher, the more important the feature.\n The importance of a feature is computed as the\n (normalized) total reduction of the criterion brought\n by that feature. It is also known as the Gini importance [4]_.\n\n Warning: impurity-based feature importances can be misleading for\n high cardinality features (many unique values). See\n :func:`sklearn.inspection.permutation_importance` as an alternative.\n\n max_features_ : int\n The inferred value of max_features.\n\n n_features_ : int\n The number of features when ``fit`` is performed.\n\n .. deprecated:: 1.0\n `n_features_` is deprecated in 1.0 and will be removed in\n 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n n_outputs_ : int\n The number of outputs when ``fit`` is performed.\n\n tree_ : Tree instance\n The underlying Tree object. Please refer to\n ``help(sklearn.tree._tree.Tree)`` for attributes of Tree object and\n :ref:`sphx_glr_auto_examples_tree_plot_unveil_tree_structure.py`\n for basic usage of these attributes.\n\n See Also\n --------\n DecisionTreeClassifier : A decision tree classifier.\n\n Notes\n -----\n The default values for the parameters controlling the size of the trees\n (e.g. ``max_depth``, ``min_samples_leaf``, etc.) lead to fully grown and\n unpruned trees which can potentially be very large on some data sets. To\n reduce memory consumption, the complexity and size of the trees should be\n controlled by setting those parameter values.\n\n References\n ----------\n\n .. [1] https://en.wikipedia.org/wiki/Decision_tree_learning\n\n .. [2] L. Breiman, J. Friedman, R. Olshen, and C. Stone, \"Classification\n and Regression Trees\", Wadsworth, Belmont, CA, 1984.\n\n .. [3] T. Hastie, R. Tibshirani and J. Friedman. \"Elements of Statistical\n Learning\", Springer, 2009.\n\n .. [4] L. Breiman, and A. Cutler, \"Random Forests\",\n https://www.stat.berkeley.edu/~breiman/RandomForests/cc_home.htm\n\n Examples\n --------\n >>> from sklearn.datasets import load_diabetes\n >>> from sklearn.model_selection import cross_val_score\n >>> from sklearn.tree import DecisionTreeRegressor\n >>> X, y = load_diabetes(return_X_y=True)\n >>> regressor = DecisionTreeRegressor(random_state=0)\n >>> cross_val_score(regressor, X, y, cv=10)\n ... # doctest: +SKIP\n ...\n array([-0.39..., -0.46..., 0.02..., 0.06..., -0.50...,\n 0.16..., 0.11..., -0.73..., -0.30..., -0.00...])\n \"\"\"\n \n def __init__(self, *, criterion='squared_error', splitter='best', max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features=None, random_state=None, max_leaf_nodes=None, min_impurity_decrease=0.0, ccp_alpha=0.0):\n super().__init__(criterion=criterion, splitter=splitter, max_depth=max_depth, min_samples_split=min_samples_split, min_samples_leaf=min_samples_leaf, min_weight_fraction_leaf=min_weight_fraction_leaf, max_features=max_features, max_leaf_nodes=max_leaf_nodes, random_state=random_state, min_impurity_decrease=min_impurity_decrease, ccp_alpha=ccp_alpha)\n \n def fit(self, X, y, sample_weight=None, check_input=True, X_idx_sorted='deprecated'):\n \"\"\"Build a decision tree regressor from the training set (X, y).\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Internally, it will be converted to\n ``dtype=np.float32`` and if a sparse matrix is provided\n to a sparse ``csc_matrix``.\n\n y : array-like of shape (n_samples,) or (n_samples, n_outputs)\n The target values (real numbers). Use ``dtype=np.float64`` and\n ``order='C'`` for maximum efficiency.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted. Splits\n that would create child nodes with net zero or negative weight are\n ignored while searching for a split in each node.\n\n check_input : bool, default=True\n Allow to bypass several input checking.\n Don't use this parameter unless you know what you do.\n\n X_idx_sorted : deprecated, default=\"deprecated\"\n This parameter is deprecated and has no effect.\n It will be removed in 1.1 (renaming of 0.26).\n\n .. deprecated:: 0.24\n\n Returns\n -------\n self : DecisionTreeRegressor\n Fitted estimator.\n \"\"\"\n super().fit(X, y, sample_weight=sample_weight, check_input=check_input, X_idx_sorted=X_idx_sorted)\n return self\n \n def _compute_partial_dependence_recursion(self, grid, target_features):\n \"\"\"Fast partial dependence computation.\n\n Parameters\n ----------\n grid : ndarray of shape (n_samples, n_target_features)\n The grid points on which the partial dependence should be\n evaluated.\n target_features : ndarray of shape (n_target_features)\n The set of target features for which the partial dependence\n should be evaluated.\n\n Returns\n -------\n averaged_predictions : ndarray of shape (n_samples,)\n The value of the partial dependence function on each grid point.\n \"\"\"\n grid = np.asarray(grid, dtype=DTYPE, order='C')\n averaged_predictions = np.zeros(shape=grid.shape[0], dtype=np.float64, order='C')\n self.tree_.compute_partial_dependence(grid, target_features, averaged_predictions)\n return averaged_predictions\n \n @deprecated('The attribute `n_features_` is deprecated in 1.0 and will be removed in 1.2. Use `n_features_in_` instead.')\n @property\n def n_features_(self):\n return self.n_features_in_\n" }, { "name": "ExtraTreeClassifier", @@ -26577,8 +26530,8 @@ "methods": ["sklearn.tree._classes.ExtraTreeRegressor.__init__"], "is_public": true, "description": "An extremely randomized tree regressor.\n\nExtra-trees differ from classic decision trees in the way they are built. When looking for the best split to separate the samples of a node into two groups, random splits are drawn for each of the `max_features` randomly selected features and the best split among those is chosen. When `max_features` is set 1, this amounts to building a totally random decision tree. Warning: Extra-trees should only be used within ensemble methods. Read more in the :ref:`User Guide `.", - "docstring": "An extremely randomized tree regressor.\n\n Extra-trees differ from classic decision trees in the way they are built.\n When looking for the best split to separate the samples of a node into two\n groups, random splits are drawn for each of the `max_features` randomly\n selected features and the best split among those is chosen. When\n `max_features` is set 1, this amounts to building a totally random\n decision tree.\n\n Warning: Extra-trees should only be used within ensemble methods.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n criterion : {\"squared_error\", \"mse\", \"friedman_mse\", \"mae\"}, default=\"squared_error\"\n The function to measure the quality of a split. Supported criteria\n are \"squared_error\" for the mean squared error, which is equal to\n variance reduction as feature selection criterion and \"mae\" for the\n mean absolute error.\n\n .. versionadded:: 0.18\n Mean Absolute Error (MAE) criterion.\n\n .. versionadded:: 0.24\n Poisson deviance criterion.\n\n .. deprecated:: 1.0\n Criterion \"mse\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"squared_error\"` which is equivalent.\n\n .. deprecated:: 1.0\n Criterion \"mae\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"absolute_error\"` which is equivalent.\n\n splitter : {\"random\", \"best\"}, default=\"random\"\n The strategy used to choose the split at each node. Supported\n strategies are \"best\" to choose the best split and \"random\" to choose\n the best random split.\n\n max_depth : int, default=None\n The maximum depth of the tree. If None, then nodes are expanded until\n all leaves are pure or until all leaves contain less than\n min_samples_split samples.\n\n min_samples_split : int or float, default=2\n The minimum number of samples required to split an internal node:\n\n - If int, then consider `min_samples_split` as the minimum number.\n - If float, then `min_samples_split` is a fraction and\n `ceil(min_samples_split * n_samples)` are the minimum\n number of samples for each split.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_samples_leaf : int or float, default=1\n The minimum number of samples required to be at a leaf node.\n A split point at any depth will only be considered if it leaves at\n least ``min_samples_leaf`` training samples in each of the left and\n right branches. This may have the effect of smoothing the model,\n especially in regression.\n\n - If int, then consider `min_samples_leaf` as the minimum number.\n - If float, then `min_samples_leaf` is a fraction and\n `ceil(min_samples_leaf * n_samples)` are the minimum\n number of samples for each node.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_weight_fraction_leaf : float, default=0.0\n The minimum weighted fraction of the sum total of weights (of all\n the input samples) required to be at a leaf node. Samples have\n equal weight when sample_weight is not provided.\n\n max_features : int, float, {\"auto\", \"sqrt\", \"log2\"} or None, default=\"auto\"\n The number of features to consider when looking for the best split:\n\n - If int, then consider `max_features` features at each split.\n - If float, then `max_features` is a fraction and\n `int(max_features * n_features)` features are considered at each\n split.\n - If \"auto\", then `max_features=n_features`.\n - If \"sqrt\", then `max_features=sqrt(n_features)`.\n - If \"log2\", then `max_features=log2(n_features)`.\n - If None, then `max_features=n_features`.\n\n Note: the search for a split does not stop until at least one\n valid partition of the node samples is found, even if it requires to\n effectively inspect more than ``max_features`` features.\n\n random_state : int, RandomState instance or None, default=None\n Used to pick randomly the `max_features` used at each split.\n See :term:`Glossary ` for details.\n\n min_impurity_decrease : float, default=0.0\n A node will be split if this split induces a decrease of the impurity\n greater than or equal to this value.\n\n The weighted impurity decrease equation is the following::\n\n N_t / N * (impurity - N_t_R / N_t * right_impurity\n - N_t_L / N_t * left_impurity)\n\n where ``N`` is the total number of samples, ``N_t`` is the number of\n samples at the current node, ``N_t_L`` is the number of samples in the\n left child, and ``N_t_R`` is the number of samples in the right child.\n\n ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n if ``sample_weight`` is passed.\n\n .. versionadded:: 0.19\n\n max_leaf_nodes : int, default=None\n Grow a tree with ``max_leaf_nodes`` in best-first fashion.\n Best nodes are defined as relative reduction in impurity.\n If None then unlimited number of leaf nodes.\n\n ccp_alpha : non-negative float, default=0.0\n Complexity parameter used for Minimal Cost-Complexity Pruning. The\n subtree with the largest cost complexity that is smaller than\n ``ccp_alpha`` will be chosen. By default, no pruning is performed. See\n :ref:`minimal_cost_complexity_pruning` for details.\n\n .. versionadded:: 0.22\n\n Attributes\n ----------\n max_features_ : int\n The inferred value of max_features.\n\n n_features_ : int\n The number of features when ``fit`` is performed.\n\n .. deprecated:: 1.0\n `n_features_` is deprecated in 1.0 and will be removed in\n 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n feature_importances_ : ndarray of shape (n_features,)\n Return impurity-based feature importances (the higher, the more\n important the feature).\n\n Warning: impurity-based feature importances can be misleading for\n high cardinality features (many unique values). See\n :func:`sklearn.inspection.permutation_importance` as an alternative.\n\n n_outputs_ : int\n The number of outputs when ``fit`` is performed.\n\n tree_ : Tree instance\n The underlying Tree object. Please refer to\n ``help(sklearn.tree._tree.Tree)`` for attributes of Tree object and\n :ref:`sphx_glr_auto_examples_tree_plot_unveil_tree_structure.py`\n for basic usage of these attributes.\n\n See Also\n --------\n ExtraTreeClassifier : An extremely randomized tree classifier.\n sklearn.ensemble.ExtraTreesClassifier : An extra-trees classifier.\n sklearn.ensemble.ExtraTreesRegressor : An extra-trees regressor.\n\n Notes\n -----\n The default values for the parameters controlling the size of the trees\n (e.g. ``max_depth``, ``min_samples_leaf``, etc.) lead to fully grown and\n unpruned trees which can potentially be very large on some data sets. To\n reduce memory consumption, the complexity and size of the trees should be\n controlled by setting those parameter values.\n\n References\n ----------\n\n .. [1] P. Geurts, D. Ernst., and L. Wehenkel, \"Extremely randomized trees\",\n Machine Learning, 63(1), 3-42, 2006.\n\n Examples\n --------\n >>> from sklearn.datasets import load_diabetes\n >>> from sklearn.model_selection import train_test_split\n >>> from sklearn.ensemble import BaggingRegressor\n >>> from sklearn.tree import ExtraTreeRegressor\n >>> X, y = load_diabetes(return_X_y=True)\n >>> X_train, X_test, y_train, y_test = train_test_split(\n ... X, y, random_state=0)\n >>> extra_tree = ExtraTreeRegressor(random_state=0)\n >>> reg = BaggingRegressor(extra_tree, random_state=0).fit(\n ... X_train, y_train)\n >>> reg.score(X_test, y_test)\n 0.33...\n ", - "source_code": "\n\nclass ExtraTreeRegressor(DecisionTreeRegressor):\n \"\"\"An extremely randomized tree regressor.\n\n Extra-trees differ from classic decision trees in the way they are built.\n When looking for the best split to separate the samples of a node into two\n groups, random splits are drawn for each of the `max_features` randomly\n selected features and the best split among those is chosen. When\n `max_features` is set 1, this amounts to building a totally random\n decision tree.\n\n Warning: Extra-trees should only be used within ensemble methods.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n criterion : {\"squared_error\", \"mse\", \"friedman_mse\", \"mae\"}, default=\"squared_error\"\n The function to measure the quality of a split. Supported criteria\n are \"squared_error\" for the mean squared error, which is equal to\n variance reduction as feature selection criterion and \"mae\" for the\n mean absolute error.\n\n .. versionadded:: 0.18\n Mean Absolute Error (MAE) criterion.\n\n .. versionadded:: 0.24\n Poisson deviance criterion.\n\n .. deprecated:: 1.0\n Criterion \"mse\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"squared_error\"` which is equivalent.\n\n .. deprecated:: 1.0\n Criterion \"mae\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"absolute_error\"` which is equivalent.\n\n splitter : {\"random\", \"best\"}, default=\"random\"\n The strategy used to choose the split at each node. Supported\n strategies are \"best\" to choose the best split and \"random\" to choose\n the best random split.\n\n max_depth : int, default=None\n The maximum depth of the tree. If None, then nodes are expanded until\n all leaves are pure or until all leaves contain less than\n min_samples_split samples.\n\n min_samples_split : int or float, default=2\n The minimum number of samples required to split an internal node:\n\n - If int, then consider `min_samples_split` as the minimum number.\n - If float, then `min_samples_split` is a fraction and\n `ceil(min_samples_split * n_samples)` are the minimum\n number of samples for each split.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_samples_leaf : int or float, default=1\n The minimum number of samples required to be at a leaf node.\n A split point at any depth will only be considered if it leaves at\n least ``min_samples_leaf`` training samples in each of the left and\n right branches. This may have the effect of smoothing the model,\n especially in regression.\n\n - If int, then consider `min_samples_leaf` as the minimum number.\n - If float, then `min_samples_leaf` is a fraction and\n `ceil(min_samples_leaf * n_samples)` are the minimum\n number of samples for each node.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_weight_fraction_leaf : float, default=0.0\n The minimum weighted fraction of the sum total of weights (of all\n the input samples) required to be at a leaf node. Samples have\n equal weight when sample_weight is not provided.\n\n max_features : int, float, {\"auto\", \"sqrt\", \"log2\"} or None, default=\"auto\"\n The number of features to consider when looking for the best split:\n\n - If int, then consider `max_features` features at each split.\n - If float, then `max_features` is a fraction and\n `int(max_features * n_features)` features are considered at each\n split.\n - If \"auto\", then `max_features=n_features`.\n - If \"sqrt\", then `max_features=sqrt(n_features)`.\n - If \"log2\", then `max_features=log2(n_features)`.\n - If None, then `max_features=n_features`.\n\n Note: the search for a split does not stop until at least one\n valid partition of the node samples is found, even if it requires to\n effectively inspect more than ``max_features`` features.\n\n random_state : int, RandomState instance or None, default=None\n Used to pick randomly the `max_features` used at each split.\n See :term:`Glossary ` for details.\n\n min_impurity_decrease : float, default=0.0\n A node will be split if this split induces a decrease of the impurity\n greater than or equal to this value.\n\n The weighted impurity decrease equation is the following::\n\n N_t / N * (impurity - N_t_R / N_t * right_impurity\n - N_t_L / N_t * left_impurity)\n\n where ``N`` is the total number of samples, ``N_t`` is the number of\n samples at the current node, ``N_t_L`` is the number of samples in the\n left child, and ``N_t_R`` is the number of samples in the right child.\n\n ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n if ``sample_weight`` is passed.\n\n .. versionadded:: 0.19\n\n max_leaf_nodes : int, default=None\n Grow a tree with ``max_leaf_nodes`` in best-first fashion.\n Best nodes are defined as relative reduction in impurity.\n If None then unlimited number of leaf nodes.\n\n ccp_alpha : non-negative float, default=0.0\n Complexity parameter used for Minimal Cost-Complexity Pruning. The\n subtree with the largest cost complexity that is smaller than\n ``ccp_alpha`` will be chosen. By default, no pruning is performed. See\n :ref:`minimal_cost_complexity_pruning` for details.\n\n .. versionadded:: 0.22\n\n Attributes\n ----------\n max_features_ : int\n The inferred value of max_features.\n\n n_features_ : int\n The number of features when ``fit`` is performed.\n\n .. deprecated:: 1.0\n `n_features_` is deprecated in 1.0 and will be removed in\n 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n feature_importances_ : ndarray of shape (n_features,)\n Return impurity-based feature importances (the higher, the more\n important the feature).\n\n Warning: impurity-based feature importances can be misleading for\n high cardinality features (many unique values). See\n :func:`sklearn.inspection.permutation_importance` as an alternative.\n\n n_outputs_ : int\n The number of outputs when ``fit`` is performed.\n\n tree_ : Tree instance\n The underlying Tree object. Please refer to\n ``help(sklearn.tree._tree.Tree)`` for attributes of Tree object and\n :ref:`sphx_glr_auto_examples_tree_plot_unveil_tree_structure.py`\n for basic usage of these attributes.\n\n See Also\n --------\n ExtraTreeClassifier : An extremely randomized tree classifier.\n sklearn.ensemble.ExtraTreesClassifier : An extra-trees classifier.\n sklearn.ensemble.ExtraTreesRegressor : An extra-trees regressor.\n\n Notes\n -----\n The default values for the parameters controlling the size of the trees\n (e.g. ``max_depth``, ``min_samples_leaf``, etc.) lead to fully grown and\n unpruned trees which can potentially be very large on some data sets. To\n reduce memory consumption, the complexity and size of the trees should be\n controlled by setting those parameter values.\n\n References\n ----------\n\n .. [1] P. Geurts, D. Ernst., and L. Wehenkel, \"Extremely randomized trees\",\n Machine Learning, 63(1), 3-42, 2006.\n\n Examples\n --------\n >>> from sklearn.datasets import load_diabetes\n >>> from sklearn.model_selection import train_test_split\n >>> from sklearn.ensemble import BaggingRegressor\n >>> from sklearn.tree import ExtraTreeRegressor\n >>> X, y = load_diabetes(return_X_y=True)\n >>> X_train, X_test, y_train, y_test = train_test_split(\n ... X, y, random_state=0)\n >>> extra_tree = ExtraTreeRegressor(random_state=0)\n >>> reg = BaggingRegressor(extra_tree, random_state=0).fit(\n ... X_train, y_train)\n >>> reg.score(X_test, y_test)\n 0.33...\n \"\"\"\n \n def __init__(self, *, criterion='squared_error', splitter='random', max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features='auto', random_state=None, min_impurity_decrease=0.0, max_leaf_nodes=None, ccp_alpha=0.0):\n super().__init__(criterion=criterion, splitter=splitter, max_depth=max_depth, min_samples_split=min_samples_split, min_samples_leaf=min_samples_leaf, min_weight_fraction_leaf=min_weight_fraction_leaf, max_features=max_features, max_leaf_nodes=max_leaf_nodes, min_impurity_decrease=min_impurity_decrease, random_state=random_state, ccp_alpha=ccp_alpha)\n" + "docstring": "An extremely randomized tree regressor.\n\n Extra-trees differ from classic decision trees in the way they are built.\n When looking for the best split to separate the samples of a node into two\n groups, random splits are drawn for each of the `max_features` randomly\n selected features and the best split among those is chosen. When\n `max_features` is set 1, this amounts to building a totally random\n decision tree.\n\n Warning: Extra-trees should only be used within ensemble methods.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n criterion : {\"squared_error\", \"friedman_mse\"}, default=\"squared_error\"\n The function to measure the quality of a split. Supported criteria\n are \"squared_error\" for the mean squared error, which is equal to\n variance reduction as feature selection criterion and \"mae\" for the\n mean absolute error.\n\n .. versionadded:: 0.18\n Mean Absolute Error (MAE) criterion.\n\n .. versionadded:: 0.24\n Poisson deviance criterion.\n\n .. deprecated:: 1.0\n Criterion \"mse\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"squared_error\"` which is equivalent.\n\n .. deprecated:: 1.0\n Criterion \"mae\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"absolute_error\"` which is equivalent.\n\n splitter : {\"random\", \"best\"}, default=\"random\"\n The strategy used to choose the split at each node. Supported\n strategies are \"best\" to choose the best split and \"random\" to choose\n the best random split.\n\n max_depth : int, default=None\n The maximum depth of the tree. If None, then nodes are expanded until\n all leaves are pure or until all leaves contain less than\n min_samples_split samples.\n\n min_samples_split : int or float, default=2\n The minimum number of samples required to split an internal node:\n\n - If int, then consider `min_samples_split` as the minimum number.\n - If float, then `min_samples_split` is a fraction and\n `ceil(min_samples_split * n_samples)` are the minimum\n number of samples for each split.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_samples_leaf : int or float, default=1\n The minimum number of samples required to be at a leaf node.\n A split point at any depth will only be considered if it leaves at\n least ``min_samples_leaf`` training samples in each of the left and\n right branches. This may have the effect of smoothing the model,\n especially in regression.\n\n - If int, then consider `min_samples_leaf` as the minimum number.\n - If float, then `min_samples_leaf` is a fraction and\n `ceil(min_samples_leaf * n_samples)` are the minimum\n number of samples for each node.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_weight_fraction_leaf : float, default=0.0\n The minimum weighted fraction of the sum total of weights (of all\n the input samples) required to be at a leaf node. Samples have\n equal weight when sample_weight is not provided.\n\n max_features : int, float, {\"auto\", \"sqrt\", \"log2\"} or None, default=\"auto\"\n The number of features to consider when looking for the best split:\n\n - If int, then consider `max_features` features at each split.\n - If float, then `max_features` is a fraction and\n `int(max_features * n_features)` features are considered at each\n split.\n - If \"auto\", then `max_features=n_features`.\n - If \"sqrt\", then `max_features=sqrt(n_features)`.\n - If \"log2\", then `max_features=log2(n_features)`.\n - If None, then `max_features=n_features`.\n\n Note: the search for a split does not stop until at least one\n valid partition of the node samples is found, even if it requires to\n effectively inspect more than ``max_features`` features.\n\n random_state : int, RandomState instance or None, default=None\n Used to pick randomly the `max_features` used at each split.\n See :term:`Glossary ` for details.\n\n min_impurity_decrease : float, default=0.0\n A node will be split if this split induces a decrease of the impurity\n greater than or equal to this value.\n\n The weighted impurity decrease equation is the following::\n\n N_t / N * (impurity - N_t_R / N_t * right_impurity\n - N_t_L / N_t * left_impurity)\n\n where ``N`` is the total number of samples, ``N_t`` is the number of\n samples at the current node, ``N_t_L`` is the number of samples in the\n left child, and ``N_t_R`` is the number of samples in the right child.\n\n ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n if ``sample_weight`` is passed.\n\n .. versionadded:: 0.19\n\n max_leaf_nodes : int, default=None\n Grow a tree with ``max_leaf_nodes`` in best-first fashion.\n Best nodes are defined as relative reduction in impurity.\n If None then unlimited number of leaf nodes.\n\n ccp_alpha : non-negative float, default=0.0\n Complexity parameter used for Minimal Cost-Complexity Pruning. The\n subtree with the largest cost complexity that is smaller than\n ``ccp_alpha`` will be chosen. By default, no pruning is performed. See\n :ref:`minimal_cost_complexity_pruning` for details.\n\n .. versionadded:: 0.22\n\n Attributes\n ----------\n max_features_ : int\n The inferred value of max_features.\n\n n_features_ : int\n The number of features when ``fit`` is performed.\n\n .. deprecated:: 1.0\n `n_features_` is deprecated in 1.0 and will be removed in\n 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n feature_importances_ : ndarray of shape (n_features,)\n Return impurity-based feature importances (the higher, the more\n important the feature).\n\n Warning: impurity-based feature importances can be misleading for\n high cardinality features (many unique values). See\n :func:`sklearn.inspection.permutation_importance` as an alternative.\n\n n_outputs_ : int\n The number of outputs when ``fit`` is performed.\n\n tree_ : Tree instance\n The underlying Tree object. Please refer to\n ``help(sklearn.tree._tree.Tree)`` for attributes of Tree object and\n :ref:`sphx_glr_auto_examples_tree_plot_unveil_tree_structure.py`\n for basic usage of these attributes.\n\n See Also\n --------\n ExtraTreeClassifier : An extremely randomized tree classifier.\n sklearn.ensemble.ExtraTreesClassifier : An extra-trees classifier.\n sklearn.ensemble.ExtraTreesRegressor : An extra-trees regressor.\n\n Notes\n -----\n The default values for the parameters controlling the size of the trees\n (e.g. ``max_depth``, ``min_samples_leaf``, etc.) lead to fully grown and\n unpruned trees which can potentially be very large on some data sets. To\n reduce memory consumption, the complexity and size of the trees should be\n controlled by setting those parameter values.\n\n References\n ----------\n\n .. [1] P. Geurts, D. Ernst., and L. Wehenkel, \"Extremely randomized trees\",\n Machine Learning, 63(1), 3-42, 2006.\n\n Examples\n --------\n >>> from sklearn.datasets import load_diabetes\n >>> from sklearn.model_selection import train_test_split\n >>> from sklearn.ensemble import BaggingRegressor\n >>> from sklearn.tree import ExtraTreeRegressor\n >>> X, y = load_diabetes(return_X_y=True)\n >>> X_train, X_test, y_train, y_test = train_test_split(\n ... X, y, random_state=0)\n >>> extra_tree = ExtraTreeRegressor(random_state=0)\n >>> reg = BaggingRegressor(extra_tree, random_state=0).fit(\n ... X_train, y_train)\n >>> reg.score(X_test, y_test)\n 0.33...\n ", + "source_code": "\n\nclass ExtraTreeRegressor(DecisionTreeRegressor):\n \"\"\"An extremely randomized tree regressor.\n\n Extra-trees differ from classic decision trees in the way they are built.\n When looking for the best split to separate the samples of a node into two\n groups, random splits are drawn for each of the `max_features` randomly\n selected features and the best split among those is chosen. When\n `max_features` is set 1, this amounts to building a totally random\n decision tree.\n\n Warning: Extra-trees should only be used within ensemble methods.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n criterion : {\"squared_error\", \"friedman_mse\"}, default=\"squared_error\"\n The function to measure the quality of a split. Supported criteria\n are \"squared_error\" for the mean squared error, which is equal to\n variance reduction as feature selection criterion and \"mae\" for the\n mean absolute error.\n\n .. versionadded:: 0.18\n Mean Absolute Error (MAE) criterion.\n\n .. versionadded:: 0.24\n Poisson deviance criterion.\n\n .. deprecated:: 1.0\n Criterion \"mse\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"squared_error\"` which is equivalent.\n\n .. deprecated:: 1.0\n Criterion \"mae\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"absolute_error\"` which is equivalent.\n\n splitter : {\"random\", \"best\"}, default=\"random\"\n The strategy used to choose the split at each node. Supported\n strategies are \"best\" to choose the best split and \"random\" to choose\n the best random split.\n\n max_depth : int, default=None\n The maximum depth of the tree. If None, then nodes are expanded until\n all leaves are pure or until all leaves contain less than\n min_samples_split samples.\n\n min_samples_split : int or float, default=2\n The minimum number of samples required to split an internal node:\n\n - If int, then consider `min_samples_split` as the minimum number.\n - If float, then `min_samples_split` is a fraction and\n `ceil(min_samples_split * n_samples)` are the minimum\n number of samples for each split.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_samples_leaf : int or float, default=1\n The minimum number of samples required to be at a leaf node.\n A split point at any depth will only be considered if it leaves at\n least ``min_samples_leaf`` training samples in each of the left and\n right branches. This may have the effect of smoothing the model,\n especially in regression.\n\n - If int, then consider `min_samples_leaf` as the minimum number.\n - If float, then `min_samples_leaf` is a fraction and\n `ceil(min_samples_leaf * n_samples)` are the minimum\n number of samples for each node.\n\n .. versionchanged:: 0.18\n Added float values for fractions.\n\n min_weight_fraction_leaf : float, default=0.0\n The minimum weighted fraction of the sum total of weights (of all\n the input samples) required to be at a leaf node. Samples have\n equal weight when sample_weight is not provided.\n\n max_features : int, float, {\"auto\", \"sqrt\", \"log2\"} or None, default=\"auto\"\n The number of features to consider when looking for the best split:\n\n - If int, then consider `max_features` features at each split.\n - If float, then `max_features` is a fraction and\n `int(max_features * n_features)` features are considered at each\n split.\n - If \"auto\", then `max_features=n_features`.\n - If \"sqrt\", then `max_features=sqrt(n_features)`.\n - If \"log2\", then `max_features=log2(n_features)`.\n - If None, then `max_features=n_features`.\n\n Note: the search for a split does not stop until at least one\n valid partition of the node samples is found, even if it requires to\n effectively inspect more than ``max_features`` features.\n\n random_state : int, RandomState instance or None, default=None\n Used to pick randomly the `max_features` used at each split.\n See :term:`Glossary ` for details.\n\n min_impurity_decrease : float, default=0.0\n A node will be split if this split induces a decrease of the impurity\n greater than or equal to this value.\n\n The weighted impurity decrease equation is the following::\n\n N_t / N * (impurity - N_t_R / N_t * right_impurity\n - N_t_L / N_t * left_impurity)\n\n where ``N`` is the total number of samples, ``N_t`` is the number of\n samples at the current node, ``N_t_L`` is the number of samples in the\n left child, and ``N_t_R`` is the number of samples in the right child.\n\n ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n if ``sample_weight`` is passed.\n\n .. versionadded:: 0.19\n\n max_leaf_nodes : int, default=None\n Grow a tree with ``max_leaf_nodes`` in best-first fashion.\n Best nodes are defined as relative reduction in impurity.\n If None then unlimited number of leaf nodes.\n\n ccp_alpha : non-negative float, default=0.0\n Complexity parameter used for Minimal Cost-Complexity Pruning. The\n subtree with the largest cost complexity that is smaller than\n ``ccp_alpha`` will be chosen. By default, no pruning is performed. See\n :ref:`minimal_cost_complexity_pruning` for details.\n\n .. versionadded:: 0.22\n\n Attributes\n ----------\n max_features_ : int\n The inferred value of max_features.\n\n n_features_ : int\n The number of features when ``fit`` is performed.\n\n .. deprecated:: 1.0\n `n_features_` is deprecated in 1.0 and will be removed in\n 1.2. Use `n_features_in_` instead.\n\n n_features_in_ : int\n Number of features seen during :term:`fit`.\n\n .. versionadded:: 0.24\n\n feature_names_in_ : ndarray of shape (`n_features_in_`,)\n Names of features seen during :term:`fit`. Defined only when `X`\n has feature names that are all strings.\n\n .. versionadded:: 1.0\n\n feature_importances_ : ndarray of shape (n_features,)\n Return impurity-based feature importances (the higher, the more\n important the feature).\n\n Warning: impurity-based feature importances can be misleading for\n high cardinality features (many unique values). See\n :func:`sklearn.inspection.permutation_importance` as an alternative.\n\n n_outputs_ : int\n The number of outputs when ``fit`` is performed.\n\n tree_ : Tree instance\n The underlying Tree object. Please refer to\n ``help(sklearn.tree._tree.Tree)`` for attributes of Tree object and\n :ref:`sphx_glr_auto_examples_tree_plot_unveil_tree_structure.py`\n for basic usage of these attributes.\n\n See Also\n --------\n ExtraTreeClassifier : An extremely randomized tree classifier.\n sklearn.ensemble.ExtraTreesClassifier : An extra-trees classifier.\n sklearn.ensemble.ExtraTreesRegressor : An extra-trees regressor.\n\n Notes\n -----\n The default values for the parameters controlling the size of the trees\n (e.g. ``max_depth``, ``min_samples_leaf``, etc.) lead to fully grown and\n unpruned trees which can potentially be very large on some data sets. To\n reduce memory consumption, the complexity and size of the trees should be\n controlled by setting those parameter values.\n\n References\n ----------\n\n .. [1] P. Geurts, D. Ernst., and L. Wehenkel, \"Extremely randomized trees\",\n Machine Learning, 63(1), 3-42, 2006.\n\n Examples\n --------\n >>> from sklearn.datasets import load_diabetes\n >>> from sklearn.model_selection import train_test_split\n >>> from sklearn.ensemble import BaggingRegressor\n >>> from sklearn.tree import ExtraTreeRegressor\n >>> X, y = load_diabetes(return_X_y=True)\n >>> X_train, X_test, y_train, y_test = train_test_split(\n ... X, y, random_state=0)\n >>> extra_tree = ExtraTreeRegressor(random_state=0)\n >>> reg = BaggingRegressor(extra_tree, random_state=0).fit(\n ... X_train, y_train)\n >>> reg.score(X_test, y_test)\n 0.33...\n \"\"\"\n \n def __init__(self, *, criterion='squared_error', splitter='random', max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features='auto', random_state=None, min_impurity_decrease=0.0, max_leaf_nodes=None, ccp_alpha=0.0):\n super().__init__(criterion=criterion, splitter=splitter, max_depth=max_depth, min_samples_split=min_samples_split, min_samples_leaf=min_samples_leaf, min_weight_fraction_leaf=min_weight_fraction_leaf, max_features=max_features, max_leaf_nodes=max_leaf_nodes, min_impurity_decrease=min_impurity_decrease, random_state=random_state, ccp_alpha=ccp_alpha)\n" }, { "name": "Sentinel", @@ -26685,8 +26638,8 @@ ], "is_public": true, "description": "Container object exposing keys as attributes.\n\nBunch objects are sometimes used as an output for functions and methods. They extend dictionaries by enabling values to be accessed by key, `bunch[\"value_key\"]`, or by an attribute, `bunch.value_key`.", - "docstring": "Container object exposing keys as attributes.\n\n Bunch objects are sometimes used as an output for functions and methods.\n They extend dictionaries by enabling values to be accessed by key,\n `bunch[\"value_key\"]`, or by an attribute, `bunch.value_key`.\n\n Examples\n --------\n >>> b = Bunch(a=1, b=2)\n >>> b['b']\n 2\n >>> b.b\n 2\n >>> b.a = 3\n >>> b['a']\n 3\n >>> b.c = 6\n >>> b['c']\n 6\n ", - "source_code": "\n\nclass Bunch(dict):\n \"\"\"Container object exposing keys as attributes.\n\n Bunch objects are sometimes used as an output for functions and methods.\n They extend dictionaries by enabling values to be accessed by key,\n `bunch[\"value_key\"]`, or by an attribute, `bunch.value_key`.\n\n Examples\n --------\n >>> b = Bunch(a=1, b=2)\n >>> b['b']\n 2\n >>> b.b\n 2\n >>> b.a = 3\n >>> b['a']\n 3\n >>> b.c = 6\n >>> b['c']\n 6\n \"\"\"\n \n def __init__(self, **kwargs):\n super().__init__(kwargs)\n \n def __setattr__(self, key, value):\n self[key] = value\n \n def __dir__(self):\n return self.keys()\n \n def __getattr__(self, key):\n try:\n return self[key]\n except KeyError:\n raise AttributeError(key)\n \n def __setstate__(self, state):\n pass\n" + "docstring": "Container object exposing keys as attributes.\n\n Bunch objects are sometimes used as an output for functions and methods.\n They extend dictionaries by enabling values to be accessed by key,\n `bunch[\"value_key\"]`, or by an attribute, `bunch.value_key`.\n\n Examples\n --------\n >>> from sklearn.utils import Bunch\n >>> b = Bunch(a=1, b=2)\n >>> b['b']\n 2\n >>> b.b\n 2\n >>> b.a = 3\n >>> b['a']\n 3\n >>> b.c = 6\n >>> b['c']\n 6\n ", + "source_code": "\n\nclass Bunch(dict):\n \"\"\"Container object exposing keys as attributes.\n\n Bunch objects are sometimes used as an output for functions and methods.\n They extend dictionaries by enabling values to be accessed by key,\n `bunch[\"value_key\"]`, or by an attribute, `bunch.value_key`.\n\n Examples\n --------\n >>> from sklearn.utils import Bunch\n >>> b = Bunch(a=1, b=2)\n >>> b['b']\n 2\n >>> b.b\n 2\n >>> b.a = 3\n >>> b['a']\n 3\n >>> b.c = 6\n >>> b['c']\n 6\n \"\"\"\n \n def __init__(self, **kwargs):\n super().__init__(kwargs)\n \n def __setattr__(self, key, value):\n self[key] = value\n \n def __dir__(self):\n return self.keys()\n \n def __getattr__(self, key):\n try:\n return self[key]\n except KeyError:\n raise AttributeError(key)\n \n def __setstate__(self, state):\n pass\n" }, { "name": "MissingValues", @@ -27040,7 +26993,7 @@ "is_public": false, "description": "Implements a conditional property using the descriptor protocol.\n\nUsing this class to create a decorator will raise an ``AttributeError`` if none of the delegates (specified in ``delegate_names``) is an attribute of the base object or the first found delegate does not have an attribute ``attribute_name``. This allows ducktyping of the decorated method based on ``delegate.attribute_name``. Here ``delegate`` is the first item in ``delegate_names`` for which ``hasattr(object, delegate) is True``. See https://docs.python.org/3/howto/descriptor.html for an explanation of descriptors.", "docstring": "Implements a conditional property using the descriptor protocol.\n\n Using this class to create a decorator will raise an ``AttributeError``\n if none of the delegates (specified in ``delegate_names``) is an attribute\n of the base object or the first found delegate does not have an attribute\n ``attribute_name``.\n\n This allows ducktyping of the decorated method based on\n ``delegate.attribute_name``. Here ``delegate`` is the first item in\n ``delegate_names`` for which ``hasattr(object, delegate) is True``.\n\n See https://docs.python.org/3/howto/descriptor.html for an explanation of\n descriptors.\n ", - "source_code": "\n\nclass _IffHasAttrDescriptor(_AvailableIfDescriptor):\n \"\"\"Implements a conditional property using the descriptor protocol.\n\n Using this class to create a decorator will raise an ``AttributeError``\n if none of the delegates (specified in ``delegate_names``) is an attribute\n of the base object or the first found delegate does not have an attribute\n ``attribute_name``.\n\n This allows ducktyping of the decorated method based on\n ``delegate.attribute_name``. Here ``delegate`` is the first item in\n ``delegate_names`` for which ``hasattr(object, delegate) is True``.\n\n See https://docs.python.org/3/howto/descriptor.html for an explanation of\n descriptors.\n \"\"\"\n \n def __init__(self, fn, delegate_names, attribute_name):\n super().__init__(fn, self._check, attribute_name)\n self.delegate_names = delegate_names\n \n def _check(self, obj):\n delegate = None\n for delegate_name in self.delegate_names:\n try:\n delegate = attrgetter(delegate_name)(obj)\n break\n except AttributeError:\n continue\n if delegate is None:\n return False\n return getattr(delegate, self.attribute_name) or True\n" + "source_code": "\n\nclass _IffHasAttrDescriptor(_AvailableIfDescriptor):\n \"\"\"Implements a conditional property using the descriptor protocol.\n\n Using this class to create a decorator will raise an ``AttributeError``\n if none of the delegates (specified in ``delegate_names``) is an attribute\n of the base object or the first found delegate does not have an attribute\n ``attribute_name``.\n\n This allows ducktyping of the decorated method based on\n ``delegate.attribute_name``. Here ``delegate`` is the first item in\n ``delegate_names`` for which ``hasattr(object, delegate) is True``.\n\n See https://docs.python.org/3/howto/descriptor.html for an explanation of\n descriptors.\n \"\"\"\n \n def __init__(self, fn, delegate_names, attribute_name):\n super().__init__(fn, self._check, attribute_name)\n self.delegate_names = delegate_names\n \n def _check(self, obj):\n delegate = None\n for delegate_name in self.delegate_names:\n try:\n delegate = attrgetter(delegate_name)(obj)\n break\n except AttributeError:\n continue\n if delegate is None:\n return False\n getattr(delegate, self.attribute_name)\n return True\n" }, { "name": "_LineSearchError", @@ -27057,7 +27010,9 @@ "functions": [ { "name": "raise_build_error", + "unique_name": "raise_build_error", "qname": "sklearn.__check_build.raise_build_error", + "unique_qname": "sklearn.__check_build.raise_build_error", "decorators": [], "parameters": [ { @@ -27079,7 +27034,9 @@ }, { "name": "configuration", + "unique_name": "configuration", "qname": "sklearn.__check_build.setup.configuration", + "unique_qname": "sklearn.__check_build.setup.configuration", "decorators": [], "parameters": [ { @@ -27111,7 +27068,9 @@ }, { "name": "_check_cython_version", + "unique_name": "_check_cython_version", "qname": "sklearn._build_utils._check_cython_version", + "unique_qname": "sklearn._build_utils._check_cython_version", "decorators": [], "parameters": [], "results": [], @@ -27122,7 +27081,9 @@ }, { "name": "cythonize_extensions", + "unique_name": "cythonize_extensions", "qname": "sklearn._build_utils.cythonize_extensions", + "unique_qname": "sklearn._build_utils.cythonize_extensions", "decorators": [], "parameters": [ { @@ -27154,7 +27115,9 @@ }, { "name": "gen_from_templates", + "unique_name": "gen_from_templates", "qname": "sklearn._build_utils.gen_from_templates", + "unique_qname": "sklearn._build_utils.gen_from_templates", "decorators": [], "parameters": [ { @@ -27176,7 +27139,9 @@ }, { "name": "check_openmp_support", + "unique_name": "check_openmp_support", "qname": "sklearn._build_utils.openmp_helpers.check_openmp_support", + "unique_qname": "sklearn._build_utils.openmp_helpers.check_openmp_support", "decorators": [], "parameters": [], "results": [], @@ -27187,7 +27152,9 @@ }, { "name": "get_openmp_flag", + "unique_name": "get_openmp_flag", "qname": "sklearn._build_utils.openmp_helpers.get_openmp_flag", + "unique_qname": "sklearn._build_utils.openmp_helpers.get_openmp_flag", "decorators": [], "parameters": [ { @@ -27209,7 +27176,9 @@ }, { "name": "_get_compiler", + "unique_name": "_get_compiler", "qname": "sklearn._build_utils.pre_build_helpers._get_compiler", + "unique_qname": "sklearn._build_utils.pre_build_helpers._get_compiler", "decorators": [], "parameters": [], "results": [], @@ -27220,7 +27189,9 @@ }, { "name": "basic_check_build", + "unique_name": "basic_check_build", "qname": "sklearn._build_utils.pre_build_helpers.basic_check_build", + "unique_qname": "sklearn._build_utils.pre_build_helpers.basic_check_build", "decorators": [], "parameters": [], "results": [], @@ -27231,7 +27202,9 @@ }, { "name": "compile_test_program", + "unique_name": "compile_test_program", "qname": "sklearn._build_utils.pre_build_helpers.compile_test_program", + "unique_qname": "sklearn._build_utils.pre_build_helpers.compile_test_program", "decorators": [], "parameters": [ { @@ -27273,7 +27246,9 @@ }, { "name": "_get_threadlocal_config", + "unique_name": "_get_threadlocal_config", "qname": "sklearn._config._get_threadlocal_config", + "unique_qname": "sklearn._config._get_threadlocal_config", "decorators": [], "parameters": [], "results": [], @@ -27284,7 +27259,9 @@ }, { "name": "config_context", + "unique_name": "config_context", "qname": "sklearn._config.config_context", + "unique_qname": "sklearn._config.config_context", "decorators": ["contextmanager"], "parameters": [], "results": [], @@ -27295,7 +27272,9 @@ }, { "name": "get_config", + "unique_name": "get_config", "qname": "sklearn._config.get_config", + "unique_qname": "sklearn._config.get_config", "decorators": [], "parameters": [], "results": [], @@ -27306,7 +27285,9 @@ }, { "name": "set_config", + "unique_name": "set_config", "qname": "sklearn._config.set_config", + "unique_qname": "sklearn._config.set_config", "decorators": [], "parameters": [ { @@ -27358,7 +27339,9 @@ }, { "name": "deviance", + "unique_name": "deviance", "qname": "sklearn._loss.glm_distribution.ExponentialDispersionModel.deviance", + "unique_qname": "sklearn._loss.glm_distribution.ExponentialDispersionModel.deviance", "decorators": [], "parameters": [ { @@ -27410,7 +27393,9 @@ }, { "name": "deviance_derivative", + "unique_name": "deviance_derivative", "qname": "sklearn._loss.glm_distribution.ExponentialDispersionModel.deviance_derivative", + "unique_qname": "sklearn._loss.glm_distribution.ExponentialDispersionModel.deviance_derivative", "decorators": [], "parameters": [ { @@ -27462,7 +27447,9 @@ }, { "name": "in_y_range", + "unique_name": "in_y_range", "qname": "sklearn._loss.glm_distribution.ExponentialDispersionModel.in_y_range", + "unique_qname": "sklearn._loss.glm_distribution.ExponentialDispersionModel.in_y_range", "decorators": [], "parameters": [ { @@ -27494,7 +27481,9 @@ }, { "name": "unit_deviance", + "unique_name": "unit_deviance", "qname": "sklearn._loss.glm_distribution.ExponentialDispersionModel.unit_deviance", + "unique_qname": "sklearn._loss.glm_distribution.ExponentialDispersionModel.unit_deviance", "decorators": ["abstractmethod"], "parameters": [ { @@ -27546,7 +27535,9 @@ }, { "name": "unit_deviance_derivative", + "unique_name": "unit_deviance_derivative", "qname": "sklearn._loss.glm_distribution.ExponentialDispersionModel.unit_deviance_derivative", + "unique_qname": "sklearn._loss.glm_distribution.ExponentialDispersionModel.unit_deviance_derivative", "decorators": [], "parameters": [ { @@ -27588,7 +27579,9 @@ }, { "name": "unit_variance", + "unique_name": "unit_variance", "qname": "sklearn._loss.glm_distribution.ExponentialDispersionModel.unit_variance", + "unique_qname": "sklearn._loss.glm_distribution.ExponentialDispersionModel.unit_variance", "decorators": ["abstractmethod"], "parameters": [ { @@ -27620,7 +27613,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn._loss.glm_distribution.GammaDistribution.__init__", + "unique_qname": "sklearn._loss.glm_distribution.GammaDistribution.__init__", "decorators": [], "parameters": [ { @@ -27642,7 +27637,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn._loss.glm_distribution.InverseGaussianDistribution.__init__", + "unique_qname": "sklearn._loss.glm_distribution.InverseGaussianDistribution.__init__", "decorators": [], "parameters": [ { @@ -27664,7 +27661,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn._loss.glm_distribution.NormalDistribution.__init__", + "unique_qname": "sklearn._loss.glm_distribution.NormalDistribution.__init__", "decorators": [], "parameters": [ { @@ -27686,7 +27685,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn._loss.glm_distribution.PoissonDistribution.__init__", + "unique_qname": "sklearn._loss.glm_distribution.PoissonDistribution.__init__", "decorators": [], "parameters": [ { @@ -27708,7 +27709,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn._loss.glm_distribution.TweedieDistribution.__init__", + "unique_qname": "sklearn._loss.glm_distribution.TweedieDistribution.__init__", "decorators": [], "parameters": [ { @@ -27740,7 +27743,33 @@ }, { "name": "power", + "unique_name": "power@getter", "qname": "sklearn._loss.glm_distribution.TweedieDistribution.power", + "unique_qname": "sklearn._loss.glm_distribution.TweedieDistribution.power@getter", + "decorators": ["property"], + "parameters": [ + { + "name": "self", + "default_value": null, + "is_public": false, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "", + "description": "" + } + } + ], + "results": [], + "is_public": false, + "description": "", + "docstring": "", + "source_code": "\n@property\ndef power(self):\n return self._power" + }, + { + "name": "power", + "unique_name": "power@setter", + "qname": "sklearn._loss.glm_distribution.TweedieDistribution.power", + "unique_qname": "sklearn._loss.glm_distribution.TweedieDistribution.power@setter", "decorators": ["power.setter"], "parameters": [ { @@ -27772,7 +27801,9 @@ }, { "name": "unit_deviance", + "unique_name": "unit_deviance", "qname": "sklearn._loss.glm_distribution.TweedieDistribution.unit_deviance", + "unique_qname": "sklearn._loss.glm_distribution.TweedieDistribution.unit_deviance", "decorators": [], "parameters": [ { @@ -27824,7 +27855,9 @@ }, { "name": "unit_variance", + "unique_name": "unit_variance", "qname": "sklearn._loss.glm_distribution.TweedieDistribution.unit_variance", + "unique_qname": "sklearn._loss.glm_distribution.TweedieDistribution.unit_variance", "decorators": [], "parameters": [ { @@ -27856,7 +27889,9 @@ }, { "name": "__getstate__", + "unique_name": "__getstate__", "qname": "sklearn.base.BaseEstimator.__getstate__", + "unique_qname": "sklearn.base.BaseEstimator.__getstate__", "decorators": [], "parameters": [ { @@ -27878,7 +27913,9 @@ }, { "name": "__repr__", + "unique_name": "__repr__", "qname": "sklearn.base.BaseEstimator.__repr__", + "unique_qname": "sklearn.base.BaseEstimator.__repr__", "decorators": [], "parameters": [ { @@ -27910,7 +27947,9 @@ }, { "name": "__setstate__", + "unique_name": "__setstate__", "qname": "sklearn.base.BaseEstimator.__setstate__", + "unique_qname": "sklearn.base.BaseEstimator.__setstate__", "decorators": [], "parameters": [ { @@ -27942,7 +27981,9 @@ }, { "name": "_check_feature_names", + "unique_name": "_check_feature_names", "qname": "sklearn.base.BaseEstimator._check_feature_names", + "unique_qname": "sklearn.base.BaseEstimator._check_feature_names", "decorators": [], "parameters": [ { @@ -27980,11 +28021,13 @@ "is_public": false, "description": "Set or check the `feature_names_in_` attribute.\n\n.. versionadded:: 1.0", "docstring": "Set or check the `feature_names_in_` attribute.\n\n.. versionadded:: 1.0\n\nParameters\n----------\nX : {ndarray, dataframe} of shape (n_samples, n_features)\n The input samples.\n\nreset : bool\n Whether to reset the `feature_names_in_` attribute.\n If False, the input will be checked for consistency with\n feature names of data provided when reset was last True.\n .. note::\n It is recommended to call `reset=True` in `fit` and in the first\n call to `partial_fit`. All other methods that validate `X`\n should set `reset=False`.", - "source_code": "\ndef _check_feature_names(self, X, *, reset):\n \"\"\"Set or check the `feature_names_in_` attribute.\n\n .. versionadded:: 1.0\n\n Parameters\n ----------\n X : {ndarray, dataframe} of shape (n_samples, n_features)\n The input samples.\n\n reset : bool\n Whether to reset the `feature_names_in_` attribute.\n If False, the input will be checked for consistency with\n feature names of data provided when reset was last True.\n .. note::\n It is recommended to call `reset=True` in `fit` and in the first\n call to `partial_fit`. All other methods that validate `X`\n should set `reset=False`.\n \"\"\"\n if reset:\n feature_names_in = _get_feature_names(X)\n if feature_names_in is not None:\n self.feature_names_in_ = feature_names_in\n return\n fitted_feature_names = getattr(self, 'feature_names_in_', None)\n X_feature_names = _get_feature_names(X)\n if fitted_feature_names is None and X_feature_names is None:\n return\n if X_feature_names is not None and fitted_feature_names is None:\n warnings.warn(f'X has feature names, but {self.__class__.__name__} was fitted without feature names')\n return\n if X_feature_names is None and fitted_feature_names is not None:\n warnings.warn(f'X does not have valid feature names, but {self.__class__.__name__} was fitted with feature names')\n return\n if len(fitted_feature_names) != len(X_feature_names) or np.any(fitted_feature_names != X_feature_names):\n message = 'The feature names should match those that were passed during fit. Starting version 1.2, an error will be raised.\\n'\n fitted_feature_names_set = set(fitted_feature_names)\n X_feature_names_set = set(X_feature_names)\n unexpected_names = sorted(X_feature_names_set - fitted_feature_names_set)\n missing_names = sorted(fitted_feature_names_set - X_feature_names_set)\n \n def add_names(names):\n output = ''\n max_n_names = 5\n for (i, name) in enumerate(names):\n if i >= max_n_names:\n output += '- ...\\n'\n break\n output += f'- {name}\\n'\n return output\n if unexpected_names:\n message += 'Feature names unseen at fit time:\\n'\n message += add_names(unexpected_names)\n if missing_names:\n message += 'Feature names seen at fit time, yet now missing:\\n'\n message += add_names(missing_names)\n if not missing_names and not missing_names:\n message += 'Feature names must be in the same order as they were in fit.\\n'\n warnings.warn(message, FutureWarning)" + "source_code": "\ndef _check_feature_names(self, X, *, reset):\n \"\"\"Set or check the `feature_names_in_` attribute.\n\n .. versionadded:: 1.0\n\n Parameters\n ----------\n X : {ndarray, dataframe} of shape (n_samples, n_features)\n The input samples.\n\n reset : bool\n Whether to reset the `feature_names_in_` attribute.\n If False, the input will be checked for consistency with\n feature names of data provided when reset was last True.\n .. note::\n It is recommended to call `reset=True` in `fit` and in the first\n call to `partial_fit`. All other methods that validate `X`\n should set `reset=False`.\n \"\"\"\n if reset:\n feature_names_in = _get_feature_names(X)\n if feature_names_in is not None:\n self.feature_names_in_ = feature_names_in\n elif hasattr(self, 'feature_names_in_'):\n delattr(self, 'feature_names_in_')\n return\n fitted_feature_names = getattr(self, 'feature_names_in_', None)\n X_feature_names = _get_feature_names(X)\n if fitted_feature_names is None and X_feature_names is None:\n return\n if X_feature_names is not None and fitted_feature_names is None:\n warnings.warn(f'X has feature names, but {self.__class__.__name__} was fitted without feature names')\n return\n if X_feature_names is None and fitted_feature_names is not None:\n warnings.warn(f'X does not have valid feature names, but {self.__class__.__name__} was fitted with feature names')\n return\n if len(fitted_feature_names) != len(X_feature_names) or np.any(fitted_feature_names != X_feature_names):\n message = 'The feature names should match those that were passed during fit. Starting version 1.2, an error will be raised.\\n'\n fitted_feature_names_set = set(fitted_feature_names)\n X_feature_names_set = set(X_feature_names)\n unexpected_names = sorted(X_feature_names_set - fitted_feature_names_set)\n missing_names = sorted(fitted_feature_names_set - X_feature_names_set)\n \n def add_names(names):\n output = ''\n max_n_names = 5\n for (i, name) in enumerate(names):\n if i >= max_n_names:\n output += '- ...\\n'\n break\n output += f'- {name}\\n'\n return output\n if unexpected_names:\n message += 'Feature names unseen at fit time:\\n'\n message += add_names(unexpected_names)\n if missing_names:\n message += 'Feature names seen at fit time, yet now missing:\\n'\n message += add_names(missing_names)\n if not missing_names and not missing_names:\n message += 'Feature names must be in the same order as they were in fit.\\n'\n warnings.warn(message, FutureWarning)" }, { "name": "_check_n_features", + "unique_name": "_check_n_features", "qname": "sklearn.base.BaseEstimator._check_n_features", + "unique_qname": "sklearn.base.BaseEstimator._check_n_features", "decorators": [], "parameters": [ { @@ -28026,7 +28069,9 @@ }, { "name": "_get_param_names", + "unique_name": "_get_param_names", "qname": "sklearn.base.BaseEstimator._get_param_names", + "unique_qname": "sklearn.base.BaseEstimator._get_param_names", "decorators": ["classmethod"], "parameters": [ { @@ -28048,7 +28093,9 @@ }, { "name": "_get_tags", + "unique_name": "_get_tags", "qname": "sklearn.base.BaseEstimator._get_tags", + "unique_qname": "sklearn.base.BaseEstimator._get_tags", "decorators": [], "parameters": [ { @@ -28070,7 +28117,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.base.BaseEstimator._more_tags", + "unique_qname": "sklearn.base.BaseEstimator._more_tags", "decorators": [], "parameters": [ { @@ -28092,7 +28141,9 @@ }, { "name": "_repr_html_", + "unique_name": "_repr_html_@getter", "qname": "sklearn.base.BaseEstimator._repr_html_", + "unique_qname": "sklearn.base.BaseEstimator._repr_html_@getter", "decorators": ["property"], "parameters": [ { @@ -28114,7 +28165,9 @@ }, { "name": "_repr_html_inner", + "unique_name": "_repr_html_inner", "qname": "sklearn.base.BaseEstimator._repr_html_inner", + "unique_qname": "sklearn.base.BaseEstimator._repr_html_inner", "decorators": [], "parameters": [ { @@ -28136,7 +28189,9 @@ }, { "name": "_repr_mimebundle_", + "unique_name": "_repr_mimebundle_", "qname": "sklearn.base.BaseEstimator._repr_mimebundle_", + "unique_qname": "sklearn.base.BaseEstimator._repr_mimebundle_", "decorators": [], "parameters": [ { @@ -28158,7 +28213,9 @@ }, { "name": "_validate_data", + "unique_name": "_validate_data", "qname": "sklearn.base.BaseEstimator._validate_data", + "unique_qname": "sklearn.base.BaseEstimator._validate_data", "decorators": [], "parameters": [ { @@ -28220,7 +28277,9 @@ }, { "name": "get_params", + "unique_name": "get_params", "qname": "sklearn.base.BaseEstimator.get_params", + "unique_qname": "sklearn.base.BaseEstimator.get_params", "decorators": [], "parameters": [ { @@ -28252,7 +28311,9 @@ }, { "name": "set_params", + "unique_name": "set_params", "qname": "sklearn.base.BaseEstimator.set_params", + "unique_qname": "sklearn.base.BaseEstimator.set_params", "decorators": [], "parameters": [ { @@ -28274,7 +28335,9 @@ }, { "name": "biclusters_", + "unique_name": "biclusters_@getter", "qname": "sklearn.base.BiclusterMixin.biclusters_", + "unique_qname": "sklearn.base.BiclusterMixin.biclusters_@getter", "decorators": ["property"], "parameters": [ { @@ -28296,7 +28359,9 @@ }, { "name": "get_indices", + "unique_name": "get_indices", "qname": "sklearn.base.BiclusterMixin.get_indices", + "unique_qname": "sklearn.base.BiclusterMixin.get_indices", "decorators": [], "parameters": [ { @@ -28324,11 +28389,13 @@ "is_public": true, "description": "Row and column indices of the `i`'th bicluster.\n\nOnly works if ``rows_`` and ``columns_`` attributes exist.", "docstring": "Row and column indices of the `i`'th bicluster.\n\nOnly works if ``rows_`` and ``columns_`` attributes exist.\n\nParameters\n----------\ni : int\n The index of the cluster.\n\nReturns\n-------\nrow_ind : ndarray, dtype=np.intp\n Indices of rows in the dataset that belong to the bicluster.\ncol_ind : ndarray, dtype=np.intp\n Indices of columns in the dataset that belong to the bicluster.", - "source_code": "\ndef get_indices(self, i):\n \"\"\"Row and column indices of the `i`'th bicluster.\n\n Only works if ``rows_`` and ``columns_`` attributes exist.\n\n Parameters\n ----------\n i : int\n The index of the cluster.\n\n Returns\n -------\n row_ind : ndarray, dtype=np.intp\n Indices of rows in the dataset that belong to the bicluster.\n col_ind : ndarray, dtype=np.intp\n Indices of columns in the dataset that belong to the bicluster.\n\n \"\"\"\n rows = self.rows_[i]\n columns = self.columns_[i]\n return np.nonzero(rows)[0], np.nonzero(columns)[0]" + "source_code": "\ndef get_indices(self, i):\n \"\"\"Row and column indices of the `i`'th bicluster.\n\n Only works if ``rows_`` and ``columns_`` attributes exist.\n\n Parameters\n ----------\n i : int\n The index of the cluster.\n\n Returns\n -------\n row_ind : ndarray, dtype=np.intp\n Indices of rows in the dataset that belong to the bicluster.\n col_ind : ndarray, dtype=np.intp\n Indices of columns in the dataset that belong to the bicluster.\n \"\"\"\n rows = self.rows_[i]\n columns = self.columns_[i]\n return np.nonzero(rows)[0], np.nonzero(columns)[0]" }, { "name": "get_shape", + "unique_name": "get_shape", "qname": "sklearn.base.BiclusterMixin.get_shape", + "unique_qname": "sklearn.base.BiclusterMixin.get_shape", "decorators": [], "parameters": [ { @@ -28360,7 +28427,9 @@ }, { "name": "get_submatrix", + "unique_name": "get_submatrix", "qname": "sklearn.base.BiclusterMixin.get_submatrix", + "unique_qname": "sklearn.base.BiclusterMixin.get_submatrix", "decorators": [], "parameters": [ { @@ -28402,7 +28471,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.base.ClassifierMixin._more_tags", + "unique_qname": "sklearn.base.ClassifierMixin._more_tags", "decorators": [], "parameters": [ { @@ -28424,7 +28495,9 @@ }, { "name": "score", + "unique_name": "score", "qname": "sklearn.base.ClassifierMixin.score", + "unique_qname": "sklearn.base.ClassifierMixin.score", "decorators": [], "parameters": [ { @@ -28476,7 +28549,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.base.ClusterMixin._more_tags", + "unique_qname": "sklearn.base.ClusterMixin._more_tags", "decorators": [], "parameters": [ { @@ -28498,7 +28573,9 @@ }, { "name": "fit_predict", + "unique_name": "fit_predict", "qname": "sklearn.base.ClusterMixin.fit_predict", + "unique_qname": "sklearn.base.ClusterMixin.fit_predict", "decorators": [], "parameters": [ { @@ -28540,7 +28617,9 @@ }, { "name": "score", + "unique_name": "score", "qname": "sklearn.base.DensityMixin.score", + "unique_qname": "sklearn.base.DensityMixin.score", "decorators": [], "parameters": [ { @@ -28582,7 +28661,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.base.MultiOutputMixin._more_tags", + "unique_qname": "sklearn.base.MultiOutputMixin._more_tags", "decorators": [], "parameters": [ { @@ -28604,7 +28685,9 @@ }, { "name": "fit_predict", + "unique_name": "fit_predict", "qname": "sklearn.base.OutlierMixin.fit_predict", + "unique_qname": "sklearn.base.OutlierMixin.fit_predict", "decorators": [], "parameters": [ { @@ -28646,7 +28729,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.base.RegressorMixin._more_tags", + "unique_qname": "sklearn.base.RegressorMixin._more_tags", "decorators": [], "parameters": [ { @@ -28668,7 +28753,9 @@ }, { "name": "score", + "unique_name": "score", "qname": "sklearn.base.RegressorMixin.score", + "unique_qname": "sklearn.base.RegressorMixin.score", "decorators": [], "parameters": [ { @@ -28720,7 +28807,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.base.TransformerMixin.fit_transform", + "unique_qname": "sklearn.base.TransformerMixin.fit_transform", "decorators": [], "parameters": [ { @@ -28762,7 +28851,9 @@ }, { "name": "get_feature_names_out", + "unique_name": "get_feature_names_out", "qname": "sklearn.base._OneToOneFeatureMixin.get_feature_names_out", + "unique_qname": "sklearn.base._OneToOneFeatureMixin.get_feature_names_out", "decorators": [], "parameters": [ { @@ -28794,7 +28885,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.base._UnstableArchMixin._more_tags", + "unique_qname": "sklearn.base._UnstableArchMixin._more_tags", "decorators": [], "parameters": [ { @@ -28816,7 +28909,9 @@ }, { "name": "_is_pairwise", + "unique_name": "_is_pairwise", "qname": "sklearn.base._is_pairwise", + "unique_qname": "sklearn.base._is_pairwise", "decorators": [], "parameters": [ { @@ -28838,7 +28933,9 @@ }, { "name": "_pprint", + "unique_name": "_pprint", "qname": "sklearn.base._pprint", + "unique_qname": "sklearn.base._pprint", "decorators": [], "parameters": [ { @@ -28880,7 +28977,9 @@ }, { "name": "clone", + "unique_name": "clone", "qname": "sklearn.base.clone", + "unique_qname": "sklearn.base.clone", "decorators": [], "parameters": [ { @@ -28912,7 +29011,9 @@ }, { "name": "is_classifier", + "unique_name": "is_classifier", "qname": "sklearn.base.is_classifier", + "unique_qname": "sklearn.base.is_classifier", "decorators": [], "parameters": [ { @@ -28934,7 +29035,9 @@ }, { "name": "is_outlier_detector", + "unique_name": "is_outlier_detector", "qname": "sklearn.base.is_outlier_detector", + "unique_qname": "sklearn.base.is_outlier_detector", "decorators": [], "parameters": [ { @@ -28956,7 +29059,9 @@ }, { "name": "is_regressor", + "unique_name": "is_regressor", "qname": "sklearn.base.is_regressor", + "unique_qname": "sklearn.base.is_regressor", "decorators": [], "parameters": [ { @@ -28978,7 +29083,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.calibration.CalibratedClassifierCV.__init__", + "unique_qname": "sklearn.calibration.CalibratedClassifierCV.__init__", "decorators": [], "parameters": [ { @@ -29050,7 +29157,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.calibration.CalibratedClassifierCV._more_tags", + "unique_qname": "sklearn.calibration.CalibratedClassifierCV._more_tags", "decorators": [], "parameters": [ { @@ -29068,11 +29177,13 @@ "is_public": false, "description": "", "docstring": "", - "source_code": "\ndef _more_tags(self):\n return {'_xfail_checks': {'check_sample_weights_invariance': 'zero sample_weight is not equivalent to removing samples'}}" + "source_code": "\ndef _more_tags(self):\n return {'_xfail_checks': {'check_sample_weights_invariance': 'Due to the cross-validation and sample ordering, removing a sample is not strictly equal to putting is weight to zero. Specific unit tests are added for CalibratedClassifierCV specifically.'}}" }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.calibration.CalibratedClassifierCV.fit", + "unique_qname": "sklearn.calibration.CalibratedClassifierCV.fit", "decorators": [], "parameters": [ { @@ -29120,11 +29231,13 @@ "is_public": true, "description": "Fit the calibrated model.", "docstring": "Fit the calibrated model.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Training data.\n\ny : array-like of shape (n_samples,)\n Target values.\n\nsample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n\nReturns\n-------\nself : object\n Returns an instance of self.", - "source_code": "\ndef fit(self, X, y, sample_weight=None):\n \"\"\"Fit the calibrated model.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training data.\n\n y : array-like of shape (n_samples,)\n Target values.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n\n Returns\n -------\n self : object\n Returns an instance of self.\n \"\"\"\n check_classification_targets(y)\n (X, y) = indexable(X, y)\n if self.base_estimator is None:\n base_estimator = LinearSVC(random_state=0)\n else:\n base_estimator = self.base_estimator\n self.calibrated_classifiers_ = []\n if self.cv == 'prefit':\n check_is_fitted(self.base_estimator, attributes=['classes_'])\n self.classes_ = self.base_estimator.classes_\n (pred_method, method_name) = _get_prediction_method(base_estimator)\n n_classes = len(self.classes_)\n predictions = _compute_predictions(pred_method, method_name, X, n_classes)\n calibrated_classifier = _fit_calibrator(base_estimator, predictions, y, self.classes_, self.method, sample_weight)\n self.calibrated_classifiers_.append(calibrated_classifier)\n else:\n label_encoder_ = LabelEncoder().fit(y)\n self.classes_ = label_encoder_.classes_\n n_classes = len(self.classes_)\n fit_parameters = signature(base_estimator.fit).parameters\n supports_sw = 'sample_weight' in fit_parameters\n if sample_weight is not None:\n sample_weight = _check_sample_weight(sample_weight, X)\n if not supports_sw:\n estimator_name = type(base_estimator).__name__\n warnings.warn(f'Since {estimator_name} does not support sample_weights, sample weights will only be used for the calibration itself.')\n if isinstance(self.cv, int):\n n_folds = self.cv\n elif hasattr(self.cv, 'n_splits'):\n n_folds = self.cv.n_splits\n else:\n n_folds = None\n if n_folds and np.any([np.sum(y == class_) < n_folds for class_ in self.classes_]):\n raise ValueError(f'Requesting {n_folds}-fold cross-validation but provided less than {n_folds} examples for at least one class.')\n cv = check_cv(self.cv, y, classifier=True)\n if self.ensemble:\n parallel = Parallel(n_jobs=self.n_jobs)\n self.calibrated_classifiers_ = parallel((delayed(_fit_classifier_calibrator_pair)(clone(base_estimator), X, y, train=train, test=test, method=self.method, classes=self.classes_, supports_sw=supports_sw, sample_weight=sample_weight) for (train, test) in cv.split(X, y)))\n else:\n this_estimator = clone(base_estimator)\n (_, method_name) = _get_prediction_method(this_estimator)\n pred_method = partial(cross_val_predict, estimator=this_estimator, X=X, y=y, cv=cv, method=method_name, n_jobs=self.n_jobs)\n predictions = _compute_predictions(pred_method, method_name, X, n_classes)\n if sample_weight is not None and supports_sw:\n this_estimator.fit(X, y, sample_weight)\n else:\n this_estimator.fit(X, y)\n calibrated_classifier = _fit_calibrator(this_estimator, predictions, y, self.classes_, self.method, sample_weight)\n self.calibrated_classifiers_.append(calibrated_classifier)\n first_clf = self.calibrated_classifiers_[0].base_estimator\n if hasattr(first_clf, 'n_features_in_'):\n self.n_features_in_ = first_clf.n_features_in_\n if hasattr(first_clf, 'feature_names_in_'):\n self.feature_names_in_ = first_clf.feature_names_in_\n return self" + "source_code": "\ndef fit(self, X, y, sample_weight=None):\n \"\"\"Fit the calibrated model.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training data.\n\n y : array-like of shape (n_samples,)\n Target values.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n\n Returns\n -------\n self : object\n Returns an instance of self.\n \"\"\"\n check_classification_targets(y)\n (X, y) = indexable(X, y)\n if sample_weight is not None:\n sample_weight = _check_sample_weight(sample_weight, X)\n if self.base_estimator is None:\n base_estimator = LinearSVC(random_state=0)\n else:\n base_estimator = self.base_estimator\n self.calibrated_classifiers_ = []\n if self.cv == 'prefit':\n check_is_fitted(self.base_estimator, attributes=['classes_'])\n self.classes_ = self.base_estimator.classes_\n (pred_method, method_name) = _get_prediction_method(base_estimator)\n n_classes = len(self.classes_)\n predictions = _compute_predictions(pred_method, method_name, X, n_classes)\n calibrated_classifier = _fit_calibrator(base_estimator, predictions, y, self.classes_, self.method, sample_weight)\n self.calibrated_classifiers_.append(calibrated_classifier)\n else:\n label_encoder_ = LabelEncoder().fit(y)\n self.classes_ = label_encoder_.classes_\n n_classes = len(self.classes_)\n fit_parameters = signature(base_estimator.fit).parameters\n supports_sw = 'sample_weight' in fit_parameters\n if sample_weight is not None and not supports_sw:\n estimator_name = type(base_estimator).__name__\n warnings.warn(f'Since {estimator_name} does not appear to accept sample_weight, sample weights will only be used for the calibration itself. This can be caused by a limitation of the current scikit-learn API. See the following issue for more details: https://github.com/scikit-learn/scikit-learn/issues/21134. Be warned that the result of the calibration is likely to be incorrect.')\n if isinstance(self.cv, int):\n n_folds = self.cv\n elif hasattr(self.cv, 'n_splits'):\n n_folds = self.cv.n_splits\n else:\n n_folds = None\n if n_folds and np.any([np.sum(y == class_) < n_folds for class_ in self.classes_]):\n raise ValueError(f'Requesting {n_folds}-fold cross-validation but provided less than {n_folds} examples for at least one class.')\n cv = check_cv(self.cv, y, classifier=True)\n if self.ensemble:\n parallel = Parallel(n_jobs=self.n_jobs)\n self.calibrated_classifiers_ = parallel((delayed(_fit_classifier_calibrator_pair)(clone(base_estimator), X, y, train=train, test=test, method=self.method, classes=self.classes_, supports_sw=supports_sw, sample_weight=sample_weight) for (train, test) in cv.split(X, y)))\n else:\n this_estimator = clone(base_estimator)\n (_, method_name) = _get_prediction_method(this_estimator)\n fit_params = {'sample_weight': sample_weight} if sample_weight is not None and supports_sw else None\n pred_method = partial(cross_val_predict, estimator=this_estimator, X=X, y=y, cv=cv, method=method_name, n_jobs=self.n_jobs, fit_params=fit_params)\n predictions = _compute_predictions(pred_method, method_name, X, n_classes)\n if sample_weight is not None and supports_sw:\n this_estimator.fit(X, y, sample_weight)\n else:\n this_estimator.fit(X, y)\n calibrated_classifier = _fit_calibrator(this_estimator, predictions, y, self.classes_, self.method, sample_weight)\n self.calibrated_classifiers_.append(calibrated_classifier)\n first_clf = self.calibrated_classifiers_[0].base_estimator\n if hasattr(first_clf, 'n_features_in_'):\n self.n_features_in_ = first_clf.n_features_in_\n if hasattr(first_clf, 'feature_names_in_'):\n self.feature_names_in_ = first_clf.feature_names_in_\n return self" }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.calibration.CalibratedClassifierCV.predict", + "unique_qname": "sklearn.calibration.CalibratedClassifierCV.predict", "decorators": [], "parameters": [ { @@ -29156,7 +29269,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.calibration.CalibratedClassifierCV.predict_proba", + "unique_qname": "sklearn.calibration.CalibratedClassifierCV.predict_proba", "decorators": [], "parameters": [ { @@ -29188,7 +29303,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.calibration.CalibrationDisplay.__init__", + "unique_qname": "sklearn.calibration.CalibrationDisplay.__init__", "decorators": [], "parameters": [ { @@ -29250,7 +29367,9 @@ }, { "name": "from_estimator", + "unique_name": "from_estimator", "qname": "sklearn.calibration.CalibrationDisplay.from_estimator", + "unique_qname": "sklearn.calibration.CalibrationDisplay.from_estimator", "decorators": ["classmethod"], "parameters": [ { @@ -29346,13 +29465,15 @@ ], "results": [], "is_public": true, - "description": "Plot calibration curve using an binary classifier and data.\n\nCalibration curve, also known as reliability diagram, uses inputs from a binary classifier and plots the average predicted probability for each bin against the fraction of positive classes, on the y-axis. Extra keyword arguments will be passed to :func:`matplotlib.pyplot.plot`. Read more about calibration in the :ref:`User Guide ` and more about the scikit-learn visualization API in :ref:`visualizations`. .. versionadded:: 1.0", - "docstring": "Plot calibration curve using an binary classifier and data.\n\nCalibration curve, also known as reliability diagram, uses inputs\nfrom a binary classifier and plots the average predicted probability\nfor each bin against the fraction of positive classes, on the\ny-axis.\n\nExtra keyword arguments will be passed to\n:func:`matplotlib.pyplot.plot`.\n\nRead more about calibration in the :ref:`User Guide ` and\nmore about the scikit-learn visualization API in :ref:`visualizations`.\n\n.. versionadded:: 1.0\n\nParameters\n----------\nestimator : estimator instance\n Fitted classifier or a fitted :class:`~sklearn.pipeline.Pipeline`\n in which the last estimator is a classifier. The classifier must\n have a :term:`predict_proba` method.\n\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input values.\n\ny : array-like of shape (n_samples,)\n Binary target values.\n\nn_bins : int, default=5\n Number of bins to discretize the [0, 1] interval into when\n calculating the calibration curve. A bigger number requires more\n data.\n\nstrategy : {'uniform', 'quantile'}, default='uniform'\n Strategy used to define the widths of the bins.\n\n - `'uniform'`: The bins have identical widths.\n - `'quantile'`: The bins have the same number of samples and depend\n on predicted probabilities.\n\nname : str, default=None\n Name for labeling curve. If `None`, the name of the estimator is\n used.\n\nref_line : bool, default=True\n If `True`, plots a reference line representing a perfectly\n calibrated classifier.\n\nax : matplotlib axes, default=None\n Axes object to plot on. If `None`, a new figure and axes is\n created.\n\n**kwargs : dict\n Keyword arguments to be passed to :func:`matplotlib.pyplot.plot`.\n\nReturns\n-------\ndisplay : :class:`~sklearn.calibration.CalibrationDisplay`.\n Object that stores computed values.\n\nSee Also\n--------\nCalibrationDisplay.from_predictions : Plot calibration curve using true\n and predicted labels.\n\nExamples\n--------\n>>> import matplotlib.pyplot as plt\n>>> from sklearn.datasets import make_classification\n>>> from sklearn.model_selection import train_test_split\n>>> from sklearn.linear_model import LogisticRegression\n>>> from sklearn.calibration import CalibrationDisplay\n>>> X, y = make_classification(random_state=0)\n>>> X_train, X_test, y_train, y_test = train_test_split(\n... X, y, random_state=0)\n>>> clf = LogisticRegression(random_state=0)\n>>> clf.fit(X_train, y_train)\nLogisticRegression(random_state=0)\n>>> disp = CalibrationDisplay.from_estimator(clf, X_test, y_test)\n>>> plt.show()", - "source_code": "\n@classmethod\ndef from_estimator(cls, estimator, X, y, *, n_bins=5, strategy='uniform', name=None, ref_line=True, ax=None, **kwargs):\n \"\"\"Plot calibration curve using an binary classifier and data.\n\n Calibration curve, also known as reliability diagram, uses inputs\n from a binary classifier and plots the average predicted probability\n for each bin against the fraction of positive classes, on the\n y-axis.\n\n Extra keyword arguments will be passed to\n :func:`matplotlib.pyplot.plot`.\n\n Read more about calibration in the :ref:`User Guide ` and\n more about the scikit-learn visualization API in :ref:`visualizations`.\n\n .. versionadded:: 1.0\n\n Parameters\n ----------\n estimator : estimator instance\n Fitted classifier or a fitted :class:`~sklearn.pipeline.Pipeline`\n in which the last estimator is a classifier. The classifier must\n have a :term:`predict_proba` method.\n\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input values.\n\n y : array-like of shape (n_samples,)\n Binary target values.\n\n n_bins : int, default=5\n Number of bins to discretize the [0, 1] interval into when\n calculating the calibration curve. A bigger number requires more\n data.\n\n strategy : {'uniform', 'quantile'}, default='uniform'\n Strategy used to define the widths of the bins.\n\n - `'uniform'`: The bins have identical widths.\n - `'quantile'`: The bins have the same number of samples and depend\n on predicted probabilities.\n\n name : str, default=None\n Name for labeling curve. If `None`, the name of the estimator is\n used.\n\n ref_line : bool, default=True\n If `True`, plots a reference line representing a perfectly\n calibrated classifier.\n\n ax : matplotlib axes, default=None\n Axes object to plot on. If `None`, a new figure and axes is\n created.\n\n **kwargs : dict\n Keyword arguments to be passed to :func:`matplotlib.pyplot.plot`.\n\n Returns\n -------\n display : :class:`~sklearn.calibration.CalibrationDisplay`.\n Object that stores computed values.\n\n See Also\n --------\n CalibrationDisplay.from_predictions : Plot calibration curve using true\n and predicted labels.\n\n Examples\n --------\n >>> import matplotlib.pyplot as plt\n >>> from sklearn.datasets import make_classification\n >>> from sklearn.model_selection import train_test_split\n >>> from sklearn.linear_model import LogisticRegression\n >>> from sklearn.calibration import CalibrationDisplay\n >>> X, y = make_classification(random_state=0)\n >>> X_train, X_test, y_train, y_test = train_test_split(\n ... X, y, random_state=0)\n >>> clf = LogisticRegression(random_state=0)\n >>> clf.fit(X_train, y_train)\n LogisticRegression(random_state=0)\n >>> disp = CalibrationDisplay.from_estimator(clf, X_test, y_test)\n >>> plt.show()\n \"\"\"\n method_name = f'{cls.__name__}.from_estimator'\n check_matplotlib_support(method_name)\n if not is_classifier(estimator):\n raise ValueError(\"'estimator' should be a fitted classifier.\")\n (y_prob, _) = _get_response(X, estimator, response_method='predict_proba', pos_label=None)\n name = name if name is not None else estimator.__class__.__name__\n return cls.from_predictions(y, y_prob, n_bins=n_bins, strategy=strategy, name=name, ref_line=ref_line, ax=ax, **kwargs)" + "description": "Plot calibration curve using a binary classifier and data.\n\nA calibration curve, also known as a reliability diagram, uses inputs from a binary classifier and plots the average predicted probability for each bin against the fraction of positive classes, on the y-axis. Extra keyword arguments will be passed to :func:`matplotlib.pyplot.plot`. Read more about calibration in the :ref:`User Guide ` and more about the scikit-learn visualization API in :ref:`visualizations`. .. versionadded:: 1.0", + "docstring": "Plot calibration curve using a binary classifier and data.\n\nA calibration curve, also known as a reliability diagram, uses inputs\nfrom a binary classifier and plots the average predicted probability\nfor each bin against the fraction of positive classes, on the\ny-axis.\n\nExtra keyword arguments will be passed to\n:func:`matplotlib.pyplot.plot`.\n\nRead more about calibration in the :ref:`User Guide ` and\nmore about the scikit-learn visualization API in :ref:`visualizations`.\n\n.. versionadded:: 1.0\n\nParameters\n----------\nestimator : estimator instance\n Fitted classifier or a fitted :class:`~sklearn.pipeline.Pipeline`\n in which the last estimator is a classifier. The classifier must\n have a :term:`predict_proba` method.\n\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input values.\n\ny : array-like of shape (n_samples,)\n Binary target values.\n\nn_bins : int, default=5\n Number of bins to discretize the [0, 1] interval into when\n calculating the calibration curve. A bigger number requires more\n data.\n\nstrategy : {'uniform', 'quantile'}, default='uniform'\n Strategy used to define the widths of the bins.\n\n - `'uniform'`: The bins have identical widths.\n - `'quantile'`: The bins have the same number of samples and depend\n on predicted probabilities.\n\nname : str, default=None\n Name for labeling curve. If `None`, the name of the estimator is\n used.\n\nref_line : bool, default=True\n If `True`, plots a reference line representing a perfectly\n calibrated classifier.\n\nax : matplotlib axes, default=None\n Axes object to plot on. If `None`, a new figure and axes is\n created.\n\n**kwargs : dict\n Keyword arguments to be passed to :func:`matplotlib.pyplot.plot`.\n\nReturns\n-------\ndisplay : :class:`~sklearn.calibration.CalibrationDisplay`.\n Object that stores computed values.\n\nSee Also\n--------\nCalibrationDisplay.from_predictions : Plot calibration curve using true\n and predicted labels.\n\nExamples\n--------\n>>> import matplotlib.pyplot as plt\n>>> from sklearn.datasets import make_classification\n>>> from sklearn.model_selection import train_test_split\n>>> from sklearn.linear_model import LogisticRegression\n>>> from sklearn.calibration import CalibrationDisplay\n>>> X, y = make_classification(random_state=0)\n>>> X_train, X_test, y_train, y_test = train_test_split(\n... X, y, random_state=0)\n>>> clf = LogisticRegression(random_state=0)\n>>> clf.fit(X_train, y_train)\nLogisticRegression(random_state=0)\n>>> disp = CalibrationDisplay.from_estimator(clf, X_test, y_test)\n>>> plt.show()", + "source_code": "\n@classmethod\ndef from_estimator(cls, estimator, X, y, *, n_bins=5, strategy='uniform', name=None, ref_line=True, ax=None, **kwargs):\n \"\"\"Plot calibration curve using a binary classifier and data.\n\n A calibration curve, also known as a reliability diagram, uses inputs\n from a binary classifier and plots the average predicted probability\n for each bin against the fraction of positive classes, on the\n y-axis.\n\n Extra keyword arguments will be passed to\n :func:`matplotlib.pyplot.plot`.\n\n Read more about calibration in the :ref:`User Guide ` and\n more about the scikit-learn visualization API in :ref:`visualizations`.\n\n .. versionadded:: 1.0\n\n Parameters\n ----------\n estimator : estimator instance\n Fitted classifier or a fitted :class:`~sklearn.pipeline.Pipeline`\n in which the last estimator is a classifier. The classifier must\n have a :term:`predict_proba` method.\n\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input values.\n\n y : array-like of shape (n_samples,)\n Binary target values.\n\n n_bins : int, default=5\n Number of bins to discretize the [0, 1] interval into when\n calculating the calibration curve. A bigger number requires more\n data.\n\n strategy : {'uniform', 'quantile'}, default='uniform'\n Strategy used to define the widths of the bins.\n\n - `'uniform'`: The bins have identical widths.\n - `'quantile'`: The bins have the same number of samples and depend\n on predicted probabilities.\n\n name : str, default=None\n Name for labeling curve. If `None`, the name of the estimator is\n used.\n\n ref_line : bool, default=True\n If `True`, plots a reference line representing a perfectly\n calibrated classifier.\n\n ax : matplotlib axes, default=None\n Axes object to plot on. If `None`, a new figure and axes is\n created.\n\n **kwargs : dict\n Keyword arguments to be passed to :func:`matplotlib.pyplot.plot`.\n\n Returns\n -------\n display : :class:`~sklearn.calibration.CalibrationDisplay`.\n Object that stores computed values.\n\n See Also\n --------\n CalibrationDisplay.from_predictions : Plot calibration curve using true\n and predicted labels.\n\n Examples\n --------\n >>> import matplotlib.pyplot as plt\n >>> from sklearn.datasets import make_classification\n >>> from sklearn.model_selection import train_test_split\n >>> from sklearn.linear_model import LogisticRegression\n >>> from sklearn.calibration import CalibrationDisplay\n >>> X, y = make_classification(random_state=0)\n >>> X_train, X_test, y_train, y_test = train_test_split(\n ... X, y, random_state=0)\n >>> clf = LogisticRegression(random_state=0)\n >>> clf.fit(X_train, y_train)\n LogisticRegression(random_state=0)\n >>> disp = CalibrationDisplay.from_estimator(clf, X_test, y_test)\n >>> plt.show()\n \"\"\"\n method_name = f'{cls.__name__}.from_estimator'\n check_matplotlib_support(method_name)\n if not is_classifier(estimator):\n raise ValueError(\"'estimator' should be a fitted classifier.\")\n (y_prob, _) = _get_response(X, estimator, response_method='predict_proba', pos_label=None)\n name = name if name is not None else estimator.__class__.__name__\n return cls.from_predictions(y, y_prob, n_bins=n_bins, strategy=strategy, name=name, ref_line=ref_line, ax=ax, **kwargs)" }, { "name": "from_predictions", + "unique_name": "from_predictions", "qname": "sklearn.calibration.CalibrationDisplay.from_predictions", + "unique_qname": "sklearn.calibration.CalibrationDisplay.from_predictions", "decorators": ["classmethod"], "parameters": [ { @@ -29444,7 +29565,9 @@ }, { "name": "plot", + "unique_name": "plot", "qname": "sklearn.calibration.CalibrationDisplay.plot", + "unique_qname": "sklearn.calibration.CalibrationDisplay.plot", "decorators": [], "parameters": [ { @@ -29496,7 +29619,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.calibration._CalibratedClassifier.__init__", + "unique_qname": "sklearn.calibration._CalibratedClassifier.__init__", "decorators": [], "parameters": [ { @@ -29558,7 +29683,9 @@ }, { "name": "calibrators_", + "unique_name": "calibrators_@getter", "qname": "sklearn.calibration._CalibratedClassifier.calibrators_", + "unique_qname": "sklearn.calibration._CalibratedClassifier.calibrators_@getter", "decorators": [ "deprecated('`calibrators_` is deprecated in 0.24 and will be removed in 1.1(renaming of 0.26). Use `calibrators` instead.')", "property" @@ -29583,7 +29710,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.calibration._CalibratedClassifier.predict_proba", + "unique_qname": "sklearn.calibration._CalibratedClassifier.predict_proba", "decorators": [], "parameters": [ { @@ -29615,7 +29744,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.calibration._SigmoidCalibration.fit", + "unique_qname": "sklearn.calibration._SigmoidCalibration.fit", "decorators": [], "parameters": [ { @@ -29667,7 +29798,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.calibration._SigmoidCalibration.predict", + "unique_qname": "sklearn.calibration._SigmoidCalibration.predict", "decorators": [], "parameters": [ { @@ -29699,7 +29832,9 @@ }, { "name": "_compute_predictions", + "unique_name": "_compute_predictions", "qname": "sklearn.calibration._compute_predictions", + "unique_qname": "sklearn.calibration._compute_predictions", "decorators": [], "parameters": [ { @@ -29751,7 +29886,9 @@ }, { "name": "_fit_calibrator", + "unique_name": "_fit_calibrator", "qname": "sklearn.calibration._fit_calibrator", + "unique_qname": "sklearn.calibration._fit_calibrator", "decorators": [], "parameters": [ { @@ -29823,7 +29960,9 @@ }, { "name": "_fit_classifier_calibrator_pair", + "unique_name": "_fit_classifier_calibrator_pair", "qname": "sklearn.calibration._fit_classifier_calibrator_pair", + "unique_qname": "sklearn.calibration._fit_classifier_calibrator_pair", "decorators": [], "parameters": [ { @@ -29925,7 +30064,9 @@ }, { "name": "_get_prediction_method", + "unique_name": "_get_prediction_method", "qname": "sklearn.calibration._get_prediction_method", + "unique_qname": "sklearn.calibration._get_prediction_method", "decorators": [], "parameters": [ { @@ -29947,7 +30088,9 @@ }, { "name": "_sigmoid_calibration", + "unique_name": "_sigmoid_calibration", "qname": "sklearn.calibration._sigmoid_calibration", + "unique_qname": "sklearn.calibration._sigmoid_calibration", "decorators": [], "parameters": [ { @@ -29985,11 +30128,13 @@ "is_public": false, "description": "Probability Calibration with sigmoid method (Platt 2000)", "docstring": "Probability Calibration with sigmoid method (Platt 2000)\n\nParameters\n----------\npredictions : ndarray of shape (n_samples,)\n The decision function or predict proba for the samples.\n\ny : ndarray of shape (n_samples,)\n The targets.\n\nsample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n\nReturns\n-------\na : float\n The slope.\n\nb : float\n The intercept.\n\nReferences\n----------\nPlatt, \"Probabilistic Outputs for Support Vector Machines\"", - "source_code": "\ndef _sigmoid_calibration(predictions, y, sample_weight=None):\n \"\"\"Probability Calibration with sigmoid method (Platt 2000)\n\n Parameters\n ----------\n predictions : ndarray of shape (n_samples,)\n The decision function or predict proba for the samples.\n\n y : ndarray of shape (n_samples,)\n The targets.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n\n Returns\n -------\n a : float\n The slope.\n\n b : float\n The intercept.\n\n References\n ----------\n Platt, \"Probabilistic Outputs for Support Vector Machines\"\n \"\"\"\n predictions = column_or_1d(predictions)\n y = column_or_1d(y)\n F = predictions\n prior0 = float(np.sum(y <= 0))\n prior1 = y.shape[0] - prior0\n T = np.zeros(y.shape)\n T[y > 0] = (prior1 + 1.0) / (prior1 + 2.0)\n T[y <= 0] = 1.0 / (prior0 + 2.0)\n T1 = 1.0 - T\n \n def objective(AB):\n P = expit(-(AB[0] * F + AB[1]))\n loss = -(xlogy(T, P) + xlogy(T1, 1.0 - P))\n if sample_weight is not None:\n return (sample_weight * loss).sum()\n else:\n return loss.sum()\n \n def grad(AB):\n P = expit(-(AB[0] * F + AB[1]))\n TEP_minus_T1P = T - P\n if sample_weight is not None:\n TEP_minus_T1P *= sample_weight\n dA = np.dot(TEP_minus_T1P, F)\n dB = np.sum(TEP_minus_T1P)\n return np.array([dA, dB])\n AB0 = np.array([0.0, log((prior0 + 1.0) / (prior1 + 1.0))])\n AB_ = fmin_bfgs(objective, AB0, fprime=grad, disp=False)\n return AB_[0], AB_[1]" + "source_code": "\ndef _sigmoid_calibration(predictions, y, sample_weight=None):\n \"\"\"Probability Calibration with sigmoid method (Platt 2000)\n\n Parameters\n ----------\n predictions : ndarray of shape (n_samples,)\n The decision function or predict proba for the samples.\n\n y : ndarray of shape (n_samples,)\n The targets.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n\n Returns\n -------\n a : float\n The slope.\n\n b : float\n The intercept.\n\n References\n ----------\n Platt, \"Probabilistic Outputs for Support Vector Machines\"\n \"\"\"\n predictions = column_or_1d(predictions)\n y = column_or_1d(y)\n F = predictions\n mask_negative_samples = y <= 0\n if sample_weight is not None:\n prior0 = sample_weight[mask_negative_samples].sum()\n prior1 = sample_weight[~mask_negative_samples].sum()\n else:\n prior0 = float(np.sum(mask_negative_samples))\n prior1 = y.shape[0] - prior0\n T = np.zeros_like(y, dtype=np.float64)\n T[y > 0] = (prior1 + 1.0) / (prior1 + 2.0)\n T[y <= 0] = 1.0 / (prior0 + 2.0)\n T1 = 1.0 - T\n \n def objective(AB):\n P = expit(-(AB[0] * F + AB[1]))\n loss = -(xlogy(T, P) + xlogy(T1, 1.0 - P))\n if sample_weight is not None:\n return (sample_weight * loss).sum()\n else:\n return loss.sum()\n \n def grad(AB):\n P = expit(-(AB[0] * F + AB[1]))\n TEP_minus_T1P = T - P\n if sample_weight is not None:\n TEP_minus_T1P *= sample_weight\n dA = np.dot(TEP_minus_T1P, F)\n dB = np.sum(TEP_minus_T1P)\n return np.array([dA, dB])\n AB0 = np.array([0.0, log((prior0 + 1.0) / (prior1 + 1.0))])\n AB_ = fmin_bfgs(objective, AB0, fprime=grad, disp=False)\n return AB_[0], AB_[1]" }, { "name": "calibration_curve", + "unique_name": "calibration_curve", "qname": "sklearn.calibration.calibration_curve", + "unique_qname": "sklearn.calibration.calibration_curve", "decorators": [], "parameters": [ { @@ -30051,7 +30196,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.cluster._affinity_propagation.AffinityPropagation.__init__", + "unique_qname": "sklearn.cluster._affinity_propagation.AffinityPropagation.__init__", "decorators": [], "parameters": [ { @@ -30153,7 +30300,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.cluster._affinity_propagation.AffinityPropagation._more_tags", + "unique_qname": "sklearn.cluster._affinity_propagation.AffinityPropagation._more_tags", "decorators": [], "parameters": [ { @@ -30175,7 +30324,9 @@ }, { "name": "_pairwise", + "unique_name": "_pairwise@getter", "qname": "sklearn.cluster._affinity_propagation.AffinityPropagation._pairwise", + "unique_qname": "sklearn.cluster._affinity_propagation.AffinityPropagation._pairwise@getter", "decorators": [ "deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -30200,7 +30351,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.cluster._affinity_propagation.AffinityPropagation.fit", + "unique_qname": "sklearn.cluster._affinity_propagation.AffinityPropagation.fit", "decorators": [], "parameters": [ { @@ -30242,7 +30395,9 @@ }, { "name": "fit_predict", + "unique_name": "fit_predict", "qname": "sklearn.cluster._affinity_propagation.AffinityPropagation.fit_predict", + "unique_qname": "sklearn.cluster._affinity_propagation.AffinityPropagation.fit_predict", "decorators": [], "parameters": [ { @@ -30284,7 +30439,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.cluster._affinity_propagation.AffinityPropagation.predict", + "unique_qname": "sklearn.cluster._affinity_propagation.AffinityPropagation.predict", "decorators": [], "parameters": [ { @@ -30316,7 +30473,9 @@ }, { "name": "_equal_similarities_and_preferences", + "unique_name": "_equal_similarities_and_preferences", "qname": "sklearn.cluster._affinity_propagation._equal_similarities_and_preferences", + "unique_qname": "sklearn.cluster._affinity_propagation._equal_similarities_and_preferences", "decorators": [], "parameters": [ { @@ -30348,7 +30507,9 @@ }, { "name": "affinity_propagation", + "unique_name": "affinity_propagation", "qname": "sklearn.cluster._affinity_propagation.affinity_propagation", + "unique_qname": "sklearn.cluster._affinity_propagation.affinity_propagation", "decorators": [], "parameters": [ { @@ -30450,7 +30611,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.cluster._agglomerative.AgglomerativeClustering.__init__", + "unique_qname": "sklearn.cluster._agglomerative.AgglomerativeClustering.__init__", "decorators": [], "parameters": [ { @@ -30550,9 +30713,45 @@ "docstring": "", "source_code": "\ndef __init__(self, n_clusters=2, *, affinity='euclidean', memory=None, connectivity=None, compute_full_tree='auto', linkage='ward', distance_threshold=None, compute_distances=False):\n self.n_clusters = n_clusters\n self.distance_threshold = distance_threshold\n self.memory = memory\n self.connectivity = connectivity\n self.compute_full_tree = compute_full_tree\n self.linkage = linkage\n self.affinity = affinity\n self.compute_distances = compute_distances" }, + { + "name": "_fit", + "unique_name": "_fit", + "qname": "sklearn.cluster._agglomerative.AgglomerativeClustering._fit", + "unique_qname": "sklearn.cluster._agglomerative.AgglomerativeClustering._fit", + "decorators": [], + "parameters": [ + { + "name": "self", + "default_value": null, + "is_public": false, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "", + "description": "" + } + }, + { + "name": "X", + "default_value": null, + "is_public": false, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "ndarray of shape (n_samples, n_features) or (n_samples, n_samples)", + "description": "Training instances to cluster, or distances between instances if\n``affinity='precomputed'``." + } + } + ], + "results": [], + "is_public": false, + "description": "Fit without validation", + "docstring": "Fit without validation\n\nParameters\n----------\nX : ndarray of shape (n_samples, n_features) or (n_samples, n_samples)\n Training instances to cluster, or distances between instances if\n ``affinity='precomputed'``.\n\nReturns\n-------\nself : object\n Returns the fitted instance.", + "source_code": "\ndef _fit(self, X):\n \"\"\"Fit without validation\n\n Parameters\n ----------\n X : ndarray of shape (n_samples, n_features) or (n_samples, n_samples)\n Training instances to cluster, or distances between instances if\n ``affinity='precomputed'``.\n\n Returns\n -------\n self : object\n Returns the fitted instance.\n \"\"\"\n memory = check_memory(self.memory)\n if self.n_clusters is not None and self.n_clusters <= 0:\n raise ValueError('n_clusters should be an integer greater than 0. %s was provided.' % str(self.n_clusters))\n if not (self.n_clusters is None) ^ (self.distance_threshold is None):\n raise ValueError('Exactly one of n_clusters and distance_threshold has to be set, and the other needs to be None.')\n if self.distance_threshold is not None and not self.compute_full_tree:\n raise ValueError('compute_full_tree must be True if distance_threshold is set.')\n if self.linkage == 'ward' and self.affinity != 'euclidean':\n raise ValueError('%s was provided as affinity. Ward can only work with euclidean distances.' % (self.affinity, ))\n if self.linkage not in _TREE_BUILDERS:\n raise ValueError('Unknown linkage type %s. Valid options are %s' % (self.linkage, _TREE_BUILDERS.keys()))\n tree_builder = _TREE_BUILDERS[self.linkage]\n connectivity = self.connectivity\n if self.connectivity is not None:\n if callable(self.connectivity):\n connectivity = self.connectivity(X)\n connectivity = check_array(connectivity, accept_sparse=['csr', 'coo', 'lil'])\n n_samples = len(X)\n compute_full_tree = self.compute_full_tree\n if self.connectivity is None:\n compute_full_tree = True\n if compute_full_tree == 'auto':\n if self.distance_threshold is not None:\n compute_full_tree = True\n else:\n compute_full_tree = self.n_clusters < max(100, 0.02 * n_samples)\n n_clusters = self.n_clusters\n if compute_full_tree:\n n_clusters = None\n kwargs = {}\n if self.linkage != 'ward':\n kwargs['linkage'] = self.linkage\n kwargs['affinity'] = self.affinity\n distance_threshold = self.distance_threshold\n return_distance = distance_threshold is not None or self.compute_distances\n out = memory.cache(tree_builder)(X, connectivity=connectivity, n_clusters=n_clusters, return_distance=return_distance, **kwargs)\n (self.children_, self.n_connected_components_, self.n_leaves_, parents) = out[:4]\n if return_distance:\n self.distances_ = out[-1]\n if self.distance_threshold is not None:\n self.n_clusters_ = np.count_nonzero(self.distances_ >= distance_threshold) + 1\n else:\n self.n_clusters_ = self.n_clusters\n if compute_full_tree:\n self.labels_ = _hc_cut(self.n_clusters_, self.children_, self.n_leaves_)\n else:\n labels = _hierarchical.hc_get_heads(parents, copy=False)\n labels = np.copy(labels[:n_samples])\n self.labels_ = np.searchsorted(np.unique(labels), labels)\n return self" + }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.cluster._agglomerative.AgglomerativeClustering.fit", + "unique_qname": "sklearn.cluster._agglomerative.AgglomerativeClustering.fit", "decorators": [], "parameters": [ { @@ -30590,11 +30789,13 @@ "is_public": true, "description": "Fit the hierarchical clustering from features, or distance matrix.", "docstring": "Fit the hierarchical clustering from features, or distance matrix.\n\nParameters\n----------\nX : array-like, shape (n_samples, n_features) or (n_samples, n_samples)\n Training instances to cluster, or distances between instances if\n ``affinity='precomputed'``.\n\ny : Ignored\n Not used, present here for API consistency by convention.\n\nReturns\n-------\nself : object\n Returns the fitted instance.", - "source_code": "\ndef fit(self, X, y=None):\n \"\"\"Fit the hierarchical clustering from features, or distance matrix.\n\n Parameters\n ----------\n X : array-like, shape (n_samples, n_features) or (n_samples, n_samples)\n Training instances to cluster, or distances between instances if\n ``affinity='precomputed'``.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self : object\n Returns the fitted instance.\n \"\"\"\n X = self._validate_data(X, ensure_min_samples=2, estimator=self)\n memory = check_memory(self.memory)\n if self.n_clusters is not None and self.n_clusters <= 0:\n raise ValueError('n_clusters should be an integer greater than 0. %s was provided.' % str(self.n_clusters))\n if not (self.n_clusters is None) ^ (self.distance_threshold is None):\n raise ValueError('Exactly one of n_clusters and distance_threshold has to be set, and the other needs to be None.')\n if self.distance_threshold is not None and not self.compute_full_tree:\n raise ValueError('compute_full_tree must be True if distance_threshold is set.')\n if self.linkage == 'ward' and self.affinity != 'euclidean':\n raise ValueError('%s was provided as affinity. Ward can only work with euclidean distances.' % (self.affinity, ))\n if self.linkage not in _TREE_BUILDERS:\n raise ValueError('Unknown linkage type %s. Valid options are %s' % (self.linkage, _TREE_BUILDERS.keys()))\n tree_builder = _TREE_BUILDERS[self.linkage]\n connectivity = self.connectivity\n if self.connectivity is not None:\n if callable(self.connectivity):\n connectivity = self.connectivity(X)\n connectivity = check_array(connectivity, accept_sparse=['csr', 'coo', 'lil'])\n n_samples = len(X)\n compute_full_tree = self.compute_full_tree\n if self.connectivity is None:\n compute_full_tree = True\n if compute_full_tree == 'auto':\n if self.distance_threshold is not None:\n compute_full_tree = True\n else:\n compute_full_tree = self.n_clusters < max(100, 0.02 * n_samples)\n n_clusters = self.n_clusters\n if compute_full_tree:\n n_clusters = None\n kwargs = {}\n if self.linkage != 'ward':\n kwargs['linkage'] = self.linkage\n kwargs['affinity'] = self.affinity\n distance_threshold = self.distance_threshold\n return_distance = distance_threshold is not None or self.compute_distances\n out = memory.cache(tree_builder)(X, connectivity=connectivity, n_clusters=n_clusters, return_distance=return_distance, **kwargs)\n (self.children_, self.n_connected_components_, self.n_leaves_, parents) = out[:4]\n if return_distance:\n self.distances_ = out[-1]\n if self.distance_threshold is not None:\n self.n_clusters_ = np.count_nonzero(self.distances_ >= distance_threshold) + 1\n else:\n self.n_clusters_ = self.n_clusters\n if compute_full_tree:\n self.labels_ = _hc_cut(self.n_clusters_, self.children_, self.n_leaves_)\n else:\n labels = _hierarchical.hc_get_heads(parents, copy=False)\n labels = np.copy(labels[:n_samples])\n self.labels_ = np.searchsorted(np.unique(labels), labels)\n return self" + "source_code": "\ndef fit(self, X, y=None):\n \"\"\"Fit the hierarchical clustering from features, or distance matrix.\n\n Parameters\n ----------\n X : array-like, shape (n_samples, n_features) or (n_samples, n_samples)\n Training instances to cluster, or distances between instances if\n ``affinity='precomputed'``.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self : object\n Returns the fitted instance.\n \"\"\"\n X = self._validate_data(X, ensure_min_samples=2, estimator=self)\n return self._fit(X)" }, { "name": "fit_predict", + "unique_name": "fit_predict", "qname": "sklearn.cluster._agglomerative.AgglomerativeClustering.fit_predict", + "unique_qname": "sklearn.cluster._agglomerative.AgglomerativeClustering.fit_predict", "decorators": [], "parameters": [ { @@ -30636,7 +30837,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.cluster._agglomerative.FeatureAgglomeration.__init__", + "unique_qname": "sklearn.cluster._agglomerative.FeatureAgglomeration.__init__", "decorators": [], "parameters": [ { @@ -30748,7 +30951,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.cluster._agglomerative.FeatureAgglomeration.fit", + "unique_qname": "sklearn.cluster._agglomerative.FeatureAgglomeration.fit", "decorators": [], "parameters": [ { @@ -30786,11 +30991,13 @@ "is_public": true, "description": "Fit the hierarchical clustering on the data.", "docstring": "Fit the hierarchical clustering on the data.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n The data.\n\ny : Ignored\n Not used, present here for API consistency by convention.\n\nReturns\n-------\nself : object\n Returns the transformer.", - "source_code": "\ndef fit(self, X, y=None):\n \"\"\"Fit the hierarchical clustering on the data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self : object\n Returns the transformer.\n \"\"\"\n X = self._validate_data(X, accept_sparse=['csr', 'csc', 'coo'], ensure_min_features=2, estimator=self)\n n_features_in_ = self.n_features_in_\n AgglomerativeClustering.fit(self, X.T)\n self.n_features_in_ = n_features_in_\n return self" + "source_code": "\ndef fit(self, X, y=None):\n \"\"\"Fit the hierarchical clustering on the data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self : object\n Returns the transformer.\n \"\"\"\n X = self._validate_data(X, ensure_min_features=2, estimator=self)\n super()._fit(X.T)\n return self" }, { "name": "fit_predict", + "unique_name": "fit_predict@getter", "qname": "sklearn.cluster._agglomerative.FeatureAgglomeration.fit_predict", + "unique_qname": "sklearn.cluster._agglomerative.FeatureAgglomeration.fit_predict@getter", "decorators": ["property"], "parameters": [ { @@ -30812,7 +31019,9 @@ }, { "name": "_average_linkage", + "unique_name": "_average_linkage", "qname": "sklearn.cluster._agglomerative._average_linkage", + "unique_qname": "sklearn.cluster._agglomerative._average_linkage", "decorators": [], "parameters": [], "results": [], @@ -30823,7 +31032,9 @@ }, { "name": "_complete_linkage", + "unique_name": "_complete_linkage", "qname": "sklearn.cluster._agglomerative._complete_linkage", + "unique_qname": "sklearn.cluster._agglomerative._complete_linkage", "decorators": [], "parameters": [], "results": [], @@ -30834,7 +31045,9 @@ }, { "name": "_fix_connectivity", + "unique_name": "_fix_connectivity", "qname": "sklearn.cluster._agglomerative._fix_connectivity", + "unique_qname": "sklearn.cluster._agglomerative._fix_connectivity", "decorators": [], "parameters": [ { @@ -30876,7 +31089,9 @@ }, { "name": "_hc_cut", + "unique_name": "_hc_cut", "qname": "sklearn.cluster._agglomerative._hc_cut", + "unique_qname": "sklearn.cluster._agglomerative._hc_cut", "decorators": [], "parameters": [ { @@ -30918,7 +31133,9 @@ }, { "name": "_single_linkage", + "unique_name": "_single_linkage", "qname": "sklearn.cluster._agglomerative._single_linkage", + "unique_qname": "sklearn.cluster._agglomerative._single_linkage", "decorators": [], "parameters": [], "results": [], @@ -30929,7 +31146,9 @@ }, { "name": "_single_linkage_tree", + "unique_name": "_single_linkage_tree", "qname": "sklearn.cluster._agglomerative._single_linkage_tree", + "unique_qname": "sklearn.cluster._agglomerative._single_linkage_tree", "decorators": [], "parameters": [ { @@ -31001,7 +31220,9 @@ }, { "name": "linkage_tree", + "unique_name": "linkage_tree", "qname": "sklearn.cluster._agglomerative.linkage_tree", + "unique_qname": "sklearn.cluster._agglomerative.linkage_tree", "decorators": [], "parameters": [ { @@ -31073,7 +31294,9 @@ }, { "name": "ward_tree", + "unique_name": "ward_tree", "qname": "sklearn.cluster._agglomerative.ward_tree", + "unique_qname": "sklearn.cluster._agglomerative.ward_tree", "decorators": [], "parameters": [ { @@ -31125,7 +31348,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.cluster._bicluster.BaseSpectral.__init__", + "unique_qname": "sklearn.cluster._bicluster.BaseSpectral.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -31217,7 +31442,9 @@ }, { "name": "_check_parameters", + "unique_name": "_check_parameters", "qname": "sklearn.cluster._bicluster.BaseSpectral._check_parameters", + "unique_qname": "sklearn.cluster._bicluster.BaseSpectral._check_parameters", "decorators": [], "parameters": [ { @@ -31239,7 +31466,9 @@ }, { "name": "_k_means", + "unique_name": "_k_means", "qname": "sklearn.cluster._bicluster.BaseSpectral._k_means", + "unique_qname": "sklearn.cluster._bicluster.BaseSpectral._k_means", "decorators": [], "parameters": [ { @@ -31281,7 +31510,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.cluster._bicluster.BaseSpectral._more_tags", + "unique_qname": "sklearn.cluster._bicluster.BaseSpectral._more_tags", "decorators": [], "parameters": [ { @@ -31303,7 +31534,9 @@ }, { "name": "_svd", + "unique_name": "_svd", "qname": "sklearn.cluster._bicluster.BaseSpectral._svd", + "unique_qname": "sklearn.cluster._bicluster.BaseSpectral._svd", "decorators": [], "parameters": [ { @@ -31355,7 +31588,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.cluster._bicluster.BaseSpectral.fit", + "unique_qname": "sklearn.cluster._bicluster.BaseSpectral.fit", "decorators": [], "parameters": [ { @@ -31375,7 +31610,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "array-like of shape (n_samples, n_features)", - "description": "" + "description": "Training data." } }, { @@ -31385,19 +31620,21 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "Ignored", - "description": "" + "description": "Not used, present for API consistency by convention." } } ], "results": [], "is_public": false, - "description": "Creates a biclustering for X.", - "docstring": "Creates a biclustering for X.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n\ny : Ignored", - "source_code": "\ndef fit(self, X, y=None):\n \"\"\"Creates a biclustering for X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n\n y : Ignored\n\n \"\"\"\n X = self._validate_data(X, accept_sparse='csr', dtype=np.float64)\n self._check_parameters()\n self._fit(X)\n return self" + "description": "Create a biclustering for X.", + "docstring": "Create a biclustering for X.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Training data.\n\ny : Ignored\n Not used, present for API consistency by convention.\n\nReturns\n-------\nself : object\n SpectralBiclustering instance.", + "source_code": "\ndef fit(self, X, y=None):\n \"\"\"Create a biclustering for X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training data.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n self : object\n SpectralBiclustering instance.\n \"\"\"\n X = self._validate_data(X, accept_sparse='csr', dtype=np.float64)\n self._check_parameters()\n self._fit(X)\n return self" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.cluster._bicluster.SpectralBiclustering.__init__", + "unique_qname": "sklearn.cluster._bicluster.SpectralBiclustering.__init__", "decorators": [], "parameters": [ { @@ -31519,7 +31756,9 @@ }, { "name": "_check_parameters", + "unique_name": "_check_parameters", "qname": "sklearn.cluster._bicluster.SpectralBiclustering._check_parameters", + "unique_qname": "sklearn.cluster._bicluster.SpectralBiclustering._check_parameters", "decorators": [], "parameters": [ { @@ -31541,7 +31780,9 @@ }, { "name": "_fit", + "unique_name": "_fit", "qname": "sklearn.cluster._bicluster.SpectralBiclustering._fit", + "unique_qname": "sklearn.cluster._bicluster.SpectralBiclustering._fit", "decorators": [], "parameters": [ { @@ -31573,7 +31814,9 @@ }, { "name": "_fit_best_piecewise", + "unique_name": "_fit_best_piecewise", "qname": "sklearn.cluster._bicluster.SpectralBiclustering._fit_best_piecewise", + "unique_qname": "sklearn.cluster._bicluster.SpectralBiclustering._fit_best_piecewise", "decorators": [], "parameters": [ { @@ -31625,7 +31868,9 @@ }, { "name": "_project_and_cluster", + "unique_name": "_project_and_cluster", "qname": "sklearn.cluster._bicluster.SpectralBiclustering._project_and_cluster", + "unique_qname": "sklearn.cluster._bicluster.SpectralBiclustering._project_and_cluster", "decorators": [], "parameters": [ { @@ -31677,7 +31922,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.cluster._bicluster.SpectralCoclustering.__init__", + "unique_qname": "sklearn.cluster._bicluster.SpectralCoclustering.__init__", "decorators": [], "parameters": [ { @@ -31769,7 +32016,9 @@ }, { "name": "_fit", + "unique_name": "_fit", "qname": "sklearn.cluster._bicluster.SpectralCoclustering._fit", + "unique_qname": "sklearn.cluster._bicluster.SpectralCoclustering._fit", "decorators": [], "parameters": [ { @@ -31801,7 +32050,9 @@ }, { "name": "_bistochastic_normalize", + "unique_name": "_bistochastic_normalize", "qname": "sklearn.cluster._bicluster._bistochastic_normalize", + "unique_qname": "sklearn.cluster._bicluster._bistochastic_normalize", "decorators": [], "parameters": [ { @@ -31843,7 +32094,9 @@ }, { "name": "_log_normalize", + "unique_name": "_log_normalize", "qname": "sklearn.cluster._bicluster._log_normalize", + "unique_qname": "sklearn.cluster._bicluster._log_normalize", "decorators": [], "parameters": [ { @@ -31865,7 +32118,9 @@ }, { "name": "_scale_normalize", + "unique_name": "_scale_normalize", "qname": "sklearn.cluster._bicluster._scale_normalize", + "unique_qname": "sklearn.cluster._bicluster._scale_normalize", "decorators": [], "parameters": [ { @@ -31887,7 +32142,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.cluster._birch.Birch.__init__", + "unique_qname": "sklearn.cluster._birch.Birch.__init__", "decorators": [], "parameters": [ { @@ -31959,7 +32216,9 @@ }, { "name": "_check_fit", + "unique_name": "_check_fit", "qname": "sklearn.cluster._birch.Birch._check_fit", + "unique_qname": "sklearn.cluster._birch.Birch._check_fit", "decorators": [], "parameters": [ { @@ -31991,7 +32250,9 @@ }, { "name": "_fit", + "unique_name": "_fit", "qname": "sklearn.cluster._birch.Birch._fit", + "unique_qname": "sklearn.cluster._birch.Birch._fit", "decorators": [], "parameters": [ { @@ -32033,7 +32294,9 @@ }, { "name": "_get_leaves", + "unique_name": "_get_leaves", "qname": "sklearn.cluster._birch.Birch._get_leaves", + "unique_qname": "sklearn.cluster._birch.Birch._get_leaves", "decorators": [], "parameters": [ { @@ -32055,7 +32318,9 @@ }, { "name": "_global_clustering", + "unique_name": "_global_clustering", "qname": "sklearn.cluster._birch.Birch._global_clustering", + "unique_qname": "sklearn.cluster._birch.Birch._global_clustering", "decorators": [], "parameters": [ { @@ -32087,7 +32352,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.cluster._birch.Birch.fit", + "unique_qname": "sklearn.cluster._birch.Birch.fit", "decorators": [], "parameters": [ { @@ -32129,7 +32396,9 @@ }, { "name": "fit_", + "unique_name": "fit_@getter", "qname": "sklearn.cluster._birch.Birch.fit_", + "unique_qname": "sklearn.cluster._birch.Birch.fit_@getter", "decorators": [ "deprecated('`fit_` is deprecated in 1.0 and will be removed in 1.2.')", "property" @@ -32154,7 +32423,9 @@ }, { "name": "partial_fit", + "unique_name": "partial_fit", "qname": "sklearn.cluster._birch.Birch.partial_fit", + "unique_qname": "sklearn.cluster._birch.Birch.partial_fit", "decorators": [], "parameters": [ { @@ -32196,7 +32467,9 @@ }, { "name": "partial_fit_", + "unique_name": "partial_fit_@getter", "qname": "sklearn.cluster._birch.Birch.partial_fit_", + "unique_qname": "sklearn.cluster._birch.Birch.partial_fit_@getter", "decorators": [ "deprecated('`partial_fit_` is deprecated in 1.0 and will be removed in 1.2.')", "property" @@ -32221,7 +32494,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.cluster._birch.Birch.predict", + "unique_qname": "sklearn.cluster._birch.Birch.predict", "decorators": [], "parameters": [ { @@ -32253,7 +32528,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.cluster._birch.Birch.transform", + "unique_qname": "sklearn.cluster._birch.Birch.transform", "decorators": [], "parameters": [ { @@ -32285,7 +32562,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.cluster._birch._CFNode.__init__", + "unique_qname": "sklearn.cluster._birch._CFNode.__init__", "decorators": [], "parameters": [ { @@ -32347,7 +32626,9 @@ }, { "name": "append_subcluster", + "unique_name": "append_subcluster", "qname": "sklearn.cluster._birch._CFNode.append_subcluster", + "unique_qname": "sklearn.cluster._birch._CFNode.append_subcluster", "decorators": [], "parameters": [ { @@ -32379,7 +32660,9 @@ }, { "name": "insert_cf_subcluster", + "unique_name": "insert_cf_subcluster", "qname": "sklearn.cluster._birch._CFNode.insert_cf_subcluster", + "unique_qname": "sklearn.cluster._birch._CFNode.insert_cf_subcluster", "decorators": [], "parameters": [ { @@ -32411,7 +32694,9 @@ }, { "name": "update_split_subclusters", + "unique_name": "update_split_subclusters", "qname": "sklearn.cluster._birch._CFNode.update_split_subclusters", + "unique_qname": "sklearn.cluster._birch._CFNode.update_split_subclusters", "decorators": [], "parameters": [ { @@ -32463,7 +32748,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.cluster._birch._CFSubcluster.__init__", + "unique_qname": "sklearn.cluster._birch._CFSubcluster.__init__", "decorators": [], "parameters": [ { @@ -32495,7 +32782,9 @@ }, { "name": "merge_subcluster", + "unique_name": "merge_subcluster", "qname": "sklearn.cluster._birch._CFSubcluster.merge_subcluster", + "unique_qname": "sklearn.cluster._birch._CFSubcluster.merge_subcluster", "decorators": [], "parameters": [ { @@ -32537,7 +32826,9 @@ }, { "name": "radius", + "unique_name": "radius@getter", "qname": "sklearn.cluster._birch._CFSubcluster.radius", + "unique_qname": "sklearn.cluster._birch._CFSubcluster.radius@getter", "decorators": ["property"], "parameters": [ { @@ -32559,7 +32850,9 @@ }, { "name": "update", + "unique_name": "update", "qname": "sklearn.cluster._birch._CFSubcluster.update", + "unique_qname": "sklearn.cluster._birch._CFSubcluster.update", "decorators": [], "parameters": [ { @@ -32591,7 +32884,9 @@ }, { "name": "_iterate_sparse_X", + "unique_name": "_iterate_sparse_X", "qname": "sklearn.cluster._birch._iterate_sparse_X", + "unique_qname": "sklearn.cluster._birch._iterate_sparse_X", "decorators": [], "parameters": [ { @@ -32613,7 +32908,9 @@ }, { "name": "_split_node", + "unique_name": "_split_node", "qname": "sklearn.cluster._birch._split_node", + "unique_qname": "sklearn.cluster._birch._split_node", "decorators": [], "parameters": [ { @@ -32655,7 +32952,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.cluster._dbscan.DBSCAN.__init__", + "unique_qname": "sklearn.cluster._dbscan.DBSCAN.__init__", "decorators": [], "parameters": [ { @@ -32757,7 +33056,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.cluster._dbscan.DBSCAN.fit", + "unique_qname": "sklearn.cluster._dbscan.DBSCAN.fit", "decorators": [], "parameters": [ { @@ -32809,7 +33110,9 @@ }, { "name": "fit_predict", + "unique_name": "fit_predict", "qname": "sklearn.cluster._dbscan.DBSCAN.fit_predict", + "unique_qname": "sklearn.cluster._dbscan.DBSCAN.fit_predict", "decorators": [], "parameters": [ { @@ -32861,7 +33164,9 @@ }, { "name": "dbscan", + "unique_name": "dbscan", "qname": "sklearn.cluster._dbscan.dbscan", + "unique_qname": "sklearn.cluster._dbscan.dbscan", "decorators": [], "parameters": [ { @@ -32973,7 +33278,9 @@ }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.cluster._feature_agglomeration.AgglomerationTransform.inverse_transform", + "unique_qname": "sklearn.cluster._feature_agglomeration.AgglomerationTransform.inverse_transform", "decorators": [], "parameters": [ { @@ -33005,7 +33312,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.cluster._feature_agglomeration.AgglomerationTransform.transform", + "unique_qname": "sklearn.cluster._feature_agglomeration.AgglomerationTransform.transform", "decorators": [], "parameters": [ { @@ -33037,7 +33346,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.cluster._kmeans.KMeans.__init__", + "unique_qname": "sklearn.cluster._kmeans.KMeans.__init__", "decorators": [], "parameters": [ { @@ -33149,7 +33460,9 @@ }, { "name": "_check_mkl_vcomp", + "unique_name": "_check_mkl_vcomp", "qname": "sklearn.cluster._kmeans.KMeans._check_mkl_vcomp", + "unique_qname": "sklearn.cluster._kmeans.KMeans._check_mkl_vcomp", "decorators": [], "parameters": [ { @@ -33191,7 +33504,9 @@ }, { "name": "_check_params", + "unique_name": "_check_params", "qname": "sklearn.cluster._kmeans.KMeans._check_params", + "unique_qname": "sklearn.cluster._kmeans.KMeans._check_params", "decorators": [], "parameters": [ { @@ -33223,7 +33538,9 @@ }, { "name": "_check_test_data", + "unique_name": "_check_test_data", "qname": "sklearn.cluster._kmeans.KMeans._check_test_data", + "unique_qname": "sklearn.cluster._kmeans.KMeans._check_test_data", "decorators": [], "parameters": [ { @@ -33255,7 +33572,9 @@ }, { "name": "_init_centroids", + "unique_name": "_init_centroids", "qname": "sklearn.cluster._kmeans.KMeans._init_centroids", + "unique_qname": "sklearn.cluster._kmeans.KMeans._init_centroids", "decorators": [], "parameters": [ { @@ -33327,7 +33646,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.cluster._kmeans.KMeans._more_tags", + "unique_qname": "sklearn.cluster._kmeans.KMeans._more_tags", "decorators": [], "parameters": [ { @@ -33349,7 +33670,9 @@ }, { "name": "_transform", + "unique_name": "_transform", "qname": "sklearn.cluster._kmeans.KMeans._transform", + "unique_qname": "sklearn.cluster._kmeans.KMeans._transform", "decorators": [], "parameters": [ { @@ -33381,7 +33704,9 @@ }, { "name": "_validate_center_shape", + "unique_name": "_validate_center_shape", "qname": "sklearn.cluster._kmeans.KMeans._validate_center_shape", + "unique_qname": "sklearn.cluster._kmeans.KMeans._validate_center_shape", "decorators": [], "parameters": [ { @@ -33423,7 +33748,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.cluster._kmeans.KMeans.fit", + "unique_qname": "sklearn.cluster._kmeans.KMeans.fit", "decorators": [], "parameters": [ { @@ -33470,12 +33797,14 @@ "results": [], "is_public": true, "description": "Compute k-means clustering.", - "docstring": "Compute k-means clustering.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training instances to cluster. It must be noted that the data\n will be converted to C ordering, which will cause a memory\n copy if the given data is not C-contiguous.\n If a sparse matrix is passed, a copy will be made if it's not in\n CSR format.\n\ny : Ignored\n Not used, present here for API consistency by convention.\n\nsample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n .. versionadded:: 0.20\n\nReturns\n-------\nself\n Fitted estimator.", - "source_code": "\ndef fit(self, X, y=None, sample_weight=None):\n \"\"\"Compute k-means clustering.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training instances to cluster. It must be noted that the data\n will be converted to C ordering, which will cause a memory\n copy if the given data is not C-contiguous.\n If a sparse matrix is passed, a copy will be made if it's not in\n CSR format.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n .. versionadded:: 0.20\n\n Returns\n -------\n self\n Fitted estimator.\n \"\"\"\n X = self._validate_data(X, accept_sparse='csr', dtype=[np.float64, np.float32], order='C', copy=self.copy_x, accept_large_sparse=False)\n self._check_params(X)\n random_state = check_random_state(self.random_state)\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n self._n_threads = _openmp_effective_n_threads()\n init = self.init\n if hasattr(init, '__array__'):\n init = check_array(init, dtype=X.dtype, copy=True, order='C')\n self._validate_center_shape(X, init)\n if not sp.issparse(X):\n X_mean = X.mean(axis=0)\n X -= X_mean\n if hasattr(init, '__array__'):\n init -= X_mean\n x_squared_norms = row_norms(X, squared=True)\n if self._algorithm == 'full':\n kmeans_single = _kmeans_single_lloyd\n self._check_mkl_vcomp(X, X.shape[0])\n else:\n kmeans_single = _kmeans_single_elkan\n best_inertia = None\n for i in range(self._n_init):\n centers_init = self._init_centroids(X, x_squared_norms=x_squared_norms, init=init, random_state=random_state)\n if self.verbose:\n print('Initialization complete')\n (labels, inertia, centers, n_iter_) = kmeans_single(X, sample_weight, centers_init, max_iter=self.max_iter, verbose=self.verbose, tol=self._tol, x_squared_norms=x_squared_norms, n_threads=self._n_threads)\n if best_inertia is None or inertia < best_inertia * (1 - 1e-06):\n best_labels = labels\n best_centers = centers\n best_inertia = inertia\n best_n_iter = n_iter_\n if not sp.issparse(X):\n if not self.copy_x:\n X += X_mean\n best_centers += X_mean\n distinct_clusters = len(set(best_labels))\n if distinct_clusters < self.n_clusters:\n warnings.warn('Number of distinct clusters ({}) found smaller than n_clusters ({}). Possibly due to duplicate points in X.'.format(distinct_clusters, self.n_clusters), ConvergenceWarning, stacklevel=2)\n self.cluster_centers_ = best_centers\n self.labels_ = best_labels\n self.inertia_ = best_inertia\n self.n_iter_ = best_n_iter\n return self" + "docstring": "Compute k-means clustering.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training instances to cluster. It must be noted that the data\n will be converted to C ordering, which will cause a memory\n copy if the given data is not C-contiguous.\n If a sparse matrix is passed, a copy will be made if it's not in\n CSR format.\n\ny : Ignored\n Not used, present here for API consistency by convention.\n\nsample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n .. versionadded:: 0.20\n\nReturns\n-------\nself : object\n Fitted estimator.", + "source_code": "\ndef fit(self, X, y=None, sample_weight=None):\n \"\"\"Compute k-means clustering.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training instances to cluster. It must be noted that the data\n will be converted to C ordering, which will cause a memory\n copy if the given data is not C-contiguous.\n If a sparse matrix is passed, a copy will be made if it's not in\n CSR format.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n .. versionadded:: 0.20\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n X = self._validate_data(X, accept_sparse='csr', dtype=[np.float64, np.float32], order='C', copy=self.copy_x, accept_large_sparse=False)\n self._check_params(X)\n random_state = check_random_state(self.random_state)\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n self._n_threads = _openmp_effective_n_threads()\n init = self.init\n if hasattr(init, '__array__'):\n init = check_array(init, dtype=X.dtype, copy=True, order='C')\n self._validate_center_shape(X, init)\n if not sp.issparse(X):\n X_mean = X.mean(axis=0)\n X -= X_mean\n if hasattr(init, '__array__'):\n init -= X_mean\n x_squared_norms = row_norms(X, squared=True)\n if self._algorithm == 'full':\n kmeans_single = _kmeans_single_lloyd\n self._check_mkl_vcomp(X, X.shape[0])\n else:\n kmeans_single = _kmeans_single_elkan\n (best_inertia, best_labels) = (None, None)\n for i in range(self._n_init):\n centers_init = self._init_centroids(X, x_squared_norms=x_squared_norms, init=init, random_state=random_state)\n if self.verbose:\n print('Initialization complete')\n (labels, inertia, centers, n_iter_) = kmeans_single(X, sample_weight, centers_init, max_iter=self.max_iter, verbose=self.verbose, tol=self._tol, x_squared_norms=x_squared_norms, n_threads=self._n_threads)\n if best_inertia is None or inertia < best_inertia and not _is_same_clustering(labels, best_labels, self.n_clusters):\n best_labels = labels\n best_centers = centers\n best_inertia = inertia\n best_n_iter = n_iter_\n if not sp.issparse(X):\n if not self.copy_x:\n X += X_mean\n best_centers += X_mean\n distinct_clusters = len(set(best_labels))\n if distinct_clusters < self.n_clusters:\n warnings.warn('Number of distinct clusters ({}) found smaller than n_clusters ({}). Possibly due to duplicate points in X.'.format(distinct_clusters, self.n_clusters), ConvergenceWarning, stacklevel=2)\n self.cluster_centers_ = best_centers\n self.labels_ = best_labels\n self.inertia_ = best_inertia\n self.n_iter_ = best_n_iter\n return self" }, { "name": "fit_predict", + "unique_name": "fit_predict", "qname": "sklearn.cluster._kmeans.KMeans.fit_predict", + "unique_qname": "sklearn.cluster._kmeans.KMeans.fit_predict", "decorators": [], "parameters": [ { @@ -33527,7 +33856,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.cluster._kmeans.KMeans.fit_transform", + "unique_qname": "sklearn.cluster._kmeans.KMeans.fit_transform", "decorators": [], "parameters": [ { @@ -33579,7 +33910,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.cluster._kmeans.KMeans.predict", + "unique_qname": "sklearn.cluster._kmeans.KMeans.predict", "decorators": [], "parameters": [ { @@ -33621,7 +33954,9 @@ }, { "name": "score", + "unique_name": "score", "qname": "sklearn.cluster._kmeans.KMeans.score", + "unique_qname": "sklearn.cluster._kmeans.KMeans.score", "decorators": [], "parameters": [ { @@ -33673,7 +34008,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.cluster._kmeans.KMeans.transform", + "unique_qname": "sklearn.cluster._kmeans.KMeans.transform", "decorators": [], "parameters": [ { @@ -33705,7 +34042,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.cluster._kmeans.MiniBatchKMeans.__init__", + "unique_qname": "sklearn.cluster._kmeans.MiniBatchKMeans.__init__", "decorators": [], "parameters": [ { @@ -33847,7 +34186,9 @@ }, { "name": "_check_params", + "unique_name": "_check_params", "qname": "sklearn.cluster._kmeans.MiniBatchKMeans._check_params", + "unique_qname": "sklearn.cluster._kmeans.MiniBatchKMeans._check_params", "decorators": [], "parameters": [ { @@ -33879,7 +34220,9 @@ }, { "name": "_mini_batch_convergence", + "unique_name": "_mini_batch_convergence", "qname": "sklearn.cluster._kmeans.MiniBatchKMeans._mini_batch_convergence", + "unique_qname": "sklearn.cluster._kmeans.MiniBatchKMeans._mini_batch_convergence", "decorators": [], "parameters": [ { @@ -33951,7 +34294,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.cluster._kmeans.MiniBatchKMeans._more_tags", + "unique_qname": "sklearn.cluster._kmeans.MiniBatchKMeans._more_tags", "decorators": [], "parameters": [ { @@ -33973,7 +34318,9 @@ }, { "name": "_random_reassign", + "unique_name": "_random_reassign", "qname": "sklearn.cluster._kmeans.MiniBatchKMeans._random_reassign", + "unique_qname": "sklearn.cluster._kmeans.MiniBatchKMeans._random_reassign", "decorators": [], "parameters": [ { @@ -33995,7 +34342,9 @@ }, { "name": "counts_", + "unique_name": "counts_@getter", "qname": "sklearn.cluster._kmeans.MiniBatchKMeans.counts_", + "unique_qname": "sklearn.cluster._kmeans.MiniBatchKMeans.counts_@getter", "decorators": [ "deprecated('The attribute `counts_` is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -34020,7 +34369,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.cluster._kmeans.MiniBatchKMeans.fit", + "unique_qname": "sklearn.cluster._kmeans.MiniBatchKMeans.fit", "decorators": [], "parameters": [ { @@ -34067,12 +34418,14 @@ "results": [], "is_public": true, "description": "Compute the centroids on X by chunking it into mini-batches.", - "docstring": "Compute the centroids on X by chunking it into mini-batches.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training instances to cluster. It must be noted that the data\n will be converted to C ordering, which will cause a memory copy\n if the given data is not C-contiguous.\n If a sparse matrix is passed, a copy will be made if it's not in\n CSR format.\n\ny : Ignored\n Not used, present here for API consistency by convention.\n\nsample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n .. versionadded:: 0.20\n\nReturns\n-------\nself", - "source_code": "\ndef fit(self, X, y=None, sample_weight=None):\n \"\"\"Compute the centroids on X by chunking it into mini-batches.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training instances to cluster. It must be noted that the data\n will be converted to C ordering, which will cause a memory copy\n if the given data is not C-contiguous.\n If a sparse matrix is passed, a copy will be made if it's not in\n CSR format.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n .. versionadded:: 0.20\n\n Returns\n -------\n self\n \"\"\"\n X = self._validate_data(X, accept_sparse='csr', dtype=[np.float64, np.float32], order='C', accept_large_sparse=False)\n self._check_params(X)\n random_state = check_random_state(self.random_state)\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n self._n_threads = _openmp_effective_n_threads()\n (n_samples, n_features) = X.shape\n init = self.init\n if hasattr(init, '__array__'):\n init = check_array(init, dtype=X.dtype, copy=True, order='C')\n self._validate_center_shape(X, init)\n self._check_mkl_vcomp(X, self._batch_size)\n x_squared_norms = row_norms(X, squared=True)\n validation_indices = random_state.randint(0, n_samples, self._init_size)\n X_valid = X[validation_indices]\n sample_weight_valid = sample_weight[validation_indices]\n x_squared_norms_valid = x_squared_norms[validation_indices]\n best_inertia = None\n for init_idx in range(self._n_init):\n if self.verbose:\n print(f'Init {init_idx + 1}/{self._n_init} with method {init}')\n cluster_centers = self._init_centroids(X, x_squared_norms=x_squared_norms, init=init, random_state=random_state, init_size=self._init_size)\n (_, inertia) = _labels_inertia_threadpool_limit(X_valid, sample_weight_valid, x_squared_norms_valid, cluster_centers, n_threads=self._n_threads)\n if self.verbose:\n print(f'Inertia for init {init_idx + 1}/{self._n_init}: {inertia}')\n if best_inertia is None or inertia < best_inertia:\n init_centers = cluster_centers\n best_inertia = inertia\n centers = init_centers\n centers_new = np.empty_like(centers)\n self._counts = np.zeros(self.n_clusters, dtype=X.dtype)\n self._ewa_inertia = None\n self._ewa_inertia_min = None\n self._no_improvement = 0\n self._n_since_last_reassign = 0\n n_steps = self.max_iter * n_samples // self._batch_size\n with threadpool_limits(limits=1, user_api='blas'):\n for i in range(n_steps):\n minibatch_indices = random_state.randint(0, n_samples, self._batch_size)\n batch_inertia = _mini_batch_step(X=X[minibatch_indices], x_squared_norms=x_squared_norms[minibatch_indices], sample_weight=sample_weight[minibatch_indices], centers=centers, centers_new=centers_new, weight_sums=self._counts, random_state=random_state, random_reassign=self._random_reassign(), reassignment_ratio=self.reassignment_ratio, verbose=self.verbose, n_threads=self._n_threads)\n if self._tol > 0.0:\n centers_squared_diff = np.sum((centers_new - centers)**2)\n else:\n centers_squared_diff = 0\n (centers, centers_new) = (centers_new, centers)\n if self._mini_batch_convergence(i, n_steps, n_samples, centers_squared_diff, batch_inertia):\n break\n self.cluster_centers_ = centers\n self.n_steps_ = i + 1\n self.n_iter_ = int(np.ceil((i + 1) * self._batch_size / n_samples))\n if self.compute_labels:\n (self.labels_, self.inertia_) = _labels_inertia_threadpool_limit(X, sample_weight, x_squared_norms, self.cluster_centers_, n_threads=self._n_threads)\n else:\n self.inertia_ = self._ewa_inertia * n_samples\n return self" + "docstring": "Compute the centroids on X by chunking it into mini-batches.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training instances to cluster. It must be noted that the data\n will be converted to C ordering, which will cause a memory copy\n if the given data is not C-contiguous.\n If a sparse matrix is passed, a copy will be made if it's not in\n CSR format.\n\ny : Ignored\n Not used, present here for API consistency by convention.\n\nsample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n .. versionadded:: 0.20\n\nReturns\n-------\nself : object\n Fitted estimator.", + "source_code": "\ndef fit(self, X, y=None, sample_weight=None):\n \"\"\"Compute the centroids on X by chunking it into mini-batches.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training instances to cluster. It must be noted that the data\n will be converted to C ordering, which will cause a memory copy\n if the given data is not C-contiguous.\n If a sparse matrix is passed, a copy will be made if it's not in\n CSR format.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n .. versionadded:: 0.20\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n X = self._validate_data(X, accept_sparse='csr', dtype=[np.float64, np.float32], order='C', accept_large_sparse=False)\n self._check_params(X)\n random_state = check_random_state(self.random_state)\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n self._n_threads = _openmp_effective_n_threads()\n (n_samples, n_features) = X.shape\n init = self.init\n if hasattr(init, '__array__'):\n init = check_array(init, dtype=X.dtype, copy=True, order='C')\n self._validate_center_shape(X, init)\n self._check_mkl_vcomp(X, self._batch_size)\n x_squared_norms = row_norms(X, squared=True)\n validation_indices = random_state.randint(0, n_samples, self._init_size)\n X_valid = X[validation_indices]\n sample_weight_valid = sample_weight[validation_indices]\n x_squared_norms_valid = x_squared_norms[validation_indices]\n best_inertia = None\n for init_idx in range(self._n_init):\n if self.verbose:\n print(f'Init {init_idx + 1}/{self._n_init} with method {init}')\n cluster_centers = self._init_centroids(X, x_squared_norms=x_squared_norms, init=init, random_state=random_state, init_size=self._init_size)\n (_, inertia) = _labels_inertia_threadpool_limit(X_valid, sample_weight_valid, x_squared_norms_valid, cluster_centers, n_threads=self._n_threads)\n if self.verbose:\n print(f'Inertia for init {init_idx + 1}/{self._n_init}: {inertia}')\n if best_inertia is None or inertia < best_inertia:\n init_centers = cluster_centers\n best_inertia = inertia\n centers = init_centers\n centers_new = np.empty_like(centers)\n self._counts = np.zeros(self.n_clusters, dtype=X.dtype)\n self._ewa_inertia = None\n self._ewa_inertia_min = None\n self._no_improvement = 0\n self._n_since_last_reassign = 0\n n_steps = self.max_iter * n_samples // self._batch_size\n with threadpool_limits(limits=1, user_api='blas'):\n for i in range(n_steps):\n minibatch_indices = random_state.randint(0, n_samples, self._batch_size)\n batch_inertia = _mini_batch_step(X=X[minibatch_indices], x_squared_norms=x_squared_norms[minibatch_indices], sample_weight=sample_weight[minibatch_indices], centers=centers, centers_new=centers_new, weight_sums=self._counts, random_state=random_state, random_reassign=self._random_reassign(), reassignment_ratio=self.reassignment_ratio, verbose=self.verbose, n_threads=self._n_threads)\n if self._tol > 0.0:\n centers_squared_diff = np.sum((centers_new - centers)**2)\n else:\n centers_squared_diff = 0\n (centers, centers_new) = (centers_new, centers)\n if self._mini_batch_convergence(i, n_steps, n_samples, centers_squared_diff, batch_inertia):\n break\n self.cluster_centers_ = centers\n self.n_steps_ = i + 1\n self.n_iter_ = int(np.ceil((i + 1) * self._batch_size / n_samples))\n if self.compute_labels:\n (self.labels_, self.inertia_) = _labels_inertia_threadpool_limit(X, sample_weight, x_squared_norms, self.cluster_centers_, n_threads=self._n_threads)\n else:\n self.inertia_ = self._ewa_inertia * n_samples\n return self" }, { "name": "init_size_", + "unique_name": "init_size_@getter", "qname": "sklearn.cluster._kmeans.MiniBatchKMeans.init_size_", + "unique_qname": "sklearn.cluster._kmeans.MiniBatchKMeans.init_size_@getter", "decorators": [ "deprecated('The attribute `init_size_` is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -34097,7 +34450,9 @@ }, { "name": "partial_fit", + "unique_name": "partial_fit", "qname": "sklearn.cluster._kmeans.MiniBatchKMeans.partial_fit", + "unique_qname": "sklearn.cluster._kmeans.MiniBatchKMeans.partial_fit", "decorators": [], "parameters": [ { @@ -34144,12 +34499,14 @@ "results": [], "is_public": true, "description": "Update k means estimate on a single mini-batch X.", - "docstring": "Update k means estimate on a single mini-batch X.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training instances to cluster. It must be noted that the data\n will be converted to C ordering, which will cause a memory copy\n if the given data is not C-contiguous.\n If a sparse matrix is passed, a copy will be made if it's not in\n CSR format.\n\ny : Ignored\n Not used, present here for API consistency by convention.\n\nsample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\nReturns\n-------\nself", - "source_code": "\ndef partial_fit(self, X, y=None, sample_weight=None):\n \"\"\"Update k means estimate on a single mini-batch X.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training instances to cluster. It must be noted that the data\n will be converted to C ordering, which will cause a memory copy\n if the given data is not C-contiguous.\n If a sparse matrix is passed, a copy will be made if it's not in\n CSR format.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n Returns\n -------\n self\n \"\"\"\n has_centers = hasattr(self, 'cluster_centers_')\n X = self._validate_data(X, accept_sparse='csr', dtype=[np.float64, np.float32], order='C', accept_large_sparse=False, reset=not has_centers)\n self._random_state = getattr(self, '_random_state', check_random_state(self.random_state))\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n self.n_steps_ = getattr(self, 'n_steps_', 0)\n x_squared_norms = row_norms(X, squared=True)\n if not has_centers:\n self._check_params(X)\n self._n_threads = _openmp_effective_n_threads()\n init = self.init\n if hasattr(init, '__array__'):\n init = check_array(init, dtype=X.dtype, copy=True, order='C')\n self._validate_center_shape(X, init)\n self._check_mkl_vcomp(X, X.shape[0])\n self.cluster_centers_ = self._init_centroids(X, x_squared_norms=x_squared_norms, init=init, random_state=self._random_state, init_size=self._init_size)\n self._counts = np.zeros(self.n_clusters, dtype=X.dtype)\n self._n_since_last_reassign = 0\n with threadpool_limits(limits=1, user_api='blas'):\n _mini_batch_step(X, x_squared_norms=x_squared_norms, sample_weight=sample_weight, centers=self.cluster_centers_, centers_new=self.cluster_centers_, weight_sums=self._counts, random_state=self._random_state, random_reassign=self._random_reassign(), reassignment_ratio=self.reassignment_ratio, verbose=self.verbose, n_threads=self._n_threads)\n if self.compute_labels:\n (self.labels_, self.inertia_) = _labels_inertia_threadpool_limit(X, sample_weight, x_squared_norms, self.cluster_centers_, n_threads=self._n_threads)\n self.n_steps_ += 1\n return self" + "docstring": "Update k means estimate on a single mini-batch X.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training instances to cluster. It must be noted that the data\n will be converted to C ordering, which will cause a memory copy\n if the given data is not C-contiguous.\n If a sparse matrix is passed, a copy will be made if it's not in\n CSR format.\n\ny : Ignored\n Not used, present here for API consistency by convention.\n\nsample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\nReturns\n-------\nself : object\n Return updated estimator.", + "source_code": "\ndef partial_fit(self, X, y=None, sample_weight=None):\n \"\"\"Update k means estimate on a single mini-batch X.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training instances to cluster. It must be noted that the data\n will be converted to C ordering, which will cause a memory copy\n if the given data is not C-contiguous.\n If a sparse matrix is passed, a copy will be made if it's not in\n CSR format.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n The weights for each observation in X. If None, all observations\n are assigned equal weight.\n\n Returns\n -------\n self : object\n Return updated estimator.\n \"\"\"\n has_centers = hasattr(self, 'cluster_centers_')\n X = self._validate_data(X, accept_sparse='csr', dtype=[np.float64, np.float32], order='C', accept_large_sparse=False, reset=not has_centers)\n self._random_state = getattr(self, '_random_state', check_random_state(self.random_state))\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n self.n_steps_ = getattr(self, 'n_steps_', 0)\n x_squared_norms = row_norms(X, squared=True)\n if not has_centers:\n self._check_params(X)\n self._n_threads = _openmp_effective_n_threads()\n init = self.init\n if hasattr(init, '__array__'):\n init = check_array(init, dtype=X.dtype, copy=True, order='C')\n self._validate_center_shape(X, init)\n self._check_mkl_vcomp(X, X.shape[0])\n self.cluster_centers_ = self._init_centroids(X, x_squared_norms=x_squared_norms, init=init, random_state=self._random_state, init_size=self._init_size)\n self._counts = np.zeros(self.n_clusters, dtype=X.dtype)\n self._n_since_last_reassign = 0\n with threadpool_limits(limits=1, user_api='blas'):\n _mini_batch_step(X, x_squared_norms=x_squared_norms, sample_weight=sample_weight, centers=self.cluster_centers_, centers_new=self.cluster_centers_, weight_sums=self._counts, random_state=self._random_state, random_reassign=self._random_reassign(), reassignment_ratio=self.reassignment_ratio, verbose=self.verbose, n_threads=self._n_threads)\n if self.compute_labels:\n (self.labels_, self.inertia_) = _labels_inertia_threadpool_limit(X, sample_weight, x_squared_norms, self.cluster_centers_, n_threads=self._n_threads)\n self.n_steps_ += 1\n return self" }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.cluster._kmeans.MiniBatchKMeans.predict", + "unique_qname": "sklearn.cluster._kmeans.MiniBatchKMeans.predict", "decorators": [], "parameters": [ { @@ -34191,7 +34548,9 @@ }, { "name": "random_state_", + "unique_name": "random_state_@getter", "qname": "sklearn.cluster._kmeans.MiniBatchKMeans.random_state_", + "unique_qname": "sklearn.cluster._kmeans.MiniBatchKMeans.random_state_@getter", "decorators": [ "deprecated('The attribute `random_state_` is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -34216,7 +34575,9 @@ }, { "name": "_kmeans_plusplus", + "unique_name": "_kmeans_plusplus", "qname": "sklearn.cluster._kmeans._kmeans_plusplus", + "unique_qname": "sklearn.cluster._kmeans._kmeans_plusplus", "decorators": [], "parameters": [ { @@ -34278,7 +34639,9 @@ }, { "name": "_kmeans_single_elkan", + "unique_name": "_kmeans_single_elkan", "qname": "sklearn.cluster._kmeans._kmeans_single_elkan", + "unique_qname": "sklearn.cluster._kmeans._kmeans_single_elkan", "decorators": [], "parameters": [ { @@ -34370,7 +34733,9 @@ }, { "name": "_kmeans_single_lloyd", + "unique_name": "_kmeans_single_lloyd", "qname": "sklearn.cluster._kmeans._kmeans_single_lloyd", + "unique_qname": "sklearn.cluster._kmeans._kmeans_single_lloyd", "decorators": [], "parameters": [ { @@ -34462,7 +34827,9 @@ }, { "name": "_labels_inertia", + "unique_name": "_labels_inertia", "qname": "sklearn.cluster._kmeans._labels_inertia", + "unique_qname": "sklearn.cluster._kmeans._labels_inertia", "decorators": [], "parameters": [ { @@ -34524,7 +34891,9 @@ }, { "name": "_labels_inertia_threadpool_limit", + "unique_name": "_labels_inertia_threadpool_limit", "qname": "sklearn.cluster._kmeans._labels_inertia_threadpool_limit", + "unique_qname": "sklearn.cluster._kmeans._labels_inertia_threadpool_limit", "decorators": [], "parameters": [ { @@ -34586,7 +34955,9 @@ }, { "name": "_mini_batch_step", + "unique_name": "_mini_batch_step", "qname": "sklearn.cluster._kmeans._mini_batch_step", + "unique_qname": "sklearn.cluster._kmeans._mini_batch_step", "decorators": [], "parameters": [ { @@ -34708,7 +35079,9 @@ }, { "name": "_tolerance", + "unique_name": "_tolerance", "qname": "sklearn.cluster._kmeans._tolerance", + "unique_qname": "sklearn.cluster._kmeans._tolerance", "decorators": [], "parameters": [ { @@ -34740,7 +35113,9 @@ }, { "name": "k_means", + "unique_name": "k_means", "qname": "sklearn.cluster._kmeans.k_means", + "unique_qname": "sklearn.cluster._kmeans.k_means", "decorators": [], "parameters": [ { @@ -34872,7 +35247,9 @@ }, { "name": "kmeans_plusplus", + "unique_name": "kmeans_plusplus", "qname": "sklearn.cluster._kmeans.kmeans_plusplus", + "unique_qname": "sklearn.cluster._kmeans.kmeans_plusplus", "decorators": [], "parameters": [ { @@ -34934,7 +35311,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.cluster._mean_shift.MeanShift.__init__", + "unique_qname": "sklearn.cluster._mean_shift.MeanShift.__init__", "decorators": [], "parameters": [ { @@ -35026,7 +35405,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.cluster._mean_shift.MeanShift.fit", + "unique_qname": "sklearn.cluster._mean_shift.MeanShift.fit", "decorators": [], "parameters": [ { @@ -35068,7 +35449,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.cluster._mean_shift.MeanShift.predict", + "unique_qname": "sklearn.cluster._mean_shift.MeanShift.predict", "decorators": [], "parameters": [ { @@ -35087,7 +35470,7 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "{array-like, sparse matrix} of shape (n_samples, n_features)", + "type": "array-like of shape (n_samples, n_features)", "description": "New data to predict." } } @@ -35095,12 +35478,14 @@ "results": [], "is_public": true, "description": "Predict the closest cluster each sample in X belongs to.", - "docstring": "Predict the closest cluster each sample in X belongs to.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n New data to predict.\n\nReturns\n-------\nlabels : ndarray of shape (n_samples,)\n Index of the cluster each sample belongs to.", - "source_code": "\ndef predict(self, X):\n \"\"\"Predict the closest cluster each sample in X belongs to.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n New data to predict.\n\n Returns\n -------\n labels : ndarray of shape (n_samples,)\n Index of the cluster each sample belongs to.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, reset=False)\n with config_context(assume_finite=True):\n return pairwise_distances_argmin(X, self.cluster_centers_)" + "docstring": "Predict the closest cluster each sample in X belongs to.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n New data to predict.\n\nReturns\n-------\nlabels : ndarray of shape (n_samples,)\n Index of the cluster each sample belongs to.", + "source_code": "\ndef predict(self, X):\n \"\"\"Predict the closest cluster each sample in X belongs to.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n New data to predict.\n\n Returns\n -------\n labels : ndarray of shape (n_samples,)\n Index of the cluster each sample belongs to.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, reset=False)\n with config_context(assume_finite=True):\n return pairwise_distances_argmin(X, self.cluster_centers_)" }, { "name": "_mean_shift_single_seed", + "unique_name": "_mean_shift_single_seed", "qname": "sklearn.cluster._mean_shift._mean_shift_single_seed", + "unique_qname": "sklearn.cluster._mean_shift._mean_shift_single_seed", "decorators": [], "parameters": [ { @@ -35152,7 +35537,9 @@ }, { "name": "estimate_bandwidth", + "unique_name": "estimate_bandwidth", "qname": "sklearn.cluster._mean_shift.estimate_bandwidth", + "unique_qname": "sklearn.cluster._mean_shift.estimate_bandwidth", "decorators": [], "parameters": [ { @@ -35214,7 +35601,9 @@ }, { "name": "get_bin_seeds", + "unique_name": "get_bin_seeds", "qname": "sklearn.cluster._mean_shift.get_bin_seeds", + "unique_qname": "sklearn.cluster._mean_shift.get_bin_seeds", "decorators": [], "parameters": [ { @@ -35256,7 +35645,9 @@ }, { "name": "mean_shift", + "unique_name": "mean_shift", "qname": "sklearn.cluster._mean_shift.mean_shift", + "unique_qname": "sklearn.cluster._mean_shift.mean_shift", "decorators": [], "parameters": [ { @@ -35348,7 +35739,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.cluster._optics.OPTICS.__init__", + "unique_qname": "sklearn.cluster._optics.OPTICS.__init__", "decorators": [], "parameters": [ { @@ -35510,7 +35903,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.cluster._optics.OPTICS.fit", + "unique_qname": "sklearn.cluster._optics.OPTICS.fit", "decorators": [], "parameters": [ { @@ -35552,7 +35947,9 @@ }, { "name": "_compute_core_distances_", + "unique_name": "_compute_core_distances_", "qname": "sklearn.cluster._optics._compute_core_distances_", + "unique_qname": "sklearn.cluster._optics._compute_core_distances_", "decorators": [], "parameters": [ { @@ -35604,7 +36001,9 @@ }, { "name": "_correct_predecessor", + "unique_name": "_correct_predecessor", "qname": "sklearn.cluster._optics._correct_predecessor", + "unique_qname": "sklearn.cluster._optics._correct_predecessor", "decorators": [], "parameters": [ { @@ -35666,7 +36065,9 @@ }, { "name": "_extend_region", + "unique_name": "_extend_region", "qname": "sklearn.cluster._optics._extend_region", + "unique_qname": "sklearn.cluster._optics._extend_region", "decorators": [], "parameters": [ { @@ -35718,7 +36119,9 @@ }, { "name": "_extract_xi_labels", + "unique_name": "_extract_xi_labels", "qname": "sklearn.cluster._optics._extract_xi_labels", + "unique_qname": "sklearn.cluster._optics._extract_xi_labels", "decorators": [], "parameters": [ { @@ -35750,7 +36153,9 @@ }, { "name": "_set_reach_dist", + "unique_name": "_set_reach_dist", "qname": "sklearn.cluster._optics._set_reach_dist", + "unique_qname": "sklearn.cluster._optics._set_reach_dist", "decorators": [], "parameters": [ { @@ -35872,7 +36277,9 @@ }, { "name": "_update_filter_sdas", + "unique_name": "_update_filter_sdas", "qname": "sklearn.cluster._optics._update_filter_sdas", + "unique_qname": "sklearn.cluster._optics._update_filter_sdas", "decorators": [], "parameters": [ { @@ -35924,7 +36331,9 @@ }, { "name": "_validate_size", + "unique_name": "_validate_size", "qname": "sklearn.cluster._optics._validate_size", + "unique_qname": "sklearn.cluster._optics._validate_size", "decorators": [], "parameters": [ { @@ -35966,7 +36375,9 @@ }, { "name": "_xi_cluster", + "unique_name": "_xi_cluster", "qname": "sklearn.cluster._optics._xi_cluster", + "unique_qname": "sklearn.cluster._optics._xi_cluster", "decorators": [], "parameters": [ { @@ -36048,7 +36459,9 @@ }, { "name": "cluster_optics_dbscan", + "unique_name": "cluster_optics_dbscan", "qname": "sklearn.cluster._optics.cluster_optics_dbscan", + "unique_qname": "sklearn.cluster._optics.cluster_optics_dbscan", "decorators": [], "parameters": [ { @@ -36100,7 +36513,9 @@ }, { "name": "cluster_optics_xi", + "unique_name": "cluster_optics_xi", "qname": "sklearn.cluster._optics.cluster_optics_xi", + "unique_qname": "sklearn.cluster._optics.cluster_optics_xi", "decorators": [], "parameters": [ { @@ -36182,7 +36597,9 @@ }, { "name": "compute_optics_graph", + "unique_name": "compute_optics_graph", "qname": "sklearn.cluster._optics.compute_optics_graph", + "unique_qname": "sklearn.cluster._optics.compute_optics_graph", "decorators": [], "parameters": [ { @@ -36284,7 +36701,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.cluster._spectral.SpectralClustering.__init__", + "unique_qname": "sklearn.cluster._spectral.SpectralClustering.__init__", "decorators": [], "parameters": [ { @@ -36314,7 +36733,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "{'arpack', 'lobpcg', 'amg'}, default=None", - "description": "The eigenvalue decomposition strategy to use. AMG requires pyamg\nto be installed. It can be faster on very large, sparse problems,\nbut may also lead to instabilities. If None, then ``'arpack'`` is\nused." + "description": "The eigenvalue decomposition strategy to use. AMG requires pyamg\nto be installed. It can be faster on very large, sparse problems,\nbut may also lead to instabilities. If None, then ``'arpack'`` is\nused. See [4]_ for more details regarding `'lobpcg'`." } }, { @@ -36324,7 +36743,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int, default=n_clusters", - "description": "Number of eigenvectors to use for the spectral embedding" + "description": "Number of eigenvectors to use for the spectral embedding." } }, { @@ -36394,7 +36813,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "{'kmeans', 'discretize'}, default='kmeans'", - "description": "The strategy for assigning labels in the embedding space. There are two\nways to assign labels after the Laplacian embedding. k-means is a\npopular choice, but it can be sensitive to initialization.\nDiscretization is another approach which is less sensitive to random\ninitialization." + "description": "The strategy for assigning labels in the embedding space. There are two\nways to assign labels after the Laplacian embedding. k-means is a\npopular choice, but it can be sensitive to initialization.\nDiscretization is another approach which is less sensitive to random\ninitialization [3]_." } }, { @@ -36456,7 +36875,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.cluster._spectral.SpectralClustering._more_tags", + "unique_qname": "sklearn.cluster._spectral.SpectralClustering._more_tags", "decorators": [], "parameters": [ { @@ -36478,7 +36899,9 @@ }, { "name": "_pairwise", + "unique_name": "_pairwise@getter", "qname": "sklearn.cluster._spectral.SpectralClustering._pairwise", + "unique_qname": "sklearn.cluster._spectral.SpectralClustering._pairwise@getter", "decorators": [ "deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -36503,7 +36926,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.cluster._spectral.SpectralClustering.fit", + "unique_qname": "sklearn.cluster._spectral.SpectralClustering.fit", "decorators": [], "parameters": [ { @@ -36540,12 +36965,14 @@ "results": [], "is_public": true, "description": "Perform spectral clustering from features, or affinity matrix.", - "docstring": "Perform spectral clustering from features, or affinity matrix.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples)\n Training instances to cluster, similarities / affinities between\n instances if ``affinity='precomputed'``, or distances between\n instances if ``affinity='precomputed_nearest_neighbors``. If a\n sparse matrix is provided in a format other than ``csr_matrix``,\n ``csc_matrix``, or ``coo_matrix``, it will be converted into a\n sparse ``csr_matrix``.\n\ny : Ignored\n Not used, present here for API consistency by convention.\n\nReturns\n-------\nself", - "source_code": "\ndef fit(self, X, y=None):\n \"\"\"Perform spectral clustering from features, or affinity matrix.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples)\n Training instances to cluster, similarities / affinities between\n instances if ``affinity='precomputed'``, or distances between\n instances if ``affinity='precomputed_nearest_neighbors``. If a\n sparse matrix is provided in a format other than ``csr_matrix``,\n ``csc_matrix``, or ``coo_matrix``, it will be converted into a\n sparse ``csr_matrix``.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self\n\n \"\"\"\n X = self._validate_data(X, accept_sparse=['csr', 'csc', 'coo'], dtype=np.float64, ensure_min_samples=2)\n allow_squared = self.affinity in ['precomputed', 'precomputed_nearest_neighbors']\n if X.shape[0] == X.shape[1] and not allow_squared:\n warnings.warn('The spectral clustering API has changed. ``fit``now constructs an affinity matrix from data. To use a custom affinity matrix, set ``affinity=precomputed``.')\n if self.affinity == 'nearest_neighbors':\n connectivity = kneighbors_graph(X, n_neighbors=self.n_neighbors, include_self=True, n_jobs=self.n_jobs)\n self.affinity_matrix_ = 0.5 * (connectivity + connectivity.T)\n elif self.affinity == 'precomputed_nearest_neighbors':\n estimator = NearestNeighbors(n_neighbors=self.n_neighbors, n_jobs=self.n_jobs, metric='precomputed').fit(X)\n connectivity = estimator.kneighbors_graph(X=X, mode='connectivity')\n self.affinity_matrix_ = 0.5 * (connectivity + connectivity.T)\n elif self.affinity == 'precomputed':\n self.affinity_matrix_ = X\n else:\n params = self.kernel_params\n if params is None:\n params = {}\n if not callable(self.affinity):\n params['gamma'] = self.gamma\n params['degree'] = self.degree\n params['coef0'] = self.coef0\n self.affinity_matrix_ = pairwise_kernels(X, metric=self.affinity, filter_params=True, **params)\n random_state = check_random_state(self.random_state)\n self.labels_ = spectral_clustering(self.affinity_matrix_, n_clusters=self.n_clusters, n_components=self.n_components, eigen_solver=self.eigen_solver, random_state=random_state, n_init=self.n_init, eigen_tol=self.eigen_tol, assign_labels=self.assign_labels, verbose=self.verbose)\n return self" + "docstring": "Perform spectral clustering from features, or affinity matrix.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples)\n Training instances to cluster, similarities / affinities between\n instances if ``affinity='precomputed'``, or distances between\n instances if ``affinity='precomputed_nearest_neighbors``. If a\n sparse matrix is provided in a format other than ``csr_matrix``,\n ``csc_matrix``, or ``coo_matrix``, it will be converted into a\n sparse ``csr_matrix``.\n\ny : Ignored\n Not used, present here for API consistency by convention.\n\nReturns\n-------\nself : object\n A fitted instance of the estimator.", + "source_code": "\ndef fit(self, X, y=None):\n \"\"\"Perform spectral clustering from features, or affinity matrix.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples)\n Training instances to cluster, similarities / affinities between\n instances if ``affinity='precomputed'``, or distances between\n instances if ``affinity='precomputed_nearest_neighbors``. If a\n sparse matrix is provided in a format other than ``csr_matrix``,\n ``csc_matrix``, or ``coo_matrix``, it will be converted into a\n sparse ``csr_matrix``.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self : object\n A fitted instance of the estimator.\n \"\"\"\n X = self._validate_data(X, accept_sparse=['csr', 'csc', 'coo'], dtype=np.float64, ensure_min_samples=2)\n allow_squared = self.affinity in ['precomputed', 'precomputed_nearest_neighbors']\n if X.shape[0] == X.shape[1] and not allow_squared:\n warnings.warn('The spectral clustering API has changed. ``fit``now constructs an affinity matrix from data. To use a custom affinity matrix, set ``affinity=precomputed``.')\n if self.affinity == 'nearest_neighbors':\n connectivity = kneighbors_graph(X, n_neighbors=self.n_neighbors, include_self=True, n_jobs=self.n_jobs)\n self.affinity_matrix_ = 0.5 * (connectivity + connectivity.T)\n elif self.affinity == 'precomputed_nearest_neighbors':\n estimator = NearestNeighbors(n_neighbors=self.n_neighbors, n_jobs=self.n_jobs, metric='precomputed').fit(X)\n connectivity = estimator.kneighbors_graph(X=X, mode='connectivity')\n self.affinity_matrix_ = 0.5 * (connectivity + connectivity.T)\n elif self.affinity == 'precomputed':\n self.affinity_matrix_ = X\n else:\n params = self.kernel_params\n if params is None:\n params = {}\n if not callable(self.affinity):\n params['gamma'] = self.gamma\n params['degree'] = self.degree\n params['coef0'] = self.coef0\n self.affinity_matrix_ = pairwise_kernels(X, metric=self.affinity, filter_params=True, **params)\n random_state = check_random_state(self.random_state)\n self.labels_ = spectral_clustering(self.affinity_matrix_, n_clusters=self.n_clusters, n_components=self.n_components, eigen_solver=self.eigen_solver, random_state=random_state, n_init=self.n_init, eigen_tol=self.eigen_tol, assign_labels=self.assign_labels, verbose=self.verbose)\n return self" }, { "name": "fit_predict", + "unique_name": "fit_predict", "qname": "sklearn.cluster._spectral.SpectralClustering.fit_predict", + "unique_qname": "sklearn.cluster._spectral.SpectralClustering.fit_predict", "decorators": [], "parameters": [ { @@ -36581,13 +37008,15 @@ ], "results": [], "is_public": true, - "description": "Perform spectral clustering from features, or affinity matrix, and return cluster labels.", - "docstring": "Perform spectral clustering from features, or affinity matrix,\nand return cluster labels.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples)\n Training instances to cluster, similarities / affinities between\n instances if ``affinity='precomputed'``, or distances between\n instances if ``affinity='precomputed_nearest_neighbors``. If a\n sparse matrix is provided in a format other than ``csr_matrix``,\n ``csc_matrix``, or ``coo_matrix``, it will be converted into a\n sparse ``csr_matrix``.\n\ny : Ignored\n Not used, present here for API consistency by convention.\n\nReturns\n-------\nlabels : ndarray of shape (n_samples,)\n Cluster labels.", - "source_code": "\ndef fit_predict(self, X, y=None):\n \"\"\"Perform spectral clustering from features, or affinity matrix,\n and return cluster labels.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples)\n Training instances to cluster, similarities / affinities between\n instances if ``affinity='precomputed'``, or distances between\n instances if ``affinity='precomputed_nearest_neighbors``. If a\n sparse matrix is provided in a format other than ``csr_matrix``,\n ``csc_matrix``, or ``coo_matrix``, it will be converted into a\n sparse ``csr_matrix``.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n labels : ndarray of shape (n_samples,)\n Cluster labels.\n \"\"\"\n return super().fit_predict(X, y)" + "description": "Perform spectral clustering on `X` and return cluster labels.", + "docstring": "Perform spectral clustering on `X` and return cluster labels.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples)\n Training instances to cluster, similarities / affinities between\n instances if ``affinity='precomputed'``, or distances between\n instances if ``affinity='precomputed_nearest_neighbors``. If a\n sparse matrix is provided in a format other than ``csr_matrix``,\n ``csc_matrix``, or ``coo_matrix``, it will be converted into a\n sparse ``csr_matrix``.\n\ny : Ignored\n Not used, present here for API consistency by convention.\n\nReturns\n-------\nlabels : ndarray of shape (n_samples,)\n Cluster labels.", + "source_code": "\ndef fit_predict(self, X, y=None):\n \"\"\"Perform spectral clustering on `X` and return cluster labels.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples)\n Training instances to cluster, similarities / affinities between\n instances if ``affinity='precomputed'``, or distances between\n instances if ``affinity='precomputed_nearest_neighbors``. If a\n sparse matrix is provided in a format other than ``csr_matrix``,\n ``csc_matrix``, or ``coo_matrix``, it will be converted into a\n sparse ``csr_matrix``.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n labels : ndarray of shape (n_samples,)\n Cluster labels.\n \"\"\"\n return super().fit_predict(X, y)" }, { "name": "discretize", + "unique_name": "discretize", "qname": "sklearn.cluster._spectral.discretize", + "unique_qname": "sklearn.cluster._spectral.discretize", "decorators": [], "parameters": [ { @@ -36643,13 +37072,15 @@ ], "results": [], "is_public": false, - "description": "Search for a partition matrix (clustering) which is closest to the eigenvector embedding.", - "docstring": "Search for a partition matrix (clustering) which is closest to the\neigenvector embedding.\n\nParameters\n----------\nvectors : array-like of shape (n_samples, n_clusters)\n The embedding space of the samples.\n\ncopy : bool, default=True\n Whether to copy vectors, or perform in-place normalization.\n\nmax_svd_restarts : int, default=30\n Maximum number of attempts to restart SVD if convergence fails\n\nn_iter_max : int, default=30\n Maximum number of iterations to attempt in rotation and partition\n matrix search if machine precision convergence is not reached\n\nrandom_state : int, RandomState instance, default=None\n Determines random number generation for rotation matrix initialization.\n Use an int to make the randomness deterministic.\n See :term:`Glossary `.\n\nReturns\n-------\nlabels : array of integers, shape: n_samples\n The labels of the clusters.\n\nReferences\n----------\n\n- Multiclass spectral clustering, 2003\n Stella X. Yu, Jianbo Shi\n https://www1.icsi.berkeley.edu/~stellayu/publication/doc/2003kwayICCV.pdf\n\nNotes\n-----\n\nThe eigenvector embedding is used to iteratively search for the\nclosest discrete partition. First, the eigenvector embedding is\nnormalized to the space of partition matrices. An optimal discrete\npartition matrix closest to this normalized embedding multiplied by\nan initial rotation is calculated. Fixing this discrete partition\nmatrix, an optimal rotation matrix is calculated. These two\ncalculations are performed until convergence. The discrete partition\nmatrix is returned as the clustering solution. Used in spectral\nclustering, this method tends to be faster and more robust to random\ninitialization than k-means.", - "source_code": "\ndef discretize(vectors, *, copy=True, max_svd_restarts=30, n_iter_max=20, random_state=None):\n \"\"\"Search for a partition matrix (clustering) which is closest to the\n eigenvector embedding.\n\n Parameters\n ----------\n vectors : array-like of shape (n_samples, n_clusters)\n The embedding space of the samples.\n\n copy : bool, default=True\n Whether to copy vectors, or perform in-place normalization.\n\n max_svd_restarts : int, default=30\n Maximum number of attempts to restart SVD if convergence fails\n\n n_iter_max : int, default=30\n Maximum number of iterations to attempt in rotation and partition\n matrix search if machine precision convergence is not reached\n\n random_state : int, RandomState instance, default=None\n Determines random number generation for rotation matrix initialization.\n Use an int to make the randomness deterministic.\n See :term:`Glossary `.\n\n Returns\n -------\n labels : array of integers, shape: n_samples\n The labels of the clusters.\n\n References\n ----------\n\n - Multiclass spectral clustering, 2003\n Stella X. Yu, Jianbo Shi\n https://www1.icsi.berkeley.edu/~stellayu/publication/doc/2003kwayICCV.pdf\n\n Notes\n -----\n\n The eigenvector embedding is used to iteratively search for the\n closest discrete partition. First, the eigenvector embedding is\n normalized to the space of partition matrices. An optimal discrete\n partition matrix closest to this normalized embedding multiplied by\n an initial rotation is calculated. Fixing this discrete partition\n matrix, an optimal rotation matrix is calculated. These two\n calculations are performed until convergence. The discrete partition\n matrix is returned as the clustering solution. Used in spectral\n clustering, this method tends to be faster and more robust to random\n initialization than k-means.\n\n \"\"\"\n from scipy.sparse import csc_matrix\n from scipy.linalg import LinAlgError\n random_state = check_random_state(random_state)\n vectors = as_float_array(vectors, copy=copy)\n eps = np.finfo(float).eps\n (n_samples, n_components) = vectors.shape\n norm_ones = np.sqrt(n_samples)\n for i in range(vectors.shape[1]):\n vectors[:, i] = vectors[:, i] / np.linalg.norm(vectors[:, i]) * norm_ones\n if vectors[0, i] != 0:\n vectors[:, i] = -1 * vectors[:, i] * np.sign(vectors[0, i])\n vectors = vectors / np.sqrt((vectors**2).sum(axis=1))[:, np.newaxis]\n svd_restarts = 0\n has_converged = False\n while svd_restarts < max_svd_restarts and not has_converged:\n rotation = np.zeros((n_components, n_components))\n rotation[:, 0] = vectors[random_state.randint(n_samples), :].T\n c = np.zeros(n_samples)\n for j in range(1, n_components):\n c += np.abs(np.dot(vectors, rotation[:, j - 1]))\n rotation[:, j] = vectors[c.argmin(), :].T\n last_objective_value = 0.0\n n_iter = 0\n while not has_converged:\n n_iter += 1\n t_discrete = np.dot(vectors, rotation)\n labels = t_discrete.argmax(axis=1)\n vectors_discrete = csc_matrix((np.ones(len(labels)), (np.arange(0, n_samples), labels)), shape=(n_samples, n_components))\n t_svd = vectors_discrete.T * vectors\n try:\n (U, S, Vh) = np.linalg.svd(t_svd)\n svd_restarts += 1\n except LinAlgError:\n print('SVD did not converge, randomizing and trying again')\n break\n ncut_value = 2.0 * (n_samples - S.sum())\n if abs(ncut_value - last_objective_value) < eps or n_iter > n_iter_max:\n has_converged = True\n else:\n last_objective_value = ncut_value\n rotation = np.dot(Vh.T, U.T)\n if not has_converged:\n raise LinAlgError('SVD did not converge')\n return labels" + "description": "Search for a partition matrix which is closest to the eigenvector embedding.\n\nThis implementation was proposed in [1]_.", + "docstring": "Search for a partition matrix which is closest to the eigenvector embedding.\n\nThis implementation was proposed in [1]_.\n\nParameters\n----------\nvectors : array-like of shape (n_samples, n_clusters)\n The embedding space of the samples.\n\ncopy : bool, default=True\n Whether to copy vectors, or perform in-place normalization.\n\nmax_svd_restarts : int, default=30\n Maximum number of attempts to restart SVD if convergence fails\n\nn_iter_max : int, default=30\n Maximum number of iterations to attempt in rotation and partition\n matrix search if machine precision convergence is not reached\n\nrandom_state : int, RandomState instance, default=None\n Determines random number generation for rotation matrix initialization.\n Use an int to make the randomness deterministic.\n See :term:`Glossary `.\n\nReturns\n-------\nlabels : array of integers, shape: n_samples\n The labels of the clusters.\n\nReferences\n----------\n\n.. [1] `Multiclass spectral clustering, 2003\n Stella X. Yu, Jianbo Shi\n `_\n\nNotes\n-----\n\nThe eigenvector embedding is used to iteratively search for the\nclosest discrete partition. First, the eigenvector embedding is\nnormalized to the space of partition matrices. An optimal discrete\npartition matrix closest to this normalized embedding multiplied by\nan initial rotation is calculated. Fixing this discrete partition\nmatrix, an optimal rotation matrix is calculated. These two\ncalculations are performed until convergence. The discrete partition\nmatrix is returned as the clustering solution. Used in spectral\nclustering, this method tends to be faster and more robust to random\ninitialization than k-means.", + "source_code": "\ndef discretize(vectors, *, copy=True, max_svd_restarts=30, n_iter_max=20, random_state=None):\n \"\"\"Search for a partition matrix which is closest to the eigenvector embedding.\n\n This implementation was proposed in [1]_.\n\n Parameters\n ----------\n vectors : array-like of shape (n_samples, n_clusters)\n The embedding space of the samples.\n\n copy : bool, default=True\n Whether to copy vectors, or perform in-place normalization.\n\n max_svd_restarts : int, default=30\n Maximum number of attempts to restart SVD if convergence fails\n\n n_iter_max : int, default=30\n Maximum number of iterations to attempt in rotation and partition\n matrix search if machine precision convergence is not reached\n\n random_state : int, RandomState instance, default=None\n Determines random number generation for rotation matrix initialization.\n Use an int to make the randomness deterministic.\n See :term:`Glossary `.\n\n Returns\n -------\n labels : array of integers, shape: n_samples\n The labels of the clusters.\n\n References\n ----------\n\n .. [1] `Multiclass spectral clustering, 2003\n Stella X. Yu, Jianbo Shi\n `_\n\n Notes\n -----\n\n The eigenvector embedding is used to iteratively search for the\n closest discrete partition. First, the eigenvector embedding is\n normalized to the space of partition matrices. An optimal discrete\n partition matrix closest to this normalized embedding multiplied by\n an initial rotation is calculated. Fixing this discrete partition\n matrix, an optimal rotation matrix is calculated. These two\n calculations are performed until convergence. The discrete partition\n matrix is returned as the clustering solution. Used in spectral\n clustering, this method tends to be faster and more robust to random\n initialization than k-means.\n\n \"\"\"\n from scipy.sparse import csc_matrix\n from scipy.linalg import LinAlgError\n random_state = check_random_state(random_state)\n vectors = as_float_array(vectors, copy=copy)\n eps = np.finfo(float).eps\n (n_samples, n_components) = vectors.shape\n norm_ones = np.sqrt(n_samples)\n for i in range(vectors.shape[1]):\n vectors[:, i] = vectors[:, i] / np.linalg.norm(vectors[:, i]) * norm_ones\n if vectors[0, i] != 0:\n vectors[:, i] = -1 * vectors[:, i] * np.sign(vectors[0, i])\n vectors = vectors / np.sqrt((vectors**2).sum(axis=1))[:, np.newaxis]\n svd_restarts = 0\n has_converged = False\n while svd_restarts < max_svd_restarts and not has_converged:\n rotation = np.zeros((n_components, n_components))\n rotation[:, 0] = vectors[random_state.randint(n_samples), :].T\n c = np.zeros(n_samples)\n for j in range(1, n_components):\n c += np.abs(np.dot(vectors, rotation[:, j - 1]))\n rotation[:, j] = vectors[c.argmin(), :].T\n last_objective_value = 0.0\n n_iter = 0\n while not has_converged:\n n_iter += 1\n t_discrete = np.dot(vectors, rotation)\n labels = t_discrete.argmax(axis=1)\n vectors_discrete = csc_matrix((np.ones(len(labels)), (np.arange(0, n_samples), labels)), shape=(n_samples, n_components))\n t_svd = vectors_discrete.T * vectors\n try:\n (U, S, Vh) = np.linalg.svd(t_svd)\n svd_restarts += 1\n except LinAlgError:\n print('SVD did not converge, randomizing and trying again')\n break\n ncut_value = 2.0 * (n_samples - S.sum())\n if abs(ncut_value - last_objective_value) < eps or n_iter > n_iter_max:\n has_converged = True\n else:\n last_objective_value = ncut_value\n rotation = np.dot(Vh.T, U.T)\n if not has_converged:\n raise LinAlgError('SVD did not converge')\n return labels" }, { "name": "spectral_clustering", + "unique_name": "spectral_clustering", "qname": "sklearn.cluster._spectral.spectral_clustering", + "unique_qname": "sklearn.cluster._spectral.spectral_clustering", "decorators": [], "parameters": [ { @@ -36689,7 +37120,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "{None, 'arpack', 'lobpcg', or 'amg'}", - "description": "The eigenvalue decomposition strategy to use. AMG requires pyamg\nto be installed. It can be faster on very large, sparse problems,\nbut may also lead to instabilities. If None, then ``'arpack'`` is\nused." + "description": "The eigenvalue decomposition strategy to use. AMG requires pyamg\nto be installed. It can be faster on very large, sparse problems,\nbut may also lead to instabilities. If None, then ``'arpack'`` is\nused. See [4]_ for more details regarding `'lobpcg'`." } }, { @@ -36729,7 +37160,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "{'kmeans', 'discretize'}, default='kmeans'", - "description": "The strategy to use to assign labels in the embedding\nspace. There are two ways to assign labels after the Laplacian\nembedding. k-means can be applied and is a popular choice. But it can\nalso be sensitive to initialization. Discretization is another\napproach which is less sensitive to random initialization. See\nthe 'Multiclass spectral clustering' paper referenced below for\nmore details on the discretization approach." + "description": "The strategy to use to assign labels in the embedding\nspace. There are two ways to assign labels after the Laplacian\nembedding. k-means can be applied and is a popular choice. But it can\nalso be sensitive to initialization. Discretization is another\napproach which is less sensitive to random initialization [3]_." } }, { @@ -36745,13 +37176,15 @@ ], "results": [], "is_public": true, - "description": "Apply clustering to a projection of the normalized Laplacian.\n\nIn practice Spectral Clustering is very useful when the structure of the individual clusters is highly non-convex or more generally when a measure of the center and spread of the cluster is not a suitable description of the complete cluster. For instance, when clusters are nested circles on the 2D plane. If affinity is the adjacency matrix of a graph, this method can be used to find normalized graph cuts. Read more in the :ref:`User Guide `.", - "docstring": "Apply clustering to a projection of the normalized Laplacian.\n\nIn practice Spectral Clustering is very useful when the structure of\nthe individual clusters is highly non-convex or more generally when\na measure of the center and spread of the cluster is not a suitable\ndescription of the complete cluster. For instance, when clusters are\nnested circles on the 2D plane.\n\nIf affinity is the adjacency matrix of a graph, this method can be\nused to find normalized graph cuts.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\naffinity : {array-like, sparse matrix} of shape (n_samples, n_samples)\n The affinity matrix describing the relationship of the samples to\n embed. **Must be symmetric**.\n\n Possible examples:\n - adjacency matrix of a graph,\n - heat kernel of the pairwise distance matrix of the samples,\n - symmetric k-nearest neighbours connectivity matrix of the samples.\n\nn_clusters : int, default=None\n Number of clusters to extract.\n\nn_components : int, default=n_clusters\n Number of eigenvectors to use for the spectral embedding\n\neigen_solver : {None, 'arpack', 'lobpcg', or 'amg'}\n The eigenvalue decomposition strategy to use. AMG requires pyamg\n to be installed. It can be faster on very large, sparse problems,\n but may also lead to instabilities. If None, then ``'arpack'`` is\n used.\n\nrandom_state : int, RandomState instance, default=None\n A pseudo random number generator used for the initialization\n of the lobpcg eigenvectors decomposition when `eigen_solver ==\n 'amg'`, and for the K-Means initialization. Use an int to make\n the results deterministic across calls (See\n :term:`Glossary `).\n\n .. note::\n When using `eigen_solver == 'amg'`,\n it is necessary to also fix the global numpy seed with\n `np.random.seed(int)` to get deterministic results. See\n https://github.com/pyamg/pyamg/issues/139 for further\n information.\n\nn_init : int, default=10\n Number of time the k-means algorithm will be run with different\n centroid seeds. The final results will be the best output of n_init\n consecutive runs in terms of inertia. Only used if\n ``assign_labels='kmeans'``.\n\neigen_tol : float, default=0.0\n Stopping criterion for eigendecomposition of the Laplacian matrix\n when using arpack eigen_solver.\n\nassign_labels : {'kmeans', 'discretize'}, default='kmeans'\n The strategy to use to assign labels in the embedding\n space. There are two ways to assign labels after the Laplacian\n embedding. k-means can be applied and is a popular choice. But it can\n also be sensitive to initialization. Discretization is another\n approach which is less sensitive to random initialization. See\n the 'Multiclass spectral clustering' paper referenced below for\n more details on the discretization approach.\n\nverbose : bool, default=False\n Verbosity mode.\n\n .. versionadded:: 0.24\n\nReturns\n-------\nlabels : array of integers, shape: n_samples\n The labels of the clusters.\n\nReferences\n----------\n\n- Normalized cuts and image segmentation, 2000\n Jianbo Shi, Jitendra Malik\n http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.160.2324\n\n- A Tutorial on Spectral Clustering, 2007\n Ulrike von Luxburg\n http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.165.9323\n\n- Multiclass spectral clustering, 2003\n Stella X. Yu, Jianbo Shi\n https://www1.icsi.berkeley.edu/~stellayu/publication/doc/2003kwayICCV.pdf\n\nNotes\n-----\nThe graph should contain only one connect component, elsewhere\nthe results make little sense.\n\nThis algorithm solves the normalized cut for k=2: it is a\nnormalized spectral clustering.", - "source_code": "\ndef spectral_clustering(affinity, *, n_clusters=8, n_components=None, eigen_solver=None, random_state=None, n_init=10, eigen_tol=0.0, assign_labels='kmeans', verbose=False):\n \"\"\"Apply clustering to a projection of the normalized Laplacian.\n\n In practice Spectral Clustering is very useful when the structure of\n the individual clusters is highly non-convex or more generally when\n a measure of the center and spread of the cluster is not a suitable\n description of the complete cluster. For instance, when clusters are\n nested circles on the 2D plane.\n\n If affinity is the adjacency matrix of a graph, this method can be\n used to find normalized graph cuts.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n affinity : {array-like, sparse matrix} of shape (n_samples, n_samples)\n The affinity matrix describing the relationship of the samples to\n embed. **Must be symmetric**.\n\n Possible examples:\n - adjacency matrix of a graph,\n - heat kernel of the pairwise distance matrix of the samples,\n - symmetric k-nearest neighbours connectivity matrix of the samples.\n\n n_clusters : int, default=None\n Number of clusters to extract.\n\n n_components : int, default=n_clusters\n Number of eigenvectors to use for the spectral embedding\n\n eigen_solver : {None, 'arpack', 'lobpcg', or 'amg'}\n The eigenvalue decomposition strategy to use. AMG requires pyamg\n to be installed. It can be faster on very large, sparse problems,\n but may also lead to instabilities. If None, then ``'arpack'`` is\n used.\n\n random_state : int, RandomState instance, default=None\n A pseudo random number generator used for the initialization\n of the lobpcg eigenvectors decomposition when `eigen_solver ==\n 'amg'`, and for the K-Means initialization. Use an int to make\n the results deterministic across calls (See\n :term:`Glossary `).\n\n .. note::\n When using `eigen_solver == 'amg'`,\n it is necessary to also fix the global numpy seed with\n `np.random.seed(int)` to get deterministic results. See\n https://github.com/pyamg/pyamg/issues/139 for further\n information.\n\n n_init : int, default=10\n Number of time the k-means algorithm will be run with different\n centroid seeds. The final results will be the best output of n_init\n consecutive runs in terms of inertia. Only used if\n ``assign_labels='kmeans'``.\n\n eigen_tol : float, default=0.0\n Stopping criterion for eigendecomposition of the Laplacian matrix\n when using arpack eigen_solver.\n\n assign_labels : {'kmeans', 'discretize'}, default='kmeans'\n The strategy to use to assign labels in the embedding\n space. There are two ways to assign labels after the Laplacian\n embedding. k-means can be applied and is a popular choice. But it can\n also be sensitive to initialization. Discretization is another\n approach which is less sensitive to random initialization. See\n the 'Multiclass spectral clustering' paper referenced below for\n more details on the discretization approach.\n\n verbose : bool, default=False\n Verbosity mode.\n\n .. versionadded:: 0.24\n\n Returns\n -------\n labels : array of integers, shape: n_samples\n The labels of the clusters.\n\n References\n ----------\n\n - Normalized cuts and image segmentation, 2000\n Jianbo Shi, Jitendra Malik\n http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.160.2324\n\n - A Tutorial on Spectral Clustering, 2007\n Ulrike von Luxburg\n http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.165.9323\n\n - Multiclass spectral clustering, 2003\n Stella X. Yu, Jianbo Shi\n https://www1.icsi.berkeley.edu/~stellayu/publication/doc/2003kwayICCV.pdf\n\n Notes\n -----\n The graph should contain only one connect component, elsewhere\n the results make little sense.\n\n This algorithm solves the normalized cut for k=2: it is a\n normalized spectral clustering.\n \"\"\"\n if assign_labels not in ('kmeans', 'discretize'):\n raise ValueError(\"The 'assign_labels' parameter should be 'kmeans' or 'discretize', but '%s' was given\" % assign_labels)\n if isinstance(affinity, np.matrix):\n raise TypeError('spectral_clustering does not support passing in affinity as an np.matrix. Please convert to a numpy array with np.asarray. For more information see: https://numpy.org/doc/stable/reference/generated/numpy.matrix.html')\n random_state = check_random_state(random_state)\n n_components = n_clusters if n_components is None else n_components\n maps = spectral_embedding(affinity, n_components=n_components, eigen_solver=eigen_solver, random_state=random_state, eigen_tol=eigen_tol, drop_first=False)\n if verbose:\n print(f'Computing label assignment using {assign_labels}')\n if assign_labels == 'kmeans':\n (_, labels, _) = k_means(maps, n_clusters, random_state=random_state, n_init=n_init, verbose=verbose)\n else:\n labels = discretize(maps, random_state=random_state)\n return labels" + "description": "Apply clustering to a projection of the normalized Laplacian.\n\nIn practice Spectral Clustering is very useful when the structure of the individual clusters is highly non-convex or more generally when a measure of the center and spread of the cluster is not a suitable description of the complete cluster. For instance, when clusters are nested circles on the 2D plane. If affinity is the adjacency matrix of a graph, this method can be used to find normalized graph cuts [1]_, [2]_. Read more in the :ref:`User Guide `.", + "docstring": "Apply clustering to a projection of the normalized Laplacian.\n\nIn practice Spectral Clustering is very useful when the structure of\nthe individual clusters is highly non-convex or more generally when\na measure of the center and spread of the cluster is not a suitable\ndescription of the complete cluster. For instance, when clusters are\nnested circles on the 2D plane.\n\nIf affinity is the adjacency matrix of a graph, this method can be\nused to find normalized graph cuts [1]_, [2]_.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\naffinity : {array-like, sparse matrix} of shape (n_samples, n_samples)\n The affinity matrix describing the relationship of the samples to\n embed. **Must be symmetric**.\n\n Possible examples:\n - adjacency matrix of a graph,\n - heat kernel of the pairwise distance matrix of the samples,\n - symmetric k-nearest neighbours connectivity matrix of the samples.\n\nn_clusters : int, default=None\n Number of clusters to extract.\n\nn_components : int, default=n_clusters\n Number of eigenvectors to use for the spectral embedding\n\neigen_solver : {None, 'arpack', 'lobpcg', or 'amg'}\n The eigenvalue decomposition strategy to use. AMG requires pyamg\n to be installed. It can be faster on very large, sparse problems,\n but may also lead to instabilities. If None, then ``'arpack'`` is\n used. See [4]_ for more details regarding `'lobpcg'`.\n\nrandom_state : int, RandomState instance, default=None\n A pseudo random number generator used for the initialization\n of the lobpcg eigenvectors decomposition when `eigen_solver ==\n 'amg'`, and for the K-Means initialization. Use an int to make\n the results deterministic across calls (See\n :term:`Glossary `).\n\n .. note::\n When using `eigen_solver == 'amg'`,\n it is necessary to also fix the global numpy seed with\n `np.random.seed(int)` to get deterministic results. See\n https://github.com/pyamg/pyamg/issues/139 for further\n information.\n\nn_init : int, default=10\n Number of time the k-means algorithm will be run with different\n centroid seeds. The final results will be the best output of n_init\n consecutive runs in terms of inertia. Only used if\n ``assign_labels='kmeans'``.\n\neigen_tol : float, default=0.0\n Stopping criterion for eigendecomposition of the Laplacian matrix\n when using arpack eigen_solver.\n\nassign_labels : {'kmeans', 'discretize'}, default='kmeans'\n The strategy to use to assign labels in the embedding\n space. There are two ways to assign labels after the Laplacian\n embedding. k-means can be applied and is a popular choice. But it can\n also be sensitive to initialization. Discretization is another\n approach which is less sensitive to random initialization [3]_.\n\nverbose : bool, default=False\n Verbosity mode.\n\n .. versionadded:: 0.24\n\nReturns\n-------\nlabels : array of integers, shape: n_samples\n The labels of the clusters.\n\nReferences\n----------\n\n.. [1] `Normalized cuts and image segmentation, 2000\n Jianbo Shi, Jitendra Malik\n `_\n\n.. [2] `A Tutorial on Spectral Clustering, 2007\n Ulrike von Luxburg\n `_\n\n.. [3] `Multiclass spectral clustering, 2003\n Stella X. Yu, Jianbo Shi\n `_\n\n.. [4] `Toward the Optimal Preconditioned Eigensolver:\n Locally Optimal Block Preconditioned Conjugate Gradient Method, 2001.\n A. V. Knyazev\n SIAM Journal on Scientific Computing 23, no. 2, pp. 517-541.\n `_\n\nNotes\n-----\nThe graph should contain only one connect component, elsewhere\nthe results make little sense.\n\nThis algorithm solves the normalized cut for k=2: it is a\nnormalized spectral clustering.", + "source_code": "\ndef spectral_clustering(affinity, *, n_clusters=8, n_components=None, eigen_solver=None, random_state=None, n_init=10, eigen_tol=0.0, assign_labels='kmeans', verbose=False):\n \"\"\"Apply clustering to a projection of the normalized Laplacian.\n\n In practice Spectral Clustering is very useful when the structure of\n the individual clusters is highly non-convex or more generally when\n a measure of the center and spread of the cluster is not a suitable\n description of the complete cluster. For instance, when clusters are\n nested circles on the 2D plane.\n\n If affinity is the adjacency matrix of a graph, this method can be\n used to find normalized graph cuts [1]_, [2]_.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n affinity : {array-like, sparse matrix} of shape (n_samples, n_samples)\n The affinity matrix describing the relationship of the samples to\n embed. **Must be symmetric**.\n\n Possible examples:\n - adjacency matrix of a graph,\n - heat kernel of the pairwise distance matrix of the samples,\n - symmetric k-nearest neighbours connectivity matrix of the samples.\n\n n_clusters : int, default=None\n Number of clusters to extract.\n\n n_components : int, default=n_clusters\n Number of eigenvectors to use for the spectral embedding\n\n eigen_solver : {None, 'arpack', 'lobpcg', or 'amg'}\n The eigenvalue decomposition strategy to use. AMG requires pyamg\n to be installed. It can be faster on very large, sparse problems,\n but may also lead to instabilities. If None, then ``'arpack'`` is\n used. See [4]_ for more details regarding `'lobpcg'`.\n\n random_state : int, RandomState instance, default=None\n A pseudo random number generator used for the initialization\n of the lobpcg eigenvectors decomposition when `eigen_solver ==\n 'amg'`, and for the K-Means initialization. Use an int to make\n the results deterministic across calls (See\n :term:`Glossary `).\n\n .. note::\n When using `eigen_solver == 'amg'`,\n it is necessary to also fix the global numpy seed with\n `np.random.seed(int)` to get deterministic results. See\n https://github.com/pyamg/pyamg/issues/139 for further\n information.\n\n n_init : int, default=10\n Number of time the k-means algorithm will be run with different\n centroid seeds. The final results will be the best output of n_init\n consecutive runs in terms of inertia. Only used if\n ``assign_labels='kmeans'``.\n\n eigen_tol : float, default=0.0\n Stopping criterion for eigendecomposition of the Laplacian matrix\n when using arpack eigen_solver.\n\n assign_labels : {'kmeans', 'discretize'}, default='kmeans'\n The strategy to use to assign labels in the embedding\n space. There are two ways to assign labels after the Laplacian\n embedding. k-means can be applied and is a popular choice. But it can\n also be sensitive to initialization. Discretization is another\n approach which is less sensitive to random initialization [3]_.\n\n verbose : bool, default=False\n Verbosity mode.\n\n .. versionadded:: 0.24\n\n Returns\n -------\n labels : array of integers, shape: n_samples\n The labels of the clusters.\n\n References\n ----------\n\n .. [1] `Normalized cuts and image segmentation, 2000\n Jianbo Shi, Jitendra Malik\n `_\n\n .. [2] `A Tutorial on Spectral Clustering, 2007\n Ulrike von Luxburg\n `_\n\n .. [3] `Multiclass spectral clustering, 2003\n Stella X. Yu, Jianbo Shi\n `_\n\n .. [4] `Toward the Optimal Preconditioned Eigensolver:\n Locally Optimal Block Preconditioned Conjugate Gradient Method, 2001.\n A. V. Knyazev\n SIAM Journal on Scientific Computing 23, no. 2, pp. 517-541.\n `_\n\n Notes\n -----\n The graph should contain only one connect component, elsewhere\n the results make little sense.\n\n This algorithm solves the normalized cut for k=2: it is a\n normalized spectral clustering.\n \"\"\"\n if assign_labels not in ('kmeans', 'discretize'):\n raise ValueError(\"The 'assign_labels' parameter should be 'kmeans' or 'discretize', but '%s' was given\" % assign_labels)\n if isinstance(affinity, np.matrix):\n raise TypeError('spectral_clustering does not support passing in affinity as an np.matrix. Please convert to a numpy array with np.asarray. For more information see: https://numpy.org/doc/stable/reference/generated/numpy.matrix.html')\n random_state = check_random_state(random_state)\n n_components = n_clusters if n_components is None else n_components\n maps = spectral_embedding(affinity, n_components=n_components, eigen_solver=eigen_solver, random_state=random_state, eigen_tol=eigen_tol, drop_first=False)\n if verbose:\n print(f'Computing label assignment using {assign_labels}')\n if assign_labels == 'kmeans':\n (_, labels, _) = k_means(maps, n_clusters, random_state=random_state, n_init=n_init, verbose=verbose)\n else:\n labels = discretize(maps, random_state=random_state)\n return labels" }, { "name": "configuration", + "unique_name": "configuration", "qname": "sklearn.cluster.setup.configuration", + "unique_qname": "sklearn.cluster.setup.configuration", "decorators": [], "parameters": [ { @@ -36783,7 +37216,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.compose._column_transformer.ColumnTransformer.__init__", + "unique_qname": "sklearn.compose._column_transformer.ColumnTransformer.__init__", "decorators": [], "parameters": [ { @@ -36875,7 +37310,9 @@ }, { "name": "_fit_transform", + "unique_name": "_fit_transform", "qname": "sklearn.compose._column_transformer.ColumnTransformer._fit_transform", + "unique_qname": "sklearn.compose._column_transformer.ColumnTransformer._fit_transform", "decorators": [], "parameters": [ { @@ -36947,7 +37384,9 @@ }, { "name": "_get_feature_name_out_for_transformer", + "unique_name": "_get_feature_name_out_for_transformer", "qname": "sklearn.compose._column_transformer.ColumnTransformer._get_feature_name_out_for_transformer", + "unique_qname": "sklearn.compose._column_transformer.ColumnTransformer._get_feature_name_out_for_transformer", "decorators": [], "parameters": [ { @@ -37009,7 +37448,9 @@ }, { "name": "_hstack", + "unique_name": "_hstack", "qname": "sklearn.compose._column_transformer.ColumnTransformer._hstack", + "unique_qname": "sklearn.compose._column_transformer.ColumnTransformer._hstack", "decorators": [], "parameters": [ { @@ -37041,7 +37482,9 @@ }, { "name": "_iter", + "unique_name": "_iter", "qname": "sklearn.compose._column_transformer.ColumnTransformer._iter", + "unique_qname": "sklearn.compose._column_transformer.ColumnTransformer._iter", "decorators": [], "parameters": [ { @@ -37093,7 +37536,9 @@ }, { "name": "_log_message", + "unique_name": "_log_message", "qname": "sklearn.compose._column_transformer.ColumnTransformer._log_message", + "unique_qname": "sklearn.compose._column_transformer.ColumnTransformer._log_message", "decorators": [], "parameters": [ { @@ -37145,7 +37590,9 @@ }, { "name": "_record_output_indices", + "unique_name": "_record_output_indices", "qname": "sklearn.compose._column_transformer.ColumnTransformer._record_output_indices", + "unique_qname": "sklearn.compose._column_transformer.ColumnTransformer._record_output_indices", "decorators": [], "parameters": [ { @@ -37177,7 +37624,9 @@ }, { "name": "_sk_visual_block_", + "unique_name": "_sk_visual_block_", "qname": "sklearn.compose._column_transformer.ColumnTransformer._sk_visual_block_", + "unique_qname": "sklearn.compose._column_transformer.ColumnTransformer._sk_visual_block_", "decorators": [], "parameters": [ { @@ -37199,7 +37648,33 @@ }, { "name": "_transformers", + "unique_name": "_transformers@getter", "qname": "sklearn.compose._column_transformer.ColumnTransformer._transformers", + "unique_qname": "sklearn.compose._column_transformer.ColumnTransformer._transformers@getter", + "decorators": ["property"], + "parameters": [ + { + "name": "self", + "default_value": null, + "is_public": false, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "", + "description": "" + } + } + ], + "results": [], + "is_public": false, + "description": "Internal list of transformer only containing the name and transformers, dropping the columns. This is for the implementation of get_params via BaseComposition._get_params which expects lists of tuples of len 2.", + "docstring": "Internal list of transformer only containing the name and\ntransformers, dropping the columns. This is for the implementation\nof get_params via BaseComposition._get_params which expects lists\nof tuples of len 2.", + "source_code": "\n@property\ndef _transformers(self):\n \"\"\"\n Internal list of transformer only containing the name and\n transformers, dropping the columns. This is for the implementation\n of get_params via BaseComposition._get_params which expects lists\n of tuples of len 2.\n \"\"\"\n return [(name, trans) for (name, trans, _) in self.transformers]" + }, + { + "name": "_transformers", + "unique_name": "_transformers@setter", + "qname": "sklearn.compose._column_transformer.ColumnTransformer._transformers", + "unique_qname": "sklearn.compose._column_transformer.ColumnTransformer._transformers@setter", "decorators": ["_transformers.setter"], "parameters": [ { @@ -37231,7 +37706,9 @@ }, { "name": "_update_fitted_transformers", + "unique_name": "_update_fitted_transformers", "qname": "sklearn.compose._column_transformer.ColumnTransformer._update_fitted_transformers", + "unique_qname": "sklearn.compose._column_transformer.ColumnTransformer._update_fitted_transformers", "decorators": [], "parameters": [ { @@ -37263,7 +37740,9 @@ }, { "name": "_validate_column_callables", + "unique_name": "_validate_column_callables", "qname": "sklearn.compose._column_transformer.ColumnTransformer._validate_column_callables", + "unique_qname": "sklearn.compose._column_transformer.ColumnTransformer._validate_column_callables", "decorators": [], "parameters": [ { @@ -37295,7 +37774,9 @@ }, { "name": "_validate_output", + "unique_name": "_validate_output", "qname": "sklearn.compose._column_transformer.ColumnTransformer._validate_output", + "unique_qname": "sklearn.compose._column_transformer.ColumnTransformer._validate_output", "decorators": [], "parameters": [ { @@ -37327,7 +37808,9 @@ }, { "name": "_validate_remainder", + "unique_name": "_validate_remainder", "qname": "sklearn.compose._column_transformer.ColumnTransformer._validate_remainder", + "unique_qname": "sklearn.compose._column_transformer.ColumnTransformer._validate_remainder", "decorators": [], "parameters": [ { @@ -37359,7 +37842,9 @@ }, { "name": "_validate_transformers", + "unique_name": "_validate_transformers", "qname": "sklearn.compose._column_transformer.ColumnTransformer._validate_transformers", + "unique_qname": "sklearn.compose._column_transformer.ColumnTransformer._validate_transformers", "decorators": [], "parameters": [ { @@ -37381,7 +37866,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.compose._column_transformer.ColumnTransformer.fit", + "unique_qname": "sklearn.compose._column_transformer.ColumnTransformer.fit", "decorators": [], "parameters": [ { @@ -37423,7 +37910,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.compose._column_transformer.ColumnTransformer.fit_transform", + "unique_qname": "sklearn.compose._column_transformer.ColumnTransformer.fit_transform", "decorators": [], "parameters": [ { @@ -37465,7 +37954,9 @@ }, { "name": "get_feature_names", + "unique_name": "get_feature_names", "qname": "sklearn.compose._column_transformer.ColumnTransformer.get_feature_names", + "unique_qname": "sklearn.compose._column_transformer.ColumnTransformer.get_feature_names", "decorators": [ "deprecated('get_feature_names is deprecated in 1.0 and will be removed in 1.2. Please use get_feature_names_out instead.')" ], @@ -37489,7 +37980,9 @@ }, { "name": "get_feature_names_out", + "unique_name": "get_feature_names_out", "qname": "sklearn.compose._column_transformer.ColumnTransformer.get_feature_names_out", + "unique_qname": "sklearn.compose._column_transformer.ColumnTransformer.get_feature_names_out", "decorators": [], "parameters": [ { @@ -37521,7 +38014,9 @@ }, { "name": "get_params", + "unique_name": "get_params", "qname": "sklearn.compose._column_transformer.ColumnTransformer.get_params", + "unique_qname": "sklearn.compose._column_transformer.ColumnTransformer.get_params", "decorators": [], "parameters": [ { @@ -37553,7 +38048,9 @@ }, { "name": "named_transformers_", + "unique_name": "named_transformers_@getter", "qname": "sklearn.compose._column_transformer.ColumnTransformer.named_transformers_", + "unique_qname": "sklearn.compose._column_transformer.ColumnTransformer.named_transformers_@getter", "decorators": ["property"], "parameters": [ { @@ -37575,7 +38072,9 @@ }, { "name": "set_params", + "unique_name": "set_params", "qname": "sklearn.compose._column_transformer.ColumnTransformer.set_params", + "unique_qname": "sklearn.compose._column_transformer.ColumnTransformer.set_params", "decorators": [], "parameters": [ { @@ -37597,7 +38096,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.compose._column_transformer.ColumnTransformer.transform", + "unique_qname": "sklearn.compose._column_transformer.ColumnTransformer.transform", "decorators": [], "parameters": [ { @@ -37629,7 +38130,9 @@ }, { "name": "_check_X", + "unique_name": "_check_X", "qname": "sklearn.compose._column_transformer._check_X", + "unique_qname": "sklearn.compose._column_transformer._check_X", "decorators": [], "parameters": [ { @@ -37651,7 +38154,9 @@ }, { "name": "_get_transformer_list", + "unique_name": "_get_transformer_list", "qname": "sklearn.compose._column_transformer._get_transformer_list", + "unique_qname": "sklearn.compose._column_transformer._get_transformer_list", "decorators": [], "parameters": [ { @@ -37673,7 +38178,9 @@ }, { "name": "_is_empty_column_selection", + "unique_name": "_is_empty_column_selection", "qname": "sklearn.compose._column_transformer._is_empty_column_selection", + "unique_qname": "sklearn.compose._column_transformer._is_empty_column_selection", "decorators": [], "parameters": [ { @@ -37695,7 +38202,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.compose._column_transformer.make_column_selector.__call__", + "unique_qname": "sklearn.compose._column_transformer.make_column_selector.__call__", "decorators": [], "parameters": [ { @@ -37727,7 +38236,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.compose._column_transformer.make_column_selector.__init__", + "unique_qname": "sklearn.compose._column_transformer.make_column_selector.__init__", "decorators": [], "parameters": [ { @@ -37779,7 +38290,9 @@ }, { "name": "make_column_transformer", + "unique_name": "make_column_transformer", "qname": "sklearn.compose._column_transformer.make_column_transformer", + "unique_qname": "sklearn.compose._column_transformer.make_column_transformer", "decorators": [], "parameters": [ { @@ -37841,7 +38354,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.compose._target.TransformedTargetRegressor.__init__", + "unique_qname": "sklearn.compose._target.TransformedTargetRegressor.__init__", "decorators": [], "parameters": [ { @@ -37861,7 +38376,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "object, default=None", - "description": "Regressor object such as derived from ``RegressorMixin``. This\nregressor will automatically be cloned each time prior to fitting.\nIf regressor is ``None``, ``LinearRegression()`` is created and used." + "description": "Regressor object such as derived from\n:class:`~sklearn.base.RegressorMixin`. This regressor will\nautomatically be cloned each time prior to fitting. If `regressor is\nNone`, :class:`~sklearn.linear_model.LinearRegression` is created and used." } }, { @@ -37871,7 +38386,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "object, default=None", - "description": "Estimator object such as derived from ``TransformerMixin``. Cannot be\nset at the same time as ``func`` and ``inverse_func``. If\n``transformer`` is ``None`` as well as ``func`` and ``inverse_func``,\nthe transformer will be an identity transformer. Note that the\ntransformer will be cloned during fitting. Also, the transformer is\nrestricting ``y`` to be a numpy array." + "description": "Estimator object such as derived from\n:class:`~sklearn.base.TransformerMixin`. Cannot be set at the same time\nas `func` and `inverse_func`. If `transformer is None` as well as\n`func` and `inverse_func`, the transformer will be an identity\ntransformer. Note that the transformer will be cloned during fitting.\nAlso, the transformer is restricting `y` to be a numpy array." } }, { @@ -37881,7 +38396,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "function, default=None", - "description": "Function to apply to ``y`` before passing to ``fit``. Cannot be set at\nthe same time as ``transformer``. The function needs to return a\n2-dimensional array. If ``func`` is ``None``, the function used will be\nthe identity function." + "description": "Function to apply to `y` before passing to :meth:`fit`. Cannot be set\nat the same time as `transformer`. The function needs to return a\n2-dimensional array. If `func is None`, the function used will be the\nidentity function." } }, { @@ -37891,7 +38406,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "function, default=None", - "description": "Function to apply to the prediction of the regressor. Cannot be set at\nthe same time as ``transformer`` as well. The function needs to return\na 2-dimensional array. The inverse function is used to return\npredictions to the same space of the original training labels." + "description": "Function to apply to the prediction of the regressor. Cannot be set at\nthe same time as `transformer`. The function needs to return a\n2-dimensional array. The inverse function is used to return\npredictions to the same space of the original training labels." } }, { @@ -37901,7 +38416,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "bool, default=True", - "description": "Whether to check that ``transform`` followed by ``inverse_transform``\nor ``func`` followed by ``inverse_func`` leads to the original targets." + "description": "Whether to check that `transform` followed by `inverse_transform`\nor `func` followed by `inverse_func` leads to the original targets." } } ], @@ -37913,7 +38428,9 @@ }, { "name": "_fit_transformer", + "unique_name": "_fit_transformer", "qname": "sklearn.compose._target.TransformedTargetRegressor._fit_transformer", + "unique_qname": "sklearn.compose._target.TransformedTargetRegressor._fit_transformer", "decorators": [], "parameters": [ { @@ -37945,7 +38462,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.compose._target.TransformedTargetRegressor._more_tags", + "unique_qname": "sklearn.compose._target.TransformedTargetRegressor._more_tags", "decorators": [], "parameters": [ { @@ -37967,7 +38486,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.compose._target.TransformedTargetRegressor.fit", + "unique_qname": "sklearn.compose._target.TransformedTargetRegressor.fit", "decorators": [], "parameters": [ { @@ -38004,12 +38525,14 @@ "results": [], "is_public": true, "description": "Fit the model according to the given training data.", - "docstring": "Fit the model according to the given training data.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\ny : array-like of shape (n_samples,)\n Target values.\n\n**fit_params : dict\n Parameters passed to the ``fit`` method of the underlying\n regressor.\n\n\nReturns\n-------\nself : object", - "source_code": "\ndef fit(self, X, y, **fit_params):\n \"\"\"Fit the model according to the given training data.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target values.\n\n **fit_params : dict\n Parameters passed to the ``fit`` method of the underlying\n regressor.\n\n\n Returns\n -------\n self : object\n \"\"\"\n y = check_array(y, accept_sparse=False, force_all_finite=True, ensure_2d=False, dtype='numeric', allow_nd=True)\n self._training_dim = y.ndim\n if y.ndim == 1:\n y_2d = y.reshape(-1, 1)\n else:\n y_2d = y\n self._fit_transformer(y_2d)\n y_trans = self.transformer_.transform(y_2d)\n if y_trans.ndim == 2 and y_trans.shape[1] == 1:\n y_trans = y_trans.squeeze(axis=1)\n if self.regressor is None:\n from ..linear_model import LinearRegression\n self.regressor_ = LinearRegression()\n else:\n self.regressor_ = clone(self.regressor)\n self.regressor_.fit(X, y_trans, **fit_params)\n if hasattr(self.regressor_, 'feature_names_in_'):\n self.feature_names_in_ = self.regressor_.feature_names_in_\n return self" + "docstring": "Fit the model according to the given training data.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\ny : array-like of shape (n_samples,)\n Target values.\n\n**fit_params : dict\n Parameters passed to the `fit` method of the underlying\n regressor.\n\nReturns\n-------\nself : object\n Fitted estimator.", + "source_code": "\ndef fit(self, X, y, **fit_params):\n \"\"\"Fit the model according to the given training data.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target values.\n\n **fit_params : dict\n Parameters passed to the `fit` method of the underlying\n regressor.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n y = check_array(y, accept_sparse=False, force_all_finite=True, ensure_2d=False, dtype='numeric', allow_nd=True)\n self._training_dim = y.ndim\n if y.ndim == 1:\n y_2d = y.reshape(-1, 1)\n else:\n y_2d = y\n self._fit_transformer(y_2d)\n y_trans = self.transformer_.transform(y_2d)\n if y_trans.ndim == 2 and y_trans.shape[1] == 1:\n y_trans = y_trans.squeeze(axis=1)\n if self.regressor is None:\n from ..linear_model import LinearRegression\n self.regressor_ = LinearRegression()\n else:\n self.regressor_ = clone(self.regressor)\n self.regressor_.fit(X, y_trans, **fit_params)\n if hasattr(self.regressor_, 'feature_names_in_'):\n self.feature_names_in_ = self.regressor_.feature_names_in_\n return self" }, { "name": "n_features_in_", + "unique_name": "n_features_in_@getter", "qname": "sklearn.compose._target.TransformedTargetRegressor.n_features_in_", + "unique_qname": "sklearn.compose._target.TransformedTargetRegressor.n_features_in_@getter", "decorators": ["property"], "parameters": [ { @@ -38025,13 +38548,15 @@ ], "results": [], "is_public": true, - "description": "", - "docstring": "", - "source_code": "\n@property\ndef n_features_in_(self):\n try:\n check_is_fitted(self)\n except NotFittedError as nfe:\n raise AttributeError('{} object has no n_features_in_ attribute.'.format(self.__class__.__name__)) from nfe\n return self.regressor_.n_features_in_" + "description": "Number of features seen during :term:`fit`.", + "docstring": "Number of features seen during :term:`fit`.", + "source_code": "\n@property\ndef n_features_in_(self):\n \"\"\"Number of features seen during :term:`fit`.\"\"\"\n try:\n check_is_fitted(self)\n except NotFittedError as nfe:\n raise AttributeError('{} object has no n_features_in_ attribute.'.format(self.__class__.__name__)) from nfe\n return self.regressor_.n_features_in_" }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.compose._target.TransformedTargetRegressor.predict", + "unique_qname": "sklearn.compose._target.TransformedTargetRegressor.predict", "decorators": [], "parameters": [ { @@ -38057,13 +38582,15 @@ ], "results": [], "is_public": true, - "description": "Predict using the base regressor, applying inverse.\n\nThe regressor is used to predict and the ``inverse_func`` or ``inverse_transform`` is applied before returning the prediction.", - "docstring": "Predict using the base regressor, applying inverse.\n\nThe regressor is used to predict and the ``inverse_func`` or\n``inverse_transform`` is applied before returning the prediction.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Samples.\n\n**predict_params : dict of str -> object\n Parameters passed to the `predict` method of the underlying\n regressor.\n\nReturns\n-------\ny_hat : ndarray of shape (n_samples,)\n Predicted values.", - "source_code": "\ndef predict(self, X, **predict_params):\n \"\"\"Predict using the base regressor, applying inverse.\n\n The regressor is used to predict and the ``inverse_func`` or\n ``inverse_transform`` is applied before returning the prediction.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Samples.\n\n **predict_params : dict of str -> object\n Parameters passed to the `predict` method of the underlying\n regressor.\n\n Returns\n -------\n y_hat : ndarray of shape (n_samples,)\n Predicted values.\n\n \"\"\"\n check_is_fitted(self)\n pred = self.regressor_.predict(X, **predict_params)\n if pred.ndim == 1:\n pred_trans = self.transformer_.inverse_transform(pred.reshape(-1, 1))\n else:\n pred_trans = self.transformer_.inverse_transform(pred)\n if self._training_dim == 1 and pred_trans.ndim == 2 and pred_trans.shape[1] == 1:\n pred_trans = pred_trans.squeeze(axis=1)\n return pred_trans" + "description": "Predict using the base regressor, applying inverse.\n\nThe regressor is used to predict and the `inverse_func` or `inverse_transform` is applied before returning the prediction.", + "docstring": "Predict using the base regressor, applying inverse.\n\nThe regressor is used to predict and the `inverse_func` or\n`inverse_transform` is applied before returning the prediction.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Samples.\n\n**predict_params : dict of str -> object\n Parameters passed to the `predict` method of the underlying\n regressor.\n\nReturns\n-------\ny_hat : ndarray of shape (n_samples,)\n Predicted values.", + "source_code": "\ndef predict(self, X, **predict_params):\n \"\"\"Predict using the base regressor, applying inverse.\n\n The regressor is used to predict and the `inverse_func` or\n `inverse_transform` is applied before returning the prediction.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Samples.\n\n **predict_params : dict of str -> object\n Parameters passed to the `predict` method of the underlying\n regressor.\n\n Returns\n -------\n y_hat : ndarray of shape (n_samples,)\n Predicted values.\n \"\"\"\n check_is_fitted(self)\n pred = self.regressor_.predict(X, **predict_params)\n if pred.ndim == 1:\n pred_trans = self.transformer_.inverse_transform(pred.reshape(-1, 1))\n else:\n pred_trans = self.transformer_.inverse_transform(pred)\n if self._training_dim == 1 and pred_trans.ndim == 2 and pred_trans.shape[1] == 1:\n pred_trans = pred_trans.squeeze(axis=1)\n return pred_trans" }, { "name": "_fetch_fixture", + "unique_name": "_fetch_fixture", "qname": "sklearn.conftest._fetch_fixture", + "unique_qname": "sklearn.conftest._fetch_fixture", "decorators": [], "parameters": [ { @@ -38085,7 +38612,9 @@ }, { "name": "pyplot", + "unique_name": "pyplot", "qname": "sklearn.conftest.pyplot", + "unique_qname": "sklearn.conftest.pyplot", "decorators": ["pytest.fixture(scope='function')"], "parameters": [], "results": [], @@ -38096,7 +38625,9 @@ }, { "name": "pytest_collection_modifyitems", + "unique_name": "pytest_collection_modifyitems", "qname": "sklearn.conftest.pytest_collection_modifyitems", + "unique_qname": "sklearn.conftest.pytest_collection_modifyitems", "decorators": [], "parameters": [ { @@ -38124,11 +38655,13 @@ "is_public": true, "description": "Called after collect is completed.", "docstring": "Called after collect is completed.\n\nParameters\n----------\nconfig : pytest config\nitems : list of collected items", - "source_code": "\ndef pytest_collection_modifyitems(config, items):\n \"\"\"Called after collect is completed.\n\n Parameters\n ----------\n config : pytest config\n items : list of collected items\n \"\"\"\n run_network_tests = environ.get('SKLEARN_SKIP_NETWORK_TESTS', '1') == '0'\n skip_network = pytest.mark.skip(reason='test is enabled when SKLEARN_SKIP_NETWORK_TESTS=0')\n dataset_features_set = set(dataset_fetchers)\n datasets_to_download = set()\n for item in items:\n if not hasattr(item, 'fixturenames'):\n continue\n item_fixtures = set(item.fixturenames)\n dataset_to_fetch = item_fixtures & dataset_features_set\n if not dataset_to_fetch:\n continue\n if run_network_tests:\n datasets_to_download |= dataset_to_fetch\n else:\n item.add_marker(skip_network)\n worker_id = environ.get('PYTEST_XDIST_WORKER', 'gw0')\n if worker_id == 'gw0' and run_network_tests:\n for name in datasets_to_download:\n dataset_fetchers[name]()\n for item in items:\n if item.name.endswith(('_hash.FeatureHasher', 'text.HashingVectorizer')) and platform.python_implementation() == 'PyPy':\n marker = pytest.mark.skip(reason='FeatureHasher is not compatible with PyPy')\n item.add_marker(marker)\n elif item.name.endswith('GradientBoostingClassifier') and platform.machine() == 'aarch64':\n marker = pytest.mark.xfail(reason='know failure. See https://github.com/scikit-learn/scikit-learn/issues/17797')\n item.add_marker(marker)\n skip_doctests = False\n try:\n import matplotlib\n except ImportError:\n skip_doctests = True\n reason = 'matplotlib is required to run the doctests'\n try:\n if np_version < parse_version('1.14'):\n reason = 'doctests are only run for numpy >= 1.14'\n skip_doctests = True\n elif _IS_32BIT:\n reason = 'doctest are only run when the default numpy int is 64 bits.'\n skip_doctests = True\n elif sys.platform.startswith('win32'):\n reason = 'doctests are not run for Windows because numpy arrays repr is inconsistent across platforms.'\n skip_doctests = True\n except ImportError:\n pass\n if skip_doctests:\n skip_marker = pytest.mark.skip(reason=reason)\n for item in items:\n if isinstance(item, DoctestItem):\n if item.name != 'sklearn._config.config_context':\n item.add_marker(skip_marker)\n elif not _pilutil.pillow_installed:\n skip_marker = pytest.mark.skip(reason='pillow (or PIL) not installed!')\n for item in items:\n if item.name in ['sklearn.feature_extraction.image.PatchExtractor', 'sklearn.feature_extraction.image.extract_patches_2d']:\n item.add_marker(skip_marker)" + "source_code": "\ndef pytest_collection_modifyitems(config, items):\n \"\"\"Called after collect is completed.\n\n Parameters\n ----------\n config : pytest config\n items : list of collected items\n \"\"\"\n run_network_tests = environ.get('SKLEARN_SKIP_NETWORK_TESTS', '1') == '0'\n skip_network = pytest.mark.skip(reason='test is enabled when SKLEARN_SKIP_NETWORK_TESTS=0')\n dataset_features_set = set(dataset_fetchers)\n datasets_to_download = set()\n for item in items:\n if not hasattr(item, 'fixturenames'):\n continue\n item_fixtures = set(item.fixturenames)\n dataset_to_fetch = item_fixtures & dataset_features_set\n if not dataset_to_fetch:\n continue\n if run_network_tests:\n datasets_to_download |= dataset_to_fetch\n else:\n item.add_marker(skip_network)\n worker_id = environ.get('PYTEST_XDIST_WORKER', 'gw0')\n if worker_id == 'gw0' and run_network_tests:\n for name in datasets_to_download:\n dataset_fetchers[name]()\n for item in items:\n if item.name.endswith(('_hash.FeatureHasher', 'text.HashingVectorizer')) and platform.python_implementation() == 'PyPy':\n marker = pytest.mark.skip(reason='FeatureHasher is not compatible with PyPy')\n item.add_marker(marker)\n elif item.name.endswith('GradientBoostingClassifier') and platform.machine() == 'aarch64':\n marker = pytest.mark.xfail(reason='know failure. See https://github.com/scikit-learn/scikit-learn/issues/17797')\n item.add_marker(marker)\n skip_doctests = False\n try:\n import matplotlib\n except ImportError:\n skip_doctests = True\n reason = 'matplotlib is required to run the doctests'\n try:\n if np_version < parse_version('1.14'):\n reason = 'doctests are only run for numpy >= 1.14'\n skip_doctests = True\n elif _IS_32BIT:\n reason = 'doctest are only run when the default numpy int is 64 bits.'\n skip_doctests = True\n elif sys.platform.startswith('win32'):\n reason = 'doctests are not run for Windows because numpy arrays repr is inconsistent across platforms.'\n skip_doctests = True\n except ImportError:\n pass\n for item in items:\n if isinstance(item, DoctestItem):\n item.dtest.globs = {}\n if skip_doctests:\n skip_marker = pytest.mark.skip(reason=reason)\n for item in items:\n if isinstance(item, DoctestItem):\n if item.name != 'sklearn._config.config_context':\n item.add_marker(skip_marker)\n elif not _pilutil.pillow_installed:\n skip_marker = pytest.mark.skip(reason='pillow (or PIL) not installed!')\n for item in items:\n if item.name in ['sklearn.feature_extraction.image.PatchExtractor', 'sklearn.feature_extraction.image.extract_patches_2d']:\n item.add_marker(skip_marker)" }, { "name": "pytest_configure", + "unique_name": "pytest_configure", "qname": "sklearn.conftest.pytest_configure", + "unique_qname": "sklearn.conftest.pytest_configure", "decorators": [], "parameters": [ { @@ -38150,7 +38683,9 @@ }, { "name": "pytest_runtest_setup", + "unique_name": "pytest_runtest_setup", "qname": "sklearn.conftest.pytest_runtest_setup", + "unique_qname": "sklearn.conftest.pytest_runtest_setup", "decorators": [], "parameters": [ { @@ -38172,7 +38707,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.covariance._elliptic_envelope.EllipticEnvelope.__init__", + "unique_qname": "sklearn.covariance._elliptic_envelope.EllipticEnvelope.__init__", "decorators": [], "parameters": [ { @@ -38232,7 +38769,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int, RandomState instance or None, default=None", - "description": "Determines the pseudo random number generator for shuffling\nthe data. Pass an int for reproducible results across multiple function\ncalls. See :term: `Glossary `." + "description": "Determines the pseudo random number generator for shuffling\nthe data. Pass an int for reproducible results across multiple function\ncalls. See :term:`Glossary `." } } ], @@ -38244,7 +38781,9 @@ }, { "name": "decision_function", + "unique_name": "decision_function", "qname": "sklearn.covariance._elliptic_envelope.EllipticEnvelope.decision_function", + "unique_qname": "sklearn.covariance._elliptic_envelope.EllipticEnvelope.decision_function", "decorators": [], "parameters": [ { @@ -38276,7 +38815,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.covariance._elliptic_envelope.EllipticEnvelope.fit", + "unique_qname": "sklearn.covariance._elliptic_envelope.EllipticEnvelope.fit", "decorators": [], "parameters": [ { @@ -38318,7 +38859,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.covariance._elliptic_envelope.EllipticEnvelope.predict", + "unique_qname": "sklearn.covariance._elliptic_envelope.EllipticEnvelope.predict", "decorators": [], "parameters": [ { @@ -38350,7 +38893,9 @@ }, { "name": "score", + "unique_name": "score", "qname": "sklearn.covariance._elliptic_envelope.EllipticEnvelope.score", + "unique_qname": "sklearn.covariance._elliptic_envelope.EllipticEnvelope.score", "decorators": [], "parameters": [ { @@ -38402,7 +38947,9 @@ }, { "name": "score_samples", + "unique_name": "score_samples", "qname": "sklearn.covariance._elliptic_envelope.EllipticEnvelope.score_samples", + "unique_qname": "sklearn.covariance._elliptic_envelope.EllipticEnvelope.score_samples", "decorators": [], "parameters": [ { @@ -38430,11 +38977,13 @@ "is_public": true, "description": "Compute the negative Mahalanobis distances.", "docstring": "Compute the negative Mahalanobis distances.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n The data matrix.\n\nReturns\n-------\nnegative_mahal_distances : array-like of shape (n_samples,)\n Opposite of the Mahalanobis distances.", - "source_code": "\ndef score_samples(self, X):\n \"\"\"Compute the negative Mahalanobis distances.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data matrix.\n\n Returns\n -------\n negative_mahal_distances : array-like of shape (n_samples,)\n Opposite of the Mahalanobis distances.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, reset=False)\n return -self.mahalanobis(X)" + "source_code": "\ndef score_samples(self, X):\n \"\"\"Compute the negative Mahalanobis distances.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data matrix.\n\n Returns\n -------\n negative_mahal_distances : array-like of shape (n_samples,)\n Opposite of the Mahalanobis distances.\n \"\"\"\n check_is_fitted(self)\n return -self.mahalanobis(X)" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.covariance._empirical_covariance.EmpiricalCovariance.__init__", + "unique_qname": "sklearn.covariance._empirical_covariance.EmpiricalCovariance.__init__", "decorators": [], "parameters": [ { @@ -38476,7 +39025,9 @@ }, { "name": "_set_covariance", + "unique_name": "_set_covariance", "qname": "sklearn.covariance._empirical_covariance.EmpiricalCovariance._set_covariance", + "unique_qname": "sklearn.covariance._empirical_covariance.EmpiricalCovariance._set_covariance", "decorators": [], "parameters": [ { @@ -38508,7 +39059,9 @@ }, { "name": "error_norm", + "unique_name": "error_norm", "qname": "sklearn.covariance._empirical_covariance.EmpiricalCovariance.error_norm", + "unique_qname": "sklearn.covariance._empirical_covariance.EmpiricalCovariance.error_norm", "decorators": [], "parameters": [ { @@ -38570,7 +39123,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.covariance._empirical_covariance.EmpiricalCovariance.fit", + "unique_qname": "sklearn.covariance._empirical_covariance.EmpiricalCovariance.fit", "decorators": [], "parameters": [ { @@ -38612,7 +39167,9 @@ }, { "name": "get_precision", + "unique_name": "get_precision", "qname": "sklearn.covariance._empirical_covariance.EmpiricalCovariance.get_precision", + "unique_qname": "sklearn.covariance._empirical_covariance.EmpiricalCovariance.get_precision", "decorators": [], "parameters": [ { @@ -38634,7 +39191,9 @@ }, { "name": "mahalanobis", + "unique_name": "mahalanobis", "qname": "sklearn.covariance._empirical_covariance.EmpiricalCovariance.mahalanobis", + "unique_qname": "sklearn.covariance._empirical_covariance.EmpiricalCovariance.mahalanobis", "decorators": [], "parameters": [ { @@ -38666,7 +39225,9 @@ }, { "name": "score", + "unique_name": "score", "qname": "sklearn.covariance._empirical_covariance.EmpiricalCovariance.score", + "unique_qname": "sklearn.covariance._empirical_covariance.EmpiricalCovariance.score", "decorators": [], "parameters": [ { @@ -38708,7 +39269,9 @@ }, { "name": "empirical_covariance", + "unique_name": "empirical_covariance", "qname": "sklearn.covariance._empirical_covariance.empirical_covariance", + "unique_qname": "sklearn.covariance._empirical_covariance.empirical_covariance", "decorators": [], "parameters": [ { @@ -38740,7 +39303,9 @@ }, { "name": "log_likelihood", + "unique_name": "log_likelihood", "qname": "sklearn.covariance._empirical_covariance.log_likelihood", + "unique_qname": "sklearn.covariance._empirical_covariance.log_likelihood", "decorators": [], "parameters": [ { @@ -38772,7 +39337,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.covariance._graph_lasso.GraphicalLasso.__init__", + "unique_qname": "sklearn.covariance._graph_lasso.GraphicalLasso.__init__", "decorators": [], "parameters": [ { @@ -38864,7 +39431,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.covariance._graph_lasso.GraphicalLasso.fit", + "unique_qname": "sklearn.covariance._graph_lasso.GraphicalLasso.fit", "decorators": [], "parameters": [ { @@ -38906,7 +39475,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.covariance._graph_lasso.GraphicalLassoCV.__init__", + "unique_qname": "sklearn.covariance._graph_lasso.GraphicalLassoCV.__init__", "decorators": [], "parameters": [ { @@ -39028,7 +39599,9 @@ }, { "name": "cv_alphas_", + "unique_name": "cv_alphas_@getter", "qname": "sklearn.covariance._graph_lasso.GraphicalLassoCV.cv_alphas_", + "unique_qname": "sklearn.covariance._graph_lasso.GraphicalLassoCV.cv_alphas_@getter", "decorators": [ "deprecated(\"The `cv_alphas_` attribute is deprecated in version 0.24 in favor of `cv_results_['alpha']` and will be removed in version 1.1 (renaming of 0.26).\")", "property" @@ -39053,7 +39626,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.covariance._graph_lasso.GraphicalLassoCV.fit", + "unique_qname": "sklearn.covariance._graph_lasso.GraphicalLassoCV.fit", "decorators": [], "parameters": [ { @@ -39095,7 +39670,9 @@ }, { "name": "grid_scores_", + "unique_name": "grid_scores_@getter", "qname": "sklearn.covariance._graph_lasso.GraphicalLassoCV.grid_scores_", + "unique_qname": "sklearn.covariance._graph_lasso.GraphicalLassoCV.grid_scores_@getter", "decorators": [ "deprecated('The `grid_scores_` attribute is deprecated in version 0.24 in favor of `cv_results_` and will be removed in version 1.1 (renaming of 0.26).')", "property" @@ -39120,7 +39697,9 @@ }, { "name": "__getitem__", + "unique_name": "__getitem__", "qname": "sklearn.covariance._graph_lasso._DictWithDeprecatedKeys.__getitem__", + "unique_qname": "sklearn.covariance._graph_lasso._DictWithDeprecatedKeys.__getitem__", "decorators": [], "parameters": [ { @@ -39152,7 +39731,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.covariance._graph_lasso._DictWithDeprecatedKeys.__init__", + "unique_qname": "sklearn.covariance._graph_lasso._DictWithDeprecatedKeys.__init__", "decorators": [], "parameters": [ { @@ -39174,7 +39755,9 @@ }, { "name": "_set_deprecated", + "unique_name": "_set_deprecated", "qname": "sklearn.covariance._graph_lasso._DictWithDeprecatedKeys._set_deprecated", + "unique_qname": "sklearn.covariance._graph_lasso._DictWithDeprecatedKeys._set_deprecated", "decorators": [], "parameters": [ { @@ -39226,7 +39809,9 @@ }, { "name": "_dual_gap", + "unique_name": "_dual_gap", "qname": "sklearn.covariance._graph_lasso._dual_gap", + "unique_qname": "sklearn.covariance._graph_lasso._dual_gap", "decorators": [], "parameters": [ { @@ -39268,7 +39853,9 @@ }, { "name": "_objective", + "unique_name": "_objective", "qname": "sklearn.covariance._graph_lasso._objective", + "unique_qname": "sklearn.covariance._graph_lasso._objective", "decorators": [], "parameters": [ { @@ -39310,7 +39897,9 @@ }, { "name": "alpha_max", + "unique_name": "alpha_max", "qname": "sklearn.covariance._graph_lasso.alpha_max", + "unique_qname": "sklearn.covariance._graph_lasso.alpha_max", "decorators": [], "parameters": [ { @@ -39332,7 +39921,9 @@ }, { "name": "graphical_lasso", + "unique_name": "graphical_lasso", "qname": "sklearn.covariance._graph_lasso.graphical_lasso", + "unique_qname": "sklearn.covariance._graph_lasso.graphical_lasso", "decorators": [], "parameters": [ { @@ -39454,7 +40045,9 @@ }, { "name": "graphical_lasso_path", + "unique_name": "graphical_lasso_path", "qname": "sklearn.covariance._graph_lasso.graphical_lasso_path", + "unique_qname": "sklearn.covariance._graph_lasso.graphical_lasso_path", "decorators": [], "parameters": [ { @@ -39556,7 +40149,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.covariance._robust_covariance.MinCovDet.__init__", + "unique_qname": "sklearn.covariance._robust_covariance.MinCovDet.__init__", "decorators": [], "parameters": [ { @@ -39606,7 +40201,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int, RandomState instance or None, default=None", - "description": "Determines the pseudo random number generator for shuffling the data.\nPass an int for reproducible results across multiple function calls.\nSee :term: `Glossary `." + "description": "Determines the pseudo random number generator for shuffling the data.\nPass an int for reproducible results across multiple function calls.\nSee :term:`Glossary `." } } ], @@ -39618,7 +40213,9 @@ }, { "name": "correct_covariance", + "unique_name": "correct_covariance", "qname": "sklearn.covariance._robust_covariance.MinCovDet.correct_covariance", + "unique_qname": "sklearn.covariance._robust_covariance.MinCovDet.correct_covariance", "decorators": [], "parameters": [ { @@ -39650,7 +40247,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.covariance._robust_covariance.MinCovDet.fit", + "unique_qname": "sklearn.covariance._robust_covariance.MinCovDet.fit", "decorators": [], "parameters": [ { @@ -39692,7 +40291,9 @@ }, { "name": "reweight_covariance", + "unique_name": "reweight_covariance", "qname": "sklearn.covariance._robust_covariance.MinCovDet.reweight_covariance", + "unique_qname": "sklearn.covariance._robust_covariance.MinCovDet.reweight_covariance", "decorators": [], "parameters": [ { @@ -39724,7 +40325,9 @@ }, { "name": "_c_step", + "unique_name": "_c_step", "qname": "sklearn.covariance._robust_covariance._c_step", + "unique_qname": "sklearn.covariance._robust_covariance._c_step", "decorators": [], "parameters": [ { @@ -39806,7 +40409,9 @@ }, { "name": "c_step", + "unique_name": "c_step", "qname": "sklearn.covariance._robust_covariance.c_step", + "unique_qname": "sklearn.covariance._robust_covariance.c_step", "decorators": [], "parameters": [ { @@ -39876,19 +40481,21 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "int, RandomState instance or None, default=None", - "description": "Determines the pseudo random number generator for shuffling the data.\nPass an int for reproducible results across multiple function calls.\nSee :term: `Glossary `." + "description": "Determines the pseudo random number generator for shuffling the data.\nPass an int for reproducible results across multiple function calls.\nSee :term:`Glossary `." } } ], "results": [], "is_public": false, "description": "C_step procedure described in [Rouseeuw1984]_ aiming at computing MCD.", - "docstring": "C_step procedure described in [Rouseeuw1984]_ aiming at computing MCD.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Data set in which we look for the n_support observations whose\n scatter matrix has minimum determinant.\n\nn_support : int\n Number of observations to compute the robust estimates of location\n and covariance from. This parameter must be greater than\n `n_samples / 2`.\n\nremaining_iterations : int, default=30\n Number of iterations to perform.\n According to [Rouseeuw1999]_, two iterations are sufficient to get\n close to the minimum, and we never need more than 30 to reach\n convergence.\n\ninitial_estimates : tuple of shape (2,), default=None\n Initial estimates of location and shape from which to run the c_step\n procedure:\n - initial_estimates[0]: an initial location estimate\n - initial_estimates[1]: an initial covariance estimate\n\nverbose : bool, default=False\n Verbose mode.\n\ncov_computation_method : callable, default=:func:`sklearn.covariance.empirical_covariance`\n The function which will be used to compute the covariance.\n Must return array of shape (n_features, n_features).\n\nrandom_state : int, RandomState instance or None, default=None\n Determines the pseudo random number generator for shuffling the data.\n Pass an int for reproducible results across multiple function calls.\n See :term: `Glossary `.\n\nReturns\n-------\nlocation : ndarray of shape (n_features,)\n Robust location estimates.\n\ncovariance : ndarray of shape (n_features, n_features)\n Robust covariance estimates.\n\nsupport : ndarray of shape (n_samples,)\n A mask for the `n_support` observations whose scatter matrix has\n minimum determinant.\n\nReferences\n----------\n.. [Rouseeuw1999] A Fast Algorithm for the Minimum Covariance Determinant\n Estimator, 1999, American Statistical Association and the American\n Society for Quality, TECHNOMETRICS", - "source_code": "\ndef c_step(X, n_support, remaining_iterations=30, initial_estimates=None, verbose=False, cov_computation_method=empirical_covariance, random_state=None):\n \"\"\"C_step procedure described in [Rouseeuw1984]_ aiming at computing MCD.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Data set in which we look for the n_support observations whose\n scatter matrix has minimum determinant.\n\n n_support : int\n Number of observations to compute the robust estimates of location\n and covariance from. This parameter must be greater than\n `n_samples / 2`.\n\n remaining_iterations : int, default=30\n Number of iterations to perform.\n According to [Rouseeuw1999]_, two iterations are sufficient to get\n close to the minimum, and we never need more than 30 to reach\n convergence.\n\n initial_estimates : tuple of shape (2,), default=None\n Initial estimates of location and shape from which to run the c_step\n procedure:\n - initial_estimates[0]: an initial location estimate\n - initial_estimates[1]: an initial covariance estimate\n\n verbose : bool, default=False\n Verbose mode.\n\n cov_computation_method : callable, default=:func:`sklearn.covariance.empirical_covariance`\n The function which will be used to compute the covariance.\n Must return array of shape (n_features, n_features).\n\n random_state : int, RandomState instance or None, default=None\n Determines the pseudo random number generator for shuffling the data.\n Pass an int for reproducible results across multiple function calls.\n See :term: `Glossary `.\n\n Returns\n -------\n location : ndarray of shape (n_features,)\n Robust location estimates.\n\n covariance : ndarray of shape (n_features, n_features)\n Robust covariance estimates.\n\n support : ndarray of shape (n_samples,)\n A mask for the `n_support` observations whose scatter matrix has\n minimum determinant.\n\n References\n ----------\n .. [Rouseeuw1999] A Fast Algorithm for the Minimum Covariance Determinant\n Estimator, 1999, American Statistical Association and the American\n Society for Quality, TECHNOMETRICS\n \"\"\"\n X = np.asarray(X)\n random_state = check_random_state(random_state)\n return _c_step(X, n_support, remaining_iterations=remaining_iterations, initial_estimates=initial_estimates, verbose=verbose, cov_computation_method=cov_computation_method, random_state=random_state)" + "docstring": "C_step procedure described in [Rouseeuw1984]_ aiming at computing MCD.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Data set in which we look for the n_support observations whose\n scatter matrix has minimum determinant.\n\nn_support : int\n Number of observations to compute the robust estimates of location\n and covariance from. This parameter must be greater than\n `n_samples / 2`.\n\nremaining_iterations : int, default=30\n Number of iterations to perform.\n According to [Rouseeuw1999]_, two iterations are sufficient to get\n close to the minimum, and we never need more than 30 to reach\n convergence.\n\ninitial_estimates : tuple of shape (2,), default=None\n Initial estimates of location and shape from which to run the c_step\n procedure:\n - initial_estimates[0]: an initial location estimate\n - initial_estimates[1]: an initial covariance estimate\n\nverbose : bool, default=False\n Verbose mode.\n\ncov_computation_method : callable, default=:func:`sklearn.covariance.empirical_covariance`\n The function which will be used to compute the covariance.\n Must return array of shape (n_features, n_features).\n\nrandom_state : int, RandomState instance or None, default=None\n Determines the pseudo random number generator for shuffling the data.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\nReturns\n-------\nlocation : ndarray of shape (n_features,)\n Robust location estimates.\n\ncovariance : ndarray of shape (n_features, n_features)\n Robust covariance estimates.\n\nsupport : ndarray of shape (n_samples,)\n A mask for the `n_support` observations whose scatter matrix has\n minimum determinant.\n\nReferences\n----------\n.. [Rouseeuw1999] A Fast Algorithm for the Minimum Covariance Determinant\n Estimator, 1999, American Statistical Association and the American\n Society for Quality, TECHNOMETRICS", + "source_code": "\ndef c_step(X, n_support, remaining_iterations=30, initial_estimates=None, verbose=False, cov_computation_method=empirical_covariance, random_state=None):\n \"\"\"C_step procedure described in [Rouseeuw1984]_ aiming at computing MCD.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Data set in which we look for the n_support observations whose\n scatter matrix has minimum determinant.\n\n n_support : int\n Number of observations to compute the robust estimates of location\n and covariance from. This parameter must be greater than\n `n_samples / 2`.\n\n remaining_iterations : int, default=30\n Number of iterations to perform.\n According to [Rouseeuw1999]_, two iterations are sufficient to get\n close to the minimum, and we never need more than 30 to reach\n convergence.\n\n initial_estimates : tuple of shape (2,), default=None\n Initial estimates of location and shape from which to run the c_step\n procedure:\n - initial_estimates[0]: an initial location estimate\n - initial_estimates[1]: an initial covariance estimate\n\n verbose : bool, default=False\n Verbose mode.\n\n cov_computation_method : callable, default=:func:`sklearn.covariance.empirical_covariance`\n The function which will be used to compute the covariance.\n Must return array of shape (n_features, n_features).\n\n random_state : int, RandomState instance or None, default=None\n Determines the pseudo random number generator for shuffling the data.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n Returns\n -------\n location : ndarray of shape (n_features,)\n Robust location estimates.\n\n covariance : ndarray of shape (n_features, n_features)\n Robust covariance estimates.\n\n support : ndarray of shape (n_samples,)\n A mask for the `n_support` observations whose scatter matrix has\n minimum determinant.\n\n References\n ----------\n .. [Rouseeuw1999] A Fast Algorithm for the Minimum Covariance Determinant\n Estimator, 1999, American Statistical Association and the American\n Society for Quality, TECHNOMETRICS\n \"\"\"\n X = np.asarray(X)\n random_state = check_random_state(random_state)\n return _c_step(X, n_support, remaining_iterations=remaining_iterations, initial_estimates=initial_estimates, verbose=verbose, cov_computation_method=cov_computation_method, random_state=random_state)" }, { "name": "fast_mcd", + "unique_name": "fast_mcd", "qname": "sklearn.covariance._robust_covariance.fast_mcd", + "unique_qname": "sklearn.covariance._robust_covariance.fast_mcd", "decorators": [], "parameters": [ { @@ -39928,19 +40535,21 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "int, RandomState instance or None, default=None", - "description": "Determines the pseudo random number generator for shuffling the data.\nPass an int for reproducible results across multiple function calls.\nSee :term: `Glossary `." + "description": "Determines the pseudo random number generator for shuffling the data.\nPass an int for reproducible results across multiple function calls.\nSee :term:`Glossary `." } } ], "results": [], "is_public": true, "description": "Estimates the Minimum Covariance Determinant matrix.\n\nRead more in the :ref:`User Guide `.", - "docstring": "Estimates the Minimum Covariance Determinant matrix.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n The data matrix, with p features and n samples.\n\nsupport_fraction : float, default=None\n The proportion of points to be included in the support of the raw\n MCD estimate. Default is `None`, which implies that the minimum\n value of `support_fraction` will be used within the algorithm:\n `(n_sample + n_features + 1) / 2`. This parameter must be in the\n range (0, 1).\n\ncov_computation_method : callable, default=:func:`sklearn.covariance.empirical_covariance`\n The function which will be used to compute the covariance.\n Must return an array of shape (n_features, n_features).\n\nrandom_state : int, RandomState instance or None, default=None\n Determines the pseudo random number generator for shuffling the data.\n Pass an int for reproducible results across multiple function calls.\n See :term: `Glossary `.\n\nReturns\n-------\nlocation : ndarray of shape (n_features,)\n Robust location of the data.\n\ncovariance : ndarray of shape (n_features, n_features)\n Robust covariance of the features.\n\nsupport : ndarray of shape (n_samples,), dtype=bool\n A mask of the observations that have been used to compute\n the robust location and covariance estimates of the data set.\n\nNotes\n-----\nThe FastMCD algorithm has been introduced by Rousseuw and Van Driessen\nin \"A Fast Algorithm for the Minimum Covariance Determinant Estimator,\n1999, American Statistical Association and the American Society\nfor Quality, TECHNOMETRICS\".\nThe principle is to compute robust estimates and random subsets before\npooling them into a larger subsets, and finally into the full data set.\nDepending on the size of the initial sample, we have one, two or three\nsuch computation levels.\n\nNote that only raw estimates are returned. If one is interested in\nthe correction and reweighting steps described in [RouseeuwVan]_,\nsee the MinCovDet object.\n\nReferences\n----------\n\n.. [RouseeuwVan] A Fast Algorithm for the Minimum Covariance\n Determinant Estimator, 1999, American Statistical Association\n and the American Society for Quality, TECHNOMETRICS\n\n.. [Butler1993] R. W. Butler, P. L. Davies and M. Jhun,\n Asymptotics For The Minimum Covariance Determinant Estimator,\n The Annals of Statistics, 1993, Vol. 21, No. 3, 1385-1400", - "source_code": "\ndef fast_mcd(X, support_fraction=None, cov_computation_method=empirical_covariance, random_state=None):\n \"\"\"Estimates the Minimum Covariance Determinant matrix.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data matrix, with p features and n samples.\n\n support_fraction : float, default=None\n The proportion of points to be included in the support of the raw\n MCD estimate. Default is `None`, which implies that the minimum\n value of `support_fraction` will be used within the algorithm:\n `(n_sample + n_features + 1) / 2`. This parameter must be in the\n range (0, 1).\n\n cov_computation_method : callable, default=:func:`sklearn.covariance.empirical_covariance`\n The function which will be used to compute the covariance.\n Must return an array of shape (n_features, n_features).\n\n random_state : int, RandomState instance or None, default=None\n Determines the pseudo random number generator for shuffling the data.\n Pass an int for reproducible results across multiple function calls.\n See :term: `Glossary `.\n\n Returns\n -------\n location : ndarray of shape (n_features,)\n Robust location of the data.\n\n covariance : ndarray of shape (n_features, n_features)\n Robust covariance of the features.\n\n support : ndarray of shape (n_samples,), dtype=bool\n A mask of the observations that have been used to compute\n the robust location and covariance estimates of the data set.\n\n Notes\n -----\n The FastMCD algorithm has been introduced by Rousseuw and Van Driessen\n in \"A Fast Algorithm for the Minimum Covariance Determinant Estimator,\n 1999, American Statistical Association and the American Society\n for Quality, TECHNOMETRICS\".\n The principle is to compute robust estimates and random subsets before\n pooling them into a larger subsets, and finally into the full data set.\n Depending on the size of the initial sample, we have one, two or three\n such computation levels.\n\n Note that only raw estimates are returned. If one is interested in\n the correction and reweighting steps described in [RouseeuwVan]_,\n see the MinCovDet object.\n\n References\n ----------\n\n .. [RouseeuwVan] A Fast Algorithm for the Minimum Covariance\n Determinant Estimator, 1999, American Statistical Association\n and the American Society for Quality, TECHNOMETRICS\n\n .. [Butler1993] R. W. Butler, P. L. Davies and M. Jhun,\n Asymptotics For The Minimum Covariance Determinant Estimator,\n The Annals of Statistics, 1993, Vol. 21, No. 3, 1385-1400\n \"\"\"\n random_state = check_random_state(random_state)\n X = check_array(X, ensure_min_samples=2, estimator='fast_mcd')\n (n_samples, n_features) = X.shape\n if support_fraction is None:\n n_support = int(np.ceil(0.5 * (n_samples + n_features + 1)))\n else:\n n_support = int(support_fraction * n_samples)\n if n_features == 1:\n if n_support < n_samples:\n X_sorted = np.sort(np.ravel(X))\n diff = X_sorted[n_support:] - X_sorted[:n_samples - n_support]\n halves_start = np.where(diff == np.min(diff))[0]\n location = 0.5 * (X_sorted[n_support + halves_start] + X_sorted[halves_start]).mean()\n support = np.zeros(n_samples, dtype=bool)\n X_centered = X - location\n support[np.argsort(np.abs(X_centered), 0)[:n_support]] = True\n covariance = np.asarray([[np.var(X[support])]])\n location = np.array([location])\n precision = linalg.pinvh(covariance)\n dist = (np.dot(X_centered, precision) * X_centered).sum(axis=1)\n else:\n support = np.ones(n_samples, dtype=bool)\n covariance = np.asarray([[np.var(X)]])\n location = np.asarray([np.mean(X)])\n X_centered = X - location\n precision = linalg.pinvh(covariance)\n dist = (np.dot(X_centered, precision) * X_centered).sum(axis=1)\n if n_samples > 500 and n_features > 1:\n n_subsets = n_samples // 300\n n_samples_subsets = n_samples // n_subsets\n samples_shuffle = random_state.permutation(n_samples)\n h_subset = int(np.ceil(n_samples_subsets * (n_support / float(n_samples))))\n n_trials_tot = 500\n n_best_sub = 10\n n_trials = max(10, n_trials_tot // n_subsets)\n n_best_tot = n_subsets * n_best_sub\n all_best_locations = np.zeros((n_best_tot, n_features))\n try:\n all_best_covariances = np.zeros((n_best_tot, n_features, n_features))\n except MemoryError:\n n_best_tot = 10\n all_best_covariances = np.zeros((n_best_tot, n_features, n_features))\n n_best_sub = 2\n for i in range(n_subsets):\n low_bound = i * n_samples_subsets\n high_bound = low_bound + n_samples_subsets\n current_subset = X[samples_shuffle[low_bound:high_bound]]\n (best_locations_sub, best_covariances_sub, _, _) = select_candidates(current_subset, h_subset, n_trials, select=n_best_sub, n_iter=2, cov_computation_method=cov_computation_method, random_state=random_state)\n subset_slice = np.arange(i * n_best_sub, (i + 1) * n_best_sub)\n all_best_locations[subset_slice] = best_locations_sub\n all_best_covariances[subset_slice] = best_covariances_sub\n n_samples_merged = min(1500, n_samples)\n h_merged = int(np.ceil(n_samples_merged * (n_support / float(n_samples))))\n if n_samples > 1500:\n n_best_merged = 10\n else:\n n_best_merged = 1\n selection = random_state.permutation(n_samples)[:n_samples_merged]\n (locations_merged, covariances_merged, supports_merged, d) = select_candidates(X[selection], h_merged, n_trials=(all_best_locations, all_best_covariances), select=n_best_merged, cov_computation_method=cov_computation_method, random_state=random_state)\n if n_samples < 1500:\n location = locations_merged[0]\n covariance = covariances_merged[0]\n support = np.zeros(n_samples, dtype=bool)\n dist = np.zeros(n_samples)\n support[selection] = supports_merged[0]\n dist[selection] = d[0]\n else:\n (locations_full, covariances_full, supports_full, d) = select_candidates(X, n_support, n_trials=(locations_merged, covariances_merged), select=1, cov_computation_method=cov_computation_method, random_state=random_state)\n location = locations_full[0]\n covariance = covariances_full[0]\n support = supports_full[0]\n dist = d[0]\n elif n_features > 1:\n n_trials = 30\n n_best = 10\n (locations_best, covariances_best, _, _) = select_candidates(X, n_support, n_trials=n_trials, select=n_best, n_iter=2, cov_computation_method=cov_computation_method, random_state=random_state)\n (locations_full, covariances_full, supports_full, d) = select_candidates(X, n_support, n_trials=(locations_best, covariances_best), select=1, cov_computation_method=cov_computation_method, random_state=random_state)\n location = locations_full[0]\n covariance = covariances_full[0]\n support = supports_full[0]\n dist = d[0]\n return location, covariance, support, dist" + "docstring": "Estimates the Minimum Covariance Determinant matrix.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n The data matrix, with p features and n samples.\n\nsupport_fraction : float, default=None\n The proportion of points to be included in the support of the raw\n MCD estimate. Default is `None`, which implies that the minimum\n value of `support_fraction` will be used within the algorithm:\n `(n_sample + n_features + 1) / 2`. This parameter must be in the\n range (0, 1).\n\ncov_computation_method : callable, default=:func:`sklearn.covariance.empirical_covariance`\n The function which will be used to compute the covariance.\n Must return an array of shape (n_features, n_features).\n\nrandom_state : int, RandomState instance or None, default=None\n Determines the pseudo random number generator for shuffling the data.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\nReturns\n-------\nlocation : ndarray of shape (n_features,)\n Robust location of the data.\n\ncovariance : ndarray of shape (n_features, n_features)\n Robust covariance of the features.\n\nsupport : ndarray of shape (n_samples,), dtype=bool\n A mask of the observations that have been used to compute\n the robust location and covariance estimates of the data set.\n\nNotes\n-----\nThe FastMCD algorithm has been introduced by Rousseuw and Van Driessen\nin \"A Fast Algorithm for the Minimum Covariance Determinant Estimator,\n1999, American Statistical Association and the American Society\nfor Quality, TECHNOMETRICS\".\nThe principle is to compute robust estimates and random subsets before\npooling them into a larger subsets, and finally into the full data set.\nDepending on the size of the initial sample, we have one, two or three\nsuch computation levels.\n\nNote that only raw estimates are returned. If one is interested in\nthe correction and reweighting steps described in [RouseeuwVan]_,\nsee the MinCovDet object.\n\nReferences\n----------\n\n.. [RouseeuwVan] A Fast Algorithm for the Minimum Covariance\n Determinant Estimator, 1999, American Statistical Association\n and the American Society for Quality, TECHNOMETRICS\n\n.. [Butler1993] R. W. Butler, P. L. Davies and M. Jhun,\n Asymptotics For The Minimum Covariance Determinant Estimator,\n The Annals of Statistics, 1993, Vol. 21, No. 3, 1385-1400", + "source_code": "\ndef fast_mcd(X, support_fraction=None, cov_computation_method=empirical_covariance, random_state=None):\n \"\"\"Estimates the Minimum Covariance Determinant matrix.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data matrix, with p features and n samples.\n\n support_fraction : float, default=None\n The proportion of points to be included in the support of the raw\n MCD estimate. Default is `None`, which implies that the minimum\n value of `support_fraction` will be used within the algorithm:\n `(n_sample + n_features + 1) / 2`. This parameter must be in the\n range (0, 1).\n\n cov_computation_method : callable, default=:func:`sklearn.covariance.empirical_covariance`\n The function which will be used to compute the covariance.\n Must return an array of shape (n_features, n_features).\n\n random_state : int, RandomState instance or None, default=None\n Determines the pseudo random number generator for shuffling the data.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n Returns\n -------\n location : ndarray of shape (n_features,)\n Robust location of the data.\n\n covariance : ndarray of shape (n_features, n_features)\n Robust covariance of the features.\n\n support : ndarray of shape (n_samples,), dtype=bool\n A mask of the observations that have been used to compute\n the robust location and covariance estimates of the data set.\n\n Notes\n -----\n The FastMCD algorithm has been introduced by Rousseuw and Van Driessen\n in \"A Fast Algorithm for the Minimum Covariance Determinant Estimator,\n 1999, American Statistical Association and the American Society\n for Quality, TECHNOMETRICS\".\n The principle is to compute robust estimates and random subsets before\n pooling them into a larger subsets, and finally into the full data set.\n Depending on the size of the initial sample, we have one, two or three\n such computation levels.\n\n Note that only raw estimates are returned. If one is interested in\n the correction and reweighting steps described in [RouseeuwVan]_,\n see the MinCovDet object.\n\n References\n ----------\n\n .. [RouseeuwVan] A Fast Algorithm for the Minimum Covariance\n Determinant Estimator, 1999, American Statistical Association\n and the American Society for Quality, TECHNOMETRICS\n\n .. [Butler1993] R. W. Butler, P. L. Davies and M. Jhun,\n Asymptotics For The Minimum Covariance Determinant Estimator,\n The Annals of Statistics, 1993, Vol. 21, No. 3, 1385-1400\n \"\"\"\n random_state = check_random_state(random_state)\n X = check_array(X, ensure_min_samples=2, estimator='fast_mcd')\n (n_samples, n_features) = X.shape\n if support_fraction is None:\n n_support = int(np.ceil(0.5 * (n_samples + n_features + 1)))\n else:\n n_support = int(support_fraction * n_samples)\n if n_features == 1:\n if n_support < n_samples:\n X_sorted = np.sort(np.ravel(X))\n diff = X_sorted[n_support:] - X_sorted[:n_samples - n_support]\n halves_start = np.where(diff == np.min(diff))[0]\n location = 0.5 * (X_sorted[n_support + halves_start] + X_sorted[halves_start]).mean()\n support = np.zeros(n_samples, dtype=bool)\n X_centered = X - location\n support[np.argsort(np.abs(X_centered), 0)[:n_support]] = True\n covariance = np.asarray([[np.var(X[support])]])\n location = np.array([location])\n precision = linalg.pinvh(covariance)\n dist = (np.dot(X_centered, precision) * X_centered).sum(axis=1)\n else:\n support = np.ones(n_samples, dtype=bool)\n covariance = np.asarray([[np.var(X)]])\n location = np.asarray([np.mean(X)])\n X_centered = X - location\n precision = linalg.pinvh(covariance)\n dist = (np.dot(X_centered, precision) * X_centered).sum(axis=1)\n if n_samples > 500 and n_features > 1:\n n_subsets = n_samples // 300\n n_samples_subsets = n_samples // n_subsets\n samples_shuffle = random_state.permutation(n_samples)\n h_subset = int(np.ceil(n_samples_subsets * (n_support / float(n_samples))))\n n_trials_tot = 500\n n_best_sub = 10\n n_trials = max(10, n_trials_tot // n_subsets)\n n_best_tot = n_subsets * n_best_sub\n all_best_locations = np.zeros((n_best_tot, n_features))\n try:\n all_best_covariances = np.zeros((n_best_tot, n_features, n_features))\n except MemoryError:\n n_best_tot = 10\n all_best_covariances = np.zeros((n_best_tot, n_features, n_features))\n n_best_sub = 2\n for i in range(n_subsets):\n low_bound = i * n_samples_subsets\n high_bound = low_bound + n_samples_subsets\n current_subset = X[samples_shuffle[low_bound:high_bound]]\n (best_locations_sub, best_covariances_sub, _, _) = select_candidates(current_subset, h_subset, n_trials, select=n_best_sub, n_iter=2, cov_computation_method=cov_computation_method, random_state=random_state)\n subset_slice = np.arange(i * n_best_sub, (i + 1) * n_best_sub)\n all_best_locations[subset_slice] = best_locations_sub\n all_best_covariances[subset_slice] = best_covariances_sub\n n_samples_merged = min(1500, n_samples)\n h_merged = int(np.ceil(n_samples_merged * (n_support / float(n_samples))))\n if n_samples > 1500:\n n_best_merged = 10\n else:\n n_best_merged = 1\n selection = random_state.permutation(n_samples)[:n_samples_merged]\n (locations_merged, covariances_merged, supports_merged, d) = select_candidates(X[selection], h_merged, n_trials=(all_best_locations, all_best_covariances), select=n_best_merged, cov_computation_method=cov_computation_method, random_state=random_state)\n if n_samples < 1500:\n location = locations_merged[0]\n covariance = covariances_merged[0]\n support = np.zeros(n_samples, dtype=bool)\n dist = np.zeros(n_samples)\n support[selection] = supports_merged[0]\n dist[selection] = d[0]\n else:\n (locations_full, covariances_full, supports_full, d) = select_candidates(X, n_support, n_trials=(locations_merged, covariances_merged), select=1, cov_computation_method=cov_computation_method, random_state=random_state)\n location = locations_full[0]\n covariance = covariances_full[0]\n support = supports_full[0]\n dist = d[0]\n elif n_features > 1:\n n_trials = 30\n n_best = 10\n (locations_best, covariances_best, _, _) = select_candidates(X, n_support, n_trials=n_trials, select=n_best, n_iter=2, cov_computation_method=cov_computation_method, random_state=random_state)\n (locations_full, covariances_full, supports_full, d) = select_candidates(X, n_support, n_trials=(locations_best, covariances_best), select=1, cov_computation_method=cov_computation_method, random_state=random_state)\n location = locations_full[0]\n covariance = covariances_full[0]\n support = supports_full[0]\n dist = d[0]\n return location, covariance, support, dist" }, { "name": "select_candidates", + "unique_name": "select_candidates", "qname": "sklearn.covariance._robust_covariance.select_candidates", + "unique_qname": "sklearn.covariance._robust_covariance.select_candidates", "decorators": [], "parameters": [ { @@ -40020,19 +40629,21 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "int, RandomState instance or None, default=None", - "description": "Determines the pseudo random number generator for shuffling the data.\nPass an int for reproducible results across multiple function calls.\nSee :term: `Glossary `." + "description": "Determines the pseudo random number generator for shuffling the data.\nPass an int for reproducible results across multiple function calls.\nSee :term:`Glossary `." } } ], "results": [], "is_public": false, "description": "Finds the best pure subset of observations to compute MCD from it.\n\nThe purpose of this function is to find the best sets of n_support observations with respect to a minimization of their covariance matrix determinant. Equivalently, it removes n_samples-n_support observations to construct what we call a pure data set (i.e. not containing outliers). The list of the observations of the pure data set is referred to as the `support`. Starting from a random support, the pure data set is found by the c_step procedure introduced by Rousseeuw and Van Driessen in [RV]_.", - "docstring": "Finds the best pure subset of observations to compute MCD from it.\n\nThe purpose of this function is to find the best sets of n_support\nobservations with respect to a minimization of their covariance\nmatrix determinant. Equivalently, it removes n_samples-n_support\nobservations to construct what we call a pure data set (i.e. not\ncontaining outliers). The list of the observations of the pure\ndata set is referred to as the `support`.\n\nStarting from a random support, the pure data set is found by the\nc_step procedure introduced by Rousseeuw and Van Driessen in\n[RV]_.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Data (sub)set in which we look for the n_support purest observations.\n\nn_support : int\n The number of samples the pure data set must contain.\n This parameter must be in the range `[(n + p + 1)/2] < n_support < n`.\n\nn_trials : int or tuple of shape (2,)\n Number of different initial sets of observations from which to\n run the algorithm. This parameter should be a strictly positive\n integer.\n Instead of giving a number of trials to perform, one can provide a\n list of initial estimates that will be used to iteratively run\n c_step procedures. In this case:\n - n_trials[0]: array-like, shape (n_trials, n_features)\n is the list of `n_trials` initial location estimates\n - n_trials[1]: array-like, shape (n_trials, n_features, n_features)\n is the list of `n_trials` initial covariances estimates\n\nselect : int, default=1\n Number of best candidates results to return. This parameter must be\n a strictly positive integer.\n\nn_iter : int, default=30\n Maximum number of iterations for the c_step procedure.\n (2 is enough to be close to the final solution. \"Never\" exceeds 20).\n This parameter must be a strictly positive integer.\n\nverbose : bool, default=False\n Control the output verbosity.\n\ncov_computation_method : callable, default=:func:`sklearn.covariance.empirical_covariance`\n The function which will be used to compute the covariance.\n Must return an array of shape (n_features, n_features).\n\nrandom_state : int, RandomState instance or None, default=None\n Determines the pseudo random number generator for shuffling the data.\n Pass an int for reproducible results across multiple function calls.\n See :term: `Glossary `.\n\nSee Also\n---------\nc_step\n\nReturns\n-------\nbest_locations : ndarray of shape (select, n_features)\n The `select` location estimates computed from the `select` best\n supports found in the data set (`X`).\n\nbest_covariances : ndarray of shape (select, n_features, n_features)\n The `select` covariance estimates computed from the `select`\n best supports found in the data set (`X`).\n\nbest_supports : ndarray of shape (select, n_samples)\n The `select` best supports found in the data set (`X`).\n\nReferences\n----------\n.. [RV] A Fast Algorithm for the Minimum Covariance Determinant\n Estimator, 1999, American Statistical Association and the American\n Society for Quality, TECHNOMETRICS", - "source_code": "\ndef select_candidates(X, n_support, n_trials, select=1, n_iter=30, verbose=False, cov_computation_method=empirical_covariance, random_state=None):\n \"\"\"Finds the best pure subset of observations to compute MCD from it.\n\n The purpose of this function is to find the best sets of n_support\n observations with respect to a minimization of their covariance\n matrix determinant. Equivalently, it removes n_samples-n_support\n observations to construct what we call a pure data set (i.e. not\n containing outliers). The list of the observations of the pure\n data set is referred to as the `support`.\n\n Starting from a random support, the pure data set is found by the\n c_step procedure introduced by Rousseeuw and Van Driessen in\n [RV]_.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Data (sub)set in which we look for the n_support purest observations.\n\n n_support : int\n The number of samples the pure data set must contain.\n This parameter must be in the range `[(n + p + 1)/2] < n_support < n`.\n\n n_trials : int or tuple of shape (2,)\n Number of different initial sets of observations from which to\n run the algorithm. This parameter should be a strictly positive\n integer.\n Instead of giving a number of trials to perform, one can provide a\n list of initial estimates that will be used to iteratively run\n c_step procedures. In this case:\n - n_trials[0]: array-like, shape (n_trials, n_features)\n is the list of `n_trials` initial location estimates\n - n_trials[1]: array-like, shape (n_trials, n_features, n_features)\n is the list of `n_trials` initial covariances estimates\n\n select : int, default=1\n Number of best candidates results to return. This parameter must be\n a strictly positive integer.\n\n n_iter : int, default=30\n Maximum number of iterations for the c_step procedure.\n (2 is enough to be close to the final solution. \"Never\" exceeds 20).\n This parameter must be a strictly positive integer.\n\n verbose : bool, default=False\n Control the output verbosity.\n\n cov_computation_method : callable, default=:func:`sklearn.covariance.empirical_covariance`\n The function which will be used to compute the covariance.\n Must return an array of shape (n_features, n_features).\n\n random_state : int, RandomState instance or None, default=None\n Determines the pseudo random number generator for shuffling the data.\n Pass an int for reproducible results across multiple function calls.\n See :term: `Glossary `.\n\n See Also\n ---------\n c_step\n\n Returns\n -------\n best_locations : ndarray of shape (select, n_features)\n The `select` location estimates computed from the `select` best\n supports found in the data set (`X`).\n\n best_covariances : ndarray of shape (select, n_features, n_features)\n The `select` covariance estimates computed from the `select`\n best supports found in the data set (`X`).\n\n best_supports : ndarray of shape (select, n_samples)\n The `select` best supports found in the data set (`X`).\n\n References\n ----------\n .. [RV] A Fast Algorithm for the Minimum Covariance Determinant\n Estimator, 1999, American Statistical Association and the American\n Society for Quality, TECHNOMETRICS\n \"\"\"\n random_state = check_random_state(random_state)\n if isinstance(n_trials, numbers.Integral):\n run_from_estimates = False\n elif isinstance(n_trials, tuple):\n run_from_estimates = True\n estimates_list = n_trials\n n_trials = estimates_list[0].shape[0]\n else:\n raise TypeError(\"Invalid 'n_trials' parameter, expected tuple or integer, got %s (%s)\" % (n_trials, type(n_trials)))\n all_estimates = []\n if not run_from_estimates:\n for j in range(n_trials):\n all_estimates.append(_c_step(X, n_support, remaining_iterations=n_iter, verbose=verbose, cov_computation_method=cov_computation_method, random_state=random_state))\n else:\n for j in range(n_trials):\n initial_estimates = (estimates_list[0][j], estimates_list[1][j])\n all_estimates.append(_c_step(X, n_support, remaining_iterations=n_iter, initial_estimates=initial_estimates, verbose=verbose, cov_computation_method=cov_computation_method, random_state=random_state))\n (all_locs_sub, all_covs_sub, all_dets_sub, all_supports_sub, all_ds_sub) = zip(*all_estimates)\n index_best = np.argsort(all_dets_sub)[:select]\n best_locations = np.asarray(all_locs_sub)[index_best]\n best_covariances = np.asarray(all_covs_sub)[index_best]\n best_supports = np.asarray(all_supports_sub)[index_best]\n best_ds = np.asarray(all_ds_sub)[index_best]\n return best_locations, best_covariances, best_supports, best_ds" + "docstring": "Finds the best pure subset of observations to compute MCD from it.\n\nThe purpose of this function is to find the best sets of n_support\nobservations with respect to a minimization of their covariance\nmatrix determinant. Equivalently, it removes n_samples-n_support\nobservations to construct what we call a pure data set (i.e. not\ncontaining outliers). The list of the observations of the pure\ndata set is referred to as the `support`.\n\nStarting from a random support, the pure data set is found by the\nc_step procedure introduced by Rousseeuw and Van Driessen in\n[RV]_.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Data (sub)set in which we look for the n_support purest observations.\n\nn_support : int\n The number of samples the pure data set must contain.\n This parameter must be in the range `[(n + p + 1)/2] < n_support < n`.\n\nn_trials : int or tuple of shape (2,)\n Number of different initial sets of observations from which to\n run the algorithm. This parameter should be a strictly positive\n integer.\n Instead of giving a number of trials to perform, one can provide a\n list of initial estimates that will be used to iteratively run\n c_step procedures. In this case:\n - n_trials[0]: array-like, shape (n_trials, n_features)\n is the list of `n_trials` initial location estimates\n - n_trials[1]: array-like, shape (n_trials, n_features, n_features)\n is the list of `n_trials` initial covariances estimates\n\nselect : int, default=1\n Number of best candidates results to return. This parameter must be\n a strictly positive integer.\n\nn_iter : int, default=30\n Maximum number of iterations for the c_step procedure.\n (2 is enough to be close to the final solution. \"Never\" exceeds 20).\n This parameter must be a strictly positive integer.\n\nverbose : bool, default=False\n Control the output verbosity.\n\ncov_computation_method : callable, default=:func:`sklearn.covariance.empirical_covariance`\n The function which will be used to compute the covariance.\n Must return an array of shape (n_features, n_features).\n\nrandom_state : int, RandomState instance or None, default=None\n Determines the pseudo random number generator for shuffling the data.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\nSee Also\n---------\nc_step\n\nReturns\n-------\nbest_locations : ndarray of shape (select, n_features)\n The `select` location estimates computed from the `select` best\n supports found in the data set (`X`).\n\nbest_covariances : ndarray of shape (select, n_features, n_features)\n The `select` covariance estimates computed from the `select`\n best supports found in the data set (`X`).\n\nbest_supports : ndarray of shape (select, n_samples)\n The `select` best supports found in the data set (`X`).\n\nReferences\n----------\n.. [RV] A Fast Algorithm for the Minimum Covariance Determinant\n Estimator, 1999, American Statistical Association and the American\n Society for Quality, TECHNOMETRICS", + "source_code": "\ndef select_candidates(X, n_support, n_trials, select=1, n_iter=30, verbose=False, cov_computation_method=empirical_covariance, random_state=None):\n \"\"\"Finds the best pure subset of observations to compute MCD from it.\n\n The purpose of this function is to find the best sets of n_support\n observations with respect to a minimization of their covariance\n matrix determinant. Equivalently, it removes n_samples-n_support\n observations to construct what we call a pure data set (i.e. not\n containing outliers). The list of the observations of the pure\n data set is referred to as the `support`.\n\n Starting from a random support, the pure data set is found by the\n c_step procedure introduced by Rousseeuw and Van Driessen in\n [RV]_.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Data (sub)set in which we look for the n_support purest observations.\n\n n_support : int\n The number of samples the pure data set must contain.\n This parameter must be in the range `[(n + p + 1)/2] < n_support < n`.\n\n n_trials : int or tuple of shape (2,)\n Number of different initial sets of observations from which to\n run the algorithm. This parameter should be a strictly positive\n integer.\n Instead of giving a number of trials to perform, one can provide a\n list of initial estimates that will be used to iteratively run\n c_step procedures. In this case:\n - n_trials[0]: array-like, shape (n_trials, n_features)\n is the list of `n_trials` initial location estimates\n - n_trials[1]: array-like, shape (n_trials, n_features, n_features)\n is the list of `n_trials` initial covariances estimates\n\n select : int, default=1\n Number of best candidates results to return. This parameter must be\n a strictly positive integer.\n\n n_iter : int, default=30\n Maximum number of iterations for the c_step procedure.\n (2 is enough to be close to the final solution. \"Never\" exceeds 20).\n This parameter must be a strictly positive integer.\n\n verbose : bool, default=False\n Control the output verbosity.\n\n cov_computation_method : callable, default=:func:`sklearn.covariance.empirical_covariance`\n The function which will be used to compute the covariance.\n Must return an array of shape (n_features, n_features).\n\n random_state : int, RandomState instance or None, default=None\n Determines the pseudo random number generator for shuffling the data.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n See Also\n ---------\n c_step\n\n Returns\n -------\n best_locations : ndarray of shape (select, n_features)\n The `select` location estimates computed from the `select` best\n supports found in the data set (`X`).\n\n best_covariances : ndarray of shape (select, n_features, n_features)\n The `select` covariance estimates computed from the `select`\n best supports found in the data set (`X`).\n\n best_supports : ndarray of shape (select, n_samples)\n The `select` best supports found in the data set (`X`).\n\n References\n ----------\n .. [RV] A Fast Algorithm for the Minimum Covariance Determinant\n Estimator, 1999, American Statistical Association and the American\n Society for Quality, TECHNOMETRICS\n \"\"\"\n random_state = check_random_state(random_state)\n if isinstance(n_trials, numbers.Integral):\n run_from_estimates = False\n elif isinstance(n_trials, tuple):\n run_from_estimates = True\n estimates_list = n_trials\n n_trials = estimates_list[0].shape[0]\n else:\n raise TypeError(\"Invalid 'n_trials' parameter, expected tuple or integer, got %s (%s)\" % (n_trials, type(n_trials)))\n all_estimates = []\n if not run_from_estimates:\n for j in range(n_trials):\n all_estimates.append(_c_step(X, n_support, remaining_iterations=n_iter, verbose=verbose, cov_computation_method=cov_computation_method, random_state=random_state))\n else:\n for j in range(n_trials):\n initial_estimates = (estimates_list[0][j], estimates_list[1][j])\n all_estimates.append(_c_step(X, n_support, remaining_iterations=n_iter, initial_estimates=initial_estimates, verbose=verbose, cov_computation_method=cov_computation_method, random_state=random_state))\n (all_locs_sub, all_covs_sub, all_dets_sub, all_supports_sub, all_ds_sub) = zip(*all_estimates)\n index_best = np.argsort(all_dets_sub)[:select]\n best_locations = np.asarray(all_locs_sub)[index_best]\n best_covariances = np.asarray(all_covs_sub)[index_best]\n best_supports = np.asarray(all_supports_sub)[index_best]\n best_ds = np.asarray(all_ds_sub)[index_best]\n return best_locations, best_covariances, best_supports, best_ds" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.covariance._shrunk_covariance.LedoitWolf.__init__", + "unique_qname": "sklearn.covariance._shrunk_covariance.LedoitWolf.__init__", "decorators": [], "parameters": [ { @@ -40084,7 +40695,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.covariance._shrunk_covariance.LedoitWolf.fit", + "unique_qname": "sklearn.covariance._shrunk_covariance.LedoitWolf.fit", "decorators": [], "parameters": [ { @@ -40126,7 +40739,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.covariance._shrunk_covariance.OAS.fit", + "unique_qname": "sklearn.covariance._shrunk_covariance.OAS.fit", "decorators": [], "parameters": [ { @@ -40168,7 +40783,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.covariance._shrunk_covariance.ShrunkCovariance.__init__", + "unique_qname": "sklearn.covariance._shrunk_covariance.ShrunkCovariance.__init__", "decorators": [], "parameters": [ { @@ -40220,7 +40837,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.covariance._shrunk_covariance.ShrunkCovariance.fit", + "unique_qname": "sklearn.covariance._shrunk_covariance.ShrunkCovariance.fit", "decorators": [], "parameters": [ { @@ -40262,7 +40881,9 @@ }, { "name": "ledoit_wolf", + "unique_name": "ledoit_wolf", "qname": "sklearn.covariance._shrunk_covariance.ledoit_wolf", + "unique_qname": "sklearn.covariance._shrunk_covariance.ledoit_wolf", "decorators": [], "parameters": [ { @@ -40304,7 +40925,9 @@ }, { "name": "ledoit_wolf_shrinkage", + "unique_name": "ledoit_wolf_shrinkage", "qname": "sklearn.covariance._shrunk_covariance.ledoit_wolf_shrinkage", + "unique_qname": "sklearn.covariance._shrunk_covariance.ledoit_wolf_shrinkage", "decorators": [], "parameters": [ { @@ -40346,7 +40969,9 @@ }, { "name": "oas", + "unique_name": "oas", "qname": "sklearn.covariance._shrunk_covariance.oas", + "unique_qname": "sklearn.covariance._shrunk_covariance.oas", "decorators": [], "parameters": [ { @@ -40378,7 +41003,9 @@ }, { "name": "shrunk_covariance", + "unique_name": "shrunk_covariance", "qname": "sklearn.covariance._shrunk_covariance.shrunk_covariance", + "unique_qname": "sklearn.covariance._shrunk_covariance.shrunk_covariance", "decorators": [], "parameters": [ { @@ -40410,7 +41037,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.cross_decomposition._pls.CCA.__init__", + "unique_qname": "sklearn.cross_decomposition._pls.CCA.__init__", "decorators": [], "parameters": [ { @@ -40482,7 +41111,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.cross_decomposition._pls.PLSCanonical.__init__", + "unique_qname": "sklearn.cross_decomposition._pls.PLSCanonical.__init__", "decorators": [], "parameters": [ { @@ -40532,7 +41163,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int, default=500", - "description": "the maximum number of iterations of the power method when\n`algorithm='nipals'`. Ignored otherwise." + "description": "The maximum number of iterations of the power method when\n`algorithm='nipals'`. Ignored otherwise." } }, { @@ -40564,7 +41195,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.cross_decomposition._pls.PLSRegression.__init__", + "unique_qname": "sklearn.cross_decomposition._pls.PLSRegression.__init__", "decorators": [], "parameters": [ { @@ -40624,7 +41257,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "bool, default=True", - "description": "Whether to copy `X` and `Y` in fit before applying centering, and\npotentially scaling. If False, these operations will be done inplace,\nmodifying both arrays." + "description": "Whether to copy `X` and `Y` in :term:`fit` before applying centering,\nand potentially scaling. If `False`, these operations will be done\ninplace, modifying both arrays." } } ], @@ -40636,7 +41269,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.cross_decomposition._pls.PLSSVD.__init__", + "unique_qname": "sklearn.cross_decomposition._pls.PLSSVD.__init__", "decorators": [], "parameters": [ { @@ -40676,7 +41311,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "bool, default=True", - "description": "Whether to copy `X` and `Y` in fit before applying centering, and\npotentially scaling. If False, these operations will be done inplace,\nmodifying both arrays." + "description": "Whether to copy `X` and `Y` in fit before applying centering, and\npotentially scaling. If `False`, these operations will be done inplace,\nmodifying both arrays." } } ], @@ -40688,7 +41323,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.cross_decomposition._pls.PLSSVD.fit", + "unique_qname": "sklearn.cross_decomposition._pls.PLSSVD.fit", "decorators": [], "parameters": [ { @@ -40725,12 +41362,14 @@ "results": [], "is_public": true, "description": "Fit model to data.", - "docstring": "Fit model to data.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Training samples.\n\nY : array-like of shape (n_samples,) or (n_samples, n_targets)\n Targets.", - "source_code": "\ndef fit(self, X, Y):\n \"\"\"Fit model to data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training samples.\n\n Y : array-like of shape (n_samples,) or (n_samples, n_targets)\n Targets.\n \"\"\"\n check_consistent_length(X, Y)\n X = self._validate_data(X, dtype=np.float64, copy=self.copy, ensure_min_samples=2)\n Y = check_array(Y, dtype=np.float64, copy=self.copy, ensure_2d=False)\n if Y.ndim == 1:\n Y = Y.reshape(-1, 1)\n n_components = self.n_components\n rank_upper_bound = min(X.shape[0], X.shape[1], Y.shape[1])\n if not 1 <= n_components <= rank_upper_bound:\n warnings.warn(f'As of version 0.24, n_components({n_components}) should be in [1, min(n_features, n_samples, n_targets)] = [1, {rank_upper_bound}]. n_components={rank_upper_bound} will be used instead. In version 1.1 (renaming of 0.26), an error will be raised.', FutureWarning)\n n_components = rank_upper_bound\n (X, Y, self._x_mean, self._y_mean, self._x_std, self._y_std) = _center_scale_xy(X, Y, self.scale)\n C = np.dot(X.T, Y)\n (U, s, Vt) = svd(C, full_matrices=False)\n U = U[:, :n_components]\n Vt = Vt[:n_components]\n (U, Vt) = svd_flip(U, Vt)\n V = Vt.T\n self._x_scores = np.dot(X, U)\n self._y_scores = np.dot(Y, V)\n self.x_weights_ = U\n self.y_weights_ = V\n return self" + "docstring": "Fit model to data.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Training samples.\n\nY : array-like of shape (n_samples,) or (n_samples, n_targets)\n Targets.\n\nReturns\n-------\nself : object\n Fitted estimator.", + "source_code": "\ndef fit(self, X, Y):\n \"\"\"Fit model to data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training samples.\n\n Y : array-like of shape (n_samples,) or (n_samples, n_targets)\n Targets.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n check_consistent_length(X, Y)\n X = self._validate_data(X, dtype=np.float64, copy=self.copy, ensure_min_samples=2)\n Y = check_array(Y, dtype=np.float64, copy=self.copy, ensure_2d=False)\n if Y.ndim == 1:\n Y = Y.reshape(-1, 1)\n n_components = self.n_components\n rank_upper_bound = min(X.shape[0], X.shape[1], Y.shape[1])\n if not 1 <= n_components <= rank_upper_bound:\n warnings.warn(f'As of version 0.24, n_components({n_components}) should be in [1, min(n_features, n_samples, n_targets)] = [1, {rank_upper_bound}]. n_components={rank_upper_bound} will be used instead. In version 1.1 (renaming of 0.26), an error will be raised.', FutureWarning)\n n_components = rank_upper_bound\n (X, Y, self._x_mean, self._y_mean, self._x_std, self._y_std) = _center_scale_xy(X, Y, self.scale)\n C = np.dot(X.T, Y)\n (U, s, Vt) = svd(C, full_matrices=False)\n U = U[:, :n_components]\n Vt = Vt[:n_components]\n (U, Vt) = svd_flip(U, Vt)\n V = Vt.T\n self._x_scores = np.dot(X, U)\n self._y_scores = np.dot(Y, V)\n self.x_weights_ = U\n self.y_weights_ = V\n return self" }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.cross_decomposition._pls.PLSSVD.fit_transform", + "unique_qname": "sklearn.cross_decomposition._pls.PLSSVD.fit_transform", "decorators": [], "parameters": [ { @@ -40767,12 +41406,14 @@ "results": [], "is_public": true, "description": "Learn and apply the dimensionality reduction.", - "docstring": "Learn and apply the dimensionality reduction.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Training samples.\n\ny : array-like of shape (n_samples,) or (n_samples, n_targets), default=None\n Targets.\n\nReturns\n-------\nout : array-like or tuple of array-like\n The transformed data `X_tranformed` if `Y` is not None,\n `(X_transformed, Y_transformed)` otherwise.", - "source_code": "\ndef fit_transform(self, X, y=None):\n \"\"\"Learn and apply the dimensionality reduction.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training samples.\n\n y : array-like of shape (n_samples,) or (n_samples, n_targets), default=None\n Targets.\n\n Returns\n -------\n out : array-like or tuple of array-like\n The transformed data `X_tranformed` if `Y` is not None,\n `(X_transformed, Y_transformed)` otherwise.\n \"\"\"\n return self.fit(X, y).transform(X, y)" + "docstring": "Learn and apply the dimensionality reduction.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Training samples.\n\ny : array-like of shape (n_samples,) or (n_samples, n_targets), default=None\n Targets.\n\nReturns\n-------\nout : array-like or tuple of array-like\n The transformed data `X_tranformed` if `Y is not None`,\n `(X_transformed, Y_transformed)` otherwise.", + "source_code": "\ndef fit_transform(self, X, y=None):\n \"\"\"Learn and apply the dimensionality reduction.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training samples.\n\n y : array-like of shape (n_samples,) or (n_samples, n_targets), default=None\n Targets.\n\n Returns\n -------\n out : array-like or tuple of array-like\n The transformed data `X_tranformed` if `Y is not None`,\n `(X_transformed, Y_transformed)` otherwise.\n \"\"\"\n return self.fit(X, y).transform(X, y)" }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.cross_decomposition._pls.PLSSVD.transform", + "unique_qname": "sklearn.cross_decomposition._pls.PLSSVD.transform", "decorators": [], "parameters": [ { @@ -40809,12 +41450,14 @@ "results": [], "is_public": true, "description": "Apply the dimensionality reduction.", - "docstring": "Apply the dimensionality reduction.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Samples to be transformed.\n\nY : array-like of shape (n_samples,) or (n_samples, n_targets), default=None\n Targets.\n\nReturns\n-------\nx_scores : array-like or tuple of array-like\n The transformed data `X_tranformed` if `Y` is not None,\n `(X_transformed, Y_transformed)` otherwise.", - "source_code": "\ndef transform(self, X, Y=None):\n \"\"\"\n Apply the dimensionality reduction.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Samples to be transformed.\n\n Y : array-like of shape (n_samples,) or (n_samples, n_targets), default=None\n Targets.\n\n Returns\n -------\n x_scores : array-like or tuple of array-like\n The transformed data `X_tranformed` if `Y` is not None,\n `(X_transformed, Y_transformed)` otherwise.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, dtype=np.float64, reset=False)\n Xr = (X - self._x_mean) / self._x_std\n x_scores = np.dot(Xr, self.x_weights_)\n if Y is not None:\n Y = check_array(Y, ensure_2d=False, dtype=np.float64)\n if Y.ndim == 1:\n Y = Y.reshape(-1, 1)\n Yr = (Y - self._y_mean) / self._y_std\n y_scores = np.dot(Yr, self.y_weights_)\n return x_scores, y_scores\n return x_scores" + "docstring": "Apply the dimensionality reduction.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Samples to be transformed.\n\nY : array-like of shape (n_samples,) or (n_samples, n_targets), default=None\n Targets.\n\nReturns\n-------\nx_scores : array-like or tuple of array-like\n The transformed data `X_tranformed` if `Y is not None`,\n `(X_transformed, Y_transformed)` otherwise.", + "source_code": "\ndef transform(self, X, Y=None):\n \"\"\"\n Apply the dimensionality reduction.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Samples to be transformed.\n\n Y : array-like of shape (n_samples,) or (n_samples, n_targets), default=None\n Targets.\n\n Returns\n -------\n x_scores : array-like or tuple of array-like\n The transformed data `X_tranformed` if `Y is not None`,\n `(X_transformed, Y_transformed)` otherwise.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, dtype=np.float64, reset=False)\n Xr = (X - self._x_mean) / self._x_std\n x_scores = np.dot(Xr, self.x_weights_)\n if Y is not None:\n Y = check_array(Y, ensure_2d=False, dtype=np.float64)\n if Y.ndim == 1:\n Y = Y.reshape(-1, 1)\n Yr = (Y - self._y_mean) / self._y_std\n y_scores = np.dot(Yr, self.y_weights_)\n return x_scores, y_scores\n return x_scores" }, { "name": "x_mean_", + "unique_name": "x_mean_@getter", "qname": "sklearn.cross_decomposition._pls.PLSSVD.x_mean_", + "unique_qname": "sklearn.cross_decomposition._pls.PLSSVD.x_mean_@getter", "decorators": [ "deprecated('Attribute `x_mean_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -40839,7 +41482,9 @@ }, { "name": "x_scores_", + "unique_name": "x_scores_@getter", "qname": "sklearn.cross_decomposition._pls.PLSSVD.x_scores_", + "unique_qname": "sklearn.cross_decomposition._pls.PLSSVD.x_scores_@getter", "decorators": [ "deprecated('Attribute `x_scores_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26). Use est.transform(X) on the training data instead.')", "property" @@ -40864,7 +41509,9 @@ }, { "name": "x_std_", + "unique_name": "x_std_@getter", "qname": "sklearn.cross_decomposition._pls.PLSSVD.x_std_", + "unique_qname": "sklearn.cross_decomposition._pls.PLSSVD.x_std_@getter", "decorators": [ "deprecated('Attribute `x_std_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -40889,7 +41536,9 @@ }, { "name": "y_mean_", + "unique_name": "y_mean_@getter", "qname": "sklearn.cross_decomposition._pls.PLSSVD.y_mean_", + "unique_qname": "sklearn.cross_decomposition._pls.PLSSVD.y_mean_@getter", "decorators": [ "deprecated('Attribute `y_mean_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -40914,7 +41563,9 @@ }, { "name": "y_scores_", + "unique_name": "y_scores_@getter", "qname": "sklearn.cross_decomposition._pls.PLSSVD.y_scores_", + "unique_qname": "sklearn.cross_decomposition._pls.PLSSVD.y_scores_@getter", "decorators": [ "deprecated('Attribute `y_scores_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26). Use est.transform(X, Y) on the training data instead.')", "property" @@ -40939,7 +41590,9 @@ }, { "name": "y_std_", + "unique_name": "y_std_@getter", "qname": "sklearn.cross_decomposition._pls.PLSSVD.y_std_", + "unique_qname": "sklearn.cross_decomposition._pls.PLSSVD.y_std_@getter", "decorators": [ "deprecated('Attribute `y_std_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -40964,7 +41617,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.cross_decomposition._pls._PLS.__init__", + "unique_qname": "sklearn.cross_decomposition._pls._PLS.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -41066,7 +41721,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.cross_decomposition._pls._PLS._more_tags", + "unique_qname": "sklearn.cross_decomposition._pls._PLS._more_tags", "decorators": [], "parameters": [ { @@ -41088,7 +41745,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.cross_decomposition._pls._PLS.fit", + "unique_qname": "sklearn.cross_decomposition._pls._PLS.fit", "decorators": [], "parameters": [ { @@ -41130,7 +41789,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.cross_decomposition._pls._PLS.fit_transform", + "unique_qname": "sklearn.cross_decomposition._pls._PLS.fit_transform", "decorators": [], "parameters": [ { @@ -41172,7 +41833,9 @@ }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.cross_decomposition._pls._PLS.inverse_transform", + "unique_qname": "sklearn.cross_decomposition._pls._PLS.inverse_transform", "decorators": [], "parameters": [ { @@ -41204,7 +41867,9 @@ }, { "name": "norm_y_weights", + "unique_name": "norm_y_weights@getter", "qname": "sklearn.cross_decomposition._pls._PLS.norm_y_weights", + "unique_qname": "sklearn.cross_decomposition._pls._PLS.norm_y_weights@getter", "decorators": [ "deprecated('Attribute `norm_y_weights` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -41229,7 +41894,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.cross_decomposition._pls._PLS.predict", + "unique_qname": "sklearn.cross_decomposition._pls._PLS.predict", "decorators": [], "parameters": [ { @@ -41271,7 +41938,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.cross_decomposition._pls._PLS.transform", + "unique_qname": "sklearn.cross_decomposition._pls._PLS.transform", "decorators": [], "parameters": [ { @@ -41323,7 +41992,9 @@ }, { "name": "x_mean_", + "unique_name": "x_mean_@getter", "qname": "sklearn.cross_decomposition._pls._PLS.x_mean_", + "unique_qname": "sklearn.cross_decomposition._pls._PLS.x_mean_@getter", "decorators": [ "deprecated('Attribute `x_mean_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -41348,7 +42019,9 @@ }, { "name": "x_scores_", + "unique_name": "x_scores_@getter", "qname": "sklearn.cross_decomposition._pls._PLS.x_scores_", + "unique_qname": "sklearn.cross_decomposition._pls._PLS.x_scores_@getter", "decorators": ["property"], "parameters": [ { @@ -41370,7 +42043,9 @@ }, { "name": "x_std_", + "unique_name": "x_std_@getter", "qname": "sklearn.cross_decomposition._pls._PLS.x_std_", + "unique_qname": "sklearn.cross_decomposition._pls._PLS.x_std_@getter", "decorators": [ "deprecated('Attribute `x_std_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -41395,7 +42070,9 @@ }, { "name": "y_mean_", + "unique_name": "y_mean_@getter", "qname": "sklearn.cross_decomposition._pls._PLS.y_mean_", + "unique_qname": "sklearn.cross_decomposition._pls._PLS.y_mean_@getter", "decorators": [ "deprecated('Attribute `y_mean_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -41420,7 +42097,9 @@ }, { "name": "y_scores_", + "unique_name": "y_scores_@getter", "qname": "sklearn.cross_decomposition._pls._PLS.y_scores_", + "unique_qname": "sklearn.cross_decomposition._pls._PLS.y_scores_@getter", "decorators": ["property"], "parameters": [ { @@ -41442,7 +42121,9 @@ }, { "name": "y_std_", + "unique_name": "y_std_@getter", "qname": "sklearn.cross_decomposition._pls._PLS.y_std_", + "unique_qname": "sklearn.cross_decomposition._pls._PLS.y_std_@getter", "decorators": [ "deprecated('Attribute `y_std_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -41467,7 +42148,9 @@ }, { "name": "_center_scale_xy", + "unique_name": "_center_scale_xy", "qname": "sklearn.cross_decomposition._pls._center_scale_xy", + "unique_qname": "sklearn.cross_decomposition._pls._center_scale_xy", "decorators": [], "parameters": [ { @@ -41509,7 +42192,9 @@ }, { "name": "_get_first_singular_vectors_power_method", + "unique_name": "_get_first_singular_vectors_power_method", "qname": "sklearn.cross_decomposition._pls._get_first_singular_vectors_power_method", + "unique_qname": "sklearn.cross_decomposition._pls._get_first_singular_vectors_power_method", "decorators": [], "parameters": [ { @@ -41581,7 +42266,9 @@ }, { "name": "_get_first_singular_vectors_svd", + "unique_name": "_get_first_singular_vectors_svd", "qname": "sklearn.cross_decomposition._pls._get_first_singular_vectors_svd", + "unique_qname": "sklearn.cross_decomposition._pls._get_first_singular_vectors_svd", "decorators": [], "parameters": [ { @@ -41613,7 +42300,9 @@ }, { "name": "_pinv2_old", + "unique_name": "_pinv2_old", "qname": "sklearn.cross_decomposition._pls._pinv2_old", + "unique_qname": "sklearn.cross_decomposition._pls._pinv2_old", "decorators": [], "parameters": [ { @@ -41635,7 +42324,9 @@ }, { "name": "_svd_flip_1d", + "unique_name": "_svd_flip_1d", "qname": "sklearn.cross_decomposition._pls._svd_flip_1d", + "unique_qname": "sklearn.cross_decomposition._pls._svd_flip_1d", "decorators": [], "parameters": [ { @@ -41667,7 +42358,9 @@ }, { "name": "_convert_data_dataframe", + "unique_name": "_convert_data_dataframe", "qname": "sklearn.datasets._base._convert_data_dataframe", + "unique_qname": "sklearn.datasets._base._convert_data_dataframe", "decorators": [], "parameters": [ { @@ -41739,7 +42432,9 @@ }, { "name": "_fetch_remote", + "unique_name": "_fetch_remote", "qname": "sklearn.datasets._base._fetch_remote", + "unique_qname": "sklearn.datasets._base._fetch_remote", "decorators": [], "parameters": [ { @@ -41771,7 +42466,9 @@ }, { "name": "_pkl_filepath", + "unique_name": "_pkl_filepath", "qname": "sklearn.datasets._base._pkl_filepath", + "unique_qname": "sklearn.datasets._base._pkl_filepath", "decorators": [], "parameters": [], "results": [], @@ -41782,7 +42479,9 @@ }, { "name": "_sha256", + "unique_name": "_sha256", "qname": "sklearn.datasets._base._sha256", + "unique_qname": "sklearn.datasets._base._sha256", "decorators": [], "parameters": [ { @@ -41804,7 +42503,9 @@ }, { "name": "clear_data_home", + "unique_name": "clear_data_home", "qname": "sklearn.datasets._base.clear_data_home", + "unique_qname": "sklearn.datasets._base.clear_data_home", "decorators": [], "parameters": [ { @@ -41826,7 +42527,9 @@ }, { "name": "get_data_home", + "unique_name": "get_data_home", "qname": "sklearn.datasets._base.get_data_home", + "unique_qname": "sklearn.datasets._base.get_data_home", "decorators": [], "parameters": [ { @@ -41848,9 +42551,11 @@ }, { "name": "load_boston", + "unique_name": "load_boston", "qname": "sklearn.datasets._base.load_boston", + "unique_qname": "sklearn.datasets._base.load_boston", "decorators": [ - "deprecated('`load_boston` is deprecated in 1.0 and will be removed in 1.2.\\n\\n The Boston housing prices dataset has an ethical problem. You can refer to\\n the documentation of this function for further details.\\n\\n The scikit-learn maintainers therefore strongly discourage the use of this\\n dataset unless the purpose of the code is to study and educate about\\n ethical issues in data science and machine learning.\\n\\n In this case special case, you can fetch the dataset from the original\\n source::\\n\\n import pandas as pd\\n import numpy as np\\n\\n\\n data_url = \"http://lib.stat.cmu.edu/datasets/boston\"\\n raw_df = pd.read_csv(data_url, sep=\"\\\\s+\", skiprows=22, header=None)\\n data = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]])\\n target = raw_df.values[1::2, 2]\\n\\n Alternative datasets include the California housing dataset (i.e.\\n func:`~sklearn.datasets.fetch_california_housing`) and the Ames housing\\n dataset. You can load the datasets as follows:\\n\\n from sklearn.datasets import fetch_california_housing\\n housing = fetch_california_housing()\\n\\n for the California housing dataset and:\\n\\n from sklearn.datasets import fetch_openml\\n housing = fetch_openml(name=\"house_prices\", as_frame=True)\\n\\n for the Ames housing dataset.\\n ')" + "deprecated('`load_boston` is deprecated in 1.0 and will be removed in 1.2.\\n\\n The Boston housing prices dataset has an ethical problem. You can refer to\\n the documentation of this function for further details.\\n\\n The scikit-learn maintainers therefore strongly discourage the use of this\\n dataset unless the purpose of the code is to study and educate about\\n ethical issues in data science and machine learning.\\n\\n In this special case, you can fetch the dataset from the original\\n source::\\n\\n import pandas as pd\\n import numpy as np\\n\\n\\n data_url = \"http://lib.stat.cmu.edu/datasets/boston\"\\n raw_df = pd.read_csv(data_url, sep=\"\\\\s+\", skiprows=22, header=None)\\n data = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]])\\n target = raw_df.values[1::2, 2]\\n\\n Alternative datasets include the California housing dataset (i.e.\\n :func:`~sklearn.datasets.fetch_california_housing`) and the Ames housing\\n dataset. You can load the datasets as follows::\\n\\n from sklearn.datasets import fetch_california_housing\\n housing = fetch_california_housing()\\n\\n for the California housing dataset and::\\n\\n from sklearn.datasets import fetch_openml\\n housing = fetch_openml(name=\"house_prices\", as_frame=True)\\n\\n for the Ames housing dataset.\\n ')" ], "parameters": [ { @@ -41866,13 +42571,15 @@ ], "results": [], "is_public": true, - "description": "Load and return the boston house-prices dataset (regression).\n\n============== ============== Samples total 506 Dimensionality 13 Features real, positive Targets real 5. - 50. ============== ============== Read more in the :ref:`User Guide `. .. deprecated:: 1.0 This function is deprecated in 1.0 and will be removed in 1.2. See the warning message below for further details regarding the alternative datasets. .. warning:: The Boston housing prices dataset has an ethical problem: as investigated in [1]_, the authors of this dataset engineered a non-invertible variable \"B\" assuming that racial self-segregation had a positive impact on house prices [2]_. Furthermore the goal of the research that led to the creation of this dataset was to study the impact of air quality but it did not give adequate demonstration of the validity of this assumption. The scikit-learn maintainers therefore strongly discourage the use of this dataset unless the purpose of the code is to study and educate about ethical issues in data science and machine learning. In this case special case, you can fetch the dataset from the original source:: import pandas as pd # doctest: +SKIP import numpy as np data_url = \"http://lib.stat.cmu.edu/datasets/boston\" raw_df = pd.read_csv(data_url, sep=\"s+\", skiprows=22, header=None) data = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]]) target = raw_df.values[1::2, 2] Alternative datasets include the California housing dataset [3]_ (i.e. func:`~sklearn.datasets.fetch_california_housing`) and Ames housing dataset [4]_. You can load the datasets as follows:: from sklearn.datasets import fetch_california_housing housing = fetch_california_housing() for the California housing dataset and:: from sklearn.datasets import fetch_openml housing = fetch_openml(name=\"house_prices\", as_frame=True) # noqa for the Ames housing dataset.", - "docstring": "Load and return the boston house-prices dataset (regression).\n\n============== ==============\nSamples total 506\nDimensionality 13\nFeatures real, positive\nTargets real 5. - 50.\n============== ==============\n\nRead more in the :ref:`User Guide `.\n\n.. deprecated:: 1.0\n This function is deprecated in 1.0 and will be removed in 1.2. See the\n warning message below for further details regarding the alternative\n datasets.\n\n.. warning::\n The Boston housing prices dataset has an ethical problem: as\n investigated in [1]_, the authors of this dataset engineered a\n non-invertible variable \"B\" assuming that racial self-segregation had a\n positive impact on house prices [2]_. Furthermore the goal of the\n research that led to the creation of this dataset was to study the\n impact of air quality but it did not give adequate demonstration of the\n validity of this assumption.\n\n The scikit-learn maintainers therefore strongly discourage the use of\n this dataset unless the purpose of the code is to study and educate\n about ethical issues in data science and machine learning.\n\n In this case special case, you can fetch the dataset from the original\n source::\n\n import pandas as pd # doctest: +SKIP\n import numpy as np\n\n\n data_url = \"http://lib.stat.cmu.edu/datasets/boston\"\n raw_df = pd.read_csv(data_url, sep=\"s+\", skiprows=22, header=None)\n data = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]])\n target = raw_df.values[1::2, 2]\n\n Alternative datasets include the California housing dataset [3]_\n (i.e. func:`~sklearn.datasets.fetch_california_housing`) and Ames\n housing dataset [4]_. You can load the datasets as follows::\n\n from sklearn.datasets import fetch_california_housing\n housing = fetch_california_housing()\n\n for the California housing dataset and::\n\n from sklearn.datasets import fetch_openml\n housing = fetch_openml(name=\"house_prices\", as_frame=True) # noqa\n\n for the Ames housing dataset.\n\nParameters\n----------\nreturn_X_y : bool, default=False\n If True, returns ``(data, target)`` instead of a Bunch object.\n See below for more information about the `data` and `target` object.\n\n .. versionadded:: 0.18\n\nReturns\n-------\ndata : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data : ndarray of shape (506, 13)\n The data matrix.\n target : ndarray of shape (506,)\n The regression target.\n filename : str\n The physical location of boston csv dataset.\n\n .. versionadded:: 0.20\n\n DESCR : str\n The full description of the dataset.\n feature_names : ndarray\n The names of features\n\n(data, target) : tuple if ``return_X_y`` is True\n\n .. versionadded:: 0.18\n\nNotes\n-----\n .. versionchanged:: 0.20\n Fixed a wrong data point at [445, 0].\n\nReferences\n----------\n.. [1] `Racist data destruction? M Carlisle,\n `_\n.. [2] `Harrison Jr, David, and Daniel L. Rubinfeld.\n \"Hedonic housing prices and the demand for clean air.\"\n Journal of environmental economics and management 5.1 (1978): 81-102.\n `_\n.. [3] `California housing dataset\n `_\n.. [4] `Ames housing dataset\n `_\n\nExamples\n--------\n>>> import warnings\n>>> from sklearn.datasets import load_boston\n>>> with warnings.catch_warnings():\n... # You should probably not use this dataset.\n... warnings.filterwarnings(\"ignore\")\n... X, y = load_boston(return_X_y=True)\n>>> print(X.shape)\n(506, 13)", - "source_code": "\n@deprecated('`load_boston` is deprecated in 1.0 and will be removed in 1.2.\\n\\n The Boston housing prices dataset has an ethical problem. You can refer to\\n the documentation of this function for further details.\\n\\n The scikit-learn maintainers therefore strongly discourage the use of this\\n dataset unless the purpose of the code is to study and educate about\\n ethical issues in data science and machine learning.\\n\\n In this case special case, you can fetch the dataset from the original\\n source::\\n\\n import pandas as pd\\n import numpy as np\\n\\n\\n data_url = \"http://lib.stat.cmu.edu/datasets/boston\"\\n raw_df = pd.read_csv(data_url, sep=\"\\\\s+\", skiprows=22, header=None)\\n data = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]])\\n target = raw_df.values[1::2, 2]\\n\\n Alternative datasets include the California housing dataset (i.e.\\n func:`~sklearn.datasets.fetch_california_housing`) and the Ames housing\\n dataset. You can load the datasets as follows:\\n\\n from sklearn.datasets import fetch_california_housing\\n housing = fetch_california_housing()\\n\\n for the California housing dataset and:\\n\\n from sklearn.datasets import fetch_openml\\n housing = fetch_openml(name=\"house_prices\", as_frame=True)\\n\\n for the Ames housing dataset.\\n ')\ndef load_boston(*, return_X_y=False):\n \"\"\"Load and return the boston house-prices dataset (regression).\n\n ============== ==============\n Samples total 506\n Dimensionality 13\n Features real, positive\n Targets real 5. - 50.\n ============== ==============\n\n Read more in the :ref:`User Guide `.\n\n .. deprecated:: 1.0\n This function is deprecated in 1.0 and will be removed in 1.2. See the\n warning message below for further details regarding the alternative\n datasets.\n\n .. warning::\n The Boston housing prices dataset has an ethical problem: as\n investigated in [1]_, the authors of this dataset engineered a\n non-invertible variable \"B\" assuming that racial self-segregation had a\n positive impact on house prices [2]_. Furthermore the goal of the\n research that led to the creation of this dataset was to study the\n impact of air quality but it did not give adequate demonstration of the\n validity of this assumption.\n\n The scikit-learn maintainers therefore strongly discourage the use of\n this dataset unless the purpose of the code is to study and educate\n about ethical issues in data science and machine learning.\n\n In this case special case, you can fetch the dataset from the original\n source::\n\n import pandas as pd # doctest: +SKIP\n import numpy as np\n\n\n data_url = \"http://lib.stat.cmu.edu/datasets/boston\"\n raw_df = pd.read_csv(data_url, sep=\"s+\", skiprows=22, header=None)\n data = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]])\n target = raw_df.values[1::2, 2]\n\n Alternative datasets include the California housing dataset [3]_\n (i.e. func:`~sklearn.datasets.fetch_california_housing`) and Ames\n housing dataset [4]_. You can load the datasets as follows::\n\n from sklearn.datasets import fetch_california_housing\n housing = fetch_california_housing()\n\n for the California housing dataset and::\n\n from sklearn.datasets import fetch_openml\n housing = fetch_openml(name=\"house_prices\", as_frame=True) # noqa\n\n for the Ames housing dataset.\n\n Parameters\n ----------\n return_X_y : bool, default=False\n If True, returns ``(data, target)`` instead of a Bunch object.\n See below for more information about the `data` and `target` object.\n\n .. versionadded:: 0.18\n\n Returns\n -------\n data : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data : ndarray of shape (506, 13)\n The data matrix.\n target : ndarray of shape (506,)\n The regression target.\n filename : str\n The physical location of boston csv dataset.\n\n .. versionadded:: 0.20\n\n DESCR : str\n The full description of the dataset.\n feature_names : ndarray\n The names of features\n\n (data, target) : tuple if ``return_X_y`` is True\n\n .. versionadded:: 0.18\n\n Notes\n -----\n .. versionchanged:: 0.20\n Fixed a wrong data point at [445, 0].\n\n References\n ----------\n .. [1] `Racist data destruction? M Carlisle,\n `_\n .. [2] `Harrison Jr, David, and Daniel L. Rubinfeld.\n \"Hedonic housing prices and the demand for clean air.\"\n Journal of environmental economics and management 5.1 (1978): 81-102.\n `_\n .. [3] `California housing dataset\n `_\n .. [4] `Ames housing dataset\n `_\n\n Examples\n --------\n >>> import warnings\n >>> from sklearn.datasets import load_boston\n >>> with warnings.catch_warnings():\n ... # You should probably not use this dataset.\n ... warnings.filterwarnings(\"ignore\")\n ... X, y = load_boston(return_X_y=True)\n >>> print(X.shape)\n (506, 13)\n \"\"\"\n descr_text = load_descr('boston_house_prices.rst')\n data_file_name = 'boston_house_prices.csv'\n with resources.open_text(DATA_MODULE, data_file_name) as f:\n data_file = csv.reader(f)\n temp = next(data_file)\n n_samples = int(temp[0])\n n_features = int(temp[1])\n data = np.empty((n_samples, n_features))\n target = np.empty((n_samples, ))\n temp = next(data_file)\n feature_names = np.array(temp)\n for (i, d) in enumerate(data_file):\n data[i] = np.asarray(d[:-1], dtype=np.float64)\n target[i] = np.asarray(d[-1], dtype=np.float64)\n if return_X_y:\n return data, target\n return Bunch(data=data, target=target, feature_names=feature_names[:-1], DESCR=descr_text, filename=data_file_name, data_module=DATA_MODULE)" + "description": "Load and return the boston house-prices dataset (regression).\n\n============== ============== Samples total 506 Dimensionality 13 Features real, positive Targets real 5. - 50. ============== ============== Read more in the :ref:`User Guide `. .. deprecated:: 1.0 This function is deprecated in 1.0 and will be removed in 1.2. See the warning message below for further details regarding the alternative datasets. .. warning:: The Boston housing prices dataset has an ethical problem: as investigated in [1]_, the authors of this dataset engineered a non-invertible variable \"B\" assuming that racial self-segregation had a positive impact on house prices [2]_. Furthermore the goal of the research that led to the creation of this dataset was to study the impact of air quality but it did not give adequate demonstration of the validity of this assumption. The scikit-learn maintainers therefore strongly discourage the use of this dataset unless the purpose of the code is to study and educate about ethical issues in data science and machine learning. In this special case, you can fetch the dataset from the original source:: import pandas as pd # doctest: +SKIP import numpy as np data_url = \"http://lib.stat.cmu.edu/datasets/boston\" raw_df = pd.read_csv(data_url, sep=\"s+\", skiprows=22, header=None) data = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]]) target = raw_df.values[1::2, 2] Alternative datasets include the California housing dataset [3]_ (i.e. :func:`~sklearn.datasets.fetch_california_housing`) and Ames housing dataset [4]_. You can load the datasets as follows:: from sklearn.datasets import fetch_california_housing housing = fetch_california_housing() for the California housing dataset and:: from sklearn.datasets import fetch_openml housing = fetch_openml(name=\"house_prices\", as_frame=True) # noqa for the Ames housing dataset.", + "docstring": "Load and return the boston house-prices dataset (regression).\n\n============== ==============\nSamples total 506\nDimensionality 13\nFeatures real, positive\nTargets real 5. - 50.\n============== ==============\n\nRead more in the :ref:`User Guide `.\n\n.. deprecated:: 1.0\n This function is deprecated in 1.0 and will be removed in 1.2. See the\n warning message below for further details regarding the alternative\n datasets.\n\n.. warning::\n The Boston housing prices dataset has an ethical problem: as\n investigated in [1]_, the authors of this dataset engineered a\n non-invertible variable \"B\" assuming that racial self-segregation had a\n positive impact on house prices [2]_. Furthermore the goal of the\n research that led to the creation of this dataset was to study the\n impact of air quality but it did not give adequate demonstration of the\n validity of this assumption.\n\n The scikit-learn maintainers therefore strongly discourage the use of\n this dataset unless the purpose of the code is to study and educate\n about ethical issues in data science and machine learning.\n\n In this special case, you can fetch the dataset from the original\n source::\n\n import pandas as pd # doctest: +SKIP\n import numpy as np\n\n\n data_url = \"http://lib.stat.cmu.edu/datasets/boston\"\n raw_df = pd.read_csv(data_url, sep=\"s+\", skiprows=22, header=None)\n data = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]])\n target = raw_df.values[1::2, 2]\n\n Alternative datasets include the California housing dataset [3]_\n (i.e. :func:`~sklearn.datasets.fetch_california_housing`) and Ames\n housing dataset [4]_. You can load the datasets as follows::\n\n from sklearn.datasets import fetch_california_housing\n housing = fetch_california_housing()\n\n for the California housing dataset and::\n\n from sklearn.datasets import fetch_openml\n housing = fetch_openml(name=\"house_prices\", as_frame=True) # noqa\n\n for the Ames housing dataset.\n\nParameters\n----------\nreturn_X_y : bool, default=False\n If True, returns ``(data, target)`` instead of a Bunch object.\n See below for more information about the `data` and `target` object.\n\n .. versionadded:: 0.18\n\nReturns\n-------\ndata : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data : ndarray of shape (506, 13)\n The data matrix.\n target : ndarray of shape (506,)\n The regression target.\n filename : str\n The physical location of boston csv dataset.\n\n .. versionadded:: 0.20\n\n DESCR : str\n The full description of the dataset.\n feature_names : ndarray\n The names of features\n\n(data, target) : tuple if ``return_X_y`` is True\n\n .. versionadded:: 0.18\n\nNotes\n-----\n .. versionchanged:: 0.20\n Fixed a wrong data point at [445, 0].\n\nReferences\n----------\n.. [1] `Racist data destruction? M Carlisle,\n `_\n.. [2] `Harrison Jr, David, and Daniel L. Rubinfeld.\n \"Hedonic housing prices and the demand for clean air.\"\n Journal of environmental economics and management 5.1 (1978): 81-102.\n `_\n.. [3] `California housing dataset\n `_\n.. [4] `Ames housing dataset\n `_\n\nExamples\n--------\n>>> import warnings\n>>> from sklearn.datasets import load_boston\n>>> with warnings.catch_warnings():\n... # You should probably not use this dataset.\n... warnings.filterwarnings(\"ignore\")\n... X, y = load_boston(return_X_y=True)\n>>> print(X.shape)\n(506, 13)", + "source_code": "\n@deprecated('`load_boston` is deprecated in 1.0 and will be removed in 1.2.\\n\\n The Boston housing prices dataset has an ethical problem. You can refer to\\n the documentation of this function for further details.\\n\\n The scikit-learn maintainers therefore strongly discourage the use of this\\n dataset unless the purpose of the code is to study and educate about\\n ethical issues in data science and machine learning.\\n\\n In this special case, you can fetch the dataset from the original\\n source::\\n\\n import pandas as pd\\n import numpy as np\\n\\n\\n data_url = \"http://lib.stat.cmu.edu/datasets/boston\"\\n raw_df = pd.read_csv(data_url, sep=\"\\\\s+\", skiprows=22, header=None)\\n data = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]])\\n target = raw_df.values[1::2, 2]\\n\\n Alternative datasets include the California housing dataset (i.e.\\n :func:`~sklearn.datasets.fetch_california_housing`) and the Ames housing\\n dataset. You can load the datasets as follows::\\n\\n from sklearn.datasets import fetch_california_housing\\n housing = fetch_california_housing()\\n\\n for the California housing dataset and::\\n\\n from sklearn.datasets import fetch_openml\\n housing = fetch_openml(name=\"house_prices\", as_frame=True)\\n\\n for the Ames housing dataset.\\n ')\ndef load_boston(*, return_X_y=False):\n \"\"\"Load and return the boston house-prices dataset (regression).\n\n ============== ==============\n Samples total 506\n Dimensionality 13\n Features real, positive\n Targets real 5. - 50.\n ============== ==============\n\n Read more in the :ref:`User Guide `.\n\n .. deprecated:: 1.0\n This function is deprecated in 1.0 and will be removed in 1.2. See the\n warning message below for further details regarding the alternative\n datasets.\n\n .. warning::\n The Boston housing prices dataset has an ethical problem: as\n investigated in [1]_, the authors of this dataset engineered a\n non-invertible variable \"B\" assuming that racial self-segregation had a\n positive impact on house prices [2]_. Furthermore the goal of the\n research that led to the creation of this dataset was to study the\n impact of air quality but it did not give adequate demonstration of the\n validity of this assumption.\n\n The scikit-learn maintainers therefore strongly discourage the use of\n this dataset unless the purpose of the code is to study and educate\n about ethical issues in data science and machine learning.\n\n In this special case, you can fetch the dataset from the original\n source::\n\n import pandas as pd # doctest: +SKIP\n import numpy as np\n\n\n data_url = \"http://lib.stat.cmu.edu/datasets/boston\"\n raw_df = pd.read_csv(data_url, sep=\"s+\", skiprows=22, header=None)\n data = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]])\n target = raw_df.values[1::2, 2]\n\n Alternative datasets include the California housing dataset [3]_\n (i.e. :func:`~sklearn.datasets.fetch_california_housing`) and Ames\n housing dataset [4]_. You can load the datasets as follows::\n\n from sklearn.datasets import fetch_california_housing\n housing = fetch_california_housing()\n\n for the California housing dataset and::\n\n from sklearn.datasets import fetch_openml\n housing = fetch_openml(name=\"house_prices\", as_frame=True) # noqa\n\n for the Ames housing dataset.\n\n Parameters\n ----------\n return_X_y : bool, default=False\n If True, returns ``(data, target)`` instead of a Bunch object.\n See below for more information about the `data` and `target` object.\n\n .. versionadded:: 0.18\n\n Returns\n -------\n data : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data : ndarray of shape (506, 13)\n The data matrix.\n target : ndarray of shape (506,)\n The regression target.\n filename : str\n The physical location of boston csv dataset.\n\n .. versionadded:: 0.20\n\n DESCR : str\n The full description of the dataset.\n feature_names : ndarray\n The names of features\n\n (data, target) : tuple if ``return_X_y`` is True\n\n .. versionadded:: 0.18\n\n Notes\n -----\n .. versionchanged:: 0.20\n Fixed a wrong data point at [445, 0].\n\n References\n ----------\n .. [1] `Racist data destruction? M Carlisle,\n `_\n .. [2] `Harrison Jr, David, and Daniel L. Rubinfeld.\n \"Hedonic housing prices and the demand for clean air.\"\n Journal of environmental economics and management 5.1 (1978): 81-102.\n `_\n .. [3] `California housing dataset\n `_\n .. [4] `Ames housing dataset\n `_\n\n Examples\n --------\n >>> import warnings\n >>> from sklearn.datasets import load_boston\n >>> with warnings.catch_warnings():\n ... # You should probably not use this dataset.\n ... warnings.filterwarnings(\"ignore\")\n ... X, y = load_boston(return_X_y=True)\n >>> print(X.shape)\n (506, 13)\n \"\"\"\n descr_text = load_descr('boston_house_prices.rst')\n data_file_name = 'boston_house_prices.csv'\n with resources.open_text(DATA_MODULE, data_file_name) as f:\n data_file = csv.reader(f)\n temp = next(data_file)\n n_samples = int(temp[0])\n n_features = int(temp[1])\n data = np.empty((n_samples, n_features))\n target = np.empty((n_samples, ))\n temp = next(data_file)\n feature_names = np.array(temp)\n for (i, d) in enumerate(data_file):\n data[i] = np.asarray(d[:-1], dtype=np.float64)\n target[i] = np.asarray(d[-1], dtype=np.float64)\n if return_X_y:\n return data, target\n return Bunch(data=data, target=target, feature_names=feature_names[:-1], DESCR=descr_text, filename=data_file_name, data_module=DATA_MODULE)" }, { "name": "load_breast_cancer", + "unique_name": "load_breast_cancer", "qname": "sklearn.datasets._base.load_breast_cancer", + "unique_qname": "sklearn.datasets._base.load_breast_cancer", "decorators": [], "parameters": [ { @@ -41904,7 +42611,9 @@ }, { "name": "load_csv_data", + "unique_name": "load_csv_data", "qname": "sklearn.datasets._base.load_csv_data", + "unique_qname": "sklearn.datasets._base.load_csv_data", "decorators": [], "parameters": [ { @@ -41956,7 +42665,9 @@ }, { "name": "load_descr", + "unique_name": "load_descr", "qname": "sklearn.datasets._base.load_descr", + "unique_qname": "sklearn.datasets._base.load_descr", "decorators": [], "parameters": [ { @@ -41988,7 +42699,9 @@ }, { "name": "load_diabetes", + "unique_name": "load_diabetes", "qname": "sklearn.datasets._base.load_diabetes", + "unique_qname": "sklearn.datasets._base.load_diabetes", "decorators": [], "parameters": [ { @@ -42020,7 +42733,9 @@ }, { "name": "load_digits", + "unique_name": "load_digits", "qname": "sklearn.datasets._base.load_digits", + "unique_qname": "sklearn.datasets._base.load_digits", "decorators": [], "parameters": [ { @@ -42062,7 +42777,9 @@ }, { "name": "load_files", + "unique_name": "load_files", "qname": "sklearn.datasets._base.load_files", + "unique_qname": "sklearn.datasets._base.load_files", "decorators": [], "parameters": [ { @@ -42071,7 +42788,7 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "str or unicode", + "type": "str", "description": "Path to the main folder holding one subfolder per category" } }, @@ -42081,7 +42798,7 @@ "is_public": true, "assigned_by": "NAME_ONLY", "docstring": { - "type": "str or unicode, default=None", + "type": "str, default=None", "description": "A paragraph describing the characteristic of the dataset: its source,\nreference, etc." } }, @@ -42149,12 +42866,14 @@ "results": [], "is_public": true, "description": "Load text files with categories as subfolder names.\n\nIndividual samples are assumed to be files stored a two levels folder structure such as the following: container_folder/ category_1_folder/ file_1.txt file_2.txt ... file_42.txt category_2_folder/ file_43.txt file_44.txt ... The folder names are used as supervised signal label names. The individual file names are not important. This function does not try to extract features into a numpy array or scipy sparse matrix. In addition, if load_content is false it does not try to load the files in memory. To use text files in a scikit-learn classification or clustering algorithm, you will need to use the :mod`~sklearn.feature_extraction.text` module to build a feature extraction transformer that suits your problem. If you set load_content=True, you should also specify the encoding of the text using the 'encoding' parameter. For many modern text files, 'utf-8' will be the correct encoding. If you leave encoding equal to None, then the content will be made of bytes instead of Unicode, and you will not be able to use most functions in :mod:`~sklearn.feature_extraction.text`. Similar feature extractors should be built for other kind of unstructured data input such as images, audio, video, ... Read more in the :ref:`User Guide `.", - "docstring": "Load text files with categories as subfolder names.\n\nIndividual samples are assumed to be files stored a two levels folder\nstructure such as the following:\n\n container_folder/\n category_1_folder/\n file_1.txt\n file_2.txt\n ...\n file_42.txt\n category_2_folder/\n file_43.txt\n file_44.txt\n ...\n\nThe folder names are used as supervised signal label names. The individual\nfile names are not important.\n\nThis function does not try to extract features into a numpy array or scipy\nsparse matrix. In addition, if load_content is false it does not try to\nload the files in memory.\n\nTo use text files in a scikit-learn classification or clustering algorithm,\nyou will need to use the :mod`~sklearn.feature_extraction.text` module to\nbuild a feature extraction transformer that suits your problem.\n\nIf you set load_content=True, you should also specify the encoding of the\ntext using the 'encoding' parameter. For many modern text files, 'utf-8'\nwill be the correct encoding. If you leave encoding equal to None, then the\ncontent will be made of bytes instead of Unicode, and you will not be able\nto use most functions in :mod:`~sklearn.feature_extraction.text`.\n\nSimilar feature extractors should be built for other kind of unstructured\ndata input such as images, audio, video, ...\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\ncontainer_path : str or unicode\n Path to the main folder holding one subfolder per category\n\ndescription : str or unicode, default=None\n A paragraph describing the characteristic of the dataset: its source,\n reference, etc.\n\ncategories : list of str, default=None\n If None (default), load all the categories. If not None, list of\n category names to load (other categories ignored).\n\nload_content : bool, default=True\n Whether to load or not the content of the different files. If true a\n 'data' attribute containing the text information is present in the data\n structure returned. If not, a filenames attribute gives the path to the\n files.\n\nshuffle : bool, default=True\n Whether or not to shuffle the data: might be important for models that\n make the assumption that the samples are independent and identically\n distributed (i.i.d.), such as stochastic gradient descent.\n\nencoding : str, default=None\n If None, do not try to decode the content of the files (e.g. for images\n or other non-text content). If not None, encoding to use to decode text\n files to Unicode if load_content is True.\n\ndecode_error : {'strict', 'ignore', 'replace'}, default='strict'\n Instruction on what to do if a byte sequence is given to analyze that\n contains characters not of the given `encoding`. Passed as keyword\n argument 'errors' to bytes.decode.\n\nrandom_state : int, RandomState instance or None, default=0\n Determines random number generation for dataset shuffling. Pass an int\n for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\nReturns\n-------\ndata : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data : list of str\n Only present when `load_content=True`.\n The raw text data to learn.\n target : ndarray\n The target labels (integer index).\n target_names : list\n The names of target classes.\n DESCR : str\n The full description of the dataset.\n filenames: ndarray\n The filenames holding the dataset.", - "source_code": "\ndef load_files(container_path, *, description=None, categories=None, load_content=True, shuffle=True, encoding=None, decode_error='strict', random_state=0):\n \"\"\"Load text files with categories as subfolder names.\n\n Individual samples are assumed to be files stored a two levels folder\n structure such as the following:\n\n container_folder/\n category_1_folder/\n file_1.txt\n file_2.txt\n ...\n file_42.txt\n category_2_folder/\n file_43.txt\n file_44.txt\n ...\n\n The folder names are used as supervised signal label names. The individual\n file names are not important.\n\n This function does not try to extract features into a numpy array or scipy\n sparse matrix. In addition, if load_content is false it does not try to\n load the files in memory.\n\n To use text files in a scikit-learn classification or clustering algorithm,\n you will need to use the :mod`~sklearn.feature_extraction.text` module to\n build a feature extraction transformer that suits your problem.\n\n If you set load_content=True, you should also specify the encoding of the\n text using the 'encoding' parameter. For many modern text files, 'utf-8'\n will be the correct encoding. If you leave encoding equal to None, then the\n content will be made of bytes instead of Unicode, and you will not be able\n to use most functions in :mod:`~sklearn.feature_extraction.text`.\n\n Similar feature extractors should be built for other kind of unstructured\n data input such as images, audio, video, ...\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n container_path : str or unicode\n Path to the main folder holding one subfolder per category\n\n description : str or unicode, default=None\n A paragraph describing the characteristic of the dataset: its source,\n reference, etc.\n\n categories : list of str, default=None\n If None (default), load all the categories. If not None, list of\n category names to load (other categories ignored).\n\n load_content : bool, default=True\n Whether to load or not the content of the different files. If true a\n 'data' attribute containing the text information is present in the data\n structure returned. If not, a filenames attribute gives the path to the\n files.\n\n shuffle : bool, default=True\n Whether or not to shuffle the data: might be important for models that\n make the assumption that the samples are independent and identically\n distributed (i.i.d.), such as stochastic gradient descent.\n\n encoding : str, default=None\n If None, do not try to decode the content of the files (e.g. for images\n or other non-text content). If not None, encoding to use to decode text\n files to Unicode if load_content is True.\n\n decode_error : {'strict', 'ignore', 'replace'}, default='strict'\n Instruction on what to do if a byte sequence is given to analyze that\n contains characters not of the given `encoding`. Passed as keyword\n argument 'errors' to bytes.decode.\n\n random_state : int, RandomState instance or None, default=0\n Determines random number generation for dataset shuffling. Pass an int\n for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n Returns\n -------\n data : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data : list of str\n Only present when `load_content=True`.\n The raw text data to learn.\n target : ndarray\n The target labels (integer index).\n target_names : list\n The names of target classes.\n DESCR : str\n The full description of the dataset.\n filenames: ndarray\n The filenames holding the dataset.\n \"\"\"\n target = []\n target_names = []\n filenames = []\n folders = [f for f in sorted(listdir(container_path)) if isdir(join(container_path, f))]\n if categories is not None:\n folders = [f for f in folders if f in categories]\n for (label, folder) in enumerate(folders):\n target_names.append(folder)\n folder_path = join(container_path, folder)\n documents = [join(folder_path, d) for d in sorted(listdir(folder_path))]\n target.extend(len(documents) * [label])\n filenames.extend(documents)\n filenames = np.array(filenames)\n target = np.array(target)\n if shuffle:\n random_state = check_random_state(random_state)\n indices = np.arange(filenames.shape[0])\n random_state.shuffle(indices)\n filenames = filenames[indices]\n target = target[indices]\n if load_content:\n data = []\n for filename in filenames:\n with open(filename, 'rb') as f:\n data.append(f.read())\n if encoding is not None:\n data = [d.decode(encoding, decode_error) for d in data]\n return Bunch(data=data, filenames=filenames, target_names=target_names, target=target, DESCR=description)\n return Bunch(filenames=filenames, target_names=target_names, target=target, DESCR=description)" + "docstring": "Load text files with categories as subfolder names.\n\nIndividual samples are assumed to be files stored a two levels folder\nstructure such as the following:\n\n container_folder/\n category_1_folder/\n file_1.txt\n file_2.txt\n ...\n file_42.txt\n category_2_folder/\n file_43.txt\n file_44.txt\n ...\n\nThe folder names are used as supervised signal label names. The individual\nfile names are not important.\n\nThis function does not try to extract features into a numpy array or scipy\nsparse matrix. In addition, if load_content is false it does not try to\nload the files in memory.\n\nTo use text files in a scikit-learn classification or clustering algorithm,\nyou will need to use the :mod`~sklearn.feature_extraction.text` module to\nbuild a feature extraction transformer that suits your problem.\n\nIf you set load_content=True, you should also specify the encoding of the\ntext using the 'encoding' parameter. For many modern text files, 'utf-8'\nwill be the correct encoding. If you leave encoding equal to None, then the\ncontent will be made of bytes instead of Unicode, and you will not be able\nto use most functions in :mod:`~sklearn.feature_extraction.text`.\n\nSimilar feature extractors should be built for other kind of unstructured\ndata input such as images, audio, video, ...\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\ncontainer_path : str\n Path to the main folder holding one subfolder per category\n\ndescription : str, default=None\n A paragraph describing the characteristic of the dataset: its source,\n reference, etc.\n\ncategories : list of str, default=None\n If None (default), load all the categories. If not None, list of\n category names to load (other categories ignored).\n\nload_content : bool, default=True\n Whether to load or not the content of the different files. If true a\n 'data' attribute containing the text information is present in the data\n structure returned. If not, a filenames attribute gives the path to the\n files.\n\nshuffle : bool, default=True\n Whether or not to shuffle the data: might be important for models that\n make the assumption that the samples are independent and identically\n distributed (i.i.d.), such as stochastic gradient descent.\n\nencoding : str, default=None\n If None, do not try to decode the content of the files (e.g. for images\n or other non-text content). If not None, encoding to use to decode text\n files to Unicode if load_content is True.\n\ndecode_error : {'strict', 'ignore', 'replace'}, default='strict'\n Instruction on what to do if a byte sequence is given to analyze that\n contains characters not of the given `encoding`. Passed as keyword\n argument 'errors' to bytes.decode.\n\nrandom_state : int, RandomState instance or None, default=0\n Determines random number generation for dataset shuffling. Pass an int\n for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\nReturns\n-------\ndata : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data : list of str\n Only present when `load_content=True`.\n The raw text data to learn.\n target : ndarray\n The target labels (integer index).\n target_names : list\n The names of target classes.\n DESCR : str\n The full description of the dataset.\n filenames: ndarray\n The filenames holding the dataset.", + "source_code": "\ndef load_files(container_path, *, description=None, categories=None, load_content=True, shuffle=True, encoding=None, decode_error='strict', random_state=0):\n \"\"\"Load text files with categories as subfolder names.\n\n Individual samples are assumed to be files stored a two levels folder\n structure such as the following:\n\n container_folder/\n category_1_folder/\n file_1.txt\n file_2.txt\n ...\n file_42.txt\n category_2_folder/\n file_43.txt\n file_44.txt\n ...\n\n The folder names are used as supervised signal label names. The individual\n file names are not important.\n\n This function does not try to extract features into a numpy array or scipy\n sparse matrix. In addition, if load_content is false it does not try to\n load the files in memory.\n\n To use text files in a scikit-learn classification or clustering algorithm,\n you will need to use the :mod`~sklearn.feature_extraction.text` module to\n build a feature extraction transformer that suits your problem.\n\n If you set load_content=True, you should also specify the encoding of the\n text using the 'encoding' parameter. For many modern text files, 'utf-8'\n will be the correct encoding. If you leave encoding equal to None, then the\n content will be made of bytes instead of Unicode, and you will not be able\n to use most functions in :mod:`~sklearn.feature_extraction.text`.\n\n Similar feature extractors should be built for other kind of unstructured\n data input such as images, audio, video, ...\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n container_path : str\n Path to the main folder holding one subfolder per category\n\n description : str, default=None\n A paragraph describing the characteristic of the dataset: its source,\n reference, etc.\n\n categories : list of str, default=None\n If None (default), load all the categories. If not None, list of\n category names to load (other categories ignored).\n\n load_content : bool, default=True\n Whether to load or not the content of the different files. If true a\n 'data' attribute containing the text information is present in the data\n structure returned. If not, a filenames attribute gives the path to the\n files.\n\n shuffle : bool, default=True\n Whether or not to shuffle the data: might be important for models that\n make the assumption that the samples are independent and identically\n distributed (i.i.d.), such as stochastic gradient descent.\n\n encoding : str, default=None\n If None, do not try to decode the content of the files (e.g. for images\n or other non-text content). If not None, encoding to use to decode text\n files to Unicode if load_content is True.\n\n decode_error : {'strict', 'ignore', 'replace'}, default='strict'\n Instruction on what to do if a byte sequence is given to analyze that\n contains characters not of the given `encoding`. Passed as keyword\n argument 'errors' to bytes.decode.\n\n random_state : int, RandomState instance or None, default=0\n Determines random number generation for dataset shuffling. Pass an int\n for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n Returns\n -------\n data : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data : list of str\n Only present when `load_content=True`.\n The raw text data to learn.\n target : ndarray\n The target labels (integer index).\n target_names : list\n The names of target classes.\n DESCR : str\n The full description of the dataset.\n filenames: ndarray\n The filenames holding the dataset.\n \"\"\"\n target = []\n target_names = []\n filenames = []\n folders = [f for f in sorted(listdir(container_path)) if isdir(join(container_path, f))]\n if categories is not None:\n folders = [f for f in folders if f in categories]\n for (label, folder) in enumerate(folders):\n target_names.append(folder)\n folder_path = join(container_path, folder)\n documents = [join(folder_path, d) for d in sorted(listdir(folder_path))]\n target.extend(len(documents) * [label])\n filenames.extend(documents)\n filenames = np.array(filenames)\n target = np.array(target)\n if shuffle:\n random_state = check_random_state(random_state)\n indices = np.arange(filenames.shape[0])\n random_state.shuffle(indices)\n filenames = filenames[indices]\n target = target[indices]\n if load_content:\n data = []\n for filename in filenames:\n with open(filename, 'rb') as f:\n data.append(f.read())\n if encoding is not None:\n data = [d.decode(encoding, decode_error) for d in data]\n return Bunch(data=data, filenames=filenames, target_names=target_names, target=target, DESCR=description)\n return Bunch(filenames=filenames, target_names=target_names, target=target, DESCR=description)" }, { "name": "load_gzip_compressed_csv_data", + "unique_name": "load_gzip_compressed_csv_data", "qname": "sklearn.datasets._base.load_gzip_compressed_csv_data", + "unique_qname": "sklearn.datasets._base.load_gzip_compressed_csv_data", "decorators": [], "parameters": [ { @@ -42216,7 +42935,9 @@ }, { "name": "load_iris", + "unique_name": "load_iris", "qname": "sklearn.datasets._base.load_iris", + "unique_qname": "sklearn.datasets._base.load_iris", "decorators": [], "parameters": [ { @@ -42248,7 +42969,9 @@ }, { "name": "load_linnerud", + "unique_name": "load_linnerud", "qname": "sklearn.datasets._base.load_linnerud", + "unique_qname": "sklearn.datasets._base.load_linnerud", "decorators": [], "parameters": [ { @@ -42280,7 +43003,9 @@ }, { "name": "load_sample_image", + "unique_name": "load_sample_image", "qname": "sklearn.datasets._base.load_sample_image", + "unique_qname": "sklearn.datasets._base.load_sample_image", "decorators": [], "parameters": [ { @@ -42302,7 +43027,9 @@ }, { "name": "load_sample_images", + "unique_name": "load_sample_images", "qname": "sklearn.datasets._base.load_sample_images", + "unique_qname": "sklearn.datasets._base.load_sample_images", "decorators": [], "parameters": [], "results": [], @@ -42313,7 +43040,9 @@ }, { "name": "load_wine", + "unique_name": "load_wine", "qname": "sklearn.datasets._base.load_wine", + "unique_qname": "sklearn.datasets._base.load_wine", "decorators": [], "parameters": [ { @@ -42345,7 +43074,9 @@ }, { "name": "fetch_california_housing", + "unique_name": "fetch_california_housing", "qname": "sklearn.datasets._california_housing.fetch_california_housing", + "unique_qname": "sklearn.datasets._california_housing.fetch_california_housing", "decorators": [], "parameters": [ { @@ -42392,12 +43123,14 @@ "results": [], "is_public": true, "description": "Load the California housing dataset (regression).\n\n============== ============== Samples total 20640 Dimensionality 8 Features real Target real 0.15 - 5. ============== ============== Read more in the :ref:`User Guide `.", - "docstring": "Load the California housing dataset (regression).\n\n============== ==============\nSamples total 20640\nDimensionality 8\nFeatures real\nTarget real 0.15 - 5.\n============== ==============\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\ndata_home : str, default=None\n Specify another download and cache folder for the datasets. By default\n all scikit-learn data is stored in '~/scikit_learn_data' subfolders.\n\ndownload_if_missing : bool, default=True\n If False, raise a IOError if the data is not locally available\n instead of trying to download the data from the source site.\n\n\nreturn_X_y : bool, default=False.\n If True, returns ``(data.data, data.target)`` instead of a Bunch\n object.\n\n .. versionadded:: 0.20\n\nas_frame : bool, default=False\n If True, the data is a pandas DataFrame including columns with\n appropriate dtypes (numeric, string or categorical). The target is\n a pandas DataFrame or Series depending on the number of target_columns.\n\n .. versionadded:: 0.23\n\nReturns\n-------\ndataset : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data : ndarray, shape (20640, 8)\n Each row corresponding to the 8 feature values in order.\n If ``as_frame`` is True, ``data`` is a pandas object.\n target : numpy array of shape (20640,)\n Each value corresponds to the average\n house value in units of 100,000.\n If ``as_frame`` is True, ``target`` is a pandas object.\n feature_names : list of length 8\n Array of ordered feature names used in the dataset.\n DESCR : string\n Description of the California housing dataset.\n frame : pandas DataFrame\n Only present when `as_frame=True`. DataFrame with ``data`` and\n ``target``.\n\n .. versionadded:: 0.23\n\n(data, target) : tuple if ``return_X_y`` is True\n\n .. versionadded:: 0.20\n\nNotes\n-----\n\nThis dataset consists of 20,640 samples and 9 features.", - "source_code": "\ndef fetch_california_housing(*, data_home=None, download_if_missing=True, return_X_y=False, as_frame=False):\n \"\"\"Load the California housing dataset (regression).\n\n ============== ==============\n Samples total 20640\n Dimensionality 8\n Features real\n Target real 0.15 - 5.\n ============== ==============\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n data_home : str, default=None\n Specify another download and cache folder for the datasets. By default\n all scikit-learn data is stored in '~/scikit_learn_data' subfolders.\n\n download_if_missing : bool, default=True\n If False, raise a IOError if the data is not locally available\n instead of trying to download the data from the source site.\n\n\n return_X_y : bool, default=False.\n If True, returns ``(data.data, data.target)`` instead of a Bunch\n object.\n\n .. versionadded:: 0.20\n\n as_frame : bool, default=False\n If True, the data is a pandas DataFrame including columns with\n appropriate dtypes (numeric, string or categorical). The target is\n a pandas DataFrame or Series depending on the number of target_columns.\n\n .. versionadded:: 0.23\n\n Returns\n -------\n dataset : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data : ndarray, shape (20640, 8)\n Each row corresponding to the 8 feature values in order.\n If ``as_frame`` is True, ``data`` is a pandas object.\n target : numpy array of shape (20640,)\n Each value corresponds to the average\n house value in units of 100,000.\n If ``as_frame`` is True, ``target`` is a pandas object.\n feature_names : list of length 8\n Array of ordered feature names used in the dataset.\n DESCR : string\n Description of the California housing dataset.\n frame : pandas DataFrame\n Only present when `as_frame=True`. DataFrame with ``data`` and\n ``target``.\n\n .. versionadded:: 0.23\n\n (data, target) : tuple if ``return_X_y`` is True\n\n .. versionadded:: 0.20\n\n Notes\n -----\n\n This dataset consists of 20,640 samples and 9 features.\n \"\"\"\n data_home = get_data_home(data_home=data_home)\n if not exists(data_home):\n makedirs(data_home)\n filepath = _pkl_filepath(data_home, 'cal_housing.pkz')\n if not exists(filepath):\n if not download_if_missing:\n raise IOError('Data not found and `download_if_missing` is False')\n logger.info('Downloading Cal. housing from {} to {}'.format(ARCHIVE.url, data_home))\n archive_path = _fetch_remote(ARCHIVE, dirname=data_home)\n with tarfile.open(mode='r:gz', name=archive_path) as f:\n cal_housing = np.loadtxt(f.extractfile('CaliforniaHousing/cal_housing.data'), delimiter=',')\n columns_index = [8, 7, 2, 3, 4, 5, 6, 1, 0]\n cal_housing = cal_housing[:, columns_index]\n joblib.dump(cal_housing, filepath, compress=6)\n remove(archive_path)\n else:\n cal_housing = joblib.load(filepath)\n feature_names = ['MedInc', 'HouseAge', 'AveRooms', 'AveBedrms', 'Population', 'AveOccup', 'Latitude', 'Longitude']\n (target, data) = (cal_housing[:, 0], cal_housing[:, 1:])\n data[:, 2] /= data[:, 5]\n data[:, 3] /= data[:, 5]\n data[:, 5] = data[:, 4] / data[:, 5]\n target = target / 100000.0\n descr = load_descr('california_housing.rst')\n X = data\n y = target\n frame = None\n target_names = ['MedHouseVal']\n if as_frame:\n (frame, X, y) = _convert_data_dataframe('fetch_california_housing', data, target, feature_names, target_names)\n if return_X_y:\n return X, y\n return Bunch(data=X, target=y, frame=frame, target_names=target_names, feature_names=feature_names, DESCR=descr)" + "docstring": "Load the California housing dataset (regression).\n\n============== ==============\nSamples total 20640\nDimensionality 8\nFeatures real\nTarget real 0.15 - 5.\n============== ==============\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\ndata_home : str, default=None\n Specify another download and cache folder for the datasets. By default\n all scikit-learn data is stored in '~/scikit_learn_data' subfolders.\n\ndownload_if_missing : bool, default=True\n If False, raise a IOError if the data is not locally available\n instead of trying to download the data from the source site.\n\n\nreturn_X_y : bool, default=False.\n If True, returns ``(data.data, data.target)`` instead of a Bunch\n object.\n\n .. versionadded:: 0.20\n\nas_frame : bool, default=False\n If True, the data is a pandas DataFrame including columns with\n appropriate dtypes (numeric, string or categorical). The target is\n a pandas DataFrame or Series depending on the number of target_columns.\n\n .. versionadded:: 0.23\n\nReturns\n-------\ndataset : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data : ndarray, shape (20640, 8)\n Each row corresponding to the 8 feature values in order.\n If ``as_frame`` is True, ``data`` is a pandas object.\n target : numpy array of shape (20640,)\n Each value corresponds to the average\n house value in units of 100,000.\n If ``as_frame`` is True, ``target`` is a pandas object.\n feature_names : list of length 8\n Array of ordered feature names used in the dataset.\n DESCR : str\n Description of the California housing dataset.\n frame : pandas DataFrame\n Only present when `as_frame=True`. DataFrame with ``data`` and\n ``target``.\n\n .. versionadded:: 0.23\n\n(data, target) : tuple if ``return_X_y`` is True\n\n .. versionadded:: 0.20\n\nNotes\n-----\n\nThis dataset consists of 20,640 samples and 9 features.", + "source_code": "\ndef fetch_california_housing(*, data_home=None, download_if_missing=True, return_X_y=False, as_frame=False):\n \"\"\"Load the California housing dataset (regression).\n\n ============== ==============\n Samples total 20640\n Dimensionality 8\n Features real\n Target real 0.15 - 5.\n ============== ==============\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n data_home : str, default=None\n Specify another download and cache folder for the datasets. By default\n all scikit-learn data is stored in '~/scikit_learn_data' subfolders.\n\n download_if_missing : bool, default=True\n If False, raise a IOError if the data is not locally available\n instead of trying to download the data from the source site.\n\n\n return_X_y : bool, default=False.\n If True, returns ``(data.data, data.target)`` instead of a Bunch\n object.\n\n .. versionadded:: 0.20\n\n as_frame : bool, default=False\n If True, the data is a pandas DataFrame including columns with\n appropriate dtypes (numeric, string or categorical). The target is\n a pandas DataFrame or Series depending on the number of target_columns.\n\n .. versionadded:: 0.23\n\n Returns\n -------\n dataset : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data : ndarray, shape (20640, 8)\n Each row corresponding to the 8 feature values in order.\n If ``as_frame`` is True, ``data`` is a pandas object.\n target : numpy array of shape (20640,)\n Each value corresponds to the average\n house value in units of 100,000.\n If ``as_frame`` is True, ``target`` is a pandas object.\n feature_names : list of length 8\n Array of ordered feature names used in the dataset.\n DESCR : str\n Description of the California housing dataset.\n frame : pandas DataFrame\n Only present when `as_frame=True`. DataFrame with ``data`` and\n ``target``.\n\n .. versionadded:: 0.23\n\n (data, target) : tuple if ``return_X_y`` is True\n\n .. versionadded:: 0.20\n\n Notes\n -----\n\n This dataset consists of 20,640 samples and 9 features.\n \"\"\"\n data_home = get_data_home(data_home=data_home)\n if not exists(data_home):\n makedirs(data_home)\n filepath = _pkl_filepath(data_home, 'cal_housing.pkz')\n if not exists(filepath):\n if not download_if_missing:\n raise IOError('Data not found and `download_if_missing` is False')\n logger.info('Downloading Cal. housing from {} to {}'.format(ARCHIVE.url, data_home))\n archive_path = _fetch_remote(ARCHIVE, dirname=data_home)\n with tarfile.open(mode='r:gz', name=archive_path) as f:\n cal_housing = np.loadtxt(f.extractfile('CaliforniaHousing/cal_housing.data'), delimiter=',')\n columns_index = [8, 7, 2, 3, 4, 5, 6, 1, 0]\n cal_housing = cal_housing[:, columns_index]\n joblib.dump(cal_housing, filepath, compress=6)\n remove(archive_path)\n else:\n cal_housing = joblib.load(filepath)\n feature_names = ['MedInc', 'HouseAge', 'AveRooms', 'AveBedrms', 'Population', 'AveOccup', 'Latitude', 'Longitude']\n (target, data) = (cal_housing[:, 0], cal_housing[:, 1:])\n data[:, 2] /= data[:, 5]\n data[:, 3] /= data[:, 5]\n data[:, 5] = data[:, 4] / data[:, 5]\n target = target / 100000.0\n descr = load_descr('california_housing.rst')\n X = data\n y = target\n frame = None\n target_names = ['MedHouseVal']\n if as_frame:\n (frame, X, y) = _convert_data_dataframe('fetch_california_housing', data, target, feature_names, target_names)\n if return_X_y:\n return X, y\n return Bunch(data=X, target=y, frame=frame, target_names=target_names, feature_names=feature_names, DESCR=descr)" }, { "name": "fetch_covtype", + "unique_name": "fetch_covtype", "qname": "sklearn.datasets._covtype.fetch_covtype", + "unique_qname": "sklearn.datasets._covtype.fetch_covtype", "decorators": [], "parameters": [ { @@ -42469,7 +43202,9 @@ }, { "name": "_fetch_brute_kddcup99", + "unique_name": "_fetch_brute_kddcup99", "qname": "sklearn.datasets._kddcup99._fetch_brute_kddcup99", + "unique_qname": "sklearn.datasets._kddcup99._fetch_brute_kddcup99", "decorators": [], "parameters": [ { @@ -42511,7 +43246,9 @@ }, { "name": "_mkdirp", + "unique_name": "_mkdirp", "qname": "sklearn.datasets._kddcup99._mkdirp", + "unique_qname": "sklearn.datasets._kddcup99._mkdirp", "decorators": [], "parameters": [ { @@ -42533,7 +43270,9 @@ }, { "name": "fetch_kddcup99", + "unique_name": "fetch_kddcup99", "qname": "sklearn.datasets._kddcup99.fetch_kddcup99", + "unique_qname": "sklearn.datasets._kddcup99.fetch_kddcup99", "decorators": [], "parameters": [ { @@ -42625,7 +43364,9 @@ }, { "name": "_check_fetch_lfw", + "unique_name": "_check_fetch_lfw", "qname": "sklearn.datasets._lfw._check_fetch_lfw", + "unique_qname": "sklearn.datasets._lfw._check_fetch_lfw", "decorators": [], "parameters": [ { @@ -42667,7 +43408,9 @@ }, { "name": "_fetch_lfw_pairs", + "unique_name": "_fetch_lfw_pairs", "qname": "sklearn.datasets._lfw._fetch_lfw_pairs", + "unique_qname": "sklearn.datasets._lfw._fetch_lfw_pairs", "decorators": [], "parameters": [ { @@ -42729,7 +43472,9 @@ }, { "name": "_fetch_lfw_people", + "unique_name": "_fetch_lfw_people", "qname": "sklearn.datasets._lfw._fetch_lfw_people", + "unique_qname": "sklearn.datasets._lfw._fetch_lfw_people", "decorators": [], "parameters": [ { @@ -42791,7 +43536,9 @@ }, { "name": "_load_imgs", + "unique_name": "_load_imgs", "qname": "sklearn.datasets._lfw._load_imgs", + "unique_qname": "sklearn.datasets._lfw._load_imgs", "decorators": [], "parameters": [ { @@ -42843,7 +43590,9 @@ }, { "name": "fetch_lfw_pairs", + "unique_name": "fetch_lfw_pairs", "qname": "sklearn.datasets._lfw.fetch_lfw_pairs", + "unique_qname": "sklearn.datasets._lfw.fetch_lfw_pairs", "decorators": [], "parameters": [ { @@ -42920,12 +43669,14 @@ "results": [], "is_public": true, "description": "Load the Labeled Faces in the Wild (LFW) pairs dataset (classification).\n\nDownload it if necessary. ================= ======================= Classes 2 Samples total 13233 Dimensionality 5828 Features real, between 0 and 255 ================= ======================= In the official `README.txt`_ this task is described as the \"Restricted\" task. As I am not sure as to implement the \"Unrestricted\" variant correctly, I left it as unsupported for now. .. _`README.txt`: http://vis-www.cs.umass.edu/lfw/README.txt The original images are 250 x 250 pixels, but the default slice and resize arguments reduce them to 62 x 47. Read more in the :ref:`User Guide `.", - "docstring": "Load the Labeled Faces in the Wild (LFW) pairs dataset (classification).\n\nDownload it if necessary.\n\n================= =======================\nClasses 2\nSamples total 13233\nDimensionality 5828\nFeatures real, between 0 and 255\n================= =======================\n\nIn the official `README.txt`_ this task is described as the\n\"Restricted\" task. As I am not sure as to implement the\n\"Unrestricted\" variant correctly, I left it as unsupported for now.\n\n .. _`README.txt`: http://vis-www.cs.umass.edu/lfw/README.txt\n\nThe original images are 250 x 250 pixels, but the default slice and resize\narguments reduce them to 62 x 47.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\nsubset : {'train', 'test', '10_folds'}, default='train'\n Select the dataset to load: 'train' for the development training\n set, 'test' for the development test set, and '10_folds' for the\n official evaluation set that is meant to be used with a 10-folds\n cross validation.\n\ndata_home : str, default=None\n Specify another download and cache folder for the datasets. By\n default all scikit-learn data is stored in '~/scikit_learn_data'\n subfolders.\n\nfunneled : bool, default=True\n Download and use the funneled variant of the dataset.\n\nresize : float, default=0.5\n Ratio used to resize the each face picture.\n\ncolor : bool, default=False\n Keep the 3 RGB channels instead of averaging them to a single\n gray level channel. If color is True the shape of the data has\n one more dimension than the shape with color = False.\n\nslice_ : tuple of slice, default=(slice(70, 195), slice(78, 172))\n Provide a custom 2D slice (height, width) to extract the\n 'interesting' part of the jpeg files and avoid use statistical\n correlation from the background\n\ndownload_if_missing : bool, default=True\n If False, raise a IOError if the data is not locally available\n instead of trying to download the data from the source site.\n\nReturns\n-------\ndata : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data : ndarray of shape (2200, 5828). Shape depends on ``subset``.\n Each row corresponds to 2 ravel'd face images\n of original size 62 x 47 pixels.\n Changing the ``slice_``, ``resize`` or ``subset`` parameters\n will change the shape of the output.\n pairs : ndarray of shape (2200, 2, 62, 47). Shape depends on ``subset``\n Each row has 2 face images corresponding\n to same or different person from the dataset\n containing 5749 people. Changing the ``slice_``,\n ``resize`` or ``subset`` parameters will change the shape of the\n output.\n target : numpy array of shape (2200,). Shape depends on ``subset``.\n Labels associated to each pair of images.\n The two label values being different persons or the same person.\n DESCR : string\n Description of the Labeled Faces in the Wild (LFW) dataset.", - "source_code": "\ndef fetch_lfw_pairs(*, subset='train', data_home=None, funneled=True, resize=0.5, color=False, slice_=(slice(70, 195), slice(78, 172)), download_if_missing=True):\n \"\"\"Load the Labeled Faces in the Wild (LFW) pairs dataset (classification).\n\n Download it if necessary.\n\n ================= =======================\n Classes 2\n Samples total 13233\n Dimensionality 5828\n Features real, between 0 and 255\n ================= =======================\n\n In the official `README.txt`_ this task is described as the\n \"Restricted\" task. As I am not sure as to implement the\n \"Unrestricted\" variant correctly, I left it as unsupported for now.\n\n .. _`README.txt`: http://vis-www.cs.umass.edu/lfw/README.txt\n\n The original images are 250 x 250 pixels, but the default slice and resize\n arguments reduce them to 62 x 47.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n subset : {'train', 'test', '10_folds'}, default='train'\n Select the dataset to load: 'train' for the development training\n set, 'test' for the development test set, and '10_folds' for the\n official evaluation set that is meant to be used with a 10-folds\n cross validation.\n\n data_home : str, default=None\n Specify another download and cache folder for the datasets. By\n default all scikit-learn data is stored in '~/scikit_learn_data'\n subfolders.\n\n funneled : bool, default=True\n Download and use the funneled variant of the dataset.\n\n resize : float, default=0.5\n Ratio used to resize the each face picture.\n\n color : bool, default=False\n Keep the 3 RGB channels instead of averaging them to a single\n gray level channel. If color is True the shape of the data has\n one more dimension than the shape with color = False.\n\n slice_ : tuple of slice, default=(slice(70, 195), slice(78, 172))\n Provide a custom 2D slice (height, width) to extract the\n 'interesting' part of the jpeg files and avoid use statistical\n correlation from the background\n\n download_if_missing : bool, default=True\n If False, raise a IOError if the data is not locally available\n instead of trying to download the data from the source site.\n\n Returns\n -------\n data : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data : ndarray of shape (2200, 5828). Shape depends on ``subset``.\n Each row corresponds to 2 ravel'd face images\n of original size 62 x 47 pixels.\n Changing the ``slice_``, ``resize`` or ``subset`` parameters\n will change the shape of the output.\n pairs : ndarray of shape (2200, 2, 62, 47). Shape depends on ``subset``\n Each row has 2 face images corresponding\n to same or different person from the dataset\n containing 5749 people. Changing the ``slice_``,\n ``resize`` or ``subset`` parameters will change the shape of the\n output.\n target : numpy array of shape (2200,). Shape depends on ``subset``.\n Labels associated to each pair of images.\n The two label values being different persons or the same person.\n DESCR : string\n Description of the Labeled Faces in the Wild (LFW) dataset.\n\n \"\"\"\n (lfw_home, data_folder_path) = _check_fetch_lfw(data_home=data_home, funneled=funneled, download_if_missing=download_if_missing)\n logger.debug('Loading %s LFW pairs from %s', subset, lfw_home)\n if parse_version(joblib.__version__) < parse_version('0.12'):\n m = Memory(cachedir=lfw_home, compress=6, verbose=0)\n else:\n m = Memory(location=lfw_home, compress=6, verbose=0)\n load_func = m.cache(_fetch_lfw_pairs)\n label_filenames = {'train': 'pairsDevTrain.txt', 'test': 'pairsDevTest.txt', '10_folds': 'pairs.txt'}\n if subset not in label_filenames:\n raise ValueError(\"subset='%s' is invalid: should be one of %r\" % (subset, list(sorted(label_filenames.keys()))))\n index_file_path = join(lfw_home, label_filenames[subset])\n (pairs, target, target_names) = load_func(index_file_path, data_folder_path, resize=resize, color=color, slice_=slice_)\n fdescr = load_descr('lfw.rst')\n return Bunch(data=pairs.reshape(len(pairs), -1), pairs=pairs, target=target, target_names=target_names, DESCR=fdescr)" + "docstring": "Load the Labeled Faces in the Wild (LFW) pairs dataset (classification).\n\nDownload it if necessary.\n\n================= =======================\nClasses 2\nSamples total 13233\nDimensionality 5828\nFeatures real, between 0 and 255\n================= =======================\n\nIn the official `README.txt`_ this task is described as the\n\"Restricted\" task. As I am not sure as to implement the\n\"Unrestricted\" variant correctly, I left it as unsupported for now.\n\n .. _`README.txt`: http://vis-www.cs.umass.edu/lfw/README.txt\n\nThe original images are 250 x 250 pixels, but the default slice and resize\narguments reduce them to 62 x 47.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\nsubset : {'train', 'test', '10_folds'}, default='train'\n Select the dataset to load: 'train' for the development training\n set, 'test' for the development test set, and '10_folds' for the\n official evaluation set that is meant to be used with a 10-folds\n cross validation.\n\ndata_home : str, default=None\n Specify another download and cache folder for the datasets. By\n default all scikit-learn data is stored in '~/scikit_learn_data'\n subfolders.\n\nfunneled : bool, default=True\n Download and use the funneled variant of the dataset.\n\nresize : float, default=0.5\n Ratio used to resize the each face picture.\n\ncolor : bool, default=False\n Keep the 3 RGB channels instead of averaging them to a single\n gray level channel. If color is True the shape of the data has\n one more dimension than the shape with color = False.\n\nslice_ : tuple of slice, default=(slice(70, 195), slice(78, 172))\n Provide a custom 2D slice (height, width) to extract the\n 'interesting' part of the jpeg files and avoid use statistical\n correlation from the background\n\ndownload_if_missing : bool, default=True\n If False, raise a IOError if the data is not locally available\n instead of trying to download the data from the source site.\n\nReturns\n-------\ndata : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data : ndarray of shape (2200, 5828). Shape depends on ``subset``.\n Each row corresponds to 2 ravel'd face images\n of original size 62 x 47 pixels.\n Changing the ``slice_``, ``resize`` or ``subset`` parameters\n will change the shape of the output.\n pairs : ndarray of shape (2200, 2, 62, 47). Shape depends on ``subset``\n Each row has 2 face images corresponding\n to same or different person from the dataset\n containing 5749 people. Changing the ``slice_``,\n ``resize`` or ``subset`` parameters will change the shape of the\n output.\n target : numpy array of shape (2200,). Shape depends on ``subset``.\n Labels associated to each pair of images.\n The two label values being different persons or the same person.\n DESCR : str\n Description of the Labeled Faces in the Wild (LFW) dataset.", + "source_code": "\ndef fetch_lfw_pairs(*, subset='train', data_home=None, funneled=True, resize=0.5, color=False, slice_=(slice(70, 195), slice(78, 172)), download_if_missing=True):\n \"\"\"Load the Labeled Faces in the Wild (LFW) pairs dataset (classification).\n\n Download it if necessary.\n\n ================= =======================\n Classes 2\n Samples total 13233\n Dimensionality 5828\n Features real, between 0 and 255\n ================= =======================\n\n In the official `README.txt`_ this task is described as the\n \"Restricted\" task. As I am not sure as to implement the\n \"Unrestricted\" variant correctly, I left it as unsupported for now.\n\n .. _`README.txt`: http://vis-www.cs.umass.edu/lfw/README.txt\n\n The original images are 250 x 250 pixels, but the default slice and resize\n arguments reduce them to 62 x 47.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n subset : {'train', 'test', '10_folds'}, default='train'\n Select the dataset to load: 'train' for the development training\n set, 'test' for the development test set, and '10_folds' for the\n official evaluation set that is meant to be used with a 10-folds\n cross validation.\n\n data_home : str, default=None\n Specify another download and cache folder for the datasets. By\n default all scikit-learn data is stored in '~/scikit_learn_data'\n subfolders.\n\n funneled : bool, default=True\n Download and use the funneled variant of the dataset.\n\n resize : float, default=0.5\n Ratio used to resize the each face picture.\n\n color : bool, default=False\n Keep the 3 RGB channels instead of averaging them to a single\n gray level channel. If color is True the shape of the data has\n one more dimension than the shape with color = False.\n\n slice_ : tuple of slice, default=(slice(70, 195), slice(78, 172))\n Provide a custom 2D slice (height, width) to extract the\n 'interesting' part of the jpeg files and avoid use statistical\n correlation from the background\n\n download_if_missing : bool, default=True\n If False, raise a IOError if the data is not locally available\n instead of trying to download the data from the source site.\n\n Returns\n -------\n data : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data : ndarray of shape (2200, 5828). Shape depends on ``subset``.\n Each row corresponds to 2 ravel'd face images\n of original size 62 x 47 pixels.\n Changing the ``slice_``, ``resize`` or ``subset`` parameters\n will change the shape of the output.\n pairs : ndarray of shape (2200, 2, 62, 47). Shape depends on ``subset``\n Each row has 2 face images corresponding\n to same or different person from the dataset\n containing 5749 people. Changing the ``slice_``,\n ``resize`` or ``subset`` parameters will change the shape of the\n output.\n target : numpy array of shape (2200,). Shape depends on ``subset``.\n Labels associated to each pair of images.\n The two label values being different persons or the same person.\n DESCR : str\n Description of the Labeled Faces in the Wild (LFW) dataset.\n\n \"\"\"\n (lfw_home, data_folder_path) = _check_fetch_lfw(data_home=data_home, funneled=funneled, download_if_missing=download_if_missing)\n logger.debug('Loading %s LFW pairs from %s', subset, lfw_home)\n if parse_version(joblib.__version__) < parse_version('0.12'):\n m = Memory(cachedir=lfw_home, compress=6, verbose=0)\n else:\n m = Memory(location=lfw_home, compress=6, verbose=0)\n load_func = m.cache(_fetch_lfw_pairs)\n label_filenames = {'train': 'pairsDevTrain.txt', 'test': 'pairsDevTest.txt', '10_folds': 'pairs.txt'}\n if subset not in label_filenames:\n raise ValueError(\"subset='%s' is invalid: should be one of %r\" % (subset, list(sorted(label_filenames.keys()))))\n index_file_path = join(lfw_home, label_filenames[subset])\n (pairs, target, target_names) = load_func(index_file_path, data_folder_path, resize=resize, color=color, slice_=slice_)\n fdescr = load_descr('lfw.rst')\n return Bunch(data=pairs.reshape(len(pairs), -1), pairs=pairs, target=target, target_names=target_names, DESCR=fdescr)" }, { "name": "fetch_lfw_people", + "unique_name": "fetch_lfw_people", "qname": "sklearn.datasets._lfw.fetch_lfw_people", + "unique_qname": "sklearn.datasets._lfw.fetch_lfw_people", "decorators": [], "parameters": [ { @@ -43012,12 +43763,14 @@ "results": [], "is_public": true, "description": "Load the Labeled Faces in the Wild (LFW) people dataset (classification).\n\nDownload it if necessary. ================= ======================= Classes 5749 Samples total 13233 Dimensionality 5828 Features real, between 0 and 255 ================= ======================= Read more in the :ref:`User Guide `.", - "docstring": "Load the Labeled Faces in the Wild (LFW) people dataset (classification).\n\nDownload it if necessary.\n\n================= =======================\nClasses 5749\nSamples total 13233\nDimensionality 5828\nFeatures real, between 0 and 255\n================= =======================\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\ndata_home : str, default=None\n Specify another download and cache folder for the datasets. By default\n all scikit-learn data is stored in '~/scikit_learn_data' subfolders.\n\nfunneled : bool, default=True\n Download and use the funneled variant of the dataset.\n\nresize : float, default=0.5\n Ratio used to resize the each face picture.\n\nmin_faces_per_person : int, default=None\n The extracted dataset will only retain pictures of people that have at\n least `min_faces_per_person` different pictures.\n\ncolor : bool, default=False\n Keep the 3 RGB channels instead of averaging them to a single\n gray level channel. If color is True the shape of the data has\n one more dimension than the shape with color = False.\n\nslice_ : tuple of slice, default=(slice(70, 195), slice(78, 172))\n Provide a custom 2D slice (height, width) to extract the\n 'interesting' part of the jpeg files and avoid use statistical\n correlation from the background\n\ndownload_if_missing : bool, default=True\n If False, raise a IOError if the data is not locally available\n instead of trying to download the data from the source site.\n\nreturn_X_y : bool, default=False\n If True, returns ``(dataset.data, dataset.target)`` instead of a Bunch\n object. See below for more information about the `dataset.data` and\n `dataset.target` object.\n\n .. versionadded:: 0.20\n\nReturns\n-------\ndataset : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data : numpy array of shape (13233, 2914)\n Each row corresponds to a ravelled face image\n of original size 62 x 47 pixels.\n Changing the ``slice_`` or resize parameters will change the\n shape of the output.\n images : numpy array of shape (13233, 62, 47)\n Each row is a face image corresponding to one of the 5749 people in\n the dataset. Changing the ``slice_``\n or resize parameters will change the shape of the output.\n target : numpy array of shape (13233,)\n Labels associated to each face image.\n Those labels range from 0-5748 and correspond to the person IDs.\n DESCR : string\n Description of the Labeled Faces in the Wild (LFW) dataset.\n\n(data, target) : tuple if ``return_X_y`` is True\n\n .. versionadded:: 0.20", - "source_code": "\ndef fetch_lfw_people(*, data_home=None, funneled=True, resize=0.5, min_faces_per_person=0, color=False, slice_=(slice(70, 195), slice(78, 172)), download_if_missing=True, return_X_y=False):\n \"\"\"Load the Labeled Faces in the Wild (LFW) people dataset (classification).\n\n Download it if necessary.\n\n ================= =======================\n Classes 5749\n Samples total 13233\n Dimensionality 5828\n Features real, between 0 and 255\n ================= =======================\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n data_home : str, default=None\n Specify another download and cache folder for the datasets. By default\n all scikit-learn data is stored in '~/scikit_learn_data' subfolders.\n\n funneled : bool, default=True\n Download and use the funneled variant of the dataset.\n\n resize : float, default=0.5\n Ratio used to resize the each face picture.\n\n min_faces_per_person : int, default=None\n The extracted dataset will only retain pictures of people that have at\n least `min_faces_per_person` different pictures.\n\n color : bool, default=False\n Keep the 3 RGB channels instead of averaging them to a single\n gray level channel. If color is True the shape of the data has\n one more dimension than the shape with color = False.\n\n slice_ : tuple of slice, default=(slice(70, 195), slice(78, 172))\n Provide a custom 2D slice (height, width) to extract the\n 'interesting' part of the jpeg files and avoid use statistical\n correlation from the background\n\n download_if_missing : bool, default=True\n If False, raise a IOError if the data is not locally available\n instead of trying to download the data from the source site.\n\n return_X_y : bool, default=False\n If True, returns ``(dataset.data, dataset.target)`` instead of a Bunch\n object. See below for more information about the `dataset.data` and\n `dataset.target` object.\n\n .. versionadded:: 0.20\n\n Returns\n -------\n dataset : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data : numpy array of shape (13233, 2914)\n Each row corresponds to a ravelled face image\n of original size 62 x 47 pixels.\n Changing the ``slice_`` or resize parameters will change the\n shape of the output.\n images : numpy array of shape (13233, 62, 47)\n Each row is a face image corresponding to one of the 5749 people in\n the dataset. Changing the ``slice_``\n or resize parameters will change the shape of the output.\n target : numpy array of shape (13233,)\n Labels associated to each face image.\n Those labels range from 0-5748 and correspond to the person IDs.\n DESCR : string\n Description of the Labeled Faces in the Wild (LFW) dataset.\n\n (data, target) : tuple if ``return_X_y`` is True\n\n .. versionadded:: 0.20\n\n \"\"\"\n (lfw_home, data_folder_path) = _check_fetch_lfw(data_home=data_home, funneled=funneled, download_if_missing=download_if_missing)\n logger.debug('Loading LFW people faces from %s', lfw_home)\n if parse_version(joblib.__version__) < parse_version('0.12'):\n m = Memory(cachedir=lfw_home, compress=6, verbose=0)\n else:\n m = Memory(location=lfw_home, compress=6, verbose=0)\n load_func = m.cache(_fetch_lfw_people)\n (faces, target, target_names) = load_func(data_folder_path, resize=resize, min_faces_per_person=min_faces_per_person, color=color, slice_=slice_)\n X = faces.reshape(len(faces), -1)\n fdescr = load_descr('lfw.rst')\n if return_X_y:\n return X, target\n return Bunch(data=X, images=faces, target=target, target_names=target_names, DESCR=fdescr)" + "docstring": "Load the Labeled Faces in the Wild (LFW) people dataset (classification).\n\nDownload it if necessary.\n\n================= =======================\nClasses 5749\nSamples total 13233\nDimensionality 5828\nFeatures real, between 0 and 255\n================= =======================\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\ndata_home : str, default=None\n Specify another download and cache folder for the datasets. By default\n all scikit-learn data is stored in '~/scikit_learn_data' subfolders.\n\nfunneled : bool, default=True\n Download and use the funneled variant of the dataset.\n\nresize : float, default=0.5\n Ratio used to resize the each face picture.\n\nmin_faces_per_person : int, default=None\n The extracted dataset will only retain pictures of people that have at\n least `min_faces_per_person` different pictures.\n\ncolor : bool, default=False\n Keep the 3 RGB channels instead of averaging them to a single\n gray level channel. If color is True the shape of the data has\n one more dimension than the shape with color = False.\n\nslice_ : tuple of slice, default=(slice(70, 195), slice(78, 172))\n Provide a custom 2D slice (height, width) to extract the\n 'interesting' part of the jpeg files and avoid use statistical\n correlation from the background\n\ndownload_if_missing : bool, default=True\n If False, raise a IOError if the data is not locally available\n instead of trying to download the data from the source site.\n\nreturn_X_y : bool, default=False\n If True, returns ``(dataset.data, dataset.target)`` instead of a Bunch\n object. See below for more information about the `dataset.data` and\n `dataset.target` object.\n\n .. versionadded:: 0.20\n\nReturns\n-------\ndataset : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data : numpy array of shape (13233, 2914)\n Each row corresponds to a ravelled face image\n of original size 62 x 47 pixels.\n Changing the ``slice_`` or resize parameters will change the\n shape of the output.\n images : numpy array of shape (13233, 62, 47)\n Each row is a face image corresponding to one of the 5749 people in\n the dataset. Changing the ``slice_``\n or resize parameters will change the shape of the output.\n target : numpy array of shape (13233,)\n Labels associated to each face image.\n Those labels range from 0-5748 and correspond to the person IDs.\n DESCR : str\n Description of the Labeled Faces in the Wild (LFW) dataset.\n\n(data, target) : tuple if ``return_X_y`` is True\n\n .. versionadded:: 0.20", + "source_code": "\ndef fetch_lfw_people(*, data_home=None, funneled=True, resize=0.5, min_faces_per_person=0, color=False, slice_=(slice(70, 195), slice(78, 172)), download_if_missing=True, return_X_y=False):\n \"\"\"Load the Labeled Faces in the Wild (LFW) people dataset (classification).\n\n Download it if necessary.\n\n ================= =======================\n Classes 5749\n Samples total 13233\n Dimensionality 5828\n Features real, between 0 and 255\n ================= =======================\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n data_home : str, default=None\n Specify another download and cache folder for the datasets. By default\n all scikit-learn data is stored in '~/scikit_learn_data' subfolders.\n\n funneled : bool, default=True\n Download and use the funneled variant of the dataset.\n\n resize : float, default=0.5\n Ratio used to resize the each face picture.\n\n min_faces_per_person : int, default=None\n The extracted dataset will only retain pictures of people that have at\n least `min_faces_per_person` different pictures.\n\n color : bool, default=False\n Keep the 3 RGB channels instead of averaging them to a single\n gray level channel. If color is True the shape of the data has\n one more dimension than the shape with color = False.\n\n slice_ : tuple of slice, default=(slice(70, 195), slice(78, 172))\n Provide a custom 2D slice (height, width) to extract the\n 'interesting' part of the jpeg files and avoid use statistical\n correlation from the background\n\n download_if_missing : bool, default=True\n If False, raise a IOError if the data is not locally available\n instead of trying to download the data from the source site.\n\n return_X_y : bool, default=False\n If True, returns ``(dataset.data, dataset.target)`` instead of a Bunch\n object. See below for more information about the `dataset.data` and\n `dataset.target` object.\n\n .. versionadded:: 0.20\n\n Returns\n -------\n dataset : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data : numpy array of shape (13233, 2914)\n Each row corresponds to a ravelled face image\n of original size 62 x 47 pixels.\n Changing the ``slice_`` or resize parameters will change the\n shape of the output.\n images : numpy array of shape (13233, 62, 47)\n Each row is a face image corresponding to one of the 5749 people in\n the dataset. Changing the ``slice_``\n or resize parameters will change the shape of the output.\n target : numpy array of shape (13233,)\n Labels associated to each face image.\n Those labels range from 0-5748 and correspond to the person IDs.\n DESCR : str\n Description of the Labeled Faces in the Wild (LFW) dataset.\n\n (data, target) : tuple if ``return_X_y`` is True\n\n .. versionadded:: 0.20\n\n \"\"\"\n (lfw_home, data_folder_path) = _check_fetch_lfw(data_home=data_home, funneled=funneled, download_if_missing=download_if_missing)\n logger.debug('Loading LFW people faces from %s', lfw_home)\n if parse_version(joblib.__version__) < parse_version('0.12'):\n m = Memory(cachedir=lfw_home, compress=6, verbose=0)\n else:\n m = Memory(location=lfw_home, compress=6, verbose=0)\n load_func = m.cache(_fetch_lfw_people)\n (faces, target, target_names) = load_func(data_folder_path, resize=resize, min_faces_per_person=min_faces_per_person, color=color, slice_=slice_)\n X = faces.reshape(len(faces), -1)\n fdescr = load_descr('lfw.rst')\n if return_X_y:\n return X, target\n return Bunch(data=X, images=faces, target=target, target_names=target_names, DESCR=fdescr)" }, { "name": "fetch_olivetti_faces", + "unique_name": "fetch_olivetti_faces", "qname": "sklearn.datasets._olivetti_faces.fetch_olivetti_faces", + "unique_qname": "sklearn.datasets._olivetti_faces.fetch_olivetti_faces", "decorators": [], "parameters": [ { @@ -43079,7 +43832,9 @@ }, { "name": "_convert_arff_data", + "unique_name": "_convert_arff_data", "qname": "sklearn.datasets._openml._convert_arff_data", + "unique_qname": "sklearn.datasets._openml._convert_arff_data", "decorators": [], "parameters": [ { @@ -43131,7 +43886,9 @@ }, { "name": "_convert_arff_data_dataframe", + "unique_name": "_convert_arff_data_dataframe", "qname": "sklearn.datasets._openml._convert_arff_data_dataframe", + "unique_qname": "sklearn.datasets._openml._convert_arff_data_dataframe", "decorators": [], "parameters": [ { @@ -43173,7 +43930,9 @@ }, { "name": "_download_data_to_bunch", + "unique_name": "_download_data_to_bunch", "qname": "sklearn.datasets._openml._download_data_to_bunch", + "unique_qname": "sklearn.datasets._openml._download_data_to_bunch", "decorators": [], "parameters": [ { @@ -43275,7 +44034,9 @@ }, { "name": "_feature_to_dtype", + "unique_name": "_feature_to_dtype", "qname": "sklearn.datasets._openml._feature_to_dtype", + "unique_qname": "sklearn.datasets._openml._feature_to_dtype", "decorators": [], "parameters": [ { @@ -43297,7 +44058,9 @@ }, { "name": "_get_data_description_by_id", + "unique_name": "_get_data_description_by_id", "qname": "sklearn.datasets._openml._get_data_description_by_id", + "unique_qname": "sklearn.datasets._openml._get_data_description_by_id", "decorators": [], "parameters": [ { @@ -43329,7 +44092,9 @@ }, { "name": "_get_data_features", + "unique_name": "_get_data_features", "qname": "sklearn.datasets._openml._get_data_features", + "unique_qname": "sklearn.datasets._openml._get_data_features", "decorators": [], "parameters": [ { @@ -43361,7 +44126,9 @@ }, { "name": "_get_data_info_by_name", + "unique_name": "_get_data_info_by_name", "qname": "sklearn.datasets._openml._get_data_info_by_name", + "unique_qname": "sklearn.datasets._openml._get_data_info_by_name", "decorators": [], "parameters": [ { @@ -43403,7 +44170,9 @@ }, { "name": "_get_data_qualities", + "unique_name": "_get_data_qualities", "qname": "sklearn.datasets._openml._get_data_qualities", + "unique_qname": "sklearn.datasets._openml._get_data_qualities", "decorators": [], "parameters": [ { @@ -43435,7 +44204,9 @@ }, { "name": "_get_json_content_from_openml_api", + "unique_name": "_get_json_content_from_openml_api", "qname": "sklearn.datasets._openml._get_json_content_from_openml_api", + "unique_qname": "sklearn.datasets._openml._get_json_content_from_openml_api", "decorators": [], "parameters": [ { @@ -43477,7 +44248,9 @@ }, { "name": "_get_local_path", + "unique_name": "_get_local_path", "qname": "sklearn.datasets._openml._get_local_path", + "unique_qname": "sklearn.datasets._openml._get_local_path", "decorators": [], "parameters": [ { @@ -43509,7 +44282,9 @@ }, { "name": "_get_num_samples", + "unique_name": "_get_num_samples", "qname": "sklearn.datasets._openml._get_num_samples", + "unique_qname": "sklearn.datasets._openml._get_num_samples", "decorators": [], "parameters": [ { @@ -43531,7 +44306,9 @@ }, { "name": "_load_arff_response", + "unique_name": "_load_arff_response", "qname": "sklearn.datasets._openml._load_arff_response", + "unique_qname": "sklearn.datasets._openml._load_arff_response", "decorators": [], "parameters": [ { @@ -43603,7 +44380,9 @@ }, { "name": "_open_openml_url", + "unique_name": "_open_openml_url", "qname": "sklearn.datasets._openml._open_openml_url", + "unique_qname": "sklearn.datasets._openml._open_openml_url", "decorators": [], "parameters": [ { @@ -43635,7 +44414,9 @@ }, { "name": "_retry_with_clean_cache", + "unique_name": "_retry_with_clean_cache", "qname": "sklearn.datasets._openml._retry_with_clean_cache", + "unique_qname": "sklearn.datasets._openml._retry_with_clean_cache", "decorators": [], "parameters": [ { @@ -43667,7 +44448,9 @@ }, { "name": "_sparse_data_to_array", + "unique_name": "_sparse_data_to_array", "qname": "sklearn.datasets._openml._sparse_data_to_array", + "unique_qname": "sklearn.datasets._openml._sparse_data_to_array", "decorators": [], "parameters": [ { @@ -43699,7 +44482,9 @@ }, { "name": "_split_sparse_columns", + "unique_name": "_split_sparse_columns", "qname": "sklearn.datasets._openml._split_sparse_columns", + "unique_qname": "sklearn.datasets._openml._split_sparse_columns", "decorators": [], "parameters": [ { @@ -43731,7 +44516,9 @@ }, { "name": "_valid_data_column_names", + "unique_name": "_valid_data_column_names", "qname": "sklearn.datasets._openml._valid_data_column_names", + "unique_qname": "sklearn.datasets._openml._valid_data_column_names", "decorators": [], "parameters": [ { @@ -43763,7 +44550,9 @@ }, { "name": "_verify_target_data_type", + "unique_name": "_verify_target_data_type", "qname": "sklearn.datasets._openml._verify_target_data_type", + "unique_qname": "sklearn.datasets._openml._verify_target_data_type", "decorators": [], "parameters": [ { @@ -43795,7 +44584,9 @@ }, { "name": "fetch_openml", + "unique_name": "fetch_openml", "qname": "sklearn.datasets._openml.fetch_openml", + "unique_qname": "sklearn.datasets._openml.fetch_openml", "decorators": [], "parameters": [ { @@ -43887,7 +44678,9 @@ }, { "name": "_find_permutation", + "unique_name": "_find_permutation", "qname": "sklearn.datasets._rcv1._find_permutation", + "unique_qname": "sklearn.datasets._rcv1._find_permutation", "decorators": [], "parameters": [ { @@ -43919,7 +44712,9 @@ }, { "name": "_inverse_permutation", + "unique_name": "_inverse_permutation", "qname": "sklearn.datasets._rcv1._inverse_permutation", + "unique_qname": "sklearn.datasets._rcv1._inverse_permutation", "decorators": [], "parameters": [ { @@ -43941,7 +44736,9 @@ }, { "name": "fetch_rcv1", + "unique_name": "fetch_rcv1", "qname": "sklearn.datasets._rcv1.fetch_rcv1", + "unique_qname": "sklearn.datasets._rcv1.fetch_rcv1", "decorators": [], "parameters": [ { @@ -44013,7 +44810,9 @@ }, { "name": "_generate_hypercube", + "unique_name": "_generate_hypercube", "qname": "sklearn.datasets._samples_generator._generate_hypercube", + "unique_qname": "sklearn.datasets._samples_generator._generate_hypercube", "decorators": [], "parameters": [ { @@ -44055,7 +44854,9 @@ }, { "name": "_shuffle", + "unique_name": "_shuffle", "qname": "sklearn.datasets._samples_generator._shuffle", + "unique_qname": "sklearn.datasets._samples_generator._shuffle", "decorators": [], "parameters": [ { @@ -44087,7 +44888,9 @@ }, { "name": "make_biclusters", + "unique_name": "make_biclusters", "qname": "sklearn.datasets._samples_generator.make_biclusters", + "unique_qname": "sklearn.datasets._samples_generator.make_biclusters", "decorators": [], "parameters": [ { @@ -44169,7 +44972,9 @@ }, { "name": "make_blobs", + "unique_name": "make_blobs", "qname": "sklearn.datasets._samples_generator.make_blobs", + "unique_qname": "sklearn.datasets._samples_generator.make_blobs", "decorators": [], "parameters": [ { @@ -44261,7 +45066,9 @@ }, { "name": "make_checkerboard", + "unique_name": "make_checkerboard", "qname": "sklearn.datasets._samples_generator.make_checkerboard", + "unique_qname": "sklearn.datasets._samples_generator.make_checkerboard", "decorators": [], "parameters": [ { @@ -44343,7 +45150,9 @@ }, { "name": "make_circles", + "unique_name": "make_circles", "qname": "sklearn.datasets._samples_generator.make_circles", + "unique_qname": "sklearn.datasets._samples_generator.make_circles", "decorators": [], "parameters": [ { @@ -44405,7 +45214,9 @@ }, { "name": "make_classification", + "unique_name": "make_classification", "qname": "sklearn.datasets._samples_generator.make_classification", + "unique_qname": "sklearn.datasets._samples_generator.make_classification", "decorators": [], "parameters": [ { @@ -44567,7 +45378,9 @@ }, { "name": "make_friedman1", + "unique_name": "make_friedman1", "qname": "sklearn.datasets._samples_generator.make_friedman1", + "unique_qname": "sklearn.datasets._samples_generator.make_friedman1", "decorators": [], "parameters": [ { @@ -44619,7 +45432,9 @@ }, { "name": "make_friedman2", + "unique_name": "make_friedman2", "qname": "sklearn.datasets._samples_generator.make_friedman2", + "unique_qname": "sklearn.datasets._samples_generator.make_friedman2", "decorators": [], "parameters": [ { @@ -44661,7 +45476,9 @@ }, { "name": "make_friedman3", + "unique_name": "make_friedman3", "qname": "sklearn.datasets._samples_generator.make_friedman3", + "unique_qname": "sklearn.datasets._samples_generator.make_friedman3", "decorators": [], "parameters": [ { @@ -44703,7 +45520,9 @@ }, { "name": "make_gaussian_quantiles", + "unique_name": "make_gaussian_quantiles", "qname": "sklearn.datasets._samples_generator.make_gaussian_quantiles", + "unique_qname": "sklearn.datasets._samples_generator.make_gaussian_quantiles", "decorators": [], "parameters": [ { @@ -44785,7 +45604,9 @@ }, { "name": "make_hastie_10_2", + "unique_name": "make_hastie_10_2", "qname": "sklearn.datasets._samples_generator.make_hastie_10_2", + "unique_qname": "sklearn.datasets._samples_generator.make_hastie_10_2", "decorators": [], "parameters": [ { @@ -44817,7 +45638,9 @@ }, { "name": "make_low_rank_matrix", + "unique_name": "make_low_rank_matrix", "qname": "sklearn.datasets._samples_generator.make_low_rank_matrix", + "unique_qname": "sklearn.datasets._samples_generator.make_low_rank_matrix", "decorators": [], "parameters": [ { @@ -44879,7 +45702,9 @@ }, { "name": "make_moons", + "unique_name": "make_moons", "qname": "sklearn.datasets._samples_generator.make_moons", + "unique_qname": "sklearn.datasets._samples_generator.make_moons", "decorators": [], "parameters": [ { @@ -44931,7 +45756,9 @@ }, { "name": "make_multilabel_classification", + "unique_name": "make_multilabel_classification", "qname": "sklearn.datasets._samples_generator.make_multilabel_classification", + "unique_qname": "sklearn.datasets._samples_generator.make_multilabel_classification", "decorators": [], "parameters": [ { @@ -45043,7 +45870,9 @@ }, { "name": "make_regression", + "unique_name": "make_regression", "qname": "sklearn.datasets._samples_generator.make_regression", + "unique_qname": "sklearn.datasets._samples_generator.make_regression", "decorators": [], "parameters": [ { @@ -45165,7 +45994,9 @@ }, { "name": "make_s_curve", + "unique_name": "make_s_curve", "qname": "sklearn.datasets._samples_generator.make_s_curve", + "unique_qname": "sklearn.datasets._samples_generator.make_s_curve", "decorators": [], "parameters": [ { @@ -45207,7 +46038,9 @@ }, { "name": "make_sparse_coded_signal", + "unique_name": "make_sparse_coded_signal", "qname": "sklearn.datasets._samples_generator.make_sparse_coded_signal", + "unique_qname": "sklearn.datasets._samples_generator.make_sparse_coded_signal", "decorators": [], "parameters": [ { @@ -45269,7 +46102,9 @@ }, { "name": "make_sparse_spd_matrix", + "unique_name": "make_sparse_spd_matrix", "qname": "sklearn.datasets._samples_generator.make_sparse_spd_matrix", + "unique_qname": "sklearn.datasets._samples_generator.make_sparse_spd_matrix", "decorators": [], "parameters": [ { @@ -45341,7 +46176,9 @@ }, { "name": "make_sparse_uncorrelated", + "unique_name": "make_sparse_uncorrelated", "qname": "sklearn.datasets._samples_generator.make_sparse_uncorrelated", + "unique_qname": "sklearn.datasets._samples_generator.make_sparse_uncorrelated", "decorators": [], "parameters": [ { @@ -45383,7 +46220,9 @@ }, { "name": "make_spd_matrix", + "unique_name": "make_spd_matrix", "qname": "sklearn.datasets._samples_generator.make_spd_matrix", + "unique_qname": "sklearn.datasets._samples_generator.make_spd_matrix", "decorators": [], "parameters": [ { @@ -45415,7 +46254,9 @@ }, { "name": "make_swiss_roll", + "unique_name": "make_swiss_roll", "qname": "sklearn.datasets._samples_generator.make_swiss_roll", + "unique_qname": "sklearn.datasets._samples_generator.make_swiss_roll", "decorators": [], "parameters": [ { @@ -45457,7 +46298,9 @@ }, { "name": "_load_coverage", + "unique_name": "_load_coverage", "qname": "sklearn.datasets._species_distributions._load_coverage", + "unique_qname": "sklearn.datasets._species_distributions._load_coverage", "decorators": [], "parameters": [ { @@ -45499,7 +46342,9 @@ }, { "name": "_load_csv", + "unique_name": "_load_csv", "qname": "sklearn.datasets._species_distributions._load_csv", + "unique_qname": "sklearn.datasets._species_distributions._load_csv", "decorators": [], "parameters": [ { @@ -45521,7 +46366,9 @@ }, { "name": "construct_grids", + "unique_name": "construct_grids", "qname": "sklearn.datasets._species_distributions.construct_grids", + "unique_qname": "sklearn.datasets._species_distributions.construct_grids", "decorators": [], "parameters": [ { @@ -45543,7 +46390,9 @@ }, { "name": "fetch_species_distributions", + "unique_name": "fetch_species_distributions", "qname": "sklearn.datasets._species_distributions.fetch_species_distributions", + "unique_qname": "sklearn.datasets._species_distributions.fetch_species_distributions", "decorators": [], "parameters": [ { @@ -45575,7 +46424,9 @@ }, { "name": "_dump_svmlight", + "unique_name": "_dump_svmlight", "qname": "sklearn.datasets._svmlight_format_io._dump_svmlight", + "unique_qname": "sklearn.datasets._svmlight_format_io._dump_svmlight", "decorators": [], "parameters": [ { @@ -45657,7 +46508,9 @@ }, { "name": "_gen_open", + "unique_name": "_gen_open", "qname": "sklearn.datasets._svmlight_format_io._gen_open", + "unique_qname": "sklearn.datasets._svmlight_format_io._gen_open", "decorators": [], "parameters": [ { @@ -45679,7 +46532,9 @@ }, { "name": "_load_svmlight_file", + "unique_name": "_load_svmlight_file", "qname": "sklearn.datasets._svmlight_format_io._load_svmlight_file", + "unique_qname": "sklearn.datasets._svmlight_format_io._load_svmlight_file", "decorators": [], "parameters": [], "results": [], @@ -45690,7 +46545,9 @@ }, { "name": "_open_and_load", + "unique_name": "_open_and_load", "qname": "sklearn.datasets._svmlight_format_io._open_and_load", + "unique_qname": "sklearn.datasets._svmlight_format_io._open_and_load", "decorators": [], "parameters": [ { @@ -45772,7 +46629,9 @@ }, { "name": "dump_svmlight_file", + "unique_name": "dump_svmlight_file", "qname": "sklearn.datasets._svmlight_format_io.dump_svmlight_file", + "unique_qname": "sklearn.datasets._svmlight_format_io.dump_svmlight_file", "decorators": [], "parameters": [ { @@ -45801,7 +46660,7 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "string or file-like in binary mode", + "type": "str or file-like in binary mode", "description": "If string, specifies the path that will contain the data.\nIf file-like, data will be written to f. f should be opened in binary\nmode." } }, @@ -45821,7 +46680,7 @@ "is_public": true, "assigned_by": "NAME_ONLY", "docstring": { - "type": "string, default=None", + "type": "str, default=None", "description": "Comment to insert at the top of the file. This should be either a\nUnicode string, which will be encoded as UTF-8, or an ASCII byte\nstring.\nIf a comment is given, then it will be preceded by one that identifies\nthe file as having been dumped by scikit-learn. Note that not all\ntools grok comments in SVMlight files." } }, @@ -45849,12 +46708,14 @@ "results": [], "is_public": true, "description": "Dump the dataset in svmlight / libsvm file format.\n\nThis format is a text-based format, with one sample per line. It does not store zero valued features hence is suitable for sparse dataset. The first element of each line can be used to store a target variable to predict.", - "docstring": "Dump the dataset in svmlight / libsvm file format.\n\nThis format is a text-based format, with one sample per line. It does\nnot store zero valued features hence is suitable for sparse dataset.\n\nThe first element of each line can be used to store a target variable\nto predict.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\ny : {array-like, sparse matrix}, shape = [n_samples (, n_labels)]\n Target values. Class labels must be an\n integer or float, or array-like objects of integer or float for\n multilabel classifications.\n\nf : string or file-like in binary mode\n If string, specifies the path that will contain the data.\n If file-like, data will be written to f. f should be opened in binary\n mode.\n\nzero_based : boolean, default=True\n Whether column indices should be written zero-based (True) or one-based\n (False).\n\ncomment : string, default=None\n Comment to insert at the top of the file. This should be either a\n Unicode string, which will be encoded as UTF-8, or an ASCII byte\n string.\n If a comment is given, then it will be preceded by one that identifies\n the file as having been dumped by scikit-learn. Note that not all\n tools grok comments in SVMlight files.\n\nquery_id : array-like of shape (n_samples,), default=None\n Array containing pairwise preference constraints (qid in svmlight\n format).\n\nmultilabel : boolean, default=False\n Samples may have several labels each (see\n https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/multilabel.html)\n\n .. versionadded:: 0.17\n parameter *multilabel* to support multilabel datasets.", - "source_code": "\ndef dump_svmlight_file(X, y, f, *, zero_based=True, comment=None, query_id=None, multilabel=False):\n \"\"\"Dump the dataset in svmlight / libsvm file format.\n\n This format is a text-based format, with one sample per line. It does\n not store zero valued features hence is suitable for sparse dataset.\n\n The first element of each line can be used to store a target variable\n to predict.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : {array-like, sparse matrix}, shape = [n_samples (, n_labels)]\n Target values. Class labels must be an\n integer or float, or array-like objects of integer or float for\n multilabel classifications.\n\n f : string or file-like in binary mode\n If string, specifies the path that will contain the data.\n If file-like, data will be written to f. f should be opened in binary\n mode.\n\n zero_based : boolean, default=True\n Whether column indices should be written zero-based (True) or one-based\n (False).\n\n comment : string, default=None\n Comment to insert at the top of the file. This should be either a\n Unicode string, which will be encoded as UTF-8, or an ASCII byte\n string.\n If a comment is given, then it will be preceded by one that identifies\n the file as having been dumped by scikit-learn. Note that not all\n tools grok comments in SVMlight files.\n\n query_id : array-like of shape (n_samples,), default=None\n Array containing pairwise preference constraints (qid in svmlight\n format).\n\n multilabel : boolean, default=False\n Samples may have several labels each (see\n https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/multilabel.html)\n\n .. versionadded:: 0.17\n parameter *multilabel* to support multilabel datasets.\n \"\"\"\n if comment is not None:\n if isinstance(comment, bytes):\n comment.decode('ascii')\n else:\n comment = comment.encode('utf-8')\n if b'\\x00' in comment:\n raise ValueError('comment string contains NUL byte')\n yval = check_array(y, accept_sparse='csr', ensure_2d=False)\n if sp.issparse(yval):\n if yval.shape[1] != 1 and not multilabel:\n raise ValueError('expected y of shape (n_samples, 1), got %r' % (yval.shape, ))\n elif yval.ndim != 1 and not multilabel:\n raise ValueError('expected y of shape (n_samples,), got %r' % (yval.shape, ))\n Xval = check_array(X, accept_sparse='csr')\n if Xval.shape[0] != yval.shape[0]:\n raise ValueError('X.shape[0] and y.shape[0] should be the same, got %r and %r instead.' % (Xval.shape[0], yval.shape[0]))\n if yval is y and hasattr(yval, 'sorted_indices'):\n y = yval.sorted_indices()\n else:\n y = yval\n if hasattr(y, 'sort_indices'):\n y.sort_indices()\n if Xval is X and hasattr(Xval, 'sorted_indices'):\n X = Xval.sorted_indices()\n else:\n X = Xval\n if hasattr(X, 'sort_indices'):\n X.sort_indices()\n if query_id is not None:\n query_id = np.asarray(query_id)\n if query_id.shape[0] != y.shape[0]:\n raise ValueError('expected query_id of shape (n_samples,), got %r' % (query_id.shape, ))\n one_based = not zero_based\n if hasattr(f, 'write'):\n _dump_svmlight(X, y, f, multilabel, one_based, comment, query_id)\n else:\n with open(f, 'wb') as f:\n _dump_svmlight(X, y, f, multilabel, one_based, comment, query_id)" + "docstring": "Dump the dataset in svmlight / libsvm file format.\n\nThis format is a text-based format, with one sample per line. It does\nnot store zero valued features hence is suitable for sparse dataset.\n\nThe first element of each line can be used to store a target variable\nto predict.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\ny : {array-like, sparse matrix}, shape = [n_samples (, n_labels)]\n Target values. Class labels must be an\n integer or float, or array-like objects of integer or float for\n multilabel classifications.\n\nf : str or file-like in binary mode\n If string, specifies the path that will contain the data.\n If file-like, data will be written to f. f should be opened in binary\n mode.\n\nzero_based : boolean, default=True\n Whether column indices should be written zero-based (True) or one-based\n (False).\n\ncomment : str, default=None\n Comment to insert at the top of the file. This should be either a\n Unicode string, which will be encoded as UTF-8, or an ASCII byte\n string.\n If a comment is given, then it will be preceded by one that identifies\n the file as having been dumped by scikit-learn. Note that not all\n tools grok comments in SVMlight files.\n\nquery_id : array-like of shape (n_samples,), default=None\n Array containing pairwise preference constraints (qid in svmlight\n format).\n\nmultilabel : boolean, default=False\n Samples may have several labels each (see\n https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/multilabel.html)\n\n .. versionadded:: 0.17\n parameter *multilabel* to support multilabel datasets.", + "source_code": "\ndef dump_svmlight_file(X, y, f, *, zero_based=True, comment=None, query_id=None, multilabel=False):\n \"\"\"Dump the dataset in svmlight / libsvm file format.\n\n This format is a text-based format, with one sample per line. It does\n not store zero valued features hence is suitable for sparse dataset.\n\n The first element of each line can be used to store a target variable\n to predict.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : {array-like, sparse matrix}, shape = [n_samples (, n_labels)]\n Target values. Class labels must be an\n integer or float, or array-like objects of integer or float for\n multilabel classifications.\n\n f : str or file-like in binary mode\n If string, specifies the path that will contain the data.\n If file-like, data will be written to f. f should be opened in binary\n mode.\n\n zero_based : boolean, default=True\n Whether column indices should be written zero-based (True) or one-based\n (False).\n\n comment : str, default=None\n Comment to insert at the top of the file. This should be either a\n Unicode string, which will be encoded as UTF-8, or an ASCII byte\n string.\n If a comment is given, then it will be preceded by one that identifies\n the file as having been dumped by scikit-learn. Note that not all\n tools grok comments in SVMlight files.\n\n query_id : array-like of shape (n_samples,), default=None\n Array containing pairwise preference constraints (qid in svmlight\n format).\n\n multilabel : boolean, default=False\n Samples may have several labels each (see\n https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/multilabel.html)\n\n .. versionadded:: 0.17\n parameter *multilabel* to support multilabel datasets.\n \"\"\"\n if comment is not None:\n if isinstance(comment, bytes):\n comment.decode('ascii')\n else:\n comment = comment.encode('utf-8')\n if b'\\x00' in comment:\n raise ValueError('comment string contains NUL byte')\n yval = check_array(y, accept_sparse='csr', ensure_2d=False)\n if sp.issparse(yval):\n if yval.shape[1] != 1 and not multilabel:\n raise ValueError('expected y of shape (n_samples, 1), got %r' % (yval.shape, ))\n elif yval.ndim != 1 and not multilabel:\n raise ValueError('expected y of shape (n_samples,), got %r' % (yval.shape, ))\n Xval = check_array(X, accept_sparse='csr')\n if Xval.shape[0] != yval.shape[0]:\n raise ValueError('X.shape[0] and y.shape[0] should be the same, got %r and %r instead.' % (Xval.shape[0], yval.shape[0]))\n if yval is y and hasattr(yval, 'sorted_indices'):\n y = yval.sorted_indices()\n else:\n y = yval\n if hasattr(y, 'sort_indices'):\n y.sort_indices()\n if Xval is X and hasattr(Xval, 'sorted_indices'):\n X = Xval.sorted_indices()\n else:\n X = Xval\n if hasattr(X, 'sort_indices'):\n X.sort_indices()\n if query_id is not None:\n query_id = np.asarray(query_id)\n if query_id.shape[0] != y.shape[0]:\n raise ValueError('expected query_id of shape (n_samples,), got %r' % (query_id.shape, ))\n one_based = not zero_based\n if hasattr(f, 'write'):\n _dump_svmlight(X, y, f, multilabel, one_based, comment, query_id)\n else:\n with open(f, 'wb') as f:\n _dump_svmlight(X, y, f, multilabel, one_based, comment, query_id)" }, { "name": "load_svmlight_file", + "unique_name": "load_svmlight_file", "qname": "sklearn.datasets._svmlight_format_io.load_svmlight_file", + "unique_qname": "sklearn.datasets._svmlight_format_io.load_svmlight_file", "decorators": [], "parameters": [ { @@ -45946,7 +46807,9 @@ }, { "name": "load_svmlight_files", + "unique_name": "load_svmlight_files", "qname": "sklearn.datasets._svmlight_format_io.load_svmlight_files", + "unique_qname": "sklearn.datasets._svmlight_format_io.load_svmlight_files", "decorators": [], "parameters": [ { @@ -46038,7 +46901,9 @@ }, { "name": "_download_20newsgroups", + "unique_name": "_download_20newsgroups", "qname": "sklearn.datasets._twenty_newsgroups._download_20newsgroups", + "unique_qname": "sklearn.datasets._twenty_newsgroups._download_20newsgroups", "decorators": [], "parameters": [ { @@ -46070,7 +46935,9 @@ }, { "name": "fetch_20newsgroups", + "unique_name": "fetch_20newsgroups", "qname": "sklearn.datasets._twenty_newsgroups.fetch_20newsgroups", + "unique_qname": "sklearn.datasets._twenty_newsgroups.fetch_20newsgroups", "decorators": [], "parameters": [ { @@ -46099,7 +46966,7 @@ "is_public": true, "assigned_by": "NAME_ONLY", "docstring": { - "type": "array-like, dtype=str or unicode, default=None", + "type": "array-like, dtype=str, default=None", "description": "If None (default), load all the categories.\nIf not None, list of category names to load (other categories\nignored)." } }, @@ -46157,12 +47024,14 @@ "results": [], "is_public": true, "description": "Load the filenames and data from the 20 newsgroups dataset (classification).\n\nDownload it if necessary. ================= ========== Classes 20 Samples total 18846 Dimensionality 1 Features text ================= ========== Read more in the :ref:`User Guide <20newsgroups_dataset>`.", - "docstring": "Load the filenames and data from the 20 newsgroups dataset (classification).\n\nDownload it if necessary.\n\n================= ==========\nClasses 20\nSamples total 18846\nDimensionality 1\nFeatures text\n================= ==========\n\nRead more in the :ref:`User Guide <20newsgroups_dataset>`.\n\nParameters\n----------\ndata_home : str, default=None\n Specify a download and cache folder for the datasets. If None,\n all scikit-learn data is stored in '~/scikit_learn_data' subfolders.\n\nsubset : {'train', 'test', 'all'}, default='train'\n Select the dataset to load: 'train' for the training set, 'test'\n for the test set, 'all' for both, with shuffled ordering.\n\ncategories : array-like, dtype=str or unicode, default=None\n If None (default), load all the categories.\n If not None, list of category names to load (other categories\n ignored).\n\nshuffle : bool, default=True\n Whether or not to shuffle the data: might be important for models that\n make the assumption that the samples are independent and identically\n distributed (i.i.d.), such as stochastic gradient descent.\n\nrandom_state : int, RandomState instance or None, default=None\n Determines random number generation for dataset shuffling. Pass an int\n for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\nremove : tuple, default=()\n May contain any subset of ('headers', 'footers', 'quotes'). Each of\n these are kinds of text that will be detected and removed from the\n newsgroup posts, preventing classifiers from overfitting on\n metadata.\n\n 'headers' removes newsgroup headers, 'footers' removes blocks at the\n ends of posts that look like signatures, and 'quotes' removes lines\n that appear to be quoting another post.\n\n 'headers' follows an exact standard; the other filters are not always\n correct.\n\ndownload_if_missing : bool, default=True\n If False, raise an IOError if the data is not locally available\n instead of trying to download the data from the source site.\n\nreturn_X_y : bool, default=False\n If True, returns `(data.data, data.target)` instead of a Bunch\n object.\n\n .. versionadded:: 0.22\n\nReturns\n-------\nbunch : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data : list of shape (n_samples,)\n The data list to learn.\n target: ndarray of shape (n_samples,)\n The target labels.\n filenames: list of shape (n_samples,)\n The path to the location of the data.\n DESCR: str\n The full description of the dataset.\n target_names: list of shape (n_classes,)\n The names of target classes.\n\n(data, target) : tuple if `return_X_y=True`\n .. versionadded:: 0.22", - "source_code": "\ndef fetch_20newsgroups(*, data_home=None, subset='train', categories=None, shuffle=True, random_state=42, remove=(), download_if_missing=True, return_X_y=False):\n \"\"\"Load the filenames and data from the 20 newsgroups dataset (classification).\n\n Download it if necessary.\n\n ================= ==========\n Classes 20\n Samples total 18846\n Dimensionality 1\n Features text\n ================= ==========\n\n Read more in the :ref:`User Guide <20newsgroups_dataset>`.\n\n Parameters\n ----------\n data_home : str, default=None\n Specify a download and cache folder for the datasets. If None,\n all scikit-learn data is stored in '~/scikit_learn_data' subfolders.\n\n subset : {'train', 'test', 'all'}, default='train'\n Select the dataset to load: 'train' for the training set, 'test'\n for the test set, 'all' for both, with shuffled ordering.\n\n categories : array-like, dtype=str or unicode, default=None\n If None (default), load all the categories.\n If not None, list of category names to load (other categories\n ignored).\n\n shuffle : bool, default=True\n Whether or not to shuffle the data: might be important for models that\n make the assumption that the samples are independent and identically\n distributed (i.i.d.), such as stochastic gradient descent.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation for dataset shuffling. Pass an int\n for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n remove : tuple, default=()\n May contain any subset of ('headers', 'footers', 'quotes'). Each of\n these are kinds of text that will be detected and removed from the\n newsgroup posts, preventing classifiers from overfitting on\n metadata.\n\n 'headers' removes newsgroup headers, 'footers' removes blocks at the\n ends of posts that look like signatures, and 'quotes' removes lines\n that appear to be quoting another post.\n\n 'headers' follows an exact standard; the other filters are not always\n correct.\n\n download_if_missing : bool, default=True\n If False, raise an IOError if the data is not locally available\n instead of trying to download the data from the source site.\n\n return_X_y : bool, default=False\n If True, returns `(data.data, data.target)` instead of a Bunch\n object.\n\n .. versionadded:: 0.22\n\n Returns\n -------\n bunch : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data : list of shape (n_samples,)\n The data list to learn.\n target: ndarray of shape (n_samples,)\n The target labels.\n filenames: list of shape (n_samples,)\n The path to the location of the data.\n DESCR: str\n The full description of the dataset.\n target_names: list of shape (n_classes,)\n The names of target classes.\n\n (data, target) : tuple if `return_X_y=True`\n .. versionadded:: 0.22\n \"\"\"\n data_home = get_data_home(data_home=data_home)\n cache_path = _pkl_filepath(data_home, CACHE_NAME)\n twenty_home = os.path.join(data_home, '20news_home')\n cache = None\n if os.path.exists(cache_path):\n try:\n with open(cache_path, 'rb') as f:\n compressed_content = f.read()\n uncompressed_content = codecs.decode(compressed_content, 'zlib_codec')\n cache = pickle.loads(uncompressed_content)\n except Exception as e:\n print(80 * '_')\n print('Cache loading failed')\n print(80 * '_')\n print(e)\n if cache is None:\n if download_if_missing:\n logger.info('Downloading 20news dataset. This may take a few minutes.')\n cache = _download_20newsgroups(target_dir=twenty_home, cache_path=cache_path)\n else:\n raise IOError('20Newsgroups dataset not found')\n if subset in ('train', 'test'):\n data = cache[subset]\n elif subset == 'all':\n data_lst = list()\n target = list()\n filenames = list()\n for subset in ('train', 'test'):\n data = cache[subset]\n data_lst.extend(data.data)\n target.extend(data.target)\n filenames.extend(data.filenames)\n data.data = data_lst\n data.target = np.array(target)\n data.filenames = np.array(filenames)\n else:\n raise ValueError(\"subset can only be 'train', 'test' or 'all', got '%s'\" % subset)\n fdescr = load_descr('twenty_newsgroups.rst')\n data.DESCR = fdescr\n if 'headers' in remove:\n data.data = [strip_newsgroup_header(text) for text in data.data]\n if 'footers' in remove:\n data.data = [strip_newsgroup_footer(text) for text in data.data]\n if 'quotes' in remove:\n data.data = [strip_newsgroup_quoting(text) for text in data.data]\n if categories is not None:\n labels = [(data.target_names.index(cat), cat) for cat in categories]\n labels.sort()\n (labels, categories) = zip(*labels)\n mask = np.in1d(data.target, labels)\n data.filenames = data.filenames[mask]\n data.target = data.target[mask]\n data.target = np.searchsorted(labels, data.target)\n data.target_names = list(categories)\n data_lst = np.array(data.data, dtype=object)\n data_lst = data_lst[mask]\n data.data = data_lst.tolist()\n if shuffle:\n random_state = check_random_state(random_state)\n indices = np.arange(data.target.shape[0])\n random_state.shuffle(indices)\n data.filenames = data.filenames[indices]\n data.target = data.target[indices]\n data_lst = np.array(data.data, dtype=object)\n data_lst = data_lst[indices]\n data.data = data_lst.tolist()\n if return_X_y:\n return data.data, data.target\n return data" + "docstring": "Load the filenames and data from the 20 newsgroups dataset (classification).\n\nDownload it if necessary.\n\n================= ==========\nClasses 20\nSamples total 18846\nDimensionality 1\nFeatures text\n================= ==========\n\nRead more in the :ref:`User Guide <20newsgroups_dataset>`.\n\nParameters\n----------\ndata_home : str, default=None\n Specify a download and cache folder for the datasets. If None,\n all scikit-learn data is stored in '~/scikit_learn_data' subfolders.\n\nsubset : {'train', 'test', 'all'}, default='train'\n Select the dataset to load: 'train' for the training set, 'test'\n for the test set, 'all' for both, with shuffled ordering.\n\ncategories : array-like, dtype=str, default=None\n If None (default), load all the categories.\n If not None, list of category names to load (other categories\n ignored).\n\nshuffle : bool, default=True\n Whether or not to shuffle the data: might be important for models that\n make the assumption that the samples are independent and identically\n distributed (i.i.d.), such as stochastic gradient descent.\n\nrandom_state : int, RandomState instance or None, default=None\n Determines random number generation for dataset shuffling. Pass an int\n for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\nremove : tuple, default=()\n May contain any subset of ('headers', 'footers', 'quotes'). Each of\n these are kinds of text that will be detected and removed from the\n newsgroup posts, preventing classifiers from overfitting on\n metadata.\n\n 'headers' removes newsgroup headers, 'footers' removes blocks at the\n ends of posts that look like signatures, and 'quotes' removes lines\n that appear to be quoting another post.\n\n 'headers' follows an exact standard; the other filters are not always\n correct.\n\ndownload_if_missing : bool, default=True\n If False, raise an IOError if the data is not locally available\n instead of trying to download the data from the source site.\n\nreturn_X_y : bool, default=False\n If True, returns `(data.data, data.target)` instead of a Bunch\n object.\n\n .. versionadded:: 0.22\n\nReturns\n-------\nbunch : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data : list of shape (n_samples,)\n The data list to learn.\n target: ndarray of shape (n_samples,)\n The target labels.\n filenames: list of shape (n_samples,)\n The path to the location of the data.\n DESCR: str\n The full description of the dataset.\n target_names: list of shape (n_classes,)\n The names of target classes.\n\n(data, target) : tuple if `return_X_y=True`\n .. versionadded:: 0.22", + "source_code": "\ndef fetch_20newsgroups(*, data_home=None, subset='train', categories=None, shuffle=True, random_state=42, remove=(), download_if_missing=True, return_X_y=False):\n \"\"\"Load the filenames and data from the 20 newsgroups dataset (classification).\n\n Download it if necessary.\n\n ================= ==========\n Classes 20\n Samples total 18846\n Dimensionality 1\n Features text\n ================= ==========\n\n Read more in the :ref:`User Guide <20newsgroups_dataset>`.\n\n Parameters\n ----------\n data_home : str, default=None\n Specify a download and cache folder for the datasets. If None,\n all scikit-learn data is stored in '~/scikit_learn_data' subfolders.\n\n subset : {'train', 'test', 'all'}, default='train'\n Select the dataset to load: 'train' for the training set, 'test'\n for the test set, 'all' for both, with shuffled ordering.\n\n categories : array-like, dtype=str, default=None\n If None (default), load all the categories.\n If not None, list of category names to load (other categories\n ignored).\n\n shuffle : bool, default=True\n Whether or not to shuffle the data: might be important for models that\n make the assumption that the samples are independent and identically\n distributed (i.i.d.), such as stochastic gradient descent.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation for dataset shuffling. Pass an int\n for reproducible output across multiple function calls.\n See :term:`Glossary `.\n\n remove : tuple, default=()\n May contain any subset of ('headers', 'footers', 'quotes'). Each of\n these are kinds of text that will be detected and removed from the\n newsgroup posts, preventing classifiers from overfitting on\n metadata.\n\n 'headers' removes newsgroup headers, 'footers' removes blocks at the\n ends of posts that look like signatures, and 'quotes' removes lines\n that appear to be quoting another post.\n\n 'headers' follows an exact standard; the other filters are not always\n correct.\n\n download_if_missing : bool, default=True\n If False, raise an IOError if the data is not locally available\n instead of trying to download the data from the source site.\n\n return_X_y : bool, default=False\n If True, returns `(data.data, data.target)` instead of a Bunch\n object.\n\n .. versionadded:: 0.22\n\n Returns\n -------\n bunch : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data : list of shape (n_samples,)\n The data list to learn.\n target: ndarray of shape (n_samples,)\n The target labels.\n filenames: list of shape (n_samples,)\n The path to the location of the data.\n DESCR: str\n The full description of the dataset.\n target_names: list of shape (n_classes,)\n The names of target classes.\n\n (data, target) : tuple if `return_X_y=True`\n .. versionadded:: 0.22\n \"\"\"\n data_home = get_data_home(data_home=data_home)\n cache_path = _pkl_filepath(data_home, CACHE_NAME)\n twenty_home = os.path.join(data_home, '20news_home')\n cache = None\n if os.path.exists(cache_path):\n try:\n with open(cache_path, 'rb') as f:\n compressed_content = f.read()\n uncompressed_content = codecs.decode(compressed_content, 'zlib_codec')\n cache = pickle.loads(uncompressed_content)\n except Exception as e:\n print(80 * '_')\n print('Cache loading failed')\n print(80 * '_')\n print(e)\n if cache is None:\n if download_if_missing:\n logger.info('Downloading 20news dataset. This may take a few minutes.')\n cache = _download_20newsgroups(target_dir=twenty_home, cache_path=cache_path)\n else:\n raise IOError('20Newsgroups dataset not found')\n if subset in ('train', 'test'):\n data = cache[subset]\n elif subset == 'all':\n data_lst = list()\n target = list()\n filenames = list()\n for subset in ('train', 'test'):\n data = cache[subset]\n data_lst.extend(data.data)\n target.extend(data.target)\n filenames.extend(data.filenames)\n data.data = data_lst\n data.target = np.array(target)\n data.filenames = np.array(filenames)\n else:\n raise ValueError(\"subset can only be 'train', 'test' or 'all', got '%s'\" % subset)\n fdescr = load_descr('twenty_newsgroups.rst')\n data.DESCR = fdescr\n if 'headers' in remove:\n data.data = [strip_newsgroup_header(text) for text in data.data]\n if 'footers' in remove:\n data.data = [strip_newsgroup_footer(text) for text in data.data]\n if 'quotes' in remove:\n data.data = [strip_newsgroup_quoting(text) for text in data.data]\n if categories is not None:\n labels = [(data.target_names.index(cat), cat) for cat in categories]\n labels.sort()\n (labels, categories) = zip(*labels)\n mask = np.in1d(data.target, labels)\n data.filenames = data.filenames[mask]\n data.target = data.target[mask]\n data.target = np.searchsorted(labels, data.target)\n data.target_names = list(categories)\n data_lst = np.array(data.data, dtype=object)\n data_lst = data_lst[mask]\n data.data = data_lst.tolist()\n if shuffle:\n random_state = check_random_state(random_state)\n indices = np.arange(data.target.shape[0])\n random_state.shuffle(indices)\n data.filenames = data.filenames[indices]\n data.target = data.target[indices]\n data_lst = np.array(data.data, dtype=object)\n data_lst = data_lst[indices]\n data.data = data_lst.tolist()\n if return_X_y:\n return data.data, data.target\n return data" }, { "name": "fetch_20newsgroups_vectorized", + "unique_name": "fetch_20newsgroups_vectorized", "qname": "sklearn.datasets._twenty_newsgroups.fetch_20newsgroups_vectorized", + "unique_qname": "sklearn.datasets._twenty_newsgroups.fetch_20newsgroups_vectorized", "decorators": [], "parameters": [ { @@ -46240,11 +47109,13 @@ "is_public": true, "description": "Load and vectorize the 20 newsgroups dataset (classification).\n\nDownload it if necessary. This is a convenience function; the transformation is done using the default settings for :class:`~sklearn.feature_extraction.text.CountVectorizer`. For more advanced usage (stopword filtering, n-gram extraction, etc.), combine fetch_20newsgroups with a custom :class:`~sklearn.feature_extraction.text.CountVectorizer`, :class:`~sklearn.feature_extraction.text.HashingVectorizer`, :class:`~sklearn.feature_extraction.text.TfidfTransformer` or :class:`~sklearn.feature_extraction.text.TfidfVectorizer`. The resulting counts are normalized using :func:`sklearn.preprocessing.normalize` unless normalize is set to False. ================= ========== Classes 20 Samples total 18846 Dimensionality 130107 Features real ================= ========== Read more in the :ref:`User Guide <20newsgroups_dataset>`.", "docstring": "Load and vectorize the 20 newsgroups dataset (classification).\n\nDownload it if necessary.\n\nThis is a convenience function; the transformation is done using the\ndefault settings for\n:class:`~sklearn.feature_extraction.text.CountVectorizer`. For more\nadvanced usage (stopword filtering, n-gram extraction, etc.), combine\nfetch_20newsgroups with a custom\n:class:`~sklearn.feature_extraction.text.CountVectorizer`,\n:class:`~sklearn.feature_extraction.text.HashingVectorizer`,\n:class:`~sklearn.feature_extraction.text.TfidfTransformer` or\n:class:`~sklearn.feature_extraction.text.TfidfVectorizer`.\n\nThe resulting counts are normalized using\n:func:`sklearn.preprocessing.normalize` unless normalize is set to False.\n\n================= ==========\nClasses 20\nSamples total 18846\nDimensionality 130107\nFeatures real\n================= ==========\n\nRead more in the :ref:`User Guide <20newsgroups_dataset>`.\n\nParameters\n----------\nsubset : {'train', 'test', 'all'}, default='train'\n Select the dataset to load: 'train' for the training set, 'test'\n for the test set, 'all' for both, with shuffled ordering.\n\nremove : tuple, default=()\n May contain any subset of ('headers', 'footers', 'quotes'). Each of\n these are kinds of text that will be detected and removed from the\n newsgroup posts, preventing classifiers from overfitting on\n metadata.\n\n 'headers' removes newsgroup headers, 'footers' removes blocks at the\n ends of posts that look like signatures, and 'quotes' removes lines\n that appear to be quoting another post.\n\ndata_home : str, default=None\n Specify an download and cache folder for the datasets. If None,\n all scikit-learn data is stored in '~/scikit_learn_data' subfolders.\n\ndownload_if_missing : bool, default=True\n If False, raise an IOError if the data is not locally available\n instead of trying to download the data from the source site.\n\nreturn_X_y : bool, default=False\n If True, returns ``(data.data, data.target)`` instead of a Bunch\n object.\n\n .. versionadded:: 0.20\n\nnormalize : bool, default=True\n If True, normalizes each document's feature vector to unit norm using\n :func:`sklearn.preprocessing.normalize`.\n\n .. versionadded:: 0.22\n\nas_frame : bool, default=False\n If True, the data is a pandas DataFrame including columns with\n appropriate dtypes (numeric, string, or categorical). The target is\n a pandas DataFrame or Series depending on the number of\n `target_columns`.\n\n .. versionadded:: 0.24\n\nReturns\n-------\nbunch : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data: {sparse matrix, dataframe} of shape (n_samples, n_features)\n The input data matrix. If ``as_frame`` is `True`, ``data`` is\n a pandas DataFrame with sparse columns.\n target: {ndarray, series} of shape (n_samples,)\n The target labels. If ``as_frame`` is `True`, ``target`` is a\n pandas Series.\n target_names: list of shape (n_classes,)\n The names of target classes.\n DESCR: str\n The full description of the dataset.\n frame: dataframe of shape (n_samples, n_features + 1)\n Only present when `as_frame=True`. Pandas DataFrame with ``data``\n and ``target``.\n\n .. versionadded:: 0.24\n\n(data, target) : tuple if ``return_X_y`` is True\n `data` and `target` would be of the format defined in the `Bunch`\n description above.\n\n .. versionadded:: 0.20", - "source_code": "\ndef fetch_20newsgroups_vectorized(*, subset='train', remove=(), data_home=None, download_if_missing=True, return_X_y=False, normalize=True, as_frame=False):\n \"\"\"Load and vectorize the 20 newsgroups dataset (classification).\n\n Download it if necessary.\n\n This is a convenience function; the transformation is done using the\n default settings for\n :class:`~sklearn.feature_extraction.text.CountVectorizer`. For more\n advanced usage (stopword filtering, n-gram extraction, etc.), combine\n fetch_20newsgroups with a custom\n :class:`~sklearn.feature_extraction.text.CountVectorizer`,\n :class:`~sklearn.feature_extraction.text.HashingVectorizer`,\n :class:`~sklearn.feature_extraction.text.TfidfTransformer` or\n :class:`~sklearn.feature_extraction.text.TfidfVectorizer`.\n\n The resulting counts are normalized using\n :func:`sklearn.preprocessing.normalize` unless normalize is set to False.\n\n ================= ==========\n Classes 20\n Samples total 18846\n Dimensionality 130107\n Features real\n ================= ==========\n\n Read more in the :ref:`User Guide <20newsgroups_dataset>`.\n\n Parameters\n ----------\n subset : {'train', 'test', 'all'}, default='train'\n Select the dataset to load: 'train' for the training set, 'test'\n for the test set, 'all' for both, with shuffled ordering.\n\n remove : tuple, default=()\n May contain any subset of ('headers', 'footers', 'quotes'). Each of\n these are kinds of text that will be detected and removed from the\n newsgroup posts, preventing classifiers from overfitting on\n metadata.\n\n 'headers' removes newsgroup headers, 'footers' removes blocks at the\n ends of posts that look like signatures, and 'quotes' removes lines\n that appear to be quoting another post.\n\n data_home : str, default=None\n Specify an download and cache folder for the datasets. If None,\n all scikit-learn data is stored in '~/scikit_learn_data' subfolders.\n\n download_if_missing : bool, default=True\n If False, raise an IOError if the data is not locally available\n instead of trying to download the data from the source site.\n\n return_X_y : bool, default=False\n If True, returns ``(data.data, data.target)`` instead of a Bunch\n object.\n\n .. versionadded:: 0.20\n\n normalize : bool, default=True\n If True, normalizes each document's feature vector to unit norm using\n :func:`sklearn.preprocessing.normalize`.\n\n .. versionadded:: 0.22\n\n as_frame : bool, default=False\n If True, the data is a pandas DataFrame including columns with\n appropriate dtypes (numeric, string, or categorical). The target is\n a pandas DataFrame or Series depending on the number of\n `target_columns`.\n\n .. versionadded:: 0.24\n\n Returns\n -------\n bunch : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data: {sparse matrix, dataframe} of shape (n_samples, n_features)\n The input data matrix. If ``as_frame`` is `True`, ``data`` is\n a pandas DataFrame with sparse columns.\n target: {ndarray, series} of shape (n_samples,)\n The target labels. If ``as_frame`` is `True`, ``target`` is a\n pandas Series.\n target_names: list of shape (n_classes,)\n The names of target classes.\n DESCR: str\n The full description of the dataset.\n frame: dataframe of shape (n_samples, n_features + 1)\n Only present when `as_frame=True`. Pandas DataFrame with ``data``\n and ``target``.\n\n .. versionadded:: 0.24\n\n (data, target) : tuple if ``return_X_y`` is True\n `data` and `target` would be of the format defined in the `Bunch`\n description above.\n\n .. versionadded:: 0.20\n \"\"\"\n data_home = get_data_home(data_home=data_home)\n filebase = '20newsgroup_vectorized'\n if remove:\n filebase += 'remove-' + '-'.join(remove)\n target_file = _pkl_filepath(data_home, filebase + '.pkl')\n data_train = fetch_20newsgroups(data_home=data_home, subset='train', categories=None, shuffle=True, random_state=12, remove=remove, download_if_missing=download_if_missing)\n data_test = fetch_20newsgroups(data_home=data_home, subset='test', categories=None, shuffle=True, random_state=12, remove=remove, download_if_missing=download_if_missing)\n if os.path.exists(target_file):\n try:\n (X_train, X_test, feature_names) = joblib.load(target_file)\n except ValueError as e:\n raise ValueError(f'The cached dataset located in {target_file} was fetched with an older scikit-learn version and it is not compatible with the scikit-learn version imported. You need to manually delete the file: {target_file}.') from e\n else:\n vectorizer = CountVectorizer(dtype=np.int16)\n X_train = vectorizer.fit_transform(data_train.data).tocsr()\n X_test = vectorizer.transform(data_test.data).tocsr()\n feature_names = vectorizer.get_feature_names()\n joblib.dump((X_train, X_test, feature_names), target_file, compress=9)\n if normalize:\n X_train = X_train.astype(np.float64)\n X_test = X_test.astype(np.float64)\n preprocessing.normalize(X_train, copy=False)\n preprocessing.normalize(X_test, copy=False)\n target_names = data_train.target_names\n if subset == 'train':\n data = X_train\n target = data_train.target\n elif subset == 'test':\n data = X_test\n target = data_test.target\n elif subset == 'all':\n data = sp.vstack((X_train, X_test)).tocsr()\n target = np.concatenate((data_train.target, data_test.target))\n else:\n raise ValueError(\"%r is not a valid subset: should be one of ['train', 'test', 'all']\" % subset)\n fdescr = load_descr('twenty_newsgroups.rst')\n frame = None\n target_name = ['category_class']\n if as_frame:\n (frame, data, target) = _convert_data_dataframe('fetch_20newsgroups_vectorized', data, target, feature_names, target_names=target_name, sparse_data=True)\n if return_X_y:\n return data, target\n return Bunch(data=data, target=target, frame=frame, target_names=target_names, feature_names=feature_names, DESCR=fdescr)" + "source_code": "\ndef fetch_20newsgroups_vectorized(*, subset='train', remove=(), data_home=None, download_if_missing=True, return_X_y=False, normalize=True, as_frame=False):\n \"\"\"Load and vectorize the 20 newsgroups dataset (classification).\n\n Download it if necessary.\n\n This is a convenience function; the transformation is done using the\n default settings for\n :class:`~sklearn.feature_extraction.text.CountVectorizer`. For more\n advanced usage (stopword filtering, n-gram extraction, etc.), combine\n fetch_20newsgroups with a custom\n :class:`~sklearn.feature_extraction.text.CountVectorizer`,\n :class:`~sklearn.feature_extraction.text.HashingVectorizer`,\n :class:`~sklearn.feature_extraction.text.TfidfTransformer` or\n :class:`~sklearn.feature_extraction.text.TfidfVectorizer`.\n\n The resulting counts are normalized using\n :func:`sklearn.preprocessing.normalize` unless normalize is set to False.\n\n ================= ==========\n Classes 20\n Samples total 18846\n Dimensionality 130107\n Features real\n ================= ==========\n\n Read more in the :ref:`User Guide <20newsgroups_dataset>`.\n\n Parameters\n ----------\n subset : {'train', 'test', 'all'}, default='train'\n Select the dataset to load: 'train' for the training set, 'test'\n for the test set, 'all' for both, with shuffled ordering.\n\n remove : tuple, default=()\n May contain any subset of ('headers', 'footers', 'quotes'). Each of\n these are kinds of text that will be detected and removed from the\n newsgroup posts, preventing classifiers from overfitting on\n metadata.\n\n 'headers' removes newsgroup headers, 'footers' removes blocks at the\n ends of posts that look like signatures, and 'quotes' removes lines\n that appear to be quoting another post.\n\n data_home : str, default=None\n Specify an download and cache folder for the datasets. If None,\n all scikit-learn data is stored in '~/scikit_learn_data' subfolders.\n\n download_if_missing : bool, default=True\n If False, raise an IOError if the data is not locally available\n instead of trying to download the data from the source site.\n\n return_X_y : bool, default=False\n If True, returns ``(data.data, data.target)`` instead of a Bunch\n object.\n\n .. versionadded:: 0.20\n\n normalize : bool, default=True\n If True, normalizes each document's feature vector to unit norm using\n :func:`sklearn.preprocessing.normalize`.\n\n .. versionadded:: 0.22\n\n as_frame : bool, default=False\n If True, the data is a pandas DataFrame including columns with\n appropriate dtypes (numeric, string, or categorical). The target is\n a pandas DataFrame or Series depending on the number of\n `target_columns`.\n\n .. versionadded:: 0.24\n\n Returns\n -------\n bunch : :class:`~sklearn.utils.Bunch`\n Dictionary-like object, with the following attributes.\n\n data: {sparse matrix, dataframe} of shape (n_samples, n_features)\n The input data matrix. If ``as_frame`` is `True`, ``data`` is\n a pandas DataFrame with sparse columns.\n target: {ndarray, series} of shape (n_samples,)\n The target labels. If ``as_frame`` is `True`, ``target`` is a\n pandas Series.\n target_names: list of shape (n_classes,)\n The names of target classes.\n DESCR: str\n The full description of the dataset.\n frame: dataframe of shape (n_samples, n_features + 1)\n Only present when `as_frame=True`. Pandas DataFrame with ``data``\n and ``target``.\n\n .. versionadded:: 0.24\n\n (data, target) : tuple if ``return_X_y`` is True\n `data` and `target` would be of the format defined in the `Bunch`\n description above.\n\n .. versionadded:: 0.20\n \"\"\"\n data_home = get_data_home(data_home=data_home)\n filebase = '20newsgroup_vectorized'\n if remove:\n filebase += 'remove-' + '-'.join(remove)\n target_file = _pkl_filepath(data_home, filebase + '.pkl')\n data_train = fetch_20newsgroups(data_home=data_home, subset='train', categories=None, shuffle=True, random_state=12, remove=remove, download_if_missing=download_if_missing)\n data_test = fetch_20newsgroups(data_home=data_home, subset='test', categories=None, shuffle=True, random_state=12, remove=remove, download_if_missing=download_if_missing)\n if os.path.exists(target_file):\n try:\n (X_train, X_test, feature_names) = joblib.load(target_file)\n except ValueError as e:\n raise ValueError(f'The cached dataset located in {target_file} was fetched with an older scikit-learn version and it is not compatible with the scikit-learn version imported. You need to manually delete the file: {target_file}.') from e\n else:\n vectorizer = CountVectorizer(dtype=np.int16)\n X_train = vectorizer.fit_transform(data_train.data).tocsr()\n X_test = vectorizer.transform(data_test.data).tocsr()\n feature_names = vectorizer.get_feature_names_out()\n joblib.dump((X_train, X_test, feature_names), target_file, compress=9)\n if normalize:\n X_train = X_train.astype(np.float64)\n X_test = X_test.astype(np.float64)\n preprocessing.normalize(X_train, copy=False)\n preprocessing.normalize(X_test, copy=False)\n target_names = data_train.target_names\n if subset == 'train':\n data = X_train\n target = data_train.target\n elif subset == 'test':\n data = X_test\n target = data_test.target\n elif subset == 'all':\n data = sp.vstack((X_train, X_test)).tocsr()\n target = np.concatenate((data_train.target, data_test.target))\n else:\n raise ValueError(\"%r is not a valid subset: should be one of ['train', 'test', 'all']\" % subset)\n fdescr = load_descr('twenty_newsgroups.rst')\n frame = None\n target_name = ['category_class']\n if as_frame:\n (frame, data, target) = _convert_data_dataframe('fetch_20newsgroups_vectorized', data, target, feature_names, target_names=target_name, sparse_data=True)\n if return_X_y:\n return data, target\n return Bunch(data=data, target=target, frame=frame, target_names=target_names, feature_names=feature_names, DESCR=fdescr)" }, { "name": "strip_newsgroup_footer", + "unique_name": "strip_newsgroup_footer", "qname": "sklearn.datasets._twenty_newsgroups.strip_newsgroup_footer", + "unique_qname": "sklearn.datasets._twenty_newsgroups.strip_newsgroup_footer", "decorators": [], "parameters": [ { @@ -46266,7 +47137,9 @@ }, { "name": "strip_newsgroup_header", + "unique_name": "strip_newsgroup_header", "qname": "sklearn.datasets._twenty_newsgroups.strip_newsgroup_header", + "unique_qname": "sklearn.datasets._twenty_newsgroups.strip_newsgroup_header", "decorators": [], "parameters": [ { @@ -46288,7 +47161,9 @@ }, { "name": "strip_newsgroup_quoting", + "unique_name": "strip_newsgroup_quoting", "qname": "sklearn.datasets._twenty_newsgroups.strip_newsgroup_quoting", + "unique_qname": "sklearn.datasets._twenty_newsgroups.strip_newsgroup_quoting", "decorators": [], "parameters": [ { @@ -46310,7 +47185,9 @@ }, { "name": "configuration", + "unique_name": "configuration", "qname": "sklearn.datasets.setup.configuration", + "unique_qname": "sklearn.datasets.setup.configuration", "decorators": [], "parameters": [ { @@ -46342,7 +47219,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.decomposition._base._BasePCA.fit", + "unique_qname": "sklearn.decomposition._base._BasePCA.fit", "decorators": ["abstractmethod"], "parameters": [ { @@ -46384,7 +47263,9 @@ }, { "name": "get_covariance", + "unique_name": "get_covariance", "qname": "sklearn.decomposition._base._BasePCA.get_covariance", + "unique_qname": "sklearn.decomposition._base._BasePCA.get_covariance", "decorators": [], "parameters": [ { @@ -46406,7 +47287,9 @@ }, { "name": "get_precision", + "unique_name": "get_precision", "qname": "sklearn.decomposition._base._BasePCA.get_precision", + "unique_qname": "sklearn.decomposition._base._BasePCA.get_precision", "decorators": [], "parameters": [ { @@ -46428,7 +47311,9 @@ }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.decomposition._base._BasePCA.inverse_transform", + "unique_qname": "sklearn.decomposition._base._BasePCA.inverse_transform", "decorators": [], "parameters": [ { @@ -46460,7 +47345,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.decomposition._base._BasePCA.transform", + "unique_qname": "sklearn.decomposition._base._BasePCA.transform", "decorators": [], "parameters": [ { @@ -46492,7 +47379,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.decomposition._dict_learning.DictionaryLearning.__init__", + "unique_qname": "sklearn.decomposition._dict_learning.DictionaryLearning.__init__", "decorators": [], "parameters": [ { @@ -46684,7 +47573,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.decomposition._dict_learning.DictionaryLearning.fit", + "unique_qname": "sklearn.decomposition._dict_learning.DictionaryLearning.fit", "decorators": [], "parameters": [ { @@ -46726,7 +47617,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.decomposition._dict_learning.MiniBatchDictionaryLearning.__init__", + "unique_qname": "sklearn.decomposition._dict_learning.MiniBatchDictionaryLearning.__init__", "decorators": [], "parameters": [ { @@ -46918,7 +47811,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.decomposition._dict_learning.MiniBatchDictionaryLearning.fit", + "unique_qname": "sklearn.decomposition._dict_learning.MiniBatchDictionaryLearning.fit", "decorators": [], "parameters": [ { @@ -46960,7 +47855,9 @@ }, { "name": "partial_fit", + "unique_name": "partial_fit", "qname": "sklearn.decomposition._dict_learning.MiniBatchDictionaryLearning.partial_fit", + "unique_qname": "sklearn.decomposition._dict_learning.MiniBatchDictionaryLearning.partial_fit", "decorators": [], "parameters": [ { @@ -47012,7 +47909,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.decomposition._dict_learning.SparseCoder.__init__", + "unique_qname": "sklearn.decomposition._dict_learning.SparseCoder.__init__", "decorators": [], "parameters": [ { @@ -47114,7 +48013,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.decomposition._dict_learning.SparseCoder._more_tags", + "unique_qname": "sklearn.decomposition._dict_learning.SparseCoder._more_tags", "decorators": [], "parameters": [ { @@ -47136,7 +48037,9 @@ }, { "name": "components_", + "unique_name": "components_@getter", "qname": "sklearn.decomposition._dict_learning.SparseCoder.components_", + "unique_qname": "sklearn.decomposition._dict_learning.SparseCoder.components_@getter", "decorators": [ "deprecated('The attribute `components_` is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26). Use the `dictionary` instead.')", "property" @@ -47161,7 +48064,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.decomposition._dict_learning.SparseCoder.fit", + "unique_qname": "sklearn.decomposition._dict_learning.SparseCoder.fit", "decorators": [], "parameters": [ { @@ -47203,7 +48108,9 @@ }, { "name": "n_components_", + "unique_name": "n_components_@getter", "qname": "sklearn.decomposition._dict_learning.SparseCoder.n_components_", + "unique_qname": "sklearn.decomposition._dict_learning.SparseCoder.n_components_@getter", "decorators": ["property"], "parameters": [ { @@ -47225,7 +48132,9 @@ }, { "name": "n_features_in_", + "unique_name": "n_features_in_@getter", "qname": "sklearn.decomposition._dict_learning.SparseCoder.n_features_in_", + "unique_qname": "sklearn.decomposition._dict_learning.SparseCoder.n_features_in_@getter", "decorators": ["property"], "parameters": [ { @@ -47247,7 +48156,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.decomposition._dict_learning.SparseCoder.transform", + "unique_qname": "sklearn.decomposition._dict_learning.SparseCoder.transform", "decorators": [], "parameters": [ { @@ -47289,7 +48200,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.decomposition._dict_learning._BaseSparseCoding.__init__", + "unique_qname": "sklearn.decomposition._dict_learning._BaseSparseCoding.__init__", "decorators": [], "parameters": [ { @@ -47381,7 +48294,9 @@ }, { "name": "_transform", + "unique_name": "_transform", "qname": "sklearn.decomposition._dict_learning._BaseSparseCoding._transform", + "unique_qname": "sklearn.decomposition._dict_learning._BaseSparseCoding._transform", "decorators": [], "parameters": [ { @@ -47423,7 +48338,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.decomposition._dict_learning._BaseSparseCoding.transform", + "unique_qname": "sklearn.decomposition._dict_learning._BaseSparseCoding.transform", "decorators": [], "parameters": [ { @@ -47455,7 +48372,9 @@ }, { "name": "_check_positive_coding", + "unique_name": "_check_positive_coding", "qname": "sklearn.decomposition._dict_learning._check_positive_coding", + "unique_qname": "sklearn.decomposition._dict_learning._check_positive_coding", "decorators": [], "parameters": [ { @@ -47487,7 +48406,9 @@ }, { "name": "_sparse_encode", + "unique_name": "_sparse_encode", "qname": "sklearn.decomposition._dict_learning._sparse_encode", + "unique_qname": "sklearn.decomposition._dict_learning._sparse_encode", "decorators": [], "parameters": [ { @@ -47619,7 +48540,9 @@ }, { "name": "_update_dict", + "unique_name": "_update_dict", "qname": "sklearn.decomposition._dict_learning._update_dict", + "unique_qname": "sklearn.decomposition._dict_learning._update_dict", "decorators": [], "parameters": [ { @@ -47711,7 +48634,9 @@ }, { "name": "dict_learning", + "unique_name": "dict_learning", "qname": "sklearn.decomposition._dict_learning.dict_learning", + "unique_qname": "sklearn.decomposition._dict_learning.dict_learning", "decorators": [], "parameters": [ { @@ -47883,7 +48808,9 @@ }, { "name": "dict_learning_online", + "unique_name": "dict_learning_online", "qname": "sklearn.decomposition._dict_learning.dict_learning_online", + "unique_qname": "sklearn.decomposition._dict_learning.dict_learning_online", "decorators": [], "parameters": [ { @@ -48095,7 +49022,9 @@ }, { "name": "sparse_encode", + "unique_name": "sparse_encode", "qname": "sklearn.decomposition._dict_learning.sparse_encode", + "unique_qname": "sklearn.decomposition._dict_learning.sparse_encode", "decorators": [], "parameters": [ { @@ -48247,7 +49176,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.decomposition._factor_analysis.FactorAnalysis.__init__", + "unique_qname": "sklearn.decomposition._factor_analysis.FactorAnalysis.__init__", "decorators": [], "parameters": [ { @@ -48359,7 +49290,9 @@ }, { "name": "_rotate", + "unique_name": "_rotate", "qname": "sklearn.decomposition._factor_analysis.FactorAnalysis._rotate", + "unique_qname": "sklearn.decomposition._factor_analysis.FactorAnalysis._rotate", "decorators": [], "parameters": [ { @@ -48411,7 +49344,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.decomposition._factor_analysis.FactorAnalysis.fit", + "unique_qname": "sklearn.decomposition._factor_analysis.FactorAnalysis.fit", "decorators": [], "parameters": [ { @@ -48453,7 +49388,9 @@ }, { "name": "get_covariance", + "unique_name": "get_covariance", "qname": "sklearn.decomposition._factor_analysis.FactorAnalysis.get_covariance", + "unique_qname": "sklearn.decomposition._factor_analysis.FactorAnalysis.get_covariance", "decorators": [], "parameters": [ { @@ -48475,7 +49412,9 @@ }, { "name": "get_precision", + "unique_name": "get_precision", "qname": "sklearn.decomposition._factor_analysis.FactorAnalysis.get_precision", + "unique_qname": "sklearn.decomposition._factor_analysis.FactorAnalysis.get_precision", "decorators": [], "parameters": [ { @@ -48497,7 +49436,9 @@ }, { "name": "score", + "unique_name": "score", "qname": "sklearn.decomposition._factor_analysis.FactorAnalysis.score", + "unique_qname": "sklearn.decomposition._factor_analysis.FactorAnalysis.score", "decorators": [], "parameters": [ { @@ -48539,7 +49480,9 @@ }, { "name": "score_samples", + "unique_name": "score_samples", "qname": "sklearn.decomposition._factor_analysis.FactorAnalysis.score_samples", + "unique_qname": "sklearn.decomposition._factor_analysis.FactorAnalysis.score_samples", "decorators": [], "parameters": [ { @@ -48571,7 +49514,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.decomposition._factor_analysis.FactorAnalysis.transform", + "unique_qname": "sklearn.decomposition._factor_analysis.FactorAnalysis.transform", "decorators": [], "parameters": [ { @@ -48603,7 +49548,9 @@ }, { "name": "_ortho_rotation", + "unique_name": "_ortho_rotation", "qname": "sklearn.decomposition._factor_analysis._ortho_rotation", + "unique_qname": "sklearn.decomposition._factor_analysis._ortho_rotation", "decorators": [], "parameters": [ { @@ -48655,7 +49602,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.decomposition._fastica.FastICA.__init__", + "unique_qname": "sklearn.decomposition._fastica.FastICA.__init__", "decorators": [], "parameters": [ { @@ -48767,7 +49716,9 @@ }, { "name": "_fit", + "unique_name": "_fit", "qname": "sklearn.decomposition._fastica.FastICA._fit", + "unique_qname": "sklearn.decomposition._fastica.FastICA._fit", "decorators": [], "parameters": [ { @@ -48809,7 +49760,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.decomposition._fastica.FastICA.fit", + "unique_qname": "sklearn.decomposition._fastica.FastICA.fit", "decorators": [], "parameters": [ { @@ -48851,7 +49804,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.decomposition._fastica.FastICA.fit_transform", + "unique_qname": "sklearn.decomposition._fastica.FastICA.fit_transform", "decorators": [], "parameters": [ { @@ -48893,7 +49848,9 @@ }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.decomposition._fastica.FastICA.inverse_transform", + "unique_qname": "sklearn.decomposition._fastica.FastICA.inverse_transform", "decorators": [], "parameters": [ { @@ -48935,7 +49892,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.decomposition._fastica.FastICA.transform", + "unique_qname": "sklearn.decomposition._fastica.FastICA.transform", "decorators": [], "parameters": [ { @@ -48977,7 +49936,9 @@ }, { "name": "_cube", + "unique_name": "_cube", "qname": "sklearn.decomposition._fastica._cube", + "unique_qname": "sklearn.decomposition._fastica._cube", "decorators": [], "parameters": [ { @@ -49009,7 +49970,9 @@ }, { "name": "_exp", + "unique_name": "_exp", "qname": "sklearn.decomposition._fastica._exp", + "unique_qname": "sklearn.decomposition._fastica._exp", "decorators": [], "parameters": [ { @@ -49041,7 +50004,9 @@ }, { "name": "_gs_decorrelation", + "unique_name": "_gs_decorrelation", "qname": "sklearn.decomposition._fastica._gs_decorrelation", + "unique_qname": "sklearn.decomposition._fastica._gs_decorrelation", "decorators": [], "parameters": [ { @@ -49083,7 +50048,9 @@ }, { "name": "_ica_def", + "unique_name": "_ica_def", "qname": "sklearn.decomposition._fastica._ica_def", + "unique_qname": "sklearn.decomposition._fastica._ica_def", "decorators": [], "parameters": [ { @@ -49155,7 +50122,9 @@ }, { "name": "_ica_par", + "unique_name": "_ica_par", "qname": "sklearn.decomposition._fastica._ica_par", + "unique_qname": "sklearn.decomposition._fastica._ica_par", "decorators": [], "parameters": [ { @@ -49227,7 +50196,9 @@ }, { "name": "_logcosh", + "unique_name": "_logcosh", "qname": "sklearn.decomposition._fastica._logcosh", + "unique_qname": "sklearn.decomposition._fastica._logcosh", "decorators": [], "parameters": [ { @@ -49259,7 +50230,9 @@ }, { "name": "_sym_decorrelation", + "unique_name": "_sym_decorrelation", "qname": "sklearn.decomposition._fastica._sym_decorrelation", + "unique_qname": "sklearn.decomposition._fastica._sym_decorrelation", "decorators": [], "parameters": [ { @@ -49281,7 +50254,9 @@ }, { "name": "fastica", + "unique_name": "fastica", "qname": "sklearn.decomposition._fastica.fastica", + "unique_qname": "sklearn.decomposition._fastica.fastica", "decorators": [], "parameters": [ { @@ -49423,7 +50398,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.decomposition._incremental_pca.IncrementalPCA.__init__", + "unique_qname": "sklearn.decomposition._incremental_pca.IncrementalPCA.__init__", "decorators": [], "parameters": [ { @@ -49485,7 +50462,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.decomposition._incremental_pca.IncrementalPCA.fit", + "unique_qname": "sklearn.decomposition._incremental_pca.IncrementalPCA.fit", "decorators": [], "parameters": [ { @@ -49527,7 +50506,9 @@ }, { "name": "partial_fit", + "unique_name": "partial_fit", "qname": "sklearn.decomposition._incremental_pca.IncrementalPCA.partial_fit", + "unique_qname": "sklearn.decomposition._incremental_pca.IncrementalPCA.partial_fit", "decorators": [], "parameters": [ { @@ -49579,7 +50560,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.decomposition._incremental_pca.IncrementalPCA.transform", + "unique_qname": "sklearn.decomposition._incremental_pca.IncrementalPCA.transform", "decorators": [], "parameters": [ { @@ -49611,7 +50594,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.decomposition._kernel_pca.KernelPCA.__init__", + "unique_qname": "sklearn.decomposition._kernel_pca.KernelPCA.__init__", "decorators": [], "parameters": [ { @@ -49793,7 +50778,9 @@ }, { "name": "_fit_inverse_transform", + "unique_name": "_fit_inverse_transform", "qname": "sklearn.decomposition._kernel_pca.KernelPCA._fit_inverse_transform", + "unique_qname": "sklearn.decomposition._kernel_pca.KernelPCA._fit_inverse_transform", "decorators": [], "parameters": [ { @@ -49835,7 +50822,9 @@ }, { "name": "_fit_transform", + "unique_name": "_fit_transform", "qname": "sklearn.decomposition._kernel_pca.KernelPCA._fit_transform", + "unique_qname": "sklearn.decomposition._kernel_pca.KernelPCA._fit_transform", "decorators": [], "parameters": [ { @@ -49867,7 +50856,9 @@ }, { "name": "_get_kernel", + "unique_name": "_get_kernel", "qname": "sklearn.decomposition._kernel_pca.KernelPCA._get_kernel", + "unique_qname": "sklearn.decomposition._kernel_pca.KernelPCA._get_kernel", "decorators": [], "parameters": [ { @@ -49909,7 +50900,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.decomposition._kernel_pca.KernelPCA._more_tags", + "unique_qname": "sklearn.decomposition._kernel_pca.KernelPCA._more_tags", "decorators": [], "parameters": [ { @@ -49931,7 +50924,9 @@ }, { "name": "_pairwise", + "unique_name": "_pairwise@getter", "qname": "sklearn.decomposition._kernel_pca.KernelPCA._pairwise", + "unique_qname": "sklearn.decomposition._kernel_pca.KernelPCA._pairwise@getter", "decorators": [ "deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -49956,7 +50951,9 @@ }, { "name": "alphas_", + "unique_name": "alphas_@getter", "qname": "sklearn.decomposition._kernel_pca.KernelPCA.alphas_", + "unique_qname": "sklearn.decomposition._kernel_pca.KernelPCA.alphas_@getter", "decorators": [ "deprecated('Attribute `alphas_` was deprecated in version 1.0 and will be removed in 1.2. Use `eigenvectors_` instead.')", "property" @@ -49981,7 +50978,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.decomposition._kernel_pca.KernelPCA.fit", + "unique_qname": "sklearn.decomposition._kernel_pca.KernelPCA.fit", "decorators": [], "parameters": [ { @@ -50023,7 +51022,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.decomposition._kernel_pca.KernelPCA.fit_transform", + "unique_qname": "sklearn.decomposition._kernel_pca.KernelPCA.fit_transform", "decorators": [], "parameters": [ { @@ -50065,7 +51066,9 @@ }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.decomposition._kernel_pca.KernelPCA.inverse_transform", + "unique_qname": "sklearn.decomposition._kernel_pca.KernelPCA.inverse_transform", "decorators": [], "parameters": [ { @@ -50097,7 +51100,9 @@ }, { "name": "lambdas_", + "unique_name": "lambdas_@getter", "qname": "sklearn.decomposition._kernel_pca.KernelPCA.lambdas_", + "unique_qname": "sklearn.decomposition._kernel_pca.KernelPCA.lambdas_@getter", "decorators": [ "deprecated('Attribute `lambdas_` was deprecated in version 1.0 and will be removed in 1.2. Use `eigenvalues_` instead.')", "property" @@ -50122,7 +51127,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.decomposition._kernel_pca.KernelPCA.transform", + "unique_qname": "sklearn.decomposition._kernel_pca.KernelPCA.transform", "decorators": [], "parameters": [ { @@ -50154,7 +51161,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.decomposition._lda.LatentDirichletAllocation.__init__", + "unique_qname": "sklearn.decomposition._lda.LatentDirichletAllocation.__init__", "decorators": [], "parameters": [ { @@ -50336,7 +51345,9 @@ }, { "name": "_approx_bound", + "unique_name": "_approx_bound", "qname": "sklearn.decomposition._lda.LatentDirichletAllocation._approx_bound", + "unique_qname": "sklearn.decomposition._lda.LatentDirichletAllocation._approx_bound", "decorators": [], "parameters": [ { @@ -50388,7 +51399,9 @@ }, { "name": "_check_non_neg_array", + "unique_name": "_check_non_neg_array", "qname": "sklearn.decomposition._lda.LatentDirichletAllocation._check_non_neg_array", + "unique_qname": "sklearn.decomposition._lda.LatentDirichletAllocation._check_non_neg_array", "decorators": [], "parameters": [ { @@ -50440,7 +51453,9 @@ }, { "name": "_check_params", + "unique_name": "_check_params", "qname": "sklearn.decomposition._lda.LatentDirichletAllocation._check_params", + "unique_qname": "sklearn.decomposition._lda.LatentDirichletAllocation._check_params", "decorators": [], "parameters": [ { @@ -50462,7 +51477,9 @@ }, { "name": "_e_step", + "unique_name": "_e_step", "qname": "sklearn.decomposition._lda.LatentDirichletAllocation._e_step", + "unique_qname": "sklearn.decomposition._lda.LatentDirichletAllocation._e_step", "decorators": [], "parameters": [ { @@ -50524,7 +51541,9 @@ }, { "name": "_em_step", + "unique_name": "_em_step", "qname": "sklearn.decomposition._lda.LatentDirichletAllocation._em_step", + "unique_qname": "sklearn.decomposition._lda.LatentDirichletAllocation._em_step", "decorators": [], "parameters": [ { @@ -50586,7 +51605,9 @@ }, { "name": "_init_latent_vars", + "unique_name": "_init_latent_vars", "qname": "sklearn.decomposition._lda.LatentDirichletAllocation._init_latent_vars", + "unique_qname": "sklearn.decomposition._lda.LatentDirichletAllocation._init_latent_vars", "decorators": [], "parameters": [ { @@ -50618,7 +51639,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.decomposition._lda.LatentDirichletAllocation._more_tags", + "unique_qname": "sklearn.decomposition._lda.LatentDirichletAllocation._more_tags", "decorators": [], "parameters": [ { @@ -50640,7 +51663,9 @@ }, { "name": "_perplexity_precomp_distr", + "unique_name": "_perplexity_precomp_distr", "qname": "sklearn.decomposition._lda.LatentDirichletAllocation._perplexity_precomp_distr", + "unique_qname": "sklearn.decomposition._lda.LatentDirichletAllocation._perplexity_precomp_distr", "decorators": [], "parameters": [ { @@ -50688,11 +51713,13 @@ "is_public": false, "description": "Calculate approximate perplexity for data X with ability to accept precomputed doc_topic_distr\n\nPerplexity is defined as exp(-1. * log-likelihood per word)", "docstring": "Calculate approximate perplexity for data X with ability to accept\nprecomputed doc_topic_distr\n\nPerplexity is defined as exp(-1. * log-likelihood per word)\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\ndoc_topic_distr : ndarray of shape (n_samples, n_components), default=None\n Document topic distribution.\n If it is None, it will be generated by applying transform on X.\n\nReturns\n-------\nscore : float\n Perplexity score.", - "source_code": "\ndef _perplexity_precomp_distr(self, X, doc_topic_distr=None, sub_sampling=False):\n \"\"\"Calculate approximate perplexity for data X with ability to accept\n precomputed doc_topic_distr\n\n Perplexity is defined as exp(-1. * log-likelihood per word)\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n doc_topic_distr : ndarray of shape (n_samples, n_components), default=None\n Document topic distribution.\n If it is None, it will be generated by applying transform on X.\n\n Returns\n -------\n score : float\n Perplexity score.\n \"\"\"\n check_is_fitted(self)\n X = self._check_non_neg_array(X, reset_n_features=True, whom='LatentDirichletAllocation.perplexity')\n if doc_topic_distr is None:\n doc_topic_distr = self._unnormalized_transform(X)\n else:\n (n_samples, n_components) = doc_topic_distr.shape\n if n_samples != X.shape[0]:\n raise ValueError('Number of samples in X and doc_topic_distr do not match.')\n if n_components != self.n_components:\n raise ValueError('Number of topics does not match.')\n current_samples = X.shape[0]\n bound = self._approx_bound(X, doc_topic_distr, sub_sampling)\n if sub_sampling:\n word_cnt = X.sum() * (float(self.total_samples) / current_samples)\n else:\n word_cnt = X.sum()\n perword_bound = bound / word_cnt\n return np.exp(-1.0 * perword_bound)" + "source_code": "\ndef _perplexity_precomp_distr(self, X, doc_topic_distr=None, sub_sampling=False):\n \"\"\"Calculate approximate perplexity for data X with ability to accept\n precomputed doc_topic_distr\n\n Perplexity is defined as exp(-1. * log-likelihood per word)\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n doc_topic_distr : ndarray of shape (n_samples, n_components), default=None\n Document topic distribution.\n If it is None, it will be generated by applying transform on X.\n\n Returns\n -------\n score : float\n Perplexity score.\n \"\"\"\n if doc_topic_distr is None:\n doc_topic_distr = self._unnormalized_transform(X)\n else:\n (n_samples, n_components) = doc_topic_distr.shape\n if n_samples != X.shape[0]:\n raise ValueError('Number of samples in X and doc_topic_distr do not match.')\n if n_components != self.n_components:\n raise ValueError('Number of topics does not match.')\n current_samples = X.shape[0]\n bound = self._approx_bound(X, doc_topic_distr, sub_sampling)\n if sub_sampling:\n word_cnt = X.sum() * (float(self.total_samples) / current_samples)\n else:\n word_cnt = X.sum()\n perword_bound = bound / word_cnt\n return np.exp(-1.0 * perword_bound)" }, { "name": "_unnormalized_transform", + "unique_name": "_unnormalized_transform", "qname": "sklearn.decomposition._lda.LatentDirichletAllocation._unnormalized_transform", + "unique_qname": "sklearn.decomposition._lda.LatentDirichletAllocation._unnormalized_transform", "decorators": [], "parameters": [ { @@ -50720,11 +51747,13 @@ "is_public": false, "description": "Transform data X according to fitted model.", "docstring": "Transform data X according to fitted model.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\nReturns\n-------\ndoc_topic_distr : ndarray of shape (n_samples, n_components)\n Document topic distribution for X.", - "source_code": "\ndef _unnormalized_transform(self, X):\n \"\"\"Transform data X according to fitted model.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n Returns\n -------\n doc_topic_distr : ndarray of shape (n_samples, n_components)\n Document topic distribution for X.\n \"\"\"\n check_is_fitted(self)\n X = self._check_non_neg_array(X, reset_n_features=True, whom='LatentDirichletAllocation.transform')\n (n_samples, n_features) = X.shape\n if n_features != self.components_.shape[1]:\n raise ValueError('The provided data has %d dimensions while the model was trained with feature size %d.' % (n_features, self.components_.shape[1]))\n (doc_topic_distr, _) = self._e_step(X, cal_sstats=False, random_init=False)\n return doc_topic_distr" + "source_code": "\ndef _unnormalized_transform(self, X):\n \"\"\"Transform data X according to fitted model.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n Returns\n -------\n doc_topic_distr : ndarray of shape (n_samples, n_components)\n Document topic distribution for X.\n \"\"\"\n (doc_topic_distr, _) = self._e_step(X, cal_sstats=False, random_init=False)\n return doc_topic_distr" }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.decomposition._lda.LatentDirichletAllocation.fit", + "unique_qname": "sklearn.decomposition._lda.LatentDirichletAllocation.fit", "decorators": [], "parameters": [ { @@ -50766,7 +51795,9 @@ }, { "name": "partial_fit", + "unique_name": "partial_fit", "qname": "sklearn.decomposition._lda.LatentDirichletAllocation.partial_fit", + "unique_qname": "sklearn.decomposition._lda.LatentDirichletAllocation.partial_fit", "decorators": [], "parameters": [ { @@ -50808,7 +51839,9 @@ }, { "name": "perplexity", + "unique_name": "perplexity", "qname": "sklearn.decomposition._lda.LatentDirichletAllocation.perplexity", + "unique_qname": "sklearn.decomposition._lda.LatentDirichletAllocation.perplexity", "decorators": [], "parameters": [ { @@ -50846,11 +51879,13 @@ "is_public": true, "description": "Calculate approximate perplexity for data X.\n\nPerplexity is defined as exp(-1. * log-likelihood per word) .. versionchanged:: 0.19 *doc_topic_distr* argument has been deprecated and is ignored because user no longer has access to unnormalized distribution", "docstring": "Calculate approximate perplexity for data X.\n\nPerplexity is defined as exp(-1. * log-likelihood per word)\n\n.. versionchanged:: 0.19\n *doc_topic_distr* argument has been deprecated and is ignored\n because user no longer has access to unnormalized distribution\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\nsub_sampling : bool\n Do sub-sampling or not.\n\nReturns\n-------\nscore : float\n Perplexity score.", - "source_code": "\ndef perplexity(self, X, sub_sampling=False):\n \"\"\"Calculate approximate perplexity for data X.\n\n Perplexity is defined as exp(-1. * log-likelihood per word)\n\n .. versionchanged:: 0.19\n *doc_topic_distr* argument has been deprecated and is ignored\n because user no longer has access to unnormalized distribution\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n sub_sampling : bool\n Do sub-sampling or not.\n\n Returns\n -------\n score : float\n Perplexity score.\n \"\"\"\n return self._perplexity_precomp_distr(X, sub_sampling=sub_sampling)" + "source_code": "\ndef perplexity(self, X, sub_sampling=False):\n \"\"\"Calculate approximate perplexity for data X.\n\n Perplexity is defined as exp(-1. * log-likelihood per word)\n\n .. versionchanged:: 0.19\n *doc_topic_distr* argument has been deprecated and is ignored\n because user no longer has access to unnormalized distribution\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Document word matrix.\n\n sub_sampling : bool\n Do sub-sampling or not.\n\n Returns\n -------\n score : float\n Perplexity score.\n \"\"\"\n check_is_fitted(self)\n X = self._check_non_neg_array(X, reset_n_features=True, whom='LatentDirichletAllocation.perplexity')\n return self._perplexity_precomp_distr(X, sub_sampling=sub_sampling)" }, { "name": "score", + "unique_name": "score", "qname": "sklearn.decomposition._lda.LatentDirichletAllocation.score", + "unique_qname": "sklearn.decomposition._lda.LatentDirichletAllocation.score", "decorators": [], "parameters": [ { @@ -50892,7 +51927,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.decomposition._lda.LatentDirichletAllocation.transform", + "unique_qname": "sklearn.decomposition._lda.LatentDirichletAllocation.transform", "decorators": [], "parameters": [ { @@ -50924,7 +51961,9 @@ }, { "name": "_update_doc_distribution", + "unique_name": "_update_doc_distribution", "qname": "sklearn.decomposition._lda._update_doc_distribution", + "unique_qname": "sklearn.decomposition._lda._update_doc_distribution", "decorators": [], "parameters": [ { @@ -51006,7 +52045,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.decomposition._nmf.NMF.__init__", + "unique_qname": "sklearn.decomposition._nmf.NMF.__init__", "decorators": [], "parameters": [ { @@ -51168,7 +52209,9 @@ }, { "name": "_check_params", + "unique_name": "_check_params", "qname": "sklearn.decomposition._nmf.NMF._check_params", + "unique_qname": "sklearn.decomposition._nmf.NMF._check_params", "decorators": [], "parameters": [ { @@ -51200,7 +52243,9 @@ }, { "name": "_check_w_h", + "unique_name": "_check_w_h", "qname": "sklearn.decomposition._nmf.NMF._check_w_h", + "unique_qname": "sklearn.decomposition._nmf.NMF._check_w_h", "decorators": [], "parameters": [ { @@ -51262,7 +52307,9 @@ }, { "name": "_fit_transform", + "unique_name": "_fit_transform", "qname": "sklearn.decomposition._nmf.NMF._fit_transform", + "unique_qname": "sklearn.decomposition._nmf.NMF._fit_transform", "decorators": [], "parameters": [ { @@ -51334,7 +52381,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.decomposition._nmf.NMF._more_tags", + "unique_qname": "sklearn.decomposition._nmf.NMF._more_tags", "decorators": [], "parameters": [ { @@ -51356,7 +52405,9 @@ }, { "name": "_scale_regularization", + "unique_name": "_scale_regularization", "qname": "sklearn.decomposition._nmf.NMF._scale_regularization", + "unique_qname": "sklearn.decomposition._nmf.NMF._scale_regularization", "decorators": [], "parameters": [ { @@ -51388,7 +52439,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.decomposition._nmf.NMF.fit", + "unique_qname": "sklearn.decomposition._nmf.NMF.fit", "decorators": [], "parameters": [ { @@ -51430,7 +52483,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.decomposition._nmf.NMF.fit_transform", + "unique_qname": "sklearn.decomposition._nmf.NMF.fit_transform", "decorators": [], "parameters": [ { @@ -51492,7 +52547,9 @@ }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.decomposition._nmf.NMF.inverse_transform", + "unique_qname": "sklearn.decomposition._nmf.NMF.inverse_transform", "decorators": [], "parameters": [ { @@ -51524,7 +52581,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.decomposition._nmf.NMF.transform", + "unique_qname": "sklearn.decomposition._nmf.NMF.transform", "decorators": [], "parameters": [ { @@ -51556,7 +52615,9 @@ }, { "name": "_beta_divergence", + "unique_name": "_beta_divergence", "qname": "sklearn.decomposition._nmf._beta_divergence", + "unique_qname": "sklearn.decomposition._nmf._beta_divergence", "decorators": [], "parameters": [ { @@ -51618,7 +52679,9 @@ }, { "name": "_beta_loss_to_float", + "unique_name": "_beta_loss_to_float", "qname": "sklearn.decomposition._nmf._beta_loss_to_float", + "unique_qname": "sklearn.decomposition._nmf._beta_loss_to_float", "decorators": [], "parameters": [ { @@ -51640,7 +52703,9 @@ }, { "name": "_check_init", + "unique_name": "_check_init", "qname": "sklearn.decomposition._nmf._check_init", + "unique_qname": "sklearn.decomposition._nmf._check_init", "decorators": [], "parameters": [ { @@ -51682,7 +52747,9 @@ }, { "name": "_compute_regularization", + "unique_name": "_compute_regularization", "qname": "sklearn.decomposition._nmf._compute_regularization", + "unique_qname": "sklearn.decomposition._nmf._compute_regularization", "decorators": [], "parameters": [ { @@ -51744,7 +52811,9 @@ }, { "name": "_fit_coordinate_descent", + "unique_name": "_fit_coordinate_descent", "qname": "sklearn.decomposition._nmf._fit_coordinate_descent", + "unique_qname": "sklearn.decomposition._nmf._fit_coordinate_descent", "decorators": [], "parameters": [ { @@ -51886,7 +52955,9 @@ }, { "name": "_fit_multiplicative_update", + "unique_name": "_fit_multiplicative_update", "qname": "sklearn.decomposition._nmf._fit_multiplicative_update", + "unique_qname": "sklearn.decomposition._nmf._fit_multiplicative_update", "decorators": [], "parameters": [ { @@ -52018,7 +53089,9 @@ }, { "name": "_initialize_nmf", + "unique_name": "_initialize_nmf", "qname": "sklearn.decomposition._nmf._initialize_nmf", + "unique_qname": "sklearn.decomposition._nmf._initialize_nmf", "decorators": [], "parameters": [ { @@ -52080,7 +53153,9 @@ }, { "name": "_multiplicative_update_h", + "unique_name": "_multiplicative_update_h", "qname": "sklearn.decomposition._nmf._multiplicative_update_h", + "unique_qname": "sklearn.decomposition._nmf._multiplicative_update_h", "decorators": [], "parameters": [ { @@ -52162,7 +53237,9 @@ }, { "name": "_multiplicative_update_w", + "unique_name": "_multiplicative_update_w", "qname": "sklearn.decomposition._nmf._multiplicative_update_w", + "unique_qname": "sklearn.decomposition._nmf._multiplicative_update_w", "decorators": [], "parameters": [ { @@ -52284,7 +53361,9 @@ }, { "name": "_special_sparse_dot", + "unique_name": "_special_sparse_dot", "qname": "sklearn.decomposition._nmf._special_sparse_dot", + "unique_qname": "sklearn.decomposition._nmf._special_sparse_dot", "decorators": [], "parameters": [ { @@ -52326,7 +53405,9 @@ }, { "name": "_update_coordinate_descent", + "unique_name": "_update_coordinate_descent", "qname": "sklearn.decomposition._nmf._update_coordinate_descent", + "unique_qname": "sklearn.decomposition._nmf._update_coordinate_descent", "decorators": [], "parameters": [ { @@ -52408,7 +53489,9 @@ }, { "name": "non_negative_factorization", + "unique_name": "non_negative_factorization", "qname": "sklearn.decomposition._nmf.non_negative_factorization", + "unique_qname": "sklearn.decomposition._nmf.non_negative_factorization", "decorators": [], "parameters": [ { @@ -52600,7 +53683,9 @@ }, { "name": "norm", + "unique_name": "norm", "qname": "sklearn.decomposition._nmf.norm", + "unique_qname": "sklearn.decomposition._nmf.norm", "decorators": [], "parameters": [ { @@ -52622,7 +53707,9 @@ }, { "name": "trace_dot", + "unique_name": "trace_dot", "qname": "sklearn.decomposition._nmf.trace_dot", + "unique_qname": "sklearn.decomposition._nmf.trace_dot", "decorators": [], "parameters": [ { @@ -52654,7 +53741,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.decomposition._pca.PCA.__init__", + "unique_qname": "sklearn.decomposition._pca.PCA.__init__", "decorators": [], "parameters": [ { @@ -52746,7 +53835,9 @@ }, { "name": "_fit", + "unique_name": "_fit", "qname": "sklearn.decomposition._pca.PCA._fit", + "unique_qname": "sklearn.decomposition._pca.PCA._fit", "decorators": [], "parameters": [ { @@ -52778,7 +53869,9 @@ }, { "name": "_fit_full", + "unique_name": "_fit_full", "qname": "sklearn.decomposition._pca.PCA._fit_full", + "unique_qname": "sklearn.decomposition._pca.PCA._fit_full", "decorators": [], "parameters": [ { @@ -52820,7 +53913,9 @@ }, { "name": "_fit_truncated", + "unique_name": "_fit_truncated", "qname": "sklearn.decomposition._pca.PCA._fit_truncated", + "unique_qname": "sklearn.decomposition._pca.PCA._fit_truncated", "decorators": [], "parameters": [ { @@ -52872,7 +53967,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.decomposition._pca.PCA._more_tags", + "unique_qname": "sklearn.decomposition._pca.PCA._more_tags", "decorators": [], "parameters": [ { @@ -52894,7 +53991,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.decomposition._pca.PCA.fit", + "unique_qname": "sklearn.decomposition._pca.PCA.fit", "decorators": [], "parameters": [ { @@ -52936,7 +54035,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.decomposition._pca.PCA.fit_transform", + "unique_qname": "sklearn.decomposition._pca.PCA.fit_transform", "decorators": [], "parameters": [ { @@ -52978,7 +54079,9 @@ }, { "name": "score", + "unique_name": "score", "qname": "sklearn.decomposition._pca.PCA.score", + "unique_qname": "sklearn.decomposition._pca.PCA.score", "decorators": [], "parameters": [ { @@ -53020,7 +54123,9 @@ }, { "name": "score_samples", + "unique_name": "score_samples", "qname": "sklearn.decomposition._pca.PCA.score_samples", + "unique_qname": "sklearn.decomposition._pca.PCA.score_samples", "decorators": [], "parameters": [ { @@ -53052,7 +54157,9 @@ }, { "name": "_assess_dimension", + "unique_name": "_assess_dimension", "qname": "sklearn.decomposition._pca._assess_dimension", + "unique_qname": "sklearn.decomposition._pca._assess_dimension", "decorators": [], "parameters": [ { @@ -53094,7 +54201,9 @@ }, { "name": "_infer_dimension", + "unique_name": "_infer_dimension", "qname": "sklearn.decomposition._pca._infer_dimension", + "unique_qname": "sklearn.decomposition._pca._infer_dimension", "decorators": [], "parameters": [ { @@ -53126,7 +54235,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.decomposition._sparse_pca.MiniBatchSparsePCA.__init__", + "unique_qname": "sklearn.decomposition._sparse_pca.MiniBatchSparsePCA.__init__", "decorators": [], "parameters": [ { @@ -53258,7 +54369,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.decomposition._sparse_pca.MiniBatchSparsePCA.fit", + "unique_qname": "sklearn.decomposition._sparse_pca.MiniBatchSparsePCA.fit", "decorators": [], "parameters": [ { @@ -53300,7 +54413,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.decomposition._sparse_pca.SparsePCA.__init__", + "unique_qname": "sklearn.decomposition._sparse_pca.SparsePCA.__init__", "decorators": [], "parameters": [ { @@ -53432,7 +54547,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.decomposition._sparse_pca.SparsePCA.fit", + "unique_qname": "sklearn.decomposition._sparse_pca.SparsePCA.fit", "decorators": [], "parameters": [ { @@ -53474,7 +54591,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.decomposition._sparse_pca.SparsePCA.transform", + "unique_qname": "sklearn.decomposition._sparse_pca.SparsePCA.transform", "decorators": [], "parameters": [ { @@ -53506,7 +54625,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.decomposition._truncated_svd.TruncatedSVD.__init__", + "unique_qname": "sklearn.decomposition._truncated_svd.TruncatedSVD.__init__", "decorators": [], "parameters": [ { @@ -53578,7 +54699,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.decomposition._truncated_svd.TruncatedSVD._more_tags", + "unique_qname": "sklearn.decomposition._truncated_svd.TruncatedSVD._more_tags", "decorators": [], "parameters": [ { @@ -53600,7 +54723,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.decomposition._truncated_svd.TruncatedSVD.fit", + "unique_qname": "sklearn.decomposition._truncated_svd.TruncatedSVD.fit", "decorators": [], "parameters": [ { @@ -53642,7 +54767,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.decomposition._truncated_svd.TruncatedSVD.fit_transform", + "unique_qname": "sklearn.decomposition._truncated_svd.TruncatedSVD.fit_transform", "decorators": [], "parameters": [ { @@ -53684,7 +54811,9 @@ }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.decomposition._truncated_svd.TruncatedSVD.inverse_transform", + "unique_qname": "sklearn.decomposition._truncated_svd.TruncatedSVD.inverse_transform", "decorators": [], "parameters": [ { @@ -53716,7 +54845,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.decomposition._truncated_svd.TruncatedSVD.transform", + "unique_qname": "sklearn.decomposition._truncated_svd.TruncatedSVD.transform", "decorators": [], "parameters": [ { @@ -53748,7 +54879,9 @@ }, { "name": "configuration", + "unique_name": "configuration", "qname": "sklearn.decomposition.setup.configuration", + "unique_qname": "sklearn.decomposition.setup.configuration", "decorators": [], "parameters": [ { @@ -53780,7 +54913,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.discriminant_analysis.LinearDiscriminantAnalysis.__init__", + "unique_qname": "sklearn.discriminant_analysis.LinearDiscriminantAnalysis.__init__", "decorators": [], "parameters": [ { @@ -53872,7 +55007,9 @@ }, { "name": "_solve_eigen", + "unique_name": "_solve_eigen", "qname": "sklearn.discriminant_analysis.LinearDiscriminantAnalysis._solve_eigen", + "unique_qname": "sklearn.discriminant_analysis.LinearDiscriminantAnalysis._solve_eigen", "decorators": [], "parameters": [ { @@ -53934,7 +55071,9 @@ }, { "name": "_solve_lsqr", + "unique_name": "_solve_lsqr", "qname": "sklearn.discriminant_analysis.LinearDiscriminantAnalysis._solve_lsqr", + "unique_qname": "sklearn.discriminant_analysis.LinearDiscriminantAnalysis._solve_lsqr", "decorators": [], "parameters": [ { @@ -53996,7 +55135,9 @@ }, { "name": "_solve_svd", + "unique_name": "_solve_svd", "qname": "sklearn.discriminant_analysis.LinearDiscriminantAnalysis._solve_svd", + "unique_qname": "sklearn.discriminant_analysis.LinearDiscriminantAnalysis._solve_svd", "decorators": [], "parameters": [ { @@ -54038,7 +55179,9 @@ }, { "name": "decision_function", + "unique_name": "decision_function", "qname": "sklearn.discriminant_analysis.LinearDiscriminantAnalysis.decision_function", + "unique_qname": "sklearn.discriminant_analysis.LinearDiscriminantAnalysis.decision_function", "decorators": [], "parameters": [ { @@ -54070,7 +55213,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.discriminant_analysis.LinearDiscriminantAnalysis.fit", + "unique_qname": "sklearn.discriminant_analysis.LinearDiscriminantAnalysis.fit", "decorators": [], "parameters": [ { @@ -54112,7 +55257,9 @@ }, { "name": "predict_log_proba", + "unique_name": "predict_log_proba", "qname": "sklearn.discriminant_analysis.LinearDiscriminantAnalysis.predict_log_proba", + "unique_qname": "sklearn.discriminant_analysis.LinearDiscriminantAnalysis.predict_log_proba", "decorators": [], "parameters": [ { @@ -54144,7 +55291,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.discriminant_analysis.LinearDiscriminantAnalysis.predict_proba", + "unique_qname": "sklearn.discriminant_analysis.LinearDiscriminantAnalysis.predict_proba", "decorators": [], "parameters": [ { @@ -54176,7 +55325,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.discriminant_analysis.LinearDiscriminantAnalysis.transform", + "unique_qname": "sklearn.discriminant_analysis.LinearDiscriminantAnalysis.transform", "decorators": [], "parameters": [ { @@ -54208,7 +55359,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.discriminant_analysis.QuadraticDiscriminantAnalysis.__init__", + "unique_qname": "sklearn.discriminant_analysis.QuadraticDiscriminantAnalysis.__init__", "decorators": [], "parameters": [ { @@ -54270,7 +55423,9 @@ }, { "name": "_decision_function", + "unique_name": "_decision_function", "qname": "sklearn.discriminant_analysis.QuadraticDiscriminantAnalysis._decision_function", + "unique_qname": "sklearn.discriminant_analysis.QuadraticDiscriminantAnalysis._decision_function", "decorators": [], "parameters": [ { @@ -54302,7 +55457,9 @@ }, { "name": "decision_function", + "unique_name": "decision_function", "qname": "sklearn.discriminant_analysis.QuadraticDiscriminantAnalysis.decision_function", + "unique_qname": "sklearn.discriminant_analysis.QuadraticDiscriminantAnalysis.decision_function", "decorators": [], "parameters": [ { @@ -54334,7 +55491,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.discriminant_analysis.QuadraticDiscriminantAnalysis.fit", + "unique_qname": "sklearn.discriminant_analysis.QuadraticDiscriminantAnalysis.fit", "decorators": [], "parameters": [ { @@ -54364,19 +55523,21 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "array-like of shape (n_samples,)", - "description": "Target values (integers)" + "description": "Target values (integers)." } } ], "results": [], "is_public": true, "description": "Fit the model according to the given training data and parameters.\n\n .. versionchanged:: 0.19 ``store_covariances`` has been moved to main constructor as ``store_covariance`` .. versionchanged:: 0.19 ``tol`` has been moved to main constructor.", - "docstring": "Fit the model according to the given training data and parameters.\n\n .. versionchanged:: 0.19\n ``store_covariances`` has been moved to main constructor as\n ``store_covariance``\n\n .. versionchanged:: 0.19\n ``tol`` has been moved to main constructor.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\ny : array-like of shape (n_samples,)\n Target values (integers)", - "source_code": "\ndef fit(self, X, y):\n \"\"\"Fit the model according to the given training data and parameters.\n\n .. versionchanged:: 0.19\n ``store_covariances`` has been moved to main constructor as\n ``store_covariance``\n\n .. versionchanged:: 0.19\n ``tol`` has been moved to main constructor.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target values (integers)\n \"\"\"\n (X, y) = self._validate_data(X, y)\n check_classification_targets(y)\n (self.classes_, y) = np.unique(y, return_inverse=True)\n (n_samples, n_features) = X.shape\n n_classes = len(self.classes_)\n if n_classes < 2:\n raise ValueError('The number of classes has to be greater than one; got %d class' % n_classes)\n if self.priors is None:\n self.priors_ = np.bincount(y) / float(n_samples)\n else:\n self.priors_ = self.priors\n cov = None\n store_covariance = self.store_covariance\n if store_covariance:\n cov = []\n means = []\n scalings = []\n rotations = []\n for ind in range(n_classes):\n Xg = X[y == ind, :]\n meang = Xg.mean(0)\n means.append(meang)\n if len(Xg) == 1:\n raise ValueError('y has only 1 sample in class %s, covariance is ill defined.' % str(self.classes_[ind]))\n Xgc = Xg - meang\n (_, S, Vt) = np.linalg.svd(Xgc, full_matrices=False)\n rank = np.sum(S > self.tol)\n if rank < n_features:\n warnings.warn('Variables are collinear')\n S2 = S**2 / (len(Xg) - 1)\n S2 = (1 - self.reg_param) * S2 + self.reg_param\n if self.store_covariance or store_covariance:\n cov.append(np.dot(S2 * Vt.T, Vt))\n scalings.append(S2)\n rotations.append(Vt.T)\n if self.store_covariance or store_covariance:\n self.covariance_ = cov\n self.means_ = np.asarray(means)\n self.scalings_ = scalings\n self.rotations_ = rotations\n return self" + "docstring": "Fit the model according to the given training data and parameters.\n\n .. versionchanged:: 0.19\n ``store_covariances`` has been moved to main constructor as\n ``store_covariance``\n\n .. versionchanged:: 0.19\n ``tol`` has been moved to main constructor.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\ny : array-like of shape (n_samples,)\n Target values (integers).\n\nReturns\n-------\nself : object\n Fitted estimator.", + "source_code": "\ndef fit(self, X, y):\n \"\"\"Fit the model according to the given training data and parameters.\n\n .. versionchanged:: 0.19\n ``store_covariances`` has been moved to main constructor as\n ``store_covariance``\n\n .. versionchanged:: 0.19\n ``tol`` has been moved to main constructor.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target values (integers).\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n (X, y) = self._validate_data(X, y)\n check_classification_targets(y)\n (self.classes_, y) = np.unique(y, return_inverse=True)\n (n_samples, n_features) = X.shape\n n_classes = len(self.classes_)\n if n_classes < 2:\n raise ValueError('The number of classes has to be greater than one; got %d class' % n_classes)\n if self.priors is None:\n self.priors_ = np.bincount(y) / float(n_samples)\n else:\n self.priors_ = self.priors\n cov = None\n store_covariance = self.store_covariance\n if store_covariance:\n cov = []\n means = []\n scalings = []\n rotations = []\n for ind in range(n_classes):\n Xg = X[y == ind, :]\n meang = Xg.mean(0)\n means.append(meang)\n if len(Xg) == 1:\n raise ValueError('y has only 1 sample in class %s, covariance is ill defined.' % str(self.classes_[ind]))\n Xgc = Xg - meang\n (_, S, Vt) = np.linalg.svd(Xgc, full_matrices=False)\n rank = np.sum(S > self.tol)\n if rank < n_features:\n warnings.warn('Variables are collinear')\n S2 = S**2 / (len(Xg) - 1)\n S2 = (1 - self.reg_param) * S2 + self.reg_param\n if self.store_covariance or store_covariance:\n cov.append(np.dot(S2 * Vt.T, Vt))\n scalings.append(S2)\n rotations.append(Vt.T)\n if self.store_covariance or store_covariance:\n self.covariance_ = cov\n self.means_ = np.asarray(means)\n self.scalings_ = scalings\n self.rotations_ = rotations\n return self" }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.discriminant_analysis.QuadraticDiscriminantAnalysis.predict", + "unique_qname": "sklearn.discriminant_analysis.QuadraticDiscriminantAnalysis.predict", "decorators": [], "parameters": [ { @@ -54396,19 +55557,21 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "array-like of shape (n_samples, n_features)", - "description": "" + "description": "Vector to be scored, where `n_samples` is the number of samples and\n`n_features` is the number of features." } } ], "results": [], "is_public": true, "description": "Perform classification on an array of test vectors X.\n\nThe predicted class C for each sample in X is returned.", - "docstring": "Perform classification on an array of test vectors X.\n\nThe predicted class C for each sample in X is returned.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n\nReturns\n-------\nC : ndarray of shape (n_samples,)", - "source_code": "\ndef predict(self, X):\n \"\"\"Perform classification on an array of test vectors X.\n\n The predicted class C for each sample in X is returned.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n\n Returns\n -------\n C : ndarray of shape (n_samples,)\n \"\"\"\n d = self._decision_function(X)\n y_pred = self.classes_.take(d.argmax(1))\n return y_pred" + "docstring": "Perform classification on an array of test vectors X.\n\nThe predicted class C for each sample in X is returned.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Vector to be scored, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\nReturns\n-------\nC : ndarray of shape (n_samples,)\n Estimated probabilities.", + "source_code": "\ndef predict(self, X):\n \"\"\"Perform classification on an array of test vectors X.\n\n The predicted class C for each sample in X is returned.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Vector to be scored, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n Returns\n -------\n C : ndarray of shape (n_samples,)\n Estimated probabilities.\n \"\"\"\n d = self._decision_function(X)\n y_pred = self.classes_.take(d.argmax(1))\n return y_pred" }, { "name": "predict_log_proba", + "unique_name": "predict_log_proba", "qname": "sklearn.discriminant_analysis.QuadraticDiscriminantAnalysis.predict_log_proba", + "unique_qname": "sklearn.discriminant_analysis.QuadraticDiscriminantAnalysis.predict_log_proba", "decorators": [], "parameters": [ { @@ -54440,7 +55603,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.discriminant_analysis.QuadraticDiscriminantAnalysis.predict_proba", + "unique_qname": "sklearn.discriminant_analysis.QuadraticDiscriminantAnalysis.predict_proba", "decorators": [], "parameters": [ { @@ -54472,7 +55637,9 @@ }, { "name": "_class_cov", + "unique_name": "_class_cov", "qname": "sklearn.discriminant_analysis._class_cov", + "unique_qname": "sklearn.discriminant_analysis._class_cov", "decorators": [], "parameters": [ { @@ -54534,7 +55701,9 @@ }, { "name": "_class_means", + "unique_name": "_class_means", "qname": "sklearn.discriminant_analysis._class_means", + "unique_qname": "sklearn.discriminant_analysis._class_means", "decorators": [], "parameters": [ { @@ -54566,7 +55735,9 @@ }, { "name": "_cov", + "unique_name": "_cov", "qname": "sklearn.discriminant_analysis._cov", + "unique_qname": "sklearn.discriminant_analysis._cov", "decorators": [], "parameters": [ { @@ -54608,7 +55779,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.dummy.DummyClassifier.__init__", + "unique_qname": "sklearn.dummy.DummyClassifier.__init__", "decorators": [], "parameters": [ { @@ -54660,7 +55833,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.dummy.DummyClassifier._more_tags", + "unique_qname": "sklearn.dummy.DummyClassifier._more_tags", "decorators": [], "parameters": [ { @@ -54682,7 +55857,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.dummy.DummyClassifier.fit", + "unique_qname": "sklearn.dummy.DummyClassifier.fit", "decorators": [], "parameters": [ { @@ -54734,7 +55911,9 @@ }, { "name": "n_features_in_", + "unique_name": "n_features_in_@getter", "qname": "sklearn.dummy.DummyClassifier.n_features_in_", + "unique_qname": "sklearn.dummy.DummyClassifier.n_features_in_@getter", "decorators": [ "deprecated('`n_features_in_` is deprecated in 1.0 and will be removed in 1.2.')", "property" @@ -54759,7 +55938,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.dummy.DummyClassifier.predict", + "unique_qname": "sklearn.dummy.DummyClassifier.predict", "decorators": [], "parameters": [ { @@ -54791,7 +55972,9 @@ }, { "name": "predict_log_proba", + "unique_name": "predict_log_proba", "qname": "sklearn.dummy.DummyClassifier.predict_log_proba", + "unique_qname": "sklearn.dummy.DummyClassifier.predict_log_proba", "decorators": [], "parameters": [ { @@ -54823,7 +56006,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.dummy.DummyClassifier.predict_proba", + "unique_qname": "sklearn.dummy.DummyClassifier.predict_proba", "decorators": [], "parameters": [ { @@ -54855,7 +56040,9 @@ }, { "name": "score", + "unique_name": "score", "qname": "sklearn.dummy.DummyClassifier.score", + "unique_qname": "sklearn.dummy.DummyClassifier.score", "decorators": [], "parameters": [ { @@ -54907,7 +56094,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.dummy.DummyRegressor.__init__", + "unique_qname": "sklearn.dummy.DummyRegressor.__init__", "decorators": [], "parameters": [ { @@ -54959,7 +56148,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.dummy.DummyRegressor._more_tags", + "unique_qname": "sklearn.dummy.DummyRegressor._more_tags", "decorators": [], "parameters": [ { @@ -54981,7 +56172,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.dummy.DummyRegressor.fit", + "unique_qname": "sklearn.dummy.DummyRegressor.fit", "decorators": [], "parameters": [ { @@ -55033,7 +56226,9 @@ }, { "name": "n_features_in_", + "unique_name": "n_features_in_@getter", "qname": "sklearn.dummy.DummyRegressor.n_features_in_", + "unique_qname": "sklearn.dummy.DummyRegressor.n_features_in_@getter", "decorators": [ "deprecated('`n_features_in_` is deprecated in 1.0 and will be removed in 1.2.')", "property" @@ -55058,7 +56253,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.dummy.DummyRegressor.predict", + "unique_qname": "sklearn.dummy.DummyRegressor.predict", "decorators": [], "parameters": [ { @@ -55100,7 +56297,9 @@ }, { "name": "score", + "unique_name": "score", "qname": "sklearn.dummy.DummyRegressor.score", + "unique_qname": "sklearn.dummy.DummyRegressor.score", "decorators": [], "parameters": [ { @@ -55152,7 +56351,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._bagging.BaggingClassifier.__init__", + "unique_qname": "sklearn.ensemble._bagging.BaggingClassifier.__init__", "decorators": [], "parameters": [ { @@ -55284,7 +56485,9 @@ }, { "name": "_set_oob_score", + "unique_name": "_set_oob_score", "qname": "sklearn.ensemble._bagging.BaggingClassifier._set_oob_score", + "unique_qname": "sklearn.ensemble._bagging.BaggingClassifier._set_oob_score", "decorators": [], "parameters": [ { @@ -55326,7 +56529,9 @@ }, { "name": "_validate_estimator", + "unique_name": "_validate_estimator", "qname": "sklearn.ensemble._bagging.BaggingClassifier._validate_estimator", + "unique_qname": "sklearn.ensemble._bagging.BaggingClassifier._validate_estimator", "decorators": [], "parameters": [ { @@ -55348,7 +56553,9 @@ }, { "name": "_validate_y", + "unique_name": "_validate_y", "qname": "sklearn.ensemble._bagging.BaggingClassifier._validate_y", + "unique_qname": "sklearn.ensemble._bagging.BaggingClassifier._validate_y", "decorators": [], "parameters": [ { @@ -55380,7 +56587,9 @@ }, { "name": "decision_function", + "unique_name": "decision_function", "qname": "sklearn.ensemble._bagging.BaggingClassifier.decision_function", + "unique_qname": "sklearn.ensemble._bagging.BaggingClassifier.decision_function", "decorators": ["if_delegate_has_method(delegate='base_estimator')"], "parameters": [ { @@ -55412,7 +56621,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.ensemble._bagging.BaggingClassifier.predict", + "unique_qname": "sklearn.ensemble._bagging.BaggingClassifier.predict", "decorators": [], "parameters": [ { @@ -55444,7 +56655,9 @@ }, { "name": "predict_log_proba", + "unique_name": "predict_log_proba", "qname": "sklearn.ensemble._bagging.BaggingClassifier.predict_log_proba", + "unique_qname": "sklearn.ensemble._bagging.BaggingClassifier.predict_log_proba", "decorators": [], "parameters": [ { @@ -55476,7 +56689,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.ensemble._bagging.BaggingClassifier.predict_proba", + "unique_qname": "sklearn.ensemble._bagging.BaggingClassifier.predict_proba", "decorators": [], "parameters": [ { @@ -55508,7 +56723,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._bagging.BaggingRegressor.__init__", + "unique_qname": "sklearn.ensemble._bagging.BaggingRegressor.__init__", "decorators": [], "parameters": [ { @@ -55640,7 +56857,9 @@ }, { "name": "_set_oob_score", + "unique_name": "_set_oob_score", "qname": "sklearn.ensemble._bagging.BaggingRegressor._set_oob_score", + "unique_qname": "sklearn.ensemble._bagging.BaggingRegressor._set_oob_score", "decorators": [], "parameters": [ { @@ -55682,7 +56901,9 @@ }, { "name": "_validate_estimator", + "unique_name": "_validate_estimator", "qname": "sklearn.ensemble._bagging.BaggingRegressor._validate_estimator", + "unique_qname": "sklearn.ensemble._bagging.BaggingRegressor._validate_estimator", "decorators": [], "parameters": [ { @@ -55704,7 +56925,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.ensemble._bagging.BaggingRegressor.predict", + "unique_qname": "sklearn.ensemble._bagging.BaggingRegressor.predict", "decorators": [], "parameters": [ { @@ -55736,7 +56959,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._bagging.BaseBagging.__init__", + "unique_qname": "sklearn.ensemble._bagging.BaseBagging.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -55868,7 +57093,9 @@ }, { "name": "_fit", + "unique_name": "_fit", "qname": "sklearn.ensemble._bagging.BaseBagging._fit", + "unique_qname": "sklearn.ensemble._bagging.BaseBagging._fit", "decorators": [], "parameters": [ { @@ -55936,11 +57163,13 @@ "is_public": false, "description": "Build a Bagging ensemble of estimators from the training set (X, y).", "docstring": "Build a Bagging ensemble of estimators from the training\n set (X, y).\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrices are accepted only if\n they are supported by the base estimator.\n\ny : array-like of shape (n_samples,)\n The target values (class labels in classification, real numbers in\n regression).\n\nmax_samples : int or float, default=None\n Argument to use instead of self.max_samples.\n\nmax_depth : int, default=None\n Override value used when constructing base estimator. Only\n supported if the base estimator has a max_depth parameter.\n\nsample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n Note that this is supported only if the base estimator supports\n sample weighting.\n\nReturns\n-------\nself : object\n Fitted estimator.", - "source_code": "\ndef _fit(self, X, y, max_samples=None, max_depth=None, sample_weight=None):\n \"\"\"Build a Bagging ensemble of estimators from the training\n set (X, y).\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrices are accepted only if\n they are supported by the base estimator.\n\n y : array-like of shape (n_samples,)\n The target values (class labels in classification, real numbers in\n regression).\n\n max_samples : int or float, default=None\n Argument to use instead of self.max_samples.\n\n max_depth : int, default=None\n Override value used when constructing base estimator. Only\n supported if the base estimator has a max_depth parameter.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n Note that this is supported only if the base estimator supports\n sample weighting.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n random_state = check_random_state(self.random_state)\n (X, y) = self._validate_data(X, y, accept_sparse=['csr', 'csc'], dtype=None, force_all_finite=False, multi_output=True)\n if sample_weight is not None:\n sample_weight = _check_sample_weight(sample_weight, X, dtype=None)\n n_samples = X.shape[0]\n self._n_samples = n_samples\n y = self._validate_y(y)\n self._validate_estimator()\n if max_depth is not None:\n self.base_estimator_.max_depth = max_depth\n if max_samples is None:\n max_samples = self.max_samples\n elif not isinstance(max_samples, numbers.Integral):\n max_samples = int(max_samples * X.shape[0])\n if not 0 < max_samples <= X.shape[0]:\n raise ValueError('max_samples must be in (0, n_samples]')\n self._max_samples = max_samples\n if isinstance(self.max_features, numbers.Integral):\n max_features = self.max_features\n elif isinstance(self.max_features, float):\n max_features = self.max_features * self.n_features_in_\n else:\n raise ValueError('max_features must be int or float')\n if not 0 < max_features <= self.n_features_in_:\n raise ValueError('max_features must be in (0, n_features]')\n max_features = max(1, int(max_features))\n self._max_features = max_features\n if not self.bootstrap and self.oob_score:\n raise ValueError('Out of bag estimation only available if bootstrap=True')\n if self.warm_start and self.oob_score:\n raise ValueError('Out of bag estimate only available if warm_start=False')\n if hasattr(self, 'oob_score_') and self.warm_start:\n del self.oob_score_\n if not self.warm_start or not hasattr(self, 'estimators_'):\n self.estimators_ = []\n self.estimators_features_ = []\n n_more_estimators = self.n_estimators - len(self.estimators_)\n if n_more_estimators < 0:\n raise ValueError('n_estimators=%d must be larger or equal to len(estimators_)=%d when warm_start==True' % (self.n_estimators, len(self.estimators_)))\n elif n_more_estimators == 0:\n warn('Warm-start fitting without increasing n_estimators does not fit new trees.')\n return self\n (n_jobs, n_estimators, starts) = _partition_estimators(n_more_estimators, self.n_jobs)\n total_n_estimators = sum(n_estimators)\n if self.warm_start and len(self.estimators_) > 0:\n random_state.randint(MAX_INT, size=len(self.estimators_))\n seeds = random_state.randint(MAX_INT, size=n_more_estimators)\n self._seeds = seeds\n all_results = Parallel(n_jobs=n_jobs, verbose=self.verbose, **self._parallel_args())((delayed(_parallel_build_estimators)(n_estimators[i], self, X, y, sample_weight, seeds[starts[i]:starts[i + 1]], total_n_estimators, verbose=self.verbose) for i in range(n_jobs)))\n self.estimators_ += list(itertools.chain.from_iterable((t[0] for t in all_results)))\n self.estimators_features_ += list(itertools.chain.from_iterable((t[1] for t in all_results)))\n if self.oob_score:\n self._set_oob_score(X, y)\n return self" + "source_code": "\ndef _fit(self, X, y, max_samples=None, max_depth=None, sample_weight=None):\n \"\"\"Build a Bagging ensemble of estimators from the training\n set (X, y).\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrices are accepted only if\n they are supported by the base estimator.\n\n y : array-like of shape (n_samples,)\n The target values (class labels in classification, real numbers in\n regression).\n\n max_samples : int or float, default=None\n Argument to use instead of self.max_samples.\n\n max_depth : int, default=None\n Override value used when constructing base estimator. Only\n supported if the base estimator has a max_depth parameter.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n Note that this is supported only if the base estimator supports\n sample weighting.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n random_state = check_random_state(self.random_state)\n if sample_weight is not None:\n sample_weight = _check_sample_weight(sample_weight, X, dtype=None)\n n_samples = X.shape[0]\n self._n_samples = n_samples\n y = self._validate_y(y)\n self._validate_estimator()\n if max_depth is not None:\n self.base_estimator_.max_depth = max_depth\n if max_samples is None:\n max_samples = self.max_samples\n elif not isinstance(max_samples, numbers.Integral):\n max_samples = int(max_samples * X.shape[0])\n if not 0 < max_samples <= X.shape[0]:\n raise ValueError('max_samples must be in (0, n_samples]')\n self._max_samples = max_samples\n if isinstance(self.max_features, numbers.Integral):\n max_features = self.max_features\n elif isinstance(self.max_features, float):\n max_features = self.max_features * self.n_features_in_\n else:\n raise ValueError('max_features must be int or float')\n if not 0 < max_features <= self.n_features_in_:\n raise ValueError('max_features must be in (0, n_features]')\n max_features = max(1, int(max_features))\n self._max_features = max_features\n if not self.bootstrap and self.oob_score:\n raise ValueError('Out of bag estimation only available if bootstrap=True')\n if self.warm_start and self.oob_score:\n raise ValueError('Out of bag estimate only available if warm_start=False')\n if hasattr(self, 'oob_score_') and self.warm_start:\n del self.oob_score_\n if not self.warm_start or not hasattr(self, 'estimators_'):\n self.estimators_ = []\n self.estimators_features_ = []\n n_more_estimators = self.n_estimators - len(self.estimators_)\n if n_more_estimators < 0:\n raise ValueError('n_estimators=%d must be larger or equal to len(estimators_)=%d when warm_start==True' % (self.n_estimators, len(self.estimators_)))\n elif n_more_estimators == 0:\n warn('Warm-start fitting without increasing n_estimators does not fit new trees.')\n return self\n (n_jobs, n_estimators, starts) = _partition_estimators(n_more_estimators, self.n_jobs)\n total_n_estimators = sum(n_estimators)\n if self.warm_start and len(self.estimators_) > 0:\n random_state.randint(MAX_INT, size=len(self.estimators_))\n seeds = random_state.randint(MAX_INT, size=n_more_estimators)\n self._seeds = seeds\n all_results = Parallel(n_jobs=n_jobs, verbose=self.verbose, **self._parallel_args())((delayed(_parallel_build_estimators)(n_estimators[i], self, X, y, sample_weight, seeds[starts[i]:starts[i + 1]], total_n_estimators, verbose=self.verbose) for i in range(n_jobs)))\n self.estimators_ += list(itertools.chain.from_iterable((t[0] for t in all_results)))\n self.estimators_features_ += list(itertools.chain.from_iterable((t[1] for t in all_results)))\n if self.oob_score:\n self._set_oob_score(X, y)\n return self" }, { "name": "_get_estimators_indices", + "unique_name": "_get_estimators_indices", "qname": "sklearn.ensemble._bagging.BaseBagging._get_estimators_indices", + "unique_qname": "sklearn.ensemble._bagging.BaseBagging._get_estimators_indices", "decorators": [], "parameters": [ { @@ -55962,7 +57191,9 @@ }, { "name": "_parallel_args", + "unique_name": "_parallel_args", "qname": "sklearn.ensemble._bagging.BaseBagging._parallel_args", + "unique_qname": "sklearn.ensemble._bagging.BaseBagging._parallel_args", "decorators": [], "parameters": [ { @@ -55984,7 +57215,9 @@ }, { "name": "_set_oob_score", + "unique_name": "_set_oob_score", "qname": "sklearn.ensemble._bagging.BaseBagging._set_oob_score", + "unique_qname": "sklearn.ensemble._bagging.BaseBagging._set_oob_score", "decorators": ["abstractmethod"], "parameters": [ { @@ -56026,7 +57259,9 @@ }, { "name": "_validate_y", + "unique_name": "_validate_y", "qname": "sklearn.ensemble._bagging.BaseBagging._validate_y", + "unique_qname": "sklearn.ensemble._bagging.BaseBagging._validate_y", "decorators": [], "parameters": [ { @@ -56058,7 +57293,9 @@ }, { "name": "estimators_samples_", + "unique_name": "estimators_samples_@getter", "qname": "sklearn.ensemble._bagging.BaseBagging.estimators_samples_", + "unique_qname": "sklearn.ensemble._bagging.BaseBagging.estimators_samples_@getter", "decorators": ["property"], "parameters": [ { @@ -56080,7 +57317,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.ensemble._bagging.BaseBagging.fit", + "unique_qname": "sklearn.ensemble._bagging.BaseBagging.fit", "decorators": [], "parameters": [ { @@ -56128,11 +57367,13 @@ "is_public": false, "description": "Build a Bagging ensemble of estimators from the training set (X, y).", "docstring": "Build a Bagging ensemble of estimators from the training set (X, y).\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrices are accepted only if\n they are supported by the base estimator.\n\ny : array-like of shape (n_samples,)\n The target values (class labels in classification, real numbers in\n regression).\n\nsample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n Note that this is supported only if the base estimator supports\n sample weighting.\n\nReturns\n-------\nself : object\n Fitted estimator.", - "source_code": "\ndef fit(self, X, y, sample_weight=None):\n \"\"\"Build a Bagging ensemble of estimators from the training set (X, y).\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrices are accepted only if\n they are supported by the base estimator.\n\n y : array-like of shape (n_samples,)\n The target values (class labels in classification, real numbers in\n regression).\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n Note that this is supported only if the base estimator supports\n sample weighting.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n return self._fit(X, y, self.max_samples, sample_weight=sample_weight)" + "source_code": "\ndef fit(self, X, y, sample_weight=None):\n \"\"\"Build a Bagging ensemble of estimators from the training set (X, y).\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrices are accepted only if\n they are supported by the base estimator.\n\n y : array-like of shape (n_samples,)\n The target values (class labels in classification, real numbers in\n regression).\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n Note that this is supported only if the base estimator supports\n sample weighting.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n (X, y) = self._validate_data(X, y, accept_sparse=['csr', 'csc'], dtype=None, force_all_finite=False, multi_output=True)\n return self._fit(X, y, self.max_samples, sample_weight=sample_weight)" }, { "name": "n_features_", + "unique_name": "n_features_@getter", "qname": "sklearn.ensemble._bagging.BaseBagging.n_features_", + "unique_qname": "sklearn.ensemble._bagging.BaseBagging.n_features_@getter", "decorators": [ "deprecated('Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead.')", "property" @@ -56157,7 +57398,9 @@ }, { "name": "_generate_bagging_indices", + "unique_name": "_generate_bagging_indices", "qname": "sklearn.ensemble._bagging._generate_bagging_indices", + "unique_qname": "sklearn.ensemble._bagging._generate_bagging_indices", "decorators": [], "parameters": [ { @@ -56239,7 +57482,9 @@ }, { "name": "_generate_indices", + "unique_name": "_generate_indices", "qname": "sklearn.ensemble._bagging._generate_indices", + "unique_qname": "sklearn.ensemble._bagging._generate_indices", "decorators": [], "parameters": [ { @@ -56291,7 +57536,9 @@ }, { "name": "_parallel_build_estimators", + "unique_name": "_parallel_build_estimators", "qname": "sklearn.ensemble._bagging._parallel_build_estimators", + "unique_qname": "sklearn.ensemble._bagging._parallel_build_estimators", "decorators": [], "parameters": [ { @@ -56383,7 +57630,9 @@ }, { "name": "_parallel_decision_function", + "unique_name": "_parallel_decision_function", "qname": "sklearn.ensemble._bagging._parallel_decision_function", + "unique_qname": "sklearn.ensemble._bagging._parallel_decision_function", "decorators": [], "parameters": [ { @@ -56425,7 +57674,9 @@ }, { "name": "_parallel_predict_log_proba", + "unique_name": "_parallel_predict_log_proba", "qname": "sklearn.ensemble._bagging._parallel_predict_log_proba", + "unique_qname": "sklearn.ensemble._bagging._parallel_predict_log_proba", "decorators": [], "parameters": [ { @@ -56477,7 +57728,9 @@ }, { "name": "_parallel_predict_proba", + "unique_name": "_parallel_predict_proba", "qname": "sklearn.ensemble._bagging._parallel_predict_proba", + "unique_qname": "sklearn.ensemble._bagging._parallel_predict_proba", "decorators": [], "parameters": [ { @@ -56529,7 +57782,9 @@ }, { "name": "_parallel_predict_regression", + "unique_name": "_parallel_predict_regression", "qname": "sklearn.ensemble._bagging._parallel_predict_regression", + "unique_qname": "sklearn.ensemble._bagging._parallel_predict_regression", "decorators": [], "parameters": [ { @@ -56571,7 +57826,9 @@ }, { "name": "__getitem__", + "unique_name": "__getitem__", "qname": "sklearn.ensemble._base.BaseEnsemble.__getitem__", + "unique_qname": "sklearn.ensemble._base.BaseEnsemble.__getitem__", "decorators": [], "parameters": [ { @@ -56603,7 +57860,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._base.BaseEnsemble.__init__", + "unique_qname": "sklearn.ensemble._base.BaseEnsemble.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -56655,7 +57914,9 @@ }, { "name": "__iter__", + "unique_name": "__iter__", "qname": "sklearn.ensemble._base.BaseEnsemble.__iter__", + "unique_qname": "sklearn.ensemble._base.BaseEnsemble.__iter__", "decorators": [], "parameters": [ { @@ -56677,7 +57938,9 @@ }, { "name": "__len__", + "unique_name": "__len__", "qname": "sklearn.ensemble._base.BaseEnsemble.__len__", + "unique_qname": "sklearn.ensemble._base.BaseEnsemble.__len__", "decorators": [], "parameters": [ { @@ -56699,7 +57962,9 @@ }, { "name": "_make_estimator", + "unique_name": "_make_estimator", "qname": "sklearn.ensemble._base.BaseEnsemble._make_estimator", + "unique_qname": "sklearn.ensemble._base.BaseEnsemble._make_estimator", "decorators": [], "parameters": [ { @@ -56741,7 +58006,9 @@ }, { "name": "_validate_estimator", + "unique_name": "_validate_estimator", "qname": "sklearn.ensemble._base.BaseEnsemble._validate_estimator", + "unique_qname": "sklearn.ensemble._base.BaseEnsemble._validate_estimator", "decorators": [], "parameters": [ { @@ -56773,7 +58040,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._base._BaseHeterogeneousEnsemble.__init__", + "unique_qname": "sklearn.ensemble._base._BaseHeterogeneousEnsemble.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -56805,7 +58074,9 @@ }, { "name": "_validate_estimators", + "unique_name": "_validate_estimators", "qname": "sklearn.ensemble._base._BaseHeterogeneousEnsemble._validate_estimators", + "unique_qname": "sklearn.ensemble._base._BaseHeterogeneousEnsemble._validate_estimators", "decorators": [], "parameters": [ { @@ -56827,7 +58098,9 @@ }, { "name": "get_params", + "unique_name": "get_params", "qname": "sklearn.ensemble._base._BaseHeterogeneousEnsemble.get_params", + "unique_qname": "sklearn.ensemble._base._BaseHeterogeneousEnsemble.get_params", "decorators": [], "parameters": [ { @@ -56859,7 +58132,9 @@ }, { "name": "named_estimators", + "unique_name": "named_estimators@getter", "qname": "sklearn.ensemble._base._BaseHeterogeneousEnsemble.named_estimators", + "unique_qname": "sklearn.ensemble._base._BaseHeterogeneousEnsemble.named_estimators@getter", "decorators": ["property"], "parameters": [ { @@ -56881,7 +58156,9 @@ }, { "name": "set_params", + "unique_name": "set_params", "qname": "sklearn.ensemble._base._BaseHeterogeneousEnsemble.set_params", + "unique_qname": "sklearn.ensemble._base._BaseHeterogeneousEnsemble.set_params", "decorators": [], "parameters": [ { @@ -56903,7 +58180,9 @@ }, { "name": "_fit_single_estimator", + "unique_name": "_fit_single_estimator", "qname": "sklearn.ensemble._base._fit_single_estimator", + "unique_qname": "sklearn.ensemble._base._fit_single_estimator", "decorators": [], "parameters": [ { @@ -56975,7 +58254,9 @@ }, { "name": "_partition_estimators", + "unique_name": "_partition_estimators", "qname": "sklearn.ensemble._base._partition_estimators", + "unique_qname": "sklearn.ensemble._base._partition_estimators", "decorators": [], "parameters": [ { @@ -57007,7 +58288,9 @@ }, { "name": "_set_random_states", + "unique_name": "_set_random_states", "qname": "sklearn.ensemble._base._set_random_states", + "unique_qname": "sklearn.ensemble._base._set_random_states", "decorators": [], "parameters": [ { @@ -57039,7 +58322,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._forest.BaseForest.__init__", + "unique_qname": "sklearn.ensemble._forest.BaseForest.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -57171,7 +58456,9 @@ }, { "name": "_compute_oob_predictions", + "unique_name": "_compute_oob_predictions", "qname": "sklearn.ensemble._forest.BaseForest._compute_oob_predictions", + "unique_qname": "sklearn.ensemble._forest.BaseForest._compute_oob_predictions", "decorators": [], "parameters": [ { @@ -57213,7 +58500,9 @@ }, { "name": "_set_oob_score_and_attributes", + "unique_name": "_set_oob_score_and_attributes", "qname": "sklearn.ensemble._forest.BaseForest._set_oob_score_and_attributes", + "unique_qname": "sklearn.ensemble._forest.BaseForest._set_oob_score_and_attributes", "decorators": ["abstractmethod"], "parameters": [ { @@ -57255,7 +58544,9 @@ }, { "name": "_validate_X_predict", + "unique_name": "_validate_X_predict", "qname": "sklearn.ensemble._forest.BaseForest._validate_X_predict", + "unique_qname": "sklearn.ensemble._forest.BaseForest._validate_X_predict", "decorators": [], "parameters": [ { @@ -57287,7 +58578,9 @@ }, { "name": "_validate_y_class_weight", + "unique_name": "_validate_y_class_weight", "qname": "sklearn.ensemble._forest.BaseForest._validate_y_class_weight", + "unique_qname": "sklearn.ensemble._forest.BaseForest._validate_y_class_weight", "decorators": [], "parameters": [ { @@ -57319,7 +58612,9 @@ }, { "name": "apply", + "unique_name": "apply", "qname": "sklearn.ensemble._forest.BaseForest.apply", + "unique_qname": "sklearn.ensemble._forest.BaseForest.apply", "decorators": [], "parameters": [ { @@ -57351,7 +58646,9 @@ }, { "name": "decision_path", + "unique_name": "decision_path", "qname": "sklearn.ensemble._forest.BaseForest.decision_path", + "unique_qname": "sklearn.ensemble._forest.BaseForest.decision_path", "decorators": [], "parameters": [ { @@ -57383,7 +58680,9 @@ }, { "name": "feature_importances_", + "unique_name": "feature_importances_@getter", "qname": "sklearn.ensemble._forest.BaseForest.feature_importances_", + "unique_qname": "sklearn.ensemble._forest.BaseForest.feature_importances_@getter", "decorators": ["property"], "parameters": [ { @@ -57405,7 +58704,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.ensemble._forest.BaseForest.fit", + "unique_qname": "sklearn.ensemble._forest.BaseForest.fit", "decorators": [], "parameters": [ { @@ -57457,7 +58758,9 @@ }, { "name": "n_features_", + "unique_name": "n_features_@getter", "qname": "sklearn.ensemble._forest.BaseForest.n_features_", + "unique_qname": "sklearn.ensemble._forest.BaseForest.n_features_@getter", "decorators": [ "deprecated('Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead.')", "property" @@ -57482,7 +58785,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._forest.ExtraTreesClassifier.__init__", + "unique_qname": "sklearn.ensemble._forest.ExtraTreesClassifier.__init__", "decorators": [], "parameters": [ { @@ -57684,7 +58989,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._forest.ExtraTreesRegressor.__init__", + "unique_qname": "sklearn.ensemble._forest.ExtraTreesRegressor.__init__", "decorators": [], "parameters": [ { @@ -57713,7 +59020,7 @@ "is_public": true, "assigned_by": "NAME_ONLY", "docstring": { - "type": "{\"squared_error\", \"mse\", \"absolute_error\", \"mae\"}, default=\"squared_error\"", + "type": "{\"squared_error\", \"absolute_error\"}, default=\"squared_error\"", "description": "The function to measure the quality of a split. Supported criteria\nare \"squared_error\" for the mean squared error, which is equal to\nvariance reduction as feature selection criterion, and \"absolute_error\"\nfor the mean absolute error.\n\n.. versionadded:: 0.18\n Mean Absolute Error (MAE) criterion.\n\n.. deprecated:: 1.0\n Criterion \"mse\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"squared_error\"` which is equivalent.\n\n.. deprecated:: 1.0\n Criterion \"mae\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"absolute_error\"` which is equivalent." } }, @@ -57876,7 +59183,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._forest.ForestClassifier.__init__", + "unique_qname": "sklearn.ensemble._forest.ForestClassifier.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -58008,7 +59317,9 @@ }, { "name": "_get_oob_predictions", + "unique_name": "_get_oob_predictions", "qname": "sklearn.ensemble._forest.ForestClassifier._get_oob_predictions", + "unique_qname": "sklearn.ensemble._forest.ForestClassifier._get_oob_predictions", "decorators": ["staticmethod"], "parameters": [ { @@ -58040,7 +59351,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.ensemble._forest.ForestClassifier._more_tags", + "unique_qname": "sklearn.ensemble._forest.ForestClassifier._more_tags", "decorators": [], "parameters": [ { @@ -58062,7 +59375,9 @@ }, { "name": "_set_oob_score_and_attributes", + "unique_name": "_set_oob_score_and_attributes", "qname": "sklearn.ensemble._forest.ForestClassifier._set_oob_score_and_attributes", + "unique_qname": "sklearn.ensemble._forest.ForestClassifier._set_oob_score_and_attributes", "decorators": [], "parameters": [ { @@ -58104,7 +59419,9 @@ }, { "name": "_validate_y_class_weight", + "unique_name": "_validate_y_class_weight", "qname": "sklearn.ensemble._forest.ForestClassifier._validate_y_class_weight", + "unique_qname": "sklearn.ensemble._forest.ForestClassifier._validate_y_class_weight", "decorators": [], "parameters": [ { @@ -58136,7 +59453,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.ensemble._forest.ForestClassifier.predict", + "unique_qname": "sklearn.ensemble._forest.ForestClassifier.predict", "decorators": [], "parameters": [ { @@ -58168,7 +59487,9 @@ }, { "name": "predict_log_proba", + "unique_name": "predict_log_proba", "qname": "sklearn.ensemble._forest.ForestClassifier.predict_log_proba", + "unique_qname": "sklearn.ensemble._forest.ForestClassifier.predict_log_proba", "decorators": [], "parameters": [ { @@ -58200,7 +59521,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.ensemble._forest.ForestClassifier.predict_proba", + "unique_qname": "sklearn.ensemble._forest.ForestClassifier.predict_proba", "decorators": [], "parameters": [ { @@ -58232,7 +59555,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._forest.ForestRegressor.__init__", + "unique_qname": "sklearn.ensemble._forest.ForestRegressor.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -58354,7 +59679,9 @@ }, { "name": "_compute_partial_dependence_recursion", + "unique_name": "_compute_partial_dependence_recursion", "qname": "sklearn.ensemble._forest.ForestRegressor._compute_partial_dependence_recursion", + "unique_qname": "sklearn.ensemble._forest.ForestRegressor._compute_partial_dependence_recursion", "decorators": [], "parameters": [ { @@ -58396,7 +59723,9 @@ }, { "name": "_get_oob_predictions", + "unique_name": "_get_oob_predictions", "qname": "sklearn.ensemble._forest.ForestRegressor._get_oob_predictions", + "unique_qname": "sklearn.ensemble._forest.ForestRegressor._get_oob_predictions", "decorators": ["staticmethod"], "parameters": [ { @@ -58428,7 +59757,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.ensemble._forest.ForestRegressor._more_tags", + "unique_qname": "sklearn.ensemble._forest.ForestRegressor._more_tags", "decorators": [], "parameters": [ { @@ -58450,7 +59781,9 @@ }, { "name": "_set_oob_score_and_attributes", + "unique_name": "_set_oob_score_and_attributes", "qname": "sklearn.ensemble._forest.ForestRegressor._set_oob_score_and_attributes", + "unique_qname": "sklearn.ensemble._forest.ForestRegressor._set_oob_score_and_attributes", "decorators": [], "parameters": [ { @@ -58492,7 +59825,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.ensemble._forest.ForestRegressor.predict", + "unique_qname": "sklearn.ensemble._forest.ForestRegressor.predict", "decorators": [], "parameters": [ { @@ -58524,7 +59859,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._forest.RandomForestClassifier.__init__", + "unique_qname": "sklearn.ensemble._forest.RandomForestClassifier.__init__", "decorators": [], "parameters": [ { @@ -58726,7 +60063,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._forest.RandomForestRegressor.__init__", + "unique_qname": "sklearn.ensemble._forest.RandomForestRegressor.__init__", "decorators": [], "parameters": [ { @@ -58755,7 +60094,7 @@ "is_public": true, "assigned_by": "NAME_ONLY", "docstring": { - "type": "{\"squared_error\", \"mse\", \"absolute_error\", \"poisson\"}, default=\"squared_error\"", + "type": "{\"squared_error\", \"absolute_error\", \"poisson\"}, default=\"squared_error\"", "description": "The function to measure the quality of a split. Supported criteria\nare \"squared_error\" for the mean squared error, which is equal to\nvariance reduction as feature selection criterion, \"absolute_error\"\nfor the mean absolute error, and \"poisson\" which uses reduction in\nPoisson deviance to find splits.\nTraining using \"absolute_error\" is significantly slower\nthan when using \"squared_error\".\n\n.. versionadded:: 0.18\n Mean Absolute Error (MAE) criterion.\n\n.. versionadded:: 1.0\n Poisson criterion.\n\n.. deprecated:: 1.0\n Criterion \"mse\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"squared_error\"` which is equivalent.\n\n.. deprecated:: 1.0\n Criterion \"mae\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"absolute_error\"` which is equivalent." } }, @@ -58918,7 +60257,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._forest.RandomTreesEmbedding.__init__", + "unique_qname": "sklearn.ensemble._forest.RandomTreesEmbedding.__init__", "decorators": [], "parameters": [ { @@ -59060,7 +60401,9 @@ }, { "name": "_set_oob_score_and_attributes", + "unique_name": "_set_oob_score_and_attributes", "qname": "sklearn.ensemble._forest.RandomTreesEmbedding._set_oob_score_and_attributes", + "unique_qname": "sklearn.ensemble._forest.RandomTreesEmbedding._set_oob_score_and_attributes", "decorators": [], "parameters": [ { @@ -59102,7 +60445,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.ensemble._forest.RandomTreesEmbedding.fit", + "unique_qname": "sklearn.ensemble._forest.RandomTreesEmbedding.fit", "decorators": [], "parameters": [ { @@ -59154,7 +60499,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.ensemble._forest.RandomTreesEmbedding.fit_transform", + "unique_qname": "sklearn.ensemble._forest.RandomTreesEmbedding.fit_transform", "decorators": [], "parameters": [ { @@ -59202,11 +60549,13 @@ "is_public": true, "description": "Fit estimator and transform dataset.", "docstring": "Fit estimator and transform dataset.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input data used to build forests. Use ``dtype=np.float32`` for\n maximum efficiency.\n\ny : Ignored\n Not used, present for API consistency by convention.\n\nsample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted. Splits\n that would create child nodes with net zero or negative weight are\n ignored while searching for a split in each node. In the case of\n classification, splits are also ignored if they would result in any\n single class carrying a negative weight in either child node.\n\nReturns\n-------\nX_transformed : sparse matrix of shape (n_samples, n_out)\n Transformed dataset.", - "source_code": "\ndef fit_transform(self, X, y=None, sample_weight=None):\n \"\"\"\n Fit estimator and transform dataset.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input data used to build forests. Use ``dtype=np.float32`` for\n maximum efficiency.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted. Splits\n that would create child nodes with net zero or negative weight are\n ignored while searching for a split in each node. In the case of\n classification, splits are also ignored if they would result in any\n single class carrying a negative weight in either child node.\n\n Returns\n -------\n X_transformed : sparse matrix of shape (n_samples, n_out)\n Transformed dataset.\n \"\"\"\n X = self._validate_data(X, accept_sparse=['csc'])\n if issparse(X):\n X.sort_indices()\n rnd = check_random_state(self.random_state)\n y = rnd.uniform(size=X.shape[0])\n super().fit(X, y, sample_weight=sample_weight)\n self.one_hot_encoder_ = OneHotEncoder(sparse=self.sparse_output)\n return self.one_hot_encoder_.fit_transform(self.apply(X))" + "source_code": "\ndef fit_transform(self, X, y=None, sample_weight=None):\n \"\"\"\n Fit estimator and transform dataset.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input data used to build forests. Use ``dtype=np.float32`` for\n maximum efficiency.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted. Splits\n that would create child nodes with net zero or negative weight are\n ignored while searching for a split in each node. In the case of\n classification, splits are also ignored if they would result in any\n single class carrying a negative weight in either child node.\n\n Returns\n -------\n X_transformed : sparse matrix of shape (n_samples, n_out)\n Transformed dataset.\n \"\"\"\n rnd = check_random_state(self.random_state)\n y = rnd.uniform(size=_num_samples(X))\n super().fit(X, y, sample_weight=sample_weight)\n self.one_hot_encoder_ = OneHotEncoder(sparse=self.sparse_output)\n return self.one_hot_encoder_.fit_transform(self.apply(X))" }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.ensemble._forest.RandomTreesEmbedding.transform", + "unique_qname": "sklearn.ensemble._forest.RandomTreesEmbedding.transform", "decorators": [], "parameters": [ { @@ -59238,7 +60587,9 @@ }, { "name": "_accumulate_prediction", + "unique_name": "_accumulate_prediction", "qname": "sklearn.ensemble._forest._accumulate_prediction", + "unique_qname": "sklearn.ensemble._forest._accumulate_prediction", "decorators": [], "parameters": [ { @@ -59290,7 +60641,9 @@ }, { "name": "_generate_sample_indices", + "unique_name": "_generate_sample_indices", "qname": "sklearn.ensemble._forest._generate_sample_indices", + "unique_qname": "sklearn.ensemble._forest._generate_sample_indices", "decorators": [], "parameters": [ { @@ -59332,7 +60685,9 @@ }, { "name": "_generate_unsampled_indices", + "unique_name": "_generate_unsampled_indices", "qname": "sklearn.ensemble._forest._generate_unsampled_indices", + "unique_qname": "sklearn.ensemble._forest._generate_unsampled_indices", "decorators": [], "parameters": [ { @@ -59374,7 +60729,9 @@ }, { "name": "_get_n_samples_bootstrap", + "unique_name": "_get_n_samples_bootstrap", "qname": "sklearn.ensemble._forest._get_n_samples_bootstrap", + "unique_qname": "sklearn.ensemble._forest._get_n_samples_bootstrap", "decorators": [], "parameters": [ { @@ -59406,7 +60763,9 @@ }, { "name": "_parallel_build_trees", + "unique_name": "_parallel_build_trees", "qname": "sklearn.ensemble._forest._parallel_build_trees", + "unique_qname": "sklearn.ensemble._forest._parallel_build_trees", "decorators": [], "parameters": [ { @@ -59518,7 +60877,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._gb.BaseGradientBoosting.__init__", + "unique_qname": "sklearn.ensemble._gb.BaseGradientBoosting.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -59750,7 +61111,9 @@ }, { "name": "_check_initialized", + "unique_name": "_check_initialized", "qname": "sklearn.ensemble._gb.BaseGradientBoosting._check_initialized", + "unique_qname": "sklearn.ensemble._gb.BaseGradientBoosting._check_initialized", "decorators": [], "parameters": [ { @@ -59772,7 +61135,9 @@ }, { "name": "_check_params", + "unique_name": "_check_params", "qname": "sklearn.ensemble._gb.BaseGradientBoosting._check_params", + "unique_qname": "sklearn.ensemble._gb.BaseGradientBoosting._check_params", "decorators": [], "parameters": [ { @@ -59794,7 +61159,9 @@ }, { "name": "_clear_state", + "unique_name": "_clear_state", "qname": "sklearn.ensemble._gb.BaseGradientBoosting._clear_state", + "unique_qname": "sklearn.ensemble._gb.BaseGradientBoosting._clear_state", "decorators": [], "parameters": [ { @@ -59816,7 +61183,9 @@ }, { "name": "_compute_partial_dependence_recursion", + "unique_name": "_compute_partial_dependence_recursion", "qname": "sklearn.ensemble._gb.BaseGradientBoosting._compute_partial_dependence_recursion", + "unique_qname": "sklearn.ensemble._gb.BaseGradientBoosting._compute_partial_dependence_recursion", "decorators": [], "parameters": [ { @@ -59858,7 +61227,9 @@ }, { "name": "_fit_stage", + "unique_name": "_fit_stage", "qname": "sklearn.ensemble._gb.BaseGradientBoosting._fit_stage", + "unique_qname": "sklearn.ensemble._gb.BaseGradientBoosting._fit_stage", "decorators": [], "parameters": [ { @@ -59970,7 +61341,9 @@ }, { "name": "_fit_stages", + "unique_name": "_fit_stages", "qname": "sklearn.ensemble._gb.BaseGradientBoosting._fit_stages", + "unique_qname": "sklearn.ensemble._gb.BaseGradientBoosting._fit_stages", "decorators": [], "parameters": [ { @@ -60092,7 +61465,9 @@ }, { "name": "_init_state", + "unique_name": "_init_state", "qname": "sklearn.ensemble._gb.BaseGradientBoosting._init_state", + "unique_qname": "sklearn.ensemble._gb.BaseGradientBoosting._init_state", "decorators": [], "parameters": [ { @@ -60114,7 +61489,9 @@ }, { "name": "_is_initialized", + "unique_name": "_is_initialized", "qname": "sklearn.ensemble._gb.BaseGradientBoosting._is_initialized", + "unique_qname": "sklearn.ensemble._gb.BaseGradientBoosting._is_initialized", "decorators": [], "parameters": [ { @@ -60136,7 +61513,9 @@ }, { "name": "_make_estimator", + "unique_name": "_make_estimator", "qname": "sklearn.ensemble._gb.BaseGradientBoosting._make_estimator", + "unique_qname": "sklearn.ensemble._gb.BaseGradientBoosting._make_estimator", "decorators": [], "parameters": [ { @@ -60168,7 +61547,9 @@ }, { "name": "_raw_predict", + "unique_name": "_raw_predict", "qname": "sklearn.ensemble._gb.BaseGradientBoosting._raw_predict", + "unique_qname": "sklearn.ensemble._gb.BaseGradientBoosting._raw_predict", "decorators": [], "parameters": [ { @@ -60200,7 +61581,9 @@ }, { "name": "_raw_predict_init", + "unique_name": "_raw_predict_init", "qname": "sklearn.ensemble._gb.BaseGradientBoosting._raw_predict_init", + "unique_qname": "sklearn.ensemble._gb.BaseGradientBoosting._raw_predict_init", "decorators": [], "parameters": [ { @@ -60232,7 +61615,9 @@ }, { "name": "_resize_state", + "unique_name": "_resize_state", "qname": "sklearn.ensemble._gb.BaseGradientBoosting._resize_state", + "unique_qname": "sklearn.ensemble._gb.BaseGradientBoosting._resize_state", "decorators": [], "parameters": [ { @@ -60254,7 +61639,9 @@ }, { "name": "_staged_raw_predict", + "unique_name": "_staged_raw_predict", "qname": "sklearn.ensemble._gb.BaseGradientBoosting._staged_raw_predict", + "unique_qname": "sklearn.ensemble._gb.BaseGradientBoosting._staged_raw_predict", "decorators": [], "parameters": [ { @@ -60286,7 +61673,9 @@ }, { "name": "_validate_y", + "unique_name": "_validate_y", "qname": "sklearn.ensemble._gb.BaseGradientBoosting._validate_y", + "unique_qname": "sklearn.ensemble._gb.BaseGradientBoosting._validate_y", "decorators": ["abstractmethod"], "parameters": [ { @@ -60328,7 +61717,9 @@ }, { "name": "_warn_mae_for_criterion", + "unique_name": "_warn_mae_for_criterion", "qname": "sklearn.ensemble._gb.BaseGradientBoosting._warn_mae_for_criterion", + "unique_qname": "sklearn.ensemble._gb.BaseGradientBoosting._warn_mae_for_criterion", "decorators": ["abstractmethod"], "parameters": [ { @@ -60350,7 +61741,9 @@ }, { "name": "apply", + "unique_name": "apply", "qname": "sklearn.ensemble._gb.BaseGradientBoosting.apply", + "unique_qname": "sklearn.ensemble._gb.BaseGradientBoosting.apply", "decorators": [], "parameters": [ { @@ -60382,7 +61775,9 @@ }, { "name": "feature_importances_", + "unique_name": "feature_importances_@getter", "qname": "sklearn.ensemble._gb.BaseGradientBoosting.feature_importances_", + "unique_qname": "sklearn.ensemble._gb.BaseGradientBoosting.feature_importances_@getter", "decorators": ["property"], "parameters": [ { @@ -60404,7 +61799,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.ensemble._gb.BaseGradientBoosting.fit", + "unique_qname": "sklearn.ensemble._gb.BaseGradientBoosting.fit", "decorators": [], "parameters": [ { @@ -60466,7 +61863,9 @@ }, { "name": "n_features_", + "unique_name": "n_features_@getter", "qname": "sklearn.ensemble._gb.BaseGradientBoosting.n_features_", + "unique_qname": "sklearn.ensemble._gb.BaseGradientBoosting.n_features_@getter", "decorators": [ "deprecated('Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead.')", "property" @@ -60491,7 +61890,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._gb.GradientBoostingClassifier.__init__", + "unique_qname": "sklearn.ensemble._gb.GradientBoostingClassifier.__init__", "decorators": [], "parameters": [ { @@ -60713,7 +62114,9 @@ }, { "name": "_validate_y", + "unique_name": "_validate_y", "qname": "sklearn.ensemble._gb.GradientBoostingClassifier._validate_y", + "unique_qname": "sklearn.ensemble._gb.GradientBoostingClassifier._validate_y", "decorators": [], "parameters": [ { @@ -60755,7 +62158,9 @@ }, { "name": "_warn_mae_for_criterion", + "unique_name": "_warn_mae_for_criterion", "qname": "sklearn.ensemble._gb.GradientBoostingClassifier._warn_mae_for_criterion", + "unique_qname": "sklearn.ensemble._gb.GradientBoostingClassifier._warn_mae_for_criterion", "decorators": [], "parameters": [ { @@ -60777,7 +62182,9 @@ }, { "name": "decision_function", + "unique_name": "decision_function", "qname": "sklearn.ensemble._gb.GradientBoostingClassifier.decision_function", + "unique_qname": "sklearn.ensemble._gb.GradientBoostingClassifier.decision_function", "decorators": [], "parameters": [ { @@ -60809,7 +62216,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.ensemble._gb.GradientBoostingClassifier.predict", + "unique_qname": "sklearn.ensemble._gb.GradientBoostingClassifier.predict", "decorators": [], "parameters": [ { @@ -60841,7 +62250,9 @@ }, { "name": "predict_log_proba", + "unique_name": "predict_log_proba", "qname": "sklearn.ensemble._gb.GradientBoostingClassifier.predict_log_proba", + "unique_qname": "sklearn.ensemble._gb.GradientBoostingClassifier.predict_log_proba", "decorators": [], "parameters": [ { @@ -60873,7 +62284,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.ensemble._gb.GradientBoostingClassifier.predict_proba", + "unique_qname": "sklearn.ensemble._gb.GradientBoostingClassifier.predict_proba", "decorators": [], "parameters": [ { @@ -60905,7 +62318,9 @@ }, { "name": "staged_decision_function", + "unique_name": "staged_decision_function", "qname": "sklearn.ensemble._gb.GradientBoostingClassifier.staged_decision_function", + "unique_qname": "sklearn.ensemble._gb.GradientBoostingClassifier.staged_decision_function", "decorators": [], "parameters": [ { @@ -60937,7 +62352,9 @@ }, { "name": "staged_predict", + "unique_name": "staged_predict", "qname": "sklearn.ensemble._gb.GradientBoostingClassifier.staged_predict", + "unique_qname": "sklearn.ensemble._gb.GradientBoostingClassifier.staged_predict", "decorators": [], "parameters": [ { @@ -60969,7 +62386,9 @@ }, { "name": "staged_predict_proba", + "unique_name": "staged_predict_proba", "qname": "sklearn.ensemble._gb.GradientBoostingClassifier.staged_predict_proba", + "unique_qname": "sklearn.ensemble._gb.GradientBoostingClassifier.staged_predict_proba", "decorators": [], "parameters": [ { @@ -61001,7 +62420,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._gb.GradientBoostingRegressor.__init__", + "unique_qname": "sklearn.ensemble._gb.GradientBoostingRegressor.__init__", "decorators": [], "parameters": [ { @@ -61020,7 +62441,7 @@ "is_public": true, "assigned_by": "NAME_ONLY", "docstring": { - "type": "{'squared_error', 'ls', 'absolute_error', 'lad', 'huber', 'quantile'}, default='squared_error'", + "type": "{'squared_error', 'absolute_error', 'huber', 'quantile'}, default='squared_error'", "description": "Loss function to be optimized. 'squared_error' refers to the squared\nerror for regression. 'absolute_error' refers to the absolute error of\nregression and is a robust loss function. 'huber' is a\ncombination of the two. 'quantile' allows quantile regression (use\n`alpha` to specify the quantile).\n\n.. deprecated:: 1.0\n The loss 'ls' was deprecated in v1.0 and will be removed in\n version 1.2. Use `loss='squared_error'` which is equivalent.\n\n.. deprecated:: 1.0\n The loss 'lad' was deprecated in v1.0 and will be removed in\n version 1.2. Use `loss='absolute_error'` which is equivalent." } }, @@ -61233,7 +62654,9 @@ }, { "name": "_validate_y", + "unique_name": "_validate_y", "qname": "sklearn.ensemble._gb.GradientBoostingRegressor._validate_y", + "unique_qname": "sklearn.ensemble._gb.GradientBoostingRegressor._validate_y", "decorators": [], "parameters": [ { @@ -61275,7 +62698,9 @@ }, { "name": "_warn_mae_for_criterion", + "unique_name": "_warn_mae_for_criterion", "qname": "sklearn.ensemble._gb.GradientBoostingRegressor._warn_mae_for_criterion", + "unique_qname": "sklearn.ensemble._gb.GradientBoostingRegressor._warn_mae_for_criterion", "decorators": [], "parameters": [ { @@ -61297,7 +62722,9 @@ }, { "name": "apply", + "unique_name": "apply", "qname": "sklearn.ensemble._gb.GradientBoostingRegressor.apply", + "unique_qname": "sklearn.ensemble._gb.GradientBoostingRegressor.apply", "decorators": [], "parameters": [ { @@ -61329,7 +62756,9 @@ }, { "name": "n_classes_", + "unique_name": "n_classes_@getter", "qname": "sklearn.ensemble._gb.GradientBoostingRegressor.n_classes_", + "unique_qname": "sklearn.ensemble._gb.GradientBoostingRegressor.n_classes_@getter", "decorators": [ "deprecated('Attribute `n_classes_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -61354,7 +62783,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.ensemble._gb.GradientBoostingRegressor.predict", + "unique_qname": "sklearn.ensemble._gb.GradientBoostingRegressor.predict", "decorators": [], "parameters": [ { @@ -61386,7 +62817,9 @@ }, { "name": "staged_predict", + "unique_name": "staged_predict", "qname": "sklearn.ensemble._gb.GradientBoostingRegressor.staged_predict", + "unique_qname": "sklearn.ensemble._gb.GradientBoostingRegressor.staged_predict", "decorators": [], "parameters": [ { @@ -61418,7 +62851,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._gb.VerboseReporter.__init__", + "unique_qname": "sklearn.ensemble._gb.VerboseReporter.__init__", "decorators": [], "parameters": [ { @@ -61450,7 +62885,9 @@ }, { "name": "init", + "unique_name": "init", "qname": "sklearn.ensemble._gb.VerboseReporter.init", + "unique_qname": "sklearn.ensemble._gb.VerboseReporter.init", "decorators": [], "parameters": [ { @@ -61492,7 +62929,9 @@ }, { "name": "update", + "unique_name": "update", "qname": "sklearn.ensemble._gb.VerboseReporter.update", + "unique_qname": "sklearn.ensemble._gb.VerboseReporter.update", "decorators": [], "parameters": [ { @@ -61534,7 +62973,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.ensemble._gb_losses.BinomialDeviance.__call__", + "unique_qname": "sklearn.ensemble._gb_losses.BinomialDeviance.__call__", "decorators": [], "parameters": [ { @@ -61586,7 +63027,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._gb_losses.BinomialDeviance.__init__", + "unique_qname": "sklearn.ensemble._gb_losses.BinomialDeviance.__init__", "decorators": [], "parameters": [ { @@ -61618,7 +63061,9 @@ }, { "name": "_raw_prediction_to_decision", + "unique_name": "_raw_prediction_to_decision", "qname": "sklearn.ensemble._gb_losses.BinomialDeviance._raw_prediction_to_decision", + "unique_qname": "sklearn.ensemble._gb_losses.BinomialDeviance._raw_prediction_to_decision", "decorators": [], "parameters": [ { @@ -61650,7 +63095,9 @@ }, { "name": "_raw_prediction_to_proba", + "unique_name": "_raw_prediction_to_proba", "qname": "sklearn.ensemble._gb_losses.BinomialDeviance._raw_prediction_to_proba", + "unique_qname": "sklearn.ensemble._gb_losses.BinomialDeviance._raw_prediction_to_proba", "decorators": [], "parameters": [ { @@ -61682,7 +63129,9 @@ }, { "name": "_update_terminal_region", + "unique_name": "_update_terminal_region", "qname": "sklearn.ensemble._gb_losses.BinomialDeviance._update_terminal_region", + "unique_qname": "sklearn.ensemble._gb_losses.BinomialDeviance._update_terminal_region", "decorators": [], "parameters": [ { @@ -61784,7 +63233,9 @@ }, { "name": "get_init_raw_predictions", + "unique_name": "get_init_raw_predictions", "qname": "sklearn.ensemble._gb_losses.BinomialDeviance.get_init_raw_predictions", + "unique_qname": "sklearn.ensemble._gb_losses.BinomialDeviance.get_init_raw_predictions", "decorators": [], "parameters": [ { @@ -61826,7 +63277,9 @@ }, { "name": "init_estimator", + "unique_name": "init_estimator", "qname": "sklearn.ensemble._gb_losses.BinomialDeviance.init_estimator", + "unique_qname": "sklearn.ensemble._gb_losses.BinomialDeviance.init_estimator", "decorators": [], "parameters": [ { @@ -61848,7 +63301,9 @@ }, { "name": "negative_gradient", + "unique_name": "negative_gradient", "qname": "sklearn.ensemble._gb_losses.BinomialDeviance.negative_gradient", + "unique_qname": "sklearn.ensemble._gb_losses.BinomialDeviance.negative_gradient", "decorators": [], "parameters": [ { @@ -61890,7 +63345,9 @@ }, { "name": "_raw_prediction_to_decision", + "unique_name": "_raw_prediction_to_decision", "qname": "sklearn.ensemble._gb_losses.ClassificationLossFunction._raw_prediction_to_decision", + "unique_qname": "sklearn.ensemble._gb_losses.ClassificationLossFunction._raw_prediction_to_decision", "decorators": ["abstractmethod"], "parameters": [ { @@ -61922,7 +63379,9 @@ }, { "name": "_raw_prediction_to_proba", + "unique_name": "_raw_prediction_to_proba", "qname": "sklearn.ensemble._gb_losses.ClassificationLossFunction._raw_prediction_to_proba", + "unique_qname": "sklearn.ensemble._gb_losses.ClassificationLossFunction._raw_prediction_to_proba", "decorators": [], "parameters": [ { @@ -61954,7 +63413,9 @@ }, { "name": "check_init_estimator", + "unique_name": "check_init_estimator", "qname": "sklearn.ensemble._gb_losses.ClassificationLossFunction.check_init_estimator", + "unique_qname": "sklearn.ensemble._gb_losses.ClassificationLossFunction.check_init_estimator", "decorators": [], "parameters": [ { @@ -61986,7 +63447,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.ensemble._gb_losses.ExponentialLoss.__call__", + "unique_qname": "sklearn.ensemble._gb_losses.ExponentialLoss.__call__", "decorators": [], "parameters": [ { @@ -62038,7 +63501,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._gb_losses.ExponentialLoss.__init__", + "unique_qname": "sklearn.ensemble._gb_losses.ExponentialLoss.__init__", "decorators": [], "parameters": [ { @@ -62070,7 +63535,9 @@ }, { "name": "_raw_prediction_to_decision", + "unique_name": "_raw_prediction_to_decision", "qname": "sklearn.ensemble._gb_losses.ExponentialLoss._raw_prediction_to_decision", + "unique_qname": "sklearn.ensemble._gb_losses.ExponentialLoss._raw_prediction_to_decision", "decorators": [], "parameters": [ { @@ -62102,7 +63569,9 @@ }, { "name": "_raw_prediction_to_proba", + "unique_name": "_raw_prediction_to_proba", "qname": "sklearn.ensemble._gb_losses.ExponentialLoss._raw_prediction_to_proba", + "unique_qname": "sklearn.ensemble._gb_losses.ExponentialLoss._raw_prediction_to_proba", "decorators": [], "parameters": [ { @@ -62134,7 +63603,9 @@ }, { "name": "_update_terminal_region", + "unique_name": "_update_terminal_region", "qname": "sklearn.ensemble._gb_losses.ExponentialLoss._update_terminal_region", + "unique_qname": "sklearn.ensemble._gb_losses.ExponentialLoss._update_terminal_region", "decorators": [], "parameters": [ { @@ -62236,7 +63707,9 @@ }, { "name": "get_init_raw_predictions", + "unique_name": "get_init_raw_predictions", "qname": "sklearn.ensemble._gb_losses.ExponentialLoss.get_init_raw_predictions", + "unique_qname": "sklearn.ensemble._gb_losses.ExponentialLoss.get_init_raw_predictions", "decorators": [], "parameters": [ { @@ -62278,7 +63751,9 @@ }, { "name": "init_estimator", + "unique_name": "init_estimator", "qname": "sklearn.ensemble._gb_losses.ExponentialLoss.init_estimator", + "unique_qname": "sklearn.ensemble._gb_losses.ExponentialLoss.init_estimator", "decorators": [], "parameters": [ { @@ -62300,7 +63775,9 @@ }, { "name": "negative_gradient", + "unique_name": "negative_gradient", "qname": "sklearn.ensemble._gb_losses.ExponentialLoss.negative_gradient", + "unique_qname": "sklearn.ensemble._gb_losses.ExponentialLoss.negative_gradient", "decorators": [], "parameters": [ { @@ -62342,7 +63819,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.ensemble._gb_losses.HuberLossFunction.__call__", + "unique_qname": "sklearn.ensemble._gb_losses.HuberLossFunction.__call__", "decorators": [], "parameters": [ { @@ -62394,7 +63873,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._gb_losses.HuberLossFunction.__init__", + "unique_qname": "sklearn.ensemble._gb_losses.HuberLossFunction.__init__", "decorators": [], "parameters": [ { @@ -62426,7 +63907,9 @@ }, { "name": "_update_terminal_region", + "unique_name": "_update_terminal_region", "qname": "sklearn.ensemble._gb_losses.HuberLossFunction._update_terminal_region", + "unique_qname": "sklearn.ensemble._gb_losses.HuberLossFunction._update_terminal_region", "decorators": [], "parameters": [ { @@ -62528,7 +64011,9 @@ }, { "name": "init_estimator", + "unique_name": "init_estimator", "qname": "sklearn.ensemble._gb_losses.HuberLossFunction.init_estimator", + "unique_qname": "sklearn.ensemble._gb_losses.HuberLossFunction.init_estimator", "decorators": [], "parameters": [ { @@ -62550,7 +64035,9 @@ }, { "name": "negative_gradient", + "unique_name": "negative_gradient", "qname": "sklearn.ensemble._gb_losses.HuberLossFunction.negative_gradient", + "unique_qname": "sklearn.ensemble._gb_losses.HuberLossFunction.negative_gradient", "decorators": [], "parameters": [ { @@ -62602,7 +64089,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.ensemble._gb_losses.LeastAbsoluteError.__call__", + "unique_qname": "sklearn.ensemble._gb_losses.LeastAbsoluteError.__call__", "decorators": [], "parameters": [ { @@ -62654,7 +64143,9 @@ }, { "name": "_update_terminal_region", + "unique_name": "_update_terminal_region", "qname": "sklearn.ensemble._gb_losses.LeastAbsoluteError._update_terminal_region", + "unique_qname": "sklearn.ensemble._gb_losses.LeastAbsoluteError._update_terminal_region", "decorators": [], "parameters": [ { @@ -62756,7 +64247,9 @@ }, { "name": "init_estimator", + "unique_name": "init_estimator", "qname": "sklearn.ensemble._gb_losses.LeastAbsoluteError.init_estimator", + "unique_qname": "sklearn.ensemble._gb_losses.LeastAbsoluteError.init_estimator", "decorators": [], "parameters": [ { @@ -62778,7 +64271,9 @@ }, { "name": "negative_gradient", + "unique_name": "negative_gradient", "qname": "sklearn.ensemble._gb_losses.LeastAbsoluteError.negative_gradient", + "unique_qname": "sklearn.ensemble._gb_losses.LeastAbsoluteError.negative_gradient", "decorators": [], "parameters": [ { @@ -62820,7 +64315,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.ensemble._gb_losses.LeastSquaresError.__call__", + "unique_qname": "sklearn.ensemble._gb_losses.LeastSquaresError.__call__", "decorators": [], "parameters": [ { @@ -62872,7 +64369,9 @@ }, { "name": "_update_terminal_region", + "unique_name": "_update_terminal_region", "qname": "sklearn.ensemble._gb_losses.LeastSquaresError._update_terminal_region", + "unique_qname": "sklearn.ensemble._gb_losses.LeastSquaresError._update_terminal_region", "decorators": [], "parameters": [ { @@ -62974,7 +64473,9 @@ }, { "name": "init_estimator", + "unique_name": "init_estimator", "qname": "sklearn.ensemble._gb_losses.LeastSquaresError.init_estimator", + "unique_qname": "sklearn.ensemble._gb_losses.LeastSquaresError.init_estimator", "decorators": [], "parameters": [ { @@ -62996,7 +64497,9 @@ }, { "name": "negative_gradient", + "unique_name": "negative_gradient", "qname": "sklearn.ensemble._gb_losses.LeastSquaresError.negative_gradient", + "unique_qname": "sklearn.ensemble._gb_losses.LeastSquaresError.negative_gradient", "decorators": [], "parameters": [ { @@ -63038,7 +64541,9 @@ }, { "name": "update_terminal_regions", + "unique_name": "update_terminal_regions", "qname": "sklearn.ensemble._gb_losses.LeastSquaresError.update_terminal_regions", + "unique_qname": "sklearn.ensemble._gb_losses.LeastSquaresError.update_terminal_regions", "decorators": [], "parameters": [ { @@ -63150,7 +64655,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.ensemble._gb_losses.LossFunction.__call__", + "unique_qname": "sklearn.ensemble._gb_losses.LossFunction.__call__", "decorators": ["abstractmethod"], "parameters": [ { @@ -63202,7 +64709,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._gb_losses.LossFunction.__init__", + "unique_qname": "sklearn.ensemble._gb_losses.LossFunction.__init__", "decorators": [], "parameters": [ { @@ -63234,7 +64743,9 @@ }, { "name": "_update_terminal_region", + "unique_name": "_update_terminal_region", "qname": "sklearn.ensemble._gb_losses.LossFunction._update_terminal_region", + "unique_qname": "sklearn.ensemble._gb_losses.LossFunction._update_terminal_region", "decorators": ["abstractmethod"], "parameters": [ { @@ -63336,7 +64847,9 @@ }, { "name": "get_init_raw_predictions", + "unique_name": "get_init_raw_predictions", "qname": "sklearn.ensemble._gb_losses.LossFunction.get_init_raw_predictions", + "unique_qname": "sklearn.ensemble._gb_losses.LossFunction.get_init_raw_predictions", "decorators": ["abstractmethod"], "parameters": [ { @@ -63378,7 +64891,9 @@ }, { "name": "init_estimator", + "unique_name": "init_estimator", "qname": "sklearn.ensemble._gb_losses.LossFunction.init_estimator", + "unique_qname": "sklearn.ensemble._gb_losses.LossFunction.init_estimator", "decorators": [], "parameters": [ { @@ -63400,7 +64915,9 @@ }, { "name": "negative_gradient", + "unique_name": "negative_gradient", "qname": "sklearn.ensemble._gb_losses.LossFunction.negative_gradient", + "unique_qname": "sklearn.ensemble._gb_losses.LossFunction.negative_gradient", "decorators": ["abstractmethod"], "parameters": [ { @@ -63442,7 +64959,9 @@ }, { "name": "update_terminal_regions", + "unique_name": "update_terminal_regions", "qname": "sklearn.ensemble._gb_losses.LossFunction.update_terminal_regions", + "unique_qname": "sklearn.ensemble._gb_losses.LossFunction.update_terminal_regions", "decorators": [], "parameters": [ { @@ -63554,7 +65073,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.ensemble._gb_losses.MultinomialDeviance.__call__", + "unique_qname": "sklearn.ensemble._gb_losses.MultinomialDeviance.__call__", "decorators": [], "parameters": [ { @@ -63606,7 +65127,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._gb_losses.MultinomialDeviance.__init__", + "unique_qname": "sklearn.ensemble._gb_losses.MultinomialDeviance.__init__", "decorators": [], "parameters": [ { @@ -63638,7 +65161,9 @@ }, { "name": "_raw_prediction_to_decision", + "unique_name": "_raw_prediction_to_decision", "qname": "sklearn.ensemble._gb_losses.MultinomialDeviance._raw_prediction_to_decision", + "unique_qname": "sklearn.ensemble._gb_losses.MultinomialDeviance._raw_prediction_to_decision", "decorators": [], "parameters": [ { @@ -63670,7 +65195,9 @@ }, { "name": "_raw_prediction_to_proba", + "unique_name": "_raw_prediction_to_proba", "qname": "sklearn.ensemble._gb_losses.MultinomialDeviance._raw_prediction_to_proba", + "unique_qname": "sklearn.ensemble._gb_losses.MultinomialDeviance._raw_prediction_to_proba", "decorators": [], "parameters": [ { @@ -63702,7 +65229,9 @@ }, { "name": "_update_terminal_region", + "unique_name": "_update_terminal_region", "qname": "sklearn.ensemble._gb_losses.MultinomialDeviance._update_terminal_region", + "unique_qname": "sklearn.ensemble._gb_losses.MultinomialDeviance._update_terminal_region", "decorators": [], "parameters": [ { @@ -63804,7 +65333,9 @@ }, { "name": "get_init_raw_predictions", + "unique_name": "get_init_raw_predictions", "qname": "sklearn.ensemble._gb_losses.MultinomialDeviance.get_init_raw_predictions", + "unique_qname": "sklearn.ensemble._gb_losses.MultinomialDeviance.get_init_raw_predictions", "decorators": [], "parameters": [ { @@ -63846,7 +65377,9 @@ }, { "name": "init_estimator", + "unique_name": "init_estimator", "qname": "sklearn.ensemble._gb_losses.MultinomialDeviance.init_estimator", + "unique_qname": "sklearn.ensemble._gb_losses.MultinomialDeviance.init_estimator", "decorators": [], "parameters": [ { @@ -63868,7 +65401,9 @@ }, { "name": "negative_gradient", + "unique_name": "negative_gradient", "qname": "sklearn.ensemble._gb_losses.MultinomialDeviance.negative_gradient", + "unique_qname": "sklearn.ensemble._gb_losses.MultinomialDeviance.negative_gradient", "decorators": [], "parameters": [ { @@ -63920,7 +65455,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.ensemble._gb_losses.QuantileLossFunction.__call__", + "unique_qname": "sklearn.ensemble._gb_losses.QuantileLossFunction.__call__", "decorators": [], "parameters": [ { @@ -63972,7 +65509,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._gb_losses.QuantileLossFunction.__init__", + "unique_qname": "sklearn.ensemble._gb_losses.QuantileLossFunction.__init__", "decorators": [], "parameters": [ { @@ -64004,7 +65543,9 @@ }, { "name": "_update_terminal_region", + "unique_name": "_update_terminal_region", "qname": "sklearn.ensemble._gb_losses.QuantileLossFunction._update_terminal_region", + "unique_qname": "sklearn.ensemble._gb_losses.QuantileLossFunction._update_terminal_region", "decorators": [], "parameters": [ { @@ -64106,7 +65647,9 @@ }, { "name": "init_estimator", + "unique_name": "init_estimator", "qname": "sklearn.ensemble._gb_losses.QuantileLossFunction.init_estimator", + "unique_qname": "sklearn.ensemble._gb_losses.QuantileLossFunction.init_estimator", "decorators": [], "parameters": [ { @@ -64128,7 +65671,9 @@ }, { "name": "negative_gradient", + "unique_name": "negative_gradient", "qname": "sklearn.ensemble._gb_losses.QuantileLossFunction.negative_gradient", + "unique_qname": "sklearn.ensemble._gb_losses.QuantileLossFunction.negative_gradient", "decorators": [], "parameters": [ { @@ -64170,7 +65715,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._gb_losses.RegressionLossFunction.__init__", + "unique_qname": "sklearn.ensemble._gb_losses.RegressionLossFunction.__init__", "decorators": [], "parameters": [ { @@ -64192,7 +65739,9 @@ }, { "name": "check_init_estimator", + "unique_name": "check_init_estimator", "qname": "sklearn.ensemble._gb_losses.RegressionLossFunction.check_init_estimator", + "unique_qname": "sklearn.ensemble._gb_losses.RegressionLossFunction.check_init_estimator", "decorators": [], "parameters": [ { @@ -64224,7 +65773,9 @@ }, { "name": "get_init_raw_predictions", + "unique_name": "get_init_raw_predictions", "qname": "sklearn.ensemble._gb_losses.RegressionLossFunction.get_init_raw_predictions", + "unique_qname": "sklearn.ensemble._gb_losses.RegressionLossFunction.get_init_raw_predictions", "decorators": [], "parameters": [ { @@ -64266,7 +65817,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._hist_gradient_boosting.binning._BinMapper.__init__", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.binning._BinMapper.__init__", "decorators": [], "parameters": [ { @@ -64348,7 +65901,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.ensemble._hist_gradient_boosting.binning._BinMapper.fit", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.binning._BinMapper.fit", "decorators": [], "parameters": [ { @@ -64390,7 +65945,9 @@ }, { "name": "make_known_categories_bitsets", + "unique_name": "make_known_categories_bitsets", "qname": "sklearn.ensemble._hist_gradient_boosting.binning._BinMapper.make_known_categories_bitsets", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.binning._BinMapper.make_known_categories_bitsets", "decorators": [], "parameters": [ { @@ -64412,7 +65969,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.ensemble._hist_gradient_boosting.binning._BinMapper.transform", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.binning._BinMapper.transform", "decorators": [], "parameters": [ { @@ -64444,7 +66003,9 @@ }, { "name": "_find_binning_thresholds", + "unique_name": "_find_binning_thresholds", "qname": "sklearn.ensemble._hist_gradient_boosting.binning._find_binning_thresholds", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.binning._find_binning_thresholds", "decorators": [], "parameters": [ { @@ -64476,7 +66037,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting.__init__", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -64678,7 +66241,9 @@ }, { "name": "_bin_data", + "unique_name": "_bin_data", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._bin_data", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._bin_data", "decorators": [], "parameters": [ { @@ -64720,7 +66285,9 @@ }, { "name": "_check_categories", + "unique_name": "_check_categories", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._check_categories", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._check_categories", "decorators": [], "parameters": [ { @@ -64752,7 +66319,9 @@ }, { "name": "_check_early_stopping_loss", + "unique_name": "_check_early_stopping_loss", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._check_early_stopping_loss", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._check_early_stopping_loss", "decorators": [], "parameters": [ { @@ -64834,7 +66403,9 @@ }, { "name": "_check_early_stopping_scorer", + "unique_name": "_check_early_stopping_scorer", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._check_early_stopping_scorer", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._check_early_stopping_scorer", "decorators": [], "parameters": [ { @@ -64916,7 +66487,9 @@ }, { "name": "_clear_state", + "unique_name": "_clear_state", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._clear_state", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._clear_state", "decorators": [], "parameters": [ { @@ -64938,7 +66511,9 @@ }, { "name": "_compute_partial_dependence_recursion", + "unique_name": "_compute_partial_dependence_recursion", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._compute_partial_dependence_recursion", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._compute_partial_dependence_recursion", "decorators": [], "parameters": [ { @@ -64980,7 +66555,9 @@ }, { "name": "_encode_y", + "unique_name": "_encode_y", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._encode_y", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._encode_y", "decorators": ["abstractmethod"], "parameters": [ { @@ -65012,7 +66589,9 @@ }, { "name": "_get_loss", + "unique_name": "_get_loss", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._get_loss", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._get_loss", "decorators": ["abstractmethod"], "parameters": [ { @@ -65054,7 +66633,9 @@ }, { "name": "_get_small_trainset", + "unique_name": "_get_small_trainset", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._get_small_trainset", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._get_small_trainset", "decorators": [], "parameters": [ { @@ -65116,7 +66697,9 @@ }, { "name": "_is_fitted", + "unique_name": "_is_fitted", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._is_fitted", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._is_fitted", "decorators": [], "parameters": [ { @@ -65138,7 +66721,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._more_tags", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._more_tags", "decorators": [], "parameters": [ { @@ -65160,7 +66745,9 @@ }, { "name": "_predict_iterations", + "unique_name": "_predict_iterations", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._predict_iterations", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._predict_iterations", "decorators": [], "parameters": [ { @@ -65232,7 +66819,9 @@ }, { "name": "_print_iteration_stats", + "unique_name": "_print_iteration_stats", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._print_iteration_stats", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._print_iteration_stats", "decorators": [], "parameters": [ { @@ -65264,7 +66853,9 @@ }, { "name": "_raw_predict", + "unique_name": "_raw_predict", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._raw_predict", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._raw_predict", "decorators": [], "parameters": [ { @@ -65306,7 +66897,9 @@ }, { "name": "_should_stop", + "unique_name": "_should_stop", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._should_stop", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._should_stop", "decorators": [], "parameters": [ { @@ -65338,7 +66931,9 @@ }, { "name": "_staged_raw_predict", + "unique_name": "_staged_raw_predict", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._staged_raw_predict", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._staged_raw_predict", "decorators": [], "parameters": [ { @@ -65370,7 +66965,9 @@ }, { "name": "_validate_parameters", + "unique_name": "_validate_parameters", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._validate_parameters", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting._validate_parameters", "decorators": [], "parameters": [ { @@ -65392,7 +66989,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting.fit", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting.fit", "decorators": [], "parameters": [ { @@ -65444,7 +67043,9 @@ }, { "name": "n_iter_", + "unique_name": "n_iter_@getter", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting.n_iter_", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.BaseHistGradientBoosting.n_iter_@getter", "decorators": ["property"], "parameters": [ { @@ -65466,7 +67067,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingClassifier.__init__", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingClassifier.__init__", "decorators": [], "parameters": [ { @@ -65668,7 +67271,9 @@ }, { "name": "_encode_y", + "unique_name": "_encode_y", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingClassifier._encode_y", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingClassifier._encode_y", "decorators": [], "parameters": [ { @@ -65700,7 +67305,9 @@ }, { "name": "_get_loss", + "unique_name": "_get_loss", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingClassifier._get_loss", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingClassifier._get_loss", "decorators": [], "parameters": [ { @@ -65742,7 +67349,9 @@ }, { "name": "decision_function", + "unique_name": "decision_function", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingClassifier.decision_function", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingClassifier.decision_function", "decorators": [], "parameters": [ { @@ -65774,7 +67383,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingClassifier.predict", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingClassifier.predict", "decorators": [], "parameters": [ { @@ -65806,7 +67417,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingClassifier.predict_proba", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingClassifier.predict_proba", "decorators": [], "parameters": [ { @@ -65838,7 +67451,9 @@ }, { "name": "staged_decision_function", + "unique_name": "staged_decision_function", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingClassifier.staged_decision_function", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingClassifier.staged_decision_function", "decorators": [], "parameters": [ { @@ -65870,7 +67485,9 @@ }, { "name": "staged_predict", + "unique_name": "staged_predict", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingClassifier.staged_predict", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingClassifier.staged_predict", "decorators": [], "parameters": [ { @@ -65902,7 +67519,9 @@ }, { "name": "staged_predict_proba", + "unique_name": "staged_predict_proba", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingClassifier.staged_predict_proba", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingClassifier.staged_predict_proba", "decorators": [], "parameters": [ { @@ -65934,7 +67553,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingRegressor.__init__", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingRegressor.__init__", "decorators": [], "parameters": [ { @@ -65953,8 +67574,8 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "{'squared_error', 'least_squares', 'absolute_error', 'least_absolute_deviation', 'poisson'}, default='squared_error'", - "description": "The loss function to use in the boosting process. Note that the\n\"least squares\" and \"poisson\" losses actually implement\n\"half least squares loss\" and \"half poisson deviance\" to simplify the\ncomputation of the gradient. Furthermore, \"poisson\" loss internally\nuses a log-link and requires ``y >= 0``.\n\n.. versionchanged:: 0.23\n Added option 'poisson'.\n\n.. deprecated:: 1.0\n The loss 'least_squares' was deprecated in v1.0 and will be removed\n in version 1.2. Use `loss='squared_error'` which is equivalent.\n\n.. deprecated:: 1.0\n The loss 'least_absolute_deviation' was deprecated in v1.0 and will\n be removed in version 1.2. Use `loss='absolute_error'` which is\n equivalent." + "type": "{'squared_error', 'absolute_error', 'poisson'}, default='squared_error'", + "description": "The loss function to use in the boosting process. Note that the\n\"squared error\" and \"poisson\" losses actually implement\n\"half least squares loss\" and \"half poisson deviance\" to simplify the\ncomputation of the gradient. Furthermore, \"poisson\" loss internally\nuses a log-link and requires ``y >= 0``.\n\n.. versionchanged:: 0.23\n Added option 'poisson'.\n\n.. deprecated:: 1.0\n The loss 'least_squares' was deprecated in v1.0 and will be removed\n in version 1.2. Use `loss='squared_error'` which is equivalent.\n\n.. deprecated:: 1.0\n The loss 'least_absolute_deviation' was deprecated in v1.0 and will\n be removed in version 1.2. Use `loss='absolute_error'` which is\n equivalent." } }, { @@ -66136,7 +67757,9 @@ }, { "name": "_encode_y", + "unique_name": "_encode_y", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingRegressor._encode_y", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingRegressor._encode_y", "decorators": [], "parameters": [ { @@ -66168,7 +67791,9 @@ }, { "name": "_get_loss", + "unique_name": "_get_loss", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingRegressor._get_loss", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingRegressor._get_loss", "decorators": [], "parameters": [ { @@ -66210,7 +67835,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingRegressor.predict", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingRegressor.predict", "decorators": [], "parameters": [ { @@ -66242,7 +67869,9 @@ }, { "name": "staged_predict", + "unique_name": "staged_predict", "qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingRegressor.staged_predict", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.gradient_boosting.HistGradientBoostingRegressor.staged_predict", "decorators": [], "parameters": [ { @@ -66274,7 +67903,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeGrower.__init__", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeGrower.__init__", "decorators": [], "parameters": [ { @@ -66456,7 +68087,9 @@ }, { "name": "_apply_shrinkage", + "unique_name": "_apply_shrinkage", "qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeGrower._apply_shrinkage", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeGrower._apply_shrinkage", "decorators": [], "parameters": [ { @@ -66478,7 +68111,9 @@ }, { "name": "_compute_best_split_and_push", + "unique_name": "_compute_best_split_and_push", "qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeGrower._compute_best_split_and_push", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeGrower._compute_best_split_and_push", "decorators": [], "parameters": [ { @@ -66510,7 +68145,9 @@ }, { "name": "_finalize_leaf", + "unique_name": "_finalize_leaf", "qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeGrower._finalize_leaf", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeGrower._finalize_leaf", "decorators": [], "parameters": [ { @@ -66542,7 +68179,9 @@ }, { "name": "_finalize_splittable_nodes", + "unique_name": "_finalize_splittable_nodes", "qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeGrower._finalize_splittable_nodes", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeGrower._finalize_splittable_nodes", "decorators": [], "parameters": [ { @@ -66564,7 +68203,9 @@ }, { "name": "_intilialize_root", + "unique_name": "_intilialize_root", "qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeGrower._intilialize_root", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeGrower._intilialize_root", "decorators": [], "parameters": [ { @@ -66616,7 +68257,9 @@ }, { "name": "_validate_parameters", + "unique_name": "_validate_parameters", "qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeGrower._validate_parameters", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeGrower._validate_parameters", "decorators": [], "parameters": [ { @@ -66708,7 +68351,9 @@ }, { "name": "grow", + "unique_name": "grow", "qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeGrower.grow", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeGrower.grow", "decorators": [], "parameters": [ { @@ -66730,7 +68375,9 @@ }, { "name": "make_predictor", + "unique_name": "make_predictor", "qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeGrower.make_predictor", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeGrower.make_predictor", "decorators": [], "parameters": [ { @@ -66762,7 +68409,9 @@ }, { "name": "split_next", + "unique_name": "split_next", "qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeGrower.split_next", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeGrower.split_next", "decorators": [], "parameters": [ { @@ -66784,7 +68433,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeNode.__init__", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeNode.__init__", "decorators": [], "parameters": [ { @@ -66856,7 +68507,9 @@ }, { "name": "__lt__", + "unique_name": "__lt__", "qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeNode.__lt__", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeNode.__lt__", "decorators": [], "parameters": [ { @@ -66888,7 +68541,9 @@ }, { "name": "set_children_bounds", + "unique_name": "set_children_bounds", "qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeNode.set_children_bounds", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.grower.TreeNode.set_children_bounds", "decorators": [], "parameters": [ { @@ -66930,7 +68585,9 @@ }, { "name": "_fill_predictor_arrays", + "unique_name": "_fill_predictor_arrays", "qname": "sklearn.ensemble._hist_gradient_boosting.grower._fill_predictor_arrays", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.grower._fill_predictor_arrays", "decorators": [], "parameters": [ { @@ -67022,7 +68679,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.BaseLoss.__call__", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.BaseLoss.__call__", "decorators": [], "parameters": [ { @@ -67074,7 +68733,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.BaseLoss.__init__", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.BaseLoss.__init__", "decorators": [], "parameters": [ { @@ -67116,7 +68777,9 @@ }, { "name": "get_baseline_prediction", + "unique_name": "get_baseline_prediction", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.BaseLoss.get_baseline_prediction", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.BaseLoss.get_baseline_prediction", "decorators": ["abstractmethod"], "parameters": [ { @@ -67168,7 +68831,9 @@ }, { "name": "init_gradients_and_hessians", + "unique_name": "init_gradients_and_hessians", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.BaseLoss.init_gradients_and_hessians", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.BaseLoss.init_gradients_and_hessians", "decorators": [], "parameters": [ { @@ -67220,7 +68885,9 @@ }, { "name": "pointwise_loss", + "unique_name": "pointwise_loss", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.BaseLoss.pointwise_loss", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.BaseLoss.pointwise_loss", "decorators": ["abstractmethod"], "parameters": [ { @@ -67262,7 +68929,9 @@ }, { "name": "update_gradients_and_hessians", + "unique_name": "update_gradients_and_hessians", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.BaseLoss.update_gradients_and_hessians", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.BaseLoss.update_gradients_and_hessians", "decorators": ["abstractmethod"], "parameters": [ { @@ -67334,7 +69003,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.BinaryCrossEntropy.__init__", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.BinaryCrossEntropy.__init__", "decorators": [], "parameters": [ { @@ -67376,7 +69047,9 @@ }, { "name": "get_baseline_prediction", + "unique_name": "get_baseline_prediction", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.BinaryCrossEntropy.get_baseline_prediction", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.BinaryCrossEntropy.get_baseline_prediction", "decorators": [], "parameters": [ { @@ -67428,7 +69101,9 @@ }, { "name": "pointwise_loss", + "unique_name": "pointwise_loss", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.BinaryCrossEntropy.pointwise_loss", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.BinaryCrossEntropy.pointwise_loss", "decorators": [], "parameters": [ { @@ -67470,7 +69145,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.BinaryCrossEntropy.predict_proba", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.BinaryCrossEntropy.predict_proba", "decorators": [], "parameters": [ { @@ -67502,7 +69179,9 @@ }, { "name": "update_gradients_and_hessians", + "unique_name": "update_gradients_and_hessians", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.BinaryCrossEntropy.update_gradients_and_hessians", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.BinaryCrossEntropy.update_gradients_and_hessians", "decorators": [], "parameters": [ { @@ -67574,7 +69253,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.CategoricalCrossEntropy.__init__", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.CategoricalCrossEntropy.__init__", "decorators": [], "parameters": [ { @@ -67616,7 +69297,9 @@ }, { "name": "get_baseline_prediction", + "unique_name": "get_baseline_prediction", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.CategoricalCrossEntropy.get_baseline_prediction", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.CategoricalCrossEntropy.get_baseline_prediction", "decorators": [], "parameters": [ { @@ -67668,7 +69351,9 @@ }, { "name": "pointwise_loss", + "unique_name": "pointwise_loss", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.CategoricalCrossEntropy.pointwise_loss", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.CategoricalCrossEntropy.pointwise_loss", "decorators": [], "parameters": [ { @@ -67710,7 +69395,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.CategoricalCrossEntropy.predict_proba", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.CategoricalCrossEntropy.predict_proba", "decorators": [], "parameters": [ { @@ -67742,7 +69429,9 @@ }, { "name": "update_gradients_and_hessians", + "unique_name": "update_gradients_and_hessians", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.CategoricalCrossEntropy.update_gradients_and_hessians", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.CategoricalCrossEntropy.update_gradients_and_hessians", "decorators": [], "parameters": [ { @@ -67814,7 +69503,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.LeastAbsoluteDeviation.__init__", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.LeastAbsoluteDeviation.__init__", "decorators": [], "parameters": [ { @@ -67856,7 +69547,9 @@ }, { "name": "get_baseline_prediction", + "unique_name": "get_baseline_prediction", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.LeastAbsoluteDeviation.get_baseline_prediction", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.LeastAbsoluteDeviation.get_baseline_prediction", "decorators": [], "parameters": [ { @@ -67908,7 +69601,9 @@ }, { "name": "inverse_link_function", + "unique_name": "inverse_link_function", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.LeastAbsoluteDeviation.inverse_link_function", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.LeastAbsoluteDeviation.inverse_link_function", "decorators": ["staticmethod"], "parameters": [ { @@ -67930,7 +69625,9 @@ }, { "name": "pointwise_loss", + "unique_name": "pointwise_loss", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.LeastAbsoluteDeviation.pointwise_loss", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.LeastAbsoluteDeviation.pointwise_loss", "decorators": [], "parameters": [ { @@ -67972,7 +69669,9 @@ }, { "name": "update_gradients_and_hessians", + "unique_name": "update_gradients_and_hessians", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.LeastAbsoluteDeviation.update_gradients_and_hessians", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.LeastAbsoluteDeviation.update_gradients_and_hessians", "decorators": [], "parameters": [ { @@ -68044,7 +69743,9 @@ }, { "name": "update_leaves_values", + "unique_name": "update_leaves_values", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.LeastAbsoluteDeviation.update_leaves_values", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.LeastAbsoluteDeviation.update_leaves_values", "decorators": [], "parameters": [ { @@ -68106,7 +69807,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.LeastSquares.__init__", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.LeastSquares.__init__", "decorators": [], "parameters": [ { @@ -68148,7 +69851,9 @@ }, { "name": "get_baseline_prediction", + "unique_name": "get_baseline_prediction", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.LeastSquares.get_baseline_prediction", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.LeastSquares.get_baseline_prediction", "decorators": [], "parameters": [ { @@ -68200,7 +69905,9 @@ }, { "name": "inverse_link_function", + "unique_name": "inverse_link_function", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.LeastSquares.inverse_link_function", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.LeastSquares.inverse_link_function", "decorators": ["staticmethod"], "parameters": [ { @@ -68222,7 +69929,9 @@ }, { "name": "pointwise_loss", + "unique_name": "pointwise_loss", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.LeastSquares.pointwise_loss", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.LeastSquares.pointwise_loss", "decorators": [], "parameters": [ { @@ -68264,7 +69973,9 @@ }, { "name": "update_gradients_and_hessians", + "unique_name": "update_gradients_and_hessians", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.LeastSquares.update_gradients_and_hessians", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.LeastSquares.update_gradients_and_hessians", "decorators": [], "parameters": [ { @@ -68336,7 +70047,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.Poisson.__init__", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.Poisson.__init__", "decorators": [], "parameters": [ { @@ -68378,7 +70091,9 @@ }, { "name": "get_baseline_prediction", + "unique_name": "get_baseline_prediction", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.Poisson.get_baseline_prediction", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.Poisson.get_baseline_prediction", "decorators": [], "parameters": [ { @@ -68430,7 +70145,9 @@ }, { "name": "pointwise_loss", + "unique_name": "pointwise_loss", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.Poisson.pointwise_loss", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.Poisson.pointwise_loss", "decorators": [], "parameters": [ { @@ -68472,7 +70189,9 @@ }, { "name": "update_gradients_and_hessians", + "unique_name": "update_gradients_and_hessians", "qname": "sklearn.ensemble._hist_gradient_boosting.loss.Poisson.update_gradients_and_hessians", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.loss.Poisson.update_gradients_and_hessians", "decorators": [], "parameters": [ { @@ -68544,7 +70263,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._hist_gradient_boosting.predictor.TreePredictor.__init__", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.predictor.TreePredictor.__init__", "decorators": [], "parameters": [ { @@ -68596,7 +70317,9 @@ }, { "name": "compute_partial_dependence", + "unique_name": "compute_partial_dependence", "qname": "sklearn.ensemble._hist_gradient_boosting.predictor.TreePredictor.compute_partial_dependence", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.predictor.TreePredictor.compute_partial_dependence", "decorators": [], "parameters": [ { @@ -68648,7 +70371,9 @@ }, { "name": "get_max_depth", + "unique_name": "get_max_depth", "qname": "sklearn.ensemble._hist_gradient_boosting.predictor.TreePredictor.get_max_depth", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.predictor.TreePredictor.get_max_depth", "decorators": [], "parameters": [ { @@ -68670,7 +70395,9 @@ }, { "name": "get_n_leaf_nodes", + "unique_name": "get_n_leaf_nodes", "qname": "sklearn.ensemble._hist_gradient_boosting.predictor.TreePredictor.get_n_leaf_nodes", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.predictor.TreePredictor.get_n_leaf_nodes", "decorators": [], "parameters": [ { @@ -68692,7 +70419,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.ensemble._hist_gradient_boosting.predictor.TreePredictor.predict", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.predictor.TreePredictor.predict", "decorators": [], "parameters": [ { @@ -68754,7 +70483,9 @@ }, { "name": "predict_binned", + "unique_name": "predict_binned", "qname": "sklearn.ensemble._hist_gradient_boosting.predictor.TreePredictor.predict_binned", + "unique_qname": "sklearn.ensemble._hist_gradient_boosting.predictor.TreePredictor.predict_binned", "decorators": [], "parameters": [ { @@ -68806,7 +70537,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._iforest.IsolationForest.__init__", + "unique_qname": "sklearn.ensemble._iforest.IsolationForest.__init__", "decorators": [], "parameters": [ { @@ -68918,7 +70651,9 @@ }, { "name": "_compute_chunked_score_samples", + "unique_name": "_compute_chunked_score_samples", "qname": "sklearn.ensemble._iforest.IsolationForest._compute_chunked_score_samples", + "unique_qname": "sklearn.ensemble._iforest.IsolationForest._compute_chunked_score_samples", "decorators": [], "parameters": [ { @@ -68950,7 +70685,9 @@ }, { "name": "_compute_score_samples", + "unique_name": "_compute_score_samples", "qname": "sklearn.ensemble._iforest.IsolationForest._compute_score_samples", + "unique_qname": "sklearn.ensemble._iforest.IsolationForest._compute_score_samples", "decorators": [], "parameters": [ { @@ -68992,7 +70729,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.ensemble._iforest.IsolationForest._more_tags", + "unique_qname": "sklearn.ensemble._iforest.IsolationForest._more_tags", "decorators": [], "parameters": [ { @@ -69014,7 +70753,9 @@ }, { "name": "_parallel_args", + "unique_name": "_parallel_args", "qname": "sklearn.ensemble._iforest.IsolationForest._parallel_args", + "unique_qname": "sklearn.ensemble._iforest.IsolationForest._parallel_args", "decorators": [], "parameters": [ { @@ -69036,7 +70777,9 @@ }, { "name": "_set_oob_score", + "unique_name": "_set_oob_score", "qname": "sklearn.ensemble._iforest.IsolationForest._set_oob_score", + "unique_qname": "sklearn.ensemble._iforest.IsolationForest._set_oob_score", "decorators": [], "parameters": [ { @@ -69078,7 +70821,9 @@ }, { "name": "decision_function", + "unique_name": "decision_function", "qname": "sklearn.ensemble._iforest.IsolationForest.decision_function", + "unique_qname": "sklearn.ensemble._iforest.IsolationForest.decision_function", "decorators": [], "parameters": [ { @@ -69110,7 +70855,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.ensemble._iforest.IsolationForest.fit", + "unique_qname": "sklearn.ensemble._iforest.IsolationForest.fit", "decorators": [], "parameters": [ { @@ -69162,7 +70909,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.ensemble._iforest.IsolationForest.predict", + "unique_qname": "sklearn.ensemble._iforest.IsolationForest.predict", "decorators": [], "parameters": [ { @@ -69190,11 +70939,13 @@ "is_public": true, "description": "Predict if a particular sample is an outlier or not.", "docstring": "Predict if a particular sample is an outlier or not.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n The input samples. Internally, it will be converted to\n ``dtype=np.float32`` and if a sparse matrix is provided\n to a sparse ``csr_matrix``.\n\nReturns\n-------\nis_inlier : ndarray of shape (n_samples,)\n For each observation, tells whether or not (+1 or -1) it should\n be considered as an inlier according to the fitted model.", - "source_code": "\ndef predict(self, X):\n \"\"\"\n Predict if a particular sample is an outlier or not.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The input samples. Internally, it will be converted to\n ``dtype=np.float32`` and if a sparse matrix is provided\n to a sparse ``csr_matrix``.\n\n Returns\n -------\n is_inlier : ndarray of shape (n_samples,)\n For each observation, tells whether or not (+1 or -1) it should\n be considered as an inlier according to the fitted model.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse='csr', reset=False)\n is_inlier = np.ones(X.shape[0], dtype=int)\n is_inlier[self.decision_function(X) < 0] = -1\n return is_inlier" + "source_code": "\ndef predict(self, X):\n \"\"\"\n Predict if a particular sample is an outlier or not.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The input samples. Internally, it will be converted to\n ``dtype=np.float32`` and if a sparse matrix is provided\n to a sparse ``csr_matrix``.\n\n Returns\n -------\n is_inlier : ndarray of shape (n_samples,)\n For each observation, tells whether or not (+1 or -1) it should\n be considered as an inlier according to the fitted model.\n \"\"\"\n check_is_fitted(self)\n decision_func = self.decision_function(X)\n is_inlier = np.ones_like(decision_func, dtype=int)\n is_inlier[decision_func < 0] = -1\n return is_inlier" }, { "name": "score_samples", + "unique_name": "score_samples", "qname": "sklearn.ensemble._iforest.IsolationForest.score_samples", + "unique_qname": "sklearn.ensemble._iforest.IsolationForest.score_samples", "decorators": [], "parameters": [ { @@ -69226,7 +70977,9 @@ }, { "name": "_average_path_length", + "unique_name": "_average_path_length", "qname": "sklearn.ensemble._iforest._average_path_length", + "unique_qname": "sklearn.ensemble._iforest._average_path_length", "decorators": [], "parameters": [ { @@ -69248,7 +71001,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._stacking.StackingClassifier.__init__", + "unique_qname": "sklearn.ensemble._stacking.StackingClassifier.__init__", "decorators": [], "parameters": [ { @@ -69340,7 +71095,9 @@ }, { "name": "_sk_visual_block_", + "unique_name": "_sk_visual_block_", "qname": "sklearn.ensemble._stacking.StackingClassifier._sk_visual_block_", + "unique_qname": "sklearn.ensemble._stacking.StackingClassifier._sk_visual_block_", "decorators": [], "parameters": [ { @@ -69362,7 +71119,9 @@ }, { "name": "_validate_final_estimator", + "unique_name": "_validate_final_estimator", "qname": "sklearn.ensemble._stacking.StackingClassifier._validate_final_estimator", + "unique_qname": "sklearn.ensemble._stacking.StackingClassifier._validate_final_estimator", "decorators": [], "parameters": [ { @@ -69384,7 +71143,9 @@ }, { "name": "decision_function", + "unique_name": "decision_function", "qname": "sklearn.ensemble._stacking.StackingClassifier.decision_function", + "unique_qname": "sklearn.ensemble._stacking.StackingClassifier.decision_function", "decorators": [ "if_delegate_has_method(delegate='final_estimator_')" ], @@ -69412,13 +71173,15 @@ ], "results": [], "is_public": true, - "description": "Predict decision function for samples in X using `final_estimator_.decision_function`.", - "docstring": "Predict decision function for samples in X using\n`final_estimator_.decision_function`.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\nReturns\n-------\ndecisions : ndarray of shape (n_samples,), (n_samples, n_classes), or (n_samples, n_classes * (n_classes-1) / 2)\n The decision function computed the final estimator.", - "source_code": "\n@if_delegate_has_method(delegate='final_estimator_')\ndef decision_function(self, X):\n \"\"\"Predict decision function for samples in X using\n `final_estimator_.decision_function`.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n Returns\n -------\n decisions : ndarray of shape (n_samples,), (n_samples, n_classes), or (n_samples, n_classes * (n_classes-1) / 2)\n The decision function computed the final estimator.\n \"\"\"\n check_is_fitted(self)\n return self.final_estimator_.decision_function(self.transform(X))" + "description": "Decision function for samples in `X` using the final estimator.", + "docstring": "Decision function for samples in `X` using the final estimator.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\nReturns\n-------\ndecisions : ndarray of shape (n_samples,), (n_samples, n_classes), or (n_samples, n_classes * (n_classes-1) / 2)\n The decision function computed the final estimator.", + "source_code": "\n@if_delegate_has_method(delegate='final_estimator_')\ndef decision_function(self, X):\n \"\"\"Decision function for samples in `X` using the final estimator.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n Returns\n -------\n decisions : ndarray of shape (n_samples,), (n_samples, n_classes), or (n_samples, n_classes * (n_classes-1) / 2)\n The decision function computed the final estimator.\n \"\"\"\n check_is_fitted(self)\n return self.final_estimator_.decision_function(self.transform(X))" }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.ensemble._stacking.StackingClassifier.fit", + "unique_qname": "sklearn.ensemble._stacking.StackingClassifier.fit", "decorators": [], "parameters": [ { @@ -69465,12 +71228,14 @@ "results": [], "is_public": true, "description": "Fit the estimators.", - "docstring": "Fit the estimators.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\ny : array-like of shape (n_samples,)\n Target values.\n\nsample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n Note that this is supported only if all underlying estimators\n support sample weights.\n\nReturns\n-------\nself : object", - "source_code": "\ndef fit(self, X, y, sample_weight=None):\n \"\"\"Fit the estimators.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target values.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n Note that this is supported only if all underlying estimators\n support sample weights.\n\n Returns\n -------\n self : object\n \"\"\"\n check_classification_targets(y)\n self._le = LabelEncoder().fit(y)\n self.classes_ = self._le.classes_\n return super().fit(X, self._le.transform(y), sample_weight)" + "docstring": "Fit the estimators.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\ny : array-like of shape (n_samples,)\n Target values.\n\nsample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n Note that this is supported only if all underlying estimators\n support sample weights.\n\nReturns\n-------\nself : object\n Returns a fitted instance of estimator.", + "source_code": "\ndef fit(self, X, y, sample_weight=None):\n \"\"\"Fit the estimators.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target values.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights. If None, then samples are equally weighted.\n Note that this is supported only if all underlying estimators\n support sample weights.\n\n Returns\n -------\n self : object\n Returns a fitted instance of estimator.\n \"\"\"\n check_classification_targets(y)\n self._le = LabelEncoder().fit(y)\n self.classes_ = self._le.classes_\n return super().fit(X, self._le.transform(y), sample_weight)" }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.ensemble._stacking.StackingClassifier.predict", + "unique_qname": "sklearn.ensemble._stacking.StackingClassifier.predict", "decorators": [ "if_delegate_has_method(delegate='final_estimator_')" ], @@ -69504,7 +71269,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.ensemble._stacking.StackingClassifier.predict_proba", + "unique_qname": "sklearn.ensemble._stacking.StackingClassifier.predict_proba", "decorators": [ "if_delegate_has_method(delegate='final_estimator_')" ], @@ -69532,13 +71299,15 @@ ], "results": [], "is_public": true, - "description": "Predict class probabilities for X using `final_estimator_.predict_proba`.", - "docstring": "Predict class probabilities for X using\n`final_estimator_.predict_proba`.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\nReturns\n-------\nprobabilities : ndarray of shape (n_samples, n_classes) or list of ndarray of shape (n_output,)\n The class probabilities of the input samples.", - "source_code": "\n@if_delegate_has_method(delegate='final_estimator_')\ndef predict_proba(self, X):\n \"\"\"Predict class probabilities for X using\n `final_estimator_.predict_proba`.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n Returns\n -------\n probabilities : ndarray of shape (n_samples, n_classes) or list of ndarray of shape (n_output,)\n The class probabilities of the input samples.\n \"\"\"\n check_is_fitted(self)\n return self.final_estimator_.predict_proba(self.transform(X))" + "description": "Predict class probabilities for `X` using the final estimator.", + "docstring": "Predict class probabilities for `X` using the final estimator.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\nReturns\n-------\nprobabilities : ndarray of shape (n_samples, n_classes) or list of ndarray of shape (n_output,)\n The class probabilities of the input samples.", + "source_code": "\n@if_delegate_has_method(delegate='final_estimator_')\ndef predict_proba(self, X):\n \"\"\"Predict class probabilities for `X` using the final estimator.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n Returns\n -------\n probabilities : ndarray of shape (n_samples, n_classes) or list of ndarray of shape (n_output,)\n The class probabilities of the input samples.\n \"\"\"\n check_is_fitted(self)\n return self.final_estimator_.predict_proba(self.transform(X))" }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.ensemble._stacking.StackingClassifier.transform", + "unique_qname": "sklearn.ensemble._stacking.StackingClassifier.transform", "decorators": [], "parameters": [ { @@ -69570,7 +71339,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._stacking.StackingRegressor.__init__", + "unique_qname": "sklearn.ensemble._stacking.StackingRegressor.__init__", "decorators": [], "parameters": [ { @@ -69652,7 +71423,9 @@ }, { "name": "_sk_visual_block_", + "unique_name": "_sk_visual_block_", "qname": "sklearn.ensemble._stacking.StackingRegressor._sk_visual_block_", + "unique_qname": "sklearn.ensemble._stacking.StackingRegressor._sk_visual_block_", "decorators": [], "parameters": [ { @@ -69674,7 +71447,9 @@ }, { "name": "_validate_final_estimator", + "unique_name": "_validate_final_estimator", "qname": "sklearn.ensemble._stacking.StackingRegressor._validate_final_estimator", + "unique_qname": "sklearn.ensemble._stacking.StackingRegressor._validate_final_estimator", "decorators": [], "parameters": [ { @@ -69696,7 +71471,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.ensemble._stacking.StackingRegressor.fit", + "unique_qname": "sklearn.ensemble._stacking.StackingRegressor.fit", "decorators": [], "parameters": [ { @@ -69748,7 +71525,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.ensemble._stacking.StackingRegressor.transform", + "unique_qname": "sklearn.ensemble._stacking.StackingRegressor.transform", "decorators": [], "parameters": [ { @@ -69780,7 +71559,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._stacking._BaseStacking.__init__", + "unique_qname": "sklearn.ensemble._stacking._BaseStacking.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -69872,7 +71653,9 @@ }, { "name": "_clone_final_estimator", + "unique_name": "_clone_final_estimator", "qname": "sklearn.ensemble._stacking._BaseStacking._clone_final_estimator", + "unique_qname": "sklearn.ensemble._stacking._BaseStacking._clone_final_estimator", "decorators": [], "parameters": [ { @@ -69904,7 +71687,9 @@ }, { "name": "_concatenate_predictions", + "unique_name": "_concatenate_predictions", "qname": "sklearn.ensemble._stacking._BaseStacking._concatenate_predictions", + "unique_qname": "sklearn.ensemble._stacking._BaseStacking._concatenate_predictions", "decorators": [], "parameters": [ { @@ -69946,7 +71731,9 @@ }, { "name": "_method_name", + "unique_name": "_method_name", "qname": "sklearn.ensemble._stacking._BaseStacking._method_name", + "unique_qname": "sklearn.ensemble._stacking._BaseStacking._method_name", "decorators": ["staticmethod"], "parameters": [ { @@ -69988,7 +71775,9 @@ }, { "name": "_sk_visual_block_", + "unique_name": "_sk_visual_block_", "qname": "sklearn.ensemble._stacking._BaseStacking._sk_visual_block_", + "unique_qname": "sklearn.ensemble._stacking._BaseStacking._sk_visual_block_", "decorators": [], "parameters": [ { @@ -70020,7 +71809,9 @@ }, { "name": "_transform", + "unique_name": "_transform", "qname": "sklearn.ensemble._stacking._BaseStacking._transform", + "unique_qname": "sklearn.ensemble._stacking._BaseStacking._transform", "decorators": [], "parameters": [ { @@ -70052,7 +71843,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.ensemble._stacking._BaseStacking.fit", + "unique_qname": "sklearn.ensemble._stacking._BaseStacking.fit", "decorators": [], "parameters": [ { @@ -70104,7 +71897,9 @@ }, { "name": "n_features_in_", + "unique_name": "n_features_in_@getter", "qname": "sklearn.ensemble._stacking._BaseStacking.n_features_in_", + "unique_qname": "sklearn.ensemble._stacking._BaseStacking.n_features_in_@getter", "decorators": ["property"], "parameters": [ { @@ -70126,7 +71921,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.ensemble._stacking._BaseStacking.predict", + "unique_qname": "sklearn.ensemble._stacking._BaseStacking.predict", "decorators": [ "if_delegate_has_method(delegate='final_estimator_')" ], @@ -70160,7 +71957,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._voting.VotingClassifier.__init__", + "unique_qname": "sklearn.ensemble._voting.VotingClassifier.__init__", "decorators": [], "parameters": [ { @@ -70242,7 +72041,9 @@ }, { "name": "_check_voting", + "unique_name": "_check_voting", "qname": "sklearn.ensemble._voting.VotingClassifier._check_voting", + "unique_qname": "sklearn.ensemble._voting.VotingClassifier._check_voting", "decorators": [], "parameters": [ { @@ -70264,7 +72065,9 @@ }, { "name": "_collect_probas", + "unique_name": "_collect_probas", "qname": "sklearn.ensemble._voting.VotingClassifier._collect_probas", + "unique_qname": "sklearn.ensemble._voting.VotingClassifier._collect_probas", "decorators": [], "parameters": [ { @@ -70296,7 +72099,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.ensemble._voting.VotingClassifier.fit", + "unique_qname": "sklearn.ensemble._voting.VotingClassifier.fit", "decorators": [], "parameters": [ { @@ -70348,7 +72153,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.ensemble._voting.VotingClassifier.predict", + "unique_qname": "sklearn.ensemble._voting.VotingClassifier.predict", "decorators": [], "parameters": [ { @@ -70380,7 +72187,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.ensemble._voting.VotingClassifier.predict_proba", + "unique_qname": "sklearn.ensemble._voting.VotingClassifier.predict_proba", "decorators": ["available_if(_check_voting)"], "parameters": [ { @@ -70412,7 +72221,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.ensemble._voting.VotingClassifier.transform", + "unique_qname": "sklearn.ensemble._voting.VotingClassifier.transform", "decorators": [], "parameters": [ { @@ -70444,7 +72255,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._voting.VotingRegressor.__init__", + "unique_qname": "sklearn.ensemble._voting.VotingRegressor.__init__", "decorators": [], "parameters": [ { @@ -70506,7 +72319,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.ensemble._voting.VotingRegressor.fit", + "unique_qname": "sklearn.ensemble._voting.VotingRegressor.fit", "decorators": [], "parameters": [ { @@ -70558,7 +72373,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.ensemble._voting.VotingRegressor.predict", + "unique_qname": "sklearn.ensemble._voting.VotingRegressor.predict", "decorators": [], "parameters": [ { @@ -70590,7 +72407,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.ensemble._voting.VotingRegressor.transform", + "unique_qname": "sklearn.ensemble._voting.VotingRegressor.transform", "decorators": [], "parameters": [ { @@ -70622,7 +72441,9 @@ }, { "name": "_log_message", + "unique_name": "_log_message", "qname": "sklearn.ensemble._voting._BaseVoting._log_message", + "unique_qname": "sklearn.ensemble._voting._BaseVoting._log_message", "decorators": [], "parameters": [ { @@ -70674,7 +72495,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.ensemble._voting._BaseVoting._more_tags", + "unique_qname": "sklearn.ensemble._voting._BaseVoting._more_tags", "decorators": [], "parameters": [ { @@ -70696,7 +72519,9 @@ }, { "name": "_predict", + "unique_name": "_predict", "qname": "sklearn.ensemble._voting._BaseVoting._predict", + "unique_qname": "sklearn.ensemble._voting._BaseVoting._predict", "decorators": [], "parameters": [ { @@ -70728,7 +72553,9 @@ }, { "name": "_sk_visual_block_", + "unique_name": "_sk_visual_block_", "qname": "sklearn.ensemble._voting._BaseVoting._sk_visual_block_", + "unique_qname": "sklearn.ensemble._voting._BaseVoting._sk_visual_block_", "decorators": [], "parameters": [ { @@ -70750,7 +72577,9 @@ }, { "name": "_weights_not_none", + "unique_name": "_weights_not_none@getter", "qname": "sklearn.ensemble._voting._BaseVoting._weights_not_none", + "unique_qname": "sklearn.ensemble._voting._BaseVoting._weights_not_none@getter", "decorators": ["property"], "parameters": [ { @@ -70772,7 +72601,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.ensemble._voting._BaseVoting.fit", + "unique_qname": "sklearn.ensemble._voting._BaseVoting.fit", "decorators": ["abstractmethod"], "parameters": [ { @@ -70824,7 +72655,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.ensemble._voting._BaseVoting.fit_transform", + "unique_qname": "sklearn.ensemble._voting._BaseVoting.fit_transform", "decorators": [], "parameters": [ { @@ -70866,7 +72699,9 @@ }, { "name": "n_features_in_", + "unique_name": "n_features_in_@getter", "qname": "sklearn.ensemble._voting._BaseVoting.n_features_in_", + "unique_qname": "sklearn.ensemble._voting._BaseVoting.n_features_in_@getter", "decorators": ["property"], "parameters": [ { @@ -70888,7 +72723,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier.__init__", + "unique_qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier.__init__", "decorators": [], "parameters": [ { @@ -70960,7 +72797,9 @@ }, { "name": "_boost", + "unique_name": "_boost", "qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier._boost", + "unique_qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier._boost", "decorators": [], "parameters": [ { @@ -71032,7 +72871,9 @@ }, { "name": "_boost_discrete", + "unique_name": "_boost_discrete", "qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier._boost_discrete", + "unique_qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier._boost_discrete", "decorators": [], "parameters": [ { @@ -71104,7 +72945,9 @@ }, { "name": "_boost_real", + "unique_name": "_boost_real", "qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier._boost_real", + "unique_qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier._boost_real", "decorators": [], "parameters": [ { @@ -71176,7 +73019,9 @@ }, { "name": "_compute_proba_from_decision", + "unique_name": "_compute_proba_from_decision", "qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier._compute_proba_from_decision", + "unique_qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier._compute_proba_from_decision", "decorators": ["staticmethod"], "parameters": [ { @@ -71208,7 +73053,9 @@ }, { "name": "_validate_estimator", + "unique_name": "_validate_estimator", "qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier._validate_estimator", + "unique_qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier._validate_estimator", "decorators": [], "parameters": [ { @@ -71230,7 +73077,9 @@ }, { "name": "decision_function", + "unique_name": "decision_function", "qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier.decision_function", + "unique_qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier.decision_function", "decorators": [], "parameters": [ { @@ -71262,7 +73111,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier.fit", + "unique_qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier.fit", "decorators": [], "parameters": [ { @@ -71314,7 +73165,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier.predict", + "unique_qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier.predict", "decorators": [], "parameters": [ { @@ -71342,11 +73195,13 @@ "is_public": true, "description": "Predict classes for X.\n\nThe predicted class of an input sample is computed as the weighted mean prediction of the classifiers in the ensemble.", "docstring": "Predict classes for X.\n\nThe predicted class of an input sample is computed as the weighted mean\nprediction of the classifiers in the ensemble.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\nReturns\n-------\ny : ndarray of shape (n_samples,)\n The predicted classes.", - "source_code": "\ndef predict(self, X):\n \"\"\"Predict classes for X.\n\n The predicted class of an input sample is computed as the weighted mean\n prediction of the classifiers in the ensemble.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\n Returns\n -------\n y : ndarray of shape (n_samples,)\n The predicted classes.\n \"\"\"\n X = self._check_X(X)\n pred = self.decision_function(X)\n if self.n_classes_ == 2:\n return self.classes_.take(pred > 0, axis=0)\n return self.classes_.take(np.argmax(pred, axis=1), axis=0)" + "source_code": "\ndef predict(self, X):\n \"\"\"Predict classes for X.\n\n The predicted class of an input sample is computed as the weighted mean\n prediction of the classifiers in the ensemble.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\n Returns\n -------\n y : ndarray of shape (n_samples,)\n The predicted classes.\n \"\"\"\n pred = self.decision_function(X)\n if self.n_classes_ == 2:\n return self.classes_.take(pred > 0, axis=0)\n return self.classes_.take(np.argmax(pred, axis=1), axis=0)" }, { "name": "predict_log_proba", + "unique_name": "predict_log_proba", "qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier.predict_log_proba", + "unique_qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier.predict_log_proba", "decorators": [], "parameters": [ { @@ -71374,11 +73229,13 @@ "is_public": true, "description": "Predict class log-probabilities for X.\n\nThe predicted class log-probabilities of an input sample is computed as the weighted mean predicted class log-probabilities of the classifiers in the ensemble.", "docstring": "Predict class log-probabilities for X.\n\nThe predicted class log-probabilities of an input sample is computed as\nthe weighted mean predicted class log-probabilities of the classifiers\nin the ensemble.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\nReturns\n-------\np : ndarray of shape (n_samples, n_classes)\n The class probabilities of the input samples. The order of\n outputs is the same of that of the :term:`classes_` attribute.", - "source_code": "\ndef predict_log_proba(self, X):\n \"\"\"Predict class log-probabilities for X.\n\n The predicted class log-probabilities of an input sample is computed as\n the weighted mean predicted class log-probabilities of the classifiers\n in the ensemble.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\n Returns\n -------\n p : ndarray of shape (n_samples, n_classes)\n The class probabilities of the input samples. The order of\n outputs is the same of that of the :term:`classes_` attribute.\n \"\"\"\n X = self._check_X(X)\n return np.log(self.predict_proba(X))" + "source_code": "\ndef predict_log_proba(self, X):\n \"\"\"Predict class log-probabilities for X.\n\n The predicted class log-probabilities of an input sample is computed as\n the weighted mean predicted class log-probabilities of the classifiers\n in the ensemble.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\n Returns\n -------\n p : ndarray of shape (n_samples, n_classes)\n The class probabilities of the input samples. The order of\n outputs is the same of that of the :term:`classes_` attribute.\n \"\"\"\n return np.log(self.predict_proba(X))" }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier.predict_proba", + "unique_qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier.predict_proba", "decorators": [], "parameters": [ { @@ -71406,11 +73263,13 @@ "is_public": true, "description": "Predict class probabilities for X.\n\nThe predicted class probabilities of an input sample is computed as the weighted mean predicted class probabilities of the classifiers in the ensemble.", "docstring": "Predict class probabilities for X.\n\nThe predicted class probabilities of an input sample is computed as\nthe weighted mean predicted class probabilities of the classifiers\nin the ensemble.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\nReturns\n-------\np : ndarray of shape (n_samples, n_classes)\n The class probabilities of the input samples. The order of\n outputs is the same of that of the :term:`classes_` attribute.", - "source_code": "\ndef predict_proba(self, X):\n \"\"\"Predict class probabilities for X.\n\n The predicted class probabilities of an input sample is computed as\n the weighted mean predicted class probabilities of the classifiers\n in the ensemble.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\n Returns\n -------\n p : ndarray of shape (n_samples, n_classes)\n The class probabilities of the input samples. The order of\n outputs is the same of that of the :term:`classes_` attribute.\n \"\"\"\n check_is_fitted(self)\n X = self._check_X(X)\n n_classes = self.n_classes_\n if n_classes == 1:\n return np.ones((_num_samples(X), 1))\n decision = self.decision_function(X)\n return self._compute_proba_from_decision(decision, n_classes)" + "source_code": "\ndef predict_proba(self, X):\n \"\"\"Predict class probabilities for X.\n\n The predicted class probabilities of an input sample is computed as\n the weighted mean predicted class probabilities of the classifiers\n in the ensemble.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\n Returns\n -------\n p : ndarray of shape (n_samples, n_classes)\n The class probabilities of the input samples. The order of\n outputs is the same of that of the :term:`classes_` attribute.\n \"\"\"\n check_is_fitted(self)\n n_classes = self.n_classes_\n if n_classes == 1:\n return np.ones((_num_samples(X), 1))\n decision = self.decision_function(X)\n return self._compute_proba_from_decision(decision, n_classes)" }, { "name": "staged_decision_function", + "unique_name": "staged_decision_function", "qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier.staged_decision_function", + "unique_qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier.staged_decision_function", "decorators": [], "parameters": [ { @@ -71442,7 +73301,9 @@ }, { "name": "staged_predict", + "unique_name": "staged_predict", "qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier.staged_predict", + "unique_qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier.staged_predict", "decorators": [], "parameters": [ { @@ -71474,7 +73335,9 @@ }, { "name": "staged_predict_proba", + "unique_name": "staged_predict_proba", "qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier.staged_predict_proba", + "unique_qname": "sklearn.ensemble._weight_boosting.AdaBoostClassifier.staged_predict_proba", "decorators": [], "parameters": [ { @@ -71501,12 +73364,14 @@ "results": [], "is_public": true, "description": "Predict class probabilities for X.\n\nThe predicted class probabilities of an input sample is computed as the weighted mean predicted class probabilities of the classifiers in the ensemble. This generator method yields the ensemble predicted class probabilities after each iteration of boosting and therefore allows monitoring, such as to determine the predicted class probabilities on a test set after each boost.", - "docstring": "Predict class probabilities for X.\n\nThe predicted class probabilities of an input sample is computed as\nthe weighted mean predicted class probabilities of the classifiers\nin the ensemble.\n\nThis generator method yields the ensemble predicted class probabilities\nafter each iteration of boosting and therefore allows monitoring, such\nas to determine the predicted class probabilities on a test set after\neach boost.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\nYields\n-------\np : generator of ndarray of shape (n_samples,)\n The class probabilities of the input samples. The order of\n outputs is the same of that of the :term:`classes_` attribute.", - "source_code": "\ndef staged_predict_proba(self, X):\n \"\"\"Predict class probabilities for X.\n\n The predicted class probabilities of an input sample is computed as\n the weighted mean predicted class probabilities of the classifiers\n in the ensemble.\n\n This generator method yields the ensemble predicted class probabilities\n after each iteration of boosting and therefore allows monitoring, such\n as to determine the predicted class probabilities on a test set after\n each boost.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\n Yields\n -------\n p : generator of ndarray of shape (n_samples,)\n The class probabilities of the input samples. The order of\n outputs is the same of that of the :term:`classes_` attribute.\n \"\"\"\n X = self._check_X(X)\n n_classes = self.n_classes_\n for decision in self.staged_decision_function(X):\n yield self._compute_proba_from_decision(decision, n_classes)" + "docstring": "Predict class probabilities for X.\n\nThe predicted class probabilities of an input sample is computed as\nthe weighted mean predicted class probabilities of the classifiers\nin the ensemble.\n\nThis generator method yields the ensemble predicted class probabilities\nafter each iteration of boosting and therefore allows monitoring, such\nas to determine the predicted class probabilities on a test set after\neach boost.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\nYields\n------\np : generator of ndarray of shape (n_samples,)\n The class probabilities of the input samples. The order of\n outputs is the same of that of the :term:`classes_` attribute.", + "source_code": "\ndef staged_predict_proba(self, X):\n \"\"\"Predict class probabilities for X.\n\n The predicted class probabilities of an input sample is computed as\n the weighted mean predicted class probabilities of the classifiers\n in the ensemble.\n\n This generator method yields the ensemble predicted class probabilities\n after each iteration of boosting and therefore allows monitoring, such\n as to determine the predicted class probabilities on a test set after\n each boost.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The training input samples. Sparse matrix can be CSC, CSR, COO,\n DOK, or LIL. COO, DOK, and LIL are converted to CSR.\n\n Yields\n ------\n p : generator of ndarray of shape (n_samples,)\n The class probabilities of the input samples. The order of\n outputs is the same of that of the :term:`classes_` attribute.\n \"\"\"\n n_classes = self.n_classes_\n for decision in self.staged_decision_function(X):\n yield self._compute_proba_from_decision(decision, n_classes)" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._weight_boosting.AdaBoostRegressor.__init__", + "unique_qname": "sklearn.ensemble._weight_boosting.AdaBoostRegressor.__init__", "decorators": [], "parameters": [ { @@ -71578,7 +73443,9 @@ }, { "name": "_boost", + "unique_name": "_boost", "qname": "sklearn.ensemble._weight_boosting.AdaBoostRegressor._boost", + "unique_qname": "sklearn.ensemble._weight_boosting.AdaBoostRegressor._boost", "decorators": [], "parameters": [ { @@ -71650,7 +73517,9 @@ }, { "name": "_get_median_predict", + "unique_name": "_get_median_predict", "qname": "sklearn.ensemble._weight_boosting.AdaBoostRegressor._get_median_predict", + "unique_qname": "sklearn.ensemble._weight_boosting.AdaBoostRegressor._get_median_predict", "decorators": [], "parameters": [ { @@ -71692,7 +73561,9 @@ }, { "name": "_validate_estimator", + "unique_name": "_validate_estimator", "qname": "sklearn.ensemble._weight_boosting.AdaBoostRegressor._validate_estimator", + "unique_qname": "sklearn.ensemble._weight_boosting.AdaBoostRegressor._validate_estimator", "decorators": [], "parameters": [ { @@ -71714,7 +73585,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.ensemble._weight_boosting.AdaBoostRegressor.fit", + "unique_qname": "sklearn.ensemble._weight_boosting.AdaBoostRegressor.fit", "decorators": [], "parameters": [ { @@ -71766,7 +73639,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.ensemble._weight_boosting.AdaBoostRegressor.predict", + "unique_qname": "sklearn.ensemble._weight_boosting.AdaBoostRegressor.predict", "decorators": [], "parameters": [ { @@ -71798,7 +73673,9 @@ }, { "name": "staged_predict", + "unique_name": "staged_predict", "qname": "sklearn.ensemble._weight_boosting.AdaBoostRegressor.staged_predict", + "unique_qname": "sklearn.ensemble._weight_boosting.AdaBoostRegressor.staged_predict", "decorators": [], "parameters": [ { @@ -71830,7 +73707,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.ensemble._weight_boosting.BaseWeightBoosting.__init__", + "unique_qname": "sklearn.ensemble._weight_boosting.BaseWeightBoosting.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -71902,7 +73781,9 @@ }, { "name": "_boost", + "unique_name": "_boost", "qname": "sklearn.ensemble._weight_boosting.BaseWeightBoosting._boost", + "unique_qname": "sklearn.ensemble._weight_boosting.BaseWeightBoosting._boost", "decorators": ["abstractmethod"], "parameters": [ { @@ -71974,7 +73855,9 @@ }, { "name": "_check_X", + "unique_name": "_check_X", "qname": "sklearn.ensemble._weight_boosting.BaseWeightBoosting._check_X", + "unique_qname": "sklearn.ensemble._weight_boosting.BaseWeightBoosting._check_X", "decorators": [], "parameters": [ { @@ -72006,7 +73889,9 @@ }, { "name": "feature_importances_", + "unique_name": "feature_importances_@getter", "qname": "sklearn.ensemble._weight_boosting.BaseWeightBoosting.feature_importances_", + "unique_qname": "sklearn.ensemble._weight_boosting.BaseWeightBoosting.feature_importances_@getter", "decorators": ["property"], "parameters": [ { @@ -72028,7 +73913,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.ensemble._weight_boosting.BaseWeightBoosting.fit", + "unique_qname": "sklearn.ensemble._weight_boosting.BaseWeightBoosting.fit", "decorators": [], "parameters": [ { @@ -72080,7 +73967,9 @@ }, { "name": "staged_score", + "unique_name": "staged_score", "qname": "sklearn.ensemble._weight_boosting.BaseWeightBoosting.staged_score", + "unique_qname": "sklearn.ensemble._weight_boosting.BaseWeightBoosting.staged_score", "decorators": [], "parameters": [ { @@ -72132,7 +74021,9 @@ }, { "name": "_samme_proba", + "unique_name": "_samme_proba", "qname": "sklearn.ensemble._weight_boosting._samme_proba", + "unique_qname": "sklearn.ensemble._weight_boosting._samme_proba", "decorators": [], "parameters": [ { @@ -72174,7 +74065,9 @@ }, { "name": "configuration", + "unique_name": "configuration", "qname": "sklearn.ensemble.setup.configuration", + "unique_qname": "sklearn.ensemble.setup.configuration", "decorators": [], "parameters": [ { @@ -72206,7 +74099,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.externals._arff.ArffDecoder.__init__", + "unique_qname": "sklearn.externals._arff.ArffDecoder.__init__", "decorators": [], "parameters": [ { @@ -72228,7 +74123,9 @@ }, { "name": "_decode", + "unique_name": "_decode", "qname": "sklearn.externals._arff.ArffDecoder._decode", + "unique_qname": "sklearn.externals._arff.ArffDecoder._decode", "decorators": [], "parameters": [ { @@ -72280,7 +74177,9 @@ }, { "name": "_decode_attribute", + "unique_name": "_decode_attribute", "qname": "sklearn.externals._arff.ArffDecoder._decode_attribute", + "unique_qname": "sklearn.externals._arff.ArffDecoder._decode_attribute", "decorators": [], "parameters": [ { @@ -72312,7 +74211,9 @@ }, { "name": "_decode_comment", + "unique_name": "_decode_comment", "qname": "sklearn.externals._arff.ArffDecoder._decode_comment", + "unique_qname": "sklearn.externals._arff.ArffDecoder._decode_comment", "decorators": [], "parameters": [ { @@ -72344,7 +74245,9 @@ }, { "name": "_decode_relation", + "unique_name": "_decode_relation", "qname": "sklearn.externals._arff.ArffDecoder._decode_relation", + "unique_qname": "sklearn.externals._arff.ArffDecoder._decode_relation", "decorators": [], "parameters": [ { @@ -72376,7 +74279,9 @@ }, { "name": "decode", + "unique_name": "decode", "qname": "sklearn.externals._arff.ArffDecoder.decode", + "unique_qname": "sklearn.externals._arff.ArffDecoder.decode", "decorators": [], "parameters": [ { @@ -72428,7 +74333,9 @@ }, { "name": "_encode_attribute", + "unique_name": "_encode_attribute", "qname": "sklearn.externals._arff.ArffEncoder._encode_attribute", + "unique_qname": "sklearn.externals._arff.ArffEncoder._encode_attribute", "decorators": [], "parameters": [ { @@ -72470,7 +74377,9 @@ }, { "name": "_encode_comment", + "unique_name": "_encode_comment", "qname": "sklearn.externals._arff.ArffEncoder._encode_comment", + "unique_qname": "sklearn.externals._arff.ArffEncoder._encode_comment", "decorators": [], "parameters": [ { @@ -72502,7 +74411,9 @@ }, { "name": "_encode_relation", + "unique_name": "_encode_relation", "qname": "sklearn.externals._arff.ArffEncoder._encode_relation", + "unique_qname": "sklearn.externals._arff.ArffEncoder._encode_relation", "decorators": [], "parameters": [ { @@ -72534,7 +74445,9 @@ }, { "name": "encode", + "unique_name": "encode", "qname": "sklearn.externals._arff.ArffEncoder.encode", + "unique_qname": "sklearn.externals._arff.ArffEncoder.encode", "decorators": [], "parameters": [ { @@ -72566,7 +74479,9 @@ }, { "name": "iter_encode", + "unique_name": "iter_encode", "qname": "sklearn.externals._arff.ArffEncoder.iter_encode", + "unique_qname": "sklearn.externals._arff.ArffEncoder.iter_encode", "decorators": [], "parameters": [ { @@ -72598,7 +74513,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.externals._arff.ArffException.__init__", + "unique_qname": "sklearn.externals._arff.ArffException.__init__", "decorators": [], "parameters": [ { @@ -72620,7 +74537,9 @@ }, { "name": "__str__", + "unique_name": "__str__", "qname": "sklearn.externals._arff.ArffException.__str__", + "unique_qname": "sklearn.externals._arff.ArffException.__str__", "decorators": [], "parameters": [ { @@ -72642,7 +74561,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.externals._arff.BadAttributeName.__init__", + "unique_qname": "sklearn.externals._arff.BadAttributeName.__init__", "decorators": [], "parameters": [ { @@ -72684,7 +74605,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.externals._arff.BadDataFormat.__init__", + "unique_qname": "sklearn.externals._arff.BadDataFormat.__init__", "decorators": [], "parameters": [ { @@ -72716,7 +74639,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.externals._arff.BadLayout.__init__", + "unique_qname": "sklearn.externals._arff.BadLayout.__init__", "decorators": [], "parameters": [ { @@ -72748,7 +74673,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.externals._arff.BadNominalFormatting.__init__", + "unique_qname": "sklearn.externals._arff.BadNominalFormatting.__init__", "decorators": [], "parameters": [ { @@ -72780,7 +74707,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.externals._arff.BadNominalValue.__init__", + "unique_qname": "sklearn.externals._arff.BadNominalValue.__init__", "decorators": [], "parameters": [ { @@ -72812,7 +74741,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.externals._arff.BadObject.__init__", + "unique_qname": "sklearn.externals._arff.BadObject.__init__", "decorators": [], "parameters": [ { @@ -72844,7 +74775,9 @@ }, { "name": "__str__", + "unique_name": "__str__", "qname": "sklearn.externals._arff.BadObject.__str__", + "unique_qname": "sklearn.externals._arff.BadObject.__str__", "decorators": [], "parameters": [ { @@ -72866,7 +74799,9 @@ }, { "name": "decode_rows", + "unique_name": "decode_rows", "qname": "sklearn.externals._arff.COOData.decode_rows", + "unique_qname": "sklearn.externals._arff.COOData.decode_rows", "decorators": [], "parameters": [ { @@ -72908,7 +74843,9 @@ }, { "name": "encode_data", + "unique_name": "encode_data", "qname": "sklearn.externals._arff.COOData.encode_data", + "unique_qname": "sklearn.externals._arff.COOData.encode_data", "decorators": [], "parameters": [ { @@ -72950,7 +74887,9 @@ }, { "name": "_decode_values", + "unique_name": "_decode_values", "qname": "sklearn.externals._arff.DenseGeneratorData._decode_values", + "unique_qname": "sklearn.externals._arff.DenseGeneratorData._decode_values", "decorators": ["staticmethod"], "parameters": [ { @@ -72982,7 +74921,9 @@ }, { "name": "decode_rows", + "unique_name": "decode_rows", "qname": "sklearn.externals._arff.DenseGeneratorData.decode_rows", + "unique_qname": "sklearn.externals._arff.DenseGeneratorData.decode_rows", "decorators": [], "parameters": [ { @@ -73024,7 +74965,9 @@ }, { "name": "encode_data", + "unique_name": "encode_data", "qname": "sklearn.externals._arff.DenseGeneratorData.encode_data", + "unique_qname": "sklearn.externals._arff.DenseGeneratorData.encode_data", "decorators": [], "parameters": [ { @@ -73066,7 +75009,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.externals._arff.EncodedNominalConversor.__call__", + "unique_qname": "sklearn.externals._arff.EncodedNominalConversor.__call__", "decorators": [], "parameters": [ { @@ -73098,7 +75043,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.externals._arff.EncodedNominalConversor.__init__", + "unique_qname": "sklearn.externals._arff.EncodedNominalConversor.__init__", "decorators": [], "parameters": [ { @@ -73130,7 +75077,9 @@ }, { "name": "decode_rows", + "unique_name": "decode_rows", "qname": "sklearn.externals._arff.LODGeneratorData.decode_rows", + "unique_qname": "sklearn.externals._arff.LODGeneratorData.decode_rows", "decorators": [], "parameters": [ { @@ -73172,7 +75121,9 @@ }, { "name": "encode_data", + "unique_name": "encode_data", "qname": "sklearn.externals._arff.LODGeneratorData.encode_data", + "unique_qname": "sklearn.externals._arff.LODGeneratorData.encode_data", "decorators": [], "parameters": [ { @@ -73214,7 +75165,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.externals._arff.NominalConversor.__call__", + "unique_qname": "sklearn.externals._arff.NominalConversor.__call__", "decorators": [], "parameters": [ { @@ -73246,7 +75199,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.externals._arff.NominalConversor.__init__", + "unique_qname": "sklearn.externals._arff.NominalConversor.__init__", "decorators": [], "parameters": [ { @@ -73278,7 +75233,9 @@ }, { "name": "decode_rows", + "unique_name": "decode_rows", "qname": "sklearn.externals._arff._DataListMixin.decode_rows", + "unique_qname": "sklearn.externals._arff._DataListMixin.decode_rows", "decorators": [], "parameters": [ { @@ -73320,7 +75277,9 @@ }, { "name": "_build_re_values", + "unique_name": "_build_re_values", "qname": "sklearn.externals._arff._build_re_values", + "unique_qname": "sklearn.externals._arff._build_re_values", "decorators": [], "parameters": [], "results": [], @@ -73331,7 +75290,9 @@ }, { "name": "_escape_sub_callback", + "unique_name": "_escape_sub_callback", "qname": "sklearn.externals._arff._escape_sub_callback", + "unique_qname": "sklearn.externals._arff._escape_sub_callback", "decorators": [], "parameters": [ { @@ -73353,7 +75314,9 @@ }, { "name": "_get_data_object_for_decoding", + "unique_name": "_get_data_object_for_decoding", "qname": "sklearn.externals._arff._get_data_object_for_decoding", + "unique_qname": "sklearn.externals._arff._get_data_object_for_decoding", "decorators": [], "parameters": [ { @@ -73375,7 +75338,9 @@ }, { "name": "_get_data_object_for_encoding", + "unique_name": "_get_data_object_for_encoding", "qname": "sklearn.externals._arff._get_data_object_for_encoding", + "unique_qname": "sklearn.externals._arff._get_data_object_for_encoding", "decorators": [], "parameters": [ { @@ -73397,7 +75362,9 @@ }, { "name": "_parse_values", + "unique_name": "_parse_values", "qname": "sklearn.externals._arff._parse_values", + "unique_qname": "sklearn.externals._arff._parse_values", "decorators": [], "parameters": [ { @@ -73419,7 +75386,9 @@ }, { "name": "_unescape_sub_callback", + "unique_name": "_unescape_sub_callback", "qname": "sklearn.externals._arff._unescape_sub_callback", + "unique_qname": "sklearn.externals._arff._unescape_sub_callback", "decorators": [], "parameters": [ { @@ -73441,7 +75410,9 @@ }, { "name": "_unquote", + "unique_name": "_unquote", "qname": "sklearn.externals._arff._unquote", + "unique_qname": "sklearn.externals._arff._unquote", "decorators": [], "parameters": [ { @@ -73463,7 +75434,9 @@ }, { "name": "dump", + "unique_name": "dump", "qname": "sklearn.externals._arff.dump", + "unique_qname": "sklearn.externals._arff.dump", "decorators": [], "parameters": [ { @@ -73495,7 +75468,9 @@ }, { "name": "dumps", + "unique_name": "dumps", "qname": "sklearn.externals._arff.dumps", + "unique_qname": "sklearn.externals._arff.dumps", "decorators": [], "parameters": [ { @@ -73517,7 +75492,9 @@ }, { "name": "encode_string", + "unique_name": "encode_string", "qname": "sklearn.externals._arff.encode_string", + "unique_qname": "sklearn.externals._arff.encode_string", "decorators": [], "parameters": [ { @@ -73539,7 +75516,9 @@ }, { "name": "load", + "unique_name": "load", "qname": "sklearn.externals._arff.load", + "unique_qname": "sklearn.externals._arff.load", "decorators": [], "parameters": [ { @@ -73581,7 +75560,9 @@ }, { "name": "loads", + "unique_name": "loads", "qname": "sklearn.externals._arff.loads", + "unique_qname": "sklearn.externals._arff.loads", "decorators": [], "parameters": [ { @@ -73623,7 +75604,9 @@ }, { "name": "_applyConstraints", + "unique_name": "_applyConstraints", "qname": "sklearn.externals._lobpcg._applyConstraints", + "unique_qname": "sklearn.externals._lobpcg._applyConstraints", "decorators": [], "parameters": [ { @@ -73675,7 +75658,9 @@ }, { "name": "_as2d", + "unique_name": "_as2d", "qname": "sklearn.externals._lobpcg._as2d", + "unique_qname": "sklearn.externals._lobpcg._as2d", "decorators": [], "parameters": [ { @@ -73697,7 +75682,9 @@ }, { "name": "_b_orthonormalize", + "unique_name": "_b_orthonormalize", "qname": "sklearn.externals._lobpcg._b_orthonormalize", + "unique_qname": "sklearn.externals._lobpcg._b_orthonormalize", "decorators": [], "parameters": [ { @@ -73749,7 +75736,9 @@ }, { "name": "_get_indx", + "unique_name": "_get_indx", "qname": "sklearn.externals._lobpcg._get_indx", + "unique_qname": "sklearn.externals._lobpcg._get_indx", "decorators": [], "parameters": [ { @@ -73791,7 +75780,9 @@ }, { "name": "_makeOperator", + "unique_name": "_makeOperator", "qname": "sklearn.externals._lobpcg._makeOperator", + "unique_qname": "sklearn.externals._lobpcg._makeOperator", "decorators": [], "parameters": [ { @@ -73823,7 +75814,9 @@ }, { "name": "_report_nonhermitian", + "unique_name": "_report_nonhermitian", "qname": "sklearn.externals._lobpcg._report_nonhermitian", + "unique_qname": "sklearn.externals._lobpcg._report_nonhermitian", "decorators": [], "parameters": [ { @@ -73849,56 +75842,15 @@ ], "results": [], "is_public": false, - "description": "Report if `M` is not a hermitian matrix given its type.", - "docstring": "Report if `M` is not a hermitian matrix given its type.", - "source_code": "\ndef _report_nonhermitian(M, name):\n \"\"\"\n Report if `M` is not a hermitian matrix given its type.\n \"\"\"\n from scipy.linalg import norm\n md = M - M.T.conj()\n nmd = norm(md, 1)\n tol = 10 * np.finfo(M.dtype).eps\n tol = max(tol, tol * norm(M, 1))\n if nmd > tol:\n print('matrix %s of the type %s is not sufficiently Hermitian:' % (name, M.dtype))\n print('condition: %.e < %e' % (nmd, tol))" - }, - { - "name": "_save", - "qname": "sklearn.externals._lobpcg._save", - "decorators": [], - "parameters": [ - { - "name": "ar", - "default_value": null, - "is_public": false, - "assigned_by": "POSITION_OR_NAME", - "docstring": { - "type": "", - "description": "" - } - }, - { - "name": "fileName", - "default_value": null, - "is_public": false, - "assigned_by": "POSITION_OR_NAME", - "docstring": { - "type": "", - "description": "" - } - } - ], - "results": [], - "is_public": false, - "description": "", - "docstring": "", - "source_code": "\ndef _save(ar, fileName):\n np.savetxt(fileName, ar)" - }, - { - "name": "bmat", - "qname": "sklearn.externals._lobpcg.bmat", - "decorators": [], - "parameters": [], - "results": [], - "is_public": false, - "description": "", - "docstring": "", - "source_code": "\ndef bmat(*args, **kwargs):\n import warnings\n with warnings.catch_warnings(record=True):\n warnings.filterwarnings('ignore', '.*the matrix subclass is not the recommended way.*')\n return np.bmat(*args, **kwargs)" + "description": "Report if `M` is not a Hermitian matrix given its type.", + "docstring": "Report if `M` is not a Hermitian matrix given its type.", + "source_code": "\ndef _report_nonhermitian(M, name):\n \"\"\"\n Report if `M` is not a Hermitian matrix given its type.\n \"\"\"\n from scipy.linalg import norm\n md = M - M.T.conj()\n nmd = norm(md, 1)\n tol = 10 * np.finfo(M.dtype).eps\n tol = max(tol, tol * norm(M, 1))\n if nmd > tol:\n print('matrix %s of the type %s is not sufficiently Hermitian:' % (name, M.dtype))\n print('condition: %.e < %e' % (nmd, tol))" }, { "name": "lobpcg", + "unique_name": "lobpcg", "qname": "sklearn.externals._lobpcg.lobpcg", + "unique_qname": "sklearn.externals._lobpcg.lobpcg", "decorators": [], "parameters": [ { @@ -73963,12 +75915,12 @@ }, { "name": "maxiter", - "default_value": "20", + "default_value": "None", "is_public": false, "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "int, optional", - "description": "Maximum number of iterations. The default is ``maxiter=min(n, 20)``." + "description": "Maximum number of iterations. The default is ``maxiter = 20``." } }, { @@ -74015,12 +75967,14 @@ "results": [], "is_public": false, "description": "Locally Optimal Block Preconditioned Conjugate Gradient Method (LOBPCG)\n\nLOBPCG is a preconditioned eigensolver for large symmetric positive definite (SPD) generalized eigenproblems.", - "docstring": "Locally Optimal Block Preconditioned Conjugate Gradient Method (LOBPCG)\n\nLOBPCG is a preconditioned eigensolver for large symmetric positive\ndefinite (SPD) generalized eigenproblems.\n\nParameters\n----------\nA : {sparse matrix, dense matrix, LinearOperator}\n The symmetric linear operator of the problem, usually a\n sparse matrix. Often called the \"stiffness matrix\".\nX : ndarray, float32 or float64\n Initial approximation to the ``k`` eigenvectors (non-sparse). If `A`\n has ``shape=(n,n)`` then `X` should have shape ``shape=(n,k)``.\nB : {dense matrix, sparse matrix, LinearOperator}, optional\n The right hand side operator in a generalized eigenproblem.\n By default, ``B = Identity``. Often called the \"mass matrix\".\nM : {dense matrix, sparse matrix, LinearOperator}, optional\n Preconditioner to `A`; by default ``M = Identity``.\n `M` should approximate the inverse of `A`.\nY : ndarray, float32 or float64, optional\n n-by-sizeY matrix of constraints (non-sparse), sizeY < n\n The iterations will be performed in the B-orthogonal complement\n of the column-space of Y. Y must be full rank.\ntol : scalar, optional\n Solver tolerance (stopping criterion).\n The default is ``tol=n*sqrt(eps)``.\nmaxiter : int, optional\n Maximum number of iterations. The default is ``maxiter=min(n, 20)``.\nlargest : bool, optional\n When True, solve for the largest eigenvalues, otherwise the smallest.\nverbosityLevel : int, optional\n Controls solver output. The default is ``verbosityLevel=0``.\nretLambdaHistory : bool, optional\n Whether to return eigenvalue history. Default is False.\nretResidualNormsHistory : bool, optional\n Whether to return history of residual norms. Default is False.\n\nReturns\n-------\nw : ndarray\n Array of ``k`` eigenvalues\nv : ndarray\n An array of ``k`` eigenvectors. `v` has the same shape as `X`.\nlambdas : list of ndarray, optional\n The eigenvalue history, if `retLambdaHistory` is True.\nrnorms : list of ndarray, optional\n The history of residual norms, if `retResidualNormsHistory` is True.\n\nNotes\n-----\nIf both ``retLambdaHistory`` and ``retResidualNormsHistory`` are True,\nthe return tuple has the following format\n``(lambda, V, lambda history, residual norms history)``.\n\nIn the following ``n`` denotes the matrix size and ``m`` the number\nof required eigenvalues (smallest or largest).\n\nThe LOBPCG code internally solves eigenproblems of the size ``3m`` on every\niteration by calling the \"standard\" dense eigensolver, so if ``m`` is not\nsmall enough compared to ``n``, it does not make sense to call the LOBPCG\ncode, but rather one should use the \"standard\" eigensolver, e.g. numpy or\nscipy function in this case.\nIf one calls the LOBPCG algorithm for ``5m > n``, it will most likely break\ninternally, so the code tries to call the standard function instead.\n\nIt is not that ``n`` should be large for the LOBPCG to work, but rather the\nratio ``n / m`` should be large. It you call LOBPCG with ``m=1``\nand ``n=10``, it works though ``n`` is small. The method is intended\nfor extremely large ``n / m``, see e.g., reference [28] in\nhttps://arxiv.org/abs/0705.2626\n\nThe convergence speed depends basically on two factors:\n\n1. How well relatively separated the seeking eigenvalues are from the rest\n of the eigenvalues. One can try to vary ``m`` to make this better.\n\n2. How well conditioned the problem is. This can be changed by using proper\n preconditioning. For example, a rod vibration test problem (under tests\n directory) is ill-conditioned for large ``n``, so convergence will be\n slow, unless efficient preconditioning is used. For this specific\n problem, a good simple preconditioner function would be a linear solve\n for `A`, which is easy to code since A is tridiagonal.\n\nReferences\n----------\n.. [1] A. V. Knyazev (2001),\n Toward the Optimal Preconditioned Eigensolver: Locally Optimal\n Block Preconditioned Conjugate Gradient Method.\n SIAM Journal on Scientific Computing 23, no. 2,\n pp. 517-541. http://dx.doi.org/10.1137/S1064827500366124\n\n.. [2] A. V. Knyazev, I. Lashuk, M. E. Argentati, and E. Ovchinnikov\n (2007), Block Locally Optimal Preconditioned Eigenvalue Xolvers\n (BLOPEX) in hypre and PETSc. https://arxiv.org/abs/0705.2626\n\n.. [3] A. V. Knyazev's C and MATLAB implementations:\n https://bitbucket.org/joseroman/blopex\n\nExamples\n--------\n\nSolve ``A x = lambda x`` with constraints and preconditioning.\n\n>>> import numpy as np\n>>> from scipy.sparse import spdiags, issparse\n>>> from scipy.sparse.linalg import lobpcg, LinearOperator\n>>> n = 100\n>>> vals = np.arange(1, n + 1)\n>>> A = spdiags(vals, 0, n, n)\n>>> A.toarray()\narray([[ 1., 0., 0., ..., 0., 0., 0.],\n [ 0., 2., 0., ..., 0., 0., 0.],\n [ 0., 0., 3., ..., 0., 0., 0.],\n ...,\n [ 0., 0., 0., ..., 98., 0., 0.],\n [ 0., 0., 0., ..., 0., 99., 0.],\n [ 0., 0., 0., ..., 0., 0., 100.]])\n\nConstraints:\n\n>>> Y = np.eye(n, 3)\n\nInitial guess for eigenvectors, should have linearly independent\ncolumns. Column dimension = number of requested eigenvalues.\n\n>>> X = np.random.rand(n, 3)\n\nPreconditioner in the inverse of A in this example:\n\n>>> invA = spdiags([1./vals], 0, n, n)\n\nThe preconditiner must be defined by a function:\n\n>>> def precond( x ):\n... return invA @ x\n\nThe argument x of the preconditioner function is a matrix inside `lobpcg`,\nthus the use of matrix-matrix product ``@``.\n\nThe preconditioner function is passed to lobpcg as a `LinearOperator`:\n\n>>> M = LinearOperator(matvec=precond, matmat=precond,\n... shape=(n, n), dtype=float)\n\nLet us now solve the eigenvalue problem for the matrix A:\n\n>>> eigenvalues, _ = lobpcg(A, X, Y=Y, M=M, largest=False)\n>>> eigenvalues\narray([4., 5., 6.])\n\nNote that the vectors passed in Y are the eigenvectors of the 3 smallest\neigenvalues. The results returned are orthogonal to those.", - "source_code": "\ndef lobpcg(A, X, B=None, M=None, Y=None, tol=None, maxiter=20, largest=True, verbosityLevel=0, retLambdaHistory=False, retResidualNormsHistory=False):\n \"\"\"Locally Optimal Block Preconditioned Conjugate Gradient Method (LOBPCG)\n\n LOBPCG is a preconditioned eigensolver for large symmetric positive\n definite (SPD) generalized eigenproblems.\n\n Parameters\n ----------\n A : {sparse matrix, dense matrix, LinearOperator}\n The symmetric linear operator of the problem, usually a\n sparse matrix. Often called the \"stiffness matrix\".\n X : ndarray, float32 or float64\n Initial approximation to the ``k`` eigenvectors (non-sparse). If `A`\n has ``shape=(n,n)`` then `X` should have shape ``shape=(n,k)``.\n B : {dense matrix, sparse matrix, LinearOperator}, optional\n The right hand side operator in a generalized eigenproblem.\n By default, ``B = Identity``. Often called the \"mass matrix\".\n M : {dense matrix, sparse matrix, LinearOperator}, optional\n Preconditioner to `A`; by default ``M = Identity``.\n `M` should approximate the inverse of `A`.\n Y : ndarray, float32 or float64, optional\n n-by-sizeY matrix of constraints (non-sparse), sizeY < n\n The iterations will be performed in the B-orthogonal complement\n of the column-space of Y. Y must be full rank.\n tol : scalar, optional\n Solver tolerance (stopping criterion).\n The default is ``tol=n*sqrt(eps)``.\n maxiter : int, optional\n Maximum number of iterations. The default is ``maxiter=min(n, 20)``.\n largest : bool, optional\n When True, solve for the largest eigenvalues, otherwise the smallest.\n verbosityLevel : int, optional\n Controls solver output. The default is ``verbosityLevel=0``.\n retLambdaHistory : bool, optional\n Whether to return eigenvalue history. Default is False.\n retResidualNormsHistory : bool, optional\n Whether to return history of residual norms. Default is False.\n\n Returns\n -------\n w : ndarray\n Array of ``k`` eigenvalues\n v : ndarray\n An array of ``k`` eigenvectors. `v` has the same shape as `X`.\n lambdas : list of ndarray, optional\n The eigenvalue history, if `retLambdaHistory` is True.\n rnorms : list of ndarray, optional\n The history of residual norms, if `retResidualNormsHistory` is True.\n\n Notes\n -----\n If both ``retLambdaHistory`` and ``retResidualNormsHistory`` are True,\n the return tuple has the following format\n ``(lambda, V, lambda history, residual norms history)``.\n\n In the following ``n`` denotes the matrix size and ``m`` the number\n of required eigenvalues (smallest or largest).\n\n The LOBPCG code internally solves eigenproblems of the size ``3m`` on every\n iteration by calling the \"standard\" dense eigensolver, so if ``m`` is not\n small enough compared to ``n``, it does not make sense to call the LOBPCG\n code, but rather one should use the \"standard\" eigensolver, e.g. numpy or\n scipy function in this case.\n If one calls the LOBPCG algorithm for ``5m > n``, it will most likely break\n internally, so the code tries to call the standard function instead.\n\n It is not that ``n`` should be large for the LOBPCG to work, but rather the\n ratio ``n / m`` should be large. It you call LOBPCG with ``m=1``\n and ``n=10``, it works though ``n`` is small. The method is intended\n for extremely large ``n / m``, see e.g., reference [28] in\n https://arxiv.org/abs/0705.2626\n\n The convergence speed depends basically on two factors:\n\n 1. How well relatively separated the seeking eigenvalues are from the rest\n of the eigenvalues. One can try to vary ``m`` to make this better.\n\n 2. How well conditioned the problem is. This can be changed by using proper\n preconditioning. For example, a rod vibration test problem (under tests\n directory) is ill-conditioned for large ``n``, so convergence will be\n slow, unless efficient preconditioning is used. For this specific\n problem, a good simple preconditioner function would be a linear solve\n for `A`, which is easy to code since A is tridiagonal.\n\n References\n ----------\n .. [1] A. V. Knyazev (2001),\n Toward the Optimal Preconditioned Eigensolver: Locally Optimal\n Block Preconditioned Conjugate Gradient Method.\n SIAM Journal on Scientific Computing 23, no. 2,\n pp. 517-541. http://dx.doi.org/10.1137/S1064827500366124\n\n .. [2] A. V. Knyazev, I. Lashuk, M. E. Argentati, and E. Ovchinnikov\n (2007), Block Locally Optimal Preconditioned Eigenvalue Xolvers\n (BLOPEX) in hypre and PETSc. https://arxiv.org/abs/0705.2626\n\n .. [3] A. V. Knyazev's C and MATLAB implementations:\n https://bitbucket.org/joseroman/blopex\n\n Examples\n --------\n\n Solve ``A x = lambda x`` with constraints and preconditioning.\n\n >>> import numpy as np\n >>> from scipy.sparse import spdiags, issparse\n >>> from scipy.sparse.linalg import lobpcg, LinearOperator\n >>> n = 100\n >>> vals = np.arange(1, n + 1)\n >>> A = spdiags(vals, 0, n, n)\n >>> A.toarray()\n array([[ 1., 0., 0., ..., 0., 0., 0.],\n [ 0., 2., 0., ..., 0., 0., 0.],\n [ 0., 0., 3., ..., 0., 0., 0.],\n ...,\n [ 0., 0., 0., ..., 98., 0., 0.],\n [ 0., 0., 0., ..., 0., 99., 0.],\n [ 0., 0., 0., ..., 0., 0., 100.]])\n\n Constraints:\n\n >>> Y = np.eye(n, 3)\n\n Initial guess for eigenvectors, should have linearly independent\n columns. Column dimension = number of requested eigenvalues.\n\n >>> X = np.random.rand(n, 3)\n\n Preconditioner in the inverse of A in this example:\n\n >>> invA = spdiags([1./vals], 0, n, n)\n\n The preconditiner must be defined by a function:\n\n >>> def precond( x ):\n ... return invA @ x\n\n The argument x of the preconditioner function is a matrix inside `lobpcg`,\n thus the use of matrix-matrix product ``@``.\n\n The preconditioner function is passed to lobpcg as a `LinearOperator`:\n\n >>> M = LinearOperator(matvec=precond, matmat=precond,\n ... shape=(n, n), dtype=float)\n\n Let us now solve the eigenvalue problem for the matrix A:\n\n >>> eigenvalues, _ = lobpcg(A, X, Y=Y, M=M, largest=False)\n >>> eigenvalues\n array([4., 5., 6.])\n\n Note that the vectors passed in Y are the eigenvectors of the 3 smallest\n eigenvalues. The results returned are orthogonal to those.\n\n \"\"\"\n blockVectorX = X\n blockVectorY = Y\n residualTolerance = tol\n maxIterations = maxiter\n if blockVectorY is not None:\n sizeY = blockVectorY.shape[1]\n else:\n sizeY = 0\n if len(blockVectorX.shape) != 2:\n raise ValueError('expected rank-2 array for argument X')\n (n, sizeX) = blockVectorX.shape\n if verbosityLevel:\n aux = 'Solving '\n if B is None:\n aux += 'standard'\n else:\n aux += 'generalized'\n aux += ' eigenvalue problem with'\n if M is None:\n aux += 'out'\n aux += ' preconditioning\\n\\n'\n aux += 'matrix size %d\\n' % n\n aux += 'block size %d\\n\\n' % sizeX\n if blockVectorY is None:\n aux += 'No constraints\\n\\n'\n elif sizeY > 1:\n aux += '%d constraints\\n\\n' % sizeY\n else:\n aux += '%d constraint\\n\\n' % sizeY\n print(aux)\n A = _makeOperator(A, (n, n))\n B = _makeOperator(B, (n, n))\n M = _makeOperator(M, (n, n))\n if n - sizeY < 5 * sizeX:\n sizeX = min(sizeX, n)\n if blockVectorY is not None:\n raise NotImplementedError('The dense eigensolver does not support constraints.')\n if largest:\n eigvals = (n - sizeX, n - 1)\n else:\n eigvals = (0, sizeX - 1)\n A_dense = A(np.eye(n, dtype=A.dtype))\n B_dense = None if B is None else B(np.eye(n, dtype=B.dtype))\n (vals, vecs) = eigh(A_dense, B_dense, eigvals=eigvals, check_finite=False)\n if largest:\n vals = vals[::-1]\n vecs = vecs[:, ::-1]\n return vals, vecs\n if residualTolerance is None or residualTolerance <= 0.0:\n residualTolerance = np.sqrt(1e-15) * n\n if blockVectorY is not None:\n if B is not None:\n blockVectorBY = B(blockVectorY)\n else:\n blockVectorBY = blockVectorY\n gramYBY = np.dot(blockVectorY.T.conj(), blockVectorBY)\n try:\n gramYBY = cho_factor(gramYBY)\n except LinAlgError as e:\n raise ValueError('cannot handle linearly dependent constraints') from e\n _applyConstraints(blockVectorX, gramYBY, blockVectorBY, blockVectorY)\n (blockVectorX, blockVectorBX) = _b_orthonormalize(B, blockVectorX)\n blockVectorAX = A(blockVectorX)\n gramXAX = np.dot(blockVectorX.T.conj(), blockVectorAX)\n (_lambda, eigBlockVector) = eigh(gramXAX, check_finite=False)\n ii = _get_indx(_lambda, sizeX, largest)\n _lambda = _lambda[ii]\n eigBlockVector = np.asarray(eigBlockVector[:, ii])\n blockVectorX = np.dot(blockVectorX, eigBlockVector)\n blockVectorAX = np.dot(blockVectorAX, eigBlockVector)\n if B is not None:\n blockVectorBX = np.dot(blockVectorBX, eigBlockVector)\n activeMask = np.ones((sizeX, ), dtype=bool)\n lambdaHistory = [_lambda]\n residualNormsHistory = []\n previousBlockSize = sizeX\n ident = np.eye(sizeX, dtype=A.dtype)\n ident0 = np.eye(sizeX, dtype=A.dtype)\n blockVectorP = None\n blockVectorAP = None\n blockVectorBP = None\n iterationNumber = -1\n restart = True\n explicitGramFlag = False\n while iterationNumber < maxIterations:\n iterationNumber += 1\n if verbosityLevel > 0:\n print('iteration %d' % iterationNumber)\n if B is not None:\n aux = blockVectorBX * _lambda[np.newaxis, :]\n else:\n aux = blockVectorX * _lambda[np.newaxis, :]\n blockVectorR = blockVectorAX - aux\n aux = np.sum(blockVectorR.conj() * blockVectorR, 0)\n residualNorms = np.sqrt(aux)\n residualNormsHistory.append(residualNorms)\n ii = np.where(residualNorms > residualTolerance, True, False)\n activeMask = activeMask & ii\n if verbosityLevel > 2:\n print(activeMask)\n currentBlockSize = activeMask.sum()\n if currentBlockSize != previousBlockSize:\n previousBlockSize = currentBlockSize\n ident = np.eye(currentBlockSize, dtype=A.dtype)\n if currentBlockSize == 0:\n break\n if verbosityLevel > 0:\n print('current block size:', currentBlockSize)\n print('eigenvalue:', _lambda)\n print('residual norms:', residualNorms)\n if verbosityLevel > 10:\n print(eigBlockVector)\n activeBlockVectorR = _as2d(blockVectorR[:, activeMask])\n if iterationNumber > 0:\n activeBlockVectorP = _as2d(blockVectorP[:, activeMask])\n activeBlockVectorAP = _as2d(blockVectorAP[:, activeMask])\n if B is not None:\n activeBlockVectorBP = _as2d(blockVectorBP[:, activeMask])\n if M is not None:\n activeBlockVectorR = M(activeBlockVectorR)\n if blockVectorY is not None:\n _applyConstraints(activeBlockVectorR, gramYBY, blockVectorBY, blockVectorY)\n if B is not None:\n activeBlockVectorR = activeBlockVectorR - np.matmul(blockVectorX, np.matmul(blockVectorBX.T.conj(), activeBlockVectorR))\n else:\n activeBlockVectorR = activeBlockVectorR - np.matmul(blockVectorX, np.matmul(blockVectorX.T.conj(), activeBlockVectorR))\n aux = _b_orthonormalize(B, activeBlockVectorR)\n (activeBlockVectorR, activeBlockVectorBR) = aux\n activeBlockVectorAR = A(activeBlockVectorR)\n if iterationNumber > 0:\n if B is not None:\n aux = _b_orthonormalize(B, activeBlockVectorP, activeBlockVectorBP, retInvR=True)\n (activeBlockVectorP, activeBlockVectorBP, invR, normal) = aux\n else:\n aux = _b_orthonormalize(B, activeBlockVectorP, retInvR=True)\n (activeBlockVectorP, _, invR, normal) = aux\n if activeBlockVectorP is not None:\n activeBlockVectorAP = activeBlockVectorAP / normal\n activeBlockVectorAP = np.dot(activeBlockVectorAP, invR)\n restart = False\n else:\n restart = True\n if activeBlockVectorAR.dtype == 'float32':\n myeps = 1\n elif activeBlockVectorR.dtype == 'float32':\n myeps = 0.0001\n else:\n myeps = 1e-08\n if residualNorms.max() > myeps and not explicitGramFlag:\n explicitGramFlag = False\n else:\n explicitGramFlag = True\n if B is None:\n blockVectorBX = blockVectorX\n activeBlockVectorBR = activeBlockVectorR\n if not restart:\n activeBlockVectorBP = activeBlockVectorP\n gramXAR = np.dot(blockVectorX.T.conj(), activeBlockVectorAR)\n gramRAR = np.dot(activeBlockVectorR.T.conj(), activeBlockVectorAR)\n if explicitGramFlag:\n gramRAR = (gramRAR + gramRAR.T.conj()) / 2\n gramXAX = np.dot(blockVectorX.T.conj(), blockVectorAX)\n gramXAX = (gramXAX + gramXAX.T.conj()) / 2\n gramXBX = np.dot(blockVectorX.T.conj(), blockVectorBX)\n gramRBR = np.dot(activeBlockVectorR.T.conj(), activeBlockVectorBR)\n gramXBR = np.dot(blockVectorX.T.conj(), activeBlockVectorBR)\n else:\n gramXAX = np.diag(_lambda)\n gramXBX = ident0\n gramRBR = ident\n gramXBR = np.zeros((sizeX, currentBlockSize), dtype=A.dtype)\n \n def _handle_gramA_gramB_verbosity(gramA, gramB):\n if verbosityLevel > 0:\n _report_nonhermitian(gramA, 'gramA')\n _report_nonhermitian(gramB, 'gramB')\n if verbosityLevel > 10:\n np.savetxt('gramA.txt', gramA)\n np.savetxt('gramB.txt', gramB)\n if not restart:\n gramXAP = np.dot(blockVectorX.T.conj(), activeBlockVectorAP)\n gramRAP = np.dot(activeBlockVectorR.T.conj(), activeBlockVectorAP)\n gramPAP = np.dot(activeBlockVectorP.T.conj(), activeBlockVectorAP)\n gramXBP = np.dot(blockVectorX.T.conj(), activeBlockVectorBP)\n gramRBP = np.dot(activeBlockVectorR.T.conj(), activeBlockVectorBP)\n if explicitGramFlag:\n gramPAP = (gramPAP + gramPAP.T.conj()) / 2\n gramPBP = np.dot(activeBlockVectorP.T.conj(), activeBlockVectorBP)\n else:\n gramPBP = ident\n gramA = bmat([[gramXAX, gramXAR, gramXAP], [gramXAR.T.conj(), gramRAR, gramRAP], [gramXAP.T.conj(), gramRAP.T.conj(), gramPAP]])\n gramB = bmat([[gramXBX, gramXBR, gramXBP], [gramXBR.T.conj(), gramRBR, gramRBP], [gramXBP.T.conj(), gramRBP.T.conj(), gramPBP]])\n _handle_gramA_gramB_verbosity(gramA, gramB)\n try:\n (_lambda, eigBlockVector) = eigh(gramA, gramB, check_finite=False)\n except LinAlgError:\n restart = True\n if restart:\n gramA = bmat([[gramXAX, gramXAR], [gramXAR.T.conj(), gramRAR]])\n gramB = bmat([[gramXBX, gramXBR], [gramXBR.T.conj(), gramRBR]])\n _handle_gramA_gramB_verbosity(gramA, gramB)\n try:\n (_lambda, eigBlockVector) = eigh(gramA, gramB, check_finite=False)\n except LinAlgError as e:\n raise ValueError('eigh has failed in lobpcg iterations') from e\n ii = _get_indx(_lambda, sizeX, largest)\n if verbosityLevel > 10:\n print(ii)\n print(_lambda)\n _lambda = _lambda[ii]\n eigBlockVector = eigBlockVector[:, ii]\n lambdaHistory.append(_lambda)\n if verbosityLevel > 10:\n print('lambda:', _lambda)\n if verbosityLevel > 10:\n print(eigBlockVector)\n if B is not None:\n if not restart:\n eigBlockVectorX = eigBlockVector[:sizeX]\n eigBlockVectorR = eigBlockVector[sizeX:sizeX + currentBlockSize]\n eigBlockVectorP = eigBlockVector[sizeX + currentBlockSize:]\n pp = np.dot(activeBlockVectorR, eigBlockVectorR)\n pp += np.dot(activeBlockVectorP, eigBlockVectorP)\n app = np.dot(activeBlockVectorAR, eigBlockVectorR)\n app += np.dot(activeBlockVectorAP, eigBlockVectorP)\n bpp = np.dot(activeBlockVectorBR, eigBlockVectorR)\n bpp += np.dot(activeBlockVectorBP, eigBlockVectorP)\n else:\n eigBlockVectorX = eigBlockVector[:sizeX]\n eigBlockVectorR = eigBlockVector[sizeX:]\n pp = np.dot(activeBlockVectorR, eigBlockVectorR)\n app = np.dot(activeBlockVectorAR, eigBlockVectorR)\n bpp = np.dot(activeBlockVectorBR, eigBlockVectorR)\n if verbosityLevel > 10:\n print(pp)\n print(app)\n print(bpp)\n blockVectorX = np.dot(blockVectorX, eigBlockVectorX) + pp\n blockVectorAX = np.dot(blockVectorAX, eigBlockVectorX) + app\n blockVectorBX = np.dot(blockVectorBX, eigBlockVectorX) + bpp\n (blockVectorP, blockVectorAP, blockVectorBP) = (pp, app, bpp)\n else:\n if not restart:\n eigBlockVectorX = eigBlockVector[:sizeX]\n eigBlockVectorR = eigBlockVector[sizeX:sizeX + currentBlockSize]\n eigBlockVectorP = eigBlockVector[sizeX + currentBlockSize:]\n pp = np.dot(activeBlockVectorR, eigBlockVectorR)\n pp += np.dot(activeBlockVectorP, eigBlockVectorP)\n app = np.dot(activeBlockVectorAR, eigBlockVectorR)\n app += np.dot(activeBlockVectorAP, eigBlockVectorP)\n else:\n eigBlockVectorX = eigBlockVector[:sizeX]\n eigBlockVectorR = eigBlockVector[sizeX:]\n pp = np.dot(activeBlockVectorR, eigBlockVectorR)\n app = np.dot(activeBlockVectorAR, eigBlockVectorR)\n if verbosityLevel > 10:\n print(pp)\n print(app)\n blockVectorX = np.dot(blockVectorX, eigBlockVectorX) + pp\n blockVectorAX = np.dot(blockVectorAX, eigBlockVectorX) + app\n (blockVectorP, blockVectorAP) = (pp, app)\n if B is not None:\n aux = blockVectorBX * _lambda[np.newaxis, :]\n else:\n aux = blockVectorX * _lambda[np.newaxis, :]\n blockVectorR = blockVectorAX - aux\n aux = np.sum(blockVectorR.conj() * blockVectorR, 0)\n residualNorms = np.sqrt(aux)\n if verbosityLevel > 0:\n print('final eigenvalue:', _lambda)\n print('final residual norms:', residualNorms)\n if retLambdaHistory:\n if retResidualNormsHistory:\n return _lambda, blockVectorX, lambdaHistory, residualNormsHistory\n else:\n return _lambda, blockVectorX, lambdaHistory\n elif retResidualNormsHistory:\n return _lambda, blockVectorX, residualNormsHistory\n else:\n return _lambda, blockVectorX" + "docstring": "Locally Optimal Block Preconditioned Conjugate Gradient Method (LOBPCG)\n\nLOBPCG is a preconditioned eigensolver for large symmetric positive\ndefinite (SPD) generalized eigenproblems.\n\nParameters\n----------\nA : {sparse matrix, dense matrix, LinearOperator}\n The symmetric linear operator of the problem, usually a\n sparse matrix. Often called the \"stiffness matrix\".\nX : ndarray, float32 or float64\n Initial approximation to the ``k`` eigenvectors (non-sparse). If `A`\n has ``shape=(n,n)`` then `X` should have shape ``shape=(n,k)``.\nB : {dense matrix, sparse matrix, LinearOperator}, optional\n The right hand side operator in a generalized eigenproblem.\n By default, ``B = Identity``. Often called the \"mass matrix\".\nM : {dense matrix, sparse matrix, LinearOperator}, optional\n Preconditioner to `A`; by default ``M = Identity``.\n `M` should approximate the inverse of `A`.\nY : ndarray, float32 or float64, optional\n n-by-sizeY matrix of constraints (non-sparse), sizeY < n\n The iterations will be performed in the B-orthogonal complement\n of the column-space of Y. Y must be full rank.\ntol : scalar, optional\n Solver tolerance (stopping criterion).\n The default is ``tol=n*sqrt(eps)``.\nmaxiter : int, optional\n Maximum number of iterations. The default is ``maxiter = 20``.\nlargest : bool, optional\n When True, solve for the largest eigenvalues, otherwise the smallest.\nverbosityLevel : int, optional\n Controls solver output. The default is ``verbosityLevel=0``.\nretLambdaHistory : bool, optional\n Whether to return eigenvalue history. Default is False.\nretResidualNormsHistory : bool, optional\n Whether to return history of residual norms. Default is False.\n\nReturns\n-------\nw : ndarray\n Array of ``k`` eigenvalues\nv : ndarray\n An array of ``k`` eigenvectors. `v` has the same shape as `X`.\nlambdas : list of ndarray, optional\n The eigenvalue history, if `retLambdaHistory` is True.\nrnorms : list of ndarray, optional\n The history of residual norms, if `retResidualNormsHistory` is True.\n\nNotes\n-----\nIf both ``retLambdaHistory`` and ``retResidualNormsHistory`` are True,\nthe return tuple has the following format\n``(lambda, V, lambda history, residual norms history)``.\n\nIn the following ``n`` denotes the matrix size and ``m`` the number\nof required eigenvalues (smallest or largest).\n\nThe LOBPCG code internally solves eigenproblems of the size ``3m`` on every\niteration by calling the \"standard\" dense eigensolver, so if ``m`` is not\nsmall enough compared to ``n``, it does not make sense to call the LOBPCG\ncode, but rather one should use the \"standard\" eigensolver, e.g. numpy or\nscipy function in this case.\nIf one calls the LOBPCG algorithm for ``5m > n``, it will most likely break\ninternally, so the code tries to call the standard function instead.\n\nIt is not that ``n`` should be large for the LOBPCG to work, but rather the\nratio ``n / m`` should be large. It you call LOBPCG with ``m=1``\nand ``n=10``, it works though ``n`` is small. The method is intended\nfor extremely large ``n / m`` [4]_.\n\nThe convergence speed depends basically on two factors:\n\n1. How well relatively separated the seeking eigenvalues are from the rest\n of the eigenvalues. One can try to vary ``m`` to make this better.\n\n2. How well conditioned the problem is. This can be changed by using proper\n preconditioning. For example, a rod vibration test problem (under tests\n directory) is ill-conditioned for large ``n``, so convergence will be\n slow, unless efficient preconditioning is used. For this specific\n problem, a good simple preconditioner function would be a linear solve\n for `A`, which is easy to code since A is tridiagonal.\n\nReferences\n----------\n.. [1] A. V. Knyazev (2001),\n Toward the Optimal Preconditioned Eigensolver: Locally Optimal\n Block Preconditioned Conjugate Gradient Method.\n SIAM Journal on Scientific Computing 23, no. 2,\n pp. 517-541. :doi:`10.1137/S1064827500366124`\n\n.. [2] A. V. Knyazev, I. Lashuk, M. E. Argentati, and E. Ovchinnikov\n (2007), Block Locally Optimal Preconditioned Eigenvalue Xolvers\n (BLOPEX) in hypre and PETSc. :arxiv:`0705.2626`\n\n.. [3] A. V. Knyazev's C and MATLAB implementations:\n https://bitbucket.org/joseroman/blopex\n\n.. [4] S. Yamada, T. Imamura, T. Kano, and M. Machida (2006),\n High-performance computing for exact numerical approaches to\n quantum many-body problems on the earth simulator. In Proceedings\n of the 2006 ACM/IEEE Conference on Supercomputing.\n :doi:`10.1145/1188455.1188504`\n\nExamples\n--------\n\nSolve ``A x = lambda x`` with constraints and preconditioning.\n\n>>> import numpy as np\n>>> from scipy.sparse import spdiags, issparse\n>>> from scipy.sparse.linalg import lobpcg, LinearOperator\n>>> n = 100\n>>> vals = np.arange(1, n + 1)\n>>> A = spdiags(vals, 0, n, n)\n>>> A.toarray()\narray([[ 1., 0., 0., ..., 0., 0., 0.],\n [ 0., 2., 0., ..., 0., 0., 0.],\n [ 0., 0., 3., ..., 0., 0., 0.],\n ...,\n [ 0., 0., 0., ..., 98., 0., 0.],\n [ 0., 0., 0., ..., 0., 99., 0.],\n [ 0., 0., 0., ..., 0., 0., 100.]])\n\nConstraints:\n\n>>> Y = np.eye(n, 3)\n\nInitial guess for eigenvectors, should have linearly independent\ncolumns. Column dimension = number of requested eigenvalues.\n\n>>> rng = np.random.default_rng()\n>>> X = rng.random((n, 3))\n\nPreconditioner in the inverse of A in this example:\n\n>>> invA = spdiags([1./vals], 0, n, n)\n\nThe preconditiner must be defined by a function:\n\n>>> def precond( x ):\n... return invA @ x\n\nThe argument x of the preconditioner function is a matrix inside `lobpcg`,\nthus the use of matrix-matrix product ``@``.\n\nThe preconditioner function is passed to lobpcg as a `LinearOperator`:\n\n>>> M = LinearOperator(matvec=precond, matmat=precond,\n... shape=(n, n), dtype=float)\n\nLet us now solve the eigenvalue problem for the matrix A:\n\n>>> eigenvalues, _ = lobpcg(A, X, Y=Y, M=M, largest=False)\n>>> eigenvalues\narray([4., 5., 6.])\n\nNote that the vectors passed in Y are the eigenvectors of the 3 smallest\neigenvalues. The results returned are orthogonal to those.", + "source_code": "\ndef lobpcg(A, X, B=None, M=None, Y=None, tol=None, maxiter=None, largest=True, verbosityLevel=0, retLambdaHistory=False, retResidualNormsHistory=False):\n \"\"\"Locally Optimal Block Preconditioned Conjugate Gradient Method (LOBPCG)\n\n LOBPCG is a preconditioned eigensolver for large symmetric positive\n definite (SPD) generalized eigenproblems.\n\n Parameters\n ----------\n A : {sparse matrix, dense matrix, LinearOperator}\n The symmetric linear operator of the problem, usually a\n sparse matrix. Often called the \"stiffness matrix\".\n X : ndarray, float32 or float64\n Initial approximation to the ``k`` eigenvectors (non-sparse). If `A`\n has ``shape=(n,n)`` then `X` should have shape ``shape=(n,k)``.\n B : {dense matrix, sparse matrix, LinearOperator}, optional\n The right hand side operator in a generalized eigenproblem.\n By default, ``B = Identity``. Often called the \"mass matrix\".\n M : {dense matrix, sparse matrix, LinearOperator}, optional\n Preconditioner to `A`; by default ``M = Identity``.\n `M` should approximate the inverse of `A`.\n Y : ndarray, float32 or float64, optional\n n-by-sizeY matrix of constraints (non-sparse), sizeY < n\n The iterations will be performed in the B-orthogonal complement\n of the column-space of Y. Y must be full rank.\n tol : scalar, optional\n Solver tolerance (stopping criterion).\n The default is ``tol=n*sqrt(eps)``.\n maxiter : int, optional\n Maximum number of iterations. The default is ``maxiter = 20``.\n largest : bool, optional\n When True, solve for the largest eigenvalues, otherwise the smallest.\n verbosityLevel : int, optional\n Controls solver output. The default is ``verbosityLevel=0``.\n retLambdaHistory : bool, optional\n Whether to return eigenvalue history. Default is False.\n retResidualNormsHistory : bool, optional\n Whether to return history of residual norms. Default is False.\n\n Returns\n -------\n w : ndarray\n Array of ``k`` eigenvalues\n v : ndarray\n An array of ``k`` eigenvectors. `v` has the same shape as `X`.\n lambdas : list of ndarray, optional\n The eigenvalue history, if `retLambdaHistory` is True.\n rnorms : list of ndarray, optional\n The history of residual norms, if `retResidualNormsHistory` is True.\n\n Notes\n -----\n If both ``retLambdaHistory`` and ``retResidualNormsHistory`` are True,\n the return tuple has the following format\n ``(lambda, V, lambda history, residual norms history)``.\n\n In the following ``n`` denotes the matrix size and ``m`` the number\n of required eigenvalues (smallest or largest).\n\n The LOBPCG code internally solves eigenproblems of the size ``3m`` on every\n iteration by calling the \"standard\" dense eigensolver, so if ``m`` is not\n small enough compared to ``n``, it does not make sense to call the LOBPCG\n code, but rather one should use the \"standard\" eigensolver, e.g. numpy or\n scipy function in this case.\n If one calls the LOBPCG algorithm for ``5m > n``, it will most likely break\n internally, so the code tries to call the standard function instead.\n\n It is not that ``n`` should be large for the LOBPCG to work, but rather the\n ratio ``n / m`` should be large. It you call LOBPCG with ``m=1``\n and ``n=10``, it works though ``n`` is small. The method is intended\n for extremely large ``n / m`` [4]_.\n\n The convergence speed depends basically on two factors:\n\n 1. How well relatively separated the seeking eigenvalues are from the rest\n of the eigenvalues. One can try to vary ``m`` to make this better.\n\n 2. How well conditioned the problem is. This can be changed by using proper\n preconditioning. For example, a rod vibration test problem (under tests\n directory) is ill-conditioned for large ``n``, so convergence will be\n slow, unless efficient preconditioning is used. For this specific\n problem, a good simple preconditioner function would be a linear solve\n for `A`, which is easy to code since A is tridiagonal.\n\n References\n ----------\n .. [1] A. V. Knyazev (2001),\n Toward the Optimal Preconditioned Eigensolver: Locally Optimal\n Block Preconditioned Conjugate Gradient Method.\n SIAM Journal on Scientific Computing 23, no. 2,\n pp. 517-541. :doi:`10.1137/S1064827500366124`\n\n .. [2] A. V. Knyazev, I. Lashuk, M. E. Argentati, and E. Ovchinnikov\n (2007), Block Locally Optimal Preconditioned Eigenvalue Xolvers\n (BLOPEX) in hypre and PETSc. :arxiv:`0705.2626`\n\n .. [3] A. V. Knyazev's C and MATLAB implementations:\n https://bitbucket.org/joseroman/blopex\n\n .. [4] S. Yamada, T. Imamura, T. Kano, and M. Machida (2006),\n High-performance computing for exact numerical approaches to\n quantum many-body problems on the earth simulator. In Proceedings\n of the 2006 ACM/IEEE Conference on Supercomputing.\n :doi:`10.1145/1188455.1188504`\n\n Examples\n --------\n\n Solve ``A x = lambda x`` with constraints and preconditioning.\n\n >>> import numpy as np\n >>> from scipy.sparse import spdiags, issparse\n >>> from scipy.sparse.linalg import lobpcg, LinearOperator\n >>> n = 100\n >>> vals = np.arange(1, n + 1)\n >>> A = spdiags(vals, 0, n, n)\n >>> A.toarray()\n array([[ 1., 0., 0., ..., 0., 0., 0.],\n [ 0., 2., 0., ..., 0., 0., 0.],\n [ 0., 0., 3., ..., 0., 0., 0.],\n ...,\n [ 0., 0., 0., ..., 98., 0., 0.],\n [ 0., 0., 0., ..., 0., 99., 0.],\n [ 0., 0., 0., ..., 0., 0., 100.]])\n\n Constraints:\n\n >>> Y = np.eye(n, 3)\n\n Initial guess for eigenvectors, should have linearly independent\n columns. Column dimension = number of requested eigenvalues.\n\n >>> rng = np.random.default_rng()\n >>> X = rng.random((n, 3))\n\n Preconditioner in the inverse of A in this example:\n\n >>> invA = spdiags([1./vals], 0, n, n)\n\n The preconditiner must be defined by a function:\n\n >>> def precond( x ):\n ... return invA @ x\n\n The argument x of the preconditioner function is a matrix inside `lobpcg`,\n thus the use of matrix-matrix product ``@``.\n\n The preconditioner function is passed to lobpcg as a `LinearOperator`:\n\n >>> M = LinearOperator(matvec=precond, matmat=precond,\n ... shape=(n, n), dtype=float)\n\n Let us now solve the eigenvalue problem for the matrix A:\n\n >>> eigenvalues, _ = lobpcg(A, X, Y=Y, M=M, largest=False)\n >>> eigenvalues\n array([4., 5., 6.])\n\n Note that the vectors passed in Y are the eigenvectors of the 3 smallest\n eigenvalues. The results returned are orthogonal to those.\n\n \"\"\"\n blockVectorX = X\n blockVectorY = Y\n residualTolerance = tol\n if maxiter is None:\n maxiter = 20\n if blockVectorY is not None:\n sizeY = blockVectorY.shape[1]\n else:\n sizeY = 0\n if len(blockVectorX.shape) != 2:\n raise ValueError('expected rank-2 array for argument X')\n (n, sizeX) = blockVectorX.shape\n if verbosityLevel:\n aux = 'Solving '\n if B is None:\n aux += 'standard'\n else:\n aux += 'generalized'\n aux += ' eigenvalue problem with'\n if M is None:\n aux += 'out'\n aux += ' preconditioning\\n\\n'\n aux += 'matrix size %d\\n' % n\n aux += 'block size %d\\n\\n' % sizeX\n if blockVectorY is None:\n aux += 'No constraints\\n\\n'\n elif sizeY > 1:\n aux += '%d constraints\\n\\n' % sizeY\n else:\n aux += '%d constraint\\n\\n' % sizeY\n print(aux)\n A = _makeOperator(A, (n, n))\n B = _makeOperator(B, (n, n))\n M = _makeOperator(M, (n, n))\n if n - sizeY < 5 * sizeX:\n sizeX = min(sizeX, n)\n if blockVectorY is not None:\n raise NotImplementedError('The dense eigensolver does not support constraints.')\n if largest:\n eigvals = (n - sizeX, n - 1)\n else:\n eigvals = (0, sizeX - 1)\n A_dense = A(np.eye(n, dtype=A.dtype))\n B_dense = None if B is None else B(np.eye(n, dtype=B.dtype))\n (vals, vecs) = eigh(A_dense, B_dense, eigvals=eigvals, check_finite=False)\n if largest:\n vals = vals[::-1]\n vecs = vecs[:, ::-1]\n return vals, vecs\n if residualTolerance is None or residualTolerance <= 0.0:\n residualTolerance = np.sqrt(1e-15) * n\n if blockVectorY is not None:\n if B is not None:\n blockVectorBY = B(blockVectorY)\n else:\n blockVectorBY = blockVectorY\n gramYBY = np.dot(blockVectorY.T.conj(), blockVectorBY)\n try:\n gramYBY = cho_factor(gramYBY)\n except LinAlgError as e:\n raise ValueError('cannot handle linearly dependent constraints') from e\n _applyConstraints(blockVectorX, gramYBY, blockVectorBY, blockVectorY)\n (blockVectorX, blockVectorBX) = _b_orthonormalize(B, blockVectorX)\n blockVectorAX = A(blockVectorX)\n gramXAX = np.dot(blockVectorX.T.conj(), blockVectorAX)\n (_lambda, eigBlockVector) = eigh(gramXAX, check_finite=False)\n ii = _get_indx(_lambda, sizeX, largest)\n _lambda = _lambda[ii]\n eigBlockVector = np.asarray(eigBlockVector[:, ii])\n blockVectorX = np.dot(blockVectorX, eigBlockVector)\n blockVectorAX = np.dot(blockVectorAX, eigBlockVector)\n if B is not None:\n blockVectorBX = np.dot(blockVectorBX, eigBlockVector)\n activeMask = np.ones((sizeX, ), dtype=bool)\n lambdaHistory = [_lambda]\n residualNormsHistory = []\n previousBlockSize = sizeX\n ident = np.eye(sizeX, dtype=A.dtype)\n ident0 = np.eye(sizeX, dtype=A.dtype)\n blockVectorP = None\n blockVectorAP = None\n blockVectorBP = None\n iterationNumber = -1\n restart = True\n explicitGramFlag = False\n while iterationNumber < maxiter:\n iterationNumber += 1\n if verbosityLevel > 0:\n print('iteration %d' % iterationNumber)\n if B is not None:\n aux = blockVectorBX * _lambda[np.newaxis, :]\n else:\n aux = blockVectorX * _lambda[np.newaxis, :]\n blockVectorR = blockVectorAX - aux\n aux = np.sum(blockVectorR.conj() * blockVectorR, 0)\n residualNorms = np.sqrt(aux)\n residualNormsHistory.append(residualNorms)\n ii = np.where(residualNorms > residualTolerance, True, False)\n activeMask = activeMask & ii\n if verbosityLevel > 2:\n print(activeMask)\n currentBlockSize = activeMask.sum()\n if currentBlockSize != previousBlockSize:\n previousBlockSize = currentBlockSize\n ident = np.eye(currentBlockSize, dtype=A.dtype)\n if currentBlockSize == 0:\n break\n if verbosityLevel > 0:\n print('current block size:', currentBlockSize)\n print('eigenvalue:', _lambda)\n print('residual norms:', residualNorms)\n if verbosityLevel > 10:\n print(eigBlockVector)\n activeBlockVectorR = _as2d(blockVectorR[:, activeMask])\n if iterationNumber > 0:\n activeBlockVectorP = _as2d(blockVectorP[:, activeMask])\n activeBlockVectorAP = _as2d(blockVectorAP[:, activeMask])\n if B is not None:\n activeBlockVectorBP = _as2d(blockVectorBP[:, activeMask])\n if M is not None:\n activeBlockVectorR = M(activeBlockVectorR)\n if blockVectorY is not None:\n _applyConstraints(activeBlockVectorR, gramYBY, blockVectorBY, blockVectorY)\n if B is not None:\n activeBlockVectorR = activeBlockVectorR - np.matmul(blockVectorX, np.matmul(blockVectorBX.T.conj(), activeBlockVectorR))\n else:\n activeBlockVectorR = activeBlockVectorR - np.matmul(blockVectorX, np.matmul(blockVectorX.T.conj(), activeBlockVectorR))\n aux = _b_orthonormalize(B, activeBlockVectorR)\n (activeBlockVectorR, activeBlockVectorBR) = aux\n activeBlockVectorAR = A(activeBlockVectorR)\n if iterationNumber > 0:\n if B is not None:\n aux = _b_orthonormalize(B, activeBlockVectorP, activeBlockVectorBP, retInvR=True)\n (activeBlockVectorP, activeBlockVectorBP, invR, normal) = aux\n else:\n aux = _b_orthonormalize(B, activeBlockVectorP, retInvR=True)\n (activeBlockVectorP, _, invR, normal) = aux\n if activeBlockVectorP is not None:\n activeBlockVectorAP = activeBlockVectorAP / normal\n activeBlockVectorAP = np.dot(activeBlockVectorAP, invR)\n restart = False\n else:\n restart = True\n if activeBlockVectorAR.dtype == 'float32':\n myeps = 1\n elif activeBlockVectorR.dtype == 'float32':\n myeps = 0.0001\n else:\n myeps = 1e-08\n if residualNorms.max() > myeps and not explicitGramFlag:\n explicitGramFlag = False\n else:\n explicitGramFlag = True\n if B is None:\n blockVectorBX = blockVectorX\n activeBlockVectorBR = activeBlockVectorR\n if not restart:\n activeBlockVectorBP = activeBlockVectorP\n gramXAR = np.dot(blockVectorX.T.conj(), activeBlockVectorAR)\n gramRAR = np.dot(activeBlockVectorR.T.conj(), activeBlockVectorAR)\n if explicitGramFlag:\n gramRAR = (gramRAR + gramRAR.T.conj()) / 2\n gramXAX = np.dot(blockVectorX.T.conj(), blockVectorAX)\n gramXAX = (gramXAX + gramXAX.T.conj()) / 2\n gramXBX = np.dot(blockVectorX.T.conj(), blockVectorBX)\n gramRBR = np.dot(activeBlockVectorR.T.conj(), activeBlockVectorBR)\n gramXBR = np.dot(blockVectorX.T.conj(), activeBlockVectorBR)\n else:\n gramXAX = np.diag(_lambda)\n gramXBX = ident0\n gramRBR = ident\n gramXBR = np.zeros((sizeX, currentBlockSize), dtype=A.dtype)\n \n def _handle_gramA_gramB_verbosity(gramA, gramB):\n if verbosityLevel > 0:\n _report_nonhermitian(gramA, 'gramA')\n _report_nonhermitian(gramB, 'gramB')\n if verbosityLevel > 10:\n np.savetxt('gramA.txt', gramA)\n np.savetxt('gramB.txt', gramB)\n if not restart:\n gramXAP = np.dot(blockVectorX.T.conj(), activeBlockVectorAP)\n gramRAP = np.dot(activeBlockVectorR.T.conj(), activeBlockVectorAP)\n gramPAP = np.dot(activeBlockVectorP.T.conj(), activeBlockVectorAP)\n gramXBP = np.dot(blockVectorX.T.conj(), activeBlockVectorBP)\n gramRBP = np.dot(activeBlockVectorR.T.conj(), activeBlockVectorBP)\n if explicitGramFlag:\n gramPAP = (gramPAP + gramPAP.T.conj()) / 2\n gramPBP = np.dot(activeBlockVectorP.T.conj(), activeBlockVectorBP)\n else:\n gramPBP = ident\n gramA = bmat([[gramXAX, gramXAR, gramXAP], [gramXAR.T.conj(), gramRAR, gramRAP], [gramXAP.T.conj(), gramRAP.T.conj(), gramPAP]])\n gramB = bmat([[gramXBX, gramXBR, gramXBP], [gramXBR.T.conj(), gramRBR, gramRBP], [gramXBP.T.conj(), gramRBP.T.conj(), gramPBP]])\n _handle_gramA_gramB_verbosity(gramA, gramB)\n try:\n (_lambda, eigBlockVector) = eigh(gramA, gramB, check_finite=False)\n except LinAlgError:\n restart = True\n if restart:\n gramA = bmat([[gramXAX, gramXAR], [gramXAR.T.conj(), gramRAR]])\n gramB = bmat([[gramXBX, gramXBR], [gramXBR.T.conj(), gramRBR]])\n _handle_gramA_gramB_verbosity(gramA, gramB)\n try:\n (_lambda, eigBlockVector) = eigh(gramA, gramB, check_finite=False)\n except LinAlgError as e:\n raise ValueError('eigh has failed in lobpcg iterations') from e\n ii = _get_indx(_lambda, sizeX, largest)\n if verbosityLevel > 10:\n print(ii)\n print(_lambda)\n _lambda = _lambda[ii]\n eigBlockVector = eigBlockVector[:, ii]\n lambdaHistory.append(_lambda)\n if verbosityLevel > 10:\n print('lambda:', _lambda)\n if verbosityLevel > 10:\n print(eigBlockVector)\n if B is not None:\n if not restart:\n eigBlockVectorX = eigBlockVector[:sizeX]\n eigBlockVectorR = eigBlockVector[sizeX:sizeX + currentBlockSize]\n eigBlockVectorP = eigBlockVector[sizeX + currentBlockSize:]\n pp = np.dot(activeBlockVectorR, eigBlockVectorR)\n pp += np.dot(activeBlockVectorP, eigBlockVectorP)\n app = np.dot(activeBlockVectorAR, eigBlockVectorR)\n app += np.dot(activeBlockVectorAP, eigBlockVectorP)\n bpp = np.dot(activeBlockVectorBR, eigBlockVectorR)\n bpp += np.dot(activeBlockVectorBP, eigBlockVectorP)\n else:\n eigBlockVectorX = eigBlockVector[:sizeX]\n eigBlockVectorR = eigBlockVector[sizeX:]\n pp = np.dot(activeBlockVectorR, eigBlockVectorR)\n app = np.dot(activeBlockVectorAR, eigBlockVectorR)\n bpp = np.dot(activeBlockVectorBR, eigBlockVectorR)\n if verbosityLevel > 10:\n print(pp)\n print(app)\n print(bpp)\n blockVectorX = np.dot(blockVectorX, eigBlockVectorX) + pp\n blockVectorAX = np.dot(blockVectorAX, eigBlockVectorX) + app\n blockVectorBX = np.dot(blockVectorBX, eigBlockVectorX) + bpp\n (blockVectorP, blockVectorAP, blockVectorBP) = (pp, app, bpp)\n else:\n if not restart:\n eigBlockVectorX = eigBlockVector[:sizeX]\n eigBlockVectorR = eigBlockVector[sizeX:sizeX + currentBlockSize]\n eigBlockVectorP = eigBlockVector[sizeX + currentBlockSize:]\n pp = np.dot(activeBlockVectorR, eigBlockVectorR)\n pp += np.dot(activeBlockVectorP, eigBlockVectorP)\n app = np.dot(activeBlockVectorAR, eigBlockVectorR)\n app += np.dot(activeBlockVectorAP, eigBlockVectorP)\n else:\n eigBlockVectorX = eigBlockVector[:sizeX]\n eigBlockVectorR = eigBlockVector[sizeX:]\n pp = np.dot(activeBlockVectorR, eigBlockVectorR)\n app = np.dot(activeBlockVectorAR, eigBlockVectorR)\n if verbosityLevel > 10:\n print(pp)\n print(app)\n blockVectorX = np.dot(blockVectorX, eigBlockVectorX) + pp\n blockVectorAX = np.dot(blockVectorAX, eigBlockVectorX) + app\n (blockVectorP, blockVectorAP) = (pp, app)\n if B is not None:\n aux = blockVectorBX * _lambda[np.newaxis, :]\n else:\n aux = blockVectorX * _lambda[np.newaxis, :]\n blockVectorR = blockVectorAX - aux\n aux = np.sum(blockVectorR.conj() * blockVectorR, 0)\n residualNorms = np.sqrt(aux)\n if verbosityLevel > 0:\n print('final eigenvalue:', _lambda)\n print('final residual norms:', residualNorms)\n if retLambdaHistory:\n if retResidualNormsHistory:\n return _lambda, blockVectorX, lambdaHistory, residualNormsHistory\n else:\n return _lambda, blockVectorX, lambdaHistory\n elif retResidualNormsHistory:\n return _lambda, blockVectorX, residualNormsHistory\n else:\n return _lambda, blockVectorX" }, { "name": "__eq__", + "unique_name": "__eq__", "qname": "sklearn.externals._packaging._structures.InfinityType.__eq__", + "unique_qname": "sklearn.externals._packaging._structures.InfinityType.__eq__", "decorators": [], "parameters": [ { @@ -74052,7 +76006,9 @@ }, { "name": "__ge__", + "unique_name": "__ge__", "qname": "sklearn.externals._packaging._structures.InfinityType.__ge__", + "unique_qname": "sklearn.externals._packaging._structures.InfinityType.__ge__", "decorators": [], "parameters": [ { @@ -74084,7 +76040,9 @@ }, { "name": "__gt__", + "unique_name": "__gt__", "qname": "sklearn.externals._packaging._structures.InfinityType.__gt__", + "unique_qname": "sklearn.externals._packaging._structures.InfinityType.__gt__", "decorators": [], "parameters": [ { @@ -74116,7 +76074,9 @@ }, { "name": "__hash__", + "unique_name": "__hash__", "qname": "sklearn.externals._packaging._structures.InfinityType.__hash__", + "unique_qname": "sklearn.externals._packaging._structures.InfinityType.__hash__", "decorators": [], "parameters": [ { @@ -74138,7 +76098,9 @@ }, { "name": "__le__", + "unique_name": "__le__", "qname": "sklearn.externals._packaging._structures.InfinityType.__le__", + "unique_qname": "sklearn.externals._packaging._structures.InfinityType.__le__", "decorators": [], "parameters": [ { @@ -74170,7 +76132,9 @@ }, { "name": "__lt__", + "unique_name": "__lt__", "qname": "sklearn.externals._packaging._structures.InfinityType.__lt__", + "unique_qname": "sklearn.externals._packaging._structures.InfinityType.__lt__", "decorators": [], "parameters": [ { @@ -74202,7 +76166,9 @@ }, { "name": "__ne__", + "unique_name": "__ne__", "qname": "sklearn.externals._packaging._structures.InfinityType.__ne__", + "unique_qname": "sklearn.externals._packaging._structures.InfinityType.__ne__", "decorators": [], "parameters": [ { @@ -74234,7 +76200,9 @@ }, { "name": "__neg__", + "unique_name": "__neg__", "qname": "sklearn.externals._packaging._structures.InfinityType.__neg__", + "unique_qname": "sklearn.externals._packaging._structures.InfinityType.__neg__", "decorators": [], "parameters": [ { @@ -74256,7 +76224,9 @@ }, { "name": "__repr__", + "unique_name": "__repr__", "qname": "sklearn.externals._packaging._structures.InfinityType.__repr__", + "unique_qname": "sklearn.externals._packaging._structures.InfinityType.__repr__", "decorators": [], "parameters": [ { @@ -74278,7 +76248,9 @@ }, { "name": "__eq__", + "unique_name": "__eq__", "qname": "sklearn.externals._packaging._structures.NegativeInfinityType.__eq__", + "unique_qname": "sklearn.externals._packaging._structures.NegativeInfinityType.__eq__", "decorators": [], "parameters": [ { @@ -74310,7 +76282,9 @@ }, { "name": "__ge__", + "unique_name": "__ge__", "qname": "sklearn.externals._packaging._structures.NegativeInfinityType.__ge__", + "unique_qname": "sklearn.externals._packaging._structures.NegativeInfinityType.__ge__", "decorators": [], "parameters": [ { @@ -74342,7 +76316,9 @@ }, { "name": "__gt__", + "unique_name": "__gt__", "qname": "sklearn.externals._packaging._structures.NegativeInfinityType.__gt__", + "unique_qname": "sklearn.externals._packaging._structures.NegativeInfinityType.__gt__", "decorators": [], "parameters": [ { @@ -74374,7 +76350,9 @@ }, { "name": "__hash__", + "unique_name": "__hash__", "qname": "sklearn.externals._packaging._structures.NegativeInfinityType.__hash__", + "unique_qname": "sklearn.externals._packaging._structures.NegativeInfinityType.__hash__", "decorators": [], "parameters": [ { @@ -74396,7 +76374,9 @@ }, { "name": "__le__", + "unique_name": "__le__", "qname": "sklearn.externals._packaging._structures.NegativeInfinityType.__le__", + "unique_qname": "sklearn.externals._packaging._structures.NegativeInfinityType.__le__", "decorators": [], "parameters": [ { @@ -74428,7 +76408,9 @@ }, { "name": "__lt__", + "unique_name": "__lt__", "qname": "sklearn.externals._packaging._structures.NegativeInfinityType.__lt__", + "unique_qname": "sklearn.externals._packaging._structures.NegativeInfinityType.__lt__", "decorators": [], "parameters": [ { @@ -74460,7 +76442,9 @@ }, { "name": "__ne__", + "unique_name": "__ne__", "qname": "sklearn.externals._packaging._structures.NegativeInfinityType.__ne__", + "unique_qname": "sklearn.externals._packaging._structures.NegativeInfinityType.__ne__", "decorators": [], "parameters": [ { @@ -74492,7 +76476,9 @@ }, { "name": "__neg__", + "unique_name": "__neg__", "qname": "sklearn.externals._packaging._structures.NegativeInfinityType.__neg__", + "unique_qname": "sklearn.externals._packaging._structures.NegativeInfinityType.__neg__", "decorators": [], "parameters": [ { @@ -74514,7 +76500,9 @@ }, { "name": "__repr__", + "unique_name": "__repr__", "qname": "sklearn.externals._packaging._structures.NegativeInfinityType.__repr__", + "unique_qname": "sklearn.externals._packaging._structures.NegativeInfinityType.__repr__", "decorators": [], "parameters": [ { @@ -74536,7 +76524,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.externals._packaging.version.LegacyVersion.__init__", + "unique_qname": "sklearn.externals._packaging.version.LegacyVersion.__init__", "decorators": [], "parameters": [ { @@ -74568,7 +76558,9 @@ }, { "name": "__repr__", + "unique_name": "__repr__", "qname": "sklearn.externals._packaging.version.LegacyVersion.__repr__", + "unique_qname": "sklearn.externals._packaging.version.LegacyVersion.__repr__", "decorators": [], "parameters": [ { @@ -74590,7 +76582,9 @@ }, { "name": "__str__", + "unique_name": "__str__", "qname": "sklearn.externals._packaging.version.LegacyVersion.__str__", + "unique_qname": "sklearn.externals._packaging.version.LegacyVersion.__str__", "decorators": [], "parameters": [ { @@ -74612,7 +76606,9 @@ }, { "name": "base_version", + "unique_name": "base_version@getter", "qname": "sklearn.externals._packaging.version.LegacyVersion.base_version", + "unique_qname": "sklearn.externals._packaging.version.LegacyVersion.base_version@getter", "decorators": ["property"], "parameters": [ { @@ -74634,7 +76630,9 @@ }, { "name": "dev", + "unique_name": "dev@getter", "qname": "sklearn.externals._packaging.version.LegacyVersion.dev", + "unique_qname": "sklearn.externals._packaging.version.LegacyVersion.dev@getter", "decorators": ["property"], "parameters": [ { @@ -74656,7 +76654,9 @@ }, { "name": "epoch", + "unique_name": "epoch@getter", "qname": "sklearn.externals._packaging.version.LegacyVersion.epoch", + "unique_qname": "sklearn.externals._packaging.version.LegacyVersion.epoch@getter", "decorators": ["property"], "parameters": [ { @@ -74678,7 +76678,9 @@ }, { "name": "is_devrelease", + "unique_name": "is_devrelease@getter", "qname": "sklearn.externals._packaging.version.LegacyVersion.is_devrelease", + "unique_qname": "sklearn.externals._packaging.version.LegacyVersion.is_devrelease@getter", "decorators": ["property"], "parameters": [ { @@ -74700,7 +76702,9 @@ }, { "name": "is_postrelease", + "unique_name": "is_postrelease@getter", "qname": "sklearn.externals._packaging.version.LegacyVersion.is_postrelease", + "unique_qname": "sklearn.externals._packaging.version.LegacyVersion.is_postrelease@getter", "decorators": ["property"], "parameters": [ { @@ -74722,7 +76726,9 @@ }, { "name": "is_prerelease", + "unique_name": "is_prerelease@getter", "qname": "sklearn.externals._packaging.version.LegacyVersion.is_prerelease", + "unique_qname": "sklearn.externals._packaging.version.LegacyVersion.is_prerelease@getter", "decorators": ["property"], "parameters": [ { @@ -74744,7 +76750,9 @@ }, { "name": "local", + "unique_name": "local@getter", "qname": "sklearn.externals._packaging.version.LegacyVersion.local", + "unique_qname": "sklearn.externals._packaging.version.LegacyVersion.local@getter", "decorators": ["property"], "parameters": [ { @@ -74766,7 +76774,9 @@ }, { "name": "post", + "unique_name": "post@getter", "qname": "sklearn.externals._packaging.version.LegacyVersion.post", + "unique_qname": "sklearn.externals._packaging.version.LegacyVersion.post@getter", "decorators": ["property"], "parameters": [ { @@ -74788,7 +76798,9 @@ }, { "name": "pre", + "unique_name": "pre@getter", "qname": "sklearn.externals._packaging.version.LegacyVersion.pre", + "unique_qname": "sklearn.externals._packaging.version.LegacyVersion.pre@getter", "decorators": ["property"], "parameters": [ { @@ -74810,7 +76822,9 @@ }, { "name": "public", + "unique_name": "public@getter", "qname": "sklearn.externals._packaging.version.LegacyVersion.public", + "unique_qname": "sklearn.externals._packaging.version.LegacyVersion.public@getter", "decorators": ["property"], "parameters": [ { @@ -74832,7 +76846,9 @@ }, { "name": "release", + "unique_name": "release@getter", "qname": "sklearn.externals._packaging.version.LegacyVersion.release", + "unique_qname": "sklearn.externals._packaging.version.LegacyVersion.release@getter", "decorators": ["property"], "parameters": [ { @@ -74854,7 +76870,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.externals._packaging.version.Version.__init__", + "unique_qname": "sklearn.externals._packaging.version.Version.__init__", "decorators": [], "parameters": [ { @@ -74886,7 +76904,9 @@ }, { "name": "__repr__", + "unique_name": "__repr__", "qname": "sklearn.externals._packaging.version.Version.__repr__", + "unique_qname": "sklearn.externals._packaging.version.Version.__repr__", "decorators": [], "parameters": [ { @@ -74908,7 +76928,9 @@ }, { "name": "__str__", + "unique_name": "__str__", "qname": "sklearn.externals._packaging.version.Version.__str__", + "unique_qname": "sklearn.externals._packaging.version.Version.__str__", "decorators": [], "parameters": [ { @@ -74930,7 +76952,9 @@ }, { "name": "base_version", + "unique_name": "base_version@getter", "qname": "sklearn.externals._packaging.version.Version.base_version", + "unique_qname": "sklearn.externals._packaging.version.Version.base_version@getter", "decorators": ["property"], "parameters": [ { @@ -74952,7 +76976,9 @@ }, { "name": "dev", + "unique_name": "dev@getter", "qname": "sklearn.externals._packaging.version.Version.dev", + "unique_qname": "sklearn.externals._packaging.version.Version.dev@getter", "decorators": ["property"], "parameters": [ { @@ -74974,7 +77000,9 @@ }, { "name": "epoch", + "unique_name": "epoch@getter", "qname": "sklearn.externals._packaging.version.Version.epoch", + "unique_qname": "sklearn.externals._packaging.version.Version.epoch@getter", "decorators": ["property"], "parameters": [ { @@ -74996,7 +77024,9 @@ }, { "name": "is_devrelease", + "unique_name": "is_devrelease@getter", "qname": "sklearn.externals._packaging.version.Version.is_devrelease", + "unique_qname": "sklearn.externals._packaging.version.Version.is_devrelease@getter", "decorators": ["property"], "parameters": [ { @@ -75018,7 +77048,9 @@ }, { "name": "is_postrelease", + "unique_name": "is_postrelease@getter", "qname": "sklearn.externals._packaging.version.Version.is_postrelease", + "unique_qname": "sklearn.externals._packaging.version.Version.is_postrelease@getter", "decorators": ["property"], "parameters": [ { @@ -75040,7 +77072,9 @@ }, { "name": "is_prerelease", + "unique_name": "is_prerelease@getter", "qname": "sklearn.externals._packaging.version.Version.is_prerelease", + "unique_qname": "sklearn.externals._packaging.version.Version.is_prerelease@getter", "decorators": ["property"], "parameters": [ { @@ -75062,7 +77096,9 @@ }, { "name": "local", + "unique_name": "local@getter", "qname": "sklearn.externals._packaging.version.Version.local", + "unique_qname": "sklearn.externals._packaging.version.Version.local@getter", "decorators": ["property"], "parameters": [ { @@ -75084,7 +77120,9 @@ }, { "name": "major", + "unique_name": "major@getter", "qname": "sklearn.externals._packaging.version.Version.major", + "unique_qname": "sklearn.externals._packaging.version.Version.major@getter", "decorators": ["property"], "parameters": [ { @@ -75106,7 +77144,9 @@ }, { "name": "micro", + "unique_name": "micro@getter", "qname": "sklearn.externals._packaging.version.Version.micro", + "unique_qname": "sklearn.externals._packaging.version.Version.micro@getter", "decorators": ["property"], "parameters": [ { @@ -75128,7 +77168,9 @@ }, { "name": "minor", + "unique_name": "minor@getter", "qname": "sklearn.externals._packaging.version.Version.minor", + "unique_qname": "sklearn.externals._packaging.version.Version.minor@getter", "decorators": ["property"], "parameters": [ { @@ -75150,7 +77192,9 @@ }, { "name": "post", + "unique_name": "post@getter", "qname": "sklearn.externals._packaging.version.Version.post", + "unique_qname": "sklearn.externals._packaging.version.Version.post@getter", "decorators": ["property"], "parameters": [ { @@ -75172,7 +77216,9 @@ }, { "name": "pre", + "unique_name": "pre@getter", "qname": "sklearn.externals._packaging.version.Version.pre", + "unique_qname": "sklearn.externals._packaging.version.Version.pre@getter", "decorators": ["property"], "parameters": [ { @@ -75194,7 +77240,9 @@ }, { "name": "public", + "unique_name": "public@getter", "qname": "sklearn.externals._packaging.version.Version.public", + "unique_qname": "sklearn.externals._packaging.version.Version.public@getter", "decorators": ["property"], "parameters": [ { @@ -75216,7 +77264,9 @@ }, { "name": "release", + "unique_name": "release@getter", "qname": "sklearn.externals._packaging.version.Version.release", + "unique_qname": "sklearn.externals._packaging.version.Version.release@getter", "decorators": ["property"], "parameters": [ { @@ -75238,7 +77288,9 @@ }, { "name": "__eq__", + "unique_name": "__eq__", "qname": "sklearn.externals._packaging.version._BaseVersion.__eq__", + "unique_qname": "sklearn.externals._packaging.version._BaseVersion.__eq__", "decorators": [], "parameters": [ { @@ -75270,7 +77322,9 @@ }, { "name": "__ge__", + "unique_name": "__ge__", "qname": "sklearn.externals._packaging.version._BaseVersion.__ge__", + "unique_qname": "sklearn.externals._packaging.version._BaseVersion.__ge__", "decorators": [], "parameters": [ { @@ -75302,7 +77356,9 @@ }, { "name": "__gt__", + "unique_name": "__gt__", "qname": "sklearn.externals._packaging.version._BaseVersion.__gt__", + "unique_qname": "sklearn.externals._packaging.version._BaseVersion.__gt__", "decorators": [], "parameters": [ { @@ -75334,7 +77390,9 @@ }, { "name": "__hash__", + "unique_name": "__hash__", "qname": "sklearn.externals._packaging.version._BaseVersion.__hash__", + "unique_qname": "sklearn.externals._packaging.version._BaseVersion.__hash__", "decorators": [], "parameters": [ { @@ -75356,7 +77414,9 @@ }, { "name": "__le__", + "unique_name": "__le__", "qname": "sklearn.externals._packaging.version._BaseVersion.__le__", + "unique_qname": "sklearn.externals._packaging.version._BaseVersion.__le__", "decorators": [], "parameters": [ { @@ -75388,7 +77448,9 @@ }, { "name": "__lt__", + "unique_name": "__lt__", "qname": "sklearn.externals._packaging.version._BaseVersion.__lt__", + "unique_qname": "sklearn.externals._packaging.version._BaseVersion.__lt__", "decorators": [], "parameters": [ { @@ -75420,7 +77482,9 @@ }, { "name": "__ne__", + "unique_name": "__ne__", "qname": "sklearn.externals._packaging.version._BaseVersion.__ne__", + "unique_qname": "sklearn.externals._packaging.version._BaseVersion.__ne__", "decorators": [], "parameters": [ { @@ -75452,7 +77516,9 @@ }, { "name": "_cmpkey", + "unique_name": "_cmpkey", "qname": "sklearn.externals._packaging.version._cmpkey", + "unique_qname": "sklearn.externals._packaging.version._cmpkey", "decorators": [], "parameters": [ { @@ -75524,7 +77590,9 @@ }, { "name": "_legacy_cmpkey", + "unique_name": "_legacy_cmpkey", "qname": "sklearn.externals._packaging.version._legacy_cmpkey", + "unique_qname": "sklearn.externals._packaging.version._legacy_cmpkey", "decorators": [], "parameters": [ { @@ -75546,7 +77614,9 @@ }, { "name": "_parse_letter_version", + "unique_name": "_parse_letter_version", "qname": "sklearn.externals._packaging.version._parse_letter_version", + "unique_qname": "sklearn.externals._packaging.version._parse_letter_version", "decorators": [], "parameters": [ { @@ -75578,7 +77648,9 @@ }, { "name": "_parse_local_version", + "unique_name": "_parse_local_version", "qname": "sklearn.externals._packaging.version._parse_local_version", + "unique_qname": "sklearn.externals._packaging.version._parse_local_version", "decorators": [], "parameters": [ { @@ -75600,7 +77672,9 @@ }, { "name": "_parse_version_parts", + "unique_name": "_parse_version_parts", "qname": "sklearn.externals._packaging.version._parse_version_parts", + "unique_qname": "sklearn.externals._packaging.version._parse_version_parts", "decorators": [], "parameters": [ { @@ -75622,7 +77696,9 @@ }, { "name": "parse", + "unique_name": "parse", "qname": "sklearn.externals._packaging.version.parse", + "unique_qname": "sklearn.externals._packaging.version.parse", "decorators": [], "parameters": [ { @@ -75642,95 +77718,11 @@ "docstring": "Parse the given version string and return either a :class:`Version` object\nor a :class:`LegacyVersion` object depending on if the given version is\na valid PEP 440 version or a legacy version.", "source_code": "\ndef parse(version: str) -> Union['LegacyVersion', 'Version']:\n \"\"\"\n Parse the given version string and return either a :class:`Version` object\n or a :class:`LegacyVersion` object depending on if the given version is\n a valid PEP 440 version or a legacy version.\n \"\"\"\n try:\n return Version(version)\n except InvalidVersion:\n return LegacyVersion(version)" }, - { - "name": "__dir__", - "qname": "sklearn.externals._pep562.Pep562.__dir__", - "decorators": [], - "parameters": [ - { - "name": "self", - "default_value": null, - "is_public": false, - "assigned_by": "POSITION_OR_NAME", - "docstring": { - "type": "", - "description": "" - } - } - ], - "results": [], - "is_public": false, - "description": "Return the overridden `dir` if one was provided, else apply `dir` to the module.", - "docstring": "Return the overridden `dir` if one was provided, else apply `dir` to the module.", - "source_code": "\ndef __dir__(self):\n \"\"\"Return the overridden `dir` if one was provided, else apply `dir` to the module.\"\"\"\n return self._get_dir() if self._get_dir else dir(self._module)" - }, - { - "name": "__getattr__", - "qname": "sklearn.externals._pep562.Pep562.__getattr__", - "decorators": [], - "parameters": [ - { - "name": "self", - "default_value": null, - "is_public": false, - "assigned_by": "POSITION_OR_NAME", - "docstring": { - "type": "", - "description": "" - } - }, - { - "name": "name", - "default_value": null, - "is_public": false, - "assigned_by": "POSITION_OR_NAME", - "docstring": { - "type": "", - "description": "" - } - } - ], - "results": [], - "is_public": false, - "description": "Attempt to retrieve the attribute from the module, and if missing, use the overridden function if present.", - "docstring": "Attempt to retrieve the attribute from the module, and if missing, use the overridden function if present.", - "source_code": "\ndef __getattr__(self, name):\n \"\"\"Attempt to retrieve the attribute from the module, and if missing, use the overridden function if present.\"\"\"\n try:\n return getattr(self._module, name)\n except AttributeError:\n if self._get_attr:\n return self._get_attr(name)\n raise" - }, - { - "name": "__init__", - "qname": "sklearn.externals._pep562.Pep562.__init__", - "decorators": [], - "parameters": [ - { - "name": "self", - "default_value": null, - "is_public": false, - "assigned_by": "POSITION_OR_NAME", - "docstring": { - "type": "", - "description": "" - } - }, - { - "name": "name", - "default_value": null, - "is_public": false, - "assigned_by": "POSITION_OR_NAME", - "docstring": { - "type": "", - "description": "" - } - } - ], - "results": [], - "is_public": false, - "description": "Acquire `__getattr__` and `__dir__`, but only replace module for versions less than Python 3.7.", - "docstring": "Acquire `__getattr__` and `__dir__`, but only replace module for versions less than Python 3.7.", - "source_code": "\ndef __init__(self, name):\n \"\"\"Acquire `__getattr__` and `__dir__`, but only replace module for versions less than Python 3.7.\"\"\"\n self._module = sys.modules[name]\n self._get_attr = getattr(self._module, '__getattr__', None)\n self._get_dir = getattr(self._module, '__dir__', None)\n sys.modules[name] = self" - }, { "name": "bytescale", + "unique_name": "bytescale", "qname": "sklearn.externals._pilutil.bytescale", + "unique_qname": "sklearn.externals._pilutil.bytescale", "decorators": [], "parameters": [ { @@ -75792,7 +77784,9 @@ }, { "name": "fromimage", + "unique_name": "fromimage", "qname": "sklearn.externals._pilutil.fromimage", + "unique_qname": "sklearn.externals._pilutil.fromimage", "decorators": [], "parameters": [ { @@ -75834,7 +77828,9 @@ }, { "name": "imread", + "unique_name": "imread", "qname": "sklearn.externals._pilutil.imread", + "unique_qname": "sklearn.externals._pilutil.imread", "decorators": [], "parameters": [ { @@ -75876,7 +77872,9 @@ }, { "name": "imresize", + "unique_name": "imresize", "qname": "sklearn.externals._pilutil.imresize", + "unique_qname": "sklearn.externals._pilutil.imresize", "decorators": [], "parameters": [ { @@ -75928,7 +77926,9 @@ }, { "name": "imsave", + "unique_name": "imsave", "qname": "sklearn.externals._pilutil.imsave", + "unique_qname": "sklearn.externals._pilutil.imsave", "decorators": [], "parameters": [ { @@ -75970,7 +77970,9 @@ }, { "name": "toimage", + "unique_name": "toimage", "qname": "sklearn.externals._pilutil.toimage", + "unique_qname": "sklearn.externals._pilutil.toimage", "decorators": [], "parameters": [ { @@ -76062,7 +78064,9 @@ }, { "name": "pytest_ignore_collect", + "unique_name": "pytest_ignore_collect", "qname": "sklearn.externals.conftest.pytest_ignore_collect", + "unique_qname": "sklearn.externals.conftest.pytest_ignore_collect", "decorators": [], "parameters": [ { @@ -76094,7 +78098,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.feature_extraction._dict_vectorizer.DictVectorizer.__init__", + "unique_qname": "sklearn.feature_extraction._dict_vectorizer.DictVectorizer.__init__", "decorators": [], "parameters": [ { @@ -76156,7 +78162,9 @@ }, { "name": "_add_iterable_element", + "unique_name": "_add_iterable_element", "qname": "sklearn.feature_extraction._dict_vectorizer.DictVectorizer._add_iterable_element", + "unique_qname": "sklearn.feature_extraction._dict_vectorizer.DictVectorizer._add_iterable_element", "decorators": [], "parameters": [ { @@ -76258,7 +78266,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.feature_extraction._dict_vectorizer.DictVectorizer._more_tags", + "unique_qname": "sklearn.feature_extraction._dict_vectorizer.DictVectorizer._more_tags", "decorators": [], "parameters": [ { @@ -76280,7 +78290,9 @@ }, { "name": "_transform", + "unique_name": "_transform", "qname": "sklearn.feature_extraction._dict_vectorizer.DictVectorizer._transform", + "unique_qname": "sklearn.feature_extraction._dict_vectorizer.DictVectorizer._transform", "decorators": [], "parameters": [ { @@ -76322,7 +78334,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.feature_extraction._dict_vectorizer.DictVectorizer.fit", + "unique_qname": "sklearn.feature_extraction._dict_vectorizer.DictVectorizer.fit", "decorators": [], "parameters": [ { @@ -76364,7 +78378,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.feature_extraction._dict_vectorizer.DictVectorizer.fit_transform", + "unique_qname": "sklearn.feature_extraction._dict_vectorizer.DictVectorizer.fit_transform", "decorators": [], "parameters": [ { @@ -76406,7 +78422,9 @@ }, { "name": "get_feature_names", + "unique_name": "get_feature_names", "qname": "sklearn.feature_extraction._dict_vectorizer.DictVectorizer.get_feature_names", + "unique_qname": "sklearn.feature_extraction._dict_vectorizer.DictVectorizer.get_feature_names", "decorators": [ "deprecated('get_feature_names is deprecated in 1.0 and will be removed in 1.2. Please use get_feature_names_out instead.')" ], @@ -76430,7 +78448,9 @@ }, { "name": "get_feature_names_out", + "unique_name": "get_feature_names_out", "qname": "sklearn.feature_extraction._dict_vectorizer.DictVectorizer.get_feature_names_out", + "unique_qname": "sklearn.feature_extraction._dict_vectorizer.DictVectorizer.get_feature_names_out", "decorators": [], "parameters": [ { @@ -76462,7 +78482,9 @@ }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.feature_extraction._dict_vectorizer.DictVectorizer.inverse_transform", + "unique_qname": "sklearn.feature_extraction._dict_vectorizer.DictVectorizer.inverse_transform", "decorators": [], "parameters": [ { @@ -76504,7 +78526,9 @@ }, { "name": "restrict", + "unique_name": "restrict", "qname": "sklearn.feature_extraction._dict_vectorizer.DictVectorizer.restrict", + "unique_qname": "sklearn.feature_extraction._dict_vectorizer.DictVectorizer.restrict", "decorators": [], "parameters": [ { @@ -76546,7 +78570,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.feature_extraction._dict_vectorizer.DictVectorizer.transform", + "unique_qname": "sklearn.feature_extraction._dict_vectorizer.DictVectorizer.transform", "decorators": [], "parameters": [ { @@ -76578,7 +78604,9 @@ }, { "name": "_tosequence", + "unique_name": "_tosequence", "qname": "sklearn.feature_extraction._dict_vectorizer._tosequence", + "unique_qname": "sklearn.feature_extraction._dict_vectorizer._tosequence", "decorators": [], "parameters": [ { @@ -76600,7 +78628,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.feature_extraction._hash.FeatureHasher.__init__", + "unique_qname": "sklearn.feature_extraction._hash.FeatureHasher.__init__", "decorators": [], "parameters": [ { @@ -76662,7 +78692,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.feature_extraction._hash.FeatureHasher._more_tags", + "unique_qname": "sklearn.feature_extraction._hash.FeatureHasher._more_tags", "decorators": [], "parameters": [ { @@ -76684,7 +78716,9 @@ }, { "name": "_validate_params", + "unique_name": "_validate_params", "qname": "sklearn.feature_extraction._hash.FeatureHasher._validate_params", + "unique_qname": "sklearn.feature_extraction._hash.FeatureHasher._validate_params", "decorators": ["staticmethod"], "parameters": [ { @@ -76716,7 +78750,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.feature_extraction._hash.FeatureHasher.fit", + "unique_qname": "sklearn.feature_extraction._hash.FeatureHasher.fit", "decorators": [], "parameters": [ { @@ -76758,7 +78794,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.feature_extraction._hash.FeatureHasher.transform", + "unique_qname": "sklearn.feature_extraction._hash.FeatureHasher.transform", "decorators": [], "parameters": [ { @@ -76790,7 +78828,9 @@ }, { "name": "_hashing_transform", + "unique_name": "_hashing_transform", "qname": "sklearn.feature_extraction._hash._hashing_transform", + "unique_qname": "sklearn.feature_extraction._hash._hashing_transform", "decorators": [], "parameters": [], "results": [], @@ -76801,7 +78841,9 @@ }, { "name": "_iteritems", + "unique_name": "_iteritems", "qname": "sklearn.feature_extraction._hash._iteritems", + "unique_qname": "sklearn.feature_extraction._hash._iteritems", "decorators": [], "parameters": [ { @@ -76823,7 +78865,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.feature_extraction.image.PatchExtractor.__init__", + "unique_qname": "sklearn.feature_extraction.image.PatchExtractor.__init__", "decorators": [], "parameters": [ { @@ -76853,7 +78897,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int or float, default=None", - "description": "The maximum number of patches per image to extract. If max_patches is a\nfloat in (0, 1), it is taken to mean a proportion of the total number\nof patches." + "description": "The maximum number of patches per image to extract. If `max_patches` is\na float in (0, 1), it is taken to mean a proportion of the total number\nof patches." } }, { @@ -76863,7 +78907,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int, RandomState instance, default=None", - "description": "Determines the random number generator used for random sampling when\n`max_patches` is not None. Use an int to make the randomness\ndeterministic.\nSee :term:`Glossary `." + "description": "Determines the random number generator used for random sampling when\n`max_patches is not None`. Use an int to make the randomness\ndeterministic.\nSee :term:`Glossary `." } } ], @@ -76875,7 +78919,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.feature_extraction.image.PatchExtractor._more_tags", + "unique_qname": "sklearn.feature_extraction.image.PatchExtractor._more_tags", "decorators": [], "parameters": [ { @@ -76897,7 +78943,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.feature_extraction.image.PatchExtractor.fit", + "unique_qname": "sklearn.feature_extraction.image.PatchExtractor.fit", "decorators": [], "parameters": [ { @@ -76926,20 +78974,22 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "", - "description": "" + "type": "Ignored", + "description": "Not used, present for API consistency by convention." } } ], "results": [], "is_public": true, "description": "Do nothing and return the estimator unchanged.\n\nThis method is just there to implement the usual API and hence work in pipelines.", - "docstring": "Do nothing and return the estimator unchanged.\n\nThis method is just there to implement the usual API and hence\nwork in pipelines.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Training data.", - "source_code": "\ndef fit(self, X, y=None):\n \"\"\"Do nothing and return the estimator unchanged.\n\n This method is just there to implement the usual API and hence\n work in pipelines.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training data.\n \"\"\"\n return self" + "docstring": "Do nothing and return the estimator unchanged.\n\nThis method is just there to implement the usual API and hence\nwork in pipelines.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Training data.\n\ny : Ignored\n Not used, present for API consistency by convention.\n\nReturns\n-------\nself : object\n Returns the instance itself.", + "source_code": "\ndef fit(self, X, y=None):\n \"\"\"Do nothing and return the estimator unchanged.\n\n This method is just there to implement the usual API and hence\n work in pipelines.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training data.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n return self" }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.feature_extraction.image.PatchExtractor.transform", + "unique_qname": "sklearn.feature_extraction.image.PatchExtractor.transform", "decorators": [], "parameters": [ { @@ -76965,13 +79015,15 @@ ], "results": [], "is_public": true, - "description": "Transforms the image samples in X into a matrix of patch data.", - "docstring": "Transforms the image samples in X into a matrix of patch data.\n\nParameters\n----------\nX : ndarray of shape (n_samples, image_height, image_width) or (n_samples, image_height, image_width, n_channels)\n Array of images from which to extract patches. For color images,\n the last dimension specifies the channel: a RGB image would have\n `n_channels=3`.\n\nReturns\n-------\npatches : array of shape (n_patches, patch_height, patch_width) or (n_patches, patch_height, patch_width, n_channels)\n The collection of patches extracted from the images, where\n `n_patches` is either `n_samples * max_patches` or the total\n number of patches that can be extracted.", - "source_code": "\ndef transform(self, X):\n \"\"\"Transforms the image samples in X into a matrix of patch data.\n\n Parameters\n ----------\n X : ndarray of shape (n_samples, image_height, image_width) or (n_samples, image_height, image_width, n_channels)\n Array of images from which to extract patches. For color images,\n the last dimension specifies the channel: a RGB image would have\n `n_channels=3`.\n\n Returns\n -------\n patches : array of shape (n_patches, patch_height, patch_width) or (n_patches, patch_height, patch_width, n_channels)\n The collection of patches extracted from the images, where\n `n_patches` is either `n_samples * max_patches` or the total\n number of patches that can be extracted.\n \"\"\"\n self.random_state = check_random_state(self.random_state)\n (n_images, i_h, i_w) = X.shape[:3]\n X = np.reshape(X, (n_images, i_h, i_w, -1))\n n_channels = X.shape[-1]\n if self.patch_size is None:\n patch_size = (i_h // 10, i_w // 10)\n else:\n patch_size = self.patch_size\n (p_h, p_w) = patch_size\n n_patches = _compute_n_patches(i_h, i_w, p_h, p_w, self.max_patches)\n patches_shape = (n_images * n_patches, ) + patch_size\n if n_channels > 1:\n patches_shape += (n_channels, )\n patches = np.empty(patches_shape)\n for (ii, image) in enumerate(X):\n patches[ii * n_patches:(ii + 1) * n_patches] = extract_patches_2d(image, patch_size, max_patches=self.max_patches, random_state=self.random_state)\n return patches" + "description": "Transform the image samples in `X` into a matrix of patch data.", + "docstring": "Transform the image samples in `X` into a matrix of patch data.\n\nParameters\n----------\nX : ndarray of shape (n_samples, image_height, image_width) or (n_samples, image_height, image_width, n_channels)\n Array of images from which to extract patches. For color images,\n the last dimension specifies the channel: a RGB image would have\n `n_channels=3`.\n\nReturns\n-------\npatches : array of shape (n_patches, patch_height, patch_width) or (n_patches, patch_height, patch_width, n_channels)\n The collection of patches extracted from the images, where\n `n_patches` is either `n_samples * max_patches` or the total\n number of patches that can be extracted.", + "source_code": "\ndef transform(self, X):\n \"\"\"Transform the image samples in `X` into a matrix of patch data.\n\n Parameters\n ----------\n X : ndarray of shape (n_samples, image_height, image_width) or (n_samples, image_height, image_width, n_channels)\n Array of images from which to extract patches. For color images,\n the last dimension specifies the channel: a RGB image would have\n `n_channels=3`.\n\n Returns\n -------\n patches : array of shape (n_patches, patch_height, patch_width) or (n_patches, patch_height, patch_width, n_channels)\n The collection of patches extracted from the images, where\n `n_patches` is either `n_samples * max_patches` or the total\n number of patches that can be extracted.\n \"\"\"\n self.random_state = check_random_state(self.random_state)\n (n_images, i_h, i_w) = X.shape[:3]\n X = np.reshape(X, (n_images, i_h, i_w, -1))\n n_channels = X.shape[-1]\n if self.patch_size is None:\n patch_size = (i_h // 10, i_w // 10)\n else:\n patch_size = self.patch_size\n (p_h, p_w) = patch_size\n n_patches = _compute_n_patches(i_h, i_w, p_h, p_w, self.max_patches)\n patches_shape = (n_images * n_patches, ) + patch_size\n if n_channels > 1:\n patches_shape += (n_channels, )\n patches = np.empty(patches_shape)\n for (ii, image) in enumerate(X):\n patches[ii * n_patches:(ii + 1) * n_patches] = extract_patches_2d(image, patch_size, max_patches=self.max_patches, random_state=self.random_state)\n return patches" }, { "name": "_compute_gradient_3d", + "unique_name": "_compute_gradient_3d", "qname": "sklearn.feature_extraction.image._compute_gradient_3d", + "unique_qname": "sklearn.feature_extraction.image._compute_gradient_3d", "decorators": [], "parameters": [ { @@ -77003,7 +79055,9 @@ }, { "name": "_compute_n_patches", + "unique_name": "_compute_n_patches", "qname": "sklearn.feature_extraction.image._compute_n_patches", + "unique_qname": "sklearn.feature_extraction.image._compute_n_patches", "decorators": [], "parameters": [ { @@ -77065,7 +79119,9 @@ }, { "name": "_extract_patches", + "unique_name": "_extract_patches", "qname": "sklearn.feature_extraction.image._extract_patches", + "unique_qname": "sklearn.feature_extraction.image._extract_patches", "decorators": [], "parameters": [ { @@ -77107,7 +79163,9 @@ }, { "name": "_make_edges_3d", + "unique_name": "_make_edges_3d", "qname": "sklearn.feature_extraction.image._make_edges_3d", + "unique_qname": "sklearn.feature_extraction.image._make_edges_3d", "decorators": [], "parameters": [ { @@ -77149,7 +79207,9 @@ }, { "name": "_mask_edges_weights", + "unique_name": "_mask_edges_weights", "qname": "sklearn.feature_extraction.image._mask_edges_weights", + "unique_qname": "sklearn.feature_extraction.image._mask_edges_weights", "decorators": [], "parameters": [ { @@ -77191,7 +79251,9 @@ }, { "name": "_to_graph", + "unique_name": "_to_graph", "qname": "sklearn.feature_extraction.image._to_graph", + "unique_qname": "sklearn.feature_extraction.image._to_graph", "decorators": [], "parameters": [ { @@ -77273,7 +79335,9 @@ }, { "name": "extract_patches_2d", + "unique_name": "extract_patches_2d", "qname": "sklearn.feature_extraction.image.extract_patches_2d", + "unique_qname": "sklearn.feature_extraction.image.extract_patches_2d", "decorators": [], "parameters": [ { @@ -77325,7 +79389,9 @@ }, { "name": "grid_to_graph", + "unique_name": "grid_to_graph", "qname": "sklearn.feature_extraction.image.grid_to_graph", + "unique_qname": "sklearn.feature_extraction.image.grid_to_graph", "decorators": [], "parameters": [ { @@ -77397,7 +79463,9 @@ }, { "name": "img_to_graph", + "unique_name": "img_to_graph", "qname": "sklearn.feature_extraction.image.img_to_graph", + "unique_qname": "sklearn.feature_extraction.image.img_to_graph", "decorators": [], "parameters": [ { @@ -77449,7 +79517,9 @@ }, { "name": "reconstruct_from_patches_2d", + "unique_name": "reconstruct_from_patches_2d", "qname": "sklearn.feature_extraction.image.reconstruct_from_patches_2d", + "unique_qname": "sklearn.feature_extraction.image.reconstruct_from_patches_2d", "decorators": [], "parameters": [ { @@ -77481,7 +79551,9 @@ }, { "name": "configuration", + "unique_name": "configuration", "qname": "sklearn.feature_extraction.setup.configuration", + "unique_qname": "sklearn.feature_extraction.setup.configuration", "decorators": [], "parameters": [ { @@ -77513,7 +79585,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.feature_extraction.text.CountVectorizer.__init__", + "unique_qname": "sklearn.feature_extraction.text.CountVectorizer.__init__", "decorators": [], "parameters": [ { @@ -77701,11 +79775,13 @@ "is_public": true, "description": "", "docstring": "", - "source_code": "\ndef __init__(self, *, input='content', encoding='utf-8', decode_error='strict', strip_accents=None, lowercase=True, preprocessor=None, tokenizer=None, stop_words=None, token_pattern='(?u)\\\\b\\\\w\\\\w+\\\\b', ngram_range=(1, 1), analyzer='word', max_df=1.0, min_df=1, max_features=None, vocabulary=None, binary=False, dtype=np.int64):\n self.input = input\n self.encoding = encoding\n self.decode_error = decode_error\n self.strip_accents = strip_accents\n self.preprocessor = preprocessor\n self.tokenizer = tokenizer\n self.analyzer = analyzer\n self.lowercase = lowercase\n self.token_pattern = token_pattern\n self.stop_words = stop_words\n self.max_df = max_df\n self.min_df = min_df\n if max_df < 0 or min_df < 0:\n raise ValueError('negative value for max_df or min_df')\n self.max_features = max_features\n if max_features is not None:\n if not isinstance(max_features, numbers.Integral) or max_features <= 0:\n raise ValueError('max_features=%r, neither a positive integer nor None' % max_features)\n self.ngram_range = ngram_range\n self.vocabulary = vocabulary\n self.binary = binary\n self.dtype = dtype" + "source_code": "\ndef __init__(self, *, input='content', encoding='utf-8', decode_error='strict', strip_accents=None, lowercase=True, preprocessor=None, tokenizer=None, stop_words=None, token_pattern='(?u)\\\\b\\\\w\\\\w+\\\\b', ngram_range=(1, 1), analyzer='word', max_df=1.0, min_df=1, max_features=None, vocabulary=None, binary=False, dtype=np.int64):\n self.input = input\n self.encoding = encoding\n self.decode_error = decode_error\n self.strip_accents = strip_accents\n self.preprocessor = preprocessor\n self.tokenizer = tokenizer\n self.analyzer = analyzer\n self.lowercase = lowercase\n self.token_pattern = token_pattern\n self.stop_words = stop_words\n self.max_df = max_df\n self.min_df = min_df\n self.max_features = max_features\n self.ngram_range = ngram_range\n self.vocabulary = vocabulary\n self.binary = binary\n self.dtype = dtype" }, { "name": "_count_vocab", + "unique_name": "_count_vocab", "qname": "sklearn.feature_extraction.text.CountVectorizer._count_vocab", + "unique_qname": "sklearn.feature_extraction.text.CountVectorizer._count_vocab", "decorators": [], "parameters": [ { @@ -77743,11 +79819,13 @@ "is_public": false, "description": "Create sparse feature matrix, and vocabulary where fixed_vocab=False", "docstring": "Create sparse feature matrix, and vocabulary where fixed_vocab=False", - "source_code": "\ndef _count_vocab(self, raw_documents, fixed_vocab):\n \"\"\"Create sparse feature matrix, and vocabulary where fixed_vocab=False\"\"\"\n if fixed_vocab:\n vocabulary = self.vocabulary_\n else:\n vocabulary = defaultdict()\n vocabulary.default_factory = vocabulary.__len__\n analyze = self.build_analyzer()\n j_indices = []\n indptr = []\n if self.lowercase:\n for vocab in vocabulary:\n if any(map(str.isupper, vocab)):\n warnings.warn(\"Upper case characters found in vocabulary while 'lowercase' is True. These entries will not be matched with any documents\")\n break\n values = _make_int_array()\n indptr.append(0)\n for doc in raw_documents:\n feature_counter = {}\n for feature in analyze(doc):\n try:\n feature_idx = vocabulary[feature]\n if feature_idx not in feature_counter:\n feature_counter[feature_idx] = 1\n else:\n feature_counter[feature_idx] += 1\n except KeyError:\n continue\n j_indices.extend(feature_counter.keys())\n values.extend(feature_counter.values())\n indptr.append(len(j_indices))\n if not fixed_vocab:\n vocabulary = dict(vocabulary)\n if not vocabulary:\n raise ValueError('empty vocabulary; perhaps the documents only contain stop words')\n if indptr[-1] > np.iinfo(np.int32).max:\n if _IS_32BIT:\n raise ValueError('sparse CSR array has {} non-zero elements and requires 64 bit indexing, which is unsupported with 32 bit Python.'.format(indptr[-1]))\n indices_dtype = np.int64\n else:\n indices_dtype = np.int32\n j_indices = np.asarray(j_indices, dtype=indices_dtype)\n indptr = np.asarray(indptr, dtype=indices_dtype)\n values = np.frombuffer(values, dtype=np.intc)\n X = sp.csr_matrix((values, j_indices, indptr), shape=(len(indptr) - 1, len(vocabulary)), dtype=self.dtype)\n X.sort_indices()\n return vocabulary, X" + "source_code": "\ndef _count_vocab(self, raw_documents, fixed_vocab):\n \"\"\"Create sparse feature matrix, and vocabulary where fixed_vocab=False\"\"\"\n if fixed_vocab:\n vocabulary = self.vocabulary_\n else:\n vocabulary = defaultdict()\n vocabulary.default_factory = vocabulary.__len__\n analyze = self.build_analyzer()\n j_indices = []\n indptr = []\n values = _make_int_array()\n indptr.append(0)\n for doc in raw_documents:\n feature_counter = {}\n for feature in analyze(doc):\n try:\n feature_idx = vocabulary[feature]\n if feature_idx not in feature_counter:\n feature_counter[feature_idx] = 1\n else:\n feature_counter[feature_idx] += 1\n except KeyError:\n continue\n j_indices.extend(feature_counter.keys())\n values.extend(feature_counter.values())\n indptr.append(len(j_indices))\n if not fixed_vocab:\n vocabulary = dict(vocabulary)\n if not vocabulary:\n raise ValueError('empty vocabulary; perhaps the documents only contain stop words')\n if indptr[-1] > np.iinfo(np.int32).max:\n if _IS_32BIT:\n raise ValueError('sparse CSR array has {} non-zero elements and requires 64 bit indexing, which is unsupported with 32 bit Python.'.format(indptr[-1]))\n indices_dtype = np.int64\n else:\n indices_dtype = np.int32\n j_indices = np.asarray(j_indices, dtype=indices_dtype)\n indptr = np.asarray(indptr, dtype=indices_dtype)\n values = np.frombuffer(values, dtype=np.intc)\n X = sp.csr_matrix((values, j_indices, indptr), shape=(len(indptr) - 1, len(vocabulary)), dtype=self.dtype)\n X.sort_indices()\n return vocabulary, X" }, { "name": "_limit_features", + "unique_name": "_limit_features", "qname": "sklearn.feature_extraction.text.CountVectorizer._limit_features", + "unique_qname": "sklearn.feature_extraction.text.CountVectorizer._limit_features", "decorators": [], "parameters": [ { @@ -77819,7 +79897,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.feature_extraction.text.CountVectorizer._more_tags", + "unique_qname": "sklearn.feature_extraction.text.CountVectorizer._more_tags", "decorators": [], "parameters": [ { @@ -77841,7 +79921,9 @@ }, { "name": "_sort_features", + "unique_name": "_sort_features", "qname": "sklearn.feature_extraction.text.CountVectorizer._sort_features", + "unique_qname": "sklearn.feature_extraction.text.CountVectorizer._sort_features", "decorators": [], "parameters": [ { @@ -77881,9 +79963,35 @@ "docstring": "Sort features by name\n\nReturns a reordered matrix and modifies the vocabulary in place", "source_code": "\ndef _sort_features(self, X, vocabulary):\n \"\"\"Sort features by name\n\n Returns a reordered matrix and modifies the vocabulary in place\n \"\"\"\n sorted_features = sorted(vocabulary.items())\n map_index = np.empty(len(sorted_features), dtype=X.indices.dtype)\n for (new_val, (term, old_val)) in enumerate(sorted_features):\n vocabulary[term] = new_val\n map_index[old_val] = new_val\n X.indices = map_index.take(X.indices, mode='clip')\n return X" }, + { + "name": "_validate_params", + "unique_name": "_validate_params", + "qname": "sklearn.feature_extraction.text.CountVectorizer._validate_params", + "unique_qname": "sklearn.feature_extraction.text.CountVectorizer._validate_params", + "decorators": [], + "parameters": [ + { + "name": "self", + "default_value": null, + "is_public": false, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "", + "description": "" + } + } + ], + "results": [], + "is_public": false, + "description": "Validation of min_df, max_df and max_features", + "docstring": "Validation of min_df, max_df and max_features", + "source_code": "\ndef _validate_params(self):\n \"\"\"Validation of min_df, max_df and max_features\"\"\"\n super()._validate_params()\n if self.max_features is not None:\n check_scalar(self.max_features, 'max_features', numbers.Integral, min_val=0)\n if isinstance(self.min_df, numbers.Integral):\n check_scalar(self.min_df, 'min_df', numbers.Integral, min_val=0)\n else:\n check_scalar(self.min_df, 'min_df', numbers.Real, min_val=0.0, max_val=1.0)\n if isinstance(self.max_df, numbers.Integral):\n check_scalar(self.max_df, 'max_df', numbers.Integral, min_val=0)\n else:\n check_scalar(self.max_df, 'max_df', numbers.Real, min_val=0.0, max_val=1.0)" + }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.feature_extraction.text.CountVectorizer.fit", + "unique_qname": "sklearn.feature_extraction.text.CountVectorizer.fit", "decorators": [], "parameters": [ { @@ -77925,7 +80033,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.feature_extraction.text.CountVectorizer.fit_transform", + "unique_qname": "sklearn.feature_extraction.text.CountVectorizer.fit_transform", "decorators": [], "parameters": [ { @@ -77963,11 +80073,13 @@ "is_public": true, "description": "Learn the vocabulary dictionary and return document-term matrix.\n\nThis is equivalent to fit followed by transform, but more efficiently implemented.", "docstring": "Learn the vocabulary dictionary and return document-term matrix.\n\nThis is equivalent to fit followed by transform, but more efficiently\nimplemented.\n\nParameters\n----------\nraw_documents : iterable\n An iterable which generates either str, unicode or file objects.\n\ny : None\n This parameter is ignored.\n\nReturns\n-------\nX : array of shape (n_samples, n_features)\n Document-term matrix.", - "source_code": "\ndef fit_transform(self, raw_documents, y=None):\n \"\"\"Learn the vocabulary dictionary and return document-term matrix.\n\n This is equivalent to fit followed by transform, but more efficiently\n implemented.\n\n Parameters\n ----------\n raw_documents : iterable\n An iterable which generates either str, unicode or file objects.\n\n y : None\n This parameter is ignored.\n\n Returns\n -------\n X : array of shape (n_samples, n_features)\n Document-term matrix.\n \"\"\"\n if isinstance(raw_documents, str):\n raise ValueError('Iterable over raw text documents expected, string object received.')\n self._validate_params()\n self._validate_vocabulary()\n max_df = self.max_df\n min_df = self.min_df\n max_features = self.max_features\n (vocabulary, X) = self._count_vocab(raw_documents, self.fixed_vocabulary_)\n if self.binary:\n X.data.fill(1)\n if not self.fixed_vocabulary_:\n n_doc = X.shape[0]\n max_doc_count = max_df if isinstance(max_df, numbers.Integral) else max_df * n_doc\n min_doc_count = min_df if isinstance(min_df, numbers.Integral) else min_df * n_doc\n if max_doc_count < min_doc_count:\n raise ValueError('max_df corresponds to < documents than min_df')\n if max_features is not None:\n X = self._sort_features(X, vocabulary)\n (X, self.stop_words_) = self._limit_features(X, vocabulary, max_doc_count, min_doc_count, max_features)\n if max_features is None:\n X = self._sort_features(X, vocabulary)\n self.vocabulary_ = vocabulary\n return X" + "source_code": "\ndef fit_transform(self, raw_documents, y=None):\n \"\"\"Learn the vocabulary dictionary and return document-term matrix.\n\n This is equivalent to fit followed by transform, but more efficiently\n implemented.\n\n Parameters\n ----------\n raw_documents : iterable\n An iterable which generates either str, unicode or file objects.\n\n y : None\n This parameter is ignored.\n\n Returns\n -------\n X : array of shape (n_samples, n_features)\n Document-term matrix.\n \"\"\"\n if isinstance(raw_documents, str):\n raise ValueError('Iterable over raw text documents expected, string object received.')\n self._validate_params()\n self._validate_vocabulary()\n max_df = self.max_df\n min_df = self.min_df\n max_features = self.max_features\n if self.fixed_vocabulary_ and self.lowercase:\n for term in self.vocabulary:\n if any(map(str.isupper, term)):\n warnings.warn(\"Upper case characters found in vocabulary while 'lowercase' is True. These entries will not be matched with any documents\")\n break\n (vocabulary, X) = self._count_vocab(raw_documents, self.fixed_vocabulary_)\n if self.binary:\n X.data.fill(1)\n if not self.fixed_vocabulary_:\n n_doc = X.shape[0]\n max_doc_count = max_df if isinstance(max_df, numbers.Integral) else max_df * n_doc\n min_doc_count = min_df if isinstance(min_df, numbers.Integral) else min_df * n_doc\n if max_doc_count < min_doc_count:\n raise ValueError('max_df corresponds to < documents than min_df')\n if max_features is not None:\n X = self._sort_features(X, vocabulary)\n (X, self.stop_words_) = self._limit_features(X, vocabulary, max_doc_count, min_doc_count, max_features)\n if max_features is None:\n X = self._sort_features(X, vocabulary)\n self.vocabulary_ = vocabulary\n return X" }, { "name": "get_feature_names", + "unique_name": "get_feature_names", "qname": "sklearn.feature_extraction.text.CountVectorizer.get_feature_names", + "unique_qname": "sklearn.feature_extraction.text.CountVectorizer.get_feature_names", "decorators": [ "deprecated('get_feature_names is deprecated in 1.0 and will be removed in 1.2. Please use get_feature_names_out instead.')" ], @@ -77991,7 +80103,9 @@ }, { "name": "get_feature_names_out", + "unique_name": "get_feature_names_out", "qname": "sklearn.feature_extraction.text.CountVectorizer.get_feature_names_out", + "unique_qname": "sklearn.feature_extraction.text.CountVectorizer.get_feature_names_out", "decorators": [], "parameters": [ { @@ -78023,7 +80137,9 @@ }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.feature_extraction.text.CountVectorizer.inverse_transform", + "unique_qname": "sklearn.feature_extraction.text.CountVectorizer.inverse_transform", "decorators": [], "parameters": [ { @@ -78055,7 +80171,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.feature_extraction.text.CountVectorizer.transform", + "unique_qname": "sklearn.feature_extraction.text.CountVectorizer.transform", "decorators": [], "parameters": [ { @@ -78087,7 +80205,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.feature_extraction.text.HashingVectorizer.__init__", + "unique_qname": "sklearn.feature_extraction.text.HashingVectorizer.__init__", "decorators": [], "parameters": [ { @@ -78137,7 +80257,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "{'ascii', 'unicode'}, default=None", - "description": "Remove accents and perform other character normalization\nduring the preprocessing step.\n'ascii' is a fast method that only works on characters that have\nan direct ASCII mapping.\n'unicode' is a slightly slower method that works on any characters.\nNone (default) does nothing.\n\nBoth 'ascii' and 'unicode' use NFKD normalization from\n:func:`unicodedata.normalize`." + "description": "Remove accents and perform other character normalization\nduring the preprocessing step.\n'ascii' is a fast method that only works on characters that have\na direct ASCII mapping.\n'unicode' is a slightly slower method that works on any characters.\nNone (default) does nothing.\n\nBoth 'ascii' and 'unicode' use NFKD normalization from\n:func:`unicodedata.normalize`." } }, { @@ -78269,7 +80389,9 @@ }, { "name": "_get_hasher", + "unique_name": "_get_hasher", "qname": "sklearn.feature_extraction.text.HashingVectorizer._get_hasher", + "unique_qname": "sklearn.feature_extraction.text.HashingVectorizer._get_hasher", "decorators": [], "parameters": [ { @@ -78291,7 +80413,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.feature_extraction.text.HashingVectorizer._more_tags", + "unique_qname": "sklearn.feature_extraction.text.HashingVectorizer._more_tags", "decorators": [], "parameters": [ { @@ -78313,7 +80437,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.feature_extraction.text.HashingVectorizer.fit", + "unique_qname": "sklearn.feature_extraction.text.HashingVectorizer.fit", "decorators": [], "parameters": [ { @@ -78355,7 +80481,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.feature_extraction.text.HashingVectorizer.fit_transform", + "unique_qname": "sklearn.feature_extraction.text.HashingVectorizer.fit_transform", "decorators": [], "parameters": [ { @@ -78397,7 +80525,9 @@ }, { "name": "partial_fit", + "unique_name": "partial_fit", "qname": "sklearn.feature_extraction.text.HashingVectorizer.partial_fit", + "unique_qname": "sklearn.feature_extraction.text.HashingVectorizer.partial_fit", "decorators": [], "parameters": [ { @@ -78439,7 +80569,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.feature_extraction.text.HashingVectorizer.transform", + "unique_qname": "sklearn.feature_extraction.text.HashingVectorizer.transform", "decorators": [], "parameters": [ { @@ -78471,7 +80603,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.feature_extraction.text.TfidfTransformer.__init__", + "unique_qname": "sklearn.feature_extraction.text.TfidfTransformer.__init__", "decorators": [], "parameters": [ { @@ -78501,7 +80635,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "bool, default=True", - "description": "Enable inverse-document-frequency reweighting." + "description": "Enable inverse-document-frequency reweighting. If False, idf(t) = 1." } }, { @@ -78533,7 +80667,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.feature_extraction.text.TfidfTransformer._more_tags", + "unique_qname": "sklearn.feature_extraction.text.TfidfTransformer._more_tags", "decorators": [], "parameters": [ { @@ -78555,7 +80691,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.feature_extraction.text.TfidfTransformer.fit", + "unique_qname": "sklearn.feature_extraction.text.TfidfTransformer.fit", "decorators": [], "parameters": [ { @@ -78597,7 +80735,33 @@ }, { "name": "idf_", + "unique_name": "idf_@getter", + "qname": "sklearn.feature_extraction.text.TfidfTransformer.idf_", + "unique_qname": "sklearn.feature_extraction.text.TfidfTransformer.idf_@getter", + "decorators": ["property"], + "parameters": [ + { + "name": "self", + "default_value": null, + "is_public": true, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "", + "description": "" + } + } + ], + "results": [], + "is_public": true, + "description": "Inverse document frequency vector, only defined if `use_idf=True`.", + "docstring": "Inverse document frequency vector, only defined if `use_idf=True`.\n\nReturns\n-------\nndarray of shape (n_features,)", + "source_code": "\n@property\ndef idf_(self):\n \"\"\"Inverse document frequency vector, only defined if `use_idf=True`.\n\n Returns\n -------\n ndarray of shape (n_features,)\n \"\"\"\n return np.ravel(self._idf_diag.sum(axis=0))" + }, + { + "name": "idf_", + "unique_name": "idf_@setter", "qname": "sklearn.feature_extraction.text.TfidfTransformer.idf_", + "unique_qname": "sklearn.feature_extraction.text.TfidfTransformer.idf_@setter", "decorators": ["idf_.setter"], "parameters": [ { @@ -78629,7 +80793,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.feature_extraction.text.TfidfTransformer.transform", + "unique_qname": "sklearn.feature_extraction.text.TfidfTransformer.transform", "decorators": [], "parameters": [ { @@ -78671,7 +80837,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.feature_extraction.text.TfidfVectorizer.__init__", + "unique_qname": "sklearn.feature_extraction.text.TfidfVectorizer.__init__", "decorators": [], "parameters": [ { @@ -78871,7 +81039,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "bool, default=True", - "description": "Enable inverse-document-frequency reweighting." + "description": "Enable inverse-document-frequency reweighting. If False, idf(t) = 1." } }, { @@ -78903,7 +81071,9 @@ }, { "name": "_check_params", + "unique_name": "_check_params", "qname": "sklearn.feature_extraction.text.TfidfVectorizer._check_params", + "unique_qname": "sklearn.feature_extraction.text.TfidfVectorizer._check_params", "decorators": [], "parameters": [ { @@ -78925,7 +81095,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.feature_extraction.text.TfidfVectorizer._more_tags", + "unique_qname": "sklearn.feature_extraction.text.TfidfVectorizer._more_tags", "decorators": [], "parameters": [ { @@ -78947,7 +81119,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.feature_extraction.text.TfidfVectorizer.fit", + "unique_qname": "sklearn.feature_extraction.text.TfidfVectorizer.fit", "decorators": [], "parameters": [ { @@ -78989,7 +81163,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.feature_extraction.text.TfidfVectorizer.fit_transform", + "unique_qname": "sklearn.feature_extraction.text.TfidfVectorizer.fit_transform", "decorators": [], "parameters": [ { @@ -79031,7 +81207,33 @@ }, { "name": "idf_", + "unique_name": "idf_@getter", "qname": "sklearn.feature_extraction.text.TfidfVectorizer.idf_", + "unique_qname": "sklearn.feature_extraction.text.TfidfVectorizer.idf_@getter", + "decorators": ["property"], + "parameters": [ + { + "name": "self", + "default_value": null, + "is_public": true, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "", + "description": "" + } + } + ], + "results": [], + "is_public": true, + "description": "Inverse document frequency vector, only defined if `use_idf=True`.", + "docstring": "Inverse document frequency vector, only defined if `use_idf=True`.\n\nReturns\n-------\nndarray of shape (n_features,)", + "source_code": "\n@property\ndef idf_(self):\n \"\"\"Inverse document frequency vector, only defined if `use_idf=True`.\n\n Returns\n -------\n ndarray of shape (n_features,)\n \"\"\"\n return self._tfidf.idf_" + }, + { + "name": "idf_", + "unique_name": "idf_@setter", + "qname": "sklearn.feature_extraction.text.TfidfVectorizer.idf_", + "unique_qname": "sklearn.feature_extraction.text.TfidfVectorizer.idf_@setter", "decorators": ["idf_.setter"], "parameters": [ { @@ -79063,7 +81265,33 @@ }, { "name": "norm", + "unique_name": "norm@getter", "qname": "sklearn.feature_extraction.text.TfidfVectorizer.norm", + "unique_qname": "sklearn.feature_extraction.text.TfidfVectorizer.norm@getter", + "decorators": ["property"], + "parameters": [ + { + "name": "self", + "default_value": null, + "is_public": true, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "", + "description": "" + } + } + ], + "results": [], + "is_public": true, + "description": "Norm of each row output, can be either \"l1\" or \"l2\".", + "docstring": "Norm of each row output, can be either \"l1\" or \"l2\".", + "source_code": "\n@property\ndef norm(self):\n \"\"\"Norm of each row output, can be either \"l1\" or \"l2\".\"\"\"\n return self._tfidf.norm" + }, + { + "name": "norm", + "unique_name": "norm@setter", + "qname": "sklearn.feature_extraction.text.TfidfVectorizer.norm", + "unique_qname": "sklearn.feature_extraction.text.TfidfVectorizer.norm@setter", "decorators": ["norm.setter"], "parameters": [ { @@ -79095,7 +81323,33 @@ }, { "name": "smooth_idf", + "unique_name": "smooth_idf@getter", + "qname": "sklearn.feature_extraction.text.TfidfVectorizer.smooth_idf", + "unique_qname": "sklearn.feature_extraction.text.TfidfVectorizer.smooth_idf@getter", + "decorators": ["property"], + "parameters": [ + { + "name": "self", + "default_value": null, + "is_public": true, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "", + "description": "" + } + } + ], + "results": [], + "is_public": true, + "description": "Whether or not IDF weights are smoothed.", + "docstring": "Whether or not IDF weights are smoothed.", + "source_code": "\n@property\ndef smooth_idf(self):\n \"\"\"Whether or not IDF weights are smoothed.\"\"\"\n return self._tfidf.smooth_idf" + }, + { + "name": "smooth_idf", + "unique_name": "smooth_idf@setter", "qname": "sklearn.feature_extraction.text.TfidfVectorizer.smooth_idf", + "unique_qname": "sklearn.feature_extraction.text.TfidfVectorizer.smooth_idf@setter", "decorators": ["smooth_idf.setter"], "parameters": [ { @@ -79127,7 +81381,33 @@ }, { "name": "sublinear_tf", + "unique_name": "sublinear_tf@getter", "qname": "sklearn.feature_extraction.text.TfidfVectorizer.sublinear_tf", + "unique_qname": "sklearn.feature_extraction.text.TfidfVectorizer.sublinear_tf@getter", + "decorators": ["property"], + "parameters": [ + { + "name": "self", + "default_value": null, + "is_public": true, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "", + "description": "" + } + } + ], + "results": [], + "is_public": true, + "description": "Whether or not sublinear TF scaling is applied.", + "docstring": "Whether or not sublinear TF scaling is applied.", + "source_code": "\n@property\ndef sublinear_tf(self):\n \"\"\"Whether or not sublinear TF scaling is applied.\"\"\"\n return self._tfidf.sublinear_tf" + }, + { + "name": "sublinear_tf", + "unique_name": "sublinear_tf@setter", + "qname": "sklearn.feature_extraction.text.TfidfVectorizer.sublinear_tf", + "unique_qname": "sklearn.feature_extraction.text.TfidfVectorizer.sublinear_tf@setter", "decorators": ["sublinear_tf.setter"], "parameters": [ { @@ -79159,7 +81439,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.feature_extraction.text.TfidfVectorizer.transform", + "unique_qname": "sklearn.feature_extraction.text.TfidfVectorizer.transform", "decorators": [], "parameters": [ { @@ -79191,7 +81473,33 @@ }, { "name": "use_idf", + "unique_name": "use_idf@getter", "qname": "sklearn.feature_extraction.text.TfidfVectorizer.use_idf", + "unique_qname": "sklearn.feature_extraction.text.TfidfVectorizer.use_idf@getter", + "decorators": ["property"], + "parameters": [ + { + "name": "self", + "default_value": null, + "is_public": true, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "", + "description": "" + } + } + ], + "results": [], + "is_public": true, + "description": "Whether or not IDF re-weighting is used.", + "docstring": "Whether or not IDF re-weighting is used.", + "source_code": "\n@property\ndef use_idf(self):\n \"\"\"Whether or not IDF re-weighting is used.\"\"\"\n return self._tfidf.use_idf" + }, + { + "name": "use_idf", + "unique_name": "use_idf@setter", + "qname": "sklearn.feature_extraction.text.TfidfVectorizer.use_idf", + "unique_qname": "sklearn.feature_extraction.text.TfidfVectorizer.use_idf@setter", "decorators": ["use_idf.setter"], "parameters": [ { @@ -79223,7 +81531,9 @@ }, { "name": "_char_ngrams", + "unique_name": "_char_ngrams", "qname": "sklearn.feature_extraction.text._VectorizerMixin._char_ngrams", + "unique_qname": "sklearn.feature_extraction.text._VectorizerMixin._char_ngrams", "decorators": [], "parameters": [ { @@ -79255,7 +81565,9 @@ }, { "name": "_char_wb_ngrams", + "unique_name": "_char_wb_ngrams", "qname": "sklearn.feature_extraction.text._VectorizerMixin._char_wb_ngrams", + "unique_qname": "sklearn.feature_extraction.text._VectorizerMixin._char_wb_ngrams", "decorators": [], "parameters": [ { @@ -79287,7 +81599,9 @@ }, { "name": "_check_stop_words_consistency", + "unique_name": "_check_stop_words_consistency", "qname": "sklearn.feature_extraction.text._VectorizerMixin._check_stop_words_consistency", + "unique_qname": "sklearn.feature_extraction.text._VectorizerMixin._check_stop_words_consistency", "decorators": [], "parameters": [ { @@ -79339,7 +81653,9 @@ }, { "name": "_check_vocabulary", + "unique_name": "_check_vocabulary", "qname": "sklearn.feature_extraction.text._VectorizerMixin._check_vocabulary", + "unique_qname": "sklearn.feature_extraction.text._VectorizerMixin._check_vocabulary", "decorators": [], "parameters": [ { @@ -79361,7 +81677,9 @@ }, { "name": "_validate_params", + "unique_name": "_validate_params", "qname": "sklearn.feature_extraction.text._VectorizerMixin._validate_params", + "unique_qname": "sklearn.feature_extraction.text._VectorizerMixin._validate_params", "decorators": [], "parameters": [ { @@ -79383,7 +81701,9 @@ }, { "name": "_validate_vocabulary", + "unique_name": "_validate_vocabulary", "qname": "sklearn.feature_extraction.text._VectorizerMixin._validate_vocabulary", + "unique_qname": "sklearn.feature_extraction.text._VectorizerMixin._validate_vocabulary", "decorators": [], "parameters": [ { @@ -79405,7 +81725,9 @@ }, { "name": "_warn_for_unused_params", + "unique_name": "_warn_for_unused_params", "qname": "sklearn.feature_extraction.text._VectorizerMixin._warn_for_unused_params", + "unique_qname": "sklearn.feature_extraction.text._VectorizerMixin._warn_for_unused_params", "decorators": [], "parameters": [ { @@ -79427,7 +81749,9 @@ }, { "name": "_word_ngrams", + "unique_name": "_word_ngrams", "qname": "sklearn.feature_extraction.text._VectorizerMixin._word_ngrams", + "unique_qname": "sklearn.feature_extraction.text._VectorizerMixin._word_ngrams", "decorators": [], "parameters": [ { @@ -79469,7 +81793,9 @@ }, { "name": "build_analyzer", + "unique_name": "build_analyzer", "qname": "sklearn.feature_extraction.text._VectorizerMixin.build_analyzer", + "unique_qname": "sklearn.feature_extraction.text._VectorizerMixin.build_analyzer", "decorators": [], "parameters": [ { @@ -79491,7 +81817,9 @@ }, { "name": "build_preprocessor", + "unique_name": "build_preprocessor", "qname": "sklearn.feature_extraction.text._VectorizerMixin.build_preprocessor", + "unique_qname": "sklearn.feature_extraction.text._VectorizerMixin.build_preprocessor", "decorators": [], "parameters": [ { @@ -79513,7 +81841,9 @@ }, { "name": "build_tokenizer", + "unique_name": "build_tokenizer", "qname": "sklearn.feature_extraction.text._VectorizerMixin.build_tokenizer", + "unique_qname": "sklearn.feature_extraction.text._VectorizerMixin.build_tokenizer", "decorators": [], "parameters": [ { @@ -79535,7 +81865,9 @@ }, { "name": "decode", + "unique_name": "decode", "qname": "sklearn.feature_extraction.text._VectorizerMixin.decode", + "unique_qname": "sklearn.feature_extraction.text._VectorizerMixin.decode", "decorators": [], "parameters": [ { @@ -79554,7 +81886,7 @@ "is_public": false, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "str", + "type": "bytes or str", "description": "The string to decode." } } @@ -79562,12 +81894,14 @@ "results": [], "is_public": false, "description": "Decode the input into a string of unicode symbols.\n\nThe decoding strategy depends on the vectorizer parameters.", - "docstring": "Decode the input into a string of unicode symbols.\n\nThe decoding strategy depends on the vectorizer parameters.\n\nParameters\n----------\ndoc : str\n The string to decode.\n\nReturns\n-------\ndoc: str\n A string of unicode symbols.", - "source_code": "\ndef decode(self, doc):\n \"\"\"Decode the input into a string of unicode symbols.\n\n The decoding strategy depends on the vectorizer parameters.\n\n Parameters\n ----------\n doc : str\n The string to decode.\n\n Returns\n -------\n doc: str\n A string of unicode symbols.\n \"\"\"\n if self.input == 'filename':\n with open(doc, 'rb') as fh:\n doc = fh.read()\n elif self.input == 'file':\n doc = doc.read()\n if isinstance(doc, bytes):\n doc = doc.decode(self.encoding, self.decode_error)\n if doc is np.nan:\n raise ValueError('np.nan is an invalid document, expected byte or unicode string.')\n return doc" + "docstring": "Decode the input into a string of unicode symbols.\n\nThe decoding strategy depends on the vectorizer parameters.\n\nParameters\n----------\ndoc : bytes or str\n The string to decode.\n\nReturns\n-------\ndoc: str\n A string of unicode symbols.", + "source_code": "\ndef decode(self, doc):\n \"\"\"Decode the input into a string of unicode symbols.\n\n The decoding strategy depends on the vectorizer parameters.\n\n Parameters\n ----------\n doc : bytes or str\n The string to decode.\n\n Returns\n -------\n doc: str\n A string of unicode symbols.\n \"\"\"\n if self.input == 'filename':\n with open(doc, 'rb') as fh:\n doc = fh.read()\n elif self.input == 'file':\n doc = doc.read()\n if isinstance(doc, bytes):\n doc = doc.decode(self.encoding, self.decode_error)\n if doc is np.nan:\n raise ValueError('np.nan is an invalid document, expected byte or unicode string.')\n return doc" }, { "name": "get_stop_words", + "unique_name": "get_stop_words", "qname": "sklearn.feature_extraction.text._VectorizerMixin.get_stop_words", + "unique_qname": "sklearn.feature_extraction.text._VectorizerMixin.get_stop_words", "decorators": [], "parameters": [ { @@ -79589,7 +81923,9 @@ }, { "name": "_analyze", + "unique_name": "_analyze", "qname": "sklearn.feature_extraction.text._analyze", + "unique_qname": "sklearn.feature_extraction.text._analyze", "decorators": [], "parameters": [ { @@ -79671,7 +82007,9 @@ }, { "name": "_check_stop_list", + "unique_name": "_check_stop_list", "qname": "sklearn.feature_extraction.text._check_stop_list", + "unique_qname": "sklearn.feature_extraction.text._check_stop_list", "decorators": [], "parameters": [ { @@ -79693,7 +82031,9 @@ }, { "name": "_document_frequency", + "unique_name": "_document_frequency", "qname": "sklearn.feature_extraction.text._document_frequency", + "unique_qname": "sklearn.feature_extraction.text._document_frequency", "decorators": [], "parameters": [ { @@ -79715,7 +82055,9 @@ }, { "name": "_make_int_array", + "unique_name": "_make_int_array", "qname": "sklearn.feature_extraction.text._make_int_array", + "unique_qname": "sklearn.feature_extraction.text._make_int_array", "decorators": [], "parameters": [], "results": [], @@ -79726,7 +82068,9 @@ }, { "name": "_preprocess", + "unique_name": "_preprocess", "qname": "sklearn.feature_extraction.text._preprocess", + "unique_qname": "sklearn.feature_extraction.text._preprocess", "decorators": [], "parameters": [ { @@ -79768,7 +82112,9 @@ }, { "name": "strip_accents_ascii", + "unique_name": "strip_accents_ascii", "qname": "sklearn.feature_extraction.text.strip_accents_ascii", + "unique_qname": "sklearn.feature_extraction.text.strip_accents_ascii", "decorators": [], "parameters": [ { @@ -79777,7 +82123,7 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "string", + "type": "str", "description": "The string to strip" } } @@ -79785,12 +82131,14 @@ "results": [], "is_public": true, "description": "Transform accentuated unicode symbols into ascii or nothing\n\nWarning: this solution is only suited for languages that have a direct transliteration to ASCII symbols.", - "docstring": "Transform accentuated unicode symbols into ascii or nothing\n\nWarning: this solution is only suited for languages that have a direct\ntransliteration to ASCII symbols.\n\nParameters\n----------\ns : string\n The string to strip\n\nSee Also\n--------\nstrip_accents_unicode : Remove accentuated char for any unicode symbol.", - "source_code": "\ndef strip_accents_ascii(s):\n \"\"\"Transform accentuated unicode symbols into ascii or nothing\n\n Warning: this solution is only suited for languages that have a direct\n transliteration to ASCII symbols.\n\n Parameters\n ----------\n s : string\n The string to strip\n\n See Also\n --------\n strip_accents_unicode : Remove accentuated char for any unicode symbol.\n \"\"\"\n nkfd_form = unicodedata.normalize('NFKD', s)\n return nkfd_form.encode('ASCII', 'ignore').decode('ASCII')" + "docstring": "Transform accentuated unicode symbols into ascii or nothing\n\nWarning: this solution is only suited for languages that have a direct\ntransliteration to ASCII symbols.\n\nParameters\n----------\ns : str\n The string to strip\n\nSee Also\n--------\nstrip_accents_unicode : Remove accentuated char for any unicode symbol.", + "source_code": "\ndef strip_accents_ascii(s):\n \"\"\"Transform accentuated unicode symbols into ascii or nothing\n\n Warning: this solution is only suited for languages that have a direct\n transliteration to ASCII symbols.\n\n Parameters\n ----------\n s : str\n The string to strip\n\n See Also\n --------\n strip_accents_unicode : Remove accentuated char for any unicode symbol.\n \"\"\"\n nkfd_form = unicodedata.normalize('NFKD', s)\n return nkfd_form.encode('ASCII', 'ignore').decode('ASCII')" }, { "name": "strip_accents_unicode", + "unique_name": "strip_accents_unicode", "qname": "sklearn.feature_extraction.text.strip_accents_unicode", + "unique_qname": "sklearn.feature_extraction.text.strip_accents_unicode", "decorators": [], "parameters": [ { @@ -79812,7 +82160,9 @@ }, { "name": "strip_tags", + "unique_name": "strip_tags", "qname": "sklearn.feature_extraction.text.strip_tags", + "unique_qname": "sklearn.feature_extraction.text.strip_tags", "decorators": [], "parameters": [ { @@ -79821,7 +82171,7 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "string", + "type": "str", "description": "The string to strip" } } @@ -79829,12 +82179,14 @@ "results": [], "is_public": true, "description": "Basic regexp based HTML / XML tag stripper function\n\nFor serious HTML/XML preprocessing you should rather use an external library such as lxml or BeautifulSoup.", - "docstring": "Basic regexp based HTML / XML tag stripper function\n\nFor serious HTML/XML preprocessing you should rather use an external\nlibrary such as lxml or BeautifulSoup.\n\nParameters\n----------\ns : string\n The string to strip", - "source_code": "\ndef strip_tags(s):\n \"\"\"Basic regexp based HTML / XML tag stripper function\n\n For serious HTML/XML preprocessing you should rather use an external\n library such as lxml or BeautifulSoup.\n\n Parameters\n ----------\n s : string\n The string to strip\n \"\"\"\n return re.compile('<([^>]+)>', flags=re.UNICODE).sub(' ', s)" + "docstring": "Basic regexp based HTML / XML tag stripper function\n\nFor serious HTML/XML preprocessing you should rather use an external\nlibrary such as lxml or BeautifulSoup.\n\nParameters\n----------\ns : str\n The string to strip", + "source_code": "\ndef strip_tags(s):\n \"\"\"Basic regexp based HTML / XML tag stripper function\n\n For serious HTML/XML preprocessing you should rather use an external\n library such as lxml or BeautifulSoup.\n\n Parameters\n ----------\n s : str\n The string to strip\n \"\"\"\n return re.compile('<([^>]+)>', flags=re.UNICODE).sub(' ', s)" }, { "name": "_get_support_mask", + "unique_name": "_get_support_mask", "qname": "sklearn.feature_selection._base.SelectorMixin._get_support_mask", + "unique_qname": "sklearn.feature_selection._base.SelectorMixin._get_support_mask", "decorators": ["abstractmethod"], "parameters": [ { @@ -79856,7 +82208,9 @@ }, { "name": "get_feature_names_out", + "unique_name": "get_feature_names_out", "qname": "sklearn.feature_selection._base.SelectorMixin.get_feature_names_out", + "unique_qname": "sklearn.feature_selection._base.SelectorMixin.get_feature_names_out", "decorators": [], "parameters": [ { @@ -79888,7 +82242,9 @@ }, { "name": "get_support", + "unique_name": "get_support", "qname": "sklearn.feature_selection._base.SelectorMixin.get_support", + "unique_qname": "sklearn.feature_selection._base.SelectorMixin.get_support", "decorators": [], "parameters": [ { @@ -79920,7 +82276,9 @@ }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.feature_selection._base.SelectorMixin.inverse_transform", + "unique_qname": "sklearn.feature_selection._base.SelectorMixin.inverse_transform", "decorators": [], "parameters": [ { @@ -79952,7 +82310,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.feature_selection._base.SelectorMixin.transform", + "unique_qname": "sklearn.feature_selection._base.SelectorMixin.transform", "decorators": [], "parameters": [ { @@ -79984,7 +82344,9 @@ }, { "name": "_get_feature_importances", + "unique_name": "_get_feature_importances", "qname": "sklearn.feature_selection._base._get_feature_importances", + "unique_qname": "sklearn.feature_selection._base._get_feature_importances", "decorators": [], "parameters": [ { @@ -80036,7 +82398,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.feature_selection._from_model.SelectFromModel.__init__", + "unique_qname": "sklearn.feature_selection._from_model.SelectFromModel.__init__", "decorators": [], "parameters": [ { @@ -80118,7 +82482,9 @@ }, { "name": "_get_support_mask", + "unique_name": "_get_support_mask", "qname": "sklearn.feature_selection._from_model.SelectFromModel._get_support_mask", + "unique_qname": "sklearn.feature_selection._from_model.SelectFromModel._get_support_mask", "decorators": [], "parameters": [ { @@ -80140,7 +82506,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.feature_selection._from_model.SelectFromModel._more_tags", + "unique_qname": "sklearn.feature_selection._from_model.SelectFromModel._more_tags", "decorators": [], "parameters": [ { @@ -80162,7 +82530,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.feature_selection._from_model.SelectFromModel.fit", + "unique_qname": "sklearn.feature_selection._from_model.SelectFromModel.fit", "decorators": [], "parameters": [ { @@ -80204,7 +82574,9 @@ }, { "name": "n_features_in_", + "unique_name": "n_features_in_@getter", "qname": "sklearn.feature_selection._from_model.SelectFromModel.n_features_in_", + "unique_qname": "sklearn.feature_selection._from_model.SelectFromModel.n_features_in_@getter", "decorators": ["property"], "parameters": [ { @@ -80226,7 +82598,9 @@ }, { "name": "partial_fit", + "unique_name": "partial_fit", "qname": "sklearn.feature_selection._from_model.SelectFromModel.partial_fit", + "unique_qname": "sklearn.feature_selection._from_model.SelectFromModel.partial_fit", "decorators": ["if_delegate_has_method('estimator')"], "parameters": [ { @@ -80268,7 +82642,9 @@ }, { "name": "threshold_", + "unique_name": "threshold_@getter", "qname": "sklearn.feature_selection._from_model.SelectFromModel.threshold_", + "unique_qname": "sklearn.feature_selection._from_model.SelectFromModel.threshold_@getter", "decorators": ["property"], "parameters": [ { @@ -80290,7 +82666,9 @@ }, { "name": "_calculate_threshold", + "unique_name": "_calculate_threshold", "qname": "sklearn.feature_selection._from_model._calculate_threshold", + "unique_qname": "sklearn.feature_selection._from_model._calculate_threshold", "decorators": [], "parameters": [ { @@ -80332,7 +82710,9 @@ }, { "name": "_compute_mi", + "unique_name": "_compute_mi", "qname": "sklearn.feature_selection._mutual_info._compute_mi", + "unique_qname": "sklearn.feature_selection._mutual_info._compute_mi", "decorators": [], "parameters": [ { @@ -80394,7 +82774,9 @@ }, { "name": "_compute_mi_cc", + "unique_name": "_compute_mi_cc", "qname": "sklearn.feature_selection._mutual_info._compute_mi_cc", + "unique_qname": "sklearn.feature_selection._mutual_info._compute_mi_cc", "decorators": [], "parameters": [ { @@ -80436,7 +82818,9 @@ }, { "name": "_compute_mi_cd", + "unique_name": "_compute_mi_cd", "qname": "sklearn.feature_selection._mutual_info._compute_mi_cd", + "unique_qname": "sklearn.feature_selection._mutual_info._compute_mi_cd", "decorators": [], "parameters": [ { @@ -80478,7 +82862,9 @@ }, { "name": "_estimate_mi", + "unique_name": "_estimate_mi", "qname": "sklearn.feature_selection._mutual_info._estimate_mi", + "unique_qname": "sklearn.feature_selection._mutual_info._estimate_mi", "decorators": [], "parameters": [ { @@ -80560,7 +82946,9 @@ }, { "name": "_iterate_columns", + "unique_name": "_iterate_columns", "qname": "sklearn.feature_selection._mutual_info._iterate_columns", + "unique_qname": "sklearn.feature_selection._mutual_info._iterate_columns", "decorators": [], "parameters": [ { @@ -80592,7 +82980,9 @@ }, { "name": "mutual_info_classif", + "unique_name": "mutual_info_classif", "qname": "sklearn.feature_selection._mutual_info.mutual_info_classif", + "unique_qname": "sklearn.feature_selection._mutual_info.mutual_info_classif", "decorators": [], "parameters": [ { @@ -80664,7 +83054,9 @@ }, { "name": "mutual_info_regression", + "unique_name": "mutual_info_regression", "qname": "sklearn.feature_selection._mutual_info.mutual_info_regression", + "unique_qname": "sklearn.feature_selection._mutual_info.mutual_info_regression", "decorators": [], "parameters": [ { @@ -80736,7 +83128,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.feature_selection._rfe.RFE.__init__", + "unique_qname": "sklearn.feature_selection._rfe.RFE.__init__", "decorators": [], "parameters": [ { @@ -80808,7 +83202,9 @@ }, { "name": "_estimator_type", + "unique_name": "_estimator_type@getter", "qname": "sklearn.feature_selection._rfe.RFE._estimator_type", + "unique_qname": "sklearn.feature_selection._rfe.RFE._estimator_type@getter", "decorators": ["property"], "parameters": [ { @@ -80830,7 +83226,9 @@ }, { "name": "_fit", + "unique_name": "_fit", "qname": "sklearn.feature_selection._rfe.RFE._fit", + "unique_qname": "sklearn.feature_selection._rfe.RFE._fit", "decorators": [], "parameters": [ { @@ -80882,7 +83280,9 @@ }, { "name": "_get_support_mask", + "unique_name": "_get_support_mask", "qname": "sklearn.feature_selection._rfe.RFE._get_support_mask", + "unique_qname": "sklearn.feature_selection._rfe.RFE._get_support_mask", "decorators": [], "parameters": [ { @@ -80904,7 +83304,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.feature_selection._rfe.RFE._more_tags", + "unique_qname": "sklearn.feature_selection._rfe.RFE._more_tags", "decorators": [], "parameters": [ { @@ -80926,7 +83328,9 @@ }, { "name": "classes_", + "unique_name": "classes_@getter", "qname": "sklearn.feature_selection._rfe.RFE.classes_", + "unique_qname": "sklearn.feature_selection._rfe.RFE.classes_@getter", "decorators": ["property"], "parameters": [ { @@ -80948,7 +83352,9 @@ }, { "name": "decision_function", + "unique_name": "decision_function", "qname": "sklearn.feature_selection._rfe.RFE.decision_function", + "unique_qname": "sklearn.feature_selection._rfe.RFE.decision_function", "decorators": ["if_delegate_has_method(delegate='estimator')"], "parameters": [ { @@ -80980,7 +83386,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.feature_selection._rfe.RFE.fit", + "unique_qname": "sklearn.feature_selection._rfe.RFE.fit", "decorators": [], "parameters": [ { @@ -81022,7 +83430,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.feature_selection._rfe.RFE.predict", + "unique_qname": "sklearn.feature_selection._rfe.RFE.predict", "decorators": ["if_delegate_has_method(delegate='estimator')"], "parameters": [ { @@ -81054,7 +83464,9 @@ }, { "name": "predict_log_proba", + "unique_name": "predict_log_proba", "qname": "sklearn.feature_selection._rfe.RFE.predict_log_proba", + "unique_qname": "sklearn.feature_selection._rfe.RFE.predict_log_proba", "decorators": ["if_delegate_has_method(delegate='estimator')"], "parameters": [ { @@ -81086,7 +83498,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.feature_selection._rfe.RFE.predict_proba", + "unique_qname": "sklearn.feature_selection._rfe.RFE.predict_proba", "decorators": ["if_delegate_has_method(delegate='estimator')"], "parameters": [ { @@ -81118,7 +83532,9 @@ }, { "name": "score", + "unique_name": "score", "qname": "sklearn.feature_selection._rfe.RFE.score", + "unique_qname": "sklearn.feature_selection._rfe.RFE.score", "decorators": ["if_delegate_has_method(delegate='estimator')"], "parameters": [ { @@ -81160,7 +83576,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.feature_selection._rfe.RFECV.__init__", + "unique_qname": "sklearn.feature_selection._rfe.RFECV.__init__", "decorators": [], "parameters": [ { @@ -81262,7 +83680,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.feature_selection._rfe.RFECV.fit", + "unique_qname": "sklearn.feature_selection._rfe.RFECV.fit", "decorators": [], "parameters": [ { @@ -81314,7 +83734,9 @@ }, { "name": "grid_scores_", + "unique_name": "grid_scores_@getter", "qname": "sklearn.feature_selection._rfe.RFECV.grid_scores_", + "unique_qname": "sklearn.feature_selection._rfe.RFECV.grid_scores_@getter", "decorators": [ "deprecated('The `grid_scores_` attribute is deprecated in version 1.0 in favor of `cv_results_` and will be removed in version 1.2.')", "property" @@ -81339,7 +83761,9 @@ }, { "name": "_rfe_single_fit", + "unique_name": "_rfe_single_fit", "qname": "sklearn.feature_selection._rfe._rfe_single_fit", + "unique_qname": "sklearn.feature_selection._rfe._rfe_single_fit", "decorators": [], "parameters": [ { @@ -81421,7 +83845,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.feature_selection._sequential.SequentialFeatureSelector.__init__", + "unique_qname": "sklearn.feature_selection._sequential.SequentialFeatureSelector.__init__", "decorators": [], "parameters": [ { @@ -81503,7 +83929,9 @@ }, { "name": "_get_best_new_feature", + "unique_name": "_get_best_new_feature", "qname": "sklearn.feature_selection._sequential.SequentialFeatureSelector._get_best_new_feature", + "unique_qname": "sklearn.feature_selection._sequential.SequentialFeatureSelector._get_best_new_feature", "decorators": [], "parameters": [ { @@ -81565,7 +83993,9 @@ }, { "name": "_get_support_mask", + "unique_name": "_get_support_mask", "qname": "sklearn.feature_selection._sequential.SequentialFeatureSelector._get_support_mask", + "unique_qname": "sklearn.feature_selection._sequential.SequentialFeatureSelector._get_support_mask", "decorators": [], "parameters": [ { @@ -81587,7 +84017,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.feature_selection._sequential.SequentialFeatureSelector._more_tags", + "unique_qname": "sklearn.feature_selection._sequential.SequentialFeatureSelector._more_tags", "decorators": [], "parameters": [ { @@ -81609,7 +84041,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.feature_selection._sequential.SequentialFeatureSelector.fit", + "unique_qname": "sklearn.feature_selection._sequential.SequentialFeatureSelector.fit", "decorators": [], "parameters": [ { @@ -81651,7 +84085,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.feature_selection._univariate_selection.GenericUnivariateSelect.__init__", + "unique_qname": "sklearn.feature_selection._univariate_selection.GenericUnivariateSelect.__init__", "decorators": [], "parameters": [ { @@ -81703,7 +84139,9 @@ }, { "name": "_check_params", + "unique_name": "_check_params", "qname": "sklearn.feature_selection._univariate_selection.GenericUnivariateSelect._check_params", + "unique_qname": "sklearn.feature_selection._univariate_selection.GenericUnivariateSelect._check_params", "decorators": [], "parameters": [ { @@ -81745,7 +84183,9 @@ }, { "name": "_get_support_mask", + "unique_name": "_get_support_mask", "qname": "sklearn.feature_selection._univariate_selection.GenericUnivariateSelect._get_support_mask", + "unique_qname": "sklearn.feature_selection._univariate_selection.GenericUnivariateSelect._get_support_mask", "decorators": [], "parameters": [ { @@ -81767,7 +84207,9 @@ }, { "name": "_make_selector", + "unique_name": "_make_selector", "qname": "sklearn.feature_selection._univariate_selection.GenericUnivariateSelect._make_selector", + "unique_qname": "sklearn.feature_selection._univariate_selection.GenericUnivariateSelect._make_selector", "decorators": [], "parameters": [ { @@ -81789,7 +84231,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.feature_selection._univariate_selection.SelectFdr.__init__", + "unique_qname": "sklearn.feature_selection._univariate_selection.SelectFdr.__init__", "decorators": [], "parameters": [ { @@ -81831,7 +84275,9 @@ }, { "name": "_get_support_mask", + "unique_name": "_get_support_mask", "qname": "sklearn.feature_selection._univariate_selection.SelectFdr._get_support_mask", + "unique_qname": "sklearn.feature_selection._univariate_selection.SelectFdr._get_support_mask", "decorators": [], "parameters": [ { @@ -81853,7 +84299,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.feature_selection._univariate_selection.SelectFpr.__init__", + "unique_qname": "sklearn.feature_selection._univariate_selection.SelectFpr.__init__", "decorators": [], "parameters": [ { @@ -81895,7 +84343,9 @@ }, { "name": "_get_support_mask", + "unique_name": "_get_support_mask", "qname": "sklearn.feature_selection._univariate_selection.SelectFpr._get_support_mask", + "unique_qname": "sklearn.feature_selection._univariate_selection.SelectFpr._get_support_mask", "decorators": [], "parameters": [ { @@ -81917,7 +84367,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.feature_selection._univariate_selection.SelectFwe.__init__", + "unique_qname": "sklearn.feature_selection._univariate_selection.SelectFwe.__init__", "decorators": [], "parameters": [ { @@ -81959,7 +84411,9 @@ }, { "name": "_get_support_mask", + "unique_name": "_get_support_mask", "qname": "sklearn.feature_selection._univariate_selection.SelectFwe._get_support_mask", + "unique_qname": "sklearn.feature_selection._univariate_selection.SelectFwe._get_support_mask", "decorators": [], "parameters": [ { @@ -81981,7 +84435,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.feature_selection._univariate_selection.SelectKBest.__init__", + "unique_qname": "sklearn.feature_selection._univariate_selection.SelectKBest.__init__", "decorators": [], "parameters": [ { @@ -82023,7 +84479,9 @@ }, { "name": "_check_params", + "unique_name": "_check_params", "qname": "sklearn.feature_selection._univariate_selection.SelectKBest._check_params", + "unique_qname": "sklearn.feature_selection._univariate_selection.SelectKBest._check_params", "decorators": [], "parameters": [ { @@ -82065,7 +84523,9 @@ }, { "name": "_get_support_mask", + "unique_name": "_get_support_mask", "qname": "sklearn.feature_selection._univariate_selection.SelectKBest._get_support_mask", + "unique_qname": "sklearn.feature_selection._univariate_selection.SelectKBest._get_support_mask", "decorators": [], "parameters": [ { @@ -82087,7 +84547,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.feature_selection._univariate_selection.SelectPercentile.__init__", + "unique_qname": "sklearn.feature_selection._univariate_selection.SelectPercentile.__init__", "decorators": [], "parameters": [ { @@ -82129,7 +84591,9 @@ }, { "name": "_check_params", + "unique_name": "_check_params", "qname": "sklearn.feature_selection._univariate_selection.SelectPercentile._check_params", + "unique_qname": "sklearn.feature_selection._univariate_selection.SelectPercentile._check_params", "decorators": [], "parameters": [ { @@ -82171,7 +84635,9 @@ }, { "name": "_get_support_mask", + "unique_name": "_get_support_mask", "qname": "sklearn.feature_selection._univariate_selection.SelectPercentile._get_support_mask", + "unique_qname": "sklearn.feature_selection._univariate_selection.SelectPercentile._get_support_mask", "decorators": [], "parameters": [ { @@ -82193,7 +84659,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.feature_selection._univariate_selection._BaseFilter.__init__", + "unique_qname": "sklearn.feature_selection._univariate_selection._BaseFilter.__init__", "decorators": [], "parameters": [ { @@ -82225,7 +84693,9 @@ }, { "name": "_check_params", + "unique_name": "_check_params", "qname": "sklearn.feature_selection._univariate_selection._BaseFilter._check_params", + "unique_qname": "sklearn.feature_selection._univariate_selection._BaseFilter._check_params", "decorators": [], "parameters": [ { @@ -82267,7 +84737,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.feature_selection._univariate_selection._BaseFilter._more_tags", + "unique_qname": "sklearn.feature_selection._univariate_selection._BaseFilter._more_tags", "decorators": [], "parameters": [ { @@ -82289,7 +84761,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.feature_selection._univariate_selection._BaseFilter.fit", + "unique_qname": "sklearn.feature_selection._univariate_selection._BaseFilter.fit", "decorators": [], "parameters": [ { @@ -82331,7 +84805,9 @@ }, { "name": "_chisquare", + "unique_name": "_chisquare", "qname": "sklearn.feature_selection._univariate_selection._chisquare", + "unique_qname": "sklearn.feature_selection._univariate_selection._chisquare", "decorators": [], "parameters": [ { @@ -82363,7 +84839,9 @@ }, { "name": "_clean_nans", + "unique_name": "_clean_nans", "qname": "sklearn.feature_selection._univariate_selection._clean_nans", + "unique_qname": "sklearn.feature_selection._univariate_selection._clean_nans", "decorators": [], "parameters": [ { @@ -82385,7 +84863,9 @@ }, { "name": "chi2", + "unique_name": "chi2", "qname": "sklearn.feature_selection._univariate_selection.chi2", + "unique_qname": "sklearn.feature_selection._univariate_selection.chi2", "decorators": [], "parameters": [ { @@ -82417,7 +84897,9 @@ }, { "name": "f_classif", + "unique_name": "f_classif", "qname": "sklearn.feature_selection._univariate_selection.f_classif", + "unique_qname": "sklearn.feature_selection._univariate_selection.f_classif", "decorators": [], "parameters": [ { @@ -82449,7 +84931,9 @@ }, { "name": "f_oneway", + "unique_name": "f_oneway", "qname": "sklearn.feature_selection._univariate_selection.f_oneway", + "unique_qname": "sklearn.feature_selection._univariate_selection.f_oneway", "decorators": [], "parameters": [], "results": [], @@ -82460,7 +84944,9 @@ }, { "name": "f_regression", + "unique_name": "f_regression", "qname": "sklearn.feature_selection._univariate_selection.f_regression", + "unique_qname": "sklearn.feature_selection._univariate_selection.f_regression", "decorators": [], "parameters": [ { @@ -82502,7 +84988,9 @@ }, { "name": "r_regression", + "unique_name": "r_regression", "qname": "sklearn.feature_selection._univariate_selection.r_regression", + "unique_qname": "sklearn.feature_selection._univariate_selection.r_regression", "decorators": [], "parameters": [ { @@ -82544,7 +85032,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.feature_selection._variance_threshold.VarianceThreshold.__init__", + "unique_qname": "sklearn.feature_selection._variance_threshold.VarianceThreshold.__init__", "decorators": [], "parameters": [ { @@ -82576,7 +85066,9 @@ }, { "name": "_get_support_mask", + "unique_name": "_get_support_mask", "qname": "sklearn.feature_selection._variance_threshold.VarianceThreshold._get_support_mask", + "unique_qname": "sklearn.feature_selection._variance_threshold.VarianceThreshold._get_support_mask", "decorators": [], "parameters": [ { @@ -82598,7 +85090,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.feature_selection._variance_threshold.VarianceThreshold._more_tags", + "unique_qname": "sklearn.feature_selection._variance_threshold.VarianceThreshold._more_tags", "decorators": [], "parameters": [ { @@ -82620,7 +85114,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.feature_selection._variance_threshold.VarianceThreshold.fit", + "unique_qname": "sklearn.feature_selection._variance_threshold.VarianceThreshold.fit", "decorators": [], "parameters": [ { @@ -82662,7 +85158,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.gaussian_process._gpc.GaussianProcessClassifier.__init__", + "unique_qname": "sklearn.gaussian_process._gpc.GaussianProcessClassifier.__init__", "decorators": [], "parameters": [ { @@ -82742,7 +85240,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int, RandomState instance or None, default=None", - "description": "Determines random number generation used to initialize the centers.\nPass an int for reproducible results across multiple function calls.\nSee :term: `Glossary `." + "description": "Determines random number generation used to initialize the centers.\nPass an int for reproducible results across multiple function calls.\nSee :term:`Glossary `." } }, { @@ -82774,7 +85272,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.gaussian_process._gpc.GaussianProcessClassifier.fit", + "unique_qname": "sklearn.gaussian_process._gpc.GaussianProcessClassifier.fit", "decorators": [], "parameters": [ { @@ -82816,7 +85316,9 @@ }, { "name": "kernel_", + "unique_name": "kernel_@getter", "qname": "sklearn.gaussian_process._gpc.GaussianProcessClassifier.kernel_", + "unique_qname": "sklearn.gaussian_process._gpc.GaussianProcessClassifier.kernel_@getter", "decorators": ["property"], "parameters": [ { @@ -82838,7 +85340,9 @@ }, { "name": "log_marginal_likelihood", + "unique_name": "log_marginal_likelihood", "qname": "sklearn.gaussian_process._gpc.GaussianProcessClassifier.log_marginal_likelihood", + "unique_qname": "sklearn.gaussian_process._gpc.GaussianProcessClassifier.log_marginal_likelihood", "decorators": [], "parameters": [ { @@ -82890,7 +85394,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.gaussian_process._gpc.GaussianProcessClassifier.predict", + "unique_qname": "sklearn.gaussian_process._gpc.GaussianProcessClassifier.predict", "decorators": [], "parameters": [ { @@ -82922,7 +85428,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.gaussian_process._gpc.GaussianProcessClassifier.predict_proba", + "unique_qname": "sklearn.gaussian_process._gpc.GaussianProcessClassifier.predict_proba", "decorators": [], "parameters": [ { @@ -82954,7 +85462,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.gaussian_process._gpc._BinaryGaussianProcessClassifierLaplace.__init__", + "unique_qname": "sklearn.gaussian_process._gpc._BinaryGaussianProcessClassifierLaplace.__init__", "decorators": [], "parameters": [ { @@ -83034,7 +85544,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int, RandomState instance or None, default=None", - "description": "Determines random number generation used to initialize the centers.\nPass an int for reproducible results across multiple function calls.\nSee :term: `Glossary `." + "description": "Determines random number generation used to initialize the centers.\nPass an int for reproducible results across multiple function calls.\nSee :term:`Glossary `." } } ], @@ -83046,7 +85556,9 @@ }, { "name": "_constrained_optimization", + "unique_name": "_constrained_optimization", "qname": "sklearn.gaussian_process._gpc._BinaryGaussianProcessClassifierLaplace._constrained_optimization", + "unique_qname": "sklearn.gaussian_process._gpc._BinaryGaussianProcessClassifierLaplace._constrained_optimization", "decorators": [], "parameters": [ { @@ -83098,7 +85610,9 @@ }, { "name": "_posterior_mode", + "unique_name": "_posterior_mode", "qname": "sklearn.gaussian_process._gpc._BinaryGaussianProcessClassifierLaplace._posterior_mode", + "unique_qname": "sklearn.gaussian_process._gpc._BinaryGaussianProcessClassifierLaplace._posterior_mode", "decorators": [], "parameters": [ { @@ -83140,7 +85654,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.gaussian_process._gpc._BinaryGaussianProcessClassifierLaplace.fit", + "unique_qname": "sklearn.gaussian_process._gpc._BinaryGaussianProcessClassifierLaplace.fit", "decorators": [], "parameters": [ { @@ -83182,7 +85698,9 @@ }, { "name": "log_marginal_likelihood", + "unique_name": "log_marginal_likelihood", "qname": "sklearn.gaussian_process._gpc._BinaryGaussianProcessClassifierLaplace.log_marginal_likelihood", + "unique_qname": "sklearn.gaussian_process._gpc._BinaryGaussianProcessClassifierLaplace.log_marginal_likelihood", "decorators": [], "parameters": [ { @@ -83234,7 +85752,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.gaussian_process._gpc._BinaryGaussianProcessClassifierLaplace.predict", + "unique_qname": "sklearn.gaussian_process._gpc._BinaryGaussianProcessClassifierLaplace.predict", "decorators": [], "parameters": [ { @@ -83266,7 +85786,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.gaussian_process._gpc._BinaryGaussianProcessClassifierLaplace.predict_proba", + "unique_qname": "sklearn.gaussian_process._gpc._BinaryGaussianProcessClassifierLaplace.predict_proba", "decorators": [], "parameters": [ { @@ -83298,7 +85820,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.gaussian_process._gpr.GaussianProcessRegressor.__init__", + "unique_qname": "sklearn.gaussian_process._gpr.GaussianProcessRegressor.__init__", "decorators": [], "parameters": [ { @@ -83390,7 +85914,9 @@ }, { "name": "_constrained_optimization", + "unique_name": "_constrained_optimization", "qname": "sklearn.gaussian_process._gpr.GaussianProcessRegressor._constrained_optimization", + "unique_qname": "sklearn.gaussian_process._gpr.GaussianProcessRegressor._constrained_optimization", "decorators": [], "parameters": [ { @@ -83442,7 +85968,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.gaussian_process._gpr.GaussianProcessRegressor._more_tags", + "unique_qname": "sklearn.gaussian_process._gpr.GaussianProcessRegressor._more_tags", "decorators": [], "parameters": [ { @@ -83464,7 +85992,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.gaussian_process._gpr.GaussianProcessRegressor.fit", + "unique_qname": "sklearn.gaussian_process._gpr.GaussianProcessRegressor.fit", "decorators": [], "parameters": [ { @@ -83506,7 +86036,9 @@ }, { "name": "log_marginal_likelihood", + "unique_name": "log_marginal_likelihood", "qname": "sklearn.gaussian_process._gpr.GaussianProcessRegressor.log_marginal_likelihood", + "unique_qname": "sklearn.gaussian_process._gpr.GaussianProcessRegressor.log_marginal_likelihood", "decorators": [], "parameters": [ { @@ -83558,7 +86090,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.gaussian_process._gpr.GaussianProcessRegressor.predict", + "unique_qname": "sklearn.gaussian_process._gpr.GaussianProcessRegressor.predict", "decorators": [], "parameters": [ { @@ -83605,12 +86139,14 @@ "results": [], "is_public": true, "description": "Predict using the Gaussian process regression model.\n\nWe can also predict based on an unfitted model by using the GP prior. In addition to the mean of the predictive distribution, optionally also returns its standard deviation (`return_std=True`) or covariance (`return_cov=True`). Note that at most one of the two can be requested.", - "docstring": "Predict using the Gaussian process regression model.\n\nWe can also predict based on an unfitted model by using the GP prior.\nIn addition to the mean of the predictive distribution, optionally also\nreturns its standard deviation (`return_std=True`) or covariance\n(`return_cov=True`). Note that at most one of the two can be requested.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features) or list of object\n Query points where the GP is evaluated.\n\nreturn_std : bool, default=False\n If True, the standard-deviation of the predictive distribution at\n the query points is returned along with the mean.\n\nreturn_cov : bool, default=False\n If True, the covariance of the joint predictive distribution at\n the query points is returned along with the mean.\n\nReturns\n-------\ny_mean : ndarray of shape (n_samples,) or (n_samples, n_targets)\n Mean of predictive distribution a query points.\n\ny_std : ndarray of shape (n_samples,), optional\n Standard deviation of predictive distribution at query points.\n Only returned when `return_std` is True.\n\ny_cov : ndarray of shape (n_samples, n_samples), optional\n Covariance of joint predictive distribution a query points.\n Only returned when `return_cov` is True.", - "source_code": "\ndef predict(self, X, return_std=False, return_cov=False):\n \"\"\"Predict using the Gaussian process regression model.\n\n We can also predict based on an unfitted model by using the GP prior.\n In addition to the mean of the predictive distribution, optionally also\n returns its standard deviation (`return_std=True`) or covariance\n (`return_cov=True`). Note that at most one of the two can be requested.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features) or list of object\n Query points where the GP is evaluated.\n\n return_std : bool, default=False\n If True, the standard-deviation of the predictive distribution at\n the query points is returned along with the mean.\n\n return_cov : bool, default=False\n If True, the covariance of the joint predictive distribution at\n the query points is returned along with the mean.\n\n Returns\n -------\n y_mean : ndarray of shape (n_samples,) or (n_samples, n_targets)\n Mean of predictive distribution a query points.\n\n y_std : ndarray of shape (n_samples,), optional\n Standard deviation of predictive distribution at query points.\n Only returned when `return_std` is True.\n\n y_cov : ndarray of shape (n_samples, n_samples), optional\n Covariance of joint predictive distribution a query points.\n Only returned when `return_cov` is True.\n \"\"\"\n if return_std and return_cov:\n raise RuntimeError('At most one of return_std or return_cov can be requested.')\n if self.kernel is None or self.kernel.requires_vector_input:\n (dtype, ensure_2d) = ('numeric', True)\n else:\n (dtype, ensure_2d) = (None, False)\n X = self._validate_data(X, ensure_2d=ensure_2d, dtype=dtype, reset=False)\n if not hasattr(self, 'X_train_'):\n if self.kernel is None:\n kernel = C(1.0, constant_value_bounds='fixed') * RBF(1.0, length_scale_bounds='fixed')\n else:\n kernel = self.kernel\n y_mean = np.zeros(X.shape[0])\n if return_cov:\n y_cov = kernel(X)\n return y_mean, y_cov\n elif return_std:\n y_var = kernel.diag(X)\n return y_mean, np.sqrt(y_var)\n else:\n return y_mean\n else:\n K_trans = self.kernel_(X, self.X_train_)\n y_mean = K_trans @ self.alpha_\n y_mean = self._y_train_std * y_mean + self._y_train_mean\n V = solve_triangular(self.L_, K_trans.T, lower=GPR_CHOLESKY_LOWER, check_finite=False)\n if return_cov:\n y_cov = self.kernel_(X) - V.T @ V\n y_cov = y_cov * self._y_train_std**2\n return y_mean, y_cov\n elif return_std:\n y_var = self.kernel_.diag(X)\n y_var -= np.einsum('ij,ji->i', V.T, V)\n y_var_negative = y_var < 0\n if np.any(y_var_negative):\n warnings.warn('Predicted variances smaller than 0. Setting those variances to 0.')\n y_var[y_var_negative] = 0.0\n y_var = y_var * self._y_train_std**2\n return y_mean, np.sqrt(y_var)\n else:\n return y_mean" + "docstring": "Predict using the Gaussian process regression model.\n\nWe can also predict based on an unfitted model by using the GP prior.\nIn addition to the mean of the predictive distribution, optionally also\nreturns its standard deviation (`return_std=True`) or covariance\n(`return_cov=True`). Note that at most one of the two can be requested.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features) or list of object\n Query points where the GP is evaluated.\n\nreturn_std : bool, default=False\n If True, the standard-deviation of the predictive distribution at\n the query points is returned along with the mean.\n\nreturn_cov : bool, default=False\n If True, the covariance of the joint predictive distribution at\n the query points is returned along with the mean.\n\nReturns\n-------\ny_mean : ndarray of shape (n_samples,) or (n_samples, n_targets)\n Mean of predictive distribution a query points.\n\ny_std : ndarray of shape (n_samples,) or (n_samples, n_targets), optional\n Standard deviation of predictive distribution at query points.\n Only returned when `return_std` is True.\n\ny_cov : ndarray of shape (n_samples, n_samples) or (n_samples, n_samples, n_targets), optional\n Covariance of joint predictive distribution a query points.\n Only returned when `return_cov` is True.", + "source_code": "\ndef predict(self, X, return_std=False, return_cov=False):\n \"\"\"Predict using the Gaussian process regression model.\n\n We can also predict based on an unfitted model by using the GP prior.\n In addition to the mean of the predictive distribution, optionally also\n returns its standard deviation (`return_std=True`) or covariance\n (`return_cov=True`). Note that at most one of the two can be requested.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features) or list of object\n Query points where the GP is evaluated.\n\n return_std : bool, default=False\n If True, the standard-deviation of the predictive distribution at\n the query points is returned along with the mean.\n\n return_cov : bool, default=False\n If True, the covariance of the joint predictive distribution at\n the query points is returned along with the mean.\n\n Returns\n -------\n y_mean : ndarray of shape (n_samples,) or (n_samples, n_targets)\n Mean of predictive distribution a query points.\n\n y_std : ndarray of shape (n_samples,) or (n_samples, n_targets), optional\n Standard deviation of predictive distribution at query points.\n Only returned when `return_std` is True.\n\n y_cov : ndarray of shape (n_samples, n_samples) or (n_samples, n_samples, n_targets), optional\n Covariance of joint predictive distribution a query points.\n Only returned when `return_cov` is True.\n \"\"\"\n if return_std and return_cov:\n raise RuntimeError('At most one of return_std or return_cov can be requested.')\n if self.kernel is None or self.kernel.requires_vector_input:\n (dtype, ensure_2d) = ('numeric', True)\n else:\n (dtype, ensure_2d) = (None, False)\n X = self._validate_data(X, ensure_2d=ensure_2d, dtype=dtype, reset=False)\n if not hasattr(self, 'X_train_'):\n if self.kernel is None:\n kernel = C(1.0, constant_value_bounds='fixed') * RBF(1.0, length_scale_bounds='fixed')\n else:\n kernel = self.kernel\n y_mean = np.zeros(X.shape[0])\n if return_cov:\n y_cov = kernel(X)\n return y_mean, y_cov\n elif return_std:\n y_var = kernel.diag(X)\n return y_mean, np.sqrt(y_var)\n else:\n return y_mean\n else:\n K_trans = self.kernel_(X, self.X_train_)\n y_mean = K_trans @ self.alpha_\n y_mean = self._y_train_std * y_mean + self._y_train_mean\n V = solve_triangular(self.L_, K_trans.T, lower=GPR_CHOLESKY_LOWER, check_finite=False)\n if return_cov:\n y_cov = self.kernel_(X) - V.T @ V\n y_cov = np.outer(y_cov, self._y_train_std**2).reshape(*y_cov.shape, -1)\n if y_cov.shape[2] == 1:\n y_cov = np.squeeze(y_cov, axis=2)\n return y_mean, y_cov\n elif return_std:\n y_var = self.kernel_.diag(X)\n y_var -= np.einsum('ij,ji->i', V.T, V)\n y_var_negative = y_var < 0\n if np.any(y_var_negative):\n warnings.warn('Predicted variances smaller than 0. Setting those variances to 0.')\n y_var[y_var_negative] = 0.0\n y_var = np.outer(y_var, self._y_train_std**2).reshape(*y_var.shape, -1)\n if y_var.shape[1] == 1:\n y_var = np.squeeze(y_var, axis=1)\n return y_mean, np.sqrt(y_var)\n else:\n return y_mean" }, { "name": "sample_y", + "unique_name": "sample_y", "qname": "sklearn.gaussian_process._gpr.GaussianProcessRegressor.sample_y", + "unique_qname": "sklearn.gaussian_process._gpr.GaussianProcessRegressor.sample_y", "decorators": [], "parameters": [ { @@ -83662,7 +86198,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.gaussian_process.kernels.CompoundKernel.__call__", + "unique_qname": "sklearn.gaussian_process.kernels.CompoundKernel.__call__", "decorators": [], "parameters": [ { @@ -83714,7 +86252,9 @@ }, { "name": "__eq__", + "unique_name": "__eq__", "qname": "sklearn.gaussian_process.kernels.CompoundKernel.__eq__", + "unique_qname": "sklearn.gaussian_process.kernels.CompoundKernel.__eq__", "decorators": [], "parameters": [ { @@ -83746,7 +86286,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.gaussian_process.kernels.CompoundKernel.__init__", + "unique_qname": "sklearn.gaussian_process.kernels.CompoundKernel.__init__", "decorators": [], "parameters": [ { @@ -83778,7 +86320,9 @@ }, { "name": "bounds", + "unique_name": "bounds@getter", "qname": "sklearn.gaussian_process.kernels.CompoundKernel.bounds", + "unique_qname": "sklearn.gaussian_process.kernels.CompoundKernel.bounds@getter", "decorators": ["property"], "parameters": [ { @@ -83800,7 +86344,9 @@ }, { "name": "diag", + "unique_name": "diag", "qname": "sklearn.gaussian_process.kernels.CompoundKernel.diag", + "unique_qname": "sklearn.gaussian_process.kernels.CompoundKernel.diag", "decorators": [], "parameters": [ { @@ -83832,7 +86378,9 @@ }, { "name": "get_params", + "unique_name": "get_params", "qname": "sklearn.gaussian_process.kernels.CompoundKernel.get_params", + "unique_qname": "sklearn.gaussian_process.kernels.CompoundKernel.get_params", "decorators": [], "parameters": [ { @@ -83864,7 +86412,9 @@ }, { "name": "is_stationary", + "unique_name": "is_stationary", "qname": "sklearn.gaussian_process.kernels.CompoundKernel.is_stationary", + "unique_qname": "sklearn.gaussian_process.kernels.CompoundKernel.is_stationary", "decorators": [], "parameters": [ { @@ -83886,7 +86436,9 @@ }, { "name": "requires_vector_input", + "unique_name": "requires_vector_input@getter", "qname": "sklearn.gaussian_process.kernels.CompoundKernel.requires_vector_input", + "unique_qname": "sklearn.gaussian_process.kernels.CompoundKernel.requires_vector_input@getter", "decorators": ["property"], "parameters": [ { @@ -83908,7 +86460,33 @@ }, { "name": "theta", + "unique_name": "theta@getter", "qname": "sklearn.gaussian_process.kernels.CompoundKernel.theta", + "unique_qname": "sklearn.gaussian_process.kernels.CompoundKernel.theta@getter", + "decorators": ["property"], + "parameters": [ + { + "name": "self", + "default_value": null, + "is_public": true, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "", + "description": "" + } + } + ], + "results": [], + "is_public": true, + "description": "Returns the (flattened, log-transformed) non-fixed hyperparameters.\n\nNote that theta are typically the log-transformed values of the kernel's hyperparameters as this representation of the search space is more amenable for hyperparameter search, as hyperparameters like length-scales naturally live on a log-scale.", + "docstring": "Returns the (flattened, log-transformed) non-fixed hyperparameters.\n\nNote that theta are typically the log-transformed values of the\nkernel's hyperparameters as this representation of the search space\nis more amenable for hyperparameter search, as hyperparameters like\nlength-scales naturally live on a log-scale.\n\nReturns\n-------\ntheta : ndarray of shape (n_dims,)\n The non-fixed, log-transformed hyperparameters of the kernel", + "source_code": "\n@property\ndef theta(self):\n \"\"\"Returns the (flattened, log-transformed) non-fixed hyperparameters.\n\n Note that theta are typically the log-transformed values of the\n kernel's hyperparameters as this representation of the search space\n is more amenable for hyperparameter search, as hyperparameters like\n length-scales naturally live on a log-scale.\n\n Returns\n -------\n theta : ndarray of shape (n_dims,)\n The non-fixed, log-transformed hyperparameters of the kernel\n \"\"\"\n return np.hstack([kernel.theta for kernel in self.kernels])" + }, + { + "name": "theta", + "unique_name": "theta@setter", + "qname": "sklearn.gaussian_process.kernels.CompoundKernel.theta", + "unique_qname": "sklearn.gaussian_process.kernels.CompoundKernel.theta@setter", "decorators": ["theta.setter"], "parameters": [ { @@ -83940,7 +86518,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.gaussian_process.kernels.ConstantKernel.__call__", + "unique_qname": "sklearn.gaussian_process.kernels.ConstantKernel.__call__", "decorators": [], "parameters": [ { @@ -83992,7 +86572,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.gaussian_process.kernels.ConstantKernel.__init__", + "unique_qname": "sklearn.gaussian_process.kernels.ConstantKernel.__init__", "decorators": [], "parameters": [ { @@ -84034,7 +86616,9 @@ }, { "name": "__repr__", + "unique_name": "__repr__", "qname": "sklearn.gaussian_process.kernels.ConstantKernel.__repr__", + "unique_qname": "sklearn.gaussian_process.kernels.ConstantKernel.__repr__", "decorators": [], "parameters": [ { @@ -84056,7 +86640,9 @@ }, { "name": "diag", + "unique_name": "diag", "qname": "sklearn.gaussian_process.kernels.ConstantKernel.diag", + "unique_qname": "sklearn.gaussian_process.kernels.ConstantKernel.diag", "decorators": [], "parameters": [ { @@ -84088,7 +86674,9 @@ }, { "name": "hyperparameter_constant_value", + "unique_name": "hyperparameter_constant_value@getter", "qname": "sklearn.gaussian_process.kernels.ConstantKernel.hyperparameter_constant_value", + "unique_qname": "sklearn.gaussian_process.kernels.ConstantKernel.hyperparameter_constant_value@getter", "decorators": ["property"], "parameters": [ { @@ -84110,7 +86698,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.gaussian_process.kernels.DotProduct.__call__", + "unique_qname": "sklearn.gaussian_process.kernels.DotProduct.__call__", "decorators": [], "parameters": [ { @@ -84162,7 +86752,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.gaussian_process.kernels.DotProduct.__init__", + "unique_qname": "sklearn.gaussian_process.kernels.DotProduct.__init__", "decorators": [], "parameters": [ { @@ -84204,7 +86796,9 @@ }, { "name": "__repr__", + "unique_name": "__repr__", "qname": "sklearn.gaussian_process.kernels.DotProduct.__repr__", + "unique_qname": "sklearn.gaussian_process.kernels.DotProduct.__repr__", "decorators": [], "parameters": [ { @@ -84226,7 +86820,9 @@ }, { "name": "diag", + "unique_name": "diag", "qname": "sklearn.gaussian_process.kernels.DotProduct.diag", + "unique_qname": "sklearn.gaussian_process.kernels.DotProduct.diag", "decorators": [], "parameters": [ { @@ -84258,7 +86854,9 @@ }, { "name": "hyperparameter_sigma_0", + "unique_name": "hyperparameter_sigma_0@getter", "qname": "sklearn.gaussian_process.kernels.DotProduct.hyperparameter_sigma_0", + "unique_qname": "sklearn.gaussian_process.kernels.DotProduct.hyperparameter_sigma_0@getter", "decorators": ["property"], "parameters": [ { @@ -84280,7 +86878,9 @@ }, { "name": "is_stationary", + "unique_name": "is_stationary", "qname": "sklearn.gaussian_process.kernels.DotProduct.is_stationary", + "unique_qname": "sklearn.gaussian_process.kernels.DotProduct.is_stationary", "decorators": [], "parameters": [ { @@ -84302,7 +86902,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.gaussian_process.kernels.ExpSineSquared.__call__", + "unique_qname": "sklearn.gaussian_process.kernels.ExpSineSquared.__call__", "decorators": [], "parameters": [ { @@ -84354,7 +86956,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.gaussian_process.kernels.ExpSineSquared.__init__", + "unique_qname": "sklearn.gaussian_process.kernels.ExpSineSquared.__init__", "decorators": [], "parameters": [ { @@ -84416,7 +87020,9 @@ }, { "name": "__repr__", + "unique_name": "__repr__", "qname": "sklearn.gaussian_process.kernels.ExpSineSquared.__repr__", + "unique_qname": "sklearn.gaussian_process.kernels.ExpSineSquared.__repr__", "decorators": [], "parameters": [ { @@ -84438,7 +87044,9 @@ }, { "name": "hyperparameter_length_scale", + "unique_name": "hyperparameter_length_scale@getter", "qname": "sklearn.gaussian_process.kernels.ExpSineSquared.hyperparameter_length_scale", + "unique_qname": "sklearn.gaussian_process.kernels.ExpSineSquared.hyperparameter_length_scale@getter", "decorators": ["property"], "parameters": [ { @@ -84460,7 +87068,9 @@ }, { "name": "hyperparameter_periodicity", + "unique_name": "hyperparameter_periodicity@getter", "qname": "sklearn.gaussian_process.kernels.ExpSineSquared.hyperparameter_periodicity", + "unique_qname": "sklearn.gaussian_process.kernels.ExpSineSquared.hyperparameter_periodicity@getter", "decorators": ["property"], "parameters": [ { @@ -84482,7 +87092,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.gaussian_process.kernels.Exponentiation.__call__", + "unique_qname": "sklearn.gaussian_process.kernels.Exponentiation.__call__", "decorators": [], "parameters": [ { @@ -84534,7 +87146,9 @@ }, { "name": "__eq__", + "unique_name": "__eq__", "qname": "sklearn.gaussian_process.kernels.Exponentiation.__eq__", + "unique_qname": "sklearn.gaussian_process.kernels.Exponentiation.__eq__", "decorators": [], "parameters": [ { @@ -84566,7 +87180,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.gaussian_process.kernels.Exponentiation.__init__", + "unique_qname": "sklearn.gaussian_process.kernels.Exponentiation.__init__", "decorators": [], "parameters": [ { @@ -84608,7 +87224,9 @@ }, { "name": "__repr__", + "unique_name": "__repr__", "qname": "sklearn.gaussian_process.kernels.Exponentiation.__repr__", + "unique_qname": "sklearn.gaussian_process.kernels.Exponentiation.__repr__", "decorators": [], "parameters": [ { @@ -84630,7 +87248,9 @@ }, { "name": "bounds", + "unique_name": "bounds@getter", "qname": "sklearn.gaussian_process.kernels.Exponentiation.bounds", + "unique_qname": "sklearn.gaussian_process.kernels.Exponentiation.bounds@getter", "decorators": ["property"], "parameters": [ { @@ -84652,7 +87272,9 @@ }, { "name": "diag", + "unique_name": "diag", "qname": "sklearn.gaussian_process.kernels.Exponentiation.diag", + "unique_qname": "sklearn.gaussian_process.kernels.Exponentiation.diag", "decorators": [], "parameters": [ { @@ -84684,7 +87306,9 @@ }, { "name": "get_params", + "unique_name": "get_params", "qname": "sklearn.gaussian_process.kernels.Exponentiation.get_params", + "unique_qname": "sklearn.gaussian_process.kernels.Exponentiation.get_params", "decorators": [], "parameters": [ { @@ -84716,7 +87340,9 @@ }, { "name": "hyperparameters", + "unique_name": "hyperparameters@getter", "qname": "sklearn.gaussian_process.kernels.Exponentiation.hyperparameters", + "unique_qname": "sklearn.gaussian_process.kernels.Exponentiation.hyperparameters@getter", "decorators": ["property"], "parameters": [ { @@ -84738,7 +87364,9 @@ }, { "name": "is_stationary", + "unique_name": "is_stationary", "qname": "sklearn.gaussian_process.kernels.Exponentiation.is_stationary", + "unique_qname": "sklearn.gaussian_process.kernels.Exponentiation.is_stationary", "decorators": [], "parameters": [ { @@ -84760,7 +87388,9 @@ }, { "name": "requires_vector_input", + "unique_name": "requires_vector_input@getter", "qname": "sklearn.gaussian_process.kernels.Exponentiation.requires_vector_input", + "unique_qname": "sklearn.gaussian_process.kernels.Exponentiation.requires_vector_input@getter", "decorators": ["property"], "parameters": [ { @@ -84782,7 +87412,33 @@ }, { "name": "theta", + "unique_name": "theta@getter", + "qname": "sklearn.gaussian_process.kernels.Exponentiation.theta", + "unique_qname": "sklearn.gaussian_process.kernels.Exponentiation.theta@getter", + "decorators": ["property"], + "parameters": [ + { + "name": "self", + "default_value": null, + "is_public": true, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "", + "description": "" + } + } + ], + "results": [], + "is_public": true, + "description": "Returns the (flattened, log-transformed) non-fixed hyperparameters.\n\nNote that theta are typically the log-transformed values of the kernel's hyperparameters as this representation of the search space is more amenable for hyperparameter search, as hyperparameters like length-scales naturally live on a log-scale.", + "docstring": "Returns the (flattened, log-transformed) non-fixed hyperparameters.\n\nNote that theta are typically the log-transformed values of the\nkernel's hyperparameters as this representation of the search space\nis more amenable for hyperparameter search, as hyperparameters like\nlength-scales naturally live on a log-scale.\n\nReturns\n-------\ntheta : ndarray of shape (n_dims,)\n The non-fixed, log-transformed hyperparameters of the kernel", + "source_code": "\n@property\ndef theta(self):\n \"\"\"Returns the (flattened, log-transformed) non-fixed hyperparameters.\n\n Note that theta are typically the log-transformed values of the\n kernel's hyperparameters as this representation of the search space\n is more amenable for hyperparameter search, as hyperparameters like\n length-scales naturally live on a log-scale.\n\n Returns\n -------\n theta : ndarray of shape (n_dims,)\n The non-fixed, log-transformed hyperparameters of the kernel\n \"\"\"\n return self.kernel.theta" + }, + { + "name": "theta", + "unique_name": "theta@setter", "qname": "sklearn.gaussian_process.kernels.Exponentiation.theta", + "unique_qname": "sklearn.gaussian_process.kernels.Exponentiation.theta@setter", "decorators": ["theta.setter"], "parameters": [ { @@ -84814,7 +87470,9 @@ }, { "name": "requires_vector_input", + "unique_name": "requires_vector_input@getter", "qname": "sklearn.gaussian_process.kernels.GenericKernelMixin.requires_vector_input", + "unique_qname": "sklearn.gaussian_process.kernels.GenericKernelMixin.requires_vector_input@getter", "decorators": ["property"], "parameters": [ { @@ -84836,7 +87494,9 @@ }, { "name": "__eq__", + "unique_name": "__eq__", "qname": "sklearn.gaussian_process.kernels.Hyperparameter.__eq__", + "unique_qname": "sklearn.gaussian_process.kernels.Hyperparameter.__eq__", "decorators": [], "parameters": [ { @@ -84868,7 +87528,9 @@ }, { "name": "__new__", + "unique_name": "__new__", "qname": "sklearn.gaussian_process.kernels.Hyperparameter.__new__", + "unique_qname": "sklearn.gaussian_process.kernels.Hyperparameter.__new__", "decorators": [], "parameters": [ { @@ -84940,7 +87602,9 @@ }, { "name": "__add__", + "unique_name": "__add__", "qname": "sklearn.gaussian_process.kernels.Kernel.__add__", + "unique_qname": "sklearn.gaussian_process.kernels.Kernel.__add__", "decorators": [], "parameters": [ { @@ -84972,7 +87636,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.gaussian_process.kernels.Kernel.__call__", + "unique_qname": "sklearn.gaussian_process.kernels.Kernel.__call__", "decorators": ["abstractmethod"], "parameters": [ { @@ -85024,7 +87690,9 @@ }, { "name": "__eq__", + "unique_name": "__eq__", "qname": "sklearn.gaussian_process.kernels.Kernel.__eq__", + "unique_qname": "sklearn.gaussian_process.kernels.Kernel.__eq__", "decorators": [], "parameters": [ { @@ -85056,7 +87724,9 @@ }, { "name": "__mul__", + "unique_name": "__mul__", "qname": "sklearn.gaussian_process.kernels.Kernel.__mul__", + "unique_qname": "sklearn.gaussian_process.kernels.Kernel.__mul__", "decorators": [], "parameters": [ { @@ -85088,7 +87758,9 @@ }, { "name": "__pow__", + "unique_name": "__pow__", "qname": "sklearn.gaussian_process.kernels.Kernel.__pow__", + "unique_qname": "sklearn.gaussian_process.kernels.Kernel.__pow__", "decorators": [], "parameters": [ { @@ -85120,7 +87792,9 @@ }, { "name": "__radd__", + "unique_name": "__radd__", "qname": "sklearn.gaussian_process.kernels.Kernel.__radd__", + "unique_qname": "sklearn.gaussian_process.kernels.Kernel.__radd__", "decorators": [], "parameters": [ { @@ -85152,7 +87826,9 @@ }, { "name": "__repr__", + "unique_name": "__repr__", "qname": "sklearn.gaussian_process.kernels.Kernel.__repr__", + "unique_qname": "sklearn.gaussian_process.kernels.Kernel.__repr__", "decorators": [], "parameters": [ { @@ -85174,7 +87850,9 @@ }, { "name": "__rmul__", + "unique_name": "__rmul__", "qname": "sklearn.gaussian_process.kernels.Kernel.__rmul__", + "unique_qname": "sklearn.gaussian_process.kernels.Kernel.__rmul__", "decorators": [], "parameters": [ { @@ -85206,7 +87884,9 @@ }, { "name": "_check_bounds_params", + "unique_name": "_check_bounds_params", "qname": "sklearn.gaussian_process.kernels.Kernel._check_bounds_params", + "unique_qname": "sklearn.gaussian_process.kernels.Kernel._check_bounds_params", "decorators": [], "parameters": [ { @@ -85228,7 +87908,9 @@ }, { "name": "bounds", + "unique_name": "bounds@getter", "qname": "sklearn.gaussian_process.kernels.Kernel.bounds", + "unique_qname": "sklearn.gaussian_process.kernels.Kernel.bounds@getter", "decorators": ["property"], "parameters": [ { @@ -85250,7 +87932,9 @@ }, { "name": "clone_with_theta", + "unique_name": "clone_with_theta", "qname": "sklearn.gaussian_process.kernels.Kernel.clone_with_theta", + "unique_qname": "sklearn.gaussian_process.kernels.Kernel.clone_with_theta", "decorators": [], "parameters": [ { @@ -85282,7 +87966,9 @@ }, { "name": "diag", + "unique_name": "diag", "qname": "sklearn.gaussian_process.kernels.Kernel.diag", + "unique_qname": "sklearn.gaussian_process.kernels.Kernel.diag", "decorators": ["abstractmethod"], "parameters": [ { @@ -85314,7 +88000,9 @@ }, { "name": "get_params", + "unique_name": "get_params", "qname": "sklearn.gaussian_process.kernels.Kernel.get_params", + "unique_qname": "sklearn.gaussian_process.kernels.Kernel.get_params", "decorators": [], "parameters": [ { @@ -85346,7 +88034,9 @@ }, { "name": "hyperparameters", + "unique_name": "hyperparameters@getter", "qname": "sklearn.gaussian_process.kernels.Kernel.hyperparameters", + "unique_qname": "sklearn.gaussian_process.kernels.Kernel.hyperparameters@getter", "decorators": ["property"], "parameters": [ { @@ -85368,7 +88058,9 @@ }, { "name": "is_stationary", + "unique_name": "is_stationary", "qname": "sklearn.gaussian_process.kernels.Kernel.is_stationary", + "unique_qname": "sklearn.gaussian_process.kernels.Kernel.is_stationary", "decorators": ["abstractmethod"], "parameters": [ { @@ -85390,7 +88082,9 @@ }, { "name": "n_dims", + "unique_name": "n_dims@getter", "qname": "sklearn.gaussian_process.kernels.Kernel.n_dims", + "unique_qname": "sklearn.gaussian_process.kernels.Kernel.n_dims@getter", "decorators": ["property"], "parameters": [ { @@ -85412,7 +88106,9 @@ }, { "name": "requires_vector_input", + "unique_name": "requires_vector_input@getter", "qname": "sklearn.gaussian_process.kernels.Kernel.requires_vector_input", + "unique_qname": "sklearn.gaussian_process.kernels.Kernel.requires_vector_input@getter", "decorators": ["property"], "parameters": [ { @@ -85434,7 +88130,9 @@ }, { "name": "set_params", + "unique_name": "set_params", "qname": "sklearn.gaussian_process.kernels.Kernel.set_params", + "unique_qname": "sklearn.gaussian_process.kernels.Kernel.set_params", "decorators": [], "parameters": [ { @@ -85456,7 +88154,33 @@ }, { "name": "theta", + "unique_name": "theta@getter", + "qname": "sklearn.gaussian_process.kernels.Kernel.theta", + "unique_qname": "sklearn.gaussian_process.kernels.Kernel.theta@getter", + "decorators": ["property"], + "parameters": [ + { + "name": "self", + "default_value": null, + "is_public": true, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "", + "description": "" + } + } + ], + "results": [], + "is_public": true, + "description": "Returns the (flattened, log-transformed) non-fixed hyperparameters.\n\nNote that theta are typically the log-transformed values of the kernel's hyperparameters as this representation of the search space is more amenable for hyperparameter search, as hyperparameters like length-scales naturally live on a log-scale.", + "docstring": "Returns the (flattened, log-transformed) non-fixed hyperparameters.\n\nNote that theta are typically the log-transformed values of the\nkernel's hyperparameters as this representation of the search space\nis more amenable for hyperparameter search, as hyperparameters like\nlength-scales naturally live on a log-scale.\n\nReturns\n-------\ntheta : ndarray of shape (n_dims,)\n The non-fixed, log-transformed hyperparameters of the kernel", + "source_code": "\n@property\ndef theta(self):\n \"\"\"Returns the (flattened, log-transformed) non-fixed hyperparameters.\n\n Note that theta are typically the log-transformed values of the\n kernel's hyperparameters as this representation of the search space\n is more amenable for hyperparameter search, as hyperparameters like\n length-scales naturally live on a log-scale.\n\n Returns\n -------\n theta : ndarray of shape (n_dims,)\n The non-fixed, log-transformed hyperparameters of the kernel\n \"\"\"\n theta = []\n params = self.get_params()\n for hyperparameter in self.hyperparameters:\n if not hyperparameter.fixed:\n theta.append(params[hyperparameter.name])\n if len(theta) > 0:\n return np.log(np.hstack(theta))\n else:\n return np.array([])" + }, + { + "name": "theta", + "unique_name": "theta@setter", "qname": "sklearn.gaussian_process.kernels.Kernel.theta", + "unique_qname": "sklearn.gaussian_process.kernels.Kernel.theta@setter", "decorators": ["theta.setter"], "parameters": [ { @@ -85488,7 +88212,9 @@ }, { "name": "__eq__", + "unique_name": "__eq__", "qname": "sklearn.gaussian_process.kernels.KernelOperator.__eq__", + "unique_qname": "sklearn.gaussian_process.kernels.KernelOperator.__eq__", "decorators": [], "parameters": [ { @@ -85520,7 +88246,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.gaussian_process.kernels.KernelOperator.__init__", + "unique_qname": "sklearn.gaussian_process.kernels.KernelOperator.__init__", "decorators": [], "parameters": [ { @@ -85562,7 +88290,9 @@ }, { "name": "bounds", + "unique_name": "bounds@getter", "qname": "sklearn.gaussian_process.kernels.KernelOperator.bounds", + "unique_qname": "sklearn.gaussian_process.kernels.KernelOperator.bounds@getter", "decorators": ["property"], "parameters": [ { @@ -85584,7 +88314,9 @@ }, { "name": "get_params", + "unique_name": "get_params", "qname": "sklearn.gaussian_process.kernels.KernelOperator.get_params", + "unique_qname": "sklearn.gaussian_process.kernels.KernelOperator.get_params", "decorators": [], "parameters": [ { @@ -85616,7 +88348,9 @@ }, { "name": "hyperparameters", + "unique_name": "hyperparameters@getter", "qname": "sklearn.gaussian_process.kernels.KernelOperator.hyperparameters", + "unique_qname": "sklearn.gaussian_process.kernels.KernelOperator.hyperparameters@getter", "decorators": ["property"], "parameters": [ { @@ -85638,7 +88372,9 @@ }, { "name": "is_stationary", + "unique_name": "is_stationary", "qname": "sklearn.gaussian_process.kernels.KernelOperator.is_stationary", + "unique_qname": "sklearn.gaussian_process.kernels.KernelOperator.is_stationary", "decorators": [], "parameters": [ { @@ -85660,7 +88396,9 @@ }, { "name": "requires_vector_input", + "unique_name": "requires_vector_input@getter", "qname": "sklearn.gaussian_process.kernels.KernelOperator.requires_vector_input", + "unique_qname": "sklearn.gaussian_process.kernels.KernelOperator.requires_vector_input@getter", "decorators": ["property"], "parameters": [ { @@ -85682,7 +88420,33 @@ }, { "name": "theta", + "unique_name": "theta@getter", "qname": "sklearn.gaussian_process.kernels.KernelOperator.theta", + "unique_qname": "sklearn.gaussian_process.kernels.KernelOperator.theta@getter", + "decorators": ["property"], + "parameters": [ + { + "name": "self", + "default_value": null, + "is_public": true, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "", + "description": "" + } + } + ], + "results": [], + "is_public": true, + "description": "Returns the (flattened, log-transformed) non-fixed hyperparameters.\n\nNote that theta are typically the log-transformed values of the kernel's hyperparameters as this representation of the search space is more amenable for hyperparameter search, as hyperparameters like length-scales naturally live on a log-scale.", + "docstring": "Returns the (flattened, log-transformed) non-fixed hyperparameters.\n\nNote that theta are typically the log-transformed values of the\nkernel's hyperparameters as this representation of the search space\nis more amenable for hyperparameter search, as hyperparameters like\nlength-scales naturally live on a log-scale.\n\nReturns\n-------\ntheta : ndarray of shape (n_dims,)\n The non-fixed, log-transformed hyperparameters of the kernel", + "source_code": "\n@property\ndef theta(self):\n \"\"\"Returns the (flattened, log-transformed) non-fixed hyperparameters.\n\n Note that theta are typically the log-transformed values of the\n kernel's hyperparameters as this representation of the search space\n is more amenable for hyperparameter search, as hyperparameters like\n length-scales naturally live on a log-scale.\n\n Returns\n -------\n theta : ndarray of shape (n_dims,)\n The non-fixed, log-transformed hyperparameters of the kernel\n \"\"\"\n return np.append(self.k1.theta, self.k2.theta)" + }, + { + "name": "theta", + "unique_name": "theta@setter", + "qname": "sklearn.gaussian_process.kernels.KernelOperator.theta", + "unique_qname": "sklearn.gaussian_process.kernels.KernelOperator.theta@setter", "decorators": ["theta.setter"], "parameters": [ { @@ -85714,7 +88478,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.gaussian_process.kernels.Matern.__call__", + "unique_qname": "sklearn.gaussian_process.kernels.Matern.__call__", "decorators": [], "parameters": [ { @@ -85766,7 +88532,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.gaussian_process.kernels.Matern.__init__", + "unique_qname": "sklearn.gaussian_process.kernels.Matern.__init__", "decorators": [], "parameters": [ { @@ -85818,7 +88586,9 @@ }, { "name": "__repr__", + "unique_name": "__repr__", "qname": "sklearn.gaussian_process.kernels.Matern.__repr__", + "unique_qname": "sklearn.gaussian_process.kernels.Matern.__repr__", "decorators": [], "parameters": [ { @@ -85840,7 +88610,9 @@ }, { "name": "diag", + "unique_name": "diag", "qname": "sklearn.gaussian_process.kernels.NormalizedKernelMixin.diag", + "unique_qname": "sklearn.gaussian_process.kernels.NormalizedKernelMixin.diag", "decorators": [], "parameters": [ { @@ -85872,7 +88644,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.gaussian_process.kernels.PairwiseKernel.__call__", + "unique_qname": "sklearn.gaussian_process.kernels.PairwiseKernel.__call__", "decorators": [], "parameters": [ { @@ -85924,7 +88698,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.gaussian_process.kernels.PairwiseKernel.__init__", + "unique_qname": "sklearn.gaussian_process.kernels.PairwiseKernel.__init__", "decorators": [], "parameters": [ { @@ -85986,7 +88762,9 @@ }, { "name": "__repr__", + "unique_name": "__repr__", "qname": "sklearn.gaussian_process.kernels.PairwiseKernel.__repr__", + "unique_qname": "sklearn.gaussian_process.kernels.PairwiseKernel.__repr__", "decorators": [], "parameters": [ { @@ -86008,7 +88786,9 @@ }, { "name": "diag", + "unique_name": "diag", "qname": "sklearn.gaussian_process.kernels.PairwiseKernel.diag", + "unique_qname": "sklearn.gaussian_process.kernels.PairwiseKernel.diag", "decorators": [], "parameters": [ { @@ -86040,7 +88820,9 @@ }, { "name": "hyperparameter_gamma", + "unique_name": "hyperparameter_gamma@getter", "qname": "sklearn.gaussian_process.kernels.PairwiseKernel.hyperparameter_gamma", + "unique_qname": "sklearn.gaussian_process.kernels.PairwiseKernel.hyperparameter_gamma@getter", "decorators": ["property"], "parameters": [ { @@ -86062,7 +88844,9 @@ }, { "name": "is_stationary", + "unique_name": "is_stationary", "qname": "sklearn.gaussian_process.kernels.PairwiseKernel.is_stationary", + "unique_qname": "sklearn.gaussian_process.kernels.PairwiseKernel.is_stationary", "decorators": [], "parameters": [ { @@ -86084,7 +88868,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.gaussian_process.kernels.Product.__call__", + "unique_qname": "sklearn.gaussian_process.kernels.Product.__call__", "decorators": [], "parameters": [ { @@ -86136,7 +88922,9 @@ }, { "name": "__repr__", + "unique_name": "__repr__", "qname": "sklearn.gaussian_process.kernels.Product.__repr__", + "unique_qname": "sklearn.gaussian_process.kernels.Product.__repr__", "decorators": [], "parameters": [ { @@ -86158,7 +88946,9 @@ }, { "name": "diag", + "unique_name": "diag", "qname": "sklearn.gaussian_process.kernels.Product.diag", + "unique_qname": "sklearn.gaussian_process.kernels.Product.diag", "decorators": [], "parameters": [ { @@ -86190,7 +88980,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.gaussian_process.kernels.RBF.__call__", + "unique_qname": "sklearn.gaussian_process.kernels.RBF.__call__", "decorators": [], "parameters": [ { @@ -86242,7 +89034,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.gaussian_process.kernels.RBF.__init__", + "unique_qname": "sklearn.gaussian_process.kernels.RBF.__init__", "decorators": [], "parameters": [ { @@ -86284,7 +89078,9 @@ }, { "name": "__repr__", + "unique_name": "__repr__", "qname": "sklearn.gaussian_process.kernels.RBF.__repr__", + "unique_qname": "sklearn.gaussian_process.kernels.RBF.__repr__", "decorators": [], "parameters": [ { @@ -86306,7 +89102,9 @@ }, { "name": "anisotropic", + "unique_name": "anisotropic@getter", "qname": "sklearn.gaussian_process.kernels.RBF.anisotropic", + "unique_qname": "sklearn.gaussian_process.kernels.RBF.anisotropic@getter", "decorators": ["property"], "parameters": [ { @@ -86328,7 +89126,9 @@ }, { "name": "hyperparameter_length_scale", + "unique_name": "hyperparameter_length_scale@getter", "qname": "sklearn.gaussian_process.kernels.RBF.hyperparameter_length_scale", + "unique_qname": "sklearn.gaussian_process.kernels.RBF.hyperparameter_length_scale@getter", "decorators": ["property"], "parameters": [ { @@ -86350,7 +89150,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.gaussian_process.kernels.RationalQuadratic.__call__", + "unique_qname": "sklearn.gaussian_process.kernels.RationalQuadratic.__call__", "decorators": [], "parameters": [ { @@ -86402,7 +89204,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.gaussian_process.kernels.RationalQuadratic.__init__", + "unique_qname": "sklearn.gaussian_process.kernels.RationalQuadratic.__init__", "decorators": [], "parameters": [ { @@ -86464,7 +89268,9 @@ }, { "name": "__repr__", + "unique_name": "__repr__", "qname": "sklearn.gaussian_process.kernels.RationalQuadratic.__repr__", + "unique_qname": "sklearn.gaussian_process.kernels.RationalQuadratic.__repr__", "decorators": [], "parameters": [ { @@ -86486,7 +89292,9 @@ }, { "name": "hyperparameter_alpha", + "unique_name": "hyperparameter_alpha@getter", "qname": "sklearn.gaussian_process.kernels.RationalQuadratic.hyperparameter_alpha", + "unique_qname": "sklearn.gaussian_process.kernels.RationalQuadratic.hyperparameter_alpha@getter", "decorators": ["property"], "parameters": [ { @@ -86508,7 +89316,9 @@ }, { "name": "hyperparameter_length_scale", + "unique_name": "hyperparameter_length_scale@getter", "qname": "sklearn.gaussian_process.kernels.RationalQuadratic.hyperparameter_length_scale", + "unique_qname": "sklearn.gaussian_process.kernels.RationalQuadratic.hyperparameter_length_scale@getter", "decorators": ["property"], "parameters": [ { @@ -86530,7 +89340,9 @@ }, { "name": "is_stationary", + "unique_name": "is_stationary", "qname": "sklearn.gaussian_process.kernels.StationaryKernelMixin.is_stationary", + "unique_qname": "sklearn.gaussian_process.kernels.StationaryKernelMixin.is_stationary", "decorators": [], "parameters": [ { @@ -86552,7 +89364,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.gaussian_process.kernels.Sum.__call__", + "unique_qname": "sklearn.gaussian_process.kernels.Sum.__call__", "decorators": [], "parameters": [ { @@ -86604,7 +89418,9 @@ }, { "name": "__repr__", + "unique_name": "__repr__", "qname": "sklearn.gaussian_process.kernels.Sum.__repr__", + "unique_qname": "sklearn.gaussian_process.kernels.Sum.__repr__", "decorators": [], "parameters": [ { @@ -86626,7 +89442,9 @@ }, { "name": "diag", + "unique_name": "diag", "qname": "sklearn.gaussian_process.kernels.Sum.diag", + "unique_qname": "sklearn.gaussian_process.kernels.Sum.diag", "decorators": [], "parameters": [ { @@ -86658,7 +89476,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.gaussian_process.kernels.WhiteKernel.__call__", + "unique_qname": "sklearn.gaussian_process.kernels.WhiteKernel.__call__", "decorators": [], "parameters": [ { @@ -86710,7 +89530,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.gaussian_process.kernels.WhiteKernel.__init__", + "unique_qname": "sklearn.gaussian_process.kernels.WhiteKernel.__init__", "decorators": [], "parameters": [ { @@ -86752,7 +89574,9 @@ }, { "name": "__repr__", + "unique_name": "__repr__", "qname": "sklearn.gaussian_process.kernels.WhiteKernel.__repr__", + "unique_qname": "sklearn.gaussian_process.kernels.WhiteKernel.__repr__", "decorators": [], "parameters": [ { @@ -86774,7 +89598,9 @@ }, { "name": "diag", + "unique_name": "diag", "qname": "sklearn.gaussian_process.kernels.WhiteKernel.diag", + "unique_qname": "sklearn.gaussian_process.kernels.WhiteKernel.diag", "decorators": [], "parameters": [ { @@ -86806,7 +89632,9 @@ }, { "name": "hyperparameter_noise_level", + "unique_name": "hyperparameter_noise_level@getter", "qname": "sklearn.gaussian_process.kernels.WhiteKernel.hyperparameter_noise_level", + "unique_qname": "sklearn.gaussian_process.kernels.WhiteKernel.hyperparameter_noise_level@getter", "decorators": ["property"], "parameters": [ { @@ -86828,7 +89656,9 @@ }, { "name": "_approx_fprime", + "unique_name": "_approx_fprime", "qname": "sklearn.gaussian_process.kernels._approx_fprime", + "unique_qname": "sklearn.gaussian_process.kernels._approx_fprime", "decorators": [], "parameters": [ { @@ -86880,7 +89710,9 @@ }, { "name": "_check_length_scale", + "unique_name": "_check_length_scale", "qname": "sklearn.gaussian_process.kernels._check_length_scale", + "unique_qname": "sklearn.gaussian_process.kernels._check_length_scale", "decorators": [], "parameters": [ { @@ -86912,7 +89744,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.impute._base.MissingIndicator.__init__", + "unique_qname": "sklearn.impute._base.MissingIndicator.__init__", "decorators": [], "parameters": [ { @@ -86931,7 +89765,7 @@ "is_public": true, "assigned_by": "NAME_ONLY", "docstring": { - "type": "int, float, string, np.nan or None, default=np.nan", + "type": "int, float, str, np.nan or None, default=np.nan", "description": "The placeholder for the missing values. All occurrences of\n`missing_values` will be imputed. For pandas' dataframes with\nnullable integer dtypes with missing values, `missing_values`\nshould be set to `np.nan`, since `pd.NA` will be converted to `np.nan`." } }, @@ -86942,7 +89776,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "{'missing-only', 'all'}, default='missing-only'", - "description": "Whether the imputer mask should represent all or a subset of\nfeatures.\n\n- If 'missing-only' (default), the imputer mask will only represent\n features containing missing values during fit time.\n- If 'all', the imputer mask will represent all features." + "description": "Whether the imputer mask should represent all or a subset of\nfeatures.\n\n- If `'missing-only'` (default), the imputer mask will only represent\n features containing missing values during fit time.\n- If `'all'`, the imputer mask will represent all features." } }, { @@ -86952,7 +89786,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "bool or 'auto', default='auto'", - "description": "Whether the imputer mask format should be sparse or dense.\n\n- If 'auto' (default), the imputer mask will be of same type as\n input.\n- If True, the imputer mask will be a sparse matrix.\n- If False, the imputer mask will be a numpy array." + "description": "Whether the imputer mask format should be sparse or dense.\n\n- If `'auto'` (default), the imputer mask will be of same type as\n input.\n- If `True`, the imputer mask will be a sparse matrix.\n- If `False`, the imputer mask will be a numpy array." } }, { @@ -86962,7 +89796,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "bool, default=True", - "description": "If True, transform will raise an error when there are features with\nmissing values in transform that have no missing values in fit. This is\napplicable only when `features='missing-only'`." + "description": "If `True`, :meth:`transform` will raise an error when there are\nfeatures with missing values that have no missing values in\n:meth:`fit`. This is applicable only when `features='missing-only'`." } } ], @@ -86974,7 +89808,9 @@ }, { "name": "_fit", + "unique_name": "_fit", "qname": "sklearn.impute._base.MissingIndicator._fit", + "unique_qname": "sklearn.impute._base.MissingIndicator._fit", "decorators": [], "parameters": [ { @@ -86993,8 +89829,8 @@ "is_public": false, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "{array-like, sparse matrix}, shape (n_samples, n_features)", - "description": "Input data, where ``n_samples`` is the number of samples and\n``n_features`` is the number of features.\nIf `precomputed` is True, then `X` is a mask of the\ninput data." + "type": "{array-like, sparse matrix} of shape (n_samples, n_features)", + "description": "Input data, where `n_samples` is the number of samples and\n`n_features` is the number of features.\nIf `precomputed=True`, then `X` is a mask of the input data." } }, { @@ -87020,13 +89856,15 @@ ], "results": [], "is_public": false, - "description": "Fit the transformer on X.", - "docstring": "Fit the transformer on X.\n\nParameters\n----------\nX : {array-like, sparse matrix}, shape (n_samples, n_features)\n Input data, where ``n_samples`` is the number of samples and\n ``n_features`` is the number of features.\n If `precomputed` is True, then `X` is a mask of the\n input data.\n\nprecomputed : bool\n Whether the input data is a mask.\n\nReturns\n-------\nimputer_mask : {ndarray or sparse matrix}, shape (n_samples, n_features)\n The imputer mask of the original data.", - "source_code": "\ndef _fit(self, X, y=None, precomputed=False):\n \"\"\"Fit the transformer on X.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Input data, where ``n_samples`` is the number of samples and\n ``n_features`` is the number of features.\n If `precomputed` is True, then `X` is a mask of the\n input data.\n\n precomputed : bool\n Whether the input data is a mask.\n\n Returns\n -------\n imputer_mask : {ndarray or sparse matrix}, shape (n_samples, n_features)\n The imputer mask of the original data.\n\n \"\"\"\n if precomputed:\n if not (hasattr(X, 'dtype') and X.dtype.kind == 'b'):\n raise ValueError('precomputed is True but the input data is not a mask')\n self._precomputed = True\n else:\n self._precomputed = False\n if not self._precomputed:\n X = self._validate_input(X, in_fit=True)\n self._n_features = X.shape[1]\n if self.features not in ('missing-only', 'all'):\n raise ValueError(\"'features' has to be either 'missing-only' or 'all'. Got {} instead.\".format(self.features))\n if not (isinstance(self.sparse, str) and self.sparse == 'auto' or isinstance(self.sparse, bool)):\n raise ValueError(\"'sparse' has to be a boolean or 'auto'. Got {!r} instead.\".format(self.sparse))\n missing_features_info = self._get_missing_features_info(X)\n self.features_ = missing_features_info[1]\n return missing_features_info[0]" + "description": "Fit the transformer on `X`.", + "docstring": "Fit the transformer on `X`.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input data, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n If `precomputed=True`, then `X` is a mask of the input data.\n\nprecomputed : bool\n Whether the input data is a mask.\n\nReturns\n-------\nimputer_mask : {ndarray, sparse matrix} of shape (n_samples, n_features)\n The imputer mask of the original data.", + "source_code": "\ndef _fit(self, X, y=None, precomputed=False):\n \"\"\"Fit the transformer on `X`.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input data, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n If `precomputed=True`, then `X` is a mask of the input data.\n\n precomputed : bool\n Whether the input data is a mask.\n\n Returns\n -------\n imputer_mask : {ndarray, sparse matrix} of shape (n_samples, n_features)\n The imputer mask of the original data.\n \"\"\"\n if precomputed:\n if not (hasattr(X, 'dtype') and X.dtype.kind == 'b'):\n raise ValueError('precomputed is True but the input data is not a mask')\n self._precomputed = True\n else:\n self._precomputed = False\n if not self._precomputed:\n X = self._validate_input(X, in_fit=True)\n self._n_features = X.shape[1]\n if self.features not in ('missing-only', 'all'):\n raise ValueError(\"'features' has to be either 'missing-only' or 'all'. Got {} instead.\".format(self.features))\n if not (isinstance(self.sparse, str) and self.sparse == 'auto' or isinstance(self.sparse, bool)):\n raise ValueError(\"'sparse' has to be a boolean or 'auto'. Got {!r} instead.\".format(self.sparse))\n missing_features_info = self._get_missing_features_info(X)\n self.features_ = missing_features_info[1]\n return missing_features_info[0]" }, { "name": "_get_missing_features_info", + "unique_name": "_get_missing_features_info", "qname": "sklearn.impute._base.MissingIndicator._get_missing_features_info", + "unique_qname": "sklearn.impute._base.MissingIndicator._get_missing_features_info", "decorators": [], "parameters": [ { @@ -87045,20 +89883,22 @@ "is_public": false, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "{ndarray or sparse matrix}, shape (n_samples, n_features)", - "description": "The input data with missing values. Note that ``X`` has been\nchecked in ``fit`` and ``transform`` before to call this function." + "type": "{ndarray, sparse matrix} of shape (n_samples, n_features)", + "description": "The input data with missing values. Note that `X` has been\nchecked in :meth:`fit` and :meth:`transform` before to call this\nfunction." } } ], "results": [], "is_public": false, "description": "Compute the imputer mask and the indices of the features containing missing values.", - "docstring": "Compute the imputer mask and the indices of the features\ncontaining missing values.\n\nParameters\n----------\nX : {ndarray or sparse matrix}, shape (n_samples, n_features)\n The input data with missing values. Note that ``X`` has been\n checked in ``fit`` and ``transform`` before to call this function.\n\nReturns\n-------\nimputer_mask : {ndarray or sparse matrix}, shape (n_samples, n_features)\n The imputer mask of the original data.\n\nfeatures_with_missing : ndarray, shape (n_features_with_missing)\n The features containing missing values.", - "source_code": "\ndef _get_missing_features_info(self, X):\n \"\"\"Compute the imputer mask and the indices of the features\n containing missing values.\n\n Parameters\n ----------\n X : {ndarray or sparse matrix}, shape (n_samples, n_features)\n The input data with missing values. Note that ``X`` has been\n checked in ``fit`` and ``transform`` before to call this function.\n\n Returns\n -------\n imputer_mask : {ndarray or sparse matrix}, shape (n_samples, n_features)\n The imputer mask of the original data.\n\n features_with_missing : ndarray, shape (n_features_with_missing)\n The features containing missing values.\n\n \"\"\"\n if not self._precomputed:\n imputer_mask = _get_mask(X, self.missing_values)\n else:\n imputer_mask = X\n if sp.issparse(X):\n imputer_mask.eliminate_zeros()\n if self.features == 'missing-only':\n n_missing = imputer_mask.getnnz(axis=0)\n if self.sparse is False:\n imputer_mask = imputer_mask.toarray()\n elif imputer_mask.format == 'csr':\n imputer_mask = imputer_mask.tocsc()\n else:\n if not self._precomputed:\n imputer_mask = _get_mask(X, self.missing_values)\n else:\n imputer_mask = X\n if self.features == 'missing-only':\n n_missing = imputer_mask.sum(axis=0)\n if self.sparse is True:\n imputer_mask = sp.csc_matrix(imputer_mask)\n if self.features == 'all':\n features_indices = np.arange(X.shape[1])\n else:\n features_indices = np.flatnonzero(n_missing)\n return imputer_mask, features_indices" + "docstring": "Compute the imputer mask and the indices of the features\ncontaining missing values.\n\nParameters\n----------\nX : {ndarray, sparse matrix} of shape (n_samples, n_features)\n The input data with missing values. Note that `X` has been\n checked in :meth:`fit` and :meth:`transform` before to call this\n function.\n\nReturns\n-------\nimputer_mask : {ndarray, sparse matrix} of shape (n_samples, n_features)\n The imputer mask of the original data.\n\nfeatures_with_missing : ndarray of shape (n_features_with_missing)\n The features containing missing values.", + "source_code": "\ndef _get_missing_features_info(self, X):\n \"\"\"Compute the imputer mask and the indices of the features\n containing missing values.\n\n Parameters\n ----------\n X : {ndarray, sparse matrix} of shape (n_samples, n_features)\n The input data with missing values. Note that `X` has been\n checked in :meth:`fit` and :meth:`transform` before to call this\n function.\n\n Returns\n -------\n imputer_mask : {ndarray, sparse matrix} of shape (n_samples, n_features)\n The imputer mask of the original data.\n\n features_with_missing : ndarray of shape (n_features_with_missing)\n The features containing missing values.\n \"\"\"\n if not self._precomputed:\n imputer_mask = _get_mask(X, self.missing_values)\n else:\n imputer_mask = X\n if sp.issparse(X):\n imputer_mask.eliminate_zeros()\n if self.features == 'missing-only':\n n_missing = imputer_mask.getnnz(axis=0)\n if self.sparse is False:\n imputer_mask = imputer_mask.toarray()\n elif imputer_mask.format == 'csr':\n imputer_mask = imputer_mask.tocsc()\n else:\n if not self._precomputed:\n imputer_mask = _get_mask(X, self.missing_values)\n else:\n imputer_mask = X\n if self.features == 'missing-only':\n n_missing = imputer_mask.sum(axis=0)\n if self.sparse is True:\n imputer_mask = sp.csc_matrix(imputer_mask)\n if self.features == 'all':\n features_indices = np.arange(X.shape[1])\n else:\n features_indices = np.flatnonzero(n_missing)\n return imputer_mask, features_indices" }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.impute._base.MissingIndicator._more_tags", + "unique_qname": "sklearn.impute._base.MissingIndicator._more_tags", "decorators": [], "parameters": [ { @@ -87080,7 +89920,9 @@ }, { "name": "_validate_input", + "unique_name": "_validate_input", "qname": "sklearn.impute._base.MissingIndicator._validate_input", + "unique_qname": "sklearn.impute._base.MissingIndicator._validate_input", "decorators": [], "parameters": [ { @@ -87122,7 +89964,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.impute._base.MissingIndicator.fit", + "unique_qname": "sklearn.impute._base.MissingIndicator.fit", "decorators": [], "parameters": [ { @@ -87141,8 +89985,8 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "{array-like, sparse matrix}, shape (n_samples, n_features)", - "description": "Input data, where ``n_samples`` is the number of samples and\n``n_features`` is the number of features." + "type": "{array-like, sparse matrix} of shape (n_samples, n_features)", + "description": "Input data, where `n_samples` is the number of samples and\n`n_features` is the number of features." } }, { @@ -87151,20 +89995,22 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "", - "description": "" + "type": "Ignored", + "description": "Not used, present for API consistency by convention." } } ], "results": [], "is_public": true, - "description": "Fit the transformer on X.", - "docstring": "Fit the transformer on X.\n\nParameters\n----------\nX : {array-like, sparse matrix}, shape (n_samples, n_features)\n Input data, where ``n_samples`` is the number of samples and\n ``n_features`` is the number of features.\n\nReturns\n-------\nself : object\n Returns self.", - "source_code": "\ndef fit(self, X, y=None):\n \"\"\"Fit the transformer on X.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Input data, where ``n_samples`` is the number of samples and\n ``n_features`` is the number of features.\n\n Returns\n -------\n self : object\n Returns self.\n \"\"\"\n self._fit(X, y)\n return self" + "description": "Fit the transformer on `X`.", + "docstring": "Fit the transformer on `X`.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input data, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\ny : Ignored\n Not used, present for API consistency by convention.\n\nReturns\n-------\nself : object\n Fitted estimator.", + "source_code": "\ndef fit(self, X, y=None):\n \"\"\"Fit the transformer on `X`.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input data, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n self._fit(X, y)\n return self" }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.impute._base.MissingIndicator.fit_transform", + "unique_qname": "sklearn.impute._base.MissingIndicator.fit_transform", "decorators": [], "parameters": [ { @@ -87183,7 +90029,7 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "{array-like, sparse matrix}, shape (n_samples, n_features)", + "type": "{array-like, sparse matrix} of shape (n_samples, n_features)", "description": "The input data to complete." } }, @@ -87193,20 +90039,22 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "", - "description": "" + "type": "Ignored", + "description": "Not used, present for API consistency by convention." } } ], "results": [], "is_public": true, - "description": "Generate missing values indicator for X.", - "docstring": "Generate missing values indicator for X.\n\nParameters\n----------\nX : {array-like, sparse matrix}, shape (n_samples, n_features)\n The input data to complete.\n\nReturns\n-------\nXt : {ndarray or sparse matrix}, shape (n_samples, n_features) or (n_samples, n_features_with_missing)\n The missing indicator for input data. The data type of ``Xt``\n will be boolean.", - "source_code": "\ndef fit_transform(self, X, y=None):\n \"\"\"Generate missing values indicator for X.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n The input data to complete.\n\n Returns\n -------\n Xt : {ndarray or sparse matrix}, shape (n_samples, n_features) or (n_samples, n_features_with_missing)\n The missing indicator for input data. The data type of ``Xt``\n will be boolean.\n\n \"\"\"\n imputer_mask = self._fit(X, y)\n if self.features_.size < self._n_features:\n imputer_mask = imputer_mask[:, self.features_]\n return imputer_mask" + "description": "Generate missing values indicator for `X`.", + "docstring": "Generate missing values indicator for `X`.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n The input data to complete.\n\ny : Ignored\n Not used, present for API consistency by convention.\n\nReturns\n-------\nXt : {ndarray, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_features_with_missing)\n The missing indicator for input data. The data type of `Xt`\n will be boolean.", + "source_code": "\ndef fit_transform(self, X, y=None):\n \"\"\"Generate missing values indicator for `X`.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The input data to complete.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n Xt : {ndarray, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_features_with_missing)\n The missing indicator for input data. The data type of `Xt`\n will be boolean.\n \"\"\"\n imputer_mask = self._fit(X, y)\n if self.features_.size < self._n_features:\n imputer_mask = imputer_mask[:, self.features_]\n return imputer_mask" }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.impute._base.MissingIndicator.transform", + "unique_qname": "sklearn.impute._base.MissingIndicator.transform", "decorators": [], "parameters": [ { @@ -87225,20 +90073,22 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "{array-like, sparse matrix}, shape (n_samples, n_features)", + "type": "{array-like, sparse matrix} of shape (n_samples, n_features)", "description": "The input data to complete." } } ], "results": [], "is_public": true, - "description": "Generate missing values indicator for X.", - "docstring": "Generate missing values indicator for X.\n\nParameters\n----------\nX : {array-like, sparse matrix}, shape (n_samples, n_features)\n The input data to complete.\n\nReturns\n-------\nXt : {ndarray or sparse matrix}, shape (n_samples, n_features) or (n_samples, n_features_with_missing)\n The missing indicator for input data. The data type of ``Xt``\n will be boolean.", - "source_code": "\ndef transform(self, X):\n \"\"\"Generate missing values indicator for X.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n The input data to complete.\n\n Returns\n -------\n Xt : {ndarray or sparse matrix}, shape (n_samples, n_features) or (n_samples, n_features_with_missing)\n The missing indicator for input data. The data type of ``Xt``\n will be boolean.\n\n \"\"\"\n check_is_fitted(self)\n if not self._precomputed:\n X = self._validate_input(X, in_fit=False)\n elif not (hasattr(X, 'dtype') and X.dtype.kind == 'b'):\n raise ValueError('precomputed is True but the input data is not a mask')\n (imputer_mask, features) = self._get_missing_features_info(X)\n if self.features == 'missing-only':\n features_diff_fit_trans = np.setdiff1d(features, self.features_)\n if self.error_on_new and features_diff_fit_trans.size > 0:\n raise ValueError('The features {} have missing values in transform but have no missing values in fit.'.format(features_diff_fit_trans))\n if self.features_.size < self._n_features:\n imputer_mask = imputer_mask[:, self.features_]\n return imputer_mask" + "description": "Generate missing values indicator for `X`.", + "docstring": "Generate missing values indicator for `X`.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n The input data to complete.\n\nReturns\n-------\nXt : {ndarray, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_features_with_missing)\n The missing indicator for input data. The data type of `Xt`\n will be boolean.", + "source_code": "\ndef transform(self, X):\n \"\"\"Generate missing values indicator for `X`.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The input data to complete.\n\n Returns\n -------\n Xt : {ndarray, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_features_with_missing)\n The missing indicator for input data. The data type of `Xt`\n will be boolean.\n \"\"\"\n check_is_fitted(self)\n if not self._precomputed:\n X = self._validate_input(X, in_fit=False)\n elif not (hasattr(X, 'dtype') and X.dtype.kind == 'b'):\n raise ValueError('precomputed is True but the input data is not a mask')\n (imputer_mask, features) = self._get_missing_features_info(X)\n if self.features == 'missing-only':\n features_diff_fit_trans = np.setdiff1d(features, self.features_)\n if self.error_on_new and features_diff_fit_trans.size > 0:\n raise ValueError('The features {} have missing values in transform but have no missing values in fit.'.format(features_diff_fit_trans))\n if self.features_.size < self._n_features:\n imputer_mask = imputer_mask[:, self.features_]\n return imputer_mask" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.impute._base.SimpleImputer.__init__", + "unique_qname": "sklearn.impute._base.SimpleImputer.__init__", "decorators": [], "parameters": [ { @@ -87320,7 +90170,9 @@ }, { "name": "_dense_fit", + "unique_name": "_dense_fit", "qname": "sklearn.impute._base.SimpleImputer._dense_fit", + "unique_qname": "sklearn.impute._base.SimpleImputer._dense_fit", "decorators": [], "parameters": [ { @@ -87382,7 +90234,9 @@ }, { "name": "_sparse_fit", + "unique_name": "_sparse_fit", "qname": "sklearn.impute._base.SimpleImputer._sparse_fit", + "unique_qname": "sklearn.impute._base.SimpleImputer._sparse_fit", "decorators": [], "parameters": [ { @@ -87444,7 +90298,9 @@ }, { "name": "_validate_input", + "unique_name": "_validate_input", "qname": "sklearn.impute._base.SimpleImputer._validate_input", + "unique_qname": "sklearn.impute._base.SimpleImputer._validate_input", "decorators": [], "parameters": [ { @@ -87486,7 +90342,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.impute._base.SimpleImputer.fit", + "unique_qname": "sklearn.impute._base.SimpleImputer.fit", "decorators": [], "parameters": [ { @@ -87528,7 +90386,9 @@ }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.impute._base.SimpleImputer.inverse_transform", + "unique_qname": "sklearn.impute._base.SimpleImputer.inverse_transform", "decorators": [], "parameters": [ { @@ -87560,7 +90420,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.impute._base.SimpleImputer.transform", + "unique_qname": "sklearn.impute._base.SimpleImputer.transform", "decorators": [], "parameters": [ { @@ -87592,7 +90454,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.impute._base._BaseImputer.__init__", + "unique_qname": "sklearn.impute._base._BaseImputer.__init__", "decorators": [], "parameters": [ { @@ -87634,7 +90498,9 @@ }, { "name": "_concatenate_indicator", + "unique_name": "_concatenate_indicator", "qname": "sklearn.impute._base._BaseImputer._concatenate_indicator", + "unique_qname": "sklearn.impute._base._BaseImputer._concatenate_indicator", "decorators": [], "parameters": [ { @@ -87676,7 +90542,9 @@ }, { "name": "_fit_indicator", + "unique_name": "_fit_indicator", "qname": "sklearn.impute._base._BaseImputer._fit_indicator", + "unique_qname": "sklearn.impute._base._BaseImputer._fit_indicator", "decorators": [], "parameters": [ { @@ -87708,7 +90576,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.impute._base._BaseImputer._more_tags", + "unique_qname": "sklearn.impute._base._BaseImputer._more_tags", "decorators": [], "parameters": [ { @@ -87730,7 +90600,9 @@ }, { "name": "_transform_indicator", + "unique_name": "_transform_indicator", "qname": "sklearn.impute._base._BaseImputer._transform_indicator", + "unique_qname": "sklearn.impute._base._BaseImputer._transform_indicator", "decorators": [], "parameters": [ { @@ -87762,7 +90634,9 @@ }, { "name": "_check_inputs_dtype", + "unique_name": "_check_inputs_dtype", "qname": "sklearn.impute._base._check_inputs_dtype", + "unique_qname": "sklearn.impute._base._check_inputs_dtype", "decorators": [], "parameters": [ { @@ -87794,7 +90668,9 @@ }, { "name": "_most_frequent", + "unique_name": "_most_frequent", "qname": "sklearn.impute._base._most_frequent", + "unique_qname": "sklearn.impute._base._most_frequent", "decorators": [], "parameters": [ { @@ -87836,7 +90712,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.impute._iterative.IterativeImputer.__init__", + "unique_qname": "sklearn.impute._iterative.IterativeImputer.__init__", "decorators": [], "parameters": [ { @@ -87856,7 +90734,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "estimator object, default=BayesianRidge()", - "description": "The estimator to use at each step of the round-robin imputation.\nIf ``sample_posterior`` is True, the estimator must support\n``return_std`` in its ``predict`` method." + "description": "The estimator to use at each step of the round-robin imputation.\nIf `sample_posterior=True`, the estimator must support\n`return_std` in its `predict` method." } }, { @@ -87865,7 +90743,7 @@ "is_public": true, "assigned_by": "NAME_ONLY", "docstring": { - "type": "int, np.nan, default=np.nan", + "type": "int or np.nan, default=np.nan", "description": "The placeholder for the missing values. All occurrences of\n`missing_values` will be imputed. For pandas' dataframes with\nnullable integer dtypes with missing values, `missing_values`\nshould be set to `np.nan`, since `pd.NA` will be converted to `np.nan`." } }, @@ -87875,8 +90753,8 @@ "is_public": true, "assigned_by": "NAME_ONLY", "docstring": { - "type": "boolean, default=False", - "description": "Whether to sample from the (Gaussian) predictive posterior of the\nfitted estimator for each imputation. Estimator must support\n``return_std`` in its ``predict`` method if set to ``True``. Set to\n``True`` if using ``IterativeImputer`` for multiple imputations." + "type": "bool, default=False", + "description": "Whether to sample from the (Gaussian) predictive posterior of the\nfitted estimator for each imputation. Estimator must support\n`return_std` in its `predict` method if set to `True`. Set to\n`True` if using `IterativeImputer` for multiple imputations." } }, { @@ -87886,7 +90764,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int, default=10", - "description": "Maximum number of imputation rounds to perform before returning the\nimputations computed during the final round. A round is a single\nimputation of each feature with missing values. The stopping criterion\nis met once `max(abs(X_t - X_{t-1}))/max(abs(X[known_vals])) < tol`,\nwhere `X_t` is `X` at iteration `t`. Note that early stopping is only\napplied if ``sample_posterior=False``." + "description": "Maximum number of imputation rounds to perform before returning the\nimputations computed during the final round. A round is a single\nimputation of each feature with missing values. The stopping criterion\nis met once `max(abs(X_t - X_{t-1}))/max(abs(X[known_vals])) < tol`,\nwhere `X_t` is `X` at iteration `t`. Note that early stopping is only\napplied if `sample_posterior=False`." } }, { @@ -87906,7 +90784,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int, default=None", - "description": "Number of other features to use to estimate the missing values of\neach feature column. Nearness between features is measured using\nthe absolute correlation coefficient between each feature pair (after\ninitial imputation). To ensure coverage of features throughout the\nimputation process, the neighbor features are not necessarily nearest,\nbut are drawn with probability proportional to correlation for each\nimputed target feature. Can provide significant speed-up when the\nnumber of features is huge. If ``None``, all features will be used." + "description": "Number of other features to use to estimate the missing values of\neach feature column. Nearness between features is measured using\nthe absolute correlation coefficient between each feature pair (after\ninitial imputation). To ensure coverage of features throughout the\nimputation process, the neighbor features are not necessarily nearest,\nbut are drawn with probability proportional to correlation for each\nimputed target feature. Can provide significant speed-up when the\nnumber of features is huge. If `None`, all features will be used." } }, { @@ -87915,8 +90793,8 @@ "is_public": true, "assigned_by": "NAME_ONLY", "docstring": { - "type": "str, default='mean'", - "description": "Which strategy to use to initialize the missing values. Same as the\n``strategy`` parameter in :class:`~sklearn.impute.SimpleImputer`\nValid values: {\"mean\", \"median\", \"most_frequent\", or \"constant\"}." + "type": "{'mean', 'median', 'most_frequent', 'constant'}, default='mean'", + "description": "Which strategy to use to initialize the missing values. Same as the\n`strategy` parameter in :class:`~sklearn.impute.SimpleImputer`." } }, { @@ -87925,8 +90803,8 @@ "is_public": true, "assigned_by": "NAME_ONLY", "docstring": { - "type": "str, default='ascending'", - "description": "The order in which the features will be imputed. Possible values:\n\n\"ascending\"\n From features with fewest missing values to most.\n\"descending\"\n From features with most missing values to fewest.\n\"roman\"\n Left to right.\n\"arabic\"\n Right to left.\n\"random\"\n A random order for each round." + "type": "{'ascending', 'descending', 'roman', 'arabic', 'random'}, default='ascending'", + "description": "The order in which the features will be imputed. Possible values:\n\n- `'ascending'`: From features with fewest missing values to most.\n- `'descending'`: From features with most missing values to fewest.\n- `'roman'`: Left to right.\n- `'arabic'`: Right to left.\n- `'random'`: A random order for each round." } }, { @@ -87935,8 +90813,8 @@ "is_public": true, "assigned_by": "NAME_ONLY", "docstring": { - "type": "boolean, default=False", - "description": "If ``True`` then features with missing values during ``transform``\nwhich did not have any missing values during ``fit`` will be imputed\nwith the initial imputation method only. Set to ``True`` if you have\nmany features with no missing values at both ``fit`` and ``transform``\ntime to save compute." + "type": "bool, default=False", + "description": "If `True` then features with missing values during :meth:`transform`\nwhich did not have any missing values during :meth:`fit` will be\nimputed with the initial imputation method only. Set to `True` if you\nhave many features with no missing values at both :meth:`fit` and\n:meth:`transform` time to save compute." } }, { @@ -87946,7 +90824,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "float or array-like of shape (n_features,), default=-np.inf", - "description": "Minimum possible imputed value. Broadcast to shape (n_features,) if\nscalar. If array-like, expects shape (n_features,), one min value for\neach feature. The default is `-np.inf`.\n\n.. versionchanged:: 0.23\n Added support for array-like." + "description": "Minimum possible imputed value. Broadcast to shape `(n_features,)` if\nscalar. If array-like, expects shape `(n_features,)`, one min value for\neach feature. The default is `-np.inf`.\n\n.. versionchanged:: 0.23\n Added support for array-like." } }, { @@ -87956,7 +90834,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "float or array-like of shape (n_features,), default=np.inf", - "description": "Maximum possible imputed value. Broadcast to shape (n_features,) if\nscalar. If array-like, expects shape (n_features,), one max value for\neach feature. The default is `np.inf`.\n\n.. versionchanged:: 0.23\n Added support for array-like." + "description": "Maximum possible imputed value. Broadcast to shape `(n_features,)` if\nscalar. If array-like, expects shape `(n_features,)`, one max value for\neach feature. The default is `np.inf`.\n\n.. versionchanged:: 0.23\n Added support for array-like." } }, { @@ -87976,7 +90854,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int, RandomState instance or None, default=None", - "description": "The seed of the pseudo random number generator to use. Randomizes\nselection of estimator features if n_nearest_features is not None, the\n``imputation_order`` if ``random``, and the sampling from posterior if\n``sample_posterior`` is True. Use an integer for determinism.\nSee :term:`the Glossary `." + "description": "The seed of the pseudo random number generator to use. Randomizes\nselection of estimator features if `n_nearest_features` is not `None`,\nthe `imputation_order` if `random`, and the sampling from posterior if\n`sample_posterior=True`. Use an integer for determinism.\nSee :term:`the Glossary `." } }, { @@ -87985,8 +90863,8 @@ "is_public": true, "assigned_by": "NAME_ONLY", "docstring": { - "type": "boolean, default=False", - "description": "If True, a :class:`MissingIndicator` transform will stack onto output\nof the imputer's transform. This allows a predictive estimator\nto account for missingness despite imputation. If a feature has no\nmissing values at fit/train time, the feature won't appear on\nthe missing indicator even if there are missing values at\ntransform/test time." + "type": "bool, default=False", + "description": "If `True`, a :class:`MissingIndicator` transform will stack onto output\nof the imputer's transform. This allows a predictive estimator\nto account for missingness despite imputation. If a feature has no\nmissing values at fit/train time, the feature won't appear on\nthe missing indicator even if there are missing values at\ntransform/test time." } } ], @@ -87998,7 +90876,9 @@ }, { "name": "_get_abs_corr_mat", + "unique_name": "_get_abs_corr_mat", "qname": "sklearn.impute._iterative.IterativeImputer._get_abs_corr_mat", + "unique_qname": "sklearn.impute._iterative.IterativeImputer._get_abs_corr_mat", "decorators": [], "parameters": [ { @@ -88028,19 +90908,21 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "float, default=1e-6", - "description": "``abs_corr_mat`` can have nans, which will be replaced\nwith ``tolerance``." + "description": "`abs_corr_mat` can have nans, which will be replaced\nwith `tolerance`." } } ], "results": [], "is_public": false, "description": "Get absolute correlation matrix between features.", - "docstring": "Get absolute correlation matrix between features.\n\nParameters\n----------\nX_filled : ndarray, shape (n_samples, n_features)\n Input data with the most recent imputations.\n\ntolerance : float, default=1e-6\n ``abs_corr_mat`` can have nans, which will be replaced\n with ``tolerance``.\n\nReturns\n-------\nabs_corr_mat : ndarray, shape (n_features, n_features)\n Absolute correlation matrix of ``X`` at the beginning of the\n current round. The diagonal has been zeroed out and each feature's\n absolute correlations with all others have been normalized to sum\n to 1.", - "source_code": "\ndef _get_abs_corr_mat(self, X_filled, tolerance=1e-06):\n \"\"\"Get absolute correlation matrix between features.\n\n Parameters\n ----------\n X_filled : ndarray, shape (n_samples, n_features)\n Input data with the most recent imputations.\n\n tolerance : float, default=1e-6\n ``abs_corr_mat`` can have nans, which will be replaced\n with ``tolerance``.\n\n Returns\n -------\n abs_corr_mat : ndarray, shape (n_features, n_features)\n Absolute correlation matrix of ``X`` at the beginning of the\n current round. The diagonal has been zeroed out and each feature's\n absolute correlations with all others have been normalized to sum\n to 1.\n \"\"\"\n n_features = X_filled.shape[1]\n if self.n_nearest_features is None or self.n_nearest_features >= n_features:\n return None\n with np.errstate(invalid='ignore'):\n abs_corr_mat = np.abs(np.corrcoef(X_filled.T))\n abs_corr_mat[np.isnan(abs_corr_mat)] = tolerance\n np.clip(abs_corr_mat, tolerance, None, out=abs_corr_mat)\n np.fill_diagonal(abs_corr_mat, 0)\n abs_corr_mat = normalize(abs_corr_mat, norm='l1', axis=0, copy=False)\n return abs_corr_mat" + "docstring": "Get absolute correlation matrix between features.\n\nParameters\n----------\nX_filled : ndarray, shape (n_samples, n_features)\n Input data with the most recent imputations.\n\ntolerance : float, default=1e-6\n `abs_corr_mat` can have nans, which will be replaced\n with `tolerance`.\n\nReturns\n-------\nabs_corr_mat : ndarray, shape (n_features, n_features)\n Absolute correlation matrix of `X` at the beginning of the\n current round. The diagonal has been zeroed out and each feature's\n absolute correlations with all others have been normalized to sum\n to 1.", + "source_code": "\ndef _get_abs_corr_mat(self, X_filled, tolerance=1e-06):\n \"\"\"Get absolute correlation matrix between features.\n\n Parameters\n ----------\n X_filled : ndarray, shape (n_samples, n_features)\n Input data with the most recent imputations.\n\n tolerance : float, default=1e-6\n `abs_corr_mat` can have nans, which will be replaced\n with `tolerance`.\n\n Returns\n -------\n abs_corr_mat : ndarray, shape (n_features, n_features)\n Absolute correlation matrix of `X` at the beginning of the\n current round. The diagonal has been zeroed out and each feature's\n absolute correlations with all others have been normalized to sum\n to 1.\n \"\"\"\n n_features = X_filled.shape[1]\n if self.n_nearest_features is None or self.n_nearest_features >= n_features:\n return None\n with np.errstate(invalid='ignore'):\n abs_corr_mat = np.abs(np.corrcoef(X_filled.T))\n abs_corr_mat[np.isnan(abs_corr_mat)] = tolerance\n np.clip(abs_corr_mat, tolerance, None, out=abs_corr_mat)\n np.fill_diagonal(abs_corr_mat, 0)\n abs_corr_mat = normalize(abs_corr_mat, norm='l1', axis=0, copy=False)\n return abs_corr_mat" }, { "name": "_get_neighbor_feat_idx", + "unique_name": "_get_neighbor_feat_idx", "qname": "sklearn.impute._iterative.IterativeImputer._get_neighbor_feat_idx", + "unique_qname": "sklearn.impute._iterative.IterativeImputer._get_neighbor_feat_idx", "decorators": [], "parameters": [ { @@ -88060,7 +90942,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "int", - "description": "Number of features in ``X``." + "description": "Number of features in `X`." } }, { @@ -88080,19 +90962,21 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "ndarray, shape (n_features, n_features)", - "description": "Absolute correlation matrix of ``X``. The diagonal has been zeroed\nout and each feature has been normalized to sum to 1. Can be None." + "description": "Absolute correlation matrix of `X`. The diagonal has been zeroed\nout and each feature has been normalized to sum to 1. Can be None." } } ], "results": [], "is_public": false, - "description": "Get a list of other features to predict ``feat_idx``.\n\nIf self.n_nearest_features is less than or equal to the total number of features, then use a probability proportional to the absolute correlation between ``feat_idx`` and each other feature to randomly choose a subsample of the other features (without replacement).", - "docstring": "Get a list of other features to predict ``feat_idx``.\n\nIf self.n_nearest_features is less than or equal to the total\nnumber of features, then use a probability proportional to the absolute\ncorrelation between ``feat_idx`` and each other feature to randomly\nchoose a subsample of the other features (without replacement).\n\nParameters\n----------\nn_features : int\n Number of features in ``X``.\n\nfeat_idx : int\n Index of the feature currently being imputed.\n\nabs_corr_mat : ndarray, shape (n_features, n_features)\n Absolute correlation matrix of ``X``. The diagonal has been zeroed\n out and each feature has been normalized to sum to 1. Can be None.\n\nReturns\n-------\nneighbor_feat_idx : array-like\n The features to use to impute ``feat_idx``.", - "source_code": "\ndef _get_neighbor_feat_idx(self, n_features, feat_idx, abs_corr_mat):\n \"\"\"Get a list of other features to predict ``feat_idx``.\n\n If self.n_nearest_features is less than or equal to the total\n number of features, then use a probability proportional to the absolute\n correlation between ``feat_idx`` and each other feature to randomly\n choose a subsample of the other features (without replacement).\n\n Parameters\n ----------\n n_features : int\n Number of features in ``X``.\n\n feat_idx : int\n Index of the feature currently being imputed.\n\n abs_corr_mat : ndarray, shape (n_features, n_features)\n Absolute correlation matrix of ``X``. The diagonal has been zeroed\n out and each feature has been normalized to sum to 1. Can be None.\n\n Returns\n -------\n neighbor_feat_idx : array-like\n The features to use to impute ``feat_idx``.\n \"\"\"\n if self.n_nearest_features is not None and self.n_nearest_features < n_features:\n p = abs_corr_mat[:, feat_idx]\n neighbor_feat_idx = self.random_state_.choice(np.arange(n_features), self.n_nearest_features, replace=False, p=p)\n else:\n inds_left = np.arange(feat_idx)\n inds_right = np.arange(feat_idx + 1, n_features)\n neighbor_feat_idx = np.concatenate((inds_left, inds_right))\n return neighbor_feat_idx" + "description": "Get a list of other features to predict `feat_idx`.\n\nIf `self.n_nearest_features` is less than or equal to the total number of features, then use a probability proportional to the absolute correlation between `feat_idx` and each other feature to randomly choose a subsample of the other features (without replacement).", + "docstring": "Get a list of other features to predict `feat_idx`.\n\nIf `self.n_nearest_features` is less than or equal to the total\nnumber of features, then use a probability proportional to the absolute\ncorrelation between `feat_idx` and each other feature to randomly\nchoose a subsample of the other features (without replacement).\n\nParameters\n----------\nn_features : int\n Number of features in `X`.\n\nfeat_idx : int\n Index of the feature currently being imputed.\n\nabs_corr_mat : ndarray, shape (n_features, n_features)\n Absolute correlation matrix of `X`. The diagonal has been zeroed\n out and each feature has been normalized to sum to 1. Can be None.\n\nReturns\n-------\nneighbor_feat_idx : array-like\n The features to use to impute `feat_idx`.", + "source_code": "\ndef _get_neighbor_feat_idx(self, n_features, feat_idx, abs_corr_mat):\n \"\"\"Get a list of other features to predict `feat_idx`.\n\n If `self.n_nearest_features` is less than or equal to the total\n number of features, then use a probability proportional to the absolute\n correlation between `feat_idx` and each other feature to randomly\n choose a subsample of the other features (without replacement).\n\n Parameters\n ----------\n n_features : int\n Number of features in `X`.\n\n feat_idx : int\n Index of the feature currently being imputed.\n\n abs_corr_mat : ndarray, shape (n_features, n_features)\n Absolute correlation matrix of `X`. The diagonal has been zeroed\n out and each feature has been normalized to sum to 1. Can be None.\n\n Returns\n -------\n neighbor_feat_idx : array-like\n The features to use to impute `feat_idx`.\n \"\"\"\n if self.n_nearest_features is not None and self.n_nearest_features < n_features:\n p = abs_corr_mat[:, feat_idx]\n neighbor_feat_idx = self.random_state_.choice(np.arange(n_features), self.n_nearest_features, replace=False, p=p)\n else:\n inds_left = np.arange(feat_idx)\n inds_right = np.arange(feat_idx + 1, n_features)\n neighbor_feat_idx = np.concatenate((inds_left, inds_right))\n return neighbor_feat_idx" }, { "name": "_get_ordered_idx", + "unique_name": "_get_ordered_idx", "qname": "sklearn.impute._iterative.IterativeImputer._get_ordered_idx", + "unique_qname": "sklearn.impute._iterative.IterativeImputer._get_ordered_idx", "decorators": [], "parameters": [ { @@ -88112,19 +90996,21 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "array-like, shape (n_samples, n_features)", - "description": "Input data's missing indicator matrix, where \"n_samples\" is the\nnumber of samples and \"n_features\" is the number of features." + "description": "Input data's missing indicator matrix, where `n_samples` is the\nnumber of samples and `n_features` is the number of features." } } ], "results": [], "is_public": false, "description": "Decide in what order we will update the features.\n\nAs a homage to the MICE R package, we will have 4 main options of how to order the updates, and use a random order if anything else is specified. Also, this function skips features which have no missing values.", - "docstring": "Decide in what order we will update the features.\n\nAs a homage to the MICE R package, we will have 4 main options of\nhow to order the updates, and use a random order if anything else\nis specified.\n\nAlso, this function skips features which have no missing values.\n\nParameters\n----------\nmask_missing_values : array-like, shape (n_samples, n_features)\n Input data's missing indicator matrix, where \"n_samples\" is the\n number of samples and \"n_features\" is the number of features.\n\nReturns\n-------\nordered_idx : ndarray, shape (n_features,)\n The order in which to impute the features.", - "source_code": "\ndef _get_ordered_idx(self, mask_missing_values):\n \"\"\"Decide in what order we will update the features.\n\n As a homage to the MICE R package, we will have 4 main options of\n how to order the updates, and use a random order if anything else\n is specified.\n\n Also, this function skips features which have no missing values.\n\n Parameters\n ----------\n mask_missing_values : array-like, shape (n_samples, n_features)\n Input data's missing indicator matrix, where \"n_samples\" is the\n number of samples and \"n_features\" is the number of features.\n\n Returns\n -------\n ordered_idx : ndarray, shape (n_features,)\n The order in which to impute the features.\n \"\"\"\n frac_of_missing_values = mask_missing_values.mean(axis=0)\n if self.skip_complete:\n missing_values_idx = np.flatnonzero(frac_of_missing_values)\n else:\n missing_values_idx = np.arange(np.shape(frac_of_missing_values)[0])\n if self.imputation_order == 'roman':\n ordered_idx = missing_values_idx\n elif self.imputation_order == 'arabic':\n ordered_idx = missing_values_idx[::-1]\n elif self.imputation_order == 'ascending':\n n = len(frac_of_missing_values) - len(missing_values_idx)\n ordered_idx = np.argsort(frac_of_missing_values, kind='mergesort')[n:]\n elif self.imputation_order == 'descending':\n n = len(frac_of_missing_values) - len(missing_values_idx)\n ordered_idx = np.argsort(frac_of_missing_values, kind='mergesort')[n:][::-1]\n elif self.imputation_order == 'random':\n ordered_idx = missing_values_idx\n self.random_state_.shuffle(ordered_idx)\n else:\n raise ValueError(\"Got an invalid imputation order: '{0}'. It must be one of the following: 'roman', 'arabic', 'ascending', 'descending', or 'random'.\".format(self.imputation_order))\n return ordered_idx" + "docstring": "Decide in what order we will update the features.\n\nAs a homage to the MICE R package, we will have 4 main options of\nhow to order the updates, and use a random order if anything else\nis specified.\n\nAlso, this function skips features which have no missing values.\n\nParameters\n----------\nmask_missing_values : array-like, shape (n_samples, n_features)\n Input data's missing indicator matrix, where `n_samples` is the\n number of samples and `n_features` is the number of features.\n\nReturns\n-------\nordered_idx : ndarray, shape (n_features,)\n The order in which to impute the features.", + "source_code": "\ndef _get_ordered_idx(self, mask_missing_values):\n \"\"\"Decide in what order we will update the features.\n\n As a homage to the MICE R package, we will have 4 main options of\n how to order the updates, and use a random order if anything else\n is specified.\n\n Also, this function skips features which have no missing values.\n\n Parameters\n ----------\n mask_missing_values : array-like, shape (n_samples, n_features)\n Input data's missing indicator matrix, where `n_samples` is the\n number of samples and `n_features` is the number of features.\n\n Returns\n -------\n ordered_idx : ndarray, shape (n_features,)\n The order in which to impute the features.\n \"\"\"\n frac_of_missing_values = mask_missing_values.mean(axis=0)\n if self.skip_complete:\n missing_values_idx = np.flatnonzero(frac_of_missing_values)\n else:\n missing_values_idx = np.arange(np.shape(frac_of_missing_values)[0])\n if self.imputation_order == 'roman':\n ordered_idx = missing_values_idx\n elif self.imputation_order == 'arabic':\n ordered_idx = missing_values_idx[::-1]\n elif self.imputation_order == 'ascending':\n n = len(frac_of_missing_values) - len(missing_values_idx)\n ordered_idx = np.argsort(frac_of_missing_values, kind='mergesort')[n:]\n elif self.imputation_order == 'descending':\n n = len(frac_of_missing_values) - len(missing_values_idx)\n ordered_idx = np.argsort(frac_of_missing_values, kind='mergesort')[n:][::-1]\n elif self.imputation_order == 'random':\n ordered_idx = missing_values_idx\n self.random_state_.shuffle(ordered_idx)\n else:\n raise ValueError(\"Got an invalid imputation order: '{0}'. It must be one of the following: 'roman', 'arabic', 'ascending', 'descending', or 'random'.\".format(self.imputation_order))\n return ordered_idx" }, { "name": "_impute_one_feature", + "unique_name": "_impute_one_feature", "qname": "sklearn.impute._iterative.IterativeImputer._impute_one_feature", + "unique_qname": "sklearn.impute._iterative.IterativeImputer._impute_one_feature", "decorators": [], "parameters": [ { @@ -88174,7 +91060,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "ndarray", - "description": "Indices of the features to be used in imputing ``feat_idx``." + "description": "Indices of the features to be used in imputing `feat_idx`." } }, { @@ -88184,7 +91070,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "object", - "description": "The estimator to use at this step of the round-robin imputation.\nIf ``sample_posterior`` is True, the estimator must support\n``return_std`` in its ``predict`` method.\nIf None, it will be cloned from self._estimator." + "description": "The estimator to use at this step of the round-robin imputation.\nIf `sample_posterior=True`, the estimator must support\n`return_std` in its `predict` method.\nIf None, it will be cloned from self._estimator." } }, { @@ -88200,13 +91086,15 @@ ], "results": [], "is_public": false, - "description": "Impute a single feature from the others provided.\n\nThis function predicts the missing values of one of the features using the current estimates of all the other features. The ``estimator`` must support ``return_std=True`` in its ``predict`` method for this function to work.", - "docstring": "Impute a single feature from the others provided.\n\nThis function predicts the missing values of one of the features using\nthe current estimates of all the other features. The ``estimator`` must\nsupport ``return_std=True`` in its ``predict`` method for this function\nto work.\n\nParameters\n----------\nX_filled : ndarray\n Input data with the most recent imputations.\n\nmask_missing_values : ndarray\n Input data's missing indicator matrix.\n\nfeat_idx : int\n Index of the feature currently being imputed.\n\nneighbor_feat_idx : ndarray\n Indices of the features to be used in imputing ``feat_idx``.\n\nestimator : object\n The estimator to use at this step of the round-robin imputation.\n If ``sample_posterior`` is True, the estimator must support\n ``return_std`` in its ``predict`` method.\n If None, it will be cloned from self._estimator.\n\nfit_mode : boolean, default=True\n Whether to fit and predict with the estimator or just predict.\n\nReturns\n-------\nX_filled : ndarray\n Input data with ``X_filled[missing_row_mask, feat_idx]`` updated.\n\nestimator : estimator with sklearn API\n The fitted estimator used to impute\n ``X_filled[missing_row_mask, feat_idx]``.", - "source_code": "\ndef _impute_one_feature(self, X_filled, mask_missing_values, feat_idx, neighbor_feat_idx, estimator=None, fit_mode=True):\n \"\"\"Impute a single feature from the others provided.\n\n This function predicts the missing values of one of the features using\n the current estimates of all the other features. The ``estimator`` must\n support ``return_std=True`` in its ``predict`` method for this function\n to work.\n\n Parameters\n ----------\n X_filled : ndarray\n Input data with the most recent imputations.\n\n mask_missing_values : ndarray\n Input data's missing indicator matrix.\n\n feat_idx : int\n Index of the feature currently being imputed.\n\n neighbor_feat_idx : ndarray\n Indices of the features to be used in imputing ``feat_idx``.\n\n estimator : object\n The estimator to use at this step of the round-robin imputation.\n If ``sample_posterior`` is True, the estimator must support\n ``return_std`` in its ``predict`` method.\n If None, it will be cloned from self._estimator.\n\n fit_mode : boolean, default=True\n Whether to fit and predict with the estimator or just predict.\n\n Returns\n -------\n X_filled : ndarray\n Input data with ``X_filled[missing_row_mask, feat_idx]`` updated.\n\n estimator : estimator with sklearn API\n The fitted estimator used to impute\n ``X_filled[missing_row_mask, feat_idx]``.\n \"\"\"\n if estimator is None and fit_mode is False:\n raise ValueError('If fit_mode is False, then an already-fitted estimator should be passed in.')\n if estimator is None:\n estimator = clone(self._estimator)\n missing_row_mask = mask_missing_values[:, feat_idx]\n if fit_mode:\n X_train = _safe_indexing(X_filled[:, neighbor_feat_idx], ~missing_row_mask)\n y_train = _safe_indexing(X_filled[:, feat_idx], ~missing_row_mask)\n estimator.fit(X_train, y_train)\n if np.sum(missing_row_mask) == 0:\n return X_filled, estimator\n X_test = _safe_indexing(X_filled[:, neighbor_feat_idx], missing_row_mask)\n if self.sample_posterior:\n (mus, sigmas) = estimator.predict(X_test, return_std=True)\n imputed_values = np.zeros(mus.shape, dtype=X_filled.dtype)\n positive_sigmas = sigmas > 0\n imputed_values[~positive_sigmas] = mus[~positive_sigmas]\n mus_too_low = mus < self._min_value[feat_idx]\n imputed_values[mus_too_low] = self._min_value[feat_idx]\n mus_too_high = mus > self._max_value[feat_idx]\n imputed_values[mus_too_high] = self._max_value[feat_idx]\n inrange_mask = positive_sigmas & ~mus_too_low & ~mus_too_high\n mus = mus[inrange_mask]\n sigmas = sigmas[inrange_mask]\n a = (self._min_value[feat_idx] - mus) / sigmas\n b = (self._max_value[feat_idx] - mus) / sigmas\n truncated_normal = stats.truncnorm(a=a, b=b, loc=mus, scale=sigmas)\n imputed_values[inrange_mask] = truncated_normal.rvs(random_state=self.random_state_)\n else:\n imputed_values = estimator.predict(X_test)\n imputed_values = np.clip(imputed_values, self._min_value[feat_idx], self._max_value[feat_idx])\n X_filled[missing_row_mask, feat_idx] = imputed_values\n return X_filled, estimator" + "description": "Impute a single feature from the others provided.\n\nThis function predicts the missing values of one of the features using the current estimates of all the other features. The `estimator` must support `return_std=True` in its `predict` method for this function to work.", + "docstring": "Impute a single feature from the others provided.\n\nThis function predicts the missing values of one of the features using\nthe current estimates of all the other features. The `estimator` must\nsupport `return_std=True` in its `predict` method for this function\nto work.\n\nParameters\n----------\nX_filled : ndarray\n Input data with the most recent imputations.\n\nmask_missing_values : ndarray\n Input data's missing indicator matrix.\n\nfeat_idx : int\n Index of the feature currently being imputed.\n\nneighbor_feat_idx : ndarray\n Indices of the features to be used in imputing `feat_idx`.\n\nestimator : object\n The estimator to use at this step of the round-robin imputation.\n If `sample_posterior=True`, the estimator must support\n `return_std` in its `predict` method.\n If None, it will be cloned from self._estimator.\n\nfit_mode : boolean, default=True\n Whether to fit and predict with the estimator or just predict.\n\nReturns\n-------\nX_filled : ndarray\n Input data with `X_filled[missing_row_mask, feat_idx]` updated.\n\nestimator : estimator with sklearn API\n The fitted estimator used to impute\n `X_filled[missing_row_mask, feat_idx]`.", + "source_code": "\ndef _impute_one_feature(self, X_filled, mask_missing_values, feat_idx, neighbor_feat_idx, estimator=None, fit_mode=True):\n \"\"\"Impute a single feature from the others provided.\n\n This function predicts the missing values of one of the features using\n the current estimates of all the other features. The `estimator` must\n support `return_std=True` in its `predict` method for this function\n to work.\n\n Parameters\n ----------\n X_filled : ndarray\n Input data with the most recent imputations.\n\n mask_missing_values : ndarray\n Input data's missing indicator matrix.\n\n feat_idx : int\n Index of the feature currently being imputed.\n\n neighbor_feat_idx : ndarray\n Indices of the features to be used in imputing `feat_idx`.\n\n estimator : object\n The estimator to use at this step of the round-robin imputation.\n If `sample_posterior=True`, the estimator must support\n `return_std` in its `predict` method.\n If None, it will be cloned from self._estimator.\n\n fit_mode : boolean, default=True\n Whether to fit and predict with the estimator or just predict.\n\n Returns\n -------\n X_filled : ndarray\n Input data with `X_filled[missing_row_mask, feat_idx]` updated.\n\n estimator : estimator with sklearn API\n The fitted estimator used to impute\n `X_filled[missing_row_mask, feat_idx]`.\n \"\"\"\n if estimator is None and fit_mode is False:\n raise ValueError('If fit_mode is False, then an already-fitted estimator should be passed in.')\n if estimator is None:\n estimator = clone(self._estimator)\n missing_row_mask = mask_missing_values[:, feat_idx]\n if fit_mode:\n X_train = _safe_indexing(X_filled[:, neighbor_feat_idx], ~missing_row_mask)\n y_train = _safe_indexing(X_filled[:, feat_idx], ~missing_row_mask)\n estimator.fit(X_train, y_train)\n if np.sum(missing_row_mask) == 0:\n return X_filled, estimator\n X_test = _safe_indexing(X_filled[:, neighbor_feat_idx], missing_row_mask)\n if self.sample_posterior:\n (mus, sigmas) = estimator.predict(X_test, return_std=True)\n imputed_values = np.zeros(mus.shape, dtype=X_filled.dtype)\n positive_sigmas = sigmas > 0\n imputed_values[~positive_sigmas] = mus[~positive_sigmas]\n mus_too_low = mus < self._min_value[feat_idx]\n imputed_values[mus_too_low] = self._min_value[feat_idx]\n mus_too_high = mus > self._max_value[feat_idx]\n imputed_values[mus_too_high] = self._max_value[feat_idx]\n inrange_mask = positive_sigmas & ~mus_too_low & ~mus_too_high\n mus = mus[inrange_mask]\n sigmas = sigmas[inrange_mask]\n a = (self._min_value[feat_idx] - mus) / sigmas\n b = (self._max_value[feat_idx] - mus) / sigmas\n truncated_normal = stats.truncnorm(a=a, b=b, loc=mus, scale=sigmas)\n imputed_values[inrange_mask] = truncated_normal.rvs(random_state=self.random_state_)\n else:\n imputed_values = estimator.predict(X_test)\n imputed_values = np.clip(imputed_values, self._min_value[feat_idx], self._max_value[feat_idx])\n X_filled[missing_row_mask, feat_idx] = imputed_values\n return X_filled, estimator" }, { "name": "_initial_imputation", + "unique_name": "_initial_imputation", "qname": "sklearn.impute._iterative.IterativeImputer._initial_imputation", + "unique_qname": "sklearn.impute._iterative.IterativeImputer._initial_imputation", "decorators": [], "parameters": [ { @@ -88226,7 +91114,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "ndarray, shape (n_samples, n_features)", - "description": "Input data, where \"n_samples\" is the number of samples and\n\"n_features\" is the number of features." + "description": "Input data, where `n_samples` is the number of samples and\n`n_features` is the number of features." } }, { @@ -88236,19 +91124,21 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "bool, default=False", - "description": "Whether function is called in fit." + "description": "Whether function is called in :meth:`fit`." } } ], "results": [], "is_public": false, - "description": "Perform initial imputation for input X.", - "docstring": "Perform initial imputation for input X.\n\nParameters\n----------\nX : ndarray, shape (n_samples, n_features)\n Input data, where \"n_samples\" is the number of samples and\n \"n_features\" is the number of features.\n\nin_fit : bool, default=False\n Whether function is called in fit.\n\nReturns\n-------\nXt : ndarray, shape (n_samples, n_features)\n Input data, where \"n_samples\" is the number of samples and\n \"n_features\" is the number of features.\n\nX_filled : ndarray, shape (n_samples, n_features)\n Input data with the most recent imputations.\n\nmask_missing_values : ndarray, shape (n_samples, n_features)\n Input data's missing indicator matrix, where \"n_samples\" is the\n number of samples and \"n_features\" is the number of features.\n\nX_missing_mask : ndarray, shape (n_samples, n_features)\n Input data's mask matrix indicating missing datapoints, where\n \"n_samples\" is the number of samples and \"n_features\" is the\n number of features.", - "source_code": "\ndef _initial_imputation(self, X, in_fit=False):\n \"\"\"Perform initial imputation for input X.\n\n Parameters\n ----------\n X : ndarray, shape (n_samples, n_features)\n Input data, where \"n_samples\" is the number of samples and\n \"n_features\" is the number of features.\n\n in_fit : bool, default=False\n Whether function is called in fit.\n\n Returns\n -------\n Xt : ndarray, shape (n_samples, n_features)\n Input data, where \"n_samples\" is the number of samples and\n \"n_features\" is the number of features.\n\n X_filled : ndarray, shape (n_samples, n_features)\n Input data with the most recent imputations.\n\n mask_missing_values : ndarray, shape (n_samples, n_features)\n Input data's missing indicator matrix, where \"n_samples\" is the\n number of samples and \"n_features\" is the number of features.\n\n X_missing_mask : ndarray, shape (n_samples, n_features)\n Input data's mask matrix indicating missing datapoints, where\n \"n_samples\" is the number of samples and \"n_features\" is the\n number of features.\n \"\"\"\n if is_scalar_nan(self.missing_values):\n force_all_finite = 'allow-nan'\n else:\n force_all_finite = True\n X = self._validate_data(X, dtype=FLOAT_DTYPES, order='F', reset=in_fit, force_all_finite=force_all_finite)\n _check_inputs_dtype(X, self.missing_values)\n X_missing_mask = _get_mask(X, self.missing_values)\n mask_missing_values = X_missing_mask.copy()\n if self.initial_imputer_ is None:\n self.initial_imputer_ = SimpleImputer(missing_values=self.missing_values, strategy=self.initial_strategy)\n X_filled = self.initial_imputer_.fit_transform(X)\n else:\n X_filled = self.initial_imputer_.transform(X)\n valid_mask = np.flatnonzero(np.logical_not(np.isnan(self.initial_imputer_.statistics_)))\n Xt = X[:, valid_mask]\n mask_missing_values = mask_missing_values[:, valid_mask]\n return Xt, X_filled, mask_missing_values, X_missing_mask" + "description": "Perform initial imputation for input `X`.", + "docstring": "Perform initial imputation for input `X`.\n\nParameters\n----------\nX : ndarray, shape (n_samples, n_features)\n Input data, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\nin_fit : bool, default=False\n Whether function is called in :meth:`fit`.\n\nReturns\n-------\nXt : ndarray, shape (n_samples, n_features)\n Input data, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\nX_filled : ndarray, shape (n_samples, n_features)\n Input data with the most recent imputations.\n\nmask_missing_values : ndarray, shape (n_samples, n_features)\n Input data's missing indicator matrix, where `n_samples` is the\n number of samples and `n_features` is the number of features.\n\nX_missing_mask : ndarray, shape (n_samples, n_features)\n Input data's mask matrix indicating missing datapoints, where\n `n_samples` is the number of samples and `n_features` is the\n number of features.", + "source_code": "\ndef _initial_imputation(self, X, in_fit=False):\n \"\"\"Perform initial imputation for input `X`.\n\n Parameters\n ----------\n X : ndarray, shape (n_samples, n_features)\n Input data, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n in_fit : bool, default=False\n Whether function is called in :meth:`fit`.\n\n Returns\n -------\n Xt : ndarray, shape (n_samples, n_features)\n Input data, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n X_filled : ndarray, shape (n_samples, n_features)\n Input data with the most recent imputations.\n\n mask_missing_values : ndarray, shape (n_samples, n_features)\n Input data's missing indicator matrix, where `n_samples` is the\n number of samples and `n_features` is the number of features.\n\n X_missing_mask : ndarray, shape (n_samples, n_features)\n Input data's mask matrix indicating missing datapoints, where\n `n_samples` is the number of samples and `n_features` is the\n number of features.\n \"\"\"\n if is_scalar_nan(self.missing_values):\n force_all_finite = 'allow-nan'\n else:\n force_all_finite = True\n X = self._validate_data(X, dtype=FLOAT_DTYPES, order='F', reset=in_fit, force_all_finite=force_all_finite)\n _check_inputs_dtype(X, self.missing_values)\n X_missing_mask = _get_mask(X, self.missing_values)\n mask_missing_values = X_missing_mask.copy()\n if self.initial_imputer_ is None:\n self.initial_imputer_ = SimpleImputer(missing_values=self.missing_values, strategy=self.initial_strategy)\n X_filled = self.initial_imputer_.fit_transform(X)\n else:\n X_filled = self.initial_imputer_.transform(X)\n valid_mask = np.flatnonzero(np.logical_not(np.isnan(self.initial_imputer_.statistics_)))\n Xt = X[:, valid_mask]\n mask_missing_values = mask_missing_values[:, valid_mask]\n return Xt, X_filled, mask_missing_values, X_missing_mask" }, { "name": "_validate_limit", + "unique_name": "_validate_limit", "qname": "sklearn.impute._iterative.IterativeImputer._validate_limit", + "unique_qname": "sklearn.impute._iterative.IterativeImputer._validate_limit", "decorators": ["staticmethod"], "parameters": [ { @@ -88284,13 +91174,15 @@ ], "results": [], "is_public": false, - "description": "Validate the limits (min/max) of the feature values Converts scalar min/max limits to vectors of shape (n_features,)", - "docstring": "Validate the limits (min/max) of the feature values\nConverts scalar min/max limits to vectors of shape (n_features,)\n\nParameters\n----------\nlimit: scalar or array-like\n The user-specified limit (i.e, min_value or max_value)\nlimit_type: string, \"max\" or \"min\"\n n_features: Number of features in the dataset\n\nReturns\n-------\nlimit: ndarray, shape(n_features,)\n Array of limits, one for each feature", - "source_code": "\n@staticmethod\ndef _validate_limit(limit, limit_type, n_features):\n \"\"\"Validate the limits (min/max) of the feature values\n Converts scalar min/max limits to vectors of shape (n_features,)\n\n Parameters\n ----------\n limit: scalar or array-like\n The user-specified limit (i.e, min_value or max_value)\n limit_type: string, \"max\" or \"min\"\n n_features: Number of features in the dataset\n\n Returns\n -------\n limit: ndarray, shape(n_features,)\n Array of limits, one for each feature\n \"\"\"\n limit_bound = np.inf if limit_type == 'max' else -np.inf\n limit = limit_bound if limit is None else limit\n if np.isscalar(limit):\n limit = np.full(n_features, limit)\n limit = check_array(limit, force_all_finite=False, copy=False, ensure_2d=False)\n if not limit.shape[0] == n_features:\n raise ValueError(f\"'{limit_type}_value' should be of shape ({n_features},) when an array-like is provided. Got {limit.shape}, instead.\")\n return limit" + "description": "Validate the limits (min/max) of the feature values.\n\nConverts scalar min/max limits to vectors of shape `(n_features,)`.", + "docstring": "Validate the limits (min/max) of the feature values.\n\nConverts scalar min/max limits to vectors of shape `(n_features,)`.\n\nParameters\n----------\nlimit: scalar or array-like\n The user-specified limit (i.e, min_value or max_value).\nlimit_type: {'max', 'min'}\n Type of limit to validate.\nn_features: int\n Number of features in the dataset.\n\nReturns\n-------\nlimit: ndarray, shape(n_features,)\n Array of limits, one for each feature.", + "source_code": "\n@staticmethod\ndef _validate_limit(limit, limit_type, n_features):\n \"\"\"Validate the limits (min/max) of the feature values.\n\n Converts scalar min/max limits to vectors of shape `(n_features,)`.\n\n Parameters\n ----------\n limit: scalar or array-like\n The user-specified limit (i.e, min_value or max_value).\n limit_type: {'max', 'min'}\n Type of limit to validate.\n n_features: int\n Number of features in the dataset.\n\n Returns\n -------\n limit: ndarray, shape(n_features,)\n Array of limits, one for each feature.\n \"\"\"\n limit_bound = np.inf if limit_type == 'max' else -np.inf\n limit = limit_bound if limit is None else limit\n if np.isscalar(limit):\n limit = np.full(n_features, limit)\n limit = check_array(limit, force_all_finite=False, copy=False, ensure_2d=False)\n if not limit.shape[0] == n_features:\n raise ValueError(f\"'{limit_type}_value' should be of shape ({n_features},) when an array-like is provided. Got {limit.shape}, instead.\")\n return limit" }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.impute._iterative.IterativeImputer.fit", + "unique_qname": "sklearn.impute._iterative.IterativeImputer.fit", "decorators": [], "parameters": [ { @@ -88310,7 +91202,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "array-like, shape (n_samples, n_features)", - "description": "Input data, where \"n_samples\" is the number of samples and\n\"n_features\" is the number of features." + "description": "Input data, where `n_samples` is the number of samples and\n`n_features` is the number of features." } }, { @@ -88319,20 +91211,22 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "ignored", - "description": "" + "type": "Ignored", + "description": "Not used, present for API consistency by convention." } } ], "results": [], "is_public": true, - "description": "Fits the imputer on X and return self.", - "docstring": "Fits the imputer on X and return self.\n\nParameters\n----------\nX : array-like, shape (n_samples, n_features)\n Input data, where \"n_samples\" is the number of samples and\n \"n_features\" is the number of features.\n\ny : ignored\n\nReturns\n-------\nself : object\n Returns self.", - "source_code": "\ndef fit(self, X, y=None):\n \"\"\"Fits the imputer on X and return self.\n\n Parameters\n ----------\n X : array-like, shape (n_samples, n_features)\n Input data, where \"n_samples\" is the number of samples and\n \"n_features\" is the number of features.\n\n y : ignored\n\n Returns\n -------\n self : object\n Returns self.\n \"\"\"\n self.fit_transform(X)\n return self" + "description": "Fit the imputer on `X` and return self.", + "docstring": "Fit the imputer on `X` and return self.\n\nParameters\n----------\nX : array-like, shape (n_samples, n_features)\n Input data, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\ny : Ignored\n Not used, present for API consistency by convention.\n\nReturns\n-------\nself : object\n Fitted estimator.", + "source_code": "\ndef fit(self, X, y=None):\n \"\"\"Fit the imputer on `X` and return self.\n\n Parameters\n ----------\n X : array-like, shape (n_samples, n_features)\n Input data, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n self.fit_transform(X)\n return self" }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.impute._iterative.IterativeImputer.fit_transform", + "unique_qname": "sklearn.impute._iterative.IterativeImputer.fit_transform", "decorators": [], "parameters": [ { @@ -88352,7 +91246,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "array-like, shape (n_samples, n_features)", - "description": "Input data, where \"n_samples\" is the number of samples and\n\"n_features\" is the number of features." + "description": "Input data, where `n_samples` is the number of samples and\n`n_features` is the number of features." } }, { @@ -88361,20 +91255,22 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "ignored.", - "description": "" + "type": "Ignored", + "description": "Not used, present for API consistency by convention." } } ], "results": [], "is_public": true, - "description": "Fits the imputer on X and return the transformed X.", - "docstring": "Fits the imputer on X and return the transformed X.\n\nParameters\n----------\nX : array-like, shape (n_samples, n_features)\n Input data, where \"n_samples\" is the number of samples and\n \"n_features\" is the number of features.\n\ny : ignored.\n\nReturns\n-------\nXt : array-like, shape (n_samples, n_features)\n The imputed input data.", - "source_code": "\ndef fit_transform(self, X, y=None):\n \"\"\"Fits the imputer on X and return the transformed X.\n\n Parameters\n ----------\n X : array-like, shape (n_samples, n_features)\n Input data, where \"n_samples\" is the number of samples and\n \"n_features\" is the number of features.\n\n y : ignored.\n\n Returns\n -------\n Xt : array-like, shape (n_samples, n_features)\n The imputed input data.\n \"\"\"\n self.random_state_ = getattr(self, 'random_state_', check_random_state(self.random_state))\n if self.max_iter < 0:\n raise ValueError(\"'max_iter' should be a positive integer. Got {} instead.\".format(self.max_iter))\n if self.tol < 0:\n raise ValueError(\"'tol' should be a non-negative float. Got {} instead.\".format(self.tol))\n if self.estimator is None:\n from ..linear_model import BayesianRidge\n self._estimator = BayesianRidge()\n else:\n self._estimator = clone(self.estimator)\n self.imputation_sequence_ = []\n self.initial_imputer_ = None\n (X, Xt, mask_missing_values, complete_mask) = self._initial_imputation(X, in_fit=True)\n super()._fit_indicator(complete_mask)\n X_indicator = super()._transform_indicator(complete_mask)\n if self.max_iter == 0 or np.all(mask_missing_values):\n self.n_iter_ = 0\n return super()._concatenate_indicator(Xt, X_indicator)\n if Xt.shape[1] == 1:\n self.n_iter_ = 0\n return super()._concatenate_indicator(Xt, X_indicator)\n self._min_value = self._validate_limit(self.min_value, 'min', X.shape[1])\n self._max_value = self._validate_limit(self.max_value, 'max', X.shape[1])\n if not np.all(np.greater(self._max_value, self._min_value)):\n raise ValueError('One (or more) features have min_value >= max_value.')\n ordered_idx = self._get_ordered_idx(mask_missing_values)\n self.n_features_with_missing_ = len(ordered_idx)\n abs_corr_mat = self._get_abs_corr_mat(Xt)\n (n_samples, n_features) = Xt.shape\n if self.verbose > 0:\n print('[IterativeImputer] Completing matrix with shape %s' % (X.shape, ))\n start_t = time()\n if not self.sample_posterior:\n Xt_previous = Xt.copy()\n normalized_tol = self.tol * np.max(np.abs(X[~mask_missing_values]))\n for self.n_iter_ in range(1, self.max_iter + 1):\n if self.imputation_order == 'random':\n ordered_idx = self._get_ordered_idx(mask_missing_values)\n for feat_idx in ordered_idx:\n neighbor_feat_idx = self._get_neighbor_feat_idx(n_features, feat_idx, abs_corr_mat)\n (Xt, estimator) = self._impute_one_feature(Xt, mask_missing_values, feat_idx, neighbor_feat_idx, estimator=None, fit_mode=True)\n estimator_triplet = _ImputerTriplet(feat_idx, neighbor_feat_idx, estimator)\n self.imputation_sequence_.append(estimator_triplet)\n if self.verbose > 1:\n print('[IterativeImputer] Ending imputation round %d/%d, elapsed time %0.2f' % (self.n_iter_, self.max_iter, time() - start_t))\n if not self.sample_posterior:\n inf_norm = np.linalg.norm(Xt - Xt_previous, ord=np.inf, axis=None)\n if self.verbose > 0:\n print('[IterativeImputer] Change: {}, scaled tolerance: {} '.format(inf_norm, normalized_tol))\n if inf_norm < normalized_tol:\n if self.verbose > 0:\n print('[IterativeImputer] Early stopping criterion reached.')\n break\n Xt_previous = Xt.copy()\n else:\n if not self.sample_posterior:\n warnings.warn('[IterativeImputer] Early stopping criterion not reached.', ConvergenceWarning)\n Xt[~mask_missing_values] = X[~mask_missing_values]\n return super()._concatenate_indicator(Xt, X_indicator)" + "description": "Fit the imputer on `X` and return the transformed `X`.", + "docstring": "Fit the imputer on `X` and return the transformed `X`.\n\nParameters\n----------\nX : array-like, shape (n_samples, n_features)\n Input data, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\ny : Ignored\n Not used, present for API consistency by convention.\n\nReturns\n-------\nXt : array-like, shape (n_samples, n_features)\n The imputed input data.", + "source_code": "\ndef fit_transform(self, X, y=None):\n \"\"\"Fit the imputer on `X` and return the transformed `X`.\n\n Parameters\n ----------\n X : array-like, shape (n_samples, n_features)\n Input data, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n Xt : array-like, shape (n_samples, n_features)\n The imputed input data.\n \"\"\"\n self.random_state_ = getattr(self, 'random_state_', check_random_state(self.random_state))\n if self.max_iter < 0:\n raise ValueError(\"'max_iter' should be a positive integer. Got {} instead.\".format(self.max_iter))\n if self.tol < 0:\n raise ValueError(\"'tol' should be a non-negative float. Got {} instead.\".format(self.tol))\n if self.estimator is None:\n from ..linear_model import BayesianRidge\n self._estimator = BayesianRidge()\n else:\n self._estimator = clone(self.estimator)\n self.imputation_sequence_ = []\n self.initial_imputer_ = None\n (X, Xt, mask_missing_values, complete_mask) = self._initial_imputation(X, in_fit=True)\n super()._fit_indicator(complete_mask)\n X_indicator = super()._transform_indicator(complete_mask)\n if self.max_iter == 0 or np.all(mask_missing_values):\n self.n_iter_ = 0\n return super()._concatenate_indicator(Xt, X_indicator)\n if Xt.shape[1] == 1:\n self.n_iter_ = 0\n return super()._concatenate_indicator(Xt, X_indicator)\n self._min_value = self._validate_limit(self.min_value, 'min', X.shape[1])\n self._max_value = self._validate_limit(self.max_value, 'max', X.shape[1])\n if not np.all(np.greater(self._max_value, self._min_value)):\n raise ValueError('One (or more) features have min_value >= max_value.')\n ordered_idx = self._get_ordered_idx(mask_missing_values)\n self.n_features_with_missing_ = len(ordered_idx)\n abs_corr_mat = self._get_abs_corr_mat(Xt)\n (n_samples, n_features) = Xt.shape\n if self.verbose > 0:\n print('[IterativeImputer] Completing matrix with shape %s' % (X.shape, ))\n start_t = time()\n if not self.sample_posterior:\n Xt_previous = Xt.copy()\n normalized_tol = self.tol * np.max(np.abs(X[~mask_missing_values]))\n for self.n_iter_ in range(1, self.max_iter + 1):\n if self.imputation_order == 'random':\n ordered_idx = self._get_ordered_idx(mask_missing_values)\n for feat_idx in ordered_idx:\n neighbor_feat_idx = self._get_neighbor_feat_idx(n_features, feat_idx, abs_corr_mat)\n (Xt, estimator) = self._impute_one_feature(Xt, mask_missing_values, feat_idx, neighbor_feat_idx, estimator=None, fit_mode=True)\n estimator_triplet = _ImputerTriplet(feat_idx, neighbor_feat_idx, estimator)\n self.imputation_sequence_.append(estimator_triplet)\n if self.verbose > 1:\n print('[IterativeImputer] Ending imputation round %d/%d, elapsed time %0.2f' % (self.n_iter_, self.max_iter, time() - start_t))\n if not self.sample_posterior:\n inf_norm = np.linalg.norm(Xt - Xt_previous, ord=np.inf, axis=None)\n if self.verbose > 0:\n print('[IterativeImputer] Change: {}, scaled tolerance: {} '.format(inf_norm, normalized_tol))\n if inf_norm < normalized_tol:\n if self.verbose > 0:\n print('[IterativeImputer] Early stopping criterion reached.')\n break\n Xt_previous = Xt.copy()\n else:\n if not self.sample_posterior:\n warnings.warn('[IterativeImputer] Early stopping criterion not reached.', ConvergenceWarning)\n Xt[~mask_missing_values] = X[~mask_missing_values]\n return super()._concatenate_indicator(Xt, X_indicator)" }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.impute._iterative.IterativeImputer.transform", + "unique_qname": "sklearn.impute._iterative.IterativeImputer.transform", "decorators": [], "parameters": [ { @@ -88400,13 +91296,15 @@ ], "results": [], "is_public": true, - "description": "Imputes all missing values in X.\n\nNote that this is stochastic, and that if random_state is not fixed, repeated calls, or permuted input, will yield different results.", - "docstring": "Imputes all missing values in X.\n\nNote that this is stochastic, and that if random_state is not fixed,\nrepeated calls, or permuted input, will yield different results.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n The input data to complete.\n\nReturns\n-------\nXt : array-like, shape (n_samples, n_features)\n The imputed input data.", - "source_code": "\ndef transform(self, X):\n \"\"\"Imputes all missing values in X.\n\n Note that this is stochastic, and that if random_state is not fixed,\n repeated calls, or permuted input, will yield different results.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The input data to complete.\n\n Returns\n -------\n Xt : array-like, shape (n_samples, n_features)\n The imputed input data.\n \"\"\"\n check_is_fitted(self)\n (X, Xt, mask_missing_values, complete_mask) = self._initial_imputation(X)\n X_indicator = super()._transform_indicator(complete_mask)\n if self.n_iter_ == 0 or np.all(mask_missing_values):\n return super()._concatenate_indicator(Xt, X_indicator)\n imputations_per_round = len(self.imputation_sequence_) // self.n_iter_\n i_rnd = 0\n if self.verbose > 0:\n print('[IterativeImputer] Completing matrix with shape %s' % (X.shape, ))\n start_t = time()\n for (it, estimator_triplet) in enumerate(self.imputation_sequence_):\n (Xt, _) = self._impute_one_feature(Xt, mask_missing_values, estimator_triplet.feat_idx, estimator_triplet.neighbor_feat_idx, estimator=estimator_triplet.estimator, fit_mode=False)\n if not (it + 1) % imputations_per_round:\n if self.verbose > 1:\n print('[IterativeImputer] Ending imputation round %d/%d, elapsed time %0.2f' % (i_rnd + 1, self.n_iter_, time() - start_t))\n i_rnd += 1\n Xt[~mask_missing_values] = X[~mask_missing_values]\n return super()._concatenate_indicator(Xt, X_indicator)" + "description": "Impute all missing values in `X`.\n\nNote that this is stochastic, and that if `random_state` is not fixed, repeated calls, or permuted input, results will differ.", + "docstring": "Impute all missing values in `X`.\n\nNote that this is stochastic, and that if `random_state` is not fixed,\nrepeated calls, or permuted input, results will differ.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n The input data to complete.\n\nReturns\n-------\nXt : array-like, shape (n_samples, n_features)\n The imputed input data.", + "source_code": "\ndef transform(self, X):\n \"\"\"Impute all missing values in `X`.\n\n Note that this is stochastic, and that if `random_state` is not fixed,\n repeated calls, or permuted input, results will differ.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The input data to complete.\n\n Returns\n -------\n Xt : array-like, shape (n_samples, n_features)\n The imputed input data.\n \"\"\"\n check_is_fitted(self)\n (X, Xt, mask_missing_values, complete_mask) = self._initial_imputation(X)\n X_indicator = super()._transform_indicator(complete_mask)\n if self.n_iter_ == 0 or np.all(mask_missing_values):\n return super()._concatenate_indicator(Xt, X_indicator)\n imputations_per_round = len(self.imputation_sequence_) // self.n_iter_\n i_rnd = 0\n if self.verbose > 0:\n print('[IterativeImputer] Completing matrix with shape %s' % (X.shape, ))\n start_t = time()\n for (it, estimator_triplet) in enumerate(self.imputation_sequence_):\n (Xt, _) = self._impute_one_feature(Xt, mask_missing_values, estimator_triplet.feat_idx, estimator_triplet.neighbor_feat_idx, estimator=estimator_triplet.estimator, fit_mode=False)\n if not (it + 1) % imputations_per_round:\n if self.verbose > 1:\n print('[IterativeImputer] Ending imputation round %d/%d, elapsed time %0.2f' % (i_rnd + 1, self.n_iter_, time() - start_t))\n i_rnd += 1\n Xt[~mask_missing_values] = X[~mask_missing_values]\n return super()._concatenate_indicator(Xt, X_indicator)" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.impute._knn.KNNImputer.__init__", + "unique_qname": "sklearn.impute._knn.KNNImputer.__init__", "decorators": [], "parameters": [ { @@ -88488,7 +91386,9 @@ }, { "name": "_calc_impute", + "unique_name": "_calc_impute", "qname": "sklearn.impute._knn.KNNImputer._calc_impute", + "unique_qname": "sklearn.impute._knn.KNNImputer._calc_impute", "decorators": [], "parameters": [ { @@ -88550,7 +91450,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.impute._knn.KNNImputer.fit", + "unique_qname": "sklearn.impute._knn.KNNImputer.fit", "decorators": [], "parameters": [ { @@ -88579,20 +91481,22 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "", - "description": "" + "type": "Ignored", + "description": "Not used, present here for API consistency by convention." } } ], "results": [], "is_public": true, "description": "Fit the imputer on X.", - "docstring": "Fit the imputer on X.\n\nParameters\n----------\nX : array-like shape of (n_samples, n_features)\n Input data, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\nReturns\n-------\nself : object", - "source_code": "\ndef fit(self, X, y=None):\n \"\"\"Fit the imputer on X.\n\n Parameters\n ----------\n X : array-like shape of (n_samples, n_features)\n Input data, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n Returns\n -------\n self : object\n \"\"\"\n if not is_scalar_nan(self.missing_values):\n force_all_finite = True\n else:\n force_all_finite = 'allow-nan'\n if self.metric not in _NAN_METRICS and not callable(self.metric):\n raise ValueError('The selected metric does not support NaN values')\n if self.n_neighbors <= 0:\n raise ValueError('Expected n_neighbors > 0. Got {}'.format(self.n_neighbors))\n X = self._validate_data(X, accept_sparse=False, dtype=FLOAT_DTYPES, force_all_finite=force_all_finite, copy=self.copy)\n _check_weights(self.weights)\n self._fit_X = X\n self._mask_fit_X = _get_mask(self._fit_X, self.missing_values)\n super()._fit_indicator(self._mask_fit_X)\n return self" + "docstring": "Fit the imputer on X.\n\nParameters\n----------\nX : array-like shape of (n_samples, n_features)\n Input data, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\ny : Ignored\n Not used, present here for API consistency by convention.\n\nReturns\n-------\nself : object\n The fitted `KNNImputer` class instance.", + "source_code": "\ndef fit(self, X, y=None):\n \"\"\"Fit the imputer on X.\n\n Parameters\n ----------\n X : array-like shape of (n_samples, n_features)\n Input data, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self : object\n The fitted `KNNImputer` class instance.\n \"\"\"\n if not is_scalar_nan(self.missing_values):\n force_all_finite = True\n else:\n force_all_finite = 'allow-nan'\n if self.metric not in _NAN_METRICS and not callable(self.metric):\n raise ValueError('The selected metric does not support NaN values')\n if self.n_neighbors <= 0:\n raise ValueError('Expected n_neighbors > 0. Got {}'.format(self.n_neighbors))\n X = self._validate_data(X, accept_sparse=False, dtype=FLOAT_DTYPES, force_all_finite=force_all_finite, copy=self.copy)\n _check_weights(self.weights)\n self._fit_X = X\n self._mask_fit_X = _get_mask(self._fit_X, self.missing_values)\n super()._fit_indicator(self._mask_fit_X)\n return self" }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.impute._knn.KNNImputer.transform", + "unique_qname": "sklearn.impute._knn.KNNImputer.transform", "decorators": [], "parameters": [ { @@ -88624,7 +91528,9 @@ }, { "name": "_grid_from_X", + "unique_name": "_grid_from_X", "qname": "sklearn.inspection._partial_dependence._grid_from_X", + "unique_qname": "sklearn.inspection._partial_dependence._grid_from_X", "decorators": [], "parameters": [ { @@ -88666,7 +91572,9 @@ }, { "name": "_partial_dependence_brute", + "unique_name": "_partial_dependence_brute", "qname": "sklearn.inspection._partial_dependence._partial_dependence_brute", + "unique_qname": "sklearn.inspection._partial_dependence._partial_dependence_brute", "decorators": [], "parameters": [ { @@ -88728,7 +91636,9 @@ }, { "name": "_partial_dependence_recursion", + "unique_name": "_partial_dependence_recursion", "qname": "sklearn.inspection._partial_dependence._partial_dependence_recursion", + "unique_qname": "sklearn.inspection._partial_dependence._partial_dependence_recursion", "decorators": [], "parameters": [ { @@ -88770,7 +91680,9 @@ }, { "name": "partial_dependence", + "unique_name": "partial_dependence", "qname": "sklearn.inspection._partial_dependence.partial_dependence", + "unique_qname": "sklearn.inspection._partial_dependence.partial_dependence", "decorators": [], "parameters": [ { @@ -88862,7 +91774,9 @@ }, { "name": "_calculate_permutation_scores", + "unique_name": "_calculate_permutation_scores", "qname": "sklearn.inspection._permutation_importance._calculate_permutation_scores", + "unique_qname": "sklearn.inspection._permutation_importance._calculate_permutation_scores", "decorators": [], "parameters": [ { @@ -88964,7 +91878,9 @@ }, { "name": "_create_importances_bunch", + "unique_name": "_create_importances_bunch", "qname": "sklearn.inspection._permutation_importance._create_importances_bunch", + "unique_qname": "sklearn.inspection._permutation_importance._create_importances_bunch", "decorators": [], "parameters": [ { @@ -88996,7 +91912,9 @@ }, { "name": "_weights_scorer", + "unique_name": "_weights_scorer", "qname": "sklearn.inspection._permutation_importance._weights_scorer", + "unique_qname": "sklearn.inspection._permutation_importance._weights_scorer", "decorators": [], "parameters": [ { @@ -89058,7 +91976,9 @@ }, { "name": "permutation_importance", + "unique_name": "permutation_importance", "qname": "sklearn.inspection._permutation_importance.permutation_importance", + "unique_qname": "sklearn.inspection._permutation_importance.permutation_importance", "decorators": [], "parameters": [ { @@ -89128,7 +92048,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int, RandomState instance, default=None", - "description": "Pseudo-random number generator to control the permutations of each\nfeature.\nPass an int to get reproducible results across function calls.\nSee :term: `Glossary `." + "description": "Pseudo-random number generator to control the permutations of each\nfeature.\nPass an int to get reproducible results across function calls.\nSee :term:`Glossary `." } }, { @@ -89155,12 +92075,14 @@ "results": [], "is_public": true, "description": "Permutation importance for feature evaluation [BRE]_.\n\nThe :term:`estimator` is required to be a fitted estimator. `X` can be the data set used to train the estimator or a hold-out set. The permutation importance of a feature is calculated as follows. First, a baseline metric, defined by :term:`scoring`, is evaluated on a (potentially different) dataset defined by the `X`. Next, a feature column from the validation set is permuted and the metric is evaluated again. The permutation importance is defined to be the difference between the baseline metric and metric from permutating the feature column. Read more in the :ref:`User Guide `.", - "docstring": "Permutation importance for feature evaluation [BRE]_.\n\nThe :term:`estimator` is required to be a fitted estimator. `X` can be the\ndata set used to train the estimator or a hold-out set. The permutation\nimportance of a feature is calculated as follows. First, a baseline metric,\ndefined by :term:`scoring`, is evaluated on a (potentially different)\ndataset defined by the `X`. Next, a feature column from the validation set\nis permuted and the metric is evaluated again. The permutation importance\nis defined to be the difference between the baseline metric and metric from\npermutating the feature column.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\nestimator : object\n An estimator that has already been :term:`fitted` and is compatible\n with :term:`scorer`.\n\nX : ndarray or DataFrame, shape (n_samples, n_features)\n Data on which permutation importance will be computed.\n\ny : array-like or None, shape (n_samples, ) or (n_samples, n_classes)\n Targets for supervised or `None` for unsupervised.\n\nscoring : str, callable, list, tuple, or dict, default=None\n Scorer to use.\n If `scoring` represents a single score, one can use:\n\n - a single string (see :ref:`scoring_parameter`);\n - a callable (see :ref:`scoring`) that returns a single value.\n\n If `scoring` represents multiple scores, one can use:\n\n - a list or tuple of unique strings;\n - a callable returning a dictionary where the keys are the metric\n names and the values are the metric scores;\n - a dictionary with metric names as keys and callables a values.\n\n Passing multiple scores to `scoring` is more efficient than calling\n `permutation_importance` for each of the scores as it reuses\n predictions to avoid redundant computation.\n\n If None, the estimator's default scorer is used.\n\nn_repeats : int, default=5\n Number of times to permute a feature.\n\nn_jobs : int or None, default=None\n Number of jobs to run in parallel. The computation is done by computing\n permutation score for each columns and parallelized over the columns.\n `None` means 1 unless in a :obj:`joblib.parallel_backend` context.\n `-1` means using all processors. See :term:`Glossary `\n for more details.\n\nrandom_state : int, RandomState instance, default=None\n Pseudo-random number generator to control the permutations of each\n feature.\n Pass an int to get reproducible results across function calls.\n See :term: `Glossary `.\n\nsample_weight : array-like of shape (n_samples,), default=None\n Sample weights used in scoring.\n\n .. versionadded:: 0.24\n\nmax_samples : int or float, default=1.0\n The number of samples to draw from X to compute feature importance\n in each repeat (without replacement).\n\n - If int, then draw `max_samples` samples.\n - If float, then draw `max_samples * X.shape[0]` samples.\n - If `max_samples` is equal to `1.0` or `X.shape[0]`, all samples\n will be used.\n\n While using this option may provide less accurate importance estimates,\n it keeps the method tractable when evaluating feature importance on\n large datasets. In combination with `n_repeats`, this allows to control\n the computational speed vs statistical accuracy trade-off of this method.\n\n .. versionadded:: 1.0\n\nReturns\n-------\nresult : :class:`~sklearn.utils.Bunch` or dict of such instances\n Dictionary-like object, with the following attributes.\n\n importances_mean : ndarray of shape (n_features, )\n Mean of feature importance over `n_repeats`.\n importances_std : ndarray of shape (n_features, )\n Standard deviation over `n_repeats`.\n importances : ndarray of shape (n_features, n_repeats)\n Raw permutation importance scores.\n\n If there are multiple scoring metrics in the scoring parameter\n `result` is a dict with scorer names as keys (e.g. 'roc_auc') and\n `Bunch` objects like above as values.\n\nReferences\n----------\n.. [BRE] L. Breiman, \"Random Forests\", Machine Learning, 45(1), 5-32,\n 2001. https://doi.org/10.1023/A:1010933404324\n\nExamples\n--------\n>>> from sklearn.linear_model import LogisticRegression\n>>> from sklearn.inspection import permutation_importance\n>>> X = [[1, 9, 9],[1, 9, 9],[1, 9, 9],\n... [0, 9, 9],[0, 9, 9],[0, 9, 9]]\n>>> y = [1, 1, 1, 0, 0, 0]\n>>> clf = LogisticRegression().fit(X, y)\n>>> result = permutation_importance(clf, X, y, n_repeats=10,\n... random_state=0)\n>>> result.importances_mean\narray([0.4666..., 0. , 0. ])\n>>> result.importances_std\narray([0.2211..., 0. , 0. ])", - "source_code": "\ndef permutation_importance(estimator, X, y, *, scoring=None, n_repeats=5, n_jobs=None, random_state=None, sample_weight=None, max_samples=1.0):\n \"\"\"Permutation importance for feature evaluation [BRE]_.\n\n The :term:`estimator` is required to be a fitted estimator. `X` can be the\n data set used to train the estimator or a hold-out set. The permutation\n importance of a feature is calculated as follows. First, a baseline metric,\n defined by :term:`scoring`, is evaluated on a (potentially different)\n dataset defined by the `X`. Next, a feature column from the validation set\n is permuted and the metric is evaluated again. The permutation importance\n is defined to be the difference between the baseline metric and metric from\n permutating the feature column.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n estimator : object\n An estimator that has already been :term:`fitted` and is compatible\n with :term:`scorer`.\n\n X : ndarray or DataFrame, shape (n_samples, n_features)\n Data on which permutation importance will be computed.\n\n y : array-like or None, shape (n_samples, ) or (n_samples, n_classes)\n Targets for supervised or `None` for unsupervised.\n\n scoring : str, callable, list, tuple, or dict, default=None\n Scorer to use.\n If `scoring` represents a single score, one can use:\n\n - a single string (see :ref:`scoring_parameter`);\n - a callable (see :ref:`scoring`) that returns a single value.\n\n If `scoring` represents multiple scores, one can use:\n\n - a list or tuple of unique strings;\n - a callable returning a dictionary where the keys are the metric\n names and the values are the metric scores;\n - a dictionary with metric names as keys and callables a values.\n\n Passing multiple scores to `scoring` is more efficient than calling\n `permutation_importance` for each of the scores as it reuses\n predictions to avoid redundant computation.\n\n If None, the estimator's default scorer is used.\n\n n_repeats : int, default=5\n Number of times to permute a feature.\n\n n_jobs : int or None, default=None\n Number of jobs to run in parallel. The computation is done by computing\n permutation score for each columns and parallelized over the columns.\n `None` means 1 unless in a :obj:`joblib.parallel_backend` context.\n `-1` means using all processors. See :term:`Glossary `\n for more details.\n\n random_state : int, RandomState instance, default=None\n Pseudo-random number generator to control the permutations of each\n feature.\n Pass an int to get reproducible results across function calls.\n See :term: `Glossary `.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights used in scoring.\n\n .. versionadded:: 0.24\n\n max_samples : int or float, default=1.0\n The number of samples to draw from X to compute feature importance\n in each repeat (without replacement).\n\n - If int, then draw `max_samples` samples.\n - If float, then draw `max_samples * X.shape[0]` samples.\n - If `max_samples` is equal to `1.0` or `X.shape[0]`, all samples\n will be used.\n\n While using this option may provide less accurate importance estimates,\n it keeps the method tractable when evaluating feature importance on\n large datasets. In combination with `n_repeats`, this allows to control\n the computational speed vs statistical accuracy trade-off of this method.\n\n .. versionadded:: 1.0\n\n Returns\n -------\n result : :class:`~sklearn.utils.Bunch` or dict of such instances\n Dictionary-like object, with the following attributes.\n\n importances_mean : ndarray of shape (n_features, )\n Mean of feature importance over `n_repeats`.\n importances_std : ndarray of shape (n_features, )\n Standard deviation over `n_repeats`.\n importances : ndarray of shape (n_features, n_repeats)\n Raw permutation importance scores.\n\n If there are multiple scoring metrics in the scoring parameter\n `result` is a dict with scorer names as keys (e.g. 'roc_auc') and\n `Bunch` objects like above as values.\n\n References\n ----------\n .. [BRE] L. Breiman, \"Random Forests\", Machine Learning, 45(1), 5-32,\n 2001. https://doi.org/10.1023/A:1010933404324\n\n Examples\n --------\n >>> from sklearn.linear_model import LogisticRegression\n >>> from sklearn.inspection import permutation_importance\n >>> X = [[1, 9, 9],[1, 9, 9],[1, 9, 9],\n ... [0, 9, 9],[0, 9, 9],[0, 9, 9]]\n >>> y = [1, 1, 1, 0, 0, 0]\n >>> clf = LogisticRegression().fit(X, y)\n >>> result = permutation_importance(clf, X, y, n_repeats=10,\n ... random_state=0)\n >>> result.importances_mean\n array([0.4666..., 0. , 0. ])\n >>> result.importances_std\n array([0.2211..., 0. , 0. ])\n \"\"\"\n if not hasattr(X, 'iloc'):\n X = check_array(X, force_all_finite='allow-nan', dtype=None)\n random_state = check_random_state(random_state)\n random_seed = random_state.randint(np.iinfo(np.int32).max + 1)\n if not isinstance(max_samples, numbers.Integral):\n max_samples = int(max_samples * X.shape[0])\n elif not 0 < max_samples <= X.shape[0]:\n raise ValueError('max_samples must be in (0, n_samples]')\n if callable(scoring):\n scorer = scoring\n elif scoring is None or isinstance(scoring, str):\n scorer = check_scoring(estimator, scoring=scoring)\n else:\n scorers_dict = _check_multimetric_scoring(estimator, scoring)\n scorer = _MultimetricScorer(**scorers_dict)\n baseline_score = _weights_scorer(scorer, estimator, X, y, sample_weight)\n scores = Parallel(n_jobs=n_jobs)((delayed(_calculate_permutation_scores)(estimator, X, y, sample_weight, col_idx, random_seed, n_repeats, scorer, max_samples) for col_idx in range(X.shape[1])))\n if isinstance(baseline_score, dict):\n return {name: _create_importances_bunch(baseline_score[name], np.array([scores[col_idx][name] for col_idx in range(X.shape[1])])) for name in baseline_score}\n else:\n return _create_importances_bunch(baseline_score, np.array(scores))" + "docstring": "Permutation importance for feature evaluation [BRE]_.\n\nThe :term:`estimator` is required to be a fitted estimator. `X` can be the\ndata set used to train the estimator or a hold-out set. The permutation\nimportance of a feature is calculated as follows. First, a baseline metric,\ndefined by :term:`scoring`, is evaluated on a (potentially different)\ndataset defined by the `X`. Next, a feature column from the validation set\nis permuted and the metric is evaluated again. The permutation importance\nis defined to be the difference between the baseline metric and metric from\npermutating the feature column.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\nestimator : object\n An estimator that has already been :term:`fitted` and is compatible\n with :term:`scorer`.\n\nX : ndarray or DataFrame, shape (n_samples, n_features)\n Data on which permutation importance will be computed.\n\ny : array-like or None, shape (n_samples, ) or (n_samples, n_classes)\n Targets for supervised or `None` for unsupervised.\n\nscoring : str, callable, list, tuple, or dict, default=None\n Scorer to use.\n If `scoring` represents a single score, one can use:\n\n - a single string (see :ref:`scoring_parameter`);\n - a callable (see :ref:`scoring`) that returns a single value.\n\n If `scoring` represents multiple scores, one can use:\n\n - a list or tuple of unique strings;\n - a callable returning a dictionary where the keys are the metric\n names and the values are the metric scores;\n - a dictionary with metric names as keys and callables a values.\n\n Passing multiple scores to `scoring` is more efficient than calling\n `permutation_importance` for each of the scores as it reuses\n predictions to avoid redundant computation.\n\n If None, the estimator's default scorer is used.\n\nn_repeats : int, default=5\n Number of times to permute a feature.\n\nn_jobs : int or None, default=None\n Number of jobs to run in parallel. The computation is done by computing\n permutation score for each columns and parallelized over the columns.\n `None` means 1 unless in a :obj:`joblib.parallel_backend` context.\n `-1` means using all processors. See :term:`Glossary `\n for more details.\n\nrandom_state : int, RandomState instance, default=None\n Pseudo-random number generator to control the permutations of each\n feature.\n Pass an int to get reproducible results across function calls.\n See :term:`Glossary `.\n\nsample_weight : array-like of shape (n_samples,), default=None\n Sample weights used in scoring.\n\n .. versionadded:: 0.24\n\nmax_samples : int or float, default=1.0\n The number of samples to draw from X to compute feature importance\n in each repeat (without replacement).\n\n - If int, then draw `max_samples` samples.\n - If float, then draw `max_samples * X.shape[0]` samples.\n - If `max_samples` is equal to `1.0` or `X.shape[0]`, all samples\n will be used.\n\n While using this option may provide less accurate importance estimates,\n it keeps the method tractable when evaluating feature importance on\n large datasets. In combination with `n_repeats`, this allows to control\n the computational speed vs statistical accuracy trade-off of this method.\n\n .. versionadded:: 1.0\n\nReturns\n-------\nresult : :class:`~sklearn.utils.Bunch` or dict of such instances\n Dictionary-like object, with the following attributes.\n\n importances_mean : ndarray of shape (n_features, )\n Mean of feature importance over `n_repeats`.\n importances_std : ndarray of shape (n_features, )\n Standard deviation over `n_repeats`.\n importances : ndarray of shape (n_features, n_repeats)\n Raw permutation importance scores.\n\n If there are multiple scoring metrics in the scoring parameter\n `result` is a dict with scorer names as keys (e.g. 'roc_auc') and\n `Bunch` objects like above as values.\n\nReferences\n----------\n.. [BRE] L. Breiman, \"Random Forests\", Machine Learning, 45(1), 5-32,\n 2001. https://doi.org/10.1023/A:1010933404324\n\nExamples\n--------\n>>> from sklearn.linear_model import LogisticRegression\n>>> from sklearn.inspection import permutation_importance\n>>> X = [[1, 9, 9],[1, 9, 9],[1, 9, 9],\n... [0, 9, 9],[0, 9, 9],[0, 9, 9]]\n>>> y = [1, 1, 1, 0, 0, 0]\n>>> clf = LogisticRegression().fit(X, y)\n>>> result = permutation_importance(clf, X, y, n_repeats=10,\n... random_state=0)\n>>> result.importances_mean\narray([0.4666..., 0. , 0. ])\n>>> result.importances_std\narray([0.2211..., 0. , 0. ])", + "source_code": "\ndef permutation_importance(estimator, X, y, *, scoring=None, n_repeats=5, n_jobs=None, random_state=None, sample_weight=None, max_samples=1.0):\n \"\"\"Permutation importance for feature evaluation [BRE]_.\n\n The :term:`estimator` is required to be a fitted estimator. `X` can be the\n data set used to train the estimator or a hold-out set. The permutation\n importance of a feature is calculated as follows. First, a baseline metric,\n defined by :term:`scoring`, is evaluated on a (potentially different)\n dataset defined by the `X`. Next, a feature column from the validation set\n is permuted and the metric is evaluated again. The permutation importance\n is defined to be the difference between the baseline metric and metric from\n permutating the feature column.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n estimator : object\n An estimator that has already been :term:`fitted` and is compatible\n with :term:`scorer`.\n\n X : ndarray or DataFrame, shape (n_samples, n_features)\n Data on which permutation importance will be computed.\n\n y : array-like or None, shape (n_samples, ) or (n_samples, n_classes)\n Targets for supervised or `None` for unsupervised.\n\n scoring : str, callable, list, tuple, or dict, default=None\n Scorer to use.\n If `scoring` represents a single score, one can use:\n\n - a single string (see :ref:`scoring_parameter`);\n - a callable (see :ref:`scoring`) that returns a single value.\n\n If `scoring` represents multiple scores, one can use:\n\n - a list or tuple of unique strings;\n - a callable returning a dictionary where the keys are the metric\n names and the values are the metric scores;\n - a dictionary with metric names as keys and callables a values.\n\n Passing multiple scores to `scoring` is more efficient than calling\n `permutation_importance` for each of the scores as it reuses\n predictions to avoid redundant computation.\n\n If None, the estimator's default scorer is used.\n\n n_repeats : int, default=5\n Number of times to permute a feature.\n\n n_jobs : int or None, default=None\n Number of jobs to run in parallel. The computation is done by computing\n permutation score for each columns and parallelized over the columns.\n `None` means 1 unless in a :obj:`joblib.parallel_backend` context.\n `-1` means using all processors. See :term:`Glossary `\n for more details.\n\n random_state : int, RandomState instance, default=None\n Pseudo-random number generator to control the permutations of each\n feature.\n Pass an int to get reproducible results across function calls.\n See :term:`Glossary `.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights used in scoring.\n\n .. versionadded:: 0.24\n\n max_samples : int or float, default=1.0\n The number of samples to draw from X to compute feature importance\n in each repeat (without replacement).\n\n - If int, then draw `max_samples` samples.\n - If float, then draw `max_samples * X.shape[0]` samples.\n - If `max_samples` is equal to `1.0` or `X.shape[0]`, all samples\n will be used.\n\n While using this option may provide less accurate importance estimates,\n it keeps the method tractable when evaluating feature importance on\n large datasets. In combination with `n_repeats`, this allows to control\n the computational speed vs statistical accuracy trade-off of this method.\n\n .. versionadded:: 1.0\n\n Returns\n -------\n result : :class:`~sklearn.utils.Bunch` or dict of such instances\n Dictionary-like object, with the following attributes.\n\n importances_mean : ndarray of shape (n_features, )\n Mean of feature importance over `n_repeats`.\n importances_std : ndarray of shape (n_features, )\n Standard deviation over `n_repeats`.\n importances : ndarray of shape (n_features, n_repeats)\n Raw permutation importance scores.\n\n If there are multiple scoring metrics in the scoring parameter\n `result` is a dict with scorer names as keys (e.g. 'roc_auc') and\n `Bunch` objects like above as values.\n\n References\n ----------\n .. [BRE] L. Breiman, \"Random Forests\", Machine Learning, 45(1), 5-32,\n 2001. https://doi.org/10.1023/A:1010933404324\n\n Examples\n --------\n >>> from sklearn.linear_model import LogisticRegression\n >>> from sklearn.inspection import permutation_importance\n >>> X = [[1, 9, 9],[1, 9, 9],[1, 9, 9],\n ... [0, 9, 9],[0, 9, 9],[0, 9, 9]]\n >>> y = [1, 1, 1, 0, 0, 0]\n >>> clf = LogisticRegression().fit(X, y)\n >>> result = permutation_importance(clf, X, y, n_repeats=10,\n ... random_state=0)\n >>> result.importances_mean\n array([0.4666..., 0. , 0. ])\n >>> result.importances_std\n array([0.2211..., 0. , 0. ])\n \"\"\"\n if not hasattr(X, 'iloc'):\n X = check_array(X, force_all_finite='allow-nan', dtype=None)\n random_state = check_random_state(random_state)\n random_seed = random_state.randint(np.iinfo(np.int32).max + 1)\n if not isinstance(max_samples, numbers.Integral):\n max_samples = int(max_samples * X.shape[0])\n elif not 0 < max_samples <= X.shape[0]:\n raise ValueError('max_samples must be in (0, n_samples]')\n if callable(scoring):\n scorer = scoring\n elif scoring is None or isinstance(scoring, str):\n scorer = check_scoring(estimator, scoring=scoring)\n else:\n scorers_dict = _check_multimetric_scoring(estimator, scoring)\n scorer = _MultimetricScorer(**scorers_dict)\n baseline_score = _weights_scorer(scorer, estimator, X, y, sample_weight)\n scores = Parallel(n_jobs=n_jobs)((delayed(_calculate_permutation_scores)(estimator, X, y, sample_weight, col_idx, random_seed, n_repeats, scorer, max_samples) for col_idx in range(X.shape[1])))\n if isinstance(baseline_score, dict):\n return {name: _create_importances_bunch(baseline_score[name], np.array([scores[col_idx][name] for col_idx in range(X.shape[1])])) for name in baseline_score}\n else:\n return _create_importances_bunch(baseline_score, np.array(scores))" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.inspection._plot.partial_dependence.PartialDependenceDisplay.__init__", + "unique_qname": "sklearn.inspection._plot.partial_dependence.PartialDependenceDisplay.__init__", "decorators": [], "parameters": [ { @@ -89272,7 +92194,9 @@ }, { "name": "_get_sample_count", + "unique_name": "_get_sample_count", "qname": "sklearn.inspection._plot.partial_dependence.PartialDependenceDisplay._get_sample_count", + "unique_qname": "sklearn.inspection._plot.partial_dependence.PartialDependenceDisplay._get_sample_count", "decorators": [], "parameters": [ { @@ -89304,7 +92228,9 @@ }, { "name": "_plot_average_dependence", + "unique_name": "_plot_average_dependence", "qname": "sklearn.inspection._plot.partial_dependence.PartialDependenceDisplay._plot_average_dependence", + "unique_qname": "sklearn.inspection._plot.partial_dependence.PartialDependenceDisplay._plot_average_dependence", "decorators": [], "parameters": [ { @@ -89376,7 +92302,9 @@ }, { "name": "_plot_ice_lines", + "unique_name": "_plot_ice_lines", "qname": "sklearn.inspection._plot.partial_dependence.PartialDependenceDisplay._plot_ice_lines", + "unique_qname": "sklearn.inspection._plot.partial_dependence.PartialDependenceDisplay._plot_ice_lines", "decorators": [], "parameters": [ { @@ -89468,7 +92396,9 @@ }, { "name": "_plot_one_way_partial_dependence", + "unique_name": "_plot_one_way_partial_dependence", "qname": "sklearn.inspection._plot.partial_dependence.PartialDependenceDisplay._plot_one_way_partial_dependence", + "unique_qname": "sklearn.inspection._plot.partial_dependence.PartialDependenceDisplay._plot_one_way_partial_dependence", "decorators": [], "parameters": [ { @@ -89600,7 +92530,9 @@ }, { "name": "_plot_two_way_partial_dependence", + "unique_name": "_plot_two_way_partial_dependence", "qname": "sklearn.inspection._plot.partial_dependence.PartialDependenceDisplay._plot_two_way_partial_dependence", + "unique_qname": "sklearn.inspection._plot.partial_dependence.PartialDependenceDisplay._plot_two_way_partial_dependence", "decorators": [], "parameters": [ { @@ -89692,7 +92624,9 @@ }, { "name": "from_estimator", + "unique_name": "from_estimator", "qname": "sklearn.inspection._plot.partial_dependence.PartialDependenceDisplay.from_estimator", + "unique_qname": "sklearn.inspection._plot.partial_dependence.PartialDependenceDisplay.from_estimator", "decorators": ["classmethod"], "parameters": [ { @@ -89914,7 +92848,9 @@ }, { "name": "plot", + "unique_name": "plot", "qname": "sklearn.inspection._plot.partial_dependence.PartialDependenceDisplay.plot", + "unique_qname": "sklearn.inspection._plot.partial_dependence.PartialDependenceDisplay.plot", "decorators": ["_deprecate_positional_args(version='1.1')"], "parameters": [ { @@ -89996,7 +92932,9 @@ }, { "name": "_plot_partial_dependence", + "unique_name": "_plot_partial_dependence", "qname": "sklearn.inspection._plot.partial_dependence._plot_partial_dependence", + "unique_qname": "sklearn.inspection._plot.partial_dependence._plot_partial_dependence", "decorators": [], "parameters": [ { @@ -90208,7 +93146,9 @@ }, { "name": "plot_partial_dependence", + "unique_name": "plot_partial_dependence", "qname": "sklearn.inspection._plot.partial_dependence.plot_partial_dependence", + "unique_qname": "sklearn.inspection._plot.partial_dependence.plot_partial_dependence", "decorators": [ "deprecated('Function `plot_partial_dependence` is deprecated in 1.0 and will be removed in 1.2. Use PartialDependenceDisplay.from_estimator instead')" ], @@ -90422,7 +93362,9 @@ }, { "name": "configuration", + "unique_name": "configuration", "qname": "sklearn.inspection.setup.configuration", + "unique_qname": "sklearn.inspection.setup.configuration", "decorators": [], "parameters": [ { @@ -90454,7 +93396,9 @@ }, { "name": "__getstate__", + "unique_name": "__getstate__", "qname": "sklearn.isotonic.IsotonicRegression.__getstate__", + "unique_qname": "sklearn.isotonic.IsotonicRegression.__getstate__", "decorators": [], "parameters": [ { @@ -90476,7 +93420,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.isotonic.IsotonicRegression.__init__", + "unique_qname": "sklearn.isotonic.IsotonicRegression.__init__", "decorators": [], "parameters": [ { @@ -90538,7 +93484,9 @@ }, { "name": "__setstate__", + "unique_name": "__setstate__", "qname": "sklearn.isotonic.IsotonicRegression.__setstate__", + "unique_qname": "sklearn.isotonic.IsotonicRegression.__setstate__", "decorators": [], "parameters": [ { @@ -90570,7 +93518,9 @@ }, { "name": "_build_f", + "unique_name": "_build_f", "qname": "sklearn.isotonic.IsotonicRegression._build_f", + "unique_qname": "sklearn.isotonic.IsotonicRegression._build_f", "decorators": [], "parameters": [ { @@ -90612,7 +93562,9 @@ }, { "name": "_build_y", + "unique_name": "_build_y", "qname": "sklearn.isotonic.IsotonicRegression._build_y", + "unique_qname": "sklearn.isotonic.IsotonicRegression._build_y", "decorators": [], "parameters": [ { @@ -90674,7 +93626,9 @@ }, { "name": "_check_input_data_shape", + "unique_name": "_check_input_data_shape", "qname": "sklearn.isotonic.IsotonicRegression._check_input_data_shape", + "unique_qname": "sklearn.isotonic.IsotonicRegression._check_input_data_shape", "decorators": [], "parameters": [ { @@ -90706,7 +93660,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.isotonic.IsotonicRegression._more_tags", + "unique_qname": "sklearn.isotonic.IsotonicRegression._more_tags", "decorators": [], "parameters": [ { @@ -90728,7 +93684,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.isotonic.IsotonicRegression.fit", + "unique_qname": "sklearn.isotonic.IsotonicRegression.fit", "decorators": [], "parameters": [ { @@ -90780,7 +93738,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.isotonic.IsotonicRegression.predict", + "unique_qname": "sklearn.isotonic.IsotonicRegression.predict", "decorators": [], "parameters": [ { @@ -90812,7 +93772,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.isotonic.IsotonicRegression.transform", + "unique_qname": "sklearn.isotonic.IsotonicRegression.transform", "decorators": [], "parameters": [ { @@ -90844,7 +93806,9 @@ }, { "name": "check_increasing", + "unique_name": "check_increasing", "qname": "sklearn.isotonic.check_increasing", + "unique_qname": "sklearn.isotonic.check_increasing", "decorators": [], "parameters": [ { @@ -90876,7 +93840,9 @@ }, { "name": "isotonic_regression", + "unique_name": "isotonic_regression", "qname": "sklearn.isotonic.isotonic_regression", + "unique_qname": "sklearn.isotonic.isotonic_regression", "decorators": [], "parameters": [ { @@ -90938,7 +93904,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.kernel_approximation.AdditiveChi2Sampler.__init__", + "unique_qname": "sklearn.kernel_approximation.AdditiveChi2Sampler.__init__", "decorators": [], "parameters": [ { @@ -90980,7 +93948,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.kernel_approximation.AdditiveChi2Sampler._more_tags", + "unique_qname": "sklearn.kernel_approximation.AdditiveChi2Sampler._more_tags", "decorators": [], "parameters": [ { @@ -91002,7 +93972,9 @@ }, { "name": "_transform_dense", + "unique_name": "_transform_dense", "qname": "sklearn.kernel_approximation.AdditiveChi2Sampler._transform_dense", + "unique_qname": "sklearn.kernel_approximation.AdditiveChi2Sampler._transform_dense", "decorators": [], "parameters": [ { @@ -91034,7 +94006,9 @@ }, { "name": "_transform_sparse", + "unique_name": "_transform_sparse", "qname": "sklearn.kernel_approximation.AdditiveChi2Sampler._transform_sparse", + "unique_qname": "sklearn.kernel_approximation.AdditiveChi2Sampler._transform_sparse", "decorators": [], "parameters": [ { @@ -91066,7 +94040,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.kernel_approximation.AdditiveChi2Sampler.fit", + "unique_qname": "sklearn.kernel_approximation.AdditiveChi2Sampler.fit", "decorators": [], "parameters": [ { @@ -91108,7 +94084,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.kernel_approximation.AdditiveChi2Sampler.transform", + "unique_qname": "sklearn.kernel_approximation.AdditiveChi2Sampler.transform", "decorators": [], "parameters": [ { @@ -91140,7 +94118,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.kernel_approximation.Nystroem.__init__", + "unique_qname": "sklearn.kernel_approximation.Nystroem.__init__", "decorators": [], "parameters": [ { @@ -91242,7 +94222,9 @@ }, { "name": "_get_kernel_params", + "unique_name": "_get_kernel_params", "qname": "sklearn.kernel_approximation.Nystroem._get_kernel_params", + "unique_qname": "sklearn.kernel_approximation.Nystroem._get_kernel_params", "decorators": [], "parameters": [ { @@ -91264,7 +94246,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.kernel_approximation.Nystroem._more_tags", + "unique_qname": "sklearn.kernel_approximation.Nystroem._more_tags", "decorators": [], "parameters": [ { @@ -91286,7 +94270,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.kernel_approximation.Nystroem.fit", + "unique_qname": "sklearn.kernel_approximation.Nystroem.fit", "decorators": [], "parameters": [ { @@ -91328,7 +94314,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.kernel_approximation.Nystroem.transform", + "unique_qname": "sklearn.kernel_approximation.Nystroem.transform", "decorators": [], "parameters": [ { @@ -91360,7 +94348,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.kernel_approximation.PolynomialCountSketch.__init__", + "unique_qname": "sklearn.kernel_approximation.PolynomialCountSketch.__init__", "decorators": [], "parameters": [ { @@ -91432,7 +94422,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.kernel_approximation.PolynomialCountSketch.fit", + "unique_qname": "sklearn.kernel_approximation.PolynomialCountSketch.fit", "decorators": [], "parameters": [ { @@ -91474,7 +94466,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.kernel_approximation.PolynomialCountSketch.transform", + "unique_qname": "sklearn.kernel_approximation.PolynomialCountSketch.transform", "decorators": [], "parameters": [ { @@ -91506,7 +94500,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.kernel_approximation.RBFSampler.__init__", + "unique_qname": "sklearn.kernel_approximation.RBFSampler.__init__", "decorators": [], "parameters": [ { @@ -91558,7 +94554,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.kernel_approximation.RBFSampler.fit", + "unique_qname": "sklearn.kernel_approximation.RBFSampler.fit", "decorators": [], "parameters": [ { @@ -91600,7 +94598,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.kernel_approximation.RBFSampler.transform", + "unique_qname": "sklearn.kernel_approximation.RBFSampler.transform", "decorators": [], "parameters": [ { @@ -91632,7 +94632,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.kernel_approximation.SkewedChi2Sampler.__init__", + "unique_qname": "sklearn.kernel_approximation.SkewedChi2Sampler.__init__", "decorators": [], "parameters": [ { @@ -91684,7 +94686,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.kernel_approximation.SkewedChi2Sampler.fit", + "unique_qname": "sklearn.kernel_approximation.SkewedChi2Sampler.fit", "decorators": [], "parameters": [ { @@ -91726,7 +94730,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.kernel_approximation.SkewedChi2Sampler.transform", + "unique_qname": "sklearn.kernel_approximation.SkewedChi2Sampler.transform", "decorators": [], "parameters": [ { @@ -91758,7 +94764,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.kernel_ridge.KernelRidge.__init__", + "unique_qname": "sklearn.kernel_ridge.KernelRidge.__init__", "decorators": [], "parameters": [ { @@ -91840,7 +94848,9 @@ }, { "name": "_get_kernel", + "unique_name": "_get_kernel", "qname": "sklearn.kernel_ridge.KernelRidge._get_kernel", + "unique_qname": "sklearn.kernel_ridge.KernelRidge._get_kernel", "decorators": [], "parameters": [ { @@ -91882,7 +94892,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.kernel_ridge.KernelRidge._more_tags", + "unique_qname": "sklearn.kernel_ridge.KernelRidge._more_tags", "decorators": [], "parameters": [ { @@ -91904,7 +94916,9 @@ }, { "name": "_pairwise", + "unique_name": "_pairwise@getter", "qname": "sklearn.kernel_ridge.KernelRidge._pairwise", + "unique_qname": "sklearn.kernel_ridge.KernelRidge._pairwise@getter", "decorators": [ "deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -91929,7 +94943,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.kernel_ridge.KernelRidge.fit", + "unique_qname": "sklearn.kernel_ridge.KernelRidge.fit", "decorators": [], "parameters": [ { @@ -91981,7 +94997,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.kernel_ridge.KernelRidge.predict", + "unique_qname": "sklearn.kernel_ridge.KernelRidge.predict", "decorators": [], "parameters": [ { @@ -92013,7 +95031,9 @@ }, { "name": "_predict_proba_lr", + "unique_name": "_predict_proba_lr", "qname": "sklearn.linear_model._base.LinearClassifierMixin._predict_proba_lr", + "unique_qname": "sklearn.linear_model._base.LinearClassifierMixin._predict_proba_lr", "decorators": [], "parameters": [ { @@ -92045,7 +95065,9 @@ }, { "name": "decision_function", + "unique_name": "decision_function", "qname": "sklearn.linear_model._base.LinearClassifierMixin.decision_function", + "unique_qname": "sklearn.linear_model._base.LinearClassifierMixin.decision_function", "decorators": [], "parameters": [ { @@ -92077,7 +95099,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.linear_model._base.LinearClassifierMixin.predict", + "unique_qname": "sklearn.linear_model._base.LinearClassifierMixin.predict", "decorators": [], "parameters": [ { @@ -92109,7 +95133,9 @@ }, { "name": "_decision_function", + "unique_name": "_decision_function", "qname": "sklearn.linear_model._base.LinearModel._decision_function", + "unique_qname": "sklearn.linear_model._base.LinearModel._decision_function", "decorators": [], "parameters": [ { @@ -92141,7 +95167,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.linear_model._base.LinearModel._more_tags", + "unique_qname": "sklearn.linear_model._base.LinearModel._more_tags", "decorators": [], "parameters": [ { @@ -92163,7 +95191,9 @@ }, { "name": "_set_intercept", + "unique_name": "_set_intercept", "qname": "sklearn.linear_model._base.LinearModel._set_intercept", + "unique_qname": "sklearn.linear_model._base.LinearModel._set_intercept", "decorators": [], "parameters": [ { @@ -92215,7 +95245,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._base.LinearModel.fit", + "unique_qname": "sklearn.linear_model._base.LinearModel.fit", "decorators": ["abstractmethod"], "parameters": [ { @@ -92257,7 +95289,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.linear_model._base.LinearModel.predict", + "unique_qname": "sklearn.linear_model._base.LinearModel.predict", "decorators": [], "parameters": [ { @@ -92289,7 +95323,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._base.LinearRegression.__init__", + "unique_qname": "sklearn.linear_model._base.LinearRegression.__init__", "decorators": [], "parameters": [ { @@ -92339,7 +95375,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int, default=None", - "description": "The number of jobs to use for the computation. This will only provide\nspeedup for n_targets > 1 and sufficient large problems.\n``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n``-1`` means using all processors. See :term:`Glossary `\nfor more details." + "description": "The number of jobs to use for the computation. This will only provide\nspeedup in case of sufficiently large problems, that is if firstly\n`n_targets > 1` and secondly `X` is sparse or if `positive` is set\nto `True`. ``None`` means 1 unless in a\n:obj:`joblib.parallel_backend` context. ``-1`` means using all\nprocessors. See :term:`Glossary ` for more details." } }, { @@ -92361,7 +95397,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._base.LinearRegression.fit", + "unique_qname": "sklearn.linear_model._base.LinearRegression.fit", "decorators": [], "parameters": [ { @@ -92413,7 +95451,9 @@ }, { "name": "densify", + "unique_name": "densify", "qname": "sklearn.linear_model._base.SparseCoefMixin.densify", + "unique_qname": "sklearn.linear_model._base.SparseCoefMixin.densify", "decorators": [], "parameters": [ { @@ -92435,7 +95475,9 @@ }, { "name": "sparsify", + "unique_name": "sparsify", "qname": "sklearn.linear_model._base.SparseCoefMixin.sparsify", + "unique_qname": "sklearn.linear_model._base.SparseCoefMixin.sparsify", "decorators": [], "parameters": [ { @@ -92457,7 +95499,9 @@ }, { "name": "_check_precomputed_gram_matrix", + "unique_name": "_check_precomputed_gram_matrix", "qname": "sklearn.linear_model._base._check_precomputed_gram_matrix", + "unique_qname": "sklearn.linear_model._base._check_precomputed_gram_matrix", "decorators": [], "parameters": [ { @@ -92529,7 +95573,9 @@ }, { "name": "_deprecate_normalize", + "unique_name": "_deprecate_normalize", "qname": "sklearn.linear_model._base._deprecate_normalize", + "unique_qname": "sklearn.linear_model._base._deprecate_normalize", "decorators": [], "parameters": [ { @@ -92558,7 +95604,7 @@ "is_public": false, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "string,", + "type": "str", "description": "name of the linear estimator which calls this function.\nThe name will be used for writing the deprecation warnings" } } @@ -92566,12 +95612,14 @@ "results": [], "is_public": false, "description": "Normalize is to be deprecated from linear models and a use of a pipeline with a StandardScaler is to be recommended instead. Here the appropriate message is selected to be displayed to the user depending on the default normalize value (as it varies between the linear models and normalize value selected by the user).", - "docstring": "Normalize is to be deprecated from linear models and a use of\na pipeline with a StandardScaler is to be recommended instead.\nHere the appropriate message is selected to be displayed to the user\ndepending on the default normalize value (as it varies between the linear\nmodels and normalize value selected by the user).\n\nParameters\n----------\nnormalize : bool,\n normalize value passed by the user\n\ndefault : bool,\n default normalize value used by the estimator\n\nestimator_name : string,\n name of the linear estimator which calls this function.\n The name will be used for writing the deprecation warnings\n\nReturns\n-------\nnormalize : bool,\n normalize value which should further be used by the estimator at this\n stage of the depreciation process\n\nNotes\n-----\nThis function should be updated in 1.2 depending on the value of\n`normalize`:\n- True, warning: `normalize` was deprecated in 1.2 and will be removed in\n 1.4. Suggest to use pipeline instead.\n- False, `normalize` was deprecated in 1.2 and it will be removed in 1.4.\n Leave normalize to its default value.\n- `deprecated` - this should only be possible with default == False as from\n 1.2 `normalize` in all the linear models should be either removed or the\n default should be set to False.\nThis function should be completely removed in 1.4.", - "source_code": "\ndef _deprecate_normalize(normalize, default, estimator_name):\n \"\"\"Normalize is to be deprecated from linear models and a use of\n a pipeline with a StandardScaler is to be recommended instead.\n Here the appropriate message is selected to be displayed to the user\n depending on the default normalize value (as it varies between the linear\n models and normalize value selected by the user).\n\n Parameters\n ----------\n normalize : bool,\n normalize value passed by the user\n\n default : bool,\n default normalize value used by the estimator\n\n estimator_name : string,\n name of the linear estimator which calls this function.\n The name will be used for writing the deprecation warnings\n\n Returns\n -------\n normalize : bool,\n normalize value which should further be used by the estimator at this\n stage of the depreciation process\n\n Notes\n -----\n This function should be updated in 1.2 depending on the value of\n `normalize`:\n - True, warning: `normalize` was deprecated in 1.2 and will be removed in\n 1.4. Suggest to use pipeline instead.\n - False, `normalize` was deprecated in 1.2 and it will be removed in 1.4.\n Leave normalize to its default value.\n - `deprecated` - this should only be possible with default == False as from\n 1.2 `normalize` in all the linear models should be either removed or the\n default should be set to False.\n This function should be completely removed in 1.4.\n \"\"\"\n if normalize not in [True, False, 'deprecated']:\n raise ValueError(\"Leave 'normalize' to its default value or set it to True or False\")\n if normalize == 'deprecated':\n _normalize = default\n else:\n _normalize = normalize\n pipeline_msg = f\"If you wish to scale the data, use Pipeline with a StandardScaler in a preprocessing stage. To reproduce the previous behavior:\\n\\nfrom sklearn.pipeline import make_pipeline\\n\\nmodel = make_pipeline(StandardScaler(with_mean=False), {estimator_name}())\\n\\nIf you wish to pass a sample_weight parameter, you need to pass it as a fit parameter to each step of the pipeline as follows:\\n\\nkwargs = {{s[0] + '__sample_weight': sample_weight for s in model.steps}}\\nmodel.fit(X, y, **kwargs)\\n\\n\"\n if estimator_name == 'Ridge' or estimator_name == 'RidgeClassifier':\n alpha_msg = 'Set parameter alpha to: original_alpha * n_samples. '\n elif 'Lasso' in estimator_name:\n alpha_msg = 'Set parameter alpha to: original_alpha * np.sqrt(n_samples). '\n elif 'ElasticNet' in estimator_name:\n alpha_msg = 'Set parameter alpha to original_alpha * np.sqrt(n_samples) if l1_ratio is 1, and to original_alpha * n_samples if l1_ratio is 0. For other values of l1_ratio, no analytic formula is available.'\n elif estimator_name == 'RidgeCV' or estimator_name == 'RidgeClassifierCV':\n alpha_msg = 'Set parameter alphas to: original_alphas * n_samples. '\n else:\n alpha_msg = ''\n if default and normalize == 'deprecated':\n warnings.warn(\"The default of 'normalize' will be set to False in version 1.2 and deprecated in version 1.4.\\n\" + pipeline_msg + alpha_msg, FutureWarning)\n elif normalize != 'deprecated' and normalize and not default:\n warnings.warn(\"'normalize' was deprecated in version 1.0 and will be removed in 1.2.\\n\" + pipeline_msg + alpha_msg, FutureWarning)\n elif not normalize and not default:\n warnings.warn(\"'normalize' was deprecated in version 1.0 and will be removed in 1.2. Please leave the normalize parameter to its default value to silence this warning. The default behavior of this estimator is to not do any normalization. If normalization is needed please use sklearn.preprocessing.StandardScaler instead.\", FutureWarning)\n return _normalize" + "docstring": "Normalize is to be deprecated from linear models and a use of\na pipeline with a StandardScaler is to be recommended instead.\nHere the appropriate message is selected to be displayed to the user\ndepending on the default normalize value (as it varies between the linear\nmodels and normalize value selected by the user).\n\nParameters\n----------\nnormalize : bool,\n normalize value passed by the user\n\ndefault : bool,\n default normalize value used by the estimator\n\nestimator_name : str\n name of the linear estimator which calls this function.\n The name will be used for writing the deprecation warnings\n\nReturns\n-------\nnormalize : bool,\n normalize value which should further be used by the estimator at this\n stage of the depreciation process\n\nNotes\n-----\nThis function should be updated in 1.2 depending on the value of\n`normalize`:\n- True, warning: `normalize` was deprecated in 1.2 and will be removed in\n 1.4. Suggest to use pipeline instead.\n- False, `normalize` was deprecated in 1.2 and it will be removed in 1.4.\n Leave normalize to its default value.\n- `deprecated` - this should only be possible with default == False as from\n 1.2 `normalize` in all the linear models should be either removed or the\n default should be set to False.\nThis function should be completely removed in 1.4.", + "source_code": "\ndef _deprecate_normalize(normalize, default, estimator_name):\n \"\"\"Normalize is to be deprecated from linear models and a use of\n a pipeline with a StandardScaler is to be recommended instead.\n Here the appropriate message is selected to be displayed to the user\n depending on the default normalize value (as it varies between the linear\n models and normalize value selected by the user).\n\n Parameters\n ----------\n normalize : bool,\n normalize value passed by the user\n\n default : bool,\n default normalize value used by the estimator\n\n estimator_name : str\n name of the linear estimator which calls this function.\n The name will be used for writing the deprecation warnings\n\n Returns\n -------\n normalize : bool,\n normalize value which should further be used by the estimator at this\n stage of the depreciation process\n\n Notes\n -----\n This function should be updated in 1.2 depending on the value of\n `normalize`:\n - True, warning: `normalize` was deprecated in 1.2 and will be removed in\n 1.4. Suggest to use pipeline instead.\n - False, `normalize` was deprecated in 1.2 and it will be removed in 1.4.\n Leave normalize to its default value.\n - `deprecated` - this should only be possible with default == False as from\n 1.2 `normalize` in all the linear models should be either removed or the\n default should be set to False.\n This function should be completely removed in 1.4.\n \"\"\"\n if normalize not in [True, False, 'deprecated']:\n raise ValueError(\"Leave 'normalize' to its default value or set it to True or False\")\n if normalize == 'deprecated':\n _normalize = default\n else:\n _normalize = normalize\n pipeline_msg = f\"If you wish to scale the data, use Pipeline with a StandardScaler in a preprocessing stage. To reproduce the previous behavior:\\n\\nfrom sklearn.pipeline import make_pipeline\\n\\nmodel = make_pipeline(StandardScaler(with_mean=False), {estimator_name}())\\n\\nIf you wish to pass a sample_weight parameter, you need to pass it as a fit parameter to each step of the pipeline as follows:\\n\\nkwargs = {{s[0] + '__sample_weight': sample_weight for s in model.steps}}\\nmodel.fit(X, y, **kwargs)\\n\\n\"\n if estimator_name == 'Ridge' or estimator_name == 'RidgeClassifier':\n alpha_msg = 'Set parameter alpha to: original_alpha * n_samples. '\n elif 'Lasso' in estimator_name:\n alpha_msg = 'Set parameter alpha to: original_alpha * np.sqrt(n_samples). '\n elif 'ElasticNet' in estimator_name:\n alpha_msg = 'Set parameter alpha to original_alpha * np.sqrt(n_samples) if l1_ratio is 1, and to original_alpha * n_samples if l1_ratio is 0. For other values of l1_ratio, no analytic formula is available.'\n elif estimator_name == 'RidgeCV' or estimator_name == 'RidgeClassifierCV':\n alpha_msg = 'Set parameter alphas to: original_alphas * n_samples. '\n else:\n alpha_msg = ''\n if default and normalize == 'deprecated':\n warnings.warn(\"The default of 'normalize' will be set to False in version 1.2 and deprecated in version 1.4.\\n\" + pipeline_msg + alpha_msg, FutureWarning)\n elif normalize != 'deprecated' and normalize and not default:\n warnings.warn(\"'normalize' was deprecated in version 1.0 and will be removed in 1.2.\\n\" + pipeline_msg + alpha_msg, FutureWarning)\n elif not normalize and not default:\n warnings.warn(\"'normalize' was deprecated in version 1.0 and will be removed in 1.2. Please leave the normalize parameter to its default value to silence this warning. The default behavior of this estimator is to not do any normalization. If normalization is needed please use sklearn.preprocessing.StandardScaler instead.\", FutureWarning)\n return _normalize" }, { "name": "_pre_fit", + "unique_name": "_pre_fit", "qname": "sklearn.linear_model._base._pre_fit", + "unique_qname": "sklearn.linear_model._base._pre_fit", "decorators": [], "parameters": [ { @@ -92673,7 +95721,9 @@ }, { "name": "_preprocess_data", + "unique_name": "_preprocess_data", "qname": "sklearn.linear_model._base._preprocess_data", + "unique_qname": "sklearn.linear_model._base._preprocess_data", "decorators": [], "parameters": [ { @@ -92765,7 +95815,9 @@ }, { "name": "_rescale_data", + "unique_name": "_rescale_data", "qname": "sklearn.linear_model._base._rescale_data", + "unique_qname": "sklearn.linear_model._base._rescale_data", "decorators": [], "parameters": [ { @@ -92807,7 +95859,9 @@ }, { "name": "make_dataset", + "unique_name": "make_dataset", "qname": "sklearn.linear_model._base.make_dataset", + "unique_qname": "sklearn.linear_model._base.make_dataset", "decorators": [], "parameters": [ { @@ -92859,7 +95913,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._bayes.ARDRegression.__init__", + "unique_qname": "sklearn.linear_model._bayes.ARDRegression.__init__", "decorators": [], "parameters": [ { @@ -93001,7 +96057,9 @@ }, { "name": "_update_sigma", + "unique_name": "_update_sigma", "qname": "sklearn.linear_model._bayes.ARDRegression._update_sigma", + "unique_qname": "sklearn.linear_model._bayes.ARDRegression._update_sigma", "decorators": [], "parameters": [ { @@ -93063,7 +96121,9 @@ }, { "name": "_update_sigma_woodbury", + "unique_name": "_update_sigma_woodbury", "qname": "sklearn.linear_model._bayes.ARDRegression._update_sigma_woodbury", + "unique_qname": "sklearn.linear_model._bayes.ARDRegression._update_sigma_woodbury", "decorators": [], "parameters": [ { @@ -93125,7 +96185,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._bayes.ARDRegression.fit", + "unique_qname": "sklearn.linear_model._bayes.ARDRegression.fit", "decorators": [], "parameters": [ { @@ -93167,7 +96229,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.linear_model._bayes.ARDRegression.predict", + "unique_qname": "sklearn.linear_model._bayes.ARDRegression.predict", "decorators": [], "parameters": [ { @@ -93209,7 +96273,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._bayes.BayesianRidge.__init__", + "unique_qname": "sklearn.linear_model._bayes.BayesianRidge.__init__", "decorators": [], "parameters": [ { @@ -93361,7 +96427,9 @@ }, { "name": "_log_marginal_likelihood", + "unique_name": "_log_marginal_likelihood", "qname": "sklearn.linear_model._bayes.BayesianRidge._log_marginal_likelihood", + "unique_qname": "sklearn.linear_model._bayes.BayesianRidge._log_marginal_likelihood", "decorators": [], "parameters": [ { @@ -93453,7 +96521,9 @@ }, { "name": "_update_coef_", + "unique_name": "_update_coef_", "qname": "sklearn.linear_model._bayes.BayesianRidge._update_coef_", + "unique_qname": "sklearn.linear_model._bayes.BayesianRidge._update_coef_", "decorators": [], "parameters": [ { @@ -93575,7 +96645,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._bayes.BayesianRidge.fit", + "unique_qname": "sklearn.linear_model._bayes.BayesianRidge.fit", "decorators": [], "parameters": [ { @@ -93627,7 +96699,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.linear_model._bayes.BayesianRidge.predict", + "unique_qname": "sklearn.linear_model._bayes.BayesianRidge.predict", "decorators": [], "parameters": [ { @@ -93669,7 +96743,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._coordinate_descent.ElasticNet.__init__", + "unique_qname": "sklearn.linear_model._coordinate_descent.ElasticNet.__init__", "decorators": [], "parameters": [ { @@ -93811,7 +96887,9 @@ }, { "name": "_decision_function", + "unique_name": "_decision_function", "qname": "sklearn.linear_model._coordinate_descent.ElasticNet._decision_function", + "unique_qname": "sklearn.linear_model._coordinate_descent.ElasticNet._decision_function", "decorators": [], "parameters": [ { @@ -93843,7 +96921,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._coordinate_descent.ElasticNet.fit", + "unique_qname": "sklearn.linear_model._coordinate_descent.ElasticNet.fit", "decorators": [], "parameters": [ { @@ -93905,7 +96985,9 @@ }, { "name": "sparse_coef_", + "unique_name": "sparse_coef_@getter", "qname": "sklearn.linear_model._coordinate_descent.ElasticNet.sparse_coef_", + "unique_qname": "sklearn.linear_model._coordinate_descent.ElasticNet.sparse_coef_@getter", "decorators": ["property"], "parameters": [ { @@ -93927,7 +97009,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._coordinate_descent.ElasticNetCV.__init__", + "unique_qname": "sklearn.linear_model._coordinate_descent.ElasticNetCV.__init__", "decorators": [], "parameters": [ { @@ -94109,7 +97193,9 @@ }, { "name": "_get_estimator", + "unique_name": "_get_estimator", "qname": "sklearn.linear_model._coordinate_descent.ElasticNetCV._get_estimator", + "unique_qname": "sklearn.linear_model._coordinate_descent.ElasticNetCV._get_estimator", "decorators": [], "parameters": [ { @@ -94131,7 +97217,9 @@ }, { "name": "_is_multitask", + "unique_name": "_is_multitask", "qname": "sklearn.linear_model._coordinate_descent.ElasticNetCV._is_multitask", + "unique_qname": "sklearn.linear_model._coordinate_descent.ElasticNetCV._is_multitask", "decorators": [], "parameters": [ { @@ -94153,7 +97241,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.linear_model._coordinate_descent.ElasticNetCV._more_tags", + "unique_qname": "sklearn.linear_model._coordinate_descent.ElasticNetCV._more_tags", "decorators": [], "parameters": [ { @@ -94175,7 +97265,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._coordinate_descent.Lasso.__init__", + "unique_qname": "sklearn.linear_model._coordinate_descent.Lasso.__init__", "decorators": [], "parameters": [ { @@ -94307,7 +97399,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._coordinate_descent.LassoCV.__init__", + "unique_qname": "sklearn.linear_model._coordinate_descent.LassoCV.__init__", "decorators": [], "parameters": [ { @@ -94479,7 +97573,9 @@ }, { "name": "_get_estimator", + "unique_name": "_get_estimator", "qname": "sklearn.linear_model._coordinate_descent.LassoCV._get_estimator", + "unique_qname": "sklearn.linear_model._coordinate_descent.LassoCV._get_estimator", "decorators": [], "parameters": [ { @@ -94501,7 +97597,9 @@ }, { "name": "_is_multitask", + "unique_name": "_is_multitask", "qname": "sklearn.linear_model._coordinate_descent.LassoCV._is_multitask", + "unique_qname": "sklearn.linear_model._coordinate_descent.LassoCV._is_multitask", "decorators": [], "parameters": [ { @@ -94523,7 +97621,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.linear_model._coordinate_descent.LassoCV._more_tags", + "unique_qname": "sklearn.linear_model._coordinate_descent.LassoCV._more_tags", "decorators": [], "parameters": [ { @@ -94545,7 +97645,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._coordinate_descent.LinearModelCV.__init__", + "unique_qname": "sklearn.linear_model._coordinate_descent.LinearModelCV.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -94717,7 +97819,9 @@ }, { "name": "_get_estimator", + "unique_name": "_get_estimator", "qname": "sklearn.linear_model._coordinate_descent.LinearModelCV._get_estimator", + "unique_qname": "sklearn.linear_model._coordinate_descent.LinearModelCV._get_estimator", "decorators": ["abstractmethod"], "parameters": [ { @@ -94739,7 +97843,9 @@ }, { "name": "_is_multitask", + "unique_name": "_is_multitask", "qname": "sklearn.linear_model._coordinate_descent.LinearModelCV._is_multitask", + "unique_qname": "sklearn.linear_model._coordinate_descent.LinearModelCV._is_multitask", "decorators": ["abstractmethod"], "parameters": [ { @@ -94761,7 +97867,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.linear_model._coordinate_descent.LinearModelCV._more_tags", + "unique_qname": "sklearn.linear_model._coordinate_descent.LinearModelCV._more_tags", "decorators": [], "parameters": [ { @@ -94783,7 +97891,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._coordinate_descent.LinearModelCV.fit", + "unique_qname": "sklearn.linear_model._coordinate_descent.LinearModelCV.fit", "decorators": [], "parameters": [ { @@ -94835,7 +97945,9 @@ }, { "name": "path", + "unique_name": "path", "qname": "sklearn.linear_model._coordinate_descent.LinearModelCV.path", + "unique_qname": "sklearn.linear_model._coordinate_descent.LinearModelCV.path", "decorators": ["staticmethod", "abstractmethod"], "parameters": [ { @@ -94867,7 +97979,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._coordinate_descent.MultiTaskElasticNet.__init__", + "unique_qname": "sklearn.linear_model._coordinate_descent.MultiTaskElasticNet.__init__", "decorators": [], "parameters": [ { @@ -94989,7 +98103,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.linear_model._coordinate_descent.MultiTaskElasticNet._more_tags", + "unique_qname": "sklearn.linear_model._coordinate_descent.MultiTaskElasticNet._more_tags", "decorators": [], "parameters": [ { @@ -95011,7 +98127,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._coordinate_descent.MultiTaskElasticNet.fit", + "unique_qname": "sklearn.linear_model._coordinate_descent.MultiTaskElasticNet.fit", "decorators": [], "parameters": [ { @@ -95048,12 +98166,14 @@ "results": [], "is_public": true, "description": "Fit MultiTaskElasticNet model with coordinate descent.", - "docstring": "Fit MultiTaskElasticNet model with coordinate descent.\n\nParameters\n----------\nX : ndarray of shape (n_samples, n_features)\n Data.\ny : ndarray of shape (n_samples, n_targets)\n Target. Will be cast to X's dtype if necessary.\n\nReturns\n-------\nself : object\n\nNotes\n-----\nCoordinate descent is an algorithm that considers each column of\ndata at a time hence it will automatically convert the X input\nas a Fortran-contiguous numpy array if necessary.\n\nTo avoid memory re-allocation it is advised to allocate the\ninitial data in memory directly using that format.", - "source_code": "\ndef fit(self, X, y):\n \"\"\"Fit MultiTaskElasticNet model with coordinate descent.\n\n Parameters\n ----------\n X : ndarray of shape (n_samples, n_features)\n Data.\n y : ndarray of shape (n_samples, n_targets)\n Target. Will be cast to X's dtype if necessary.\n\n Returns\n -------\n self : object\n\n Notes\n -----\n Coordinate descent is an algorithm that considers each column of\n data at a time hence it will automatically convert the X input\n as a Fortran-contiguous numpy array if necessary.\n\n To avoid memory re-allocation it is advised to allocate the\n initial data in memory directly using that format.\n \"\"\"\n _normalize = _deprecate_normalize(self.normalize, default=False, estimator_name=self.__class__.__name__)\n check_X_params = dict(dtype=[np.float64, np.float32], order='F', copy=self.copy_X and self.fit_intercept)\n check_y_params = dict(ensure_2d=False, order='F')\n (X, y) = self._validate_data(X, y, validate_separately=(check_X_params, check_y_params))\n check_consistent_length(X, y)\n y = y.astype(X.dtype)\n if hasattr(self, 'l1_ratio'):\n model_str = 'ElasticNet'\n else:\n model_str = 'Lasso'\n if y.ndim == 1:\n raise ValueError('For mono-task outputs, use %s' % model_str)\n (n_samples, n_features) = X.shape\n n_targets = y.shape[1]\n (X, y, X_offset, y_offset, X_scale) = _preprocess_data(X, y, self.fit_intercept, _normalize, copy=False)\n if not self.warm_start or not hasattr(self, 'coef_'):\n self.coef_ = np.zeros((n_targets, n_features), dtype=X.dtype.type, order='F')\n l1_reg = self.alpha * self.l1_ratio * n_samples\n l2_reg = self.alpha * (1.0 - self.l1_ratio) * n_samples\n self.coef_ = np.asfortranarray(self.coef_)\n if self.selection not in ['random', 'cyclic']:\n raise ValueError('selection should be either random or cyclic.')\n random = self.selection == 'random'\n (self.coef_, self.dual_gap_, self.eps_, self.n_iter_) = cd_fast.enet_coordinate_descent_multi_task(self.coef_, l1_reg, l2_reg, X, y, self.max_iter, self.tol, check_random_state(self.random_state), random)\n self.dual_gap_ /= n_samples\n self._set_intercept(X_offset, y_offset, X_scale)\n return self" + "docstring": "Fit MultiTaskElasticNet model with coordinate descent.\n\nParameters\n----------\nX : ndarray of shape (n_samples, n_features)\n Data.\ny : ndarray of shape (n_samples, n_targets)\n Target. Will be cast to X's dtype if necessary.\n\nReturns\n-------\nself : object\n Fitted estimator.\n\nNotes\n-----\nCoordinate descent is an algorithm that considers each column of\ndata at a time hence it will automatically convert the X input\nas a Fortran-contiguous numpy array if necessary.\n\nTo avoid memory re-allocation it is advised to allocate the\ninitial data in memory directly using that format.", + "source_code": "\ndef fit(self, X, y):\n \"\"\"Fit MultiTaskElasticNet model with coordinate descent.\n\n Parameters\n ----------\n X : ndarray of shape (n_samples, n_features)\n Data.\n y : ndarray of shape (n_samples, n_targets)\n Target. Will be cast to X's dtype if necessary.\n\n Returns\n -------\n self : object\n Fitted estimator.\n\n Notes\n -----\n Coordinate descent is an algorithm that considers each column of\n data at a time hence it will automatically convert the X input\n as a Fortran-contiguous numpy array if necessary.\n\n To avoid memory re-allocation it is advised to allocate the\n initial data in memory directly using that format.\n \"\"\"\n _normalize = _deprecate_normalize(self.normalize, default=False, estimator_name=self.__class__.__name__)\n check_X_params = dict(dtype=[np.float64, np.float32], order='F', copy=self.copy_X and self.fit_intercept)\n check_y_params = dict(ensure_2d=False, order='F')\n (X, y) = self._validate_data(X, y, validate_separately=(check_X_params, check_y_params))\n check_consistent_length(X, y)\n y = y.astype(X.dtype)\n if hasattr(self, 'l1_ratio'):\n model_str = 'ElasticNet'\n else:\n model_str = 'Lasso'\n if y.ndim == 1:\n raise ValueError('For mono-task outputs, use %s' % model_str)\n (n_samples, n_features) = X.shape\n n_targets = y.shape[1]\n (X, y, X_offset, y_offset, X_scale) = _preprocess_data(X, y, self.fit_intercept, _normalize, copy=False)\n if not self.warm_start or not hasattr(self, 'coef_'):\n self.coef_ = np.zeros((n_targets, n_features), dtype=X.dtype.type, order='F')\n l1_reg = self.alpha * self.l1_ratio * n_samples\n l2_reg = self.alpha * (1.0 - self.l1_ratio) * n_samples\n self.coef_ = np.asfortranarray(self.coef_)\n if self.selection not in ['random', 'cyclic']:\n raise ValueError('selection should be either random or cyclic.')\n random = self.selection == 'random'\n (self.coef_, self.dual_gap_, self.eps_, self.n_iter_) = cd_fast.enet_coordinate_descent_multi_task(self.coef_, l1_reg, l2_reg, X, y, self.max_iter, self.tol, check_random_state(self.random_state), random)\n self.dual_gap_ /= n_samples\n self._set_intercept(X_offset, y_offset, X_scale)\n return self" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._coordinate_descent.MultiTaskElasticNetCV.__init__", + "unique_qname": "sklearn.linear_model._coordinate_descent.MultiTaskElasticNetCV.__init__", "decorators": [], "parameters": [ { @@ -95073,7 +98193,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "float or list of float, default=0.5", - "description": "The ElasticNet mixing parameter, with 0 < l1_ratio <= 1.\nFor l1_ratio = 1 the penalty is an L1/L2 penalty. For l1_ratio = 0 it\nis an L2 penalty.\nFor ``0 < l1_ratio < 1``, the penalty is a combination of L1/L2 and L2.\nThis parameter can be a list, in which case the different\nvalues are tested by cross-validation and the one giving the best\nprediction score is used. Note that a good choice of list of\nvalues for l1_ratio is often to put more values close to 1\n(i.e. Lasso) and less close to 0 (i.e. Ridge), as in ``[.1, .5, .7,\n.9, .95, .99, 1]``" + "description": "The ElasticNet mixing parameter, with 0 < l1_ratio <= 1.\nFor l1_ratio = 1 the penalty is an L1/L2 penalty. For l1_ratio = 0 it\nis an L2 penalty.\nFor ``0 < l1_ratio < 1``, the penalty is a combination of L1/L2 and L2.\nThis parameter can be a list, in which case the different\nvalues are tested by cross-validation and the one giving the best\nprediction score is used. Note that a good choice of list of\nvalues for l1_ratio is often to put more values close to 1\n(i.e. Lasso) and less close to 0 (i.e. Ridge), as in ``[.1, .5, .7,\n.9, .95, .99, 1]``." } }, { @@ -95215,7 +98335,9 @@ }, { "name": "_get_estimator", + "unique_name": "_get_estimator", "qname": "sklearn.linear_model._coordinate_descent.MultiTaskElasticNetCV._get_estimator", + "unique_qname": "sklearn.linear_model._coordinate_descent.MultiTaskElasticNetCV._get_estimator", "decorators": [], "parameters": [ { @@ -95237,7 +98359,9 @@ }, { "name": "_is_multitask", + "unique_name": "_is_multitask", "qname": "sklearn.linear_model._coordinate_descent.MultiTaskElasticNetCV._is_multitask", + "unique_qname": "sklearn.linear_model._coordinate_descent.MultiTaskElasticNetCV._is_multitask", "decorators": [], "parameters": [ { @@ -95259,7 +98383,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.linear_model._coordinate_descent.MultiTaskElasticNetCV._more_tags", + "unique_qname": "sklearn.linear_model._coordinate_descent.MultiTaskElasticNetCV._more_tags", "decorators": [], "parameters": [ { @@ -95281,7 +98407,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._coordinate_descent.MultiTaskElasticNetCV.fit", + "unique_qname": "sklearn.linear_model._coordinate_descent.MultiTaskElasticNetCV.fit", "decorators": [], "parameters": [ { @@ -95301,7 +98429,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "ndarray of shape (n_samples, n_features)", - "description": "Data" + "description": "Training data." } }, { @@ -95311,19 +98439,21 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "ndarray of shape (n_samples, n_targets)", - "description": "Target. Will be cast to X's dtype if necessary" + "description": "Training target variable. Will be cast to X's dtype if necessary." } } ], "results": [], "is_public": true, "description": "Fit MultiTaskElasticNet model with coordinate descent.\n\nFit is on grid of alphas and best alpha estimated by cross-validation.", - "docstring": "Fit MultiTaskElasticNet model with coordinate descent.\n\nFit is on grid of alphas and best alpha estimated by cross-validation.\n\nParameters\n----------\nX : ndarray of shape (n_samples, n_features)\n Data\ny : ndarray of shape (n_samples, n_targets)\n Target. Will be cast to X's dtype if necessary\n\nReturns\n-------\nself : object", - "source_code": "\ndef fit(self, X, y):\n \"\"\"Fit MultiTaskElasticNet model with coordinate descent.\n\n Fit is on grid of alphas and best alpha estimated by cross-validation.\n\n Parameters\n ----------\n X : ndarray of shape (n_samples, n_features)\n Data\n y : ndarray of shape (n_samples, n_targets)\n Target. Will be cast to X's dtype if necessary\n\n Returns\n -------\n self : object\n \"\"\"\n return super().fit(X, y)" + "docstring": "Fit MultiTaskElasticNet model with coordinate descent.\n\nFit is on grid of alphas and best alpha estimated by cross-validation.\n\nParameters\n----------\nX : ndarray of shape (n_samples, n_features)\n Training data.\ny : ndarray of shape (n_samples, n_targets)\n Training target variable. Will be cast to X's dtype if necessary.\n\nReturns\n-------\nself : object\n Returns MultiTaskElasticNet instance.", + "source_code": "\ndef fit(self, X, y):\n \"\"\"Fit MultiTaskElasticNet model with coordinate descent.\n\n Fit is on grid of alphas and best alpha estimated by cross-validation.\n\n Parameters\n ----------\n X : ndarray of shape (n_samples, n_features)\n Training data.\n y : ndarray of shape (n_samples, n_targets)\n Training target variable. Will be cast to X's dtype if necessary.\n\n Returns\n -------\n self : object\n Returns MultiTaskElasticNet instance.\n \"\"\"\n return super().fit(X, y)" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._coordinate_descent.MultiTaskLasso.__init__", + "unique_qname": "sklearn.linear_model._coordinate_descent.MultiTaskLasso.__init__", "decorators": [], "parameters": [ { @@ -95423,7 +98553,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "{'cyclic', 'random'}, default='cyclic'", - "description": "If set to 'random', a random coefficient is updated every iteration\nrather than looping over features sequentially by default. This\n(setting to 'random') often leads to significantly faster convergence\nespecially when tol is higher than 1e-4" + "description": "If set to 'random', a random coefficient is updated every iteration\nrather than looping over features sequentially by default. This\n(setting to 'random') often leads to significantly faster convergence\nespecially when tol is higher than 1e-4." } } ], @@ -95435,7 +98565,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._coordinate_descent.MultiTaskLassoCV.__init__", + "unique_qname": "sklearn.linear_model._coordinate_descent.MultiTaskLassoCV.__init__", "decorators": [], "parameters": [ { @@ -95587,7 +98719,9 @@ }, { "name": "_get_estimator", + "unique_name": "_get_estimator", "qname": "sklearn.linear_model._coordinate_descent.MultiTaskLassoCV._get_estimator", + "unique_qname": "sklearn.linear_model._coordinate_descent.MultiTaskLassoCV._get_estimator", "decorators": [], "parameters": [ { @@ -95609,7 +98743,9 @@ }, { "name": "_is_multitask", + "unique_name": "_is_multitask", "qname": "sklearn.linear_model._coordinate_descent.MultiTaskLassoCV._is_multitask", + "unique_qname": "sklearn.linear_model._coordinate_descent.MultiTaskLassoCV._is_multitask", "decorators": [], "parameters": [ { @@ -95631,7 +98767,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.linear_model._coordinate_descent.MultiTaskLassoCV._more_tags", + "unique_qname": "sklearn.linear_model._coordinate_descent.MultiTaskLassoCV._more_tags", "decorators": [], "parameters": [ { @@ -95653,7 +98791,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._coordinate_descent.MultiTaskLassoCV.fit", + "unique_qname": "sklearn.linear_model._coordinate_descent.MultiTaskLassoCV.fit", "decorators": [], "parameters": [ { @@ -95695,7 +98835,9 @@ }, { "name": "_alpha_grid", + "unique_name": "_alpha_grid", "qname": "sklearn.linear_model._coordinate_descent._alpha_grid", + "unique_qname": "sklearn.linear_model._coordinate_descent._alpha_grid", "decorators": [], "parameters": [ { @@ -95797,7 +98939,9 @@ }, { "name": "_path_residuals", + "unique_name": "_path_residuals", "qname": "sklearn.linear_model._coordinate_descent._path_residuals", + "unique_qname": "sklearn.linear_model._coordinate_descent._path_residuals", "decorators": [], "parameters": [ { @@ -95939,7 +99083,9 @@ }, { "name": "_set_order", + "unique_name": "_set_order", "qname": "sklearn.linear_model._coordinate_descent._set_order", + "unique_qname": "sklearn.linear_model._coordinate_descent._set_order", "decorators": [], "parameters": [ { @@ -95981,7 +99127,9 @@ }, { "name": "enet_path", + "unique_name": "enet_path", "qname": "sklearn.linear_model._coordinate_descent.enet_path", + "unique_qname": "sklearn.linear_model._coordinate_descent.enet_path", "decorators": [], "parameters": [ { @@ -96133,7 +99281,9 @@ }, { "name": "lasso_path", + "unique_name": "lasso_path", "qname": "sklearn.linear_model._coordinate_descent.lasso_path", + "unique_qname": "sklearn.linear_model._coordinate_descent.lasso_path", "decorators": [], "parameters": [ { @@ -96260,12 +99410,14 @@ "results": [], "is_public": true, "description": "Compute Lasso path with coordinate descent.\n\nThe Lasso optimization function varies for mono and multi-outputs. For mono-output tasks it is:: (1 / (2 * n_samples)) * ||y - Xw||^2_2 + alpha * ||w||_1 For multi-output tasks it is:: (1 / (2 * n_samples)) * ||Y - XW||^2_Fro + alpha * ||W||_21 Where:: ||W||_21 = \\sum_i \\sqrt{\\sum_j w_{ij}^2} i.e. the sum of norm of each row. Read more in the :ref:`User Guide `.", - "docstring": "Compute Lasso path with coordinate descent.\n\nThe Lasso optimization function varies for mono and multi-outputs.\n\nFor mono-output tasks it is::\n\n (1 / (2 * n_samples)) * ||y - Xw||^2_2 + alpha * ||w||_1\n\nFor multi-output tasks it is::\n\n (1 / (2 * n_samples)) * ||Y - XW||^2_Fro + alpha * ||W||_21\n\nWhere::\n\n ||W||_21 = \\sum_i \\sqrt{\\sum_j w_{ij}^2}\n\ni.e. the sum of norm of each row.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training data. Pass directly as Fortran-contiguous data to avoid\n unnecessary memory duplication. If ``y`` is mono-output then ``X``\n can be sparse.\n\ny : {array-like, sparse matrix} of shape (n_samples,) or (n_samples, n_targets)\n Target values.\n\neps : float, default=1e-3\n Length of the path. ``eps=1e-3`` means that\n ``alpha_min / alpha_max = 1e-3``.\n\nn_alphas : int, default=100\n Number of alphas along the regularization path.\n\nalphas : ndarray, default=None\n List of alphas where to compute the models.\n If ``None`` alphas are set automatically.\n\nprecompute : 'auto', bool or array-like of shape (n_features, n_features), default='auto'\n Whether to use a precomputed Gram matrix to speed up\n calculations. If set to ``'auto'`` let us decide. The Gram\n matrix can also be passed as argument.\n\nXy : array-like of shape (n_features,) or (n_features, n_targets), default=None\n Xy = np.dot(X.T, y) that can be precomputed. It is useful\n only when the Gram matrix is precomputed.\n\ncopy_X : bool, default=True\n If ``True``, X will be copied; else, it may be overwritten.\n\ncoef_init : ndarray of shape (n_features, ), default=None\n The initial values of the coefficients.\n\nverbose : bool or int, default=False\n Amount of verbosity.\n\nreturn_n_iter : bool, default=False\n Whether to return the number of iterations or not.\n\npositive : bool, default=False\n If set to True, forces coefficients to be positive.\n (Only allowed when ``y.ndim == 1``).\n\n**params : kwargs\n Keyword arguments passed to the coordinate descent solver.\n\nReturns\n-------\nalphas : ndarray of shape (n_alphas,)\n The alphas along the path where models are computed.\n\ncoefs : ndarray of shape (n_features, n_alphas) or (n_targets, n_features, n_alphas)\n Coefficients along the path.\n\ndual_gaps : ndarray of shape (n_alphas,)\n The dual gaps at the end of the optimization for each alpha.\n\nn_iters : list of int\n The number of iterations taken by the coordinate descent optimizer to\n reach the specified tolerance for each alpha.\n\nSee Also\n--------\nlars_path : Compute Least Angle Regression or Lasso path using LARS\n algorithm.\nLasso : The Lasso is a linear model that estimates sparse coefficients.\nLassoLars : Lasso model fit with Least Angle Regression a.k.a. Lars.\nLassoCV : Lasso linear model with iterative fitting along a regularization\n path.\nLassoLarsCV : Cross-validated Lasso using the LARS algorithm.\nsklearn.decomposition.sparse_encode : Estimator that can be used to\n transform signals into sparse linear combination of atoms from a fixed.\n\nNotes\n-----\nFor an example, see\n:ref:`examples/linear_model/plot_lasso_coordinate_descent_path.py\n`.\n\nTo avoid unnecessary memory duplication the X argument of the fit method\nshould be directly passed as a Fortran-contiguous numpy array.\n\nNote that in certain cases, the Lars solver may be significantly\nfaster to implement this functionality. In particular, linear\ninterpolation can be used to retrieve model coefficients between the\nvalues output by lars_path\n\nExamples\n--------\n\nComparing lasso_path and lars_path with interpolation:\n\n>>> X = np.array([[1, 2, 3.1], [2.3, 5.4, 4.3]]).T\n>>> y = np.array([1, 2, 3.1])\n>>> # Use lasso_path to compute a coefficient path\n>>> _, coef_path, _ = lasso_path(X, y, alphas=[5., 1., .5])\n>>> print(coef_path)\n[[0. 0. 0.46874778]\n [0.2159048 0.4425765 0.23689075]]\n\n>>> # Now use lars_path and 1D linear interpolation to compute the\n>>> # same path\n>>> from sklearn.linear_model import lars_path\n>>> alphas, active, coef_path_lars = lars_path(X, y, method='lasso')\n>>> from scipy import interpolate\n>>> coef_path_continuous = interpolate.interp1d(alphas[::-1],\n... coef_path_lars[:, ::-1])\n>>> print(coef_path_continuous([5., 1., .5]))\n[[0. 0. 0.46915237]\n [0.2159048 0.4425765 0.23668876]]", - "source_code": "\ndef lasso_path(X, y, *, eps=0.001, n_alphas=100, alphas=None, precompute='auto', Xy=None, copy_X=True, coef_init=None, verbose=False, return_n_iter=False, positive=False, **params):\n \"\"\"Compute Lasso path with coordinate descent.\n\n The Lasso optimization function varies for mono and multi-outputs.\n\n For mono-output tasks it is::\n\n (1 / (2 * n_samples)) * ||y - Xw||^2_2 + alpha * ||w||_1\n\n For multi-output tasks it is::\n\n (1 / (2 * n_samples)) * ||Y - XW||^2_Fro + alpha * ||W||_21\n\n Where::\n\n ||W||_21 = \\sum_i \\sqrt{\\sum_j w_{ij}^2}\n\n i.e. the sum of norm of each row.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training data. Pass directly as Fortran-contiguous data to avoid\n unnecessary memory duplication. If ``y`` is mono-output then ``X``\n can be sparse.\n\n y : {array-like, sparse matrix} of shape (n_samples,) or (n_samples, n_targets)\n Target values.\n\n eps : float, default=1e-3\n Length of the path. ``eps=1e-3`` means that\n ``alpha_min / alpha_max = 1e-3``.\n\n n_alphas : int, default=100\n Number of alphas along the regularization path.\n\n alphas : ndarray, default=None\n List of alphas where to compute the models.\n If ``None`` alphas are set automatically.\n\n precompute : 'auto', bool or array-like of shape (n_features, n_features), default='auto'\n Whether to use a precomputed Gram matrix to speed up\n calculations. If set to ``'auto'`` let us decide. The Gram\n matrix can also be passed as argument.\n\n Xy : array-like of shape (n_features,) or (n_features, n_targets), default=None\n Xy = np.dot(X.T, y) that can be precomputed. It is useful\n only when the Gram matrix is precomputed.\n\n copy_X : bool, default=True\n If ``True``, X will be copied; else, it may be overwritten.\n\n coef_init : ndarray of shape (n_features, ), default=None\n The initial values of the coefficients.\n\n verbose : bool or int, default=False\n Amount of verbosity.\n\n return_n_iter : bool, default=False\n Whether to return the number of iterations or not.\n\n positive : bool, default=False\n If set to True, forces coefficients to be positive.\n (Only allowed when ``y.ndim == 1``).\n\n **params : kwargs\n Keyword arguments passed to the coordinate descent solver.\n\n Returns\n -------\n alphas : ndarray of shape (n_alphas,)\n The alphas along the path where models are computed.\n\n coefs : ndarray of shape (n_features, n_alphas) or (n_targets, n_features, n_alphas)\n Coefficients along the path.\n\n dual_gaps : ndarray of shape (n_alphas,)\n The dual gaps at the end of the optimization for each alpha.\n\n n_iters : list of int\n The number of iterations taken by the coordinate descent optimizer to\n reach the specified tolerance for each alpha.\n\n See Also\n --------\n lars_path : Compute Least Angle Regression or Lasso path using LARS\n algorithm.\n Lasso : The Lasso is a linear model that estimates sparse coefficients.\n LassoLars : Lasso model fit with Least Angle Regression a.k.a. Lars.\n LassoCV : Lasso linear model with iterative fitting along a regularization\n path.\n LassoLarsCV : Cross-validated Lasso using the LARS algorithm.\n sklearn.decomposition.sparse_encode : Estimator that can be used to\n transform signals into sparse linear combination of atoms from a fixed.\n\n Notes\n -----\n For an example, see\n :ref:`examples/linear_model/plot_lasso_coordinate_descent_path.py\n `.\n\n To avoid unnecessary memory duplication the X argument of the fit method\n should be directly passed as a Fortran-contiguous numpy array.\n\n Note that in certain cases, the Lars solver may be significantly\n faster to implement this functionality. In particular, linear\n interpolation can be used to retrieve model coefficients between the\n values output by lars_path\n\n Examples\n --------\n\n Comparing lasso_path and lars_path with interpolation:\n\n >>> X = np.array([[1, 2, 3.1], [2.3, 5.4, 4.3]]).T\n >>> y = np.array([1, 2, 3.1])\n >>> # Use lasso_path to compute a coefficient path\n >>> _, coef_path, _ = lasso_path(X, y, alphas=[5., 1., .5])\n >>> print(coef_path)\n [[0. 0. 0.46874778]\n [0.2159048 0.4425765 0.23689075]]\n\n >>> # Now use lars_path and 1D linear interpolation to compute the\n >>> # same path\n >>> from sklearn.linear_model import lars_path\n >>> alphas, active, coef_path_lars = lars_path(X, y, method='lasso')\n >>> from scipy import interpolate\n >>> coef_path_continuous = interpolate.interp1d(alphas[::-1],\n ... coef_path_lars[:, ::-1])\n >>> print(coef_path_continuous([5., 1., .5]))\n [[0. 0. 0.46915237]\n [0.2159048 0.4425765 0.23668876]]\n \"\"\"\n return enet_path(X, y, l1_ratio=1.0, eps=eps, n_alphas=n_alphas, alphas=alphas, precompute=precompute, Xy=Xy, copy_X=copy_X, coef_init=coef_init, verbose=verbose, positive=positive, return_n_iter=return_n_iter, **params)" + "docstring": "Compute Lasso path with coordinate descent.\n\nThe Lasso optimization function varies for mono and multi-outputs.\n\nFor mono-output tasks it is::\n\n (1 / (2 * n_samples)) * ||y - Xw||^2_2 + alpha * ||w||_1\n\nFor multi-output tasks it is::\n\n (1 / (2 * n_samples)) * ||Y - XW||^2_Fro + alpha * ||W||_21\n\nWhere::\n\n ||W||_21 = \\sum_i \\sqrt{\\sum_j w_{ij}^2}\n\ni.e. the sum of norm of each row.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training data. Pass directly as Fortran-contiguous data to avoid\n unnecessary memory duplication. If ``y`` is mono-output then ``X``\n can be sparse.\n\ny : {array-like, sparse matrix} of shape (n_samples,) or (n_samples, n_targets)\n Target values.\n\neps : float, default=1e-3\n Length of the path. ``eps=1e-3`` means that\n ``alpha_min / alpha_max = 1e-3``.\n\nn_alphas : int, default=100\n Number of alphas along the regularization path.\n\nalphas : ndarray, default=None\n List of alphas where to compute the models.\n If ``None`` alphas are set automatically.\n\nprecompute : 'auto', bool or array-like of shape (n_features, n_features), default='auto'\n Whether to use a precomputed Gram matrix to speed up\n calculations. If set to ``'auto'`` let us decide. The Gram\n matrix can also be passed as argument.\n\nXy : array-like of shape (n_features,) or (n_features, n_targets), default=None\n Xy = np.dot(X.T, y) that can be precomputed. It is useful\n only when the Gram matrix is precomputed.\n\ncopy_X : bool, default=True\n If ``True``, X will be copied; else, it may be overwritten.\n\ncoef_init : ndarray of shape (n_features, ), default=None\n The initial values of the coefficients.\n\nverbose : bool or int, default=False\n Amount of verbosity.\n\nreturn_n_iter : bool, default=False\n Whether to return the number of iterations or not.\n\npositive : bool, default=False\n If set to True, forces coefficients to be positive.\n (Only allowed when ``y.ndim == 1``).\n\n**params : kwargs\n Keyword arguments passed to the coordinate descent solver.\n\nReturns\n-------\nalphas : ndarray of shape (n_alphas,)\n The alphas along the path where models are computed.\n\ncoefs : ndarray of shape (n_features, n_alphas) or (n_targets, n_features, n_alphas)\n Coefficients along the path.\n\ndual_gaps : ndarray of shape (n_alphas,)\n The dual gaps at the end of the optimization for each alpha.\n\nn_iters : list of int\n The number of iterations taken by the coordinate descent optimizer to\n reach the specified tolerance for each alpha.\n\nSee Also\n--------\nlars_path : Compute Least Angle Regression or Lasso path using LARS\n algorithm.\nLasso : The Lasso is a linear model that estimates sparse coefficients.\nLassoLars : Lasso model fit with Least Angle Regression a.k.a. Lars.\nLassoCV : Lasso linear model with iterative fitting along a regularization\n path.\nLassoLarsCV : Cross-validated Lasso using the LARS algorithm.\nsklearn.decomposition.sparse_encode : Estimator that can be used to\n transform signals into sparse linear combination of atoms from a fixed.\n\nNotes\n-----\nFor an example, see\n:ref:`examples/linear_model/plot_lasso_coordinate_descent_path.py\n`.\n\nTo avoid unnecessary memory duplication the X argument of the fit method\nshould be directly passed as a Fortran-contiguous numpy array.\n\nNote that in certain cases, the Lars solver may be significantly\nfaster to implement this functionality. In particular, linear\ninterpolation can be used to retrieve model coefficients between the\nvalues output by lars_path\n\nExamples\n--------\n\nComparing lasso_path and lars_path with interpolation:\n\n>>> import numpy as np\n>>> from sklearn.linear_model import lasso_path\n>>> X = np.array([[1, 2, 3.1], [2.3, 5.4, 4.3]]).T\n>>> y = np.array([1, 2, 3.1])\n>>> # Use lasso_path to compute a coefficient path\n>>> _, coef_path, _ = lasso_path(X, y, alphas=[5., 1., .5])\n>>> print(coef_path)\n[[0. 0. 0.46874778]\n [0.2159048 0.4425765 0.23689075]]\n\n>>> # Now use lars_path and 1D linear interpolation to compute the\n>>> # same path\n>>> from sklearn.linear_model import lars_path\n>>> alphas, active, coef_path_lars = lars_path(X, y, method='lasso')\n>>> from scipy import interpolate\n>>> coef_path_continuous = interpolate.interp1d(alphas[::-1],\n... coef_path_lars[:, ::-1])\n>>> print(coef_path_continuous([5., 1., .5]))\n[[0. 0. 0.46915237]\n [0.2159048 0.4425765 0.23668876]]", + "source_code": "\ndef lasso_path(X, y, *, eps=0.001, n_alphas=100, alphas=None, precompute='auto', Xy=None, copy_X=True, coef_init=None, verbose=False, return_n_iter=False, positive=False, **params):\n \"\"\"Compute Lasso path with coordinate descent.\n\n The Lasso optimization function varies for mono and multi-outputs.\n\n For mono-output tasks it is::\n\n (1 / (2 * n_samples)) * ||y - Xw||^2_2 + alpha * ||w||_1\n\n For multi-output tasks it is::\n\n (1 / (2 * n_samples)) * ||Y - XW||^2_Fro + alpha * ||W||_21\n\n Where::\n\n ||W||_21 = \\sum_i \\sqrt{\\sum_j w_{ij}^2}\n\n i.e. the sum of norm of each row.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training data. Pass directly as Fortran-contiguous data to avoid\n unnecessary memory duplication. If ``y`` is mono-output then ``X``\n can be sparse.\n\n y : {array-like, sparse matrix} of shape (n_samples,) or (n_samples, n_targets)\n Target values.\n\n eps : float, default=1e-3\n Length of the path. ``eps=1e-3`` means that\n ``alpha_min / alpha_max = 1e-3``.\n\n n_alphas : int, default=100\n Number of alphas along the regularization path.\n\n alphas : ndarray, default=None\n List of alphas where to compute the models.\n If ``None`` alphas are set automatically.\n\n precompute : 'auto', bool or array-like of shape (n_features, n_features), default='auto'\n Whether to use a precomputed Gram matrix to speed up\n calculations. If set to ``'auto'`` let us decide. The Gram\n matrix can also be passed as argument.\n\n Xy : array-like of shape (n_features,) or (n_features, n_targets), default=None\n Xy = np.dot(X.T, y) that can be precomputed. It is useful\n only when the Gram matrix is precomputed.\n\n copy_X : bool, default=True\n If ``True``, X will be copied; else, it may be overwritten.\n\n coef_init : ndarray of shape (n_features, ), default=None\n The initial values of the coefficients.\n\n verbose : bool or int, default=False\n Amount of verbosity.\n\n return_n_iter : bool, default=False\n Whether to return the number of iterations or not.\n\n positive : bool, default=False\n If set to True, forces coefficients to be positive.\n (Only allowed when ``y.ndim == 1``).\n\n **params : kwargs\n Keyword arguments passed to the coordinate descent solver.\n\n Returns\n -------\n alphas : ndarray of shape (n_alphas,)\n The alphas along the path where models are computed.\n\n coefs : ndarray of shape (n_features, n_alphas) or (n_targets, n_features, n_alphas)\n Coefficients along the path.\n\n dual_gaps : ndarray of shape (n_alphas,)\n The dual gaps at the end of the optimization for each alpha.\n\n n_iters : list of int\n The number of iterations taken by the coordinate descent optimizer to\n reach the specified tolerance for each alpha.\n\n See Also\n --------\n lars_path : Compute Least Angle Regression or Lasso path using LARS\n algorithm.\n Lasso : The Lasso is a linear model that estimates sparse coefficients.\n LassoLars : Lasso model fit with Least Angle Regression a.k.a. Lars.\n LassoCV : Lasso linear model with iterative fitting along a regularization\n path.\n LassoLarsCV : Cross-validated Lasso using the LARS algorithm.\n sklearn.decomposition.sparse_encode : Estimator that can be used to\n transform signals into sparse linear combination of atoms from a fixed.\n\n Notes\n -----\n For an example, see\n :ref:`examples/linear_model/plot_lasso_coordinate_descent_path.py\n `.\n\n To avoid unnecessary memory duplication the X argument of the fit method\n should be directly passed as a Fortran-contiguous numpy array.\n\n Note that in certain cases, the Lars solver may be significantly\n faster to implement this functionality. In particular, linear\n interpolation can be used to retrieve model coefficients between the\n values output by lars_path\n\n Examples\n --------\n\n Comparing lasso_path and lars_path with interpolation:\n\n >>> import numpy as np\n >>> from sklearn.linear_model import lasso_path\n >>> X = np.array([[1, 2, 3.1], [2.3, 5.4, 4.3]]).T\n >>> y = np.array([1, 2, 3.1])\n >>> # Use lasso_path to compute a coefficient path\n >>> _, coef_path, _ = lasso_path(X, y, alphas=[5., 1., .5])\n >>> print(coef_path)\n [[0. 0. 0.46874778]\n [0.2159048 0.4425765 0.23689075]]\n\n >>> # Now use lars_path and 1D linear interpolation to compute the\n >>> # same path\n >>> from sklearn.linear_model import lars_path\n >>> alphas, active, coef_path_lars = lars_path(X, y, method='lasso')\n >>> from scipy import interpolate\n >>> coef_path_continuous = interpolate.interp1d(alphas[::-1],\n ... coef_path_lars[:, ::-1])\n >>> print(coef_path_continuous([5., 1., .5]))\n [[0. 0. 0.46915237]\n [0.2159048 0.4425765 0.23668876]]\n \"\"\"\n return enet_path(X, y, l1_ratio=1.0, eps=eps, n_alphas=n_alphas, alphas=alphas, precompute=precompute, Xy=Xy, copy_X=copy_X, coef_init=coef_init, verbose=verbose, positive=positive, return_n_iter=return_n_iter, **params)" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._glm.glm.GammaRegressor.__init__", + "unique_qname": "sklearn.linear_model._glm.glm.GammaRegressor.__init__", "decorators": [], "parameters": [ { @@ -96347,7 +99499,33 @@ }, { "name": "family", + "unique_name": "family@getter", "qname": "sklearn.linear_model._glm.glm.GammaRegressor.family", + "unique_qname": "sklearn.linear_model._glm.glm.GammaRegressor.family@getter", + "decorators": ["property"], + "parameters": [ + { + "name": "self", + "default_value": null, + "is_public": true, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "", + "description": "" + } + } + ], + "results": [], + "is_public": true, + "description": "Return the family of the regressor.", + "docstring": "Return the family of the regressor.", + "source_code": "\n@property\ndef family(self):\n \"\"\"Return the family of the regressor.\"\"\"\n return 'gamma'" + }, + { + "name": "family", + "unique_name": "family@setter", + "qname": "sklearn.linear_model._glm.glm.GammaRegressor.family", + "unique_qname": "sklearn.linear_model._glm.glm.GammaRegressor.family@setter", "decorators": ["family.setter"], "parameters": [ { @@ -96379,7 +99557,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._glm.glm.GeneralizedLinearRegressor.__init__", + "unique_qname": "sklearn.linear_model._glm.glm.GeneralizedLinearRegressor.__init__", "decorators": [], "parameters": [ { @@ -96491,7 +99671,9 @@ }, { "name": "_linear_predictor", + "unique_name": "_linear_predictor", "qname": "sklearn.linear_model._glm.glm.GeneralizedLinearRegressor._linear_predictor", + "unique_qname": "sklearn.linear_model._glm.glm.GeneralizedLinearRegressor._linear_predictor", "decorators": [], "parameters": [ { @@ -96523,7 +99705,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.linear_model._glm.glm.GeneralizedLinearRegressor._more_tags", + "unique_qname": "sklearn.linear_model._glm.glm.GeneralizedLinearRegressor._more_tags", "decorators": [], "parameters": [ { @@ -96545,7 +99729,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._glm.glm.GeneralizedLinearRegressor.fit", + "unique_qname": "sklearn.linear_model._glm.glm.GeneralizedLinearRegressor.fit", "decorators": [], "parameters": [ { @@ -96597,7 +99783,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.linear_model._glm.glm.GeneralizedLinearRegressor.predict", + "unique_qname": "sklearn.linear_model._glm.glm.GeneralizedLinearRegressor.predict", "decorators": [], "parameters": [ { @@ -96629,7 +99817,9 @@ }, { "name": "score", + "unique_name": "score", "qname": "sklearn.linear_model._glm.glm.GeneralizedLinearRegressor.score", + "unique_qname": "sklearn.linear_model._glm.glm.GeneralizedLinearRegressor.score", "decorators": [], "parameters": [ { @@ -96681,7 +99871,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._glm.glm.PoissonRegressor.__init__", + "unique_qname": "sklearn.linear_model._glm.glm.PoissonRegressor.__init__", "decorators": [], "parameters": [ { @@ -96763,7 +99955,33 @@ }, { "name": "family", + "unique_name": "family@getter", + "qname": "sklearn.linear_model._glm.glm.PoissonRegressor.family", + "unique_qname": "sklearn.linear_model._glm.glm.PoissonRegressor.family@getter", + "decorators": ["property"], + "parameters": [ + { + "name": "self", + "default_value": null, + "is_public": true, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "", + "description": "" + } + } + ], + "results": [], + "is_public": true, + "description": "Return the string `'poisson'`.", + "docstring": "Return the string `'poisson'`.", + "source_code": "\n@property\ndef family(self):\n \"\"\"Return the string `'poisson'`.\"\"\"\n return 'poisson'" + }, + { + "name": "family", + "unique_name": "family@setter", "qname": "sklearn.linear_model._glm.glm.PoissonRegressor.family", + "unique_qname": "sklearn.linear_model._glm.glm.PoissonRegressor.family@setter", "decorators": ["family.setter"], "parameters": [ { @@ -96795,7 +100013,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._glm.glm.TweedieRegressor.__init__", + "unique_qname": "sklearn.linear_model._glm.glm.TweedieRegressor.__init__", "decorators": [], "parameters": [ { @@ -96897,7 +100117,33 @@ }, { "name": "family", + "unique_name": "family@getter", + "qname": "sklearn.linear_model._glm.glm.TweedieRegressor.family", + "unique_qname": "sklearn.linear_model._glm.glm.TweedieRegressor.family@getter", + "decorators": ["property"], + "parameters": [ + { + "name": "self", + "default_value": null, + "is_public": true, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "", + "description": "" + } + } + ], + "results": [], + "is_public": true, + "description": "Return the family of the regressor.", + "docstring": "Return the family of the regressor.", + "source_code": "\n@property\ndef family(self):\n \"\"\"Return the family of the regressor.\"\"\"\n dist = TweedieDistribution(power=self.power)\n return dist" + }, + { + "name": "family", + "unique_name": "family@setter", "qname": "sklearn.linear_model._glm.glm.TweedieRegressor.family", + "unique_qname": "sklearn.linear_model._glm.glm.TweedieRegressor.family@setter", "decorators": ["family.setter"], "parameters": [ { @@ -96929,7 +100175,9 @@ }, { "name": "_safe_lin_pred", + "unique_name": "_safe_lin_pred", "qname": "sklearn.linear_model._glm.glm._safe_lin_pred", + "unique_qname": "sklearn.linear_model._glm.glm._safe_lin_pred", "decorators": [], "parameters": [ { @@ -96961,7 +100209,9 @@ }, { "name": "_y_pred_deviance_derivative", + "unique_name": "_y_pred_deviance_derivative", "qname": "sklearn.linear_model._glm.glm._y_pred_deviance_derivative", + "unique_qname": "sklearn.linear_model._glm.glm._y_pred_deviance_derivative", "decorators": [], "parameters": [ { @@ -97033,7 +100283,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.linear_model._glm.link.BaseLink.__call__", + "unique_qname": "sklearn.linear_model._glm.link.BaseLink.__call__", "decorators": ["abstractmethod"], "parameters": [ { @@ -97065,7 +100317,9 @@ }, { "name": "derivative", + "unique_name": "derivative", "qname": "sklearn.linear_model._glm.link.BaseLink.derivative", + "unique_qname": "sklearn.linear_model._glm.link.BaseLink.derivative", "decorators": ["abstractmethod"], "parameters": [ { @@ -97097,7 +100351,9 @@ }, { "name": "inverse", + "unique_name": "inverse", "qname": "sklearn.linear_model._glm.link.BaseLink.inverse", + "unique_qname": "sklearn.linear_model._glm.link.BaseLink.inverse", "decorators": ["abstractmethod"], "parameters": [ { @@ -97129,7 +100385,9 @@ }, { "name": "inverse_derivative", + "unique_name": "inverse_derivative", "qname": "sklearn.linear_model._glm.link.BaseLink.inverse_derivative", + "unique_qname": "sklearn.linear_model._glm.link.BaseLink.inverse_derivative", "decorators": ["abstractmethod"], "parameters": [ { @@ -97161,7 +100419,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.linear_model._glm.link.IdentityLink.__call__", + "unique_qname": "sklearn.linear_model._glm.link.IdentityLink.__call__", "decorators": [], "parameters": [ { @@ -97193,7 +100453,9 @@ }, { "name": "derivative", + "unique_name": "derivative", "qname": "sklearn.linear_model._glm.link.IdentityLink.derivative", + "unique_qname": "sklearn.linear_model._glm.link.IdentityLink.derivative", "decorators": [], "parameters": [ { @@ -97225,7 +100487,9 @@ }, { "name": "inverse", + "unique_name": "inverse", "qname": "sklearn.linear_model._glm.link.IdentityLink.inverse", + "unique_qname": "sklearn.linear_model._glm.link.IdentityLink.inverse", "decorators": [], "parameters": [ { @@ -97257,7 +100521,9 @@ }, { "name": "inverse_derivative", + "unique_name": "inverse_derivative", "qname": "sklearn.linear_model._glm.link.IdentityLink.inverse_derivative", + "unique_qname": "sklearn.linear_model._glm.link.IdentityLink.inverse_derivative", "decorators": [], "parameters": [ { @@ -97289,7 +100555,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.linear_model._glm.link.LogLink.__call__", + "unique_qname": "sklearn.linear_model._glm.link.LogLink.__call__", "decorators": [], "parameters": [ { @@ -97321,7 +100589,9 @@ }, { "name": "derivative", + "unique_name": "derivative", "qname": "sklearn.linear_model._glm.link.LogLink.derivative", + "unique_qname": "sklearn.linear_model._glm.link.LogLink.derivative", "decorators": [], "parameters": [ { @@ -97353,7 +100623,9 @@ }, { "name": "inverse", + "unique_name": "inverse", "qname": "sklearn.linear_model._glm.link.LogLink.inverse", + "unique_qname": "sklearn.linear_model._glm.link.LogLink.inverse", "decorators": [], "parameters": [ { @@ -97385,7 +100657,9 @@ }, { "name": "inverse_derivative", + "unique_name": "inverse_derivative", "qname": "sklearn.linear_model._glm.link.LogLink.inverse_derivative", + "unique_qname": "sklearn.linear_model._glm.link.LogLink.inverse_derivative", "decorators": [], "parameters": [ { @@ -97417,7 +100691,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.linear_model._glm.link.LogitLink.__call__", + "unique_qname": "sklearn.linear_model._glm.link.LogitLink.__call__", "decorators": [], "parameters": [ { @@ -97449,7 +100725,9 @@ }, { "name": "derivative", + "unique_name": "derivative", "qname": "sklearn.linear_model._glm.link.LogitLink.derivative", + "unique_qname": "sklearn.linear_model._glm.link.LogitLink.derivative", "decorators": [], "parameters": [ { @@ -97481,7 +100759,9 @@ }, { "name": "inverse", + "unique_name": "inverse", "qname": "sklearn.linear_model._glm.link.LogitLink.inverse", + "unique_qname": "sklearn.linear_model._glm.link.LogitLink.inverse", "decorators": [], "parameters": [ { @@ -97513,7 +100793,9 @@ }, { "name": "inverse_derivative", + "unique_name": "inverse_derivative", "qname": "sklearn.linear_model._glm.link.LogitLink.inverse_derivative", + "unique_qname": "sklearn.linear_model._glm.link.LogitLink.inverse_derivative", "decorators": [], "parameters": [ { @@ -97545,7 +100827,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._huber.HuberRegressor.__init__", + "unique_qname": "sklearn.linear_model._huber.HuberRegressor.__init__", "decorators": [], "parameters": [ { @@ -97627,7 +100911,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._huber.HuberRegressor.fit", + "unique_qname": "sklearn.linear_model._huber.HuberRegressor.fit", "decorators": [], "parameters": [ { @@ -97679,7 +100965,9 @@ }, { "name": "_huber_loss_and_gradient", + "unique_name": "_huber_loss_and_gradient", "qname": "sklearn.linear_model._huber._huber_loss_and_gradient", + "unique_qname": "sklearn.linear_model._huber._huber_loss_and_gradient", "decorators": [], "parameters": [ { @@ -97751,7 +101039,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._least_angle.Lars.__init__", + "unique_qname": "sklearn.linear_model._least_angle.Lars.__init__", "decorators": [], "parameters": [ { @@ -97873,7 +101163,9 @@ }, { "name": "_fit", + "unique_name": "_fit", "qname": "sklearn.linear_model._least_angle.Lars._fit", + "unique_qname": "sklearn.linear_model._least_angle.Lars._fit", "decorators": [], "parameters": [ { @@ -97965,7 +101257,9 @@ }, { "name": "_get_gram", + "unique_name": "_get_gram", "qname": "sklearn.linear_model._least_angle.Lars._get_gram", + "unique_qname": "sklearn.linear_model._least_angle.Lars._get_gram", "decorators": ["staticmethod"], "parameters": [ { @@ -98007,7 +101301,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._least_angle.Lars.fit", + "unique_qname": "sklearn.linear_model._least_angle.Lars.fit", "decorators": [], "parameters": [ { @@ -98059,7 +101355,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._least_angle.LarsCV.__init__", + "unique_qname": "sklearn.linear_model._least_angle.LarsCV.__init__", "decorators": [], "parameters": [ { @@ -98181,7 +101479,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.linear_model._least_angle.LarsCV._more_tags", + "unique_qname": "sklearn.linear_model._least_angle.LarsCV._more_tags", "decorators": [], "parameters": [ { @@ -98203,7 +101503,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._least_angle.LarsCV.fit", + "unique_qname": "sklearn.linear_model._least_angle.LarsCV.fit", "decorators": [], "parameters": [ { @@ -98245,7 +101547,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._least_angle.LassoLars.__init__", + "unique_qname": "sklearn.linear_model._least_angle.LassoLars.__init__", "decorators": [], "parameters": [ { @@ -98387,7 +101691,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._least_angle.LassoLarsCV.__init__", + "unique_qname": "sklearn.linear_model._least_angle.LassoLarsCV.__init__", "decorators": [], "parameters": [ { @@ -98519,7 +101825,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._least_angle.LassoLarsIC.__init__", + "unique_qname": "sklearn.linear_model._least_angle.LassoLarsIC.__init__", "decorators": [], "parameters": [ { @@ -98631,7 +101939,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.linear_model._least_angle.LassoLarsIC._more_tags", + "unique_qname": "sklearn.linear_model._least_angle.LassoLarsIC._more_tags", "decorators": [], "parameters": [ { @@ -98653,7 +101963,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._least_angle.LassoLarsIC.fit", + "unique_qname": "sklearn.linear_model._least_angle.LassoLarsIC.fit", "decorators": [], "parameters": [ { @@ -98705,7 +102017,9 @@ }, { "name": "_check_copy_and_writeable", + "unique_name": "_check_copy_and_writeable", "qname": "sklearn.linear_model._least_angle._check_copy_and_writeable", + "unique_qname": "sklearn.linear_model._least_angle._check_copy_and_writeable", "decorators": [], "parameters": [ { @@ -98737,7 +102051,9 @@ }, { "name": "_lars_path_residues", + "unique_name": "_lars_path_residues", "qname": "sklearn.linear_model._least_angle._lars_path_residues", + "unique_qname": "sklearn.linear_model._least_angle._lars_path_residues", "decorators": [], "parameters": [ { @@ -98879,7 +102195,9 @@ }, { "name": "_lars_path_solver", + "unique_name": "_lars_path_solver", "qname": "sklearn.linear_model._least_angle._lars_path_solver", + "unique_qname": "sklearn.linear_model._least_angle._lars_path_solver", "decorators": [], "parameters": [ { @@ -99037,11 +102355,13 @@ "is_public": false, "description": "Compute Least Angle Regression or Lasso path using LARS algorithm [1]\n\nThe optimization objective for the case method='lasso' is:: (1 / (2 * n_samples)) * ||y - Xw||^2_2 + alpha * ||w||_1 in the case of method='lars', the objective function is only known in the form of an implicit equation (see discussion in [1]) Read more in the :ref:`User Guide `.", "docstring": "Compute Least Angle Regression or Lasso path using LARS algorithm [1]\n\nThe optimization objective for the case method='lasso' is::\n\n(1 / (2 * n_samples)) * ||y - Xw||^2_2 + alpha * ||w||_1\n\nin the case of method='lars', the objective function is only known in\nthe form of an implicit equation (see discussion in [1])\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\nX : None or ndarray of shape (n_samples, n_features)\n Input data. Note that if X is None then Gram must be specified,\n i.e., cannot be None or False.\n\ny : None or ndarray of shape (n_samples,)\n Input targets.\n\nXy : array-like of shape (n_samples,) or (n_samples, n_targets), default=None\n `Xy = np.dot(X.T, y)` that can be precomputed. It is useful\n only when the Gram matrix is precomputed.\n\nGram : None, 'auto' or array-like of shape (n_features, n_features), default=None\n Precomputed Gram matrix `(X' * X)`, if ``'auto'``, the Gram\n matrix is precomputed from the given X, if there are more samples\n than features.\n\nn_samples : int or float, default=None\n Equivalent size of sample. If `None`, it will be `n_samples`.\n\nmax_iter : int, default=500\n Maximum number of iterations to perform, set to infinity for no limit.\n\nalpha_min : float, default=0\n Minimum correlation along the path. It corresponds to the\n regularization parameter alpha parameter in the Lasso.\n\nmethod : {'lar', 'lasso'}, default='lar'\n Specifies the returned model. Select ``'lar'`` for Least Angle\n Regression, ``'lasso'`` for the Lasso.\n\ncopy_X : bool, default=True\n If ``False``, ``X`` is overwritten.\n\neps : float, default=np.finfo(float).eps\n The machine-precision regularization in the computation of the\n Cholesky diagonal factors. Increase this for very ill-conditioned\n systems. Unlike the ``tol`` parameter in some iterative\n optimization-based algorithms, this parameter does not control\n the tolerance of the optimization.\n\ncopy_Gram : bool, default=True\n If ``False``, ``Gram`` is overwritten.\n\nverbose : int, default=0\n Controls output verbosity.\n\nreturn_path : bool, default=True\n If ``return_path==True`` returns the entire path, else returns only the\n last point of the path.\n\nreturn_n_iter : bool, default=False\n Whether to return the number of iterations.\n\npositive : bool, default=False\n Restrict coefficients to be >= 0.\n This option is only allowed with method 'lasso'. Note that the model\n coefficients will not converge to the ordinary-least-squares solution\n for small values of alpha. Only coefficients up to the smallest alpha\n value (``alphas_[alphas_ > 0.].min()`` when fit_path=True) reached by\n the stepwise Lars-Lasso algorithm are typically in congruence with the\n solution of the coordinate descent lasso_path function.\n\nReturns\n-------\nalphas : array-like of shape (n_alphas + 1,)\n Maximum of covariances (in absolute value) at each iteration.\n ``n_alphas`` is either ``max_iter``, ``n_features`` or the\n number of nodes in the path with ``alpha >= alpha_min``, whichever\n is smaller.\n\nactive : array-like of shape (n_alphas,)\n Indices of active variables at the end of the path.\n\ncoefs : array-like of shape (n_features, n_alphas + 1)\n Coefficients along the path\n\nn_iter : int\n Number of iterations run. Returned only if return_n_iter is set\n to True.\n\nSee Also\n--------\nlasso_path\nLassoLars\nLars\nLassoLarsCV\nLarsCV\nsklearn.decomposition.sparse_encode\n\nReferences\n----------\n.. [1] \"Least Angle Regression\", Efron et al.\n http://statweb.stanford.edu/~tibs/ftp/lars.pdf\n\n.. [2] `Wikipedia entry on the Least-angle regression\n `_\n\n.. [3] `Wikipedia entry on the Lasso\n `_", - "source_code": "\ndef _lars_path_solver(X, y, Xy=None, Gram=None, n_samples=None, max_iter=500, alpha_min=0, method='lar', copy_X=True, eps=np.finfo(float).eps, copy_Gram=True, verbose=0, return_path=True, return_n_iter=False, positive=False):\n \"\"\"Compute Least Angle Regression or Lasso path using LARS algorithm [1]\n\n The optimization objective for the case method='lasso' is::\n\n (1 / (2 * n_samples)) * ||y - Xw||^2_2 + alpha * ||w||_1\n\n in the case of method='lars', the objective function is only known in\n the form of an implicit equation (see discussion in [1])\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n X : None or ndarray of shape (n_samples, n_features)\n Input data. Note that if X is None then Gram must be specified,\n i.e., cannot be None or False.\n\n y : None or ndarray of shape (n_samples,)\n Input targets.\n\n Xy : array-like of shape (n_samples,) or (n_samples, n_targets), default=None\n `Xy = np.dot(X.T, y)` that can be precomputed. It is useful\n only when the Gram matrix is precomputed.\n\n Gram : None, 'auto' or array-like of shape (n_features, n_features), default=None\n Precomputed Gram matrix `(X' * X)`, if ``'auto'``, the Gram\n matrix is precomputed from the given X, if there are more samples\n than features.\n\n n_samples : int or float, default=None\n Equivalent size of sample. If `None`, it will be `n_samples`.\n\n max_iter : int, default=500\n Maximum number of iterations to perform, set to infinity for no limit.\n\n alpha_min : float, default=0\n Minimum correlation along the path. It corresponds to the\n regularization parameter alpha parameter in the Lasso.\n\n method : {'lar', 'lasso'}, default='lar'\n Specifies the returned model. Select ``'lar'`` for Least Angle\n Regression, ``'lasso'`` for the Lasso.\n\n copy_X : bool, default=True\n If ``False``, ``X`` is overwritten.\n\n eps : float, default=np.finfo(float).eps\n The machine-precision regularization in the computation of the\n Cholesky diagonal factors. Increase this for very ill-conditioned\n systems. Unlike the ``tol`` parameter in some iterative\n optimization-based algorithms, this parameter does not control\n the tolerance of the optimization.\n\n copy_Gram : bool, default=True\n If ``False``, ``Gram`` is overwritten.\n\n verbose : int, default=0\n Controls output verbosity.\n\n return_path : bool, default=True\n If ``return_path==True`` returns the entire path, else returns only the\n last point of the path.\n\n return_n_iter : bool, default=False\n Whether to return the number of iterations.\n\n positive : bool, default=False\n Restrict coefficients to be >= 0.\n This option is only allowed with method 'lasso'. Note that the model\n coefficients will not converge to the ordinary-least-squares solution\n for small values of alpha. Only coefficients up to the smallest alpha\n value (``alphas_[alphas_ > 0.].min()`` when fit_path=True) reached by\n the stepwise Lars-Lasso algorithm are typically in congruence with the\n solution of the coordinate descent lasso_path function.\n\n Returns\n -------\n alphas : array-like of shape (n_alphas + 1,)\n Maximum of covariances (in absolute value) at each iteration.\n ``n_alphas`` is either ``max_iter``, ``n_features`` or the\n number of nodes in the path with ``alpha >= alpha_min``, whichever\n is smaller.\n\n active : array-like of shape (n_alphas,)\n Indices of active variables at the end of the path.\n\n coefs : array-like of shape (n_features, n_alphas + 1)\n Coefficients along the path\n\n n_iter : int\n Number of iterations run. Returned only if return_n_iter is set\n to True.\n\n See Also\n --------\n lasso_path\n LassoLars\n Lars\n LassoLarsCV\n LarsCV\n sklearn.decomposition.sparse_encode\n\n References\n ----------\n .. [1] \"Least Angle Regression\", Efron et al.\n http://statweb.stanford.edu/~tibs/ftp/lars.pdf\n\n .. [2] `Wikipedia entry on the Least-angle regression\n `_\n\n .. [3] `Wikipedia entry on the Lasso\n `_\n\n \"\"\"\n if method == 'lar' and positive:\n raise ValueError(\"Positive constraint not supported for 'lar' coding method.\")\n n_samples = n_samples if n_samples is not None else y.size\n if Xy is None:\n Cov = np.dot(X.T, y)\n else:\n Cov = Xy.copy()\n if Gram is None or Gram is False:\n Gram = None\n if X is None:\n raise ValueError('X and Gram cannot both be unspecified.')\n elif isinstance(Gram, str) and Gram == 'auto' or Gram is True:\n if Gram is True or X.shape[0] > X.shape[1]:\n Gram = np.dot(X.T, X)\n else:\n Gram = None\n elif copy_Gram:\n Gram = Gram.copy()\n if Gram is None:\n n_features = X.shape[1]\n else:\n n_features = Cov.shape[0]\n if Gram.shape != (n_features, n_features):\n raise ValueError('The shapes of the inputs Gram and Xy do not match.')\n if copy_X and X is not None and Gram is None:\n X = X.copy('F')\n max_features = min(max_iter, n_features)\n dtypes = set((a.dtype for a in (X, y, Xy, Gram) if a is not None))\n if len(dtypes) == 1:\n return_dtype = next(iter(dtypes))\n else:\n return_dtype = np.float64\n if return_path:\n coefs = np.zeros((max_features + 1, n_features), dtype=return_dtype)\n alphas = np.zeros(max_features + 1, dtype=return_dtype)\n else:\n (coef, prev_coef) = (np.zeros(n_features, dtype=return_dtype), np.zeros(n_features, dtype=return_dtype))\n (alpha, prev_alpha) = (np.array([0.0], dtype=return_dtype), np.array([0.0], dtype=return_dtype))\n (n_iter, n_active) = (0, 0)\n (active, indices) = (list(), np.arange(n_features))\n sign_active = np.empty(max_features, dtype=np.int8)\n drop = False\n if Gram is None:\n L = np.empty((max_features, max_features), dtype=X.dtype)\n (swap, nrm2) = linalg.get_blas_funcs(('swap', 'nrm2'), (X, ))\n else:\n L = np.empty((max_features, max_features), dtype=Gram.dtype)\n (swap, nrm2) = linalg.get_blas_funcs(('swap', 'nrm2'), (Cov, ))\n (solve_cholesky, ) = get_lapack_funcs(('potrs', ), (L, ))\n if verbose:\n if verbose > 1:\n print('Step\\t\\tAdded\\t\\tDropped\\t\\tActive set size\\t\\tC')\n else:\n sys.stdout.write('.')\n sys.stdout.flush()\n tiny32 = np.finfo(np.float32).tiny\n equality_tolerance = np.finfo(np.float32).eps\n if Gram is not None:\n Gram_copy = Gram.copy()\n Cov_copy = Cov.copy()\n while True:\n if Cov.size:\n if positive:\n C_idx = np.argmax(Cov)\n else:\n C_idx = np.argmax(np.abs(Cov))\n C_ = Cov[C_idx]\n if positive:\n C = C_\n else:\n C = np.fabs(C_)\n else:\n C = 0.0\n if return_path:\n alpha = alphas[n_iter, np.newaxis]\n coef = coefs[n_iter]\n prev_alpha = alphas[n_iter - 1, np.newaxis]\n prev_coef = coefs[n_iter - 1]\n alpha[0] = C / n_samples\n if alpha[0] <= alpha_min + equality_tolerance:\n if abs(alpha[0] - alpha_min) > equality_tolerance:\n if n_iter > 0:\n ss = (prev_alpha[0] - alpha_min) / (prev_alpha[0] - alpha[0])\n coef[:] = prev_coef + ss * (coef - prev_coef)\n alpha[0] = alpha_min\n if return_path:\n coefs[n_iter] = coef\n break\n if n_iter >= max_iter or n_active >= n_features:\n break\n if not drop:\n if positive:\n sign_active[n_active] = np.ones_like(C_)\n else:\n sign_active[n_active] = np.sign(C_)\n (m, n) = (n_active, C_idx + n_active)\n (Cov[C_idx], Cov[0]) = swap(Cov[C_idx], Cov[0])\n (indices[n], indices[m]) = (indices[m], indices[n])\n Cov_not_shortened = Cov\n Cov = Cov[1:]\n if Gram is None:\n (X.T[n], X.T[m]) = swap(X.T[n], X.T[m])\n c = nrm2(X.T[n_active])**2\n L[n_active, :n_active] = np.dot(X.T[n_active], X.T[:n_active].T)\n else:\n (Gram[m], Gram[n]) = swap(Gram[m], Gram[n])\n (Gram[:, m], Gram[:, n]) = swap(Gram[:, m], Gram[:, n])\n c = Gram[n_active, n_active]\n L[n_active, :n_active] = Gram[n_active, :n_active]\n if n_active:\n linalg.solve_triangular(L[:n_active, :n_active], L[n_active, :n_active], trans=0, lower=1, overwrite_b=True, **SOLVE_TRIANGULAR_ARGS)\n v = np.dot(L[n_active, :n_active], L[n_active, :n_active])\n diag = max(np.sqrt(np.abs(c - v)), eps)\n L[n_active, n_active] = diag\n if diag < 1e-07:\n warnings.warn('Regressors in active set degenerate. Dropping a regressor, after %i iterations, i.e. alpha=%.3e, with an active set of %i regressors, and the smallest cholesky pivot element being %.3e. Reduce max_iter or increase eps parameters.' % (n_iter, alpha, n_active, diag), ConvergenceWarning)\n Cov = Cov_not_shortened\n Cov[0] = 0\n (Cov[C_idx], Cov[0]) = swap(Cov[C_idx], Cov[0])\n continue\n active.append(indices[n_active])\n n_active += 1\n if verbose > 1:\n print('%s\\t\\t%s\\t\\t%s\\t\\t%s\\t\\t%s' % (n_iter, active[-1], '', n_active, C))\n if method == 'lasso' and n_iter > 0 and prev_alpha[0] < alpha[0]:\n warnings.warn('Early stopping the lars path, as the residues are small and the current value of alpha is no longer well controlled. %i iterations, alpha=%.3e, previous alpha=%.3e, with an active set of %i regressors.' % (n_iter, alpha, prev_alpha, n_active), ConvergenceWarning)\n break\n (least_squares, _) = solve_cholesky(L[:n_active, :n_active], sign_active[:n_active], lower=True)\n if least_squares.size == 1 and least_squares == 0:\n least_squares[...] = 1\n AA = 1.0\n else:\n AA = 1.0 / np.sqrt(np.sum(least_squares * sign_active[:n_active]))\n if not np.isfinite(AA):\n i = 0\n L_ = L[:n_active, :n_active].copy()\n while not np.isfinite(AA):\n L_.flat[::n_active + 1] += 2**i * eps\n (least_squares, _) = solve_cholesky(L_, sign_active[:n_active], lower=True)\n tmp = max(np.sum(least_squares * sign_active[:n_active]), eps)\n AA = 1.0 / np.sqrt(tmp)\n i += 1\n least_squares *= AA\n if Gram is None:\n eq_dir = np.dot(X.T[:n_active].T, least_squares)\n corr_eq_dir = np.dot(X.T[n_active:], eq_dir)\n else:\n corr_eq_dir = np.dot(Gram[:n_active, n_active:].T, least_squares)\n g1 = arrayfuncs.min_pos((C - Cov) / (AA - corr_eq_dir + tiny32))\n if positive:\n gamma_ = min(g1, C / AA)\n else:\n g2 = arrayfuncs.min_pos((C + Cov) / (AA + corr_eq_dir + tiny32))\n gamma_ = min(g1, g2, C / AA)\n drop = False\n z = -coef[active] / (least_squares + tiny32)\n z_pos = arrayfuncs.min_pos(z)\n if z_pos < gamma_:\n idx = np.where(z == z_pos)[0][::-1]\n sign_active[idx] = -sign_active[idx]\n if method == 'lasso':\n gamma_ = z_pos\n drop = True\n n_iter += 1\n if return_path:\n if n_iter >= coefs.shape[0]:\n del coef, alpha, prev_alpha, prev_coef\n add_features = 2 * max(1, max_features - n_active)\n coefs = np.resize(coefs, (n_iter + add_features, n_features))\n coefs[-add_features:] = 0\n alphas = np.resize(alphas, n_iter + add_features)\n alphas[-add_features:] = 0\n coef = coefs[n_iter]\n prev_coef = coefs[n_iter - 1]\n else:\n prev_coef = coef\n prev_alpha[0] = alpha[0]\n coef = np.zeros_like(coef)\n coef[active] = prev_coef[active] + gamma_ * least_squares\n Cov -= gamma_ * corr_eq_dir\n if drop and method == 'lasso':\n for ii in idx:\n arrayfuncs.cholesky_delete(L[:n_active, :n_active], ii)\n n_active -= 1\n drop_idx = [active.pop(ii) for ii in idx]\n if Gram is None:\n for ii in idx:\n for i in range(ii, n_active):\n (X.T[i], X.T[i + 1]) = swap(X.T[i], X.T[i + 1])\n (indices[i], indices[i + 1]) = (indices[i + 1], indices[i])\n residual = y - np.dot(X[:, :n_active], coef[active])\n temp = np.dot(X.T[n_active], residual)\n Cov = np.r_[temp, Cov]\n else:\n for ii in idx:\n for i in range(ii, n_active):\n (indices[i], indices[i + 1]) = (indices[i + 1], indices[i])\n (Gram[i], Gram[i + 1]) = swap(Gram[i], Gram[i + 1])\n (Gram[:, i], Gram[:, i + 1]) = swap(Gram[:, i], Gram[:, i + 1])\n temp = Cov_copy[drop_idx] - np.dot(Gram_copy[drop_idx], coef)\n Cov = np.r_[temp, Cov]\n sign_active = np.delete(sign_active, idx)\n sign_active = np.append(sign_active, 0.0)\n if verbose > 1:\n print('%s\\t\\t%s\\t\\t%s\\t\\t%s\\t\\t%s' % (n_iter, '', drop_idx, n_active, abs(temp)))\n if return_path:\n alphas = alphas[:n_iter + 1]\n coefs = coefs[:n_iter + 1]\n if return_n_iter:\n return alphas, active, coefs.T, n_iter\n else:\n return alphas, active, coefs.T\n elif return_n_iter:\n return alpha, active, coef, n_iter\n else:\n return alpha, active, coef" + "source_code": "\ndef _lars_path_solver(X, y, Xy=None, Gram=None, n_samples=None, max_iter=500, alpha_min=0, method='lar', copy_X=True, eps=np.finfo(float).eps, copy_Gram=True, verbose=0, return_path=True, return_n_iter=False, positive=False):\n \"\"\"Compute Least Angle Regression or Lasso path using LARS algorithm [1]\n\n The optimization objective for the case method='lasso' is::\n\n (1 / (2 * n_samples)) * ||y - Xw||^2_2 + alpha * ||w||_1\n\n in the case of method='lars', the objective function is only known in\n the form of an implicit equation (see discussion in [1])\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n X : None or ndarray of shape (n_samples, n_features)\n Input data. Note that if X is None then Gram must be specified,\n i.e., cannot be None or False.\n\n y : None or ndarray of shape (n_samples,)\n Input targets.\n\n Xy : array-like of shape (n_samples,) or (n_samples, n_targets), default=None\n `Xy = np.dot(X.T, y)` that can be precomputed. It is useful\n only when the Gram matrix is precomputed.\n\n Gram : None, 'auto' or array-like of shape (n_features, n_features), default=None\n Precomputed Gram matrix `(X' * X)`, if ``'auto'``, the Gram\n matrix is precomputed from the given X, if there are more samples\n than features.\n\n n_samples : int or float, default=None\n Equivalent size of sample. If `None`, it will be `n_samples`.\n\n max_iter : int, default=500\n Maximum number of iterations to perform, set to infinity for no limit.\n\n alpha_min : float, default=0\n Minimum correlation along the path. It corresponds to the\n regularization parameter alpha parameter in the Lasso.\n\n method : {'lar', 'lasso'}, default='lar'\n Specifies the returned model. Select ``'lar'`` for Least Angle\n Regression, ``'lasso'`` for the Lasso.\n\n copy_X : bool, default=True\n If ``False``, ``X`` is overwritten.\n\n eps : float, default=np.finfo(float).eps\n The machine-precision regularization in the computation of the\n Cholesky diagonal factors. Increase this for very ill-conditioned\n systems. Unlike the ``tol`` parameter in some iterative\n optimization-based algorithms, this parameter does not control\n the tolerance of the optimization.\n\n copy_Gram : bool, default=True\n If ``False``, ``Gram`` is overwritten.\n\n verbose : int, default=0\n Controls output verbosity.\n\n return_path : bool, default=True\n If ``return_path==True`` returns the entire path, else returns only the\n last point of the path.\n\n return_n_iter : bool, default=False\n Whether to return the number of iterations.\n\n positive : bool, default=False\n Restrict coefficients to be >= 0.\n This option is only allowed with method 'lasso'. Note that the model\n coefficients will not converge to the ordinary-least-squares solution\n for small values of alpha. Only coefficients up to the smallest alpha\n value (``alphas_[alphas_ > 0.].min()`` when fit_path=True) reached by\n the stepwise Lars-Lasso algorithm are typically in congruence with the\n solution of the coordinate descent lasso_path function.\n\n Returns\n -------\n alphas : array-like of shape (n_alphas + 1,)\n Maximum of covariances (in absolute value) at each iteration.\n ``n_alphas`` is either ``max_iter``, ``n_features`` or the\n number of nodes in the path with ``alpha >= alpha_min``, whichever\n is smaller.\n\n active : array-like of shape (n_alphas,)\n Indices of active variables at the end of the path.\n\n coefs : array-like of shape (n_features, n_alphas + 1)\n Coefficients along the path\n\n n_iter : int\n Number of iterations run. Returned only if return_n_iter is set\n to True.\n\n See Also\n --------\n lasso_path\n LassoLars\n Lars\n LassoLarsCV\n LarsCV\n sklearn.decomposition.sparse_encode\n\n References\n ----------\n .. [1] \"Least Angle Regression\", Efron et al.\n http://statweb.stanford.edu/~tibs/ftp/lars.pdf\n\n .. [2] `Wikipedia entry on the Least-angle regression\n `_\n\n .. [3] `Wikipedia entry on the Lasso\n `_\n\n \"\"\"\n if method == 'lar' and positive:\n raise ValueError(\"Positive constraint not supported for 'lar' coding method.\")\n n_samples = n_samples if n_samples is not None else y.size\n if Xy is None:\n Cov = np.dot(X.T, y)\n else:\n Cov = Xy.copy()\n if Gram is None or Gram is False:\n Gram = None\n if X is None:\n raise ValueError('X and Gram cannot both be unspecified.')\n elif isinstance(Gram, str) and Gram == 'auto' or Gram is True:\n if Gram is True or X.shape[0] > X.shape[1]:\n Gram = np.dot(X.T, X)\n else:\n Gram = None\n elif copy_Gram:\n Gram = Gram.copy()\n if Gram is None:\n n_features = X.shape[1]\n else:\n n_features = Cov.shape[0]\n if Gram.shape != (n_features, n_features):\n raise ValueError('The shapes of the inputs Gram and Xy do not match.')\n if copy_X and X is not None and Gram is None:\n X = X.copy('F')\n max_features = min(max_iter, n_features)\n dtypes = set((a.dtype for a in (X, y, Xy, Gram) if a is not None))\n if len(dtypes) == 1:\n return_dtype = next(iter(dtypes))\n else:\n return_dtype = np.float64\n if return_path:\n coefs = np.zeros((max_features + 1, n_features), dtype=return_dtype)\n alphas = np.zeros(max_features + 1, dtype=return_dtype)\n else:\n (coef, prev_coef) = (np.zeros(n_features, dtype=return_dtype), np.zeros(n_features, dtype=return_dtype))\n (alpha, prev_alpha) = (np.array([0.0], dtype=return_dtype), np.array([0.0], dtype=return_dtype))\n (n_iter, n_active) = (0, 0)\n (active, indices) = (list(), np.arange(n_features))\n sign_active = np.empty(max_features, dtype=np.int8)\n drop = False\n if Gram is None:\n L = np.empty((max_features, max_features), dtype=X.dtype)\n (swap, nrm2) = linalg.get_blas_funcs(('swap', 'nrm2'), (X, ))\n else:\n L = np.empty((max_features, max_features), dtype=Gram.dtype)\n (swap, nrm2) = linalg.get_blas_funcs(('swap', 'nrm2'), (Cov, ))\n (solve_cholesky, ) = get_lapack_funcs(('potrs', ), (L, ))\n if verbose:\n if verbose > 1:\n print('Step\\t\\tAdded\\t\\tDropped\\t\\tActive set size\\t\\tC')\n else:\n sys.stdout.write('.')\n sys.stdout.flush()\n tiny32 = np.finfo(np.float32).tiny\n cov_precision = np.finfo(Cov.dtype).precision\n equality_tolerance = np.finfo(np.float32).eps\n if Gram is not None:\n Gram_copy = Gram.copy()\n Cov_copy = Cov.copy()\n while True:\n if Cov.size:\n if positive:\n C_idx = np.argmax(Cov)\n else:\n C_idx = np.argmax(np.abs(Cov))\n C_ = Cov[C_idx]\n if positive:\n C = C_\n else:\n C = np.fabs(C_)\n else:\n C = 0.0\n if return_path:\n alpha = alphas[n_iter, np.newaxis]\n coef = coefs[n_iter]\n prev_alpha = alphas[n_iter - 1, np.newaxis]\n prev_coef = coefs[n_iter - 1]\n alpha[0] = C / n_samples\n if alpha[0] <= alpha_min + equality_tolerance:\n if abs(alpha[0] - alpha_min) > equality_tolerance:\n if n_iter > 0:\n ss = (prev_alpha[0] - alpha_min) / (prev_alpha[0] - alpha[0])\n coef[:] = prev_coef + ss * (coef - prev_coef)\n alpha[0] = alpha_min\n if return_path:\n coefs[n_iter] = coef\n break\n if n_iter >= max_iter or n_active >= n_features:\n break\n if not drop:\n if positive:\n sign_active[n_active] = np.ones_like(C_)\n else:\n sign_active[n_active] = np.sign(C_)\n (m, n) = (n_active, C_idx + n_active)\n (Cov[C_idx], Cov[0]) = swap(Cov[C_idx], Cov[0])\n (indices[n], indices[m]) = (indices[m], indices[n])\n Cov_not_shortened = Cov\n Cov = Cov[1:]\n if Gram is None:\n (X.T[n], X.T[m]) = swap(X.T[n], X.T[m])\n c = nrm2(X.T[n_active])**2\n L[n_active, :n_active] = np.dot(X.T[n_active], X.T[:n_active].T)\n else:\n (Gram[m], Gram[n]) = swap(Gram[m], Gram[n])\n (Gram[:, m], Gram[:, n]) = swap(Gram[:, m], Gram[:, n])\n c = Gram[n_active, n_active]\n L[n_active, :n_active] = Gram[n_active, :n_active]\n if n_active:\n linalg.solve_triangular(L[:n_active, :n_active], L[n_active, :n_active], trans=0, lower=1, overwrite_b=True, **SOLVE_TRIANGULAR_ARGS)\n v = np.dot(L[n_active, :n_active], L[n_active, :n_active])\n diag = max(np.sqrt(np.abs(c - v)), eps)\n L[n_active, n_active] = diag\n if diag < 1e-07:\n warnings.warn('Regressors in active set degenerate. Dropping a regressor, after %i iterations, i.e. alpha=%.3e, with an active set of %i regressors, and the smallest cholesky pivot element being %.3e. Reduce max_iter or increase eps parameters.' % (n_iter, alpha, n_active, diag), ConvergenceWarning)\n Cov = Cov_not_shortened\n Cov[0] = 0\n (Cov[C_idx], Cov[0]) = swap(Cov[C_idx], Cov[0])\n continue\n active.append(indices[n_active])\n n_active += 1\n if verbose > 1:\n print('%s\\t\\t%s\\t\\t%s\\t\\t%s\\t\\t%s' % (n_iter, active[-1], '', n_active, C))\n if method == 'lasso' and n_iter > 0 and prev_alpha[0] < alpha[0]:\n warnings.warn('Early stopping the lars path, as the residues are small and the current value of alpha is no longer well controlled. %i iterations, alpha=%.3e, previous alpha=%.3e, with an active set of %i regressors.' % (n_iter, alpha, prev_alpha, n_active), ConvergenceWarning)\n break\n (least_squares, _) = solve_cholesky(L[:n_active, :n_active], sign_active[:n_active], lower=True)\n if least_squares.size == 1 and least_squares == 0:\n least_squares[...] = 1\n AA = 1.0\n else:\n AA = 1.0 / np.sqrt(np.sum(least_squares * sign_active[:n_active]))\n if not np.isfinite(AA):\n i = 0\n L_ = L[:n_active, :n_active].copy()\n while not np.isfinite(AA):\n L_.flat[::n_active + 1] += 2**i * eps\n (least_squares, _) = solve_cholesky(L_, sign_active[:n_active], lower=True)\n tmp = max(np.sum(least_squares * sign_active[:n_active]), eps)\n AA = 1.0 / np.sqrt(tmp)\n i += 1\n least_squares *= AA\n if Gram is None:\n eq_dir = np.dot(X.T[:n_active].T, least_squares)\n corr_eq_dir = np.dot(X.T[n_active:], eq_dir)\n else:\n corr_eq_dir = np.dot(Gram[:n_active, n_active:].T, least_squares)\n np.around(corr_eq_dir, decimals=cov_precision, out=corr_eq_dir)\n g1 = arrayfuncs.min_pos((C - Cov) / (AA - corr_eq_dir + tiny32))\n if positive:\n gamma_ = min(g1, C / AA)\n else:\n g2 = arrayfuncs.min_pos((C + Cov) / (AA + corr_eq_dir + tiny32))\n gamma_ = min(g1, g2, C / AA)\n drop = False\n z = -coef[active] / (least_squares + tiny32)\n z_pos = arrayfuncs.min_pos(z)\n if z_pos < gamma_:\n idx = np.where(z == z_pos)[0][::-1]\n sign_active[idx] = -sign_active[idx]\n if method == 'lasso':\n gamma_ = z_pos\n drop = True\n n_iter += 1\n if return_path:\n if n_iter >= coefs.shape[0]:\n del coef, alpha, prev_alpha, prev_coef\n add_features = 2 * max(1, max_features - n_active)\n coefs = np.resize(coefs, (n_iter + add_features, n_features))\n coefs[-add_features:] = 0\n alphas = np.resize(alphas, n_iter + add_features)\n alphas[-add_features:] = 0\n coef = coefs[n_iter]\n prev_coef = coefs[n_iter - 1]\n else:\n prev_coef = coef\n prev_alpha[0] = alpha[0]\n coef = np.zeros_like(coef)\n coef[active] = prev_coef[active] + gamma_ * least_squares\n Cov -= gamma_ * corr_eq_dir\n if drop and method == 'lasso':\n for ii in idx:\n arrayfuncs.cholesky_delete(L[:n_active, :n_active], ii)\n n_active -= 1\n drop_idx = [active.pop(ii) for ii in idx]\n if Gram is None:\n for ii in idx:\n for i in range(ii, n_active):\n (X.T[i], X.T[i + 1]) = swap(X.T[i], X.T[i + 1])\n (indices[i], indices[i + 1]) = (indices[i + 1], indices[i])\n residual = y - np.dot(X[:, :n_active], coef[active])\n temp = np.dot(X.T[n_active], residual)\n Cov = np.r_[temp, Cov]\n else:\n for ii in idx:\n for i in range(ii, n_active):\n (indices[i], indices[i + 1]) = (indices[i + 1], indices[i])\n (Gram[i], Gram[i + 1]) = swap(Gram[i], Gram[i + 1])\n (Gram[:, i], Gram[:, i + 1]) = swap(Gram[:, i], Gram[:, i + 1])\n temp = Cov_copy[drop_idx] - np.dot(Gram_copy[drop_idx], coef)\n Cov = np.r_[temp, Cov]\n sign_active = np.delete(sign_active, idx)\n sign_active = np.append(sign_active, 0.0)\n if verbose > 1:\n print('%s\\t\\t%s\\t\\t%s\\t\\t%s\\t\\t%s' % (n_iter, '', drop_idx, n_active, abs(temp)))\n if return_path:\n alphas = alphas[:n_iter + 1]\n coefs = coefs[:n_iter + 1]\n if return_n_iter:\n return alphas, active, coefs.T, n_iter\n else:\n return alphas, active, coefs.T\n elif return_n_iter:\n return alpha, active, coef, n_iter\n else:\n return alpha, active, coef" }, { "name": "lars_path", + "unique_name": "lars_path", "qname": "sklearn.linear_model._least_angle.lars_path", + "unique_qname": "sklearn.linear_model._least_angle.lars_path", "decorators": [], "parameters": [ { @@ -99193,7 +102513,9 @@ }, { "name": "lars_path_gram", + "unique_name": "lars_path_gram", "qname": "sklearn.linear_model._least_angle.lars_path_gram", + "unique_qname": "sklearn.linear_model._least_angle.lars_path_gram", "decorators": [], "parameters": [ { @@ -99335,7 +102657,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._logistic.LogisticRegression.__init__", + "unique_qname": "sklearn.linear_model._logistic.LogisticRegression.__init__", "decorators": [], "parameters": [ { @@ -99507,7 +102831,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._logistic.LogisticRegression.fit", + "unique_qname": "sklearn.linear_model._logistic.LogisticRegression.fit", "decorators": [], "parameters": [ { @@ -99555,11 +102881,13 @@ "is_public": true, "description": "Fit the model according to the given training data.", "docstring": "Fit the model according to the given training data.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\ny : array-like of shape (n_samples,)\n Target vector relative to X.\n\nsample_weight : array-like of shape (n_samples,) default=None\n Array of weights that are assigned to individual samples.\n If not provided, then each sample is given unit weight.\n\n .. versionadded:: 0.17\n *sample_weight* support to LogisticRegression.\n\nReturns\n-------\nself\n Fitted estimator.\n\nNotes\n-----\nThe SAGA solver supports both float64 and float32 bit arrays.", - "source_code": "\ndef fit(self, X, y, sample_weight=None):\n \"\"\"\n Fit the model according to the given training data.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target vector relative to X.\n\n sample_weight : array-like of shape (n_samples,) default=None\n Array of weights that are assigned to individual samples.\n If not provided, then each sample is given unit weight.\n\n .. versionadded:: 0.17\n *sample_weight* support to LogisticRegression.\n\n Returns\n -------\n self\n Fitted estimator.\n\n Notes\n -----\n The SAGA solver supports both float64 and float32 bit arrays.\n \"\"\"\n solver = _check_solver(self.solver, self.penalty, self.dual)\n if not isinstance(self.C, numbers.Number) or self.C < 0:\n raise ValueError('Penalty term must be positive; got (C=%r)' % self.C)\n if self.penalty == 'elasticnet':\n if not isinstance(self.l1_ratio, numbers.Number) or self.l1_ratio < 0 or self.l1_ratio > 1:\n raise ValueError('l1_ratio must be between 0 and 1; got (l1_ratio=%r)' % self.l1_ratio)\n elif self.l1_ratio is not None:\n warnings.warn(\"l1_ratio parameter is only used when penalty is 'elasticnet'. Got (penalty={})\".format(self.penalty))\n if self.penalty == 'none':\n if self.C != 1.0:\n warnings.warn(\"Setting penalty='none' will ignore the C and l1_ratio parameters\")\n C_ = np.inf\n penalty = 'l2'\n else:\n C_ = self.C\n penalty = self.penalty\n if not isinstance(self.max_iter, numbers.Number) or self.max_iter < 0:\n raise ValueError('Maximum number of iteration must be positive; got (max_iter=%r)' % self.max_iter)\n if not isinstance(self.tol, numbers.Number) or self.tol < 0:\n raise ValueError('Tolerance for stopping criteria must be positive; got (tol=%r)' % self.tol)\n if solver == 'lbfgs':\n _dtype = np.float64\n else:\n _dtype = [np.float64, np.float32]\n (X, y) = self._validate_data(X, y, accept_sparse='csr', dtype=_dtype, order='C', accept_large_sparse=solver != 'liblinear')\n check_classification_targets(y)\n self.classes_ = np.unique(y)\n multi_class = _check_multi_class(self.multi_class, solver, len(self.classes_))\n if solver == 'liblinear':\n if effective_n_jobs(self.n_jobs) != 1:\n warnings.warn(\"'n_jobs' > 1 does not have any effect when 'solver' is set to 'liblinear'. Got 'n_jobs' = {}.\".format(effective_n_jobs(self.n_jobs)))\n (self.coef_, self.intercept_, n_iter_) = _fit_liblinear(X, y, self.C, self.fit_intercept, self.intercept_scaling, self.class_weight, self.penalty, self.dual, self.verbose, self.max_iter, self.tol, self.random_state, sample_weight=sample_weight)\n self.n_iter_ = np.array([n_iter_])\n return self\n if solver in ['sag', 'saga']:\n max_squared_sum = row_norms(X, squared=True).max()\n else:\n max_squared_sum = None\n n_classes = len(self.classes_)\n classes_ = self.classes_\n if n_classes < 2:\n raise ValueError('This solver needs samples of at least 2 classes in the data, but the data contains only one class: %r' % classes_[0])\n if len(self.classes_) == 2:\n n_classes = 1\n classes_ = classes_[1:]\n if self.warm_start:\n warm_start_coef = getattr(self, 'coef_', None)\n else:\n warm_start_coef = None\n if warm_start_coef is not None and self.fit_intercept:\n warm_start_coef = np.append(warm_start_coef, self.intercept_[:, np.newaxis], axis=1)\n if multi_class == 'multinomial':\n classes_ = [None]\n warm_start_coef = [warm_start_coef]\n if warm_start_coef is None:\n warm_start_coef = [None] * n_classes\n path_func = delayed(_logistic_regression_path)\n if solver in ['sag', 'saga']:\n prefer = 'threads'\n else:\n prefer = 'processes'\n fold_coefs_ = Parallel(n_jobs=self.n_jobs, verbose=self.verbose, **_joblib_parallel_args(prefer=prefer))((path_func(X, y, pos_class=class_, Cs=[C_], l1_ratio=self.l1_ratio, fit_intercept=self.fit_intercept, tol=self.tol, verbose=self.verbose, solver=solver, multi_class=multi_class, max_iter=self.max_iter, class_weight=self.class_weight, check_input=False, random_state=self.random_state, coef=warm_start_coef_, penalty=penalty, max_squared_sum=max_squared_sum, sample_weight=sample_weight) for (class_, warm_start_coef_) in zip(classes_, warm_start_coef)))\n (fold_coefs_, _, n_iter_) = zip(*fold_coefs_)\n self.n_iter_ = np.asarray(n_iter_, dtype=np.int32)[:, 0]\n n_features = X.shape[1]\n if multi_class == 'multinomial':\n self.coef_ = fold_coefs_[0][0]\n else:\n self.coef_ = np.asarray(fold_coefs_)\n self.coef_ = self.coef_.reshape(n_classes, n_features + int(self.fit_intercept))\n if self.fit_intercept:\n self.intercept_ = self.coef_[:, -1]\n self.coef_ = self.coef_[:, :-1]\n else:\n self.intercept_ = np.zeros(n_classes)\n return self" + "source_code": "\ndef fit(self, X, y, sample_weight=None):\n \"\"\"\n Fit the model according to the given training data.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target vector relative to X.\n\n sample_weight : array-like of shape (n_samples,) default=None\n Array of weights that are assigned to individual samples.\n If not provided, then each sample is given unit weight.\n\n .. versionadded:: 0.17\n *sample_weight* support to LogisticRegression.\n\n Returns\n -------\n self\n Fitted estimator.\n\n Notes\n -----\n The SAGA solver supports both float64 and float32 bit arrays.\n \"\"\"\n solver = _check_solver(self.solver, self.penalty, self.dual)\n if not isinstance(self.C, numbers.Number) or self.C < 0:\n raise ValueError('Penalty term must be positive; got (C=%r)' % self.C)\n if self.penalty == 'elasticnet':\n if not isinstance(self.l1_ratio, numbers.Number) or self.l1_ratio < 0 or self.l1_ratio > 1:\n raise ValueError('l1_ratio must be between 0 and 1; got (l1_ratio=%r)' % self.l1_ratio)\n elif self.l1_ratio is not None:\n warnings.warn(\"l1_ratio parameter is only used when penalty is 'elasticnet'. Got (penalty={})\".format(self.penalty))\n if self.penalty == 'none':\n if self.C != 1.0:\n warnings.warn(\"Setting penalty='none' will ignore the C and l1_ratio parameters\")\n C_ = np.inf\n penalty = 'l2'\n else:\n C_ = self.C\n penalty = self.penalty\n if not isinstance(self.max_iter, numbers.Number) or self.max_iter < 0:\n raise ValueError('Maximum number of iteration must be positive; got (max_iter=%r)' % self.max_iter)\n if not isinstance(self.tol, numbers.Number) or self.tol < 0:\n raise ValueError('Tolerance for stopping criteria must be positive; got (tol=%r)' % self.tol)\n if solver == 'lbfgs':\n _dtype = np.float64\n else:\n _dtype = [np.float64, np.float32]\n (X, y) = self._validate_data(X, y, accept_sparse='csr', dtype=_dtype, order='C', accept_large_sparse=solver not in ['liblinear', 'sag', 'saga'])\n check_classification_targets(y)\n self.classes_ = np.unique(y)\n multi_class = _check_multi_class(self.multi_class, solver, len(self.classes_))\n if solver == 'liblinear':\n if effective_n_jobs(self.n_jobs) != 1:\n warnings.warn(\"'n_jobs' > 1 does not have any effect when 'solver' is set to 'liblinear'. Got 'n_jobs' = {}.\".format(effective_n_jobs(self.n_jobs)))\n (self.coef_, self.intercept_, n_iter_) = _fit_liblinear(X, y, self.C, self.fit_intercept, self.intercept_scaling, self.class_weight, self.penalty, self.dual, self.verbose, self.max_iter, self.tol, self.random_state, sample_weight=sample_weight)\n self.n_iter_ = np.array([n_iter_])\n return self\n if solver in ['sag', 'saga']:\n max_squared_sum = row_norms(X, squared=True).max()\n else:\n max_squared_sum = None\n n_classes = len(self.classes_)\n classes_ = self.classes_\n if n_classes < 2:\n raise ValueError('This solver needs samples of at least 2 classes in the data, but the data contains only one class: %r' % classes_[0])\n if len(self.classes_) == 2:\n n_classes = 1\n classes_ = classes_[1:]\n if self.warm_start:\n warm_start_coef = getattr(self, 'coef_', None)\n else:\n warm_start_coef = None\n if warm_start_coef is not None and self.fit_intercept:\n warm_start_coef = np.append(warm_start_coef, self.intercept_[:, np.newaxis], axis=1)\n if multi_class == 'multinomial':\n classes_ = [None]\n warm_start_coef = [warm_start_coef]\n if warm_start_coef is None:\n warm_start_coef = [None] * n_classes\n path_func = delayed(_logistic_regression_path)\n if solver in ['sag', 'saga']:\n prefer = 'threads'\n else:\n prefer = 'processes'\n fold_coefs_ = Parallel(n_jobs=self.n_jobs, verbose=self.verbose, **_joblib_parallel_args(prefer=prefer))((path_func(X, y, pos_class=class_, Cs=[C_], l1_ratio=self.l1_ratio, fit_intercept=self.fit_intercept, tol=self.tol, verbose=self.verbose, solver=solver, multi_class=multi_class, max_iter=self.max_iter, class_weight=self.class_weight, check_input=False, random_state=self.random_state, coef=warm_start_coef_, penalty=penalty, max_squared_sum=max_squared_sum, sample_weight=sample_weight) for (class_, warm_start_coef_) in zip(classes_, warm_start_coef)))\n (fold_coefs_, _, n_iter_) = zip(*fold_coefs_)\n self.n_iter_ = np.asarray(n_iter_, dtype=np.int32)[:, 0]\n n_features = X.shape[1]\n if multi_class == 'multinomial':\n self.coef_ = fold_coefs_[0][0]\n else:\n self.coef_ = np.asarray(fold_coefs_)\n self.coef_ = self.coef_.reshape(n_classes, n_features + int(self.fit_intercept))\n if self.fit_intercept:\n self.intercept_ = self.coef_[:, -1]\n self.coef_ = self.coef_[:, :-1]\n else:\n self.intercept_ = np.zeros(n_classes)\n return self" }, { "name": "predict_log_proba", + "unique_name": "predict_log_proba", "qname": "sklearn.linear_model._logistic.LogisticRegression.predict_log_proba", + "unique_qname": "sklearn.linear_model._logistic.LogisticRegression.predict_log_proba", "decorators": [], "parameters": [ { @@ -99591,7 +102919,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.linear_model._logistic.LogisticRegression.predict_proba", + "unique_qname": "sklearn.linear_model._logistic.LogisticRegression.predict_proba", "decorators": [], "parameters": [ { @@ -99623,7 +102953,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._logistic.LogisticRegressionCV.__init__", + "unique_qname": "sklearn.linear_model._logistic.LogisticRegressionCV.__init__", "decorators": [], "parameters": [ { @@ -99815,7 +103147,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.linear_model._logistic.LogisticRegressionCV._more_tags", + "unique_qname": "sklearn.linear_model._logistic.LogisticRegressionCV._more_tags", "decorators": [], "parameters": [ { @@ -99837,7 +103171,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._logistic.LogisticRegressionCV.fit", + "unique_qname": "sklearn.linear_model._logistic.LogisticRegressionCV.fit", "decorators": [], "parameters": [ { @@ -99885,11 +103221,13 @@ "is_public": true, "description": "Fit the model according to the given training data.", "docstring": "Fit the model according to the given training data.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\ny : array-like of shape (n_samples,)\n Target vector relative to X.\n\nsample_weight : array-like of shape (n_samples,) default=None\n Array of weights that are assigned to individual samples.\n If not provided, then each sample is given unit weight.\n\nReturns\n-------\nself : object\n Fitted LogisticRegressionCV estimator.", - "source_code": "\ndef fit(self, X, y, sample_weight=None):\n \"\"\"Fit the model according to the given training data.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target vector relative to X.\n\n sample_weight : array-like of shape (n_samples,) default=None\n Array of weights that are assigned to individual samples.\n If not provided, then each sample is given unit weight.\n\n Returns\n -------\n self : object\n Fitted LogisticRegressionCV estimator.\n \"\"\"\n solver = _check_solver(self.solver, self.penalty, self.dual)\n if not isinstance(self.max_iter, numbers.Number) or self.max_iter < 0:\n raise ValueError('Maximum number of iteration must be positive; got (max_iter=%r)' % self.max_iter)\n if not isinstance(self.tol, numbers.Number) or self.tol < 0:\n raise ValueError('Tolerance for stopping criteria must be positive; got (tol=%r)' % self.tol)\n if self.penalty == 'elasticnet':\n if self.l1_ratios is None or len(self.l1_ratios) == 0 or any((not isinstance(l1_ratio, numbers.Number) or l1_ratio < 0 or l1_ratio > 1 for l1_ratio in self.l1_ratios)):\n raise ValueError('l1_ratios must be a list of numbers between 0 and 1; got (l1_ratios=%r)' % self.l1_ratios)\n l1_ratios_ = self.l1_ratios\n else:\n if self.l1_ratios is not None:\n warnings.warn(\"l1_ratios parameter is only used when penalty is 'elasticnet'. Got (penalty={})\".format(self.penalty))\n l1_ratios_ = [None]\n if self.penalty == 'none':\n raise ValueError(\"penalty='none' is not useful and not supported by LogisticRegressionCV.\")\n (X, y) = self._validate_data(X, y, accept_sparse='csr', dtype=np.float64, order='C', accept_large_sparse=solver != 'liblinear')\n check_classification_targets(y)\n class_weight = self.class_weight\n label_encoder = LabelEncoder().fit(y)\n y = label_encoder.transform(y)\n if isinstance(class_weight, dict):\n class_weight = {label_encoder.transform([cls])[0]: v for (cls, v) in class_weight.items()}\n classes = self.classes_ = label_encoder.classes_\n encoded_labels = label_encoder.transform(label_encoder.classes_)\n multi_class = _check_multi_class(self.multi_class, solver, len(classes))\n if solver in ['sag', 'saga']:\n max_squared_sum = row_norms(X, squared=True).max()\n else:\n max_squared_sum = None\n cv = check_cv(self.cv, y, classifier=True)\n folds = list(cv.split(X, y))\n n_classes = len(encoded_labels)\n if n_classes < 2:\n raise ValueError('This solver needs samples of at least 2 classes in the data, but the data contains only one class: %r' % classes[0])\n if n_classes == 2:\n n_classes = 1\n encoded_labels = encoded_labels[1:]\n classes = classes[1:]\n if multi_class == 'multinomial':\n iter_encoded_labels = iter_classes = [None]\n else:\n iter_encoded_labels = encoded_labels\n iter_classes = classes\n if class_weight == 'balanced':\n class_weight = compute_class_weight(class_weight, classes=np.arange(len(self.classes_)), y=y)\n class_weight = dict(enumerate(class_weight))\n path_func = delayed(_log_reg_scoring_path)\n if self.solver in ['sag', 'saga']:\n prefer = 'threads'\n else:\n prefer = 'processes'\n fold_coefs_ = Parallel(n_jobs=self.n_jobs, verbose=self.verbose, **_joblib_parallel_args(prefer=prefer))((path_func(X, y, train, test, pos_class=label, Cs=self.Cs, fit_intercept=self.fit_intercept, penalty=self.penalty, dual=self.dual, solver=solver, tol=self.tol, max_iter=self.max_iter, verbose=self.verbose, class_weight=class_weight, scoring=self.scoring, multi_class=multi_class, intercept_scaling=self.intercept_scaling, random_state=self.random_state, max_squared_sum=max_squared_sum, sample_weight=sample_weight, l1_ratio=l1_ratio) for label in iter_encoded_labels for (train, test) in folds for l1_ratio in l1_ratios_))\n (coefs_paths, Cs, scores, n_iter_) = zip(*fold_coefs_)\n self.Cs_ = Cs[0]\n if multi_class == 'multinomial':\n coefs_paths = np.reshape(coefs_paths, (len(folds), len(l1_ratios_) * len(self.Cs_), n_classes, -1))\n coefs_paths = np.swapaxes(coefs_paths, 0, 1)\n coefs_paths = np.swapaxes(coefs_paths, 0, 2)\n self.n_iter_ = np.reshape(n_iter_, (1, len(folds), len(self.Cs_) * len(l1_ratios_)))\n scores = np.tile(scores, (n_classes, 1, 1))\n else:\n coefs_paths = np.reshape(coefs_paths, (n_classes, len(folds), len(self.Cs_) * len(l1_ratios_), -1))\n self.n_iter_ = np.reshape(n_iter_, (n_classes, len(folds), len(self.Cs_) * len(l1_ratios_)))\n scores = np.reshape(scores, (n_classes, len(folds), -1))\n self.scores_ = dict(zip(classes, scores))\n self.coefs_paths_ = dict(zip(classes, coefs_paths))\n self.C_ = list()\n self.l1_ratio_ = list()\n self.coef_ = np.empty((n_classes, X.shape[1]))\n self.intercept_ = np.zeros(n_classes)\n for (index, (cls, encoded_label)) in enumerate(zip(iter_classes, iter_encoded_labels)):\n if multi_class == 'ovr':\n scores = self.scores_[cls]\n coefs_paths = self.coefs_paths_[cls]\n else:\n scores = scores[0]\n if self.refit:\n best_index = scores.sum(axis=0).argmax()\n best_index_C = best_index % len(self.Cs_)\n C_ = self.Cs_[best_index_C]\n self.C_.append(C_)\n best_index_l1 = best_index // len(self.Cs_)\n l1_ratio_ = l1_ratios_[best_index_l1]\n self.l1_ratio_.append(l1_ratio_)\n if multi_class == 'multinomial':\n coef_init = np.mean(coefs_paths[:, :, best_index, :], axis=1)\n else:\n coef_init = np.mean(coefs_paths[:, best_index, :], axis=0)\n (w, _, _) = _logistic_regression_path(X, y, pos_class=encoded_label, Cs=[C_], solver=solver, fit_intercept=self.fit_intercept, coef=coef_init, max_iter=self.max_iter, tol=self.tol, penalty=self.penalty, class_weight=class_weight, multi_class=multi_class, verbose=max(0, self.verbose - 1), random_state=self.random_state, check_input=False, max_squared_sum=max_squared_sum, sample_weight=sample_weight, l1_ratio=l1_ratio_)\n w = w[0]\n else:\n best_indices = np.argmax(scores, axis=1)\n if multi_class == 'ovr':\n w = np.mean([coefs_paths[i, best_indices[i], :] for i in range(len(folds))], axis=0)\n else:\n w = np.mean([coefs_paths[:, i, best_indices[i], :] for i in range(len(folds))], axis=0)\n best_indices_C = best_indices % len(self.Cs_)\n self.C_.append(np.mean(self.Cs_[best_indices_C]))\n if self.penalty == 'elasticnet':\n best_indices_l1 = best_indices // len(self.Cs_)\n self.l1_ratio_.append(np.mean(l1_ratios_[best_indices_l1]))\n else:\n self.l1_ratio_.append(None)\n if multi_class == 'multinomial':\n self.C_ = np.tile(self.C_, n_classes)\n self.l1_ratio_ = np.tile(self.l1_ratio_, n_classes)\n self.coef_ = w[:, :X.shape[1]]\n if self.fit_intercept:\n self.intercept_ = w[:, -1]\n else:\n self.coef_[index] = w[:X.shape[1]]\n if self.fit_intercept:\n self.intercept_[index] = w[-1]\n self.C_ = np.asarray(self.C_)\n self.l1_ratio_ = np.asarray(self.l1_ratio_)\n self.l1_ratios_ = np.asarray(l1_ratios_)\n if self.l1_ratios is not None:\n for (cls, coefs_path) in self.coefs_paths_.items():\n self.coefs_paths_[cls] = coefs_path.reshape((len(folds), self.l1_ratios_.size, self.Cs_.size, -1))\n self.coefs_paths_[cls] = np.transpose(self.coefs_paths_[cls], (0, 2, 1, 3))\n for (cls, score) in self.scores_.items():\n self.scores_[cls] = score.reshape((len(folds), self.l1_ratios_.size, self.Cs_.size))\n self.scores_[cls] = np.transpose(self.scores_[cls], (0, 2, 1))\n self.n_iter_ = self.n_iter_.reshape((-1, len(folds), self.l1_ratios_.size, self.Cs_.size))\n self.n_iter_ = np.transpose(self.n_iter_, (0, 1, 3, 2))\n return self" + "source_code": "\ndef fit(self, X, y, sample_weight=None):\n \"\"\"Fit the model according to the given training data.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target vector relative to X.\n\n sample_weight : array-like of shape (n_samples,) default=None\n Array of weights that are assigned to individual samples.\n If not provided, then each sample is given unit weight.\n\n Returns\n -------\n self : object\n Fitted LogisticRegressionCV estimator.\n \"\"\"\n solver = _check_solver(self.solver, self.penalty, self.dual)\n if not isinstance(self.max_iter, numbers.Number) or self.max_iter < 0:\n raise ValueError('Maximum number of iteration must be positive; got (max_iter=%r)' % self.max_iter)\n if not isinstance(self.tol, numbers.Number) or self.tol < 0:\n raise ValueError('Tolerance for stopping criteria must be positive; got (tol=%r)' % self.tol)\n if self.penalty == 'elasticnet':\n if self.l1_ratios is None or len(self.l1_ratios) == 0 or any((not isinstance(l1_ratio, numbers.Number) or l1_ratio < 0 or l1_ratio > 1 for l1_ratio in self.l1_ratios)):\n raise ValueError('l1_ratios must be a list of numbers between 0 and 1; got (l1_ratios=%r)' % self.l1_ratios)\n l1_ratios_ = self.l1_ratios\n else:\n if self.l1_ratios is not None:\n warnings.warn(\"l1_ratios parameter is only used when penalty is 'elasticnet'. Got (penalty={})\".format(self.penalty))\n l1_ratios_ = [None]\n if self.penalty == 'none':\n raise ValueError(\"penalty='none' is not useful and not supported by LogisticRegressionCV.\")\n (X, y) = self._validate_data(X, y, accept_sparse='csr', dtype=np.float64, order='C', accept_large_sparse=solver not in ['liblinear', 'sag', 'saga'])\n check_classification_targets(y)\n class_weight = self.class_weight\n label_encoder = LabelEncoder().fit(y)\n y = label_encoder.transform(y)\n if isinstance(class_weight, dict):\n class_weight = {label_encoder.transform([cls])[0]: v for (cls, v) in class_weight.items()}\n classes = self.classes_ = label_encoder.classes_\n encoded_labels = label_encoder.transform(label_encoder.classes_)\n multi_class = _check_multi_class(self.multi_class, solver, len(classes))\n if solver in ['sag', 'saga']:\n max_squared_sum = row_norms(X, squared=True).max()\n else:\n max_squared_sum = None\n cv = check_cv(self.cv, y, classifier=True)\n folds = list(cv.split(X, y))\n n_classes = len(encoded_labels)\n if n_classes < 2:\n raise ValueError('This solver needs samples of at least 2 classes in the data, but the data contains only one class: %r' % classes[0])\n if n_classes == 2:\n n_classes = 1\n encoded_labels = encoded_labels[1:]\n classes = classes[1:]\n if multi_class == 'multinomial':\n iter_encoded_labels = iter_classes = [None]\n else:\n iter_encoded_labels = encoded_labels\n iter_classes = classes\n if class_weight == 'balanced':\n class_weight = compute_class_weight(class_weight, classes=np.arange(len(self.classes_)), y=y)\n class_weight = dict(enumerate(class_weight))\n path_func = delayed(_log_reg_scoring_path)\n if self.solver in ['sag', 'saga']:\n prefer = 'threads'\n else:\n prefer = 'processes'\n fold_coefs_ = Parallel(n_jobs=self.n_jobs, verbose=self.verbose, **_joblib_parallel_args(prefer=prefer))((path_func(X, y, train, test, pos_class=label, Cs=self.Cs, fit_intercept=self.fit_intercept, penalty=self.penalty, dual=self.dual, solver=solver, tol=self.tol, max_iter=self.max_iter, verbose=self.verbose, class_weight=class_weight, scoring=self.scoring, multi_class=multi_class, intercept_scaling=self.intercept_scaling, random_state=self.random_state, max_squared_sum=max_squared_sum, sample_weight=sample_weight, l1_ratio=l1_ratio) for label in iter_encoded_labels for (train, test) in folds for l1_ratio in l1_ratios_))\n (coefs_paths, Cs, scores, n_iter_) = zip(*fold_coefs_)\n self.Cs_ = Cs[0]\n if multi_class == 'multinomial':\n coefs_paths = np.reshape(coefs_paths, (len(folds), len(l1_ratios_) * len(self.Cs_), n_classes, -1))\n coefs_paths = np.swapaxes(coefs_paths, 0, 1)\n coefs_paths = np.swapaxes(coefs_paths, 0, 2)\n self.n_iter_ = np.reshape(n_iter_, (1, len(folds), len(self.Cs_) * len(l1_ratios_)))\n scores = np.tile(scores, (n_classes, 1, 1))\n else:\n coefs_paths = np.reshape(coefs_paths, (n_classes, len(folds), len(self.Cs_) * len(l1_ratios_), -1))\n self.n_iter_ = np.reshape(n_iter_, (n_classes, len(folds), len(self.Cs_) * len(l1_ratios_)))\n scores = np.reshape(scores, (n_classes, len(folds), -1))\n self.scores_ = dict(zip(classes, scores))\n self.coefs_paths_ = dict(zip(classes, coefs_paths))\n self.C_ = list()\n self.l1_ratio_ = list()\n self.coef_ = np.empty((n_classes, X.shape[1]))\n self.intercept_ = np.zeros(n_classes)\n for (index, (cls, encoded_label)) in enumerate(zip(iter_classes, iter_encoded_labels)):\n if multi_class == 'ovr':\n scores = self.scores_[cls]\n coefs_paths = self.coefs_paths_[cls]\n else:\n scores = scores[0]\n if self.refit:\n best_index = scores.sum(axis=0).argmax()\n best_index_C = best_index % len(self.Cs_)\n C_ = self.Cs_[best_index_C]\n self.C_.append(C_)\n best_index_l1 = best_index // len(self.Cs_)\n l1_ratio_ = l1_ratios_[best_index_l1]\n self.l1_ratio_.append(l1_ratio_)\n if multi_class == 'multinomial':\n coef_init = np.mean(coefs_paths[:, :, best_index, :], axis=1)\n else:\n coef_init = np.mean(coefs_paths[:, best_index, :], axis=0)\n (w, _, _) = _logistic_regression_path(X, y, pos_class=encoded_label, Cs=[C_], solver=solver, fit_intercept=self.fit_intercept, coef=coef_init, max_iter=self.max_iter, tol=self.tol, penalty=self.penalty, class_weight=class_weight, multi_class=multi_class, verbose=max(0, self.verbose - 1), random_state=self.random_state, check_input=False, max_squared_sum=max_squared_sum, sample_weight=sample_weight, l1_ratio=l1_ratio_)\n w = w[0]\n else:\n best_indices = np.argmax(scores, axis=1)\n if multi_class == 'ovr':\n w = np.mean([coefs_paths[i, best_indices[i], :] for i in range(len(folds))], axis=0)\n else:\n w = np.mean([coefs_paths[:, i, best_indices[i], :] for i in range(len(folds))], axis=0)\n best_indices_C = best_indices % len(self.Cs_)\n self.C_.append(np.mean(self.Cs_[best_indices_C]))\n if self.penalty == 'elasticnet':\n best_indices_l1 = best_indices // len(self.Cs_)\n self.l1_ratio_.append(np.mean(l1_ratios_[best_indices_l1]))\n else:\n self.l1_ratio_.append(None)\n if multi_class == 'multinomial':\n self.C_ = np.tile(self.C_, n_classes)\n self.l1_ratio_ = np.tile(self.l1_ratio_, n_classes)\n self.coef_ = w[:, :X.shape[1]]\n if self.fit_intercept:\n self.intercept_ = w[:, -1]\n else:\n self.coef_[index] = w[:X.shape[1]]\n if self.fit_intercept:\n self.intercept_[index] = w[-1]\n self.C_ = np.asarray(self.C_)\n self.l1_ratio_ = np.asarray(self.l1_ratio_)\n self.l1_ratios_ = np.asarray(l1_ratios_)\n if self.l1_ratios is not None:\n for (cls, coefs_path) in self.coefs_paths_.items():\n self.coefs_paths_[cls] = coefs_path.reshape((len(folds), self.l1_ratios_.size, self.Cs_.size, -1))\n self.coefs_paths_[cls] = np.transpose(self.coefs_paths_[cls], (0, 2, 1, 3))\n for (cls, score) in self.scores_.items():\n self.scores_[cls] = score.reshape((len(folds), self.l1_ratios_.size, self.Cs_.size))\n self.scores_[cls] = np.transpose(self.scores_[cls], (0, 2, 1))\n self.n_iter_ = self.n_iter_.reshape((-1, len(folds), self.l1_ratios_.size, self.Cs_.size))\n self.n_iter_ = np.transpose(self.n_iter_, (0, 1, 3, 2))\n return self" }, { "name": "score", + "unique_name": "score", "qname": "sklearn.linear_model._logistic.LogisticRegressionCV.score", + "unique_qname": "sklearn.linear_model._logistic.LogisticRegressionCV.score", "decorators": [], "parameters": [ { @@ -99941,7 +103279,9 @@ }, { "name": "_check_multi_class", + "unique_name": "_check_multi_class", "qname": "sklearn.linear_model._logistic._check_multi_class", + "unique_qname": "sklearn.linear_model._logistic._check_multi_class", "decorators": [], "parameters": [ { @@ -99983,7 +103323,9 @@ }, { "name": "_check_solver", + "unique_name": "_check_solver", "qname": "sklearn.linear_model._logistic._check_solver", + "unique_qname": "sklearn.linear_model._logistic._check_solver", "decorators": [], "parameters": [ { @@ -100025,7 +103367,9 @@ }, { "name": "_intercept_dot", + "unique_name": "_intercept_dot", "qname": "sklearn.linear_model._logistic._intercept_dot", + "unique_qname": "sklearn.linear_model._logistic._intercept_dot", "decorators": [], "parameters": [ { @@ -100067,7 +103411,9 @@ }, { "name": "_log_reg_scoring_path", + "unique_name": "_log_reg_scoring_path", "qname": "sklearn.linear_model._logistic._log_reg_scoring_path", + "unique_qname": "sklearn.linear_model._logistic._log_reg_scoring_path", "decorators": [], "parameters": [ { @@ -100289,7 +103635,9 @@ }, { "name": "_logistic_grad_hess", + "unique_name": "_logistic_grad_hess", "qname": "sklearn.linear_model._logistic._logistic_grad_hess", + "unique_qname": "sklearn.linear_model._logistic._logistic_grad_hess", "decorators": [], "parameters": [ { @@ -100351,7 +103699,9 @@ }, { "name": "_logistic_loss", + "unique_name": "_logistic_loss", "qname": "sklearn.linear_model._logistic._logistic_loss", + "unique_qname": "sklearn.linear_model._logistic._logistic_loss", "decorators": [], "parameters": [ { @@ -100413,7 +103763,9 @@ }, { "name": "_logistic_loss_and_grad", + "unique_name": "_logistic_loss_and_grad", "qname": "sklearn.linear_model._logistic._logistic_loss_and_grad", + "unique_qname": "sklearn.linear_model._logistic._logistic_loss_and_grad", "decorators": [], "parameters": [ { @@ -100475,7 +103827,9 @@ }, { "name": "_logistic_regression_path", + "unique_name": "_logistic_regression_path", "qname": "sklearn.linear_model._logistic._logistic_regression_path", + "unique_qname": "sklearn.linear_model._logistic._logistic_regression_path", "decorators": [], "parameters": [ { @@ -100683,11 +104037,13 @@ "is_public": false, "description": "Compute a Logistic Regression model for a list of regularization parameters.\n\nThis is an implementation that uses the result of the previous model to speed up computations along the set of solutions, making it faster than sequentially calling LogisticRegression for the different parameters. Note that there will be no speedup with liblinear solver, since it does not handle warm-starting. Read more in the :ref:`User Guide `.", "docstring": "Compute a Logistic Regression model for a list of regularization\nparameters.\n\nThis is an implementation that uses the result of the previous model\nto speed up computations along the set of solutions, making it faster\nthan sequentially calling LogisticRegression for the different parameters.\nNote that there will be no speedup with liblinear solver, since it does\nnot handle warm-starting.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input data.\n\ny : array-like of shape (n_samples,) or (n_samples, n_targets)\n Input data, target values.\n\npos_class : int, default=None\n The class with respect to which we perform a one-vs-all fit.\n If None, then it is assumed that the given problem is binary.\n\nCs : int or array-like of shape (n_cs,), default=10\n List of values for the regularization parameter or integer specifying\n the number of regularization parameters that should be used. In this\n case, the parameters will be chosen in a logarithmic scale between\n 1e-4 and 1e4.\n\nfit_intercept : bool, default=True\n Whether to fit an intercept for the model. In this case the shape of\n the returned array is (n_cs, n_features + 1).\n\nmax_iter : int, default=100\n Maximum number of iterations for the solver.\n\ntol : float, default=1e-4\n Stopping criterion. For the newton-cg and lbfgs solvers, the iteration\n will stop when ``max{|g_i | i = 1, ..., n} <= tol``\n where ``g_i`` is the i-th component of the gradient.\n\nverbose : int, default=0\n For the liblinear and lbfgs solvers set verbose to any positive\n number for verbosity.\n\nsolver : {'lbfgs', 'newton-cg', 'liblinear', 'sag', 'saga'}, default='lbfgs'\n Numerical solver to use.\n\ncoef : array-like of shape (n_features,), default=None\n Initialization value for coefficients of logistic regression.\n Useless for liblinear solver.\n\nclass_weight : dict or 'balanced', default=None\n Weights associated with classes in the form ``{class_label: weight}``.\n If not given, all classes are supposed to have weight one.\n\n The \"balanced\" mode uses the values of y to automatically adjust\n weights inversely proportional to class frequencies in the input data\n as ``n_samples / (n_classes * np.bincount(y))``.\n\n Note that these weights will be multiplied with sample_weight (passed\n through the fit method) if sample_weight is specified.\n\ndual : bool, default=False\n Dual or primal formulation. Dual formulation is only implemented for\n l2 penalty with liblinear solver. Prefer dual=False when\n n_samples > n_features.\n\npenalty : {'l1', 'l2', 'elasticnet'}, default='l2'\n Used to specify the norm used in the penalization. The 'newton-cg',\n 'sag' and 'lbfgs' solvers support only l2 penalties. 'elasticnet' is\n only supported by the 'saga' solver.\n\nintercept_scaling : float, default=1.\n Useful only when the solver 'liblinear' is used\n and self.fit_intercept is set to True. In this case, x becomes\n [x, self.intercept_scaling],\n i.e. a \"synthetic\" feature with constant value equal to\n intercept_scaling is appended to the instance vector.\n The intercept becomes ``intercept_scaling * synthetic_feature_weight``.\n\n Note! the synthetic feature weight is subject to l1/l2 regularization\n as all other features.\n To lessen the effect of regularization on synthetic feature weight\n (and therefore on the intercept) intercept_scaling has to be increased.\n\nmulti_class : {'ovr', 'multinomial', 'auto'}, default='auto'\n If the option chosen is 'ovr', then a binary problem is fit for each\n label. For 'multinomial' the loss minimised is the multinomial loss fit\n across the entire probability distribution, *even when the data is\n binary*. 'multinomial' is unavailable when solver='liblinear'.\n 'auto' selects 'ovr' if the data is binary, or if solver='liblinear',\n and otherwise selects 'multinomial'.\n\n .. versionadded:: 0.18\n Stochastic Average Gradient descent solver for 'multinomial' case.\n .. versionchanged:: 0.22\n Default changed from 'ovr' to 'auto' in 0.22.\n\nrandom_state : int, RandomState instance, default=None\n Used when ``solver`` == 'sag', 'saga' or 'liblinear' to shuffle the\n data. See :term:`Glossary ` for details.\n\ncheck_input : bool, default=True\n If False, the input arrays X and y will not be checked.\n\nmax_squared_sum : float, default=None\n Maximum squared sum of X over samples. Used only in SAG solver.\n If None, it will be computed, going through all the samples.\n The value should be precomputed to speed up cross validation.\n\nsample_weight : array-like of shape(n_samples,), default=None\n Array of weights that are assigned to individual samples.\n If not provided, then each sample is given unit weight.\n\nl1_ratio : float, default=None\n The Elastic-Net mixing parameter, with ``0 <= l1_ratio <= 1``. Only\n used if ``penalty='elasticnet'``. Setting ``l1_ratio=0`` is equivalent\n to using ``penalty='l2'``, while setting ``l1_ratio=1`` is equivalent\n to using ``penalty='l1'``. For ``0 < l1_ratio <1``, the penalty is a\n combination of L1 and L2.\n\nReturns\n-------\ncoefs : ndarray of shape (n_cs, n_features) or (n_cs, n_features + 1)\n List of coefficients for the Logistic Regression model. If\n fit_intercept is set to True then the second dimension will be\n n_features + 1, where the last item represents the intercept. For\n ``multiclass='multinomial'``, the shape is (n_classes, n_cs,\n n_features) or (n_classes, n_cs, n_features + 1).\n\nCs : ndarray\n Grid of Cs used for cross-validation.\n\nn_iter : array of shape (n_cs,)\n Actual number of iteration for each Cs.\n\nNotes\n-----\nYou might get slightly different results with the solver liblinear than\nwith the others since this uses LIBLINEAR which penalizes the intercept.\n\n.. versionchanged:: 0.19\n The \"copy\" parameter was removed.", - "source_code": "\ndef _logistic_regression_path(X, y, pos_class=None, Cs=10, fit_intercept=True, max_iter=100, tol=0.0001, verbose=0, solver='lbfgs', coef=None, class_weight=None, dual=False, penalty='l2', intercept_scaling=1.0, multi_class='auto', random_state=None, check_input=True, max_squared_sum=None, sample_weight=None, l1_ratio=None):\n \"\"\"Compute a Logistic Regression model for a list of regularization\n parameters.\n\n This is an implementation that uses the result of the previous model\n to speed up computations along the set of solutions, making it faster\n than sequentially calling LogisticRegression for the different parameters.\n Note that there will be no speedup with liblinear solver, since it does\n not handle warm-starting.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input data.\n\n y : array-like of shape (n_samples,) or (n_samples, n_targets)\n Input data, target values.\n\n pos_class : int, default=None\n The class with respect to which we perform a one-vs-all fit.\n If None, then it is assumed that the given problem is binary.\n\n Cs : int or array-like of shape (n_cs,), default=10\n List of values for the regularization parameter or integer specifying\n the number of regularization parameters that should be used. In this\n case, the parameters will be chosen in a logarithmic scale between\n 1e-4 and 1e4.\n\n fit_intercept : bool, default=True\n Whether to fit an intercept for the model. In this case the shape of\n the returned array is (n_cs, n_features + 1).\n\n max_iter : int, default=100\n Maximum number of iterations for the solver.\n\n tol : float, default=1e-4\n Stopping criterion. For the newton-cg and lbfgs solvers, the iteration\n will stop when ``max{|g_i | i = 1, ..., n} <= tol``\n where ``g_i`` is the i-th component of the gradient.\n\n verbose : int, default=0\n For the liblinear and lbfgs solvers set verbose to any positive\n number for verbosity.\n\n solver : {'lbfgs', 'newton-cg', 'liblinear', 'sag', 'saga'}, default='lbfgs'\n Numerical solver to use.\n\n coef : array-like of shape (n_features,), default=None\n Initialization value for coefficients of logistic regression.\n Useless for liblinear solver.\n\n class_weight : dict or 'balanced', default=None\n Weights associated with classes in the form ``{class_label: weight}``.\n If not given, all classes are supposed to have weight one.\n\n The \"balanced\" mode uses the values of y to automatically adjust\n weights inversely proportional to class frequencies in the input data\n as ``n_samples / (n_classes * np.bincount(y))``.\n\n Note that these weights will be multiplied with sample_weight (passed\n through the fit method) if sample_weight is specified.\n\n dual : bool, default=False\n Dual or primal formulation. Dual formulation is only implemented for\n l2 penalty with liblinear solver. Prefer dual=False when\n n_samples > n_features.\n\n penalty : {'l1', 'l2', 'elasticnet'}, default='l2'\n Used to specify the norm used in the penalization. The 'newton-cg',\n 'sag' and 'lbfgs' solvers support only l2 penalties. 'elasticnet' is\n only supported by the 'saga' solver.\n\n intercept_scaling : float, default=1.\n Useful only when the solver 'liblinear' is used\n and self.fit_intercept is set to True. In this case, x becomes\n [x, self.intercept_scaling],\n i.e. a \"synthetic\" feature with constant value equal to\n intercept_scaling is appended to the instance vector.\n The intercept becomes ``intercept_scaling * synthetic_feature_weight``.\n\n Note! the synthetic feature weight is subject to l1/l2 regularization\n as all other features.\n To lessen the effect of regularization on synthetic feature weight\n (and therefore on the intercept) intercept_scaling has to be increased.\n\n multi_class : {'ovr', 'multinomial', 'auto'}, default='auto'\n If the option chosen is 'ovr', then a binary problem is fit for each\n label. For 'multinomial' the loss minimised is the multinomial loss fit\n across the entire probability distribution, *even when the data is\n binary*. 'multinomial' is unavailable when solver='liblinear'.\n 'auto' selects 'ovr' if the data is binary, or if solver='liblinear',\n and otherwise selects 'multinomial'.\n\n .. versionadded:: 0.18\n Stochastic Average Gradient descent solver for 'multinomial' case.\n .. versionchanged:: 0.22\n Default changed from 'ovr' to 'auto' in 0.22.\n\n random_state : int, RandomState instance, default=None\n Used when ``solver`` == 'sag', 'saga' or 'liblinear' to shuffle the\n data. See :term:`Glossary ` for details.\n\n check_input : bool, default=True\n If False, the input arrays X and y will not be checked.\n\n max_squared_sum : float, default=None\n Maximum squared sum of X over samples. Used only in SAG solver.\n If None, it will be computed, going through all the samples.\n The value should be precomputed to speed up cross validation.\n\n sample_weight : array-like of shape(n_samples,), default=None\n Array of weights that are assigned to individual samples.\n If not provided, then each sample is given unit weight.\n\n l1_ratio : float, default=None\n The Elastic-Net mixing parameter, with ``0 <= l1_ratio <= 1``. Only\n used if ``penalty='elasticnet'``. Setting ``l1_ratio=0`` is equivalent\n to using ``penalty='l2'``, while setting ``l1_ratio=1`` is equivalent\n to using ``penalty='l1'``. For ``0 < l1_ratio <1``, the penalty is a\n combination of L1 and L2.\n\n Returns\n -------\n coefs : ndarray of shape (n_cs, n_features) or (n_cs, n_features + 1)\n List of coefficients for the Logistic Regression model. If\n fit_intercept is set to True then the second dimension will be\n n_features + 1, where the last item represents the intercept. For\n ``multiclass='multinomial'``, the shape is (n_classes, n_cs,\n n_features) or (n_classes, n_cs, n_features + 1).\n\n Cs : ndarray\n Grid of Cs used for cross-validation.\n\n n_iter : array of shape (n_cs,)\n Actual number of iteration for each Cs.\n\n Notes\n -----\n You might get slightly different results with the solver liblinear than\n with the others since this uses LIBLINEAR which penalizes the intercept.\n\n .. versionchanged:: 0.19\n The \"copy\" parameter was removed.\n \"\"\"\n if isinstance(Cs, numbers.Integral):\n Cs = np.logspace(-4, 4, Cs)\n solver = _check_solver(solver, penalty, dual)\n if check_input:\n X = check_array(X, accept_sparse='csr', dtype=np.float64, accept_large_sparse=solver != 'liblinear')\n y = check_array(y, ensure_2d=False, dtype=None)\n check_consistent_length(X, y)\n (_, n_features) = X.shape\n classes = np.unique(y)\n random_state = check_random_state(random_state)\n multi_class = _check_multi_class(multi_class, solver, len(classes))\n if pos_class is None and multi_class != 'multinomial':\n if classes.size > 2:\n raise ValueError('To fit OvR, use the pos_class argument')\n pos_class = classes[1]\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype, copy=True)\n le = LabelEncoder()\n if isinstance(class_weight, dict) or multi_class == 'multinomial':\n class_weight_ = compute_class_weight(class_weight, classes=classes, y=y)\n sample_weight *= class_weight_[le.fit_transform(y)]\n if multi_class == 'ovr':\n w0 = np.zeros(n_features + int(fit_intercept), dtype=X.dtype)\n mask_classes = np.array([-1, 1])\n mask = y == pos_class\n y_bin = np.ones(y.shape, dtype=X.dtype)\n y_bin[~mask] = -1.0\n if class_weight == 'balanced':\n class_weight_ = compute_class_weight(class_weight, classes=mask_classes, y=y_bin)\n sample_weight *= class_weight_[le.fit_transform(y_bin)]\n else:\n if solver not in ['sag', 'saga']:\n lbin = LabelBinarizer()\n Y_multi = lbin.fit_transform(y)\n if Y_multi.shape[1] == 1:\n Y_multi = np.hstack([1 - Y_multi, Y_multi])\n else:\n le = LabelEncoder()\n Y_multi = le.fit_transform(y).astype(X.dtype, copy=False)\n w0 = np.zeros((classes.size, n_features + int(fit_intercept)), order='F', dtype=X.dtype)\n if coef is not None:\n if multi_class == 'ovr':\n if coef.size not in (n_features, w0.size):\n raise ValueError('Initialization coef is of shape %d, expected shape %d or %d' % (coef.size, n_features, w0.size))\n w0[:coef.size] = coef\n else:\n n_classes = classes.size\n if n_classes == 2:\n n_classes = 1\n if coef.shape[0] != n_classes or coef.shape[1] not in (n_features, n_features + 1):\n raise ValueError('Initialization coef is of shape (%d, %d), expected shape (%d, %d) or (%d, %d)' % (coef.shape[0], coef.shape[1], classes.size, n_features, classes.size, n_features + 1))\n if n_classes == 1:\n w0[0, :coef.shape[1]] = -coef\n w0[1, :coef.shape[1]] = coef\n else:\n w0[:, :coef.shape[1]] = coef\n if multi_class == 'multinomial':\n if solver in ['lbfgs', 'newton-cg']:\n w0 = w0.ravel()\n target = Y_multi\n if solver == 'lbfgs':\n \n def func(x, *args):\n return _multinomial_loss_grad(x, *args)[0:2]\n elif solver == 'newton-cg':\n \n def func(x, *args):\n return _multinomial_loss(x, *args)[0]\n \n def grad(x, *args):\n return _multinomial_loss_grad(x, *args)[1]\n hess = _multinomial_grad_hess\n warm_start_sag = {'coef': w0.T}\n else:\n target = y_bin\n if solver == 'lbfgs':\n func = _logistic_loss_and_grad\n elif solver == 'newton-cg':\n func = _logistic_loss\n \n def grad(x, *args):\n return _logistic_loss_and_grad(x, *args)[1]\n hess = _logistic_grad_hess\n warm_start_sag = {'coef': np.expand_dims(w0, axis=1)}\n coefs = list()\n n_iter = np.zeros(len(Cs), dtype=np.int32)\n for (i, C) in enumerate(Cs):\n if solver == 'lbfgs':\n iprint = [-1, 50, 1, 100, 101][np.searchsorted(np.array([0, 1, 2, 3]), verbose)]\n opt_res = optimize.minimize(func, w0, method='L-BFGS-B', jac=True, args=(X, target, 1.0 / C, sample_weight), options={'iprint': iprint, 'gtol': tol, 'maxiter': max_iter})\n n_iter_i = _check_optimize_result(solver, opt_res, max_iter, extra_warning_msg=_LOGISTIC_SOLVER_CONVERGENCE_MSG)\n (w0, loss) = (opt_res.x, opt_res.fun)\n elif solver == 'newton-cg':\n args = (X, target, 1.0 / C, sample_weight)\n (w0, n_iter_i) = _newton_cg(hess, func, grad, w0, args=args, maxiter=max_iter, tol=tol)\n elif solver == 'liblinear':\n (coef_, intercept_, n_iter_i) = _fit_liblinear(X, target, C, fit_intercept, intercept_scaling, None, penalty, dual, verbose, max_iter, tol, random_state, sample_weight=sample_weight)\n if fit_intercept:\n w0 = np.concatenate([coef_.ravel(), intercept_])\n else:\n w0 = coef_.ravel()\n elif solver in ['sag', 'saga']:\n if multi_class == 'multinomial':\n target = target.astype(X.dtype, copy=False)\n loss = 'multinomial'\n else:\n loss = 'log'\n if penalty == 'l1':\n alpha = 0.0\n beta = 1.0 / C\n elif penalty == 'l2':\n alpha = 1.0 / C\n beta = 0.0\n else:\n alpha = 1.0 / C * (1 - l1_ratio)\n beta = 1.0 / C * l1_ratio\n (w0, n_iter_i, warm_start_sag) = sag_solver(X, target, sample_weight, loss, alpha, beta, max_iter, tol, verbose, random_state, False, max_squared_sum, warm_start_sag, is_saga=solver == 'saga')\n else:\n raise ValueError(\"solver must be one of {'liblinear', 'lbfgs', 'newton-cg', 'sag'}, got '%s' instead\" % solver)\n if multi_class == 'multinomial':\n n_classes = max(2, classes.size)\n multi_w0 = np.reshape(w0, (n_classes, -1))\n if n_classes == 2:\n multi_w0 = multi_w0[1][np.newaxis, :]\n coefs.append(multi_w0.copy())\n else:\n coefs.append(w0.copy())\n n_iter[i] = n_iter_i\n return np.array(coefs), np.array(Cs), n_iter" + "source_code": "\ndef _logistic_regression_path(X, y, pos_class=None, Cs=10, fit_intercept=True, max_iter=100, tol=0.0001, verbose=0, solver='lbfgs', coef=None, class_weight=None, dual=False, penalty='l2', intercept_scaling=1.0, multi_class='auto', random_state=None, check_input=True, max_squared_sum=None, sample_weight=None, l1_ratio=None):\n \"\"\"Compute a Logistic Regression model for a list of regularization\n parameters.\n\n This is an implementation that uses the result of the previous model\n to speed up computations along the set of solutions, making it faster\n than sequentially calling LogisticRegression for the different parameters.\n Note that there will be no speedup with liblinear solver, since it does\n not handle warm-starting.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input data.\n\n y : array-like of shape (n_samples,) or (n_samples, n_targets)\n Input data, target values.\n\n pos_class : int, default=None\n The class with respect to which we perform a one-vs-all fit.\n If None, then it is assumed that the given problem is binary.\n\n Cs : int or array-like of shape (n_cs,), default=10\n List of values for the regularization parameter or integer specifying\n the number of regularization parameters that should be used. In this\n case, the parameters will be chosen in a logarithmic scale between\n 1e-4 and 1e4.\n\n fit_intercept : bool, default=True\n Whether to fit an intercept for the model. In this case the shape of\n the returned array is (n_cs, n_features + 1).\n\n max_iter : int, default=100\n Maximum number of iterations for the solver.\n\n tol : float, default=1e-4\n Stopping criterion. For the newton-cg and lbfgs solvers, the iteration\n will stop when ``max{|g_i | i = 1, ..., n} <= tol``\n where ``g_i`` is the i-th component of the gradient.\n\n verbose : int, default=0\n For the liblinear and lbfgs solvers set verbose to any positive\n number for verbosity.\n\n solver : {'lbfgs', 'newton-cg', 'liblinear', 'sag', 'saga'}, default='lbfgs'\n Numerical solver to use.\n\n coef : array-like of shape (n_features,), default=None\n Initialization value for coefficients of logistic regression.\n Useless for liblinear solver.\n\n class_weight : dict or 'balanced', default=None\n Weights associated with classes in the form ``{class_label: weight}``.\n If not given, all classes are supposed to have weight one.\n\n The \"balanced\" mode uses the values of y to automatically adjust\n weights inversely proportional to class frequencies in the input data\n as ``n_samples / (n_classes * np.bincount(y))``.\n\n Note that these weights will be multiplied with sample_weight (passed\n through the fit method) if sample_weight is specified.\n\n dual : bool, default=False\n Dual or primal formulation. Dual formulation is only implemented for\n l2 penalty with liblinear solver. Prefer dual=False when\n n_samples > n_features.\n\n penalty : {'l1', 'l2', 'elasticnet'}, default='l2'\n Used to specify the norm used in the penalization. The 'newton-cg',\n 'sag' and 'lbfgs' solvers support only l2 penalties. 'elasticnet' is\n only supported by the 'saga' solver.\n\n intercept_scaling : float, default=1.\n Useful only when the solver 'liblinear' is used\n and self.fit_intercept is set to True. In this case, x becomes\n [x, self.intercept_scaling],\n i.e. a \"synthetic\" feature with constant value equal to\n intercept_scaling is appended to the instance vector.\n The intercept becomes ``intercept_scaling * synthetic_feature_weight``.\n\n Note! the synthetic feature weight is subject to l1/l2 regularization\n as all other features.\n To lessen the effect of regularization on synthetic feature weight\n (and therefore on the intercept) intercept_scaling has to be increased.\n\n multi_class : {'ovr', 'multinomial', 'auto'}, default='auto'\n If the option chosen is 'ovr', then a binary problem is fit for each\n label. For 'multinomial' the loss minimised is the multinomial loss fit\n across the entire probability distribution, *even when the data is\n binary*. 'multinomial' is unavailable when solver='liblinear'.\n 'auto' selects 'ovr' if the data is binary, or if solver='liblinear',\n and otherwise selects 'multinomial'.\n\n .. versionadded:: 0.18\n Stochastic Average Gradient descent solver for 'multinomial' case.\n .. versionchanged:: 0.22\n Default changed from 'ovr' to 'auto' in 0.22.\n\n random_state : int, RandomState instance, default=None\n Used when ``solver`` == 'sag', 'saga' or 'liblinear' to shuffle the\n data. See :term:`Glossary ` for details.\n\n check_input : bool, default=True\n If False, the input arrays X and y will not be checked.\n\n max_squared_sum : float, default=None\n Maximum squared sum of X over samples. Used only in SAG solver.\n If None, it will be computed, going through all the samples.\n The value should be precomputed to speed up cross validation.\n\n sample_weight : array-like of shape(n_samples,), default=None\n Array of weights that are assigned to individual samples.\n If not provided, then each sample is given unit weight.\n\n l1_ratio : float, default=None\n The Elastic-Net mixing parameter, with ``0 <= l1_ratio <= 1``. Only\n used if ``penalty='elasticnet'``. Setting ``l1_ratio=0`` is equivalent\n to using ``penalty='l2'``, while setting ``l1_ratio=1`` is equivalent\n to using ``penalty='l1'``. For ``0 < l1_ratio <1``, the penalty is a\n combination of L1 and L2.\n\n Returns\n -------\n coefs : ndarray of shape (n_cs, n_features) or (n_cs, n_features + 1)\n List of coefficients for the Logistic Regression model. If\n fit_intercept is set to True then the second dimension will be\n n_features + 1, where the last item represents the intercept. For\n ``multiclass='multinomial'``, the shape is (n_classes, n_cs,\n n_features) or (n_classes, n_cs, n_features + 1).\n\n Cs : ndarray\n Grid of Cs used for cross-validation.\n\n n_iter : array of shape (n_cs,)\n Actual number of iteration for each Cs.\n\n Notes\n -----\n You might get slightly different results with the solver liblinear than\n with the others since this uses LIBLINEAR which penalizes the intercept.\n\n .. versionchanged:: 0.19\n The \"copy\" parameter was removed.\n \"\"\"\n if isinstance(Cs, numbers.Integral):\n Cs = np.logspace(-4, 4, Cs)\n solver = _check_solver(solver, penalty, dual)\n if check_input:\n X = check_array(X, accept_sparse='csr', dtype=np.float64, accept_large_sparse=solver not in ['liblinear', 'sag', 'saga'])\n y = check_array(y, ensure_2d=False, dtype=None)\n check_consistent_length(X, y)\n (_, n_features) = X.shape\n classes = np.unique(y)\n random_state = check_random_state(random_state)\n multi_class = _check_multi_class(multi_class, solver, len(classes))\n if pos_class is None and multi_class != 'multinomial':\n if classes.size > 2:\n raise ValueError('To fit OvR, use the pos_class argument')\n pos_class = classes[1]\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype, copy=True)\n le = LabelEncoder()\n if isinstance(class_weight, dict) or multi_class == 'multinomial':\n class_weight_ = compute_class_weight(class_weight, classes=classes, y=y)\n sample_weight *= class_weight_[le.fit_transform(y)]\n if multi_class == 'ovr':\n w0 = np.zeros(n_features + int(fit_intercept), dtype=X.dtype)\n mask_classes = np.array([-1, 1])\n mask = y == pos_class\n y_bin = np.ones(y.shape, dtype=X.dtype)\n y_bin[~mask] = -1.0\n if class_weight == 'balanced':\n class_weight_ = compute_class_weight(class_weight, classes=mask_classes, y=y_bin)\n sample_weight *= class_weight_[le.fit_transform(y_bin)]\n else:\n if solver not in ['sag', 'saga']:\n lbin = LabelBinarizer()\n Y_multi = lbin.fit_transform(y)\n if Y_multi.shape[1] == 1:\n Y_multi = np.hstack([1 - Y_multi, Y_multi])\n else:\n le = LabelEncoder()\n Y_multi = le.fit_transform(y).astype(X.dtype, copy=False)\n w0 = np.zeros((classes.size, n_features + int(fit_intercept)), order='F', dtype=X.dtype)\n if coef is not None:\n if multi_class == 'ovr':\n if coef.size not in (n_features, w0.size):\n raise ValueError('Initialization coef is of shape %d, expected shape %d or %d' % (coef.size, n_features, w0.size))\n w0[:coef.size] = coef\n else:\n n_classes = classes.size\n if n_classes == 2:\n n_classes = 1\n if coef.shape[0] != n_classes or coef.shape[1] not in (n_features, n_features + 1):\n raise ValueError('Initialization coef is of shape (%d, %d), expected shape (%d, %d) or (%d, %d)' % (coef.shape[0], coef.shape[1], classes.size, n_features, classes.size, n_features + 1))\n if n_classes == 1:\n w0[0, :coef.shape[1]] = -coef\n w0[1, :coef.shape[1]] = coef\n else:\n w0[:, :coef.shape[1]] = coef\n if multi_class == 'multinomial':\n if solver in ['lbfgs', 'newton-cg']:\n w0 = w0.ravel()\n target = Y_multi\n if solver == 'lbfgs':\n \n def func(x, *args):\n return _multinomial_loss_grad(x, *args)[0:2]\n elif solver == 'newton-cg':\n \n def func(x, *args):\n return _multinomial_loss(x, *args)[0]\n \n def grad(x, *args):\n return _multinomial_loss_grad(x, *args)[1]\n hess = _multinomial_grad_hess\n warm_start_sag = {'coef': w0.T}\n else:\n target = y_bin\n if solver == 'lbfgs':\n func = _logistic_loss_and_grad\n elif solver == 'newton-cg':\n func = _logistic_loss\n \n def grad(x, *args):\n return _logistic_loss_and_grad(x, *args)[1]\n hess = _logistic_grad_hess\n warm_start_sag = {'coef': np.expand_dims(w0, axis=1)}\n coefs = list()\n n_iter = np.zeros(len(Cs), dtype=np.int32)\n for (i, C) in enumerate(Cs):\n if solver == 'lbfgs':\n iprint = [-1, 50, 1, 100, 101][np.searchsorted(np.array([0, 1, 2, 3]), verbose)]\n opt_res = optimize.minimize(func, w0, method='L-BFGS-B', jac=True, args=(X, target, 1.0 / C, sample_weight), options={'iprint': iprint, 'gtol': tol, 'maxiter': max_iter})\n n_iter_i = _check_optimize_result(solver, opt_res, max_iter, extra_warning_msg=_LOGISTIC_SOLVER_CONVERGENCE_MSG)\n (w0, loss) = (opt_res.x, opt_res.fun)\n elif solver == 'newton-cg':\n args = (X, target, 1.0 / C, sample_weight)\n (w0, n_iter_i) = _newton_cg(hess, func, grad, w0, args=args, maxiter=max_iter, tol=tol)\n elif solver == 'liblinear':\n (coef_, intercept_, n_iter_i) = _fit_liblinear(X, target, C, fit_intercept, intercept_scaling, None, penalty, dual, verbose, max_iter, tol, random_state, sample_weight=sample_weight)\n if fit_intercept:\n w0 = np.concatenate([coef_.ravel(), intercept_])\n else:\n w0 = coef_.ravel()\n elif solver in ['sag', 'saga']:\n if multi_class == 'multinomial':\n target = target.astype(X.dtype, copy=False)\n loss = 'multinomial'\n else:\n loss = 'log'\n if penalty == 'l1':\n alpha = 0.0\n beta = 1.0 / C\n elif penalty == 'l2':\n alpha = 1.0 / C\n beta = 0.0\n else:\n alpha = 1.0 / C * (1 - l1_ratio)\n beta = 1.0 / C * l1_ratio\n (w0, n_iter_i, warm_start_sag) = sag_solver(X, target, sample_weight, loss, alpha, beta, max_iter, tol, verbose, random_state, False, max_squared_sum, warm_start_sag, is_saga=solver == 'saga')\n else:\n raise ValueError(\"solver must be one of {'liblinear', 'lbfgs', 'newton-cg', 'sag'}, got '%s' instead\" % solver)\n if multi_class == 'multinomial':\n n_classes = max(2, classes.size)\n multi_w0 = np.reshape(w0, (n_classes, -1))\n if n_classes == 2:\n multi_w0 = multi_w0[1][np.newaxis, :]\n coefs.append(multi_w0.copy())\n else:\n coefs.append(w0.copy())\n n_iter[i] = n_iter_i\n return np.array(coefs), np.array(Cs), n_iter" }, { "name": "_multinomial_grad_hess", + "unique_name": "_multinomial_grad_hess", "qname": "sklearn.linear_model._logistic._multinomial_grad_hess", + "unique_qname": "sklearn.linear_model._logistic._multinomial_grad_hess", "decorators": [], "parameters": [ { @@ -100749,7 +104105,9 @@ }, { "name": "_multinomial_loss", + "unique_name": "_multinomial_loss", "qname": "sklearn.linear_model._logistic._multinomial_loss", + "unique_qname": "sklearn.linear_model._logistic._multinomial_loss", "decorators": [], "parameters": [ { @@ -100811,7 +104169,9 @@ }, { "name": "_multinomial_loss_grad", + "unique_name": "_multinomial_loss_grad", "qname": "sklearn.linear_model._logistic._multinomial_loss_grad", + "unique_qname": "sklearn.linear_model._logistic._multinomial_loss_grad", "decorators": [], "parameters": [ { @@ -100873,7 +104233,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._omp.OrthogonalMatchingPursuit.__init__", + "unique_qname": "sklearn.linear_model._omp.OrthogonalMatchingPursuit.__init__", "decorators": [], "parameters": [ { @@ -100913,7 +104275,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "bool, default=True", - "description": "whether to calculate the intercept for this model. If set\nto false, no intercept will be used in calculations\n(i.e. data is expected to be centered)." + "description": "Whether to calculate the intercept for this model. If set\nto false, no intercept will be used in calculations\n(i.e. data is expected to be centered)." } }, { @@ -100945,7 +104307,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._omp.OrthogonalMatchingPursuit.fit", + "unique_qname": "sklearn.linear_model._omp.OrthogonalMatchingPursuit.fit", "decorators": [], "parameters": [ { @@ -100975,19 +104339,21 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "array-like of shape (n_samples,) or (n_samples, n_targets)", - "description": "Target values. Will be cast to X's dtype if necessary" + "description": "Target values. Will be cast to X's dtype if necessary." } } ], "results": [], "is_public": true, "description": "Fit the model using X, y as training data.", - "docstring": "Fit the model using X, y as training data.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Training data.\n\ny : array-like of shape (n_samples,) or (n_samples, n_targets)\n Target values. Will be cast to X's dtype if necessary\n\n\nReturns\n-------\nself : object\n returns an instance of self.", - "source_code": "\ndef fit(self, X, y):\n \"\"\"Fit the model using X, y as training data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training data.\n\n y : array-like of shape (n_samples,) or (n_samples, n_targets)\n Target values. Will be cast to X's dtype if necessary\n\n\n Returns\n -------\n self : object\n returns an instance of self.\n \"\"\"\n _normalize = _deprecate_normalize(self.normalize, default=True, estimator_name=self.__class__.__name__)\n (X, y) = self._validate_data(X, y, multi_output=True, y_numeric=True)\n n_features = X.shape[1]\n (X, y, X_offset, y_offset, X_scale, Gram, Xy) = _pre_fit(X, y, None, self.precompute, _normalize, self.fit_intercept, copy=True)\n if y.ndim == 1:\n y = y[:, np.newaxis]\n if self.n_nonzero_coefs is None and self.tol is None:\n self.n_nonzero_coefs_ = max(int(0.1 * n_features), 1)\n else:\n self.n_nonzero_coefs_ = self.n_nonzero_coefs\n if Gram is False:\n (coef_, self.n_iter_) = orthogonal_mp(X, y, n_nonzero_coefs=self.n_nonzero_coefs_, tol=self.tol, precompute=False, copy_X=True, return_n_iter=True)\n else:\n norms_sq = np.sum(y**2, axis=0) if self.tol is not None else None\n (coef_, self.n_iter_) = orthogonal_mp_gram(Gram, Xy=Xy, n_nonzero_coefs=self.n_nonzero_coefs_, tol=self.tol, norms_squared=norms_sq, copy_Gram=True, copy_Xy=True, return_n_iter=True)\n self.coef_ = coef_.T\n self._set_intercept(X_offset, y_offset, X_scale)\n return self" + "docstring": "Fit the model using X, y as training data.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Training data.\n\ny : array-like of shape (n_samples,) or (n_samples, n_targets)\n Target values. Will be cast to X's dtype if necessary.\n\nReturns\n-------\nself : object\n Returns an instance of self.", + "source_code": "\ndef fit(self, X, y):\n \"\"\"Fit the model using X, y as training data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training data.\n\n y : array-like of shape (n_samples,) or (n_samples, n_targets)\n Target values. Will be cast to X's dtype if necessary.\n\n Returns\n -------\n self : object\n Returns an instance of self.\n \"\"\"\n _normalize = _deprecate_normalize(self.normalize, default=True, estimator_name=self.__class__.__name__)\n (X, y) = self._validate_data(X, y, multi_output=True, y_numeric=True)\n n_features = X.shape[1]\n (X, y, X_offset, y_offset, X_scale, Gram, Xy) = _pre_fit(X, y, None, self.precompute, _normalize, self.fit_intercept, copy=True)\n if y.ndim == 1:\n y = y[:, np.newaxis]\n if self.n_nonzero_coefs is None and self.tol is None:\n self.n_nonzero_coefs_ = max(int(0.1 * n_features), 1)\n else:\n self.n_nonzero_coefs_ = self.n_nonzero_coefs\n if Gram is False:\n (coef_, self.n_iter_) = orthogonal_mp(X, y, n_nonzero_coefs=self.n_nonzero_coefs_, tol=self.tol, precompute=False, copy_X=True, return_n_iter=True)\n else:\n norms_sq = np.sum(y**2, axis=0) if self.tol is not None else None\n (coef_, self.n_iter_) = orthogonal_mp_gram(Gram, Xy=Xy, n_nonzero_coefs=self.n_nonzero_coefs_, tol=self.tol, norms_squared=norms_sq, copy_Gram=True, copy_Xy=True, return_n_iter=True)\n self.coef_ = coef_.T\n self._set_intercept(X_offset, y_offset, X_scale)\n return self" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._omp.OrthogonalMatchingPursuitCV.__init__", + "unique_qname": "sklearn.linear_model._omp.OrthogonalMatchingPursuitCV.__init__", "decorators": [], "parameters": [ { @@ -101017,7 +104383,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "bool, default=True", - "description": "whether to calculate the intercept for this model. If set\nto false, no intercept will be used in calculations\n(i.e. data is expected to be centered)." + "description": "Whether to calculate the intercept for this model. If set\nto false, no intercept will be used in calculations\n(i.e. data is expected to be centered)." } }, { @@ -101079,7 +104445,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._omp.OrthogonalMatchingPursuitCV.fit", + "unique_qname": "sklearn.linear_model._omp.OrthogonalMatchingPursuitCV.fit", "decorators": [], "parameters": [ { @@ -101116,12 +104484,14 @@ "results": [], "is_public": true, "description": "Fit the model using X, y as training data.", - "docstring": "Fit the model using X, y as training data.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Training data.\n\ny : array-like of shape (n_samples,)\n Target values. Will be cast to X's dtype if necessary.\n\nReturns\n-------\nself : object\n returns an instance of self.", - "source_code": "\ndef fit(self, X, y):\n \"\"\"Fit the model using X, y as training data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training data.\n\n y : array-like of shape (n_samples,)\n Target values. Will be cast to X's dtype if necessary.\n\n Returns\n -------\n self : object\n returns an instance of self.\n \"\"\"\n _normalize = _deprecate_normalize(self.normalize, default=True, estimator_name=self.__class__.__name__)\n (X, y) = self._validate_data(X, y, y_numeric=True, ensure_min_features=2, estimator=self)\n X = as_float_array(X, copy=False, force_all_finite=False)\n cv = check_cv(self.cv, classifier=False)\n max_iter = min(max(int(0.1 * X.shape[1]), 5), X.shape[1]) if not self.max_iter else self.max_iter\n cv_paths = Parallel(n_jobs=self.n_jobs, verbose=self.verbose)((delayed(_omp_path_residues)(X[train], y[train], X[test], y[test], self.copy, self.fit_intercept, _normalize, max_iter) for (train, test) in cv.split(X)))\n min_early_stop = min((fold.shape[0] for fold in cv_paths))\n mse_folds = np.array([(fold[:min_early_stop]**2).mean(axis=1) for fold in cv_paths])\n best_n_nonzero_coefs = np.argmin(mse_folds.mean(axis=0)) + 1\n self.n_nonzero_coefs_ = best_n_nonzero_coefs\n omp = OrthogonalMatchingPursuit(n_nonzero_coefs=best_n_nonzero_coefs, fit_intercept=self.fit_intercept, normalize=_normalize)\n omp.fit(X, y)\n self.coef_ = omp.coef_\n self.intercept_ = omp.intercept_\n self.n_iter_ = omp.n_iter_\n return self" + "docstring": "Fit the model using X, y as training data.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Training data.\n\ny : array-like of shape (n_samples,)\n Target values. Will be cast to X's dtype if necessary.\n\nReturns\n-------\nself : object\n Returns an instance of self.", + "source_code": "\ndef fit(self, X, y):\n \"\"\"Fit the model using X, y as training data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training data.\n\n y : array-like of shape (n_samples,)\n Target values. Will be cast to X's dtype if necessary.\n\n Returns\n -------\n self : object\n Returns an instance of self.\n \"\"\"\n _normalize = _deprecate_normalize(self.normalize, default=True, estimator_name=self.__class__.__name__)\n (X, y) = self._validate_data(X, y, y_numeric=True, ensure_min_features=2, estimator=self)\n X = as_float_array(X, copy=False, force_all_finite=False)\n cv = check_cv(self.cv, classifier=False)\n max_iter = min(max(int(0.1 * X.shape[1]), 5), X.shape[1]) if not self.max_iter else self.max_iter\n cv_paths = Parallel(n_jobs=self.n_jobs, verbose=self.verbose)((delayed(_omp_path_residues)(X[train], y[train], X[test], y[test], self.copy, self.fit_intercept, _normalize, max_iter) for (train, test) in cv.split(X)))\n min_early_stop = min((fold.shape[0] for fold in cv_paths))\n mse_folds = np.array([(fold[:min_early_stop]**2).mean(axis=1) for fold in cv_paths])\n best_n_nonzero_coefs = np.argmin(mse_folds.mean(axis=0)) + 1\n self.n_nonzero_coefs_ = best_n_nonzero_coefs\n omp = OrthogonalMatchingPursuit(n_nonzero_coefs=best_n_nonzero_coefs, fit_intercept=self.fit_intercept, normalize=_normalize)\n omp.fit(X, y)\n self.coef_ = omp.coef_\n self.intercept_ = omp.intercept_\n self.n_iter_ = omp.n_iter_\n return self" }, { "name": "_cholesky_omp", + "unique_name": "_cholesky_omp", "qname": "sklearn.linear_model._omp._cholesky_omp", + "unique_qname": "sklearn.linear_model._omp._cholesky_omp", "decorators": [], "parameters": [ { @@ -101193,7 +104563,9 @@ }, { "name": "_gram_omp", + "unique_name": "_gram_omp", "qname": "sklearn.linear_model._omp._gram_omp", + "unique_qname": "sklearn.linear_model._omp._gram_omp", "decorators": [], "parameters": [ { @@ -101285,7 +104657,9 @@ }, { "name": "_omp_path_residues", + "unique_name": "_omp_path_residues", "qname": "sklearn.linear_model._omp._omp_path_residues", + "unique_qname": "sklearn.linear_model._omp._omp_path_residues", "decorators": [], "parameters": [ { @@ -101377,7 +104751,9 @@ }, { "name": "orthogonal_mp", + "unique_name": "orthogonal_mp", "qname": "sklearn.linear_model._omp.orthogonal_mp", + "unique_qname": "sklearn.linear_model._omp.orthogonal_mp", "decorators": [], "parameters": [ { @@ -101469,7 +104845,9 @@ }, { "name": "orthogonal_mp_gram", + "unique_name": "orthogonal_mp_gram", "qname": "sklearn.linear_model._omp.orthogonal_mp_gram", + "unique_qname": "sklearn.linear_model._omp.orthogonal_mp_gram", "decorators": [], "parameters": [ { @@ -101571,7 +104949,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._passive_aggressive.PassiveAggressiveClassifier.__init__", + "unique_qname": "sklearn.linear_model._passive_aggressive.PassiveAggressiveClassifier.__init__", "decorators": [], "parameters": [ { @@ -101670,8 +105050,8 @@ "is_public": true, "assigned_by": "NAME_ONLY", "docstring": { - "type": "integer, default=0", - "description": "The verbosity level" + "type": "int, default=0", + "description": "The verbosity level." } }, { @@ -101680,7 +105060,7 @@ "is_public": true, "assigned_by": "NAME_ONLY", "docstring": { - "type": "string, default=\"hinge\"", + "type": "str, default=\"hinge\"", "description": "The loss function to be used:\nhinge: equivalent to PA-I in the reference paper.\nsquared_hinge: equivalent to PA-II in the reference paper." } }, @@ -101721,7 +105101,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "dict, {class_label: weight} or \"balanced\" or None, default=None", - "description": "Preset for the class_weight fit parameter.\n\nWeights associated with classes. If not given, all classes\nare supposed to have weight one.\n\nThe \"balanced\" mode uses the values of y to automatically adjust\nweights inversely proportional to class frequencies in the input data\nas ``n_samples / (n_classes * np.bincount(y))``\n\n.. versionadded:: 0.17\n parameter *class_weight* to automatically weight samples." + "description": "Preset for the class_weight fit parameter.\n\nWeights associated with classes. If not given, all classes\nare supposed to have weight one.\n\nThe \"balanced\" mode uses the values of y to automatically adjust\nweights inversely proportional to class frequencies in the input data\nas ``n_samples / (n_classes * np.bincount(y))``.\n\n.. versionadded:: 0.17\n parameter *class_weight* to automatically weight samples." } }, { @@ -101731,7 +105111,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "bool or int, default=False", - "description": "When set to True, computes the averaged SGD weights and stores the\nresult in the ``coef_`` attribute. If set to an int greater than 1,\naveraging will begin once the total number of samples seen reaches\naverage. So average=10 will begin averaging after seeing 10 samples.\n\n.. versionadded:: 0.19\n parameter *average* to use weights averaging in SGD" + "description": "When set to True, computes the averaged SGD weights and stores the\nresult in the ``coef_`` attribute. If set to an int greater than 1,\naveraging will begin once the total number of samples seen reaches\naverage. So average=10 will begin averaging after seeing 10 samples.\n\n.. versionadded:: 0.19\n parameter *average* to use weights averaging in SGD." } } ], @@ -101743,7 +105123,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._passive_aggressive.PassiveAggressiveClassifier.fit", + "unique_qname": "sklearn.linear_model._passive_aggressive.PassiveAggressiveClassifier.fit", "decorators": [], "parameters": [ { @@ -101763,7 +105145,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "{array-like, sparse matrix} of shape (n_samples, n_features)", - "description": "Training data" + "description": "Training data." } }, { @@ -101772,8 +105154,8 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "numpy array of shape [n_samples]", - "description": "Target values" + "type": "array-like of shape (n_samples,)", + "description": "Target values." } }, { @@ -101782,7 +105164,7 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "array, shape = [n_classes,n_features]", + "type": "ndarray of shape (n_classes, n_features)", "description": "The initial coefficients to warm-start the optimization." } }, @@ -101792,7 +105174,7 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "array, shape = [n_classes]", + "type": "ndarray of shape (n_classes,)", "description": "The initial intercept to warm-start the optimization." } } @@ -101800,12 +105182,14 @@ "results": [], "is_public": true, "description": "Fit linear model with Passive Aggressive algorithm.", - "docstring": "Fit linear model with Passive Aggressive algorithm.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training data\n\ny : numpy array of shape [n_samples]\n Target values\n\ncoef_init : array, shape = [n_classes,n_features]\n The initial coefficients to warm-start the optimization.\n\nintercept_init : array, shape = [n_classes]\n The initial intercept to warm-start the optimization.\n\nReturns\n-------\nself : returns an instance of self.", - "source_code": "\ndef fit(self, X, y, coef_init=None, intercept_init=None):\n \"\"\"Fit linear model with Passive Aggressive algorithm.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training data\n\n y : numpy array of shape [n_samples]\n Target values\n\n coef_init : array, shape = [n_classes,n_features]\n The initial coefficients to warm-start the optimization.\n\n intercept_init : array, shape = [n_classes]\n The initial intercept to warm-start the optimization.\n\n Returns\n -------\n self : returns an instance of self.\n \"\"\"\n self._validate_params()\n lr = 'pa1' if self.loss == 'hinge' else 'pa2'\n return self._fit(X, y, alpha=1.0, C=self.C, loss='hinge', learning_rate=lr, coef_init=coef_init, intercept_init=intercept_init)" + "docstring": "Fit linear model with Passive Aggressive algorithm.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training data.\n\ny : array-like of shape (n_samples,)\n Target values.\n\ncoef_init : ndarray of shape (n_classes, n_features)\n The initial coefficients to warm-start the optimization.\n\nintercept_init : ndarray of shape (n_classes,)\n The initial intercept to warm-start the optimization.\n\nReturns\n-------\nself : object\n Fitted estimator.", + "source_code": "\ndef fit(self, X, y, coef_init=None, intercept_init=None):\n \"\"\"Fit linear model with Passive Aggressive algorithm.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training data.\n\n y : array-like of shape (n_samples,)\n Target values.\n\n coef_init : ndarray of shape (n_classes, n_features)\n The initial coefficients to warm-start the optimization.\n\n intercept_init : ndarray of shape (n_classes,)\n The initial intercept to warm-start the optimization.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n self._validate_params()\n lr = 'pa1' if self.loss == 'hinge' else 'pa2'\n return self._fit(X, y, alpha=1.0, C=self.C, loss='hinge', learning_rate=lr, coef_init=coef_init, intercept_init=intercept_init)" }, { "name": "partial_fit", + "unique_name": "partial_fit", "qname": "sklearn.linear_model._passive_aggressive.PassiveAggressiveClassifier.partial_fit", + "unique_qname": "sklearn.linear_model._passive_aggressive.PassiveAggressiveClassifier.partial_fit", "decorators": [], "parameters": [ { @@ -101825,7 +105209,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "{array-like, sparse matrix} of shape (n_samples, n_features)", - "description": "Subset of the training data" + "description": "Subset of the training data." } }, { @@ -101834,8 +105218,8 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "numpy array of shape [n_samples]", - "description": "Subset of the target values" + "type": "array-like of shape (n_samples,)", + "description": "Subset of the target values." } }, { @@ -101844,7 +105228,7 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "array, shape = [n_classes]", + "type": "ndarray of shape (n_classes,)", "description": "Classes across all calls to partial_fit.\nCan be obtained by via `np.unique(y_all)`, where y_all is the\ntarget vector of the entire dataset.\nThis argument is required for the first call to partial_fit\nand can be omitted in the subsequent calls.\nNote that y doesn't need to contain all labels in `classes`." } } @@ -101852,12 +105236,14 @@ "results": [], "is_public": true, "description": "Fit linear model with Passive Aggressive algorithm.", - "docstring": "Fit linear model with Passive Aggressive algorithm.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Subset of the training data\n\ny : numpy array of shape [n_samples]\n Subset of the target values\n\nclasses : array, shape = [n_classes]\n Classes across all calls to partial_fit.\n Can be obtained by via `np.unique(y_all)`, where y_all is the\n target vector of the entire dataset.\n This argument is required for the first call to partial_fit\n and can be omitted in the subsequent calls.\n Note that y doesn't need to contain all labels in `classes`.\n\nReturns\n-------\nself : returns an instance of self.", - "source_code": "\ndef partial_fit(self, X, y, classes=None):\n \"\"\"Fit linear model with Passive Aggressive algorithm.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Subset of the training data\n\n y : numpy array of shape [n_samples]\n Subset of the target values\n\n classes : array, shape = [n_classes]\n Classes across all calls to partial_fit.\n Can be obtained by via `np.unique(y_all)`, where y_all is the\n target vector of the entire dataset.\n This argument is required for the first call to partial_fit\n and can be omitted in the subsequent calls.\n Note that y doesn't need to contain all labels in `classes`.\n\n Returns\n -------\n self : returns an instance of self.\n \"\"\"\n self._validate_params(for_partial_fit=True)\n if self.class_weight == 'balanced':\n raise ValueError(\"class_weight 'balanced' is not supported for partial_fit. For 'balanced' weights, use `sklearn.utils.compute_class_weight` with `class_weight='balanced'`. In place of y you can use a large enough subset of the full training set target to properly estimate the class frequency distributions. Pass the resulting weights as the class_weight parameter.\")\n lr = 'pa1' if self.loss == 'hinge' else 'pa2'\n return self._partial_fit(X, y, alpha=1.0, C=self.C, loss='hinge', learning_rate=lr, max_iter=1, classes=classes, sample_weight=None, coef_init=None, intercept_init=None)" + "docstring": "Fit linear model with Passive Aggressive algorithm.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Subset of the training data.\n\ny : array-like of shape (n_samples,)\n Subset of the target values.\n\nclasses : ndarray of shape (n_classes,)\n Classes across all calls to partial_fit.\n Can be obtained by via `np.unique(y_all)`, where y_all is the\n target vector of the entire dataset.\n This argument is required for the first call to partial_fit\n and can be omitted in the subsequent calls.\n Note that y doesn't need to contain all labels in `classes`.\n\nReturns\n-------\nself : object\n Fitted estimator.", + "source_code": "\ndef partial_fit(self, X, y, classes=None):\n \"\"\"Fit linear model with Passive Aggressive algorithm.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Subset of the training data.\n\n y : array-like of shape (n_samples,)\n Subset of the target values.\n\n classes : ndarray of shape (n_classes,)\n Classes across all calls to partial_fit.\n Can be obtained by via `np.unique(y_all)`, where y_all is the\n target vector of the entire dataset.\n This argument is required for the first call to partial_fit\n and can be omitted in the subsequent calls.\n Note that y doesn't need to contain all labels in `classes`.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n self._validate_params(for_partial_fit=True)\n if self.class_weight == 'balanced':\n raise ValueError(\"class_weight 'balanced' is not supported for partial_fit. For 'balanced' weights, use `sklearn.utils.compute_class_weight` with `class_weight='balanced'`. In place of y you can use a large enough subset of the full training set target to properly estimate the class frequency distributions. Pass the resulting weights as the class_weight parameter.\")\n lr = 'pa1' if self.loss == 'hinge' else 'pa2'\n return self._partial_fit(X, y, alpha=1.0, C=self.C, loss='hinge', learning_rate=lr, max_iter=1, classes=classes, sample_weight=None, coef_init=None, intercept_init=None)" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._passive_aggressive.PassiveAggressiveRegressor.__init__", + "unique_qname": "sklearn.linear_model._passive_aggressive.PassiveAggressiveRegressor.__init__", "decorators": [], "parameters": [ { @@ -101956,8 +105342,8 @@ "is_public": true, "assigned_by": "NAME_ONLY", "docstring": { - "type": "integer, default=0", - "description": "The verbosity level" + "type": "int, default=0", + "description": "The verbosity level." } }, { @@ -101966,7 +105352,7 @@ "is_public": true, "assigned_by": "NAME_ONLY", "docstring": { - "type": "string, default=\"epsilon_insensitive\"", + "type": "str, default=\"epsilon_insensitive\"", "description": "The loss function to be used:\nepsilon_insensitive: equivalent to PA-I in the reference paper.\nsquared_epsilon_insensitive: equivalent to PA-II in the reference\npaper." } }, @@ -102007,7 +105393,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "bool or int, default=False", - "description": "When set to True, computes the averaged SGD weights and stores the\nresult in the ``coef_`` attribute. If set to an int greater than 1,\naveraging will begin once the total number of samples seen reaches\naverage. So average=10 will begin averaging after seeing 10 samples.\n\n.. versionadded:: 0.19\n parameter *average* to use weights averaging in SGD" + "description": "When set to True, computes the averaged SGD weights and stores the\nresult in the ``coef_`` attribute. If set to an int greater than 1,\naveraging will begin once the total number of samples seen reaches\naverage. So average=10 will begin averaging after seeing 10 samples.\n\n.. versionadded:: 0.19\n parameter *average* to use weights averaging in SGD." } } ], @@ -102019,7 +105405,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._passive_aggressive.PassiveAggressiveRegressor.fit", + "unique_qname": "sklearn.linear_model._passive_aggressive.PassiveAggressiveRegressor.fit", "decorators": [], "parameters": [ { @@ -102039,7 +105427,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "{array-like, sparse matrix} of shape (n_samples, n_features)", - "description": "Training data" + "description": "Training data." } }, { @@ -102049,7 +105437,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "numpy array of shape [n_samples]", - "description": "Target values" + "description": "Target values." } }, { @@ -102076,12 +105464,14 @@ "results": [], "is_public": true, "description": "Fit linear model with Passive Aggressive algorithm.", - "docstring": "Fit linear model with Passive Aggressive algorithm.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training data\n\ny : numpy array of shape [n_samples]\n Target values\n\ncoef_init : array, shape = [n_features]\n The initial coefficients to warm-start the optimization.\n\nintercept_init : array, shape = [1]\n The initial intercept to warm-start the optimization.\n\nReturns\n-------\nself : returns an instance of self.", - "source_code": "\ndef fit(self, X, y, coef_init=None, intercept_init=None):\n \"\"\"Fit linear model with Passive Aggressive algorithm.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training data\n\n y : numpy array of shape [n_samples]\n Target values\n\n coef_init : array, shape = [n_features]\n The initial coefficients to warm-start the optimization.\n\n intercept_init : array, shape = [1]\n The initial intercept to warm-start the optimization.\n\n Returns\n -------\n self : returns an instance of self.\n \"\"\"\n self._validate_params()\n lr = 'pa1' if self.loss == 'epsilon_insensitive' else 'pa2'\n return self._fit(X, y, alpha=1.0, C=self.C, loss='epsilon_insensitive', learning_rate=lr, coef_init=coef_init, intercept_init=intercept_init)" + "docstring": "Fit linear model with Passive Aggressive algorithm.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training data.\n\ny : numpy array of shape [n_samples]\n Target values.\n\ncoef_init : array, shape = [n_features]\n The initial coefficients to warm-start the optimization.\n\nintercept_init : array, shape = [1]\n The initial intercept to warm-start the optimization.\n\nReturns\n-------\nself : object\n Fitted estimator.", + "source_code": "\ndef fit(self, X, y, coef_init=None, intercept_init=None):\n \"\"\"Fit linear model with Passive Aggressive algorithm.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training data.\n\n y : numpy array of shape [n_samples]\n Target values.\n\n coef_init : array, shape = [n_features]\n The initial coefficients to warm-start the optimization.\n\n intercept_init : array, shape = [1]\n The initial intercept to warm-start the optimization.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n self._validate_params()\n lr = 'pa1' if self.loss == 'epsilon_insensitive' else 'pa2'\n return self._fit(X, y, alpha=1.0, C=self.C, loss='epsilon_insensitive', learning_rate=lr, coef_init=coef_init, intercept_init=intercept_init)" }, { "name": "partial_fit", + "unique_name": "partial_fit", "qname": "sklearn.linear_model._passive_aggressive.PassiveAggressiveRegressor.partial_fit", + "unique_qname": "sklearn.linear_model._passive_aggressive.PassiveAggressiveRegressor.partial_fit", "decorators": [], "parameters": [ { @@ -102101,7 +105491,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "{array-like, sparse matrix} of shape (n_samples, n_features)", - "description": "Subset of training data" + "description": "Subset of training data." } }, { @@ -102111,19 +105501,21 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "numpy array of shape [n_samples]", - "description": "Subset of target values" + "description": "Subset of target values." } } ], "results": [], "is_public": true, "description": "Fit linear model with Passive Aggressive algorithm.", - "docstring": "Fit linear model with Passive Aggressive algorithm.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Subset of training data\n\ny : numpy array of shape [n_samples]\n Subset of target values\n\nReturns\n-------\nself : returns an instance of self.", - "source_code": "\ndef partial_fit(self, X, y):\n \"\"\"Fit linear model with Passive Aggressive algorithm.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Subset of training data\n\n y : numpy array of shape [n_samples]\n Subset of target values\n\n Returns\n -------\n self : returns an instance of self.\n \"\"\"\n self._validate_params(for_partial_fit=True)\n lr = 'pa1' if self.loss == 'epsilon_insensitive' else 'pa2'\n return self._partial_fit(X, y, alpha=1.0, C=self.C, loss='epsilon_insensitive', learning_rate=lr, max_iter=1, sample_weight=None, coef_init=None, intercept_init=None)" + "docstring": "Fit linear model with Passive Aggressive algorithm.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Subset of training data.\n\ny : numpy array of shape [n_samples]\n Subset of target values.\n\nReturns\n-------\nself : object\n Fitted estimator.", + "source_code": "\ndef partial_fit(self, X, y):\n \"\"\"Fit linear model with Passive Aggressive algorithm.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Subset of training data.\n\n y : numpy array of shape [n_samples]\n Subset of target values.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n self._validate_params(for_partial_fit=True)\n lr = 'pa1' if self.loss == 'epsilon_insensitive' else 'pa2'\n return self._partial_fit(X, y, alpha=1.0, C=self.C, loss='epsilon_insensitive', learning_rate=lr, max_iter=1, sample_weight=None, coef_init=None, intercept_init=None)" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._perceptron.Perceptron.__init__", + "unique_qname": "sklearn.linear_model._perceptron.Perceptron.__init__", "decorators": [], "parameters": [ { @@ -102305,7 +105697,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._quantile.QuantileRegressor.__init__", + "unique_qname": "sklearn.linear_model._quantile.QuantileRegressor.__init__", "decorators": [], "parameters": [ { @@ -102377,7 +105771,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._quantile.QuantileRegressor.fit", + "unique_qname": "sklearn.linear_model._quantile.QuantileRegressor.fit", "decorators": [], "parameters": [ { @@ -102429,7 +105825,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._ransac.RANSACRegressor.__init__", + "unique_qname": "sklearn.linear_model._ransac.RANSACRegressor.__init__", "decorators": [], "parameters": [ { @@ -102571,7 +105969,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.linear_model._ransac.RANSACRegressor._more_tags", + "unique_qname": "sklearn.linear_model._ransac.RANSACRegressor._more_tags", "decorators": [], "parameters": [ { @@ -102593,7 +105993,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._ransac.RANSACRegressor.fit", + "unique_qname": "sklearn.linear_model._ransac.RANSACRegressor.fit", "decorators": [], "parameters": [ { @@ -102645,7 +106047,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.linear_model._ransac.RANSACRegressor.predict", + "unique_qname": "sklearn.linear_model._ransac.RANSACRegressor.predict", "decorators": [], "parameters": [ { @@ -102677,7 +106081,9 @@ }, { "name": "score", + "unique_name": "score", "qname": "sklearn.linear_model._ransac.RANSACRegressor.score", + "unique_qname": "sklearn.linear_model._ransac.RANSACRegressor.score", "decorators": [], "parameters": [ { @@ -102719,7 +106125,9 @@ }, { "name": "_dynamic_max_trials", + "unique_name": "_dynamic_max_trials", "qname": "sklearn.linear_model._ransac._dynamic_max_trials", + "unique_qname": "sklearn.linear_model._ransac._dynamic_max_trials", "decorators": [], "parameters": [ { @@ -102771,7 +106179,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._ridge.Ridge.__init__", + "unique_qname": "sklearn.linear_model._ridge.Ridge.__init__", "decorators": [], "parameters": [ { @@ -102883,7 +106293,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._ridge.Ridge.fit", + "unique_qname": "sklearn.linear_model._ridge.Ridge.fit", "decorators": [], "parameters": [ { @@ -102931,11 +106343,13 @@ "is_public": true, "description": "Fit Ridge regression model.", "docstring": "Fit Ridge regression model.\n\nParameters\n----------\nX : {ndarray, sparse matrix} of shape (n_samples, n_features)\n Training data.\n\ny : ndarray of shape (n_samples,) or (n_samples, n_targets)\n Target values.\n\nsample_weight : float or ndarray of shape (n_samples,), default=None\n Individual weights for each sample. If given a float, every sample\n will have the same weight.\n\nReturns\n-------\nself : object\n Fitted estimator.", - "source_code": "\ndef fit(self, X, y, sample_weight=None):\n \"\"\"Fit Ridge regression model.\n\n Parameters\n ----------\n X : {ndarray, sparse matrix} of shape (n_samples, n_features)\n Training data.\n\n y : ndarray of shape (n_samples,) or (n_samples, n_targets)\n Target values.\n\n sample_weight : float or ndarray of shape (n_samples,), default=None\n Individual weights for each sample. If given a float, every sample\n will have the same weight.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n return super().fit(X, y, sample_weight=sample_weight)" + "source_code": "\ndef fit(self, X, y, sample_weight=None):\n \"\"\"Fit Ridge regression model.\n\n Parameters\n ----------\n X : {ndarray, sparse matrix} of shape (n_samples, n_features)\n Training data.\n\n y : ndarray of shape (n_samples,) or (n_samples, n_targets)\n Target values.\n\n sample_weight : float or ndarray of shape (n_samples,), default=None\n Individual weights for each sample. If given a float, every sample\n will have the same weight.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n _accept_sparse = _get_valid_accept_sparse(sparse.issparse(X), self.solver)\n (X, y) = self._validate_data(X, y, accept_sparse=_accept_sparse, dtype=[np.float64, np.float32], multi_output=True, y_numeric=True)\n return super().fit(X, y, sample_weight=sample_weight)" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._ridge.RidgeClassifier.__init__", + "unique_qname": "sklearn.linear_model._ridge.RidgeClassifier.__init__", "decorators": [], "parameters": [ { @@ -103057,7 +106471,9 @@ }, { "name": "classes_", + "unique_name": "classes_@getter", "qname": "sklearn.linear_model._ridge.RidgeClassifier.classes_", + "unique_qname": "sklearn.linear_model._ridge.RidgeClassifier.classes_@getter", "decorators": ["property"], "parameters": [ { @@ -103079,7 +106495,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._ridge.RidgeClassifier.fit", + "unique_qname": "sklearn.linear_model._ridge.RidgeClassifier.fit", "decorators": [], "parameters": [ { @@ -103131,7 +106549,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._ridge.RidgeClassifierCV.__init__", + "unique_qname": "sklearn.linear_model._ridge.RidgeClassifierCV.__init__", "decorators": [], "parameters": [ { @@ -103223,7 +106643,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.linear_model._ridge.RidgeClassifierCV._more_tags", + "unique_qname": "sklearn.linear_model._ridge.RidgeClassifierCV._more_tags", "decorators": [], "parameters": [ { @@ -103245,7 +106667,9 @@ }, { "name": "classes_", + "unique_name": "classes_@getter", "qname": "sklearn.linear_model._ridge.RidgeClassifierCV.classes_", + "unique_qname": "sklearn.linear_model._ridge.RidgeClassifierCV.classes_@getter", "decorators": ["property"], "parameters": [ { @@ -103267,7 +106691,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._ridge.RidgeClassifierCV.fit", + "unique_qname": "sklearn.linear_model._ridge.RidgeClassifierCV.fit", "decorators": [], "parameters": [ { @@ -103319,7 +106745,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._ridge._BaseRidge.__init__", + "unique_qname": "sklearn.linear_model._ridge._BaseRidge.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -103431,7 +106859,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._ridge._BaseRidge.fit", + "unique_qname": "sklearn.linear_model._ridge._BaseRidge.fit", "decorators": [], "parameters": [ { @@ -103479,11 +106909,13 @@ "is_public": false, "description": "", "docstring": "", - "source_code": "\ndef fit(self, X, y, sample_weight=None):\n self._normalize = _deprecate_normalize(self.normalize, default=False, estimator_name=self.__class__.__name__)\n _dtype = [np.float64, np.float32]\n _accept_sparse = _get_valid_accept_sparse(sparse.issparse(X), self.solver)\n (X, y) = self._validate_data(X, y, accept_sparse=_accept_sparse, dtype=_dtype, multi_output=True, y_numeric=True)\n if self.solver == 'lbfgs' and not self.positive:\n raise ValueError(\"'lbfgs' solver can be used only when positive=True. Please use another solver.\")\n if self.positive:\n if self.solver not in ['auto', 'lbfgs']:\n raise ValueError(f\"solver='{self.solver}' does not support positive fitting. Please set the solver to 'auto' or 'lbfgs', or set `positive=False`\")\n else:\n solver = self.solver\n elif sparse.issparse(X) and self.fit_intercept:\n if self.solver not in ['auto', 'sparse_cg', 'sag', 'lbfgs']:\n raise ValueError(\"solver='{}' does not support fitting the intercept on sparse data. Please set the solver to 'auto' or 'sparse_cg', 'sag', 'lbfgs' or set `fit_intercept=False`\".format(self.solver))\n if self.solver == 'lbfgs':\n solver = 'lbfgs'\n elif self.solver == 'sag' and self.max_iter is None and self.tol > 0.0001:\n warnings.warn('\"sag\" solver requires many iterations to fit an intercept with sparse inputs. Either set the solver to \"auto\" or \"sparse_cg\", or set a low \"tol\" and a high \"max_iter\" (especially if inputs are not standardized).')\n solver = 'sag'\n else:\n solver = 'sparse_cg'\n else:\n solver = self.solver\n if sample_weight is not None:\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n (X, y, X_offset, y_offset, X_scale) = self._preprocess_data(X, y, self.fit_intercept, self._normalize, self.copy_X, sample_weight=sample_weight, return_mean=True)\n if solver == 'sag' and sparse.issparse(X) and self.fit_intercept:\n (self.coef_, self.n_iter_, self.intercept_) = _ridge_regression(X, y, alpha=self.alpha, sample_weight=sample_weight, max_iter=self.max_iter, tol=self.tol, solver='sag', positive=self.positive, random_state=self.random_state, return_n_iter=True, return_intercept=True, check_input=False)\n self.intercept_ += y_offset\n else:\n if sparse.issparse(X) and self.fit_intercept:\n params = {'X_offset': X_offset, 'X_scale': X_scale}\n else:\n params = {}\n (self.coef_, self.n_iter_) = _ridge_regression(X, y, alpha=self.alpha, sample_weight=sample_weight, max_iter=self.max_iter, tol=self.tol, solver=solver, positive=self.positive, random_state=self.random_state, return_n_iter=True, return_intercept=False, check_input=False, **params)\n self._set_intercept(X_offset, y_offset, X_scale)\n return self" + "source_code": "\ndef fit(self, X, y, sample_weight=None):\n self._normalize = _deprecate_normalize(self.normalize, default=False, estimator_name=self.__class__.__name__)\n if self.solver == 'lbfgs' and not self.positive:\n raise ValueError(\"'lbfgs' solver can be used only when positive=True. Please use another solver.\")\n if self.positive:\n if self.solver not in ['auto', 'lbfgs']:\n raise ValueError(f\"solver='{self.solver}' does not support positive fitting. Please set the solver to 'auto' or 'lbfgs', or set `positive=False`\")\n else:\n solver = self.solver\n elif sparse.issparse(X) and self.fit_intercept:\n if self.solver not in ['auto', 'sparse_cg', 'sag', 'lbfgs']:\n raise ValueError(\"solver='{}' does not support fitting the intercept on sparse data. Please set the solver to 'auto' or 'sparse_cg', 'sag', 'lbfgs' or set `fit_intercept=False`\".format(self.solver))\n if self.solver == 'lbfgs':\n solver = 'lbfgs'\n elif self.solver == 'sag' and self.max_iter is None and self.tol > 0.0001:\n warnings.warn('\"sag\" solver requires many iterations to fit an intercept with sparse inputs. Either set the solver to \"auto\" or \"sparse_cg\", or set a low \"tol\" and a high \"max_iter\" (especially if inputs are not standardized).')\n solver = 'sag'\n else:\n solver = 'sparse_cg'\n else:\n solver = self.solver\n if sample_weight is not None:\n sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)\n (X, y, X_offset, y_offset, X_scale) = self._preprocess_data(X, y, self.fit_intercept, self._normalize, self.copy_X, sample_weight=sample_weight, return_mean=True)\n if solver == 'sag' and sparse.issparse(X) and self.fit_intercept:\n (self.coef_, self.n_iter_, self.intercept_) = _ridge_regression(X, y, alpha=self.alpha, sample_weight=sample_weight, max_iter=self.max_iter, tol=self.tol, solver='sag', positive=self.positive, random_state=self.random_state, return_n_iter=True, return_intercept=True, check_input=False)\n self.intercept_ += y_offset\n else:\n if sparse.issparse(X) and self.fit_intercept:\n params = {'X_offset': X_offset, 'X_scale': X_scale}\n else:\n params = {}\n (self.coef_, self.n_iter_) = _ridge_regression(X, y, alpha=self.alpha, sample_weight=sample_weight, max_iter=self.max_iter, tol=self.tol, solver=solver, positive=self.positive, random_state=self.random_state, return_n_iter=True, return_intercept=False, check_input=False, **params)\n self._set_intercept(X_offset, y_offset, X_scale)\n return self" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._ridge._BaseRidgeCV.__init__", + "unique_qname": "sklearn.linear_model._ridge._BaseRidgeCV.__init__", "decorators": [], "parameters": [ { @@ -103585,7 +107017,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._ridge._BaseRidgeCV.fit", + "unique_qname": "sklearn.linear_model._ridge._BaseRidgeCV.fit", "decorators": [], "parameters": [ { @@ -103637,7 +107071,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._ridge._IdentityClassifier.__init__", + "unique_qname": "sklearn.linear_model._ridge._IdentityClassifier.__init__", "decorators": [], "parameters": [ { @@ -103669,7 +107105,9 @@ }, { "name": "decision_function", + "unique_name": "decision_function", "qname": "sklearn.linear_model._ridge._IdentityClassifier.decision_function", + "unique_qname": "sklearn.linear_model._ridge._IdentityClassifier.decision_function", "decorators": [], "parameters": [ { @@ -103701,7 +107139,9 @@ }, { "name": "decision_function", + "unique_name": "decision_function", "qname": "sklearn.linear_model._ridge._IdentityRegressor.decision_function", + "unique_qname": "sklearn.linear_model._ridge._IdentityRegressor.decision_function", "decorators": [], "parameters": [ { @@ -103733,7 +107173,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.linear_model._ridge._IdentityRegressor.predict", + "unique_qname": "sklearn.linear_model._ridge._IdentityRegressor.predict", "decorators": [], "parameters": [ { @@ -103765,7 +107207,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._ridge._RidgeGCV.__init__", + "unique_qname": "sklearn.linear_model._ridge._RidgeGCV.__init__", "decorators": [], "parameters": [ { @@ -103877,7 +107321,9 @@ }, { "name": "_compute_covariance", + "unique_name": "_compute_covariance", "qname": "sklearn.linear_model._ridge._RidgeGCV._compute_covariance", + "unique_qname": "sklearn.linear_model._ridge._RidgeGCV._compute_covariance", "decorators": [], "parameters": [ { @@ -103919,7 +107365,9 @@ }, { "name": "_compute_gram", + "unique_name": "_compute_gram", "qname": "sklearn.linear_model._ridge._RidgeGCV._compute_gram", + "unique_qname": "sklearn.linear_model._ridge._RidgeGCV._compute_gram", "decorators": [], "parameters": [ { @@ -103961,7 +107409,9 @@ }, { "name": "_decomp_diag", + "unique_name": "_decomp_diag", "qname": "sklearn.linear_model._ridge._RidgeGCV._decomp_diag", + "unique_qname": "sklearn.linear_model._ridge._RidgeGCV._decomp_diag", "decorators": ["staticmethod"], "parameters": [ { @@ -103993,7 +107443,9 @@ }, { "name": "_diag_dot", + "unique_name": "_diag_dot", "qname": "sklearn.linear_model._ridge._RidgeGCV._diag_dot", + "unique_qname": "sklearn.linear_model._ridge._RidgeGCV._diag_dot", "decorators": ["staticmethod"], "parameters": [ { @@ -104025,7 +107477,9 @@ }, { "name": "_eigen_decompose_covariance", + "unique_name": "_eigen_decompose_covariance", "qname": "sklearn.linear_model._ridge._RidgeGCV._eigen_decompose_covariance", + "unique_qname": "sklearn.linear_model._ridge._RidgeGCV._eigen_decompose_covariance", "decorators": [], "parameters": [ { @@ -104077,7 +107531,9 @@ }, { "name": "_eigen_decompose_gram", + "unique_name": "_eigen_decompose_gram", "qname": "sklearn.linear_model._ridge._RidgeGCV._eigen_decompose_gram", + "unique_qname": "sklearn.linear_model._ridge._RidgeGCV._eigen_decompose_gram", "decorators": [], "parameters": [ { @@ -104129,7 +107585,9 @@ }, { "name": "_solve_eigen_covariance", + "unique_name": "_solve_eigen_covariance", "qname": "sklearn.linear_model._ridge._RidgeGCV._solve_eigen_covariance", + "unique_qname": "sklearn.linear_model._ridge._RidgeGCV._solve_eigen_covariance", "decorators": [], "parameters": [ { @@ -104221,7 +107679,9 @@ }, { "name": "_solve_eigen_covariance_intercept", + "unique_name": "_solve_eigen_covariance_intercept", "qname": "sklearn.linear_model._ridge._RidgeGCV._solve_eigen_covariance_intercept", + "unique_qname": "sklearn.linear_model._ridge._RidgeGCV._solve_eigen_covariance_intercept", "decorators": [], "parameters": [ { @@ -104313,7 +107773,9 @@ }, { "name": "_solve_eigen_covariance_no_intercept", + "unique_name": "_solve_eigen_covariance_no_intercept", "qname": "sklearn.linear_model._ridge._RidgeGCV._solve_eigen_covariance_no_intercept", + "unique_qname": "sklearn.linear_model._ridge._RidgeGCV._solve_eigen_covariance_no_intercept", "decorators": [], "parameters": [ { @@ -104405,7 +107867,9 @@ }, { "name": "_solve_eigen_gram", + "unique_name": "_solve_eigen_gram", "qname": "sklearn.linear_model._ridge._RidgeGCV._solve_eigen_gram", + "unique_qname": "sklearn.linear_model._ridge._RidgeGCV._solve_eigen_gram", "decorators": [], "parameters": [ { @@ -104497,7 +107961,9 @@ }, { "name": "_solve_svd_design_matrix", + "unique_name": "_solve_svd_design_matrix", "qname": "sklearn.linear_model._ridge._RidgeGCV._solve_svd_design_matrix", + "unique_qname": "sklearn.linear_model._ridge._RidgeGCV._solve_svd_design_matrix", "decorators": [], "parameters": [ { @@ -104589,7 +108055,9 @@ }, { "name": "_sparse_multidot_diag", + "unique_name": "_sparse_multidot_diag", "qname": "sklearn.linear_model._ridge._RidgeGCV._sparse_multidot_diag", + "unique_qname": "sklearn.linear_model._ridge._RidgeGCV._sparse_multidot_diag", "decorators": [], "parameters": [ { @@ -104651,7 +108119,9 @@ }, { "name": "_svd_decompose_design_matrix", + "unique_name": "_svd_decompose_design_matrix", "qname": "sklearn.linear_model._ridge._RidgeGCV._svd_decompose_design_matrix", + "unique_qname": "sklearn.linear_model._ridge._RidgeGCV._svd_decompose_design_matrix", "decorators": [], "parameters": [ { @@ -104703,7 +108173,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._ridge._RidgeGCV.fit", + "unique_qname": "sklearn.linear_model._ridge._RidgeGCV.fit", "decorators": [], "parameters": [ { @@ -104755,7 +108227,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._ridge._XT_CenterStackOp.__init__", + "unique_qname": "sklearn.linear_model._ridge._XT_CenterStackOp.__init__", "decorators": [], "parameters": [ { @@ -104807,7 +108281,9 @@ }, { "name": "_matmat", + "unique_name": "_matmat", "qname": "sklearn.linear_model._ridge._XT_CenterStackOp._matmat", + "unique_qname": "sklearn.linear_model._ridge._XT_CenterStackOp._matmat", "decorators": [], "parameters": [ { @@ -104839,7 +108315,9 @@ }, { "name": "_matvec", + "unique_name": "_matvec", "qname": "sklearn.linear_model._ridge._XT_CenterStackOp._matvec", + "unique_qname": "sklearn.linear_model._ridge._XT_CenterStackOp._matvec", "decorators": [], "parameters": [ { @@ -104871,7 +108349,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._ridge._X_CenterStackOp.__init__", + "unique_qname": "sklearn.linear_model._ridge._X_CenterStackOp.__init__", "decorators": [], "parameters": [ { @@ -104923,7 +108403,9 @@ }, { "name": "_matmat", + "unique_name": "_matmat", "qname": "sklearn.linear_model._ridge._X_CenterStackOp._matmat", + "unique_qname": "sklearn.linear_model._ridge._X_CenterStackOp._matmat", "decorators": [], "parameters": [ { @@ -104955,7 +108437,9 @@ }, { "name": "_matvec", + "unique_name": "_matvec", "qname": "sklearn.linear_model._ridge._X_CenterStackOp._matvec", + "unique_qname": "sklearn.linear_model._ridge._X_CenterStackOp._matvec", "decorators": [], "parameters": [ { @@ -104987,7 +108471,9 @@ }, { "name": "_transpose", + "unique_name": "_transpose", "qname": "sklearn.linear_model._ridge._X_CenterStackOp._transpose", + "unique_qname": "sklearn.linear_model._ridge._X_CenterStackOp._transpose", "decorators": [], "parameters": [ { @@ -105009,7 +108495,9 @@ }, { "name": "_check_gcv_mode", + "unique_name": "_check_gcv_mode", "qname": "sklearn.linear_model._ridge._check_gcv_mode", + "unique_qname": "sklearn.linear_model._ridge._check_gcv_mode", "decorators": [], "parameters": [ { @@ -105041,7 +108529,9 @@ }, { "name": "_find_smallest_angle", + "unique_name": "_find_smallest_angle", "qname": "sklearn.linear_model._ridge._find_smallest_angle", + "unique_qname": "sklearn.linear_model._ridge._find_smallest_angle", "decorators": [], "parameters": [ { @@ -105073,7 +108563,9 @@ }, { "name": "_get_valid_accept_sparse", + "unique_name": "_get_valid_accept_sparse", "qname": "sklearn.linear_model._ridge._get_valid_accept_sparse", + "unique_qname": "sklearn.linear_model._ridge._get_valid_accept_sparse", "decorators": [], "parameters": [ { @@ -105105,7 +108597,9 @@ }, { "name": "_ridge_regression", + "unique_name": "_ridge_regression", "qname": "sklearn.linear_model._ridge._ridge_regression", + "unique_qname": "sklearn.linear_model._ridge._ridge_regression", "decorators": [], "parameters": [ { @@ -105267,7 +108761,9 @@ }, { "name": "_solve_cholesky", + "unique_name": "_solve_cholesky", "qname": "sklearn.linear_model._ridge._solve_cholesky", + "unique_qname": "sklearn.linear_model._ridge._solve_cholesky", "decorators": [], "parameters": [ { @@ -105309,7 +108805,9 @@ }, { "name": "_solve_cholesky_kernel", + "unique_name": "_solve_cholesky_kernel", "qname": "sklearn.linear_model._ridge._solve_cholesky_kernel", + "unique_qname": "sklearn.linear_model._ridge._solve_cholesky_kernel", "decorators": [], "parameters": [ { @@ -105371,7 +108869,9 @@ }, { "name": "_solve_lbfgs", + "unique_name": "_solve_lbfgs", "qname": "sklearn.linear_model._ridge._solve_lbfgs", + "unique_qname": "sklearn.linear_model._ridge._solve_lbfgs", "decorators": [], "parameters": [ { @@ -105463,7 +108963,9 @@ }, { "name": "_solve_lsqr", + "unique_name": "_solve_lsqr", "qname": "sklearn.linear_model._ridge._solve_lsqr", + "unique_qname": "sklearn.linear_model._ridge._solve_lsqr", "decorators": [], "parameters": [ { @@ -105525,7 +109027,9 @@ }, { "name": "_solve_sparse_cg", + "unique_name": "_solve_sparse_cg", "qname": "sklearn.linear_model._ridge._solve_sparse_cg", + "unique_qname": "sklearn.linear_model._ridge._solve_sparse_cg", "decorators": [], "parameters": [ { @@ -105617,7 +109121,9 @@ }, { "name": "_solve_svd", + "unique_name": "_solve_svd", "qname": "sklearn.linear_model._ridge._solve_svd", + "unique_qname": "sklearn.linear_model._ridge._solve_svd", "decorators": [], "parameters": [ { @@ -105659,7 +109165,9 @@ }, { "name": "ridge_regression", + "unique_name": "ridge_regression", "qname": "sklearn.linear_model._ridge.ridge_regression", + "unique_qname": "sklearn.linear_model._ridge.ridge_regression", "decorators": [], "parameters": [ { @@ -105801,7 +109309,9 @@ }, { "name": "get_auto_step_size", + "unique_name": "get_auto_step_size", "qname": "sklearn.linear_model._sag.get_auto_step_size", + "unique_qname": "sklearn.linear_model._sag.get_auto_step_size", "decorators": [], "parameters": [ { @@ -105873,7 +109383,9 @@ }, { "name": "sag_solver", + "unique_name": "sag_solver", "qname": "sklearn.linear_model._sag.sag_solver", + "unique_qname": "sklearn.linear_model._sag.sag_solver", "decorators": [], "parameters": [ { @@ -106025,7 +109537,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._stochastic_gradient.BaseSGD.__init__", + "unique_qname": "sklearn.linear_model._stochastic_gradient.BaseSGD.__init__", "decorators": [], "parameters": [ { @@ -106247,7 +109761,9 @@ }, { "name": "_allocate_parameter_mem", + "unique_name": "_allocate_parameter_mem", "qname": "sklearn.linear_model._stochastic_gradient.BaseSGD._allocate_parameter_mem", + "unique_qname": "sklearn.linear_model._stochastic_gradient.BaseSGD._allocate_parameter_mem", "decorators": [], "parameters": [ { @@ -106319,7 +109835,9 @@ }, { "name": "_get_learning_rate_type", + "unique_name": "_get_learning_rate_type", "qname": "sklearn.linear_model._stochastic_gradient.BaseSGD._get_learning_rate_type", + "unique_qname": "sklearn.linear_model._stochastic_gradient.BaseSGD._get_learning_rate_type", "decorators": [], "parameters": [ { @@ -106351,7 +109869,9 @@ }, { "name": "_get_loss_function", + "unique_name": "_get_loss_function", "qname": "sklearn.linear_model._stochastic_gradient.BaseSGD._get_loss_function", + "unique_qname": "sklearn.linear_model._stochastic_gradient.BaseSGD._get_loss_function", "decorators": [], "parameters": [ { @@ -106383,7 +109903,9 @@ }, { "name": "_get_penalty_type", + "unique_name": "_get_penalty_type", "qname": "sklearn.linear_model._stochastic_gradient.BaseSGD._get_penalty_type", + "unique_qname": "sklearn.linear_model._stochastic_gradient.BaseSGD._get_penalty_type", "decorators": [], "parameters": [ { @@ -106415,7 +109937,9 @@ }, { "name": "_make_validation_score_cb", + "unique_name": "_make_validation_score_cb", "qname": "sklearn.linear_model._stochastic_gradient.BaseSGD._make_validation_score_cb", + "unique_qname": "sklearn.linear_model._stochastic_gradient.BaseSGD._make_validation_score_cb", "decorators": [], "parameters": [ { @@ -106487,7 +110011,9 @@ }, { "name": "_make_validation_split", + "unique_name": "_make_validation_split", "qname": "sklearn.linear_model._stochastic_gradient.BaseSGD._make_validation_split", + "unique_qname": "sklearn.linear_model._stochastic_gradient.BaseSGD._make_validation_split", "decorators": [], "parameters": [ { @@ -106519,7 +110045,9 @@ }, { "name": "_validate_params", + "unique_name": "_validate_params", "qname": "sklearn.linear_model._stochastic_gradient.BaseSGD._validate_params", + "unique_qname": "sklearn.linear_model._stochastic_gradient.BaseSGD._validate_params", "decorators": [], "parameters": [ { @@ -106551,7 +110079,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._stochastic_gradient.BaseSGD.fit", + "unique_qname": "sklearn.linear_model._stochastic_gradient.BaseSGD.fit", "decorators": ["abstractmethod"], "parameters": [ { @@ -106593,7 +110123,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._stochastic_gradient.BaseSGDClassifier.__init__", + "unique_qname": "sklearn.linear_model._stochastic_gradient.BaseSGDClassifier.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -106825,7 +110357,9 @@ }, { "name": "_fit", + "unique_name": "_fit", "qname": "sklearn.linear_model._stochastic_gradient.BaseSGDClassifier._fit", + "unique_qname": "sklearn.linear_model._stochastic_gradient.BaseSGDClassifier._fit", "decorators": [], "parameters": [ { @@ -106933,11 +110467,13 @@ "is_public": false, "description": "", "docstring": "", - "source_code": "\ndef _fit(self, X, y, alpha, C, loss, learning_rate, coef_init=None, intercept_init=None, sample_weight=None):\n self._validate_params()\n if hasattr(self, 'classes_'):\n self.classes_ = None\n (X, y) = self._validate_data(X, y, accept_sparse='csr', dtype=np.float64, order='C', accept_large_sparse=False)\n classes = np.unique(y)\n if self.warm_start and hasattr(self, 'coef_'):\n if coef_init is None:\n coef_init = self.coef_\n if intercept_init is None:\n intercept_init = self.intercept_\n else:\n self.coef_ = None\n self.intercept_ = None\n if self.average > 0:\n self._standard_coef = self.coef_\n self._standard_intercept = self.intercept_\n self._average_coef = None\n self._average_intercept = None\n self.t_ = 1.0\n self._partial_fit(X, y, alpha, C, loss, learning_rate, self.max_iter, classes, sample_weight, coef_init, intercept_init)\n if self.tol is not None and self.tol > -np.inf and self.n_iter_ == self.max_iter:\n warnings.warn('Maximum number of iteration reached before convergence. Consider increasing max_iter to improve the fit.', ConvergenceWarning)\n return self" + "source_code": "\ndef _fit(self, X, y, alpha, C, loss, learning_rate, coef_init=None, intercept_init=None, sample_weight=None):\n self._validate_params()\n if hasattr(self, 'classes_'):\n delattr(self, 'classes_')\n y = self._validate_data(y=y)\n classes = np.unique(y)\n if self.warm_start and hasattr(self, 'coef_'):\n if coef_init is None:\n coef_init = self.coef_\n if intercept_init is None:\n intercept_init = self.intercept_\n else:\n self.coef_ = None\n self.intercept_ = None\n if self.average > 0:\n self._standard_coef = self.coef_\n self._standard_intercept = self.intercept_\n self._average_coef = None\n self._average_intercept = None\n self.t_ = 1.0\n self._partial_fit(X, y, alpha, C, loss, learning_rate, self.max_iter, classes, sample_weight, coef_init, intercept_init)\n if self.tol is not None and self.tol > -np.inf and self.n_iter_ == self.max_iter:\n warnings.warn('Maximum number of iteration reached before convergence. Consider increasing max_iter to improve the fit.', ConvergenceWarning)\n return self" }, { "name": "_fit_binary", + "unique_name": "_fit_binary", "qname": "sklearn.linear_model._stochastic_gradient.BaseSGDClassifier._fit_binary", + "unique_qname": "sklearn.linear_model._stochastic_gradient.BaseSGDClassifier._fit_binary", "decorators": [], "parameters": [ { @@ -107029,7 +110565,9 @@ }, { "name": "_fit_multiclass", + "unique_name": "_fit_multiclass", "qname": "sklearn.linear_model._stochastic_gradient.BaseSGDClassifier._fit_multiclass", + "unique_qname": "sklearn.linear_model._stochastic_gradient.BaseSGDClassifier._fit_multiclass", "decorators": [], "parameters": [ { @@ -107121,7 +110659,9 @@ }, { "name": "_partial_fit", + "unique_name": "_partial_fit", "qname": "sklearn.linear_model._stochastic_gradient.BaseSGDClassifier._partial_fit", + "unique_qname": "sklearn.linear_model._stochastic_gradient.BaseSGDClassifier._partial_fit", "decorators": [], "parameters": [ { @@ -107253,7 +110793,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._stochastic_gradient.BaseSGDClassifier.fit", + "unique_qname": "sklearn.linear_model._stochastic_gradient.BaseSGDClassifier.fit", "decorators": [], "parameters": [ { @@ -107325,7 +110867,9 @@ }, { "name": "partial_fit", + "unique_name": "partial_fit", "qname": "sklearn.linear_model._stochastic_gradient.BaseSGDClassifier.partial_fit", + "unique_qname": "sklearn.linear_model._stochastic_gradient.BaseSGDClassifier.partial_fit", "decorators": [], "parameters": [ { @@ -107387,7 +110931,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._stochastic_gradient.BaseSGDRegressor.__init__", + "unique_qname": "sklearn.linear_model._stochastic_gradient.BaseSGDRegressor.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -107599,7 +111145,9 @@ }, { "name": "_decision_function", + "unique_name": "_decision_function", "qname": "sklearn.linear_model._stochastic_gradient.BaseSGDRegressor._decision_function", + "unique_qname": "sklearn.linear_model._stochastic_gradient.BaseSGDRegressor._decision_function", "decorators": [], "parameters": [ { @@ -107631,7 +111179,9 @@ }, { "name": "_fit", + "unique_name": "_fit", "qname": "sklearn.linear_model._stochastic_gradient.BaseSGDRegressor._fit", + "unique_qname": "sklearn.linear_model._stochastic_gradient.BaseSGDRegressor._fit", "decorators": [], "parameters": [ { @@ -107743,7 +111293,9 @@ }, { "name": "_fit_regressor", + "unique_name": "_fit_regressor", "qname": "sklearn.linear_model._stochastic_gradient.BaseSGDRegressor._fit_regressor", + "unique_qname": "sklearn.linear_model._stochastic_gradient.BaseSGDRegressor._fit_regressor", "decorators": [], "parameters": [ { @@ -107845,7 +111397,9 @@ }, { "name": "_partial_fit", + "unique_name": "_partial_fit", "qname": "sklearn.linear_model._stochastic_gradient.BaseSGDRegressor._partial_fit", + "unique_qname": "sklearn.linear_model._stochastic_gradient.BaseSGDRegressor._partial_fit", "decorators": [], "parameters": [ { @@ -107967,7 +111521,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._stochastic_gradient.BaseSGDRegressor.fit", + "unique_qname": "sklearn.linear_model._stochastic_gradient.BaseSGDRegressor.fit", "decorators": [], "parameters": [ { @@ -107987,7 +111543,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "{array-like, sparse matrix}, shape (n_samples, n_features)", - "description": "Training data" + "description": "Training data." } }, { @@ -107997,7 +111553,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "ndarray of shape (n_samples,)", - "description": "Target values" + "description": "Target values." } }, { @@ -108034,12 +111590,14 @@ "results": [], "is_public": false, "description": "Fit linear model with Stochastic Gradient Descent.", - "docstring": "Fit linear model with Stochastic Gradient Descent.\n\nParameters\n----------\nX : {array-like, sparse matrix}, shape (n_samples, n_features)\n Training data\n\ny : ndarray of shape (n_samples,)\n Target values\n\ncoef_init : ndarray of shape (n_features,), default=None\n The initial coefficients to warm-start the optimization.\n\nintercept_init : ndarray of shape (1,), default=None\n The initial intercept to warm-start the optimization.\n\nsample_weight : array-like, shape (n_samples,), default=None\n Weights applied to individual samples (1. for unweighted).\n\nReturns\n-------\nself : returns an instance of self.", - "source_code": "\ndef fit(self, X, y, coef_init=None, intercept_init=None, sample_weight=None):\n \"\"\"Fit linear model with Stochastic Gradient Descent.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Training data\n\n y : ndarray of shape (n_samples,)\n Target values\n\n coef_init : ndarray of shape (n_features,), default=None\n The initial coefficients to warm-start the optimization.\n\n intercept_init : ndarray of shape (1,), default=None\n The initial intercept to warm-start the optimization.\n\n sample_weight : array-like, shape (n_samples,), default=None\n Weights applied to individual samples (1. for unweighted).\n\n Returns\n -------\n self : returns an instance of self.\n \"\"\"\n return self._fit(X, y, alpha=self.alpha, C=1.0, loss=self.loss, learning_rate=self.learning_rate, coef_init=coef_init, intercept_init=intercept_init, sample_weight=sample_weight)" + "docstring": "Fit linear model with Stochastic Gradient Descent.\n\nParameters\n----------\nX : {array-like, sparse matrix}, shape (n_samples, n_features)\n Training data.\n\ny : ndarray of shape (n_samples,)\n Target values.\n\ncoef_init : ndarray of shape (n_features,), default=None\n The initial coefficients to warm-start the optimization.\n\nintercept_init : ndarray of shape (1,), default=None\n The initial intercept to warm-start the optimization.\n\nsample_weight : array-like, shape (n_samples,), default=None\n Weights applied to individual samples (1. for unweighted).\n\nReturns\n-------\nself : object\n Fitted `SGDRegressor` estimator.", + "source_code": "\ndef fit(self, X, y, coef_init=None, intercept_init=None, sample_weight=None):\n \"\"\"Fit linear model with Stochastic Gradient Descent.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Training data.\n\n y : ndarray of shape (n_samples,)\n Target values.\n\n coef_init : ndarray of shape (n_features,), default=None\n The initial coefficients to warm-start the optimization.\n\n intercept_init : ndarray of shape (1,), default=None\n The initial intercept to warm-start the optimization.\n\n sample_weight : array-like, shape (n_samples,), default=None\n Weights applied to individual samples (1. for unweighted).\n\n Returns\n -------\n self : object\n Fitted `SGDRegressor` estimator.\n \"\"\"\n return self._fit(X, y, alpha=self.alpha, C=1.0, loss=self.loss, learning_rate=self.learning_rate, coef_init=coef_init, intercept_init=intercept_init, sample_weight=sample_weight)" }, { "name": "partial_fit", + "unique_name": "partial_fit", "qname": "sklearn.linear_model._stochastic_gradient.BaseSGDRegressor.partial_fit", + "unique_qname": "sklearn.linear_model._stochastic_gradient.BaseSGDRegressor.partial_fit", "decorators": [], "parameters": [ { @@ -108059,7 +111617,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "{array-like, sparse matrix}, shape (n_samples, n_features)", - "description": "Subset of training data" + "description": "Subset of training data." } }, { @@ -108069,7 +111627,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "numpy array of shape (n_samples,)", - "description": "Subset of target values" + "description": "Subset of target values." } }, { @@ -108086,12 +111644,14 @@ "results": [], "is_public": false, "description": "Perform one epoch of stochastic gradient descent on given samples.\n\nInternally, this method uses ``max_iter = 1``. Therefore, it is not guaranteed that a minimum of the cost function is reached after calling it once. Matters such as objective convergence and early stopping should be handled by the user.", - "docstring": "Perform one epoch of stochastic gradient descent on given samples.\n\nInternally, this method uses ``max_iter = 1``. Therefore, it is not\nguaranteed that a minimum of the cost function is reached after calling\nit once. Matters such as objective convergence and early stopping\nshould be handled by the user.\n\nParameters\n----------\nX : {array-like, sparse matrix}, shape (n_samples, n_features)\n Subset of training data\n\ny : numpy array of shape (n_samples,)\n Subset of target values\n\nsample_weight : array-like, shape (n_samples,), default=None\n Weights applied to individual samples.\n If not provided, uniform weights are assumed.\n\nReturns\n-------\nself : returns an instance of self.", - "source_code": "\ndef partial_fit(self, X, y, sample_weight=None):\n \"\"\"Perform one epoch of stochastic gradient descent on given samples.\n\n Internally, this method uses ``max_iter = 1``. Therefore, it is not\n guaranteed that a minimum of the cost function is reached after calling\n it once. Matters such as objective convergence and early stopping\n should be handled by the user.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Subset of training data\n\n y : numpy array of shape (n_samples,)\n Subset of target values\n\n sample_weight : array-like, shape (n_samples,), default=None\n Weights applied to individual samples.\n If not provided, uniform weights are assumed.\n\n Returns\n -------\n self : returns an instance of self.\n \"\"\"\n self._validate_params(for_partial_fit=True)\n return self._partial_fit(X, y, self.alpha, C=1.0, loss=self.loss, learning_rate=self.learning_rate, max_iter=1, sample_weight=sample_weight, coef_init=None, intercept_init=None)" + "docstring": "Perform one epoch of stochastic gradient descent on given samples.\n\nInternally, this method uses ``max_iter = 1``. Therefore, it is not\nguaranteed that a minimum of the cost function is reached after calling\nit once. Matters such as objective convergence and early stopping\nshould be handled by the user.\n\nParameters\n----------\nX : {array-like, sparse matrix}, shape (n_samples, n_features)\n Subset of training data.\n\ny : numpy array of shape (n_samples,)\n Subset of target values.\n\nsample_weight : array-like, shape (n_samples,), default=None\n Weights applied to individual samples.\n If not provided, uniform weights are assumed.\n\nReturns\n-------\nself : object\n Returns an instance of self.", + "source_code": "\ndef partial_fit(self, X, y, sample_weight=None):\n \"\"\"Perform one epoch of stochastic gradient descent on given samples.\n\n Internally, this method uses ``max_iter = 1``. Therefore, it is not\n guaranteed that a minimum of the cost function is reached after calling\n it once. Matters such as objective convergence and early stopping\n should be handled by the user.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Subset of training data.\n\n y : numpy array of shape (n_samples,)\n Subset of target values.\n\n sample_weight : array-like, shape (n_samples,), default=None\n Weights applied to individual samples.\n If not provided, uniform weights are assumed.\n\n Returns\n -------\n self : object\n Returns an instance of self.\n \"\"\"\n self._validate_params(for_partial_fit=True)\n return self._partial_fit(X, y, self.alpha, C=1.0, loss=self.loss, learning_rate=self.learning_rate, max_iter=1, sample_weight=sample_weight, coef_init=None, intercept_init=None)" }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.linear_model._stochastic_gradient.BaseSGDRegressor.predict", + "unique_qname": "sklearn.linear_model._stochastic_gradient.BaseSGDRegressor.predict", "decorators": [], "parameters": [ { @@ -108111,19 +111671,21 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "{array-like, sparse matrix}, shape (n_samples, n_features)", - "description": "" + "description": "Input data." } } ], "results": [], "is_public": false, - "description": "Predict using the linear model", - "docstring": "Predict using the linear model\n\nParameters\n----------\nX : {array-like, sparse matrix}, shape (n_samples, n_features)\n\nReturns\n-------\nndarray of shape (n_samples,)\n Predicted target values per element in X.", - "source_code": "\ndef predict(self, X):\n \"\"\"Predict using the linear model\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n\n Returns\n -------\n ndarray of shape (n_samples,)\n Predicted target values per element in X.\n \"\"\"\n return self._decision_function(X)" + "description": "Predict using the linear model.", + "docstring": "Predict using the linear model.\n\nParameters\n----------\nX : {array-like, sparse matrix}, shape (n_samples, n_features)\n Input data.\n\nReturns\n-------\nndarray of shape (n_samples,)\n Predicted target values per element in X.", + "source_code": "\ndef predict(self, X):\n \"\"\"Predict using the linear model.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Input data.\n\n Returns\n -------\n ndarray of shape (n_samples,)\n Predicted target values per element in X.\n \"\"\"\n return self._decision_function(X)" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._stochastic_gradient.SGDClassifier.__init__", + "unique_qname": "sklearn.linear_model._stochastic_gradient.SGDClassifier.__init__", "decorators": [], "parameters": [ { @@ -108355,7 +111917,9 @@ }, { "name": "_check_proba", + "unique_name": "_check_proba", "qname": "sklearn.linear_model._stochastic_gradient.SGDClassifier._check_proba", + "unique_qname": "sklearn.linear_model._stochastic_gradient.SGDClassifier._check_proba", "decorators": [], "parameters": [ { @@ -108377,7 +111941,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.linear_model._stochastic_gradient.SGDClassifier._more_tags", + "unique_qname": "sklearn.linear_model._stochastic_gradient.SGDClassifier._more_tags", "decorators": [], "parameters": [ { @@ -108399,7 +111965,9 @@ }, { "name": "predict_log_proba", + "unique_name": "predict_log_proba", "qname": "sklearn.linear_model._stochastic_gradient.SGDClassifier.predict_log_proba", + "unique_qname": "sklearn.linear_model._stochastic_gradient.SGDClassifier.predict_log_proba", "decorators": ["available_if(_check_proba)"], "parameters": [ { @@ -108431,7 +111999,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.linear_model._stochastic_gradient.SGDClassifier.predict_proba", + "unique_qname": "sklearn.linear_model._stochastic_gradient.SGDClassifier.predict_proba", "decorators": ["available_if(_check_proba)"], "parameters": [ { @@ -108458,12 +112028,14 @@ "results": [], "is_public": true, "description": "Probability estimates.\n\nThis method is only available for log loss and modified Huber loss. Multiclass probability estimates are derived from binary (one-vs.-rest) estimates by simple normalization, as recommended by Zadrozny and Elkan. Binary probability estimates for loss=\"modified_huber\" are given by (clip(decision_function(X), -1, 1) + 1) / 2. For other loss functions it is necessary to perform proper probability calibration by wrapping the classifier with :class:`~sklearn.calibration.CalibratedClassifierCV` instead.", - "docstring": "Probability estimates.\n\nThis method is only available for log loss and modified Huber loss.\n\nMulticlass probability estimates are derived from binary (one-vs.-rest)\nestimates by simple normalization, as recommended by Zadrozny and\nElkan.\n\nBinary probability estimates for loss=\"modified_huber\" are given by\n(clip(decision_function(X), -1, 1) + 1) / 2. For other loss functions\nit is necessary to perform proper probability calibration by wrapping\nthe classifier with\n:class:`~sklearn.calibration.CalibratedClassifierCV` instead.\n\nParameters\n----------\nX : {array-like, sparse matrix}, shape (n_samples, n_features)\n Input data for prediction.\n\nReturns\n-------\nndarray of shape (n_samples, n_classes)\n Returns the probability of the sample for each class in the model,\n where classes are ordered as they are in `self.classes_`.\n\nReferences\n----------\nZadrozny and Elkan, \"Transforming classifier scores into multiclass\nprobability estimates\", SIGKDD'02,\nhttp://www.research.ibm.com/people/z/zadrozny/kdd2002-Transf.pdf\n\nThe justification for the formula in the loss=\"modified_huber\"\ncase is in the appendix B in:\nhttp://jmlr.csail.mit.edu/papers/volume2/zhang02c/zhang02c.pdf", - "source_code": "\n@available_if(_check_proba)\ndef predict_proba(self, X):\n \"\"\"Probability estimates.\n\n This method is only available for log loss and modified Huber loss.\n\n Multiclass probability estimates are derived from binary (one-vs.-rest)\n estimates by simple normalization, as recommended by Zadrozny and\n Elkan.\n\n Binary probability estimates for loss=\"modified_huber\" are given by\n (clip(decision_function(X), -1, 1) + 1) / 2. For other loss functions\n it is necessary to perform proper probability calibration by wrapping\n the classifier with\n :class:`~sklearn.calibration.CalibratedClassifierCV` instead.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Input data for prediction.\n\n Returns\n -------\n ndarray of shape (n_samples, n_classes)\n Returns the probability of the sample for each class in the model,\n where classes are ordered as they are in `self.classes_`.\n\n References\n ----------\n Zadrozny and Elkan, \"Transforming classifier scores into multiclass\n probability estimates\", SIGKDD'02,\n http://www.research.ibm.com/people/z/zadrozny/kdd2002-Transf.pdf\n\n The justification for the formula in the loss=\"modified_huber\"\n case is in the appendix B in:\n http://jmlr.csail.mit.edu/papers/volume2/zhang02c/zhang02c.pdf\n \"\"\"\n check_is_fitted(self)\n if self.loss == 'log':\n return self._predict_proba_lr(X)\n elif self.loss == 'modified_huber':\n binary = len(self.classes_) == 2\n scores = self.decision_function(X)\n if binary:\n prob2 = np.ones((scores.shape[0], 2))\n prob = prob2[:, 1]\n else:\n prob = scores\n np.clip(scores, -1, 1, prob)\n prob += 1.0\n prob /= 2.0\n if binary:\n prob2[:, 0] -= prob\n prob = prob2\n else:\n prob_sum = prob.sum(axis=1)\n all_zero = prob_sum == 0\n if np.any(all_zero):\n prob[all_zero, :] = 1\n prob_sum[all_zero] = len(self.classes_)\n prob /= prob_sum.reshape((prob.shape[0], -1))\n return prob\n else:\n raise NotImplementedError(\"predict_(log_)proba only supported when loss='log' or loss='modified_huber' (%r given)\" % self.loss)" + "docstring": "Probability estimates.\n\nThis method is only available for log loss and modified Huber loss.\n\nMulticlass probability estimates are derived from binary (one-vs.-rest)\nestimates by simple normalization, as recommended by Zadrozny and\nElkan.\n\nBinary probability estimates for loss=\"modified_huber\" are given by\n(clip(decision_function(X), -1, 1) + 1) / 2. For other loss functions\nit is necessary to perform proper probability calibration by wrapping\nthe classifier with\n:class:`~sklearn.calibration.CalibratedClassifierCV` instead.\n\nParameters\n----------\nX : {array-like, sparse matrix}, shape (n_samples, n_features)\n Input data for prediction.\n\nReturns\n-------\nndarray of shape (n_samples, n_classes)\n Returns the probability of the sample for each class in the model,\n where classes are ordered as they are in `self.classes_`.\n\nReferences\n----------\nZadrozny and Elkan, \"Transforming classifier scores into multiclass\nprobability estimates\", SIGKDD'02,\nhttps://dl.acm.org/doi/pdf/10.1145/775047.775151\n\nThe justification for the formula in the loss=\"modified_huber\"\ncase is in the appendix B in:\nhttp://jmlr.csail.mit.edu/papers/volume2/zhang02c/zhang02c.pdf", + "source_code": "\n@available_if(_check_proba)\ndef predict_proba(self, X):\n \"\"\"Probability estimates.\n\n This method is only available for log loss and modified Huber loss.\n\n Multiclass probability estimates are derived from binary (one-vs.-rest)\n estimates by simple normalization, as recommended by Zadrozny and\n Elkan.\n\n Binary probability estimates for loss=\"modified_huber\" are given by\n (clip(decision_function(X), -1, 1) + 1) / 2. For other loss functions\n it is necessary to perform proper probability calibration by wrapping\n the classifier with\n :class:`~sklearn.calibration.CalibratedClassifierCV` instead.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Input data for prediction.\n\n Returns\n -------\n ndarray of shape (n_samples, n_classes)\n Returns the probability of the sample for each class in the model,\n where classes are ordered as they are in `self.classes_`.\n\n References\n ----------\n Zadrozny and Elkan, \"Transforming classifier scores into multiclass\n probability estimates\", SIGKDD'02,\n https://dl.acm.org/doi/pdf/10.1145/775047.775151\n\n The justification for the formula in the loss=\"modified_huber\"\n case is in the appendix B in:\n http://jmlr.csail.mit.edu/papers/volume2/zhang02c/zhang02c.pdf\n \"\"\"\n check_is_fitted(self)\n if self.loss == 'log':\n return self._predict_proba_lr(X)\n elif self.loss == 'modified_huber':\n binary = len(self.classes_) == 2\n scores = self.decision_function(X)\n if binary:\n prob2 = np.ones((scores.shape[0], 2))\n prob = prob2[:, 1]\n else:\n prob = scores\n np.clip(scores, -1, 1, prob)\n prob += 1.0\n prob /= 2.0\n if binary:\n prob2[:, 0] -= prob\n prob = prob2\n else:\n prob_sum = prob.sum(axis=1)\n all_zero = prob_sum == 0\n if np.any(all_zero):\n prob[all_zero, :] = 1\n prob_sum[all_zero] = len(self.classes_)\n prob /= prob_sum.reshape((prob.shape[0], -1))\n return prob\n else:\n raise NotImplementedError(\"predict_(log_)proba only supported when loss='log' or loss='modified_huber' (%r given)\" % self.loss)" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._stochastic_gradient.SGDOneClassSVM.__init__", + "unique_qname": "sklearn.linear_model._stochastic_gradient.SGDOneClassSVM.__init__", "decorators": [], "parameters": [ { @@ -108532,8 +112104,8 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "integer, optional", - "description": "The verbosity level" + "type": "int, optional", + "description": "The verbosity level." } }, { @@ -108552,7 +112124,7 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "string, optional", + "type": "str, optional", "description": "The learning rate schedule to use with `fit`. (If using `partial_fit`,\nlearning rate must be controlled directly).\n\n'constant':\n eta = eta0\n'optimal': [default]\n eta = 1.0 / (alpha * (t + t0))\n where t0 is chosen by a heuristic proposed by Leon Bottou.\n'invscaling':\n eta = eta0 / pow(t, power_t)\n'adaptive':\n eta = eta0, as long as the training keeps decreasing.\n Each time n_iter_no_change consecutive epochs fail to decrease the\n training loss by tol or fail to increase validation score by tol if\n early_stopping is True, the current learning rate is divided by 5." } }, @@ -108605,7 +112177,9 @@ }, { "name": "_fit", + "unique_name": "_fit", "qname": "sklearn.linear_model._stochastic_gradient.SGDOneClassSVM._fit", + "unique_qname": "sklearn.linear_model._stochastic_gradient.SGDOneClassSVM._fit", "decorators": [], "parameters": [ { @@ -108707,7 +112281,9 @@ }, { "name": "_fit_one_class", + "unique_name": "_fit_one_class", "qname": "sklearn.linear_model._stochastic_gradient.SGDOneClassSVM._fit_one_class", + "unique_qname": "sklearn.linear_model._stochastic_gradient.SGDOneClassSVM._fit_one_class", "decorators": [], "parameters": [ { @@ -108789,7 +112365,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.linear_model._stochastic_gradient.SGDOneClassSVM._more_tags", + "unique_qname": "sklearn.linear_model._stochastic_gradient.SGDOneClassSVM._more_tags", "decorators": [], "parameters": [ { @@ -108811,7 +112389,9 @@ }, { "name": "_partial_fit", + "unique_name": "_partial_fit", "qname": "sklearn.linear_model._stochastic_gradient.SGDOneClassSVM._partial_fit", + "unique_qname": "sklearn.linear_model._stochastic_gradient.SGDOneClassSVM._partial_fit", "decorators": [], "parameters": [ { @@ -108923,7 +112503,9 @@ }, { "name": "_validate_params", + "unique_name": "_validate_params", "qname": "sklearn.linear_model._stochastic_gradient.SGDOneClassSVM._validate_params", + "unique_qname": "sklearn.linear_model._stochastic_gradient.SGDOneClassSVM._validate_params", "decorators": [], "parameters": [ { @@ -108955,7 +112537,9 @@ }, { "name": "decision_function", + "unique_name": "decision_function", "qname": "sklearn.linear_model._stochastic_gradient.SGDOneClassSVM.decision_function", + "unique_qname": "sklearn.linear_model._stochastic_gradient.SGDOneClassSVM.decision_function", "decorators": [], "parameters": [ { @@ -108987,7 +112571,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._stochastic_gradient.SGDOneClassSVM.fit", + "unique_qname": "sklearn.linear_model._stochastic_gradient.SGDOneClassSVM.fit", "decorators": [], "parameters": [ { @@ -109016,8 +112602,8 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "", - "description": "" + "type": "Ignored", + "description": "Not used, present for API consistency by convention." } }, { @@ -109054,12 +112640,14 @@ "results": [], "is_public": true, "description": "Fit linear One-Class SVM with Stochastic Gradient Descent.\n\nThis solves an equivalent optimization problem of the One-Class SVM primal optimization problem and returns a weight vector w and an offset rho such that the decision function is given by - rho.", - "docstring": "Fit linear One-Class SVM with Stochastic Gradient Descent.\n\nThis solves an equivalent optimization problem of the\nOne-Class SVM primal optimization problem and returns a weight vector\nw and an offset rho such that the decision function is given by\n - rho.\n\nParameters\n----------\nX : {array-like, sparse matrix}, shape (n_samples, n_features)\n Training data.\n\ncoef_init : array, shape (n_classes, n_features)\n The initial coefficients to warm-start the optimization.\n\noffset_init : array, shape (n_classes,)\n The initial offset to warm-start the optimization.\n\nsample_weight : array-like, shape (n_samples,), optional\n Weights applied to individual samples.\n If not provided, uniform weights are assumed. These weights will\n be multiplied with class_weight (passed through the\n constructor) if class_weight is specified.\n\nReturns\n-------\nself : returns an instance of self.", - "source_code": "\ndef fit(self, X, y=None, coef_init=None, offset_init=None, sample_weight=None):\n \"\"\"Fit linear One-Class SVM with Stochastic Gradient Descent.\n\n This solves an equivalent optimization problem of the\n One-Class SVM primal optimization problem and returns a weight vector\n w and an offset rho such that the decision function is given by\n - rho.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Training data.\n\n coef_init : array, shape (n_classes, n_features)\n The initial coefficients to warm-start the optimization.\n\n offset_init : array, shape (n_classes,)\n The initial offset to warm-start the optimization.\n\n sample_weight : array-like, shape (n_samples,), optional\n Weights applied to individual samples.\n If not provided, uniform weights are assumed. These weights will\n be multiplied with class_weight (passed through the\n constructor) if class_weight is specified.\n\n Returns\n -------\n self : returns an instance of self.\n \"\"\"\n alpha = self.nu / 2\n self._fit(X, alpha=alpha, C=1.0, loss=self.loss, learning_rate=self.learning_rate, coef_init=coef_init, offset_init=offset_init, sample_weight=sample_weight)\n return self" + "docstring": "Fit linear One-Class SVM with Stochastic Gradient Descent.\n\nThis solves an equivalent optimization problem of the\nOne-Class SVM primal optimization problem and returns a weight vector\nw and an offset rho such that the decision function is given by\n - rho.\n\nParameters\n----------\nX : {array-like, sparse matrix}, shape (n_samples, n_features)\n Training data.\ny : Ignored\n Not used, present for API consistency by convention.\n\ncoef_init : array, shape (n_classes, n_features)\n The initial coefficients to warm-start the optimization.\n\noffset_init : array, shape (n_classes,)\n The initial offset to warm-start the optimization.\n\nsample_weight : array-like, shape (n_samples,), optional\n Weights applied to individual samples.\n If not provided, uniform weights are assumed. These weights will\n be multiplied with class_weight (passed through the\n constructor) if class_weight is specified.\n\nReturns\n-------\nself : object\n Returns a fitted instance of self.", + "source_code": "\ndef fit(self, X, y=None, coef_init=None, offset_init=None, sample_weight=None):\n \"\"\"Fit linear One-Class SVM with Stochastic Gradient Descent.\n\n This solves an equivalent optimization problem of the\n One-Class SVM primal optimization problem and returns a weight vector\n w and an offset rho such that the decision function is given by\n - rho.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Training data.\n y : Ignored\n Not used, present for API consistency by convention.\n\n coef_init : array, shape (n_classes, n_features)\n The initial coefficients to warm-start the optimization.\n\n offset_init : array, shape (n_classes,)\n The initial offset to warm-start the optimization.\n\n sample_weight : array-like, shape (n_samples,), optional\n Weights applied to individual samples.\n If not provided, uniform weights are assumed. These weights will\n be multiplied with class_weight (passed through the\n constructor) if class_weight is specified.\n\n Returns\n -------\n self : object\n Returns a fitted instance of self.\n \"\"\"\n alpha = self.nu / 2\n self._fit(X, alpha=alpha, C=1.0, loss=self.loss, learning_rate=self.learning_rate, coef_init=coef_init, offset_init=offset_init, sample_weight=sample_weight)\n return self" }, { "name": "partial_fit", + "unique_name": "partial_fit", "qname": "sklearn.linear_model._stochastic_gradient.SGDOneClassSVM.partial_fit", + "unique_qname": "sklearn.linear_model._stochastic_gradient.SGDOneClassSVM.partial_fit", "decorators": [], "parameters": [ { @@ -109088,8 +112676,8 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "", - "description": "" + "type": "Ignored", + "description": "Not used, present for API consistency by convention." } }, { @@ -109106,12 +112694,14 @@ "results": [], "is_public": true, "description": "Fit linear One-Class SVM with Stochastic Gradient Descent.", - "docstring": "Fit linear One-Class SVM with Stochastic Gradient Descent.\n\nParameters\n----------\nX : {array-like, sparse matrix}, shape (n_samples, n_features)\n Subset of the training data.\n\nsample_weight : array-like, shape (n_samples,), optional\n Weights applied to individual samples.\n If not provided, uniform weights are assumed.\n\nReturns\n-------\nself : returns an instance of self.", - "source_code": "\ndef partial_fit(self, X, y=None, sample_weight=None):\n \"\"\"Fit linear One-Class SVM with Stochastic Gradient Descent.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Subset of the training data.\n\n sample_weight : array-like, shape (n_samples,), optional\n Weights applied to individual samples.\n If not provided, uniform weights are assumed.\n\n Returns\n -------\n self : returns an instance of self.\n \"\"\"\n alpha = self.nu / 2\n self._validate_params(for_partial_fit=True)\n return self._partial_fit(X, alpha, C=1.0, loss=self.loss, learning_rate=self.learning_rate, max_iter=1, sample_weight=sample_weight, coef_init=None, offset_init=None)" + "docstring": "Fit linear One-Class SVM with Stochastic Gradient Descent.\n\nParameters\n----------\nX : {array-like, sparse matrix}, shape (n_samples, n_features)\n Subset of the training data.\ny : Ignored\n Not used, present for API consistency by convention.\n\nsample_weight : array-like, shape (n_samples,), optional\n Weights applied to individual samples.\n If not provided, uniform weights are assumed.\n\nReturns\n-------\nself : object\n Returns a fitted instance of self.", + "source_code": "\ndef partial_fit(self, X, y=None, sample_weight=None):\n \"\"\"Fit linear One-Class SVM with Stochastic Gradient Descent.\n\n Parameters\n ----------\n X : {array-like, sparse matrix}, shape (n_samples, n_features)\n Subset of the training data.\n y : Ignored\n Not used, present for API consistency by convention.\n\n sample_weight : array-like, shape (n_samples,), optional\n Weights applied to individual samples.\n If not provided, uniform weights are assumed.\n\n Returns\n -------\n self : object\n Returns a fitted instance of self.\n \"\"\"\n alpha = self.nu / 2\n self._validate_params(for_partial_fit=True)\n return self._partial_fit(X, alpha, C=1.0, loss=self.loss, learning_rate=self.learning_rate, max_iter=1, sample_weight=sample_weight, coef_init=None, offset_init=None)" }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.linear_model._stochastic_gradient.SGDOneClassSVM.predict", + "unique_qname": "sklearn.linear_model._stochastic_gradient.SGDOneClassSVM.predict", "decorators": [], "parameters": [ { @@ -109143,7 +112733,9 @@ }, { "name": "score_samples", + "unique_name": "score_samples", "qname": "sklearn.linear_model._stochastic_gradient.SGDOneClassSVM.score_samples", + "unique_qname": "sklearn.linear_model._stochastic_gradient.SGDOneClassSVM.score_samples", "decorators": [], "parameters": [ { @@ -109175,7 +112767,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._stochastic_gradient.SGDRegressor.__init__", + "unique_qname": "sklearn.linear_model._stochastic_gradient.SGDRegressor.__init__", "decorators": [], "parameters": [ { @@ -109304,7 +112898,7 @@ "is_public": true, "assigned_by": "NAME_ONLY", "docstring": { - "type": "string, default='invscaling'", + "type": "str, default='invscaling'", "description": "The learning rate schedule:\n\n- 'constant': `eta = eta0`\n- 'optimal': `eta = 1.0 / (alpha * (t + t0))`\n where t0 is chosen by a heuristic proposed by Leon Bottou.\n- 'invscaling': `eta = eta0 / pow(t, power_t)`\n- 'adaptive': eta = eta0, as long as the training keeps decreasing.\n Each time n_iter_no_change consecutive epochs fail to decrease the\n training loss by tol or fail to increase validation score by tol if\n early_stopping is True, the current learning rate is divided by 5.\n\n .. versionadded:: 0.20\n Added 'adaptive' option" } }, @@ -109387,7 +112981,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.linear_model._stochastic_gradient.SGDRegressor._more_tags", + "unique_qname": "sklearn.linear_model._stochastic_gradient.SGDRegressor._more_tags", "decorators": [], "parameters": [ { @@ -109409,7 +113005,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.linear_model._stochastic_gradient._ValidationScoreCallback.__call__", + "unique_qname": "sklearn.linear_model._stochastic_gradient._ValidationScoreCallback.__call__", "decorators": [], "parameters": [ { @@ -109451,7 +113049,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._stochastic_gradient._ValidationScoreCallback.__init__", + "unique_qname": "sklearn.linear_model._stochastic_gradient._ValidationScoreCallback.__init__", "decorators": [], "parameters": [ { @@ -109523,7 +113123,9 @@ }, { "name": "_prepare_fit_binary", + "unique_name": "_prepare_fit_binary", "qname": "sklearn.linear_model._stochastic_gradient._prepare_fit_binary", + "unique_qname": "sklearn.linear_model._stochastic_gradient._prepare_fit_binary", "decorators": [], "parameters": [ { @@ -109565,7 +113167,9 @@ }, { "name": "fit_binary", + "unique_name": "fit_binary", "qname": "sklearn.linear_model._stochastic_gradient.fit_binary", + "unique_qname": "sklearn.linear_model._stochastic_gradient.fit_binary", "decorators": [], "parameters": [ { @@ -109634,7 +113238,7 @@ "is_public": false, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "string", + "type": "str", "description": "The learning rate. Accepted values are 'constant', 'optimal',\n'invscaling', 'pa1' and 'pa2'." } }, @@ -109702,12 +113306,14 @@ "results": [], "is_public": false, "description": "Fit a single binary classifier.\n\nThe i'th class is considered the \"positive\" class.", - "docstring": "Fit a single binary classifier.\n\nThe i'th class is considered the \"positive\" class.\n\nParameters\n----------\nest : Estimator object\n The estimator to fit\n\ni : int\n Index of the positive class\n\nX : numpy array or sparse matrix of shape [n_samples,n_features]\n Training data\n\ny : numpy array of shape [n_samples, ]\n Target values\n\nalpha : float\n The regularization parameter\n\nC : float\n Maximum step size for passive aggressive\n\nlearning_rate : string\n The learning rate. Accepted values are 'constant', 'optimal',\n 'invscaling', 'pa1' and 'pa2'.\n\nmax_iter : int\n The maximum number of iterations (epochs)\n\npos_weight : float\n The weight of the positive class\n\nneg_weight : float\n The weight of the negative class\n\nsample_weight : numpy array of shape [n_samples, ]\n The weight of each sample\n\nvalidation_mask : numpy array of shape [n_samples, ], default=None\n Precomputed validation mask in case _fit_binary is called in the\n context of a one-vs-rest reduction.\n\nrandom_state : int, RandomState instance, default=None\n If int, random_state is the seed used by the random number generator;\n If RandomState instance, random_state is the random number generator;\n If None, the random number generator is the RandomState instance used\n by `np.random`.", - "source_code": "\ndef fit_binary(est, i, X, y, alpha, C, learning_rate, max_iter, pos_weight, neg_weight, sample_weight, validation_mask=None, random_state=None):\n \"\"\"Fit a single binary classifier.\n\n The i'th class is considered the \"positive\" class.\n\n Parameters\n ----------\n est : Estimator object\n The estimator to fit\n\n i : int\n Index of the positive class\n\n X : numpy array or sparse matrix of shape [n_samples,n_features]\n Training data\n\n y : numpy array of shape [n_samples, ]\n Target values\n\n alpha : float\n The regularization parameter\n\n C : float\n Maximum step size for passive aggressive\n\n learning_rate : string\n The learning rate. Accepted values are 'constant', 'optimal',\n 'invscaling', 'pa1' and 'pa2'.\n\n max_iter : int\n The maximum number of iterations (epochs)\n\n pos_weight : float\n The weight of the positive class\n\n neg_weight : float\n The weight of the negative class\n\n sample_weight : numpy array of shape [n_samples, ]\n The weight of each sample\n\n validation_mask : numpy array of shape [n_samples, ], default=None\n Precomputed validation mask in case _fit_binary is called in the\n context of a one-vs-rest reduction.\n\n random_state : int, RandomState instance, default=None\n If int, random_state is the seed used by the random number generator;\n If RandomState instance, random_state is the random number generator;\n If None, the random number generator is the RandomState instance used\n by `np.random`.\n \"\"\"\n (y_i, coef, intercept, average_coef, average_intercept) = _prepare_fit_binary(est, y, i)\n assert y_i.shape[0] == y.shape[0] == sample_weight.shape[0]\n random_state = check_random_state(random_state)\n (dataset, intercept_decay) = make_dataset(X, y_i, sample_weight, random_state=random_state)\n penalty_type = est._get_penalty_type(est.penalty)\n learning_rate_type = est._get_learning_rate_type(learning_rate)\n if validation_mask is None:\n validation_mask = est._make_validation_split(y_i)\n classes = np.array([-1, 1], dtype=y_i.dtype)\n validation_score_cb = est._make_validation_score_cb(validation_mask, X, y_i, sample_weight, classes=classes)\n seed = random_state.randint(MAX_INT)\n tol = est.tol if est.tol is not None else -np.inf\n (coef, intercept, average_coef, average_intercept, n_iter_) = _plain_sgd(coef, intercept, average_coef, average_intercept, est.loss_function_, penalty_type, alpha, C, est.l1_ratio, dataset, validation_mask, est.early_stopping, validation_score_cb, int(est.n_iter_no_change), max_iter, tol, int(est.fit_intercept), int(est.verbose), int(est.shuffle), seed, pos_weight, neg_weight, learning_rate_type, est.eta0, est.power_t, 0, est.t_, intercept_decay, est.average)\n if est.average:\n if len(est.classes_) == 2:\n est._average_intercept[0] = average_intercept\n else:\n est._average_intercept[i] = average_intercept\n return coef, intercept, n_iter_" + "docstring": "Fit a single binary classifier.\n\nThe i'th class is considered the \"positive\" class.\n\nParameters\n----------\nest : Estimator object\n The estimator to fit\n\ni : int\n Index of the positive class\n\nX : numpy array or sparse matrix of shape [n_samples,n_features]\n Training data\n\ny : numpy array of shape [n_samples, ]\n Target values\n\nalpha : float\n The regularization parameter\n\nC : float\n Maximum step size for passive aggressive\n\nlearning_rate : str\n The learning rate. Accepted values are 'constant', 'optimal',\n 'invscaling', 'pa1' and 'pa2'.\n\nmax_iter : int\n The maximum number of iterations (epochs)\n\npos_weight : float\n The weight of the positive class\n\nneg_weight : float\n The weight of the negative class\n\nsample_weight : numpy array of shape [n_samples, ]\n The weight of each sample\n\nvalidation_mask : numpy array of shape [n_samples, ], default=None\n Precomputed validation mask in case _fit_binary is called in the\n context of a one-vs-rest reduction.\n\nrandom_state : int, RandomState instance, default=None\n If int, random_state is the seed used by the random number generator;\n If RandomState instance, random_state is the random number generator;\n If None, the random number generator is the RandomState instance used\n by `np.random`.", + "source_code": "\ndef fit_binary(est, i, X, y, alpha, C, learning_rate, max_iter, pos_weight, neg_weight, sample_weight, validation_mask=None, random_state=None):\n \"\"\"Fit a single binary classifier.\n\n The i'th class is considered the \"positive\" class.\n\n Parameters\n ----------\n est : Estimator object\n The estimator to fit\n\n i : int\n Index of the positive class\n\n X : numpy array or sparse matrix of shape [n_samples,n_features]\n Training data\n\n y : numpy array of shape [n_samples, ]\n Target values\n\n alpha : float\n The regularization parameter\n\n C : float\n Maximum step size for passive aggressive\n\n learning_rate : str\n The learning rate. Accepted values are 'constant', 'optimal',\n 'invscaling', 'pa1' and 'pa2'.\n\n max_iter : int\n The maximum number of iterations (epochs)\n\n pos_weight : float\n The weight of the positive class\n\n neg_weight : float\n The weight of the negative class\n\n sample_weight : numpy array of shape [n_samples, ]\n The weight of each sample\n\n validation_mask : numpy array of shape [n_samples, ], default=None\n Precomputed validation mask in case _fit_binary is called in the\n context of a one-vs-rest reduction.\n\n random_state : int, RandomState instance, default=None\n If int, random_state is the seed used by the random number generator;\n If RandomState instance, random_state is the random number generator;\n If None, the random number generator is the RandomState instance used\n by `np.random`.\n \"\"\"\n (y_i, coef, intercept, average_coef, average_intercept) = _prepare_fit_binary(est, y, i)\n assert y_i.shape[0] == y.shape[0] == sample_weight.shape[0]\n random_state = check_random_state(random_state)\n (dataset, intercept_decay) = make_dataset(X, y_i, sample_weight, random_state=random_state)\n penalty_type = est._get_penalty_type(est.penalty)\n learning_rate_type = est._get_learning_rate_type(learning_rate)\n if validation_mask is None:\n validation_mask = est._make_validation_split(y_i)\n classes = np.array([-1, 1], dtype=y_i.dtype)\n validation_score_cb = est._make_validation_score_cb(validation_mask, X, y_i, sample_weight, classes=classes)\n seed = random_state.randint(MAX_INT)\n tol = est.tol if est.tol is not None else -np.inf\n (coef, intercept, average_coef, average_intercept, n_iter_) = _plain_sgd(coef, intercept, average_coef, average_intercept, est.loss_function_, penalty_type, alpha, C, est.l1_ratio, dataset, validation_mask, est.early_stopping, validation_score_cb, int(est.n_iter_no_change), max_iter, tol, int(est.fit_intercept), int(est.verbose), int(est.shuffle), seed, pos_weight, neg_weight, learning_rate_type, est.eta0, est.power_t, 0, est.t_, intercept_decay, est.average)\n if est.average:\n if len(est.classes_) == 2:\n est._average_intercept[0] = average_intercept\n else:\n est._average_intercept[i] = average_intercept\n return coef, intercept, n_iter_" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.linear_model._theil_sen.TheilSenRegressor.__init__", + "unique_qname": "sklearn.linear_model._theil_sen.TheilSenRegressor.__init__", "decorators": [], "parameters": [ { @@ -109787,7 +113393,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int, RandomState instance or None, default=None", - "description": "A random number generator instance to define the state of the random\npermutations generator. Pass an int for reproducible output across\nmultiple function calls.\nSee :term:`Glossary `" + "description": "A random number generator instance to define the state of the random\npermutations generator. Pass an int for reproducible output across\nmultiple function calls.\nSee :term:`Glossary `." } }, { @@ -109819,7 +113425,9 @@ }, { "name": "_check_subparams", + "unique_name": "_check_subparams", "qname": "sklearn.linear_model._theil_sen.TheilSenRegressor._check_subparams", + "unique_qname": "sklearn.linear_model._theil_sen.TheilSenRegressor._check_subparams", "decorators": [], "parameters": [ { @@ -109861,7 +113469,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.linear_model._theil_sen.TheilSenRegressor.fit", + "unique_qname": "sklearn.linear_model._theil_sen.TheilSenRegressor.fit", "decorators": [], "parameters": [ { @@ -109898,12 +113508,14 @@ "results": [], "is_public": true, "description": "Fit linear model.", - "docstring": "Fit linear model.\n\nParameters\n----------\nX : ndarray of shape (n_samples, n_features)\n Training data.\ny : ndarray of shape (n_samples,)\n Target values.\n\nReturns\n-------\nself : returns an instance of self.", - "source_code": "\ndef fit(self, X, y):\n \"\"\"Fit linear model.\n\n Parameters\n ----------\n X : ndarray of shape (n_samples, n_features)\n Training data.\n y : ndarray of shape (n_samples,)\n Target values.\n\n Returns\n -------\n self : returns an instance of self.\n \"\"\"\n random_state = check_random_state(self.random_state)\n (X, y) = self._validate_data(X, y, y_numeric=True)\n (n_samples, n_features) = X.shape\n (n_subsamples, self.n_subpopulation_) = self._check_subparams(n_samples, n_features)\n self.breakdown_ = _breakdown_point(n_samples, n_subsamples)\n if self.verbose:\n print('Breakdown point: {0}'.format(self.breakdown_))\n print('Number of samples: {0}'.format(n_samples))\n tol_outliers = int(self.breakdown_ * n_samples)\n print('Tolerable outliers: {0}'.format(tol_outliers))\n print('Number of subpopulations: {0}'.format(self.n_subpopulation_))\n if np.rint(binom(n_samples, n_subsamples)) <= self.max_subpopulation:\n indices = list(combinations(range(n_samples), n_subsamples))\n else:\n indices = [random_state.choice(n_samples, size=n_subsamples, replace=False) for _ in range(self.n_subpopulation_)]\n n_jobs = effective_n_jobs(self.n_jobs)\n index_list = np.array_split(indices, n_jobs)\n weights = Parallel(n_jobs=n_jobs, verbose=self.verbose)((delayed(_lstsq)(X, y, index_list[job], self.fit_intercept) for job in range(n_jobs)))\n weights = np.vstack(weights)\n (self.n_iter_, coefs) = _spatial_median(weights, max_iter=self.max_iter, tol=self.tol)\n if self.fit_intercept:\n self.intercept_ = coefs[0]\n self.coef_ = coefs[1:]\n else:\n self.intercept_ = 0.0\n self.coef_ = coefs\n return self" + "docstring": "Fit linear model.\n\nParameters\n----------\nX : ndarray of shape (n_samples, n_features)\n Training data.\ny : ndarray of shape (n_samples,)\n Target values.\n\nReturns\n-------\nself : returns an instance of self.\n Fitted `TheilSenRegressor` estimator.", + "source_code": "\ndef fit(self, X, y):\n \"\"\"Fit linear model.\n\n Parameters\n ----------\n X : ndarray of shape (n_samples, n_features)\n Training data.\n y : ndarray of shape (n_samples,)\n Target values.\n\n Returns\n -------\n self : returns an instance of self.\n Fitted `TheilSenRegressor` estimator.\n \"\"\"\n random_state = check_random_state(self.random_state)\n (X, y) = self._validate_data(X, y, y_numeric=True)\n (n_samples, n_features) = X.shape\n (n_subsamples, self.n_subpopulation_) = self._check_subparams(n_samples, n_features)\n self.breakdown_ = _breakdown_point(n_samples, n_subsamples)\n if self.verbose:\n print('Breakdown point: {0}'.format(self.breakdown_))\n print('Number of samples: {0}'.format(n_samples))\n tol_outliers = int(self.breakdown_ * n_samples)\n print('Tolerable outliers: {0}'.format(tol_outliers))\n print('Number of subpopulations: {0}'.format(self.n_subpopulation_))\n if np.rint(binom(n_samples, n_subsamples)) <= self.max_subpopulation:\n indices = list(combinations(range(n_samples), n_subsamples))\n else:\n indices = [random_state.choice(n_samples, size=n_subsamples, replace=False) for _ in range(self.n_subpopulation_)]\n n_jobs = effective_n_jobs(self.n_jobs)\n index_list = np.array_split(indices, n_jobs)\n weights = Parallel(n_jobs=n_jobs, verbose=self.verbose)((delayed(_lstsq)(X, y, index_list[job], self.fit_intercept) for job in range(n_jobs)))\n weights = np.vstack(weights)\n (self.n_iter_, coefs) = _spatial_median(weights, max_iter=self.max_iter, tol=self.tol)\n if self.fit_intercept:\n self.intercept_ = coefs[0]\n self.coef_ = coefs[1:]\n else:\n self.intercept_ = 0.0\n self.coef_ = coefs\n return self" }, { "name": "_breakdown_point", + "unique_name": "_breakdown_point", "qname": "sklearn.linear_model._theil_sen._breakdown_point", + "unique_qname": "sklearn.linear_model._theil_sen._breakdown_point", "decorators": [], "parameters": [ { @@ -109935,7 +113547,9 @@ }, { "name": "_lstsq", + "unique_name": "_lstsq", "qname": "sklearn.linear_model._theil_sen._lstsq", + "unique_qname": "sklearn.linear_model._theil_sen._lstsq", "decorators": [], "parameters": [ { @@ -109987,7 +113601,9 @@ }, { "name": "_modified_weiszfeld_step", + "unique_name": "_modified_weiszfeld_step", "qname": "sklearn.linear_model._theil_sen._modified_weiszfeld_step", + "unique_qname": "sklearn.linear_model._theil_sen._modified_weiszfeld_step", "decorators": [], "parameters": [ { @@ -110019,7 +113635,9 @@ }, { "name": "_spatial_median", + "unique_name": "_spatial_median", "qname": "sklearn.linear_model._theil_sen._spatial_median", + "unique_qname": "sklearn.linear_model._theil_sen._spatial_median", "decorators": [], "parameters": [ { @@ -110061,7 +113679,9 @@ }, { "name": "configuration", + "unique_name": "configuration", "qname": "sklearn.linear_model.setup.configuration", + "unique_qname": "sklearn.linear_model.setup.configuration", "decorators": [], "parameters": [ { @@ -110093,7 +113713,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.manifold._isomap.Isomap.__init__", + "unique_qname": "sklearn.manifold._isomap.Isomap.__init__", "decorators": [], "parameters": [ { @@ -110225,7 +113847,9 @@ }, { "name": "_fit_transform", + "unique_name": "_fit_transform", "qname": "sklearn.manifold._isomap.Isomap._fit_transform", + "unique_qname": "sklearn.manifold._isomap.Isomap._fit_transform", "decorators": [], "parameters": [ { @@ -110257,7 +113881,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.manifold._isomap.Isomap.fit", + "unique_qname": "sklearn.manifold._isomap.Isomap.fit", "decorators": [], "parameters": [ { @@ -110299,7 +113925,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.manifold._isomap.Isomap.fit_transform", + "unique_qname": "sklearn.manifold._isomap.Isomap.fit_transform", "decorators": [], "parameters": [ { @@ -110341,7 +113969,9 @@ }, { "name": "reconstruction_error", + "unique_name": "reconstruction_error", "qname": "sklearn.manifold._isomap.Isomap.reconstruction_error", + "unique_qname": "sklearn.manifold._isomap.Isomap.reconstruction_error", "decorators": [], "parameters": [ { @@ -110363,7 +113993,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.manifold._isomap.Isomap.transform", + "unique_qname": "sklearn.manifold._isomap.Isomap.transform", "decorators": [], "parameters": [ { @@ -110395,7 +114027,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.manifold._locally_linear.LocallyLinearEmbedding.__init__", + "unique_qname": "sklearn.manifold._locally_linear.LocallyLinearEmbedding.__init__", "decorators": [], "parameters": [ { @@ -110415,7 +114049,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int, default=5", - "description": "number of neighbors to consider for each point." + "description": "Number of neighbors to consider for each point." } }, { @@ -110425,7 +114059,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int, default=2", - "description": "number of coordinates for the manifold" + "description": "Number of coordinates for the manifold." } }, { @@ -110435,7 +114069,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "float, default=1e-3", - "description": "regularization constant, multiplies the trace of the local covariance\nmatrix of the distances." + "description": "Regularization constant, multiplies the trace of the local covariance\nmatrix of the distances." } }, { @@ -110445,7 +114079,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "{'auto', 'arpack', 'dense'}, default='auto'", - "description": "auto : algorithm will attempt to choose the best method for input data\n\narpack : use arnoldi iteration in shift-invert mode.\n For this method, M may be a dense matrix, sparse matrix,\n or general linear operator.\n Warning: ARPACK can be unstable for some problems. It is\n best to try several random seeds in order to check results.\n\ndense : use standard dense matrix operations for the eigenvalue\n decomposition. For this method, M must be an array\n or matrix type. This method should be avoided for\n large problems." + "description": "The solver used to compute the eigenvectors. The available options are:\n\n- `'auto'` : algorithm will attempt to choose the best method for input\n data.\n- `'arpack'` : use arnoldi iteration in shift-invert mode. For this\n method, M may be a dense matrix, sparse matrix, or general linear\n operator.\n- `'dense'` : use standard dense matrix operations for the eigenvalue\n decomposition. For this method, M must be an array or matrix type.\n This method should be avoided for large problems.\n\n.. warning::\n ARPACK can be unstable for some problems. It is best to try several\n random seeds in order to check results." } }, { @@ -110465,7 +114099,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int, default=100", - "description": "maximum number of iterations for the arpack solver.\nNot used if eigen_solver=='dense'." + "description": "Maximum number of iterations for the arpack solver.\nNot used if eigen_solver=='dense'." } }, { @@ -110485,7 +114119,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "float, default=1e-4", - "description": "Tolerance for Hessian eigenmapping method.\nOnly used if ``method == 'hessian'``" + "description": "Tolerance for Hessian eigenmapping method.\nOnly used if ``method == 'hessian'``." } }, { @@ -110495,7 +114129,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "float, default=1e-12", - "description": "Tolerance for modified LLE method.\nOnly used if ``method == 'modified'``" + "description": "Tolerance for modified LLE method.\nOnly used if ``method == 'modified'``." } }, { @@ -110505,7 +114139,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "{'auto', 'brute', 'kd_tree', 'ball_tree'}, default='auto'", - "description": "algorithm to use for nearest neighbors search,\npassed to neighbors.NearestNeighbors instance" + "description": "Algorithm to use for nearest neighbors search, passed to\n:class:`~sklearn.neighbors.NearestNeighbors` instance." } }, { @@ -110515,7 +114149,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int, RandomState instance, default=None", - "description": "Determines the random number generator when\n``eigen_solver`` == 'arpack'. Pass an int for reproducible results\nacross multiple function calls. See :term: `Glossary `." + "description": "Determines the random number generator when\n``eigen_solver`` == 'arpack'. Pass an int for reproducible results\nacross multiple function calls. See :term:`Glossary `." } }, { @@ -110537,7 +114171,9 @@ }, { "name": "_fit_transform", + "unique_name": "_fit_transform", "qname": "sklearn.manifold._locally_linear.LocallyLinearEmbedding._fit_transform", + "unique_qname": "sklearn.manifold._locally_linear.LocallyLinearEmbedding._fit_transform", "decorators": [], "parameters": [ { @@ -110569,7 +114205,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.manifold._locally_linear.LocallyLinearEmbedding.fit", + "unique_qname": "sklearn.manifold._locally_linear.LocallyLinearEmbedding.fit", "decorators": [], "parameters": [ { @@ -110588,8 +114226,8 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "array-like of shape [n_samples, n_features]", - "description": "training set." + "type": "array-like of shape (n_samples, n_features)", + "description": "Training set." } }, { @@ -110599,19 +114237,21 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "Ignored", - "description": "" + "description": "Not used, present here for API consistency by convention." } } ], "results": [], "is_public": true, - "description": "Compute the embedding vectors for data X", - "docstring": "Compute the embedding vectors for data X\n\nParameters\n----------\nX : array-like of shape [n_samples, n_features]\n training set.\n\ny : Ignored\n\nReturns\n-------\nself : returns an instance of self.", - "source_code": "\ndef fit(self, X, y=None):\n \"\"\"Compute the embedding vectors for data X\n\n Parameters\n ----------\n X : array-like of shape [n_samples, n_features]\n training set.\n\n y : Ignored\n\n Returns\n -------\n self : returns an instance of self.\n \"\"\"\n self._fit_transform(X)\n return self" + "description": "Compute the embedding vectors for data X.", + "docstring": "Compute the embedding vectors for data X.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Training set.\n\ny : Ignored\n Not used, present here for API consistency by convention.\n\nReturns\n-------\nself : object\n Fitted `LocallyLinearEmbedding` class instance.", + "source_code": "\ndef fit(self, X, y=None):\n \"\"\"Compute the embedding vectors for data X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training set.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self : object\n Fitted `LocallyLinearEmbedding` class instance.\n \"\"\"\n self._fit_transform(X)\n return self" }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.manifold._locally_linear.LocallyLinearEmbedding.fit_transform", + "unique_qname": "sklearn.manifold._locally_linear.LocallyLinearEmbedding.fit_transform", "decorators": [], "parameters": [ { @@ -110630,8 +114270,8 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "array-like of shape [n_samples, n_features]", - "description": "training set." + "type": "array-like of shape (n_samples, n_features)", + "description": "Training set." } }, { @@ -110641,19 +114281,21 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "Ignored", - "description": "" + "description": "Not used, present here for API consistency by convention." } } ], "results": [], "is_public": true, "description": "Compute the embedding vectors for data X and transform X.", - "docstring": "Compute the embedding vectors for data X and transform X.\n\nParameters\n----------\nX : array-like of shape [n_samples, n_features]\n training set.\n\ny : Ignored\n\nReturns\n-------\nX_new : array-like, shape (n_samples, n_components)", - "source_code": "\ndef fit_transform(self, X, y=None):\n \"\"\"Compute the embedding vectors for data X and transform X.\n\n Parameters\n ----------\n X : array-like of shape [n_samples, n_features]\n training set.\n\n y : Ignored\n\n Returns\n -------\n X_new : array-like, shape (n_samples, n_components)\n \"\"\"\n self._fit_transform(X)\n return self.embedding_" + "docstring": "Compute the embedding vectors for data X and transform X.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Training set.\n\ny : Ignored\n Not used, present here for API consistency by convention.\n\nReturns\n-------\nX_new : array-like, shape (n_samples, n_components)\n Returns the instance itself.", + "source_code": "\ndef fit_transform(self, X, y=None):\n \"\"\"Compute the embedding vectors for data X and transform X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training set.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n X_new : array-like, shape (n_samples, n_components)\n Returns the instance itself.\n \"\"\"\n self._fit_transform(X)\n return self.embedding_" }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.manifold._locally_linear.LocallyLinearEmbedding.transform", + "unique_qname": "sklearn.manifold._locally_linear.LocallyLinearEmbedding.transform", "decorators": [], "parameters": [ { @@ -110673,19 +114315,21 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "array-like of shape (n_samples, n_features)", - "description": "" + "description": "Training set." } } ], "results": [], "is_public": true, "description": "Transform new points into embedding space.", - "docstring": "Transform new points into embedding space.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n\nReturns\n-------\nX_new : array, shape = [n_samples, n_components]\n\nNotes\n-----\nBecause of scaling performed by this method, it is discouraged to use\nit together with methods that are not scale-invariant (like SVMs)", - "source_code": "\ndef transform(self, X):\n \"\"\"\n Transform new points into embedding space.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n\n Returns\n -------\n X_new : array, shape = [n_samples, n_components]\n\n Notes\n -----\n Because of scaling performed by this method, it is discouraged to use\n it together with methods that are not scale-invariant (like SVMs)\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, reset=False)\n ind = self.nbrs_.kneighbors(X, n_neighbors=self.n_neighbors, return_distance=False)\n weights = barycenter_weights(X, self.nbrs_._fit_X, ind, reg=self.reg)\n X_new = np.empty((X.shape[0], self.n_components))\n for i in range(X.shape[0]):\n X_new[i] = np.dot(self.embedding_[ind[i]].T, weights[i])\n return X_new" + "docstring": "Transform new points into embedding space.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Training set.\n\nReturns\n-------\nX_new : ndarray of shape (n_samples, n_components)\n Returns the instance itself.\n\nNotes\n-----\nBecause of scaling performed by this method, it is discouraged to use\nit together with methods that are not scale-invariant (like SVMs).", + "source_code": "\ndef transform(self, X):\n \"\"\"\n Transform new points into embedding space.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training set.\n\n Returns\n -------\n X_new : ndarray of shape (n_samples, n_components)\n Returns the instance itself.\n\n Notes\n -----\n Because of scaling performed by this method, it is discouraged to use\n it together with methods that are not scale-invariant (like SVMs).\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, reset=False)\n ind = self.nbrs_.kneighbors(X, n_neighbors=self.n_neighbors, return_distance=False)\n weights = barycenter_weights(X, self.nbrs_._fit_X, ind, reg=self.reg)\n X_new = np.empty((X.shape[0], self.n_components))\n for i in range(X.shape[0]):\n X_new[i] = np.dot(self.embedding_[ind[i]].T, weights[i])\n return X_new" }, { "name": "barycenter_kneighbors_graph", + "unique_name": "barycenter_kneighbors_graph", "qname": "sklearn.manifold._locally_linear.barycenter_kneighbors_graph", + "unique_qname": "sklearn.manifold._locally_linear.barycenter_kneighbors_graph", "decorators": [], "parameters": [ { @@ -110737,7 +114381,9 @@ }, { "name": "barycenter_weights", + "unique_name": "barycenter_weights", "qname": "sklearn.manifold._locally_linear.barycenter_weights", + "unique_qname": "sklearn.manifold._locally_linear.barycenter_weights", "decorators": [], "parameters": [ { @@ -110789,7 +114435,9 @@ }, { "name": "locally_linear_embedding", + "unique_name": "locally_linear_embedding", "qname": "sklearn.manifold._locally_linear.locally_linear_embedding", + "unique_qname": "sklearn.manifold._locally_linear.locally_linear_embedding", "decorators": [], "parameters": [ { @@ -110899,7 +114547,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int, RandomState instance, default=None", - "description": "Determines the random number generator when ``solver`` == 'arpack'.\nPass an int for reproducible results across multiple function calls.\nSee :term: `Glossary `." + "description": "Determines the random number generator when ``solver`` == 'arpack'.\nPass an int for reproducible results across multiple function calls.\nSee :term:`Glossary `." } }, { @@ -110916,12 +114564,14 @@ "results": [], "is_public": true, "description": "Perform a Locally Linear Embedding analysis on the data.\n\nRead more in the :ref:`User Guide `.", - "docstring": "Perform a Locally Linear Embedding analysis on the data.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\nX : {array-like, NearestNeighbors}\n Sample data, shape = (n_samples, n_features), in the form of a\n numpy array or a NearestNeighbors object.\n\nn_neighbors : int\n number of neighbors to consider for each point.\n\nn_components : int\n number of coordinates for the manifold.\n\nreg : float, default=1e-3\n regularization constant, multiplies the trace of the local covariance\n matrix of the distances.\n\neigen_solver : {'auto', 'arpack', 'dense'}, default='auto'\n auto : algorithm will attempt to choose the best method for input data\n\n arpack : use arnoldi iteration in shift-invert mode.\n For this method, M may be a dense matrix, sparse matrix,\n or general linear operator.\n Warning: ARPACK can be unstable for some problems. It is\n best to try several random seeds in order to check results.\n\n dense : use standard dense matrix operations for the eigenvalue\n decomposition. For this method, M must be an array\n or matrix type. This method should be avoided for\n large problems.\n\ntol : float, default=1e-6\n Tolerance for 'arpack' method\n Not used if eigen_solver=='dense'.\n\nmax_iter : int, default=100\n maximum number of iterations for the arpack solver.\n\nmethod : {'standard', 'hessian', 'modified', 'ltsa'}, default='standard'\n standard : use the standard locally linear embedding algorithm.\n see reference [1]_\n hessian : use the Hessian eigenmap method. This method requires\n n_neighbors > n_components * (1 + (n_components + 1) / 2.\n see reference [2]_\n modified : use the modified locally linear embedding algorithm.\n see reference [3]_\n ltsa : use local tangent space alignment algorithm\n see reference [4]_\n\nhessian_tol : float, default=1e-4\n Tolerance for Hessian eigenmapping method.\n Only used if method == 'hessian'\n\nmodified_tol : float, default=1e-12\n Tolerance for modified LLE method.\n Only used if method == 'modified'\n\nrandom_state : int, RandomState instance, default=None\n Determines the random number generator when ``solver`` == 'arpack'.\n Pass an int for reproducible results across multiple function calls.\n See :term: `Glossary `.\n\nn_jobs : int or None, default=None\n The number of parallel jobs to run for neighbors search.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\nReturns\n-------\nY : array-like, shape [n_samples, n_components]\n Embedding vectors.\n\nsquared_error : float\n Reconstruction error for the embedding vectors. Equivalent to\n ``norm(Y - W Y, 'fro')**2``, where W are the reconstruction weights.\n\nReferences\n----------\n\n.. [1] Roweis, S. & Saul, L. Nonlinear dimensionality reduction\n by locally linear embedding. Science 290:2323 (2000).\n.. [2] Donoho, D. & Grimes, C. Hessian eigenmaps: Locally\n linear embedding techniques for high-dimensional data.\n Proc Natl Acad Sci U S A. 100:5591 (2003).\n.. [3] Zhang, Z. & Wang, J. MLLE: Modified Locally Linear\n Embedding Using Multiple Weights.\n http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.70.382\n.. [4] Zhang, Z. & Zha, H. Principal manifolds and nonlinear\n dimensionality reduction via tangent space alignment.\n Journal of Shanghai Univ. 8:406 (2004)", - "source_code": "\ndef locally_linear_embedding(X, *, n_neighbors, n_components, reg=0.001, eigen_solver='auto', tol=1e-06, max_iter=100, method='standard', hessian_tol=0.0001, modified_tol=1e-12, random_state=None, n_jobs=None):\n \"\"\"Perform a Locally Linear Embedding analysis on the data.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n X : {array-like, NearestNeighbors}\n Sample data, shape = (n_samples, n_features), in the form of a\n numpy array or a NearestNeighbors object.\n\n n_neighbors : int\n number of neighbors to consider for each point.\n\n n_components : int\n number of coordinates for the manifold.\n\n reg : float, default=1e-3\n regularization constant, multiplies the trace of the local covariance\n matrix of the distances.\n\n eigen_solver : {'auto', 'arpack', 'dense'}, default='auto'\n auto : algorithm will attempt to choose the best method for input data\n\n arpack : use arnoldi iteration in shift-invert mode.\n For this method, M may be a dense matrix, sparse matrix,\n or general linear operator.\n Warning: ARPACK can be unstable for some problems. It is\n best to try several random seeds in order to check results.\n\n dense : use standard dense matrix operations for the eigenvalue\n decomposition. For this method, M must be an array\n or matrix type. This method should be avoided for\n large problems.\n\n tol : float, default=1e-6\n Tolerance for 'arpack' method\n Not used if eigen_solver=='dense'.\n\n max_iter : int, default=100\n maximum number of iterations for the arpack solver.\n\n method : {'standard', 'hessian', 'modified', 'ltsa'}, default='standard'\n standard : use the standard locally linear embedding algorithm.\n see reference [1]_\n hessian : use the Hessian eigenmap method. This method requires\n n_neighbors > n_components * (1 + (n_components + 1) / 2.\n see reference [2]_\n modified : use the modified locally linear embedding algorithm.\n see reference [3]_\n ltsa : use local tangent space alignment algorithm\n see reference [4]_\n\n hessian_tol : float, default=1e-4\n Tolerance for Hessian eigenmapping method.\n Only used if method == 'hessian'\n\n modified_tol : float, default=1e-12\n Tolerance for modified LLE method.\n Only used if method == 'modified'\n\n random_state : int, RandomState instance, default=None\n Determines the random number generator when ``solver`` == 'arpack'.\n Pass an int for reproducible results across multiple function calls.\n See :term: `Glossary `.\n\n n_jobs : int or None, default=None\n The number of parallel jobs to run for neighbors search.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n Returns\n -------\n Y : array-like, shape [n_samples, n_components]\n Embedding vectors.\n\n squared_error : float\n Reconstruction error for the embedding vectors. Equivalent to\n ``norm(Y - W Y, 'fro')**2``, where W are the reconstruction weights.\n\n References\n ----------\n\n .. [1] Roweis, S. & Saul, L. Nonlinear dimensionality reduction\n by locally linear embedding. Science 290:2323 (2000).\n .. [2] Donoho, D. & Grimes, C. Hessian eigenmaps: Locally\n linear embedding techniques for high-dimensional data.\n Proc Natl Acad Sci U S A. 100:5591 (2003).\n .. [3] Zhang, Z. & Wang, J. MLLE: Modified Locally Linear\n Embedding Using Multiple Weights.\n http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.70.382\n .. [4] Zhang, Z. & Zha, H. Principal manifolds and nonlinear\n dimensionality reduction via tangent space alignment.\n Journal of Shanghai Univ. 8:406 (2004)\n \"\"\"\n if eigen_solver not in ('auto', 'arpack', 'dense'):\n raise ValueError(\"unrecognized eigen_solver '%s'\" % eigen_solver)\n if method not in ('standard', 'hessian', 'modified', 'ltsa'):\n raise ValueError(\"unrecognized method '%s'\" % method)\n nbrs = NearestNeighbors(n_neighbors=n_neighbors + 1, n_jobs=n_jobs)\n nbrs.fit(X)\n X = nbrs._fit_X\n (N, d_in) = X.shape\n if n_components > d_in:\n raise ValueError('output dimension must be less than or equal to input dimension')\n if n_neighbors >= N:\n raise ValueError('Expected n_neighbors <= n_samples, but n_samples = %d, n_neighbors = %d' % (N, n_neighbors))\n if n_neighbors <= 0:\n raise ValueError('n_neighbors must be positive')\n M_sparse = eigen_solver != 'dense'\n if method == 'standard':\n W = barycenter_kneighbors_graph(nbrs, n_neighbors=n_neighbors, reg=reg, n_jobs=n_jobs)\n if M_sparse:\n M = eye(*W.shape, format=W.format) - W\n M = (M.T * M).tocsr()\n else:\n M = (W.T * W - W.T - W).toarray()\n M.flat[::M.shape[0] + 1] += 1\n elif method == 'hessian':\n dp = n_components * (n_components + 1) // 2\n if n_neighbors <= n_components + dp:\n raise ValueError(\"for method='hessian', n_neighbors must be greater than [n_components * (n_components + 3) / 2]\")\n neighbors = nbrs.kneighbors(X, n_neighbors=n_neighbors + 1, return_distance=False)\n neighbors = neighbors[:, 1:]\n Yi = np.empty((n_neighbors, 1 + n_components + dp), dtype=np.float64)\n Yi[:, 0] = 1\n M = np.zeros((N, N), dtype=np.float64)\n use_svd = n_neighbors > d_in\n for i in range(N):\n Gi = X[neighbors[i]]\n Gi -= Gi.mean(0)\n if use_svd:\n U = svd(Gi, full_matrices=0)[0]\n else:\n Ci = np.dot(Gi, Gi.T)\n U = eigh(Ci)[1][:, ::-1]\n Yi[:, 1:1 + n_components] = U[:, :n_components]\n j = 1 + n_components\n for k in range(n_components):\n Yi[:, j:j + n_components - k] = U[:, k:k + 1] * U[:, k:n_components]\n j += n_components - k\n (Q, R) = qr(Yi)\n w = Q[:, n_components + 1:]\n S = w.sum(0)\n S[np.where(abs(S) < hessian_tol)] = 1\n w /= S\n (nbrs_x, nbrs_y) = np.meshgrid(neighbors[i], neighbors[i])\n M[nbrs_x, nbrs_y] += np.dot(w, w.T)\n if M_sparse:\n M = csr_matrix(M)\n elif method == 'modified':\n if n_neighbors < n_components:\n raise ValueError('modified LLE requires n_neighbors >= n_components')\n neighbors = nbrs.kneighbors(X, n_neighbors=n_neighbors + 1, return_distance=False)\n neighbors = neighbors[:, 1:]\n V = np.zeros((N, n_neighbors, n_neighbors))\n nev = min(d_in, n_neighbors)\n evals = np.zeros([N, nev])\n use_svd = n_neighbors > d_in\n if use_svd:\n for i in range(N):\n X_nbrs = X[neighbors[i]] - X[i]\n (V[i], evals[i], _) = svd(X_nbrs, full_matrices=True)\n evals **= 2\n else:\n for i in range(N):\n X_nbrs = X[neighbors[i]] - X[i]\n C_nbrs = np.dot(X_nbrs, X_nbrs.T)\n (evi, vi) = eigh(C_nbrs)\n evals[i] = evi[::-1]\n V[i] = vi[:, ::-1]\n reg = 0.001 * evals.sum(1)\n tmp = np.dot(V.transpose(0, 2, 1), np.ones(n_neighbors))\n tmp[:, :nev] /= evals + reg[:, None]\n tmp[:, nev:] /= reg[:, None]\n w_reg = np.zeros((N, n_neighbors))\n for i in range(N):\n w_reg[i] = np.dot(V[i], tmp[i])\n w_reg /= w_reg.sum(1)[:, None]\n rho = evals[:, n_components:].sum(1) / evals[:, :n_components].sum(1)\n eta = np.median(rho)\n s_range = np.zeros(N, dtype=int)\n evals_cumsum = stable_cumsum(evals, 1)\n eta_range = evals_cumsum[:, -1:] / evals_cumsum[:, :-1] - 1\n for i in range(N):\n s_range[i] = np.searchsorted(eta_range[i, ::-1], eta)\n s_range += n_neighbors - nev\n M = np.zeros((N, N), dtype=np.float64)\n for i in range(N):\n s_i = s_range[i]\n Vi = V[i, :, n_neighbors - s_i:]\n alpha_i = np.linalg.norm(Vi.sum(0)) / np.sqrt(s_i)\n h = np.full(s_i, alpha_i) - np.dot(Vi.T, np.ones(n_neighbors))\n norm_h = np.linalg.norm(h)\n if norm_h < modified_tol:\n h *= 0\n else:\n h /= norm_h\n Wi = Vi - 2 * np.outer(np.dot(Vi, h), h) + (1 - alpha_i) * w_reg[i, :, None]\n (nbrs_x, nbrs_y) = np.meshgrid(neighbors[i], neighbors[i])\n M[nbrs_x, nbrs_y] += np.dot(Wi, Wi.T)\n Wi_sum1 = Wi.sum(1)\n M[i, neighbors[i]] -= Wi_sum1\n M[neighbors[i], i] -= Wi_sum1\n M[i, i] += s_i\n if M_sparse:\n M = csr_matrix(M)\n elif method == 'ltsa':\n neighbors = nbrs.kneighbors(X, n_neighbors=n_neighbors + 1, return_distance=False)\n neighbors = neighbors[:, 1:]\n M = np.zeros((N, N))\n use_svd = n_neighbors > d_in\n for i in range(N):\n Xi = X[neighbors[i]]\n Xi -= Xi.mean(0)\n if use_svd:\n v = svd(Xi, full_matrices=True)[0]\n else:\n Ci = np.dot(Xi, Xi.T)\n v = eigh(Ci)[1][:, ::-1]\n Gi = np.zeros((n_neighbors, n_components + 1))\n Gi[:, 1:] = v[:, :n_components]\n Gi[:, 0] = 1.0 / np.sqrt(n_neighbors)\n GiGiT = np.dot(Gi, Gi.T)\n (nbrs_x, nbrs_y) = np.meshgrid(neighbors[i], neighbors[i])\n M[nbrs_x, nbrs_y] -= GiGiT\n M[neighbors[i], neighbors[i]] += 1\n return null_space(M, n_components, k_skip=1, eigen_solver=eigen_solver, tol=tol, max_iter=max_iter, random_state=random_state)" + "docstring": "Perform a Locally Linear Embedding analysis on the data.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\nX : {array-like, NearestNeighbors}\n Sample data, shape = (n_samples, n_features), in the form of a\n numpy array or a NearestNeighbors object.\n\nn_neighbors : int\n number of neighbors to consider for each point.\n\nn_components : int\n number of coordinates for the manifold.\n\nreg : float, default=1e-3\n regularization constant, multiplies the trace of the local covariance\n matrix of the distances.\n\neigen_solver : {'auto', 'arpack', 'dense'}, default='auto'\n auto : algorithm will attempt to choose the best method for input data\n\n arpack : use arnoldi iteration in shift-invert mode.\n For this method, M may be a dense matrix, sparse matrix,\n or general linear operator.\n Warning: ARPACK can be unstable for some problems. It is\n best to try several random seeds in order to check results.\n\n dense : use standard dense matrix operations for the eigenvalue\n decomposition. For this method, M must be an array\n or matrix type. This method should be avoided for\n large problems.\n\ntol : float, default=1e-6\n Tolerance for 'arpack' method\n Not used if eigen_solver=='dense'.\n\nmax_iter : int, default=100\n maximum number of iterations for the arpack solver.\n\nmethod : {'standard', 'hessian', 'modified', 'ltsa'}, default='standard'\n standard : use the standard locally linear embedding algorithm.\n see reference [1]_\n hessian : use the Hessian eigenmap method. This method requires\n n_neighbors > n_components * (1 + (n_components + 1) / 2.\n see reference [2]_\n modified : use the modified locally linear embedding algorithm.\n see reference [3]_\n ltsa : use local tangent space alignment algorithm\n see reference [4]_\n\nhessian_tol : float, default=1e-4\n Tolerance for Hessian eigenmapping method.\n Only used if method == 'hessian'\n\nmodified_tol : float, default=1e-12\n Tolerance for modified LLE method.\n Only used if method == 'modified'\n\nrandom_state : int, RandomState instance, default=None\n Determines the random number generator when ``solver`` == 'arpack'.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\nn_jobs : int or None, default=None\n The number of parallel jobs to run for neighbors search.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\nReturns\n-------\nY : array-like, shape [n_samples, n_components]\n Embedding vectors.\n\nsquared_error : float\n Reconstruction error for the embedding vectors. Equivalent to\n ``norm(Y - W Y, 'fro')**2``, where W are the reconstruction weights.\n\nReferences\n----------\n\n.. [1] Roweis, S. & Saul, L. Nonlinear dimensionality reduction\n by locally linear embedding. Science 290:2323 (2000).\n.. [2] Donoho, D. & Grimes, C. Hessian eigenmaps: Locally\n linear embedding techniques for high-dimensional data.\n Proc Natl Acad Sci U S A. 100:5591 (2003).\n.. [3] Zhang, Z. & Wang, J. MLLE: Modified Locally Linear\n Embedding Using Multiple Weights.\n http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.70.382\n.. [4] Zhang, Z. & Zha, H. Principal manifolds and nonlinear\n dimensionality reduction via tangent space alignment.\n Journal of Shanghai Univ. 8:406 (2004)", + "source_code": "\ndef locally_linear_embedding(X, *, n_neighbors, n_components, reg=0.001, eigen_solver='auto', tol=1e-06, max_iter=100, method='standard', hessian_tol=0.0001, modified_tol=1e-12, random_state=None, n_jobs=None):\n \"\"\"Perform a Locally Linear Embedding analysis on the data.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n X : {array-like, NearestNeighbors}\n Sample data, shape = (n_samples, n_features), in the form of a\n numpy array or a NearestNeighbors object.\n\n n_neighbors : int\n number of neighbors to consider for each point.\n\n n_components : int\n number of coordinates for the manifold.\n\n reg : float, default=1e-3\n regularization constant, multiplies the trace of the local covariance\n matrix of the distances.\n\n eigen_solver : {'auto', 'arpack', 'dense'}, default='auto'\n auto : algorithm will attempt to choose the best method for input data\n\n arpack : use arnoldi iteration in shift-invert mode.\n For this method, M may be a dense matrix, sparse matrix,\n or general linear operator.\n Warning: ARPACK can be unstable for some problems. It is\n best to try several random seeds in order to check results.\n\n dense : use standard dense matrix operations for the eigenvalue\n decomposition. For this method, M must be an array\n or matrix type. This method should be avoided for\n large problems.\n\n tol : float, default=1e-6\n Tolerance for 'arpack' method\n Not used if eigen_solver=='dense'.\n\n max_iter : int, default=100\n maximum number of iterations for the arpack solver.\n\n method : {'standard', 'hessian', 'modified', 'ltsa'}, default='standard'\n standard : use the standard locally linear embedding algorithm.\n see reference [1]_\n hessian : use the Hessian eigenmap method. This method requires\n n_neighbors > n_components * (1 + (n_components + 1) / 2.\n see reference [2]_\n modified : use the modified locally linear embedding algorithm.\n see reference [3]_\n ltsa : use local tangent space alignment algorithm\n see reference [4]_\n\n hessian_tol : float, default=1e-4\n Tolerance for Hessian eigenmapping method.\n Only used if method == 'hessian'\n\n modified_tol : float, default=1e-12\n Tolerance for modified LLE method.\n Only used if method == 'modified'\n\n random_state : int, RandomState instance, default=None\n Determines the random number generator when ``solver`` == 'arpack'.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n n_jobs : int or None, default=None\n The number of parallel jobs to run for neighbors search.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n Returns\n -------\n Y : array-like, shape [n_samples, n_components]\n Embedding vectors.\n\n squared_error : float\n Reconstruction error for the embedding vectors. Equivalent to\n ``norm(Y - W Y, 'fro')**2``, where W are the reconstruction weights.\n\n References\n ----------\n\n .. [1] Roweis, S. & Saul, L. Nonlinear dimensionality reduction\n by locally linear embedding. Science 290:2323 (2000).\n .. [2] Donoho, D. & Grimes, C. Hessian eigenmaps: Locally\n linear embedding techniques for high-dimensional data.\n Proc Natl Acad Sci U S A. 100:5591 (2003).\n .. [3] Zhang, Z. & Wang, J. MLLE: Modified Locally Linear\n Embedding Using Multiple Weights.\n http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.70.382\n .. [4] Zhang, Z. & Zha, H. Principal manifolds and nonlinear\n dimensionality reduction via tangent space alignment.\n Journal of Shanghai Univ. 8:406 (2004)\n \"\"\"\n if eigen_solver not in ('auto', 'arpack', 'dense'):\n raise ValueError(\"unrecognized eigen_solver '%s'\" % eigen_solver)\n if method not in ('standard', 'hessian', 'modified', 'ltsa'):\n raise ValueError(\"unrecognized method '%s'\" % method)\n nbrs = NearestNeighbors(n_neighbors=n_neighbors + 1, n_jobs=n_jobs)\n nbrs.fit(X)\n X = nbrs._fit_X\n (N, d_in) = X.shape\n if n_components > d_in:\n raise ValueError('output dimension must be less than or equal to input dimension')\n if n_neighbors >= N:\n raise ValueError('Expected n_neighbors <= n_samples, but n_samples = %d, n_neighbors = %d' % (N, n_neighbors))\n if n_neighbors <= 0:\n raise ValueError('n_neighbors must be positive')\n M_sparse = eigen_solver != 'dense'\n if method == 'standard':\n W = barycenter_kneighbors_graph(nbrs, n_neighbors=n_neighbors, reg=reg, n_jobs=n_jobs)\n if M_sparse:\n M = eye(*W.shape, format=W.format) - W\n M = (M.T * M).tocsr()\n else:\n M = (W.T * W - W.T - W).toarray()\n M.flat[::M.shape[0] + 1] += 1\n elif method == 'hessian':\n dp = n_components * (n_components + 1) // 2\n if n_neighbors <= n_components + dp:\n raise ValueError(\"for method='hessian', n_neighbors must be greater than [n_components * (n_components + 3) / 2]\")\n neighbors = nbrs.kneighbors(X, n_neighbors=n_neighbors + 1, return_distance=False)\n neighbors = neighbors[:, 1:]\n Yi = np.empty((n_neighbors, 1 + n_components + dp), dtype=np.float64)\n Yi[:, 0] = 1\n M = np.zeros((N, N), dtype=np.float64)\n use_svd = n_neighbors > d_in\n for i in range(N):\n Gi = X[neighbors[i]]\n Gi -= Gi.mean(0)\n if use_svd:\n U = svd(Gi, full_matrices=0)[0]\n else:\n Ci = np.dot(Gi, Gi.T)\n U = eigh(Ci)[1][:, ::-1]\n Yi[:, 1:1 + n_components] = U[:, :n_components]\n j = 1 + n_components\n for k in range(n_components):\n Yi[:, j:j + n_components - k] = U[:, k:k + 1] * U[:, k:n_components]\n j += n_components - k\n (Q, R) = qr(Yi)\n w = Q[:, n_components + 1:]\n S = w.sum(0)\n S[np.where(abs(S) < hessian_tol)] = 1\n w /= S\n (nbrs_x, nbrs_y) = np.meshgrid(neighbors[i], neighbors[i])\n M[nbrs_x, nbrs_y] += np.dot(w, w.T)\n if M_sparse:\n M = csr_matrix(M)\n elif method == 'modified':\n if n_neighbors < n_components:\n raise ValueError('modified LLE requires n_neighbors >= n_components')\n neighbors = nbrs.kneighbors(X, n_neighbors=n_neighbors + 1, return_distance=False)\n neighbors = neighbors[:, 1:]\n V = np.zeros((N, n_neighbors, n_neighbors))\n nev = min(d_in, n_neighbors)\n evals = np.zeros([N, nev])\n use_svd = n_neighbors > d_in\n if use_svd:\n for i in range(N):\n X_nbrs = X[neighbors[i]] - X[i]\n (V[i], evals[i], _) = svd(X_nbrs, full_matrices=True)\n evals **= 2\n else:\n for i in range(N):\n X_nbrs = X[neighbors[i]] - X[i]\n C_nbrs = np.dot(X_nbrs, X_nbrs.T)\n (evi, vi) = eigh(C_nbrs)\n evals[i] = evi[::-1]\n V[i] = vi[:, ::-1]\n reg = 0.001 * evals.sum(1)\n tmp = np.dot(V.transpose(0, 2, 1), np.ones(n_neighbors))\n tmp[:, :nev] /= evals + reg[:, None]\n tmp[:, nev:] /= reg[:, None]\n w_reg = np.zeros((N, n_neighbors))\n for i in range(N):\n w_reg[i] = np.dot(V[i], tmp[i])\n w_reg /= w_reg.sum(1)[:, None]\n rho = evals[:, n_components:].sum(1) / evals[:, :n_components].sum(1)\n eta = np.median(rho)\n s_range = np.zeros(N, dtype=int)\n evals_cumsum = stable_cumsum(evals, 1)\n eta_range = evals_cumsum[:, -1:] / evals_cumsum[:, :-1] - 1\n for i in range(N):\n s_range[i] = np.searchsorted(eta_range[i, ::-1], eta)\n s_range += n_neighbors - nev\n M = np.zeros((N, N), dtype=np.float64)\n for i in range(N):\n s_i = s_range[i]\n Vi = V[i, :, n_neighbors - s_i:]\n alpha_i = np.linalg.norm(Vi.sum(0)) / np.sqrt(s_i)\n h = np.full(s_i, alpha_i) - np.dot(Vi.T, np.ones(n_neighbors))\n norm_h = np.linalg.norm(h)\n if norm_h < modified_tol:\n h *= 0\n else:\n h /= norm_h\n Wi = Vi - 2 * np.outer(np.dot(Vi, h), h) + (1 - alpha_i) * w_reg[i, :, None]\n (nbrs_x, nbrs_y) = np.meshgrid(neighbors[i], neighbors[i])\n M[nbrs_x, nbrs_y] += np.dot(Wi, Wi.T)\n Wi_sum1 = Wi.sum(1)\n M[i, neighbors[i]] -= Wi_sum1\n M[neighbors[i], i] -= Wi_sum1\n M[i, i] += s_i\n if M_sparse:\n M = csr_matrix(M)\n elif method == 'ltsa':\n neighbors = nbrs.kneighbors(X, n_neighbors=n_neighbors + 1, return_distance=False)\n neighbors = neighbors[:, 1:]\n M = np.zeros((N, N))\n use_svd = n_neighbors > d_in\n for i in range(N):\n Xi = X[neighbors[i]]\n Xi -= Xi.mean(0)\n if use_svd:\n v = svd(Xi, full_matrices=True)[0]\n else:\n Ci = np.dot(Xi, Xi.T)\n v = eigh(Ci)[1][:, ::-1]\n Gi = np.zeros((n_neighbors, n_components + 1))\n Gi[:, 1:] = v[:, :n_components]\n Gi[:, 0] = 1.0 / np.sqrt(n_neighbors)\n GiGiT = np.dot(Gi, Gi.T)\n (nbrs_x, nbrs_y) = np.meshgrid(neighbors[i], neighbors[i])\n M[nbrs_x, nbrs_y] -= GiGiT\n M[neighbors[i], neighbors[i]] += 1\n return null_space(M, n_components, k_skip=1, eigen_solver=eigen_solver, tol=tol, max_iter=max_iter, random_state=random_state)" }, { "name": "null_space", + "unique_name": "null_space", "qname": "sklearn.manifold._locally_linear.null_space", + "unique_qname": "sklearn.manifold._locally_linear.null_space", "decorators": [], "parameters": [ { @@ -110991,19 +114641,21 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "int, RandomState instance, default=None", - "description": "Determines the random number generator when ``solver`` == 'arpack'.\nPass an int for reproducible results across multiple function calls.\nSee :term: `Glossary `." + "description": "Determines the random number generator when ``solver`` == 'arpack'.\nPass an int for reproducible results across multiple function calls.\nSee :term:`Glossary `." } } ], "results": [], "is_public": false, "description": "Find the null space of a matrix M.", - "docstring": "Find the null space of a matrix M.\n\nParameters\n----------\nM : {array, matrix, sparse matrix, LinearOperator}\n Input covariance matrix: should be symmetric positive semi-definite\n\nk : int\n Number of eigenvalues/vectors to return\n\nk_skip : int, default=1\n Number of low eigenvalues to skip.\n\neigen_solver : {'auto', 'arpack', 'dense'}, default='arpack'\n auto : algorithm will attempt to choose the best method for input data\n arpack : use arnoldi iteration in shift-invert mode.\n For this method, M may be a dense matrix, sparse matrix,\n or general linear operator.\n Warning: ARPACK can be unstable for some problems. It is\n best to try several random seeds in order to check results.\n dense : use standard dense matrix operations for the eigenvalue\n decomposition. For this method, M must be an array\n or matrix type. This method should be avoided for\n large problems.\n\ntol : float, default=1e-6\n Tolerance for 'arpack' method.\n Not used if eigen_solver=='dense'.\n\nmax_iter : int, default=100\n Maximum number of iterations for 'arpack' method.\n Not used if eigen_solver=='dense'\n\nrandom_state : int, RandomState instance, default=None\n Determines the random number generator when ``solver`` == 'arpack'.\n Pass an int for reproducible results across multiple function calls.\n See :term: `Glossary `.", - "source_code": "\ndef null_space(M, k, k_skip=1, eigen_solver='arpack', tol=1e-06, max_iter=100, random_state=None):\n \"\"\"\n Find the null space of a matrix M.\n\n Parameters\n ----------\n M : {array, matrix, sparse matrix, LinearOperator}\n Input covariance matrix: should be symmetric positive semi-definite\n\n k : int\n Number of eigenvalues/vectors to return\n\n k_skip : int, default=1\n Number of low eigenvalues to skip.\n\n eigen_solver : {'auto', 'arpack', 'dense'}, default='arpack'\n auto : algorithm will attempt to choose the best method for input data\n arpack : use arnoldi iteration in shift-invert mode.\n For this method, M may be a dense matrix, sparse matrix,\n or general linear operator.\n Warning: ARPACK can be unstable for some problems. It is\n best to try several random seeds in order to check results.\n dense : use standard dense matrix operations for the eigenvalue\n decomposition. For this method, M must be an array\n or matrix type. This method should be avoided for\n large problems.\n\n tol : float, default=1e-6\n Tolerance for 'arpack' method.\n Not used if eigen_solver=='dense'.\n\n max_iter : int, default=100\n Maximum number of iterations for 'arpack' method.\n Not used if eigen_solver=='dense'\n\n random_state : int, RandomState instance, default=None\n Determines the random number generator when ``solver`` == 'arpack'.\n Pass an int for reproducible results across multiple function calls.\n See :term: `Glossary `.\n \"\"\"\n if eigen_solver == 'auto':\n if M.shape[0] > 200 and k + k_skip < 10:\n eigen_solver = 'arpack'\n else:\n eigen_solver = 'dense'\n if eigen_solver == 'arpack':\n v0 = _init_arpack_v0(M.shape[0], random_state)\n try:\n (eigen_values, eigen_vectors) = eigsh(M, k + k_skip, sigma=0.0, tol=tol, maxiter=max_iter, v0=v0)\n except RuntimeError as e:\n raise ValueError(\"Error in determining null-space with ARPACK. Error message: '%s'. Note that eigen_solver='arpack' can fail when the weight matrix is singular or otherwise ill-behaved. In that case, eigen_solver='dense' is recommended. See online documentation for more information.\" % e) from e\n return eigen_vectors[:, k_skip:], np.sum(eigen_values[k_skip:])\n elif eigen_solver == 'dense':\n if hasattr(M, 'toarray'):\n M = M.toarray()\n (eigen_values, eigen_vectors) = eigh(M, eigvals=(k_skip, k + k_skip - 1), overwrite_a=True)\n index = np.argsort(np.abs(eigen_values))\n return eigen_vectors[:, index], np.sum(eigen_values)\n else:\n raise ValueError(\"Unrecognized eigen_solver '%s'\" % eigen_solver)" + "docstring": "Find the null space of a matrix M.\n\nParameters\n----------\nM : {array, matrix, sparse matrix, LinearOperator}\n Input covariance matrix: should be symmetric positive semi-definite\n\nk : int\n Number of eigenvalues/vectors to return\n\nk_skip : int, default=1\n Number of low eigenvalues to skip.\n\neigen_solver : {'auto', 'arpack', 'dense'}, default='arpack'\n auto : algorithm will attempt to choose the best method for input data\n arpack : use arnoldi iteration in shift-invert mode.\n For this method, M may be a dense matrix, sparse matrix,\n or general linear operator.\n Warning: ARPACK can be unstable for some problems. It is\n best to try several random seeds in order to check results.\n dense : use standard dense matrix operations for the eigenvalue\n decomposition. For this method, M must be an array\n or matrix type. This method should be avoided for\n large problems.\n\ntol : float, default=1e-6\n Tolerance for 'arpack' method.\n Not used if eigen_solver=='dense'.\n\nmax_iter : int, default=100\n Maximum number of iterations for 'arpack' method.\n Not used if eigen_solver=='dense'\n\nrandom_state : int, RandomState instance, default=None\n Determines the random number generator when ``solver`` == 'arpack'.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.", + "source_code": "\ndef null_space(M, k, k_skip=1, eigen_solver='arpack', tol=1e-06, max_iter=100, random_state=None):\n \"\"\"\n Find the null space of a matrix M.\n\n Parameters\n ----------\n M : {array, matrix, sparse matrix, LinearOperator}\n Input covariance matrix: should be symmetric positive semi-definite\n\n k : int\n Number of eigenvalues/vectors to return\n\n k_skip : int, default=1\n Number of low eigenvalues to skip.\n\n eigen_solver : {'auto', 'arpack', 'dense'}, default='arpack'\n auto : algorithm will attempt to choose the best method for input data\n arpack : use arnoldi iteration in shift-invert mode.\n For this method, M may be a dense matrix, sparse matrix,\n or general linear operator.\n Warning: ARPACK can be unstable for some problems. It is\n best to try several random seeds in order to check results.\n dense : use standard dense matrix operations for the eigenvalue\n decomposition. For this method, M must be an array\n or matrix type. This method should be avoided for\n large problems.\n\n tol : float, default=1e-6\n Tolerance for 'arpack' method.\n Not used if eigen_solver=='dense'.\n\n max_iter : int, default=100\n Maximum number of iterations for 'arpack' method.\n Not used if eigen_solver=='dense'\n\n random_state : int, RandomState instance, default=None\n Determines the random number generator when ``solver`` == 'arpack'.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n \"\"\"\n if eigen_solver == 'auto':\n if M.shape[0] > 200 and k + k_skip < 10:\n eigen_solver = 'arpack'\n else:\n eigen_solver = 'dense'\n if eigen_solver == 'arpack':\n v0 = _init_arpack_v0(M.shape[0], random_state)\n try:\n (eigen_values, eigen_vectors) = eigsh(M, k + k_skip, sigma=0.0, tol=tol, maxiter=max_iter, v0=v0)\n except RuntimeError as e:\n raise ValueError(\"Error in determining null-space with ARPACK. Error message: '%s'. Note that eigen_solver='arpack' can fail when the weight matrix is singular or otherwise ill-behaved. In that case, eigen_solver='dense' is recommended. See online documentation for more information.\" % e) from e\n return eigen_vectors[:, k_skip:], np.sum(eigen_values[k_skip:])\n elif eigen_solver == 'dense':\n if hasattr(M, 'toarray'):\n M = M.toarray()\n (eigen_values, eigen_vectors) = eigh(M, eigvals=(k_skip, k + k_skip - 1), overwrite_a=True)\n index = np.argsort(np.abs(eigen_values))\n return eigen_vectors[:, index], np.sum(eigen_values)\n else:\n raise ValueError(\"Unrecognized eigen_solver '%s'\" % eigen_solver)" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.manifold._mds.MDS.__init__", + "unique_qname": "sklearn.manifold._mds.MDS.__init__", "decorators": [], "parameters": [ { @@ -111093,7 +114745,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int, RandomState instance or None, default=None", - "description": "Determines the random number generator used to initialize the centers.\nPass an int for reproducible results across multiple function calls.\nSee :term: `Glossary `." + "description": "Determines the random number generator used to initialize the centers.\nPass an int for reproducible results across multiple function calls.\nSee :term:`Glossary `." } }, { @@ -111115,7 +114767,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.manifold._mds.MDS._more_tags", + "unique_qname": "sklearn.manifold._mds.MDS._more_tags", "decorators": [], "parameters": [ { @@ -111137,7 +114791,9 @@ }, { "name": "_pairwise", + "unique_name": "_pairwise@getter", "qname": "sklearn.manifold._mds.MDS._pairwise", + "unique_qname": "sklearn.manifold._mds.MDS._pairwise@getter", "decorators": [ "deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -111162,7 +114818,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.manifold._mds.MDS.fit", + "unique_qname": "sklearn.manifold._mds.MDS.fit", "decorators": [], "parameters": [ { @@ -111214,7 +114872,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.manifold._mds.MDS.fit_transform", + "unique_qname": "sklearn.manifold._mds.MDS.fit_transform", "decorators": [], "parameters": [ { @@ -111266,7 +114926,9 @@ }, { "name": "_smacof_single", + "unique_name": "_smacof_single", "qname": "sklearn.manifold._mds._smacof_single", + "unique_qname": "sklearn.manifold._mds._smacof_single", "decorators": [], "parameters": [ { @@ -111346,19 +115008,21 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "int, RandomState instance or None, default=None", - "description": "Determines the random number generator used to initialize the centers.\nPass an int for reproducible results across multiple function calls.\nSee :term: `Glossary `." + "description": "Determines the random number generator used to initialize the centers.\nPass an int for reproducible results across multiple function calls.\nSee :term:`Glossary `." } } ], "results": [], "is_public": false, "description": "Computes multidimensional scaling using SMACOF algorithm.", - "docstring": "Computes multidimensional scaling using SMACOF algorithm.\n\nParameters\n----------\ndissimilarities : ndarray of shape (n_samples, n_samples)\n Pairwise dissimilarities between the points. Must be symmetric.\n\nmetric : bool, default=True\n Compute metric or nonmetric SMACOF algorithm.\n\nn_components : int, default=2\n Number of dimensions in which to immerse the dissimilarities. If an\n ``init`` array is provided, this option is overridden and the shape of\n ``init`` is used to determine the dimensionality of the embedding\n space.\n\ninit : ndarray of shape (n_samples, n_components), default=None\n Starting configuration of the embedding to initialize the algorithm. By\n default, the algorithm is initialized with a randomly chosen array.\n\nmax_iter : int, default=300\n Maximum number of iterations of the SMACOF algorithm for a single run.\n\nverbose : int, default=0\n Level of verbosity.\n\neps : float, default=1e-3\n Relative tolerance with respect to stress at which to declare\n convergence.\n\nrandom_state : int, RandomState instance or None, default=None\n Determines the random number generator used to initialize the centers.\n Pass an int for reproducible results across multiple function calls.\n See :term: `Glossary `.\n\nReturns\n-------\nX : ndarray of shape (n_samples, n_components)\n Coordinates of the points in a ``n_components``-space.\n\nstress : float\n The final value of the stress (sum of squared distance of the\n disparities and the distances for all constrained points).\n\nn_iter : int\n The number of iterations corresponding to the best stress.", - "source_code": "\ndef _smacof_single(dissimilarities, metric=True, n_components=2, init=None, max_iter=300, verbose=0, eps=0.001, random_state=None):\n \"\"\"Computes multidimensional scaling using SMACOF algorithm.\n\n Parameters\n ----------\n dissimilarities : ndarray of shape (n_samples, n_samples)\n Pairwise dissimilarities between the points. Must be symmetric.\n\n metric : bool, default=True\n Compute metric or nonmetric SMACOF algorithm.\n\n n_components : int, default=2\n Number of dimensions in which to immerse the dissimilarities. If an\n ``init`` array is provided, this option is overridden and the shape of\n ``init`` is used to determine the dimensionality of the embedding\n space.\n\n init : ndarray of shape (n_samples, n_components), default=None\n Starting configuration of the embedding to initialize the algorithm. By\n default, the algorithm is initialized with a randomly chosen array.\n\n max_iter : int, default=300\n Maximum number of iterations of the SMACOF algorithm for a single run.\n\n verbose : int, default=0\n Level of verbosity.\n\n eps : float, default=1e-3\n Relative tolerance with respect to stress at which to declare\n convergence.\n\n random_state : int, RandomState instance or None, default=None\n Determines the random number generator used to initialize the centers.\n Pass an int for reproducible results across multiple function calls.\n See :term: `Glossary `.\n\n Returns\n -------\n X : ndarray of shape (n_samples, n_components)\n Coordinates of the points in a ``n_components``-space.\n\n stress : float\n The final value of the stress (sum of squared distance of the\n disparities and the distances for all constrained points).\n\n n_iter : int\n The number of iterations corresponding to the best stress.\n \"\"\"\n dissimilarities = check_symmetric(dissimilarities, raise_exception=True)\n n_samples = dissimilarities.shape[0]\n random_state = check_random_state(random_state)\n sim_flat = ((1 - np.tri(n_samples)) * dissimilarities).ravel()\n sim_flat_w = sim_flat[sim_flat != 0]\n if init is None:\n X = random_state.rand(n_samples * n_components)\n X = X.reshape((n_samples, n_components))\n else:\n n_components = init.shape[1]\n if n_samples != init.shape[0]:\n raise ValueError('init matrix should be of shape (%d, %d)' % (n_samples, n_components))\n X = init\n old_stress = None\n ir = IsotonicRegression()\n for it in range(max_iter):\n dis = euclidean_distances(X)\n if metric:\n disparities = dissimilarities\n else:\n dis_flat = dis.ravel()\n dis_flat_w = dis_flat[sim_flat != 0]\n disparities_flat = ir.fit_transform(sim_flat_w, dis_flat_w)\n disparities = dis_flat.copy()\n disparities[sim_flat != 0] = disparities_flat\n disparities = disparities.reshape((n_samples, n_samples))\n disparities *= np.sqrt(n_samples * (n_samples - 1) / 2 / (disparities**2).sum())\n stress = ((dis.ravel() - disparities.ravel())**2).sum() / 2\n dis[dis == 0] = 1e-05\n ratio = disparities / dis\n B = -ratio\n B[np.arange(len(B)), np.arange(len(B))] += ratio.sum(axis=1)\n X = 1.0 / n_samples * np.dot(B, X)\n dis = np.sqrt((X**2).sum(axis=1)).sum()\n if verbose >= 2:\n print('it: %d, stress %s' % (it, stress))\n if old_stress is not None:\n if old_stress - stress / dis < eps:\n if verbose:\n print('breaking at iteration %d with stress %s' % (it, stress))\n break\n old_stress = stress / dis\n return X, stress, it + 1" + "docstring": "Computes multidimensional scaling using SMACOF algorithm.\n\nParameters\n----------\ndissimilarities : ndarray of shape (n_samples, n_samples)\n Pairwise dissimilarities between the points. Must be symmetric.\n\nmetric : bool, default=True\n Compute metric or nonmetric SMACOF algorithm.\n\nn_components : int, default=2\n Number of dimensions in which to immerse the dissimilarities. If an\n ``init`` array is provided, this option is overridden and the shape of\n ``init`` is used to determine the dimensionality of the embedding\n space.\n\ninit : ndarray of shape (n_samples, n_components), default=None\n Starting configuration of the embedding to initialize the algorithm. By\n default, the algorithm is initialized with a randomly chosen array.\n\nmax_iter : int, default=300\n Maximum number of iterations of the SMACOF algorithm for a single run.\n\nverbose : int, default=0\n Level of verbosity.\n\neps : float, default=1e-3\n Relative tolerance with respect to stress at which to declare\n convergence.\n\nrandom_state : int, RandomState instance or None, default=None\n Determines the random number generator used to initialize the centers.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\nReturns\n-------\nX : ndarray of shape (n_samples, n_components)\n Coordinates of the points in a ``n_components``-space.\n\nstress : float\n The final value of the stress (sum of squared distance of the\n disparities and the distances for all constrained points).\n\nn_iter : int\n The number of iterations corresponding to the best stress.", + "source_code": "\ndef _smacof_single(dissimilarities, metric=True, n_components=2, init=None, max_iter=300, verbose=0, eps=0.001, random_state=None):\n \"\"\"Computes multidimensional scaling using SMACOF algorithm.\n\n Parameters\n ----------\n dissimilarities : ndarray of shape (n_samples, n_samples)\n Pairwise dissimilarities between the points. Must be symmetric.\n\n metric : bool, default=True\n Compute metric or nonmetric SMACOF algorithm.\n\n n_components : int, default=2\n Number of dimensions in which to immerse the dissimilarities. If an\n ``init`` array is provided, this option is overridden and the shape of\n ``init`` is used to determine the dimensionality of the embedding\n space.\n\n init : ndarray of shape (n_samples, n_components), default=None\n Starting configuration of the embedding to initialize the algorithm. By\n default, the algorithm is initialized with a randomly chosen array.\n\n max_iter : int, default=300\n Maximum number of iterations of the SMACOF algorithm for a single run.\n\n verbose : int, default=0\n Level of verbosity.\n\n eps : float, default=1e-3\n Relative tolerance with respect to stress at which to declare\n convergence.\n\n random_state : int, RandomState instance or None, default=None\n Determines the random number generator used to initialize the centers.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n Returns\n -------\n X : ndarray of shape (n_samples, n_components)\n Coordinates of the points in a ``n_components``-space.\n\n stress : float\n The final value of the stress (sum of squared distance of the\n disparities and the distances for all constrained points).\n\n n_iter : int\n The number of iterations corresponding to the best stress.\n \"\"\"\n dissimilarities = check_symmetric(dissimilarities, raise_exception=True)\n n_samples = dissimilarities.shape[0]\n random_state = check_random_state(random_state)\n sim_flat = ((1 - np.tri(n_samples)) * dissimilarities).ravel()\n sim_flat_w = sim_flat[sim_flat != 0]\n if init is None:\n X = random_state.rand(n_samples * n_components)\n X = X.reshape((n_samples, n_components))\n else:\n n_components = init.shape[1]\n if n_samples != init.shape[0]:\n raise ValueError('init matrix should be of shape (%d, %d)' % (n_samples, n_components))\n X = init\n old_stress = None\n ir = IsotonicRegression()\n for it in range(max_iter):\n dis = euclidean_distances(X)\n if metric:\n disparities = dissimilarities\n else:\n dis_flat = dis.ravel()\n dis_flat_w = dis_flat[sim_flat != 0]\n disparities_flat = ir.fit_transform(sim_flat_w, dis_flat_w)\n disparities = dis_flat.copy()\n disparities[sim_flat != 0] = disparities_flat\n disparities = disparities.reshape((n_samples, n_samples))\n disparities *= np.sqrt(n_samples * (n_samples - 1) / 2 / (disparities**2).sum())\n stress = ((dis.ravel() - disparities.ravel())**2).sum() / 2\n dis[dis == 0] = 1e-05\n ratio = disparities / dis\n B = -ratio\n B[np.arange(len(B)), np.arange(len(B))] += ratio.sum(axis=1)\n X = 1.0 / n_samples * np.dot(B, X)\n dis = np.sqrt((X**2).sum(axis=1)).sum()\n if verbose >= 2:\n print('it: %d, stress %s' % (it, stress))\n if old_stress is not None:\n if old_stress - stress / dis < eps:\n if verbose:\n print('breaking at iteration %d with stress %s' % (it, stress))\n break\n old_stress = stress / dis\n return X, stress, it + 1" }, { "name": "smacof", + "unique_name": "smacof", "qname": "sklearn.manifold._mds.smacof", + "unique_qname": "sklearn.manifold._mds.smacof", "decorators": [], "parameters": [ { @@ -111458,7 +115122,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int, RandomState instance or None, default=None", - "description": "Determines the random number generator used to initialize the centers.\nPass an int for reproducible results across multiple function calls.\nSee :term: `Glossary `." + "description": "Determines the random number generator used to initialize the centers.\nPass an int for reproducible results across multiple function calls.\nSee :term:`Glossary `." } }, { @@ -111475,12 +115139,14 @@ "results": [], "is_public": true, "description": "Compute multidimensional scaling using the SMACOF algorithm.\n\nThe SMACOF (Scaling by MAjorizing a COmplicated Function) algorithm is a multidimensional scaling algorithm which minimizes an objective function (the *stress*) using a majorization technique. Stress majorization, also known as the Guttman Transform, guarantees a monotone convergence of stress, and is more powerful than traditional techniques such as gradient descent. The SMACOF algorithm for metric MDS can be summarized by the following steps: 1. Set an initial start configuration, randomly or not. 2. Compute the stress 3. Compute the Guttman Transform 4. Iterate 2 and 3 until convergence. The nonmetric algorithm adds a monotonic regression step before computing the stress.", - "docstring": "Compute multidimensional scaling using the SMACOF algorithm.\n\nThe SMACOF (Scaling by MAjorizing a COmplicated Function) algorithm is a\nmultidimensional scaling algorithm which minimizes an objective function\n(the *stress*) using a majorization technique. Stress majorization, also\nknown as the Guttman Transform, guarantees a monotone convergence of\nstress, and is more powerful than traditional techniques such as gradient\ndescent.\n\nThe SMACOF algorithm for metric MDS can be summarized by the following\nsteps:\n\n1. Set an initial start configuration, randomly or not.\n2. Compute the stress\n3. Compute the Guttman Transform\n4. Iterate 2 and 3 until convergence.\n\nThe nonmetric algorithm adds a monotonic regression step before computing\nthe stress.\n\nParameters\n----------\ndissimilarities : ndarray of shape (n_samples, n_samples)\n Pairwise dissimilarities between the points. Must be symmetric.\n\nmetric : bool, default=True\n Compute metric or nonmetric SMACOF algorithm.\n\nn_components : int, default=2\n Number of dimensions in which to immerse the dissimilarities. If an\n ``init`` array is provided, this option is overridden and the shape of\n ``init`` is used to determine the dimensionality of the embedding\n space.\n\ninit : ndarray of shape (n_samples, n_components), default=None\n Starting configuration of the embedding to initialize the algorithm. By\n default, the algorithm is initialized with a randomly chosen array.\n\nn_init : int, default=8\n Number of times the SMACOF algorithm will be run with different\n initializations. The final results will be the best output of the runs,\n determined by the run with the smallest final stress. If ``init`` is\n provided, this option is overridden and a single run is performed.\n\nn_jobs : int, default=None\n The number of jobs to use for the computation. If multiple\n initializations are used (``n_init``), each run of the algorithm is\n computed in parallel.\n\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\nmax_iter : int, default=300\n Maximum number of iterations of the SMACOF algorithm for a single run.\n\nverbose : int, default=0\n Level of verbosity.\n\neps : float, default=1e-3\n Relative tolerance with respect to stress at which to declare\n convergence.\n\nrandom_state : int, RandomState instance or None, default=None\n Determines the random number generator used to initialize the centers.\n Pass an int for reproducible results across multiple function calls.\n See :term: `Glossary `.\n\nreturn_n_iter : bool, default=False\n Whether or not to return the number of iterations.\n\nReturns\n-------\nX : ndarray of shape (n_samples, n_components)\n Coordinates of the points in a ``n_components``-space.\n\nstress : float\n The final value of the stress (sum of squared distance of the\n disparities and the distances for all constrained points).\n\nn_iter : int\n The number of iterations corresponding to the best stress. Returned\n only if ``return_n_iter`` is set to ``True``.\n\nNotes\n-----\n\"Modern Multidimensional Scaling - Theory and Applications\" Borg, I.;\nGroenen P. Springer Series in Statistics (1997)\n\n\"Nonmetric multidimensional scaling: a numerical method\" Kruskal, J.\nPsychometrika, 29 (1964)\n\n\"Multidimensional scaling by optimizing goodness of fit to a nonmetric\nhypothesis\" Kruskal, J. Psychometrika, 29, (1964)", - "source_code": "\ndef smacof(dissimilarities, *, metric=True, n_components=2, init=None, n_init=8, n_jobs=None, max_iter=300, verbose=0, eps=0.001, random_state=None, return_n_iter=False):\n \"\"\"Compute multidimensional scaling using the SMACOF algorithm.\n\n The SMACOF (Scaling by MAjorizing a COmplicated Function) algorithm is a\n multidimensional scaling algorithm which minimizes an objective function\n (the *stress*) using a majorization technique. Stress majorization, also\n known as the Guttman Transform, guarantees a monotone convergence of\n stress, and is more powerful than traditional techniques such as gradient\n descent.\n\n The SMACOF algorithm for metric MDS can be summarized by the following\n steps:\n\n 1. Set an initial start configuration, randomly or not.\n 2. Compute the stress\n 3. Compute the Guttman Transform\n 4. Iterate 2 and 3 until convergence.\n\n The nonmetric algorithm adds a monotonic regression step before computing\n the stress.\n\n Parameters\n ----------\n dissimilarities : ndarray of shape (n_samples, n_samples)\n Pairwise dissimilarities between the points. Must be symmetric.\n\n metric : bool, default=True\n Compute metric or nonmetric SMACOF algorithm.\n\n n_components : int, default=2\n Number of dimensions in which to immerse the dissimilarities. If an\n ``init`` array is provided, this option is overridden and the shape of\n ``init`` is used to determine the dimensionality of the embedding\n space.\n\n init : ndarray of shape (n_samples, n_components), default=None\n Starting configuration of the embedding to initialize the algorithm. By\n default, the algorithm is initialized with a randomly chosen array.\n\n n_init : int, default=8\n Number of times the SMACOF algorithm will be run with different\n initializations. The final results will be the best output of the runs,\n determined by the run with the smallest final stress. If ``init`` is\n provided, this option is overridden and a single run is performed.\n\n n_jobs : int, default=None\n The number of jobs to use for the computation. If multiple\n initializations are used (``n_init``), each run of the algorithm is\n computed in parallel.\n\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n max_iter : int, default=300\n Maximum number of iterations of the SMACOF algorithm for a single run.\n\n verbose : int, default=0\n Level of verbosity.\n\n eps : float, default=1e-3\n Relative tolerance with respect to stress at which to declare\n convergence.\n\n random_state : int, RandomState instance or None, default=None\n Determines the random number generator used to initialize the centers.\n Pass an int for reproducible results across multiple function calls.\n See :term: `Glossary `.\n\n return_n_iter : bool, default=False\n Whether or not to return the number of iterations.\n\n Returns\n -------\n X : ndarray of shape (n_samples, n_components)\n Coordinates of the points in a ``n_components``-space.\n\n stress : float\n The final value of the stress (sum of squared distance of the\n disparities and the distances for all constrained points).\n\n n_iter : int\n The number of iterations corresponding to the best stress. Returned\n only if ``return_n_iter`` is set to ``True``.\n\n Notes\n -----\n \"Modern Multidimensional Scaling - Theory and Applications\" Borg, I.;\n Groenen P. Springer Series in Statistics (1997)\n\n \"Nonmetric multidimensional scaling: a numerical method\" Kruskal, J.\n Psychometrika, 29 (1964)\n\n \"Multidimensional scaling by optimizing goodness of fit to a nonmetric\n hypothesis\" Kruskal, J. Psychometrika, 29, (1964)\n \"\"\"\n dissimilarities = check_array(dissimilarities)\n random_state = check_random_state(random_state)\n if hasattr(init, '__array__'):\n init = np.asarray(init).copy()\n if not n_init == 1:\n warnings.warn('Explicit initial positions passed: performing only one init of the MDS instead of %d' % n_init)\n n_init = 1\n (best_pos, best_stress) = (None, None)\n if effective_n_jobs(n_jobs) == 1:\n for it in range(n_init):\n (pos, stress, n_iter_) = _smacof_single(dissimilarities, metric=metric, n_components=n_components, init=init, max_iter=max_iter, verbose=verbose, eps=eps, random_state=random_state)\n if best_stress is None or stress < best_stress:\n best_stress = stress\n best_pos = pos.copy()\n best_iter = n_iter_\n else:\n seeds = random_state.randint(np.iinfo(np.int32).max, size=n_init)\n results = Parallel(n_jobs=n_jobs, verbose=max(verbose - 1, 0))((delayed(_smacof_single)(dissimilarities, metric=metric, n_components=n_components, init=init, max_iter=max_iter, verbose=verbose, eps=eps, random_state=seed) for seed in seeds))\n (positions, stress, n_iters) = zip(*results)\n best = np.argmin(stress)\n best_stress = stress[best]\n best_pos = positions[best]\n best_iter = n_iters[best]\n if return_n_iter:\n return best_pos, best_stress, best_iter\n else:\n return best_pos, best_stress" + "docstring": "Compute multidimensional scaling using the SMACOF algorithm.\n\nThe SMACOF (Scaling by MAjorizing a COmplicated Function) algorithm is a\nmultidimensional scaling algorithm which minimizes an objective function\n(the *stress*) using a majorization technique. Stress majorization, also\nknown as the Guttman Transform, guarantees a monotone convergence of\nstress, and is more powerful than traditional techniques such as gradient\ndescent.\n\nThe SMACOF algorithm for metric MDS can be summarized by the following\nsteps:\n\n1. Set an initial start configuration, randomly or not.\n2. Compute the stress\n3. Compute the Guttman Transform\n4. Iterate 2 and 3 until convergence.\n\nThe nonmetric algorithm adds a monotonic regression step before computing\nthe stress.\n\nParameters\n----------\ndissimilarities : ndarray of shape (n_samples, n_samples)\n Pairwise dissimilarities between the points. Must be symmetric.\n\nmetric : bool, default=True\n Compute metric or nonmetric SMACOF algorithm.\n\nn_components : int, default=2\n Number of dimensions in which to immerse the dissimilarities. If an\n ``init`` array is provided, this option is overridden and the shape of\n ``init`` is used to determine the dimensionality of the embedding\n space.\n\ninit : ndarray of shape (n_samples, n_components), default=None\n Starting configuration of the embedding to initialize the algorithm. By\n default, the algorithm is initialized with a randomly chosen array.\n\nn_init : int, default=8\n Number of times the SMACOF algorithm will be run with different\n initializations. The final results will be the best output of the runs,\n determined by the run with the smallest final stress. If ``init`` is\n provided, this option is overridden and a single run is performed.\n\nn_jobs : int, default=None\n The number of jobs to use for the computation. If multiple\n initializations are used (``n_init``), each run of the algorithm is\n computed in parallel.\n\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\nmax_iter : int, default=300\n Maximum number of iterations of the SMACOF algorithm for a single run.\n\nverbose : int, default=0\n Level of verbosity.\n\neps : float, default=1e-3\n Relative tolerance with respect to stress at which to declare\n convergence.\n\nrandom_state : int, RandomState instance or None, default=None\n Determines the random number generator used to initialize the centers.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\nreturn_n_iter : bool, default=False\n Whether or not to return the number of iterations.\n\nReturns\n-------\nX : ndarray of shape (n_samples, n_components)\n Coordinates of the points in a ``n_components``-space.\n\nstress : float\n The final value of the stress (sum of squared distance of the\n disparities and the distances for all constrained points).\n\nn_iter : int\n The number of iterations corresponding to the best stress. Returned\n only if ``return_n_iter`` is set to ``True``.\n\nNotes\n-----\n\"Modern Multidimensional Scaling - Theory and Applications\" Borg, I.;\nGroenen P. Springer Series in Statistics (1997)\n\n\"Nonmetric multidimensional scaling: a numerical method\" Kruskal, J.\nPsychometrika, 29 (1964)\n\n\"Multidimensional scaling by optimizing goodness of fit to a nonmetric\nhypothesis\" Kruskal, J. Psychometrika, 29, (1964)", + "source_code": "\ndef smacof(dissimilarities, *, metric=True, n_components=2, init=None, n_init=8, n_jobs=None, max_iter=300, verbose=0, eps=0.001, random_state=None, return_n_iter=False):\n \"\"\"Compute multidimensional scaling using the SMACOF algorithm.\n\n The SMACOF (Scaling by MAjorizing a COmplicated Function) algorithm is a\n multidimensional scaling algorithm which minimizes an objective function\n (the *stress*) using a majorization technique. Stress majorization, also\n known as the Guttman Transform, guarantees a monotone convergence of\n stress, and is more powerful than traditional techniques such as gradient\n descent.\n\n The SMACOF algorithm for metric MDS can be summarized by the following\n steps:\n\n 1. Set an initial start configuration, randomly or not.\n 2. Compute the stress\n 3. Compute the Guttman Transform\n 4. Iterate 2 and 3 until convergence.\n\n The nonmetric algorithm adds a monotonic regression step before computing\n the stress.\n\n Parameters\n ----------\n dissimilarities : ndarray of shape (n_samples, n_samples)\n Pairwise dissimilarities between the points. Must be symmetric.\n\n metric : bool, default=True\n Compute metric or nonmetric SMACOF algorithm.\n\n n_components : int, default=2\n Number of dimensions in which to immerse the dissimilarities. If an\n ``init`` array is provided, this option is overridden and the shape of\n ``init`` is used to determine the dimensionality of the embedding\n space.\n\n init : ndarray of shape (n_samples, n_components), default=None\n Starting configuration of the embedding to initialize the algorithm. By\n default, the algorithm is initialized with a randomly chosen array.\n\n n_init : int, default=8\n Number of times the SMACOF algorithm will be run with different\n initializations. The final results will be the best output of the runs,\n determined by the run with the smallest final stress. If ``init`` is\n provided, this option is overridden and a single run is performed.\n\n n_jobs : int, default=None\n The number of jobs to use for the computation. If multiple\n initializations are used (``n_init``), each run of the algorithm is\n computed in parallel.\n\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary `\n for more details.\n\n max_iter : int, default=300\n Maximum number of iterations of the SMACOF algorithm for a single run.\n\n verbose : int, default=0\n Level of verbosity.\n\n eps : float, default=1e-3\n Relative tolerance with respect to stress at which to declare\n convergence.\n\n random_state : int, RandomState instance or None, default=None\n Determines the random number generator used to initialize the centers.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n return_n_iter : bool, default=False\n Whether or not to return the number of iterations.\n\n Returns\n -------\n X : ndarray of shape (n_samples, n_components)\n Coordinates of the points in a ``n_components``-space.\n\n stress : float\n The final value of the stress (sum of squared distance of the\n disparities and the distances for all constrained points).\n\n n_iter : int\n The number of iterations corresponding to the best stress. Returned\n only if ``return_n_iter`` is set to ``True``.\n\n Notes\n -----\n \"Modern Multidimensional Scaling - Theory and Applications\" Borg, I.;\n Groenen P. Springer Series in Statistics (1997)\n\n \"Nonmetric multidimensional scaling: a numerical method\" Kruskal, J.\n Psychometrika, 29 (1964)\n\n \"Multidimensional scaling by optimizing goodness of fit to a nonmetric\n hypothesis\" Kruskal, J. Psychometrika, 29, (1964)\n \"\"\"\n dissimilarities = check_array(dissimilarities)\n random_state = check_random_state(random_state)\n if hasattr(init, '__array__'):\n init = np.asarray(init).copy()\n if not n_init == 1:\n warnings.warn('Explicit initial positions passed: performing only one init of the MDS instead of %d' % n_init)\n n_init = 1\n (best_pos, best_stress) = (None, None)\n if effective_n_jobs(n_jobs) == 1:\n for it in range(n_init):\n (pos, stress, n_iter_) = _smacof_single(dissimilarities, metric=metric, n_components=n_components, init=init, max_iter=max_iter, verbose=verbose, eps=eps, random_state=random_state)\n if best_stress is None or stress < best_stress:\n best_stress = stress\n best_pos = pos.copy()\n best_iter = n_iter_\n else:\n seeds = random_state.randint(np.iinfo(np.int32).max, size=n_init)\n results = Parallel(n_jobs=n_jobs, verbose=max(verbose - 1, 0))((delayed(_smacof_single)(dissimilarities, metric=metric, n_components=n_components, init=init, max_iter=max_iter, verbose=verbose, eps=eps, random_state=seed) for seed in seeds))\n (positions, stress, n_iters) = zip(*results)\n best = np.argmin(stress)\n best_stress = stress[best]\n best_pos = positions[best]\n best_iter = n_iters[best]\n if return_n_iter:\n return best_pos, best_stress, best_iter\n else:\n return best_pos, best_stress" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.manifold._spectral_embedding.SpectralEmbedding.__init__", + "unique_qname": "sklearn.manifold._spectral_embedding.SpectralEmbedding.__init__", "decorators": [], "parameters": [ { @@ -111572,7 +115238,9 @@ }, { "name": "_get_affinity_matrix", + "unique_name": "_get_affinity_matrix", "qname": "sklearn.manifold._spectral_embedding.SpectralEmbedding._get_affinity_matrix", + "unique_qname": "sklearn.manifold._spectral_embedding.SpectralEmbedding._get_affinity_matrix", "decorators": [], "parameters": [ { @@ -111614,7 +115282,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.manifold._spectral_embedding.SpectralEmbedding._more_tags", + "unique_qname": "sklearn.manifold._spectral_embedding.SpectralEmbedding._more_tags", "decorators": [], "parameters": [ { @@ -111636,7 +115306,9 @@ }, { "name": "_pairwise", + "unique_name": "_pairwise@getter", "qname": "sklearn.manifold._spectral_embedding.SpectralEmbedding._pairwise", + "unique_qname": "sklearn.manifold._spectral_embedding.SpectralEmbedding._pairwise@getter", "decorators": [ "deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -111661,7 +115333,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.manifold._spectral_embedding.SpectralEmbedding.fit", + "unique_qname": "sklearn.manifold._spectral_embedding.SpectralEmbedding.fit", "decorators": [], "parameters": [ { @@ -111703,7 +115377,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.manifold._spectral_embedding.SpectralEmbedding.fit_transform", + "unique_qname": "sklearn.manifold._spectral_embedding.SpectralEmbedding.fit_transform", "decorators": [], "parameters": [ { @@ -111745,7 +115421,9 @@ }, { "name": "_graph_connected_component", + "unique_name": "_graph_connected_component", "qname": "sklearn.manifold._spectral_embedding._graph_connected_component", + "unique_qname": "sklearn.manifold._spectral_embedding._graph_connected_component", "decorators": [], "parameters": [ { @@ -111777,7 +115455,9 @@ }, { "name": "_graph_is_connected", + "unique_name": "_graph_is_connected", "qname": "sklearn.manifold._spectral_embedding._graph_is_connected", + "unique_qname": "sklearn.manifold._spectral_embedding._graph_is_connected", "decorators": [], "parameters": [ { @@ -111799,7 +115479,9 @@ }, { "name": "_set_diag", + "unique_name": "_set_diag", "qname": "sklearn.manifold._spectral_embedding._set_diag", + "unique_qname": "sklearn.manifold._spectral_embedding._set_diag", "decorators": [], "parameters": [ { @@ -111841,7 +115523,9 @@ }, { "name": "spectral_embedding", + "unique_name": "spectral_embedding", "qname": "sklearn.manifold._spectral_embedding.spectral_embedding", + "unique_qname": "sklearn.manifold._spectral_embedding.spectral_embedding", "decorators": [], "parameters": [ { @@ -111919,11 +115603,13 @@ "is_public": true, "description": "Project the sample on the first eigenvectors of the graph Laplacian.\n\nThe adjacency matrix is used to compute a normalized graph Laplacian whose spectrum (especially the eigenvectors associated to the smallest eigenvalues) has an interpretation in terms of minimal number of cuts necessary to split the graph into comparably sized components. This embedding can also 'work' even if the ``adjacency`` variable is not strictly the adjacency matrix of a graph but more generally an affinity or similarity matrix between samples (for instance the heat kernel of a euclidean distance matrix or a k-NN matrix). However care must taken to always make the affinity matrix symmetric so that the eigenvector decomposition works as expected. Note : Laplacian Eigenmaps is the actual algorithm implemented here. Read more in the :ref:`User Guide `.", "docstring": "Project the sample on the first eigenvectors of the graph Laplacian.\n\nThe adjacency matrix is used to compute a normalized graph Laplacian\nwhose spectrum (especially the eigenvectors associated to the\nsmallest eigenvalues) has an interpretation in terms of minimal\nnumber of cuts necessary to split the graph into comparably sized\ncomponents.\n\nThis embedding can also 'work' even if the ``adjacency`` variable is\nnot strictly the adjacency matrix of a graph but more generally\nan affinity or similarity matrix between samples (for instance the\nheat kernel of a euclidean distance matrix or a k-NN matrix).\n\nHowever care must taken to always make the affinity matrix symmetric\nso that the eigenvector decomposition works as expected.\n\nNote : Laplacian Eigenmaps is the actual algorithm implemented here.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\nadjacency : {array-like, sparse graph} of shape (n_samples, n_samples)\n The adjacency matrix of the graph to embed.\n\nn_components : int, default=8\n The dimension of the projection subspace.\n\neigen_solver : {'arpack', 'lobpcg', 'amg'}, default=None\n The eigenvalue decomposition strategy to use. AMG requires pyamg\n to be installed. It can be faster on very large, sparse problems,\n but may also lead to instabilities. If None, then ``'arpack'`` is\n used.\n\nrandom_state : int, RandomState instance or None, default=None\n A pseudo random number generator used for the initialization\n of the lobpcg eigen vectors decomposition when `eigen_solver ==\n 'amg'`, and for the K-Means initialization. Use an int to make\n the results deterministic across calls (See\n :term:`Glossary `).\n\n .. note::\n When using `eigen_solver == 'amg'`,\n it is necessary to also fix the global numpy seed with\n `np.random.seed(int)` to get deterministic results. See\n https://github.com/pyamg/pyamg/issues/139 for further\n information.\n\neigen_tol : float, default=0.0\n Stopping criterion for eigendecomposition of the Laplacian matrix\n when using arpack eigen_solver.\n\nnorm_laplacian : bool, default=True\n If True, then compute symmetric normalized Laplacian.\n\ndrop_first : bool, default=True\n Whether to drop the first eigenvector. For spectral embedding, this\n should be True as the first eigenvector should be constant vector for\n connected graph, but for spectral clustering, this should be kept as\n False to retain the first eigenvector.\n\nReturns\n-------\nembedding : ndarray of shape (n_samples, n_components)\n The reduced samples.\n\nNotes\n-----\nSpectral Embedding (Laplacian Eigenmaps) is most useful when the graph\nhas one connected component. If there graph has many components, the first\nfew eigenvectors will simply uncover the connected components of the graph.\n\nReferences\n----------\n* https://en.wikipedia.org/wiki/LOBPCG\n\n* Toward the Optimal Preconditioned Eigensolver: Locally Optimal\n Block Preconditioned Conjugate Gradient Method\n Andrew V. Knyazev\n https://doi.org/10.1137%2FS1064827500366124", - "source_code": "\ndef spectral_embedding(adjacency, *, n_components=8, eigen_solver=None, random_state=None, eigen_tol=0.0, norm_laplacian=True, drop_first=True):\n \"\"\"Project the sample on the first eigenvectors of the graph Laplacian.\n\n The adjacency matrix is used to compute a normalized graph Laplacian\n whose spectrum (especially the eigenvectors associated to the\n smallest eigenvalues) has an interpretation in terms of minimal\n number of cuts necessary to split the graph into comparably sized\n components.\n\n This embedding can also 'work' even if the ``adjacency`` variable is\n not strictly the adjacency matrix of a graph but more generally\n an affinity or similarity matrix between samples (for instance the\n heat kernel of a euclidean distance matrix or a k-NN matrix).\n\n However care must taken to always make the affinity matrix symmetric\n so that the eigenvector decomposition works as expected.\n\n Note : Laplacian Eigenmaps is the actual algorithm implemented here.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n adjacency : {array-like, sparse graph} of shape (n_samples, n_samples)\n The adjacency matrix of the graph to embed.\n\n n_components : int, default=8\n The dimension of the projection subspace.\n\n eigen_solver : {'arpack', 'lobpcg', 'amg'}, default=None\n The eigenvalue decomposition strategy to use. AMG requires pyamg\n to be installed. It can be faster on very large, sparse problems,\n but may also lead to instabilities. If None, then ``'arpack'`` is\n used.\n\n random_state : int, RandomState instance or None, default=None\n A pseudo random number generator used for the initialization\n of the lobpcg eigen vectors decomposition when `eigen_solver ==\n 'amg'`, and for the K-Means initialization. Use an int to make\n the results deterministic across calls (See\n :term:`Glossary `).\n\n .. note::\n When using `eigen_solver == 'amg'`,\n it is necessary to also fix the global numpy seed with\n `np.random.seed(int)` to get deterministic results. See\n https://github.com/pyamg/pyamg/issues/139 for further\n information.\n\n eigen_tol : float, default=0.0\n Stopping criterion for eigendecomposition of the Laplacian matrix\n when using arpack eigen_solver.\n\n norm_laplacian : bool, default=True\n If True, then compute symmetric normalized Laplacian.\n\n drop_first : bool, default=True\n Whether to drop the first eigenvector. For spectral embedding, this\n should be True as the first eigenvector should be constant vector for\n connected graph, but for spectral clustering, this should be kept as\n False to retain the first eigenvector.\n\n Returns\n -------\n embedding : ndarray of shape (n_samples, n_components)\n The reduced samples.\n\n Notes\n -----\n Spectral Embedding (Laplacian Eigenmaps) is most useful when the graph\n has one connected component. If there graph has many components, the first\n few eigenvectors will simply uncover the connected components of the graph.\n\n References\n ----------\n * https://en.wikipedia.org/wiki/LOBPCG\n\n * Toward the Optimal Preconditioned Eigensolver: Locally Optimal\n Block Preconditioned Conjugate Gradient Method\n Andrew V. Knyazev\n https://doi.org/10.1137%2FS1064827500366124\n \"\"\"\n adjacency = check_symmetric(adjacency)\n try:\n from pyamg import smoothed_aggregation_solver\n except ImportError as e:\n if eigen_solver == 'amg':\n raise ValueError(\"The eigen_solver was set to 'amg', but pyamg is not available.\") from e\n if eigen_solver is None:\n eigen_solver = 'arpack'\n elif eigen_solver not in ('arpack', 'lobpcg', 'amg'):\n raise ValueError(\"Unknown value for eigen_solver: '%s'.Should be 'amg', 'arpack', or 'lobpcg'\" % eigen_solver)\n random_state = check_random_state(random_state)\n n_nodes = adjacency.shape[0]\n if drop_first:\n n_components = n_components + 1\n if not _graph_is_connected(adjacency):\n warnings.warn('Graph is not fully connected, spectral embedding may not work as expected.')\n (laplacian, dd) = csgraph_laplacian(adjacency, normed=norm_laplacian, return_diag=True)\n if eigen_solver == 'arpack' or eigen_solver != 'lobpcg' and (not sparse.isspmatrix(laplacian) or n_nodes < 5 * n_components):\n laplacian = _set_diag(laplacian, 1, norm_laplacian)\n try:\n laplacian *= -1\n v0 = _init_arpack_v0(laplacian.shape[0], random_state)\n (_, diffusion_map) = eigsh(laplacian, k=n_components, sigma=1.0, which='LM', tol=eigen_tol, v0=v0)\n embedding = diffusion_map.T[n_components::-1]\n if norm_laplacian:\n embedding = embedding / dd\n except RuntimeError:\n eigen_solver = 'lobpcg'\n laplacian *= -1\n elif eigen_solver == 'amg':\n if not sparse.issparse(laplacian):\n warnings.warn('AMG works better for sparse matrices')\n laplacian = check_array(laplacian, dtype=np.float64, accept_sparse=True)\n laplacian = _set_diag(laplacian, 1, norm_laplacian)\n diag_shift = 1e-05 * sparse.eye(laplacian.shape[0])\n laplacian += diag_shift\n ml = smoothed_aggregation_solver(check_array(laplacian, accept_sparse='csr'))\n laplacian -= diag_shift\n M = ml.aspreconditioner()\n X = random_state.rand(laplacian.shape[0], n_components + 1)\n X[:, 0] = dd.ravel()\n (_, diffusion_map) = lobpcg(laplacian, X, M=M, tol=1e-05, largest=False)\n embedding = diffusion_map.T\n if norm_laplacian:\n embedding = embedding / dd\n if embedding.shape[0] == 1:\n raise ValueError\n if eigen_solver == 'lobpcg':\n laplacian = check_array(laplacian, dtype=np.float64, accept_sparse=True)\n if n_nodes < 5 * n_components + 1:\n if sparse.isspmatrix(laplacian):\n laplacian = laplacian.toarray()\n (_, diffusion_map) = eigh(laplacian, check_finite=False)\n embedding = diffusion_map.T[:n_components]\n if norm_laplacian:\n embedding = embedding / dd\n else:\n laplacian = _set_diag(laplacian, 1, norm_laplacian)\n X = random_state.rand(laplacian.shape[0], n_components + 1)\n X[:, 0] = dd.ravel()\n (_, diffusion_map) = lobpcg(laplacian, X, tol=1e-15, largest=False, maxiter=2000)\n embedding = diffusion_map.T[:n_components]\n if norm_laplacian:\n embedding = embedding / dd\n if embedding.shape[0] == 1:\n raise ValueError\n embedding = _deterministic_vector_sign_flip(embedding)\n if drop_first:\n return embedding[1:n_components].T\n else:\n return embedding[:n_components].T" + "source_code": "\ndef spectral_embedding(adjacency, *, n_components=8, eigen_solver=None, random_state=None, eigen_tol=0.0, norm_laplacian=True, drop_first=True):\n \"\"\"Project the sample on the first eigenvectors of the graph Laplacian.\n\n The adjacency matrix is used to compute a normalized graph Laplacian\n whose spectrum (especially the eigenvectors associated to the\n smallest eigenvalues) has an interpretation in terms of minimal\n number of cuts necessary to split the graph into comparably sized\n components.\n\n This embedding can also 'work' even if the ``adjacency`` variable is\n not strictly the adjacency matrix of a graph but more generally\n an affinity or similarity matrix between samples (for instance the\n heat kernel of a euclidean distance matrix or a k-NN matrix).\n\n However care must taken to always make the affinity matrix symmetric\n so that the eigenvector decomposition works as expected.\n\n Note : Laplacian Eigenmaps is the actual algorithm implemented here.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n adjacency : {array-like, sparse graph} of shape (n_samples, n_samples)\n The adjacency matrix of the graph to embed.\n\n n_components : int, default=8\n The dimension of the projection subspace.\n\n eigen_solver : {'arpack', 'lobpcg', 'amg'}, default=None\n The eigenvalue decomposition strategy to use. AMG requires pyamg\n to be installed. It can be faster on very large, sparse problems,\n but may also lead to instabilities. If None, then ``'arpack'`` is\n used.\n\n random_state : int, RandomState instance or None, default=None\n A pseudo random number generator used for the initialization\n of the lobpcg eigen vectors decomposition when `eigen_solver ==\n 'amg'`, and for the K-Means initialization. Use an int to make\n the results deterministic across calls (See\n :term:`Glossary `).\n\n .. note::\n When using `eigen_solver == 'amg'`,\n it is necessary to also fix the global numpy seed with\n `np.random.seed(int)` to get deterministic results. See\n https://github.com/pyamg/pyamg/issues/139 for further\n information.\n\n eigen_tol : float, default=0.0\n Stopping criterion for eigendecomposition of the Laplacian matrix\n when using arpack eigen_solver.\n\n norm_laplacian : bool, default=True\n If True, then compute symmetric normalized Laplacian.\n\n drop_first : bool, default=True\n Whether to drop the first eigenvector. For spectral embedding, this\n should be True as the first eigenvector should be constant vector for\n connected graph, but for spectral clustering, this should be kept as\n False to retain the first eigenvector.\n\n Returns\n -------\n embedding : ndarray of shape (n_samples, n_components)\n The reduced samples.\n\n Notes\n -----\n Spectral Embedding (Laplacian Eigenmaps) is most useful when the graph\n has one connected component. If there graph has many components, the first\n few eigenvectors will simply uncover the connected components of the graph.\n\n References\n ----------\n * https://en.wikipedia.org/wiki/LOBPCG\n\n * Toward the Optimal Preconditioned Eigensolver: Locally Optimal\n Block Preconditioned Conjugate Gradient Method\n Andrew V. Knyazev\n https://doi.org/10.1137%2FS1064827500366124\n \"\"\"\n adjacency = check_symmetric(adjacency)\n try:\n from pyamg import smoothed_aggregation_solver\n except ImportError as e:\n if eigen_solver == 'amg':\n raise ValueError(\"The eigen_solver was set to 'amg', but pyamg is not available.\") from e\n if eigen_solver is None:\n eigen_solver = 'arpack'\n elif eigen_solver not in ('arpack', 'lobpcg', 'amg'):\n raise ValueError(\"Unknown value for eigen_solver: '%s'.Should be 'amg', 'arpack', or 'lobpcg'\" % eigen_solver)\n random_state = check_random_state(random_state)\n n_nodes = adjacency.shape[0]\n if drop_first:\n n_components = n_components + 1\n if not _graph_is_connected(adjacency):\n warnings.warn('Graph is not fully connected, spectral embedding may not work as expected.')\n (laplacian, dd) = csgraph_laplacian(adjacency, normed=norm_laplacian, return_diag=True)\n if eigen_solver == 'arpack' or eigen_solver != 'lobpcg' and (not sparse.isspmatrix(laplacian) or n_nodes < 5 * n_components):\n laplacian = _set_diag(laplacian, 1, norm_laplacian)\n try:\n laplacian *= -1\n v0 = _init_arpack_v0(laplacian.shape[0], random_state)\n (_, diffusion_map) = eigsh(laplacian, k=n_components, sigma=1.0, which='LM', tol=eigen_tol, v0=v0)\n embedding = diffusion_map.T[n_components::-1]\n if norm_laplacian:\n embedding = embedding / dd\n except RuntimeError:\n eigen_solver = 'lobpcg'\n laplacian *= -1\n elif eigen_solver == 'amg':\n if not sparse.issparse(laplacian):\n warnings.warn('AMG works better for sparse matrices')\n laplacian = check_array(laplacian, dtype=np.float64, accept_sparse=True)\n laplacian = _set_diag(laplacian, 1, norm_laplacian)\n diag_shift = 1e-05 * sparse.eye(laplacian.shape[0])\n laplacian += diag_shift\n ml = smoothed_aggregation_solver(check_array(laplacian, accept_sparse='csr'))\n laplacian -= diag_shift\n M = ml.aspreconditioner()\n X = random_state.rand(laplacian.shape[0], n_components + 1)\n X[:, 0] = dd.ravel()\n (_, diffusion_map) = lobpcg(laplacian, X, M=M, tol=1e-05, largest=False)\n embedding = diffusion_map.T\n if norm_laplacian:\n embedding = embedding / dd\n if embedding.shape[0] == 1:\n raise ValueError\n if eigen_solver == 'lobpcg':\n laplacian = check_array(laplacian, dtype=np.float64, accept_sparse=True)\n if n_nodes < 5 * n_components + 1:\n if sparse.isspmatrix(laplacian):\n laplacian = laplacian.toarray()\n (_, diffusion_map) = eigh(laplacian, check_finite=False)\n embedding = diffusion_map.T[:n_components]\n if norm_laplacian:\n embedding = embedding / dd\n else:\n laplacian = _set_diag(laplacian, 1, norm_laplacian)\n X = random_state.rand(laplacian.shape[0], n_components + 1)\n X[:, 0] = dd.ravel()\n (_, diffusion_map) = lobpcg(laplacian, X, tol=1e-05, largest=False, maxiter=2000)\n embedding = diffusion_map.T[:n_components]\n if norm_laplacian:\n embedding = embedding / dd\n if embedding.shape[0] == 1:\n raise ValueError\n embedding = _deterministic_vector_sign_flip(embedding)\n if drop_first:\n return embedding[1:n_components].T\n else:\n return embedding[:n_components].T" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.manifold._t_sne.TSNE.__init__", + "unique_qname": "sklearn.manifold._t_sne.TSNE.__init__", "decorators": [], "parameters": [ { @@ -112043,7 +115729,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int, RandomState instance or None, default=None", - "description": "Determines the random number generator. Pass an int for reproducible\nresults across multiple function calls. Note that different\ninitializations might result in different local minima of the cost\nfunction. See :term: `Glossary `." + "description": "Determines the random number generator. Pass an int for reproducible\nresults across multiple function calls. Note that different\ninitializations might result in different local minima of the cost\nfunction. See :term:`Glossary `." } }, { @@ -112095,7 +115781,9 @@ }, { "name": "_fit", + "unique_name": "_fit", "qname": "sklearn.manifold._t_sne.TSNE._fit", + "unique_qname": "sklearn.manifold._t_sne.TSNE._fit", "decorators": [], "parameters": [ { @@ -112137,7 +115825,9 @@ }, { "name": "_tsne", + "unique_name": "_tsne", "qname": "sklearn.manifold._t_sne.TSNE._tsne", + "unique_qname": "sklearn.manifold._t_sne.TSNE._tsne", "decorators": [], "parameters": [ { @@ -112219,7 +115909,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.manifold._t_sne.TSNE.fit", + "unique_qname": "sklearn.manifold._t_sne.TSNE.fit", "decorators": [], "parameters": [ { @@ -112261,7 +115953,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.manifold._t_sne.TSNE.fit_transform", + "unique_qname": "sklearn.manifold._t_sne.TSNE.fit_transform", "decorators": [], "parameters": [ { @@ -112303,7 +115997,9 @@ }, { "name": "_gradient_descent", + "unique_name": "_gradient_descent", "qname": "sklearn.manifold._t_sne._gradient_descent", + "unique_qname": "sklearn.manifold._t_sne._gradient_descent", "decorators": [], "parameters": [ { @@ -112445,7 +116141,9 @@ }, { "name": "_joint_probabilities", + "unique_name": "_joint_probabilities", "qname": "sklearn.manifold._t_sne._joint_probabilities", + "unique_qname": "sklearn.manifold._t_sne._joint_probabilities", "decorators": [], "parameters": [ { @@ -112487,7 +116185,9 @@ }, { "name": "_joint_probabilities_nn", + "unique_name": "_joint_probabilities_nn", "qname": "sklearn.manifold._t_sne._joint_probabilities_nn", + "unique_qname": "sklearn.manifold._t_sne._joint_probabilities_nn", "decorators": [], "parameters": [ { @@ -112529,7 +116229,9 @@ }, { "name": "_kl_divergence", + "unique_name": "_kl_divergence", "qname": "sklearn.manifold._t_sne._kl_divergence", + "unique_qname": "sklearn.manifold._t_sne._kl_divergence", "decorators": [], "parameters": [ { @@ -112611,7 +116313,9 @@ }, { "name": "_kl_divergence_bh", + "unique_name": "_kl_divergence_bh", "qname": "sklearn.manifold._t_sne._kl_divergence_bh", + "unique_qname": "sklearn.manifold._t_sne._kl_divergence_bh", "decorators": [], "parameters": [ { @@ -112723,7 +116427,9 @@ }, { "name": "trustworthiness", + "unique_name": "trustworthiness", "qname": "sklearn.manifold._t_sne.trustworthiness", + "unique_qname": "sklearn.manifold._t_sne.trustworthiness", "decorators": [], "parameters": [ { @@ -112775,7 +116481,9 @@ }, { "name": "configuration", + "unique_name": "configuration", "qname": "sklearn.manifold.setup.configuration", + "unique_qname": "sklearn.manifold.setup.configuration", "decorators": [], "parameters": [ { @@ -112807,7 +116515,9 @@ }, { "name": "_average_binary_score", + "unique_name": "_average_binary_score", "qname": "sklearn.metrics._base._average_binary_score", + "unique_qname": "sklearn.metrics._base._average_binary_score", "decorators": [], "parameters": [ { @@ -112846,7 +116556,7 @@ "is_public": false, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "string, [None, 'micro', 'macro' (default), 'samples', 'weighted']", + "type": "{None, 'micro', 'macro', 'samples', 'weighted'}, default='macro'", "description": "If ``None``, the scores for each class are returned. Otherwise,\nthis determines the type of averaging performed on the data:\n\n``'micro'``:\n Calculate metrics globally by considering each element of the label\n indicator matrix as a label.\n``'macro'``:\n Calculate metrics for each label, and find their unweighted\n mean. This does not take label imbalance into account.\n``'weighted'``:\n Calculate metrics for each label, and find their average, weighted\n by support (the number of true instances for each label).\n``'samples'``:\n Calculate metrics for each instance, and find their average.\n\nWill be ignored when ``y_true`` is binary." } }, @@ -112864,12 +116574,14 @@ "results": [], "is_public": false, "description": "Average a binary metric for multilabel classification.", - "docstring": "Average a binary metric for multilabel classification.\n\nParameters\n----------\ny_true : array, shape = [n_samples] or [n_samples, n_classes]\n True binary labels in binary label indicators.\n\ny_score : array, shape = [n_samples] or [n_samples, n_classes]\n Target scores, can either be probability estimates of the positive\n class, confidence values, or binary decisions.\n\naverage : string, [None, 'micro', 'macro' (default), 'samples', 'weighted']\n If ``None``, the scores for each class are returned. Otherwise,\n this determines the type of averaging performed on the data:\n\n ``'micro'``:\n Calculate metrics globally by considering each element of the label\n indicator matrix as a label.\n ``'macro'``:\n Calculate metrics for each label, and find their unweighted\n mean. This does not take label imbalance into account.\n ``'weighted'``:\n Calculate metrics for each label, and find their average, weighted\n by support (the number of true instances for each label).\n ``'samples'``:\n Calculate metrics for each instance, and find their average.\n\n Will be ignored when ``y_true`` is binary.\n\nsample_weight : array-like of shape (n_samples,), default=None\n Sample weights.\n\nbinary_metric : callable, returns shape [n_classes]\n The binary metric function to use.\n\nReturns\n-------\nscore : float or array of shape [n_classes]\n If not ``None``, average the score, else return the score for each\n classes.", - "source_code": "\ndef _average_binary_score(binary_metric, y_true, y_score, average, sample_weight=None):\n \"\"\"Average a binary metric for multilabel classification.\n\n Parameters\n ----------\n y_true : array, shape = [n_samples] or [n_samples, n_classes]\n True binary labels in binary label indicators.\n\n y_score : array, shape = [n_samples] or [n_samples, n_classes]\n Target scores, can either be probability estimates of the positive\n class, confidence values, or binary decisions.\n\n average : string, [None, 'micro', 'macro' (default), 'samples', 'weighted']\n If ``None``, the scores for each class are returned. Otherwise,\n this determines the type of averaging performed on the data:\n\n ``'micro'``:\n Calculate metrics globally by considering each element of the label\n indicator matrix as a label.\n ``'macro'``:\n Calculate metrics for each label, and find their unweighted\n mean. This does not take label imbalance into account.\n ``'weighted'``:\n Calculate metrics for each label, and find their average, weighted\n by support (the number of true instances for each label).\n ``'samples'``:\n Calculate metrics for each instance, and find their average.\n\n Will be ignored when ``y_true`` is binary.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights.\n\n binary_metric : callable, returns shape [n_classes]\n The binary metric function to use.\n\n Returns\n -------\n score : float or array of shape [n_classes]\n If not ``None``, average the score, else return the score for each\n classes.\n\n \"\"\"\n average_options = (None, 'micro', 'macro', 'weighted', 'samples')\n if average not in average_options:\n raise ValueError('average has to be one of {0}'.format(average_options))\n y_type = type_of_target(y_true)\n if y_type not in ('binary', 'multilabel-indicator'):\n raise ValueError('{0} format is not supported'.format(y_type))\n if y_type == 'binary':\n return binary_metric(y_true, y_score, sample_weight=sample_weight)\n check_consistent_length(y_true, y_score, sample_weight)\n y_true = check_array(y_true)\n y_score = check_array(y_score)\n not_average_axis = 1\n score_weight = sample_weight\n average_weight = None\n if average == 'micro':\n if score_weight is not None:\n score_weight = np.repeat(score_weight, y_true.shape[1])\n y_true = y_true.ravel()\n y_score = y_score.ravel()\n elif average == 'weighted':\n if score_weight is not None:\n average_weight = np.sum(np.multiply(y_true, np.reshape(score_weight, (-1, 1))), axis=0)\n else:\n average_weight = np.sum(y_true, axis=0)\n if np.isclose(average_weight.sum(), 0.0):\n return 0\n elif average == 'samples':\n average_weight = score_weight\n score_weight = None\n not_average_axis = 0\n if y_true.ndim == 1:\n y_true = y_true.reshape((-1, 1))\n if y_score.ndim == 1:\n y_score = y_score.reshape((-1, 1))\n n_classes = y_score.shape[not_average_axis]\n score = np.zeros((n_classes, ))\n for c in range(n_classes):\n y_true_c = y_true.take([c], axis=not_average_axis).ravel()\n y_score_c = y_score.take([c], axis=not_average_axis).ravel()\n score[c] = binary_metric(y_true_c, y_score_c, sample_weight=score_weight)\n if average is not None:\n if average_weight is not None:\n average_weight = np.asarray(average_weight)\n score[average_weight == 0] = 0\n return np.average(score, weights=average_weight)\n else:\n return score" + "docstring": "Average a binary metric for multilabel classification.\n\nParameters\n----------\ny_true : array, shape = [n_samples] or [n_samples, n_classes]\n True binary labels in binary label indicators.\n\ny_score : array, shape = [n_samples] or [n_samples, n_classes]\n Target scores, can either be probability estimates of the positive\n class, confidence values, or binary decisions.\n\naverage : {None, 'micro', 'macro', 'samples', 'weighted'}, default='macro'\n If ``None``, the scores for each class are returned. Otherwise,\n this determines the type of averaging performed on the data:\n\n ``'micro'``:\n Calculate metrics globally by considering each element of the label\n indicator matrix as a label.\n ``'macro'``:\n Calculate metrics for each label, and find their unweighted\n mean. This does not take label imbalance into account.\n ``'weighted'``:\n Calculate metrics for each label, and find their average, weighted\n by support (the number of true instances for each label).\n ``'samples'``:\n Calculate metrics for each instance, and find their average.\n\n Will be ignored when ``y_true`` is binary.\n\nsample_weight : array-like of shape (n_samples,), default=None\n Sample weights.\n\nbinary_metric : callable, returns shape [n_classes]\n The binary metric function to use.\n\nReturns\n-------\nscore : float or array of shape [n_classes]\n If not ``None``, average the score, else return the score for each\n classes.", + "source_code": "\ndef _average_binary_score(binary_metric, y_true, y_score, average, sample_weight=None):\n \"\"\"Average a binary metric for multilabel classification.\n\n Parameters\n ----------\n y_true : array, shape = [n_samples] or [n_samples, n_classes]\n True binary labels in binary label indicators.\n\n y_score : array, shape = [n_samples] or [n_samples, n_classes]\n Target scores, can either be probability estimates of the positive\n class, confidence values, or binary decisions.\n\n average : {None, 'micro', 'macro', 'samples', 'weighted'}, default='macro'\n If ``None``, the scores for each class are returned. Otherwise,\n this determines the type of averaging performed on the data:\n\n ``'micro'``:\n Calculate metrics globally by considering each element of the label\n indicator matrix as a label.\n ``'macro'``:\n Calculate metrics for each label, and find their unweighted\n mean. This does not take label imbalance into account.\n ``'weighted'``:\n Calculate metrics for each label, and find their average, weighted\n by support (the number of true instances for each label).\n ``'samples'``:\n Calculate metrics for each instance, and find their average.\n\n Will be ignored when ``y_true`` is binary.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights.\n\n binary_metric : callable, returns shape [n_classes]\n The binary metric function to use.\n\n Returns\n -------\n score : float or array of shape [n_classes]\n If not ``None``, average the score, else return the score for each\n classes.\n\n \"\"\"\n average_options = (None, 'micro', 'macro', 'weighted', 'samples')\n if average not in average_options:\n raise ValueError('average has to be one of {0}'.format(average_options))\n y_type = type_of_target(y_true)\n if y_type not in ('binary', 'multilabel-indicator'):\n raise ValueError('{0} format is not supported'.format(y_type))\n if y_type == 'binary':\n return binary_metric(y_true, y_score, sample_weight=sample_weight)\n check_consistent_length(y_true, y_score, sample_weight)\n y_true = check_array(y_true)\n y_score = check_array(y_score)\n not_average_axis = 1\n score_weight = sample_weight\n average_weight = None\n if average == 'micro':\n if score_weight is not None:\n score_weight = np.repeat(score_weight, y_true.shape[1])\n y_true = y_true.ravel()\n y_score = y_score.ravel()\n elif average == 'weighted':\n if score_weight is not None:\n average_weight = np.sum(np.multiply(y_true, np.reshape(score_weight, (-1, 1))), axis=0)\n else:\n average_weight = np.sum(y_true, axis=0)\n if np.isclose(average_weight.sum(), 0.0):\n return 0\n elif average == 'samples':\n average_weight = score_weight\n score_weight = None\n not_average_axis = 0\n if y_true.ndim == 1:\n y_true = y_true.reshape((-1, 1))\n if y_score.ndim == 1:\n y_score = y_score.reshape((-1, 1))\n n_classes = y_score.shape[not_average_axis]\n score = np.zeros((n_classes, ))\n for c in range(n_classes):\n y_true_c = y_true.take([c], axis=not_average_axis).ravel()\n y_score_c = y_score.take([c], axis=not_average_axis).ravel()\n score[c] = binary_metric(y_true_c, y_score_c, sample_weight=score_weight)\n if average is not None:\n if average_weight is not None:\n average_weight = np.asarray(average_weight)\n score[average_weight == 0] = 0\n return np.average(score, weights=average_weight)\n else:\n return score" }, { "name": "_average_multiclass_ovo_score", + "unique_name": "_average_multiclass_ovo_score", "qname": "sklearn.metrics._base._average_multiclass_ovo_score", + "unique_qname": "sklearn.metrics._base._average_multiclass_ovo_score", "decorators": [], "parameters": [ { @@ -112921,7 +116633,9 @@ }, { "name": "_check_pos_label_consistency", + "unique_name": "_check_pos_label_consistency", "qname": "sklearn.metrics._base._check_pos_label_consistency", + "unique_qname": "sklearn.metrics._base._check_pos_label_consistency", "decorators": [], "parameters": [ { @@ -112953,7 +116667,9 @@ }, { "name": "_check_set_wise_labels", + "unique_name": "_check_set_wise_labels", "qname": "sklearn.metrics._classification._check_set_wise_labels", + "unique_qname": "sklearn.metrics._classification._check_set_wise_labels", "decorators": [], "parameters": [ { @@ -113015,7 +116731,9 @@ }, { "name": "_check_targets", + "unique_name": "_check_targets", "qname": "sklearn.metrics._classification._check_targets", + "unique_qname": "sklearn.metrics._classification._check_targets", "decorators": [], "parameters": [ { @@ -113047,7 +116765,9 @@ }, { "name": "_check_zero_division", + "unique_name": "_check_zero_division", "qname": "sklearn.metrics._classification._check_zero_division", + "unique_qname": "sklearn.metrics._classification._check_zero_division", "decorators": [], "parameters": [ { @@ -113069,7 +116789,9 @@ }, { "name": "_prf_divide", + "unique_name": "_prf_divide", "qname": "sklearn.metrics._classification._prf_divide", + "unique_qname": "sklearn.metrics._classification._prf_divide", "decorators": [], "parameters": [ { @@ -113151,7 +116873,9 @@ }, { "name": "_warn_prf", + "unique_name": "_warn_prf", "qname": "sklearn.metrics._classification._warn_prf", + "unique_qname": "sklearn.metrics._classification._warn_prf", "decorators": [], "parameters": [ { @@ -113203,7 +116927,9 @@ }, { "name": "_weighted_sum", + "unique_name": "_weighted_sum", "qname": "sklearn.metrics._classification._weighted_sum", + "unique_qname": "sklearn.metrics._classification._weighted_sum", "decorators": [], "parameters": [ { @@ -113245,7 +116971,9 @@ }, { "name": "accuracy_score", + "unique_name": "accuracy_score", "qname": "sklearn.metrics._classification.accuracy_score", + "unique_qname": "sklearn.metrics._classification.accuracy_score", "decorators": [], "parameters": [ { @@ -113297,7 +117025,9 @@ }, { "name": "balanced_accuracy_score", + "unique_name": "balanced_accuracy_score", "qname": "sklearn.metrics._classification.balanced_accuracy_score", + "unique_qname": "sklearn.metrics._classification.balanced_accuracy_score", "decorators": [], "parameters": [ { @@ -113349,7 +117079,9 @@ }, { "name": "brier_score_loss", + "unique_name": "brier_score_loss", "qname": "sklearn.metrics._classification.brier_score_loss", + "unique_qname": "sklearn.metrics._classification.brier_score_loss", "decorators": [], "parameters": [ { @@ -113401,7 +117133,9 @@ }, { "name": "classification_report", + "unique_name": "classification_report", "qname": "sklearn.metrics._classification.classification_report", + "unique_qname": "sklearn.metrics._classification.classification_report", "decorators": [], "parameters": [ { @@ -113488,12 +117222,14 @@ "results": [], "is_public": true, "description": "Build a text report showing the main classification metrics.\n\nRead more in the :ref:`User Guide `.", - "docstring": "Build a text report showing the main classification metrics.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\ny_true : 1d array-like, or label indicator array / sparse matrix\n Ground truth (correct) target values.\n\ny_pred : 1d array-like, or label indicator array / sparse matrix\n Estimated targets as returned by a classifier.\n\nlabels : array-like of shape (n_labels,), default=None\n Optional list of label indices to include in the report.\n\ntarget_names : list of str of shape (n_labels,), default=None\n Optional display names matching the labels (same order).\n\nsample_weight : array-like of shape (n_samples,), default=None\n Sample weights.\n\ndigits : int, default=2\n Number of digits for formatting output floating point values.\n When ``output_dict`` is ``True``, this will be ignored and the\n returned values will not be rounded.\n\noutput_dict : bool, default=False\n If True, return output as dict.\n\n .. versionadded:: 0.20\n\nzero_division : \"warn\", 0 or 1, default=\"warn\"\n Sets the value to return when there is a zero division. If set to\n \"warn\", this acts as 0, but warnings are also raised.\n\nReturns\n-------\nreport : string / dict\n Text summary of the precision, recall, F1 score for each class.\n Dictionary returned if output_dict is True. Dictionary has the\n following structure::\n\n {'label 1': {'precision':0.5,\n 'recall':1.0,\n 'f1-score':0.67,\n 'support':1},\n 'label 2': { ... },\n ...\n }\n\n The reported averages include macro average (averaging the unweighted\n mean per label), weighted average (averaging the support-weighted mean\n per label), and sample average (only for multilabel classification).\n Micro average (averaging the total true positives, false negatives and\n false positives) is only shown for multi-label or multi-class\n with a subset of classes, because it corresponds to accuracy\n otherwise and would be the same for all metrics.\n See also :func:`precision_recall_fscore_support` for more details\n on averages.\n\n Note that in binary classification, recall of the positive class\n is also known as \"sensitivity\"; recall of the negative class is\n \"specificity\".\n\nSee Also\n--------\nprecision_recall_fscore_support, confusion_matrix,\nmultilabel_confusion_matrix\n\nExamples\n--------\n>>> from sklearn.metrics import classification_report\n>>> y_true = [0, 1, 2, 2, 2]\n>>> y_pred = [0, 0, 2, 2, 1]\n>>> target_names = ['class 0', 'class 1', 'class 2']\n>>> print(classification_report(y_true, y_pred, target_names=target_names))\n precision recall f1-score support\n\n class 0 0.50 1.00 0.67 1\n class 1 0.00 0.00 0.00 1\n class 2 1.00 0.67 0.80 3\n\n accuracy 0.60 5\n macro avg 0.50 0.56 0.49 5\nweighted avg 0.70 0.60 0.61 5\n\n>>> y_pred = [1, 1, 0]\n>>> y_true = [1, 1, 1]\n>>> print(classification_report(y_true, y_pred, labels=[1, 2, 3]))\n precision recall f1-score support\n\n 1 1.00 0.67 0.80 3\n 2 0.00 0.00 0.00 0\n 3 0.00 0.00 0.00 0\n\n micro avg 1.00 0.67 0.80 3\n macro avg 0.33 0.22 0.27 3\nweighted avg 1.00 0.67 0.80 3\n", - "source_code": "\ndef classification_report(y_true, y_pred, *, labels=None, target_names=None, sample_weight=None, digits=2, output_dict=False, zero_division='warn'):\n \"\"\"Build a text report showing the main classification metrics.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n y_true : 1d array-like, or label indicator array / sparse matrix\n Ground truth (correct) target values.\n\n y_pred : 1d array-like, or label indicator array / sparse matrix\n Estimated targets as returned by a classifier.\n\n labels : array-like of shape (n_labels,), default=None\n Optional list of label indices to include in the report.\n\n target_names : list of str of shape (n_labels,), default=None\n Optional display names matching the labels (same order).\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights.\n\n digits : int, default=2\n Number of digits for formatting output floating point values.\n When ``output_dict`` is ``True``, this will be ignored and the\n returned values will not be rounded.\n\n output_dict : bool, default=False\n If True, return output as dict.\n\n .. versionadded:: 0.20\n\n zero_division : \"warn\", 0 or 1, default=\"warn\"\n Sets the value to return when there is a zero division. If set to\n \"warn\", this acts as 0, but warnings are also raised.\n\n Returns\n -------\n report : string / dict\n Text summary of the precision, recall, F1 score for each class.\n Dictionary returned if output_dict is True. Dictionary has the\n following structure::\n\n {'label 1': {'precision':0.5,\n 'recall':1.0,\n 'f1-score':0.67,\n 'support':1},\n 'label 2': { ... },\n ...\n }\n\n The reported averages include macro average (averaging the unweighted\n mean per label), weighted average (averaging the support-weighted mean\n per label), and sample average (only for multilabel classification).\n Micro average (averaging the total true positives, false negatives and\n false positives) is only shown for multi-label or multi-class\n with a subset of classes, because it corresponds to accuracy\n otherwise and would be the same for all metrics.\n See also :func:`precision_recall_fscore_support` for more details\n on averages.\n\n Note that in binary classification, recall of the positive class\n is also known as \"sensitivity\"; recall of the negative class is\n \"specificity\".\n\n See Also\n --------\n precision_recall_fscore_support, confusion_matrix,\n multilabel_confusion_matrix\n\n Examples\n --------\n >>> from sklearn.metrics import classification_report\n >>> y_true = [0, 1, 2, 2, 2]\n >>> y_pred = [0, 0, 2, 2, 1]\n >>> target_names = ['class 0', 'class 1', 'class 2']\n >>> print(classification_report(y_true, y_pred, target_names=target_names))\n precision recall f1-score support\n \n class 0 0.50 1.00 0.67 1\n class 1 0.00 0.00 0.00 1\n class 2 1.00 0.67 0.80 3\n \n accuracy 0.60 5\n macro avg 0.50 0.56 0.49 5\n weighted avg 0.70 0.60 0.61 5\n \n >>> y_pred = [1, 1, 0]\n >>> y_true = [1, 1, 1]\n >>> print(classification_report(y_true, y_pred, labels=[1, 2, 3]))\n precision recall f1-score support\n \n 1 1.00 0.67 0.80 3\n 2 0.00 0.00 0.00 0\n 3 0.00 0.00 0.00 0\n \n micro avg 1.00 0.67 0.80 3\n macro avg 0.33 0.22 0.27 3\n weighted avg 1.00 0.67 0.80 3\n \n \"\"\"\n (y_type, y_true, y_pred) = _check_targets(y_true, y_pred)\n if labels is None:\n labels = unique_labels(y_true, y_pred)\n labels_given = False\n else:\n labels = np.asarray(labels)\n labels_given = True\n micro_is_accuracy = (y_type == 'multiclass' or y_type == 'binary') and (not labels_given or set(labels) == set(unique_labels(y_true, y_pred)))\n if target_names is not None and len(labels) != len(target_names):\n if labels_given:\n warnings.warn('labels size, {0}, does not match size of target_names, {1}'.format(len(labels), len(target_names)))\n else:\n raise ValueError('Number of classes, {0}, does not match size of target_names, {1}. Try specifying the labels parameter'.format(len(labels), len(target_names)))\n if target_names is None:\n target_names = ['%s' % l for l in labels]\n headers = ['precision', 'recall', 'f1-score', 'support']\n (p, r, f1, s) = precision_recall_fscore_support(y_true, y_pred, labels=labels, average=None, sample_weight=sample_weight, zero_division=zero_division)\n rows = zip(target_names, p, r, f1, s)\n if y_type.startswith('multilabel'):\n average_options = ('micro', 'macro', 'weighted', 'samples')\n else:\n average_options = ('micro', 'macro', 'weighted')\n if output_dict:\n report_dict = {label[0]: label[1:] for label in rows}\n for (label, scores) in report_dict.items():\n report_dict[label] = dict(zip(headers, [i.item() for i in scores]))\n else:\n longest_last_line_heading = 'weighted avg'\n name_width = max((len(cn) for cn in target_names))\n width = max(name_width, len(longest_last_line_heading), digits)\n head_fmt = '{:>{width}s} ' + ' {:>9}' * len(headers)\n report = head_fmt.format('', *headers, width=width)\n report += '\\n\\n'\n row_fmt = '{:>{width}s} ' + ' {:>9.{digits}f}' * 3 + ' {:>9}\\n'\n for row in rows:\n report += row_fmt.format(*row, width=width, digits=digits)\n report += '\\n'\n for average in average_options:\n if average.startswith('micro') and micro_is_accuracy:\n line_heading = 'accuracy'\n else:\n line_heading = average + ' avg'\n (avg_p, avg_r, avg_f1, _) = precision_recall_fscore_support(y_true, y_pred, labels=labels, average=average, sample_weight=sample_weight, zero_division=zero_division)\n avg = [avg_p, avg_r, avg_f1, np.sum(s)]\n if output_dict:\n report_dict[line_heading] = dict(zip(headers, [i.item() for i in avg]))\n elif line_heading == 'accuracy':\n row_fmt_accuracy = '{:>{width}s} ' + ' {:>9.{digits}}' * 2 + ' {:>9.{digits}f}' + ' {:>9}\\n'\n report += row_fmt_accuracy.format(line_heading, '', '', *avg[2:], width=width, digits=digits)\n else:\n report += row_fmt.format(line_heading, *avg, width=width, digits=digits)\n if output_dict:\n if 'accuracy' in report_dict.keys():\n report_dict['accuracy'] = report_dict['accuracy']['precision']\n return report_dict\n else:\n return report" + "docstring": "Build a text report showing the main classification metrics.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\ny_true : 1d array-like, or label indicator array / sparse matrix\n Ground truth (correct) target values.\n\ny_pred : 1d array-like, or label indicator array / sparse matrix\n Estimated targets as returned by a classifier.\n\nlabels : array-like of shape (n_labels,), default=None\n Optional list of label indices to include in the report.\n\ntarget_names : list of str of shape (n_labels,), default=None\n Optional display names matching the labels (same order).\n\nsample_weight : array-like of shape (n_samples,), default=None\n Sample weights.\n\ndigits : int, default=2\n Number of digits for formatting output floating point values.\n When ``output_dict`` is ``True``, this will be ignored and the\n returned values will not be rounded.\n\noutput_dict : bool, default=False\n If True, return output as dict.\n\n .. versionadded:: 0.20\n\nzero_division : \"warn\", 0 or 1, default=\"warn\"\n Sets the value to return when there is a zero division. If set to\n \"warn\", this acts as 0, but warnings are also raised.\n\nReturns\n-------\nreport : str or dict\n Text summary of the precision, recall, F1 score for each class.\n Dictionary returned if output_dict is True. Dictionary has the\n following structure::\n\n {'label 1': {'precision':0.5,\n 'recall':1.0,\n 'f1-score':0.67,\n 'support':1},\n 'label 2': { ... },\n ...\n }\n\n The reported averages include macro average (averaging the unweighted\n mean per label), weighted average (averaging the support-weighted mean\n per label), and sample average (only for multilabel classification).\n Micro average (averaging the total true positives, false negatives and\n false positives) is only shown for multi-label or multi-class\n with a subset of classes, because it corresponds to accuracy\n otherwise and would be the same for all metrics.\n See also :func:`precision_recall_fscore_support` for more details\n on averages.\n\n Note that in binary classification, recall of the positive class\n is also known as \"sensitivity\"; recall of the negative class is\n \"specificity\".\n\nSee Also\n--------\nprecision_recall_fscore_support, confusion_matrix,\nmultilabel_confusion_matrix\n\nExamples\n--------\n>>> from sklearn.metrics import classification_report\n>>> y_true = [0, 1, 2, 2, 2]\n>>> y_pred = [0, 0, 2, 2, 1]\n>>> target_names = ['class 0', 'class 1', 'class 2']\n>>> print(classification_report(y_true, y_pred, target_names=target_names))\n precision recall f1-score support\n\n class 0 0.50 1.00 0.67 1\n class 1 0.00 0.00 0.00 1\n class 2 1.00 0.67 0.80 3\n\n accuracy 0.60 5\n macro avg 0.50 0.56 0.49 5\nweighted avg 0.70 0.60 0.61 5\n\n>>> y_pred = [1, 1, 0]\n>>> y_true = [1, 1, 1]\n>>> print(classification_report(y_true, y_pred, labels=[1, 2, 3]))\n precision recall f1-score support\n\n 1 1.00 0.67 0.80 3\n 2 0.00 0.00 0.00 0\n 3 0.00 0.00 0.00 0\n\n micro avg 1.00 0.67 0.80 3\n macro avg 0.33 0.22 0.27 3\nweighted avg 1.00 0.67 0.80 3\n", + "source_code": "\ndef classification_report(y_true, y_pred, *, labels=None, target_names=None, sample_weight=None, digits=2, output_dict=False, zero_division='warn'):\n \"\"\"Build a text report showing the main classification metrics.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n y_true : 1d array-like, or label indicator array / sparse matrix\n Ground truth (correct) target values.\n\n y_pred : 1d array-like, or label indicator array / sparse matrix\n Estimated targets as returned by a classifier.\n\n labels : array-like of shape (n_labels,), default=None\n Optional list of label indices to include in the report.\n\n target_names : list of str of shape (n_labels,), default=None\n Optional display names matching the labels (same order).\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights.\n\n digits : int, default=2\n Number of digits for formatting output floating point values.\n When ``output_dict`` is ``True``, this will be ignored and the\n returned values will not be rounded.\n\n output_dict : bool, default=False\n If True, return output as dict.\n\n .. versionadded:: 0.20\n\n zero_division : \"warn\", 0 or 1, default=\"warn\"\n Sets the value to return when there is a zero division. If set to\n \"warn\", this acts as 0, but warnings are also raised.\n\n Returns\n -------\n report : str or dict\n Text summary of the precision, recall, F1 score for each class.\n Dictionary returned if output_dict is True. Dictionary has the\n following structure::\n\n {'label 1': {'precision':0.5,\n 'recall':1.0,\n 'f1-score':0.67,\n 'support':1},\n 'label 2': { ... },\n ...\n }\n\n The reported averages include macro average (averaging the unweighted\n mean per label), weighted average (averaging the support-weighted mean\n per label), and sample average (only for multilabel classification).\n Micro average (averaging the total true positives, false negatives and\n false positives) is only shown for multi-label or multi-class\n with a subset of classes, because it corresponds to accuracy\n otherwise and would be the same for all metrics.\n See also :func:`precision_recall_fscore_support` for more details\n on averages.\n\n Note that in binary classification, recall of the positive class\n is also known as \"sensitivity\"; recall of the negative class is\n \"specificity\".\n\n See Also\n --------\n precision_recall_fscore_support, confusion_matrix,\n multilabel_confusion_matrix\n\n Examples\n --------\n >>> from sklearn.metrics import classification_report\n >>> y_true = [0, 1, 2, 2, 2]\n >>> y_pred = [0, 0, 2, 2, 1]\n >>> target_names = ['class 0', 'class 1', 'class 2']\n >>> print(classification_report(y_true, y_pred, target_names=target_names))\n precision recall f1-score support\n \n class 0 0.50 1.00 0.67 1\n class 1 0.00 0.00 0.00 1\n class 2 1.00 0.67 0.80 3\n \n accuracy 0.60 5\n macro avg 0.50 0.56 0.49 5\n weighted avg 0.70 0.60 0.61 5\n \n >>> y_pred = [1, 1, 0]\n >>> y_true = [1, 1, 1]\n >>> print(classification_report(y_true, y_pred, labels=[1, 2, 3]))\n precision recall f1-score support\n \n 1 1.00 0.67 0.80 3\n 2 0.00 0.00 0.00 0\n 3 0.00 0.00 0.00 0\n \n micro avg 1.00 0.67 0.80 3\n macro avg 0.33 0.22 0.27 3\n weighted avg 1.00 0.67 0.80 3\n \n \"\"\"\n (y_type, y_true, y_pred) = _check_targets(y_true, y_pred)\n if labels is None:\n labels = unique_labels(y_true, y_pred)\n labels_given = False\n else:\n labels = np.asarray(labels)\n labels_given = True\n micro_is_accuracy = (y_type == 'multiclass' or y_type == 'binary') and (not labels_given or set(labels) == set(unique_labels(y_true, y_pred)))\n if target_names is not None and len(labels) != len(target_names):\n if labels_given:\n warnings.warn('labels size, {0}, does not match size of target_names, {1}'.format(len(labels), len(target_names)))\n else:\n raise ValueError('Number of classes, {0}, does not match size of target_names, {1}. Try specifying the labels parameter'.format(len(labels), len(target_names)))\n if target_names is None:\n target_names = ['%s' % l for l in labels]\n headers = ['precision', 'recall', 'f1-score', 'support']\n (p, r, f1, s) = precision_recall_fscore_support(y_true, y_pred, labels=labels, average=None, sample_weight=sample_weight, zero_division=zero_division)\n rows = zip(target_names, p, r, f1, s)\n if y_type.startswith('multilabel'):\n average_options = ('micro', 'macro', 'weighted', 'samples')\n else:\n average_options = ('micro', 'macro', 'weighted')\n if output_dict:\n report_dict = {label[0]: label[1:] for label in rows}\n for (label, scores) in report_dict.items():\n report_dict[label] = dict(zip(headers, [i.item() for i in scores]))\n else:\n longest_last_line_heading = 'weighted avg'\n name_width = max((len(cn) for cn in target_names))\n width = max(name_width, len(longest_last_line_heading), digits)\n head_fmt = '{:>{width}s} ' + ' {:>9}' * len(headers)\n report = head_fmt.format('', *headers, width=width)\n report += '\\n\\n'\n row_fmt = '{:>{width}s} ' + ' {:>9.{digits}f}' * 3 + ' {:>9}\\n'\n for row in rows:\n report += row_fmt.format(*row, width=width, digits=digits)\n report += '\\n'\n for average in average_options:\n if average.startswith('micro') and micro_is_accuracy:\n line_heading = 'accuracy'\n else:\n line_heading = average + ' avg'\n (avg_p, avg_r, avg_f1, _) = precision_recall_fscore_support(y_true, y_pred, labels=labels, average=average, sample_weight=sample_weight, zero_division=zero_division)\n avg = [avg_p, avg_r, avg_f1, np.sum(s)]\n if output_dict:\n report_dict[line_heading] = dict(zip(headers, [i.item() for i in avg]))\n elif line_heading == 'accuracy':\n row_fmt_accuracy = '{:>{width}s} ' + ' {:>9.{digits}}' * 2 + ' {:>9.{digits}f}' + ' {:>9}\\n'\n report += row_fmt_accuracy.format(line_heading, '', '', *avg[2:], width=width, digits=digits)\n else:\n report += row_fmt.format(line_heading, *avg, width=width, digits=digits)\n if output_dict:\n if 'accuracy' in report_dict.keys():\n report_dict['accuracy'] = report_dict['accuracy']['precision']\n return report_dict\n else:\n return report" }, { "name": "cohen_kappa_score", + "unique_name": "cohen_kappa_score", "qname": "sklearn.metrics._classification.cohen_kappa_score", + "unique_qname": "sklearn.metrics._classification.cohen_kappa_score", "decorators": [], "parameters": [ { @@ -113555,7 +117291,9 @@ }, { "name": "confusion_matrix", + "unique_name": "confusion_matrix", "qname": "sklearn.metrics._classification.confusion_matrix", + "unique_qname": "sklearn.metrics._classification.confusion_matrix", "decorators": [], "parameters": [ { @@ -113617,7 +117355,9 @@ }, { "name": "f1_score", + "unique_name": "f1_score", "qname": "sklearn.metrics._classification.f1_score", + "unique_qname": "sklearn.metrics._classification.f1_score", "decorators": [], "parameters": [ { @@ -113693,13 +117433,15 @@ ], "results": [], "is_public": true, - "description": "Compute the F1 score, also known as balanced F-score or F-measure.\n\nThe F1 score can be interpreted as a weighted average of the precision and recall, where an F1 score reaches its best value at 1 and worst score at 0. The relative contribution of precision and recall to the F1 score are equal. The formula for the F1 score is:: F1 = 2 * (precision * recall) / (precision + recall) In the multi-class and multi-label case, this is the average of the F1 score of each class with weighting depending on the ``average`` parameter. Read more in the :ref:`User Guide `.", - "docstring": "Compute the F1 score, also known as balanced F-score or F-measure.\n\nThe F1 score can be interpreted as a weighted average of the precision and\nrecall, where an F1 score reaches its best value at 1 and worst score at 0.\nThe relative contribution of precision and recall to the F1 score are\nequal. The formula for the F1 score is::\n\n F1 = 2 * (precision * recall) / (precision + recall)\n\nIn the multi-class and multi-label case, this is the average of\nthe F1 score of each class with weighting depending on the ``average``\nparameter.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\ny_true : 1d array-like, or label indicator array / sparse matrix\n Ground truth (correct) target values.\n\ny_pred : 1d array-like, or label indicator array / sparse matrix\n Estimated targets as returned by a classifier.\n\nlabels : array-like, default=None\n The set of labels to include when ``average != 'binary'``, and their\n order if ``average is None``. Labels present in the data can be\n excluded, for example to calculate a multiclass average ignoring a\n majority negative class, while labels not present in the data will\n result in 0 components in a macro average. For multilabel targets,\n labels are column indices. By default, all labels in ``y_true`` and\n ``y_pred`` are used in sorted order.\n\n .. versionchanged:: 0.17\n Parameter `labels` improved for multiclass problem.\n\npos_label : str or int, default=1\n The class to report if ``average='binary'`` and the data is binary.\n If the data are multiclass or multilabel, this will be ignored;\n setting ``labels=[pos_label]`` and ``average != 'binary'`` will report\n scores for that label only.\n\naverage : {'micro', 'macro', 'samples','weighted', 'binary'} or None, default='binary'\n This parameter is required for multiclass/multilabel targets.\n If ``None``, the scores for each class are returned. Otherwise, this\n determines the type of averaging performed on the data:\n\n ``'binary'``:\n Only report results for the class specified by ``pos_label``.\n This is applicable only if targets (``y_{true,pred}``) are binary.\n ``'micro'``:\n Calculate metrics globally by counting the total true positives,\n false negatives and false positives.\n ``'macro'``:\n Calculate metrics for each label, and find their unweighted\n mean. This does not take label imbalance into account.\n ``'weighted'``:\n Calculate metrics for each label, and find their average weighted\n by support (the number of true instances for each label). This\n alters 'macro' to account for label imbalance; it can result in an\n F-score that is not between precision and recall.\n ``'samples'``:\n Calculate metrics for each instance, and find their average (only\n meaningful for multilabel classification where this differs from\n :func:`accuracy_score`).\n\nsample_weight : array-like of shape (n_samples,), default=None\n Sample weights.\n\nzero_division : \"warn\", 0 or 1, default=\"warn\"\n Sets the value to return when there is a zero division, i.e. when all\n predictions and labels are negative. If set to \"warn\", this acts as 0,\n but warnings are also raised.\n\nReturns\n-------\nf1_score : float or array of float, shape = [n_unique_labels]\n F1 score of the positive class in binary classification or weighted\n average of the F1 scores of each class for the multiclass task.\n\nSee Also\n--------\nfbeta_score, precision_recall_fscore_support, jaccard_score,\nmultilabel_confusion_matrix\n\nReferences\n----------\n.. [1] `Wikipedia entry for the F1-score\n `_.\n\nExamples\n--------\n>>> from sklearn.metrics import f1_score\n>>> y_true = [0, 1, 2, 0, 1, 2]\n>>> y_pred = [0, 2, 1, 0, 0, 1]\n>>> f1_score(y_true, y_pred, average='macro')\n0.26...\n>>> f1_score(y_true, y_pred, average='micro')\n0.33...\n>>> f1_score(y_true, y_pred, average='weighted')\n0.26...\n>>> f1_score(y_true, y_pred, average=None)\narray([0.8, 0. , 0. ])\n>>> y_true = [0, 0, 0, 0, 0, 0]\n>>> y_pred = [0, 0, 0, 0, 0, 0]\n>>> f1_score(y_true, y_pred, zero_division=1)\n1.0...\n>>> # multilabel classification\n>>> y_true = [[0, 0, 0], [1, 1, 1], [0, 1, 1]]\n>>> y_pred = [[0, 0, 0], [1, 1, 1], [1, 1, 0]]\n>>> f1_score(y_true, y_pred, average=None)\narray([0.66666667, 1. , 0.66666667])\n\nNotes\n-----\nWhen ``true positive + false positive == 0``, precision is undefined.\nWhen ``true positive + false negative == 0``, recall is undefined.\nIn such cases, by default the metric will be set to 0, as will f-score,\nand ``UndefinedMetricWarning`` will be raised. This behavior can be\nmodified with ``zero_division``.", - "source_code": "\ndef f1_score(y_true, y_pred, *, labels=None, pos_label=1, average='binary', sample_weight=None, zero_division='warn'):\n \"\"\"Compute the F1 score, also known as balanced F-score or F-measure.\n\n The F1 score can be interpreted as a weighted average of the precision and\n recall, where an F1 score reaches its best value at 1 and worst score at 0.\n The relative contribution of precision and recall to the F1 score are\n equal. The formula for the F1 score is::\n\n F1 = 2 * (precision * recall) / (precision + recall)\n\n In the multi-class and multi-label case, this is the average of\n the F1 score of each class with weighting depending on the ``average``\n parameter.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n y_true : 1d array-like, or label indicator array / sparse matrix\n Ground truth (correct) target values.\n\n y_pred : 1d array-like, or label indicator array / sparse matrix\n Estimated targets as returned by a classifier.\n\n labels : array-like, default=None\n The set of labels to include when ``average != 'binary'``, and their\n order if ``average is None``. Labels present in the data can be\n excluded, for example to calculate a multiclass average ignoring a\n majority negative class, while labels not present in the data will\n result in 0 components in a macro average. For multilabel targets,\n labels are column indices. By default, all labels in ``y_true`` and\n ``y_pred`` are used in sorted order.\n\n .. versionchanged:: 0.17\n Parameter `labels` improved for multiclass problem.\n\n pos_label : str or int, default=1\n The class to report if ``average='binary'`` and the data is binary.\n If the data are multiclass or multilabel, this will be ignored;\n setting ``labels=[pos_label]`` and ``average != 'binary'`` will report\n scores for that label only.\n\n average : {'micro', 'macro', 'samples','weighted', 'binary'} or None, default='binary'\n This parameter is required for multiclass/multilabel targets.\n If ``None``, the scores for each class are returned. Otherwise, this\n determines the type of averaging performed on the data:\n\n ``'binary'``:\n Only report results for the class specified by ``pos_label``.\n This is applicable only if targets (``y_{true,pred}``) are binary.\n ``'micro'``:\n Calculate metrics globally by counting the total true positives,\n false negatives and false positives.\n ``'macro'``:\n Calculate metrics for each label, and find their unweighted\n mean. This does not take label imbalance into account.\n ``'weighted'``:\n Calculate metrics for each label, and find their average weighted\n by support (the number of true instances for each label). This\n alters 'macro' to account for label imbalance; it can result in an\n F-score that is not between precision and recall.\n ``'samples'``:\n Calculate metrics for each instance, and find their average (only\n meaningful for multilabel classification where this differs from\n :func:`accuracy_score`).\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights.\n\n zero_division : \"warn\", 0 or 1, default=\"warn\"\n Sets the value to return when there is a zero division, i.e. when all\n predictions and labels are negative. If set to \"warn\", this acts as 0,\n but warnings are also raised.\n\n Returns\n -------\n f1_score : float or array of float, shape = [n_unique_labels]\n F1 score of the positive class in binary classification or weighted\n average of the F1 scores of each class for the multiclass task.\n\n See Also\n --------\n fbeta_score, precision_recall_fscore_support, jaccard_score,\n multilabel_confusion_matrix\n\n References\n ----------\n .. [1] `Wikipedia entry for the F1-score\n `_.\n\n Examples\n --------\n >>> from sklearn.metrics import f1_score\n >>> y_true = [0, 1, 2, 0, 1, 2]\n >>> y_pred = [0, 2, 1, 0, 0, 1]\n >>> f1_score(y_true, y_pred, average='macro')\n 0.26...\n >>> f1_score(y_true, y_pred, average='micro')\n 0.33...\n >>> f1_score(y_true, y_pred, average='weighted')\n 0.26...\n >>> f1_score(y_true, y_pred, average=None)\n array([0.8, 0. , 0. ])\n >>> y_true = [0, 0, 0, 0, 0, 0]\n >>> y_pred = [0, 0, 0, 0, 0, 0]\n >>> f1_score(y_true, y_pred, zero_division=1)\n 1.0...\n >>> # multilabel classification\n >>> y_true = [[0, 0, 0], [1, 1, 1], [0, 1, 1]]\n >>> y_pred = [[0, 0, 0], [1, 1, 1], [1, 1, 0]]\n >>> f1_score(y_true, y_pred, average=None)\n array([0.66666667, 1. , 0.66666667])\n\n Notes\n -----\n When ``true positive + false positive == 0``, precision is undefined.\n When ``true positive + false negative == 0``, recall is undefined.\n In such cases, by default the metric will be set to 0, as will f-score,\n and ``UndefinedMetricWarning`` will be raised. This behavior can be\n modified with ``zero_division``.\n \"\"\"\n return fbeta_score(y_true, y_pred, beta=1, labels=labels, pos_label=pos_label, average=average, sample_weight=sample_weight, zero_division=zero_division)" + "description": "Compute the F1 score, also known as balanced F-score or F-measure.\n\nThe F1 score can be interpreted as a harmonic mean of the precision and recall, where an F1 score reaches its best value at 1 and worst score at 0. The relative contribution of precision and recall to the F1 score are equal. The formula for the F1 score is:: F1 = 2 * (precision * recall) / (precision + recall) In the multi-class and multi-label case, this is the average of the F1 score of each class with weighting depending on the ``average`` parameter. Read more in the :ref:`User Guide `.", + "docstring": "Compute the F1 score, also known as balanced F-score or F-measure.\n\nThe F1 score can be interpreted as a harmonic mean of the precision and\nrecall, where an F1 score reaches its best value at 1 and worst score at 0.\nThe relative contribution of precision and recall to the F1 score are\nequal. The formula for the F1 score is::\n\n F1 = 2 * (precision * recall) / (precision + recall)\n\nIn the multi-class and multi-label case, this is the average of\nthe F1 score of each class with weighting depending on the ``average``\nparameter.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\ny_true : 1d array-like, or label indicator array / sparse matrix\n Ground truth (correct) target values.\n\ny_pred : 1d array-like, or label indicator array / sparse matrix\n Estimated targets as returned by a classifier.\n\nlabels : array-like, default=None\n The set of labels to include when ``average != 'binary'``, and their\n order if ``average is None``. Labels present in the data can be\n excluded, for example to calculate a multiclass average ignoring a\n majority negative class, while labels not present in the data will\n result in 0 components in a macro average. For multilabel targets,\n labels are column indices. By default, all labels in ``y_true`` and\n ``y_pred`` are used in sorted order.\n\n .. versionchanged:: 0.17\n Parameter `labels` improved for multiclass problem.\n\npos_label : str or int, default=1\n The class to report if ``average='binary'`` and the data is binary.\n If the data are multiclass or multilabel, this will be ignored;\n setting ``labels=[pos_label]`` and ``average != 'binary'`` will report\n scores for that label only.\n\naverage : {'micro', 'macro', 'samples','weighted', 'binary'} or None, default='binary'\n This parameter is required for multiclass/multilabel targets.\n If ``None``, the scores for each class are returned. Otherwise, this\n determines the type of averaging performed on the data:\n\n ``'binary'``:\n Only report results for the class specified by ``pos_label``.\n This is applicable only if targets (``y_{true,pred}``) are binary.\n ``'micro'``:\n Calculate metrics globally by counting the total true positives,\n false negatives and false positives.\n ``'macro'``:\n Calculate metrics for each label, and find their unweighted\n mean. This does not take label imbalance into account.\n ``'weighted'``:\n Calculate metrics for each label, and find their average weighted\n by support (the number of true instances for each label). This\n alters 'macro' to account for label imbalance; it can result in an\n F-score that is not between precision and recall.\n ``'samples'``:\n Calculate metrics for each instance, and find their average (only\n meaningful for multilabel classification where this differs from\n :func:`accuracy_score`).\n\nsample_weight : array-like of shape (n_samples,), default=None\n Sample weights.\n\nzero_division : \"warn\", 0 or 1, default=\"warn\"\n Sets the value to return when there is a zero division, i.e. when all\n predictions and labels are negative. If set to \"warn\", this acts as 0,\n but warnings are also raised.\n\nReturns\n-------\nf1_score : float or array of float, shape = [n_unique_labels]\n F1 score of the positive class in binary classification or weighted\n average of the F1 scores of each class for the multiclass task.\n\nSee Also\n--------\nfbeta_score, precision_recall_fscore_support, jaccard_score,\nmultilabel_confusion_matrix\n\nReferences\n----------\n.. [1] `Wikipedia entry for the F1-score\n `_.\n\nExamples\n--------\n>>> from sklearn.metrics import f1_score\n>>> y_true = [0, 1, 2, 0, 1, 2]\n>>> y_pred = [0, 2, 1, 0, 0, 1]\n>>> f1_score(y_true, y_pred, average='macro')\n0.26...\n>>> f1_score(y_true, y_pred, average='micro')\n0.33...\n>>> f1_score(y_true, y_pred, average='weighted')\n0.26...\n>>> f1_score(y_true, y_pred, average=None)\narray([0.8, 0. , 0. ])\n>>> y_true = [0, 0, 0, 0, 0, 0]\n>>> y_pred = [0, 0, 0, 0, 0, 0]\n>>> f1_score(y_true, y_pred, zero_division=1)\n1.0...\n>>> # multilabel classification\n>>> y_true = [[0, 0, 0], [1, 1, 1], [0, 1, 1]]\n>>> y_pred = [[0, 0, 0], [1, 1, 1], [1, 1, 0]]\n>>> f1_score(y_true, y_pred, average=None)\narray([0.66666667, 1. , 0.66666667])\n\nNotes\n-----\nWhen ``true positive + false positive == 0``, precision is undefined.\nWhen ``true positive + false negative == 0``, recall is undefined.\nIn such cases, by default the metric will be set to 0, as will f-score,\nand ``UndefinedMetricWarning`` will be raised. This behavior can be\nmodified with ``zero_division``.", + "source_code": "\ndef f1_score(y_true, y_pred, *, labels=None, pos_label=1, average='binary', sample_weight=None, zero_division='warn'):\n \"\"\"Compute the F1 score, also known as balanced F-score or F-measure.\n\n The F1 score can be interpreted as a harmonic mean of the precision and\n recall, where an F1 score reaches its best value at 1 and worst score at 0.\n The relative contribution of precision and recall to the F1 score are\n equal. The formula for the F1 score is::\n\n F1 = 2 * (precision * recall) / (precision + recall)\n\n In the multi-class and multi-label case, this is the average of\n the F1 score of each class with weighting depending on the ``average``\n parameter.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n y_true : 1d array-like, or label indicator array / sparse matrix\n Ground truth (correct) target values.\n\n y_pred : 1d array-like, or label indicator array / sparse matrix\n Estimated targets as returned by a classifier.\n\n labels : array-like, default=None\n The set of labels to include when ``average != 'binary'``, and their\n order if ``average is None``. Labels present in the data can be\n excluded, for example to calculate a multiclass average ignoring a\n majority negative class, while labels not present in the data will\n result in 0 components in a macro average. For multilabel targets,\n labels are column indices. By default, all labels in ``y_true`` and\n ``y_pred`` are used in sorted order.\n\n .. versionchanged:: 0.17\n Parameter `labels` improved for multiclass problem.\n\n pos_label : str or int, default=1\n The class to report if ``average='binary'`` and the data is binary.\n If the data are multiclass or multilabel, this will be ignored;\n setting ``labels=[pos_label]`` and ``average != 'binary'`` will report\n scores for that label only.\n\n average : {'micro', 'macro', 'samples','weighted', 'binary'} or None, default='binary'\n This parameter is required for multiclass/multilabel targets.\n If ``None``, the scores for each class are returned. Otherwise, this\n determines the type of averaging performed on the data:\n\n ``'binary'``:\n Only report results for the class specified by ``pos_label``.\n This is applicable only if targets (``y_{true,pred}``) are binary.\n ``'micro'``:\n Calculate metrics globally by counting the total true positives,\n false negatives and false positives.\n ``'macro'``:\n Calculate metrics for each label, and find their unweighted\n mean. This does not take label imbalance into account.\n ``'weighted'``:\n Calculate metrics for each label, and find their average weighted\n by support (the number of true instances for each label). This\n alters 'macro' to account for label imbalance; it can result in an\n F-score that is not between precision and recall.\n ``'samples'``:\n Calculate metrics for each instance, and find their average (only\n meaningful for multilabel classification where this differs from\n :func:`accuracy_score`).\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights.\n\n zero_division : \"warn\", 0 or 1, default=\"warn\"\n Sets the value to return when there is a zero division, i.e. when all\n predictions and labels are negative. If set to \"warn\", this acts as 0,\n but warnings are also raised.\n\n Returns\n -------\n f1_score : float or array of float, shape = [n_unique_labels]\n F1 score of the positive class in binary classification or weighted\n average of the F1 scores of each class for the multiclass task.\n\n See Also\n --------\n fbeta_score, precision_recall_fscore_support, jaccard_score,\n multilabel_confusion_matrix\n\n References\n ----------\n .. [1] `Wikipedia entry for the F1-score\n `_.\n\n Examples\n --------\n >>> from sklearn.metrics import f1_score\n >>> y_true = [0, 1, 2, 0, 1, 2]\n >>> y_pred = [0, 2, 1, 0, 0, 1]\n >>> f1_score(y_true, y_pred, average='macro')\n 0.26...\n >>> f1_score(y_true, y_pred, average='micro')\n 0.33...\n >>> f1_score(y_true, y_pred, average='weighted')\n 0.26...\n >>> f1_score(y_true, y_pred, average=None)\n array([0.8, 0. , 0. ])\n >>> y_true = [0, 0, 0, 0, 0, 0]\n >>> y_pred = [0, 0, 0, 0, 0, 0]\n >>> f1_score(y_true, y_pred, zero_division=1)\n 1.0...\n >>> # multilabel classification\n >>> y_true = [[0, 0, 0], [1, 1, 1], [0, 1, 1]]\n >>> y_pred = [[0, 0, 0], [1, 1, 1], [1, 1, 0]]\n >>> f1_score(y_true, y_pred, average=None)\n array([0.66666667, 1. , 0.66666667])\n\n Notes\n -----\n When ``true positive + false positive == 0``, precision is undefined.\n When ``true positive + false negative == 0``, recall is undefined.\n In such cases, by default the metric will be set to 0, as will f-score,\n and ``UndefinedMetricWarning`` will be raised. This behavior can be\n modified with ``zero_division``.\n \"\"\"\n return fbeta_score(y_true, y_pred, beta=1, labels=labels, pos_label=pos_label, average=average, sample_weight=sample_weight, zero_division=zero_division)" }, { "name": "fbeta_score", + "unique_name": "fbeta_score", "qname": "sklearn.metrics._classification.fbeta_score", + "unique_qname": "sklearn.metrics._classification.fbeta_score", "decorators": [], "parameters": [ { @@ -113791,7 +117533,9 @@ }, { "name": "hamming_loss", + "unique_name": "hamming_loss", "qname": "sklearn.metrics._classification.hamming_loss", + "unique_qname": "sklearn.metrics._classification.hamming_loss", "decorators": [], "parameters": [ { @@ -113833,7 +117577,9 @@ }, { "name": "hinge_loss", + "unique_name": "hinge_loss", "qname": "sklearn.metrics._classification.hinge_loss", + "unique_qname": "sklearn.metrics._classification.hinge_loss", "decorators": [], "parameters": [ { @@ -113885,7 +117631,9 @@ }, { "name": "jaccard_score", + "unique_name": "jaccard_score", "qname": "sklearn.metrics._classification.jaccard_score", + "unique_qname": "sklearn.metrics._classification.jaccard_score", "decorators": [], "parameters": [ { @@ -113967,7 +117715,9 @@ }, { "name": "log_loss", + "unique_name": "log_loss", "qname": "sklearn.metrics._classification.log_loss", + "unique_qname": "sklearn.metrics._classification.log_loss", "decorators": [], "parameters": [ { @@ -114039,7 +117789,9 @@ }, { "name": "matthews_corrcoef", + "unique_name": "matthews_corrcoef", "qname": "sklearn.metrics._classification.matthews_corrcoef", + "unique_qname": "sklearn.metrics._classification.matthews_corrcoef", "decorators": [], "parameters": [ { @@ -114081,7 +117833,9 @@ }, { "name": "multilabel_confusion_matrix", + "unique_name": "multilabel_confusion_matrix", "qname": "sklearn.metrics._classification.multilabel_confusion_matrix", + "unique_qname": "sklearn.metrics._classification.multilabel_confusion_matrix", "decorators": [], "parameters": [ { @@ -114143,7 +117897,9 @@ }, { "name": "precision_recall_fscore_support", + "unique_name": "precision_recall_fscore_support", "qname": "sklearn.metrics._classification.precision_recall_fscore_support", + "unique_qname": "sklearn.metrics._classification.precision_recall_fscore_support", "decorators": [], "parameters": [ { @@ -114245,7 +118001,9 @@ }, { "name": "precision_score", + "unique_name": "precision_score", "qname": "sklearn.metrics._classification.precision_score", + "unique_qname": "sklearn.metrics._classification.precision_score", "decorators": [], "parameters": [ { @@ -114327,7 +118085,9 @@ }, { "name": "recall_score", + "unique_name": "recall_score", "qname": "sklearn.metrics._classification.recall_score", + "unique_qname": "sklearn.metrics._classification.recall_score", "decorators": [], "parameters": [ { @@ -114409,7 +118169,9 @@ }, { "name": "zero_one_loss", + "unique_name": "zero_one_loss", "qname": "sklearn.metrics._classification.zero_one_loss", + "unique_qname": "sklearn.metrics._classification.zero_one_loss", "decorators": [], "parameters": [ { @@ -114461,7 +118223,9 @@ }, { "name": "_check_classifier_response_method", + "unique_name": "_check_classifier_response_method", "qname": "sklearn.metrics._plot.base._check_classifier_response_method", + "unique_qname": "sklearn.metrics._plot.base._check_classifier_response_method", "decorators": [], "parameters": [ { @@ -114493,7 +118257,9 @@ }, { "name": "_get_response", + "unique_name": "_get_response", "qname": "sklearn.metrics._plot.base._get_response", + "unique_qname": "sklearn.metrics._plot.base._get_response", "decorators": [], "parameters": [ { @@ -114541,11 +118307,13 @@ "is_public": false, "description": "Return response and positive label.", "docstring": "Return response and positive label.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input values.\n\nestimator : estimator instance\n Fitted classifier or a fitted :class:`~sklearn.pipeline.Pipeline`\n in which the last estimator is a classifier.\n\nresponse_method: {'auto', 'predict_proba', 'decision_function'}\n Specifies whether to use :term:`predict_proba` or\n :term:`decision_function` as the target response. If set to 'auto',\n :term:`predict_proba` is tried first and if it does not exist\n :term:`decision_function` is tried next.\n\npos_label : str or int, default=None\n The class considered as the positive class when computing\n the metrics. By default, `estimators.classes_[1]` is\n considered as the positive class.\n\nReturns\n-------\ny_pred: ndarray of shape (n_samples,)\n Target scores calculated from the provided response_method\n and pos_label.\n\npos_label: str or int\n The class considered as the positive class when computing\n the metrics.", - "source_code": "\ndef _get_response(X, estimator, response_method, pos_label=None):\n \"\"\"Return response and positive label.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input values.\n\n estimator : estimator instance\n Fitted classifier or a fitted :class:`~sklearn.pipeline.Pipeline`\n in which the last estimator is a classifier.\n\n response_method: {'auto', 'predict_proba', 'decision_function'}\n Specifies whether to use :term:`predict_proba` or\n :term:`decision_function` as the target response. If set to 'auto',\n :term:`predict_proba` is tried first and if it does not exist\n :term:`decision_function` is tried next.\n\n pos_label : str or int, default=None\n The class considered as the positive class when computing\n the metrics. By default, `estimators.classes_[1]` is\n considered as the positive class.\n\n Returns\n -------\n y_pred: ndarray of shape (n_samples,)\n Target scores calculated from the provided response_method\n and pos_label.\n\n pos_label: str or int\n The class considered as the positive class when computing\n the metrics.\n \"\"\"\n classification_error = f\"Expected 'estimator' to be a binary classifier, but got {estimator.__class__.__name__}\"\n if not is_classifier(estimator):\n raise ValueError(classification_error)\n prediction_method = _check_classifier_response_method(estimator, response_method)\n y_pred = prediction_method(X)\n if pos_label is not None and pos_label not in estimator.classes_:\n raise ValueError(f\"The class provided by 'pos_label' is unknown. Got {pos_label} instead of one of {estimator.classes_}\")\n if y_pred.ndim != 1:\n y_pred_shape = y_pred.shape[1]\n if y_pred_shape != 2:\n raise ValueError(f'{classification_error} fit on multiclass ({y_pred_shape} classes) data')\n if pos_label is None:\n pos_label = estimator.classes_[1]\n y_pred = y_pred[:, 1]\n else:\n class_idx = np.flatnonzero(estimator.classes_ == pos_label)\n y_pred = y_pred[:, class_idx]\n elif pos_label is None:\n pos_label = estimator.classes_[1]\n elif pos_label == estimator.classes_[0]:\n y_pred *= -1\n return y_pred, pos_label" + "source_code": "\ndef _get_response(X, estimator, response_method, pos_label=None):\n \"\"\"Return response and positive label.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Input values.\n\n estimator : estimator instance\n Fitted classifier or a fitted :class:`~sklearn.pipeline.Pipeline`\n in which the last estimator is a classifier.\n\n response_method: {'auto', 'predict_proba', 'decision_function'}\n Specifies whether to use :term:`predict_proba` or\n :term:`decision_function` as the target response. If set to 'auto',\n :term:`predict_proba` is tried first and if it does not exist\n :term:`decision_function` is tried next.\n\n pos_label : str or int, default=None\n The class considered as the positive class when computing\n the metrics. By default, `estimators.classes_[1]` is\n considered as the positive class.\n\n Returns\n -------\n y_pred: ndarray of shape (n_samples,)\n Target scores calculated from the provided response_method\n and pos_label.\n\n pos_label: str or int\n The class considered as the positive class when computing\n the metrics.\n \"\"\"\n classification_error = f\"Expected 'estimator' to be a binary classifier, but got {estimator.__class__.__name__}\"\n if not is_classifier(estimator):\n raise ValueError(classification_error)\n prediction_method = _check_classifier_response_method(estimator, response_method)\n y_pred = prediction_method(X)\n if pos_label is not None:\n try:\n class_idx = estimator.classes_.tolist().index(pos_label)\n except ValueError as e:\n raise ValueError(f\"The class provided by 'pos_label' is unknown. Got {pos_label} instead of one of {set(estimator.classes_)}\") from e\n else:\n class_idx = 1\n pos_label = estimator.classes_[class_idx]\n if y_pred.ndim != 1:\n y_pred_shape = y_pred.shape[1]\n if y_pred_shape != 2:\n raise ValueError(f'{classification_error} fit on multiclass ({y_pred_shape} classes) data')\n y_pred = y_pred[:, class_idx]\n elif pos_label == estimator.classes_[0]:\n y_pred *= -1\n return y_pred, pos_label" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.metrics._plot.confusion_matrix.ConfusionMatrixDisplay.__init__", + "unique_qname": "sklearn.metrics._plot.confusion_matrix.ConfusionMatrixDisplay.__init__", "decorators": [], "parameters": [ { @@ -114587,7 +118355,9 @@ }, { "name": "from_estimator", + "unique_name": "from_estimator", "qname": "sklearn.metrics._plot.confusion_matrix.ConfusionMatrixDisplay.from_estimator", + "unique_qname": "sklearn.metrics._plot.confusion_matrix.ConfusionMatrixDisplay.from_estimator", "decorators": ["classmethod"], "parameters": [ { @@ -114739,7 +118509,9 @@ }, { "name": "from_predictions", + "unique_name": "from_predictions", "qname": "sklearn.metrics._plot.confusion_matrix.ConfusionMatrixDisplay.from_predictions", + "unique_qname": "sklearn.metrics._plot.confusion_matrix.ConfusionMatrixDisplay.from_predictions", "decorators": ["classmethod"], "parameters": [ { @@ -114881,7 +118653,9 @@ }, { "name": "plot", + "unique_name": "plot", "qname": "sklearn.metrics._plot.confusion_matrix.ConfusionMatrixDisplay.plot", + "unique_qname": "sklearn.metrics._plot.confusion_matrix.ConfusionMatrixDisplay.plot", "decorators": [], "parameters": [ { @@ -114963,7 +118737,9 @@ }, { "name": "plot_confusion_matrix", + "unique_name": "plot_confusion_matrix", "qname": "sklearn.metrics._plot.confusion_matrix.plot_confusion_matrix", + "unique_qname": "sklearn.metrics._plot.confusion_matrix.plot_confusion_matrix", "decorators": [ "deprecated('Function `plot_confusion_matrix` is deprecated in 1.0 and will be removed in 1.2. Use one of the class methods: ConfusionMatrixDisplay.from_predictions or ConfusionMatrixDisplay.from_estimator.')" ], @@ -115107,7 +118883,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.metrics._plot.det_curve.DetCurveDisplay.__init__", + "unique_qname": "sklearn.metrics._plot.det_curve.DetCurveDisplay.__init__", "decorators": [], "parameters": [ { @@ -115169,7 +118947,9 @@ }, { "name": "from_estimator", + "unique_name": "from_estimator", "qname": "sklearn.metrics._plot.det_curve.DetCurveDisplay.from_estimator", + "unique_qname": "sklearn.metrics._plot.det_curve.DetCurveDisplay.from_estimator", "decorators": ["classmethod"], "parameters": [ { @@ -115271,7 +119051,9 @@ }, { "name": "from_predictions", + "unique_name": "from_predictions", "qname": "sklearn.metrics._plot.det_curve.DetCurveDisplay.from_predictions", + "unique_qname": "sklearn.metrics._plot.det_curve.DetCurveDisplay.from_predictions", "decorators": ["classmethod"], "parameters": [ { @@ -115353,7 +119135,9 @@ }, { "name": "plot", + "unique_name": "plot", "qname": "sklearn.metrics._plot.det_curve.DetCurveDisplay.plot", + "unique_qname": "sklearn.metrics._plot.det_curve.DetCurveDisplay.plot", "decorators": [], "parameters": [ { @@ -115395,7 +119179,9 @@ }, { "name": "plot_det_curve", + "unique_name": "plot_det_curve", "qname": "sklearn.metrics._plot.det_curve.plot_det_curve", + "unique_qname": "sklearn.metrics._plot.det_curve.plot_det_curve", "decorators": [ "deprecated('Function plot_det_curve is deprecated in 1.0 and will be removed in 1.2. Use one of the class methods: DetCurveDisplay.from_predictions or DetCurveDisplay.from_estimator.')" ], @@ -115489,7 +119275,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.metrics._plot.precision_recall_curve.PrecisionRecallDisplay.__init__", + "unique_qname": "sklearn.metrics._plot.precision_recall_curve.PrecisionRecallDisplay.__init__", "decorators": [], "parameters": [ { @@ -115561,7 +119349,9 @@ }, { "name": "from_estimator", + "unique_name": "from_estimator", "qname": "sklearn.metrics._plot.precision_recall_curve.PrecisionRecallDisplay.from_estimator", + "unique_qname": "sklearn.metrics._plot.precision_recall_curve.PrecisionRecallDisplay.from_estimator", "decorators": ["classmethod"], "parameters": [ { @@ -115663,7 +119453,9 @@ }, { "name": "from_predictions", + "unique_name": "from_predictions", "qname": "sklearn.metrics._plot.precision_recall_curve.PrecisionRecallDisplay.from_predictions", + "unique_qname": "sklearn.metrics._plot.precision_recall_curve.PrecisionRecallDisplay.from_predictions", "decorators": ["classmethod"], "parameters": [ { @@ -115745,7 +119537,9 @@ }, { "name": "plot", + "unique_name": "plot", "qname": "sklearn.metrics._plot.precision_recall_curve.PrecisionRecallDisplay.plot", + "unique_qname": "sklearn.metrics._plot.precision_recall_curve.PrecisionRecallDisplay.plot", "decorators": [], "parameters": [ { @@ -115787,7 +119581,9 @@ }, { "name": "plot_precision_recall_curve", + "unique_name": "plot_precision_recall_curve", "qname": "sklearn.metrics._plot.precision_recall_curve.plot_precision_recall_curve", + "unique_qname": "sklearn.metrics._plot.precision_recall_curve.plot_precision_recall_curve", "decorators": [ "deprecated('Function `plot_precision_recall_curve` is deprecated in 1.0 and will be removed in 1.2. Use one of the class methods: PrecisionRecallDisplay.from_predictions or PrecisionRecallDisplay.from_estimator.')" ], @@ -115881,7 +119677,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.metrics._plot.roc_curve.RocCurveDisplay.__init__", + "unique_qname": "sklearn.metrics._plot.roc_curve.RocCurveDisplay.__init__", "decorators": [], "parameters": [ { @@ -115953,7 +119751,9 @@ }, { "name": "from_estimator", + "unique_name": "from_estimator", "qname": "sklearn.metrics._plot.roc_curve.RocCurveDisplay.from_estimator", + "unique_qname": "sklearn.metrics._plot.roc_curve.RocCurveDisplay.from_estimator", "decorators": ["classmethod"], "parameters": [ { @@ -116065,7 +119865,9 @@ }, { "name": "from_predictions", + "unique_name": "from_predictions", "qname": "sklearn.metrics._plot.roc_curve.RocCurveDisplay.from_predictions", + "unique_qname": "sklearn.metrics._plot.roc_curve.RocCurveDisplay.from_predictions", "decorators": ["classmethod"], "parameters": [ { @@ -116157,7 +119959,9 @@ }, { "name": "plot", + "unique_name": "plot", "qname": "sklearn.metrics._plot.roc_curve.RocCurveDisplay.plot", + "unique_qname": "sklearn.metrics._plot.roc_curve.RocCurveDisplay.plot", "decorators": [], "parameters": [ { @@ -116199,7 +120003,9 @@ }, { "name": "plot_roc_curve", + "unique_name": "plot_roc_curve", "qname": "sklearn.metrics._plot.roc_curve.plot_roc_curve", + "unique_qname": "sklearn.metrics._plot.roc_curve.plot_roc_curve", "decorators": [ "deprecated('Function `plot_roc_curve` is deprecated in 1.0 and will be removed in 1.2. Use one of the class methods: RocCurveDisplay.from_predictions or RocCurveDisplay.from_estimator.')" ], @@ -116303,7 +120109,9 @@ }, { "name": "_binary_clf_curve", + "unique_name": "_binary_clf_curve", "qname": "sklearn.metrics._ranking._binary_clf_curve", + "unique_qname": "sklearn.metrics._ranking._binary_clf_curve", "decorators": [], "parameters": [ { @@ -116355,7 +120163,9 @@ }, { "name": "_binary_roc_auc_score", + "unique_name": "_binary_roc_auc_score", "qname": "sklearn.metrics._ranking._binary_roc_auc_score", + "unique_qname": "sklearn.metrics._ranking._binary_roc_auc_score", "decorators": [], "parameters": [ { @@ -116407,7 +120217,9 @@ }, { "name": "_check_dcg_target_type", + "unique_name": "_check_dcg_target_type", "qname": "sklearn.metrics._ranking._check_dcg_target_type", + "unique_qname": "sklearn.metrics._ranking._check_dcg_target_type", "decorators": [], "parameters": [ { @@ -116429,7 +120241,9 @@ }, { "name": "_dcg_sample_scores", + "unique_name": "_dcg_sample_scores", "qname": "sklearn.metrics._ranking._dcg_sample_scores", + "unique_qname": "sklearn.metrics._ranking._dcg_sample_scores", "decorators": [], "parameters": [ { @@ -116491,7 +120305,9 @@ }, { "name": "_multiclass_roc_auc_score", + "unique_name": "_multiclass_roc_auc_score", "qname": "sklearn.metrics._ranking._multiclass_roc_auc_score", + "unique_qname": "sklearn.metrics._ranking._multiclass_roc_auc_score", "decorators": [], "parameters": [ { @@ -116563,7 +120379,9 @@ }, { "name": "_ndcg_sample_scores", + "unique_name": "_ndcg_sample_scores", "qname": "sklearn.metrics._ranking._ndcg_sample_scores", + "unique_qname": "sklearn.metrics._ranking._ndcg_sample_scores", "decorators": [], "parameters": [ { @@ -116615,7 +120433,9 @@ }, { "name": "_tie_averaged_dcg", + "unique_name": "_tie_averaged_dcg", "qname": "sklearn.metrics._ranking._tie_averaged_dcg", + "unique_qname": "sklearn.metrics._ranking._tie_averaged_dcg", "decorators": [], "parameters": [ { @@ -116657,7 +120477,9 @@ }, { "name": "auc", + "unique_name": "auc", "qname": "sklearn.metrics._ranking.auc", + "unique_qname": "sklearn.metrics._ranking.auc", "decorators": [], "parameters": [ { @@ -116689,7 +120511,9 @@ }, { "name": "average_precision_score", + "unique_name": "average_precision_score", "qname": "sklearn.metrics._ranking.average_precision_score", + "unique_qname": "sklearn.metrics._ranking.average_precision_score", "decorators": [], "parameters": [ { @@ -116751,7 +120575,9 @@ }, { "name": "coverage_error", + "unique_name": "coverage_error", "qname": "sklearn.metrics._ranking.coverage_error", + "unique_qname": "sklearn.metrics._ranking.coverage_error", "decorators": [], "parameters": [ { @@ -116793,7 +120619,9 @@ }, { "name": "dcg_score", + "unique_name": "dcg_score", "qname": "sklearn.metrics._ranking.dcg_score", + "unique_qname": "sklearn.metrics._ranking.dcg_score", "decorators": [], "parameters": [ { @@ -116860,12 +120688,14 @@ "results": [], "is_public": true, "description": "Compute Discounted Cumulative Gain.\n\nSum the true scores ranked in the order induced by the predicted scores, after applying a logarithmic discount. This ranking metric yields a high value if true labels are ranked high by ``y_score``. Usually the Normalized Discounted Cumulative Gain (NDCG, computed by ndcg_score) is preferred.", - "docstring": "Compute Discounted Cumulative Gain.\n\nSum the true scores ranked in the order induced by the predicted scores,\nafter applying a logarithmic discount.\n\nThis ranking metric yields a high value if true labels are ranked high by\n``y_score``.\n\nUsually the Normalized Discounted Cumulative Gain (NDCG, computed by\nndcg_score) is preferred.\n\nParameters\n----------\ny_true : ndarray of shape (n_samples, n_labels)\n True targets of multilabel classification, or true scores of entities\n to be ranked.\n\ny_score : ndarray of shape (n_samples, n_labels)\n Target scores, can either be probability estimates, confidence values,\n or non-thresholded measure of decisions (as returned by\n \"decision_function\" on some classifiers).\n\nk : int, default=None\n Only consider the highest k scores in the ranking. If None, use all\n outputs.\n\nlog_base : float, default=2\n Base of the logarithm used for the discount. A low value means a\n sharper discount (top results are more important).\n\nsample_weight : ndarray of shape (n_samples,), default=None\n Sample weights. If `None`, all samples are given the same weight.\n\nignore_ties : bool, default=False\n Assume that there are no ties in y_score (which is likely to be the\n case if y_score is continuous) for efficiency gains.\n\nReturns\n-------\ndiscounted_cumulative_gain : float\n The averaged sample DCG scores.\n\nSee Also\n--------\nndcg_score : The Discounted Cumulative Gain divided by the Ideal Discounted\n Cumulative Gain (the DCG obtained for a perfect ranking), in order to\n have a score between 0 and 1.\n\nReferences\n----------\n`Wikipedia entry for Discounted Cumulative Gain\n`_.\n\nJarvelin, K., & Kekalainen, J. (2002).\nCumulated gain-based evaluation of IR techniques. ACM Transactions on\nInformation Systems (TOIS), 20(4), 422-446.\n\nWang, Y., Wang, L., Li, Y., He, D., Chen, W., & Liu, T. Y. (2013, May).\nA theoretical analysis of NDCG ranking measures. In Proceedings of the 26th\nAnnual Conference on Learning Theory (COLT 2013).\n\nMcSherry, F., & Najork, M. (2008, March). Computing information retrieval\nperformance measures efficiently in the presence of tied scores. In\nEuropean conference on information retrieval (pp. 414-421). Springer,\nBerlin, Heidelberg.\n\nExamples\n--------\n>>> from sklearn.metrics import dcg_score\n>>> # we have groud-truth relevance of some answers to a query:\n>>> true_relevance = np.asarray([[10, 0, 0, 1, 5]])\n>>> # we predict scores for the answers\n>>> scores = np.asarray([[.1, .2, .3, 4, 70]])\n>>> dcg_score(true_relevance, scores)\n9.49...\n>>> # we can set k to truncate the sum; only top k answers contribute\n>>> dcg_score(true_relevance, scores, k=2)\n5.63...\n>>> # now we have some ties in our prediction\n>>> scores = np.asarray([[1, 0, 0, 0, 1]])\n>>> # by default ties are averaged, so here we get the average true\n>>> # relevance of our top predictions: (10 + 5) / 2 = 7.5\n>>> dcg_score(true_relevance, scores, k=1)\n7.5\n>>> # we can choose to ignore ties for faster results, but only\n>>> # if we know there aren't ties in our scores, otherwise we get\n>>> # wrong results:\n>>> dcg_score(true_relevance,\n... scores, k=1, ignore_ties=True)\n5.0", - "source_code": "\ndef dcg_score(y_true, y_score, *, k=None, log_base=2, sample_weight=None, ignore_ties=False):\n \"\"\"Compute Discounted Cumulative Gain.\n\n Sum the true scores ranked in the order induced by the predicted scores,\n after applying a logarithmic discount.\n\n This ranking metric yields a high value if true labels are ranked high by\n ``y_score``.\n\n Usually the Normalized Discounted Cumulative Gain (NDCG, computed by\n ndcg_score) is preferred.\n\n Parameters\n ----------\n y_true : ndarray of shape (n_samples, n_labels)\n True targets of multilabel classification, or true scores of entities\n to be ranked.\n\n y_score : ndarray of shape (n_samples, n_labels)\n Target scores, can either be probability estimates, confidence values,\n or non-thresholded measure of decisions (as returned by\n \"decision_function\" on some classifiers).\n\n k : int, default=None\n Only consider the highest k scores in the ranking. If None, use all\n outputs.\n\n log_base : float, default=2\n Base of the logarithm used for the discount. A low value means a\n sharper discount (top results are more important).\n\n sample_weight : ndarray of shape (n_samples,), default=None\n Sample weights. If `None`, all samples are given the same weight.\n\n ignore_ties : bool, default=False\n Assume that there are no ties in y_score (which is likely to be the\n case if y_score is continuous) for efficiency gains.\n\n Returns\n -------\n discounted_cumulative_gain : float\n The averaged sample DCG scores.\n\n See Also\n --------\n ndcg_score : The Discounted Cumulative Gain divided by the Ideal Discounted\n Cumulative Gain (the DCG obtained for a perfect ranking), in order to\n have a score between 0 and 1.\n\n References\n ----------\n `Wikipedia entry for Discounted Cumulative Gain\n `_.\n\n Jarvelin, K., & Kekalainen, J. (2002).\n Cumulated gain-based evaluation of IR techniques. ACM Transactions on\n Information Systems (TOIS), 20(4), 422-446.\n\n Wang, Y., Wang, L., Li, Y., He, D., Chen, W., & Liu, T. Y. (2013, May).\n A theoretical analysis of NDCG ranking measures. In Proceedings of the 26th\n Annual Conference on Learning Theory (COLT 2013).\n\n McSherry, F., & Najork, M. (2008, March). Computing information retrieval\n performance measures efficiently in the presence of tied scores. In\n European conference on information retrieval (pp. 414-421). Springer,\n Berlin, Heidelberg.\n\n Examples\n --------\n >>> from sklearn.metrics import dcg_score\n >>> # we have groud-truth relevance of some answers to a query:\n >>> true_relevance = np.asarray([[10, 0, 0, 1, 5]])\n >>> # we predict scores for the answers\n >>> scores = np.asarray([[.1, .2, .3, 4, 70]])\n >>> dcg_score(true_relevance, scores)\n 9.49...\n >>> # we can set k to truncate the sum; only top k answers contribute\n >>> dcg_score(true_relevance, scores, k=2)\n 5.63...\n >>> # now we have some ties in our prediction\n >>> scores = np.asarray([[1, 0, 0, 0, 1]])\n >>> # by default ties are averaged, so here we get the average true\n >>> # relevance of our top predictions: (10 + 5) / 2 = 7.5\n >>> dcg_score(true_relevance, scores, k=1)\n 7.5\n >>> # we can choose to ignore ties for faster results, but only\n >>> # if we know there aren't ties in our scores, otherwise we get\n >>> # wrong results:\n >>> dcg_score(true_relevance,\n ... scores, k=1, ignore_ties=True)\n 5.0\n\n \"\"\"\n y_true = check_array(y_true, ensure_2d=False)\n y_score = check_array(y_score, ensure_2d=False)\n check_consistent_length(y_true, y_score, sample_weight)\n _check_dcg_target_type(y_true)\n return np.average(_dcg_sample_scores(y_true, y_score, k=k, log_base=log_base, ignore_ties=ignore_ties), weights=sample_weight)" + "docstring": "Compute Discounted Cumulative Gain.\n\nSum the true scores ranked in the order induced by the predicted scores,\nafter applying a logarithmic discount.\n\nThis ranking metric yields a high value if true labels are ranked high by\n``y_score``.\n\nUsually the Normalized Discounted Cumulative Gain (NDCG, computed by\nndcg_score) is preferred.\n\nParameters\n----------\ny_true : ndarray of shape (n_samples, n_labels)\n True targets of multilabel classification, or true scores of entities\n to be ranked.\n\ny_score : ndarray of shape (n_samples, n_labels)\n Target scores, can either be probability estimates, confidence values,\n or non-thresholded measure of decisions (as returned by\n \"decision_function\" on some classifiers).\n\nk : int, default=None\n Only consider the highest k scores in the ranking. If None, use all\n outputs.\n\nlog_base : float, default=2\n Base of the logarithm used for the discount. A low value means a\n sharper discount (top results are more important).\n\nsample_weight : ndarray of shape (n_samples,), default=None\n Sample weights. If `None`, all samples are given the same weight.\n\nignore_ties : bool, default=False\n Assume that there are no ties in y_score (which is likely to be the\n case if y_score is continuous) for efficiency gains.\n\nReturns\n-------\ndiscounted_cumulative_gain : float\n The averaged sample DCG scores.\n\nSee Also\n--------\nndcg_score : The Discounted Cumulative Gain divided by the Ideal Discounted\n Cumulative Gain (the DCG obtained for a perfect ranking), in order to\n have a score between 0 and 1.\n\nReferences\n----------\n`Wikipedia entry for Discounted Cumulative Gain\n`_.\n\nJarvelin, K., & Kekalainen, J. (2002).\nCumulated gain-based evaluation of IR techniques. ACM Transactions on\nInformation Systems (TOIS), 20(4), 422-446.\n\nWang, Y., Wang, L., Li, Y., He, D., Chen, W., & Liu, T. Y. (2013, May).\nA theoretical analysis of NDCG ranking measures. In Proceedings of the 26th\nAnnual Conference on Learning Theory (COLT 2013).\n\nMcSherry, F., & Najork, M. (2008, March). Computing information retrieval\nperformance measures efficiently in the presence of tied scores. In\nEuropean conference on information retrieval (pp. 414-421). Springer,\nBerlin, Heidelberg.\n\nExamples\n--------\n>>> import numpy as np\n>>> from sklearn.metrics import dcg_score\n>>> # we have groud-truth relevance of some answers to a query:\n>>> true_relevance = np.asarray([[10, 0, 0, 1, 5]])\n>>> # we predict scores for the answers\n>>> scores = np.asarray([[.1, .2, .3, 4, 70]])\n>>> dcg_score(true_relevance, scores)\n9.49...\n>>> # we can set k to truncate the sum; only top k answers contribute\n>>> dcg_score(true_relevance, scores, k=2)\n5.63...\n>>> # now we have some ties in our prediction\n>>> scores = np.asarray([[1, 0, 0, 0, 1]])\n>>> # by default ties are averaged, so here we get the average true\n>>> # relevance of our top predictions: (10 + 5) / 2 = 7.5\n>>> dcg_score(true_relevance, scores, k=1)\n7.5\n>>> # we can choose to ignore ties for faster results, but only\n>>> # if we know there aren't ties in our scores, otherwise we get\n>>> # wrong results:\n>>> dcg_score(true_relevance,\n... scores, k=1, ignore_ties=True)\n5.0", + "source_code": "\ndef dcg_score(y_true, y_score, *, k=None, log_base=2, sample_weight=None, ignore_ties=False):\n \"\"\"Compute Discounted Cumulative Gain.\n\n Sum the true scores ranked in the order induced by the predicted scores,\n after applying a logarithmic discount.\n\n This ranking metric yields a high value if true labels are ranked high by\n ``y_score``.\n\n Usually the Normalized Discounted Cumulative Gain (NDCG, computed by\n ndcg_score) is preferred.\n\n Parameters\n ----------\n y_true : ndarray of shape (n_samples, n_labels)\n True targets of multilabel classification, or true scores of entities\n to be ranked.\n\n y_score : ndarray of shape (n_samples, n_labels)\n Target scores, can either be probability estimates, confidence values,\n or non-thresholded measure of decisions (as returned by\n \"decision_function\" on some classifiers).\n\n k : int, default=None\n Only consider the highest k scores in the ranking. If None, use all\n outputs.\n\n log_base : float, default=2\n Base of the logarithm used for the discount. A low value means a\n sharper discount (top results are more important).\n\n sample_weight : ndarray of shape (n_samples,), default=None\n Sample weights. If `None`, all samples are given the same weight.\n\n ignore_ties : bool, default=False\n Assume that there are no ties in y_score (which is likely to be the\n case if y_score is continuous) for efficiency gains.\n\n Returns\n -------\n discounted_cumulative_gain : float\n The averaged sample DCG scores.\n\n See Also\n --------\n ndcg_score : The Discounted Cumulative Gain divided by the Ideal Discounted\n Cumulative Gain (the DCG obtained for a perfect ranking), in order to\n have a score between 0 and 1.\n\n References\n ----------\n `Wikipedia entry for Discounted Cumulative Gain\n `_.\n\n Jarvelin, K., & Kekalainen, J. (2002).\n Cumulated gain-based evaluation of IR techniques. ACM Transactions on\n Information Systems (TOIS), 20(4), 422-446.\n\n Wang, Y., Wang, L., Li, Y., He, D., Chen, W., & Liu, T. Y. (2013, May).\n A theoretical analysis of NDCG ranking measures. In Proceedings of the 26th\n Annual Conference on Learning Theory (COLT 2013).\n\n McSherry, F., & Najork, M. (2008, March). Computing information retrieval\n performance measures efficiently in the presence of tied scores. In\n European conference on information retrieval (pp. 414-421). Springer,\n Berlin, Heidelberg.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.metrics import dcg_score\n >>> # we have groud-truth relevance of some answers to a query:\n >>> true_relevance = np.asarray([[10, 0, 0, 1, 5]])\n >>> # we predict scores for the answers\n >>> scores = np.asarray([[.1, .2, .3, 4, 70]])\n >>> dcg_score(true_relevance, scores)\n 9.49...\n >>> # we can set k to truncate the sum; only top k answers contribute\n >>> dcg_score(true_relevance, scores, k=2)\n 5.63...\n >>> # now we have some ties in our prediction\n >>> scores = np.asarray([[1, 0, 0, 0, 1]])\n >>> # by default ties are averaged, so here we get the average true\n >>> # relevance of our top predictions: (10 + 5) / 2 = 7.5\n >>> dcg_score(true_relevance, scores, k=1)\n 7.5\n >>> # we can choose to ignore ties for faster results, but only\n >>> # if we know there aren't ties in our scores, otherwise we get\n >>> # wrong results:\n >>> dcg_score(true_relevance,\n ... scores, k=1, ignore_ties=True)\n 5.0\n\n \"\"\"\n y_true = check_array(y_true, ensure_2d=False)\n y_score = check_array(y_score, ensure_2d=False)\n check_consistent_length(y_true, y_score, sample_weight)\n _check_dcg_target_type(y_true)\n return np.average(_dcg_sample_scores(y_true, y_score, k=k, log_base=log_base, ignore_ties=ignore_ties), weights=sample_weight)" }, { "name": "det_curve", + "unique_name": "det_curve", "qname": "sklearn.metrics._ranking.det_curve", + "unique_qname": "sklearn.metrics._ranking.det_curve", "decorators": [], "parameters": [ { @@ -116917,7 +120747,9 @@ }, { "name": "label_ranking_average_precision_score", + "unique_name": "label_ranking_average_precision_score", "qname": "sklearn.metrics._ranking.label_ranking_average_precision_score", + "unique_qname": "sklearn.metrics._ranking.label_ranking_average_precision_score", "decorators": [], "parameters": [ { @@ -116959,7 +120791,9 @@ }, { "name": "label_ranking_loss", + "unique_name": "label_ranking_loss", "qname": "sklearn.metrics._ranking.label_ranking_loss", + "unique_qname": "sklearn.metrics._ranking.label_ranking_loss", "decorators": [], "parameters": [ { @@ -117001,7 +120835,9 @@ }, { "name": "ndcg_score", + "unique_name": "ndcg_score", "qname": "sklearn.metrics._ranking.ndcg_score", + "unique_qname": "sklearn.metrics._ranking.ndcg_score", "decorators": [], "parameters": [ { @@ -117058,12 +120894,14 @@ "results": [], "is_public": true, "description": "Compute Normalized Discounted Cumulative Gain.\n\nSum the true scores ranked in the order induced by the predicted scores, after applying a logarithmic discount. Then divide by the best possible score (Ideal DCG, obtained for a perfect ranking) to obtain a score between 0 and 1. This ranking metric yields a high value if true labels are ranked high by ``y_score``.", - "docstring": "Compute Normalized Discounted Cumulative Gain.\n\nSum the true scores ranked in the order induced by the predicted scores,\nafter applying a logarithmic discount. Then divide by the best possible\nscore (Ideal DCG, obtained for a perfect ranking) to obtain a score between\n0 and 1.\n\nThis ranking metric yields a high value if true labels are ranked high by\n``y_score``.\n\nParameters\n----------\ny_true : ndarray of shape (n_samples, n_labels)\n True targets of multilabel classification, or true scores of entities\n to be ranked.\n\ny_score : ndarray of shape (n_samples, n_labels)\n Target scores, can either be probability estimates, confidence values,\n or non-thresholded measure of decisions (as returned by\n \"decision_function\" on some classifiers).\n\nk : int, default=None\n Only consider the highest k scores in the ranking. If `None`, use all\n outputs.\n\nsample_weight : ndarray of shape (n_samples,), default=None\n Sample weights. If `None`, all samples are given the same weight.\n\nignore_ties : bool, default=False\n Assume that there are no ties in y_score (which is likely to be the\n case if y_score is continuous) for efficiency gains.\n\nReturns\n-------\nnormalized_discounted_cumulative_gain : float in [0., 1.]\n The averaged NDCG scores for all samples.\n\nSee Also\n--------\ndcg_score : Discounted Cumulative Gain (not normalized).\n\nReferences\n----------\n`Wikipedia entry for Discounted Cumulative Gain\n`_\n\nJarvelin, K., & Kekalainen, J. (2002).\nCumulated gain-based evaluation of IR techniques. ACM Transactions on\nInformation Systems (TOIS), 20(4), 422-446.\n\nWang, Y., Wang, L., Li, Y., He, D., Chen, W., & Liu, T. Y. (2013, May).\nA theoretical analysis of NDCG ranking measures. In Proceedings of the 26th\nAnnual Conference on Learning Theory (COLT 2013)\n\nMcSherry, F., & Najork, M. (2008, March). Computing information retrieval\nperformance measures efficiently in the presence of tied scores. In\nEuropean conference on information retrieval (pp. 414-421). Springer,\nBerlin, Heidelberg.\n\nExamples\n--------\n>>> from sklearn.metrics import ndcg_score\n>>> # we have groud-truth relevance of some answers to a query:\n>>> true_relevance = np.asarray([[10, 0, 0, 1, 5]])\n>>> # we predict some scores (relevance) for the answers\n>>> scores = np.asarray([[.1, .2, .3, 4, 70]])\n>>> ndcg_score(true_relevance, scores)\n0.69...\n>>> scores = np.asarray([[.05, 1.1, 1., .5, .0]])\n>>> ndcg_score(true_relevance, scores)\n0.49...\n>>> # we can set k to truncate the sum; only top k answers contribute.\n>>> ndcg_score(true_relevance, scores, k=4)\n0.35...\n>>> # the normalization takes k into account so a perfect answer\n>>> # would still get 1.0\n>>> ndcg_score(true_relevance, true_relevance, k=4)\n1.0\n>>> # now we have some ties in our prediction\n>>> scores = np.asarray([[1, 0, 0, 0, 1]])\n>>> # by default ties are averaged, so here we get the average (normalized)\n>>> # true relevance of our top predictions: (10 / 10 + 5 / 10) / 2 = .75\n>>> ndcg_score(true_relevance, scores, k=1)\n0.75\n>>> # we can choose to ignore ties for faster results, but only\n>>> # if we know there aren't ties in our scores, otherwise we get\n>>> # wrong results:\n>>> ndcg_score(true_relevance,\n... scores, k=1, ignore_ties=True)\n0.5", - "source_code": "\ndef ndcg_score(y_true, y_score, *, k=None, sample_weight=None, ignore_ties=False):\n \"\"\"Compute Normalized Discounted Cumulative Gain.\n\n Sum the true scores ranked in the order induced by the predicted scores,\n after applying a logarithmic discount. Then divide by the best possible\n score (Ideal DCG, obtained for a perfect ranking) to obtain a score between\n 0 and 1.\n\n This ranking metric yields a high value if true labels are ranked high by\n ``y_score``.\n\n Parameters\n ----------\n y_true : ndarray of shape (n_samples, n_labels)\n True targets of multilabel classification, or true scores of entities\n to be ranked.\n\n y_score : ndarray of shape (n_samples, n_labels)\n Target scores, can either be probability estimates, confidence values,\n or non-thresholded measure of decisions (as returned by\n \"decision_function\" on some classifiers).\n\n k : int, default=None\n Only consider the highest k scores in the ranking. If `None`, use all\n outputs.\n\n sample_weight : ndarray of shape (n_samples,), default=None\n Sample weights. If `None`, all samples are given the same weight.\n\n ignore_ties : bool, default=False\n Assume that there are no ties in y_score (which is likely to be the\n case if y_score is continuous) for efficiency gains.\n\n Returns\n -------\n normalized_discounted_cumulative_gain : float in [0., 1.]\n The averaged NDCG scores for all samples.\n\n See Also\n --------\n dcg_score : Discounted Cumulative Gain (not normalized).\n\n References\n ----------\n `Wikipedia entry for Discounted Cumulative Gain\n `_\n\n Jarvelin, K., & Kekalainen, J. (2002).\n Cumulated gain-based evaluation of IR techniques. ACM Transactions on\n Information Systems (TOIS), 20(4), 422-446.\n\n Wang, Y., Wang, L., Li, Y., He, D., Chen, W., & Liu, T. Y. (2013, May).\n A theoretical analysis of NDCG ranking measures. In Proceedings of the 26th\n Annual Conference on Learning Theory (COLT 2013)\n\n McSherry, F., & Najork, M. (2008, March). Computing information retrieval\n performance measures efficiently in the presence of tied scores. In\n European conference on information retrieval (pp. 414-421). Springer,\n Berlin, Heidelberg.\n\n Examples\n --------\n >>> from sklearn.metrics import ndcg_score\n >>> # we have groud-truth relevance of some answers to a query:\n >>> true_relevance = np.asarray([[10, 0, 0, 1, 5]])\n >>> # we predict some scores (relevance) for the answers\n >>> scores = np.asarray([[.1, .2, .3, 4, 70]])\n >>> ndcg_score(true_relevance, scores)\n 0.69...\n >>> scores = np.asarray([[.05, 1.1, 1., .5, .0]])\n >>> ndcg_score(true_relevance, scores)\n 0.49...\n >>> # we can set k to truncate the sum; only top k answers contribute.\n >>> ndcg_score(true_relevance, scores, k=4)\n 0.35...\n >>> # the normalization takes k into account so a perfect answer\n >>> # would still get 1.0\n >>> ndcg_score(true_relevance, true_relevance, k=4)\n 1.0\n >>> # now we have some ties in our prediction\n >>> scores = np.asarray([[1, 0, 0, 0, 1]])\n >>> # by default ties are averaged, so here we get the average (normalized)\n >>> # true relevance of our top predictions: (10 / 10 + 5 / 10) / 2 = .75\n >>> ndcg_score(true_relevance, scores, k=1)\n 0.75\n >>> # we can choose to ignore ties for faster results, but only\n >>> # if we know there aren't ties in our scores, otherwise we get\n >>> # wrong results:\n >>> ndcg_score(true_relevance,\n ... scores, k=1, ignore_ties=True)\n 0.5\n\n \"\"\"\n y_true = check_array(y_true, ensure_2d=False)\n y_score = check_array(y_score, ensure_2d=False)\n check_consistent_length(y_true, y_score, sample_weight)\n _check_dcg_target_type(y_true)\n gain = _ndcg_sample_scores(y_true, y_score, k=k, ignore_ties=ignore_ties)\n return np.average(gain, weights=sample_weight)" + "docstring": "Compute Normalized Discounted Cumulative Gain.\n\nSum the true scores ranked in the order induced by the predicted scores,\nafter applying a logarithmic discount. Then divide by the best possible\nscore (Ideal DCG, obtained for a perfect ranking) to obtain a score between\n0 and 1.\n\nThis ranking metric yields a high value if true labels are ranked high by\n``y_score``.\n\nParameters\n----------\ny_true : ndarray of shape (n_samples, n_labels)\n True targets of multilabel classification, or true scores of entities\n to be ranked.\n\ny_score : ndarray of shape (n_samples, n_labels)\n Target scores, can either be probability estimates, confidence values,\n or non-thresholded measure of decisions (as returned by\n \"decision_function\" on some classifiers).\n\nk : int, default=None\n Only consider the highest k scores in the ranking. If `None`, use all\n outputs.\n\nsample_weight : ndarray of shape (n_samples,), default=None\n Sample weights. If `None`, all samples are given the same weight.\n\nignore_ties : bool, default=False\n Assume that there are no ties in y_score (which is likely to be the\n case if y_score is continuous) for efficiency gains.\n\nReturns\n-------\nnormalized_discounted_cumulative_gain : float in [0., 1.]\n The averaged NDCG scores for all samples.\n\nSee Also\n--------\ndcg_score : Discounted Cumulative Gain (not normalized).\n\nReferences\n----------\n`Wikipedia entry for Discounted Cumulative Gain\n`_\n\nJarvelin, K., & Kekalainen, J. (2002).\nCumulated gain-based evaluation of IR techniques. ACM Transactions on\nInformation Systems (TOIS), 20(4), 422-446.\n\nWang, Y., Wang, L., Li, Y., He, D., Chen, W., & Liu, T. Y. (2013, May).\nA theoretical analysis of NDCG ranking measures. In Proceedings of the 26th\nAnnual Conference on Learning Theory (COLT 2013)\n\nMcSherry, F., & Najork, M. (2008, March). Computing information retrieval\nperformance measures efficiently in the presence of tied scores. In\nEuropean conference on information retrieval (pp. 414-421). Springer,\nBerlin, Heidelberg.\n\nExamples\n--------\n>>> import numpy as np\n>>> from sklearn.metrics import ndcg_score\n>>> # we have groud-truth relevance of some answers to a query:\n>>> true_relevance = np.asarray([[10, 0, 0, 1, 5]])\n>>> # we predict some scores (relevance) for the answers\n>>> scores = np.asarray([[.1, .2, .3, 4, 70]])\n>>> ndcg_score(true_relevance, scores)\n0.69...\n>>> scores = np.asarray([[.05, 1.1, 1., .5, .0]])\n>>> ndcg_score(true_relevance, scores)\n0.49...\n>>> # we can set k to truncate the sum; only top k answers contribute.\n>>> ndcg_score(true_relevance, scores, k=4)\n0.35...\n>>> # the normalization takes k into account so a perfect answer\n>>> # would still get 1.0\n>>> ndcg_score(true_relevance, true_relevance, k=4)\n1.0\n>>> # now we have some ties in our prediction\n>>> scores = np.asarray([[1, 0, 0, 0, 1]])\n>>> # by default ties are averaged, so here we get the average (normalized)\n>>> # true relevance of our top predictions: (10 / 10 + 5 / 10) / 2 = .75\n>>> ndcg_score(true_relevance, scores, k=1)\n0.75\n>>> # we can choose to ignore ties for faster results, but only\n>>> # if we know there aren't ties in our scores, otherwise we get\n>>> # wrong results:\n>>> ndcg_score(true_relevance,\n... scores, k=1, ignore_ties=True)\n0.5", + "source_code": "\ndef ndcg_score(y_true, y_score, *, k=None, sample_weight=None, ignore_ties=False):\n \"\"\"Compute Normalized Discounted Cumulative Gain.\n\n Sum the true scores ranked in the order induced by the predicted scores,\n after applying a logarithmic discount. Then divide by the best possible\n score (Ideal DCG, obtained for a perfect ranking) to obtain a score between\n 0 and 1.\n\n This ranking metric yields a high value if true labels are ranked high by\n ``y_score``.\n\n Parameters\n ----------\n y_true : ndarray of shape (n_samples, n_labels)\n True targets of multilabel classification, or true scores of entities\n to be ranked.\n\n y_score : ndarray of shape (n_samples, n_labels)\n Target scores, can either be probability estimates, confidence values,\n or non-thresholded measure of decisions (as returned by\n \"decision_function\" on some classifiers).\n\n k : int, default=None\n Only consider the highest k scores in the ranking. If `None`, use all\n outputs.\n\n sample_weight : ndarray of shape (n_samples,), default=None\n Sample weights. If `None`, all samples are given the same weight.\n\n ignore_ties : bool, default=False\n Assume that there are no ties in y_score (which is likely to be the\n case if y_score is continuous) for efficiency gains.\n\n Returns\n -------\n normalized_discounted_cumulative_gain : float in [0., 1.]\n The averaged NDCG scores for all samples.\n\n See Also\n --------\n dcg_score : Discounted Cumulative Gain (not normalized).\n\n References\n ----------\n `Wikipedia entry for Discounted Cumulative Gain\n `_\n\n Jarvelin, K., & Kekalainen, J. (2002).\n Cumulated gain-based evaluation of IR techniques. ACM Transactions on\n Information Systems (TOIS), 20(4), 422-446.\n\n Wang, Y., Wang, L., Li, Y., He, D., Chen, W., & Liu, T. Y. (2013, May).\n A theoretical analysis of NDCG ranking measures. In Proceedings of the 26th\n Annual Conference on Learning Theory (COLT 2013)\n\n McSherry, F., & Najork, M. (2008, March). Computing information retrieval\n performance measures efficiently in the presence of tied scores. In\n European conference on information retrieval (pp. 414-421). Springer,\n Berlin, Heidelberg.\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.metrics import ndcg_score\n >>> # we have groud-truth relevance of some answers to a query:\n >>> true_relevance = np.asarray([[10, 0, 0, 1, 5]])\n >>> # we predict some scores (relevance) for the answers\n >>> scores = np.asarray([[.1, .2, .3, 4, 70]])\n >>> ndcg_score(true_relevance, scores)\n 0.69...\n >>> scores = np.asarray([[.05, 1.1, 1., .5, .0]])\n >>> ndcg_score(true_relevance, scores)\n 0.49...\n >>> # we can set k to truncate the sum; only top k answers contribute.\n >>> ndcg_score(true_relevance, scores, k=4)\n 0.35...\n >>> # the normalization takes k into account so a perfect answer\n >>> # would still get 1.0\n >>> ndcg_score(true_relevance, true_relevance, k=4)\n 1.0\n >>> # now we have some ties in our prediction\n >>> scores = np.asarray([[1, 0, 0, 0, 1]])\n >>> # by default ties are averaged, so here we get the average (normalized)\n >>> # true relevance of our top predictions: (10 / 10 + 5 / 10) / 2 = .75\n >>> ndcg_score(true_relevance, scores, k=1)\n 0.75\n >>> # we can choose to ignore ties for faster results, but only\n >>> # if we know there aren't ties in our scores, otherwise we get\n >>> # wrong results:\n >>> ndcg_score(true_relevance,\n ... scores, k=1, ignore_ties=True)\n 0.5\n\n \"\"\"\n y_true = check_array(y_true, ensure_2d=False)\n y_score = check_array(y_score, ensure_2d=False)\n check_consistent_length(y_true, y_score, sample_weight)\n _check_dcg_target_type(y_true)\n gain = _ndcg_sample_scores(y_true, y_score, k=k, ignore_ties=ignore_ties)\n return np.average(gain, weights=sample_weight)" }, { "name": "precision_recall_curve", + "unique_name": "precision_recall_curve", "qname": "sklearn.metrics._ranking.precision_recall_curve", + "unique_qname": "sklearn.metrics._ranking.precision_recall_curve", "decorators": [], "parameters": [ { @@ -117115,7 +120953,9 @@ }, { "name": "roc_auc_score", + "unique_name": "roc_auc_score", "qname": "sklearn.metrics._ranking.roc_auc_score", + "unique_qname": "sklearn.metrics._ranking.roc_auc_score", "decorators": [], "parameters": [ { @@ -117192,12 +121032,14 @@ "results": [], "is_public": true, "description": "Compute Area Under the Receiver Operating Characteristic Curve (ROC AUC) from prediction scores.\n\nNote: this implementation can be used with binary, multiclass and multilabel classification, but some restrictions apply (see Parameters). Read more in the :ref:`User Guide `.", - "docstring": "Compute Area Under the Receiver Operating Characteristic Curve (ROC AUC)\nfrom prediction scores.\n\nNote: this implementation can be used with binary, multiclass and\nmultilabel classification, but some restrictions apply (see Parameters).\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\ny_true : array-like of shape (n_samples,) or (n_samples, n_classes)\n True labels or binary label indicators. The binary and multiclass cases\n expect labels with shape (n_samples,) while the multilabel case expects\n binary label indicators with shape (n_samples, n_classes).\n\ny_score : array-like of shape (n_samples,) or (n_samples, n_classes)\n Target scores.\n\n * In the binary case, it corresponds to an array of shape\n `(n_samples,)`. Both probability estimates and non-thresholded\n decision values can be provided. The probability estimates correspond\n to the **probability of the class with the greater label**,\n i.e. `estimator.classes_[1]` and thus\n `estimator.predict_proba(X, y)[:, 1]`. The decision values\n corresponds to the output of `estimator.decision_function(X, y)`.\n See more information in the :ref:`User guide `;\n * In the multiclass case, it corresponds to an array of shape\n `(n_samples, n_classes)` of probability estimates provided by the\n `predict_proba` method. The probability estimates **must**\n sum to 1 across the possible classes. In addition, the order of the\n class scores must correspond to the order of ``labels``,\n if provided, or else to the numerical or lexicographical order of\n the labels in ``y_true``. See more information in the\n :ref:`User guide `;\n * In the multilabel case, it corresponds to an array of shape\n `(n_samples, n_classes)`. Probability estimates are provided by the\n `predict_proba` method and the non-thresholded decision values by\n the `decision_function` method. The probability estimates correspond\n to the **probability of the class with the greater label for each\n output** of the classifier. See more information in the\n :ref:`User guide `.\n\naverage : {'micro', 'macro', 'samples', 'weighted'} or None, default='macro'\n If ``None``, the scores for each class are returned. Otherwise,\n this determines the type of averaging performed on the data:\n Note: multiclass ROC AUC currently only handles the 'macro' and\n 'weighted' averages.\n\n ``'micro'``:\n Calculate metrics globally by considering each element of the label\n indicator matrix as a label.\n ``'macro'``:\n Calculate metrics for each label, and find their unweighted\n mean. This does not take label imbalance into account.\n ``'weighted'``:\n Calculate metrics for each label, and find their average, weighted\n by support (the number of true instances for each label).\n ``'samples'``:\n Calculate metrics for each instance, and find their average.\n\n Will be ignored when ``y_true`` is binary.\n\nsample_weight : array-like of shape (n_samples,), default=None\n Sample weights.\n\nmax_fpr : float > 0 and <= 1, default=None\n If not ``None``, the standardized partial AUC [2]_ over the range\n [0, max_fpr] is returned. For the multiclass case, ``max_fpr``,\n should be either equal to ``None`` or ``1.0`` as AUC ROC partial\n computation currently is not supported for multiclass.\n\nmulti_class : {'raise', 'ovr', 'ovo'}, default='raise'\n Only used for multiclass targets. Determines the type of configuration\n to use. The default value raises an error, so either\n ``'ovr'`` or ``'ovo'`` must be passed explicitly.\n\n ``'ovr'``:\n Stands for One-vs-rest. Computes the AUC of each class\n against the rest [3]_ [4]_. This\n treats the multiclass case in the same way as the multilabel case.\n Sensitive to class imbalance even when ``average == 'macro'``,\n because class imbalance affects the composition of each of the\n 'rest' groupings.\n ``'ovo'``:\n Stands for One-vs-one. Computes the average AUC of all\n possible pairwise combinations of classes [5]_.\n Insensitive to class imbalance when\n ``average == 'macro'``.\n\nlabels : array-like of shape (n_classes,), default=None\n Only used for multiclass targets. List of labels that index the\n classes in ``y_score``. If ``None``, the numerical or lexicographical\n order of the labels in ``y_true`` is used.\n\nReturns\n-------\nauc : float\n\nReferences\n----------\n.. [1] `Wikipedia entry for the Receiver operating characteristic\n `_\n\n.. [2] `Analyzing a portion of the ROC curve. McClish, 1989\n `_\n\n.. [3] Provost, F., Domingos, P. (2000). Well-trained PETs: Improving\n probability estimation trees (Section 6.2), CeDER Working Paper\n #IS-00-04, Stern School of Business, New York University.\n\n.. [4] `Fawcett, T. (2006). An introduction to ROC analysis. Pattern\n Recognition Letters, 27(8), 861-874.\n `_\n\n.. [5] `Hand, D.J., Till, R.J. (2001). A Simple Generalisation of the Area\n Under the ROC Curve for Multiple Class Classification Problems.\n Machine Learning, 45(2), 171-186.\n `_\n\nSee Also\n--------\naverage_precision_score : Area under the precision-recall curve.\nroc_curve : Compute Receiver operating characteristic (ROC) curve.\nRocCurveDisplay.from_estimator : Plot Receiver Operating Characteristic\n (ROC) curve given an estimator and some data.\nRocCurveDisplay.from_predictions : Plot Receiver Operating Characteristic\n (ROC) curve given the true and predicted values.\n\nExamples\n--------\nBinary case:\n\n>>> from sklearn.datasets import load_breast_cancer\n>>> from sklearn.linear_model import LogisticRegression\n>>> from sklearn.metrics import roc_auc_score\n>>> X, y = load_breast_cancer(return_X_y=True)\n>>> clf = LogisticRegression(solver=\"liblinear\", random_state=0).fit(X, y)\n>>> roc_auc_score(y, clf.predict_proba(X)[:, 1])\n0.99...\n>>> roc_auc_score(y, clf.decision_function(X))\n0.99...\n\nMulticlass case:\n\n>>> from sklearn.datasets import load_iris\n>>> X, y = load_iris(return_X_y=True)\n>>> clf = LogisticRegression(solver=\"liblinear\").fit(X, y)\n>>> roc_auc_score(y, clf.predict_proba(X), multi_class='ovr')\n0.99...\n\nMultilabel case:\n\n>>> from sklearn.datasets import make_multilabel_classification\n>>> from sklearn.multioutput import MultiOutputClassifier\n>>> X, y = make_multilabel_classification(random_state=0)\n>>> clf = MultiOutputClassifier(clf).fit(X, y)\n>>> # get a list of n_output containing probability arrays of shape\n>>> # (n_samples, n_classes)\n>>> y_pred = clf.predict_proba(X)\n>>> # extract the positive columns for each output\n>>> y_pred = np.transpose([pred[:, 1] for pred in y_pred])\n>>> roc_auc_score(y, y_pred, average=None)\narray([0.82..., 0.86..., 0.94..., 0.85... , 0.94...])\n>>> from sklearn.linear_model import RidgeClassifierCV\n>>> clf = RidgeClassifierCV().fit(X, y)\n>>> roc_auc_score(y, clf.decision_function(X), average=None)\narray([0.81..., 0.84... , 0.93..., 0.87..., 0.94...])", - "source_code": "\ndef roc_auc_score(y_true, y_score, *, average='macro', sample_weight=None, max_fpr=None, multi_class='raise', labels=None):\n \"\"\"Compute Area Under the Receiver Operating Characteristic Curve (ROC AUC)\n from prediction scores.\n\n Note: this implementation can be used with binary, multiclass and\n multilabel classification, but some restrictions apply (see Parameters).\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n y_true : array-like of shape (n_samples,) or (n_samples, n_classes)\n True labels or binary label indicators. The binary and multiclass cases\n expect labels with shape (n_samples,) while the multilabel case expects\n binary label indicators with shape (n_samples, n_classes).\n\n y_score : array-like of shape (n_samples,) or (n_samples, n_classes)\n Target scores.\n\n * In the binary case, it corresponds to an array of shape\n `(n_samples,)`. Both probability estimates and non-thresholded\n decision values can be provided. The probability estimates correspond\n to the **probability of the class with the greater label**,\n i.e. `estimator.classes_[1]` and thus\n `estimator.predict_proba(X, y)[:, 1]`. The decision values\n corresponds to the output of `estimator.decision_function(X, y)`.\n See more information in the :ref:`User guide `;\n * In the multiclass case, it corresponds to an array of shape\n `(n_samples, n_classes)` of probability estimates provided by the\n `predict_proba` method. The probability estimates **must**\n sum to 1 across the possible classes. In addition, the order of the\n class scores must correspond to the order of ``labels``,\n if provided, or else to the numerical or lexicographical order of\n the labels in ``y_true``. See more information in the\n :ref:`User guide `;\n * In the multilabel case, it corresponds to an array of shape\n `(n_samples, n_classes)`. Probability estimates are provided by the\n `predict_proba` method and the non-thresholded decision values by\n the `decision_function` method. The probability estimates correspond\n to the **probability of the class with the greater label for each\n output** of the classifier. See more information in the\n :ref:`User guide `.\n\n average : {'micro', 'macro', 'samples', 'weighted'} or None, default='macro'\n If ``None``, the scores for each class are returned. Otherwise,\n this determines the type of averaging performed on the data:\n Note: multiclass ROC AUC currently only handles the 'macro' and\n 'weighted' averages.\n\n ``'micro'``:\n Calculate metrics globally by considering each element of the label\n indicator matrix as a label.\n ``'macro'``:\n Calculate metrics for each label, and find their unweighted\n mean. This does not take label imbalance into account.\n ``'weighted'``:\n Calculate metrics for each label, and find their average, weighted\n by support (the number of true instances for each label).\n ``'samples'``:\n Calculate metrics for each instance, and find their average.\n\n Will be ignored when ``y_true`` is binary.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights.\n\n max_fpr : float > 0 and <= 1, default=None\n If not ``None``, the standardized partial AUC [2]_ over the range\n [0, max_fpr] is returned. For the multiclass case, ``max_fpr``,\n should be either equal to ``None`` or ``1.0`` as AUC ROC partial\n computation currently is not supported for multiclass.\n\n multi_class : {'raise', 'ovr', 'ovo'}, default='raise'\n Only used for multiclass targets. Determines the type of configuration\n to use. The default value raises an error, so either\n ``'ovr'`` or ``'ovo'`` must be passed explicitly.\n\n ``'ovr'``:\n Stands for One-vs-rest. Computes the AUC of each class\n against the rest [3]_ [4]_. This\n treats the multiclass case in the same way as the multilabel case.\n Sensitive to class imbalance even when ``average == 'macro'``,\n because class imbalance affects the composition of each of the\n 'rest' groupings.\n ``'ovo'``:\n Stands for One-vs-one. Computes the average AUC of all\n possible pairwise combinations of classes [5]_.\n Insensitive to class imbalance when\n ``average == 'macro'``.\n\n labels : array-like of shape (n_classes,), default=None\n Only used for multiclass targets. List of labels that index the\n classes in ``y_score``. If ``None``, the numerical or lexicographical\n order of the labels in ``y_true`` is used.\n\n Returns\n -------\n auc : float\n\n References\n ----------\n .. [1] `Wikipedia entry for the Receiver operating characteristic\n `_\n\n .. [2] `Analyzing a portion of the ROC curve. McClish, 1989\n `_\n\n .. [3] Provost, F., Domingos, P. (2000). Well-trained PETs: Improving\n probability estimation trees (Section 6.2), CeDER Working Paper\n #IS-00-04, Stern School of Business, New York University.\n\n .. [4] `Fawcett, T. (2006). An introduction to ROC analysis. Pattern\n Recognition Letters, 27(8), 861-874.\n `_\n\n .. [5] `Hand, D.J., Till, R.J. (2001). A Simple Generalisation of the Area\n Under the ROC Curve for Multiple Class Classification Problems.\n Machine Learning, 45(2), 171-186.\n `_\n\n See Also\n --------\n average_precision_score : Area under the precision-recall curve.\n roc_curve : Compute Receiver operating characteristic (ROC) curve.\n RocCurveDisplay.from_estimator : Plot Receiver Operating Characteristic\n (ROC) curve given an estimator and some data.\n RocCurveDisplay.from_predictions : Plot Receiver Operating Characteristic\n (ROC) curve given the true and predicted values.\n\n Examples\n --------\n Binary case:\n\n >>> from sklearn.datasets import load_breast_cancer\n >>> from sklearn.linear_model import LogisticRegression\n >>> from sklearn.metrics import roc_auc_score\n >>> X, y = load_breast_cancer(return_X_y=True)\n >>> clf = LogisticRegression(solver=\"liblinear\", random_state=0).fit(X, y)\n >>> roc_auc_score(y, clf.predict_proba(X)[:, 1])\n 0.99...\n >>> roc_auc_score(y, clf.decision_function(X))\n 0.99...\n\n Multiclass case:\n\n >>> from sklearn.datasets import load_iris\n >>> X, y = load_iris(return_X_y=True)\n >>> clf = LogisticRegression(solver=\"liblinear\").fit(X, y)\n >>> roc_auc_score(y, clf.predict_proba(X), multi_class='ovr')\n 0.99...\n\n Multilabel case:\n\n >>> from sklearn.datasets import make_multilabel_classification\n >>> from sklearn.multioutput import MultiOutputClassifier\n >>> X, y = make_multilabel_classification(random_state=0)\n >>> clf = MultiOutputClassifier(clf).fit(X, y)\n >>> # get a list of n_output containing probability arrays of shape\n >>> # (n_samples, n_classes)\n >>> y_pred = clf.predict_proba(X)\n >>> # extract the positive columns for each output\n >>> y_pred = np.transpose([pred[:, 1] for pred in y_pred])\n >>> roc_auc_score(y, y_pred, average=None)\n array([0.82..., 0.86..., 0.94..., 0.85... , 0.94...])\n >>> from sklearn.linear_model import RidgeClassifierCV\n >>> clf = RidgeClassifierCV().fit(X, y)\n >>> roc_auc_score(y, clf.decision_function(X), average=None)\n array([0.81..., 0.84... , 0.93..., 0.87..., 0.94...])\n \"\"\"\n y_type = type_of_target(y_true)\n y_true = check_array(y_true, ensure_2d=False, dtype=None)\n y_score = check_array(y_score, ensure_2d=False)\n if y_type == 'multiclass' or y_type == 'binary' and y_score.ndim == 2 and y_score.shape[1] > 2:\n if max_fpr is not None and max_fpr != 1.0:\n raise ValueError(\"Partial AUC computation not available in multiclass setting, 'max_fpr' must be set to `None`, received `max_fpr={0}` instead\".format(max_fpr))\n if multi_class == 'raise':\n raise ValueError(\"multi_class must be in ('ovo', 'ovr')\")\n return _multiclass_roc_auc_score(y_true, y_score, labels, multi_class, average, sample_weight)\n elif y_type == 'binary':\n labels = np.unique(y_true)\n y_true = label_binarize(y_true, classes=labels)[:, 0]\n return _average_binary_score(partial(_binary_roc_auc_score, max_fpr=max_fpr), y_true, y_score, average, sample_weight=sample_weight)\n else:\n return _average_binary_score(partial(_binary_roc_auc_score, max_fpr=max_fpr), y_true, y_score, average, sample_weight=sample_weight)" + "docstring": "Compute Area Under the Receiver Operating Characteristic Curve (ROC AUC)\nfrom prediction scores.\n\nNote: this implementation can be used with binary, multiclass and\nmultilabel classification, but some restrictions apply (see Parameters).\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\ny_true : array-like of shape (n_samples,) or (n_samples, n_classes)\n True labels or binary label indicators. The binary and multiclass cases\n expect labels with shape (n_samples,) while the multilabel case expects\n binary label indicators with shape (n_samples, n_classes).\n\ny_score : array-like of shape (n_samples,) or (n_samples, n_classes)\n Target scores.\n\n * In the binary case, it corresponds to an array of shape\n `(n_samples,)`. Both probability estimates and non-thresholded\n decision values can be provided. The probability estimates correspond\n to the **probability of the class with the greater label**,\n i.e. `estimator.classes_[1]` and thus\n `estimator.predict_proba(X, y)[:, 1]`. The decision values\n corresponds to the output of `estimator.decision_function(X, y)`.\n See more information in the :ref:`User guide `;\n * In the multiclass case, it corresponds to an array of shape\n `(n_samples, n_classes)` of probability estimates provided by the\n `predict_proba` method. The probability estimates **must**\n sum to 1 across the possible classes. In addition, the order of the\n class scores must correspond to the order of ``labels``,\n if provided, or else to the numerical or lexicographical order of\n the labels in ``y_true``. See more information in the\n :ref:`User guide `;\n * In the multilabel case, it corresponds to an array of shape\n `(n_samples, n_classes)`. Probability estimates are provided by the\n `predict_proba` method and the non-thresholded decision values by\n the `decision_function` method. The probability estimates correspond\n to the **probability of the class with the greater label for each\n output** of the classifier. See more information in the\n :ref:`User guide `.\n\naverage : {'micro', 'macro', 'samples', 'weighted'} or None, default='macro'\n If ``None``, the scores for each class are returned. Otherwise,\n this determines the type of averaging performed on the data:\n Note: multiclass ROC AUC currently only handles the 'macro' and\n 'weighted' averages.\n\n ``'micro'``:\n Calculate metrics globally by considering each element of the label\n indicator matrix as a label.\n ``'macro'``:\n Calculate metrics for each label, and find their unweighted\n mean. This does not take label imbalance into account.\n ``'weighted'``:\n Calculate metrics for each label, and find their average, weighted\n by support (the number of true instances for each label).\n ``'samples'``:\n Calculate metrics for each instance, and find their average.\n\n Will be ignored when ``y_true`` is binary.\n\nsample_weight : array-like of shape (n_samples,), default=None\n Sample weights.\n\nmax_fpr : float > 0 and <= 1, default=None\n If not ``None``, the standardized partial AUC [2]_ over the range\n [0, max_fpr] is returned. For the multiclass case, ``max_fpr``,\n should be either equal to ``None`` or ``1.0`` as AUC ROC partial\n computation currently is not supported for multiclass.\n\nmulti_class : {'raise', 'ovr', 'ovo'}, default='raise'\n Only used for multiclass targets. Determines the type of configuration\n to use. The default value raises an error, so either\n ``'ovr'`` or ``'ovo'`` must be passed explicitly.\n\n ``'ovr'``:\n Stands for One-vs-rest. Computes the AUC of each class\n against the rest [3]_ [4]_. This\n treats the multiclass case in the same way as the multilabel case.\n Sensitive to class imbalance even when ``average == 'macro'``,\n because class imbalance affects the composition of each of the\n 'rest' groupings.\n ``'ovo'``:\n Stands for One-vs-one. Computes the average AUC of all\n possible pairwise combinations of classes [5]_.\n Insensitive to class imbalance when\n ``average == 'macro'``.\n\nlabels : array-like of shape (n_classes,), default=None\n Only used for multiclass targets. List of labels that index the\n classes in ``y_score``. If ``None``, the numerical or lexicographical\n order of the labels in ``y_true`` is used.\n\nReturns\n-------\nauc : float\n\nReferences\n----------\n.. [1] `Wikipedia entry for the Receiver operating characteristic\n `_\n\n.. [2] `Analyzing a portion of the ROC curve. McClish, 1989\n `_\n\n.. [3] Provost, F., Domingos, P. (2000). Well-trained PETs: Improving\n probability estimation trees (Section 6.2), CeDER Working Paper\n #IS-00-04, Stern School of Business, New York University.\n\n.. [4] `Fawcett, T. (2006). An introduction to ROC analysis. Pattern\n Recognition Letters, 27(8), 861-874.\n `_\n\n.. [5] `Hand, D.J., Till, R.J. (2001). A Simple Generalisation of the Area\n Under the ROC Curve for Multiple Class Classification Problems.\n Machine Learning, 45(2), 171-186.\n `_\n\nSee Also\n--------\naverage_precision_score : Area under the precision-recall curve.\nroc_curve : Compute Receiver operating characteristic (ROC) curve.\nRocCurveDisplay.from_estimator : Plot Receiver Operating Characteristic\n (ROC) curve given an estimator and some data.\nRocCurveDisplay.from_predictions : Plot Receiver Operating Characteristic\n (ROC) curve given the true and predicted values.\n\nExamples\n--------\nBinary case:\n\n>>> from sklearn.datasets import load_breast_cancer\n>>> from sklearn.linear_model import LogisticRegression\n>>> from sklearn.metrics import roc_auc_score\n>>> X, y = load_breast_cancer(return_X_y=True)\n>>> clf = LogisticRegression(solver=\"liblinear\", random_state=0).fit(X, y)\n>>> roc_auc_score(y, clf.predict_proba(X)[:, 1])\n0.99...\n>>> roc_auc_score(y, clf.decision_function(X))\n0.99...\n\nMulticlass case:\n\n>>> from sklearn.datasets import load_iris\n>>> X, y = load_iris(return_X_y=True)\n>>> clf = LogisticRegression(solver=\"liblinear\").fit(X, y)\n>>> roc_auc_score(y, clf.predict_proba(X), multi_class='ovr')\n0.99...\n\nMultilabel case:\n\n>>> import numpy as np\n>>> from sklearn.datasets import make_multilabel_classification\n>>> from sklearn.multioutput import MultiOutputClassifier\n>>> X, y = make_multilabel_classification(random_state=0)\n>>> clf = MultiOutputClassifier(clf).fit(X, y)\n>>> # get a list of n_output containing probability arrays of shape\n>>> # (n_samples, n_classes)\n>>> y_pred = clf.predict_proba(X)\n>>> # extract the positive columns for each output\n>>> y_pred = np.transpose([pred[:, 1] for pred in y_pred])\n>>> roc_auc_score(y, y_pred, average=None)\narray([0.82..., 0.86..., 0.94..., 0.85... , 0.94...])\n>>> from sklearn.linear_model import RidgeClassifierCV\n>>> clf = RidgeClassifierCV().fit(X, y)\n>>> roc_auc_score(y, clf.decision_function(X), average=None)\narray([0.81..., 0.84... , 0.93..., 0.87..., 0.94...])", + "source_code": "\ndef roc_auc_score(y_true, y_score, *, average='macro', sample_weight=None, max_fpr=None, multi_class='raise', labels=None):\n \"\"\"Compute Area Under the Receiver Operating Characteristic Curve (ROC AUC)\n from prediction scores.\n\n Note: this implementation can be used with binary, multiclass and\n multilabel classification, but some restrictions apply (see Parameters).\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n y_true : array-like of shape (n_samples,) or (n_samples, n_classes)\n True labels or binary label indicators. The binary and multiclass cases\n expect labels with shape (n_samples,) while the multilabel case expects\n binary label indicators with shape (n_samples, n_classes).\n\n y_score : array-like of shape (n_samples,) or (n_samples, n_classes)\n Target scores.\n\n * In the binary case, it corresponds to an array of shape\n `(n_samples,)`. Both probability estimates and non-thresholded\n decision values can be provided. The probability estimates correspond\n to the **probability of the class with the greater label**,\n i.e. `estimator.classes_[1]` and thus\n `estimator.predict_proba(X, y)[:, 1]`. The decision values\n corresponds to the output of `estimator.decision_function(X, y)`.\n See more information in the :ref:`User guide `;\n * In the multiclass case, it corresponds to an array of shape\n `(n_samples, n_classes)` of probability estimates provided by the\n `predict_proba` method. The probability estimates **must**\n sum to 1 across the possible classes. In addition, the order of the\n class scores must correspond to the order of ``labels``,\n if provided, or else to the numerical or lexicographical order of\n the labels in ``y_true``. See more information in the\n :ref:`User guide `;\n * In the multilabel case, it corresponds to an array of shape\n `(n_samples, n_classes)`. Probability estimates are provided by the\n `predict_proba` method and the non-thresholded decision values by\n the `decision_function` method. The probability estimates correspond\n to the **probability of the class with the greater label for each\n output** of the classifier. See more information in the\n :ref:`User guide `.\n\n average : {'micro', 'macro', 'samples', 'weighted'} or None, default='macro'\n If ``None``, the scores for each class are returned. Otherwise,\n this determines the type of averaging performed on the data:\n Note: multiclass ROC AUC currently only handles the 'macro' and\n 'weighted' averages.\n\n ``'micro'``:\n Calculate metrics globally by considering each element of the label\n indicator matrix as a label.\n ``'macro'``:\n Calculate metrics for each label, and find their unweighted\n mean. This does not take label imbalance into account.\n ``'weighted'``:\n Calculate metrics for each label, and find their average, weighted\n by support (the number of true instances for each label).\n ``'samples'``:\n Calculate metrics for each instance, and find their average.\n\n Will be ignored when ``y_true`` is binary.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Sample weights.\n\n max_fpr : float > 0 and <= 1, default=None\n If not ``None``, the standardized partial AUC [2]_ over the range\n [0, max_fpr] is returned. For the multiclass case, ``max_fpr``,\n should be either equal to ``None`` or ``1.0`` as AUC ROC partial\n computation currently is not supported for multiclass.\n\n multi_class : {'raise', 'ovr', 'ovo'}, default='raise'\n Only used for multiclass targets. Determines the type of configuration\n to use. The default value raises an error, so either\n ``'ovr'`` or ``'ovo'`` must be passed explicitly.\n\n ``'ovr'``:\n Stands for One-vs-rest. Computes the AUC of each class\n against the rest [3]_ [4]_. This\n treats the multiclass case in the same way as the multilabel case.\n Sensitive to class imbalance even when ``average == 'macro'``,\n because class imbalance affects the composition of each of the\n 'rest' groupings.\n ``'ovo'``:\n Stands for One-vs-one. Computes the average AUC of all\n possible pairwise combinations of classes [5]_.\n Insensitive to class imbalance when\n ``average == 'macro'``.\n\n labels : array-like of shape (n_classes,), default=None\n Only used for multiclass targets. List of labels that index the\n classes in ``y_score``. If ``None``, the numerical or lexicographical\n order of the labels in ``y_true`` is used.\n\n Returns\n -------\n auc : float\n\n References\n ----------\n .. [1] `Wikipedia entry for the Receiver operating characteristic\n `_\n\n .. [2] `Analyzing a portion of the ROC curve. McClish, 1989\n `_\n\n .. [3] Provost, F., Domingos, P. (2000). Well-trained PETs: Improving\n probability estimation trees (Section 6.2), CeDER Working Paper\n #IS-00-04, Stern School of Business, New York University.\n\n .. [4] `Fawcett, T. (2006). An introduction to ROC analysis. Pattern\n Recognition Letters, 27(8), 861-874.\n `_\n\n .. [5] `Hand, D.J., Till, R.J. (2001). A Simple Generalisation of the Area\n Under the ROC Curve for Multiple Class Classification Problems.\n Machine Learning, 45(2), 171-186.\n `_\n\n See Also\n --------\n average_precision_score : Area under the precision-recall curve.\n roc_curve : Compute Receiver operating characteristic (ROC) curve.\n RocCurveDisplay.from_estimator : Plot Receiver Operating Characteristic\n (ROC) curve given an estimator and some data.\n RocCurveDisplay.from_predictions : Plot Receiver Operating Characteristic\n (ROC) curve given the true and predicted values.\n\n Examples\n --------\n Binary case:\n\n >>> from sklearn.datasets import load_breast_cancer\n >>> from sklearn.linear_model import LogisticRegression\n >>> from sklearn.metrics import roc_auc_score\n >>> X, y = load_breast_cancer(return_X_y=True)\n >>> clf = LogisticRegression(solver=\"liblinear\", random_state=0).fit(X, y)\n >>> roc_auc_score(y, clf.predict_proba(X)[:, 1])\n 0.99...\n >>> roc_auc_score(y, clf.decision_function(X))\n 0.99...\n\n Multiclass case:\n\n >>> from sklearn.datasets import load_iris\n >>> X, y = load_iris(return_X_y=True)\n >>> clf = LogisticRegression(solver=\"liblinear\").fit(X, y)\n >>> roc_auc_score(y, clf.predict_proba(X), multi_class='ovr')\n 0.99...\n\n Multilabel case:\n\n >>> import numpy as np\n >>> from sklearn.datasets import make_multilabel_classification\n >>> from sklearn.multioutput import MultiOutputClassifier\n >>> X, y = make_multilabel_classification(random_state=0)\n >>> clf = MultiOutputClassifier(clf).fit(X, y)\n >>> # get a list of n_output containing probability arrays of shape\n >>> # (n_samples, n_classes)\n >>> y_pred = clf.predict_proba(X)\n >>> # extract the positive columns for each output\n >>> y_pred = np.transpose([pred[:, 1] for pred in y_pred])\n >>> roc_auc_score(y, y_pred, average=None)\n array([0.82..., 0.86..., 0.94..., 0.85... , 0.94...])\n >>> from sklearn.linear_model import RidgeClassifierCV\n >>> clf = RidgeClassifierCV().fit(X, y)\n >>> roc_auc_score(y, clf.decision_function(X), average=None)\n array([0.81..., 0.84... , 0.93..., 0.87..., 0.94...])\n \"\"\"\n y_type = type_of_target(y_true)\n y_true = check_array(y_true, ensure_2d=False, dtype=None)\n y_score = check_array(y_score, ensure_2d=False)\n if y_type == 'multiclass' or y_type == 'binary' and y_score.ndim == 2 and y_score.shape[1] > 2:\n if max_fpr is not None and max_fpr != 1.0:\n raise ValueError(\"Partial AUC computation not available in multiclass setting, 'max_fpr' must be set to `None`, received `max_fpr={0}` instead\".format(max_fpr))\n if multi_class == 'raise':\n raise ValueError(\"multi_class must be in ('ovo', 'ovr')\")\n return _multiclass_roc_auc_score(y_true, y_score, labels, multi_class, average, sample_weight)\n elif y_type == 'binary':\n labels = np.unique(y_true)\n y_true = label_binarize(y_true, classes=labels)[:, 0]\n return _average_binary_score(partial(_binary_roc_auc_score, max_fpr=max_fpr), y_true, y_score, average, sample_weight=sample_weight)\n else:\n return _average_binary_score(partial(_binary_roc_auc_score, max_fpr=max_fpr), y_true, y_score, average, sample_weight=sample_weight)" }, { "name": "roc_curve", + "unique_name": "roc_curve", "qname": "sklearn.metrics._ranking.roc_curve", + "unique_qname": "sklearn.metrics._ranking.roc_curve", "decorators": [], "parameters": [ { @@ -117259,7 +121101,9 @@ }, { "name": "top_k_accuracy_score", + "unique_name": "top_k_accuracy_score", "qname": "sklearn.metrics._ranking.top_k_accuracy_score", + "unique_qname": "sklearn.metrics._ranking.top_k_accuracy_score", "decorators": [], "parameters": [ { @@ -117331,7 +121175,9 @@ }, { "name": "_check_reg_targets", + "unique_name": "_check_reg_targets", "qname": "sklearn.metrics._regression._check_reg_targets", + "unique_qname": "sklearn.metrics._regression._check_reg_targets", "decorators": [], "parameters": [ { @@ -117383,7 +121229,9 @@ }, { "name": "d2_tweedie_score", + "unique_name": "d2_tweedie_score", "qname": "sklearn.metrics._regression.d2_tweedie_score", + "unique_qname": "sklearn.metrics._regression.d2_tweedie_score", "decorators": [], "parameters": [ { @@ -117435,7 +121283,9 @@ }, { "name": "explained_variance_score", + "unique_name": "explained_variance_score", "qname": "sklearn.metrics._regression.explained_variance_score", + "unique_qname": "sklearn.metrics._regression.explained_variance_score", "decorators": [], "parameters": [ { @@ -117487,7 +121337,9 @@ }, { "name": "max_error", + "unique_name": "max_error", "qname": "sklearn.metrics._regression.max_error", + "unique_qname": "sklearn.metrics._regression.max_error", "decorators": [], "parameters": [ { @@ -117519,7 +121371,9 @@ }, { "name": "mean_absolute_error", + "unique_name": "mean_absolute_error", "qname": "sklearn.metrics._regression.mean_absolute_error", + "unique_qname": "sklearn.metrics._regression.mean_absolute_error", "decorators": [], "parameters": [ { @@ -117571,7 +121425,9 @@ }, { "name": "mean_absolute_percentage_error", + "unique_name": "mean_absolute_percentage_error", "qname": "sklearn.metrics._regression.mean_absolute_percentage_error", + "unique_qname": "sklearn.metrics._regression.mean_absolute_percentage_error", "decorators": [], "parameters": [ { @@ -117623,7 +121479,9 @@ }, { "name": "mean_gamma_deviance", + "unique_name": "mean_gamma_deviance", "qname": "sklearn.metrics._regression.mean_gamma_deviance", + "unique_qname": "sklearn.metrics._regression.mean_gamma_deviance", "decorators": [], "parameters": [ { @@ -117665,7 +121523,9 @@ }, { "name": "mean_pinball_loss", + "unique_name": "mean_pinball_loss", "qname": "sklearn.metrics._regression.mean_pinball_loss", + "unique_qname": "sklearn.metrics._regression.mean_pinball_loss", "decorators": [], "parameters": [ { @@ -117727,7 +121587,9 @@ }, { "name": "mean_poisson_deviance", + "unique_name": "mean_poisson_deviance", "qname": "sklearn.metrics._regression.mean_poisson_deviance", + "unique_qname": "sklearn.metrics._regression.mean_poisson_deviance", "decorators": [], "parameters": [ { @@ -117769,7 +121631,9 @@ }, { "name": "mean_squared_error", + "unique_name": "mean_squared_error", "qname": "sklearn.metrics._regression.mean_squared_error", + "unique_qname": "sklearn.metrics._regression.mean_squared_error", "decorators": [], "parameters": [ { @@ -117831,7 +121695,9 @@ }, { "name": "mean_squared_log_error", + "unique_name": "mean_squared_log_error", "qname": "sklearn.metrics._regression.mean_squared_log_error", + "unique_qname": "sklearn.metrics._regression.mean_squared_log_error", "decorators": [], "parameters": [ { @@ -117893,7 +121759,9 @@ }, { "name": "mean_tweedie_deviance", + "unique_name": "mean_tweedie_deviance", "qname": "sklearn.metrics._regression.mean_tweedie_deviance", + "unique_qname": "sklearn.metrics._regression.mean_tweedie_deviance", "decorators": [], "parameters": [ { @@ -117945,7 +121813,9 @@ }, { "name": "median_absolute_error", + "unique_name": "median_absolute_error", "qname": "sklearn.metrics._regression.median_absolute_error", + "unique_qname": "sklearn.metrics._regression.median_absolute_error", "decorators": [], "parameters": [ { @@ -117997,7 +121867,9 @@ }, { "name": "r2_score", + "unique_name": "r2_score", "qname": "sklearn.metrics._regression.r2_score", + "unique_qname": "sklearn.metrics._regression.r2_score", "decorators": [], "parameters": [ { @@ -118049,7 +121921,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.metrics._scorer._BaseScorer.__call__", + "unique_qname": "sklearn.metrics._scorer._BaseScorer.__call__", "decorators": [], "parameters": [ { @@ -118111,7 +121985,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.metrics._scorer._BaseScorer.__init__", + "unique_qname": "sklearn.metrics._scorer._BaseScorer.__init__", "decorators": [], "parameters": [ { @@ -118163,7 +122039,9 @@ }, { "name": "__repr__", + "unique_name": "__repr__", "qname": "sklearn.metrics._scorer._BaseScorer.__repr__", + "unique_qname": "sklearn.metrics._scorer._BaseScorer.__repr__", "decorators": [], "parameters": [ { @@ -118185,7 +122063,9 @@ }, { "name": "_check_pos_label", + "unique_name": "_check_pos_label", "qname": "sklearn.metrics._scorer._BaseScorer._check_pos_label", + "unique_qname": "sklearn.metrics._scorer._BaseScorer._check_pos_label", "decorators": ["staticmethod"], "parameters": [ { @@ -118217,7 +122097,9 @@ }, { "name": "_factory_args", + "unique_name": "_factory_args", "qname": "sklearn.metrics._scorer._BaseScorer._factory_args", + "unique_qname": "sklearn.metrics._scorer._BaseScorer._factory_args", "decorators": [], "parameters": [ { @@ -118239,7 +122121,9 @@ }, { "name": "_select_proba_binary", + "unique_name": "_select_proba_binary", "qname": "sklearn.metrics._scorer._BaseScorer._select_proba_binary", + "unique_qname": "sklearn.metrics._scorer._BaseScorer._select_proba_binary", "decorators": [], "parameters": [ { @@ -118281,7 +122165,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.metrics._scorer._MultimetricScorer.__call__", + "unique_qname": "sklearn.metrics._scorer._MultimetricScorer.__call__", "decorators": [], "parameters": [ { @@ -118313,7 +122199,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.metrics._scorer._MultimetricScorer.__init__", + "unique_qname": "sklearn.metrics._scorer._MultimetricScorer.__init__", "decorators": [], "parameters": [ { @@ -118335,7 +122223,9 @@ }, { "name": "_use_cache", + "unique_name": "_use_cache", "qname": "sklearn.metrics._scorer._MultimetricScorer._use_cache", + "unique_qname": "sklearn.metrics._scorer._MultimetricScorer._use_cache", "decorators": [], "parameters": [ { @@ -118367,7 +122257,9 @@ }, { "name": "_score", + "unique_name": "_score", "qname": "sklearn.metrics._scorer._PredictScorer._score", + "unique_qname": "sklearn.metrics._scorer._PredictScorer._score", "decorators": [], "parameters": [ { @@ -118439,7 +122331,9 @@ }, { "name": "_factory_args", + "unique_name": "_factory_args", "qname": "sklearn.metrics._scorer._ProbaScorer._factory_args", + "unique_qname": "sklearn.metrics._scorer._ProbaScorer._factory_args", "decorators": [], "parameters": [ { @@ -118461,7 +122355,9 @@ }, { "name": "_score", + "unique_name": "_score", "qname": "sklearn.metrics._scorer._ProbaScorer._score", + "unique_qname": "sklearn.metrics._scorer._ProbaScorer._score", "decorators": [], "parameters": [ { @@ -118533,7 +122429,9 @@ }, { "name": "_factory_args", + "unique_name": "_factory_args", "qname": "sklearn.metrics._scorer._ThresholdScorer._factory_args", + "unique_qname": "sklearn.metrics._scorer._ThresholdScorer._factory_args", "decorators": [], "parameters": [ { @@ -118555,7 +122453,9 @@ }, { "name": "_score", + "unique_name": "_score", "qname": "sklearn.metrics._scorer._ThresholdScorer._score", + "unique_qname": "sklearn.metrics._scorer._ThresholdScorer._score", "decorators": [], "parameters": [ { @@ -118627,7 +122527,9 @@ }, { "name": "_cached_call", + "unique_name": "_cached_call", "qname": "sklearn.metrics._scorer._cached_call", + "unique_qname": "sklearn.metrics._scorer._cached_call", "decorators": [], "parameters": [ { @@ -118669,7 +122571,9 @@ }, { "name": "_check_multimetric_scoring", + "unique_name": "_check_multimetric_scoring", "qname": "sklearn.metrics._scorer._check_multimetric_scoring", + "unique_qname": "sklearn.metrics._scorer._check_multimetric_scoring", "decorators": [], "parameters": [ { @@ -118701,7 +122605,9 @@ }, { "name": "_passthrough_scorer", + "unique_name": "_passthrough_scorer", "qname": "sklearn.metrics._scorer._passthrough_scorer", + "unique_qname": "sklearn.metrics._scorer._passthrough_scorer", "decorators": [], "parameters": [ { @@ -118723,7 +122629,9 @@ }, { "name": "check_scoring", + "unique_name": "check_scoring", "qname": "sklearn.metrics._scorer.check_scoring", + "unique_qname": "sklearn.metrics._scorer.check_scoring", "decorators": [], "parameters": [ { @@ -118765,7 +122673,9 @@ }, { "name": "get_scorer", + "unique_name": "get_scorer", "qname": "sklearn.metrics._scorer.get_scorer", + "unique_qname": "sklearn.metrics._scorer.get_scorer", "decorators": [], "parameters": [ { @@ -118787,7 +122697,9 @@ }, { "name": "make_scorer", + "unique_name": "make_scorer", "qname": "sklearn.metrics._scorer.make_scorer", + "unique_qname": "sklearn.metrics._scorer.make_scorer", "decorators": [], "parameters": [ { @@ -118839,7 +122751,9 @@ }, { "name": "_check_rows_and_columns", + "unique_name": "_check_rows_and_columns", "qname": "sklearn.metrics.cluster._bicluster._check_rows_and_columns", + "unique_qname": "sklearn.metrics.cluster._bicluster._check_rows_and_columns", "decorators": [], "parameters": [ { @@ -118871,7 +122785,9 @@ }, { "name": "_jaccard", + "unique_name": "_jaccard", "qname": "sklearn.metrics.cluster._bicluster._jaccard", + "unique_qname": "sklearn.metrics.cluster._bicluster._jaccard", "decorators": [], "parameters": [ { @@ -118923,7 +122839,9 @@ }, { "name": "_pairwise_similarity", + "unique_name": "_pairwise_similarity", "qname": "sklearn.metrics.cluster._bicluster._pairwise_similarity", + "unique_qname": "sklearn.metrics.cluster._bicluster._pairwise_similarity", "decorators": [], "parameters": [ { @@ -118965,7 +122883,9 @@ }, { "name": "consensus_score", + "unique_name": "consensus_score", "qname": "sklearn.metrics.cluster._bicluster.consensus_score", + "unique_qname": "sklearn.metrics.cluster._bicluster.consensus_score", "decorators": [], "parameters": [ { @@ -119007,7 +122927,9 @@ }, { "name": "_generalized_average", + "unique_name": "_generalized_average", "qname": "sklearn.metrics.cluster._supervised._generalized_average", + "unique_qname": "sklearn.metrics.cluster._supervised._generalized_average", "decorators": [], "parameters": [ { @@ -119049,7 +122971,9 @@ }, { "name": "adjusted_mutual_info_score", + "unique_name": "adjusted_mutual_info_score", "qname": "sklearn.metrics.cluster._supervised.adjusted_mutual_info_score", + "unique_qname": "sklearn.metrics.cluster._supervised.adjusted_mutual_info_score", "decorators": [], "parameters": [ { @@ -119059,7 +122983,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "int array, shape = [n_samples]", - "description": "A clustering of the data into disjoint subsets." + "description": "A clustering of the data into disjoint subsets, called :math:`U` in\nthe above formula." } }, { @@ -119069,7 +122993,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "int array-like of shape (n_samples,)", - "description": "A clustering of the data into disjoint subsets." + "description": "A clustering of the data into disjoint subsets, called :math:`V` in\nthe above formula." } }, { @@ -119085,13 +123009,15 @@ ], "results": [], "is_public": true, - "description": "Adjusted Mutual Information between two clusterings.\n\nAdjusted Mutual Information (AMI) is an adjustment of the Mutual Information (MI) score to account for chance. It accounts for the fact that the MI is generally higher for two clusterings with a larger number of clusters, regardless of whether there is actually more information shared. For two clusterings :math:`U` and :math:`V`, the AMI is given as:: AMI(U, V) = [MI(U, V) - E(MI(U, V))] / [avg(H(U), H(V)) - E(MI(U, V))] This metric is independent of the absolute values of the labels: a permutation of the class or cluster label values won't change the score value in any way. This metric is furthermore symmetric: switching ``label_true`` with ``label_pred`` will return the same score value. This can be useful to measure the agreement of two independent label assignments strategies on the same dataset when the real ground truth is not known. Be mindful that this function is an order of magnitude slower than other metrics, such as the Adjusted Rand Index. Read more in the :ref:`User Guide `.", - "docstring": "Adjusted Mutual Information between two clusterings.\n\nAdjusted Mutual Information (AMI) is an adjustment of the Mutual\nInformation (MI) score to account for chance. It accounts for the fact that\nthe MI is generally higher for two clusterings with a larger number of\nclusters, regardless of whether there is actually more information shared.\nFor two clusterings :math:`U` and :math:`V`, the AMI is given as::\n\n AMI(U, V) = [MI(U, V) - E(MI(U, V))] / [avg(H(U), H(V)) - E(MI(U, V))]\n\nThis metric is independent of the absolute values of the labels:\na permutation of the class or cluster label values won't change the\nscore value in any way.\n\nThis metric is furthermore symmetric: switching ``label_true`` with\n``label_pred`` will return the same score value. This can be useful to\nmeasure the agreement of two independent label assignments strategies\non the same dataset when the real ground truth is not known.\n\nBe mindful that this function is an order of magnitude slower than other\nmetrics, such as the Adjusted Rand Index.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\nlabels_true : int array, shape = [n_samples]\n A clustering of the data into disjoint subsets.\n\nlabels_pred : int array-like of shape (n_samples,)\n A clustering of the data into disjoint subsets.\n\naverage_method : str, default='arithmetic'\n How to compute the normalizer in the denominator. Possible options\n are 'min', 'geometric', 'arithmetic', and 'max'.\n\n .. versionadded:: 0.20\n\n .. versionchanged:: 0.22\n The default value of ``average_method`` changed from 'max' to\n 'arithmetic'.\n\nReturns\n-------\nami: float (upperlimited by 1.0)\n The AMI returns a value of 1 when the two partitions are identical\n (ie perfectly matched). Random partitions (independent labellings) have\n an expected AMI around 0 on average hence can be negative.\n\nSee Also\n--------\nadjusted_rand_score : Adjusted Rand Index.\nmutual_info_score : Mutual Information (not adjusted for chance).\n\nExamples\n--------\n\nPerfect labelings are both homogeneous and complete, hence have\nscore 1.0::\n\n >>> from sklearn.metrics.cluster import adjusted_mutual_info_score\n >>> adjusted_mutual_info_score([0, 0, 1, 1], [0, 0, 1, 1])\n ... # doctest: +SKIP\n 1.0\n >>> adjusted_mutual_info_score([0, 0, 1, 1], [1, 1, 0, 0])\n ... # doctest: +SKIP\n 1.0\n\nIf classes members are completely split across different clusters,\nthe assignment is totally in-complete, hence the AMI is null::\n\n >>> adjusted_mutual_info_score([0, 0, 0, 0], [0, 1, 2, 3])\n ... # doctest: +SKIP\n 0.0\n\nReferences\n----------\n.. [1] `Vinh, Epps, and Bailey, (2010). Information Theoretic Measures for\n Clusterings Comparison: Variants, Properties, Normalization and\n Correction for Chance, JMLR\n `_\n\n.. [2] `Wikipedia entry for the Adjusted Mutual Information\n `_", - "source_code": "\ndef adjusted_mutual_info_score(labels_true, labels_pred, *, average_method='arithmetic'):\n \"\"\"Adjusted Mutual Information between two clusterings.\n\n Adjusted Mutual Information (AMI) is an adjustment of the Mutual\n Information (MI) score to account for chance. It accounts for the fact that\n the MI is generally higher for two clusterings with a larger number of\n clusters, regardless of whether there is actually more information shared.\n For two clusterings :math:`U` and :math:`V`, the AMI is given as::\n\n AMI(U, V) = [MI(U, V) - E(MI(U, V))] / [avg(H(U), H(V)) - E(MI(U, V))]\n\n This metric is independent of the absolute values of the labels:\n a permutation of the class or cluster label values won't change the\n score value in any way.\n\n This metric is furthermore symmetric: switching ``label_true`` with\n ``label_pred`` will return the same score value. This can be useful to\n measure the agreement of two independent label assignments strategies\n on the same dataset when the real ground truth is not known.\n\n Be mindful that this function is an order of magnitude slower than other\n metrics, such as the Adjusted Rand Index.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n labels_true : int array, shape = [n_samples]\n A clustering of the data into disjoint subsets.\n\n labels_pred : int array-like of shape (n_samples,)\n A clustering of the data into disjoint subsets.\n\n average_method : str, default='arithmetic'\n How to compute the normalizer in the denominator. Possible options\n are 'min', 'geometric', 'arithmetic', and 'max'.\n\n .. versionadded:: 0.20\n\n .. versionchanged:: 0.22\n The default value of ``average_method`` changed from 'max' to\n 'arithmetic'.\n\n Returns\n -------\n ami: float (upperlimited by 1.0)\n The AMI returns a value of 1 when the two partitions are identical\n (ie perfectly matched). Random partitions (independent labellings) have\n an expected AMI around 0 on average hence can be negative.\n\n See Also\n --------\n adjusted_rand_score : Adjusted Rand Index.\n mutual_info_score : Mutual Information (not adjusted for chance).\n\n Examples\n --------\n\n Perfect labelings are both homogeneous and complete, hence have\n score 1.0::\n\n >>> from sklearn.metrics.cluster import adjusted_mutual_info_score\n >>> adjusted_mutual_info_score([0, 0, 1, 1], [0, 0, 1, 1])\n ... # doctest: +SKIP\n 1.0\n >>> adjusted_mutual_info_score([0, 0, 1, 1], [1, 1, 0, 0])\n ... # doctest: +SKIP\n 1.0\n\n If classes members are completely split across different clusters,\n the assignment is totally in-complete, hence the AMI is null::\n\n >>> adjusted_mutual_info_score([0, 0, 0, 0], [0, 1, 2, 3])\n ... # doctest: +SKIP\n 0.0\n\n References\n ----------\n .. [1] `Vinh, Epps, and Bailey, (2010). Information Theoretic Measures for\n Clusterings Comparison: Variants, Properties, Normalization and\n Correction for Chance, JMLR\n `_\n\n .. [2] `Wikipedia entry for the Adjusted Mutual Information\n `_\n \"\"\"\n (labels_true, labels_pred) = check_clusterings(labels_true, labels_pred)\n n_samples = labels_true.shape[0]\n classes = np.unique(labels_true)\n clusters = np.unique(labels_pred)\n if classes.shape[0] == clusters.shape[0] == 1 or classes.shape[0] == clusters.shape[0] == 0:\n return 1.0\n contingency = contingency_matrix(labels_true, labels_pred, sparse=True)\n contingency = contingency.astype(np.float64, **_astype_copy_false(contingency))\n mi = mutual_info_score(labels_true, labels_pred, contingency=contingency)\n emi = expected_mutual_information(contingency, n_samples)\n (h_true, h_pred) = (entropy(labels_true), entropy(labels_pred))\n normalizer = _generalized_average(h_true, h_pred, average_method)\n denominator = normalizer - emi\n if denominator < 0:\n denominator = min(denominator, -np.finfo('float64').eps)\n else:\n denominator = max(denominator, np.finfo('float64').eps)\n ami = (mi - emi) / denominator\n return ami" + "description": "Adjusted Mutual Information between two clusterings.\n\nAdjusted Mutual Information (AMI) is an adjustment of the Mutual Information (MI) score to account for chance. It accounts for the fact that the MI is generally higher for two clusterings with a larger number of clusters, regardless of whether there is actually more information shared. For two clusterings :math:`U` and :math:`V`, the AMI is given as:: AMI(U, V) = [MI(U, V) - E(MI(U, V))] / [avg(H(U), H(V)) - E(MI(U, V))] This metric is independent of the absolute values of the labels: a permutation of the class or cluster label values won't change the score value in any way. This metric is furthermore symmetric: switching :math:`U` (``label_true``) with :math:`V` (``labels_pred``) will return the same score value. This can be useful to measure the agreement of two independent label assignments strategies on the same dataset when the real ground truth is not known. Be mindful that this function is an order of magnitude slower than other metrics, such as the Adjusted Rand Index. Read more in the :ref:`User Guide `.", + "docstring": "Adjusted Mutual Information between two clusterings.\n\nAdjusted Mutual Information (AMI) is an adjustment of the Mutual\nInformation (MI) score to account for chance. It accounts for the fact that\nthe MI is generally higher for two clusterings with a larger number of\nclusters, regardless of whether there is actually more information shared.\nFor two clusterings :math:`U` and :math:`V`, the AMI is given as::\n\n AMI(U, V) = [MI(U, V) - E(MI(U, V))] / [avg(H(U), H(V)) - E(MI(U, V))]\n\nThis metric is independent of the absolute values of the labels:\na permutation of the class or cluster label values won't change the\nscore value in any way.\n\nThis metric is furthermore symmetric: switching :math:`U` (``label_true``)\nwith :math:`V` (``labels_pred``) will return the same score value. This can\nbe useful to measure the agreement of two independent label assignments\nstrategies on the same dataset when the real ground truth is not known.\n\nBe mindful that this function is an order of magnitude slower than other\nmetrics, such as the Adjusted Rand Index.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\nlabels_true : int array, shape = [n_samples]\n A clustering of the data into disjoint subsets, called :math:`U` in\n the above formula.\n\nlabels_pred : int array-like of shape (n_samples,)\n A clustering of the data into disjoint subsets, called :math:`V` in\n the above formula.\n\naverage_method : str, default='arithmetic'\n How to compute the normalizer in the denominator. Possible options\n are 'min', 'geometric', 'arithmetic', and 'max'.\n\n .. versionadded:: 0.20\n\n .. versionchanged:: 0.22\n The default value of ``average_method`` changed from 'max' to\n 'arithmetic'.\n\nReturns\n-------\nami: float (upperlimited by 1.0)\n The AMI returns a value of 1 when the two partitions are identical\n (ie perfectly matched). Random partitions (independent labellings) have\n an expected AMI around 0 on average hence can be negative. The value is\n in adjusted nats (based on the natural logarithm).\n\nSee Also\n--------\nadjusted_rand_score : Adjusted Rand Index.\nmutual_info_score : Mutual Information (not adjusted for chance).\n\nExamples\n--------\n\nPerfect labelings are both homogeneous and complete, hence have\nscore 1.0::\n\n >>> from sklearn.metrics.cluster import adjusted_mutual_info_score\n >>> adjusted_mutual_info_score([0, 0, 1, 1], [0, 0, 1, 1])\n ... # doctest: +SKIP\n 1.0\n >>> adjusted_mutual_info_score([0, 0, 1, 1], [1, 1, 0, 0])\n ... # doctest: +SKIP\n 1.0\n\nIf classes members are completely split across different clusters,\nthe assignment is totally in-complete, hence the AMI is null::\n\n >>> adjusted_mutual_info_score([0, 0, 0, 0], [0, 1, 2, 3])\n ... # doctest: +SKIP\n 0.0\n\nReferences\n----------\n.. [1] `Vinh, Epps, and Bailey, (2010). Information Theoretic Measures for\n Clusterings Comparison: Variants, Properties, Normalization and\n Correction for Chance, JMLR\n `_\n\n.. [2] `Wikipedia entry for the Adjusted Mutual Information\n `_", + "source_code": "\ndef adjusted_mutual_info_score(labels_true, labels_pred, *, average_method='arithmetic'):\n \"\"\"Adjusted Mutual Information between two clusterings.\n\n Adjusted Mutual Information (AMI) is an adjustment of the Mutual\n Information (MI) score to account for chance. It accounts for the fact that\n the MI is generally higher for two clusterings with a larger number of\n clusters, regardless of whether there is actually more information shared.\n For two clusterings :math:`U` and :math:`V`, the AMI is given as::\n\n AMI(U, V) = [MI(U, V) - E(MI(U, V))] / [avg(H(U), H(V)) - E(MI(U, V))]\n\n This metric is independent of the absolute values of the labels:\n a permutation of the class or cluster label values won't change the\n score value in any way.\n\n This metric is furthermore symmetric: switching :math:`U` (``label_true``)\n with :math:`V` (``labels_pred``) will return the same score value. This can\n be useful to measure the agreement of two independent label assignments\n strategies on the same dataset when the real ground truth is not known.\n\n Be mindful that this function is an order of magnitude slower than other\n metrics, such as the Adjusted Rand Index.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n labels_true : int array, shape = [n_samples]\n A clustering of the data into disjoint subsets, called :math:`U` in\n the above formula.\n\n labels_pred : int array-like of shape (n_samples,)\n A clustering of the data into disjoint subsets, called :math:`V` in\n the above formula.\n\n average_method : str, default='arithmetic'\n How to compute the normalizer in the denominator. Possible options\n are 'min', 'geometric', 'arithmetic', and 'max'.\n\n .. versionadded:: 0.20\n\n .. versionchanged:: 0.22\n The default value of ``average_method`` changed from 'max' to\n 'arithmetic'.\n\n Returns\n -------\n ami: float (upperlimited by 1.0)\n The AMI returns a value of 1 when the two partitions are identical\n (ie perfectly matched). Random partitions (independent labellings) have\n an expected AMI around 0 on average hence can be negative. The value is\n in adjusted nats (based on the natural logarithm).\n\n See Also\n --------\n adjusted_rand_score : Adjusted Rand Index.\n mutual_info_score : Mutual Information (not adjusted for chance).\n\n Examples\n --------\n\n Perfect labelings are both homogeneous and complete, hence have\n score 1.0::\n\n >>> from sklearn.metrics.cluster import adjusted_mutual_info_score\n >>> adjusted_mutual_info_score([0, 0, 1, 1], [0, 0, 1, 1])\n ... # doctest: +SKIP\n 1.0\n >>> adjusted_mutual_info_score([0, 0, 1, 1], [1, 1, 0, 0])\n ... # doctest: +SKIP\n 1.0\n\n If classes members are completely split across different clusters,\n the assignment is totally in-complete, hence the AMI is null::\n\n >>> adjusted_mutual_info_score([0, 0, 0, 0], [0, 1, 2, 3])\n ... # doctest: +SKIP\n 0.0\n\n References\n ----------\n .. [1] `Vinh, Epps, and Bailey, (2010). Information Theoretic Measures for\n Clusterings Comparison: Variants, Properties, Normalization and\n Correction for Chance, JMLR\n `_\n\n .. [2] `Wikipedia entry for the Adjusted Mutual Information\n `_\n \"\"\"\n (labels_true, labels_pred) = check_clusterings(labels_true, labels_pred)\n n_samples = labels_true.shape[0]\n classes = np.unique(labels_true)\n clusters = np.unique(labels_pred)\n if classes.shape[0] == clusters.shape[0] == 1 or classes.shape[0] == clusters.shape[0] == 0:\n return 1.0\n contingency = contingency_matrix(labels_true, labels_pred, sparse=True)\n contingency = contingency.astype(np.float64, **_astype_copy_false(contingency))\n mi = mutual_info_score(labels_true, labels_pred, contingency=contingency)\n emi = expected_mutual_information(contingency, n_samples)\n (h_true, h_pred) = (entropy(labels_true), entropy(labels_pred))\n normalizer = _generalized_average(h_true, h_pred, average_method)\n denominator = normalizer - emi\n if denominator < 0:\n denominator = min(denominator, -np.finfo('float64').eps)\n else:\n denominator = max(denominator, np.finfo('float64').eps)\n ami = (mi - emi) / denominator\n return ami" }, { "name": "adjusted_rand_score", + "unique_name": "adjusted_rand_score", "qname": "sklearn.metrics.cluster._supervised.adjusted_rand_score", + "unique_qname": "sklearn.metrics.cluster._supervised.adjusted_rand_score", "decorators": [], "parameters": [ { @@ -119123,7 +123049,9 @@ }, { "name": "check_clusterings", + "unique_name": "check_clusterings", "qname": "sklearn.metrics.cluster._supervised.check_clusterings", + "unique_qname": "sklearn.metrics.cluster._supervised.check_clusterings", "decorators": [], "parameters": [ { @@ -119155,7 +123083,9 @@ }, { "name": "completeness_score", + "unique_name": "completeness_score", "qname": "sklearn.metrics.cluster._supervised.completeness_score", + "unique_qname": "sklearn.metrics.cluster._supervised.completeness_score", "decorators": [], "parameters": [ { @@ -119187,7 +123117,9 @@ }, { "name": "contingency_matrix", + "unique_name": "contingency_matrix", "qname": "sklearn.metrics.cluster._supervised.contingency_matrix", + "unique_qname": "sklearn.metrics.cluster._supervised.contingency_matrix", "decorators": [], "parameters": [ { @@ -119249,7 +123181,9 @@ }, { "name": "entropy", + "unique_name": "entropy", "qname": "sklearn.metrics.cluster._supervised.entropy", + "unique_qname": "sklearn.metrics.cluster._supervised.entropy", "decorators": [], "parameters": [ { @@ -119271,7 +123205,9 @@ }, { "name": "fowlkes_mallows_score", + "unique_name": "fowlkes_mallows_score", "qname": "sklearn.metrics.cluster._supervised.fowlkes_mallows_score", + "unique_qname": "sklearn.metrics.cluster._supervised.fowlkes_mallows_score", "decorators": [], "parameters": [ { @@ -119313,7 +123249,9 @@ }, { "name": "homogeneity_completeness_v_measure", + "unique_name": "homogeneity_completeness_v_measure", "qname": "sklearn.metrics.cluster._supervised.homogeneity_completeness_v_measure", + "unique_qname": "sklearn.metrics.cluster._supervised.homogeneity_completeness_v_measure", "decorators": [], "parameters": [ { @@ -119355,7 +123293,9 @@ }, { "name": "homogeneity_score", + "unique_name": "homogeneity_score", "qname": "sklearn.metrics.cluster._supervised.homogeneity_score", + "unique_qname": "sklearn.metrics.cluster._supervised.homogeneity_score", "decorators": [], "parameters": [ { @@ -119387,7 +123327,9 @@ }, { "name": "mutual_info_score", + "unique_name": "mutual_info_score", "qname": "sklearn.metrics.cluster._supervised.mutual_info_score", + "unique_qname": "sklearn.metrics.cluster._supervised.mutual_info_score", "decorators": [], "parameters": [ { @@ -119397,7 +123339,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "int array, shape = [n_samples]", - "description": "A clustering of the data into disjoint subsets." + "description": "A clustering of the data into disjoint subsets, called :math:`U` in\nthe above formula." } }, { @@ -119407,7 +123349,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "int array-like of shape (n_samples,)", - "description": "A clustering of the data into disjoint subsets." + "description": "A clustering of the data into disjoint subsets, called :math:`V` in\nthe above formula." } }, { @@ -119423,13 +123365,15 @@ ], "results": [], "is_public": true, - "description": "Mutual Information between two clusterings.\n\nThe Mutual Information is a measure of the similarity between two labels of the same data. Where :math:`|U_i|` is the number of the samples in cluster :math:`U_i` and :math:`|V_j|` is the number of the samples in cluster :math:`V_j`, the Mutual Information between clusterings :math:`U` and :math:`V` is given as: .. math:: MI(U,V)=\\sum_{i=1}^{|U|} \\sum_{j=1}^{|V|} \\frac{|U_i\\cap V_j|}{N} \\log\\frac{N|U_i \\cap V_j|}{|U_i||V_j|} This metric is independent of the absolute values of the labels: a permutation of the class or cluster label values won't change the score value in any way. This metric is furthermore symmetric: switching ``label_true`` with ``label_pred`` will return the same score value. This can be useful to measure the agreement of two independent label assignments strategies on the same dataset when the real ground truth is not known. Read more in the :ref:`User Guide `.", - "docstring": "Mutual Information between two clusterings.\n\nThe Mutual Information is a measure of the similarity between two labels of\nthe same data. Where :math:`|U_i|` is the number of the samples\nin cluster :math:`U_i` and :math:`|V_j|` is the number of the\nsamples in cluster :math:`V_j`, the Mutual Information\nbetween clusterings :math:`U` and :math:`V` is given as:\n\n.. math::\n\n MI(U,V)=\\sum_{i=1}^{|U|} \\sum_{j=1}^{|V|} \\frac{|U_i\\cap V_j|}{N}\n \\log\\frac{N|U_i \\cap V_j|}{|U_i||V_j|}\n\nThis metric is independent of the absolute values of the labels:\na permutation of the class or cluster label values won't change the\nscore value in any way.\n\nThis metric is furthermore symmetric: switching ``label_true`` with\n``label_pred`` will return the same score value. This can be useful to\nmeasure the agreement of two independent label assignments strategies\non the same dataset when the real ground truth is not known.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\nlabels_true : int array, shape = [n_samples]\n A clustering of the data into disjoint subsets.\n\nlabels_pred : int array-like of shape (n_samples,)\n A clustering of the data into disjoint subsets.\n\ncontingency : {ndarray, sparse matrix} of shape (n_classes_true, n_classes_pred), default=None\n A contingency matrix given by the :func:`contingency_matrix` function.\n If value is ``None``, it will be computed, otherwise the given value is\n used, with ``labels_true`` and ``labels_pred`` ignored.\n\nReturns\n-------\nmi : float\n Mutual information, a non-negative value\n\nNotes\n-----\nThe logarithm used is the natural logarithm (base-e).\n\nSee Also\n--------\nadjusted_mutual_info_score : Adjusted against chance Mutual Information.\nnormalized_mutual_info_score : Normalized Mutual Information.", - "source_code": "\ndef mutual_info_score(labels_true, labels_pred, *, contingency=None):\n \"\"\"Mutual Information between two clusterings.\n\n The Mutual Information is a measure of the similarity between two labels of\n the same data. Where :math:`|U_i|` is the number of the samples\n in cluster :math:`U_i` and :math:`|V_j|` is the number of the\n samples in cluster :math:`V_j`, the Mutual Information\n between clusterings :math:`U` and :math:`V` is given as:\n\n .. math::\n\n MI(U,V)=\\sum_{i=1}^{|U|} \\sum_{j=1}^{|V|} \\frac{|U_i\\cap V_j|}{N}\n \\log\\frac{N|U_i \\cap V_j|}{|U_i||V_j|}\n\n This metric is independent of the absolute values of the labels:\n a permutation of the class or cluster label values won't change the\n score value in any way.\n\n This metric is furthermore symmetric: switching ``label_true`` with\n ``label_pred`` will return the same score value. This can be useful to\n measure the agreement of two independent label assignments strategies\n on the same dataset when the real ground truth is not known.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n labels_true : int array, shape = [n_samples]\n A clustering of the data into disjoint subsets.\n\n labels_pred : int array-like of shape (n_samples,)\n A clustering of the data into disjoint subsets.\n\n contingency : {ndarray, sparse matrix} of shape (n_classes_true, n_classes_pred), default=None\n A contingency matrix given by the :func:`contingency_matrix` function.\n If value is ``None``, it will be computed, otherwise the given value is\n used, with ``labels_true`` and ``labels_pred`` ignored.\n\n Returns\n -------\n mi : float\n Mutual information, a non-negative value\n\n Notes\n -----\n The logarithm used is the natural logarithm (base-e).\n\n See Also\n --------\n adjusted_mutual_info_score : Adjusted against chance Mutual Information.\n normalized_mutual_info_score : Normalized Mutual Information.\n \"\"\"\n if contingency is None:\n (labels_true, labels_pred) = check_clusterings(labels_true, labels_pred)\n contingency = contingency_matrix(labels_true, labels_pred, sparse=True)\n else:\n contingency = check_array(contingency, accept_sparse=['csr', 'csc', 'coo'], dtype=[int, np.int32, np.int64])\n if isinstance(contingency, np.ndarray):\n (nzx, nzy) = np.nonzero(contingency)\n nz_val = contingency[nzx, nzy]\n elif sp.issparse(contingency):\n (nzx, nzy, nz_val) = sp.find(contingency)\n else:\n raise ValueError(\"Unsupported type for 'contingency': %s\" % type(contingency))\n contingency_sum = contingency.sum()\n pi = np.ravel(contingency.sum(axis=1))\n pj = np.ravel(contingency.sum(axis=0))\n log_contingency_nm = np.log(nz_val)\n contingency_nm = nz_val / contingency_sum\n outer = pi.take(nzx).astype(np.int64, copy=False) * pj.take(nzy).astype(np.int64, copy=False)\n log_outer = -np.log(outer) + log(pi.sum()) + log(pj.sum())\n mi = contingency_nm * (log_contingency_nm - log(contingency_sum)) + contingency_nm * log_outer\n mi = np.where(np.abs(mi) < np.finfo(mi.dtype).eps, 0.0, mi)\n return np.clip(mi.sum(), 0.0, None)" + "description": "Mutual Information between two clusterings.\n\nThe Mutual Information is a measure of the similarity between two labels of the same data. Where :math:`|U_i|` is the number of the samples in cluster :math:`U_i` and :math:`|V_j|` is the number of the samples in cluster :math:`V_j`, the Mutual Information between clusterings :math:`U` and :math:`V` is given as: .. math:: MI(U,V)=\\sum_{i=1}^{|U|} \\sum_{j=1}^{|V|} \\frac{|U_i\\cap V_j|}{N} \\log\\frac{N|U_i \\cap V_j|}{|U_i||V_j|} This metric is independent of the absolute values of the labels: a permutation of the class or cluster label values won't change the score value in any way. This metric is furthermore symmetric: switching :math:`U` (i.e ``label_true``) with :math:`V` (i.e. ``label_pred``) will return the same score value. This can be useful to measure the agreement of two independent label assignments strategies on the same dataset when the real ground truth is not known. Read more in the :ref:`User Guide `.", + "docstring": "Mutual Information between two clusterings.\n\nThe Mutual Information is a measure of the similarity between two labels\nof the same data. Where :math:`|U_i|` is the number of the samples\nin cluster :math:`U_i` and :math:`|V_j|` is the number of the\nsamples in cluster :math:`V_j`, the Mutual Information\nbetween clusterings :math:`U` and :math:`V` is given as:\n\n.. math::\n\n MI(U,V)=\\sum_{i=1}^{|U|} \\sum_{j=1}^{|V|} \\frac{|U_i\\cap V_j|}{N}\n \\log\\frac{N|U_i \\cap V_j|}{|U_i||V_j|}\n\nThis metric is independent of the absolute values of the labels:\na permutation of the class or cluster label values won't change the\nscore value in any way.\n\nThis metric is furthermore symmetric: switching :math:`U` (i.e\n``label_true``) with :math:`V` (i.e. ``label_pred``) will return the\nsame score value. This can be useful to measure the agreement of two\nindependent label assignments strategies on the same dataset when the\nreal ground truth is not known.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\nlabels_true : int array, shape = [n_samples]\n A clustering of the data into disjoint subsets, called :math:`U` in\n the above formula.\n\nlabels_pred : int array-like of shape (n_samples,)\n A clustering of the data into disjoint subsets, called :math:`V` in\n the above formula.\n\ncontingency : {ndarray, sparse matrix} of shape (n_classes_true, n_classes_pred), default=None\n A contingency matrix given by the :func:`contingency_matrix` function.\n If value is ``None``, it will be computed, otherwise the given value is\n used, with ``labels_true`` and ``labels_pred`` ignored.\n\nReturns\n-------\nmi : float\n Mutual information, a non-negative value, measured in nats using the\n natural logarithm.\n\nNotes\n-----\nThe logarithm used is the natural logarithm (base-e).\n\nSee Also\n--------\nadjusted_mutual_info_score : Adjusted against chance Mutual Information.\nnormalized_mutual_info_score : Normalized Mutual Information.", + "source_code": "\ndef mutual_info_score(labels_true, labels_pred, *, contingency=None):\n \"\"\"Mutual Information between two clusterings.\n\n The Mutual Information is a measure of the similarity between two labels\n of the same data. Where :math:`|U_i|` is the number of the samples\n in cluster :math:`U_i` and :math:`|V_j|` is the number of the\n samples in cluster :math:`V_j`, the Mutual Information\n between clusterings :math:`U` and :math:`V` is given as:\n\n .. math::\n\n MI(U,V)=\\sum_{i=1}^{|U|} \\sum_{j=1}^{|V|} \\frac{|U_i\\cap V_j|}{N}\n \\log\\frac{N|U_i \\cap V_j|}{|U_i||V_j|}\n\n This metric is independent of the absolute values of the labels:\n a permutation of the class or cluster label values won't change the\n score value in any way.\n\n This metric is furthermore symmetric: switching :math:`U` (i.e\n ``label_true``) with :math:`V` (i.e. ``label_pred``) will return the\n same score value. This can be useful to measure the agreement of two\n independent label assignments strategies on the same dataset when the\n real ground truth is not known.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n labels_true : int array, shape = [n_samples]\n A clustering of the data into disjoint subsets, called :math:`U` in\n the above formula.\n\n labels_pred : int array-like of shape (n_samples,)\n A clustering of the data into disjoint subsets, called :math:`V` in\n the above formula.\n\n contingency : {ndarray, sparse matrix} of shape (n_classes_true, n_classes_pred), default=None\n A contingency matrix given by the :func:`contingency_matrix` function.\n If value is ``None``, it will be computed, otherwise the given value is\n used, with ``labels_true`` and ``labels_pred`` ignored.\n\n Returns\n -------\n mi : float\n Mutual information, a non-negative value, measured in nats using the\n natural logarithm.\n\n Notes\n -----\n The logarithm used is the natural logarithm (base-e).\n\n See Also\n --------\n adjusted_mutual_info_score : Adjusted against chance Mutual Information.\n normalized_mutual_info_score : Normalized Mutual Information.\n \"\"\"\n if contingency is None:\n (labels_true, labels_pred) = check_clusterings(labels_true, labels_pred)\n contingency = contingency_matrix(labels_true, labels_pred, sparse=True)\n else:\n contingency = check_array(contingency, accept_sparse=['csr', 'csc', 'coo'], dtype=[int, np.int32, np.int64])\n if isinstance(contingency, np.ndarray):\n (nzx, nzy) = np.nonzero(contingency)\n nz_val = contingency[nzx, nzy]\n elif sp.issparse(contingency):\n (nzx, nzy, nz_val) = sp.find(contingency)\n else:\n raise ValueError(\"Unsupported type for 'contingency': %s\" % type(contingency))\n contingency_sum = contingency.sum()\n pi = np.ravel(contingency.sum(axis=1))\n pj = np.ravel(contingency.sum(axis=0))\n log_contingency_nm = np.log(nz_val)\n contingency_nm = nz_val / contingency_sum\n outer = pi.take(nzx).astype(np.int64, copy=False) * pj.take(nzy).astype(np.int64, copy=False)\n log_outer = -np.log(outer) + log(pi.sum()) + log(pj.sum())\n mi = contingency_nm * (log_contingency_nm - log(contingency_sum)) + contingency_nm * log_outer\n mi = np.where(np.abs(mi) < np.finfo(mi.dtype).eps, 0.0, mi)\n return np.clip(mi.sum(), 0.0, None)" }, { "name": "normalized_mutual_info_score", + "unique_name": "normalized_mutual_info_score", "qname": "sklearn.metrics.cluster._supervised.normalized_mutual_info_score", + "unique_qname": "sklearn.metrics.cluster._supervised.normalized_mutual_info_score", "decorators": [], "parameters": [ { @@ -119466,12 +123410,14 @@ "results": [], "is_public": true, "description": "Normalized Mutual Information between two clusterings.\n\nNormalized Mutual Information (NMI) is a normalization of the Mutual Information (MI) score to scale the results between 0 (no mutual information) and 1 (perfect correlation). In this function, mutual information is normalized by some generalized mean of ``H(labels_true)`` and ``H(labels_pred))``, defined by the `average_method`. This measure is not adjusted for chance. Therefore :func:`adjusted_mutual_info_score` might be preferred. This metric is independent of the absolute values of the labels: a permutation of the class or cluster label values won't change the score value in any way. This metric is furthermore symmetric: switching ``label_true`` with ``label_pred`` will return the same score value. This can be useful to measure the agreement of two independent label assignments strategies on the same dataset when the real ground truth is not known. Read more in the :ref:`User Guide `.", - "docstring": "Normalized Mutual Information between two clusterings.\n\nNormalized Mutual Information (NMI) is a normalization of the Mutual\nInformation (MI) score to scale the results between 0 (no mutual\ninformation) and 1 (perfect correlation). In this function, mutual\ninformation is normalized by some generalized mean of ``H(labels_true)``\nand ``H(labels_pred))``, defined by the `average_method`.\n\nThis measure is not adjusted for chance. Therefore\n:func:`adjusted_mutual_info_score` might be preferred.\n\nThis metric is independent of the absolute values of the labels:\na permutation of the class or cluster label values won't change the\nscore value in any way.\n\nThis metric is furthermore symmetric: switching ``label_true`` with\n``label_pred`` will return the same score value. This can be useful to\nmeasure the agreement of two independent label assignments strategies\non the same dataset when the real ground truth is not known.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\nlabels_true : int array, shape = [n_samples]\n A clustering of the data into disjoint subsets.\n\nlabels_pred : int array-like of shape (n_samples,)\n A clustering of the data into disjoint subsets.\n\naverage_method : str, default='arithmetic'\n How to compute the normalizer in the denominator. Possible options\n are 'min', 'geometric', 'arithmetic', and 'max'.\n\n .. versionadded:: 0.20\n\n .. versionchanged:: 0.22\n The default value of ``average_method`` changed from 'geometric' to\n 'arithmetic'.\n\nReturns\n-------\nnmi : float\n score between 0.0 and 1.0. 1.0 stands for perfectly complete labeling\n\nSee Also\n--------\nv_measure_score : V-Measure (NMI with arithmetic mean option).\nadjusted_rand_score : Adjusted Rand Index.\nadjusted_mutual_info_score : Adjusted Mutual Information (adjusted\n against chance).\n\nExamples\n--------\n\nPerfect labelings are both homogeneous and complete, hence have\nscore 1.0::\n\n >>> from sklearn.metrics.cluster import normalized_mutual_info_score\n >>> normalized_mutual_info_score([0, 0, 1, 1], [0, 0, 1, 1])\n ... # doctest: +SKIP\n 1.0\n >>> normalized_mutual_info_score([0, 0, 1, 1], [1, 1, 0, 0])\n ... # doctest: +SKIP\n 1.0\n\nIf classes members are completely split across different clusters,\nthe assignment is totally in-complete, hence the NMI is null::\n\n >>> normalized_mutual_info_score([0, 0, 0, 0], [0, 1, 2, 3])\n ... # doctest: +SKIP\n 0.0", - "source_code": "\ndef normalized_mutual_info_score(labels_true, labels_pred, *, average_method='arithmetic'):\n \"\"\"Normalized Mutual Information between two clusterings.\n\n Normalized Mutual Information (NMI) is a normalization of the Mutual\n Information (MI) score to scale the results between 0 (no mutual\n information) and 1 (perfect correlation). In this function, mutual\n information is normalized by some generalized mean of ``H(labels_true)``\n and ``H(labels_pred))``, defined by the `average_method`.\n\n This measure is not adjusted for chance. Therefore\n :func:`adjusted_mutual_info_score` might be preferred.\n\n This metric is independent of the absolute values of the labels:\n a permutation of the class or cluster label values won't change the\n score value in any way.\n\n This metric is furthermore symmetric: switching ``label_true`` with\n ``label_pred`` will return the same score value. This can be useful to\n measure the agreement of two independent label assignments strategies\n on the same dataset when the real ground truth is not known.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n labels_true : int array, shape = [n_samples]\n A clustering of the data into disjoint subsets.\n\n labels_pred : int array-like of shape (n_samples,)\n A clustering of the data into disjoint subsets.\n\n average_method : str, default='arithmetic'\n How to compute the normalizer in the denominator. Possible options\n are 'min', 'geometric', 'arithmetic', and 'max'.\n\n .. versionadded:: 0.20\n\n .. versionchanged:: 0.22\n The default value of ``average_method`` changed from 'geometric' to\n 'arithmetic'.\n\n Returns\n -------\n nmi : float\n score between 0.0 and 1.0. 1.0 stands for perfectly complete labeling\n\n See Also\n --------\n v_measure_score : V-Measure (NMI with arithmetic mean option).\n adjusted_rand_score : Adjusted Rand Index.\n adjusted_mutual_info_score : Adjusted Mutual Information (adjusted\n against chance).\n\n Examples\n --------\n\n Perfect labelings are both homogeneous and complete, hence have\n score 1.0::\n\n >>> from sklearn.metrics.cluster import normalized_mutual_info_score\n >>> normalized_mutual_info_score([0, 0, 1, 1], [0, 0, 1, 1])\n ... # doctest: +SKIP\n 1.0\n >>> normalized_mutual_info_score([0, 0, 1, 1], [1, 1, 0, 0])\n ... # doctest: +SKIP\n 1.0\n\n If classes members are completely split across different clusters,\n the assignment is totally in-complete, hence the NMI is null::\n\n >>> normalized_mutual_info_score([0, 0, 0, 0], [0, 1, 2, 3])\n ... # doctest: +SKIP\n 0.0\n \"\"\"\n (labels_true, labels_pred) = check_clusterings(labels_true, labels_pred)\n classes = np.unique(labels_true)\n clusters = np.unique(labels_pred)\n if classes.shape[0] == clusters.shape[0] == 1 or classes.shape[0] == clusters.shape[0] == 0:\n return 1.0\n contingency = contingency_matrix(labels_true, labels_pred, sparse=True)\n contingency = contingency.astype(np.float64, **_astype_copy_false(contingency))\n mi = mutual_info_score(labels_true, labels_pred, contingency=contingency)\n (h_true, h_pred) = (entropy(labels_true), entropy(labels_pred))\n normalizer = _generalized_average(h_true, h_pred, average_method)\n normalizer = max(normalizer, np.finfo('float64').eps)\n nmi = mi / normalizer\n return nmi" + "docstring": "Normalized Mutual Information between two clusterings.\n\nNormalized Mutual Information (NMI) is a normalization of the Mutual\nInformation (MI) score to scale the results between 0 (no mutual\ninformation) and 1 (perfect correlation). In this function, mutual\ninformation is normalized by some generalized mean of ``H(labels_true)``\nand ``H(labels_pred))``, defined by the `average_method`.\n\nThis measure is not adjusted for chance. Therefore\n:func:`adjusted_mutual_info_score` might be preferred.\n\nThis metric is independent of the absolute values of the labels:\na permutation of the class or cluster label values won't change the\nscore value in any way.\n\nThis metric is furthermore symmetric: switching ``label_true`` with\n``label_pred`` will return the same score value. This can be useful to\nmeasure the agreement of two independent label assignments strategies\non the same dataset when the real ground truth is not known.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\nlabels_true : int array, shape = [n_samples]\n A clustering of the data into disjoint subsets.\n\nlabels_pred : int array-like of shape (n_samples,)\n A clustering of the data into disjoint subsets.\n\naverage_method : str, default='arithmetic'\n How to compute the normalizer in the denominator. Possible options\n are 'min', 'geometric', 'arithmetic', and 'max'.\n\n .. versionadded:: 0.20\n\n .. versionchanged:: 0.22\n The default value of ``average_method`` changed from 'geometric' to\n 'arithmetic'.\n\nReturns\n-------\nnmi : float\n Score between 0.0 and 1.0 in normalized nats (based on the natural\n logarithm). 1.0 stands for perfectly complete labeling.\n\nSee Also\n--------\nv_measure_score : V-Measure (NMI with arithmetic mean option).\nadjusted_rand_score : Adjusted Rand Index.\nadjusted_mutual_info_score : Adjusted Mutual Information (adjusted\n against chance).\n\nExamples\n--------\n\nPerfect labelings are both homogeneous and complete, hence have\nscore 1.0::\n\n >>> from sklearn.metrics.cluster import normalized_mutual_info_score\n >>> normalized_mutual_info_score([0, 0, 1, 1], [0, 0, 1, 1])\n ... # doctest: +SKIP\n 1.0\n >>> normalized_mutual_info_score([0, 0, 1, 1], [1, 1, 0, 0])\n ... # doctest: +SKIP\n 1.0\n\nIf classes members are completely split across different clusters,\nthe assignment is totally in-complete, hence the NMI is null::\n\n >>> normalized_mutual_info_score([0, 0, 0, 0], [0, 1, 2, 3])\n ... # doctest: +SKIP\n 0.0", + "source_code": "\ndef normalized_mutual_info_score(labels_true, labels_pred, *, average_method='arithmetic'):\n \"\"\"Normalized Mutual Information between two clusterings.\n\n Normalized Mutual Information (NMI) is a normalization of the Mutual\n Information (MI) score to scale the results between 0 (no mutual\n information) and 1 (perfect correlation). In this function, mutual\n information is normalized by some generalized mean of ``H(labels_true)``\n and ``H(labels_pred))``, defined by the `average_method`.\n\n This measure is not adjusted for chance. Therefore\n :func:`adjusted_mutual_info_score` might be preferred.\n\n This metric is independent of the absolute values of the labels:\n a permutation of the class or cluster label values won't change the\n score value in any way.\n\n This metric is furthermore symmetric: switching ``label_true`` with\n ``label_pred`` will return the same score value. This can be useful to\n measure the agreement of two independent label assignments strategies\n on the same dataset when the real ground truth is not known.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n labels_true : int array, shape = [n_samples]\n A clustering of the data into disjoint subsets.\n\n labels_pred : int array-like of shape (n_samples,)\n A clustering of the data into disjoint subsets.\n\n average_method : str, default='arithmetic'\n How to compute the normalizer in the denominator. Possible options\n are 'min', 'geometric', 'arithmetic', and 'max'.\n\n .. versionadded:: 0.20\n\n .. versionchanged:: 0.22\n The default value of ``average_method`` changed from 'geometric' to\n 'arithmetic'.\n\n Returns\n -------\n nmi : float\n Score between 0.0 and 1.0 in normalized nats (based on the natural\n logarithm). 1.0 stands for perfectly complete labeling.\n\n See Also\n --------\n v_measure_score : V-Measure (NMI with arithmetic mean option).\n adjusted_rand_score : Adjusted Rand Index.\n adjusted_mutual_info_score : Adjusted Mutual Information (adjusted\n against chance).\n\n Examples\n --------\n\n Perfect labelings are both homogeneous and complete, hence have\n score 1.0::\n\n >>> from sklearn.metrics.cluster import normalized_mutual_info_score\n >>> normalized_mutual_info_score([0, 0, 1, 1], [0, 0, 1, 1])\n ... # doctest: +SKIP\n 1.0\n >>> normalized_mutual_info_score([0, 0, 1, 1], [1, 1, 0, 0])\n ... # doctest: +SKIP\n 1.0\n\n If classes members are completely split across different clusters,\n the assignment is totally in-complete, hence the NMI is null::\n\n >>> normalized_mutual_info_score([0, 0, 0, 0], [0, 1, 2, 3])\n ... # doctest: +SKIP\n 0.0\n \"\"\"\n (labels_true, labels_pred) = check_clusterings(labels_true, labels_pred)\n classes = np.unique(labels_true)\n clusters = np.unique(labels_pred)\n if classes.shape[0] == clusters.shape[0] == 1 or classes.shape[0] == clusters.shape[0] == 0:\n return 1.0\n contingency = contingency_matrix(labels_true, labels_pred, sparse=True)\n contingency = contingency.astype(np.float64, **_astype_copy_false(contingency))\n mi = mutual_info_score(labels_true, labels_pred, contingency=contingency)\n (h_true, h_pred) = (entropy(labels_true), entropy(labels_pred))\n normalizer = _generalized_average(h_true, h_pred, average_method)\n normalizer = max(normalizer, np.finfo('float64').eps)\n nmi = mi / normalizer\n return nmi" }, { "name": "pair_confusion_matrix", + "unique_name": "pair_confusion_matrix", "qname": "sklearn.metrics.cluster._supervised.pair_confusion_matrix", + "unique_qname": "sklearn.metrics.cluster._supervised.pair_confusion_matrix", "decorators": [], "parameters": [ { @@ -119503,7 +123449,9 @@ }, { "name": "rand_score", + "unique_name": "rand_score", "qname": "sklearn.metrics.cluster._supervised.rand_score", + "unique_qname": "sklearn.metrics.cluster._supervised.rand_score", "decorators": [], "parameters": [ { @@ -119535,7 +123483,9 @@ }, { "name": "v_measure_score", + "unique_name": "v_measure_score", "qname": "sklearn.metrics.cluster._supervised.v_measure_score", + "unique_qname": "sklearn.metrics.cluster._supervised.v_measure_score", "decorators": [], "parameters": [ { @@ -119577,7 +123527,9 @@ }, { "name": "_silhouette_reduce", + "unique_name": "_silhouette_reduce", "qname": "sklearn.metrics.cluster._unsupervised._silhouette_reduce", + "unique_qname": "sklearn.metrics.cluster._unsupervised._silhouette_reduce", "decorators": [], "parameters": [ { @@ -119629,7 +123581,9 @@ }, { "name": "calinski_harabasz_score", + "unique_name": "calinski_harabasz_score", "qname": "sklearn.metrics.cluster._unsupervised.calinski_harabasz_score", + "unique_qname": "sklearn.metrics.cluster._unsupervised.calinski_harabasz_score", "decorators": [], "parameters": [ { @@ -119661,7 +123615,9 @@ }, { "name": "check_number_of_labels", + "unique_name": "check_number_of_labels", "qname": "sklearn.metrics.cluster._unsupervised.check_number_of_labels", + "unique_qname": "sklearn.metrics.cluster._unsupervised.check_number_of_labels", "decorators": [], "parameters": [ { @@ -119693,7 +123649,9 @@ }, { "name": "davies_bouldin_score", + "unique_name": "davies_bouldin_score", "qname": "sklearn.metrics.cluster._unsupervised.davies_bouldin_score", + "unique_qname": "sklearn.metrics.cluster._unsupervised.davies_bouldin_score", "decorators": [], "parameters": [ { @@ -119725,7 +123683,9 @@ }, { "name": "silhouette_samples", + "unique_name": "silhouette_samples", "qname": "sklearn.metrics.cluster._unsupervised.silhouette_samples", + "unique_qname": "sklearn.metrics.cluster._unsupervised.silhouette_samples", "decorators": [], "parameters": [ { @@ -119767,7 +123727,9 @@ }, { "name": "silhouette_score", + "unique_name": "silhouette_score", "qname": "sklearn.metrics.cluster._unsupervised.silhouette_score", + "unique_qname": "sklearn.metrics.cluster._unsupervised.silhouette_score", "decorators": [], "parameters": [ { @@ -119829,7 +123791,9 @@ }, { "name": "configuration", + "unique_name": "configuration", "qname": "sklearn.metrics.cluster.setup.configuration", + "unique_qname": "sklearn.metrics.cluster.setup.configuration", "decorators": [], "parameters": [ { @@ -119861,7 +123825,9 @@ }, { "name": "_argmin_min_reduce", + "unique_name": "_argmin_min_reduce", "qname": "sklearn.metrics.pairwise._argmin_min_reduce", + "unique_qname": "sklearn.metrics.pairwise._argmin_min_reduce", "decorators": [], "parameters": [ { @@ -119893,7 +123859,9 @@ }, { "name": "_check_chunk_size", + "unique_name": "_check_chunk_size", "qname": "sklearn.metrics.pairwise._check_chunk_size", + "unique_qname": "sklearn.metrics.pairwise._check_chunk_size", "decorators": [], "parameters": [ { @@ -119925,7 +123893,9 @@ }, { "name": "_dist_wrapper", + "unique_name": "_dist_wrapper", "qname": "sklearn.metrics.pairwise._dist_wrapper", + "unique_qname": "sklearn.metrics.pairwise._dist_wrapper", "decorators": [], "parameters": [ { @@ -119967,7 +123937,9 @@ }, { "name": "_euclidean_distances", + "unique_name": "_euclidean_distances", "qname": "sklearn.metrics.pairwise._euclidean_distances", + "unique_qname": "sklearn.metrics.pairwise._euclidean_distances", "decorators": [], "parameters": [ { @@ -120029,7 +124001,9 @@ }, { "name": "_euclidean_distances_upcast", + "unique_name": "_euclidean_distances_upcast", "qname": "sklearn.metrics.pairwise._euclidean_distances_upcast", + "unique_qname": "sklearn.metrics.pairwise._euclidean_distances_upcast", "decorators": [], "parameters": [ { @@ -120091,7 +124065,9 @@ }, { "name": "_pairwise_callable", + "unique_name": "_pairwise_callable", "qname": "sklearn.metrics.pairwise._pairwise_callable", + "unique_qname": "sklearn.metrics.pairwise._pairwise_callable", "decorators": [], "parameters": [ { @@ -120143,7 +124119,9 @@ }, { "name": "_parallel_pairwise", + "unique_name": "_parallel_pairwise", "qname": "sklearn.metrics.pairwise._parallel_pairwise", + "unique_qname": "sklearn.metrics.pairwise._parallel_pairwise", "decorators": [], "parameters": [ { @@ -120195,7 +124173,9 @@ }, { "name": "_precompute_metric_params", + "unique_name": "_precompute_metric_params", "qname": "sklearn.metrics.pairwise._precompute_metric_params", + "unique_qname": "sklearn.metrics.pairwise._precompute_metric_params", "decorators": [], "parameters": [ { @@ -120237,7 +124217,9 @@ }, { "name": "_return_float_dtype", + "unique_name": "_return_float_dtype", "qname": "sklearn.metrics.pairwise._return_float_dtype", + "unique_qname": "sklearn.metrics.pairwise._return_float_dtype", "decorators": [], "parameters": [ { @@ -120269,7 +124251,9 @@ }, { "name": "additive_chi2_kernel", + "unique_name": "additive_chi2_kernel", "qname": "sklearn.metrics.pairwise.additive_chi2_kernel", + "unique_qname": "sklearn.metrics.pairwise.additive_chi2_kernel", "decorators": [], "parameters": [ { @@ -120301,7 +124285,9 @@ }, { "name": "check_paired_arrays", + "unique_name": "check_paired_arrays", "qname": "sklearn.metrics.pairwise.check_paired_arrays", + "unique_qname": "sklearn.metrics.pairwise.check_paired_arrays", "decorators": [], "parameters": [ { @@ -120333,7 +124319,9 @@ }, { "name": "check_pairwise_arrays", + "unique_name": "check_pairwise_arrays", "qname": "sklearn.metrics.pairwise.check_pairwise_arrays", + "unique_qname": "sklearn.metrics.pairwise.check_pairwise_arrays", "decorators": [], "parameters": [ { @@ -120415,7 +124403,9 @@ }, { "name": "chi2_kernel", + "unique_name": "chi2_kernel", "qname": "sklearn.metrics.pairwise.chi2_kernel", + "unique_qname": "sklearn.metrics.pairwise.chi2_kernel", "decorators": [], "parameters": [ { @@ -120457,7 +124447,9 @@ }, { "name": "cosine_distances", + "unique_name": "cosine_distances", "qname": "sklearn.metrics.pairwise.cosine_distances", + "unique_qname": "sklearn.metrics.pairwise.cosine_distances", "decorators": [], "parameters": [ { @@ -120489,7 +124481,9 @@ }, { "name": "cosine_similarity", + "unique_name": "cosine_similarity", "qname": "sklearn.metrics.pairwise.cosine_similarity", + "unique_qname": "sklearn.metrics.pairwise.cosine_similarity", "decorators": [], "parameters": [ { @@ -120531,7 +124525,9 @@ }, { "name": "distance_metrics", + "unique_name": "distance_metrics", "qname": "sklearn.metrics.pairwise.distance_metrics", + "unique_qname": "sklearn.metrics.pairwise.distance_metrics", "decorators": [], "parameters": [], "results": [], @@ -120542,7 +124538,9 @@ }, { "name": "euclidean_distances", + "unique_name": "euclidean_distances", "qname": "sklearn.metrics.pairwise.euclidean_distances", + "unique_qname": "sklearn.metrics.pairwise.euclidean_distances", "decorators": [], "parameters": [ { @@ -120604,7 +124602,9 @@ }, { "name": "haversine_distances", + "unique_name": "haversine_distances", "qname": "sklearn.metrics.pairwise.haversine_distances", + "unique_qname": "sklearn.metrics.pairwise.haversine_distances", "decorators": [], "parameters": [ { @@ -120636,7 +124636,9 @@ }, { "name": "kernel_metrics", + "unique_name": "kernel_metrics", "qname": "sklearn.metrics.pairwise.kernel_metrics", + "unique_qname": "sklearn.metrics.pairwise.kernel_metrics", "decorators": [], "parameters": [], "results": [], @@ -120647,7 +124649,9 @@ }, { "name": "laplacian_kernel", + "unique_name": "laplacian_kernel", "qname": "sklearn.metrics.pairwise.laplacian_kernel", + "unique_qname": "sklearn.metrics.pairwise.laplacian_kernel", "decorators": [], "parameters": [ { @@ -120689,7 +124693,9 @@ }, { "name": "linear_kernel", + "unique_name": "linear_kernel", "qname": "sklearn.metrics.pairwise.linear_kernel", + "unique_qname": "sklearn.metrics.pairwise.linear_kernel", "decorators": [], "parameters": [ { @@ -120731,7 +124737,9 @@ }, { "name": "manhattan_distances", + "unique_name": "manhattan_distances", "qname": "sklearn.metrics.pairwise.manhattan_distances", + "unique_qname": "sklearn.metrics.pairwise.manhattan_distances", "decorators": [], "parameters": [ { @@ -120773,7 +124781,9 @@ }, { "name": "nan_euclidean_distances", + "unique_name": "nan_euclidean_distances", "qname": "sklearn.metrics.pairwise.nan_euclidean_distances", + "unique_qname": "sklearn.metrics.pairwise.nan_euclidean_distances", "decorators": [], "parameters": [ { @@ -120835,7 +124845,9 @@ }, { "name": "paired_cosine_distances", + "unique_name": "paired_cosine_distances", "qname": "sklearn.metrics.pairwise.paired_cosine_distances", + "unique_qname": "sklearn.metrics.pairwise.paired_cosine_distances", "decorators": [], "parameters": [ { @@ -120867,7 +124879,9 @@ }, { "name": "paired_distances", + "unique_name": "paired_distances", "qname": "sklearn.metrics.pairwise.paired_distances", + "unique_qname": "sklearn.metrics.pairwise.paired_distances", "decorators": [], "parameters": [ { @@ -120909,7 +124923,9 @@ }, { "name": "paired_euclidean_distances", + "unique_name": "paired_euclidean_distances", "qname": "sklearn.metrics.pairwise.paired_euclidean_distances", + "unique_qname": "sklearn.metrics.pairwise.paired_euclidean_distances", "decorators": [], "parameters": [ { @@ -120941,7 +124957,9 @@ }, { "name": "paired_manhattan_distances", + "unique_name": "paired_manhattan_distances", "qname": "sklearn.metrics.pairwise.paired_manhattan_distances", + "unique_qname": "sklearn.metrics.pairwise.paired_manhattan_distances", "decorators": [], "parameters": [ { @@ -120973,7 +124991,9 @@ }, { "name": "pairwise_distances", + "unique_name": "pairwise_distances", "qname": "sklearn.metrics.pairwise.pairwise_distances", + "unique_qname": "sklearn.metrics.pairwise.pairwise_distances", "decorators": [], "parameters": [ { @@ -121035,7 +125055,9 @@ }, { "name": "pairwise_distances_argmin", + "unique_name": "pairwise_distances_argmin", "qname": "sklearn.metrics.pairwise.pairwise_distances_argmin", + "unique_qname": "sklearn.metrics.pairwise.pairwise_distances_argmin", "decorators": [], "parameters": [ { @@ -121097,7 +125119,9 @@ }, { "name": "pairwise_distances_argmin_min", + "unique_name": "pairwise_distances_argmin_min", "qname": "sklearn.metrics.pairwise.pairwise_distances_argmin_min", + "unique_qname": "sklearn.metrics.pairwise.pairwise_distances_argmin_min", "decorators": [], "parameters": [ { @@ -121159,7 +125183,9 @@ }, { "name": "pairwise_distances_chunked", + "unique_name": "pairwise_distances_chunked", "qname": "sklearn.metrics.pairwise.pairwise_distances_chunked", + "unique_qname": "sklearn.metrics.pairwise.pairwise_distances_chunked", "decorators": [], "parameters": [ { @@ -121231,7 +125257,9 @@ }, { "name": "pairwise_kernels", + "unique_name": "pairwise_kernels", "qname": "sklearn.metrics.pairwise.pairwise_kernels", + "unique_qname": "sklearn.metrics.pairwise.pairwise_kernels", "decorators": [], "parameters": [ { @@ -121293,7 +125321,9 @@ }, { "name": "polynomial_kernel", + "unique_name": "polynomial_kernel", "qname": "sklearn.metrics.pairwise.polynomial_kernel", + "unique_qname": "sklearn.metrics.pairwise.polynomial_kernel", "decorators": [], "parameters": [ { @@ -121355,7 +125385,9 @@ }, { "name": "rbf_kernel", + "unique_name": "rbf_kernel", "qname": "sklearn.metrics.pairwise.rbf_kernel", + "unique_qname": "sklearn.metrics.pairwise.rbf_kernel", "decorators": [], "parameters": [ { @@ -121397,7 +125429,9 @@ }, { "name": "sigmoid_kernel", + "unique_name": "sigmoid_kernel", "qname": "sklearn.metrics.pairwise.sigmoid_kernel", + "unique_qname": "sklearn.metrics.pairwise.sigmoid_kernel", "decorators": [], "parameters": [ { @@ -121449,7 +125483,9 @@ }, { "name": "configuration", + "unique_name": "configuration", "qname": "sklearn.metrics.setup.configuration", + "unique_qname": "sklearn.metrics.setup.configuration", "decorators": [], "parameters": [ { @@ -121481,7 +125517,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.mixture._base.BaseMixture.__init__", + "unique_qname": "sklearn.mixture._base.BaseMixture.__init__", "decorators": [], "parameters": [ { @@ -121603,7 +125641,9 @@ }, { "name": "_check_initial_parameters", + "unique_name": "_check_initial_parameters", "qname": "sklearn.mixture._base.BaseMixture._check_initial_parameters", + "unique_qname": "sklearn.mixture._base.BaseMixture._check_initial_parameters", "decorators": [], "parameters": [ { @@ -121635,7 +125675,9 @@ }, { "name": "_check_parameters", + "unique_name": "_check_parameters", "qname": "sklearn.mixture._base.BaseMixture._check_parameters", + "unique_qname": "sklearn.mixture._base.BaseMixture._check_parameters", "decorators": ["abstractmethod"], "parameters": [ { @@ -121667,7 +125709,9 @@ }, { "name": "_e_step", + "unique_name": "_e_step", "qname": "sklearn.mixture._base.BaseMixture._e_step", + "unique_qname": "sklearn.mixture._base.BaseMixture._e_step", "decorators": [], "parameters": [ { @@ -121699,7 +125743,9 @@ }, { "name": "_estimate_log_prob", + "unique_name": "_estimate_log_prob", "qname": "sklearn.mixture._base.BaseMixture._estimate_log_prob", + "unique_qname": "sklearn.mixture._base.BaseMixture._estimate_log_prob", "decorators": ["abstractmethod"], "parameters": [ { @@ -121731,7 +125777,9 @@ }, { "name": "_estimate_log_prob_resp", + "unique_name": "_estimate_log_prob_resp", "qname": "sklearn.mixture._base.BaseMixture._estimate_log_prob_resp", + "unique_qname": "sklearn.mixture._base.BaseMixture._estimate_log_prob_resp", "decorators": [], "parameters": [ { @@ -121763,7 +125811,9 @@ }, { "name": "_estimate_log_weights", + "unique_name": "_estimate_log_weights", "qname": "sklearn.mixture._base.BaseMixture._estimate_log_weights", + "unique_qname": "sklearn.mixture._base.BaseMixture._estimate_log_weights", "decorators": ["abstractmethod"], "parameters": [ { @@ -121785,7 +125835,9 @@ }, { "name": "_estimate_weighted_log_prob", + "unique_name": "_estimate_weighted_log_prob", "qname": "sklearn.mixture._base.BaseMixture._estimate_weighted_log_prob", + "unique_qname": "sklearn.mixture._base.BaseMixture._estimate_weighted_log_prob", "decorators": [], "parameters": [ { @@ -121817,7 +125869,9 @@ }, { "name": "_get_parameters", + "unique_name": "_get_parameters", "qname": "sklearn.mixture._base.BaseMixture._get_parameters", + "unique_qname": "sklearn.mixture._base.BaseMixture._get_parameters", "decorators": ["abstractmethod"], "parameters": [ { @@ -121839,7 +125893,9 @@ }, { "name": "_initialize", + "unique_name": "_initialize", "qname": "sklearn.mixture._base.BaseMixture._initialize", + "unique_qname": "sklearn.mixture._base.BaseMixture._initialize", "decorators": ["abstractmethod"], "parameters": [ { @@ -121881,7 +125937,9 @@ }, { "name": "_initialize_parameters", + "unique_name": "_initialize_parameters", "qname": "sklearn.mixture._base.BaseMixture._initialize_parameters", + "unique_qname": "sklearn.mixture._base.BaseMixture._initialize_parameters", "decorators": [], "parameters": [ { @@ -121923,7 +125981,9 @@ }, { "name": "_m_step", + "unique_name": "_m_step", "qname": "sklearn.mixture._base.BaseMixture._m_step", + "unique_qname": "sklearn.mixture._base.BaseMixture._m_step", "decorators": ["abstractmethod"], "parameters": [ { @@ -121965,7 +126025,9 @@ }, { "name": "_print_verbose_msg_init_beg", + "unique_name": "_print_verbose_msg_init_beg", "qname": "sklearn.mixture._base.BaseMixture._print_verbose_msg_init_beg", + "unique_qname": "sklearn.mixture._base.BaseMixture._print_verbose_msg_init_beg", "decorators": [], "parameters": [ { @@ -121997,7 +126059,9 @@ }, { "name": "_print_verbose_msg_init_end", + "unique_name": "_print_verbose_msg_init_end", "qname": "sklearn.mixture._base.BaseMixture._print_verbose_msg_init_end", + "unique_qname": "sklearn.mixture._base.BaseMixture._print_verbose_msg_init_end", "decorators": [], "parameters": [ { @@ -122029,7 +126093,9 @@ }, { "name": "_print_verbose_msg_iter_end", + "unique_name": "_print_verbose_msg_iter_end", "qname": "sklearn.mixture._base.BaseMixture._print_verbose_msg_iter_end", + "unique_qname": "sklearn.mixture._base.BaseMixture._print_verbose_msg_iter_end", "decorators": [], "parameters": [ { @@ -122071,7 +126137,9 @@ }, { "name": "_set_parameters", + "unique_name": "_set_parameters", "qname": "sklearn.mixture._base.BaseMixture._set_parameters", + "unique_qname": "sklearn.mixture._base.BaseMixture._set_parameters", "decorators": ["abstractmethod"], "parameters": [ { @@ -122103,7 +126171,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.mixture._base.BaseMixture.fit", + "unique_qname": "sklearn.mixture._base.BaseMixture.fit", "decorators": [], "parameters": [ { @@ -122145,7 +126215,9 @@ }, { "name": "fit_predict", + "unique_name": "fit_predict", "qname": "sklearn.mixture._base.BaseMixture.fit_predict", + "unique_qname": "sklearn.mixture._base.BaseMixture.fit_predict", "decorators": [], "parameters": [ { @@ -122187,7 +126259,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.mixture._base.BaseMixture.predict", + "unique_qname": "sklearn.mixture._base.BaseMixture.predict", "decorators": [], "parameters": [ { @@ -122219,7 +126293,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.mixture._base.BaseMixture.predict_proba", + "unique_qname": "sklearn.mixture._base.BaseMixture.predict_proba", "decorators": [], "parameters": [ { @@ -122251,7 +126327,9 @@ }, { "name": "sample", + "unique_name": "sample", "qname": "sklearn.mixture._base.BaseMixture.sample", + "unique_qname": "sklearn.mixture._base.BaseMixture.sample", "decorators": [], "parameters": [ { @@ -122283,7 +126361,9 @@ }, { "name": "score", + "unique_name": "score", "qname": "sklearn.mixture._base.BaseMixture.score", + "unique_qname": "sklearn.mixture._base.BaseMixture.score", "decorators": [], "parameters": [ { @@ -122325,7 +126405,9 @@ }, { "name": "score_samples", + "unique_name": "score_samples", "qname": "sklearn.mixture._base.BaseMixture.score_samples", + "unique_qname": "sklearn.mixture._base.BaseMixture.score_samples", "decorators": [], "parameters": [ { @@ -122357,7 +126439,9 @@ }, { "name": "_check_shape", + "unique_name": "_check_shape", "qname": "sklearn.mixture._base._check_shape", + "unique_qname": "sklearn.mixture._base._check_shape", "decorators": [], "parameters": [ { @@ -122386,7 +126470,7 @@ "is_public": false, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "string", + "type": "str", "description": "" } } @@ -122394,12 +126478,14 @@ "results": [], "is_public": false, "description": "Validate the shape of the input parameter 'param'.", - "docstring": "Validate the shape of the input parameter 'param'.\n\nParameters\n----------\nparam : array\n\nparam_shape : tuple\n\nname : string", - "source_code": "\ndef _check_shape(param, param_shape, name):\n \"\"\"Validate the shape of the input parameter 'param'.\n\n Parameters\n ----------\n param : array\n\n param_shape : tuple\n\n name : string\n \"\"\"\n param = np.array(param)\n if param.shape != param_shape:\n raise ValueError(\"The parameter '%s' should have the shape of %s, but got %s\" % (name, param_shape, param.shape))" + "docstring": "Validate the shape of the input parameter 'param'.\n\nParameters\n----------\nparam : array\n\nparam_shape : tuple\n\nname : str", + "source_code": "\ndef _check_shape(param, param_shape, name):\n \"\"\"Validate the shape of the input parameter 'param'.\n\n Parameters\n ----------\n param : array\n\n param_shape : tuple\n\n name : str\n \"\"\"\n param = np.array(param)\n if param.shape != param_shape:\n raise ValueError(\"The parameter '%s' should have the shape of %s, but got %s\" % (name, param_shape, param.shape))" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture.__init__", + "unique_qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture.__init__", "decorators": [], "parameters": [ { @@ -122591,7 +126677,9 @@ }, { "name": "_check_means_parameters", + "unique_name": "_check_means_parameters", "qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._check_means_parameters", + "unique_qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._check_means_parameters", "decorators": [], "parameters": [ { @@ -122623,7 +126711,9 @@ }, { "name": "_check_parameters", + "unique_name": "_check_parameters", "qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._check_parameters", + "unique_qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._check_parameters", "decorators": [], "parameters": [ { @@ -122655,7 +126745,9 @@ }, { "name": "_check_precision_parameters", + "unique_name": "_check_precision_parameters", "qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._check_precision_parameters", + "unique_qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._check_precision_parameters", "decorators": [], "parameters": [ { @@ -122687,7 +126779,9 @@ }, { "name": "_check_weights_parameters", + "unique_name": "_check_weights_parameters", "qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._check_weights_parameters", + "unique_qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._check_weights_parameters", "decorators": [], "parameters": [ { @@ -122709,7 +126803,9 @@ }, { "name": "_checkcovariance_prior_parameter", + "unique_name": "_checkcovariance_prior_parameter", "qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._checkcovariance_prior_parameter", + "unique_qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._checkcovariance_prior_parameter", "decorators": [], "parameters": [ { @@ -122741,7 +126837,9 @@ }, { "name": "_compute_lower_bound", + "unique_name": "_compute_lower_bound", "qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._compute_lower_bound", + "unique_qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._compute_lower_bound", "decorators": [], "parameters": [ { @@ -122783,7 +126881,9 @@ }, { "name": "_estimate_log_prob", + "unique_name": "_estimate_log_prob", "qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._estimate_log_prob", + "unique_qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._estimate_log_prob", "decorators": [], "parameters": [ { @@ -122815,7 +126915,9 @@ }, { "name": "_estimate_log_weights", + "unique_name": "_estimate_log_weights", "qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._estimate_log_weights", + "unique_qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._estimate_log_weights", "decorators": [], "parameters": [ { @@ -122837,7 +126939,9 @@ }, { "name": "_estimate_means", + "unique_name": "_estimate_means", "qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._estimate_means", + "unique_qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._estimate_means", "decorators": [], "parameters": [ { @@ -122879,7 +126983,9 @@ }, { "name": "_estimate_precisions", + "unique_name": "_estimate_precisions", "qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._estimate_precisions", + "unique_qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._estimate_precisions", "decorators": [], "parameters": [ { @@ -122931,7 +127037,9 @@ }, { "name": "_estimate_weights", + "unique_name": "_estimate_weights", "qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._estimate_weights", + "unique_qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._estimate_weights", "decorators": [], "parameters": [ { @@ -122963,7 +127071,9 @@ }, { "name": "_estimate_wishart_diag", + "unique_name": "_estimate_wishart_diag", "qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._estimate_wishart_diag", + "unique_qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._estimate_wishart_diag", "decorators": [], "parameters": [ { @@ -123015,7 +127125,9 @@ }, { "name": "_estimate_wishart_full", + "unique_name": "_estimate_wishart_full", "qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._estimate_wishart_full", + "unique_qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._estimate_wishart_full", "decorators": [], "parameters": [ { @@ -123067,7 +127179,9 @@ }, { "name": "_estimate_wishart_spherical", + "unique_name": "_estimate_wishart_spherical", "qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._estimate_wishart_spherical", + "unique_qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._estimate_wishart_spherical", "decorators": [], "parameters": [ { @@ -123119,7 +127233,9 @@ }, { "name": "_estimate_wishart_tied", + "unique_name": "_estimate_wishart_tied", "qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._estimate_wishart_tied", + "unique_qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._estimate_wishart_tied", "decorators": [], "parameters": [ { @@ -123171,7 +127287,9 @@ }, { "name": "_get_parameters", + "unique_name": "_get_parameters", "qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._get_parameters", + "unique_qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._get_parameters", "decorators": [], "parameters": [ { @@ -123193,7 +127311,9 @@ }, { "name": "_initialize", + "unique_name": "_initialize", "qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._initialize", + "unique_qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._initialize", "decorators": [], "parameters": [ { @@ -123235,7 +127355,9 @@ }, { "name": "_m_step", + "unique_name": "_m_step", "qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._m_step", + "unique_qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._m_step", "decorators": [], "parameters": [ { @@ -123277,7 +127399,9 @@ }, { "name": "_set_parameters", + "unique_name": "_set_parameters", "qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._set_parameters", + "unique_qname": "sklearn.mixture._bayesian_mixture.BayesianGaussianMixture._set_parameters", "decorators": [], "parameters": [ { @@ -123309,7 +127433,9 @@ }, { "name": "_log_dirichlet_norm", + "unique_name": "_log_dirichlet_norm", "qname": "sklearn.mixture._bayesian_mixture._log_dirichlet_norm", + "unique_qname": "sklearn.mixture._bayesian_mixture._log_dirichlet_norm", "decorators": [], "parameters": [ { @@ -123331,7 +127457,9 @@ }, { "name": "_log_wishart_norm", + "unique_name": "_log_wishart_norm", "qname": "sklearn.mixture._bayesian_mixture._log_wishart_norm", + "unique_qname": "sklearn.mixture._bayesian_mixture._log_wishart_norm", "decorators": [], "parameters": [ { @@ -123373,7 +127501,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.mixture._gaussian_mixture.GaussianMixture.__init__", + "unique_qname": "sklearn.mixture._gaussian_mixture.GaussianMixture.__init__", "decorators": [], "parameters": [ { @@ -123535,7 +127665,9 @@ }, { "name": "_check_parameters", + "unique_name": "_check_parameters", "qname": "sklearn.mixture._gaussian_mixture.GaussianMixture._check_parameters", + "unique_qname": "sklearn.mixture._gaussian_mixture.GaussianMixture._check_parameters", "decorators": [], "parameters": [ { @@ -123567,7 +127699,9 @@ }, { "name": "_compute_lower_bound", + "unique_name": "_compute_lower_bound", "qname": "sklearn.mixture._gaussian_mixture.GaussianMixture._compute_lower_bound", + "unique_qname": "sklearn.mixture._gaussian_mixture.GaussianMixture._compute_lower_bound", "decorators": [], "parameters": [ { @@ -123609,7 +127743,9 @@ }, { "name": "_estimate_log_prob", + "unique_name": "_estimate_log_prob", "qname": "sklearn.mixture._gaussian_mixture.GaussianMixture._estimate_log_prob", + "unique_qname": "sklearn.mixture._gaussian_mixture.GaussianMixture._estimate_log_prob", "decorators": [], "parameters": [ { @@ -123641,7 +127777,9 @@ }, { "name": "_estimate_log_weights", + "unique_name": "_estimate_log_weights", "qname": "sklearn.mixture._gaussian_mixture.GaussianMixture._estimate_log_weights", + "unique_qname": "sklearn.mixture._gaussian_mixture.GaussianMixture._estimate_log_weights", "decorators": [], "parameters": [ { @@ -123663,7 +127801,9 @@ }, { "name": "_get_parameters", + "unique_name": "_get_parameters", "qname": "sklearn.mixture._gaussian_mixture.GaussianMixture._get_parameters", + "unique_qname": "sklearn.mixture._gaussian_mixture.GaussianMixture._get_parameters", "decorators": [], "parameters": [ { @@ -123685,7 +127825,9 @@ }, { "name": "_initialize", + "unique_name": "_initialize", "qname": "sklearn.mixture._gaussian_mixture.GaussianMixture._initialize", + "unique_qname": "sklearn.mixture._gaussian_mixture.GaussianMixture._initialize", "decorators": [], "parameters": [ { @@ -123727,7 +127869,9 @@ }, { "name": "_m_step", + "unique_name": "_m_step", "qname": "sklearn.mixture._gaussian_mixture.GaussianMixture._m_step", + "unique_qname": "sklearn.mixture._gaussian_mixture.GaussianMixture._m_step", "decorators": [], "parameters": [ { @@ -123769,7 +127913,9 @@ }, { "name": "_n_parameters", + "unique_name": "_n_parameters", "qname": "sklearn.mixture._gaussian_mixture.GaussianMixture._n_parameters", + "unique_qname": "sklearn.mixture._gaussian_mixture.GaussianMixture._n_parameters", "decorators": [], "parameters": [ { @@ -123791,7 +127937,9 @@ }, { "name": "_set_parameters", + "unique_name": "_set_parameters", "qname": "sklearn.mixture._gaussian_mixture.GaussianMixture._set_parameters", + "unique_qname": "sklearn.mixture._gaussian_mixture.GaussianMixture._set_parameters", "decorators": [], "parameters": [ { @@ -123823,7 +127971,9 @@ }, { "name": "aic", + "unique_name": "aic", "qname": "sklearn.mixture._gaussian_mixture.GaussianMixture.aic", + "unique_qname": "sklearn.mixture._gaussian_mixture.GaussianMixture.aic", "decorators": [], "parameters": [ { @@ -123855,7 +128005,9 @@ }, { "name": "bic", + "unique_name": "bic", "qname": "sklearn.mixture._gaussian_mixture.GaussianMixture.bic", + "unique_qname": "sklearn.mixture._gaussian_mixture.GaussianMixture.bic", "decorators": [], "parameters": [ { @@ -123887,7 +128039,9 @@ }, { "name": "_check_means", + "unique_name": "_check_means", "qname": "sklearn.mixture._gaussian_mixture._check_means", + "unique_qname": "sklearn.mixture._gaussian_mixture._check_means", "decorators": [], "parameters": [ { @@ -123929,7 +128083,9 @@ }, { "name": "_check_precision_matrix", + "unique_name": "_check_precision_matrix", "qname": "sklearn.mixture._gaussian_mixture._check_precision_matrix", + "unique_qname": "sklearn.mixture._gaussian_mixture._check_precision_matrix", "decorators": [], "parameters": [ { @@ -123961,7 +128117,9 @@ }, { "name": "_check_precision_positivity", + "unique_name": "_check_precision_positivity", "qname": "sklearn.mixture._gaussian_mixture._check_precision_positivity", + "unique_qname": "sklearn.mixture._gaussian_mixture._check_precision_positivity", "decorators": [], "parameters": [ { @@ -123993,7 +128151,9 @@ }, { "name": "_check_precisions", + "unique_name": "_check_precisions", "qname": "sklearn.mixture._gaussian_mixture._check_precisions", + "unique_qname": "sklearn.mixture._gaussian_mixture._check_precisions", "decorators": [], "parameters": [ { @@ -124012,7 +128172,7 @@ "is_public": false, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "string", + "type": "str", "description": "" } }, @@ -124040,12 +128200,14 @@ "results": [], "is_public": false, "description": "Validate user provided precisions.", - "docstring": "Validate user provided precisions.\n\nParameters\n----------\nprecisions : array-like\n 'full' : shape of (n_components, n_features, n_features)\n 'tied' : shape of (n_features, n_features)\n 'diag' : shape of (n_components, n_features)\n 'spherical' : shape of (n_components,)\n\ncovariance_type : string\n\nn_components : int\n Number of components.\n\nn_features : int\n Number of features.\n\nReturns\n-------\nprecisions : array", - "source_code": "\ndef _check_precisions(precisions, covariance_type, n_components, n_features):\n \"\"\"Validate user provided precisions.\n\n Parameters\n ----------\n precisions : array-like\n 'full' : shape of (n_components, n_features, n_features)\n 'tied' : shape of (n_features, n_features)\n 'diag' : shape of (n_components, n_features)\n 'spherical' : shape of (n_components,)\n\n covariance_type : string\n\n n_components : int\n Number of components.\n\n n_features : int\n Number of features.\n\n Returns\n -------\n precisions : array\n \"\"\"\n precisions = check_array(precisions, dtype=[np.float64, np.float32], ensure_2d=False, allow_nd=covariance_type == 'full')\n precisions_shape = {'full': (n_components, n_features, n_features), 'tied': (n_features, n_features), 'diag': (n_components, n_features), 'spherical': (n_components, )}\n _check_shape(precisions, precisions_shape[covariance_type], '%s precision' % covariance_type)\n _check_precisions = {'full': _check_precisions_full, 'tied': _check_precision_matrix, 'diag': _check_precision_positivity, 'spherical': _check_precision_positivity}\n _check_precisions[covariance_type](precisions, covariance_type)\n return precisions" + "docstring": "Validate user provided precisions.\n\nParameters\n----------\nprecisions : array-like\n 'full' : shape of (n_components, n_features, n_features)\n 'tied' : shape of (n_features, n_features)\n 'diag' : shape of (n_components, n_features)\n 'spherical' : shape of (n_components,)\n\ncovariance_type : str\n\nn_components : int\n Number of components.\n\nn_features : int\n Number of features.\n\nReturns\n-------\nprecisions : array", + "source_code": "\ndef _check_precisions(precisions, covariance_type, n_components, n_features):\n \"\"\"Validate user provided precisions.\n\n Parameters\n ----------\n precisions : array-like\n 'full' : shape of (n_components, n_features, n_features)\n 'tied' : shape of (n_features, n_features)\n 'diag' : shape of (n_components, n_features)\n 'spherical' : shape of (n_components,)\n\n covariance_type : str\n\n n_components : int\n Number of components.\n\n n_features : int\n Number of features.\n\n Returns\n -------\n precisions : array\n \"\"\"\n precisions = check_array(precisions, dtype=[np.float64, np.float32], ensure_2d=False, allow_nd=covariance_type == 'full')\n precisions_shape = {'full': (n_components, n_features, n_features), 'tied': (n_features, n_features), 'diag': (n_components, n_features), 'spherical': (n_components, )}\n _check_shape(precisions, precisions_shape[covariance_type], '%s precision' % covariance_type)\n _check_precisions = {'full': _check_precisions_full, 'tied': _check_precision_matrix, 'diag': _check_precision_positivity, 'spherical': _check_precision_positivity}\n _check_precisions[covariance_type](precisions, covariance_type)\n return precisions" }, { "name": "_check_precisions_full", + "unique_name": "_check_precisions_full", "qname": "sklearn.mixture._gaussian_mixture._check_precisions_full", + "unique_qname": "sklearn.mixture._gaussian_mixture._check_precisions_full", "decorators": [], "parameters": [ { @@ -124077,7 +128239,9 @@ }, { "name": "_check_weights", + "unique_name": "_check_weights", "qname": "sklearn.mixture._gaussian_mixture._check_weights", + "unique_qname": "sklearn.mixture._gaussian_mixture._check_weights", "decorators": [], "parameters": [ { @@ -124109,7 +128273,9 @@ }, { "name": "_compute_log_det_cholesky", + "unique_name": "_compute_log_det_cholesky", "qname": "sklearn.mixture._gaussian_mixture._compute_log_det_cholesky", + "unique_qname": "sklearn.mixture._gaussian_mixture._compute_log_det_cholesky", "decorators": [], "parameters": [ { @@ -124151,7 +128317,9 @@ }, { "name": "_compute_precision_cholesky", + "unique_name": "_compute_precision_cholesky", "qname": "sklearn.mixture._gaussian_mixture._compute_precision_cholesky", + "unique_qname": "sklearn.mixture._gaussian_mixture._compute_precision_cholesky", "decorators": [], "parameters": [ { @@ -124183,7 +128351,9 @@ }, { "name": "_estimate_gaussian_covariances_diag", + "unique_name": "_estimate_gaussian_covariances_diag", "qname": "sklearn.mixture._gaussian_mixture._estimate_gaussian_covariances_diag", + "unique_qname": "sklearn.mixture._gaussian_mixture._estimate_gaussian_covariances_diag", "decorators": [], "parameters": [ { @@ -124245,7 +128415,9 @@ }, { "name": "_estimate_gaussian_covariances_full", + "unique_name": "_estimate_gaussian_covariances_full", "qname": "sklearn.mixture._gaussian_mixture._estimate_gaussian_covariances_full", + "unique_qname": "sklearn.mixture._gaussian_mixture._estimate_gaussian_covariances_full", "decorators": [], "parameters": [ { @@ -124307,7 +128479,9 @@ }, { "name": "_estimate_gaussian_covariances_spherical", + "unique_name": "_estimate_gaussian_covariances_spherical", "qname": "sklearn.mixture._gaussian_mixture._estimate_gaussian_covariances_spherical", + "unique_qname": "sklearn.mixture._gaussian_mixture._estimate_gaussian_covariances_spherical", "decorators": [], "parameters": [ { @@ -124369,7 +128543,9 @@ }, { "name": "_estimate_gaussian_covariances_tied", + "unique_name": "_estimate_gaussian_covariances_tied", "qname": "sklearn.mixture._gaussian_mixture._estimate_gaussian_covariances_tied", + "unique_qname": "sklearn.mixture._gaussian_mixture._estimate_gaussian_covariances_tied", "decorators": [], "parameters": [ { @@ -124431,7 +128607,9 @@ }, { "name": "_estimate_gaussian_parameters", + "unique_name": "_estimate_gaussian_parameters", "qname": "sklearn.mixture._gaussian_mixture._estimate_gaussian_parameters", + "unique_qname": "sklearn.mixture._gaussian_mixture._estimate_gaussian_parameters", "decorators": [], "parameters": [ { @@ -124483,7 +128661,9 @@ }, { "name": "_estimate_log_gaussian_prob", + "unique_name": "_estimate_log_gaussian_prob", "qname": "sklearn.mixture._gaussian_mixture._estimate_log_gaussian_prob", + "unique_qname": "sklearn.mixture._gaussian_mixture._estimate_log_gaussian_prob", "decorators": [], "parameters": [ { @@ -124535,7 +128715,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._search.BaseSearchCV.__init__", + "unique_qname": "sklearn.model_selection._search.BaseSearchCV.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -124647,7 +128829,9 @@ }, { "name": "_check_refit_for_multimetric", + "unique_name": "_check_refit_for_multimetric", "qname": "sklearn.model_selection._search.BaseSearchCV._check_refit_for_multimetric", + "unique_qname": "sklearn.model_selection._search.BaseSearchCV._check_refit_for_multimetric", "decorators": [], "parameters": [ { @@ -124679,7 +128863,9 @@ }, { "name": "_estimator_type", + "unique_name": "_estimator_type@getter", "qname": "sklearn.model_selection._search.BaseSearchCV._estimator_type", + "unique_qname": "sklearn.model_selection._search.BaseSearchCV._estimator_type@getter", "decorators": ["property"], "parameters": [ { @@ -124701,7 +128887,9 @@ }, { "name": "_format_results", + "unique_name": "_format_results", "qname": "sklearn.model_selection._search.BaseSearchCV._format_results", + "unique_qname": "sklearn.model_selection._search.BaseSearchCV._format_results", "decorators": [], "parameters": [ { @@ -124763,7 +128951,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.model_selection._search.BaseSearchCV._more_tags", + "unique_qname": "sklearn.model_selection._search.BaseSearchCV._more_tags", "decorators": [], "parameters": [ { @@ -124785,7 +128975,9 @@ }, { "name": "_pairwise", + "unique_name": "_pairwise@getter", "qname": "sklearn.model_selection._search.BaseSearchCV._pairwise", + "unique_qname": "sklearn.model_selection._search.BaseSearchCV._pairwise@getter", "decorators": [ "deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -124810,7 +129002,9 @@ }, { "name": "_run_search", + "unique_name": "_run_search", "qname": "sklearn.model_selection._search.BaseSearchCV._run_search", + "unique_qname": "sklearn.model_selection._search.BaseSearchCV._run_search", "decorators": [], "parameters": [ { @@ -124842,7 +129036,9 @@ }, { "name": "_select_best_index", + "unique_name": "_select_best_index", "qname": "sklearn.model_selection._search.BaseSearchCV._select_best_index", + "unique_qname": "sklearn.model_selection._search.BaseSearchCV._select_best_index", "decorators": ["staticmethod"], "parameters": [ { @@ -124884,7 +129080,9 @@ }, { "name": "classes_", + "unique_name": "classes_@getter", "qname": "sklearn.model_selection._search.BaseSearchCV.classes_", + "unique_qname": "sklearn.model_selection._search.BaseSearchCV.classes_@getter", "decorators": ["property"], "parameters": [ { @@ -124906,7 +129104,9 @@ }, { "name": "decision_function", + "unique_name": "decision_function", "qname": "sklearn.model_selection._search.BaseSearchCV.decision_function", + "unique_qname": "sklearn.model_selection._search.BaseSearchCV.decision_function", "decorators": ["available_if(_estimator_has('decision_function'))"], "parameters": [ { @@ -124938,7 +129138,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.model_selection._search.BaseSearchCV.fit", + "unique_qname": "sklearn.model_selection._search.BaseSearchCV.fit", "decorators": [], "parameters": [ { @@ -124990,7 +129192,9 @@ }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.model_selection._search.BaseSearchCV.inverse_transform", + "unique_qname": "sklearn.model_selection._search.BaseSearchCV.inverse_transform", "decorators": ["available_if(_estimator_has('inverse_transform'))"], "parameters": [ { @@ -125022,7 +129226,9 @@ }, { "name": "n_features_in_", + "unique_name": "n_features_in_@getter", "qname": "sklearn.model_selection._search.BaseSearchCV.n_features_in_", + "unique_qname": "sklearn.model_selection._search.BaseSearchCV.n_features_in_@getter", "decorators": ["property"], "parameters": [ { @@ -125044,7 +129250,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.model_selection._search.BaseSearchCV.predict", + "unique_qname": "sklearn.model_selection._search.BaseSearchCV.predict", "decorators": ["available_if(_estimator_has('predict'))"], "parameters": [ { @@ -125076,7 +129284,9 @@ }, { "name": "predict_log_proba", + "unique_name": "predict_log_proba", "qname": "sklearn.model_selection._search.BaseSearchCV.predict_log_proba", + "unique_qname": "sklearn.model_selection._search.BaseSearchCV.predict_log_proba", "decorators": ["available_if(_estimator_has('predict_log_proba'))"], "parameters": [ { @@ -125108,7 +129318,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.model_selection._search.BaseSearchCV.predict_proba", + "unique_qname": "sklearn.model_selection._search.BaseSearchCV.predict_proba", "decorators": ["available_if(_estimator_has('predict_proba'))"], "parameters": [ { @@ -125140,7 +129352,9 @@ }, { "name": "score", + "unique_name": "score", "qname": "sklearn.model_selection._search.BaseSearchCV.score", + "unique_qname": "sklearn.model_selection._search.BaseSearchCV.score", "decorators": [], "parameters": [ { @@ -125182,7 +129396,9 @@ }, { "name": "score_samples", + "unique_name": "score_samples", "qname": "sklearn.model_selection._search.BaseSearchCV.score_samples", + "unique_qname": "sklearn.model_selection._search.BaseSearchCV.score_samples", "decorators": ["available_if(_estimator_has('score_samples'))"], "parameters": [ { @@ -125214,7 +129430,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.model_selection._search.BaseSearchCV.transform", + "unique_qname": "sklearn.model_selection._search.BaseSearchCV.transform", "decorators": ["available_if(_estimator_has('transform'))"], "parameters": [ { @@ -125246,7 +129464,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._search.GridSearchCV.__init__", + "unique_qname": "sklearn.model_selection._search.GridSearchCV.__init__", "decorators": [], "parameters": [ { @@ -125368,7 +129588,9 @@ }, { "name": "_run_search", + "unique_name": "_run_search", "qname": "sklearn.model_selection._search.GridSearchCV._run_search", + "unique_qname": "sklearn.model_selection._search.GridSearchCV._run_search", "decorators": [], "parameters": [ { @@ -125400,7 +129622,9 @@ }, { "name": "__getitem__", + "unique_name": "__getitem__", "qname": "sklearn.model_selection._search.ParameterGrid.__getitem__", + "unique_qname": "sklearn.model_selection._search.ParameterGrid.__getitem__", "decorators": [], "parameters": [ { @@ -125432,7 +129656,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._search.ParameterGrid.__init__", + "unique_qname": "sklearn.model_selection._search.ParameterGrid.__init__", "decorators": [], "parameters": [ { @@ -125464,7 +129690,9 @@ }, { "name": "__iter__", + "unique_name": "__iter__", "qname": "sklearn.model_selection._search.ParameterGrid.__iter__", + "unique_qname": "sklearn.model_selection._search.ParameterGrid.__iter__", "decorators": [], "parameters": [ { @@ -125486,7 +129714,9 @@ }, { "name": "__len__", + "unique_name": "__len__", "qname": "sklearn.model_selection._search.ParameterGrid.__len__", + "unique_qname": "sklearn.model_selection._search.ParameterGrid.__len__", "decorators": [], "parameters": [ { @@ -125508,7 +129738,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._search.ParameterSampler.__init__", + "unique_qname": "sklearn.model_selection._search.ParameterSampler.__init__", "decorators": [], "parameters": [ { @@ -125560,7 +129792,9 @@ }, { "name": "__iter__", + "unique_name": "__iter__", "qname": "sklearn.model_selection._search.ParameterSampler.__iter__", + "unique_qname": "sklearn.model_selection._search.ParameterSampler.__iter__", "decorators": [], "parameters": [ { @@ -125582,7 +129816,9 @@ }, { "name": "__len__", + "unique_name": "__len__", "qname": "sklearn.model_selection._search.ParameterSampler.__len__", + "unique_qname": "sklearn.model_selection._search.ParameterSampler.__len__", "decorators": [], "parameters": [ { @@ -125604,7 +129840,9 @@ }, { "name": "_is_all_lists", + "unique_name": "_is_all_lists", "qname": "sklearn.model_selection._search.ParameterSampler._is_all_lists", + "unique_qname": "sklearn.model_selection._search.ParameterSampler._is_all_lists", "decorators": [], "parameters": [ { @@ -125626,7 +129864,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._search.RandomizedSearchCV.__init__", + "unique_qname": "sklearn.model_selection._search.RandomizedSearchCV.__init__", "decorators": [], "parameters": [ { @@ -125645,7 +129885,7 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "estimator object.", + "type": "estimator object", "description": "A object of that type is instantiated for each grid point.\nThis is assumed to implement the scikit-learn estimator interface.\nEither estimator needs to provide a ``score`` function,\nor ``scoring`` must be passed." } }, @@ -125768,7 +130008,9 @@ }, { "name": "_run_search", + "unique_name": "_run_search", "qname": "sklearn.model_selection._search.RandomizedSearchCV._run_search", + "unique_qname": "sklearn.model_selection._search.RandomizedSearchCV._run_search", "decorators": [], "parameters": [ { @@ -125800,7 +130042,9 @@ }, { "name": "_check_param_grid", + "unique_name": "_check_param_grid", "qname": "sklearn.model_selection._search._check_param_grid", + "unique_qname": "sklearn.model_selection._search._check_param_grid", "decorators": [], "parameters": [ { @@ -125822,7 +130066,9 @@ }, { "name": "_check_refit", + "unique_name": "_check_refit", "qname": "sklearn.model_selection._search._check_refit", + "unique_qname": "sklearn.model_selection._search._check_refit", "decorators": [], "parameters": [ { @@ -125854,7 +130100,9 @@ }, { "name": "_estimator_has", + "unique_name": "_estimator_has", "qname": "sklearn.model_selection._search._estimator_has", + "unique_qname": "sklearn.model_selection._search._estimator_has", "decorators": [], "parameters": [ { @@ -125876,7 +130124,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._search_successive_halving.BaseSuccessiveHalving.__init__", + "unique_qname": "sklearn.model_selection._search_successive_halving.BaseSuccessiveHalving.__init__", "decorators": [], "parameters": [ { @@ -126038,7 +130288,9 @@ }, { "name": "_check_input_parameters", + "unique_name": "_check_input_parameters", "qname": "sklearn.model_selection._search_successive_halving.BaseSuccessiveHalving._check_input_parameters", + "unique_qname": "sklearn.model_selection._search_successive_halving.BaseSuccessiveHalving._check_input_parameters", "decorators": [], "parameters": [ { @@ -126090,7 +130342,9 @@ }, { "name": "_generate_candidate_params", + "unique_name": "_generate_candidate_params", "qname": "sklearn.model_selection._search_successive_halving.BaseSuccessiveHalving._generate_candidate_params", + "unique_qname": "sklearn.model_selection._search_successive_halving.BaseSuccessiveHalving._generate_candidate_params", "decorators": ["abstractmethod"], "parameters": [ { @@ -126112,7 +130366,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.model_selection._search_successive_halving.BaseSuccessiveHalving._more_tags", + "unique_qname": "sklearn.model_selection._search_successive_halving.BaseSuccessiveHalving._more_tags", "decorators": [], "parameters": [ { @@ -126134,7 +130390,9 @@ }, { "name": "_run_search", + "unique_name": "_run_search", "qname": "sklearn.model_selection._search_successive_halving.BaseSuccessiveHalving._run_search", + "unique_qname": "sklearn.model_selection._search_successive_halving.BaseSuccessiveHalving._run_search", "decorators": [], "parameters": [ { @@ -126166,7 +130424,9 @@ }, { "name": "_select_best_index", + "unique_name": "_select_best_index", "qname": "sklearn.model_selection._search_successive_halving.BaseSuccessiveHalving._select_best_index", + "unique_qname": "sklearn.model_selection._search_successive_halving.BaseSuccessiveHalving._select_best_index", "decorators": ["staticmethod"], "parameters": [ { @@ -126208,7 +130468,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.model_selection._search_successive_halving.BaseSuccessiveHalving.fit", + "unique_qname": "sklearn.model_selection._search_successive_halving.BaseSuccessiveHalving.fit", "decorators": [], "parameters": [ { @@ -126260,7 +130522,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._search_successive_halving.HalvingGridSearchCV.__init__", + "unique_qname": "sklearn.model_selection._search_successive_halving.HalvingGridSearchCV.__init__", "decorators": [], "parameters": [ { @@ -126432,7 +130696,9 @@ }, { "name": "_generate_candidate_params", + "unique_name": "_generate_candidate_params", "qname": "sklearn.model_selection._search_successive_halving.HalvingGridSearchCV._generate_candidate_params", + "unique_qname": "sklearn.model_selection._search_successive_halving.HalvingGridSearchCV._generate_candidate_params", "decorators": [], "parameters": [ { @@ -126454,7 +130720,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._search_successive_halving.HalvingRandomSearchCV.__init__", + "unique_qname": "sklearn.model_selection._search_successive_halving.HalvingRandomSearchCV.__init__", "decorators": [], "parameters": [ { @@ -126636,7 +130904,9 @@ }, { "name": "_generate_candidate_params", + "unique_name": "_generate_candidate_params", "qname": "sklearn.model_selection._search_successive_halving.HalvingRandomSearchCV._generate_candidate_params", + "unique_qname": "sklearn.model_selection._search_successive_halving.HalvingRandomSearchCV._generate_candidate_params", "decorators": [], "parameters": [ { @@ -126658,7 +130928,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._search_successive_halving._SubsampleMetaSplitter.__init__", + "unique_qname": "sklearn.model_selection._search_successive_halving._SubsampleMetaSplitter.__init__", "decorators": [], "parameters": [ { @@ -126720,7 +130992,9 @@ }, { "name": "split", + "unique_name": "split", "qname": "sklearn.model_selection._search_successive_halving._SubsampleMetaSplitter.split", + "unique_qname": "sklearn.model_selection._search_successive_halving._SubsampleMetaSplitter.split", "decorators": [], "parameters": [ { @@ -126772,7 +131046,9 @@ }, { "name": "_top_k", + "unique_name": "_top_k", "qname": "sklearn.model_selection._search_successive_halving._top_k", + "unique_qname": "sklearn.model_selection._search_successive_halving._top_k", "decorators": [], "parameters": [ { @@ -126814,7 +131090,9 @@ }, { "name": "__repr__", + "unique_name": "__repr__", "qname": "sklearn.model_selection._split.BaseCrossValidator.__repr__", + "unique_qname": "sklearn.model_selection._split.BaseCrossValidator.__repr__", "decorators": [], "parameters": [ { @@ -126836,7 +131114,9 @@ }, { "name": "_iter_test_indices", + "unique_name": "_iter_test_indices", "qname": "sklearn.model_selection._split.BaseCrossValidator._iter_test_indices", + "unique_qname": "sklearn.model_selection._split.BaseCrossValidator._iter_test_indices", "decorators": [], "parameters": [ { @@ -126888,7 +131168,9 @@ }, { "name": "_iter_test_masks", + "unique_name": "_iter_test_masks", "qname": "sklearn.model_selection._split.BaseCrossValidator._iter_test_masks", + "unique_qname": "sklearn.model_selection._split.BaseCrossValidator._iter_test_masks", "decorators": [], "parameters": [ { @@ -126940,7 +131222,9 @@ }, { "name": "get_n_splits", + "unique_name": "get_n_splits", "qname": "sklearn.model_selection._split.BaseCrossValidator.get_n_splits", + "unique_qname": "sklearn.model_selection._split.BaseCrossValidator.get_n_splits", "decorators": ["abstractmethod"], "parameters": [ { @@ -126992,7 +131276,9 @@ }, { "name": "split", + "unique_name": "split", "qname": "sklearn.model_selection._split.BaseCrossValidator.split", + "unique_qname": "sklearn.model_selection._split.BaseCrossValidator.split", "decorators": [], "parameters": [ { @@ -127044,7 +131330,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._split.BaseShuffleSplit.__init__", + "unique_qname": "sklearn.model_selection._split.BaseShuffleSplit.__init__", "decorators": [], "parameters": [ { @@ -127106,7 +131394,9 @@ }, { "name": "__repr__", + "unique_name": "__repr__", "qname": "sklearn.model_selection._split.BaseShuffleSplit.__repr__", + "unique_qname": "sklearn.model_selection._split.BaseShuffleSplit.__repr__", "decorators": [], "parameters": [ { @@ -127128,7 +131418,9 @@ }, { "name": "_iter_indices", + "unique_name": "_iter_indices", "qname": "sklearn.model_selection._split.BaseShuffleSplit._iter_indices", + "unique_qname": "sklearn.model_selection._split.BaseShuffleSplit._iter_indices", "decorators": ["abstractmethod"], "parameters": [ { @@ -127180,7 +131472,9 @@ }, { "name": "get_n_splits", + "unique_name": "get_n_splits", "qname": "sklearn.model_selection._split.BaseShuffleSplit.get_n_splits", + "unique_qname": "sklearn.model_selection._split.BaseShuffleSplit.get_n_splits", "decorators": [], "parameters": [ { @@ -127232,7 +131526,9 @@ }, { "name": "split", + "unique_name": "split", "qname": "sklearn.model_selection._split.BaseShuffleSplit.split", + "unique_qname": "sklearn.model_selection._split.BaseShuffleSplit.split", "decorators": [], "parameters": [ { @@ -127284,7 +131580,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._split.GroupKFold.__init__", + "unique_qname": "sklearn.model_selection._split.GroupKFold.__init__", "decorators": [], "parameters": [ { @@ -127316,7 +131614,9 @@ }, { "name": "_iter_test_indices", + "unique_name": "_iter_test_indices", "qname": "sklearn.model_selection._split.GroupKFold._iter_test_indices", + "unique_qname": "sklearn.model_selection._split.GroupKFold._iter_test_indices", "decorators": [], "parameters": [ { @@ -127368,7 +131668,9 @@ }, { "name": "split", + "unique_name": "split", "qname": "sklearn.model_selection._split.GroupKFold.split", + "unique_qname": "sklearn.model_selection._split.GroupKFold.split", "decorators": [], "parameters": [ { @@ -127420,7 +131722,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._split.GroupShuffleSplit.__init__", + "unique_qname": "sklearn.model_selection._split.GroupShuffleSplit.__init__", "decorators": [], "parameters": [ { @@ -127482,7 +131786,9 @@ }, { "name": "_iter_indices", + "unique_name": "_iter_indices", "qname": "sklearn.model_selection._split.GroupShuffleSplit._iter_indices", + "unique_qname": "sklearn.model_selection._split.GroupShuffleSplit._iter_indices", "decorators": [], "parameters": [ { @@ -127534,7 +131840,9 @@ }, { "name": "split", + "unique_name": "split", "qname": "sklearn.model_selection._split.GroupShuffleSplit.split", + "unique_qname": "sklearn.model_selection._split.GroupShuffleSplit.split", "decorators": [], "parameters": [ { @@ -127586,7 +131894,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._split.KFold.__init__", + "unique_qname": "sklearn.model_selection._split.KFold.__init__", "decorators": [], "parameters": [ { @@ -127638,7 +131948,9 @@ }, { "name": "_iter_test_indices", + "unique_name": "_iter_test_indices", "qname": "sklearn.model_selection._split.KFold._iter_test_indices", + "unique_qname": "sklearn.model_selection._split.KFold._iter_test_indices", "decorators": [], "parameters": [ { @@ -127690,7 +132002,9 @@ }, { "name": "_iter_test_masks", + "unique_name": "_iter_test_masks", "qname": "sklearn.model_selection._split.LeaveOneGroupOut._iter_test_masks", + "unique_qname": "sklearn.model_selection._split.LeaveOneGroupOut._iter_test_masks", "decorators": [], "parameters": [ { @@ -127742,7 +132056,9 @@ }, { "name": "get_n_splits", + "unique_name": "get_n_splits", "qname": "sklearn.model_selection._split.LeaveOneGroupOut.get_n_splits", + "unique_qname": "sklearn.model_selection._split.LeaveOneGroupOut.get_n_splits", "decorators": [], "parameters": [ { @@ -127794,7 +132110,9 @@ }, { "name": "split", + "unique_name": "split", "qname": "sklearn.model_selection._split.LeaveOneGroupOut.split", + "unique_qname": "sklearn.model_selection._split.LeaveOneGroupOut.split", "decorators": [], "parameters": [ { @@ -127846,7 +132164,9 @@ }, { "name": "_iter_test_indices", + "unique_name": "_iter_test_indices", "qname": "sklearn.model_selection._split.LeaveOneOut._iter_test_indices", + "unique_qname": "sklearn.model_selection._split.LeaveOneOut._iter_test_indices", "decorators": [], "parameters": [ { @@ -127898,7 +132218,9 @@ }, { "name": "get_n_splits", + "unique_name": "get_n_splits", "qname": "sklearn.model_selection._split.LeaveOneOut.get_n_splits", + "unique_qname": "sklearn.model_selection._split.LeaveOneOut.get_n_splits", "decorators": [], "parameters": [ { @@ -127950,7 +132272,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._split.LeavePGroupsOut.__init__", + "unique_qname": "sklearn.model_selection._split.LeavePGroupsOut.__init__", "decorators": [], "parameters": [ { @@ -127982,7 +132306,9 @@ }, { "name": "_iter_test_masks", + "unique_name": "_iter_test_masks", "qname": "sklearn.model_selection._split.LeavePGroupsOut._iter_test_masks", + "unique_qname": "sklearn.model_selection._split.LeavePGroupsOut._iter_test_masks", "decorators": [], "parameters": [ { @@ -128034,7 +132360,9 @@ }, { "name": "get_n_splits", + "unique_name": "get_n_splits", "qname": "sklearn.model_selection._split.LeavePGroupsOut.get_n_splits", + "unique_qname": "sklearn.model_selection._split.LeavePGroupsOut.get_n_splits", "decorators": [], "parameters": [ { @@ -128086,7 +132414,9 @@ }, { "name": "split", + "unique_name": "split", "qname": "sklearn.model_selection._split.LeavePGroupsOut.split", + "unique_qname": "sklearn.model_selection._split.LeavePGroupsOut.split", "decorators": [], "parameters": [ { @@ -128138,7 +132468,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._split.LeavePOut.__init__", + "unique_qname": "sklearn.model_selection._split.LeavePOut.__init__", "decorators": [], "parameters": [ { @@ -128170,7 +132502,9 @@ }, { "name": "_iter_test_indices", + "unique_name": "_iter_test_indices", "qname": "sklearn.model_selection._split.LeavePOut._iter_test_indices", + "unique_qname": "sklearn.model_selection._split.LeavePOut._iter_test_indices", "decorators": [], "parameters": [ { @@ -128222,7 +132556,9 @@ }, { "name": "get_n_splits", + "unique_name": "get_n_splits", "qname": "sklearn.model_selection._split.LeavePOut.get_n_splits", + "unique_qname": "sklearn.model_selection._split.LeavePOut.get_n_splits", "decorators": [], "parameters": [ { @@ -128274,7 +132610,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._split.PredefinedSplit.__init__", + "unique_qname": "sklearn.model_selection._split.PredefinedSplit.__init__", "decorators": [], "parameters": [ { @@ -128306,7 +132644,9 @@ }, { "name": "_iter_test_masks", + "unique_name": "_iter_test_masks", "qname": "sklearn.model_selection._split.PredefinedSplit._iter_test_masks", + "unique_qname": "sklearn.model_selection._split.PredefinedSplit._iter_test_masks", "decorators": [], "parameters": [ { @@ -128328,7 +132668,9 @@ }, { "name": "get_n_splits", + "unique_name": "get_n_splits", "qname": "sklearn.model_selection._split.PredefinedSplit.get_n_splits", + "unique_qname": "sklearn.model_selection._split.PredefinedSplit.get_n_splits", "decorators": [], "parameters": [ { @@ -128380,7 +132722,9 @@ }, { "name": "split", + "unique_name": "split", "qname": "sklearn.model_selection._split.PredefinedSplit.split", + "unique_qname": "sklearn.model_selection._split.PredefinedSplit.split", "decorators": [], "parameters": [ { @@ -128432,7 +132776,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._split.RepeatedKFold.__init__", + "unique_qname": "sklearn.model_selection._split.RepeatedKFold.__init__", "decorators": [], "parameters": [ { @@ -128484,7 +132830,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._split.RepeatedStratifiedKFold.__init__", + "unique_qname": "sklearn.model_selection._split.RepeatedStratifiedKFold.__init__", "decorators": [], "parameters": [ { @@ -128536,7 +132884,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._split.ShuffleSplit.__init__", + "unique_qname": "sklearn.model_selection._split.ShuffleSplit.__init__", "decorators": [], "parameters": [ { @@ -128598,7 +132948,9 @@ }, { "name": "_iter_indices", + "unique_name": "_iter_indices", "qname": "sklearn.model_selection._split.ShuffleSplit._iter_indices", + "unique_qname": "sklearn.model_selection._split.ShuffleSplit._iter_indices", "decorators": [], "parameters": [ { @@ -128650,7 +133002,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._split.StratifiedGroupKFold.__init__", + "unique_qname": "sklearn.model_selection._split.StratifiedGroupKFold.__init__", "decorators": [], "parameters": [ { @@ -128702,7 +133056,9 @@ }, { "name": "_find_best_fold", + "unique_name": "_find_best_fold", "qname": "sklearn.model_selection._split.StratifiedGroupKFold._find_best_fold", + "unique_qname": "sklearn.model_selection._split.StratifiedGroupKFold._find_best_fold", "decorators": [], "parameters": [ { @@ -128754,7 +133110,9 @@ }, { "name": "_iter_test_indices", + "unique_name": "_iter_test_indices", "qname": "sklearn.model_selection._split.StratifiedGroupKFold._iter_test_indices", + "unique_qname": "sklearn.model_selection._split.StratifiedGroupKFold._iter_test_indices", "decorators": [], "parameters": [ { @@ -128806,7 +133164,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._split.StratifiedKFold.__init__", + "unique_qname": "sklearn.model_selection._split.StratifiedKFold.__init__", "decorators": [], "parameters": [ { @@ -128858,7 +133218,9 @@ }, { "name": "_iter_test_masks", + "unique_name": "_iter_test_masks", "qname": "sklearn.model_selection._split.StratifiedKFold._iter_test_masks", + "unique_qname": "sklearn.model_selection._split.StratifiedKFold._iter_test_masks", "decorators": [], "parameters": [ { @@ -128910,7 +133272,9 @@ }, { "name": "_make_test_folds", + "unique_name": "_make_test_folds", "qname": "sklearn.model_selection._split.StratifiedKFold._make_test_folds", + "unique_qname": "sklearn.model_selection._split.StratifiedKFold._make_test_folds", "decorators": [], "parameters": [ { @@ -128952,7 +133316,9 @@ }, { "name": "split", + "unique_name": "split", "qname": "sklearn.model_selection._split.StratifiedKFold.split", + "unique_qname": "sklearn.model_selection._split.StratifiedKFold.split", "decorators": [], "parameters": [ { @@ -129004,7 +133370,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._split.StratifiedShuffleSplit.__init__", + "unique_qname": "sklearn.model_selection._split.StratifiedShuffleSplit.__init__", "decorators": [], "parameters": [ { @@ -129066,7 +133434,9 @@ }, { "name": "_iter_indices", + "unique_name": "_iter_indices", "qname": "sklearn.model_selection._split.StratifiedShuffleSplit._iter_indices", + "unique_qname": "sklearn.model_selection._split.StratifiedShuffleSplit._iter_indices", "decorators": [], "parameters": [ { @@ -129118,7 +133488,9 @@ }, { "name": "split", + "unique_name": "split", "qname": "sklearn.model_selection._split.StratifiedShuffleSplit.split", + "unique_qname": "sklearn.model_selection._split.StratifiedShuffleSplit.split", "decorators": [], "parameters": [ { @@ -129170,7 +133542,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._split.TimeSeriesSplit.__init__", + "unique_qname": "sklearn.model_selection._split.TimeSeriesSplit.__init__", "decorators": [], "parameters": [ { @@ -129232,7 +133606,9 @@ }, { "name": "split", + "unique_name": "split", "qname": "sklearn.model_selection._split.TimeSeriesSplit.split", + "unique_qname": "sklearn.model_selection._split.TimeSeriesSplit.split", "decorators": [], "parameters": [ { @@ -129284,7 +133660,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._split._BaseKFold.__init__", + "unique_qname": "sklearn.model_selection._split._BaseKFold.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -129336,7 +133714,9 @@ }, { "name": "get_n_splits", + "unique_name": "get_n_splits", "qname": "sklearn.model_selection._split._BaseKFold.get_n_splits", + "unique_qname": "sklearn.model_selection._split._BaseKFold.get_n_splits", "decorators": [], "parameters": [ { @@ -129388,7 +133768,9 @@ }, { "name": "split", + "unique_name": "split", "qname": "sklearn.model_selection._split._BaseKFold.split", + "unique_qname": "sklearn.model_selection._split._BaseKFold.split", "decorators": [], "parameters": [ { @@ -129440,7 +133822,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._split._CVIterableWrapper.__init__", + "unique_qname": "sklearn.model_selection._split._CVIterableWrapper.__init__", "decorators": [], "parameters": [ { @@ -129472,7 +133856,9 @@ }, { "name": "get_n_splits", + "unique_name": "get_n_splits", "qname": "sklearn.model_selection._split._CVIterableWrapper.get_n_splits", + "unique_qname": "sklearn.model_selection._split._CVIterableWrapper.get_n_splits", "decorators": [], "parameters": [ { @@ -129524,7 +133910,9 @@ }, { "name": "split", + "unique_name": "split", "qname": "sklearn.model_selection._split._CVIterableWrapper.split", + "unique_qname": "sklearn.model_selection._split._CVIterableWrapper.split", "decorators": [], "parameters": [ { @@ -129576,7 +133964,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.model_selection._split._RepeatedSplits.__init__", + "unique_qname": "sklearn.model_selection._split._RepeatedSplits.__init__", "decorators": [], "parameters": [ { @@ -129628,7 +134018,9 @@ }, { "name": "__repr__", + "unique_name": "__repr__", "qname": "sklearn.model_selection._split._RepeatedSplits.__repr__", + "unique_qname": "sklearn.model_selection._split._RepeatedSplits.__repr__", "decorators": [], "parameters": [ { @@ -129650,7 +134042,9 @@ }, { "name": "get_n_splits", + "unique_name": "get_n_splits", "qname": "sklearn.model_selection._split._RepeatedSplits.get_n_splits", + "unique_qname": "sklearn.model_selection._split._RepeatedSplits.get_n_splits", "decorators": [], "parameters": [ { @@ -129702,7 +134096,9 @@ }, { "name": "split", + "unique_name": "split", "qname": "sklearn.model_selection._split._RepeatedSplits.split", + "unique_qname": "sklearn.model_selection._split._RepeatedSplits.split", "decorators": [], "parameters": [ { @@ -129754,7 +134150,9 @@ }, { "name": "_build_repr", + "unique_name": "_build_repr", "qname": "sklearn.model_selection._split._build_repr", + "unique_qname": "sklearn.model_selection._split._build_repr", "decorators": [], "parameters": [ { @@ -129776,7 +134174,9 @@ }, { "name": "_validate_shuffle_split", + "unique_name": "_validate_shuffle_split", "qname": "sklearn.model_selection._split._validate_shuffle_split", + "unique_qname": "sklearn.model_selection._split._validate_shuffle_split", "decorators": [], "parameters": [ { @@ -129828,7 +134228,9 @@ }, { "name": "_yields_constant_splits", + "unique_name": "_yields_constant_splits", "qname": "sklearn.model_selection._split._yields_constant_splits", + "unique_qname": "sklearn.model_selection._split._yields_constant_splits", "decorators": [], "parameters": [ { @@ -129850,7 +134252,9 @@ }, { "name": "check_cv", + "unique_name": "check_cv", "qname": "sklearn.model_selection._split.check_cv", + "unique_qname": "sklearn.model_selection._split.check_cv", "decorators": [], "parameters": [ { @@ -129892,7 +134296,9 @@ }, { "name": "train_test_split", + "unique_name": "train_test_split", "qname": "sklearn.model_selection._split.train_test_split", + "unique_qname": "sklearn.model_selection._split.train_test_split", "decorators": [], "parameters": [ { @@ -129954,7 +134360,9 @@ }, { "name": "_aggregate_score_dicts", + "unique_name": "_aggregate_score_dicts", "qname": "sklearn.model_selection._validation._aggregate_score_dicts", + "unique_qname": "sklearn.model_selection._validation._aggregate_score_dicts", "decorators": [], "parameters": [ { @@ -129976,7 +134384,9 @@ }, { "name": "_check_is_permutation", + "unique_name": "_check_is_permutation", "qname": "sklearn.model_selection._validation._check_is_permutation", + "unique_qname": "sklearn.model_selection._validation._check_is_permutation", "decorators": [], "parameters": [ { @@ -130008,7 +134418,9 @@ }, { "name": "_enforce_prediction_order", + "unique_name": "_enforce_prediction_order", "qname": "sklearn.model_selection._validation._enforce_prediction_order", + "unique_qname": "sklearn.model_selection._validation._enforce_prediction_order", "decorators": [], "parameters": [ { @@ -130060,7 +134472,9 @@ }, { "name": "_fit_and_predict", + "unique_name": "_fit_and_predict", "qname": "sklearn.model_selection._validation._fit_and_predict", + "unique_qname": "sklearn.model_selection._validation._fit_and_predict", "decorators": [], "parameters": [ { @@ -130152,7 +134566,9 @@ }, { "name": "_fit_and_score", + "unique_name": "_fit_and_score", "qname": "sklearn.model_selection._validation._fit_and_score", + "unique_qname": "sklearn.model_selection._validation._fit_and_score", "decorators": [], "parameters": [ { @@ -130334,7 +134750,9 @@ }, { "name": "_incremental_fit_estimator", + "unique_name": "_incremental_fit_estimator", "qname": "sklearn.model_selection._validation._incremental_fit_estimator", + "unique_qname": "sklearn.model_selection._validation._incremental_fit_estimator", "decorators": [], "parameters": [ { @@ -130466,7 +134884,9 @@ }, { "name": "_insert_error_scores", + "unique_name": "_insert_error_scores", "qname": "sklearn.model_selection._validation._insert_error_scores", + "unique_qname": "sklearn.model_selection._validation._insert_error_scores", "decorators": [], "parameters": [ { @@ -130498,7 +134918,9 @@ }, { "name": "_normalize_score_results", + "unique_name": "_normalize_score_results", "qname": "sklearn.model_selection._validation._normalize_score_results", + "unique_qname": "sklearn.model_selection._validation._normalize_score_results", "decorators": [], "parameters": [ { @@ -130530,7 +134952,9 @@ }, { "name": "_permutation_test_score", + "unique_name": "_permutation_test_score", "qname": "sklearn.model_selection._validation._permutation_test_score", + "unique_qname": "sklearn.model_selection._validation._permutation_test_score", "decorators": [], "parameters": [ { @@ -130612,7 +135036,9 @@ }, { "name": "_score", + "unique_name": "_score", "qname": "sklearn.model_selection._validation._score", + "unique_qname": "sklearn.model_selection._validation._score", "decorators": [], "parameters": [ { @@ -130674,7 +135100,9 @@ }, { "name": "_shuffle", + "unique_name": "_shuffle", "qname": "sklearn.model_selection._validation._shuffle", + "unique_qname": "sklearn.model_selection._validation._shuffle", "decorators": [], "parameters": [ { @@ -130716,7 +135144,9 @@ }, { "name": "_translate_train_sizes", + "unique_name": "_translate_train_sizes", "qname": "sklearn.model_selection._validation._translate_train_sizes", + "unique_qname": "sklearn.model_selection._validation._translate_train_sizes", "decorators": [], "parameters": [ { @@ -130748,7 +135178,9 @@ }, { "name": "_warn_about_fit_failures", + "unique_name": "_warn_about_fit_failures", "qname": "sklearn.model_selection._validation._warn_about_fit_failures", + "unique_qname": "sklearn.model_selection._validation._warn_about_fit_failures", "decorators": [], "parameters": [ { @@ -130780,7 +135212,9 @@ }, { "name": "cross_val_predict", + "unique_name": "cross_val_predict", "qname": "sklearn.model_selection._validation.cross_val_predict", + "unique_qname": "sklearn.model_selection._validation.cross_val_predict", "decorators": [], "parameters": [ { @@ -130892,7 +135326,9 @@ }, { "name": "cross_val_score", + "unique_name": "cross_val_score", "qname": "sklearn.model_selection._validation.cross_val_score", + "unique_qname": "sklearn.model_selection._validation.cross_val_score", "decorators": [], "parameters": [ { @@ -131014,7 +135450,9 @@ }, { "name": "cross_validate", + "unique_name": "cross_validate", "qname": "sklearn.model_selection._validation.cross_validate", + "unique_qname": "sklearn.model_selection._validation.cross_validate", "decorators": [], "parameters": [ { @@ -131156,7 +135594,9 @@ }, { "name": "learning_curve", + "unique_name": "learning_curve", "qname": "sklearn.model_selection._validation.learning_curve", + "unique_qname": "sklearn.model_selection._validation.learning_curve", "decorators": [], "parameters": [ { @@ -131328,7 +135768,9 @@ }, { "name": "permutation_test_score", + "unique_name": "permutation_test_score", "qname": "sklearn.model_selection._validation.permutation_test_score", + "unique_qname": "sklearn.model_selection._validation.permutation_test_score", "decorators": [], "parameters": [ { @@ -131450,7 +135892,9 @@ }, { "name": "validation_curve", + "unique_name": "validation_curve", "qname": "sklearn.model_selection._validation.validation_curve", + "unique_qname": "sklearn.model_selection._validation.validation_curve", "decorators": [], "parameters": [ { @@ -131592,7 +136036,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.multiclass.OneVsOneClassifier.__init__", + "unique_qname": "sklearn.multiclass.OneVsOneClassifier.__init__", "decorators": [], "parameters": [ { @@ -131634,7 +136080,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.multiclass.OneVsOneClassifier._more_tags", + "unique_qname": "sklearn.multiclass.OneVsOneClassifier._more_tags", "decorators": [], "parameters": [ { @@ -131656,7 +136104,9 @@ }, { "name": "_pairwise", + "unique_name": "_pairwise@getter", "qname": "sklearn.multiclass.OneVsOneClassifier._pairwise", + "unique_qname": "sklearn.multiclass.OneVsOneClassifier._pairwise@getter", "decorators": [ "deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -131681,7 +136131,9 @@ }, { "name": "decision_function", + "unique_name": "decision_function", "qname": "sklearn.multiclass.OneVsOneClassifier.decision_function", + "unique_qname": "sklearn.multiclass.OneVsOneClassifier.decision_function", "decorators": [], "parameters": [ { @@ -131713,7 +136165,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.multiclass.OneVsOneClassifier.fit", + "unique_qname": "sklearn.multiclass.OneVsOneClassifier.fit", "decorators": [], "parameters": [ { @@ -131755,7 +136209,9 @@ }, { "name": "n_classes_", + "unique_name": "n_classes_@getter", "qname": "sklearn.multiclass.OneVsOneClassifier.n_classes_", + "unique_qname": "sklearn.multiclass.OneVsOneClassifier.n_classes_@getter", "decorators": ["property"], "parameters": [ { @@ -131777,7 +136233,9 @@ }, { "name": "partial_fit", + "unique_name": "partial_fit", "qname": "sklearn.multiclass.OneVsOneClassifier.partial_fit", + "unique_qname": "sklearn.multiclass.OneVsOneClassifier.partial_fit", "decorators": ["available_if(_estimators_has('partial_fit'))"], "parameters": [ { @@ -131829,7 +136287,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.multiclass.OneVsOneClassifier.predict", + "unique_qname": "sklearn.multiclass.OneVsOneClassifier.predict", "decorators": [], "parameters": [ { @@ -131861,7 +136321,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.multiclass.OneVsRestClassifier.__init__", + "unique_qname": "sklearn.multiclass.OneVsRestClassifier.__init__", "decorators": [], "parameters": [ { @@ -131903,7 +136365,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.multiclass.OneVsRestClassifier._more_tags", + "unique_qname": "sklearn.multiclass.OneVsRestClassifier._more_tags", "decorators": [], "parameters": [ { @@ -131925,7 +136389,9 @@ }, { "name": "_pairwise", + "unique_name": "_pairwise@getter", "qname": "sklearn.multiclass.OneVsRestClassifier._pairwise", + "unique_qname": "sklearn.multiclass.OneVsRestClassifier._pairwise@getter", "decorators": [ "deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -131950,7 +136416,9 @@ }, { "name": "coef_", + "unique_name": "coef_@getter", "qname": "sklearn.multiclass.OneVsRestClassifier.coef_", + "unique_qname": "sklearn.multiclass.OneVsRestClassifier.coef_@getter", "decorators": [ "deprecated('Attribute `coef_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26). If you observe this warning while using RFE or SelectFromModel, use the importance_getter parameter instead.')", "property" @@ -131975,7 +136443,9 @@ }, { "name": "decision_function", + "unique_name": "decision_function", "qname": "sklearn.multiclass.OneVsRestClassifier.decision_function", + "unique_qname": "sklearn.multiclass.OneVsRestClassifier.decision_function", "decorators": [ "available_if(_estimators_has('decision_function'))" ], @@ -132009,7 +136479,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.multiclass.OneVsRestClassifier.fit", + "unique_qname": "sklearn.multiclass.OneVsRestClassifier.fit", "decorators": [], "parameters": [ { @@ -132051,7 +136523,9 @@ }, { "name": "intercept_", + "unique_name": "intercept_@getter", "qname": "sklearn.multiclass.OneVsRestClassifier.intercept_", + "unique_qname": "sklearn.multiclass.OneVsRestClassifier.intercept_@getter", "decorators": [ "deprecated('Attribute `intercept_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26). If you observe this warning while using RFE or SelectFromModel, use the importance_getter parameter instead.')", "property" @@ -132076,7 +136550,9 @@ }, { "name": "multilabel_", + "unique_name": "multilabel_@getter", "qname": "sklearn.multiclass.OneVsRestClassifier.multilabel_", + "unique_qname": "sklearn.multiclass.OneVsRestClassifier.multilabel_@getter", "decorators": ["property"], "parameters": [ { @@ -132098,7 +136574,9 @@ }, { "name": "n_classes_", + "unique_name": "n_classes_@getter", "qname": "sklearn.multiclass.OneVsRestClassifier.n_classes_", + "unique_qname": "sklearn.multiclass.OneVsRestClassifier.n_classes_@getter", "decorators": ["property"], "parameters": [ { @@ -132120,7 +136598,9 @@ }, { "name": "partial_fit", + "unique_name": "partial_fit", "qname": "sklearn.multiclass.OneVsRestClassifier.partial_fit", + "unique_qname": "sklearn.multiclass.OneVsRestClassifier.partial_fit", "decorators": ["available_if(_estimators_has('partial_fit'))"], "parameters": [ { @@ -132172,7 +136652,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.multiclass.OneVsRestClassifier.predict", + "unique_qname": "sklearn.multiclass.OneVsRestClassifier.predict", "decorators": [], "parameters": [ { @@ -132204,7 +136686,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.multiclass.OneVsRestClassifier.predict_proba", + "unique_qname": "sklearn.multiclass.OneVsRestClassifier.predict_proba", "decorators": ["available_if(_estimators_has('predict_proba'))"], "parameters": [ { @@ -132236,7 +136720,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.multiclass.OutputCodeClassifier.__init__", + "unique_qname": "sklearn.multiclass.OutputCodeClassifier.__init__", "decorators": [], "parameters": [ { @@ -132298,7 +136784,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.multiclass.OutputCodeClassifier.fit", + "unique_qname": "sklearn.multiclass.OutputCodeClassifier.fit", "decorators": [], "parameters": [ { @@ -132340,7 +136828,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.multiclass.OutputCodeClassifier.predict", + "unique_qname": "sklearn.multiclass.OutputCodeClassifier.predict", "decorators": [], "parameters": [ { @@ -132372,7 +136862,9 @@ }, { "name": "decision_function", + "unique_name": "decision_function", "qname": "sklearn.multiclass._ConstantPredictor.decision_function", + "unique_qname": "sklearn.multiclass._ConstantPredictor.decision_function", "decorators": [], "parameters": [ { @@ -132404,7 +136896,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.multiclass._ConstantPredictor.fit", + "unique_qname": "sklearn.multiclass._ConstantPredictor.fit", "decorators": [], "parameters": [ { @@ -132446,7 +136940,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.multiclass._ConstantPredictor.predict", + "unique_qname": "sklearn.multiclass._ConstantPredictor.predict", "decorators": [], "parameters": [ { @@ -132478,7 +136974,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.multiclass._ConstantPredictor.predict_proba", + "unique_qname": "sklearn.multiclass._ConstantPredictor.predict_proba", "decorators": [], "parameters": [ { @@ -132510,7 +137008,9 @@ }, { "name": "_check_estimator", + "unique_name": "_check_estimator", "qname": "sklearn.multiclass._check_estimator", + "unique_qname": "sklearn.multiclass._check_estimator", "decorators": [], "parameters": [ { @@ -132532,7 +137032,9 @@ }, { "name": "_estimators_has", + "unique_name": "_estimators_has", "qname": "sklearn.multiclass._estimators_has", + "unique_qname": "sklearn.multiclass._estimators_has", "decorators": [], "parameters": [ { @@ -132554,7 +137056,9 @@ }, { "name": "_fit_binary", + "unique_name": "_fit_binary", "qname": "sklearn.multiclass._fit_binary", + "unique_qname": "sklearn.multiclass._fit_binary", "decorators": [], "parameters": [ { @@ -132606,7 +137110,9 @@ }, { "name": "_fit_ovo_binary", + "unique_name": "_fit_ovo_binary", "qname": "sklearn.multiclass._fit_ovo_binary", + "unique_qname": "sklearn.multiclass._fit_ovo_binary", "decorators": [], "parameters": [ { @@ -132668,7 +137174,9 @@ }, { "name": "_partial_fit_binary", + "unique_name": "_partial_fit_binary", "qname": "sklearn.multiclass._partial_fit_binary", + "unique_qname": "sklearn.multiclass._partial_fit_binary", "decorators": [], "parameters": [ { @@ -132710,7 +137218,9 @@ }, { "name": "_partial_fit_ovo_binary", + "unique_name": "_partial_fit_ovo_binary", "qname": "sklearn.multiclass._partial_fit_ovo_binary", + "unique_qname": "sklearn.multiclass._partial_fit_ovo_binary", "decorators": [], "parameters": [ { @@ -132772,7 +137282,9 @@ }, { "name": "_predict_binary", + "unique_name": "_predict_binary", "qname": "sklearn.multiclass._predict_binary", + "unique_qname": "sklearn.multiclass._predict_binary", "decorators": [], "parameters": [ { @@ -132804,7 +137316,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.multioutput.ClassifierChain._more_tags", + "unique_qname": "sklearn.multioutput.ClassifierChain._more_tags", "decorators": [], "parameters": [ { @@ -132826,7 +137340,9 @@ }, { "name": "decision_function", + "unique_name": "decision_function", "qname": "sklearn.multioutput.ClassifierChain.decision_function", + "unique_qname": "sklearn.multioutput.ClassifierChain.decision_function", "decorators": [ "_available_if_base_estimator_has('decision_function')" ], @@ -132860,7 +137376,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.multioutput.ClassifierChain.fit", + "unique_qname": "sklearn.multioutput.ClassifierChain.fit", "decorators": [], "parameters": [ { @@ -132902,7 +137420,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.multioutput.ClassifierChain.predict_proba", + "unique_qname": "sklearn.multioutput.ClassifierChain.predict_proba", "decorators": ["_available_if_base_estimator_has('predict_proba')"], "parameters": [ { @@ -132934,7 +137454,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.multioutput.MultiOutputClassifier.__init__", + "unique_qname": "sklearn.multioutput.MultiOutputClassifier.__init__", "decorators": [], "parameters": [ { @@ -132976,7 +137498,9 @@ }, { "name": "_check_predict_proba", + "unique_name": "_check_predict_proba", "qname": "sklearn.multioutput.MultiOutputClassifier._check_predict_proba", + "unique_qname": "sklearn.multioutput.MultiOutputClassifier._check_predict_proba", "decorators": [], "parameters": [ { @@ -132998,7 +137522,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.multioutput.MultiOutputClassifier._more_tags", + "unique_qname": "sklearn.multioutput.MultiOutputClassifier._more_tags", "decorators": [], "parameters": [ { @@ -133020,7 +137546,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.multioutput.MultiOutputClassifier.fit", + "unique_qname": "sklearn.multioutput.MultiOutputClassifier.fit", "decorators": [], "parameters": [ { @@ -133072,7 +137600,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.multioutput.MultiOutputClassifier.predict_proba", + "unique_qname": "sklearn.multioutput.MultiOutputClassifier.predict_proba", "decorators": ["available_if(_check_predict_proba)"], "parameters": [ { @@ -133104,7 +137634,9 @@ }, { "name": "score", + "unique_name": "score", "qname": "sklearn.multioutput.MultiOutputClassifier.score", + "unique_qname": "sklearn.multioutput.MultiOutputClassifier.score", "decorators": [], "parameters": [ { @@ -133146,7 +137678,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.multioutput.MultiOutputRegressor.__init__", + "unique_qname": "sklearn.multioutput.MultiOutputRegressor.__init__", "decorators": [], "parameters": [ { @@ -133188,7 +137722,9 @@ }, { "name": "partial_fit", + "unique_name": "partial_fit", "qname": "sklearn.multioutput.MultiOutputRegressor.partial_fit", + "unique_qname": "sklearn.multioutput.MultiOutputRegressor.partial_fit", "decorators": ["_available_if_estimator_has('partial_fit')"], "parameters": [ { @@ -133240,7 +137776,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.multioutput.RegressorChain._more_tags", + "unique_qname": "sklearn.multioutput.RegressorChain._more_tags", "decorators": [], "parameters": [ { @@ -133262,7 +137800,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.multioutput.RegressorChain.fit", + "unique_qname": "sklearn.multioutput.RegressorChain.fit", "decorators": [], "parameters": [ { @@ -133304,7 +137844,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.multioutput._BaseChain.__init__", + "unique_qname": "sklearn.multioutput._BaseChain.__init__", "decorators": [], "parameters": [ { @@ -133366,7 +137908,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.multioutput._BaseChain.fit", + "unique_qname": "sklearn.multioutput._BaseChain.fit", "decorators": ["abstractmethod"], "parameters": [ { @@ -133408,7 +137952,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.multioutput._BaseChain.predict", + "unique_qname": "sklearn.multioutput._BaseChain.predict", "decorators": [], "parameters": [ { @@ -133440,7 +137986,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.multioutput._MultiOutputEstimator.__init__", + "unique_qname": "sklearn.multioutput._MultiOutputEstimator.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -133482,7 +138030,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.multioutput._MultiOutputEstimator._more_tags", + "unique_qname": "sklearn.multioutput._MultiOutputEstimator._more_tags", "decorators": [], "parameters": [ { @@ -133504,7 +138054,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.multioutput._MultiOutputEstimator.fit", + "unique_qname": "sklearn.multioutput._MultiOutputEstimator.fit", "decorators": [], "parameters": [ { @@ -133556,7 +138108,9 @@ }, { "name": "partial_fit", + "unique_name": "partial_fit", "qname": "sklearn.multioutput._MultiOutputEstimator.partial_fit", + "unique_qname": "sklearn.multioutput._MultiOutputEstimator.partial_fit", "decorators": ["_available_if_estimator_has('partial_fit')"], "parameters": [ { @@ -133618,7 +138172,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.multioutput._MultiOutputEstimator.predict", + "unique_qname": "sklearn.multioutput._MultiOutputEstimator.predict", "decorators": [], "parameters": [ { @@ -133650,7 +138206,9 @@ }, { "name": "_available_if_base_estimator_has", + "unique_name": "_available_if_base_estimator_has", "qname": "sklearn.multioutput._available_if_base_estimator_has", + "unique_qname": "sklearn.multioutput._available_if_base_estimator_has", "decorators": [], "parameters": [ { @@ -133672,7 +138230,9 @@ }, { "name": "_available_if_estimator_has", + "unique_name": "_available_if_estimator_has", "qname": "sklearn.multioutput._available_if_estimator_has", + "unique_qname": "sklearn.multioutput._available_if_estimator_has", "decorators": [], "parameters": [ { @@ -133694,7 +138254,9 @@ }, { "name": "_fit_estimator", + "unique_name": "_fit_estimator", "qname": "sklearn.multioutput._fit_estimator", + "unique_qname": "sklearn.multioutput._fit_estimator", "decorators": [], "parameters": [ { @@ -133746,7 +138308,9 @@ }, { "name": "_partial_fit_estimator", + "unique_name": "_partial_fit_estimator", "qname": "sklearn.multioutput._partial_fit_estimator", + "unique_qname": "sklearn.multioutput._partial_fit_estimator", "decorators": [], "parameters": [ { @@ -133818,7 +138382,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.naive_bayes.BernoulliNB.__init__", + "unique_qname": "sklearn.naive_bayes.BernoulliNB.__init__", "decorators": [], "parameters": [ { @@ -133880,7 +138446,9 @@ }, { "name": "_check_X", + "unique_name": "_check_X", "qname": "sklearn.naive_bayes.BernoulliNB._check_X", + "unique_qname": "sklearn.naive_bayes.BernoulliNB._check_X", "decorators": [], "parameters": [ { @@ -133912,7 +138480,9 @@ }, { "name": "_check_X_y", + "unique_name": "_check_X_y", "qname": "sklearn.naive_bayes.BernoulliNB._check_X_y", + "unique_qname": "sklearn.naive_bayes.BernoulliNB._check_X_y", "decorators": [], "parameters": [ { @@ -133964,7 +138534,9 @@ }, { "name": "_count", + "unique_name": "_count", "qname": "sklearn.naive_bayes.BernoulliNB._count", + "unique_qname": "sklearn.naive_bayes.BernoulliNB._count", "decorators": [], "parameters": [ { @@ -134006,7 +138578,9 @@ }, { "name": "_joint_log_likelihood", + "unique_name": "_joint_log_likelihood", "qname": "sklearn.naive_bayes.BernoulliNB._joint_log_likelihood", + "unique_qname": "sklearn.naive_bayes.BernoulliNB._joint_log_likelihood", "decorators": [], "parameters": [ { @@ -134038,7 +138612,9 @@ }, { "name": "_update_feature_log_prob", + "unique_name": "_update_feature_log_prob", "qname": "sklearn.naive_bayes.BernoulliNB._update_feature_log_prob", + "unique_qname": "sklearn.naive_bayes.BernoulliNB._update_feature_log_prob", "decorators": [], "parameters": [ { @@ -134070,7 +138646,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.naive_bayes.CategoricalNB.__init__", + "unique_qname": "sklearn.naive_bayes.CategoricalNB.__init__", "decorators": [], "parameters": [ { @@ -134132,7 +138710,9 @@ }, { "name": "_check_X", + "unique_name": "_check_X", "qname": "sklearn.naive_bayes.CategoricalNB._check_X", + "unique_qname": "sklearn.naive_bayes.CategoricalNB._check_X", "decorators": [], "parameters": [ { @@ -134164,7 +138744,9 @@ }, { "name": "_check_X_y", + "unique_name": "_check_X_y", "qname": "sklearn.naive_bayes.CategoricalNB._check_X_y", + "unique_qname": "sklearn.naive_bayes.CategoricalNB._check_X_y", "decorators": [], "parameters": [ { @@ -134216,7 +138798,9 @@ }, { "name": "_count", + "unique_name": "_count", "qname": "sklearn.naive_bayes.CategoricalNB._count", + "unique_qname": "sklearn.naive_bayes.CategoricalNB._count", "decorators": [], "parameters": [ { @@ -134258,7 +138842,9 @@ }, { "name": "_init_counters", + "unique_name": "_init_counters", "qname": "sklearn.naive_bayes.CategoricalNB._init_counters", + "unique_qname": "sklearn.naive_bayes.CategoricalNB._init_counters", "decorators": [], "parameters": [ { @@ -134300,7 +138886,9 @@ }, { "name": "_joint_log_likelihood", + "unique_name": "_joint_log_likelihood", "qname": "sklearn.naive_bayes.CategoricalNB._joint_log_likelihood", + "unique_qname": "sklearn.naive_bayes.CategoricalNB._joint_log_likelihood", "decorators": [], "parameters": [ { @@ -134332,7 +138920,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.naive_bayes.CategoricalNB._more_tags", + "unique_qname": "sklearn.naive_bayes.CategoricalNB._more_tags", "decorators": [], "parameters": [ { @@ -134354,7 +138944,9 @@ }, { "name": "_update_feature_log_prob", + "unique_name": "_update_feature_log_prob", "qname": "sklearn.naive_bayes.CategoricalNB._update_feature_log_prob", + "unique_qname": "sklearn.naive_bayes.CategoricalNB._update_feature_log_prob", "decorators": [], "parameters": [ { @@ -134386,7 +138978,9 @@ }, { "name": "_validate_n_categories", + "unique_name": "_validate_n_categories", "qname": "sklearn.naive_bayes.CategoricalNB._validate_n_categories", + "unique_qname": "sklearn.naive_bayes.CategoricalNB._validate_n_categories", "decorators": ["staticmethod"], "parameters": [ { @@ -134418,7 +139012,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.naive_bayes.CategoricalNB.fit", + "unique_qname": "sklearn.naive_bayes.CategoricalNB.fit", "decorators": [], "parameters": [ { @@ -134470,7 +139066,9 @@ }, { "name": "partial_fit", + "unique_name": "partial_fit", "qname": "sklearn.naive_bayes.CategoricalNB.partial_fit", + "unique_qname": "sklearn.naive_bayes.CategoricalNB.partial_fit", "decorators": [], "parameters": [ { @@ -134532,7 +139130,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.naive_bayes.ComplementNB.__init__", + "unique_qname": "sklearn.naive_bayes.ComplementNB.__init__", "decorators": [], "parameters": [ { @@ -134594,7 +139194,9 @@ }, { "name": "_count", + "unique_name": "_count", "qname": "sklearn.naive_bayes.ComplementNB._count", + "unique_qname": "sklearn.naive_bayes.ComplementNB._count", "decorators": [], "parameters": [ { @@ -134636,7 +139238,9 @@ }, { "name": "_joint_log_likelihood", + "unique_name": "_joint_log_likelihood", "qname": "sklearn.naive_bayes.ComplementNB._joint_log_likelihood", + "unique_qname": "sklearn.naive_bayes.ComplementNB._joint_log_likelihood", "decorators": [], "parameters": [ { @@ -134668,7 +139272,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.naive_bayes.ComplementNB._more_tags", + "unique_qname": "sklearn.naive_bayes.ComplementNB._more_tags", "decorators": [], "parameters": [ { @@ -134690,7 +139296,9 @@ }, { "name": "_update_feature_log_prob", + "unique_name": "_update_feature_log_prob", "qname": "sklearn.naive_bayes.ComplementNB._update_feature_log_prob", + "unique_qname": "sklearn.naive_bayes.ComplementNB._update_feature_log_prob", "decorators": [], "parameters": [ { @@ -134722,7 +139330,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.naive_bayes.GaussianNB.__init__", + "unique_qname": "sklearn.naive_bayes.GaussianNB.__init__", "decorators": [], "parameters": [ { @@ -134764,7 +139374,9 @@ }, { "name": "_check_X", + "unique_name": "_check_X", "qname": "sklearn.naive_bayes.GaussianNB._check_X", + "unique_qname": "sklearn.naive_bayes.GaussianNB._check_X", "decorators": [], "parameters": [ { @@ -134796,7 +139408,9 @@ }, { "name": "_joint_log_likelihood", + "unique_name": "_joint_log_likelihood", "qname": "sklearn.naive_bayes.GaussianNB._joint_log_likelihood", + "unique_qname": "sklearn.naive_bayes.GaussianNB._joint_log_likelihood", "decorators": [], "parameters": [ { @@ -134828,7 +139442,9 @@ }, { "name": "_partial_fit", + "unique_name": "_partial_fit", "qname": "sklearn.naive_bayes.GaussianNB._partial_fit", + "unique_qname": "sklearn.naive_bayes.GaussianNB._partial_fit", "decorators": [], "parameters": [ { @@ -134900,7 +139516,9 @@ }, { "name": "_update_mean_variance", + "unique_name": "_update_mean_variance", "qname": "sklearn.naive_bayes.GaussianNB._update_mean_variance", + "unique_qname": "sklearn.naive_bayes.GaussianNB._update_mean_variance", "decorators": ["staticmethod"], "parameters": [ { @@ -134962,7 +139580,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.naive_bayes.GaussianNB.fit", + "unique_qname": "sklearn.naive_bayes.GaussianNB.fit", "decorators": [], "parameters": [ { @@ -135010,11 +139630,13 @@ "is_public": true, "description": "Fit Gaussian Naive Bayes according to X, y.", "docstring": "Fit Gaussian Naive Bayes according to X, y.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples\n and `n_features` is the number of features.\n\ny : array-like of shape (n_samples,)\n Target values.\n\nsample_weight : array-like of shape (n_samples,), default=None\n Weights applied to individual samples (1. for unweighted).\n\n .. versionadded:: 0.17\n Gaussian Naive Bayes supports fitting with *sample_weight*.\n\nReturns\n-------\nself : object\n Returns the instance itself.", - "source_code": "\ndef fit(self, X, y, sample_weight=None):\n \"\"\"Fit Gaussian Naive Bayes according to X, y.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples\n and `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target values.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Weights applied to individual samples (1. for unweighted).\n\n .. versionadded:: 0.17\n Gaussian Naive Bayes supports fitting with *sample_weight*.\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n (X, y) = self._validate_data(X, y)\n return self._partial_fit(X, y, np.unique(y), _refit=True, sample_weight=sample_weight)" + "source_code": "\ndef fit(self, X, y, sample_weight=None):\n \"\"\"Fit Gaussian Naive Bayes according to X, y.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training vectors, where `n_samples` is the number of samples\n and `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target values.\n\n sample_weight : array-like of shape (n_samples,), default=None\n Weights applied to individual samples (1. for unweighted).\n\n .. versionadded:: 0.17\n Gaussian Naive Bayes supports fitting with *sample_weight*.\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n y = self._validate_data(y=y)\n return self._partial_fit(X, y, np.unique(y), _refit=True, sample_weight=sample_weight)" }, { "name": "partial_fit", + "unique_name": "partial_fit", "qname": "sklearn.naive_bayes.GaussianNB.partial_fit", + "unique_qname": "sklearn.naive_bayes.GaussianNB.partial_fit", "decorators": [], "parameters": [ { @@ -135076,7 +139698,9 @@ }, { "name": "sigma_", + "unique_name": "sigma_@getter", "qname": "sklearn.naive_bayes.GaussianNB.sigma_", + "unique_qname": "sklearn.naive_bayes.GaussianNB.sigma_@getter", "decorators": [ "deprecated('Attribute `sigma_` was deprecated in 1.0 and will be removed in1.2. Use `var_` instead.')", "property" @@ -135101,7 +139725,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.naive_bayes.MultinomialNB.__init__", + "unique_qname": "sklearn.naive_bayes.MultinomialNB.__init__", "decorators": [], "parameters": [ { @@ -135153,7 +139779,9 @@ }, { "name": "_count", + "unique_name": "_count", "qname": "sklearn.naive_bayes.MultinomialNB._count", + "unique_qname": "sklearn.naive_bayes.MultinomialNB._count", "decorators": [], "parameters": [ { @@ -135195,7 +139823,9 @@ }, { "name": "_joint_log_likelihood", + "unique_name": "_joint_log_likelihood", "qname": "sklearn.naive_bayes.MultinomialNB._joint_log_likelihood", + "unique_qname": "sklearn.naive_bayes.MultinomialNB._joint_log_likelihood", "decorators": [], "parameters": [ { @@ -135227,7 +139857,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.naive_bayes.MultinomialNB._more_tags", + "unique_qname": "sklearn.naive_bayes.MultinomialNB._more_tags", "decorators": [], "parameters": [ { @@ -135249,7 +139881,9 @@ }, { "name": "_update_feature_log_prob", + "unique_name": "_update_feature_log_prob", "qname": "sklearn.naive_bayes.MultinomialNB._update_feature_log_prob", + "unique_qname": "sklearn.naive_bayes.MultinomialNB._update_feature_log_prob", "decorators": [], "parameters": [ { @@ -135281,7 +139915,9 @@ }, { "name": "_check_X", + "unique_name": "_check_X", "qname": "sklearn.naive_bayes._BaseDiscreteNB._check_X", + "unique_qname": "sklearn.naive_bayes._BaseDiscreteNB._check_X", "decorators": [], "parameters": [ { @@ -135313,7 +139949,9 @@ }, { "name": "_check_X_y", + "unique_name": "_check_X_y", "qname": "sklearn.naive_bayes._BaseDiscreteNB._check_X_y", + "unique_qname": "sklearn.naive_bayes._BaseDiscreteNB._check_X_y", "decorators": [], "parameters": [ { @@ -135365,7 +140003,9 @@ }, { "name": "_check_alpha", + "unique_name": "_check_alpha", "qname": "sklearn.naive_bayes._BaseDiscreteNB._check_alpha", + "unique_qname": "sklearn.naive_bayes._BaseDiscreteNB._check_alpha", "decorators": [], "parameters": [ { @@ -135387,7 +140027,9 @@ }, { "name": "_init_counters", + "unique_name": "_init_counters", "qname": "sklearn.naive_bayes._BaseDiscreteNB._init_counters", + "unique_qname": "sklearn.naive_bayes._BaseDiscreteNB._init_counters", "decorators": [], "parameters": [ { @@ -135429,7 +140071,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.naive_bayes._BaseDiscreteNB._more_tags", + "unique_qname": "sklearn.naive_bayes._BaseDiscreteNB._more_tags", "decorators": [], "parameters": [ { @@ -135451,7 +140095,9 @@ }, { "name": "_update_class_log_prior", + "unique_name": "_update_class_log_prior", "qname": "sklearn.naive_bayes._BaseDiscreteNB._update_class_log_prior", + "unique_qname": "sklearn.naive_bayes._BaseDiscreteNB._update_class_log_prior", "decorators": [], "parameters": [ { @@ -135483,7 +140129,9 @@ }, { "name": "coef_", + "unique_name": "coef_@getter", "qname": "sklearn.naive_bayes._BaseDiscreteNB.coef_", + "unique_qname": "sklearn.naive_bayes._BaseDiscreteNB.coef_@getter", "decorators": [ "deprecated('Attribute `coef_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -135508,7 +140156,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.naive_bayes._BaseDiscreteNB.fit", + "unique_qname": "sklearn.naive_bayes._BaseDiscreteNB.fit", "decorators": [], "parameters": [ { @@ -135560,7 +140210,9 @@ }, { "name": "intercept_", + "unique_name": "intercept_@getter", "qname": "sklearn.naive_bayes._BaseDiscreteNB.intercept_", + "unique_qname": "sklearn.naive_bayes._BaseDiscreteNB.intercept_@getter", "decorators": [ "deprecated('Attribute `intercept_` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -135585,7 +140237,9 @@ }, { "name": "n_features_", + "unique_name": "n_features_@getter", "qname": "sklearn.naive_bayes._BaseDiscreteNB.n_features_", + "unique_qname": "sklearn.naive_bayes._BaseDiscreteNB.n_features_@getter", "decorators": [ "deprecated('Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead.')", "property" @@ -135610,7 +140264,9 @@ }, { "name": "partial_fit", + "unique_name": "partial_fit", "qname": "sklearn.naive_bayes._BaseDiscreteNB.partial_fit", + "unique_qname": "sklearn.naive_bayes._BaseDiscreteNB.partial_fit", "decorators": [], "parameters": [ { @@ -135672,7 +140328,9 @@ }, { "name": "_check_X", + "unique_name": "_check_X", "qname": "sklearn.naive_bayes._BaseNB._check_X", + "unique_qname": "sklearn.naive_bayes._BaseNB._check_X", "decorators": ["abstractmethod"], "parameters": [ { @@ -135704,7 +140362,9 @@ }, { "name": "_joint_log_likelihood", + "unique_name": "_joint_log_likelihood", "qname": "sklearn.naive_bayes._BaseNB._joint_log_likelihood", + "unique_qname": "sklearn.naive_bayes._BaseNB._joint_log_likelihood", "decorators": ["abstractmethod"], "parameters": [ { @@ -135736,7 +140396,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.naive_bayes._BaseNB.predict", + "unique_qname": "sklearn.naive_bayes._BaseNB.predict", "decorators": [], "parameters": [ { @@ -135768,7 +140430,9 @@ }, { "name": "predict_log_proba", + "unique_name": "predict_log_proba", "qname": "sklearn.naive_bayes._BaseNB.predict_log_proba", + "unique_qname": "sklearn.naive_bayes._BaseNB.predict_log_proba", "decorators": [], "parameters": [ { @@ -135800,7 +140464,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.naive_bayes._BaseNB.predict_proba", + "unique_qname": "sklearn.naive_bayes._BaseNB.predict_proba", "decorators": [], "parameters": [ { @@ -135832,7 +140498,9 @@ }, { "name": "_kneighbors_reduce_func", + "unique_name": "_kneighbors_reduce_func", "qname": "sklearn.neighbors._base.KNeighborsMixin._kneighbors_reduce_func", + "unique_qname": "sklearn.neighbors._base.KNeighborsMixin._kneighbors_reduce_func", "decorators": [], "parameters": [ { @@ -135894,7 +140562,9 @@ }, { "name": "kneighbors", + "unique_name": "kneighbors", "qname": "sklearn.neighbors._base.KNeighborsMixin.kneighbors", + "unique_qname": "sklearn.neighbors._base.KNeighborsMixin.kneighbors", "decorators": [], "parameters": [ { @@ -135946,7 +140616,9 @@ }, { "name": "kneighbors_graph", + "unique_name": "kneighbors_graph", "qname": "sklearn.neighbors._base.KNeighborsMixin.kneighbors_graph", + "unique_qname": "sklearn.neighbors._base.KNeighborsMixin.kneighbors_graph", "decorators": [], "parameters": [ { @@ -135998,7 +140670,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.neighbors._base.NeighborsBase.__init__", + "unique_qname": "sklearn.neighbors._base.NeighborsBase.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -136100,7 +140774,9 @@ }, { "name": "_check_algorithm_metric", + "unique_name": "_check_algorithm_metric", "qname": "sklearn.neighbors._base.NeighborsBase._check_algorithm_metric", + "unique_qname": "sklearn.neighbors._base.NeighborsBase._check_algorithm_metric", "decorators": [], "parameters": [ { @@ -136122,7 +140798,9 @@ }, { "name": "_fit", + "unique_name": "_fit", "qname": "sklearn.neighbors._base.NeighborsBase._fit", + "unique_qname": "sklearn.neighbors._base.NeighborsBase._fit", "decorators": [], "parameters": [ { @@ -136164,7 +140842,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.neighbors._base.NeighborsBase._more_tags", + "unique_qname": "sklearn.neighbors._base.NeighborsBase._more_tags", "decorators": [], "parameters": [ { @@ -136186,7 +140866,9 @@ }, { "name": "_pairwise", + "unique_name": "_pairwise@getter", "qname": "sklearn.neighbors._base.NeighborsBase._pairwise", + "unique_qname": "sklearn.neighbors._base.NeighborsBase._pairwise@getter", "decorators": [ "deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -136211,7 +140893,9 @@ }, { "name": "_radius_neighbors_reduce_func", + "unique_name": "_radius_neighbors_reduce_func", "qname": "sklearn.neighbors._base.RadiusNeighborsMixin._radius_neighbors_reduce_func", + "unique_qname": "sklearn.neighbors._base.RadiusNeighborsMixin._radius_neighbors_reduce_func", "decorators": [], "parameters": [ { @@ -136273,7 +140957,9 @@ }, { "name": "radius_neighbors", + "unique_name": "radius_neighbors", "qname": "sklearn.neighbors._base.RadiusNeighborsMixin.radius_neighbors", + "unique_qname": "sklearn.neighbors._base.RadiusNeighborsMixin.radius_neighbors", "decorators": [], "parameters": [ { @@ -136335,7 +141021,9 @@ }, { "name": "radius_neighbors_graph", + "unique_name": "radius_neighbors_graph", "qname": "sklearn.neighbors._base.RadiusNeighborsMixin.radius_neighbors_graph", + "unique_qname": "sklearn.neighbors._base.RadiusNeighborsMixin.radius_neighbors_graph", "decorators": [], "parameters": [ { @@ -136397,7 +141085,9 @@ }, { "name": "_check_precomputed", + "unique_name": "_check_precomputed", "qname": "sklearn.neighbors._base._check_precomputed", + "unique_qname": "sklearn.neighbors._base._check_precomputed", "decorators": [], "parameters": [ { @@ -136419,7 +141109,9 @@ }, { "name": "_check_weights", + "unique_name": "_check_weights", "qname": "sklearn.neighbors._base._check_weights", + "unique_qname": "sklearn.neighbors._base._check_weights", "decorators": [], "parameters": [ { @@ -136441,7 +141133,9 @@ }, { "name": "_get_weights", + "unique_name": "_get_weights", "qname": "sklearn.neighbors._base._get_weights", + "unique_qname": "sklearn.neighbors._base._get_weights", "decorators": [], "parameters": [ { @@ -136473,7 +141167,9 @@ }, { "name": "_is_sorted_by_data", + "unique_name": "_is_sorted_by_data", "qname": "sklearn.neighbors._base._is_sorted_by_data", + "unique_qname": "sklearn.neighbors._base._is_sorted_by_data", "decorators": [], "parameters": [ { @@ -136495,7 +141191,9 @@ }, { "name": "_kneighbors_from_graph", + "unique_name": "_kneighbors_from_graph", "qname": "sklearn.neighbors._base._kneighbors_from_graph", + "unique_qname": "sklearn.neighbors._base._kneighbors_from_graph", "decorators": [], "parameters": [ { @@ -136537,7 +141235,9 @@ }, { "name": "_radius_neighbors_from_graph", + "unique_name": "_radius_neighbors_from_graph", "qname": "sklearn.neighbors._base._radius_neighbors_from_graph", + "unique_qname": "sklearn.neighbors._base._radius_neighbors_from_graph", "decorators": [], "parameters": [ { @@ -136579,7 +141279,9 @@ }, { "name": "_tree_query_parallel_helper", + "unique_name": "_tree_query_parallel_helper", "qname": "sklearn.neighbors._base._tree_query_parallel_helper", + "unique_qname": "sklearn.neighbors._base._tree_query_parallel_helper", "decorators": [], "parameters": [ { @@ -136601,7 +141303,9 @@ }, { "name": "_tree_query_radius_parallel_helper", + "unique_name": "_tree_query_radius_parallel_helper", "qname": "sklearn.neighbors._base._tree_query_radius_parallel_helper", + "unique_qname": "sklearn.neighbors._base._tree_query_radius_parallel_helper", "decorators": [], "parameters": [ { @@ -136623,7 +141327,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.neighbors._classification.KNeighborsClassifier.__init__", + "unique_qname": "sklearn.neighbors._classification.KNeighborsClassifier.__init__", "decorators": [], "parameters": [ { @@ -136725,7 +141431,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.neighbors._classification.KNeighborsClassifier._more_tags", + "unique_qname": "sklearn.neighbors._classification.KNeighborsClassifier._more_tags", "decorators": [], "parameters": [ { @@ -136747,7 +141455,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.neighbors._classification.KNeighborsClassifier.fit", + "unique_qname": "sklearn.neighbors._classification.KNeighborsClassifier.fit", "decorators": [], "parameters": [ { @@ -136789,7 +141499,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.neighbors._classification.KNeighborsClassifier.predict", + "unique_qname": "sklearn.neighbors._classification.KNeighborsClassifier.predict", "decorators": [], "parameters": [ { @@ -136817,11 +141529,13 @@ "is_public": true, "description": "Predict the class labels for the provided data.", "docstring": "Predict the class labels for the provided data.\n\nParameters\n----------\nX : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\nReturns\n-------\ny : ndarray of shape (n_queries,) or (n_queries, n_outputs)\n Class labels for each data sample.", - "source_code": "\ndef predict(self, X):\n \"\"\"Predict the class labels for the provided data.\n\n Parameters\n ----------\n X : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\n Returns\n -------\n y : ndarray of shape (n_queries,) or (n_queries, n_outputs)\n Class labels for each data sample.\n \"\"\"\n X = self._validate_data(X, accept_sparse='csr', reset=False)\n (neigh_dist, neigh_ind) = self.kneighbors(X)\n classes_ = self.classes_\n _y = self._y\n if not self.outputs_2d_:\n _y = self._y.reshape((-1, 1))\n classes_ = [self.classes_]\n n_outputs = len(classes_)\n n_queries = _num_samples(X)\n weights = _get_weights(neigh_dist, self.weights)\n y_pred = np.empty((n_queries, n_outputs), dtype=classes_[0].dtype)\n for (k, classes_k) in enumerate(classes_):\n if weights is None:\n (mode, _) = stats.mode(_y[neigh_ind, k], axis=1)\n else:\n (mode, _) = weighted_mode(_y[neigh_ind, k], weights, axis=1)\n mode = np.asarray(mode.ravel(), dtype=np.intp)\n y_pred[:, k] = classes_k.take(mode)\n if not self.outputs_2d_:\n y_pred = y_pred.ravel()\n return y_pred" + "source_code": "\ndef predict(self, X):\n \"\"\"Predict the class labels for the provided data.\n\n Parameters\n ----------\n X : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\n Returns\n -------\n y : ndarray of shape (n_queries,) or (n_queries, n_outputs)\n Class labels for each data sample.\n \"\"\"\n (neigh_dist, neigh_ind) = self.kneighbors(X)\n classes_ = self.classes_\n _y = self._y\n if not self.outputs_2d_:\n _y = self._y.reshape((-1, 1))\n classes_ = [self.classes_]\n n_outputs = len(classes_)\n n_queries = _num_samples(X)\n weights = _get_weights(neigh_dist, self.weights)\n y_pred = np.empty((n_queries, n_outputs), dtype=classes_[0].dtype)\n for (k, classes_k) in enumerate(classes_):\n if weights is None:\n (mode, _) = stats.mode(_y[neigh_ind, k], axis=1)\n else:\n (mode, _) = weighted_mode(_y[neigh_ind, k], weights, axis=1)\n mode = np.asarray(mode.ravel(), dtype=np.intp)\n y_pred[:, k] = classes_k.take(mode)\n if not self.outputs_2d_:\n y_pred = y_pred.ravel()\n return y_pred" }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.neighbors._classification.KNeighborsClassifier.predict_proba", + "unique_qname": "sklearn.neighbors._classification.KNeighborsClassifier.predict_proba", "decorators": [], "parameters": [ { @@ -136849,11 +141563,13 @@ "is_public": true, "description": "Return probability estimates for the test data X.", "docstring": "Return probability estimates for the test data X.\n\nParameters\n----------\nX : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\nReturns\n-------\np : ndarray of shape (n_queries, n_classes), or a list of n_outputs of such arrays if n_outputs > 1.\n The class probabilities of the input samples. Classes are ordered\n by lexicographic order.", - "source_code": "\ndef predict_proba(self, X):\n \"\"\"Return probability estimates for the test data X.\n\n Parameters\n ----------\n X : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\n Returns\n -------\n p : ndarray of shape (n_queries, n_classes), or a list of n_outputs of such arrays if n_outputs > 1.\n The class probabilities of the input samples. Classes are ordered\n by lexicographic order.\n \"\"\"\n X = self._validate_data(X, accept_sparse='csr', reset=False)\n (neigh_dist, neigh_ind) = self.kneighbors(X)\n classes_ = self.classes_\n _y = self._y\n if not self.outputs_2d_:\n _y = self._y.reshape((-1, 1))\n classes_ = [self.classes_]\n n_queries = _num_samples(X)\n weights = _get_weights(neigh_dist, self.weights)\n if weights is None:\n weights = np.ones_like(neigh_ind)\n all_rows = np.arange(X.shape[0])\n probabilities = []\n for (k, classes_k) in enumerate(classes_):\n pred_labels = _y[:, k][neigh_ind]\n proba_k = np.zeros((n_queries, classes_k.size))\n for (i, idx) in enumerate(pred_labels.T):\n proba_k[all_rows, idx] += weights[:, i]\n normalizer = proba_k.sum(axis=1)[:, np.newaxis]\n normalizer[normalizer == 0.0] = 1.0\n proba_k /= normalizer\n probabilities.append(proba_k)\n if not self.outputs_2d_:\n probabilities = probabilities[0]\n return probabilities" + "source_code": "\ndef predict_proba(self, X):\n \"\"\"Return probability estimates for the test data X.\n\n Parameters\n ----------\n X : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\n Returns\n -------\n p : ndarray of shape (n_queries, n_classes), or a list of n_outputs of such arrays if n_outputs > 1.\n The class probabilities of the input samples. Classes are ordered\n by lexicographic order.\n \"\"\"\n (neigh_dist, neigh_ind) = self.kneighbors(X)\n classes_ = self.classes_\n _y = self._y\n if not self.outputs_2d_:\n _y = self._y.reshape((-1, 1))\n classes_ = [self.classes_]\n n_queries = _num_samples(X)\n weights = _get_weights(neigh_dist, self.weights)\n if weights is None:\n weights = np.ones_like(neigh_ind)\n all_rows = np.arange(n_queries)\n probabilities = []\n for (k, classes_k) in enumerate(classes_):\n pred_labels = _y[:, k][neigh_ind]\n proba_k = np.zeros((n_queries, classes_k.size))\n for (i, idx) in enumerate(pred_labels.T):\n proba_k[all_rows, idx] += weights[:, i]\n normalizer = proba_k.sum(axis=1)[:, np.newaxis]\n normalizer[normalizer == 0.0] = 1.0\n proba_k /= normalizer\n probabilities.append(proba_k)\n if not self.outputs_2d_:\n probabilities = probabilities[0]\n return probabilities" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.neighbors._classification.RadiusNeighborsClassifier.__init__", + "unique_qname": "sklearn.neighbors._classification.RadiusNeighborsClassifier.__init__", "decorators": [], "parameters": [ { @@ -136965,7 +141681,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.neighbors._classification.RadiusNeighborsClassifier._more_tags", + "unique_qname": "sklearn.neighbors._classification.RadiusNeighborsClassifier._more_tags", "decorators": [], "parameters": [ { @@ -136987,7 +141705,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.neighbors._classification.RadiusNeighborsClassifier.fit", + "unique_qname": "sklearn.neighbors._classification.RadiusNeighborsClassifier.fit", "decorators": [], "parameters": [ { @@ -137029,7 +141749,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.neighbors._classification.RadiusNeighborsClassifier.predict", + "unique_qname": "sklearn.neighbors._classification.RadiusNeighborsClassifier.predict", "decorators": [], "parameters": [ { @@ -137061,7 +141783,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.neighbors._classification.RadiusNeighborsClassifier.predict_proba", + "unique_qname": "sklearn.neighbors._classification.RadiusNeighborsClassifier.predict_proba", "decorators": [], "parameters": [ { @@ -137089,11 +141813,13 @@ "is_public": true, "description": "Return probability estimates for the test data X.", "docstring": "Return probability estimates for the test data X.\n\nParameters\n----------\nX : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\nReturns\n-------\np : ndarray of shape (n_queries, n_classes), or a list of n_outputs of such arrays if n_outputs > 1.\n The class probabilities of the input samples. Classes are ordered\n by lexicographic order.", - "source_code": "\ndef predict_proba(self, X):\n \"\"\"Return probability estimates for the test data X.\n\n Parameters\n ----------\n X : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\n Returns\n -------\n p : ndarray of shape (n_queries, n_classes), or a list of n_outputs of such arrays if n_outputs > 1.\n The class probabilities of the input samples. Classes are ordered\n by lexicographic order.\n \"\"\"\n X = self._validate_data(X, accept_sparse='csr', reset=False)\n n_queries = _num_samples(X)\n (neigh_dist, neigh_ind) = self.radius_neighbors(X)\n outlier_mask = np.zeros(n_queries, dtype=bool)\n outlier_mask[:] = [len(nind) == 0 for nind in neigh_ind]\n outliers = np.flatnonzero(outlier_mask)\n inliers = np.flatnonzero(~outlier_mask)\n classes_ = self.classes_\n _y = self._y\n if not self.outputs_2d_:\n _y = self._y.reshape((-1, 1))\n classes_ = [self.classes_]\n if self.outlier_label_ is None and outliers.size > 0:\n raise ValueError('No neighbors found for test samples %r, you can try using larger radius, giving a label for outliers, or considering removing them from your dataset.' % outliers)\n weights = _get_weights(neigh_dist, self.weights)\n if weights is not None:\n weights = weights[inliers]\n probabilities = []\n for (k, classes_k) in enumerate(classes_):\n pred_labels = np.zeros(len(neigh_ind), dtype=object)\n pred_labels[:] = [_y[ind, k] for ind in neigh_ind]\n proba_k = np.zeros((n_queries, classes_k.size))\n proba_inl = np.zeros((len(inliers), classes_k.size))\n if weights is None:\n for (i, idx) in enumerate(pred_labels[inliers]):\n proba_inl[i, :] = np.bincount(idx, minlength=classes_k.size)\n else:\n for (i, idx) in enumerate(pred_labels[inliers]):\n proba_inl[i, :] = np.bincount(idx, weights[i], minlength=classes_k.size)\n proba_k[inliers, :] = proba_inl\n if outliers.size > 0:\n _outlier_label = self.outlier_label_[k]\n label_index = np.flatnonzero(classes_k == _outlier_label)\n if label_index.size == 1:\n proba_k[outliers, label_index[0]] = 1.0\n else:\n warnings.warn('Outlier label {} is not in training classes. All class probabilities of outliers will be assigned with 0.'.format(self.outlier_label_[k]))\n normalizer = proba_k.sum(axis=1)[:, np.newaxis]\n normalizer[normalizer == 0.0] = 1.0\n proba_k /= normalizer\n probabilities.append(proba_k)\n if not self.outputs_2d_:\n probabilities = probabilities[0]\n return probabilities" + "source_code": "\ndef predict_proba(self, X):\n \"\"\"Return probability estimates for the test data X.\n\n Parameters\n ----------\n X : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\n Returns\n -------\n p : ndarray of shape (n_queries, n_classes), or a list of n_outputs of such arrays if n_outputs > 1.\n The class probabilities of the input samples. Classes are ordered\n by lexicographic order.\n \"\"\"\n n_queries = _num_samples(X)\n (neigh_dist, neigh_ind) = self.radius_neighbors(X)\n outlier_mask = np.zeros(n_queries, dtype=bool)\n outlier_mask[:] = [len(nind) == 0 for nind in neigh_ind]\n outliers = np.flatnonzero(outlier_mask)\n inliers = np.flatnonzero(~outlier_mask)\n classes_ = self.classes_\n _y = self._y\n if not self.outputs_2d_:\n _y = self._y.reshape((-1, 1))\n classes_ = [self.classes_]\n if self.outlier_label_ is None and outliers.size > 0:\n raise ValueError('No neighbors found for test samples %r, you can try using larger radius, giving a label for outliers, or considering removing them from your dataset.' % outliers)\n weights = _get_weights(neigh_dist, self.weights)\n if weights is not None:\n weights = weights[inliers]\n probabilities = []\n for (k, classes_k) in enumerate(classes_):\n pred_labels = np.zeros(len(neigh_ind), dtype=object)\n pred_labels[:] = [_y[ind, k] for ind in neigh_ind]\n proba_k = np.zeros((n_queries, classes_k.size))\n proba_inl = np.zeros((len(inliers), classes_k.size))\n if weights is None:\n for (i, idx) in enumerate(pred_labels[inliers]):\n proba_inl[i, :] = np.bincount(idx, minlength=classes_k.size)\n else:\n for (i, idx) in enumerate(pred_labels[inliers]):\n proba_inl[i, :] = np.bincount(idx, weights[i], minlength=classes_k.size)\n proba_k[inliers, :] = proba_inl\n if outliers.size > 0:\n _outlier_label = self.outlier_label_[k]\n label_index = np.flatnonzero(classes_k == _outlier_label)\n if label_index.size == 1:\n proba_k[outliers, label_index[0]] = 1.0\n else:\n warnings.warn('Outlier label {} is not in training classes. All class probabilities of outliers will be assigned with 0.'.format(self.outlier_label_[k]))\n normalizer = proba_k.sum(axis=1)[:, np.newaxis]\n normalizer[normalizer == 0.0] = 1.0\n proba_k /= normalizer\n probabilities.append(proba_k)\n if not self.outputs_2d_:\n probabilities = probabilities[0]\n return probabilities" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.neighbors._graph.KNeighborsTransformer.__init__", + "unique_qname": "sklearn.neighbors._graph.KNeighborsTransformer.__init__", "decorators": [], "parameters": [ { @@ -137195,7 +141921,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.neighbors._graph.KNeighborsTransformer._more_tags", + "unique_qname": "sklearn.neighbors._graph.KNeighborsTransformer._more_tags", "decorators": [], "parameters": [ { @@ -137217,7 +141945,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.neighbors._graph.KNeighborsTransformer.fit", + "unique_qname": "sklearn.neighbors._graph.KNeighborsTransformer.fit", "decorators": [], "parameters": [ { @@ -137259,7 +141989,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.neighbors._graph.KNeighborsTransformer.fit_transform", + "unique_qname": "sklearn.neighbors._graph.KNeighborsTransformer.fit_transform", "decorators": [], "parameters": [ { @@ -137301,7 +142033,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.neighbors._graph.KNeighborsTransformer.transform", + "unique_qname": "sklearn.neighbors._graph.KNeighborsTransformer.transform", "decorators": [], "parameters": [ { @@ -137333,7 +142067,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.neighbors._graph.RadiusNeighborsTransformer.__init__", + "unique_qname": "sklearn.neighbors._graph.RadiusNeighborsTransformer.__init__", "decorators": [], "parameters": [ { @@ -137435,7 +142171,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.neighbors._graph.RadiusNeighborsTransformer._more_tags", + "unique_qname": "sklearn.neighbors._graph.RadiusNeighborsTransformer._more_tags", "decorators": [], "parameters": [ { @@ -137457,7 +142195,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.neighbors._graph.RadiusNeighborsTransformer.fit", + "unique_qname": "sklearn.neighbors._graph.RadiusNeighborsTransformer.fit", "decorators": [], "parameters": [ { @@ -137499,7 +142239,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.neighbors._graph.RadiusNeighborsTransformer.fit_transform", + "unique_qname": "sklearn.neighbors._graph.RadiusNeighborsTransformer.fit_transform", "decorators": [], "parameters": [ { @@ -137541,7 +142283,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.neighbors._graph.RadiusNeighborsTransformer.transform", + "unique_qname": "sklearn.neighbors._graph.RadiusNeighborsTransformer.transform", "decorators": [], "parameters": [ { @@ -137573,7 +142317,9 @@ }, { "name": "_check_params", + "unique_name": "_check_params", "qname": "sklearn.neighbors._graph._check_params", + "unique_qname": "sklearn.neighbors._graph._check_params", "decorators": [], "parameters": [ { @@ -137625,7 +142371,9 @@ }, { "name": "_query_include_self", + "unique_name": "_query_include_self", "qname": "sklearn.neighbors._graph._query_include_self", + "unique_qname": "sklearn.neighbors._graph._query_include_self", "decorators": [], "parameters": [ { @@ -137667,7 +142415,9 @@ }, { "name": "kneighbors_graph", + "unique_name": "kneighbors_graph", "qname": "sklearn.neighbors._graph.kneighbors_graph", + "unique_qname": "sklearn.neighbors._graph.kneighbors_graph", "decorators": [], "parameters": [ { @@ -137759,7 +142509,9 @@ }, { "name": "radius_neighbors_graph", + "unique_name": "radius_neighbors_graph", "qname": "sklearn.neighbors._graph.radius_neighbors_graph", + "unique_qname": "sklearn.neighbors._graph.radius_neighbors_graph", "decorators": [], "parameters": [ { @@ -137851,7 +142603,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.neighbors._kde.KernelDensity.__init__", + "unique_qname": "sklearn.neighbors._kde.KernelDensity.__init__", "decorators": [], "parameters": [ { @@ -137963,7 +142717,9 @@ }, { "name": "_choose_algorithm", + "unique_name": "_choose_algorithm", "qname": "sklearn.neighbors._kde.KernelDensity._choose_algorithm", + "unique_qname": "sklearn.neighbors._kde.KernelDensity._choose_algorithm", "decorators": [], "parameters": [ { @@ -138005,7 +142761,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.neighbors._kde.KernelDensity._more_tags", + "unique_qname": "sklearn.neighbors._kde.KernelDensity._more_tags", "decorators": [], "parameters": [ { @@ -138027,7 +142785,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.neighbors._kde.KernelDensity.fit", + "unique_qname": "sklearn.neighbors._kde.KernelDensity.fit", "decorators": [], "parameters": [ { @@ -138079,7 +142839,9 @@ }, { "name": "sample", + "unique_name": "sample", "qname": "sklearn.neighbors._kde.KernelDensity.sample", + "unique_qname": "sklearn.neighbors._kde.KernelDensity.sample", "decorators": [], "parameters": [ { @@ -138109,19 +142871,21 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "int, RandomState instance or None, default=None", - "description": "Determines random number generation used to generate\nrandom samples. Pass an int for reproducible results\nacross multiple function calls.\nSee :term: `Glossary `." + "description": "Determines random number generation used to generate\nrandom samples. Pass an int for reproducible results\nacross multiple function calls.\nSee :term:`Glossary `." } } ], "results": [], "is_public": true, "description": "Generate random samples from the model.\n\nCurrently, this is implemented only for gaussian and tophat kernels.", - "docstring": "Generate random samples from the model.\n\nCurrently, this is implemented only for gaussian and tophat kernels.\n\nParameters\n----------\nn_samples : int, default=1\n Number of samples to generate.\n\nrandom_state : int, RandomState instance or None, default=None\n Determines random number generation used to generate\n random samples. Pass an int for reproducible results\n across multiple function calls.\n See :term: `Glossary `.\n\nReturns\n-------\nX : array-like of shape (n_samples, n_features)\n List of samples.", - "source_code": "\ndef sample(self, n_samples=1, random_state=None):\n \"\"\"Generate random samples from the model.\n\n Currently, this is implemented only for gaussian and tophat kernels.\n\n Parameters\n ----------\n n_samples : int, default=1\n Number of samples to generate.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation used to generate\n random samples. Pass an int for reproducible results\n across multiple function calls.\n See :term: `Glossary `.\n\n Returns\n -------\n X : array-like of shape (n_samples, n_features)\n List of samples.\n \"\"\"\n check_is_fitted(self)\n if self.kernel not in ['gaussian', 'tophat']:\n raise NotImplementedError()\n data = np.asarray(self.tree_.data)\n rng = check_random_state(random_state)\n u = rng.uniform(0, 1, size=n_samples)\n if self.tree_.sample_weight is None:\n i = (u * data.shape[0]).astype(np.int64)\n else:\n cumsum_weight = np.cumsum(np.asarray(self.tree_.sample_weight))\n sum_weight = cumsum_weight[-1]\n i = np.searchsorted(cumsum_weight, u * sum_weight)\n if self.kernel == 'gaussian':\n return np.atleast_2d(rng.normal(data[i], self.bandwidth))\n elif self.kernel == 'tophat':\n dim = data.shape[1]\n X = rng.normal(size=(n_samples, dim))\n s_sq = row_norms(X, squared=True)\n correction = gammainc(0.5 * dim, 0.5 * s_sq)**(1.0 / dim) * self.bandwidth / np.sqrt(s_sq)\n return data[i] + X * correction[:, np.newaxis]" + "docstring": "Generate random samples from the model.\n\nCurrently, this is implemented only for gaussian and tophat kernels.\n\nParameters\n----------\nn_samples : int, default=1\n Number of samples to generate.\n\nrandom_state : int, RandomState instance or None, default=None\n Determines random number generation used to generate\n random samples. Pass an int for reproducible results\n across multiple function calls.\n See :term:`Glossary `.\n\nReturns\n-------\nX : array-like of shape (n_samples, n_features)\n List of samples.", + "source_code": "\ndef sample(self, n_samples=1, random_state=None):\n \"\"\"Generate random samples from the model.\n\n Currently, this is implemented only for gaussian and tophat kernels.\n\n Parameters\n ----------\n n_samples : int, default=1\n Number of samples to generate.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation used to generate\n random samples. Pass an int for reproducible results\n across multiple function calls.\n See :term:`Glossary `.\n\n Returns\n -------\n X : array-like of shape (n_samples, n_features)\n List of samples.\n \"\"\"\n check_is_fitted(self)\n if self.kernel not in ['gaussian', 'tophat']:\n raise NotImplementedError()\n data = np.asarray(self.tree_.data)\n rng = check_random_state(random_state)\n u = rng.uniform(0, 1, size=n_samples)\n if self.tree_.sample_weight is None:\n i = (u * data.shape[0]).astype(np.int64)\n else:\n cumsum_weight = np.cumsum(np.asarray(self.tree_.sample_weight))\n sum_weight = cumsum_weight[-1]\n i = np.searchsorted(cumsum_weight, u * sum_weight)\n if self.kernel == 'gaussian':\n return np.atleast_2d(rng.normal(data[i], self.bandwidth))\n elif self.kernel == 'tophat':\n dim = data.shape[1]\n X = rng.normal(size=(n_samples, dim))\n s_sq = row_norms(X, squared=True)\n correction = gammainc(0.5 * dim, 0.5 * s_sq)**(1.0 / dim) * self.bandwidth / np.sqrt(s_sq)\n return data[i] + X * correction[:, np.newaxis]" }, { "name": "score", + "unique_name": "score", "qname": "sklearn.neighbors._kde.KernelDensity.score", + "unique_qname": "sklearn.neighbors._kde.KernelDensity.score", "decorators": [], "parameters": [ { @@ -138163,7 +142927,9 @@ }, { "name": "score_samples", + "unique_name": "score_samples", "qname": "sklearn.neighbors._kde.KernelDensity.score_samples", + "unique_qname": "sklearn.neighbors._kde.KernelDensity.score_samples", "decorators": [], "parameters": [ { @@ -138195,7 +142961,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.neighbors._lof.LocalOutlierFactor.__init__", + "unique_qname": "sklearn.neighbors._lof.LocalOutlierFactor.__init__", "decorators": [], "parameters": [ { @@ -138235,7 +143003,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int, default=30", - "description": "Leaf size passed to :class:`BallTree` or :class:`KDTree`. This can\naffect the speed of the construction and query, as well as the memory\nrequired to store the tree. The optimal value depends on the\nnature of the problem." + "description": "Leaf is size passed to :class:`BallTree` or :class:`KDTree`. This can\naffect the speed of the construction and query, as well as the memory\nrequired to store the tree. The optimal value depends on the\nnature of the problem." } }, { @@ -138245,7 +143013,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "str or callable, default='minkowski'", - "description": "metric used for the distance computation. Any metric from scikit-learn\nor scipy.spatial.distance can be used.\n\nIf metric is \"precomputed\", X is assumed to be a distance matrix and\nmust be square. X may be a sparse matrix, in which case only \"nonzero\"\nelements may be considered neighbors.\n\nIf metric is a callable function, it is called on each\npair of instances (rows) and the resulting value recorded. The callable\nshould take two arrays as input and return one value indicating the\ndistance between them. This works for Scipy's metrics, but is less\nefficient than passing the metric name as a string.\n\nValid values for metric are:\n\n- from scikit-learn: ['cityblock', 'cosine', 'euclidean', 'l1', 'l2',\n 'manhattan']\n\n- from scipy.spatial.distance: ['braycurtis', 'canberra', 'chebyshev',\n 'correlation', 'dice', 'hamming', 'jaccard', 'kulsinski',\n 'mahalanobis', 'minkowski', 'rogerstanimoto', 'russellrao',\n 'seuclidean', 'sokalmichener', 'sokalsneath', 'sqeuclidean',\n 'yule']\n\nSee the documentation for scipy.spatial.distance for details on these\nmetrics:\nhttps://docs.scipy.org/doc/scipy/reference/spatial.distance.html" + "description": "The metric is used for distance computation. Any metric from scikit-learn\nor scipy.spatial.distance can be used.\n\nIf metric is \"precomputed\", X is assumed to be a distance matrix and\nmust be square. X may be a sparse matrix, in which case only \"nonzero\"\nelements may be considered neighbors.\n\nIf metric is a callable function, it is called on each\npair of instances (rows) and the resulting value recorded. The callable\nshould take two arrays as input and return one value indicating the\ndistance between them. This works for Scipy's metrics, but is less\nefficient than passing the metric name as a string.\n\nValid values for metric are:\n\n- from scikit-learn: ['cityblock', 'cosine', 'euclidean', 'l1', 'l2',\n 'manhattan']\n\n- from scipy.spatial.distance: ['braycurtis', 'canberra', 'chebyshev',\n 'correlation', 'dice', 'hamming', 'jaccard', 'kulsinski',\n 'mahalanobis', 'minkowski', 'rogerstanimoto', 'russellrao',\n 'seuclidean', 'sokalmichener', 'sokalsneath', 'sqeuclidean',\n 'yule']\n\nSee the documentation for scipy.spatial.distance for details on these\nmetrics:\nhttps://docs.scipy.org/doc/scipy/reference/spatial.distance.html." } }, { @@ -138307,7 +143075,9 @@ }, { "name": "_check_novelty_decision_function", + "unique_name": "_check_novelty_decision_function", "qname": "sklearn.neighbors._lof.LocalOutlierFactor._check_novelty_decision_function", + "unique_qname": "sklearn.neighbors._lof.LocalOutlierFactor._check_novelty_decision_function", "decorators": [], "parameters": [ { @@ -138329,7 +143099,9 @@ }, { "name": "_check_novelty_fit_predict", + "unique_name": "_check_novelty_fit_predict", "qname": "sklearn.neighbors._lof.LocalOutlierFactor._check_novelty_fit_predict", + "unique_qname": "sklearn.neighbors._lof.LocalOutlierFactor._check_novelty_fit_predict", "decorators": [], "parameters": [ { @@ -138351,7 +143123,9 @@ }, { "name": "_check_novelty_predict", + "unique_name": "_check_novelty_predict", "qname": "sklearn.neighbors._lof.LocalOutlierFactor._check_novelty_predict", + "unique_qname": "sklearn.neighbors._lof.LocalOutlierFactor._check_novelty_predict", "decorators": [], "parameters": [ { @@ -138373,7 +143147,9 @@ }, { "name": "_check_novelty_score_samples", + "unique_name": "_check_novelty_score_samples", "qname": "sklearn.neighbors._lof.LocalOutlierFactor._check_novelty_score_samples", + "unique_qname": "sklearn.neighbors._lof.LocalOutlierFactor._check_novelty_score_samples", "decorators": [], "parameters": [ { @@ -138395,7 +143171,9 @@ }, { "name": "_local_reachability_density", + "unique_name": "_local_reachability_density", "qname": "sklearn.neighbors._lof.LocalOutlierFactor._local_reachability_density", + "unique_qname": "sklearn.neighbors._lof.LocalOutlierFactor._local_reachability_density", "decorators": [], "parameters": [ { @@ -138437,7 +143215,9 @@ }, { "name": "_predict", + "unique_name": "_predict", "qname": "sklearn.neighbors._lof.LocalOutlierFactor._predict", + "unique_qname": "sklearn.neighbors._lof.LocalOutlierFactor._predict", "decorators": [], "parameters": [ { @@ -138469,7 +143249,9 @@ }, { "name": "decision_function", + "unique_name": "decision_function", "qname": "sklearn.neighbors._lof.LocalOutlierFactor.decision_function", + "unique_qname": "sklearn.neighbors._lof.LocalOutlierFactor.decision_function", "decorators": ["available_if(_check_novelty_decision_function)"], "parameters": [ { @@ -138501,7 +143283,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.neighbors._lof.LocalOutlierFactor.fit", + "unique_qname": "sklearn.neighbors._lof.LocalOutlierFactor.fit", "decorators": [], "parameters": [ { @@ -138543,7 +143327,9 @@ }, { "name": "fit_predict", + "unique_name": "fit_predict", "qname": "sklearn.neighbors._lof.LocalOutlierFactor.fit_predict", + "unique_qname": "sklearn.neighbors._lof.LocalOutlierFactor.fit_predict", "decorators": ["available_if(_check_novelty_fit_predict)"], "parameters": [ { @@ -138579,13 +143365,15 @@ ], "results": [], "is_public": true, - "description": "Fits the model to the training set X and returns the labels.\n\n**Not available for novelty detection (when novelty is set to True).** Label is 1 for an inlier and -1 for an outlier according to the LOF score and the contamination parameter.", - "docstring": "Fits the model to the training set X and returns the labels.\n\n**Not available for novelty detection (when novelty is set to True).**\nLabel is 1 for an inlier and -1 for an outlier according to the LOF\nscore and the contamination parameter.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features), default=None\n The query sample or samples to compute the Local Outlier Factor\n w.r.t. to the training samples.\n\ny : Ignored\n Not used, present for API consistency by convention.\n\nReturns\n-------\nis_inlier : ndarray of shape (n_samples,)\n Returns -1 for anomalies/outliers and 1 for inliers.", - "source_code": "\n@available_if(_check_novelty_fit_predict)\ndef fit_predict(self, X, y=None):\n \"\"\"Fits the model to the training set X and returns the labels.\n\n **Not available for novelty detection (when novelty is set to True).**\n Label is 1 for an inlier and -1 for an outlier according to the LOF\n score and the contamination parameter.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features), default=None\n The query sample or samples to compute the Local Outlier Factor\n w.r.t. to the training samples.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n is_inlier : ndarray of shape (n_samples,)\n Returns -1 for anomalies/outliers and 1 for inliers.\n \"\"\"\n return self.fit(X)._predict()" + "description": "Fit the model to the training set X and return the labels.\n\n**Not available for novelty detection (when novelty is set to True).** Label is 1 for an inlier and -1 for an outlier according to the LOF score and the contamination parameter.", + "docstring": "Fit the model to the training set X and return the labels.\n\n**Not available for novelty detection (when novelty is set to True).**\nLabel is 1 for an inlier and -1 for an outlier according to the LOF\nscore and the contamination parameter.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features), default=None\n The query sample or samples to compute the Local Outlier Factor\n w.r.t. to the training samples.\n\ny : Ignored\n Not used, present for API consistency by convention.\n\nReturns\n-------\nis_inlier : ndarray of shape (n_samples,)\n Returns -1 for anomalies/outliers and 1 for inliers.", + "source_code": "\n@available_if(_check_novelty_fit_predict)\ndef fit_predict(self, X, y=None):\n \"\"\"Fit the model to the training set X and return the labels.\n\n **Not available for novelty detection (when novelty is set to True).**\n Label is 1 for an inlier and -1 for an outlier according to the LOF\n score and the contamination parameter.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features), default=None\n The query sample or samples to compute the Local Outlier Factor\n w.r.t. to the training samples.\n\n y : Ignored\n Not used, present for API consistency by convention.\n\n Returns\n -------\n is_inlier : ndarray of shape (n_samples,)\n Returns -1 for anomalies/outliers and 1 for inliers.\n \"\"\"\n return self.fit(X)._predict()" }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.neighbors._lof.LocalOutlierFactor.predict", + "unique_qname": "sklearn.neighbors._lof.LocalOutlierFactor.predict", "decorators": ["available_if(_check_novelty_predict)"], "parameters": [ { @@ -138617,7 +143405,9 @@ }, { "name": "score_samples", + "unique_name": "score_samples", "qname": "sklearn.neighbors._lof.LocalOutlierFactor.score_samples", + "unique_qname": "sklearn.neighbors._lof.LocalOutlierFactor.score_samples", "decorators": ["available_if(_check_novelty_score_samples)"], "parameters": [ { @@ -138649,7 +143439,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.neighbors._nca.NeighborhoodComponentsAnalysis.__init__", + "unique_qname": "sklearn.neighbors._nca.NeighborhoodComponentsAnalysis.__init__", "decorators": [], "parameters": [ { @@ -138669,7 +143461,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "int, default=None", - "description": "Preferred dimensionality of the projected space.\nIf None it will be set to ``n_features``." + "description": "Preferred dimensionality of the projected space.\nIf None it will be set to `n_features`." } }, { @@ -138679,7 +143471,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "{'auto', 'pca', 'lda', 'identity', 'random'} or ndarray of shape (n_features_a, n_features_b), default='auto'", - "description": "Initialization of the linear transformation. Possible options are\n'auto', 'pca', 'lda', 'identity', 'random', and a numpy array of shape\n(n_features_a, n_features_b).\n\n'auto'\n Depending on ``n_components``, the most reasonable initialization\n will be chosen. If ``n_components <= n_classes`` we use 'lda', as\n it uses labels information. If not, but\n ``n_components < min(n_features, n_samples)``, we use 'pca', as\n it projects data in meaningful directions (those of higher\n variance). Otherwise, we just use 'identity'.\n\n'pca'\n ``n_components`` principal components of the inputs passed\n to :meth:`fit` will be used to initialize the transformation.\n (See :class:`~sklearn.decomposition.PCA`)\n\n'lda'\n ``min(n_components, n_classes)`` most discriminative\n components of the inputs passed to :meth:`fit` will be used to\n initialize the transformation. (If ``n_components > n_classes``,\n the rest of the components will be zero.) (See\n :class:`~sklearn.discriminant_analysis.LinearDiscriminantAnalysis`)\n\n'identity'\n If ``n_components`` is strictly smaller than the\n dimensionality of the inputs passed to :meth:`fit`, the identity\n matrix will be truncated to the first ``n_components`` rows.\n\n'random'\n The initial transformation will be a random array of shape\n `(n_components, n_features)`. Each value is sampled from the\n standard normal distribution.\n\nnumpy array\n n_features_b must match the dimensionality of the inputs passed to\n :meth:`fit` and n_features_a must be less than or equal to that.\n If ``n_components`` is not None, n_features_a must match it." + "description": "Initialization of the linear transformation. Possible options are\n`'auto'`, `'pca'`, `'lda'`, `'identity'`, `'random'`, and a numpy\narray of shape `(n_features_a, n_features_b)`.\n\n- `'auto'`\n Depending on `n_components`, the most reasonable initialization\n will be chosen. If `n_components <= n_classes` we use `'lda'`, as\n it uses labels information. If not, but\n `n_components < min(n_features, n_samples)`, we use `'pca'`, as\n it projects data in meaningful directions (those of higher\n variance). Otherwise, we just use `'identity'`.\n\n- `'pca'`\n `n_components` principal components of the inputs passed\n to :meth:`fit` will be used to initialize the transformation.\n (See :class:`~sklearn.decomposition.PCA`)\n\n- `'lda'`\n `min(n_components, n_classes)` most discriminative\n components of the inputs passed to :meth:`fit` will be used to\n initialize the transformation. (If `n_components > n_classes`,\n the rest of the components will be zero.) (See\n :class:`~sklearn.discriminant_analysis.LinearDiscriminantAnalysis`)\n\n- `'identity'`\n If `n_components` is strictly smaller than the\n dimensionality of the inputs passed to :meth:`fit`, the identity\n matrix will be truncated to the first `n_components` rows.\n\n- `'random'`\n The initial transformation will be a random array of shape\n `(n_components, n_features)`. Each value is sampled from the\n standard normal distribution.\n\n- numpy array\n `n_features_b` must match the dimensionality of the inputs passed\n to :meth:`fit` and n_features_a must be less than or equal to that.\n If `n_components` is not `None`, `n_features_a` must match it." } }, { @@ -138689,7 +143481,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "bool, default=False", - "description": "If True and :meth:`fit` has been called before, the solution of the\nprevious call to :meth:`fit` is used as the initial linear\ntransformation (``n_components`` and ``init`` will be ignored)." + "description": "If `True` and :meth:`fit` has been called before, the solution of the\nprevious call to :meth:`fit` is used as the initial linear\ntransformation (`n_components` and `init` will be ignored)." } }, { @@ -138719,7 +143511,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "callable, default=None", - "description": "If not None, this function is called after every iteration of the\noptimizer, taking as arguments the current solution (flattened\ntransformation matrix) and the number of iterations. This might be\nuseful in case one wants to examine or store the transformation\nfound after each iteration." + "description": "If not `None`, this function is called after every iteration of the\noptimizer, taking as arguments the current solution (flattened\ntransformation matrix) and the number of iterations. This might be\nuseful in case one wants to examine or store the transformation\nfound after each iteration." } }, { @@ -138729,7 +143521,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int, default=0", - "description": "If 0, no progress messages will be printed.\nIf 1, progress messages will be printed to stdout.\nIf > 1, progress messages will be printed and the ``disp``\nparameter of :func:`scipy.optimize.minimize` will be set to\n``verbose - 2``." + "description": "If 0, no progress messages will be printed.\nIf 1, progress messages will be printed to stdout.\nIf > 1, progress messages will be printed and the `disp`\nparameter of :func:`scipy.optimize.minimize` will be set to\n`verbose - 2`." } }, { @@ -138739,7 +143531,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int or numpy.RandomState, default=None", - "description": "A pseudo random number generator object or a seed for it if int. If\n``init='random'``, ``random_state`` is used to initialize the random\ntransformation. If ``init='pca'``, ``random_state`` is passed as an\nargument to PCA when initializing the transformation. Pass an int\nfor reproducible results across multiple function calls.\nSee :term: `Glossary `." + "description": "A pseudo random number generator object or a seed for it if int. If\n`init='random'`, `random_state` is used to initialize the random\ntransformation. If `init='pca'`, `random_state` is passed as an\nargument to PCA when initializing the transformation. Pass an int\nfor reproducible results across multiple function calls.\nSee :term:`Glossary `." } } ], @@ -138751,7 +143543,9 @@ }, { "name": "_callback", + "unique_name": "_callback", "qname": "sklearn.neighbors._nca.NeighborhoodComponentsAnalysis._callback", + "unique_qname": "sklearn.neighbors._nca.NeighborhoodComponentsAnalysis._callback", "decorators": [], "parameters": [ { @@ -138783,7 +143577,9 @@ }, { "name": "_initialize", + "unique_name": "_initialize", "qname": "sklearn.neighbors._nca.NeighborhoodComponentsAnalysis._initialize", + "unique_qname": "sklearn.neighbors._nca.NeighborhoodComponentsAnalysis._initialize", "decorators": [], "parameters": [ { @@ -138835,7 +143631,9 @@ }, { "name": "_loss_grad_lbfgs", + "unique_name": "_loss_grad_lbfgs", "qname": "sklearn.neighbors._nca.NeighborhoodComponentsAnalysis._loss_grad_lbfgs", + "unique_qname": "sklearn.neighbors._nca.NeighborhoodComponentsAnalysis._loss_grad_lbfgs", "decorators": [], "parameters": [ { @@ -138875,7 +143673,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "ndarray of shape (n_samples, n_samples)", - "description": "A mask where ``mask[i, j] == 1`` if ``X[i]`` and ``X[j]`` belong\nto the same class, and ``0`` otherwise." + "description": "A mask where `mask[i, j] == 1` if `X[i]` and `X[j]` belong\nto the same class, and `0` otherwise." } }, { @@ -138891,13 +143689,15 @@ ], "results": [], "is_public": false, - "description": "Compute the loss and the loss gradient w.r.t. ``transformation``.", - "docstring": "Compute the loss and the loss gradient w.r.t. ``transformation``.\n\nParameters\n----------\ntransformation : ndarray of shape (n_components * n_features,)\n The raveled linear transformation on which to compute loss and\n evaluate gradient.\n\nX : ndarray of shape (n_samples, n_features)\n The training samples.\n\nsame_class_mask : ndarray of shape (n_samples, n_samples)\n A mask where ``mask[i, j] == 1`` if ``X[i]`` and ``X[j]`` belong\n to the same class, and ``0`` otherwise.\n\nReturns\n-------\nloss : float\n The loss computed for the given transformation.\n\ngradient : ndarray of shape (n_components * n_features,)\n The new (flattened) gradient of the loss.", - "source_code": "\ndef _loss_grad_lbfgs(self, transformation, X, same_class_mask, sign=1.0):\n \"\"\"Compute the loss and the loss gradient w.r.t. ``transformation``.\n\n Parameters\n ----------\n transformation : ndarray of shape (n_components * n_features,)\n The raveled linear transformation on which to compute loss and\n evaluate gradient.\n\n X : ndarray of shape (n_samples, n_features)\n The training samples.\n\n same_class_mask : ndarray of shape (n_samples, n_samples)\n A mask where ``mask[i, j] == 1`` if ``X[i]`` and ``X[j]`` belong\n to the same class, and ``0`` otherwise.\n\n Returns\n -------\n loss : float\n The loss computed for the given transformation.\n\n gradient : ndarray of shape (n_components * n_features,)\n The new (flattened) gradient of the loss.\n \"\"\"\n if self.n_iter_ == 0:\n self.n_iter_ += 1\n if self.verbose:\n header_fields = ['Iteration', 'Objective Value', 'Time(s)']\n header_fmt = '{:>10} {:>20} {:>10}'\n header = header_fmt.format(*header_fields)\n cls_name = self.__class__.__name__\n print('[{}]'.format(cls_name))\n print('[{}] {}\\n[{}] {}'.format(cls_name, header, cls_name, '-' * len(header)))\n t_funcall = time.time()\n transformation = transformation.reshape(-1, X.shape[1])\n X_embedded = np.dot(X, transformation.T)\n p_ij = pairwise_distances(X_embedded, squared=True)\n np.fill_diagonal(p_ij, np.inf)\n p_ij = softmax(-p_ij)\n masked_p_ij = p_ij * same_class_mask\n p = np.sum(masked_p_ij, axis=1, keepdims=True)\n loss = np.sum(p)\n weighted_p_ij = masked_p_ij - p_ij * p\n weighted_p_ij_sym = weighted_p_ij + weighted_p_ij.T\n np.fill_diagonal(weighted_p_ij_sym, -weighted_p_ij.sum(axis=0))\n gradient = 2 * X_embedded.T.dot(weighted_p_ij_sym).dot(X)\n if self.verbose:\n t_funcall = time.time() - t_funcall\n values_fmt = '[{}] {:>10} {:>20.6e} {:>10.2f}'\n print(values_fmt.format(self.__class__.__name__, self.n_iter_, loss, t_funcall))\n sys.stdout.flush()\n return sign * loss, sign * gradient.ravel()" + "description": "Compute the loss and the loss gradient w.r.t. `transformation`.", + "docstring": "Compute the loss and the loss gradient w.r.t. `transformation`.\n\nParameters\n----------\ntransformation : ndarray of shape (n_components * n_features,)\n The raveled linear transformation on which to compute loss and\n evaluate gradient.\n\nX : ndarray of shape (n_samples, n_features)\n The training samples.\n\nsame_class_mask : ndarray of shape (n_samples, n_samples)\n A mask where `mask[i, j] == 1` if `X[i]` and `X[j]` belong\n to the same class, and `0` otherwise.\n\nReturns\n-------\nloss : float\n The loss computed for the given transformation.\n\ngradient : ndarray of shape (n_components * n_features,)\n The new (flattened) gradient of the loss.", + "source_code": "\ndef _loss_grad_lbfgs(self, transformation, X, same_class_mask, sign=1.0):\n \"\"\"Compute the loss and the loss gradient w.r.t. `transformation`.\n\n Parameters\n ----------\n transformation : ndarray of shape (n_components * n_features,)\n The raveled linear transformation on which to compute loss and\n evaluate gradient.\n\n X : ndarray of shape (n_samples, n_features)\n The training samples.\n\n same_class_mask : ndarray of shape (n_samples, n_samples)\n A mask where `mask[i, j] == 1` if `X[i]` and `X[j]` belong\n to the same class, and `0` otherwise.\n\n Returns\n -------\n loss : float\n The loss computed for the given transformation.\n\n gradient : ndarray of shape (n_components * n_features,)\n The new (flattened) gradient of the loss.\n \"\"\"\n if self.n_iter_ == 0:\n self.n_iter_ += 1\n if self.verbose:\n header_fields = ['Iteration', 'Objective Value', 'Time(s)']\n header_fmt = '{:>10} {:>20} {:>10}'\n header = header_fmt.format(*header_fields)\n cls_name = self.__class__.__name__\n print('[{}]'.format(cls_name))\n print('[{}] {}\\n[{}] {}'.format(cls_name, header, cls_name, '-' * len(header)))\n t_funcall = time.time()\n transformation = transformation.reshape(-1, X.shape[1])\n X_embedded = np.dot(X, transformation.T)\n p_ij = pairwise_distances(X_embedded, squared=True)\n np.fill_diagonal(p_ij, np.inf)\n p_ij = softmax(-p_ij)\n masked_p_ij = p_ij * same_class_mask\n p = np.sum(masked_p_ij, axis=1, keepdims=True)\n loss = np.sum(p)\n weighted_p_ij = masked_p_ij - p_ij * p\n weighted_p_ij_sym = weighted_p_ij + weighted_p_ij.T\n np.fill_diagonal(weighted_p_ij_sym, -weighted_p_ij.sum(axis=0))\n gradient = 2 * X_embedded.T.dot(weighted_p_ij_sym).dot(X)\n if self.verbose:\n t_funcall = time.time() - t_funcall\n values_fmt = '[{}] {:>10} {:>20.6e} {:>10.2f}'\n print(values_fmt.format(self.__class__.__name__, self.n_iter_, loss, t_funcall))\n sys.stdout.flush()\n return sign * loss, sign * gradient.ravel()" }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.neighbors._nca.NeighborhoodComponentsAnalysis._more_tags", + "unique_qname": "sklearn.neighbors._nca.NeighborhoodComponentsAnalysis._more_tags", "decorators": [], "parameters": [ { @@ -138919,7 +143719,9 @@ }, { "name": "_validate_params", + "unique_name": "_validate_params", "qname": "sklearn.neighbors._nca.NeighborhoodComponentsAnalysis._validate_params", + "unique_qname": "sklearn.neighbors._nca.NeighborhoodComponentsAnalysis._validate_params", "decorators": [], "parameters": [ { @@ -138956,12 +143758,14 @@ "results": [], "is_public": false, "description": "Validate parameters as soon as :meth:`fit` is called.", - "docstring": "Validate parameters as soon as :meth:`fit` is called.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n The training samples.\n\ny : array-like of shape (n_samples,)\n The corresponding training labels.\n\nReturns\n-------\nX : ndarray of shape (n_samples, n_features)\n The validated training samples.\n\ny : ndarray of shape (n_samples,)\n The validated training labels, encoded to be integers in\n the range(0, n_classes).\n\ninit : str or ndarray of shape (n_features_a, n_features_b)\n The validated initialization of the linear transformation.\n\nRaises\n-------\nTypeError\n If a parameter is not an instance of the desired type.\n\nValueError\n If a parameter's value violates its legal value range or if the\n combination of two or more given parameters is incompatible.", - "source_code": "\ndef _validate_params(self, X, y):\n \"\"\"Validate parameters as soon as :meth:`fit` is called.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The training samples.\n\n y : array-like of shape (n_samples,)\n The corresponding training labels.\n\n Returns\n -------\n X : ndarray of shape (n_samples, n_features)\n The validated training samples.\n\n y : ndarray of shape (n_samples,)\n The validated training labels, encoded to be integers in\n the range(0, n_classes).\n\n init : str or ndarray of shape (n_features_a, n_features_b)\n The validated initialization of the linear transformation.\n\n Raises\n -------\n TypeError\n If a parameter is not an instance of the desired type.\n\n ValueError\n If a parameter's value violates its legal value range or if the\n combination of two or more given parameters is incompatible.\n \"\"\"\n (X, y) = self._validate_data(X, y, ensure_min_samples=2)\n check_classification_targets(y)\n y = LabelEncoder().fit_transform(y)\n if self.n_components is not None:\n check_scalar(self.n_components, 'n_components', numbers.Integral, min_val=1)\n if self.n_components > X.shape[1]:\n raise ValueError('The preferred dimensionality of the projected space `n_components` ({}) cannot be greater than the given data dimensionality ({})!'.format(self.n_components, X.shape[1]))\n check_scalar(self.warm_start, 'warm_start', bool)\n if self.warm_start and hasattr(self, 'components_'):\n if self.components_.shape[1] != X.shape[1]:\n raise ValueError('The new inputs dimensionality ({}) does not match the input dimensionality of the previously learned transformation ({}).'.format(X.shape[1], self.components_.shape[1]))\n check_scalar(self.max_iter, 'max_iter', numbers.Integral, min_val=1)\n check_scalar(self.tol, 'tol', numbers.Real, min_val=0.0)\n check_scalar(self.verbose, 'verbose', numbers.Integral, min_val=0)\n if self.callback is not None:\n if not callable(self.callback):\n raise ValueError('`callback` is not callable.')\n init = self.init\n if isinstance(init, np.ndarray):\n init = check_array(init)\n if init.shape[1] != X.shape[1]:\n raise ValueError('The input dimensionality ({}) of the given linear transformation `init` must match the dimensionality of the given inputs `X` ({}).'.format(init.shape[1], X.shape[1]))\n if init.shape[0] > init.shape[1]:\n raise ValueError('The output dimensionality ({}) of the given linear transformation `init` cannot be greater than its input dimensionality ({}).'.format(init.shape[0], init.shape[1]))\n if self.n_components is not None:\n if self.n_components != init.shape[0]:\n raise ValueError('The preferred dimensionality of the projected space `n_components` ({}) does not match the output dimensionality of the given linear transformation `init` ({})!'.format(self.n_components, init.shape[0]))\n elif init in ['auto', 'pca', 'lda', 'identity', 'random']:\n pass\n else:\n raise ValueError(\"`init` must be 'auto', 'pca', 'lda', 'identity', 'random' or a numpy array of shape (n_components, n_features).\")\n return X, y, init" + "docstring": "Validate parameters as soon as :meth:`fit` is called.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n The training samples.\n\ny : array-like of shape (n_samples,)\n The corresponding training labels.\n\nReturns\n-------\nX : ndarray of shape (n_samples, n_features)\n The validated training samples.\n\ny : ndarray of shape (n_samples,)\n The validated training labels, encoded to be integers in\n the `range(0, n_classes)`.\n\ninit : str or ndarray of shape (n_features_a, n_features_b)\n The validated initialization of the linear transformation.\n\nRaises\n-------\nTypeError\n If a parameter is not an instance of the desired type.\n\nValueError\n If a parameter's value violates its legal value range or if the\n combination of two or more given parameters is incompatible.", + "source_code": "\ndef _validate_params(self, X, y):\n \"\"\"Validate parameters as soon as :meth:`fit` is called.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The training samples.\n\n y : array-like of shape (n_samples,)\n The corresponding training labels.\n\n Returns\n -------\n X : ndarray of shape (n_samples, n_features)\n The validated training samples.\n\n y : ndarray of shape (n_samples,)\n The validated training labels, encoded to be integers in\n the `range(0, n_classes)`.\n\n init : str or ndarray of shape (n_features_a, n_features_b)\n The validated initialization of the linear transformation.\n\n Raises\n -------\n TypeError\n If a parameter is not an instance of the desired type.\n\n ValueError\n If a parameter's value violates its legal value range or if the\n combination of two or more given parameters is incompatible.\n \"\"\"\n (X, y) = self._validate_data(X, y, ensure_min_samples=2)\n check_classification_targets(y)\n y = LabelEncoder().fit_transform(y)\n if self.n_components is not None:\n check_scalar(self.n_components, 'n_components', numbers.Integral, min_val=1)\n if self.n_components > X.shape[1]:\n raise ValueError('The preferred dimensionality of the projected space `n_components` ({}) cannot be greater than the given data dimensionality ({})!'.format(self.n_components, X.shape[1]))\n check_scalar(self.warm_start, 'warm_start', bool)\n if self.warm_start and hasattr(self, 'components_'):\n if self.components_.shape[1] != X.shape[1]:\n raise ValueError('The new inputs dimensionality ({}) does not match the input dimensionality of the previously learned transformation ({}).'.format(X.shape[1], self.components_.shape[1]))\n check_scalar(self.max_iter, 'max_iter', numbers.Integral, min_val=1)\n check_scalar(self.tol, 'tol', numbers.Real, min_val=0.0)\n check_scalar(self.verbose, 'verbose', numbers.Integral, min_val=0)\n if self.callback is not None:\n if not callable(self.callback):\n raise ValueError('`callback` is not callable.')\n init = self.init\n if isinstance(init, np.ndarray):\n init = check_array(init)\n if init.shape[1] != X.shape[1]:\n raise ValueError('The input dimensionality ({}) of the given linear transformation `init` must match the dimensionality of the given inputs `X` ({}).'.format(init.shape[1], X.shape[1]))\n if init.shape[0] > init.shape[1]:\n raise ValueError('The output dimensionality ({}) of the given linear transformation `init` cannot be greater than its input dimensionality ({}).'.format(init.shape[0], init.shape[1]))\n if self.n_components is not None:\n if self.n_components != init.shape[0]:\n raise ValueError('The preferred dimensionality of the projected space `n_components` ({}) does not match the output dimensionality of the given linear transformation `init` ({})!'.format(self.n_components, init.shape[0]))\n elif init in ['auto', 'pca', 'lda', 'identity', 'random']:\n pass\n else:\n raise ValueError(\"`init` must be 'auto', 'pca', 'lda', 'identity', 'random' or a numpy array of shape (n_components, n_features).\")\n return X, y, init" }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.neighbors._nca.NeighborhoodComponentsAnalysis.fit", + "unique_qname": "sklearn.neighbors._nca.NeighborhoodComponentsAnalysis.fit", "decorators": [], "parameters": [ { @@ -138998,12 +143802,14 @@ "results": [], "is_public": true, "description": "Fit the model according to the given training data.", - "docstring": "Fit the model according to the given training data.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n The training samples.\n\ny : array-like of shape (n_samples,)\n The corresponding training labels.\n\nReturns\n-------\nself : object\n returns a trained NeighborhoodComponentsAnalysis model.", - "source_code": "\ndef fit(self, X, y):\n \"\"\"Fit the model according to the given training data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The training samples.\n\n y : array-like of shape (n_samples,)\n The corresponding training labels.\n\n Returns\n -------\n self : object\n returns a trained NeighborhoodComponentsAnalysis model.\n \"\"\"\n (X, y, init) = self._validate_params(X, y)\n self.random_state_ = check_random_state(self.random_state)\n t_train = time.time()\n same_class_mask = y[:, np.newaxis] == y[np.newaxis, :]\n transformation = self._initialize(X, y, init)\n disp = self.verbose - 2 if self.verbose > 1 else -1\n optimizer_params = {'method': 'L-BFGS-B', 'fun': self._loss_grad_lbfgs, 'args': (X, same_class_mask, -1.0), 'jac': True, 'x0': transformation, 'tol': self.tol, 'options': dict(maxiter=self.max_iter, disp=disp), 'callback': self._callback}\n self.n_iter_ = 0\n opt_result = minimize(**optimizer_params)\n self.components_ = opt_result.x.reshape(-1, X.shape[1])\n t_train = time.time() - t_train\n if self.verbose:\n cls_name = self.__class__.__name__\n if not opt_result.success:\n warn('[{}] NCA did not converge: {}'.format(cls_name, opt_result.message), ConvergenceWarning)\n print('[{}] Training took {:8.2f}s.'.format(cls_name, t_train))\n return self" + "docstring": "Fit the model according to the given training data.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n The training samples.\n\ny : array-like of shape (n_samples,)\n The corresponding training labels.\n\nReturns\n-------\nself : object\n Fitted estimator.", + "source_code": "\ndef fit(self, X, y):\n \"\"\"Fit the model according to the given training data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The training samples.\n\n y : array-like of shape (n_samples,)\n The corresponding training labels.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n (X, y, init) = self._validate_params(X, y)\n self.random_state_ = check_random_state(self.random_state)\n t_train = time.time()\n same_class_mask = y[:, np.newaxis] == y[np.newaxis, :]\n transformation = self._initialize(X, y, init)\n disp = self.verbose - 2 if self.verbose > 1 else -1\n optimizer_params = {'method': 'L-BFGS-B', 'fun': self._loss_grad_lbfgs, 'args': (X, same_class_mask, -1.0), 'jac': True, 'x0': transformation, 'tol': self.tol, 'options': dict(maxiter=self.max_iter, disp=disp), 'callback': self._callback}\n self.n_iter_ = 0\n opt_result = minimize(**optimizer_params)\n self.components_ = opt_result.x.reshape(-1, X.shape[1])\n t_train = time.time() - t_train\n if self.verbose:\n cls_name = self.__class__.__name__\n if not opt_result.success:\n warn('[{}] NCA did not converge: {}'.format(cls_name, opt_result.message), ConvergenceWarning)\n print('[{}] Training took {:8.2f}s.'.format(cls_name, t_train))\n return self" }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.neighbors._nca.NeighborhoodComponentsAnalysis.transform", + "unique_qname": "sklearn.neighbors._nca.NeighborhoodComponentsAnalysis.transform", "decorators": [], "parameters": [ { @@ -139029,13 +143835,15 @@ ], "results": [], "is_public": true, - "description": "Applies the learned transformation to the given data.", - "docstring": "Applies the learned transformation to the given data.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Data samples.\n\nReturns\n-------\nX_embedded: ndarray of shape (n_samples, n_components)\n The data samples transformed.\n\nRaises\n------\nNotFittedError\n If :meth:`fit` has not been called before.", - "source_code": "\ndef transform(self, X):\n \"\"\"Applies the learned transformation to the given data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Data samples.\n\n Returns\n -------\n X_embedded: ndarray of shape (n_samples, n_components)\n The data samples transformed.\n\n Raises\n ------\n NotFittedError\n If :meth:`fit` has not been called before.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, reset=False)\n return np.dot(X, self.components_.T)" + "description": "Apply the learned transformation to the given data.", + "docstring": "Apply the learned transformation to the given data.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Data samples.\n\nReturns\n-------\nX_embedded: ndarray of shape (n_samples, n_components)\n The data samples transformed.\n\nRaises\n------\nNotFittedError\n If :meth:`fit` has not been called before.", + "source_code": "\ndef transform(self, X):\n \"\"\"Apply the learned transformation to the given data.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Data samples.\n\n Returns\n -------\n X_embedded: ndarray of shape (n_samples, n_components)\n The data samples transformed.\n\n Raises\n ------\n NotFittedError\n If :meth:`fit` has not been called before.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, reset=False)\n return np.dot(X, self.components_.T)" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.neighbors._nearest_centroid.NearestCentroid.__init__", + "unique_qname": "sklearn.neighbors._nearest_centroid.NearestCentroid.__init__", "decorators": [], "parameters": [ { @@ -139055,7 +143863,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "str or callable", - "description": "The metric to use when calculating distance between instances in a\nfeature array. If metric is a string or callable, it must be one of\nthe options allowed by metrics.pairwise.pairwise_distances for its\nmetric parameter.\nThe centroids for the samples corresponding to each class is the point\nfrom which the sum of the distances (according to the metric) of all\nsamples that belong to that particular class are minimized.\nIf the \"manhattan\" metric is provided, this centroid is the median and\nfor all other metrics, the centroid is now set to be the mean.\n\n.. versionchanged:: 0.19\n ``metric='precomputed'`` was deprecated and now raises an error" + "description": "The metric to use when calculating distance between instances in a\nfeature array. If metric is a string or callable, it must be one of\nthe options allowed by\n:func:`~sklearn.metrics.pairwise_distances` for its metric\nparameter. The centroids for the samples corresponding to each class is\nthe point from which the sum of the distances (according to the metric)\nof all samples that belong to that particular class are minimized.\nIf the `\"manhattan\"` metric is provided, this centroid is the median\nand for all other metrics, the centroid is now set to be the mean.\n\n.. versionchanged:: 0.19\n `metric='precomputed'` was deprecated and now raises an error" } }, { @@ -139077,7 +143885,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.neighbors._nearest_centroid.NearestCentroid.fit", + "unique_qname": "sklearn.neighbors._nearest_centroid.NearestCentroid.fit", "decorators": [], "parameters": [ { @@ -139107,19 +143917,21 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "array-like of shape (n_samples,)", - "description": "Target values (integers)" + "description": "Target values." } } ], "results": [], "is_public": true, "description": "Fit the NearestCentroid model according to the given training data.", - "docstring": "Fit the NearestCentroid model according to the given training data.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n Note that centroid shrinking cannot be used with sparse matrices.\ny : array-like of shape (n_samples,)\n Target values (integers)", - "source_code": "\ndef fit(self, X, y):\n \"\"\"\n Fit the NearestCentroid model according to the given training data.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n Note that centroid shrinking cannot be used with sparse matrices.\n y : array-like of shape (n_samples,)\n Target values (integers)\n \"\"\"\n if self.metric == 'precomputed':\n raise ValueError('Precomputed is not supported.')\n if self.metric == 'manhattan':\n (X, y) = self._validate_data(X, y, accept_sparse=['csc'])\n else:\n (X, y) = self._validate_data(X, y, accept_sparse=['csr', 'csc'])\n is_X_sparse = sp.issparse(X)\n if is_X_sparse and self.shrink_threshold:\n raise ValueError('threshold shrinking not supported for sparse input')\n check_classification_targets(y)\n (n_samples, n_features) = X.shape\n le = LabelEncoder()\n y_ind = le.fit_transform(y)\n self.classes_ = classes = le.classes_\n n_classes = classes.size\n if n_classes < 2:\n raise ValueError('The number of classes has to be greater than one; got %d class' % n_classes)\n self.centroids_ = np.empty((n_classes, n_features), dtype=np.float64)\n nk = np.zeros(n_classes)\n for cur_class in range(n_classes):\n center_mask = y_ind == cur_class\n nk[cur_class] = np.sum(center_mask)\n if is_X_sparse:\n center_mask = np.where(center_mask)[0]\n if self.metric == 'manhattan':\n if not is_X_sparse:\n self.centroids_[cur_class] = np.median(X[center_mask], axis=0)\n else:\n self.centroids_[cur_class] = csc_median_axis_0(X[center_mask])\n else:\n if self.metric != 'euclidean':\n warnings.warn('Averaging for metrics other than euclidean and manhattan not supported. The average is set to be the mean.')\n self.centroids_[cur_class] = X[center_mask].mean(axis=0)\n if self.shrink_threshold:\n if np.all(np.ptp(X, axis=0) == 0):\n raise ValueError('All features have zero variance. Division by zero.')\n dataset_centroid_ = np.mean(X, axis=0)\n m = np.sqrt(1.0 / nk - 1.0 / n_samples)\n variance = (X - self.centroids_[y_ind])**2\n variance = variance.sum(axis=0)\n s = np.sqrt(variance / (n_samples - n_classes))\n s += np.median(s)\n mm = m.reshape(len(m), 1)\n ms = mm * s\n deviation = (self.centroids_ - dataset_centroid_) / ms\n signs = np.sign(deviation)\n deviation = np.abs(deviation) - self.shrink_threshold\n np.clip(deviation, 0, None, out=deviation)\n deviation *= signs\n msd = ms * deviation\n self.centroids_ = dataset_centroid_[np.newaxis, :] + msd\n return self" + "docstring": "Fit the NearestCentroid model according to the given training data.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n Note that centroid shrinking cannot be used with sparse matrices.\ny : array-like of shape (n_samples,)\n Target values.\n\nReturns\n-------\nself : object\n Fitted estimator.", + "source_code": "\ndef fit(self, X, y):\n \"\"\"\n Fit the NearestCentroid model according to the given training data.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Training vector, where `n_samples` is the number of samples and\n `n_features` is the number of features.\n Note that centroid shrinking cannot be used with sparse matrices.\n y : array-like of shape (n_samples,)\n Target values.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n if self.metric == 'precomputed':\n raise ValueError('Precomputed is not supported.')\n if self.metric == 'manhattan':\n (X, y) = self._validate_data(X, y, accept_sparse=['csc'])\n else:\n (X, y) = self._validate_data(X, y, accept_sparse=['csr', 'csc'])\n is_X_sparse = sp.issparse(X)\n if is_X_sparse and self.shrink_threshold:\n raise ValueError('threshold shrinking not supported for sparse input')\n check_classification_targets(y)\n (n_samples, n_features) = X.shape\n le = LabelEncoder()\n y_ind = le.fit_transform(y)\n self.classes_ = classes = le.classes_\n n_classes = classes.size\n if n_classes < 2:\n raise ValueError('The number of classes has to be greater than one; got %d class' % n_classes)\n self.centroids_ = np.empty((n_classes, n_features), dtype=np.float64)\n nk = np.zeros(n_classes)\n for cur_class in range(n_classes):\n center_mask = y_ind == cur_class\n nk[cur_class] = np.sum(center_mask)\n if is_X_sparse:\n center_mask = np.where(center_mask)[0]\n if self.metric == 'manhattan':\n if not is_X_sparse:\n self.centroids_[cur_class] = np.median(X[center_mask], axis=0)\n else:\n self.centroids_[cur_class] = csc_median_axis_0(X[center_mask])\n else:\n if self.metric != 'euclidean':\n warnings.warn('Averaging for metrics other than euclidean and manhattan not supported. The average is set to be the mean.')\n self.centroids_[cur_class] = X[center_mask].mean(axis=0)\n if self.shrink_threshold:\n if np.all(np.ptp(X, axis=0) == 0):\n raise ValueError('All features have zero variance. Division by zero.')\n dataset_centroid_ = np.mean(X, axis=0)\n m = np.sqrt(1.0 / nk - 1.0 / n_samples)\n variance = (X - self.centroids_[y_ind])**2\n variance = variance.sum(axis=0)\n s = np.sqrt(variance / (n_samples - n_classes))\n s += np.median(s)\n mm = m.reshape(len(m), 1)\n ms = mm * s\n deviation = (self.centroids_ - dataset_centroid_) / ms\n signs = np.sign(deviation)\n deviation = np.abs(deviation) - self.shrink_threshold\n np.clip(deviation, 0, None, out=deviation)\n deviation *= signs\n msd = ms * deviation\n self.centroids_ = dataset_centroid_[np.newaxis, :] + msd\n return self" }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.neighbors._nearest_centroid.NearestCentroid.predict", + "unique_qname": "sklearn.neighbors._nearest_centroid.NearestCentroid.predict", "decorators": [], "parameters": [ { @@ -139138,20 +143950,22 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "array-like of shape (n_samples, n_features)", - "description": "" + "type": "{array-like, sparse matrix} of shape (n_samples, n_features)", + "description": "Test samples." } } ], "results": [], "is_public": true, - "description": "Perform classification on an array of test vectors X.\n\nThe predicted class C for each sample in X is returned.", - "docstring": "Perform classification on an array of test vectors X.\n\nThe predicted class C for each sample in X is returned.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n\nReturns\n-------\nC : ndarray of shape (n_samples,)\n\nNotes\n-----\nIf the metric constructor parameter is \"precomputed\", X is assumed to\nbe the distance matrix between the data to be predicted and\n``self.centroids_``.", - "source_code": "\ndef predict(self, X):\n \"\"\"Perform classification on an array of test vectors X.\n\n The predicted class C for each sample in X is returned.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n\n Returns\n -------\n C : ndarray of shape (n_samples,)\n\n Notes\n -----\n If the metric constructor parameter is \"precomputed\", X is assumed to\n be the distance matrix between the data to be predicted and\n ``self.centroids_``.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse='csr', reset=False)\n return self.classes_[pairwise_distances(X, self.centroids_, metric=self.metric).argmin(axis=1)]" + "description": "Perform classification on an array of test vectors `X`.\n\nThe predicted class `C` for each sample in `X` is returned.", + "docstring": "Perform classification on an array of test vectors `X`.\n\nThe predicted class `C` for each sample in `X` is returned.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Test samples.\n\nReturns\n-------\nC : ndarray of shape (n_samples,)\n The predicted classes.\n\nNotes\n-----\nIf the metric constructor parameter is `\"precomputed\"`, `X` is assumed\nto be the distance matrix between the data to be predicted and\n`self.centroids_`.", + "source_code": "\ndef predict(self, X):\n \"\"\"Perform classification on an array of test vectors `X`.\n\n The predicted class `C` for each sample in `X` is returned.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Test samples.\n\n Returns\n -------\n C : ndarray of shape (n_samples,)\n The predicted classes.\n\n Notes\n -----\n If the metric constructor parameter is `\"precomputed\"`, `X` is assumed\n to be the distance matrix between the data to be predicted and\n `self.centroids_`.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse='csr', reset=False)\n return self.classes_[pairwise_distances(X, self.centroids_, metric=self.metric).argmin(axis=1)]" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.neighbors._regression.KNeighborsRegressor.__init__", + "unique_qname": "sklearn.neighbors._regression.KNeighborsRegressor.__init__", "decorators": [], "parameters": [ { @@ -139253,7 +144067,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.neighbors._regression.KNeighborsRegressor._more_tags", + "unique_qname": "sklearn.neighbors._regression.KNeighborsRegressor._more_tags", "decorators": [], "parameters": [ { @@ -139275,7 +144091,9 @@ }, { "name": "_pairwise", + "unique_name": "_pairwise@getter", "qname": "sklearn.neighbors._regression.KNeighborsRegressor._pairwise", + "unique_qname": "sklearn.neighbors._regression.KNeighborsRegressor._pairwise@getter", "decorators": [ "deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -139300,7 +144118,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.neighbors._regression.KNeighborsRegressor.fit", + "unique_qname": "sklearn.neighbors._regression.KNeighborsRegressor.fit", "decorators": [], "parameters": [ { @@ -139342,7 +144162,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.neighbors._regression.KNeighborsRegressor.predict", + "unique_qname": "sklearn.neighbors._regression.KNeighborsRegressor.predict", "decorators": [], "parameters": [ { @@ -139370,11 +144192,13 @@ "is_public": true, "description": "Predict the target for the provided data.", "docstring": "Predict the target for the provided data.\n\nParameters\n----------\nX : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\nReturns\n-------\ny : ndarray of shape (n_queries,) or (n_queries, n_outputs), dtype=int\n Target values.", - "source_code": "\ndef predict(self, X):\n \"\"\"Predict the target for the provided data.\n\n Parameters\n ----------\n X : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\n Returns\n -------\n y : ndarray of shape (n_queries,) or (n_queries, n_outputs), dtype=int\n Target values.\n \"\"\"\n X = self._validate_data(X, accept_sparse='csr', reset=False)\n (neigh_dist, neigh_ind) = self.kneighbors(X)\n weights = _get_weights(neigh_dist, self.weights)\n _y = self._y\n if _y.ndim == 1:\n _y = _y.reshape((-1, 1))\n if weights is None:\n y_pred = np.mean(_y[neigh_ind], axis=1)\n else:\n y_pred = np.empty((X.shape[0], _y.shape[1]), dtype=np.float64)\n denom = np.sum(weights, axis=1)\n for j in range(_y.shape[1]):\n num = np.sum(_y[neigh_ind, j] * weights, axis=1)\n y_pred[:, j] = num / denom\n if self._y.ndim == 1:\n y_pred = y_pred.ravel()\n return y_pred" + "source_code": "\ndef predict(self, X):\n \"\"\"Predict the target for the provided data.\n\n Parameters\n ----------\n X : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\n Returns\n -------\n y : ndarray of shape (n_queries,) or (n_queries, n_outputs), dtype=int\n Target values.\n \"\"\"\n (neigh_dist, neigh_ind) = self.kneighbors(X)\n weights = _get_weights(neigh_dist, self.weights)\n _y = self._y\n if _y.ndim == 1:\n _y = _y.reshape((-1, 1))\n if weights is None:\n y_pred = np.mean(_y[neigh_ind], axis=1)\n else:\n y_pred = np.empty((X.shape[0], _y.shape[1]), dtype=np.float64)\n denom = np.sum(weights, axis=1)\n for j in range(_y.shape[1]):\n num = np.sum(_y[neigh_ind, j] * weights, axis=1)\n y_pred[:, j] = num / denom\n if self._y.ndim == 1:\n y_pred = y_pred.ravel()\n return y_pred" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.neighbors._regression.RadiusNeighborsRegressor.__init__", + "unique_qname": "sklearn.neighbors._regression.RadiusNeighborsRegressor.__init__", "decorators": [], "parameters": [ { @@ -139476,7 +144300,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.neighbors._regression.RadiusNeighborsRegressor.fit", + "unique_qname": "sklearn.neighbors._regression.RadiusNeighborsRegressor.fit", "decorators": [], "parameters": [ { @@ -139518,7 +144344,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.neighbors._regression.RadiusNeighborsRegressor.predict", + "unique_qname": "sklearn.neighbors._regression.RadiusNeighborsRegressor.predict", "decorators": [], "parameters": [ { @@ -139546,11 +144374,13 @@ "is_public": true, "description": "Predict the target for the provided data.", "docstring": "Predict the target for the provided data.\n\nParameters\n----------\nX : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\nReturns\n-------\ny : ndarray of shape (n_queries,) or (n_queries, n_outputs), dtype=double\n Target values.", - "source_code": "\ndef predict(self, X):\n \"\"\"Predict the target for the provided data.\n\n Parameters\n ----------\n X : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\n Returns\n -------\n y : ndarray of shape (n_queries,) or (n_queries, n_outputs), dtype=double\n Target values.\n \"\"\"\n X = self._validate_data(X, accept_sparse='csr', reset=False)\n (neigh_dist, neigh_ind) = self.radius_neighbors(X)\n weights = _get_weights(neigh_dist, self.weights)\n _y = self._y\n if _y.ndim == 1:\n _y = _y.reshape((-1, 1))\n empty_obs = np.full_like(_y[0], np.nan)\n if weights is None:\n y_pred = np.array([np.mean(_y[ind, :], axis=0) if len(ind) else empty_obs for (i, ind) in enumerate(neigh_ind)])\n else:\n y_pred = np.array([np.average(_y[ind, :], axis=0, weights=weights[i]) if len(ind) else empty_obs for (i, ind) in enumerate(neigh_ind)])\n if np.any(np.isnan(y_pred)):\n empty_warning_msg = 'One or more samples have no neighbors within specified radius; predicting NaN.'\n warnings.warn(empty_warning_msg)\n if self._y.ndim == 1:\n y_pred = y_pred.ravel()\n return y_pred" + "source_code": "\ndef predict(self, X):\n \"\"\"Predict the target for the provided data.\n\n Parameters\n ----------\n X : array-like of shape (n_queries, n_features), or (n_queries, n_indexed) if metric == 'precomputed'\n Test samples.\n\n Returns\n -------\n y : ndarray of shape (n_queries,) or (n_queries, n_outputs), dtype=double\n Target values.\n \"\"\"\n (neigh_dist, neigh_ind) = self.radius_neighbors(X)\n weights = _get_weights(neigh_dist, self.weights)\n _y = self._y\n if _y.ndim == 1:\n _y = _y.reshape((-1, 1))\n empty_obs = np.full_like(_y[0], np.nan)\n if weights is None:\n y_pred = np.array([np.mean(_y[ind, :], axis=0) if len(ind) else empty_obs for (i, ind) in enumerate(neigh_ind)])\n else:\n y_pred = np.array([np.average(_y[ind, :], axis=0, weights=weights[i]) if len(ind) else empty_obs for (i, ind) in enumerate(neigh_ind)])\n if np.any(np.isnan(y_pred)):\n empty_warning_msg = 'One or more samples have no neighbors within specified radius; predicting NaN.'\n warnings.warn(empty_warning_msg)\n if self._y.ndim == 1:\n y_pred = y_pred.ravel()\n return y_pred" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.neighbors._unsupervised.NearestNeighbors.__init__", + "unique_qname": "sklearn.neighbors._unsupervised.NearestNeighbors.__init__", "decorators": [], "parameters": [ { @@ -139652,7 +144482,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.neighbors._unsupervised.NearestNeighbors.fit", + "unique_qname": "sklearn.neighbors._unsupervised.NearestNeighbors.fit", "decorators": [], "parameters": [ { @@ -139694,7 +144526,9 @@ }, { "name": "configuration", + "unique_name": "configuration", "qname": "sklearn.neighbors.setup.configuration", + "unique_qname": "sklearn.neighbors.setup.configuration", "decorators": [], "parameters": [ { @@ -139726,7 +144560,9 @@ }, { "name": "binary_log_loss", + "unique_name": "binary_log_loss", "qname": "sklearn.neural_network._base.binary_log_loss", + "unique_qname": "sklearn.neural_network._base.binary_log_loss", "decorators": [], "parameters": [ { @@ -139758,7 +144594,9 @@ }, { "name": "inplace_identity", + "unique_name": "inplace_identity", "qname": "sklearn.neural_network._base.inplace_identity", + "unique_qname": "sklearn.neural_network._base.inplace_identity", "decorators": [], "parameters": [ { @@ -139780,7 +144618,9 @@ }, { "name": "inplace_identity_derivative", + "unique_name": "inplace_identity_derivative", "qname": "sklearn.neural_network._base.inplace_identity_derivative", + "unique_qname": "sklearn.neural_network._base.inplace_identity_derivative", "decorators": [], "parameters": [ { @@ -139812,7 +144652,9 @@ }, { "name": "inplace_logistic", + "unique_name": "inplace_logistic", "qname": "sklearn.neural_network._base.inplace_logistic", + "unique_qname": "sklearn.neural_network._base.inplace_logistic", "decorators": [], "parameters": [ { @@ -139834,7 +144676,9 @@ }, { "name": "inplace_logistic_derivative", + "unique_name": "inplace_logistic_derivative", "qname": "sklearn.neural_network._base.inplace_logistic_derivative", + "unique_qname": "sklearn.neural_network._base.inplace_logistic_derivative", "decorators": [], "parameters": [ { @@ -139866,7 +144710,9 @@ }, { "name": "inplace_relu", + "unique_name": "inplace_relu", "qname": "sklearn.neural_network._base.inplace_relu", + "unique_qname": "sklearn.neural_network._base.inplace_relu", "decorators": [], "parameters": [ { @@ -139888,7 +144734,9 @@ }, { "name": "inplace_relu_derivative", + "unique_name": "inplace_relu_derivative", "qname": "sklearn.neural_network._base.inplace_relu_derivative", + "unique_qname": "sklearn.neural_network._base.inplace_relu_derivative", "decorators": [], "parameters": [ { @@ -139920,7 +144768,9 @@ }, { "name": "inplace_softmax", + "unique_name": "inplace_softmax", "qname": "sklearn.neural_network._base.inplace_softmax", + "unique_qname": "sklearn.neural_network._base.inplace_softmax", "decorators": [], "parameters": [ { @@ -139942,7 +144792,9 @@ }, { "name": "inplace_tanh", + "unique_name": "inplace_tanh", "qname": "sklearn.neural_network._base.inplace_tanh", + "unique_qname": "sklearn.neural_network._base.inplace_tanh", "decorators": [], "parameters": [ { @@ -139964,7 +144816,9 @@ }, { "name": "inplace_tanh_derivative", + "unique_name": "inplace_tanh_derivative", "qname": "sklearn.neural_network._base.inplace_tanh_derivative", + "unique_qname": "sklearn.neural_network._base.inplace_tanh_derivative", "decorators": [], "parameters": [ { @@ -139996,7 +144850,9 @@ }, { "name": "log_loss", + "unique_name": "log_loss", "qname": "sklearn.neural_network._base.log_loss", + "unique_qname": "sklearn.neural_network._base.log_loss", "decorators": [], "parameters": [ { @@ -140028,7 +144884,9 @@ }, { "name": "squared_loss", + "unique_name": "squared_loss", "qname": "sklearn.neural_network._base.squared_loss", + "unique_qname": "sklearn.neural_network._base.squared_loss", "decorators": [], "parameters": [ { @@ -140060,7 +144918,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron.__init__", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -140322,7 +145182,9 @@ }, { "name": "_backprop", + "unique_name": "_backprop", "qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._backprop", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._backprop", "decorators": [], "parameters": [ { @@ -140404,7 +145266,9 @@ }, { "name": "_check_solver", + "unique_name": "_check_solver", "qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._check_solver", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._check_solver", "decorators": [], "parameters": [ { @@ -140426,7 +145290,9 @@ }, { "name": "_compute_loss_grad", + "unique_name": "_compute_loss_grad", "qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._compute_loss_grad", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._compute_loss_grad", "decorators": [], "parameters": [ { @@ -140508,7 +145374,9 @@ }, { "name": "_fit", + "unique_name": "_fit", "qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._fit", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._fit", "decorators": [], "parameters": [ { @@ -140560,7 +145428,9 @@ }, { "name": "_fit_lbfgs", + "unique_name": "_fit_lbfgs", "qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._fit_lbfgs", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._fit_lbfgs", "decorators": [], "parameters": [ { @@ -140652,7 +145522,9 @@ }, { "name": "_fit_stochastic", + "unique_name": "_fit_stochastic", "qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._fit_stochastic", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._fit_stochastic", "decorators": [], "parameters": [ { @@ -140754,7 +145626,9 @@ }, { "name": "_forward_pass", + "unique_name": "_forward_pass", "qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._forward_pass", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._forward_pass", "decorators": [], "parameters": [ { @@ -140786,7 +145660,9 @@ }, { "name": "_forward_pass_fast", + "unique_name": "_forward_pass_fast", "qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._forward_pass_fast", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._forward_pass_fast", "decorators": [], "parameters": [ { @@ -140818,7 +145694,9 @@ }, { "name": "_init_coef", + "unique_name": "_init_coef", "qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._init_coef", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._init_coef", "decorators": [], "parameters": [ { @@ -140870,7 +145748,9 @@ }, { "name": "_initialize", + "unique_name": "_initialize", "qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._initialize", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._initialize", "decorators": [], "parameters": [ { @@ -140922,7 +145802,9 @@ }, { "name": "_loss_grad_lbfgs", + "unique_name": "_loss_grad_lbfgs", "qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._loss_grad_lbfgs", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._loss_grad_lbfgs", "decorators": [], "parameters": [ { @@ -141014,7 +145896,9 @@ }, { "name": "_unpack", + "unique_name": "_unpack", "qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._unpack", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._unpack", "decorators": [], "parameters": [ { @@ -141046,7 +145930,9 @@ }, { "name": "_update_no_improvement_count", + "unique_name": "_update_no_improvement_count", "qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._update_no_improvement_count", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._update_no_improvement_count", "decorators": [], "parameters": [ { @@ -141098,7 +145984,9 @@ }, { "name": "_validate_hyperparameters", + "unique_name": "_validate_hyperparameters", "qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._validate_hyperparameters", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron._validate_hyperparameters", "decorators": [], "parameters": [ { @@ -141120,7 +146008,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron.fit", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron.fit", "decorators": [], "parameters": [ { @@ -141162,7 +146052,9 @@ }, { "name": "partial_fit", + "unique_name": "partial_fit", "qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron.partial_fit", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.BaseMultilayerPerceptron.partial_fit", "decorators": ["available_if(_check_solver)"], "parameters": [ { @@ -141204,7 +146096,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.neural_network._multilayer_perceptron.MLPClassifier.__init__", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.MLPClassifier.__init__", "decorators": [], "parameters": [ { @@ -141456,7 +146350,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.neural_network._multilayer_perceptron.MLPClassifier._more_tags", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.MLPClassifier._more_tags", "decorators": [], "parameters": [ { @@ -141478,7 +146374,9 @@ }, { "name": "_validate_input", + "unique_name": "_validate_input", "qname": "sklearn.neural_network._multilayer_perceptron.MLPClassifier._validate_input", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.MLPClassifier._validate_input", "decorators": [], "parameters": [ { @@ -141540,7 +146438,9 @@ }, { "name": "partial_fit", + "unique_name": "partial_fit", "qname": "sklearn.neural_network._multilayer_perceptron.MLPClassifier.partial_fit", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.MLPClassifier.partial_fit", "decorators": ["available_if(lambda est: est._check_solver())"], "parameters": [ { @@ -141592,7 +146492,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.neural_network._multilayer_perceptron.MLPClassifier.predict", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.MLPClassifier.predict", "decorators": [], "parameters": [ { @@ -141624,7 +146526,9 @@ }, { "name": "predict_log_proba", + "unique_name": "predict_log_proba", "qname": "sklearn.neural_network._multilayer_perceptron.MLPClassifier.predict_log_proba", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.MLPClassifier.predict_log_proba", "decorators": [], "parameters": [ { @@ -141656,7 +146560,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.neural_network._multilayer_perceptron.MLPClassifier.predict_proba", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.MLPClassifier.predict_proba", "decorators": [], "parameters": [ { @@ -141688,7 +146594,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.neural_network._multilayer_perceptron.MLPRegressor.__init__", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.MLPRegressor.__init__", "decorators": [], "parameters": [ { @@ -141940,7 +146848,9 @@ }, { "name": "_validate_input", + "unique_name": "_validate_input", "qname": "sklearn.neural_network._multilayer_perceptron.MLPRegressor._validate_input", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.MLPRegressor._validate_input", "decorators": [], "parameters": [ { @@ -142002,7 +146912,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.neural_network._multilayer_perceptron.MLPRegressor.predict", + "unique_qname": "sklearn.neural_network._multilayer_perceptron.MLPRegressor.predict", "decorators": [], "parameters": [ { @@ -142034,7 +146946,9 @@ }, { "name": "_pack", + "unique_name": "_pack", "qname": "sklearn.neural_network._multilayer_perceptron._pack", + "unique_qname": "sklearn.neural_network._multilayer_perceptron._pack", "decorators": [], "parameters": [ { @@ -142066,7 +146980,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.neural_network._rbm.BernoulliRBM.__init__", + "unique_qname": "sklearn.neural_network._rbm.BernoulliRBM.__init__", "decorators": [], "parameters": [ { @@ -142148,7 +147064,9 @@ }, { "name": "_fit", + "unique_name": "_fit", "qname": "sklearn.neural_network._rbm.BernoulliRBM._fit", + "unique_qname": "sklearn.neural_network._rbm.BernoulliRBM._fit", "decorators": [], "parameters": [ { @@ -142190,7 +147108,9 @@ }, { "name": "_free_energy", + "unique_name": "_free_energy", "qname": "sklearn.neural_network._rbm.BernoulliRBM._free_energy", + "unique_qname": "sklearn.neural_network._rbm.BernoulliRBM._free_energy", "decorators": [], "parameters": [ { @@ -142222,7 +147142,9 @@ }, { "name": "_mean_hiddens", + "unique_name": "_mean_hiddens", "qname": "sklearn.neural_network._rbm.BernoulliRBM._mean_hiddens", + "unique_qname": "sklearn.neural_network._rbm.BernoulliRBM._mean_hiddens", "decorators": [], "parameters": [ { @@ -142254,7 +147176,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.neural_network._rbm.BernoulliRBM._more_tags", + "unique_qname": "sklearn.neural_network._rbm.BernoulliRBM._more_tags", "decorators": [], "parameters": [ { @@ -142276,7 +147200,9 @@ }, { "name": "_sample_hiddens", + "unique_name": "_sample_hiddens", "qname": "sklearn.neural_network._rbm.BernoulliRBM._sample_hiddens", + "unique_qname": "sklearn.neural_network._rbm.BernoulliRBM._sample_hiddens", "decorators": [], "parameters": [ { @@ -142318,7 +147244,9 @@ }, { "name": "_sample_visibles", + "unique_name": "_sample_visibles", "qname": "sklearn.neural_network._rbm.BernoulliRBM._sample_visibles", + "unique_qname": "sklearn.neural_network._rbm.BernoulliRBM._sample_visibles", "decorators": [], "parameters": [ { @@ -142360,7 +147288,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.neural_network._rbm.BernoulliRBM.fit", + "unique_qname": "sklearn.neural_network._rbm.BernoulliRBM.fit", "decorators": [], "parameters": [ { @@ -142402,7 +147332,9 @@ }, { "name": "gibbs", + "unique_name": "gibbs", "qname": "sklearn.neural_network._rbm.BernoulliRBM.gibbs", + "unique_qname": "sklearn.neural_network._rbm.BernoulliRBM.gibbs", "decorators": [], "parameters": [ { @@ -142434,7 +147366,9 @@ }, { "name": "partial_fit", + "unique_name": "partial_fit", "qname": "sklearn.neural_network._rbm.BernoulliRBM.partial_fit", + "unique_qname": "sklearn.neural_network._rbm.BernoulliRBM.partial_fit", "decorators": [], "parameters": [ { @@ -142476,7 +147410,9 @@ }, { "name": "score_samples", + "unique_name": "score_samples", "qname": "sklearn.neural_network._rbm.BernoulliRBM.score_samples", + "unique_qname": "sklearn.neural_network._rbm.BernoulliRBM.score_samples", "decorators": [], "parameters": [ { @@ -142508,7 +147444,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.neural_network._rbm.BernoulliRBM.transform", + "unique_qname": "sklearn.neural_network._rbm.BernoulliRBM.transform", "decorators": [], "parameters": [ { @@ -142540,7 +147478,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.neural_network._stochastic_optimizers.AdamOptimizer.__init__", + "unique_qname": "sklearn.neural_network._stochastic_optimizers.AdamOptimizer.__init__", "decorators": [], "parameters": [ { @@ -142612,7 +147552,9 @@ }, { "name": "_get_updates", + "unique_name": "_get_updates", "qname": "sklearn.neural_network._stochastic_optimizers.AdamOptimizer._get_updates", + "unique_qname": "sklearn.neural_network._stochastic_optimizers.AdamOptimizer._get_updates", "decorators": [], "parameters": [ { @@ -142644,7 +147586,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.neural_network._stochastic_optimizers.BaseOptimizer.__init__", + "unique_qname": "sklearn.neural_network._stochastic_optimizers.BaseOptimizer.__init__", "decorators": [], "parameters": [ { @@ -142676,7 +147620,9 @@ }, { "name": "iteration_ends", + "unique_name": "iteration_ends", "qname": "sklearn.neural_network._stochastic_optimizers.BaseOptimizer.iteration_ends", + "unique_qname": "sklearn.neural_network._stochastic_optimizers.BaseOptimizer.iteration_ends", "decorators": [], "parameters": [ { @@ -142708,7 +147654,9 @@ }, { "name": "trigger_stopping", + "unique_name": "trigger_stopping", "qname": "sklearn.neural_network._stochastic_optimizers.BaseOptimizer.trigger_stopping", + "unique_qname": "sklearn.neural_network._stochastic_optimizers.BaseOptimizer.trigger_stopping", "decorators": [], "parameters": [ { @@ -142750,7 +147698,9 @@ }, { "name": "update_params", + "unique_name": "update_params", "qname": "sklearn.neural_network._stochastic_optimizers.BaseOptimizer.update_params", + "unique_qname": "sklearn.neural_network._stochastic_optimizers.BaseOptimizer.update_params", "decorators": [], "parameters": [ { @@ -142792,7 +147742,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.neural_network._stochastic_optimizers.SGDOptimizer.__init__", + "unique_qname": "sklearn.neural_network._stochastic_optimizers.SGDOptimizer.__init__", "decorators": [], "parameters": [ { @@ -142874,7 +147826,9 @@ }, { "name": "_get_updates", + "unique_name": "_get_updates", "qname": "sklearn.neural_network._stochastic_optimizers.SGDOptimizer._get_updates", + "unique_qname": "sklearn.neural_network._stochastic_optimizers.SGDOptimizer._get_updates", "decorators": [], "parameters": [ { @@ -142906,7 +147860,9 @@ }, { "name": "iteration_ends", + "unique_name": "iteration_ends", "qname": "sklearn.neural_network._stochastic_optimizers.SGDOptimizer.iteration_ends", + "unique_qname": "sklearn.neural_network._stochastic_optimizers.SGDOptimizer.iteration_ends", "decorators": [], "parameters": [ { @@ -142938,7 +147894,9 @@ }, { "name": "trigger_stopping", + "unique_name": "trigger_stopping", "qname": "sklearn.neural_network._stochastic_optimizers.SGDOptimizer.trigger_stopping", + "unique_qname": "sklearn.neural_network._stochastic_optimizers.SGDOptimizer.trigger_stopping", "decorators": [], "parameters": [ { @@ -142980,7 +147938,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.pipeline.FeatureUnion.__init__", + "unique_qname": "sklearn.pipeline.FeatureUnion.__init__", "decorators": [], "parameters": [ { @@ -143042,7 +148002,9 @@ }, { "name": "_hstack", + "unique_name": "_hstack", "qname": "sklearn.pipeline.FeatureUnion._hstack", + "unique_qname": "sklearn.pipeline.FeatureUnion._hstack", "decorators": [], "parameters": [ { @@ -143074,7 +148036,9 @@ }, { "name": "_iter", + "unique_name": "_iter", "qname": "sklearn.pipeline.FeatureUnion._iter", + "unique_qname": "sklearn.pipeline.FeatureUnion._iter", "decorators": [], "parameters": [ { @@ -143096,7 +148060,9 @@ }, { "name": "_log_message", + "unique_name": "_log_message", "qname": "sklearn.pipeline.FeatureUnion._log_message", + "unique_qname": "sklearn.pipeline.FeatureUnion._log_message", "decorators": [], "parameters": [ { @@ -143148,7 +148114,9 @@ }, { "name": "_parallel_func", + "unique_name": "_parallel_func", "qname": "sklearn.pipeline.FeatureUnion._parallel_func", + "unique_qname": "sklearn.pipeline.FeatureUnion._parallel_func", "decorators": [], "parameters": [ { @@ -143210,7 +148178,9 @@ }, { "name": "_sk_visual_block_", + "unique_name": "_sk_visual_block_", "qname": "sklearn.pipeline.FeatureUnion._sk_visual_block_", + "unique_qname": "sklearn.pipeline.FeatureUnion._sk_visual_block_", "decorators": [], "parameters": [ { @@ -143232,7 +148202,9 @@ }, { "name": "_update_transformer_list", + "unique_name": "_update_transformer_list", "qname": "sklearn.pipeline.FeatureUnion._update_transformer_list", + "unique_qname": "sklearn.pipeline.FeatureUnion._update_transformer_list", "decorators": [], "parameters": [ { @@ -143264,7 +148236,9 @@ }, { "name": "_validate_transformer_weights", + "unique_name": "_validate_transformer_weights", "qname": "sklearn.pipeline.FeatureUnion._validate_transformer_weights", + "unique_qname": "sklearn.pipeline.FeatureUnion._validate_transformer_weights", "decorators": [], "parameters": [ { @@ -143286,7 +148260,9 @@ }, { "name": "_validate_transformers", + "unique_name": "_validate_transformers", "qname": "sklearn.pipeline.FeatureUnion._validate_transformers", + "unique_qname": "sklearn.pipeline.FeatureUnion._validate_transformers", "decorators": [], "parameters": [ { @@ -143308,7 +148284,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.pipeline.FeatureUnion.fit", + "unique_qname": "sklearn.pipeline.FeatureUnion.fit", "decorators": [], "parameters": [ { @@ -143350,7 +148328,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.pipeline.FeatureUnion.fit_transform", + "unique_qname": "sklearn.pipeline.FeatureUnion.fit_transform", "decorators": [], "parameters": [ { @@ -143392,7 +148372,9 @@ }, { "name": "get_feature_names", + "unique_name": "get_feature_names", "qname": "sklearn.pipeline.FeatureUnion.get_feature_names", + "unique_qname": "sklearn.pipeline.FeatureUnion.get_feature_names", "decorators": [ "deprecated('get_feature_names is deprecated in 1.0 and will be removed in 1.2. Please use get_feature_names_out instead.')" ], @@ -143416,7 +148398,9 @@ }, { "name": "get_feature_names_out", + "unique_name": "get_feature_names_out", "qname": "sklearn.pipeline.FeatureUnion.get_feature_names_out", + "unique_qname": "sklearn.pipeline.FeatureUnion.get_feature_names_out", "decorators": [], "parameters": [ { @@ -143448,7 +148432,9 @@ }, { "name": "get_params", + "unique_name": "get_params", "qname": "sklearn.pipeline.FeatureUnion.get_params", + "unique_qname": "sklearn.pipeline.FeatureUnion.get_params", "decorators": [], "parameters": [ { @@ -143480,7 +148466,9 @@ }, { "name": "n_features_in_", + "unique_name": "n_features_in_@getter", "qname": "sklearn.pipeline.FeatureUnion.n_features_in_", + "unique_qname": "sklearn.pipeline.FeatureUnion.n_features_in_@getter", "decorators": ["property"], "parameters": [ { @@ -143502,7 +148490,9 @@ }, { "name": "set_params", + "unique_name": "set_params", "qname": "sklearn.pipeline.FeatureUnion.set_params", + "unique_qname": "sklearn.pipeline.FeatureUnion.set_params", "decorators": [], "parameters": [ { @@ -143524,7 +148514,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.pipeline.FeatureUnion.transform", + "unique_qname": "sklearn.pipeline.FeatureUnion.transform", "decorators": [], "parameters": [ { @@ -143556,7 +148548,9 @@ }, { "name": "__getitem__", + "unique_name": "__getitem__", "qname": "sklearn.pipeline.Pipeline.__getitem__", + "unique_qname": "sklearn.pipeline.Pipeline.__getitem__", "decorators": [], "parameters": [ { @@ -143588,7 +148582,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.pipeline.Pipeline.__init__", + "unique_qname": "sklearn.pipeline.Pipeline.__init__", "decorators": [], "parameters": [ { @@ -143640,7 +148636,9 @@ }, { "name": "__len__", + "unique_name": "__len__", "qname": "sklearn.pipeline.Pipeline.__len__", + "unique_qname": "sklearn.pipeline.Pipeline.__len__", "decorators": [], "parameters": [ { @@ -143662,7 +148660,9 @@ }, { "name": "__sklearn_is_fitted__", + "unique_name": "__sklearn_is_fitted__", "qname": "sklearn.pipeline.Pipeline.__sklearn_is_fitted__", + "unique_qname": "sklearn.pipeline.Pipeline.__sklearn_is_fitted__", "decorators": [], "parameters": [ { @@ -143684,7 +148684,9 @@ }, { "name": "_can_inverse_transform", + "unique_name": "_can_inverse_transform", "qname": "sklearn.pipeline.Pipeline._can_inverse_transform", + "unique_qname": "sklearn.pipeline.Pipeline._can_inverse_transform", "decorators": [], "parameters": [ { @@ -143706,7 +148708,9 @@ }, { "name": "_can_transform", + "unique_name": "_can_transform", "qname": "sklearn.pipeline.Pipeline._can_transform", + "unique_qname": "sklearn.pipeline.Pipeline._can_transform", "decorators": [], "parameters": [ { @@ -143728,7 +148732,9 @@ }, { "name": "_check_fit_params", + "unique_name": "_check_fit_params", "qname": "sklearn.pipeline.Pipeline._check_fit_params", + "unique_qname": "sklearn.pipeline.Pipeline._check_fit_params", "decorators": [], "parameters": [ { @@ -143750,7 +148756,9 @@ }, { "name": "_estimator_type", + "unique_name": "_estimator_type@getter", "qname": "sklearn.pipeline.Pipeline._estimator_type", + "unique_qname": "sklearn.pipeline.Pipeline._estimator_type@getter", "decorators": ["property"], "parameters": [ { @@ -143772,7 +148780,9 @@ }, { "name": "_final_estimator", + "unique_name": "_final_estimator@getter", "qname": "sklearn.pipeline.Pipeline._final_estimator", + "unique_qname": "sklearn.pipeline.Pipeline._final_estimator@getter", "decorators": ["property"], "parameters": [ { @@ -143794,7 +148804,9 @@ }, { "name": "_fit", + "unique_name": "_fit", "qname": "sklearn.pipeline.Pipeline._fit", + "unique_qname": "sklearn.pipeline.Pipeline._fit", "decorators": [], "parameters": [ { @@ -143836,7 +148848,9 @@ }, { "name": "_iter", + "unique_name": "_iter", "qname": "sklearn.pipeline.Pipeline._iter", + "unique_qname": "sklearn.pipeline.Pipeline._iter", "decorators": [], "parameters": [ { @@ -143878,7 +148892,9 @@ }, { "name": "_log_message", + "unique_name": "_log_message", "qname": "sklearn.pipeline.Pipeline._log_message", + "unique_qname": "sklearn.pipeline.Pipeline._log_message", "decorators": [], "parameters": [ { @@ -143910,7 +148926,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.pipeline.Pipeline._more_tags", + "unique_qname": "sklearn.pipeline.Pipeline._more_tags", "decorators": [], "parameters": [ { @@ -143932,7 +148950,9 @@ }, { "name": "_pairwise", + "unique_name": "_pairwise@getter", "qname": "sklearn.pipeline.Pipeline._pairwise", + "unique_qname": "sklearn.pipeline.Pipeline._pairwise@getter", "decorators": [ "deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -143957,7 +148977,9 @@ }, { "name": "_sk_visual_block_", + "unique_name": "_sk_visual_block_", "qname": "sklearn.pipeline.Pipeline._sk_visual_block_", + "unique_qname": "sklearn.pipeline.Pipeline._sk_visual_block_", "decorators": [], "parameters": [ { @@ -143979,7 +149001,9 @@ }, { "name": "_validate_steps", + "unique_name": "_validate_steps", "qname": "sklearn.pipeline.Pipeline._validate_steps", + "unique_qname": "sklearn.pipeline.Pipeline._validate_steps", "decorators": [], "parameters": [ { @@ -144001,7 +149025,9 @@ }, { "name": "classes_", + "unique_name": "classes_@getter", "qname": "sklearn.pipeline.Pipeline.classes_", + "unique_qname": "sklearn.pipeline.Pipeline.classes_@getter", "decorators": ["property"], "parameters": [ { @@ -144023,7 +149049,9 @@ }, { "name": "decision_function", + "unique_name": "decision_function", "qname": "sklearn.pipeline.Pipeline.decision_function", + "unique_qname": "sklearn.pipeline.Pipeline.decision_function", "decorators": [ "available_if(_final_estimator_has('decision_function'))" ], @@ -144057,7 +149085,9 @@ }, { "name": "feature_names_in_", + "unique_name": "feature_names_in_@getter", "qname": "sklearn.pipeline.Pipeline.feature_names_in_", + "unique_qname": "sklearn.pipeline.Pipeline.feature_names_in_@getter", "decorators": ["property"], "parameters": [ { @@ -144079,7 +149109,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.pipeline.Pipeline.fit", + "unique_qname": "sklearn.pipeline.Pipeline.fit", "decorators": [], "parameters": [ { @@ -144121,7 +149153,9 @@ }, { "name": "fit_predict", + "unique_name": "fit_predict", "qname": "sklearn.pipeline.Pipeline.fit_predict", + "unique_qname": "sklearn.pipeline.Pipeline.fit_predict", "decorators": ["available_if(_final_estimator_has('fit_predict'))"], "parameters": [ { @@ -144163,7 +149197,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.pipeline.Pipeline.fit_transform", + "unique_qname": "sklearn.pipeline.Pipeline.fit_transform", "decorators": [], "parameters": [ { @@ -144205,7 +149241,9 @@ }, { "name": "get_feature_names_out", + "unique_name": "get_feature_names_out", "qname": "sklearn.pipeline.Pipeline.get_feature_names_out", + "unique_qname": "sklearn.pipeline.Pipeline.get_feature_names_out", "decorators": [], "parameters": [ { @@ -144233,11 +149271,13 @@ "is_public": true, "description": "Get output feature names for transformation.\n\nTransform input features using the pipeline.", "docstring": "Get output feature names for transformation.\n\nTransform input features using the pipeline.\n\nParameters\n----------\ninput_features : array-like of str or None, default=None\n Input features.\n\nReturns\n-------\nfeature_names_out : ndarray of str objects\n Transformed feature names.", - "source_code": "\ndef get_feature_names_out(self, input_features=None):\n \"\"\"Get output feature names for transformation.\n\n Transform input features using the pipeline.\n\n Parameters\n ----------\n input_features : array-like of str or None, default=None\n Input features.\n\n Returns\n -------\n feature_names_out : ndarray of str objects\n Transformed feature names.\n \"\"\"\n for (_, name, transform) in self._iter():\n if not hasattr(transform, 'get_feature_names_out'):\n raise AttributeError('Estimator {} does not provide get_feature_names_out. Did you mean to call pipeline[:-1].get_feature_names_out()?'.format(name))\n feature_names = transform.get_feature_names_out(input_features)\n return feature_names" + "source_code": "\ndef get_feature_names_out(self, input_features=None):\n \"\"\"Get output feature names for transformation.\n\n Transform input features using the pipeline.\n\n Parameters\n ----------\n input_features : array-like of str or None, default=None\n Input features.\n\n Returns\n -------\n feature_names_out : ndarray of str objects\n Transformed feature names.\n \"\"\"\n feature_names_out = input_features\n for (_, name, transform) in self._iter():\n if not hasattr(transform, 'get_feature_names_out'):\n raise AttributeError('Estimator {} does not provide get_feature_names_out. Did you mean to call pipeline[:-1].get_feature_names_out()?'.format(name))\n feature_names_out = transform.get_feature_names_out(feature_names_out)\n return feature_names_out" }, { "name": "get_params", + "unique_name": "get_params", "qname": "sklearn.pipeline.Pipeline.get_params", + "unique_qname": "sklearn.pipeline.Pipeline.get_params", "decorators": [], "parameters": [ { @@ -144269,7 +149309,9 @@ }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.pipeline.Pipeline.inverse_transform", + "unique_qname": "sklearn.pipeline.Pipeline.inverse_transform", "decorators": ["available_if(_can_inverse_transform)"], "parameters": [ { @@ -144301,7 +149343,9 @@ }, { "name": "n_features_in_", + "unique_name": "n_features_in_@getter", "qname": "sklearn.pipeline.Pipeline.n_features_in_", + "unique_qname": "sklearn.pipeline.Pipeline.n_features_in_@getter", "decorators": ["property"], "parameters": [ { @@ -144323,7 +149367,9 @@ }, { "name": "named_steps", + "unique_name": "named_steps@getter", "qname": "sklearn.pipeline.Pipeline.named_steps", + "unique_qname": "sklearn.pipeline.Pipeline.named_steps@getter", "decorators": ["property"], "parameters": [ { @@ -144345,7 +149391,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.pipeline.Pipeline.predict", + "unique_qname": "sklearn.pipeline.Pipeline.predict", "decorators": ["available_if(_final_estimator_has('predict'))"], "parameters": [ { @@ -144377,7 +149425,9 @@ }, { "name": "predict_log_proba", + "unique_name": "predict_log_proba", "qname": "sklearn.pipeline.Pipeline.predict_log_proba", + "unique_qname": "sklearn.pipeline.Pipeline.predict_log_proba", "decorators": [ "available_if(_final_estimator_has('predict_log_proba'))" ], @@ -144411,7 +149461,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.pipeline.Pipeline.predict_proba", + "unique_qname": "sklearn.pipeline.Pipeline.predict_proba", "decorators": [ "available_if(_final_estimator_has('predict_proba'))" ], @@ -144445,7 +149497,9 @@ }, { "name": "score", + "unique_name": "score", "qname": "sklearn.pipeline.Pipeline.score", + "unique_qname": "sklearn.pipeline.Pipeline.score", "decorators": ["available_if(_final_estimator_has('score'))"], "parameters": [ { @@ -144497,7 +149551,9 @@ }, { "name": "score_samples", + "unique_name": "score_samples", "qname": "sklearn.pipeline.Pipeline.score_samples", + "unique_qname": "sklearn.pipeline.Pipeline.score_samples", "decorators": [ "available_if(_final_estimator_has('score_samples'))" ], @@ -144531,7 +149587,9 @@ }, { "name": "set_params", + "unique_name": "set_params", "qname": "sklearn.pipeline.Pipeline.set_params", + "unique_qname": "sklearn.pipeline.Pipeline.set_params", "decorators": [], "parameters": [ { @@ -144553,7 +149611,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.pipeline.Pipeline.transform", + "unique_qname": "sklearn.pipeline.Pipeline.transform", "decorators": ["available_if(_can_transform)"], "parameters": [ { @@ -144585,7 +149645,9 @@ }, { "name": "_final_estimator_has", + "unique_name": "_final_estimator_has", "qname": "sklearn.pipeline._final_estimator_has", + "unique_qname": "sklearn.pipeline._final_estimator_has", "decorators": [], "parameters": [ { @@ -144607,7 +149669,9 @@ }, { "name": "_fit_one", + "unique_name": "_fit_one", "qname": "sklearn.pipeline._fit_one", + "unique_qname": "sklearn.pipeline._fit_one", "decorators": [], "parameters": [ { @@ -144679,7 +149743,9 @@ }, { "name": "_fit_transform_one", + "unique_name": "_fit_transform_one", "qname": "sklearn.pipeline._fit_transform_one", + "unique_qname": "sklearn.pipeline._fit_transform_one", "decorators": [], "parameters": [ { @@ -144751,7 +149817,9 @@ }, { "name": "_name_estimators", + "unique_name": "_name_estimators", "qname": "sklearn.pipeline._name_estimators", + "unique_qname": "sklearn.pipeline._name_estimators", "decorators": [], "parameters": [ { @@ -144773,7 +149841,9 @@ }, { "name": "_transform_one", + "unique_name": "_transform_one", "qname": "sklearn.pipeline._transform_one", + "unique_qname": "sklearn.pipeline._transform_one", "decorators": [], "parameters": [ { @@ -144825,7 +149895,9 @@ }, { "name": "make_pipeline", + "unique_name": "make_pipeline", "qname": "sklearn.pipeline.make_pipeline", + "unique_qname": "sklearn.pipeline.make_pipeline", "decorators": [], "parameters": [ { @@ -144852,12 +149924,14 @@ "results": [], "is_public": true, "description": "Construct a :class:`Pipeline` from the given estimators.\n\nThis is a shorthand for the :class:`Pipeline` constructor; it does not require, and does not permit, naming the estimators. Instead, their names will be set to the lowercase of their types automatically.", - "docstring": "Construct a :class:`Pipeline` from the given estimators.\n\nThis is a shorthand for the :class:`Pipeline` constructor; it does not\nrequire, and does not permit, naming the estimators. Instead, their names\nwill be set to the lowercase of their types automatically.\n\nParameters\n----------\n*steps : list of Estimator objects\n List of the scikit-learn estimators that are chained together.\n\nmemory : str or object with the joblib.Memory interface, default=None\n Used to cache the fitted transformers of the pipeline. By default,\n no caching is performed. If a string is given, it is the path to\n the caching directory. Enabling caching triggers a clone of\n the transformers before fitting. Therefore, the transformer\n instance given to the pipeline cannot be inspected\n directly. Use the attribute ``named_steps`` or ``steps`` to\n inspect estimators within the pipeline. Caching the\n transformers is advantageous when fitting is time consuming.\n\nverbose : bool, default=False\n If True, the time elapsed while fitting each step will be printed as it\n is completed.\n\nReturns\n-------\np : Pipeline\n Returns a scikit-learn :class:`Pipeline` object.\n\nSee Also\n--------\nPipeline : Class for creating a pipeline of transforms with a final\n estimator.\n\nExamples\n--------\n>>> from sklearn.naive_bayes import GaussianNB\n>>> from sklearn.preprocessing import StandardScaler\n>>> make_pipeline(StandardScaler(), GaussianNB(priors=None))\nPipeline(steps=[('standardscaler', StandardScaler()),\n ('gaussiannb', GaussianNB())])", - "source_code": "\ndef make_pipeline(*steps, memory=None, verbose=False):\n \"\"\"Construct a :class:`Pipeline` from the given estimators.\n\n This is a shorthand for the :class:`Pipeline` constructor; it does not\n require, and does not permit, naming the estimators. Instead, their names\n will be set to the lowercase of their types automatically.\n\n Parameters\n ----------\n *steps : list of Estimator objects\n List of the scikit-learn estimators that are chained together.\n\n memory : str or object with the joblib.Memory interface, default=None\n Used to cache the fitted transformers of the pipeline. By default,\n no caching is performed. If a string is given, it is the path to\n the caching directory. Enabling caching triggers a clone of\n the transformers before fitting. Therefore, the transformer\n instance given to the pipeline cannot be inspected\n directly. Use the attribute ``named_steps`` or ``steps`` to\n inspect estimators within the pipeline. Caching the\n transformers is advantageous when fitting is time consuming.\n\n verbose : bool, default=False\n If True, the time elapsed while fitting each step will be printed as it\n is completed.\n\n Returns\n -------\n p : Pipeline\n Returns a scikit-learn :class:`Pipeline` object.\n\n See Also\n --------\n Pipeline : Class for creating a pipeline of transforms with a final\n estimator.\n\n Examples\n --------\n >>> from sklearn.naive_bayes import GaussianNB\n >>> from sklearn.preprocessing import StandardScaler\n >>> make_pipeline(StandardScaler(), GaussianNB(priors=None))\n Pipeline(steps=[('standardscaler', StandardScaler()),\n ('gaussiannb', GaussianNB())])\n \"\"\"\n return Pipeline(_name_estimators(steps), memory=memory, verbose=verbose)" + "docstring": "Construct a :class:`Pipeline` from the given estimators.\n\nThis is a shorthand for the :class:`Pipeline` constructor; it does not\nrequire, and does not permit, naming the estimators. Instead, their names\nwill be set to the lowercase of their types automatically.\n\nParameters\n----------\n*steps : list of Estimator objects\n List of the scikit-learn estimators that are chained together.\n\nmemory : str or object with the joblib.Memory interface, default=None\n Used to cache the fitted transformers of the pipeline. By default,\n no caching is performed. If a string is given, it is the path to\n the caching directory. Enabling caching triggers a clone of\n the transformers before fitting. Therefore, the transformer\n instance given to the pipeline cannot be inspected\n directly. Use the attribute ``named_steps`` or ``steps`` to\n inspect estimators within the pipeline. Caching the\n transformers is advantageous when fitting is time consuming.\n\nverbose : bool, default=False\n If True, the time elapsed while fitting each step will be printed as it\n is completed.\n\nReturns\n-------\np : Pipeline\n Returns a scikit-learn :class:`Pipeline` object.\n\nSee Also\n--------\nPipeline : Class for creating a pipeline of transforms with a final\n estimator.\n\nExamples\n--------\n>>> from sklearn.naive_bayes import GaussianNB\n>>> from sklearn.preprocessing import StandardScaler\n>>> from sklearn.pipeline import make_pipeline\n>>> make_pipeline(StandardScaler(), GaussianNB(priors=None))\nPipeline(steps=[('standardscaler', StandardScaler()),\n ('gaussiannb', GaussianNB())])", + "source_code": "\ndef make_pipeline(*steps, memory=None, verbose=False):\n \"\"\"Construct a :class:`Pipeline` from the given estimators.\n\n This is a shorthand for the :class:`Pipeline` constructor; it does not\n require, and does not permit, naming the estimators. Instead, their names\n will be set to the lowercase of their types automatically.\n\n Parameters\n ----------\n *steps : list of Estimator objects\n List of the scikit-learn estimators that are chained together.\n\n memory : str or object with the joblib.Memory interface, default=None\n Used to cache the fitted transformers of the pipeline. By default,\n no caching is performed. If a string is given, it is the path to\n the caching directory. Enabling caching triggers a clone of\n the transformers before fitting. Therefore, the transformer\n instance given to the pipeline cannot be inspected\n directly. Use the attribute ``named_steps`` or ``steps`` to\n inspect estimators within the pipeline. Caching the\n transformers is advantageous when fitting is time consuming.\n\n verbose : bool, default=False\n If True, the time elapsed while fitting each step will be printed as it\n is completed.\n\n Returns\n -------\n p : Pipeline\n Returns a scikit-learn :class:`Pipeline` object.\n\n See Also\n --------\n Pipeline : Class for creating a pipeline of transforms with a final\n estimator.\n\n Examples\n --------\n >>> from sklearn.naive_bayes import GaussianNB\n >>> from sklearn.preprocessing import StandardScaler\n >>> from sklearn.pipeline import make_pipeline\n >>> make_pipeline(StandardScaler(), GaussianNB(priors=None))\n Pipeline(steps=[('standardscaler', StandardScaler()),\n ('gaussiannb', GaussianNB())])\n \"\"\"\n return Pipeline(_name_estimators(steps), memory=memory, verbose=verbose)" }, { "name": "make_union", + "unique_name": "make_union", "qname": "sklearn.pipeline.make_union", + "unique_qname": "sklearn.pipeline.make_union", "decorators": [], "parameters": [ { @@ -144889,7 +149963,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.preprocessing._data.Binarizer.__init__", + "unique_qname": "sklearn.preprocessing._data.Binarizer.__init__", "decorators": [], "parameters": [ { @@ -144931,7 +150007,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.preprocessing._data.Binarizer._more_tags", + "unique_qname": "sklearn.preprocessing._data.Binarizer._more_tags", "decorators": [], "parameters": [ { @@ -144953,7 +150031,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.preprocessing._data.Binarizer.fit", + "unique_qname": "sklearn.preprocessing._data.Binarizer.fit", "decorators": [], "parameters": [ { @@ -144995,7 +150075,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.preprocessing._data.Binarizer.transform", + "unique_qname": "sklearn.preprocessing._data.Binarizer.transform", "decorators": [], "parameters": [ { @@ -145037,7 +150119,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.preprocessing._data.KernelCenterer.__init__", + "unique_qname": "sklearn.preprocessing._data.KernelCenterer.__init__", "decorators": [], "parameters": [ { @@ -145059,7 +150143,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.preprocessing._data.KernelCenterer._more_tags", + "unique_qname": "sklearn.preprocessing._data.KernelCenterer._more_tags", "decorators": [], "parameters": [ { @@ -145081,7 +150167,9 @@ }, { "name": "_pairwise", + "unique_name": "_pairwise@getter", "qname": "sklearn.preprocessing._data.KernelCenterer._pairwise", + "unique_qname": "sklearn.preprocessing._data.KernelCenterer._pairwise@getter", "decorators": [ "deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1.')", "property" @@ -145106,7 +150194,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.preprocessing._data.KernelCenterer.fit", + "unique_qname": "sklearn.preprocessing._data.KernelCenterer.fit", "decorators": [], "parameters": [ { @@ -145148,7 +150238,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.preprocessing._data.KernelCenterer.transform", + "unique_qname": "sklearn.preprocessing._data.KernelCenterer.transform", "decorators": [], "parameters": [ { @@ -145190,7 +150282,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.preprocessing._data.MaxAbsScaler.__init__", + "unique_qname": "sklearn.preprocessing._data.MaxAbsScaler.__init__", "decorators": [], "parameters": [ { @@ -145222,7 +150316,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.preprocessing._data.MaxAbsScaler._more_tags", + "unique_qname": "sklearn.preprocessing._data.MaxAbsScaler._more_tags", "decorators": [], "parameters": [ { @@ -145244,7 +150340,9 @@ }, { "name": "_reset", + "unique_name": "_reset", "qname": "sklearn.preprocessing._data.MaxAbsScaler._reset", + "unique_qname": "sklearn.preprocessing._data.MaxAbsScaler._reset", "decorators": [], "parameters": [ { @@ -145266,7 +150364,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.preprocessing._data.MaxAbsScaler.fit", + "unique_qname": "sklearn.preprocessing._data.MaxAbsScaler.fit", "decorators": [], "parameters": [ { @@ -145308,7 +150408,9 @@ }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.preprocessing._data.MaxAbsScaler.inverse_transform", + "unique_qname": "sklearn.preprocessing._data.MaxAbsScaler.inverse_transform", "decorators": [], "parameters": [ { @@ -145340,7 +150442,9 @@ }, { "name": "partial_fit", + "unique_name": "partial_fit", "qname": "sklearn.preprocessing._data.MaxAbsScaler.partial_fit", + "unique_qname": "sklearn.preprocessing._data.MaxAbsScaler.partial_fit", "decorators": [], "parameters": [ { @@ -145382,7 +150486,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.preprocessing._data.MaxAbsScaler.transform", + "unique_qname": "sklearn.preprocessing._data.MaxAbsScaler.transform", "decorators": [], "parameters": [ { @@ -145414,7 +150520,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.preprocessing._data.MinMaxScaler.__init__", + "unique_qname": "sklearn.preprocessing._data.MinMaxScaler.__init__", "decorators": [], "parameters": [ { @@ -145466,7 +150574,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.preprocessing._data.MinMaxScaler._more_tags", + "unique_qname": "sklearn.preprocessing._data.MinMaxScaler._more_tags", "decorators": [], "parameters": [ { @@ -145488,7 +150598,9 @@ }, { "name": "_reset", + "unique_name": "_reset", "qname": "sklearn.preprocessing._data.MinMaxScaler._reset", + "unique_qname": "sklearn.preprocessing._data.MinMaxScaler._reset", "decorators": [], "parameters": [ { @@ -145510,7 +150622,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.preprocessing._data.MinMaxScaler.fit", + "unique_qname": "sklearn.preprocessing._data.MinMaxScaler.fit", "decorators": [], "parameters": [ { @@ -145552,7 +150666,9 @@ }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.preprocessing._data.MinMaxScaler.inverse_transform", + "unique_qname": "sklearn.preprocessing._data.MinMaxScaler.inverse_transform", "decorators": [], "parameters": [ { @@ -145584,7 +150700,9 @@ }, { "name": "partial_fit", + "unique_name": "partial_fit", "qname": "sklearn.preprocessing._data.MinMaxScaler.partial_fit", + "unique_qname": "sklearn.preprocessing._data.MinMaxScaler.partial_fit", "decorators": [], "parameters": [ { @@ -145626,7 +150744,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.preprocessing._data.MinMaxScaler.transform", + "unique_qname": "sklearn.preprocessing._data.MinMaxScaler.transform", "decorators": [], "parameters": [ { @@ -145658,7 +150778,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.preprocessing._data.Normalizer.__init__", + "unique_qname": "sklearn.preprocessing._data.Normalizer.__init__", "decorators": [], "parameters": [ { @@ -145700,7 +150822,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.preprocessing._data.Normalizer._more_tags", + "unique_qname": "sklearn.preprocessing._data.Normalizer._more_tags", "decorators": [], "parameters": [ { @@ -145722,7 +150846,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.preprocessing._data.Normalizer.fit", + "unique_qname": "sklearn.preprocessing._data.Normalizer.fit", "decorators": [], "parameters": [ { @@ -145764,7 +150890,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.preprocessing._data.Normalizer.transform", + "unique_qname": "sklearn.preprocessing._data.Normalizer.transform", "decorators": [], "parameters": [ { @@ -145806,7 +150934,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.preprocessing._data.PowerTransformer.__init__", + "unique_qname": "sklearn.preprocessing._data.PowerTransformer.__init__", "decorators": [], "parameters": [ { @@ -145858,7 +150988,9 @@ }, { "name": "_box_cox_inverse_tranform", + "unique_name": "_box_cox_inverse_tranform", "qname": "sklearn.preprocessing._data.PowerTransformer._box_cox_inverse_tranform", + "unique_qname": "sklearn.preprocessing._data.PowerTransformer._box_cox_inverse_tranform", "decorators": [], "parameters": [ { @@ -145900,7 +151032,9 @@ }, { "name": "_box_cox_optimize", + "unique_name": "_box_cox_optimize", "qname": "sklearn.preprocessing._data.PowerTransformer._box_cox_optimize", + "unique_qname": "sklearn.preprocessing._data.PowerTransformer._box_cox_optimize", "decorators": [], "parameters": [ { @@ -145932,7 +151066,9 @@ }, { "name": "_check_input", + "unique_name": "_check_input", "qname": "sklearn.preprocessing._data.PowerTransformer._check_input", + "unique_qname": "sklearn.preprocessing._data.PowerTransformer._check_input", "decorators": [], "parameters": [ { @@ -146004,7 +151140,9 @@ }, { "name": "_fit", + "unique_name": "_fit", "qname": "sklearn.preprocessing._data.PowerTransformer._fit", + "unique_qname": "sklearn.preprocessing._data.PowerTransformer._fit", "decorators": [], "parameters": [ { @@ -146056,7 +151194,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.preprocessing._data.PowerTransformer._more_tags", + "unique_qname": "sklearn.preprocessing._data.PowerTransformer._more_tags", "decorators": [], "parameters": [ { @@ -146078,7 +151218,9 @@ }, { "name": "_yeo_johnson_inverse_transform", + "unique_name": "_yeo_johnson_inverse_transform", "qname": "sklearn.preprocessing._data.PowerTransformer._yeo_johnson_inverse_transform", + "unique_qname": "sklearn.preprocessing._data.PowerTransformer._yeo_johnson_inverse_transform", "decorators": [], "parameters": [ { @@ -146120,7 +151262,9 @@ }, { "name": "_yeo_johnson_optimize", + "unique_name": "_yeo_johnson_optimize", "qname": "sklearn.preprocessing._data.PowerTransformer._yeo_johnson_optimize", + "unique_qname": "sklearn.preprocessing._data.PowerTransformer._yeo_johnson_optimize", "decorators": [], "parameters": [ { @@ -146152,7 +151296,9 @@ }, { "name": "_yeo_johnson_transform", + "unique_name": "_yeo_johnson_transform", "qname": "sklearn.preprocessing._data.PowerTransformer._yeo_johnson_transform", + "unique_qname": "sklearn.preprocessing._data.PowerTransformer._yeo_johnson_transform", "decorators": [], "parameters": [ { @@ -146194,7 +151340,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.preprocessing._data.PowerTransformer.fit", + "unique_qname": "sklearn.preprocessing._data.PowerTransformer.fit", "decorators": [], "parameters": [ { @@ -146236,7 +151384,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.preprocessing._data.PowerTransformer.fit_transform", + "unique_qname": "sklearn.preprocessing._data.PowerTransformer.fit_transform", "decorators": [], "parameters": [ { @@ -146278,7 +151428,9 @@ }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.preprocessing._data.PowerTransformer.inverse_transform", + "unique_qname": "sklearn.preprocessing._data.PowerTransformer.inverse_transform", "decorators": [], "parameters": [ { @@ -146310,7 +151462,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.preprocessing._data.PowerTransformer.transform", + "unique_qname": "sklearn.preprocessing._data.PowerTransformer.transform", "decorators": [], "parameters": [ { @@ -146342,7 +151496,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.preprocessing._data.QuantileTransformer.__init__", + "unique_qname": "sklearn.preprocessing._data.QuantileTransformer.__init__", "decorators": [], "parameters": [ { @@ -146424,7 +151580,9 @@ }, { "name": "_check_inputs", + "unique_name": "_check_inputs", "qname": "sklearn.preprocessing._data.QuantileTransformer._check_inputs", + "unique_qname": "sklearn.preprocessing._data.QuantileTransformer._check_inputs", "decorators": [], "parameters": [ { @@ -146486,7 +151644,9 @@ }, { "name": "_dense_fit", + "unique_name": "_dense_fit", "qname": "sklearn.preprocessing._data.QuantileTransformer._dense_fit", + "unique_qname": "sklearn.preprocessing._data.QuantileTransformer._dense_fit", "decorators": [], "parameters": [ { @@ -146528,7 +151688,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.preprocessing._data.QuantileTransformer._more_tags", + "unique_qname": "sklearn.preprocessing._data.QuantileTransformer._more_tags", "decorators": [], "parameters": [ { @@ -146550,7 +151712,9 @@ }, { "name": "_sparse_fit", + "unique_name": "_sparse_fit", "qname": "sklearn.preprocessing._data.QuantileTransformer._sparse_fit", + "unique_qname": "sklearn.preprocessing._data.QuantileTransformer._sparse_fit", "decorators": [], "parameters": [ { @@ -146592,7 +151756,9 @@ }, { "name": "_transform", + "unique_name": "_transform", "qname": "sklearn.preprocessing._data.QuantileTransformer._transform", + "unique_qname": "sklearn.preprocessing._data.QuantileTransformer._transform", "decorators": [], "parameters": [ { @@ -146634,7 +151800,9 @@ }, { "name": "_transform_col", + "unique_name": "_transform_col", "qname": "sklearn.preprocessing._data.QuantileTransformer._transform_col", + "unique_qname": "sklearn.preprocessing._data.QuantileTransformer._transform_col", "decorators": [], "parameters": [ { @@ -146686,7 +151854,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.preprocessing._data.QuantileTransformer.fit", + "unique_qname": "sklearn.preprocessing._data.QuantileTransformer.fit", "decorators": [], "parameters": [ { @@ -146728,7 +151898,9 @@ }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.preprocessing._data.QuantileTransformer.inverse_transform", + "unique_qname": "sklearn.preprocessing._data.QuantileTransformer.inverse_transform", "decorators": [], "parameters": [ { @@ -146760,7 +151932,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.preprocessing._data.QuantileTransformer.transform", + "unique_qname": "sklearn.preprocessing._data.QuantileTransformer.transform", "decorators": [], "parameters": [ { @@ -146792,7 +151966,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.preprocessing._data.RobustScaler.__init__", + "unique_qname": "sklearn.preprocessing._data.RobustScaler.__init__", "decorators": [], "parameters": [ { @@ -146812,7 +151988,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "bool, default=True", - "description": "If True, center the data before scaling.\nThis will cause ``transform`` to raise an exception when attempted on\nsparse matrices, because centering them entails building a dense\nmatrix which in common use cases is likely to be too large to fit in\nmemory." + "description": "If `True`, center the data before scaling.\nThis will cause :meth:`transform` to raise an exception when attempted\non sparse matrices, because centering them entails building a dense\nmatrix which in common use cases is likely to be too large to fit in\nmemory." } }, { @@ -146822,7 +151998,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "bool, default=True", - "description": "If True, scale the data to interquartile range." + "description": "If `True`, scale the data to interquartile range." } }, { @@ -146831,8 +152007,8 @@ "is_public": true, "assigned_by": "NAME_ONLY", "docstring": { - "type": "tuple (q_min, q_max), 0.0 < q_min < q_max < 100.0, default=(25.0, 75.0), == (1st quantile, 3rd quantile), == IQR", - "description": "Quantile range used to calculate ``scale_``.\n\n.. versionadded:: 0.18" + "type": "tuple (q_min, q_max), 0.0 < q_min < q_max < 100.0, default=(25.0, 75.0)", + "description": "Quantile range used to calculate `scale_`. By default this is equal to\nthe IQR, i.e., `q_min` is the first quantile and `q_max` is the third\nquantile.\n\n.. versionadded:: 0.18" } }, { @@ -146842,7 +152018,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "bool, default=True", - "description": "If False, try to avoid a copy and do inplace scaling instead.\nThis is not guaranteed to always work inplace; e.g. if the data is\nnot a NumPy array or scipy.sparse CSR matrix, a copy may still be\nreturned." + "description": "If `False`, try to avoid a copy and do inplace scaling instead.\nThis is not guaranteed to always work inplace; e.g. if the data is\nnot a NumPy array or scipy.sparse CSR matrix, a copy may still be\nreturned." } }, { @@ -146852,7 +152028,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "bool, default=False", - "description": "If True, scale data so that normally distributed features have a\nvariance of 1. In general, if the difference between the x-values of\n``q_max`` and ``q_min`` for a standard normal distribution is greater\nthan 1, the dataset will be scaled down. If less than 1, the dataset\nwill be scaled up.\n\n.. versionadded:: 0.24" + "description": "If `True`, scale data so that normally distributed features have a\nvariance of 1. In general, if the difference between the x-values of\n`q_max` and `q_min` for a standard normal distribution is greater\nthan 1, the dataset will be scaled down. If less than 1, the dataset\nwill be scaled up.\n\n.. versionadded:: 0.24" } } ], @@ -146864,7 +152040,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.preprocessing._data.RobustScaler._more_tags", + "unique_qname": "sklearn.preprocessing._data.RobustScaler._more_tags", "decorators": [], "parameters": [ { @@ -146886,7 +152064,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.preprocessing._data.RobustScaler.fit", + "unique_qname": "sklearn.preprocessing._data.RobustScaler.fit", "decorators": [], "parameters": [ { @@ -146915,20 +152095,22 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "None", - "description": "Ignored." + "type": "Ignored", + "description": "Not used, present here for API consistency by convention." } } ], "results": [], "is_public": true, "description": "Compute the median and quantiles to be used for scaling.", - "docstring": "Compute the median and quantiles to be used for scaling.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n The data used to compute the median and quantiles\n used for later scaling along the features axis.\n\ny : None\n Ignored.\n\nReturns\n-------\nself : object\n Fitted scaler.", - "source_code": "\ndef fit(self, X, y=None):\n \"\"\"Compute the median and quantiles to be used for scaling.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The data used to compute the median and quantiles\n used for later scaling along the features axis.\n\n y : None\n Ignored.\n\n Returns\n -------\n self : object\n Fitted scaler.\n \"\"\"\n X = self._validate_data(X, accept_sparse='csc', estimator=self, dtype=FLOAT_DTYPES, force_all_finite='allow-nan')\n (q_min, q_max) = self.quantile_range\n if not 0 <= q_min <= q_max <= 100:\n raise ValueError('Invalid quantile range: %s' % str(self.quantile_range))\n if self.with_centering:\n if sparse.issparse(X):\n raise ValueError('Cannot center sparse matrices: use `with_centering=False` instead. See docstring for motivation and alternatives.')\n self.center_ = np.nanmedian(X, axis=0)\n else:\n self.center_ = None\n if self.with_scaling:\n quantiles = []\n for feature_idx in range(X.shape[1]):\n if sparse.issparse(X):\n column_nnz_data = X.data[X.indptr[feature_idx]:X.indptr[feature_idx + 1]]\n column_data = np.zeros(shape=X.shape[0], dtype=X.dtype)\n column_data[:len(column_nnz_data)] = column_nnz_data\n else:\n column_data = X[:, feature_idx]\n quantiles.append(np.nanpercentile(column_data, self.quantile_range))\n quantiles = np.transpose(quantiles)\n self.scale_ = quantiles[1] - quantiles[0]\n self.scale_ = _handle_zeros_in_scale(self.scale_, copy=False)\n if self.unit_variance:\n adjust = stats.norm.ppf(q_max / 100.0) - stats.norm.ppf(q_min / 100.0)\n self.scale_ = self.scale_ / adjust\n else:\n self.scale_ = None\n return self" + "docstring": "Compute the median and quantiles to be used for scaling.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n The data used to compute the median and quantiles\n used for later scaling along the features axis.\n\ny : Ignored\n Not used, present here for API consistency by convention.\n\nReturns\n-------\nself : object\n Fitted scaler.", + "source_code": "\ndef fit(self, X, y=None):\n \"\"\"Compute the median and quantiles to be used for scaling.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The data used to compute the median and quantiles\n used for later scaling along the features axis.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self : object\n Fitted scaler.\n \"\"\"\n X = self._validate_data(X, accept_sparse='csc', estimator=self, dtype=FLOAT_DTYPES, force_all_finite='allow-nan')\n (q_min, q_max) = self.quantile_range\n if not 0 <= q_min <= q_max <= 100:\n raise ValueError('Invalid quantile range: %s' % str(self.quantile_range))\n if self.with_centering:\n if sparse.issparse(X):\n raise ValueError('Cannot center sparse matrices: use `with_centering=False` instead. See docstring for motivation and alternatives.')\n self.center_ = np.nanmedian(X, axis=0)\n else:\n self.center_ = None\n if self.with_scaling:\n quantiles = []\n for feature_idx in range(X.shape[1]):\n if sparse.issparse(X):\n column_nnz_data = X.data[X.indptr[feature_idx]:X.indptr[feature_idx + 1]]\n column_data = np.zeros(shape=X.shape[0], dtype=X.dtype)\n column_data[:len(column_nnz_data)] = column_nnz_data\n else:\n column_data = X[:, feature_idx]\n quantiles.append(np.nanpercentile(column_data, self.quantile_range))\n quantiles = np.transpose(quantiles)\n self.scale_ = quantiles[1] - quantiles[0]\n self.scale_ = _handle_zeros_in_scale(self.scale_, copy=False)\n if self.unit_variance:\n adjust = stats.norm.ppf(q_max / 100.0) - stats.norm.ppf(q_min / 100.0)\n self.scale_ = self.scale_ / adjust\n else:\n self.scale_ = None\n return self" }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.preprocessing._data.RobustScaler.inverse_transform", + "unique_qname": "sklearn.preprocessing._data.RobustScaler.inverse_transform", "decorators": [], "parameters": [ { @@ -146960,7 +152142,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.preprocessing._data.RobustScaler.transform", + "unique_qname": "sklearn.preprocessing._data.RobustScaler.transform", "decorators": [], "parameters": [ { @@ -146992,7 +152176,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.preprocessing._data.StandardScaler.__init__", + "unique_qname": "sklearn.preprocessing._data.StandardScaler.__init__", "decorators": [], "parameters": [ { @@ -147044,7 +152230,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.preprocessing._data.StandardScaler._more_tags", + "unique_qname": "sklearn.preprocessing._data.StandardScaler._more_tags", "decorators": [], "parameters": [ { @@ -147066,7 +152254,9 @@ }, { "name": "_reset", + "unique_name": "_reset", "qname": "sklearn.preprocessing._data.StandardScaler._reset", + "unique_qname": "sklearn.preprocessing._data.StandardScaler._reset", "decorators": [], "parameters": [ { @@ -147088,7 +152278,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.preprocessing._data.StandardScaler.fit", + "unique_qname": "sklearn.preprocessing._data.StandardScaler.fit", "decorators": [], "parameters": [ { @@ -147140,7 +152332,9 @@ }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.preprocessing._data.StandardScaler.inverse_transform", + "unique_qname": "sklearn.preprocessing._data.StandardScaler.inverse_transform", "decorators": [], "parameters": [ { @@ -147182,7 +152376,9 @@ }, { "name": "partial_fit", + "unique_name": "partial_fit", "qname": "sklearn.preprocessing._data.StandardScaler.partial_fit", + "unique_qname": "sklearn.preprocessing._data.StandardScaler.partial_fit", "decorators": [], "parameters": [ { @@ -147234,7 +152430,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.preprocessing._data.StandardScaler.transform", + "unique_qname": "sklearn.preprocessing._data.StandardScaler.transform", "decorators": [], "parameters": [ { @@ -147276,7 +152474,9 @@ }, { "name": "_handle_zeros_in_scale", + "unique_name": "_handle_zeros_in_scale", "qname": "sklearn.preprocessing._data._handle_zeros_in_scale", + "unique_qname": "sklearn.preprocessing._data._handle_zeros_in_scale", "decorators": [], "parameters": [ { @@ -147318,7 +152518,9 @@ }, { "name": "_is_constant_feature", + "unique_name": "_is_constant_feature", "qname": "sklearn.preprocessing._data._is_constant_feature", + "unique_qname": "sklearn.preprocessing._data._is_constant_feature", "decorators": [], "parameters": [ { @@ -147360,7 +152562,9 @@ }, { "name": "add_dummy_feature", + "unique_name": "add_dummy_feature", "qname": "sklearn.preprocessing._data.add_dummy_feature", + "unique_qname": "sklearn.preprocessing._data.add_dummy_feature", "decorators": [], "parameters": [ { @@ -147392,7 +152596,9 @@ }, { "name": "binarize", + "unique_name": "binarize", "qname": "sklearn.preprocessing._data.binarize", + "unique_qname": "sklearn.preprocessing._data.binarize", "decorators": [], "parameters": [ { @@ -147434,7 +152640,9 @@ }, { "name": "maxabs_scale", + "unique_name": "maxabs_scale", "qname": "sklearn.preprocessing._data.maxabs_scale", + "unique_qname": "sklearn.preprocessing._data.maxabs_scale", "decorators": [], "parameters": [ { @@ -147476,7 +152684,9 @@ }, { "name": "minmax_scale", + "unique_name": "minmax_scale", "qname": "sklearn.preprocessing._data.minmax_scale", + "unique_qname": "sklearn.preprocessing._data.minmax_scale", "decorators": [], "parameters": [ { @@ -147528,7 +152738,9 @@ }, { "name": "normalize", + "unique_name": "normalize", "qname": "sklearn.preprocessing._data.normalize", + "unique_qname": "sklearn.preprocessing._data.normalize", "decorators": [], "parameters": [ { @@ -147590,7 +152802,9 @@ }, { "name": "power_transform", + "unique_name": "power_transform", "qname": "sklearn.preprocessing._data.power_transform", + "unique_qname": "sklearn.preprocessing._data.power_transform", "decorators": [], "parameters": [ { @@ -147642,7 +152856,9 @@ }, { "name": "quantile_transform", + "unique_name": "quantile_transform", "qname": "sklearn.preprocessing._data.quantile_transform", + "unique_qname": "sklearn.preprocessing._data.quantile_transform", "decorators": [], "parameters": [ { @@ -147734,7 +152950,9 @@ }, { "name": "robust_scale", + "unique_name": "robust_scale", "qname": "sklearn.preprocessing._data.robust_scale", + "unique_qname": "sklearn.preprocessing._data.robust_scale", "decorators": [], "parameters": [ { @@ -147754,7 +152972,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "int, default=0", - "description": "axis used to compute the medians and IQR along. If 0,\nindependently scale each feature, otherwise (if 1) scale\neach sample." + "description": "Axis used to compute the medians and IQR along. If 0,\nindependently scale each feature, otherwise (if 1) scale\neach sample." } }, { @@ -147764,7 +152982,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "bool, default=True", - "description": "If True, center the data before scaling." + "description": "If `True`, center the data before scaling." } }, { @@ -147774,7 +152992,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "bool, default=True", - "description": "If True, scale the data to unit variance (or equivalently,\nunit standard deviation)." + "description": "If `True`, scale the data to unit variance (or equivalently,\nunit standard deviation)." } }, { @@ -147783,8 +153001,8 @@ "is_public": true, "assigned_by": "NAME_ONLY", "docstring": { - "type": "tuple (q_min, q_max), 0.0 < q_min < q_max < 100.0", - "description": "default=(25.0, 75.0), == (1st quantile, 3rd quantile), == IQR\nQuantile range used to calculate ``scale_``.\n\n.. versionadded:: 0.18" + "type": "tuple (q_min, q_max), 0.0 < q_min < q_max < 100.0, default=(25.0, 75.0)", + "description": "Quantile range used to calculate `scale_`. By default this is equal to\nthe IQR, i.e., `q_min` is the first quantile and `q_max` is the third\nquantile.\n\n.. versionadded:: 0.18" } }, { @@ -147794,7 +153012,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "bool, default=True", - "description": "set to False to perform inplace row normalization and avoid a\ncopy (if the input is already a numpy array or a scipy.sparse\nCSR matrix and if axis is 1)." + "description": "Set to `False` to perform inplace row normalization and avoid a\ncopy (if the input is already a numpy array or a scipy.sparse\nCSR matrix and if axis is 1)." } }, { @@ -147804,19 +153022,21 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "bool, default=False", - "description": "If True, scale data so that normally distributed features have a\nvariance of 1. In general, if the difference between the x-values of\n``q_max`` and ``q_min`` for a standard normal distribution is greater\nthan 1, the dataset will be scaled down. If less than 1, the dataset\nwill be scaled up.\n\n.. versionadded:: 0.24" + "description": "If `True`, scale data so that normally distributed features have a\nvariance of 1. In general, if the difference between the x-values of\n`q_max` and `q_min` for a standard normal distribution is greater\nthan 1, the dataset will be scaled down. If less than 1, the dataset\nwill be scaled up.\n\n.. versionadded:: 0.24" } } ], "results": [], "is_public": true, "description": "Standardize a dataset along any axis.\n\nCenter to the median and component wise scale according to the interquartile range. Read more in the :ref:`User Guide `.", - "docstring": "Standardize a dataset along any axis.\n\nCenter to the median and component wise scale\naccording to the interquartile range.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_sample, n_features)\n The data to center and scale.\n\naxis : int, default=0\n axis used to compute the medians and IQR along. If 0,\n independently scale each feature, otherwise (if 1) scale\n each sample.\n\nwith_centering : bool, default=True\n If True, center the data before scaling.\n\nwith_scaling : bool, default=True\n If True, scale the data to unit variance (or equivalently,\n unit standard deviation).\n\nquantile_range : tuple (q_min, q_max), 0.0 < q_min < q_max < 100.0\n default=(25.0, 75.0), == (1st quantile, 3rd quantile), == IQR\n Quantile range used to calculate ``scale_``.\n\n .. versionadded:: 0.18\n\ncopy : bool, default=True\n set to False to perform inplace row normalization and avoid a\n copy (if the input is already a numpy array or a scipy.sparse\n CSR matrix and if axis is 1).\n\nunit_variance : bool, default=False\n If True, scale data so that normally distributed features have a\n variance of 1. In general, if the difference between the x-values of\n ``q_max`` and ``q_min`` for a standard normal distribution is greater\n than 1, the dataset will be scaled down. If less than 1, the dataset\n will be scaled up.\n\n .. versionadded:: 0.24\n\nReturns\n-------\nX_tr : {ndarray, sparse matrix} of shape (n_samples, n_features)\n The transformed data.\n\nNotes\n-----\nThis implementation will refuse to center scipy.sparse matrices\nsince it would make them non-sparse and would potentially crash the\nprogram with memory exhaustion problems.\n\nInstead the caller is expected to either set explicitly\n`with_centering=False` (in that case, only variance scaling will be\nperformed on the features of the CSR matrix) or to call `X.toarray()`\nif he/she expects the materialized dense array to fit in memory.\n\nTo avoid memory copy the caller should pass a CSR matrix.\n\nFor a comparison of the different scalers, transformers, and normalizers,\nsee :ref:`examples/preprocessing/plot_all_scaling.py\n`.\n\n.. warning:: Risk of data leak\n\n Do not use :func:`~sklearn.preprocessing.robust_scale` unless you know\n what you are doing. A common mistake is to apply it to the entire data\n *before* splitting into training and test sets. This will bias the\n model evaluation because information would have leaked from the test\n set to the training set.\n In general, we recommend using\n :class:`~sklearn.preprocessing.RobustScaler` within a\n :ref:`Pipeline ` in order to prevent most risks of data\n leaking: `pipe = make_pipeline(RobustScaler(), LogisticRegression())`.\n\nSee Also\n--------\nRobustScaler : Performs centering and scaling using the Transformer API\n (e.g. as part of a preprocessing :class:`~sklearn.pipeline.Pipeline`).", - "source_code": "\ndef robust_scale(X, *, axis=0, with_centering=True, with_scaling=True, quantile_range=(25.0, 75.0), copy=True, unit_variance=False):\n \"\"\"Standardize a dataset along any axis.\n\n Center to the median and component wise scale\n according to the interquartile range.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_sample, n_features)\n The data to center and scale.\n\n axis : int, default=0\n axis used to compute the medians and IQR along. If 0,\n independently scale each feature, otherwise (if 1) scale\n each sample.\n\n with_centering : bool, default=True\n If True, center the data before scaling.\n\n with_scaling : bool, default=True\n If True, scale the data to unit variance (or equivalently,\n unit standard deviation).\n\n quantile_range : tuple (q_min, q_max), 0.0 < q_min < q_max < 100.0\n default=(25.0, 75.0), == (1st quantile, 3rd quantile), == IQR\n Quantile range used to calculate ``scale_``.\n\n .. versionadded:: 0.18\n\n copy : bool, default=True\n set to False to perform inplace row normalization and avoid a\n copy (if the input is already a numpy array or a scipy.sparse\n CSR matrix and if axis is 1).\n\n unit_variance : bool, default=False\n If True, scale data so that normally distributed features have a\n variance of 1. In general, if the difference between the x-values of\n ``q_max`` and ``q_min`` for a standard normal distribution is greater\n than 1, the dataset will be scaled down. If less than 1, the dataset\n will be scaled up.\n\n .. versionadded:: 0.24\n\n Returns\n -------\n X_tr : {ndarray, sparse matrix} of shape (n_samples, n_features)\n The transformed data.\n\n Notes\n -----\n This implementation will refuse to center scipy.sparse matrices\n since it would make them non-sparse and would potentially crash the\n program with memory exhaustion problems.\n\n Instead the caller is expected to either set explicitly\n `with_centering=False` (in that case, only variance scaling will be\n performed on the features of the CSR matrix) or to call `X.toarray()`\n if he/she expects the materialized dense array to fit in memory.\n\n To avoid memory copy the caller should pass a CSR matrix.\n\n For a comparison of the different scalers, transformers, and normalizers,\n see :ref:`examples/preprocessing/plot_all_scaling.py\n `.\n\n .. warning:: Risk of data leak\n\n Do not use :func:`~sklearn.preprocessing.robust_scale` unless you know\n what you are doing. A common mistake is to apply it to the entire data\n *before* splitting into training and test sets. This will bias the\n model evaluation because information would have leaked from the test\n set to the training set.\n In general, we recommend using\n :class:`~sklearn.preprocessing.RobustScaler` within a\n :ref:`Pipeline ` in order to prevent most risks of data\n leaking: `pipe = make_pipeline(RobustScaler(), LogisticRegression())`.\n\n See Also\n --------\n RobustScaler : Performs centering and scaling using the Transformer API\n (e.g. as part of a preprocessing :class:`~sklearn.pipeline.Pipeline`).\n \"\"\"\n X = check_array(X, accept_sparse=('csr', 'csc'), copy=False, ensure_2d=False, dtype=FLOAT_DTYPES, force_all_finite='allow-nan')\n original_ndim = X.ndim\n if original_ndim == 1:\n X = X.reshape(X.shape[0], 1)\n s = RobustScaler(with_centering=with_centering, with_scaling=with_scaling, quantile_range=quantile_range, unit_variance=unit_variance, copy=copy)\n if axis == 0:\n X = s.fit_transform(X)\n else:\n X = s.fit_transform(X.T).T\n if original_ndim == 1:\n X = X.ravel()\n return X" + "docstring": "Standardize a dataset along any axis.\n\nCenter to the median and component wise scale\naccording to the interquartile range.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_sample, n_features)\n The data to center and scale.\n\naxis : int, default=0\n Axis used to compute the medians and IQR along. If 0,\n independently scale each feature, otherwise (if 1) scale\n each sample.\n\nwith_centering : bool, default=True\n If `True`, center the data before scaling.\n\nwith_scaling : bool, default=True\n If `True`, scale the data to unit variance (or equivalently,\n unit standard deviation).\n\nquantile_range : tuple (q_min, q_max), 0.0 < q_min < q_max < 100.0, default=(25.0, 75.0)\n Quantile range used to calculate `scale_`. By default this is equal to\n the IQR, i.e., `q_min` is the first quantile and `q_max` is the third\n quantile.\n\n .. versionadded:: 0.18\n\ncopy : bool, default=True\n Set to `False` to perform inplace row normalization and avoid a\n copy (if the input is already a numpy array or a scipy.sparse\n CSR matrix and if axis is 1).\n\nunit_variance : bool, default=False\n If `True`, scale data so that normally distributed features have a\n variance of 1. In general, if the difference between the x-values of\n `q_max` and `q_min` for a standard normal distribution is greater\n than 1, the dataset will be scaled down. If less than 1, the dataset\n will be scaled up.\n\n .. versionadded:: 0.24\n\nReturns\n-------\nX_tr : {ndarray, sparse matrix} of shape (n_samples, n_features)\n The transformed data.\n\nNotes\n-----\nThis implementation will refuse to center scipy.sparse matrices\nsince it would make them non-sparse and would potentially crash the\nprogram with memory exhaustion problems.\n\nInstead the caller is expected to either set explicitly\n`with_centering=False` (in that case, only variance scaling will be\nperformed on the features of the CSR matrix) or to call `X.toarray()`\nif he/she expects the materialized dense array to fit in memory.\n\nTo avoid memory copy the caller should pass a CSR matrix.\n\nFor a comparison of the different scalers, transformers, and normalizers,\nsee :ref:`examples/preprocessing/plot_all_scaling.py\n`.\n\n.. warning:: Risk of data leak\n\n Do not use :func:`~sklearn.preprocessing.robust_scale` unless you know\n what you are doing. A common mistake is to apply it to the entire data\n *before* splitting into training and test sets. This will bias the\n model evaluation because information would have leaked from the test\n set to the training set.\n In general, we recommend using\n :class:`~sklearn.preprocessing.RobustScaler` within a\n :ref:`Pipeline ` in order to prevent most risks of data\n leaking: `pipe = make_pipeline(RobustScaler(), LogisticRegression())`.\n\nSee Also\n--------\nRobustScaler : Performs centering and scaling using the Transformer API\n (e.g. as part of a preprocessing :class:`~sklearn.pipeline.Pipeline`).", + "source_code": "\ndef robust_scale(X, *, axis=0, with_centering=True, with_scaling=True, quantile_range=(25.0, 75.0), copy=True, unit_variance=False):\n \"\"\"Standardize a dataset along any axis.\n\n Center to the median and component wise scale\n according to the interquartile range.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_sample, n_features)\n The data to center and scale.\n\n axis : int, default=0\n Axis used to compute the medians and IQR along. If 0,\n independently scale each feature, otherwise (if 1) scale\n each sample.\n\n with_centering : bool, default=True\n If `True`, center the data before scaling.\n\n with_scaling : bool, default=True\n If `True`, scale the data to unit variance (or equivalently,\n unit standard deviation).\n\n quantile_range : tuple (q_min, q_max), 0.0 < q_min < q_max < 100.0, default=(25.0, 75.0)\n Quantile range used to calculate `scale_`. By default this is equal to\n the IQR, i.e., `q_min` is the first quantile and `q_max` is the third\n quantile.\n\n .. versionadded:: 0.18\n\n copy : bool, default=True\n Set to `False` to perform inplace row normalization and avoid a\n copy (if the input is already a numpy array or a scipy.sparse\n CSR matrix and if axis is 1).\n\n unit_variance : bool, default=False\n If `True`, scale data so that normally distributed features have a\n variance of 1. In general, if the difference between the x-values of\n `q_max` and `q_min` for a standard normal distribution is greater\n than 1, the dataset will be scaled down. If less than 1, the dataset\n will be scaled up.\n\n .. versionadded:: 0.24\n\n Returns\n -------\n X_tr : {ndarray, sparse matrix} of shape (n_samples, n_features)\n The transformed data.\n\n Notes\n -----\n This implementation will refuse to center scipy.sparse matrices\n since it would make them non-sparse and would potentially crash the\n program with memory exhaustion problems.\n\n Instead the caller is expected to either set explicitly\n `with_centering=False` (in that case, only variance scaling will be\n performed on the features of the CSR matrix) or to call `X.toarray()`\n if he/she expects the materialized dense array to fit in memory.\n\n To avoid memory copy the caller should pass a CSR matrix.\n\n For a comparison of the different scalers, transformers, and normalizers,\n see :ref:`examples/preprocessing/plot_all_scaling.py\n `.\n\n .. warning:: Risk of data leak\n\n Do not use :func:`~sklearn.preprocessing.robust_scale` unless you know\n what you are doing. A common mistake is to apply it to the entire data\n *before* splitting into training and test sets. This will bias the\n model evaluation because information would have leaked from the test\n set to the training set.\n In general, we recommend using\n :class:`~sklearn.preprocessing.RobustScaler` within a\n :ref:`Pipeline ` in order to prevent most risks of data\n leaking: `pipe = make_pipeline(RobustScaler(), LogisticRegression())`.\n\n See Also\n --------\n RobustScaler : Performs centering and scaling using the Transformer API\n (e.g. as part of a preprocessing :class:`~sklearn.pipeline.Pipeline`).\n \"\"\"\n X = check_array(X, accept_sparse=('csr', 'csc'), copy=False, ensure_2d=False, dtype=FLOAT_DTYPES, force_all_finite='allow-nan')\n original_ndim = X.ndim\n if original_ndim == 1:\n X = X.reshape(X.shape[0], 1)\n s = RobustScaler(with_centering=with_centering, with_scaling=with_scaling, quantile_range=quantile_range, unit_variance=unit_variance, copy=copy)\n if axis == 0:\n X = s.fit_transform(X)\n else:\n X = s.fit_transform(X.T).T\n if original_ndim == 1:\n X = X.ravel()\n return X" }, { "name": "scale", + "unique_name": "scale", "qname": "sklearn.preprocessing._data.scale", + "unique_qname": "sklearn.preprocessing._data.scale", "decorators": [], "parameters": [ { @@ -147878,7 +153098,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.preprocessing._discretization.KBinsDiscretizer.__init__", + "unique_qname": "sklearn.preprocessing._discretization.KBinsDiscretizer.__init__", "decorators": [], "parameters": [ { @@ -147940,7 +153162,9 @@ }, { "name": "_validate_n_bins", + "unique_name": "_validate_n_bins", "qname": "sklearn.preprocessing._discretization.KBinsDiscretizer._validate_n_bins", + "unique_qname": "sklearn.preprocessing._discretization.KBinsDiscretizer._validate_n_bins", "decorators": [], "parameters": [ { @@ -147972,7 +153196,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.preprocessing._discretization.KBinsDiscretizer.fit", + "unique_qname": "sklearn.preprocessing._discretization.KBinsDiscretizer.fit", "decorators": [], "parameters": [ { @@ -148014,7 +153240,9 @@ }, { "name": "get_feature_names_out", + "unique_name": "get_feature_names_out", "qname": "sklearn.preprocessing._discretization.KBinsDiscretizer.get_feature_names_out", + "unique_qname": "sklearn.preprocessing._discretization.KBinsDiscretizer.get_feature_names_out", "decorators": [], "parameters": [ { @@ -148046,7 +153274,9 @@ }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.preprocessing._discretization.KBinsDiscretizer.inverse_transform", + "unique_qname": "sklearn.preprocessing._discretization.KBinsDiscretizer.inverse_transform", "decorators": [], "parameters": [ { @@ -148078,7 +153308,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.preprocessing._discretization.KBinsDiscretizer.transform", + "unique_qname": "sklearn.preprocessing._discretization.KBinsDiscretizer.transform", "decorators": [], "parameters": [ { @@ -148110,7 +153342,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.preprocessing._encoders.OneHotEncoder.__init__", + "unique_qname": "sklearn.preprocessing._encoders.OneHotEncoder.__init__", "decorators": [], "parameters": [ { @@ -148182,7 +153416,9 @@ }, { "name": "_compute_drop_idx", + "unique_name": "_compute_drop_idx", "qname": "sklearn.preprocessing._encoders.OneHotEncoder._compute_drop_idx", + "unique_qname": "sklearn.preprocessing._encoders.OneHotEncoder._compute_drop_idx", "decorators": [], "parameters": [ { @@ -148204,7 +153440,9 @@ }, { "name": "_validate_keywords", + "unique_name": "_validate_keywords", "qname": "sklearn.preprocessing._encoders.OneHotEncoder._validate_keywords", + "unique_qname": "sklearn.preprocessing._encoders.OneHotEncoder._validate_keywords", "decorators": [], "parameters": [ { @@ -148226,7 +153464,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.preprocessing._encoders.OneHotEncoder.fit", + "unique_qname": "sklearn.preprocessing._encoders.OneHotEncoder.fit", "decorators": [], "parameters": [ { @@ -148268,7 +153508,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.preprocessing._encoders.OneHotEncoder.fit_transform", + "unique_qname": "sklearn.preprocessing._encoders.OneHotEncoder.fit_transform", "decorators": [], "parameters": [ { @@ -148310,7 +153552,9 @@ }, { "name": "get_feature_names", + "unique_name": "get_feature_names", "qname": "sklearn.preprocessing._encoders.OneHotEncoder.get_feature_names", + "unique_qname": "sklearn.preprocessing._encoders.OneHotEncoder.get_feature_names", "decorators": [ "deprecated('get_feature_names is deprecated in 1.0 and will be removed in 1.2. Please use get_feature_names_out instead.')" ], @@ -148344,7 +153588,9 @@ }, { "name": "get_feature_names_out", + "unique_name": "get_feature_names_out", "qname": "sklearn.preprocessing._encoders.OneHotEncoder.get_feature_names_out", + "unique_qname": "sklearn.preprocessing._encoders.OneHotEncoder.get_feature_names_out", "decorators": [], "parameters": [ { @@ -148370,13 +153616,15 @@ ], "results": [], "is_public": true, - "description": "Get output feature names for transformation.\n\nReturns `input_features` as this transformation doesn't add or drop features.", - "docstring": "Get output feature names for transformation.\n\nReturns `input_features` as this transformation doesn't add or drop\nfeatures.\n\nParameters\n----------\ninput_features : array-like of str or None, default=None\n Input features.\n\n - If `input_features` is `None`, then `feature_names_in_` is\n used as feature names in. If `feature_names_in_` is not defined,\n then names are generated: `[x0, x1, ..., x(n_features_in_)]`.\n - If `input_features` is an array-like, then `input_features` must\n match `feature_names_in_` if `feature_names_in_` is defined.\n\nReturns\n-------\nfeature_names_out : ndarray of str objects\n Transformed feature names.", - "source_code": "\ndef get_feature_names_out(self, input_features=None):\n \"\"\"Get output feature names for transformation.\n\n Returns `input_features` as this transformation doesn't add or drop\n features.\n\n Parameters\n ----------\n input_features : array-like of str or None, default=None\n Input features.\n\n - If `input_features` is `None`, then `feature_names_in_` is\n used as feature names in. If `feature_names_in_` is not defined,\n then names are generated: `[x0, x1, ..., x(n_features_in_)]`.\n - If `input_features` is an array-like, then `input_features` must\n match `feature_names_in_` if `feature_names_in_` is defined.\n\n Returns\n -------\n feature_names_out : ndarray of str objects\n Transformed feature names.\n \"\"\"\n check_is_fitted(self)\n cats = self.categories_\n input_features = _check_feature_names_in(self, input_features)\n feature_names = []\n for i in range(len(cats)):\n names = [input_features[i] + '_' + str(t) for t in cats[i]]\n if self.drop_idx_ is not None and self.drop_idx_[i] is not None:\n names.pop(self.drop_idx_[i])\n feature_names.extend(names)\n return np.asarray(feature_names, dtype=object)" + "description": "Get output feature names for transformation.", + "docstring": "Get output feature names for transformation.\n\nParameters\n----------\ninput_features : array-like of str or None, default=None\n Input features.\n\n - If `input_features` is `None`, then `feature_names_in_` is\n used as feature names in. If `feature_names_in_` is not defined,\n then names are generated: `[x0, x1, ..., x(n_features_in_)]`.\n - If `input_features` is an array-like, then `input_features` must\n match `feature_names_in_` if `feature_names_in_` is defined.\n\nReturns\n-------\nfeature_names_out : ndarray of str objects\n Transformed feature names.", + "source_code": "\ndef get_feature_names_out(self, input_features=None):\n \"\"\"Get output feature names for transformation.\n\n Parameters\n ----------\n input_features : array-like of str or None, default=None\n Input features.\n\n - If `input_features` is `None`, then `feature_names_in_` is\n used as feature names in. If `feature_names_in_` is not defined,\n then names are generated: `[x0, x1, ..., x(n_features_in_)]`.\n - If `input_features` is an array-like, then `input_features` must\n match `feature_names_in_` if `feature_names_in_` is defined.\n\n Returns\n -------\n feature_names_out : ndarray of str objects\n Transformed feature names.\n \"\"\"\n check_is_fitted(self)\n cats = self.categories_\n input_features = _check_feature_names_in(self, input_features)\n feature_names = []\n for i in range(len(cats)):\n names = [input_features[i] + '_' + str(t) for t in cats[i]]\n if self.drop_idx_ is not None and self.drop_idx_[i] is not None:\n names.pop(self.drop_idx_[i])\n feature_names.extend(names)\n return np.asarray(feature_names, dtype=object)" }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.preprocessing._encoders.OneHotEncoder.inverse_transform", + "unique_qname": "sklearn.preprocessing._encoders.OneHotEncoder.inverse_transform", "decorators": [], "parameters": [ { @@ -148408,7 +153656,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.preprocessing._encoders.OneHotEncoder.transform", + "unique_qname": "sklearn.preprocessing._encoders.OneHotEncoder.transform", "decorators": [], "parameters": [ { @@ -148440,7 +153690,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.preprocessing._encoders.OrdinalEncoder.__init__", + "unique_qname": "sklearn.preprocessing._encoders.OrdinalEncoder.__init__", "decorators": [], "parameters": [ { @@ -148502,7 +153754,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.preprocessing._encoders.OrdinalEncoder.fit", + "unique_qname": "sklearn.preprocessing._encoders.OrdinalEncoder.fit", "decorators": [], "parameters": [ { @@ -148544,7 +153798,9 @@ }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.preprocessing._encoders.OrdinalEncoder.inverse_transform", + "unique_qname": "sklearn.preprocessing._encoders.OrdinalEncoder.inverse_transform", "decorators": [], "parameters": [ { @@ -148576,7 +153832,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.preprocessing._encoders.OrdinalEncoder.transform", + "unique_qname": "sklearn.preprocessing._encoders.OrdinalEncoder.transform", "decorators": [], "parameters": [ { @@ -148608,7 +153866,9 @@ }, { "name": "_check_X", + "unique_name": "_check_X", "qname": "sklearn.preprocessing._encoders._BaseEncoder._check_X", + "unique_qname": "sklearn.preprocessing._encoders._BaseEncoder._check_X", "decorators": [], "parameters": [ { @@ -148650,7 +153910,9 @@ }, { "name": "_fit", + "unique_name": "_fit", "qname": "sklearn.preprocessing._encoders._BaseEncoder._fit", + "unique_qname": "sklearn.preprocessing._encoders._BaseEncoder._fit", "decorators": [], "parameters": [ { @@ -148702,7 +153964,9 @@ }, { "name": "_get_feature", + "unique_name": "_get_feature", "qname": "sklearn.preprocessing._encoders._BaseEncoder._get_feature", + "unique_qname": "sklearn.preprocessing._encoders._BaseEncoder._get_feature", "decorators": [], "parameters": [ { @@ -148744,7 +154008,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.preprocessing._encoders._BaseEncoder._more_tags", + "unique_qname": "sklearn.preprocessing._encoders._BaseEncoder._more_tags", "decorators": [], "parameters": [ { @@ -148766,7 +154032,9 @@ }, { "name": "_transform", + "unique_name": "_transform", "qname": "sklearn.preprocessing._encoders._BaseEncoder._transform", + "unique_qname": "sklearn.preprocessing._encoders._BaseEncoder._transform", "decorators": [], "parameters": [ { @@ -148828,7 +154096,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.preprocessing._function_transformer.FunctionTransformer.__init__", + "unique_qname": "sklearn.preprocessing._function_transformer.FunctionTransformer.__init__", "decorators": [], "parameters": [ { @@ -148920,7 +154190,9 @@ }, { "name": "__sklearn_is_fitted__", + "unique_name": "__sklearn_is_fitted__", "qname": "sklearn.preprocessing._function_transformer.FunctionTransformer.__sklearn_is_fitted__", + "unique_qname": "sklearn.preprocessing._function_transformer.FunctionTransformer.__sklearn_is_fitted__", "decorators": [], "parameters": [ { @@ -148942,7 +154214,9 @@ }, { "name": "_check_input", + "unique_name": "_check_input", "qname": "sklearn.preprocessing._function_transformer.FunctionTransformer._check_input", + "unique_qname": "sklearn.preprocessing._function_transformer.FunctionTransformer._check_input", "decorators": [], "parameters": [ { @@ -148984,7 +154258,9 @@ }, { "name": "_check_inverse_transform", + "unique_name": "_check_inverse_transform", "qname": "sklearn.preprocessing._function_transformer.FunctionTransformer._check_inverse_transform", + "unique_qname": "sklearn.preprocessing._function_transformer.FunctionTransformer._check_inverse_transform", "decorators": [], "parameters": [ { @@ -149016,7 +154292,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.preprocessing._function_transformer.FunctionTransformer._more_tags", + "unique_qname": "sklearn.preprocessing._function_transformer.FunctionTransformer._more_tags", "decorators": [], "parameters": [ { @@ -149038,7 +154316,9 @@ }, { "name": "_transform", + "unique_name": "_transform", "qname": "sklearn.preprocessing._function_transformer.FunctionTransformer._transform", + "unique_qname": "sklearn.preprocessing._function_transformer.FunctionTransformer._transform", "decorators": [], "parameters": [ { @@ -149090,7 +154370,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.preprocessing._function_transformer.FunctionTransformer.fit", + "unique_qname": "sklearn.preprocessing._function_transformer.FunctionTransformer.fit", "decorators": [], "parameters": [ { @@ -149132,7 +154414,9 @@ }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.preprocessing._function_transformer.FunctionTransformer.inverse_transform", + "unique_qname": "sklearn.preprocessing._function_transformer.FunctionTransformer.inverse_transform", "decorators": [], "parameters": [ { @@ -149164,7 +154448,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.preprocessing._function_transformer.FunctionTransformer.transform", + "unique_qname": "sklearn.preprocessing._function_transformer.FunctionTransformer.transform", "decorators": [], "parameters": [ { @@ -149196,7 +154482,9 @@ }, { "name": "_identity", + "unique_name": "_identity", "qname": "sklearn.preprocessing._function_transformer._identity", + "unique_qname": "sklearn.preprocessing._function_transformer._identity", "decorators": [], "parameters": [ { @@ -149218,7 +154506,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.preprocessing._label.LabelBinarizer.__init__", + "unique_qname": "sklearn.preprocessing._label.LabelBinarizer.__init__", "decorators": [], "parameters": [ { @@ -149270,7 +154560,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.preprocessing._label.LabelBinarizer._more_tags", + "unique_qname": "sklearn.preprocessing._label.LabelBinarizer._more_tags", "decorators": [], "parameters": [ { @@ -149292,7 +154584,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.preprocessing._label.LabelBinarizer.fit", + "unique_qname": "sklearn.preprocessing._label.LabelBinarizer.fit", "decorators": [], "parameters": [ { @@ -149324,7 +154618,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.preprocessing._label.LabelBinarizer.fit_transform", + "unique_qname": "sklearn.preprocessing._label.LabelBinarizer.fit_transform", "decorators": [], "parameters": [ { @@ -149356,7 +154652,9 @@ }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.preprocessing._label.LabelBinarizer.inverse_transform", + "unique_qname": "sklearn.preprocessing._label.LabelBinarizer.inverse_transform", "decorators": [], "parameters": [ { @@ -149398,7 +154696,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.preprocessing._label.LabelBinarizer.transform", + "unique_qname": "sklearn.preprocessing._label.LabelBinarizer.transform", "decorators": [], "parameters": [ { @@ -149430,7 +154730,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.preprocessing._label.LabelEncoder._more_tags", + "unique_qname": "sklearn.preprocessing._label.LabelEncoder._more_tags", "decorators": [], "parameters": [ { @@ -149452,7 +154754,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.preprocessing._label.LabelEncoder.fit", + "unique_qname": "sklearn.preprocessing._label.LabelEncoder.fit", "decorators": [], "parameters": [ { @@ -149484,7 +154788,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.preprocessing._label.LabelEncoder.fit_transform", + "unique_qname": "sklearn.preprocessing._label.LabelEncoder.fit_transform", "decorators": [], "parameters": [ { @@ -149516,7 +154822,9 @@ }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.preprocessing._label.LabelEncoder.inverse_transform", + "unique_qname": "sklearn.preprocessing._label.LabelEncoder.inverse_transform", "decorators": [], "parameters": [ { @@ -149548,7 +154856,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.preprocessing._label.LabelEncoder.transform", + "unique_qname": "sklearn.preprocessing._label.LabelEncoder.transform", "decorators": [], "parameters": [ { @@ -149580,7 +154890,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.preprocessing._label.MultiLabelBinarizer.__init__", + "unique_qname": "sklearn.preprocessing._label.MultiLabelBinarizer.__init__", "decorators": [], "parameters": [ { @@ -149622,7 +154934,9 @@ }, { "name": "_build_cache", + "unique_name": "_build_cache", "qname": "sklearn.preprocessing._label.MultiLabelBinarizer._build_cache", + "unique_qname": "sklearn.preprocessing._label.MultiLabelBinarizer._build_cache", "decorators": [], "parameters": [ { @@ -149644,7 +154958,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.preprocessing._label.MultiLabelBinarizer._more_tags", + "unique_qname": "sklearn.preprocessing._label.MultiLabelBinarizer._more_tags", "decorators": [], "parameters": [ { @@ -149666,7 +154982,9 @@ }, { "name": "_transform", + "unique_name": "_transform", "qname": "sklearn.preprocessing._label.MultiLabelBinarizer._transform", + "unique_qname": "sklearn.preprocessing._label.MultiLabelBinarizer._transform", "decorators": [], "parameters": [ { @@ -149686,7 +155004,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "iterable of iterables", - "description": "" + "description": "A set of labels (any orderable and hashable object) for each\nsample. If the `classes` parameter is set, `y` will not be\niterated." } }, { @@ -149703,12 +155021,14 @@ "results": [], "is_public": false, "description": "Transforms the label sets with a given mapping.", - "docstring": "Transforms the label sets with a given mapping.\n\nParameters\n----------\ny : iterable of iterables\nclass_mapping : Mapping\n Maps from label to column index in label indicator matrix.\n\nReturns\n-------\ny_indicator : sparse matrix of shape (n_samples, n_classes)\n Label indicator matrix. Will be of CSR format.", - "source_code": "\ndef _transform(self, y, class_mapping):\n \"\"\"Transforms the label sets with a given mapping.\n\n Parameters\n ----------\n y : iterable of iterables\n class_mapping : Mapping\n Maps from label to column index in label indicator matrix.\n\n Returns\n -------\n y_indicator : sparse matrix of shape (n_samples, n_classes)\n Label indicator matrix. Will be of CSR format.\n \"\"\"\n indices = array.array('i')\n indptr = array.array('i', [0])\n unknown = set()\n for labels in y:\n index = set()\n for label in labels:\n try:\n index.add(class_mapping[label])\n except KeyError:\n unknown.add(label)\n indices.extend(index)\n indptr.append(len(indices))\n if unknown:\n warnings.warn('unknown class(es) {0} will be ignored'.format(sorted(unknown, key=str)))\n data = np.ones(len(indices), dtype=int)\n return sp.csr_matrix((data, indices, indptr), shape=(len(indptr) - 1, len(class_mapping)))" + "docstring": "Transforms the label sets with a given mapping.\n\nParameters\n----------\ny : iterable of iterables\n A set of labels (any orderable and hashable object) for each\n sample. If the `classes` parameter is set, `y` will not be\n iterated.\n\nclass_mapping : Mapping\n Maps from label to column index in label indicator matrix.\n\nReturns\n-------\ny_indicator : sparse matrix of shape (n_samples, n_classes)\n Label indicator matrix. Will be of CSR format.", + "source_code": "\ndef _transform(self, y, class_mapping):\n \"\"\"Transforms the label sets with a given mapping.\n\n Parameters\n ----------\n y : iterable of iterables\n A set of labels (any orderable and hashable object) for each\n sample. If the `classes` parameter is set, `y` will not be\n iterated.\n\n class_mapping : Mapping\n Maps from label to column index in label indicator matrix.\n\n Returns\n -------\n y_indicator : sparse matrix of shape (n_samples, n_classes)\n Label indicator matrix. Will be of CSR format.\n \"\"\"\n indices = array.array('i')\n indptr = array.array('i', [0])\n unknown = set()\n for labels in y:\n index = set()\n for label in labels:\n try:\n index.add(class_mapping[label])\n except KeyError:\n unknown.add(label)\n indices.extend(index)\n indptr.append(len(indices))\n if unknown:\n warnings.warn('unknown class(es) {0} will be ignored'.format(sorted(unknown, key=str)))\n data = np.ones(len(indices), dtype=int)\n return sp.csr_matrix((data, indices, indptr), shape=(len(indptr) - 1, len(class_mapping)))" }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.preprocessing._label.MultiLabelBinarizer.fit", + "unique_qname": "sklearn.preprocessing._label.MultiLabelBinarizer.fit", "decorators": [], "parameters": [ { @@ -149735,12 +155055,14 @@ "results": [], "is_public": true, "description": "Fit the label sets binarizer, storing :term:`classes_`.", - "docstring": "Fit the label sets binarizer, storing :term:`classes_`.\n\nParameters\n----------\ny : iterable of iterables\n A set of labels (any orderable and hashable object) for each\n sample. If the `classes` parameter is set, `y` will not be\n iterated.\n\nReturns\n-------\nself : returns this MultiLabelBinarizer instance", - "source_code": "\ndef fit(self, y):\n \"\"\"Fit the label sets binarizer, storing :term:`classes_`.\n\n Parameters\n ----------\n y : iterable of iterables\n A set of labels (any orderable and hashable object) for each\n sample. If the `classes` parameter is set, `y` will not be\n iterated.\n\n Returns\n -------\n self : returns this MultiLabelBinarizer instance\n \"\"\"\n self._cached_dict = None\n if self.classes is None:\n classes = sorted(set(itertools.chain.from_iterable(y)))\n elif len(set(self.classes)) < len(self.classes):\n raise ValueError('The classes argument contains duplicate classes. Remove these duplicates before passing them to MultiLabelBinarizer.')\n else:\n classes = self.classes\n dtype = int if all((isinstance(c, int) for c in classes)) else object\n self.classes_ = np.empty(len(classes), dtype=dtype)\n self.classes_[:] = classes\n return self" + "docstring": "Fit the label sets binarizer, storing :term:`classes_`.\n\nParameters\n----------\ny : iterable of iterables\n A set of labels (any orderable and hashable object) for each\n sample. If the `classes` parameter is set, `y` will not be\n iterated.\n\nReturns\n-------\nself : object\n Fitted estimator.", + "source_code": "\ndef fit(self, y):\n \"\"\"Fit the label sets binarizer, storing :term:`classes_`.\n\n Parameters\n ----------\n y : iterable of iterables\n A set of labels (any orderable and hashable object) for each\n sample. If the `classes` parameter is set, `y` will not be\n iterated.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n self._cached_dict = None\n if self.classes is None:\n classes = sorted(set(itertools.chain.from_iterable(y)))\n elif len(set(self.classes)) < len(self.classes):\n raise ValueError('The classes argument contains duplicate classes. Remove these duplicates before passing them to MultiLabelBinarizer.')\n else:\n classes = self.classes\n dtype = int if all((isinstance(c, int) for c in classes)) else object\n self.classes_ = np.empty(len(classes), dtype=dtype)\n self.classes_[:] = classes\n return self" }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.preprocessing._label.MultiLabelBinarizer.fit_transform", + "unique_qname": "sklearn.preprocessing._label.MultiLabelBinarizer.fit_transform", "decorators": [], "parameters": [ { @@ -149767,12 +155089,14 @@ "results": [], "is_public": true, "description": "Fit the label sets binarizer and transform the given label sets.", - "docstring": "Fit the label sets binarizer and transform the given label sets.\n\nParameters\n----------\ny : iterable of iterables\n A set of labels (any orderable and hashable object) for each\n sample. If the `classes` parameter is set, `y` will not be\n iterated.\n\nReturns\n-------\ny_indicator : {ndarray, sparse matrix} of shape (n_samples, n_classes)\n A matrix such that `y_indicator[i, j] = 1` i.f.f. `classes_[j]`\n is in `y[i]`, and 0 otherwise. Sparse matrix will be of CSR\n format.", - "source_code": "\ndef fit_transform(self, y):\n \"\"\"Fit the label sets binarizer and transform the given label sets.\n\n Parameters\n ----------\n y : iterable of iterables\n A set of labels (any orderable and hashable object) for each\n sample. If the `classes` parameter is set, `y` will not be\n iterated.\n\n Returns\n -------\n y_indicator : {ndarray, sparse matrix} of shape (n_samples, n_classes)\n A matrix such that `y_indicator[i, j] = 1` i.f.f. `classes_[j]`\n is in `y[i]`, and 0 otherwise. Sparse matrix will be of CSR\n format.\n \"\"\"\n self._cached_dict = None\n if self.classes is not None:\n return self.fit(y).transform(y)\n class_mapping = defaultdict(int)\n class_mapping.default_factory = class_mapping.__len__\n yt = self._transform(y, class_mapping)\n tmp = sorted(class_mapping, key=class_mapping.get)\n dtype = int if all((isinstance(c, int) for c in tmp)) else object\n class_mapping = np.empty(len(tmp), dtype=dtype)\n class_mapping[:] = tmp\n (self.classes_, inverse) = np.unique(class_mapping, return_inverse=True)\n yt.indices = np.array(inverse[yt.indices], dtype=yt.indices.dtype, copy=False)\n if not self.sparse_output:\n yt = yt.toarray()\n return yt" + "docstring": "Fit the label sets binarizer and transform the given label sets.\n\nParameters\n----------\ny : iterable of iterables\n A set of labels (any orderable and hashable object) for each\n sample. If the `classes` parameter is set, `y` will not be\n iterated.\n\nReturns\n-------\ny_indicator : {ndarray, sparse matrix} of shape (n_samples, n_classes)\n A matrix such that `y_indicator[i, j] = 1` iff `classes_[j]`\n is in `y[i]`, and 0 otherwise. Sparse matrix will be of CSR\n format.", + "source_code": "\ndef fit_transform(self, y):\n \"\"\"Fit the label sets binarizer and transform the given label sets.\n\n Parameters\n ----------\n y : iterable of iterables\n A set of labels (any orderable and hashable object) for each\n sample. If the `classes` parameter is set, `y` will not be\n iterated.\n\n Returns\n -------\n y_indicator : {ndarray, sparse matrix} of shape (n_samples, n_classes)\n A matrix such that `y_indicator[i, j] = 1` iff `classes_[j]`\n is in `y[i]`, and 0 otherwise. Sparse matrix will be of CSR\n format.\n \"\"\"\n self._cached_dict = None\n if self.classes is not None:\n return self.fit(y).transform(y)\n class_mapping = defaultdict(int)\n class_mapping.default_factory = class_mapping.__len__\n yt = self._transform(y, class_mapping)\n tmp = sorted(class_mapping, key=class_mapping.get)\n dtype = int if all((isinstance(c, int) for c in tmp)) else object\n class_mapping = np.empty(len(tmp), dtype=dtype)\n class_mapping[:] = tmp\n (self.classes_, inverse) = np.unique(class_mapping, return_inverse=True)\n yt.indices = np.array(inverse[yt.indices], dtype=yt.indices.dtype, copy=False)\n if not self.sparse_output:\n yt = yt.toarray()\n return yt" }, { "name": "inverse_transform", + "unique_name": "inverse_transform", "qname": "sklearn.preprocessing._label.MultiLabelBinarizer.inverse_transform", + "unique_qname": "sklearn.preprocessing._label.MultiLabelBinarizer.inverse_transform", "decorators": [], "parameters": [ { @@ -149804,7 +155128,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.preprocessing._label.MultiLabelBinarizer.transform", + "unique_qname": "sklearn.preprocessing._label.MultiLabelBinarizer.transform", "decorators": [], "parameters": [ { @@ -149836,7 +155162,9 @@ }, { "name": "_inverse_binarize_multiclass", + "unique_name": "_inverse_binarize_multiclass", "qname": "sklearn.preprocessing._label._inverse_binarize_multiclass", + "unique_qname": "sklearn.preprocessing._label._inverse_binarize_multiclass", "decorators": [], "parameters": [ { @@ -149868,7 +155196,9 @@ }, { "name": "_inverse_binarize_thresholding", + "unique_name": "_inverse_binarize_thresholding", "qname": "sklearn.preprocessing._label._inverse_binarize_thresholding", + "unique_qname": "sklearn.preprocessing._label._inverse_binarize_thresholding", "decorators": [], "parameters": [ { @@ -149920,7 +155250,9 @@ }, { "name": "label_binarize", + "unique_name": "label_binarize", "qname": "sklearn.preprocessing._label.label_binarize", + "unique_qname": "sklearn.preprocessing._label.label_binarize", "decorators": [], "parameters": [ { @@ -149982,7 +155314,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.preprocessing._polynomial.PolynomialFeatures.__init__", + "unique_qname": "sklearn.preprocessing._polynomial.PolynomialFeatures.__init__", "decorators": [], "parameters": [ { @@ -150002,7 +155336,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "int or tuple (min_degree, max_degree), default=2", - "description": "If a single int is given, it specifies the maximal degree of the\npolynomial features. If a tuple ``(min_degree, max_degree)`` is\npassed, then ``min_degree`` is the minimum and ``max_degree`` is the\nmaximum polynomial degree of the generated features. Note that\nmin_degree=0 and 1 are equivalent as outputting the degree zero term\nis determined by ``include_bias``." + "description": "If a single int is given, it specifies the maximal degree of the\npolynomial features. If a tuple `(min_degree, max_degree)` is passed,\nthen `min_degree` is the minimum and `max_degree` is the maximum\npolynomial degree of the generated features. Note that `min_degree=0`\nand `min_degree=1` are equivalent as outputting the degree zero term is\ndetermined by `include_bias`." } }, { @@ -150012,7 +155346,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "bool, default=False", - "description": "If true, only interaction features are produced: features that are\nproducts of at most ``degree`` *distinct* input features, i.e. terms\nwith power of 2 or higher of the same input feature are excluded:\n\n - included: ``x[0]``, `x[1]`, ``x[0] * x[1]``, etc.\n - excluded: ``x[0] ** 2``, ``x[0] ** 2 * x[1]``, etc." + "description": "If `True`, only interaction features are produced: features that are\nproducts of at most `degree` *distinct* input features, i.e. terms with\npower of 2 or higher of the same input feature are excluded:\n\n - included: `x[0]`, `x[1]`, `x[0] * x[1]`, etc.\n - excluded: `x[0] ** 2`, `x[0] ** 2 * x[1]`, etc." } }, { @@ -150022,7 +155356,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "bool, default=True", - "description": "If True (default), then include a bias column, the feature in which\nall polynomial powers are zero (i.e. a column of ones - acts as an\nintercept term in a linear model)." + "description": "If `True` (default), then include a bias column, the feature in which\nall polynomial powers are zero (i.e. a column of ones - acts as an\nintercept term in a linear model)." } }, { @@ -150032,7 +155366,7 @@ "assigned_by": "NAME_ONLY", "docstring": { "type": "{'C', 'F'}, default='C'", - "description": "Order of output array in the dense case. 'F' order is faster to\ncompute, but may slow down subsequent estimators.\n\n.. versionadded:: 0.21" + "description": "Order of output array in the dense case. `'F'` order is faster to\ncompute, but may slow down subsequent estimators.\n\n.. versionadded:: 0.21" } } ], @@ -150044,7 +155378,9 @@ }, { "name": "_combinations", + "unique_name": "_combinations", "qname": "sklearn.preprocessing._polynomial.PolynomialFeatures._combinations", + "unique_qname": "sklearn.preprocessing._polynomial.PolynomialFeatures._combinations", "decorators": ["staticmethod"], "parameters": [ { @@ -150106,7 +155442,9 @@ }, { "name": "_num_combinations", + "unique_name": "_num_combinations", "qname": "sklearn.preprocessing._polynomial.PolynomialFeatures._num_combinations", + "unique_qname": "sklearn.preprocessing._polynomial.PolynomialFeatures._num_combinations", "decorators": ["staticmethod"], "parameters": [ { @@ -150168,7 +155506,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.preprocessing._polynomial.PolynomialFeatures.fit", + "unique_qname": "sklearn.preprocessing._polynomial.PolynomialFeatures.fit", "decorators": [], "parameters": [ { @@ -150197,20 +155537,22 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "None", - "description": "Ignored." + "type": "Ignored", + "description": "Not used, present here for API consistency by convention." } } ], "results": [], "is_public": true, "description": "Compute number of output features.", - "docstring": "Compute number of output features.\n\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n The data.\n\ny : None\n Ignored.\n\nReturns\n-------\nself : object\n Fitted transformer.", - "source_code": "\ndef fit(self, X, y=None):\n \"\"\"\n Compute number of output features.\n\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The data.\n\n y : None\n Ignored.\n\n Returns\n -------\n self : object\n Fitted transformer.\n \"\"\"\n (_, n_features) = self._validate_data(X, accept_sparse=True).shape\n if isinstance(self.degree, numbers.Integral):\n if self.degree < 0:\n raise ValueError(f'degree must be a non-negative integer, got {self.degree}.')\n self._min_degree = 0\n self._max_degree = self.degree\n elif isinstance(self.degree, collections.abc.Iterable) and len(self.degree) == 2:\n (self._min_degree, self._max_degree) = self.degree\n if not (isinstance(self._min_degree, numbers.Integral) and isinstance(self._max_degree, numbers.Integral) and self._min_degree >= 0 and self._min_degree <= self._max_degree):\n raise ValueError(f'degree=(min_degree, max_degree) must be non-negative integers that fulfil min_degree <= max_degree, got {self.degree}.')\n else:\n raise ValueError(f'degree must be a non-negative int or tuple (min_degree, max_degree), got {self.degree}.')\n self.n_output_features_ = self._num_combinations(n_features=n_features, min_degree=self._min_degree, max_degree=self._max_degree, interaction_only=self.interaction_only, include_bias=self.include_bias)\n self._n_out_full = self._num_combinations(n_features=n_features, min_degree=0, max_degree=self._max_degree, interaction_only=self.interaction_only, include_bias=self.include_bias)\n return self" + "docstring": "Compute number of output features.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n The data.\n\ny : Ignored\n Not used, present here for API consistency by convention.\n\nReturns\n-------\nself : object\n Fitted transformer.", + "source_code": "\ndef fit(self, X, y=None):\n \"\"\"\n Compute number of output features.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The data.\n\n y : Ignored\n Not used, present here for API consistency by convention.\n\n Returns\n -------\n self : object\n Fitted transformer.\n \"\"\"\n (_, n_features) = self._validate_data(X, accept_sparse=True).shape\n if isinstance(self.degree, numbers.Integral):\n if self.degree < 0:\n raise ValueError(f'degree must be a non-negative integer, got {self.degree}.')\n self._min_degree = 0\n self._max_degree = self.degree\n elif isinstance(self.degree, collections.abc.Iterable) and len(self.degree) == 2:\n (self._min_degree, self._max_degree) = self.degree\n if not (isinstance(self._min_degree, numbers.Integral) and isinstance(self._max_degree, numbers.Integral) and self._min_degree >= 0 and self._min_degree <= self._max_degree):\n raise ValueError(f'degree=(min_degree, max_degree) must be non-negative integers that fulfil min_degree <= max_degree, got {self.degree}.')\n else:\n raise ValueError(f'degree must be a non-negative int or tuple (min_degree, max_degree), got {self.degree}.')\n self.n_output_features_ = self._num_combinations(n_features=n_features, min_degree=self._min_degree, max_degree=self._max_degree, interaction_only=self.interaction_only, include_bias=self.include_bias)\n self._n_out_full = self._num_combinations(n_features=n_features, min_degree=0, max_degree=self._max_degree, interaction_only=self.interaction_only, include_bias=self.include_bias)\n return self" }, { "name": "get_feature_names", + "unique_name": "get_feature_names", "qname": "sklearn.preprocessing._polynomial.PolynomialFeatures.get_feature_names", + "unique_qname": "sklearn.preprocessing._polynomial.PolynomialFeatures.get_feature_names", "decorators": [ "deprecated('get_feature_names is deprecated in 1.0 and will be removed in 1.2. Please use get_feature_names_out instead.')" ], @@ -150238,13 +155580,15 @@ ], "results": [], "is_public": true, - "description": "Return feature names for output features", - "docstring": "Return feature names for output features\n\nParameters\n----------\ninput_features : list of str of shape (n_features,), default=None\n String names for input features if available. By default,\n \"x0\", \"x1\", ... \"xn_features\" is used.\n\nReturns\n-------\noutput_feature_names : list of str of shape (n_output_features,)", - "source_code": "\n@deprecated('get_feature_names is deprecated in 1.0 and will be removed in 1.2. Please use get_feature_names_out instead.')\ndef get_feature_names(self, input_features=None):\n \"\"\"\n Return feature names for output features\n\n Parameters\n ----------\n input_features : list of str of shape (n_features,), default=None\n String names for input features if available. By default,\n \"x0\", \"x1\", ... \"xn_features\" is used.\n\n Returns\n -------\n output_feature_names : list of str of shape (n_output_features,)\n \"\"\"\n powers = self.powers_\n if input_features is None:\n input_features = ['x%d' % i for i in range(powers.shape[1])]\n feature_names = []\n for row in powers:\n inds = np.where(row)[0]\n if len(inds):\n name = ' '.join(('%s^%d' % (input_features[ind], exp) if exp != 1 else input_features[ind] for (ind, exp) in zip(inds, row[inds])))\n else:\n name = '1'\n feature_names.append(name)\n return feature_names" + "description": "Return feature names for output features.", + "docstring": "Return feature names for output features.\n\nParameters\n----------\ninput_features : list of str of shape (n_features,), default=None\n String names for input features if available. By default,\n \"x0\", \"x1\", ... \"xn_features\" is used.\n\nReturns\n-------\noutput_feature_names : list of str of shape (n_output_features,)\n Transformed feature names.", + "source_code": "\n@deprecated('get_feature_names is deprecated in 1.0 and will be removed in 1.2. Please use get_feature_names_out instead.')\ndef get_feature_names(self, input_features=None):\n \"\"\"Return feature names for output features.\n\n Parameters\n ----------\n input_features : list of str of shape (n_features,), default=None\n String names for input features if available. By default,\n \"x0\", \"x1\", ... \"xn_features\" is used.\n\n Returns\n -------\n output_feature_names : list of str of shape (n_output_features,)\n Transformed feature names.\n \"\"\"\n powers = self.powers_\n if input_features is None:\n input_features = ['x%d' % i for i in range(powers.shape[1])]\n feature_names = []\n for row in powers:\n inds = np.where(row)[0]\n if len(inds):\n name = ' '.join(('%s^%d' % (input_features[ind], exp) if exp != 1 else input_features[ind] for (ind, exp) in zip(inds, row[inds])))\n else:\n name = '1'\n feature_names.append(name)\n return feature_names" }, { "name": "get_feature_names_out", + "unique_name": "get_feature_names_out", "qname": "sklearn.preprocessing._polynomial.PolynomialFeatures.get_feature_names_out", + "unique_qname": "sklearn.preprocessing._polynomial.PolynomialFeatures.get_feature_names_out", "decorators": [], "parameters": [ { @@ -150264,19 +155608,21 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "array-like of str or None, default=None", - "description": "Input features.\n\n- If `input_features` is `None`, then `feature_names_in_` is\n used as feature names in. If `feature_names_in_` is not defined,\n then names are generated: `[x0, x1, ..., x(n_features_in_)]`.\n- If `input_features` is an array-like, then `input_features` must\n match `feature_names_in_` if `feature_names_in_` is defined." + "description": "Input features.\n\n- If `input_features is None`, then `feature_names_in_` is\n used as feature names in. If `feature_names_in_` is not defined,\n then names are generated: `[x0, x1, ..., x(n_features_in_)]`.\n- If `input_features` is an array-like, then `input_features` must\n match `feature_names_in_` if `feature_names_in_` is defined." } } ], "results": [], "is_public": true, "description": "Get output feature names for transformation.", - "docstring": "Get output feature names for transformation.\n\nParameters\n----------\ninput_features : array-like of str or None, default=None\n Input features.\n\n - If `input_features` is `None`, then `feature_names_in_` is\n used as feature names in. If `feature_names_in_` is not defined,\n then names are generated: `[x0, x1, ..., x(n_features_in_)]`.\n - If `input_features` is an array-like, then `input_features` must\n match `feature_names_in_` if `feature_names_in_` is defined.\n\nReturns\n-------\nfeature_names_out : ndarray of str objects\n Transformed feature names.", - "source_code": "\ndef get_feature_names_out(self, input_features=None):\n \"\"\"Get output feature names for transformation.\n\n Parameters\n ----------\n input_features : array-like of str or None, default=None\n Input features.\n\n - If `input_features` is `None`, then `feature_names_in_` is\n used as feature names in. If `feature_names_in_` is not defined,\n then names are generated: `[x0, x1, ..., x(n_features_in_)]`.\n - If `input_features` is an array-like, then `input_features` must\n match `feature_names_in_` if `feature_names_in_` is defined.\n\n Returns\n -------\n feature_names_out : ndarray of str objects\n Transformed feature names.\n \"\"\"\n powers = self.powers_\n input_features = _check_feature_names_in(self, input_features)\n feature_names = []\n for row in powers:\n inds = np.where(row)[0]\n if len(inds):\n name = ' '.join(('%s^%d' % (input_features[ind], exp) if exp != 1 else input_features[ind] for (ind, exp) in zip(inds, row[inds])))\n else:\n name = '1'\n feature_names.append(name)\n return np.asarray(feature_names, dtype=object)" + "docstring": "Get output feature names for transformation.\n\nParameters\n----------\ninput_features : array-like of str or None, default=None\n Input features.\n\n - If `input_features is None`, then `feature_names_in_` is\n used as feature names in. If `feature_names_in_` is not defined,\n then names are generated: `[x0, x1, ..., x(n_features_in_)]`.\n - If `input_features` is an array-like, then `input_features` must\n match `feature_names_in_` if `feature_names_in_` is defined.\n\nReturns\n-------\nfeature_names_out : ndarray of str objects\n Transformed feature names.", + "source_code": "\ndef get_feature_names_out(self, input_features=None):\n \"\"\"Get output feature names for transformation.\n\n Parameters\n ----------\n input_features : array-like of str or None, default=None\n Input features.\n\n - If `input_features is None`, then `feature_names_in_` is\n used as feature names in. If `feature_names_in_` is not defined,\n then names are generated: `[x0, x1, ..., x(n_features_in_)]`.\n - If `input_features` is an array-like, then `input_features` must\n match `feature_names_in_` if `feature_names_in_` is defined.\n\n Returns\n -------\n feature_names_out : ndarray of str objects\n Transformed feature names.\n \"\"\"\n powers = self.powers_\n input_features = _check_feature_names_in(self, input_features)\n feature_names = []\n for row in powers:\n inds = np.where(row)[0]\n if len(inds):\n name = ' '.join(('%s^%d' % (input_features[ind], exp) if exp != 1 else input_features[ind] for (ind, exp) in zip(inds, row[inds])))\n else:\n name = '1'\n feature_names.append(name)\n return np.asarray(feature_names, dtype=object)" }, { "name": "n_input_features_", + "unique_name": "n_input_features_@getter", "qname": "sklearn.preprocessing._polynomial.PolynomialFeatures.n_input_features_", + "unique_qname": "sklearn.preprocessing._polynomial.PolynomialFeatures.n_input_features_@getter", "decorators": [ "deprecated('The attribute `n_input_features_` was deprecated in version 1.0 and will be removed in 1.2.')", "property" @@ -150301,7 +155647,9 @@ }, { "name": "powers_", + "unique_name": "powers_@getter", "qname": "sklearn.preprocessing._polynomial.PolynomialFeatures.powers_", + "unique_qname": "sklearn.preprocessing._polynomial.PolynomialFeatures.powers_@getter", "decorators": ["property"], "parameters": [ { @@ -150317,13 +155665,15 @@ ], "results": [], "is_public": true, - "description": "", - "docstring": "", - "source_code": "\n@property\ndef powers_(self):\n check_is_fitted(self)\n combinations = self._combinations(n_features=self.n_features_in_, min_degree=self._min_degree, max_degree=self._max_degree, interaction_only=self.interaction_only, include_bias=self.include_bias)\n return np.vstack([np.bincount(c, minlength=self.n_features_in_) for c in combinations])" + "description": "Exponent for each of the inputs in the output.", + "docstring": "Exponent for each of the inputs in the output.", + "source_code": "\n@property\ndef powers_(self):\n \"\"\"Exponent for each of the inputs in the output.\"\"\"\n check_is_fitted(self)\n combinations = self._combinations(n_features=self.n_features_in_, min_degree=self._min_degree, max_degree=self._max_degree, interaction_only=self.interaction_only, include_bias=self.include_bias)\n return np.vstack([np.bincount(c, minlength=self.n_features_in_) for c in combinations])" }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.preprocessing._polynomial.PolynomialFeatures.transform", + "unique_qname": "sklearn.preprocessing._polynomial.PolynomialFeatures.transform", "decorators": [], "parameters": [ { @@ -150350,12 +155700,14 @@ "results": [], "is_public": true, "description": "Transform data to polynomial features.", - "docstring": "Transform data to polynomial features.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n The data to transform, row by row.\n\n Prefer CSR over CSC for sparse input (for speed), but CSC is\n required if the degree is 4 or higher. If the degree is less than\n 4 and the input format is CSC, it will be converted to CSR, have\n its polynomial features generated, then converted back to CSC.\n\n If the degree is 2 or 3, the method described in \"Leveraging\n Sparsity to Speed Up Polynomial Feature Expansions of CSR Matrices\n Using K-Simplex Numbers\" by Andrew Nystrom and John Hughes is\n used, which is much faster than the method used on CSC input. For\n this reason, a CSC input will be converted to CSR, and the output\n will be converted back to CSC prior to being returned, hence the\n preference of CSR.\n\nReturns\n-------\nXP : {ndarray, sparse matrix} of shape (n_samples, NP)\n The matrix of features, where NP is the number of polynomial\n features generated from the combination of inputs. If a sparse\n matrix is provided, it will be converted into a sparse\n ``csr_matrix``.", - "source_code": "\ndef transform(self, X):\n \"\"\"Transform data to polynomial features.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The data to transform, row by row.\n\n Prefer CSR over CSC for sparse input (for speed), but CSC is\n required if the degree is 4 or higher. If the degree is less than\n 4 and the input format is CSC, it will be converted to CSR, have\n its polynomial features generated, then converted back to CSC.\n\n If the degree is 2 or 3, the method described in \"Leveraging\n Sparsity to Speed Up Polynomial Feature Expansions of CSR Matrices\n Using K-Simplex Numbers\" by Andrew Nystrom and John Hughes is\n used, which is much faster than the method used on CSC input. For\n this reason, a CSC input will be converted to CSR, and the output\n will be converted back to CSC prior to being returned, hence the\n preference of CSR.\n\n Returns\n -------\n XP : {ndarray, sparse matrix} of shape (n_samples, NP)\n The matrix of features, where NP is the number of polynomial\n features generated from the combination of inputs. If a sparse\n matrix is provided, it will be converted into a sparse\n ``csr_matrix``.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, order='F', dtype=FLOAT_DTYPES, reset=False, accept_sparse=('csr', 'csc'))\n (n_samples, n_features) = X.shape\n if sparse.isspmatrix_csr(X):\n if self._max_degree > 3:\n return self.transform(X.tocsc()).tocsr()\n to_stack = []\n if self.include_bias:\n to_stack.append(sparse.csc_matrix(np.ones(shape=(n_samples, 1), dtype=X.dtype)))\n if self._min_degree <= 1:\n to_stack.append(X)\n for deg in range(max(2, self._min_degree), self._max_degree + 1):\n Xp_next = _csr_polynomial_expansion(X.data, X.indices, X.indptr, X.shape[1], self.interaction_only, deg)\n if Xp_next is None:\n break\n to_stack.append(Xp_next)\n if len(to_stack) == 0:\n XP = sparse.csr_matrix((n_samples, 0), dtype=X.dtype)\n else:\n XP = sparse.hstack(to_stack, format='csr')\n elif sparse.isspmatrix_csc(X) and self._max_degree < 4:\n return self.transform(X.tocsr()).tocsc()\n elif sparse.isspmatrix(X):\n combinations = self._combinations(n_features=n_features, min_degree=self._min_degree, max_degree=self._max_degree, interaction_only=self.interaction_only, include_bias=self.include_bias)\n columns = []\n for combi in combinations:\n if combi:\n out_col = 1\n for col_idx in combi:\n out_col = X[:, col_idx].multiply(out_col)\n columns.append(out_col)\n else:\n bias = sparse.csc_matrix(np.ones((X.shape[0], 1)))\n columns.append(bias)\n XP = sparse.hstack(columns, dtype=X.dtype).tocsc()\n else:\n XP = np.empty(shape=(n_samples, self._n_out_full), dtype=X.dtype, order=self.order)\n if self.include_bias:\n XP[:, 0] = 1\n current_col = 1\n else:\n current_col = 0\n XP[:, current_col:current_col + n_features] = X\n index = list(range(current_col, current_col + n_features))\n current_col += n_features\n index.append(current_col)\n for _ in range(2, self._max_degree + 1):\n new_index = []\n end = index[-1]\n for feature_idx in range(n_features):\n start = index[feature_idx]\n new_index.append(current_col)\n if self.interaction_only:\n start += index[feature_idx + 1] - index[feature_idx]\n next_col = current_col + end - start\n if next_col <= current_col:\n break\n np.multiply(XP[:, start:end], X[:, feature_idx:feature_idx + 1], out=XP[:, current_col:next_col], casting='no')\n current_col = next_col\n new_index.append(current_col)\n index = new_index\n if self._min_degree > 1:\n (n_XP, n_Xout) = (self._n_out_full, self.n_output_features_)\n if self.include_bias:\n Xout = np.empty(shape=(n_samples, n_Xout), dtype=XP.dtype, order=self.order)\n Xout[:, 0] = 1\n Xout[:, 1:] = XP[:, n_XP - n_Xout + 1:]\n else:\n Xout = XP[:, n_XP - n_Xout:].copy()\n XP = Xout\n return XP" + "docstring": "Transform data to polynomial features.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n The data to transform, row by row.\n\n Prefer CSR over CSC for sparse input (for speed), but CSC is\n required if the degree is 4 or higher. If the degree is less than\n 4 and the input format is CSC, it will be converted to CSR, have\n its polynomial features generated, then converted back to CSC.\n\n If the degree is 2 or 3, the method described in \"Leveraging\n Sparsity to Speed Up Polynomial Feature Expansions of CSR Matrices\n Using K-Simplex Numbers\" by Andrew Nystrom and John Hughes is\n used, which is much faster than the method used on CSC input. For\n this reason, a CSC input will be converted to CSR, and the output\n will be converted back to CSC prior to being returned, hence the\n preference of CSR.\n\nReturns\n-------\nXP : {ndarray, sparse matrix} of shape (n_samples, NP)\n The matrix of features, where `NP` is the number of polynomial\n features generated from the combination of inputs. If a sparse\n matrix is provided, it will be converted into a sparse\n `csr_matrix`.", + "source_code": "\ndef transform(self, X):\n \"\"\"Transform data to polynomial features.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n The data to transform, row by row.\n\n Prefer CSR over CSC for sparse input (for speed), but CSC is\n required if the degree is 4 or higher. If the degree is less than\n 4 and the input format is CSC, it will be converted to CSR, have\n its polynomial features generated, then converted back to CSC.\n\n If the degree is 2 or 3, the method described in \"Leveraging\n Sparsity to Speed Up Polynomial Feature Expansions of CSR Matrices\n Using K-Simplex Numbers\" by Andrew Nystrom and John Hughes is\n used, which is much faster than the method used on CSC input. For\n this reason, a CSC input will be converted to CSR, and the output\n will be converted back to CSC prior to being returned, hence the\n preference of CSR.\n\n Returns\n -------\n XP : {ndarray, sparse matrix} of shape (n_samples, NP)\n The matrix of features, where `NP` is the number of polynomial\n features generated from the combination of inputs. If a sparse\n matrix is provided, it will be converted into a sparse\n `csr_matrix`.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, order='F', dtype=FLOAT_DTYPES, reset=False, accept_sparse=('csr', 'csc'))\n (n_samples, n_features) = X.shape\n if sparse.isspmatrix_csr(X):\n if self._max_degree > 3:\n return self.transform(X.tocsc()).tocsr()\n to_stack = []\n if self.include_bias:\n to_stack.append(sparse.csc_matrix(np.ones(shape=(n_samples, 1), dtype=X.dtype)))\n if self._min_degree <= 1:\n to_stack.append(X)\n for deg in range(max(2, self._min_degree), self._max_degree + 1):\n Xp_next = _csr_polynomial_expansion(X.data, X.indices, X.indptr, X.shape[1], self.interaction_only, deg)\n if Xp_next is None:\n break\n to_stack.append(Xp_next)\n if len(to_stack) == 0:\n XP = sparse.csr_matrix((n_samples, 0), dtype=X.dtype)\n else:\n XP = sparse.hstack(to_stack, format='csr')\n elif sparse.isspmatrix_csc(X) and self._max_degree < 4:\n return self.transform(X.tocsr()).tocsc()\n elif sparse.isspmatrix(X):\n combinations = self._combinations(n_features=n_features, min_degree=self._min_degree, max_degree=self._max_degree, interaction_only=self.interaction_only, include_bias=self.include_bias)\n columns = []\n for combi in combinations:\n if combi:\n out_col = 1\n for col_idx in combi:\n out_col = X[:, col_idx].multiply(out_col)\n columns.append(out_col)\n else:\n bias = sparse.csc_matrix(np.ones((X.shape[0], 1)))\n columns.append(bias)\n XP = sparse.hstack(columns, dtype=X.dtype).tocsc()\n else:\n XP = np.empty(shape=(n_samples, self._n_out_full), dtype=X.dtype, order=self.order)\n if self.include_bias:\n XP[:, 0] = 1\n current_col = 1\n else:\n current_col = 0\n XP[:, current_col:current_col + n_features] = X\n index = list(range(current_col, current_col + n_features))\n current_col += n_features\n index.append(current_col)\n for _ in range(2, self._max_degree + 1):\n new_index = []\n end = index[-1]\n for feature_idx in range(n_features):\n start = index[feature_idx]\n new_index.append(current_col)\n if self.interaction_only:\n start += index[feature_idx + 1] - index[feature_idx]\n next_col = current_col + end - start\n if next_col <= current_col:\n break\n np.multiply(XP[:, start:end], X[:, feature_idx:feature_idx + 1], out=XP[:, current_col:next_col], casting='no')\n current_col = next_col\n new_index.append(current_col)\n index = new_index\n if self._min_degree > 1:\n (n_XP, n_Xout) = (self._n_out_full, self.n_output_features_)\n if self.include_bias:\n Xout = np.empty(shape=(n_samples, n_Xout), dtype=XP.dtype, order=self.order)\n Xout[:, 0] = 1\n Xout[:, 1:] = XP[:, n_XP - n_Xout + 1:]\n else:\n Xout = XP[:, n_XP - n_Xout:].copy()\n XP = Xout\n return XP" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.preprocessing._polynomial.SplineTransformer.__init__", + "unique_qname": "sklearn.preprocessing._polynomial.SplineTransformer.__init__", "decorators": [], "parameters": [ { @@ -150437,7 +155789,9 @@ }, { "name": "_get_base_knot_positions", + "unique_name": "_get_base_knot_positions", "qname": "sklearn.preprocessing._polynomial.SplineTransformer._get_base_knot_positions", + "unique_qname": "sklearn.preprocessing._polynomial.SplineTransformer._get_base_knot_positions", "decorators": ["staticmethod"], "parameters": [ { @@ -150489,7 +155843,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.preprocessing._polynomial.SplineTransformer.fit", + "unique_qname": "sklearn.preprocessing._polynomial.SplineTransformer.fit", "decorators": [], "parameters": [ { @@ -150541,7 +155897,9 @@ }, { "name": "get_feature_names", + "unique_name": "get_feature_names", "qname": "sklearn.preprocessing._polynomial.SplineTransformer.get_feature_names", + "unique_qname": "sklearn.preprocessing._polynomial.SplineTransformer.get_feature_names", "decorators": [ "deprecated('get_feature_names is deprecated in 1.0 and will be removed in 1.2. Please use get_feature_names_out instead.')" ], @@ -150570,12 +155928,14 @@ "results": [], "is_public": true, "description": "Return feature names for output features.", - "docstring": "Return feature names for output features.\n\nParameters\n----------\ninput_features : list of str of shape (n_features,), default=None\n String names for input features if available. By default,\n \"x0\", \"x1\", ... \"xn_features\" is used.\n\nReturns\n-------\noutput_feature_names : list of str of shape (n_output_features,)", - "source_code": "\n@deprecated('get_feature_names is deprecated in 1.0 and will be removed in 1.2. Please use get_feature_names_out instead.')\ndef get_feature_names(self, input_features=None):\n \"\"\"Return feature names for output features.\n\n Parameters\n ----------\n input_features : list of str of shape (n_features,), default=None\n String names for input features if available. By default,\n \"x0\", \"x1\", ... \"xn_features\" is used.\n\n Returns\n -------\n output_feature_names : list of str of shape (n_output_features,)\n \"\"\"\n n_splines = self.bsplines_[0].c.shape[0]\n if input_features is None:\n input_features = ['x%d' % i for i in range(self.n_features_in_)]\n feature_names = []\n for i in range(self.n_features_in_):\n for j in range(n_splines - 1 + self.include_bias):\n feature_names.append(f'{input_features[i]}_sp_{j}')\n return feature_names" + "docstring": "Return feature names for output features.\n\nParameters\n----------\ninput_features : list of str of shape (n_features,), default=None\n String names for input features if available. By default,\n \"x0\", \"x1\", ... \"xn_features\" is used.\n\nReturns\n-------\noutput_feature_names : list of str of shape (n_output_features,)\n Transformed feature names.", + "source_code": "\n@deprecated('get_feature_names is deprecated in 1.0 and will be removed in 1.2. Please use get_feature_names_out instead.')\ndef get_feature_names(self, input_features=None):\n \"\"\"Return feature names for output features.\n\n Parameters\n ----------\n input_features : list of str of shape (n_features,), default=None\n String names for input features if available. By default,\n \"x0\", \"x1\", ... \"xn_features\" is used.\n\n Returns\n -------\n output_feature_names : list of str of shape (n_output_features,)\n Transformed feature names.\n \"\"\"\n n_splines = self.bsplines_[0].c.shape[0]\n if input_features is None:\n input_features = ['x%d' % i for i in range(self.n_features_in_)]\n feature_names = []\n for i in range(self.n_features_in_):\n for j in range(n_splines - 1 + self.include_bias):\n feature_names.append(f'{input_features[i]}_sp_{j}')\n return feature_names" }, { "name": "get_feature_names_out", + "unique_name": "get_feature_names_out", "qname": "sklearn.preprocessing._polynomial.SplineTransformer.get_feature_names_out", + "unique_qname": "sklearn.preprocessing._polynomial.SplineTransformer.get_feature_names_out", "decorators": [], "parameters": [ { @@ -150607,7 +155967,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.preprocessing._polynomial.SplineTransformer.transform", + "unique_qname": "sklearn.preprocessing._polynomial.SplineTransformer.transform", "decorators": [], "parameters": [ { @@ -150639,7 +156001,9 @@ }, { "name": "configuration", + "unique_name": "configuration", "qname": "sklearn.preprocessing.setup.configuration", + "unique_qname": "sklearn.preprocessing.setup.configuration", "decorators": [], "parameters": [ { @@ -150671,7 +156035,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.random_projection.BaseRandomProjection.__init__", + "unique_qname": "sklearn.random_projection.BaseRandomProjection.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -150733,7 +156099,9 @@ }, { "name": "_make_random_matrix", + "unique_name": "_make_random_matrix", "qname": "sklearn.random_projection.BaseRandomProjection._make_random_matrix", + "unique_qname": "sklearn.random_projection.BaseRandomProjection._make_random_matrix", "decorators": ["abstractmethod"], "parameters": [ { @@ -150775,7 +156143,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.random_projection.BaseRandomProjection.fit", + "unique_qname": "sklearn.random_projection.BaseRandomProjection.fit", "decorators": [], "parameters": [ { @@ -150817,7 +156187,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.random_projection.BaseRandomProjection.transform", + "unique_qname": "sklearn.random_projection.BaseRandomProjection.transform", "decorators": [], "parameters": [ { @@ -150849,7 +156221,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.random_projection.GaussianRandomProjection.__init__", + "unique_qname": "sklearn.random_projection.GaussianRandomProjection.__init__", "decorators": [], "parameters": [ { @@ -150901,7 +156275,9 @@ }, { "name": "_make_random_matrix", + "unique_name": "_make_random_matrix", "qname": "sklearn.random_projection.GaussianRandomProjection._make_random_matrix", + "unique_qname": "sklearn.random_projection.GaussianRandomProjection._make_random_matrix", "decorators": [], "parameters": [ { @@ -150943,7 +156319,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.random_projection.SparseRandomProjection.__init__", + "unique_qname": "sklearn.random_projection.SparseRandomProjection.__init__", "decorators": [], "parameters": [ { @@ -151015,7 +156393,9 @@ }, { "name": "_make_random_matrix", + "unique_name": "_make_random_matrix", "qname": "sklearn.random_projection.SparseRandomProjection._make_random_matrix", + "unique_qname": "sklearn.random_projection.SparseRandomProjection._make_random_matrix", "decorators": [], "parameters": [ { @@ -151057,7 +156437,9 @@ }, { "name": "_check_density", + "unique_name": "_check_density", "qname": "sklearn.random_projection._check_density", + "unique_qname": "sklearn.random_projection._check_density", "decorators": [], "parameters": [ { @@ -151089,7 +156471,9 @@ }, { "name": "_check_input_size", + "unique_name": "_check_input_size", "qname": "sklearn.random_projection._check_input_size", + "unique_qname": "sklearn.random_projection._check_input_size", "decorators": [], "parameters": [ { @@ -151121,7 +156505,9 @@ }, { "name": "_gaussian_random_matrix", + "unique_name": "_gaussian_random_matrix", "qname": "sklearn.random_projection._gaussian_random_matrix", + "unique_qname": "sklearn.random_projection._gaussian_random_matrix", "decorators": [], "parameters": [ { @@ -151163,7 +156549,9 @@ }, { "name": "_sparse_random_matrix", + "unique_name": "_sparse_random_matrix", "qname": "sklearn.random_projection._sparse_random_matrix", + "unique_qname": "sklearn.random_projection._sparse_random_matrix", "decorators": [], "parameters": [ { @@ -151215,7 +156603,9 @@ }, { "name": "johnson_lindenstrauss_min_dim", + "unique_name": "johnson_lindenstrauss_min_dim", "qname": "sklearn.random_projection.johnson_lindenstrauss_min_dim", + "unique_qname": "sklearn.random_projection.johnson_lindenstrauss_min_dim", "decorators": [], "parameters": [ { @@ -151242,12 +156632,14 @@ "results": [], "is_public": true, "description": "Find a 'safe' number of components to randomly project to.\n\nThe distortion introduced by a random projection `p` only changes the distance between two points by a factor (1 +- eps) in an euclidean space with good probability. The projection `p` is an eps-embedding as defined by: (1 - eps) ||u - v||^2 < ||p(u) - p(v)||^2 < (1 + eps) ||u - v||^2 Where u and v are any rows taken from a dataset of shape (n_samples, n_features), eps is in ]0, 1[ and p is a projection by a random Gaussian N(0, 1) matrix of shape (n_components, n_features) (or a sparse Achlioptas matrix). The minimum number of components to guarantee the eps-embedding is given by: n_components >= 4 log(n_samples) / (eps^2 / 2 - eps^3 / 3) Note that the number of dimensions is independent of the original number of features but instead depends on the size of the dataset: the larger the dataset, the higher is the minimal dimensionality of an eps-embedding. Read more in the :ref:`User Guide `.", - "docstring": "Find a 'safe' number of components to randomly project to.\n\nThe distortion introduced by a random projection `p` only changes the\ndistance between two points by a factor (1 +- eps) in an euclidean space\nwith good probability. The projection `p` is an eps-embedding as defined\nby:\n\n (1 - eps) ||u - v||^2 < ||p(u) - p(v)||^2 < (1 + eps) ||u - v||^2\n\nWhere u and v are any rows taken from a dataset of shape (n_samples,\nn_features), eps is in ]0, 1[ and p is a projection by a random Gaussian\nN(0, 1) matrix of shape (n_components, n_features) (or a sparse\nAchlioptas matrix).\n\nThe minimum number of components to guarantee the eps-embedding is\ngiven by:\n\n n_components >= 4 log(n_samples) / (eps^2 / 2 - eps^3 / 3)\n\nNote that the number of dimensions is independent of the original\nnumber of features but instead depends on the size of the dataset:\nthe larger the dataset, the higher is the minimal dimensionality of\nan eps-embedding.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\nn_samples : int or array-like of int\n Number of samples that should be a integer greater than 0. If an array\n is given, it will compute a safe number of components array-wise.\n\neps : float or ndarray of shape (n_components,), dtype=float, default=0.1\n Maximum distortion rate in the range (0,1 ) as defined by the\n Johnson-Lindenstrauss lemma. If an array is given, it will compute a\n safe number of components array-wise.\n\nReturns\n-------\nn_components : int or ndarray of int\n The minimal number of components to guarantee with good probability\n an eps-embedding with n_samples.\n\nExamples\n--------\n\n>>> johnson_lindenstrauss_min_dim(1e6, eps=0.5)\n663\n\n>>> johnson_lindenstrauss_min_dim(1e6, eps=[0.5, 0.1, 0.01])\narray([ 663, 11841, 1112658])\n\n>>> johnson_lindenstrauss_min_dim([1e4, 1e5, 1e6], eps=0.1)\narray([ 7894, 9868, 11841])\n\nReferences\n----------\n\n.. [1] https://en.wikipedia.org/wiki/Johnson%E2%80%93Lindenstrauss_lemma\n\n.. [2] Sanjoy Dasgupta and Anupam Gupta, 1999,\n \"An elementary proof of the Johnson-Lindenstrauss Lemma.\"\n http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.45.3654", - "source_code": "\ndef johnson_lindenstrauss_min_dim(n_samples, *, eps=0.1):\n \"\"\"Find a 'safe' number of components to randomly project to.\n\n The distortion introduced by a random projection `p` only changes the\n distance between two points by a factor (1 +- eps) in an euclidean space\n with good probability. The projection `p` is an eps-embedding as defined\n by:\n\n (1 - eps) ||u - v||^2 < ||p(u) - p(v)||^2 < (1 + eps) ||u - v||^2\n\n Where u and v are any rows taken from a dataset of shape (n_samples,\n n_features), eps is in ]0, 1[ and p is a projection by a random Gaussian\n N(0, 1) matrix of shape (n_components, n_features) (or a sparse\n Achlioptas matrix).\n\n The minimum number of components to guarantee the eps-embedding is\n given by:\n\n n_components >= 4 log(n_samples) / (eps^2 / 2 - eps^3 / 3)\n\n Note that the number of dimensions is independent of the original\n number of features but instead depends on the size of the dataset:\n the larger the dataset, the higher is the minimal dimensionality of\n an eps-embedding.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_samples : int or array-like of int\n Number of samples that should be a integer greater than 0. If an array\n is given, it will compute a safe number of components array-wise.\n\n eps : float or ndarray of shape (n_components,), dtype=float, default=0.1\n Maximum distortion rate in the range (0,1 ) as defined by the\n Johnson-Lindenstrauss lemma. If an array is given, it will compute a\n safe number of components array-wise.\n\n Returns\n -------\n n_components : int or ndarray of int\n The minimal number of components to guarantee with good probability\n an eps-embedding with n_samples.\n\n Examples\n --------\n\n >>> johnson_lindenstrauss_min_dim(1e6, eps=0.5)\n 663\n\n >>> johnson_lindenstrauss_min_dim(1e6, eps=[0.5, 0.1, 0.01])\n array([ 663, 11841, 1112658])\n\n >>> johnson_lindenstrauss_min_dim([1e4, 1e5, 1e6], eps=0.1)\n array([ 7894, 9868, 11841])\n\n References\n ----------\n\n .. [1] https://en.wikipedia.org/wiki/Johnson%E2%80%93Lindenstrauss_lemma\n\n .. [2] Sanjoy Dasgupta and Anupam Gupta, 1999,\n \"An elementary proof of the Johnson-Lindenstrauss Lemma.\"\n http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.45.3654\n\n \"\"\"\n eps = np.asarray(eps)\n n_samples = np.asarray(n_samples)\n if np.any(eps <= 0.0) or np.any(eps >= 1):\n raise ValueError('The JL bound is defined for eps in ]0, 1[, got %r' % eps)\n if np.any(n_samples) <= 0:\n raise ValueError('The JL bound is defined for n_samples greater than zero, got %r' % n_samples)\n denominator = eps**2 / 2 - eps**3 / 3\n return (4 * np.log(n_samples) / denominator).astype(np.int64)" + "docstring": "Find a 'safe' number of components to randomly project to.\n\nThe distortion introduced by a random projection `p` only changes the\ndistance between two points by a factor (1 +- eps) in an euclidean space\nwith good probability. The projection `p` is an eps-embedding as defined\nby:\n\n (1 - eps) ||u - v||^2 < ||p(u) - p(v)||^2 < (1 + eps) ||u - v||^2\n\nWhere u and v are any rows taken from a dataset of shape (n_samples,\nn_features), eps is in ]0, 1[ and p is a projection by a random Gaussian\nN(0, 1) matrix of shape (n_components, n_features) (or a sparse\nAchlioptas matrix).\n\nThe minimum number of components to guarantee the eps-embedding is\ngiven by:\n\n n_components >= 4 log(n_samples) / (eps^2 / 2 - eps^3 / 3)\n\nNote that the number of dimensions is independent of the original\nnumber of features but instead depends on the size of the dataset:\nthe larger the dataset, the higher is the minimal dimensionality of\nan eps-embedding.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\nn_samples : int or array-like of int\n Number of samples that should be a integer greater than 0. If an array\n is given, it will compute a safe number of components array-wise.\n\neps : float or ndarray of shape (n_components,), dtype=float, default=0.1\n Maximum distortion rate in the range (0,1 ) as defined by the\n Johnson-Lindenstrauss lemma. If an array is given, it will compute a\n safe number of components array-wise.\n\nReturns\n-------\nn_components : int or ndarray of int\n The minimal number of components to guarantee with good probability\n an eps-embedding with n_samples.\n\nExamples\n--------\n>>> from sklearn.random_projection import johnson_lindenstrauss_min_dim\n>>> johnson_lindenstrauss_min_dim(1e6, eps=0.5)\n663\n\n>>> johnson_lindenstrauss_min_dim(1e6, eps=[0.5, 0.1, 0.01])\narray([ 663, 11841, 1112658])\n\n>>> johnson_lindenstrauss_min_dim([1e4, 1e5, 1e6], eps=0.1)\narray([ 7894, 9868, 11841])\n\nReferences\n----------\n\n.. [1] https://en.wikipedia.org/wiki/Johnson%E2%80%93Lindenstrauss_lemma\n\n.. [2] Sanjoy Dasgupta and Anupam Gupta, 1999,\n \"An elementary proof of the Johnson-Lindenstrauss Lemma.\"\n http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.45.3654", + "source_code": "\ndef johnson_lindenstrauss_min_dim(n_samples, *, eps=0.1):\n \"\"\"Find a 'safe' number of components to randomly project to.\n\n The distortion introduced by a random projection `p` only changes the\n distance between two points by a factor (1 +- eps) in an euclidean space\n with good probability. The projection `p` is an eps-embedding as defined\n by:\n\n (1 - eps) ||u - v||^2 < ||p(u) - p(v)||^2 < (1 + eps) ||u - v||^2\n\n Where u and v are any rows taken from a dataset of shape (n_samples,\n n_features), eps is in ]0, 1[ and p is a projection by a random Gaussian\n N(0, 1) matrix of shape (n_components, n_features) (or a sparse\n Achlioptas matrix).\n\n The minimum number of components to guarantee the eps-embedding is\n given by:\n\n n_components >= 4 log(n_samples) / (eps^2 / 2 - eps^3 / 3)\n\n Note that the number of dimensions is independent of the original\n number of features but instead depends on the size of the dataset:\n the larger the dataset, the higher is the minimal dimensionality of\n an eps-embedding.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n n_samples : int or array-like of int\n Number of samples that should be a integer greater than 0. If an array\n is given, it will compute a safe number of components array-wise.\n\n eps : float or ndarray of shape (n_components,), dtype=float, default=0.1\n Maximum distortion rate in the range (0,1 ) as defined by the\n Johnson-Lindenstrauss lemma. If an array is given, it will compute a\n safe number of components array-wise.\n\n Returns\n -------\n n_components : int or ndarray of int\n The minimal number of components to guarantee with good probability\n an eps-embedding with n_samples.\n\n Examples\n --------\n >>> from sklearn.random_projection import johnson_lindenstrauss_min_dim\n >>> johnson_lindenstrauss_min_dim(1e6, eps=0.5)\n 663\n\n >>> johnson_lindenstrauss_min_dim(1e6, eps=[0.5, 0.1, 0.01])\n array([ 663, 11841, 1112658])\n\n >>> johnson_lindenstrauss_min_dim([1e4, 1e5, 1e6], eps=0.1)\n array([ 7894, 9868, 11841])\n\n References\n ----------\n\n .. [1] https://en.wikipedia.org/wiki/Johnson%E2%80%93Lindenstrauss_lemma\n\n .. [2] Sanjoy Dasgupta and Anupam Gupta, 1999,\n \"An elementary proof of the Johnson-Lindenstrauss Lemma.\"\n http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.45.3654\n\n \"\"\"\n eps = np.asarray(eps)\n n_samples = np.asarray(n_samples)\n if np.any(eps <= 0.0) or np.any(eps >= 1):\n raise ValueError('The JL bound is defined for eps in ]0, 1[, got %r' % eps)\n if np.any(n_samples) <= 0:\n raise ValueError('The JL bound is defined for n_samples greater than zero, got %r' % n_samples)\n denominator = eps**2 / 2 - eps**3 / 3\n return (4 * np.log(n_samples) / denominator).astype(np.int64)" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.semi_supervised._label_propagation.BaseLabelPropagation.__init__", + "unique_qname": "sklearn.semi_supervised._label_propagation.BaseLabelPropagation.__init__", "decorators": [], "parameters": [ { @@ -151339,7 +156731,9 @@ }, { "name": "_build_graph", + "unique_name": "_build_graph", "qname": "sklearn.semi_supervised._label_propagation.BaseLabelPropagation._build_graph", + "unique_qname": "sklearn.semi_supervised._label_propagation.BaseLabelPropagation._build_graph", "decorators": ["abstractmethod"], "parameters": [ { @@ -151361,7 +156755,9 @@ }, { "name": "_get_kernel", + "unique_name": "_get_kernel", "qname": "sklearn.semi_supervised._label_propagation.BaseLabelPropagation._get_kernel", + "unique_qname": "sklearn.semi_supervised._label_propagation.BaseLabelPropagation._get_kernel", "decorators": [], "parameters": [ { @@ -151403,7 +156799,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.semi_supervised._label_propagation.BaseLabelPropagation.fit", + "unique_qname": "sklearn.semi_supervised._label_propagation.BaseLabelPropagation.fit", "decorators": [], "parameters": [ { @@ -151423,7 +156821,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "array-like of shape (n_samples, n_features)", - "description": "A matrix of shape (n_samples, n_samples) will be created from this." + "description": "Training data, where `n_samples` is the number of samples\nand `n_features` is the number of features." } }, { @@ -151433,19 +156831,21 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "array-like of shape (n_samples,)", - "description": "`n_labeled_samples` (unlabeled points are marked as -1)\nAll unlabeled samples will be transductively assigned labels." + "description": "Target class values with unlabeled points marked as -1.\nAll unlabeled samples will be transductively assigned labels\ninternally." } } ], "results": [], "is_public": false, - "description": "Fit a semi-supervised label propagation model based\n\nAll the input data is provided matrix X (labeled and unlabeled) and corresponding label matrix y with a dedicated marker value for unlabeled samples.", - "docstring": "Fit a semi-supervised label propagation model based\n\nAll the input data is provided matrix X (labeled and unlabeled)\nand corresponding label matrix y with a dedicated marker value for\nunlabeled samples.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n A matrix of shape (n_samples, n_samples) will be created from this.\n\ny : array-like of shape (n_samples,)\n `n_labeled_samples` (unlabeled points are marked as -1)\n All unlabeled samples will be transductively assigned labels.\n\nReturns\n-------\nself : object", - "source_code": "\ndef fit(self, X, y):\n \"\"\"Fit a semi-supervised label propagation model based\n\n All the input data is provided matrix X (labeled and unlabeled)\n and corresponding label matrix y with a dedicated marker value for\n unlabeled samples.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n A matrix of shape (n_samples, n_samples) will be created from this.\n\n y : array-like of shape (n_samples,)\n `n_labeled_samples` (unlabeled points are marked as -1)\n All unlabeled samples will be transductively assigned labels.\n\n Returns\n -------\n self : object\n \"\"\"\n (X, y) = self._validate_data(X, y)\n self.X_ = X\n check_classification_targets(y)\n graph_matrix = self._build_graph()\n classes = np.unique(y)\n classes = classes[classes != -1]\n self.classes_ = classes\n (n_samples, n_classes) = (len(y), len(classes))\n alpha = self.alpha\n if self._variant == 'spreading' and (alpha is None or alpha <= 0.0 or alpha >= 1.0):\n raise ValueError('alpha=%s is invalid: it must be inside the open interval (0, 1)' % alpha)\n y = np.asarray(y)\n unlabeled = y == -1\n self.label_distributions_ = np.zeros((n_samples, n_classes))\n for label in classes:\n self.label_distributions_[y == label, classes == label] = 1\n y_static = np.copy(self.label_distributions_)\n if self._variant == 'propagation':\n y_static[unlabeled] = 0\n else:\n y_static *= 1 - alpha\n l_previous = np.zeros((self.X_.shape[0], n_classes))\n unlabeled = unlabeled[:, np.newaxis]\n if sparse.isspmatrix(graph_matrix):\n graph_matrix = graph_matrix.tocsr()\n for self.n_iter_ in range(self.max_iter):\n if np.abs(self.label_distributions_ - l_previous).sum() < self.tol:\n break\n l_previous = self.label_distributions_\n self.label_distributions_ = safe_sparse_dot(graph_matrix, self.label_distributions_)\n if self._variant == 'propagation':\n normalizer = np.sum(self.label_distributions_, axis=1)[:, np.newaxis]\n normalizer[normalizer == 0] = 1\n self.label_distributions_ /= normalizer\n self.label_distributions_ = np.where(unlabeled, self.label_distributions_, y_static)\n else:\n self.label_distributions_ = np.multiply(alpha, self.label_distributions_) + y_static\n else:\n warnings.warn('max_iter=%d was reached without convergence.' % self.max_iter, category=ConvergenceWarning)\n self.n_iter_ += 1\n normalizer = np.sum(self.label_distributions_, axis=1)[:, np.newaxis]\n normalizer[normalizer == 0] = 1\n self.label_distributions_ /= normalizer\n transduction = self.classes_[np.argmax(self.label_distributions_, axis=1)]\n self.transduction_ = transduction.ravel()\n return self" + "description": "Fit a semi-supervised label propagation model to X.\n\nThe input samples (labeled and unlabeled) are provided by matrix X, and target labels are provided by matrix y. We conventionally apply the label -1 to unlabeled samples in matrix y in a semi-supervised classification.", + "docstring": "Fit a semi-supervised label propagation model to X.\n\nThe input samples (labeled and unlabeled) are provided by matrix X,\nand target labels are provided by matrix y. We conventionally apply the\nlabel -1 to unlabeled samples in matrix y in a semi-supervised\nclassification.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Training data, where `n_samples` is the number of samples\n and `n_features` is the number of features.\n\ny : array-like of shape (n_samples,)\n Target class values with unlabeled points marked as -1.\n All unlabeled samples will be transductively assigned labels\n internally.\n\nReturns\n-------\nself : object\n Returns the instance itself.", + "source_code": "\ndef fit(self, X, y):\n \"\"\"Fit a semi-supervised label propagation model to X.\n\n The input samples (labeled and unlabeled) are provided by matrix X,\n and target labels are provided by matrix y. We conventionally apply the\n label -1 to unlabeled samples in matrix y in a semi-supervised\n classification.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training data, where `n_samples` is the number of samples\n and `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target class values with unlabeled points marked as -1.\n All unlabeled samples will be transductively assigned labels\n internally.\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n (X, y) = self._validate_data(X, y)\n self.X_ = X\n check_classification_targets(y)\n graph_matrix = self._build_graph()\n classes = np.unique(y)\n classes = classes[classes != -1]\n self.classes_ = classes\n (n_samples, n_classes) = (len(y), len(classes))\n alpha = self.alpha\n if self._variant == 'spreading' and (alpha is None or alpha <= 0.0 or alpha >= 1.0):\n raise ValueError('alpha=%s is invalid: it must be inside the open interval (0, 1)' % alpha)\n y = np.asarray(y)\n unlabeled = y == -1\n self.label_distributions_ = np.zeros((n_samples, n_classes))\n for label in classes:\n self.label_distributions_[y == label, classes == label] = 1\n y_static = np.copy(self.label_distributions_)\n if self._variant == 'propagation':\n y_static[unlabeled] = 0\n else:\n y_static *= 1 - alpha\n l_previous = np.zeros((self.X_.shape[0], n_classes))\n unlabeled = unlabeled[:, np.newaxis]\n if sparse.isspmatrix(graph_matrix):\n graph_matrix = graph_matrix.tocsr()\n for self.n_iter_ in range(self.max_iter):\n if np.abs(self.label_distributions_ - l_previous).sum() < self.tol:\n break\n l_previous = self.label_distributions_\n self.label_distributions_ = safe_sparse_dot(graph_matrix, self.label_distributions_)\n if self._variant == 'propagation':\n normalizer = np.sum(self.label_distributions_, axis=1)[:, np.newaxis]\n normalizer[normalizer == 0] = 1\n self.label_distributions_ /= normalizer\n self.label_distributions_ = np.where(unlabeled, self.label_distributions_, y_static)\n else:\n self.label_distributions_ = np.multiply(alpha, self.label_distributions_) + y_static\n else:\n warnings.warn('max_iter=%d was reached without convergence.' % self.max_iter, category=ConvergenceWarning)\n self.n_iter_ += 1\n normalizer = np.sum(self.label_distributions_, axis=1)[:, np.newaxis]\n normalizer[normalizer == 0] = 1\n self.label_distributions_ /= normalizer\n transduction = self.classes_[np.argmax(self.label_distributions_, axis=1)]\n self.transduction_ = transduction.ravel()\n return self" }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.semi_supervised._label_propagation.BaseLabelPropagation.predict", + "unique_qname": "sklearn.semi_supervised._label_propagation.BaseLabelPropagation.predict", "decorators": [], "parameters": [ { @@ -151471,13 +156871,15 @@ ], "results": [], "is_public": false, - "description": "Performs inductive inference across the model.", - "docstring": "Performs inductive inference across the model.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n The data matrix.\n\nReturns\n-------\ny : ndarray of shape (n_samples,)\n Predictions for input data.", - "source_code": "\ndef predict(self, X):\n \"\"\"Performs inductive inference across the model.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data matrix.\n\n Returns\n -------\n y : ndarray of shape (n_samples,)\n Predictions for input data.\n \"\"\"\n probas = self.predict_proba(X)\n return self.classes_[np.argmax(probas, axis=1)].ravel()" + "description": "Perform inductive inference across the model.", + "docstring": "Perform inductive inference across the model.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n The data matrix.\n\nReturns\n-------\ny : ndarray of shape (n_samples,)\n Predictions for input data.", + "source_code": "\ndef predict(self, X):\n \"\"\"Perform inductive inference across the model.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n The data matrix.\n\n Returns\n -------\n y : ndarray of shape (n_samples,)\n Predictions for input data.\n \"\"\"\n probas = self.predict_proba(X)\n return self.classes_[np.argmax(probas, axis=1)].ravel()" }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.semi_supervised._label_propagation.BaseLabelPropagation.predict_proba", + "unique_qname": "sklearn.semi_supervised._label_propagation.BaseLabelPropagation.predict_proba", "decorators": [], "parameters": [ { @@ -151509,7 +156911,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.semi_supervised._label_propagation.LabelPropagation.__init__", + "unique_qname": "sklearn.semi_supervised._label_propagation.LabelPropagation.__init__", "decorators": [], "parameters": [ { @@ -151591,7 +156995,9 @@ }, { "name": "_build_graph", + "unique_name": "_build_graph", "qname": "sklearn.semi_supervised._label_propagation.LabelPropagation._build_graph", + "unique_qname": "sklearn.semi_supervised._label_propagation.LabelPropagation._build_graph", "decorators": [], "parameters": [ { @@ -151613,7 +157019,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.semi_supervised._label_propagation.LabelPropagation.fit", + "unique_qname": "sklearn.semi_supervised._label_propagation.LabelPropagation.fit", "decorators": [], "parameters": [ { @@ -151632,8 +157040,8 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "", - "description": "" + "type": "array-like of shape (n_samples, n_features)", + "description": "Training data, where `n_samples` is the number of samples\nand `n_features` is the number of features." } }, { @@ -151642,20 +157050,22 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "", - "description": "" + "type": "array-like of shape (n_samples,)", + "description": "Target class values with unlabeled points marked as -1.\nAll unlabeled samples will be transductively assigned labels\ninternally." } } ], "results": [], "is_public": true, - "description": "", - "docstring": "", - "source_code": "\ndef fit(self, X, y):\n return super().fit(X, y)" + "description": "Fit a semi-supervised label propagation model to X.", + "docstring": "Fit a semi-supervised label propagation model to X.\n\nParameters\n----------\nX : array-like of shape (n_samples, n_features)\n Training data, where `n_samples` is the number of samples\n and `n_features` is the number of features.\n\ny : array-like of shape (n_samples,)\n Target class values with unlabeled points marked as -1.\n All unlabeled samples will be transductively assigned labels\n internally.\n\nReturns\n-------\nself : object\n Returns the instance itself.", + "source_code": "\ndef fit(self, X, y):\n \"\"\"Fit a semi-supervised label propagation model to X.\n\n Parameters\n ----------\n X : array-like of shape (n_samples, n_features)\n Training data, where `n_samples` is the number of samples\n and `n_features` is the number of features.\n\n y : array-like of shape (n_samples,)\n Target class values with unlabeled points marked as -1.\n All unlabeled samples will be transductively assigned labels\n internally.\n\n Returns\n -------\n self : object\n Returns the instance itself.\n \"\"\"\n return super().fit(X, y)" }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.semi_supervised._label_propagation.LabelSpreading.__init__", + "unique_qname": "sklearn.semi_supervised._label_propagation.LabelSpreading.__init__", "decorators": [], "parameters": [ { @@ -151747,7 +157157,9 @@ }, { "name": "_build_graph", + "unique_name": "_build_graph", "qname": "sklearn.semi_supervised._label_propagation.LabelSpreading._build_graph", + "unique_qname": "sklearn.semi_supervised._label_propagation.LabelSpreading._build_graph", "decorators": [], "parameters": [ { @@ -151769,7 +157181,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.semi_supervised._self_training.SelfTrainingClassifier.__init__", + "unique_qname": "sklearn.semi_supervised._self_training.SelfTrainingClassifier.__init__", "decorators": [], "parameters": [ { @@ -151789,7 +157203,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "estimator object", - "description": "An estimator object implementing ``fit`` and ``predict_proba``.\nInvoking the ``fit`` method will fit a clone of the passed estimator,\nwhich will be stored in the ``base_estimator_`` attribute." + "description": "An estimator object implementing `fit` and `predict_proba`.\nInvoking the `fit` method will fit a clone of the passed estimator,\nwhich will be stored in the `base_estimator_` attribute." } }, { @@ -151799,7 +157213,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "float, default=0.75", - "description": "The decision threshold for use with `criterion='threshold'`.\nShould be in [0, 1). When using the 'threshold' criterion, a\n:ref:`well calibrated classifier ` should be used." + "description": "The decision threshold for use with `criterion='threshold'`.\nShould be in [0, 1). When using the `'threshold'` criterion, a\n:ref:`well calibrated classifier ` should be used." } }, { @@ -151809,7 +157223,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "{'threshold', 'k_best'}, default='threshold'", - "description": "The selection criterion used to select which labels to add to the\ntraining set. If 'threshold', pseudo-labels with prediction\nprobabilities above `threshold` are added to the dataset. If 'k_best',\nthe `k_best` pseudo-labels with highest prediction probabilities are\nadded to the dataset. When using the 'threshold' criterion, a\n:ref:`well calibrated classifier ` should be used." + "description": "The selection criterion used to select which labels to add to the\ntraining set. If `'threshold'`, pseudo-labels with prediction\nprobabilities above `threshold` are added to the dataset. If `'k_best'`,\nthe `k_best` pseudo-labels with highest prediction probabilities are\nadded to the dataset. When using the 'threshold' criterion, a\n:ref:`well calibrated classifier ` should be used." } }, { @@ -151819,7 +157233,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "int, default=10", - "description": "The amount of samples to add in each iteration. Only used when\n`criterion` is k_best'." + "description": "The amount of samples to add in each iteration. Only used when\n`criterion='k_best'`." } }, { @@ -151829,7 +157243,7 @@ "assigned_by": "POSITION_OR_NAME", "docstring": { "type": "int or None, default=10", - "description": "Maximum number of iterations allowed. Should be greater than or equal\nto 0. If it is ``None``, the classifier will continue to predict labels\nuntil no new pseudo-labels are added, or all unlabeled samples have\nbeen labeled." + "description": "Maximum number of iterations allowed. Should be greater than or equal\nto 0. If it is `None`, the classifier will continue to predict labels\nuntil no new pseudo-labels are added, or all unlabeled samples have\nbeen labeled." } }, { @@ -151851,7 +157265,9 @@ }, { "name": "decision_function", + "unique_name": "decision_function", "qname": "sklearn.semi_supervised._self_training.SelfTrainingClassifier.decision_function", + "unique_qname": "sklearn.semi_supervised._self_training.SelfTrainingClassifier.decision_function", "decorators": ["if_delegate_has_method(delegate='base_estimator')"], "parameters": [ { @@ -151877,13 +157293,15 @@ ], "results": [], "is_public": true, - "description": "Calls decision function of the `base_estimator`.", - "docstring": "Calls decision function of the `base_estimator`.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\nReturns\n-------\ny : ndarray of shape (n_samples, n_features)\n Result of the decision function of the `base_estimator`.", - "source_code": "\n@if_delegate_has_method(delegate='base_estimator')\ndef decision_function(self, X):\n \"\"\"Calls decision function of the `base_estimator`.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\n Returns\n -------\n y : ndarray of shape (n_samples, n_features)\n Result of the decision function of the `base_estimator`.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse=True, force_all_finite=False, reset=False)\n return self.base_estimator_.decision_function(X)" + "description": "Call decision function of the `base_estimator`.", + "docstring": "Call decision function of the `base_estimator`.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\nReturns\n-------\ny : ndarray of shape (n_samples, n_features)\n Result of the decision function of the `base_estimator`.", + "source_code": "\n@if_delegate_has_method(delegate='base_estimator')\ndef decision_function(self, X):\n \"\"\"Call decision function of the `base_estimator`.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\n Returns\n -------\n y : ndarray of shape (n_samples, n_features)\n Result of the decision function of the `base_estimator`.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse=True, force_all_finite=False, reset=False)\n return self.base_estimator_.decision_function(X)" }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.semi_supervised._self_training.SelfTrainingClassifier.fit", + "unique_qname": "sklearn.semi_supervised._self_training.SelfTrainingClassifier.fit", "decorators": [], "parameters": [ { @@ -151919,13 +157337,15 @@ ], "results": [], "is_public": true, - "description": "Fits this ``SelfTrainingClassifier`` to a dataset.", - "docstring": "Fits this ``SelfTrainingClassifier`` to a dataset.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\ny : {array-like, sparse matrix} of shape (n_samples,)\n Array representing the labels. Unlabeled samples should have the\n label -1.\n\nReturns\n-------\nself : object\n Returns an instance of self.", - "source_code": "\ndef fit(self, X, y):\n \"\"\"\n Fits this ``SelfTrainingClassifier`` to a dataset.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\n y : {array-like, sparse matrix} of shape (n_samples,)\n Array representing the labels. Unlabeled samples should have the\n label -1.\n\n Returns\n -------\n self : object\n Returns an instance of self.\n \"\"\"\n (X, y) = self._validate_data(X, y, accept_sparse=['csr', 'csc', 'lil', 'dok'], force_all_finite=False)\n if self.base_estimator is None:\n raise ValueError('base_estimator cannot be None!')\n self.base_estimator_ = clone(self.base_estimator)\n if self.max_iter is not None and self.max_iter < 0:\n raise ValueError(f'max_iter must be >= 0 or None, got {self.max_iter}')\n if not 0 <= self.threshold < 1:\n raise ValueError(f'threshold must be in [0,1), got {self.threshold}')\n if self.criterion not in ['threshold', 'k_best']:\n raise ValueError(f\"criterion must be either 'threshold' or 'k_best', got {self.criterion}.\")\n if y.dtype.kind in ['U', 'S']:\n raise ValueError('y has dtype string. If you wish to predict on string targets, use dtype object, and use -1 as the label for unlabeled samples.')\n has_label = y != -1\n if np.all(has_label):\n warnings.warn('y contains no unlabeled samples', UserWarning)\n if self.criterion == 'k_best' and self.k_best > X.shape[0] - np.sum(has_label):\n warnings.warn('k_best is larger than the amount of unlabeled samples. All unlabeled samples will be labeled in the first iteration', UserWarning)\n self.transduction_ = np.copy(y)\n self.labeled_iter_ = np.full_like(y, -1)\n self.labeled_iter_[has_label] = 0\n self.n_iter_ = 0\n while not np.all(has_label) and (self.max_iter is None or self.n_iter_ < self.max_iter):\n self.n_iter_ += 1\n self.base_estimator_.fit(X[safe_mask(X, has_label)], self.transduction_[has_label])\n _validate_estimator(self.base_estimator_)\n prob = self.base_estimator_.predict_proba(X[safe_mask(X, ~has_label)])\n pred = self.base_estimator_.classes_[np.argmax(prob, axis=1)]\n max_proba = np.max(prob, axis=1)\n if self.criterion == 'threshold':\n selected = max_proba > self.threshold\n else:\n n_to_select = min(self.k_best, max_proba.shape[0])\n if n_to_select == max_proba.shape[0]:\n selected = np.ones_like(max_proba, dtype=bool)\n else:\n selected = np.argpartition(-max_proba, n_to_select)[:n_to_select]\n selected_full = np.nonzero(~has_label)[0][selected]\n self.transduction_[selected_full] = pred[selected]\n has_label[selected_full] = True\n self.labeled_iter_[selected_full] = self.n_iter_\n if selected_full.shape[0] == 0:\n self.termination_condition_ = 'no_change'\n break\n if self.verbose:\n print(f'End of iteration {self.n_iter_}, added {selected_full.shape[0]} new labels.')\n if self.n_iter_ == self.max_iter:\n self.termination_condition_ = 'max_iter'\n if np.all(has_label):\n self.termination_condition_ = 'all_labeled'\n self.base_estimator_.fit(X[safe_mask(X, has_label)], self.transduction_[has_label])\n self.classes_ = self.base_estimator_.classes_\n return self" + "description": "Fit self-training classifier using `X`, `y` as training data.", + "docstring": "Fit self-training classifier using `X`, `y` as training data.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\ny : {array-like, sparse matrix} of shape (n_samples,)\n Array representing the labels. Unlabeled samples should have the\n label -1.\n\nReturns\n-------\nself : object\n Fitted estimator.", + "source_code": "\ndef fit(self, X, y):\n \"\"\"\n Fit self-training classifier using `X`, `y` as training data.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\n y : {array-like, sparse matrix} of shape (n_samples,)\n Array representing the labels. Unlabeled samples should have the\n label -1.\n\n Returns\n -------\n self : object\n Fitted estimator.\n \"\"\"\n (X, y) = self._validate_data(X, y, accept_sparse=['csr', 'csc', 'lil', 'dok'], force_all_finite=False)\n if self.base_estimator is None:\n raise ValueError('base_estimator cannot be None!')\n self.base_estimator_ = clone(self.base_estimator)\n if self.max_iter is not None and self.max_iter < 0:\n raise ValueError(f'max_iter must be >= 0 or None, got {self.max_iter}')\n if not 0 <= self.threshold < 1:\n raise ValueError(f'threshold must be in [0,1), got {self.threshold}')\n if self.criterion not in ['threshold', 'k_best']:\n raise ValueError(f\"criterion must be either 'threshold' or 'k_best', got {self.criterion}.\")\n if y.dtype.kind in ['U', 'S']:\n raise ValueError('y has dtype string. If you wish to predict on string targets, use dtype object, and use -1 as the label for unlabeled samples.')\n has_label = y != -1\n if np.all(has_label):\n warnings.warn('y contains no unlabeled samples', UserWarning)\n if self.criterion == 'k_best' and self.k_best > X.shape[0] - np.sum(has_label):\n warnings.warn('k_best is larger than the amount of unlabeled samples. All unlabeled samples will be labeled in the first iteration', UserWarning)\n self.transduction_ = np.copy(y)\n self.labeled_iter_ = np.full_like(y, -1)\n self.labeled_iter_[has_label] = 0\n self.n_iter_ = 0\n while not np.all(has_label) and (self.max_iter is None or self.n_iter_ < self.max_iter):\n self.n_iter_ += 1\n self.base_estimator_.fit(X[safe_mask(X, has_label)], self.transduction_[has_label])\n _validate_estimator(self.base_estimator_)\n prob = self.base_estimator_.predict_proba(X[safe_mask(X, ~has_label)])\n pred = self.base_estimator_.classes_[np.argmax(prob, axis=1)]\n max_proba = np.max(prob, axis=1)\n if self.criterion == 'threshold':\n selected = max_proba > self.threshold\n else:\n n_to_select = min(self.k_best, max_proba.shape[0])\n if n_to_select == max_proba.shape[0]:\n selected = np.ones_like(max_proba, dtype=bool)\n else:\n selected = np.argpartition(-max_proba, n_to_select)[:n_to_select]\n selected_full = np.nonzero(~has_label)[0][selected]\n self.transduction_[selected_full] = pred[selected]\n has_label[selected_full] = True\n self.labeled_iter_[selected_full] = self.n_iter_\n if selected_full.shape[0] == 0:\n self.termination_condition_ = 'no_change'\n break\n if self.verbose:\n print(f'End of iteration {self.n_iter_}, added {selected_full.shape[0]} new labels.')\n if self.n_iter_ == self.max_iter:\n self.termination_condition_ = 'max_iter'\n if np.all(has_label):\n self.termination_condition_ = 'all_labeled'\n self.base_estimator_.fit(X[safe_mask(X, has_label)], self.transduction_[has_label])\n self.classes_ = self.base_estimator_.classes_\n return self" }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.semi_supervised._self_training.SelfTrainingClassifier.predict", + "unique_qname": "sklearn.semi_supervised._self_training.SelfTrainingClassifier.predict", "decorators": ["if_delegate_has_method(delegate='base_estimator')"], "parameters": [ { @@ -151951,13 +157371,15 @@ ], "results": [], "is_public": true, - "description": "Predict the classes of X.", - "docstring": "Predict the classes of X.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\nReturns\n-------\ny : ndarray of shape (n_samples,)\n Array with predicted labels.", - "source_code": "\n@if_delegate_has_method(delegate='base_estimator')\ndef predict(self, X):\n \"\"\"Predict the classes of X.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\n Returns\n -------\n y : ndarray of shape (n_samples,)\n Array with predicted labels.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse=True, force_all_finite=False, reset=False)\n return self.base_estimator_.predict(X)" + "description": "Predict the classes of `X`.", + "docstring": "Predict the classes of `X`.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\nReturns\n-------\ny : ndarray of shape (n_samples,)\n Array with predicted labels.", + "source_code": "\n@if_delegate_has_method(delegate='base_estimator')\ndef predict(self, X):\n \"\"\"Predict the classes of `X`.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\n Returns\n -------\n y : ndarray of shape (n_samples,)\n Array with predicted labels.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse=True, force_all_finite=False, reset=False)\n return self.base_estimator_.predict(X)" }, { "name": "predict_log_proba", + "unique_name": "predict_log_proba", "qname": "sklearn.semi_supervised._self_training.SelfTrainingClassifier.predict_log_proba", + "unique_qname": "sklearn.semi_supervised._self_training.SelfTrainingClassifier.predict_log_proba", "decorators": ["if_delegate_has_method(delegate='base_estimator')"], "parameters": [ { @@ -151989,7 +157411,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.semi_supervised._self_training.SelfTrainingClassifier.predict_proba", + "unique_qname": "sklearn.semi_supervised._self_training.SelfTrainingClassifier.predict_proba", "decorators": [], "parameters": [ { @@ -152021,7 +157445,9 @@ }, { "name": "score", + "unique_name": "score", "qname": "sklearn.semi_supervised._self_training.SelfTrainingClassifier.score", + "unique_qname": "sklearn.semi_supervised._self_training.SelfTrainingClassifier.score", "decorators": ["if_delegate_has_method(delegate='base_estimator')"], "parameters": [ { @@ -152057,13 +157483,15 @@ ], "results": [], "is_public": true, - "description": "Calls score on the `base_estimator`.", - "docstring": "Calls score on the `base_estimator`.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\ny : array-like of shape (n_samples,)\n Array representing the labels.\n\nReturns\n-------\nscore : float\n Result of calling score on the `base_estimator`.", - "source_code": "\n@if_delegate_has_method(delegate='base_estimator')\ndef score(self, X, y):\n \"\"\"Calls score on the `base_estimator`.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\n y : array-like of shape (n_samples,)\n Array representing the labels.\n\n Returns\n -------\n score : float\n Result of calling score on the `base_estimator`.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse=True, force_all_finite=False, reset=False)\n return self.base_estimator_.score(X, y)" + "description": "Call score on the `base_estimator`.", + "docstring": "Call score on the `base_estimator`.\n\nParameters\n----------\nX : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\ny : array-like of shape (n_samples,)\n Array representing the labels.\n\nReturns\n-------\nscore : float\n Result of calling score on the `base_estimator`.", + "source_code": "\n@if_delegate_has_method(delegate='base_estimator')\ndef score(self, X, y):\n \"\"\"Call score on the `base_estimator`.\n\n Parameters\n ----------\n X : {array-like, sparse matrix} of shape (n_samples, n_features)\n Array representing the data.\n\n y : array-like of shape (n_samples,)\n Array representing the labels.\n\n Returns\n -------\n score : float\n Result of calling score on the `base_estimator`.\n \"\"\"\n check_is_fitted(self)\n X = self._validate_data(X, accept_sparse=True, force_all_finite=False, reset=False)\n return self.base_estimator_.score(X, y)" }, { "name": "_validate_estimator", + "unique_name": "_validate_estimator", "qname": "sklearn.semi_supervised._self_training._validate_estimator", + "unique_qname": "sklearn.semi_supervised._self_training._validate_estimator", "decorators": [], "parameters": [ { @@ -152085,7 +157513,9 @@ }, { "name": "configuration", + "unique_name": "configuration", "qname": "sklearn.setup.configuration", + "unique_qname": "sklearn.setup.configuration", "decorators": [], "parameters": [ { @@ -152117,7 +157547,9 @@ }, { "name": "setup_module", + "unique_name": "setup_module", "qname": "sklearn.setup_module", + "unique_qname": "sklearn.setup_module", "decorators": [], "parameters": [ { @@ -152139,7 +157571,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.svm._base.BaseLibSVM.__init__", + "unique_qname": "sklearn.svm._base.BaseLibSVM.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -152311,7 +157745,9 @@ }, { "name": "_compute_kernel", + "unique_name": "_compute_kernel", "qname": "sklearn.svm._base.BaseLibSVM._compute_kernel", + "unique_qname": "sklearn.svm._base.BaseLibSVM._compute_kernel", "decorators": [], "parameters": [ { @@ -152343,7 +157779,9 @@ }, { "name": "_decision_function", + "unique_name": "_decision_function", "qname": "sklearn.svm._base.BaseLibSVM._decision_function", + "unique_qname": "sklearn.svm._base.BaseLibSVM._decision_function", "decorators": [], "parameters": [ { @@ -152375,7 +157813,9 @@ }, { "name": "_dense_decision_function", + "unique_name": "_dense_decision_function", "qname": "sklearn.svm._base.BaseLibSVM._dense_decision_function", + "unique_qname": "sklearn.svm._base.BaseLibSVM._dense_decision_function", "decorators": [], "parameters": [ { @@ -152407,7 +157847,9 @@ }, { "name": "_dense_fit", + "unique_name": "_dense_fit", "qname": "sklearn.svm._base.BaseLibSVM._dense_fit", + "unique_qname": "sklearn.svm._base.BaseLibSVM._dense_fit", "decorators": [], "parameters": [ { @@ -152489,7 +157931,9 @@ }, { "name": "_dense_predict", + "unique_name": "_dense_predict", "qname": "sklearn.svm._base.BaseLibSVM._dense_predict", + "unique_qname": "sklearn.svm._base.BaseLibSVM._dense_predict", "decorators": [], "parameters": [ { @@ -152521,7 +157965,9 @@ }, { "name": "_get_coef", + "unique_name": "_get_coef", "qname": "sklearn.svm._base.BaseLibSVM._get_coef", + "unique_qname": "sklearn.svm._base.BaseLibSVM._get_coef", "decorators": [], "parameters": [ { @@ -152543,7 +157989,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.svm._base.BaseLibSVM._more_tags", + "unique_qname": "sklearn.svm._base.BaseLibSVM._more_tags", "decorators": [], "parameters": [ { @@ -152565,7 +158013,9 @@ }, { "name": "_pairwise", + "unique_name": "_pairwise@getter", "qname": "sklearn.svm._base.BaseLibSVM._pairwise", + "unique_qname": "sklearn.svm._base.BaseLibSVM._pairwise@getter", "decorators": [ "deprecated('Attribute `_pairwise` was deprecated in version 0.24 and will be removed in 1.1 (renaming of 0.26).')", "property" @@ -152590,7 +158040,9 @@ }, { "name": "_sparse_decision_function", + "unique_name": "_sparse_decision_function", "qname": "sklearn.svm._base.BaseLibSVM._sparse_decision_function", + "unique_qname": "sklearn.svm._base.BaseLibSVM._sparse_decision_function", "decorators": [], "parameters": [ { @@ -152622,7 +158074,9 @@ }, { "name": "_sparse_fit", + "unique_name": "_sparse_fit", "qname": "sklearn.svm._base.BaseLibSVM._sparse_fit", + "unique_qname": "sklearn.svm._base.BaseLibSVM._sparse_fit", "decorators": [], "parameters": [ { @@ -152704,7 +158158,9 @@ }, { "name": "_sparse_predict", + "unique_name": "_sparse_predict", "qname": "sklearn.svm._base.BaseLibSVM._sparse_predict", + "unique_qname": "sklearn.svm._base.BaseLibSVM._sparse_predict", "decorators": [], "parameters": [ { @@ -152736,7 +158192,9 @@ }, { "name": "_validate_for_predict", + "unique_name": "_validate_for_predict", "qname": "sklearn.svm._base.BaseLibSVM._validate_for_predict", + "unique_qname": "sklearn.svm._base.BaseLibSVM._validate_for_predict", "decorators": [], "parameters": [ { @@ -152764,11 +158222,13 @@ "is_public": false, "description": "", "docstring": "", - "source_code": "\ndef _validate_for_predict(self, X):\n check_is_fitted(self)\n if not callable(self.kernel):\n X = self._validate_data(X, accept_sparse='csr', dtype=np.float64, order='C', accept_large_sparse=False, reset=False)\n if self._sparse and not sp.isspmatrix(X):\n X = sp.csr_matrix(X)\n if self._sparse:\n X.sort_indices()\n if sp.issparse(X) and not self._sparse and not callable(self.kernel):\n raise ValueError('cannot use sparse input in %r trained on dense data' % type(self).__name__)\n if self.kernel == 'precomputed':\n if X.shape[1] != self.shape_fit_[0]:\n raise ValueError('X.shape[1] = %d should be equal to %d, the number of samples at training time' % (X.shape[1], self.shape_fit_[0]))\n return X" + "source_code": "\ndef _validate_for_predict(self, X):\n check_is_fitted(self)\n if not callable(self.kernel):\n X = self._validate_data(X, accept_sparse='csr', dtype=np.float64, order='C', accept_large_sparse=False, reset=False)\n if self._sparse and not sp.isspmatrix(X):\n X = sp.csr_matrix(X)\n if self._sparse:\n X.sort_indices()\n if sp.issparse(X) and not self._sparse and not callable(self.kernel):\n raise ValueError('cannot use sparse input in %r trained on dense data' % type(self).__name__)\n if self.kernel == 'precomputed':\n if X.shape[1] != self.shape_fit_[0]:\n raise ValueError('X.shape[1] = %d should be equal to %d, the number of samples at training time' % (X.shape[1], self.shape_fit_[0]))\n sv = self.support_vectors_\n if not self._sparse and sv.size > 0 and self.n_support_.sum() != sv.shape[0]:\n raise ValueError(f'The internal representation of {self.__class__.__name__} was altered')\n return X" }, { "name": "_validate_targets", + "unique_name": "_validate_targets", "qname": "sklearn.svm._base.BaseLibSVM._validate_targets", + "unique_qname": "sklearn.svm._base.BaseLibSVM._validate_targets", "decorators": [], "parameters": [ { @@ -152800,7 +158260,9 @@ }, { "name": "_warn_from_fit_status", + "unique_name": "_warn_from_fit_status", "qname": "sklearn.svm._base.BaseLibSVM._warn_from_fit_status", + "unique_qname": "sklearn.svm._base.BaseLibSVM._warn_from_fit_status", "decorators": [], "parameters": [ { @@ -152822,7 +158284,9 @@ }, { "name": "coef_", + "unique_name": "coef_@getter", "qname": "sklearn.svm._base.BaseLibSVM.coef_", + "unique_qname": "sklearn.svm._base.BaseLibSVM.coef_@getter", "decorators": ["property"], "parameters": [ { @@ -152844,7 +158308,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.svm._base.BaseLibSVM.fit", + "unique_qname": "sklearn.svm._base.BaseLibSVM.fit", "decorators": [], "parameters": [ { @@ -152896,7 +158362,9 @@ }, { "name": "n_support_", + "unique_name": "n_support_@getter", "qname": "sklearn.svm._base.BaseLibSVM.n_support_", + "unique_qname": "sklearn.svm._base.BaseLibSVM.n_support_@getter", "decorators": ["property"], "parameters": [ { @@ -152918,7 +158386,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.svm._base.BaseLibSVM.predict", + "unique_qname": "sklearn.svm._base.BaseLibSVM.predict", "decorators": [], "parameters": [ { @@ -152950,7 +158420,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.svm._base.BaseSVC.__init__", + "unique_qname": "sklearn.svm._base.BaseSVC.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -153132,7 +158604,9 @@ }, { "name": "_check_proba", + "unique_name": "_check_proba", "qname": "sklearn.svm._base.BaseSVC._check_proba", + "unique_qname": "sklearn.svm._base.BaseSVC._check_proba", "decorators": [], "parameters": [ { @@ -153154,7 +158628,9 @@ }, { "name": "_dense_predict_proba", + "unique_name": "_dense_predict_proba", "qname": "sklearn.svm._base.BaseSVC._dense_predict_proba", + "unique_qname": "sklearn.svm._base.BaseSVC._dense_predict_proba", "decorators": [], "parameters": [ { @@ -153186,7 +158662,9 @@ }, { "name": "_get_coef", + "unique_name": "_get_coef", "qname": "sklearn.svm._base.BaseSVC._get_coef", + "unique_qname": "sklearn.svm._base.BaseSVC._get_coef", "decorators": [], "parameters": [ { @@ -153208,7 +158686,9 @@ }, { "name": "_sparse_predict_proba", + "unique_name": "_sparse_predict_proba", "qname": "sklearn.svm._base.BaseSVC._sparse_predict_proba", + "unique_qname": "sklearn.svm._base.BaseSVC._sparse_predict_proba", "decorators": [], "parameters": [ { @@ -153240,7 +158720,9 @@ }, { "name": "_validate_targets", + "unique_name": "_validate_targets", "qname": "sklearn.svm._base.BaseSVC._validate_targets", + "unique_qname": "sklearn.svm._base.BaseSVC._validate_targets", "decorators": [], "parameters": [ { @@ -153272,7 +158754,9 @@ }, { "name": "decision_function", + "unique_name": "decision_function", "qname": "sklearn.svm._base.BaseSVC.decision_function", + "unique_qname": "sklearn.svm._base.BaseSVC.decision_function", "decorators": [], "parameters": [ { @@ -153304,7 +158788,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.svm._base.BaseSVC.predict", + "unique_qname": "sklearn.svm._base.BaseSVC.predict", "decorators": [], "parameters": [ { @@ -153336,7 +158822,9 @@ }, { "name": "predict_log_proba", + "unique_name": "predict_log_proba", "qname": "sklearn.svm._base.BaseSVC.predict_log_proba", + "unique_qname": "sklearn.svm._base.BaseSVC.predict_log_proba", "decorators": ["available_if(_check_proba)"], "parameters": [ { @@ -153368,7 +158856,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.svm._base.BaseSVC.predict_proba", + "unique_qname": "sklearn.svm._base.BaseSVC.predict_proba", "decorators": ["available_if(_check_proba)"], "parameters": [ { @@ -153400,7 +158890,9 @@ }, { "name": "probA_", + "unique_name": "probA_@getter", "qname": "sklearn.svm._base.BaseSVC.probA_", + "unique_qname": "sklearn.svm._base.BaseSVC.probA_@getter", "decorators": ["property"], "parameters": [ { @@ -153422,7 +158914,9 @@ }, { "name": "probB_", + "unique_name": "probB_@getter", "qname": "sklearn.svm._base.BaseSVC.probB_", + "unique_qname": "sklearn.svm._base.BaseSVC.probB_@getter", "decorators": ["property"], "parameters": [ { @@ -153444,7 +158938,9 @@ }, { "name": "_fit_liblinear", + "unique_name": "_fit_liblinear", "qname": "sklearn.svm._base._fit_liblinear", + "unique_qname": "sklearn.svm._base._fit_liblinear", "decorators": [], "parameters": [ { @@ -153616,7 +159112,9 @@ }, { "name": "_get_liblinear_solver_type", + "unique_name": "_get_liblinear_solver_type", "qname": "sklearn.svm._base._get_liblinear_solver_type", + "unique_qname": "sklearn.svm._base._get_liblinear_solver_type", "decorators": [], "parameters": [ { @@ -153668,7 +159166,9 @@ }, { "name": "_one_vs_one_coef", + "unique_name": "_one_vs_one_coef", "qname": "sklearn.svm._base._one_vs_one_coef", + "unique_qname": "sklearn.svm._base._one_vs_one_coef", "decorators": [], "parameters": [ { @@ -153710,7 +159210,9 @@ }, { "name": "l1_min_c", + "unique_name": "l1_min_c", "qname": "sklearn.svm._bounds.l1_min_c", + "unique_qname": "sklearn.svm._bounds.l1_min_c", "decorators": [], "parameters": [ { @@ -153772,7 +159274,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.svm._classes.LinearSVC.__init__", + "unique_qname": "sklearn.svm._classes.LinearSVC.__init__", "decorators": [], "parameters": [ { @@ -153914,7 +159418,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.svm._classes.LinearSVC._more_tags", + "unique_qname": "sklearn.svm._classes.LinearSVC._more_tags", "decorators": [], "parameters": [ { @@ -153936,7 +159442,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.svm._classes.LinearSVC.fit", + "unique_qname": "sklearn.svm._classes.LinearSVC.fit", "decorators": [], "parameters": [ { @@ -153988,7 +159496,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.svm._classes.LinearSVR.__init__", + "unique_qname": "sklearn.svm._classes.LinearSVR.__init__", "decorators": [], "parameters": [ { @@ -154110,7 +159620,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.svm._classes.LinearSVR._more_tags", + "unique_qname": "sklearn.svm._classes.LinearSVR._more_tags", "decorators": [], "parameters": [ { @@ -154132,7 +159644,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.svm._classes.LinearSVR.fit", + "unique_qname": "sklearn.svm._classes.LinearSVR.fit", "decorators": [], "parameters": [ { @@ -154184,7 +159698,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.svm._classes.NuSVC.__init__", + "unique_qname": "sklearn.svm._classes.NuSVC.__init__", "decorators": [], "parameters": [ { @@ -154356,7 +159872,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.svm._classes.NuSVC._more_tags", + "unique_qname": "sklearn.svm._classes.NuSVC._more_tags", "decorators": [], "parameters": [ { @@ -154378,7 +159896,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.svm._classes.NuSVR.__init__", + "unique_qname": "sklearn.svm._classes.NuSVR.__init__", "decorators": [], "parameters": [ { @@ -154510,7 +160030,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.svm._classes.NuSVR._more_tags", + "unique_qname": "sklearn.svm._classes.NuSVR._more_tags", "decorators": [], "parameters": [ { @@ -154532,7 +160054,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.svm._classes.OneClassSVM.__init__", + "unique_qname": "sklearn.svm._classes.OneClassSVM.__init__", "decorators": [], "parameters": [ { @@ -154654,7 +160178,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.svm._classes.OneClassSVM._more_tags", + "unique_qname": "sklearn.svm._classes.OneClassSVM._more_tags", "decorators": [], "parameters": [ { @@ -154676,7 +160202,9 @@ }, { "name": "decision_function", + "unique_name": "decision_function", "qname": "sklearn.svm._classes.OneClassSVM.decision_function", + "unique_qname": "sklearn.svm._classes.OneClassSVM.decision_function", "decorators": [], "parameters": [ { @@ -154708,7 +160236,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.svm._classes.OneClassSVM.fit", + "unique_qname": "sklearn.svm._classes.OneClassSVM.fit", "decorators": [], "parameters": [ { @@ -154760,7 +160290,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.svm._classes.OneClassSVM.predict", + "unique_qname": "sklearn.svm._classes.OneClassSVM.predict", "decorators": [], "parameters": [ { @@ -154792,7 +160324,9 @@ }, { "name": "score_samples", + "unique_name": "score_samples", "qname": "sklearn.svm._classes.OneClassSVM.score_samples", + "unique_qname": "sklearn.svm._classes.OneClassSVM.score_samples", "decorators": [], "parameters": [ { @@ -154824,7 +160358,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.svm._classes.SVC.__init__", + "unique_qname": "sklearn.svm._classes.SVC.__init__", "decorators": [], "parameters": [ { @@ -154996,7 +160532,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.svm._classes.SVC._more_tags", + "unique_qname": "sklearn.svm._classes.SVC._more_tags", "decorators": [], "parameters": [ { @@ -155018,7 +160556,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.svm._classes.SVR.__init__", + "unique_qname": "sklearn.svm._classes.SVR.__init__", "decorators": [], "parameters": [ { @@ -155150,7 +160690,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.svm._classes.SVR._more_tags", + "unique_qname": "sklearn.svm._classes.SVR._more_tags", "decorators": [], "parameters": [ { @@ -155172,7 +160714,9 @@ }, { "name": "configuration", + "unique_name": "configuration", "qname": "sklearn.svm.setup.configuration", + "unique_qname": "sklearn.svm.setup.configuration", "decorators": [], "parameters": [ { @@ -155204,7 +160748,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.tree._classes.BaseDecisionTree.__init__", + "unique_qname": "sklearn.tree._classes.BaseDecisionTree.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -155346,7 +160892,9 @@ }, { "name": "_prune_tree", + "unique_name": "_prune_tree", "qname": "sklearn.tree._classes.BaseDecisionTree._prune_tree", + "unique_qname": "sklearn.tree._classes.BaseDecisionTree._prune_tree", "decorators": [], "parameters": [ { @@ -155368,7 +160916,9 @@ }, { "name": "_validate_X_predict", + "unique_name": "_validate_X_predict", "qname": "sklearn.tree._classes.BaseDecisionTree._validate_X_predict", + "unique_qname": "sklearn.tree._classes.BaseDecisionTree._validate_X_predict", "decorators": [], "parameters": [ { @@ -155410,7 +160960,9 @@ }, { "name": "apply", + "unique_name": "apply", "qname": "sklearn.tree._classes.BaseDecisionTree.apply", + "unique_qname": "sklearn.tree._classes.BaseDecisionTree.apply", "decorators": [], "parameters": [ { @@ -155452,7 +161004,9 @@ }, { "name": "cost_complexity_pruning_path", + "unique_name": "cost_complexity_pruning_path", "qname": "sklearn.tree._classes.BaseDecisionTree.cost_complexity_pruning_path", + "unique_qname": "sklearn.tree._classes.BaseDecisionTree.cost_complexity_pruning_path", "decorators": [], "parameters": [ { @@ -155504,7 +161058,9 @@ }, { "name": "decision_path", + "unique_name": "decision_path", "qname": "sklearn.tree._classes.BaseDecisionTree.decision_path", + "unique_qname": "sklearn.tree._classes.BaseDecisionTree.decision_path", "decorators": [], "parameters": [ { @@ -155546,7 +161102,9 @@ }, { "name": "feature_importances_", + "unique_name": "feature_importances_@getter", "qname": "sklearn.tree._classes.BaseDecisionTree.feature_importances_", + "unique_qname": "sklearn.tree._classes.BaseDecisionTree.feature_importances_@getter", "decorators": ["property"], "parameters": [ { @@ -155568,7 +161126,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.tree._classes.BaseDecisionTree.fit", + "unique_qname": "sklearn.tree._classes.BaseDecisionTree.fit", "decorators": [], "parameters": [ { @@ -155640,7 +161200,9 @@ }, { "name": "get_depth", + "unique_name": "get_depth", "qname": "sklearn.tree._classes.BaseDecisionTree.get_depth", + "unique_qname": "sklearn.tree._classes.BaseDecisionTree.get_depth", "decorators": [], "parameters": [ { @@ -155662,7 +161224,9 @@ }, { "name": "get_n_leaves", + "unique_name": "get_n_leaves", "qname": "sklearn.tree._classes.BaseDecisionTree.get_n_leaves", + "unique_qname": "sklearn.tree._classes.BaseDecisionTree.get_n_leaves", "decorators": [], "parameters": [ { @@ -155684,7 +161248,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.tree._classes.BaseDecisionTree.predict", + "unique_qname": "sklearn.tree._classes.BaseDecisionTree.predict", "decorators": [], "parameters": [ { @@ -155726,7 +161292,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.tree._classes.DecisionTreeClassifier.__init__", + "unique_qname": "sklearn.tree._classes.DecisionTreeClassifier.__init__", "decorators": [], "parameters": [ { @@ -155868,7 +161436,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.tree._classes.DecisionTreeClassifier._more_tags", + "unique_qname": "sklearn.tree._classes.DecisionTreeClassifier._more_tags", "decorators": [], "parameters": [ { @@ -155890,7 +161460,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.tree._classes.DecisionTreeClassifier.fit", + "unique_qname": "sklearn.tree._classes.DecisionTreeClassifier.fit", "decorators": [], "parameters": [ { @@ -155962,7 +161534,9 @@ }, { "name": "n_features_", + "unique_name": "n_features_@getter", "qname": "sklearn.tree._classes.DecisionTreeClassifier.n_features_", + "unique_qname": "sklearn.tree._classes.DecisionTreeClassifier.n_features_@getter", "decorators": [ "deprecated('The attribute `n_features_` is deprecated in 1.0 and will be removed in 1.2. Use `n_features_in_` instead.')", "property" @@ -155987,7 +161561,9 @@ }, { "name": "predict_log_proba", + "unique_name": "predict_log_proba", "qname": "sklearn.tree._classes.DecisionTreeClassifier.predict_log_proba", + "unique_qname": "sklearn.tree._classes.DecisionTreeClassifier.predict_log_proba", "decorators": [], "parameters": [ { @@ -156019,7 +161595,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.tree._classes.DecisionTreeClassifier.predict_proba", + "unique_qname": "sklearn.tree._classes.DecisionTreeClassifier.predict_proba", "decorators": [], "parameters": [ { @@ -156061,7 +161639,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.tree._classes.DecisionTreeRegressor.__init__", + "unique_qname": "sklearn.tree._classes.DecisionTreeRegressor.__init__", "decorators": [], "parameters": [ { @@ -156080,7 +161660,7 @@ "is_public": true, "assigned_by": "NAME_ONLY", "docstring": { - "type": "{\"squared_error\", \"mse\", \"friedman_mse\", \"absolute_error\", \"mae\", \"poisson\"}, default=\"squared_error\"", + "type": "{\"squared_error\", \"friedman_mse\", \"absolute_error\", \"poisson\"}, default=\"squared_error\"", "description": "The function to measure the quality of a split. Supported criteria\nare \"squared_error\" for the mean squared error, which is equal to\nvariance reduction as feature selection criterion and minimizes the L2\nloss using the mean of each terminal node, \"friedman_mse\", which uses\nmean squared error with Friedman's improvement score for potential\nsplits, \"absolute_error\" for the mean absolute error, which minimizes\nthe L1 loss using the median of each terminal node, and \"poisson\" which\nuses reduction in Poisson deviance to find splits.\n\n.. versionadded:: 0.18\n Mean Absolute Error (MAE) criterion.\n\n.. versionadded:: 0.24\n Poisson deviance criterion.\n\n.. deprecated:: 1.0\n Criterion \"mse\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"squared_error\"` which is equivalent.\n\n.. deprecated:: 1.0\n Criterion \"mae\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"absolute_error\"` which is equivalent." } }, @@ -156193,7 +161773,9 @@ }, { "name": "_compute_partial_dependence_recursion", + "unique_name": "_compute_partial_dependence_recursion", "qname": "sklearn.tree._classes.DecisionTreeRegressor._compute_partial_dependence_recursion", + "unique_qname": "sklearn.tree._classes.DecisionTreeRegressor._compute_partial_dependence_recursion", "decorators": [], "parameters": [ { @@ -156235,7 +161817,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.tree._classes.DecisionTreeRegressor.fit", + "unique_qname": "sklearn.tree._classes.DecisionTreeRegressor.fit", "decorators": [], "parameters": [ { @@ -156307,7 +161891,9 @@ }, { "name": "n_features_", + "unique_name": "n_features_@getter", "qname": "sklearn.tree._classes.DecisionTreeRegressor.n_features_", + "unique_qname": "sklearn.tree._classes.DecisionTreeRegressor.n_features_@getter", "decorators": [ "deprecated('The attribute `n_features_` is deprecated in 1.0 and will be removed in 1.2. Use `n_features_in_` instead.')", "property" @@ -156332,7 +161918,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.tree._classes.ExtraTreeClassifier.__init__", + "unique_qname": "sklearn.tree._classes.ExtraTreeClassifier.__init__", "decorators": [], "parameters": [ { @@ -156474,7 +162062,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.tree._classes.ExtraTreeRegressor.__init__", + "unique_qname": "sklearn.tree._classes.ExtraTreeRegressor.__init__", "decorators": [], "parameters": [ { @@ -156493,7 +162083,7 @@ "is_public": true, "assigned_by": "NAME_ONLY", "docstring": { - "type": "{\"squared_error\", \"mse\", \"friedman_mse\", \"mae\"}, default=\"squared_error\"", + "type": "{\"squared_error\", \"friedman_mse\"}, default=\"squared_error\"", "description": "The function to measure the quality of a split. Supported criteria\nare \"squared_error\" for the mean squared error, which is equal to\nvariance reduction as feature selection criterion and \"mae\" for the\nmean absolute error.\n\n.. versionadded:: 0.18\n Mean Absolute Error (MAE) criterion.\n\n.. versionadded:: 0.24\n Poisson deviance criterion.\n\n.. deprecated:: 1.0\n Criterion \"mse\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"squared_error\"` which is equivalent.\n\n.. deprecated:: 1.0\n Criterion \"mae\" was deprecated in v1.0 and will be removed in\n version 1.2. Use `criterion=\"absolute_error\"` which is equivalent." } }, @@ -156606,7 +162196,9 @@ }, { "name": "__repr__", + "unique_name": "__repr__", "qname": "sklearn.tree._export.Sentinel.__repr__", + "unique_qname": "sklearn.tree._export.Sentinel.__repr__", "decorators": [], "parameters": [ { @@ -156628,7 +162220,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.tree._export._BaseTreeExporter.__init__", + "unique_qname": "sklearn.tree._export._BaseTreeExporter.__init__", "decorators": [], "parameters": [ { @@ -156760,7 +162354,9 @@ }, { "name": "get_color", + "unique_name": "get_color", "qname": "sklearn.tree._export._BaseTreeExporter.get_color", + "unique_qname": "sklearn.tree._export._BaseTreeExporter.get_color", "decorators": [], "parameters": [ { @@ -156792,7 +162388,9 @@ }, { "name": "get_fill_color", + "unique_name": "get_fill_color", "qname": "sklearn.tree._export._BaseTreeExporter.get_fill_color", + "unique_qname": "sklearn.tree._export._BaseTreeExporter.get_fill_color", "decorators": [], "parameters": [ { @@ -156834,7 +162432,9 @@ }, { "name": "node_to_str", + "unique_name": "node_to_str", "qname": "sklearn.tree._export._BaseTreeExporter.node_to_str", + "unique_qname": "sklearn.tree._export._BaseTreeExporter.node_to_str", "decorators": [], "parameters": [ { @@ -156886,7 +162486,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.tree._export._DOTTreeExporter.__init__", + "unique_qname": "sklearn.tree._export._DOTTreeExporter.__init__", "decorators": [], "parameters": [ { @@ -157058,7 +162660,9 @@ }, { "name": "export", + "unique_name": "export", "qname": "sklearn.tree._export._DOTTreeExporter.export", + "unique_qname": "sklearn.tree._export._DOTTreeExporter.export", "decorators": [], "parameters": [ { @@ -157090,7 +162694,9 @@ }, { "name": "head", + "unique_name": "head", "qname": "sklearn.tree._export._DOTTreeExporter.head", + "unique_qname": "sklearn.tree._export._DOTTreeExporter.head", "decorators": [], "parameters": [ { @@ -157112,7 +162718,9 @@ }, { "name": "recurse", + "unique_name": "recurse", "qname": "sklearn.tree._export._DOTTreeExporter.recurse", + "unique_qname": "sklearn.tree._export._DOTTreeExporter.recurse", "decorators": [], "parameters": [ { @@ -157184,7 +162792,9 @@ }, { "name": "tail", + "unique_name": "tail", "qname": "sklearn.tree._export._DOTTreeExporter.tail", + "unique_qname": "sklearn.tree._export._DOTTreeExporter.tail", "decorators": [], "parameters": [ { @@ -157206,7 +162816,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.tree._export._MPLTreeExporter.__init__", + "unique_qname": "sklearn.tree._export._MPLTreeExporter.__init__", "decorators": [], "parameters": [ { @@ -157338,7 +162950,9 @@ }, { "name": "_make_tree", + "unique_name": "_make_tree", "qname": "sklearn.tree._export._MPLTreeExporter._make_tree", + "unique_qname": "sklearn.tree._export._MPLTreeExporter._make_tree", "decorators": [], "parameters": [ { @@ -157400,7 +163014,9 @@ }, { "name": "export", + "unique_name": "export", "qname": "sklearn.tree._export._MPLTreeExporter.export", + "unique_qname": "sklearn.tree._export._MPLTreeExporter.export", "decorators": [], "parameters": [ { @@ -157442,7 +163058,9 @@ }, { "name": "recurse", + "unique_name": "recurse", "qname": "sklearn.tree._export._MPLTreeExporter.recurse", + "unique_qname": "sklearn.tree._export._MPLTreeExporter.recurse", "decorators": [], "parameters": [ { @@ -157534,7 +163152,9 @@ }, { "name": "_color_brew", + "unique_name": "_color_brew", "qname": "sklearn.tree._export._color_brew", + "unique_qname": "sklearn.tree._export._color_brew", "decorators": [], "parameters": [ { @@ -157556,7 +163176,9 @@ }, { "name": "_compute_depth", + "unique_name": "_compute_depth", "qname": "sklearn.tree._export._compute_depth", + "unique_qname": "sklearn.tree._export._compute_depth", "decorators": [], "parameters": [ { @@ -157588,7 +163210,9 @@ }, { "name": "export_graphviz", + "unique_name": "export_graphviz", "qname": "sklearn.tree._export.export_graphviz", + "unique_qname": "sklearn.tree._export.export_graphviz", "decorators": [], "parameters": [ { @@ -157755,12 +163379,14 @@ "results": [], "is_public": true, "description": "Export a decision tree in DOT format.\n\nThis function generates a GraphViz representation of the decision tree, which is then written into `out_file`. Once exported, graphical renderings can be generated using, for example:: $ dot -Tps tree.dot -o tree.ps (PostScript format) $ dot -Tpng tree.dot -o tree.png (PNG format) The sample counts that are shown are weighted with any sample_weights that might be present. Read more in the :ref:`User Guide `.", - "docstring": "Export a decision tree in DOT format.\n\nThis function generates a GraphViz representation of the decision tree,\nwhich is then written into `out_file`. Once exported, graphical renderings\ncan be generated using, for example::\n\n $ dot -Tps tree.dot -o tree.ps (PostScript format)\n $ dot -Tpng tree.dot -o tree.png (PNG format)\n\nThe sample counts that are shown are weighted with any sample_weights that\nmight be present.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\ndecision_tree : decision tree classifier\n The decision tree to be exported to GraphViz.\n\nout_file : object or str, default=None\n Handle or name of the output file. If ``None``, the result is\n returned as a string.\n\n .. versionchanged:: 0.20\n Default of out_file changed from \"tree.dot\" to None.\n\nmax_depth : int, default=None\n The maximum depth of the representation. If None, the tree is fully\n generated.\n\nfeature_names : list of str, default=None\n Names of each of the features.\n If None generic names will be used (\"feature_0\", \"feature_1\", ...).\n\nclass_names : list of str or bool, default=None\n Names of each of the target classes in ascending numerical order.\n Only relevant for classification and not supported for multi-output.\n If ``True``, shows a symbolic representation of the class name.\n\nlabel : {'all', 'root', 'none'}, default='all'\n Whether to show informative labels for impurity, etc.\n Options include 'all' to show at every node, 'root' to show only at\n the top root node, or 'none' to not show at any node.\n\nfilled : bool, default=False\n When set to ``True``, paint nodes to indicate majority class for\n classification, extremity of values for regression, or purity of node\n for multi-output.\n\nleaves_parallel : bool, default=False\n When set to ``True``, draw all leaf nodes at the bottom of the tree.\n\nimpurity : bool, default=True\n When set to ``True``, show the impurity at each node.\n\nnode_ids : bool, default=False\n When set to ``True``, show the ID number on each node.\n\nproportion : bool, default=False\n When set to ``True``, change the display of 'values' and/or 'samples'\n to be proportions and percentages respectively.\n\nrotate : bool, default=False\n When set to ``True``, orient tree left to right rather than top-down.\n\nrounded : bool, default=False\n When set to ``True``, draw node boxes with rounded corners.\n\nspecial_characters : bool, default=False\n When set to ``False``, ignore special characters for PostScript\n compatibility.\n\nprecision : int, default=3\n Number of digits of precision for floating point in the values of\n impurity, threshold and value attributes of each node.\n\nfontname : str, default='helvetica'\n Name of font used to render text.\n\nReturns\n-------\ndot_data : string\n String representation of the input tree in GraphViz dot format.\n Only returned if ``out_file`` is None.\n\n .. versionadded:: 0.18\n\nExamples\n--------\n>>> from sklearn.datasets import load_iris\n>>> from sklearn import tree\n\n>>> clf = tree.DecisionTreeClassifier()\n>>> iris = load_iris()\n\n>>> clf = clf.fit(iris.data, iris.target)\n>>> tree.export_graphviz(clf)\n'digraph Tree {...", - "source_code": "\ndef export_graphviz(decision_tree, out_file=None, *, max_depth=None, feature_names=None, class_names=None, label='all', filled=False, leaves_parallel=False, impurity=True, node_ids=False, proportion=False, rotate=False, rounded=False, special_characters=False, precision=3, fontname='helvetica'):\n \"\"\"Export a decision tree in DOT format.\n\n This function generates a GraphViz representation of the decision tree,\n which is then written into `out_file`. Once exported, graphical renderings\n can be generated using, for example::\n\n $ dot -Tps tree.dot -o tree.ps (PostScript format)\n $ dot -Tpng tree.dot -o tree.png (PNG format)\n\n The sample counts that are shown are weighted with any sample_weights that\n might be present.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n decision_tree : decision tree classifier\n The decision tree to be exported to GraphViz.\n\n out_file : object or str, default=None\n Handle or name of the output file. If ``None``, the result is\n returned as a string.\n\n .. versionchanged:: 0.20\n Default of out_file changed from \"tree.dot\" to None.\n\n max_depth : int, default=None\n The maximum depth of the representation. If None, the tree is fully\n generated.\n\n feature_names : list of str, default=None\n Names of each of the features.\n If None generic names will be used (\"feature_0\", \"feature_1\", ...).\n\n class_names : list of str or bool, default=None\n Names of each of the target classes in ascending numerical order.\n Only relevant for classification and not supported for multi-output.\n If ``True``, shows a symbolic representation of the class name.\n\n label : {'all', 'root', 'none'}, default='all'\n Whether to show informative labels for impurity, etc.\n Options include 'all' to show at every node, 'root' to show only at\n the top root node, or 'none' to not show at any node.\n\n filled : bool, default=False\n When set to ``True``, paint nodes to indicate majority class for\n classification, extremity of values for regression, or purity of node\n for multi-output.\n\n leaves_parallel : bool, default=False\n When set to ``True``, draw all leaf nodes at the bottom of the tree.\n\n impurity : bool, default=True\n When set to ``True``, show the impurity at each node.\n\n node_ids : bool, default=False\n When set to ``True``, show the ID number on each node.\n\n proportion : bool, default=False\n When set to ``True``, change the display of 'values' and/or 'samples'\n to be proportions and percentages respectively.\n\n rotate : bool, default=False\n When set to ``True``, orient tree left to right rather than top-down.\n\n rounded : bool, default=False\n When set to ``True``, draw node boxes with rounded corners.\n\n special_characters : bool, default=False\n When set to ``False``, ignore special characters for PostScript\n compatibility.\n\n precision : int, default=3\n Number of digits of precision for floating point in the values of\n impurity, threshold and value attributes of each node.\n\n fontname : str, default='helvetica'\n Name of font used to render text.\n\n Returns\n -------\n dot_data : string\n String representation of the input tree in GraphViz dot format.\n Only returned if ``out_file`` is None.\n\n .. versionadded:: 0.18\n\n Examples\n --------\n >>> from sklearn.datasets import load_iris\n >>> from sklearn import tree\n\n >>> clf = tree.DecisionTreeClassifier()\n >>> iris = load_iris()\n\n >>> clf = clf.fit(iris.data, iris.target)\n >>> tree.export_graphviz(clf)\n 'digraph Tree {...\n \"\"\"\n check_is_fitted(decision_tree)\n own_file = False\n return_string = False\n try:\n if isinstance(out_file, str):\n out_file = open(out_file, 'w', encoding='utf-8')\n own_file = True\n if out_file is None:\n return_string = True\n out_file = StringIO()\n exporter = _DOTTreeExporter(out_file=out_file, max_depth=max_depth, feature_names=feature_names, class_names=class_names, label=label, filled=filled, leaves_parallel=leaves_parallel, impurity=impurity, node_ids=node_ids, proportion=proportion, rotate=rotate, rounded=rounded, special_characters=special_characters, precision=precision, fontname=fontname)\n exporter.export(decision_tree)\n if return_string:\n return exporter.out_file.getvalue()\n finally:\n if own_file:\n out_file.close()" + "docstring": "Export a decision tree in DOT format.\n\nThis function generates a GraphViz representation of the decision tree,\nwhich is then written into `out_file`. Once exported, graphical renderings\ncan be generated using, for example::\n\n $ dot -Tps tree.dot -o tree.ps (PostScript format)\n $ dot -Tpng tree.dot -o tree.png (PNG format)\n\nThe sample counts that are shown are weighted with any sample_weights that\nmight be present.\n\nRead more in the :ref:`User Guide `.\n\nParameters\n----------\ndecision_tree : decision tree classifier\n The decision tree to be exported to GraphViz.\n\nout_file : object or str, default=None\n Handle or name of the output file. If ``None``, the result is\n returned as a string.\n\n .. versionchanged:: 0.20\n Default of out_file changed from \"tree.dot\" to None.\n\nmax_depth : int, default=None\n The maximum depth of the representation. If None, the tree is fully\n generated.\n\nfeature_names : list of str, default=None\n Names of each of the features.\n If None generic names will be used (\"feature_0\", \"feature_1\", ...).\n\nclass_names : list of str or bool, default=None\n Names of each of the target classes in ascending numerical order.\n Only relevant for classification and not supported for multi-output.\n If ``True``, shows a symbolic representation of the class name.\n\nlabel : {'all', 'root', 'none'}, default='all'\n Whether to show informative labels for impurity, etc.\n Options include 'all' to show at every node, 'root' to show only at\n the top root node, or 'none' to not show at any node.\n\nfilled : bool, default=False\n When set to ``True``, paint nodes to indicate majority class for\n classification, extremity of values for regression, or purity of node\n for multi-output.\n\nleaves_parallel : bool, default=False\n When set to ``True``, draw all leaf nodes at the bottom of the tree.\n\nimpurity : bool, default=True\n When set to ``True``, show the impurity at each node.\n\nnode_ids : bool, default=False\n When set to ``True``, show the ID number on each node.\n\nproportion : bool, default=False\n When set to ``True``, change the display of 'values' and/or 'samples'\n to be proportions and percentages respectively.\n\nrotate : bool, default=False\n When set to ``True``, orient tree left to right rather than top-down.\n\nrounded : bool, default=False\n When set to ``True``, draw node boxes with rounded corners.\n\nspecial_characters : bool, default=False\n When set to ``False``, ignore special characters for PostScript\n compatibility.\n\nprecision : int, default=3\n Number of digits of precision for floating point in the values of\n impurity, threshold and value attributes of each node.\n\nfontname : str, default='helvetica'\n Name of font used to render text.\n\nReturns\n-------\ndot_data : str\n String representation of the input tree in GraphViz dot format.\n Only returned if ``out_file`` is None.\n\n .. versionadded:: 0.18\n\nExamples\n--------\n>>> from sklearn.datasets import load_iris\n>>> from sklearn import tree\n\n>>> clf = tree.DecisionTreeClassifier()\n>>> iris = load_iris()\n\n>>> clf = clf.fit(iris.data, iris.target)\n>>> tree.export_graphviz(clf)\n'digraph Tree {...", + "source_code": "\ndef export_graphviz(decision_tree, out_file=None, *, max_depth=None, feature_names=None, class_names=None, label='all', filled=False, leaves_parallel=False, impurity=True, node_ids=False, proportion=False, rotate=False, rounded=False, special_characters=False, precision=3, fontname='helvetica'):\n \"\"\"Export a decision tree in DOT format.\n\n This function generates a GraphViz representation of the decision tree,\n which is then written into `out_file`. Once exported, graphical renderings\n can be generated using, for example::\n\n $ dot -Tps tree.dot -o tree.ps (PostScript format)\n $ dot -Tpng tree.dot -o tree.png (PNG format)\n\n The sample counts that are shown are weighted with any sample_weights that\n might be present.\n\n Read more in the :ref:`User Guide `.\n\n Parameters\n ----------\n decision_tree : decision tree classifier\n The decision tree to be exported to GraphViz.\n\n out_file : object or str, default=None\n Handle or name of the output file. If ``None``, the result is\n returned as a string.\n\n .. versionchanged:: 0.20\n Default of out_file changed from \"tree.dot\" to None.\n\n max_depth : int, default=None\n The maximum depth of the representation. If None, the tree is fully\n generated.\n\n feature_names : list of str, default=None\n Names of each of the features.\n If None generic names will be used (\"feature_0\", \"feature_1\", ...).\n\n class_names : list of str or bool, default=None\n Names of each of the target classes in ascending numerical order.\n Only relevant for classification and not supported for multi-output.\n If ``True``, shows a symbolic representation of the class name.\n\n label : {'all', 'root', 'none'}, default='all'\n Whether to show informative labels for impurity, etc.\n Options include 'all' to show at every node, 'root' to show only at\n the top root node, or 'none' to not show at any node.\n\n filled : bool, default=False\n When set to ``True``, paint nodes to indicate majority class for\n classification, extremity of values for regression, or purity of node\n for multi-output.\n\n leaves_parallel : bool, default=False\n When set to ``True``, draw all leaf nodes at the bottom of the tree.\n\n impurity : bool, default=True\n When set to ``True``, show the impurity at each node.\n\n node_ids : bool, default=False\n When set to ``True``, show the ID number on each node.\n\n proportion : bool, default=False\n When set to ``True``, change the display of 'values' and/or 'samples'\n to be proportions and percentages respectively.\n\n rotate : bool, default=False\n When set to ``True``, orient tree left to right rather than top-down.\n\n rounded : bool, default=False\n When set to ``True``, draw node boxes with rounded corners.\n\n special_characters : bool, default=False\n When set to ``False``, ignore special characters for PostScript\n compatibility.\n\n precision : int, default=3\n Number of digits of precision for floating point in the values of\n impurity, threshold and value attributes of each node.\n\n fontname : str, default='helvetica'\n Name of font used to render text.\n\n Returns\n -------\n dot_data : str\n String representation of the input tree in GraphViz dot format.\n Only returned if ``out_file`` is None.\n\n .. versionadded:: 0.18\n\n Examples\n --------\n >>> from sklearn.datasets import load_iris\n >>> from sklearn import tree\n\n >>> clf = tree.DecisionTreeClassifier()\n >>> iris = load_iris()\n\n >>> clf = clf.fit(iris.data, iris.target)\n >>> tree.export_graphviz(clf)\n 'digraph Tree {...\n \"\"\"\n check_is_fitted(decision_tree)\n own_file = False\n return_string = False\n try:\n if isinstance(out_file, str):\n out_file = open(out_file, 'w', encoding='utf-8')\n own_file = True\n if out_file is None:\n return_string = True\n out_file = StringIO()\n exporter = _DOTTreeExporter(out_file=out_file, max_depth=max_depth, feature_names=feature_names, class_names=class_names, label=label, filled=filled, leaves_parallel=leaves_parallel, impurity=impurity, node_ids=node_ids, proportion=proportion, rotate=rotate, rounded=rounded, special_characters=special_characters, precision=precision, fontname=fontname)\n exporter.export(decision_tree)\n if return_string:\n return exporter.out_file.getvalue()\n finally:\n if own_file:\n out_file.close()" }, { "name": "export_text", + "unique_name": "export_text", "qname": "sklearn.tree._export.export_text", + "unique_qname": "sklearn.tree._export.export_text", "decorators": [], "parameters": [ { @@ -157827,12 +163453,14 @@ "results": [], "is_public": true, "description": "Build a text report showing the rules of a decision tree.\n\nNote that backwards compatibility may not be supported.", - "docstring": "Build a text report showing the rules of a decision tree.\n\nNote that backwards compatibility may not be supported.\n\nParameters\n----------\ndecision_tree : object\n The decision tree estimator to be exported.\n It can be an instance of\n DecisionTreeClassifier or DecisionTreeRegressor.\n\nfeature_names : list of str, default=None\n A list of length n_features containing the feature names.\n If None generic names will be used (\"feature_0\", \"feature_1\", ...).\n\nmax_depth : int, default=10\n Only the first max_depth levels of the tree are exported.\n Truncated branches will be marked with \"...\".\n\nspacing : int, default=3\n Number of spaces between edges. The higher it is, the wider the result.\n\ndecimals : int, default=2\n Number of decimal digits to display.\n\nshow_weights : bool, default=False\n If true the classification weights will be exported on each leaf.\n The classification weights are the number of samples each class.\n\nReturns\n-------\nreport : string\n Text summary of all the rules in the decision tree.\n\nExamples\n--------\n\n>>> from sklearn.datasets import load_iris\n>>> from sklearn.tree import DecisionTreeClassifier\n>>> from sklearn.tree import export_text\n>>> iris = load_iris()\n>>> X = iris['data']\n>>> y = iris['target']\n>>> decision_tree = DecisionTreeClassifier(random_state=0, max_depth=2)\n>>> decision_tree = decision_tree.fit(X, y)\n>>> r = export_text(decision_tree, feature_names=iris['feature_names'])\n>>> print(r)\n|--- petal width (cm) <= 0.80\n| |--- class: 0\n|--- petal width (cm) > 0.80\n| |--- petal width (cm) <= 1.75\n| | |--- class: 1\n| |--- petal width (cm) > 1.75\n| | |--- class: 2", - "source_code": "\ndef export_text(decision_tree, *, feature_names=None, max_depth=10, spacing=3, decimals=2, show_weights=False):\n \"\"\"Build a text report showing the rules of a decision tree.\n\n Note that backwards compatibility may not be supported.\n\n Parameters\n ----------\n decision_tree : object\n The decision tree estimator to be exported.\n It can be an instance of\n DecisionTreeClassifier or DecisionTreeRegressor.\n\n feature_names : list of str, default=None\n A list of length n_features containing the feature names.\n If None generic names will be used (\"feature_0\", \"feature_1\", ...).\n\n max_depth : int, default=10\n Only the first max_depth levels of the tree are exported.\n Truncated branches will be marked with \"...\".\n\n spacing : int, default=3\n Number of spaces between edges. The higher it is, the wider the result.\n\n decimals : int, default=2\n Number of decimal digits to display.\n\n show_weights : bool, default=False\n If true the classification weights will be exported on each leaf.\n The classification weights are the number of samples each class.\n\n Returns\n -------\n report : string\n Text summary of all the rules in the decision tree.\n\n Examples\n --------\n\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.tree import DecisionTreeClassifier\n >>> from sklearn.tree import export_text\n >>> iris = load_iris()\n >>> X = iris['data']\n >>> y = iris['target']\n >>> decision_tree = DecisionTreeClassifier(random_state=0, max_depth=2)\n >>> decision_tree = decision_tree.fit(X, y)\n >>> r = export_text(decision_tree, feature_names=iris['feature_names'])\n >>> print(r)\n |--- petal width (cm) <= 0.80\n | |--- class: 0\n |--- petal width (cm) > 0.80\n | |--- petal width (cm) <= 1.75\n | | |--- class: 1\n | |--- petal width (cm) > 1.75\n | | |--- class: 2\n \"\"\"\n check_is_fitted(decision_tree)\n tree_ = decision_tree.tree_\n if is_classifier(decision_tree):\n class_names = decision_tree.classes_\n right_child_fmt = '{} {} <= {}\\n'\n left_child_fmt = '{} {} > {}\\n'\n truncation_fmt = '{} {}\\n'\n if max_depth < 0:\n raise ValueError('max_depth bust be >= 0, given %d' % max_depth)\n if feature_names is not None and len(feature_names) != tree_.n_features:\n raise ValueError('feature_names must contain %d elements, got %d' % (tree_.n_features, len(feature_names)))\n if spacing <= 0:\n raise ValueError('spacing must be > 0, given %d' % spacing)\n if decimals < 0:\n raise ValueError('decimals must be >= 0, given %d' % decimals)\n if isinstance(decision_tree, DecisionTreeClassifier):\n value_fmt = '{}{} weights: {}\\n'\n if not show_weights:\n value_fmt = '{}{}{}\\n'\n else:\n value_fmt = '{}{} value: {}\\n'\n if feature_names:\n feature_names_ = [feature_names[i] if i != _tree.TREE_UNDEFINED else None for i in tree_.feature]\n else:\n feature_names_ = ['feature_{}'.format(i) for i in tree_.feature]\n export_text.report = ''\n \n def _add_leaf(value, class_name, indent):\n val = ''\n is_classification = isinstance(decision_tree, DecisionTreeClassifier)\n if show_weights or not is_classification:\n val = ['{1:.{0}f}, '.format(decimals, v) for v in value]\n val = '[' + ''.join(val)[:-2] + ']'\n if is_classification:\n val += ' class: ' + str(class_name)\n export_text.report += value_fmt.format(indent, '', val)\n \n def print_tree_recurse(node, depth):\n indent = ('|' + ' ' * spacing) * depth\n indent = indent[:-spacing] + '-' * spacing\n value = None\n if tree_.n_outputs == 1:\n value = tree_.value[node][0]\n else:\n value = tree_.value[node].T[0]\n class_name = np.argmax(value)\n if tree_.n_classes[0] != 1 and tree_.n_outputs == 1:\n class_name = class_names[class_name]\n if depth <= max_depth + 1:\n info_fmt = ''\n info_fmt_left = info_fmt\n info_fmt_right = info_fmt\n if tree_.feature[node] != _tree.TREE_UNDEFINED:\n name = feature_names_[node]\n threshold = tree_.threshold[node]\n threshold = '{1:.{0}f}'.format(decimals, threshold)\n export_text.report += right_child_fmt.format(indent, name, threshold)\n export_text.report += info_fmt_left\n print_tree_recurse(tree_.children_left[node], depth + 1)\n export_text.report += left_child_fmt.format(indent, name, threshold)\n export_text.report += info_fmt_right\n print_tree_recurse(tree_.children_right[node], depth + 1)\n else:\n _add_leaf(value, class_name, indent)\n else:\n subtree_depth = _compute_depth(tree_, node)\n if subtree_depth == 1:\n _add_leaf(value, class_name, indent)\n else:\n trunc_report = 'truncated branch of depth %d' % subtree_depth\n export_text.report += truncation_fmt.format(indent, trunc_report)\n print_tree_recurse(0, 1)\n return export_text.report" + "docstring": "Build a text report showing the rules of a decision tree.\n\nNote that backwards compatibility may not be supported.\n\nParameters\n----------\ndecision_tree : object\n The decision tree estimator to be exported.\n It can be an instance of\n DecisionTreeClassifier or DecisionTreeRegressor.\n\nfeature_names : list of str, default=None\n A list of length n_features containing the feature names.\n If None generic names will be used (\"feature_0\", \"feature_1\", ...).\n\nmax_depth : int, default=10\n Only the first max_depth levels of the tree are exported.\n Truncated branches will be marked with \"...\".\n\nspacing : int, default=3\n Number of spaces between edges. The higher it is, the wider the result.\n\ndecimals : int, default=2\n Number of decimal digits to display.\n\nshow_weights : bool, default=False\n If true the classification weights will be exported on each leaf.\n The classification weights are the number of samples each class.\n\nReturns\n-------\nreport : str\n Text summary of all the rules in the decision tree.\n\nExamples\n--------\n\n>>> from sklearn.datasets import load_iris\n>>> from sklearn.tree import DecisionTreeClassifier\n>>> from sklearn.tree import export_text\n>>> iris = load_iris()\n>>> X = iris['data']\n>>> y = iris['target']\n>>> decision_tree = DecisionTreeClassifier(random_state=0, max_depth=2)\n>>> decision_tree = decision_tree.fit(X, y)\n>>> r = export_text(decision_tree, feature_names=iris['feature_names'])\n>>> print(r)\n|--- petal width (cm) <= 0.80\n| |--- class: 0\n|--- petal width (cm) > 0.80\n| |--- petal width (cm) <= 1.75\n| | |--- class: 1\n| |--- petal width (cm) > 1.75\n| | |--- class: 2", + "source_code": "\ndef export_text(decision_tree, *, feature_names=None, max_depth=10, spacing=3, decimals=2, show_weights=False):\n \"\"\"Build a text report showing the rules of a decision tree.\n\n Note that backwards compatibility may not be supported.\n\n Parameters\n ----------\n decision_tree : object\n The decision tree estimator to be exported.\n It can be an instance of\n DecisionTreeClassifier or DecisionTreeRegressor.\n\n feature_names : list of str, default=None\n A list of length n_features containing the feature names.\n If None generic names will be used (\"feature_0\", \"feature_1\", ...).\n\n max_depth : int, default=10\n Only the first max_depth levels of the tree are exported.\n Truncated branches will be marked with \"...\".\n\n spacing : int, default=3\n Number of spaces between edges. The higher it is, the wider the result.\n\n decimals : int, default=2\n Number of decimal digits to display.\n\n show_weights : bool, default=False\n If true the classification weights will be exported on each leaf.\n The classification weights are the number of samples each class.\n\n Returns\n -------\n report : str\n Text summary of all the rules in the decision tree.\n\n Examples\n --------\n\n >>> from sklearn.datasets import load_iris\n >>> from sklearn.tree import DecisionTreeClassifier\n >>> from sklearn.tree import export_text\n >>> iris = load_iris()\n >>> X = iris['data']\n >>> y = iris['target']\n >>> decision_tree = DecisionTreeClassifier(random_state=0, max_depth=2)\n >>> decision_tree = decision_tree.fit(X, y)\n >>> r = export_text(decision_tree, feature_names=iris['feature_names'])\n >>> print(r)\n |--- petal width (cm) <= 0.80\n | |--- class: 0\n |--- petal width (cm) > 0.80\n | |--- petal width (cm) <= 1.75\n | | |--- class: 1\n | |--- petal width (cm) > 1.75\n | | |--- class: 2\n \"\"\"\n check_is_fitted(decision_tree)\n tree_ = decision_tree.tree_\n if is_classifier(decision_tree):\n class_names = decision_tree.classes_\n right_child_fmt = '{} {} <= {}\\n'\n left_child_fmt = '{} {} > {}\\n'\n truncation_fmt = '{} {}\\n'\n if max_depth < 0:\n raise ValueError('max_depth bust be >= 0, given %d' % max_depth)\n if feature_names is not None and len(feature_names) != tree_.n_features:\n raise ValueError('feature_names must contain %d elements, got %d' % (tree_.n_features, len(feature_names)))\n if spacing <= 0:\n raise ValueError('spacing must be > 0, given %d' % spacing)\n if decimals < 0:\n raise ValueError('decimals must be >= 0, given %d' % decimals)\n if isinstance(decision_tree, DecisionTreeClassifier):\n value_fmt = '{}{} weights: {}\\n'\n if not show_weights:\n value_fmt = '{}{}{}\\n'\n else:\n value_fmt = '{}{} value: {}\\n'\n if feature_names:\n feature_names_ = [feature_names[i] if i != _tree.TREE_UNDEFINED else None for i in tree_.feature]\n else:\n feature_names_ = ['feature_{}'.format(i) for i in tree_.feature]\n export_text.report = ''\n \n def _add_leaf(value, class_name, indent):\n val = ''\n is_classification = isinstance(decision_tree, DecisionTreeClassifier)\n if show_weights or not is_classification:\n val = ['{1:.{0}f}, '.format(decimals, v) for v in value]\n val = '[' + ''.join(val)[:-2] + ']'\n if is_classification:\n val += ' class: ' + str(class_name)\n export_text.report += value_fmt.format(indent, '', val)\n \n def print_tree_recurse(node, depth):\n indent = ('|' + ' ' * spacing) * depth\n indent = indent[:-spacing] + '-' * spacing\n value = None\n if tree_.n_outputs == 1:\n value = tree_.value[node][0]\n else:\n value = tree_.value[node].T[0]\n class_name = np.argmax(value)\n if tree_.n_classes[0] != 1 and tree_.n_outputs == 1:\n class_name = class_names[class_name]\n if depth <= max_depth + 1:\n info_fmt = ''\n info_fmt_left = info_fmt\n info_fmt_right = info_fmt\n if tree_.feature[node] != _tree.TREE_UNDEFINED:\n name = feature_names_[node]\n threshold = tree_.threshold[node]\n threshold = '{1:.{0}f}'.format(decimals, threshold)\n export_text.report += right_child_fmt.format(indent, name, threshold)\n export_text.report += info_fmt_left\n print_tree_recurse(tree_.children_left[node], depth + 1)\n export_text.report += left_child_fmt.format(indent, name, threshold)\n export_text.report += info_fmt_right\n print_tree_recurse(tree_.children_right[node], depth + 1)\n else:\n _add_leaf(value, class_name, indent)\n else:\n subtree_depth = _compute_depth(tree_, node)\n if subtree_depth == 1:\n _add_leaf(value, class_name, indent)\n else:\n trunc_report = 'truncated branch of depth %d' % subtree_depth\n export_text.report += truncation_fmt.format(indent, trunc_report)\n print_tree_recurse(0, 1)\n return export_text.report" }, { "name": "plot_tree", + "unique_name": "plot_tree", "qname": "sklearn.tree._export.plot_tree", + "unique_qname": "sklearn.tree._export.plot_tree", "decorators": [], "parameters": [ { @@ -157974,7 +163602,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.tree._reingold_tilford.DrawTree.__init__", + "unique_qname": "sklearn.tree._reingold_tilford.DrawTree.__init__", "decorators": [], "parameters": [ { @@ -158036,7 +163666,9 @@ }, { "name": "__repr__", + "unique_name": "__repr__", "qname": "sklearn.tree._reingold_tilford.DrawTree.__repr__", + "unique_qname": "sklearn.tree._reingold_tilford.DrawTree.__repr__", "decorators": [], "parameters": [ { @@ -158058,7 +163690,9 @@ }, { "name": "__str__", + "unique_name": "__str__", "qname": "sklearn.tree._reingold_tilford.DrawTree.__str__", + "unique_qname": "sklearn.tree._reingold_tilford.DrawTree.__str__", "decorators": [], "parameters": [ { @@ -158080,7 +163714,9 @@ }, { "name": "get_lmost_sibling", + "unique_name": "get_lmost_sibling", "qname": "sklearn.tree._reingold_tilford.DrawTree.get_lmost_sibling", + "unique_qname": "sklearn.tree._reingold_tilford.DrawTree.get_lmost_sibling", "decorators": [], "parameters": [ { @@ -158102,7 +163738,9 @@ }, { "name": "lbrother", + "unique_name": "lbrother", "qname": "sklearn.tree._reingold_tilford.DrawTree.lbrother", + "unique_qname": "sklearn.tree._reingold_tilford.DrawTree.lbrother", "decorators": [], "parameters": [ { @@ -158124,7 +163762,9 @@ }, { "name": "left", + "unique_name": "left", "qname": "sklearn.tree._reingold_tilford.DrawTree.left", + "unique_qname": "sklearn.tree._reingold_tilford.DrawTree.left", "decorators": [], "parameters": [ { @@ -158146,7 +163786,9 @@ }, { "name": "max_extents", + "unique_name": "max_extents", "qname": "sklearn.tree._reingold_tilford.DrawTree.max_extents", + "unique_qname": "sklearn.tree._reingold_tilford.DrawTree.max_extents", "decorators": [], "parameters": [ { @@ -158168,7 +163810,9 @@ }, { "name": "right", + "unique_name": "right", "qname": "sklearn.tree._reingold_tilford.DrawTree.right", + "unique_qname": "sklearn.tree._reingold_tilford.DrawTree.right", "decorators": [], "parameters": [ { @@ -158190,7 +163834,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.tree._reingold_tilford.Tree.__init__", + "unique_qname": "sklearn.tree._reingold_tilford.Tree.__init__", "decorators": [], "parameters": [ { @@ -158232,7 +163878,9 @@ }, { "name": "ancestor", + "unique_name": "ancestor", "qname": "sklearn.tree._reingold_tilford.ancestor", + "unique_qname": "sklearn.tree._reingold_tilford.ancestor", "decorators": [], "parameters": [ { @@ -158274,7 +163922,9 @@ }, { "name": "apportion", + "unique_name": "apportion", "qname": "sklearn.tree._reingold_tilford.apportion", + "unique_qname": "sklearn.tree._reingold_tilford.apportion", "decorators": [], "parameters": [ { @@ -158316,7 +163966,9 @@ }, { "name": "buchheim", + "unique_name": "buchheim", "qname": "sklearn.tree._reingold_tilford.buchheim", + "unique_qname": "sklearn.tree._reingold_tilford.buchheim", "decorators": [], "parameters": [ { @@ -158338,7 +163990,9 @@ }, { "name": "execute_shifts", + "unique_name": "execute_shifts", "qname": "sklearn.tree._reingold_tilford.execute_shifts", + "unique_qname": "sklearn.tree._reingold_tilford.execute_shifts", "decorators": [], "parameters": [ { @@ -158360,7 +164014,9 @@ }, { "name": "first_walk", + "unique_name": "first_walk", "qname": "sklearn.tree._reingold_tilford.first_walk", + "unique_qname": "sklearn.tree._reingold_tilford.first_walk", "decorators": [], "parameters": [ { @@ -158392,7 +164048,9 @@ }, { "name": "move_subtree", + "unique_name": "move_subtree", "qname": "sklearn.tree._reingold_tilford.move_subtree", + "unique_qname": "sklearn.tree._reingold_tilford.move_subtree", "decorators": [], "parameters": [ { @@ -158434,7 +164092,9 @@ }, { "name": "second_walk", + "unique_name": "second_walk", "qname": "sklearn.tree._reingold_tilford.second_walk", + "unique_qname": "sklearn.tree._reingold_tilford.second_walk", "decorators": [], "parameters": [ { @@ -158486,7 +164146,9 @@ }, { "name": "third_walk", + "unique_name": "third_walk", "qname": "sklearn.tree._reingold_tilford.third_walk", + "unique_qname": "sklearn.tree._reingold_tilford.third_walk", "decorators": [], "parameters": [ { @@ -158518,7 +164180,9 @@ }, { "name": "configuration", + "unique_name": "configuration", "qname": "sklearn.tree.setup.configuration", + "unique_qname": "sklearn.tree.setup.configuration", "decorators": [], "parameters": [ { @@ -158550,7 +164214,9 @@ }, { "name": "__dir__", + "unique_name": "__dir__", "qname": "sklearn.utils.Bunch.__dir__", + "unique_qname": "sklearn.utils.Bunch.__dir__", "decorators": [], "parameters": [ { @@ -158572,7 +164238,9 @@ }, { "name": "__getattr__", + "unique_name": "__getattr__", "qname": "sklearn.utils.Bunch.__getattr__", + "unique_qname": "sklearn.utils.Bunch.__getattr__", "decorators": [], "parameters": [ { @@ -158604,7 +164272,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.utils.Bunch.__init__", + "unique_qname": "sklearn.utils.Bunch.__init__", "decorators": [], "parameters": [ { @@ -158626,7 +164296,9 @@ }, { "name": "__setattr__", + "unique_name": "__setattr__", "qname": "sklearn.utils.Bunch.__setattr__", + "unique_qname": "sklearn.utils.Bunch.__setattr__", "decorators": [], "parameters": [ { @@ -158668,7 +164340,9 @@ }, { "name": "__setstate__", + "unique_name": "__setstate__", "qname": "sklearn.utils.Bunch.__setstate__", + "unique_qname": "sklearn.utils.Bunch.__setstate__", "decorators": [], "parameters": [ { @@ -158700,7 +164374,9 @@ }, { "name": "_approximate_mode", + "unique_name": "_approximate_mode", "qname": "sklearn.utils._approximate_mode", + "unique_qname": "sklearn.utils._approximate_mode", "decorators": [], "parameters": [ { @@ -158742,7 +164418,9 @@ }, { "name": "_init_arpack_v0", + "unique_name": "_init_arpack_v0", "qname": "sklearn.utils._arpack._init_arpack_v0", + "unique_qname": "sklearn.utils._arpack._init_arpack_v0", "decorators": [], "parameters": [ { @@ -158774,7 +164452,9 @@ }, { "name": "_array_indexing", + "unique_name": "_array_indexing", "qname": "sklearn.utils._array_indexing", + "unique_qname": "sklearn.utils._array_indexing", "decorators": [], "parameters": [ { @@ -158826,7 +164506,9 @@ }, { "name": "_chunk_generator", + "unique_name": "_chunk_generator", "qname": "sklearn.utils._chunk_generator", + "unique_qname": "sklearn.utils._chunk_generator", "decorators": [], "parameters": [ { @@ -158858,7 +164540,9 @@ }, { "name": "_determine_key_type", + "unique_name": "_determine_key_type", "qname": "sklearn.utils._determine_key_type", + "unique_qname": "sklearn.utils._determine_key_type", "decorators": [], "parameters": [ { @@ -158890,7 +164574,9 @@ }, { "name": "to_list", + "unique_name": "to_list", "qname": "sklearn.utils._encode.MissingValues.to_list", + "unique_qname": "sklearn.utils._encode.MissingValues.to_list", "decorators": [], "parameters": [ { @@ -158912,7 +164598,9 @@ }, { "name": "_check_unknown", + "unique_name": "_check_unknown", "qname": "sklearn.utils._encode._check_unknown", + "unique_qname": "sklearn.utils._encode._check_unknown", "decorators": [], "parameters": [ { @@ -158954,7 +164642,9 @@ }, { "name": "_encode", + "unique_name": "_encode", "qname": "sklearn.utils._encode._encode", + "unique_qname": "sklearn.utils._encode._encode", "decorators": [], "parameters": [ { @@ -158996,7 +164686,9 @@ }, { "name": "_extract_missing", + "unique_name": "_extract_missing", "qname": "sklearn.utils._encode._extract_missing", + "unique_qname": "sklearn.utils._encode._extract_missing", "decorators": [], "parameters": [ { @@ -159018,7 +164710,9 @@ }, { "name": "_map_to_integer", + "unique_name": "_map_to_integer", "qname": "sklearn.utils._encode._map_to_integer", + "unique_qname": "sklearn.utils._encode._map_to_integer", "decorators": [], "parameters": [ { @@ -159050,7 +164744,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.utils._encode._nandict.__init__", + "unique_qname": "sklearn.utils._encode._nandict.__init__", "decorators": [], "parameters": [ { @@ -159082,7 +164778,9 @@ }, { "name": "__missing__", + "unique_name": "__missing__", "qname": "sklearn.utils._encode._nandict.__missing__", + "unique_qname": "sklearn.utils._encode._nandict.__missing__", "decorators": [], "parameters": [ { @@ -159114,7 +164812,9 @@ }, { "name": "_unique", + "unique_name": "_unique", "qname": "sklearn.utils._encode._unique", + "unique_qname": "sklearn.utils._encode._unique", "decorators": [], "parameters": [ { @@ -159146,7 +164846,9 @@ }, { "name": "_unique_python", + "unique_name": "_unique_python", "qname": "sklearn.utils._encode._unique_python", + "unique_qname": "sklearn.utils._encode._unique_python", "decorators": [], "parameters": [ { @@ -159178,7 +164880,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.utils._estimator_html_repr._VisualBlock.__init__", + "unique_qname": "sklearn.utils._estimator_html_repr._VisualBlock.__init__", "decorators": [], "parameters": [ { @@ -159250,7 +164954,9 @@ }, { "name": "_sk_visual_block_", + "unique_name": "_sk_visual_block_", "qname": "sklearn.utils._estimator_html_repr._VisualBlock._sk_visual_block_", + "unique_qname": "sklearn.utils._estimator_html_repr._VisualBlock._sk_visual_block_", "decorators": [], "parameters": [ { @@ -159272,7 +164978,9 @@ }, { "name": "_get_visual_block", + "unique_name": "_get_visual_block", "qname": "sklearn.utils._estimator_html_repr._get_visual_block", + "unique_qname": "sklearn.utils._estimator_html_repr._get_visual_block", "decorators": [], "parameters": [ { @@ -159294,7 +165002,9 @@ }, { "name": "_write_estimator_html", + "unique_name": "_write_estimator_html", "qname": "sklearn.utils._estimator_html_repr._write_estimator_html", + "unique_qname": "sklearn.utils._estimator_html_repr._write_estimator_html", "decorators": [], "parameters": [ { @@ -159356,7 +165066,9 @@ }, { "name": "_write_label_html", + "unique_name": "_write_label_html", "qname": "sklearn.utils._estimator_html_repr._write_label_html", + "unique_qname": "sklearn.utils._estimator_html_repr._write_label_html", "decorators": [], "parameters": [ { @@ -159428,7 +165140,9 @@ }, { "name": "estimator_html_repr", + "unique_name": "estimator_html_repr", "qname": "sklearn.utils._estimator_html_repr.estimator_html_repr", + "unique_qname": "sklearn.utils._estimator_html_repr.estimator_html_repr", "decorators": [], "parameters": [ { @@ -159450,7 +165164,9 @@ }, { "name": "_get_column_indices", + "unique_name": "_get_column_indices", "qname": "sklearn.utils._get_column_indices", + "unique_qname": "sklearn.utils._get_column_indices", "decorators": [], "parameters": [ { @@ -159482,7 +165198,9 @@ }, { "name": "_list_indexing", + "unique_name": "_list_indexing", "qname": "sklearn.utils._list_indexing", + "unique_qname": "sklearn.utils._list_indexing", "decorators": [], "parameters": [ { @@ -159524,7 +165242,9 @@ }, { "name": "_get_dense_mask", + "unique_name": "_get_dense_mask", "qname": "sklearn.utils._mask._get_dense_mask", + "unique_qname": "sklearn.utils._mask._get_dense_mask", "decorators": [], "parameters": [ { @@ -159556,7 +165276,9 @@ }, { "name": "_get_mask", + "unique_name": "_get_mask", "qname": "sklearn.utils._mask._get_mask", + "unique_qname": "sklearn.utils._mask._get_mask", "decorators": [], "parameters": [ { @@ -159588,7 +165310,9 @@ }, { "name": "_message_with_time", + "unique_name": "_message_with_time", "qname": "sklearn.utils._message_with_time", + "unique_qname": "sklearn.utils._message_with_time", "decorators": [], "parameters": [ { @@ -159630,7 +165354,9 @@ }, { "name": "__getitem__", + "unique_name": "__getitem__", "qname": "sklearn.utils._mocking.ArraySlicingWrapper.__getitem__", + "unique_qname": "sklearn.utils._mocking.ArraySlicingWrapper.__getitem__", "decorators": [], "parameters": [ { @@ -159662,7 +165388,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.utils._mocking.ArraySlicingWrapper.__init__", + "unique_qname": "sklearn.utils._mocking.ArraySlicingWrapper.__init__", "decorators": [], "parameters": [ { @@ -159694,7 +165422,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.utils._mocking.CheckingClassifier.__init__", + "unique_qname": "sklearn.utils._mocking.CheckingClassifier.__init__", "decorators": [], "parameters": [ { @@ -159786,7 +165516,9 @@ }, { "name": "_check_X_y", + "unique_name": "_check_X_y", "qname": "sklearn.utils._mocking.CheckingClassifier._check_X_y", + "unique_qname": "sklearn.utils._mocking.CheckingClassifier._check_X_y", "decorators": [], "parameters": [ { @@ -159838,7 +165570,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.utils._mocking.CheckingClassifier._more_tags", + "unique_qname": "sklearn.utils._mocking.CheckingClassifier._more_tags", "decorators": [], "parameters": [ { @@ -159860,7 +165594,9 @@ }, { "name": "decision_function", + "unique_name": "decision_function", "qname": "sklearn.utils._mocking.CheckingClassifier.decision_function", + "unique_qname": "sklearn.utils._mocking.CheckingClassifier.decision_function", "decorators": [], "parameters": [ { @@ -159892,7 +165628,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.utils._mocking.CheckingClassifier.fit", + "unique_qname": "sklearn.utils._mocking.CheckingClassifier.fit", "decorators": [], "parameters": [ { @@ -159934,7 +165672,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.utils._mocking.CheckingClassifier.predict", + "unique_qname": "sklearn.utils._mocking.CheckingClassifier.predict", "decorators": [], "parameters": [ { @@ -159966,7 +165706,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.utils._mocking.CheckingClassifier.predict_proba", + "unique_qname": "sklearn.utils._mocking.CheckingClassifier.predict_proba", "decorators": [], "parameters": [ { @@ -159998,7 +165740,9 @@ }, { "name": "score", + "unique_name": "score", "qname": "sklearn.utils._mocking.CheckingClassifier.score", + "unique_qname": "sklearn.utils._mocking.CheckingClassifier.score", "decorators": [], "parameters": [ { @@ -160040,7 +165784,9 @@ }, { "name": "__array__", + "unique_name": "__array__", "qname": "sklearn.utils._mocking.MockDataFrame.__array__", + "unique_qname": "sklearn.utils._mocking.MockDataFrame.__array__", "decorators": [], "parameters": [ { @@ -160072,7 +165818,9 @@ }, { "name": "__eq__", + "unique_name": "__eq__", "qname": "sklearn.utils._mocking.MockDataFrame.__eq__", + "unique_qname": "sklearn.utils._mocking.MockDataFrame.__eq__", "decorators": [], "parameters": [ { @@ -160104,7 +165852,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.utils._mocking.MockDataFrame.__init__", + "unique_qname": "sklearn.utils._mocking.MockDataFrame.__init__", "decorators": [], "parameters": [ { @@ -160136,7 +165886,9 @@ }, { "name": "__len__", + "unique_name": "__len__", "qname": "sklearn.utils._mocking.MockDataFrame.__len__", + "unique_qname": "sklearn.utils._mocking.MockDataFrame.__len__", "decorators": [], "parameters": [ { @@ -160158,7 +165910,9 @@ }, { "name": "__ne__", + "unique_name": "__ne__", "qname": "sklearn.utils._mocking.MockDataFrame.__ne__", + "unique_qname": "sklearn.utils._mocking.MockDataFrame.__ne__", "decorators": [], "parameters": [ { @@ -160190,7 +165944,9 @@ }, { "name": "take", + "unique_name": "take", "qname": "sklearn.utils._mocking.MockDataFrame.take", + "unique_qname": "sklearn.utils._mocking.MockDataFrame.take", "decorators": [], "parameters": [ { @@ -160232,7 +165988,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.utils._mocking.NoSampleWeightWrapper.__init__", + "unique_qname": "sklearn.utils._mocking.NoSampleWeightWrapper.__init__", "decorators": [], "parameters": [ { @@ -160264,7 +166022,9 @@ }, { "name": "_more_tags", + "unique_name": "_more_tags", "qname": "sklearn.utils._mocking.NoSampleWeightWrapper._more_tags", + "unique_qname": "sklearn.utils._mocking.NoSampleWeightWrapper._more_tags", "decorators": [], "parameters": [ { @@ -160286,7 +166046,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.utils._mocking.NoSampleWeightWrapper.fit", + "unique_qname": "sklearn.utils._mocking.NoSampleWeightWrapper.fit", "decorators": [], "parameters": [ { @@ -160328,7 +166090,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.utils._mocking.NoSampleWeightWrapper.predict", + "unique_qname": "sklearn.utils._mocking.NoSampleWeightWrapper.predict", "decorators": [], "parameters": [ { @@ -160360,7 +166124,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.utils._mocking.NoSampleWeightWrapper.predict_proba", + "unique_qname": "sklearn.utils._mocking.NoSampleWeightWrapper.predict_proba", "decorators": [], "parameters": [ { @@ -160392,7 +166158,9 @@ }, { "name": "_pandas_indexing", + "unique_name": "_pandas_indexing", "qname": "sklearn.utils._pandas_indexing", + "unique_qname": "sklearn.utils._pandas_indexing", "decorators": [], "parameters": [ { @@ -160444,7 +166212,9 @@ }, { "name": "__repr__", + "unique_name": "__repr__", "qname": "sklearn.utils._pprint.KeyValTuple.__repr__", + "unique_qname": "sklearn.utils._pprint.KeyValTuple.__repr__", "decorators": [], "parameters": [ { @@ -160466,7 +166236,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.utils._pprint._EstimatorPrettyPrinter.__init__", + "unique_qname": "sklearn.utils._pprint._EstimatorPrettyPrinter.__init__", "decorators": [], "parameters": [ { @@ -160558,7 +166330,9 @@ }, { "name": "_format_dict_items", + "unique_name": "_format_dict_items", "qname": "sklearn.utils._pprint._EstimatorPrettyPrinter._format_dict_items", + "unique_qname": "sklearn.utils._pprint._EstimatorPrettyPrinter._format_dict_items", "decorators": [], "parameters": [ { @@ -160640,7 +166414,9 @@ }, { "name": "_format_items", + "unique_name": "_format_items", "qname": "sklearn.utils._pprint._EstimatorPrettyPrinter._format_items", + "unique_qname": "sklearn.utils._pprint._EstimatorPrettyPrinter._format_items", "decorators": [], "parameters": [ { @@ -160722,7 +166498,9 @@ }, { "name": "_format_params", + "unique_name": "_format_params", "qname": "sklearn.utils._pprint._EstimatorPrettyPrinter._format_params", + "unique_qname": "sklearn.utils._pprint._EstimatorPrettyPrinter._format_params", "decorators": [], "parameters": [ { @@ -160804,7 +166582,9 @@ }, { "name": "_format_params_or_dict_items", + "unique_name": "_format_params_or_dict_items", "qname": "sklearn.utils._pprint._EstimatorPrettyPrinter._format_params_or_dict_items", + "unique_qname": "sklearn.utils._pprint._EstimatorPrettyPrinter._format_params_or_dict_items", "decorators": [], "parameters": [ { @@ -160896,7 +166676,9 @@ }, { "name": "_pprint_estimator", + "unique_name": "_pprint_estimator", "qname": "sklearn.utils._pprint._EstimatorPrettyPrinter._pprint_estimator", + "unique_qname": "sklearn.utils._pprint._EstimatorPrettyPrinter._pprint_estimator", "decorators": [], "parameters": [ { @@ -160978,7 +166760,9 @@ }, { "name": "_pprint_key_val_tuple", + "unique_name": "_pprint_key_val_tuple", "qname": "sklearn.utils._pprint._EstimatorPrettyPrinter._pprint_key_val_tuple", + "unique_qname": "sklearn.utils._pprint._EstimatorPrettyPrinter._pprint_key_val_tuple", "decorators": [], "parameters": [ { @@ -161060,7 +166844,9 @@ }, { "name": "format", + "unique_name": "format", "qname": "sklearn.utils._pprint._EstimatorPrettyPrinter.format", + "unique_qname": "sklearn.utils._pprint._EstimatorPrettyPrinter.format", "decorators": [], "parameters": [ { @@ -161122,7 +166908,9 @@ }, { "name": "_changed_params", + "unique_name": "_changed_params", "qname": "sklearn.utils._pprint._changed_params", + "unique_qname": "sklearn.utils._pprint._changed_params", "decorators": [], "parameters": [ { @@ -161144,7 +166932,9 @@ }, { "name": "_safe_repr", + "unique_name": "_safe_repr", "qname": "sklearn.utils._pprint._safe_repr", + "unique_qname": "sklearn.utils._pprint._safe_repr", "decorators": [], "parameters": [ { @@ -161206,7 +166996,9 @@ }, { "name": "_print_elapsed_time", + "unique_name": "_print_elapsed_time", "qname": "sklearn.utils._print_elapsed_time", + "unique_qname": "sklearn.utils._print_elapsed_time", "decorators": ["contextmanager"], "parameters": [ { @@ -161238,7 +167030,9 @@ }, { "name": "_safe_indexing", + "unique_name": "_safe_indexing", "qname": "sklearn.utils._safe_indexing", + "unique_qname": "sklearn.utils._safe_indexing", "decorators": [], "parameters": [ { @@ -161280,7 +167074,9 @@ }, { "name": "_get_deps_info", + "unique_name": "_get_deps_info", "qname": "sklearn.utils._show_versions._get_deps_info", + "unique_qname": "sklearn.utils._show_versions._get_deps_info", "decorators": [], "parameters": [], "results": [], @@ -161291,7 +167087,9 @@ }, { "name": "_get_sys_info", + "unique_name": "_get_sys_info", "qname": "sklearn.utils._show_versions._get_sys_info", + "unique_qname": "sklearn.utils._show_versions._get_sys_info", "decorators": [], "parameters": [], "results": [], @@ -161302,7 +167100,9 @@ }, { "name": "show_versions", + "unique_name": "show_versions", "qname": "sklearn.utils._show_versions.show_versions", + "unique_qname": "sklearn.utils._show_versions.show_versions", "decorators": [], "parameters": [], "results": [], @@ -161313,7 +167113,9 @@ }, { "name": "_safe_tags", + "unique_name": "_safe_tags", "qname": "sklearn.utils._tags._safe_tags", + "unique_qname": "sklearn.utils._tags._safe_tags", "decorators": [], "parameters": [ { @@ -161345,7 +167147,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.utils._testing.MinimalClassifier.__init__", + "unique_qname": "sklearn.utils._testing.MinimalClassifier.__init__", "decorators": [], "parameters": [ { @@ -161377,7 +167181,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.utils._testing.MinimalClassifier.fit", + "unique_qname": "sklearn.utils._testing.MinimalClassifier.fit", "decorators": [], "parameters": [ { @@ -161419,7 +167225,9 @@ }, { "name": "get_params", + "unique_name": "get_params", "qname": "sklearn.utils._testing.MinimalClassifier.get_params", + "unique_qname": "sklearn.utils._testing.MinimalClassifier.get_params", "decorators": [], "parameters": [ { @@ -161451,7 +167259,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.utils._testing.MinimalClassifier.predict", + "unique_qname": "sklearn.utils._testing.MinimalClassifier.predict", "decorators": [], "parameters": [ { @@ -161483,7 +167293,9 @@ }, { "name": "predict_proba", + "unique_name": "predict_proba", "qname": "sklearn.utils._testing.MinimalClassifier.predict_proba", + "unique_qname": "sklearn.utils._testing.MinimalClassifier.predict_proba", "decorators": [], "parameters": [ { @@ -161515,7 +167327,9 @@ }, { "name": "score", + "unique_name": "score", "qname": "sklearn.utils._testing.MinimalClassifier.score", + "unique_qname": "sklearn.utils._testing.MinimalClassifier.score", "decorators": [], "parameters": [ { @@ -161557,7 +167371,9 @@ }, { "name": "set_params", + "unique_name": "set_params", "qname": "sklearn.utils._testing.MinimalClassifier.set_params", + "unique_qname": "sklearn.utils._testing.MinimalClassifier.set_params", "decorators": [], "parameters": [ { @@ -161579,7 +167395,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.utils._testing.MinimalRegressor.__init__", + "unique_qname": "sklearn.utils._testing.MinimalRegressor.__init__", "decorators": [], "parameters": [ { @@ -161611,7 +167429,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.utils._testing.MinimalRegressor.fit", + "unique_qname": "sklearn.utils._testing.MinimalRegressor.fit", "decorators": [], "parameters": [ { @@ -161653,7 +167473,9 @@ }, { "name": "get_params", + "unique_name": "get_params", "qname": "sklearn.utils._testing.MinimalRegressor.get_params", + "unique_qname": "sklearn.utils._testing.MinimalRegressor.get_params", "decorators": [], "parameters": [ { @@ -161685,7 +167507,9 @@ }, { "name": "predict", + "unique_name": "predict", "qname": "sklearn.utils._testing.MinimalRegressor.predict", + "unique_qname": "sklearn.utils._testing.MinimalRegressor.predict", "decorators": [], "parameters": [ { @@ -161717,7 +167541,9 @@ }, { "name": "score", + "unique_name": "score", "qname": "sklearn.utils._testing.MinimalRegressor.score", + "unique_qname": "sklearn.utils._testing.MinimalRegressor.score", "decorators": [], "parameters": [ { @@ -161759,7 +167585,9 @@ }, { "name": "set_params", + "unique_name": "set_params", "qname": "sklearn.utils._testing.MinimalRegressor.set_params", + "unique_qname": "sklearn.utils._testing.MinimalRegressor.set_params", "decorators": [], "parameters": [ { @@ -161781,7 +167609,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.utils._testing.MinimalTransformer.__init__", + "unique_qname": "sklearn.utils._testing.MinimalTransformer.__init__", "decorators": [], "parameters": [ { @@ -161813,7 +167643,9 @@ }, { "name": "fit", + "unique_name": "fit", "qname": "sklearn.utils._testing.MinimalTransformer.fit", + "unique_qname": "sklearn.utils._testing.MinimalTransformer.fit", "decorators": [], "parameters": [ { @@ -161855,7 +167687,9 @@ }, { "name": "fit_transform", + "unique_name": "fit_transform", "qname": "sklearn.utils._testing.MinimalTransformer.fit_transform", + "unique_qname": "sklearn.utils._testing.MinimalTransformer.fit_transform", "decorators": [], "parameters": [ { @@ -161897,7 +167731,9 @@ }, { "name": "get_params", + "unique_name": "get_params", "qname": "sklearn.utils._testing.MinimalTransformer.get_params", + "unique_qname": "sklearn.utils._testing.MinimalTransformer.get_params", "decorators": [], "parameters": [ { @@ -161929,7 +167765,9 @@ }, { "name": "set_params", + "unique_name": "set_params", "qname": "sklearn.utils._testing.MinimalTransformer.set_params", + "unique_qname": "sklearn.utils._testing.MinimalTransformer.set_params", "decorators": [], "parameters": [ { @@ -161951,7 +167789,9 @@ }, { "name": "transform", + "unique_name": "transform", "qname": "sklearn.utils._testing.MinimalTransformer.transform", + "unique_qname": "sklearn.utils._testing.MinimalTransformer.transform", "decorators": [], "parameters": [ { @@ -161993,7 +167833,9 @@ }, { "name": "__enter__", + "unique_name": "__enter__", "qname": "sklearn.utils._testing.TempMemmap.__enter__", + "unique_qname": "sklearn.utils._testing.TempMemmap.__enter__", "decorators": [], "parameters": [ { @@ -162015,7 +167857,9 @@ }, { "name": "__exit__", + "unique_name": "__exit__", "qname": "sklearn.utils._testing.TempMemmap.__exit__", + "unique_qname": "sklearn.utils._testing.TempMemmap.__exit__", "decorators": [], "parameters": [ { @@ -162067,7 +167911,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.utils._testing.TempMemmap.__init__", + "unique_qname": "sklearn.utils._testing.TempMemmap.__init__", "decorators": [], "parameters": [ { @@ -162109,7 +167955,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.utils._testing._IgnoreWarnings.__call__", + "unique_qname": "sklearn.utils._testing._IgnoreWarnings.__call__", "decorators": [], "parameters": [ { @@ -162141,7 +167989,9 @@ }, { "name": "__enter__", + "unique_name": "__enter__", "qname": "sklearn.utils._testing._IgnoreWarnings.__enter__", + "unique_qname": "sklearn.utils._testing._IgnoreWarnings.__enter__", "decorators": [], "parameters": [ { @@ -162163,7 +168013,9 @@ }, { "name": "__exit__", + "unique_name": "__exit__", "qname": "sklearn.utils._testing._IgnoreWarnings.__exit__", + "unique_qname": "sklearn.utils._testing._IgnoreWarnings.__exit__", "decorators": [], "parameters": [ { @@ -162185,7 +168037,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.utils._testing._IgnoreWarnings.__init__", + "unique_qname": "sklearn.utils._testing._IgnoreWarnings.__init__", "decorators": [], "parameters": [ { @@ -162217,7 +168071,9 @@ }, { "name": "__repr__", + "unique_name": "__repr__", "qname": "sklearn.utils._testing._IgnoreWarnings.__repr__", + "unique_qname": "sklearn.utils._testing._IgnoreWarnings.__repr__", "decorators": [], "parameters": [ { @@ -162239,7 +168095,9 @@ }, { "name": "__exit__", + "unique_name": "__exit__", "qname": "sklearn.utils._testing._Raises.__exit__", + "unique_qname": "sklearn.utils._testing._Raises.__exit__", "decorators": [], "parameters": [ { @@ -162291,7 +168149,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.utils._testing._Raises.__init__", + "unique_qname": "sklearn.utils._testing._Raises.__init__", "decorators": [], "parameters": [ { @@ -162353,7 +168213,9 @@ }, { "name": "_convert_container", + "unique_name": "_convert_container", "qname": "sklearn.utils._testing._convert_container", + "unique_qname": "sklearn.utils._testing._convert_container", "decorators": [], "parameters": [ { @@ -162405,7 +168267,9 @@ }, { "name": "_delete_folder", + "unique_name": "_delete_folder", "qname": "sklearn.utils._testing._delete_folder", + "unique_qname": "sklearn.utils._testing._delete_folder", "decorators": [], "parameters": [ { @@ -162437,7 +168301,9 @@ }, { "name": "_get_args", + "unique_name": "_get_args", "qname": "sklearn.utils._testing._get_args", + "unique_qname": "sklearn.utils._testing._get_args", "decorators": [], "parameters": [ { @@ -162469,7 +168335,9 @@ }, { "name": "_get_func_name", + "unique_name": "_get_func_name", "qname": "sklearn.utils._testing._get_func_name", + "unique_qname": "sklearn.utils._testing._get_func_name", "decorators": [], "parameters": [ { @@ -162491,7 +168359,9 @@ }, { "name": "assert_allclose_dense_sparse", + "unique_name": "assert_allclose_dense_sparse", "qname": "sklearn.utils._testing.assert_allclose_dense_sparse", + "unique_qname": "sklearn.utils._testing.assert_allclose_dense_sparse", "decorators": [], "parameters": [ { @@ -162553,7 +168423,9 @@ }, { "name": "assert_no_warnings", + "unique_name": "assert_no_warnings", "qname": "sklearn.utils._testing.assert_no_warnings", + "unique_qname": "sklearn.utils._testing.assert_no_warnings", "decorators": [], "parameters": [ { @@ -162575,7 +168447,9 @@ }, { "name": "assert_raise_message", + "unique_name": "assert_raise_message", "qname": "sklearn.utils._testing.assert_raise_message", + "unique_qname": "sklearn.utils._testing.assert_raise_message", "decorators": [], "parameters": [ { @@ -162617,7 +168491,9 @@ }, { "name": "assert_run_python_script", + "unique_name": "assert_run_python_script", "qname": "sklearn.utils._testing.assert_run_python_script", + "unique_qname": "sklearn.utils._testing.assert_run_python_script", "decorators": [], "parameters": [ { @@ -162649,7 +168525,9 @@ }, { "name": "assert_warns", + "unique_name": "assert_warns", "qname": "sklearn.utils._testing.assert_warns", + "unique_qname": "sklearn.utils._testing.assert_warns", "decorators": [ "deprecated('`assert_warns` is deprecated in 1.0 and will be removed in 1.2.Use `pytest.warns` instead.')" ], @@ -162683,7 +168561,9 @@ }, { "name": "assert_warns_message", + "unique_name": "assert_warns_message", "qname": "sklearn.utils._testing.assert_warns_message", + "unique_qname": "sklearn.utils._testing.assert_warns_message", "decorators": [ "deprecated('`assert_warns_message` is deprecated in 1.0 and will be removed in 1.2.Use `pytest.warns` instead.')" ], @@ -162727,7 +168607,9 @@ }, { "name": "check_docstring_parameters", + "unique_name": "check_docstring_parameters", "qname": "sklearn.utils._testing.check_docstring_parameters", + "unique_qname": "sklearn.utils._testing.check_docstring_parameters", "decorators": [], "parameters": [ { @@ -162769,7 +168651,9 @@ }, { "name": "check_skip_network", + "unique_name": "check_skip_network", "qname": "sklearn.utils._testing.check_skip_network", + "unique_qname": "sklearn.utils._testing.check_skip_network", "decorators": [], "parameters": [], "results": [], @@ -162780,7 +168664,9 @@ }, { "name": "create_memmap_backed_data", + "unique_name": "create_memmap_backed_data", "qname": "sklearn.utils._testing.create_memmap_backed_data", + "unique_qname": "sklearn.utils._testing.create_memmap_backed_data", "decorators": [], "parameters": [ { @@ -162822,7 +168708,9 @@ }, { "name": "ignore_warnings", + "unique_name": "ignore_warnings", "qname": "sklearn.utils._testing.ignore_warnings", + "unique_qname": "sklearn.utils._testing.ignore_warnings", "decorators": [], "parameters": [ { @@ -162849,12 +168737,14 @@ "results": [], "is_public": false, "description": "Context manager and decorator to ignore warnings.\n\nNote: Using this (in both variants) will clear all warnings from all python modules loaded. In case you need to test cross-module-warning-logging, this is not your tool of choice.", - "docstring": "Context manager and decorator to ignore warnings.\n\nNote: Using this (in both variants) will clear all warnings\nfrom all python modules loaded. In case you need to test\ncross-module-warning-logging, this is not your tool of choice.\n\nParameters\n----------\nobj : callable, default=None\n callable where you want to ignore the warnings.\ncategory : warning class, default=Warning\n The category to filter. If Warning, all categories will be muted.\n\nExamples\n--------\n>>> with ignore_warnings():\n... warnings.warn('buhuhuhu')\n\n>>> def nasty_warn():\n... warnings.warn('buhuhuhu')\n... print(42)\n\n>>> ignore_warnings(nasty_warn)()\n42", - "source_code": "\ndef ignore_warnings(obj=None, category=Warning):\n \"\"\"Context manager and decorator to ignore warnings.\n\n Note: Using this (in both variants) will clear all warnings\n from all python modules loaded. In case you need to test\n cross-module-warning-logging, this is not your tool of choice.\n\n Parameters\n ----------\n obj : callable, default=None\n callable where you want to ignore the warnings.\n category : warning class, default=Warning\n The category to filter. If Warning, all categories will be muted.\n\n Examples\n --------\n >>> with ignore_warnings():\n ... warnings.warn('buhuhuhu')\n\n >>> def nasty_warn():\n ... warnings.warn('buhuhuhu')\n ... print(42)\n\n >>> ignore_warnings(nasty_warn)()\n 42\n \"\"\"\n if isinstance(obj, type) and issubclass(obj, Warning):\n warning_name = obj.__name__\n raise ValueError(\"'obj' should be a callable where you want to ignore warnings. You passed a warning class instead: 'obj={warning_name}'. If you want to pass a warning class to ignore_warnings, you should use 'category={warning_name}'\".format(warning_name=warning_name))\n elif callable(obj):\n return _IgnoreWarnings(category=category)(obj)\n else:\n return _IgnoreWarnings(category=category)" + "docstring": "Context manager and decorator to ignore warnings.\n\nNote: Using this (in both variants) will clear all warnings\nfrom all python modules loaded. In case you need to test\ncross-module-warning-logging, this is not your tool of choice.\n\nParameters\n----------\nobj : callable, default=None\n callable where you want to ignore the warnings.\ncategory : warning class, default=Warning\n The category to filter. If Warning, all categories will be muted.\n\nExamples\n--------\n>>> import warnings\n>>> from sklearn.utils._testing import ignore_warnings\n>>> with ignore_warnings():\n... warnings.warn('buhuhuhu')\n\n>>> def nasty_warn():\n... warnings.warn('buhuhuhu')\n... print(42)\n\n>>> ignore_warnings(nasty_warn)()\n42", + "source_code": "\ndef ignore_warnings(obj=None, category=Warning):\n \"\"\"Context manager and decorator to ignore warnings.\n\n Note: Using this (in both variants) will clear all warnings\n from all python modules loaded. In case you need to test\n cross-module-warning-logging, this is not your tool of choice.\n\n Parameters\n ----------\n obj : callable, default=None\n callable where you want to ignore the warnings.\n category : warning class, default=Warning\n The category to filter. If Warning, all categories will be muted.\n\n Examples\n --------\n >>> import warnings\n >>> from sklearn.utils._testing import ignore_warnings\n >>> with ignore_warnings():\n ... warnings.warn('buhuhuhu')\n\n >>> def nasty_warn():\n ... warnings.warn('buhuhuhu')\n ... print(42)\n\n >>> ignore_warnings(nasty_warn)()\n 42\n \"\"\"\n if isinstance(obj, type) and issubclass(obj, Warning):\n warning_name = obj.__name__\n raise ValueError(\"'obj' should be a callable where you want to ignore warnings. You passed a warning class instead: 'obj={warning_name}'. If you want to pass a warning class to ignore_warnings, you should use 'category={warning_name}'\".format(warning_name=warning_name))\n elif callable(obj):\n return _IgnoreWarnings(category=category)(obj)\n else:\n return _IgnoreWarnings(category=category)" }, { "name": "raises", + "unique_name": "raises", "qname": "sklearn.utils._testing.raises", + "unique_qname": "sklearn.utils._testing.raises", "decorators": [], "parameters": [ { @@ -162906,7 +168796,9 @@ }, { "name": "set_random_state", + "unique_name": "set_random_state", "qname": "sklearn.utils._testing.set_random_state", + "unique_qname": "sklearn.utils._testing.set_random_state", "decorators": [], "parameters": [ { @@ -162938,7 +168830,9 @@ }, { "name": "_to_object_array", + "unique_name": "_to_object_array", "qname": "sklearn.utils._to_object_array", + "unique_qname": "sklearn.utils._to_object_array", "decorators": [], "parameters": [ { @@ -162960,7 +168854,9 @@ }, { "name": "all_estimators", + "unique_name": "all_estimators", "qname": "sklearn.utils.all_estimators", + "unique_qname": "sklearn.utils.all_estimators", "decorators": [], "parameters": [ { @@ -162982,7 +168878,9 @@ }, { "name": "axis0_safe_slice", + "unique_name": "axis0_safe_slice", "qname": "sklearn.utils.axis0_safe_slice", + "unique_qname": "sklearn.utils.axis0_safe_slice", "decorators": [], "parameters": [ { @@ -163024,7 +168922,9 @@ }, { "name": "check_matplotlib_support", + "unique_name": "check_matplotlib_support", "qname": "sklearn.utils.check_matplotlib_support", + "unique_qname": "sklearn.utils.check_matplotlib_support", "decorators": [], "parameters": [ { @@ -163046,7 +168946,9 @@ }, { "name": "check_pandas_support", + "unique_name": "check_pandas_support", "qname": "sklearn.utils.check_pandas_support", + "unique_qname": "sklearn.utils.check_pandas_support", "decorators": [], "parameters": [ { @@ -163068,7 +168970,9 @@ }, { "name": "compute_class_weight", + "unique_name": "compute_class_weight", "qname": "sklearn.utils.class_weight.compute_class_weight", + "unique_qname": "sklearn.utils.class_weight.compute_class_weight", "decorators": [], "parameters": [ { @@ -163110,7 +169014,9 @@ }, { "name": "compute_sample_weight", + "unique_name": "compute_sample_weight", "qname": "sklearn.utils.class_weight.compute_sample_weight", + "unique_qname": "sklearn.utils.class_weight.compute_sample_weight", "decorators": [], "parameters": [ { @@ -163152,7 +169058,9 @@ }, { "name": "_is_deprecated", + "unique_name": "_is_deprecated", "qname": "sklearn.utils.deprecation._is_deprecated", + "unique_qname": "sklearn.utils.deprecation._is_deprecated", "decorators": [], "parameters": [ { @@ -163174,7 +169082,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.utils.deprecation.deprecated.__call__", + "unique_qname": "sklearn.utils.deprecation.deprecated.__call__", "decorators": [], "parameters": [ { @@ -163206,7 +169116,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.utils.deprecation.deprecated.__init__", + "unique_qname": "sklearn.utils.deprecation.deprecated.__init__", "decorators": [], "parameters": [ { @@ -163238,7 +169150,9 @@ }, { "name": "_decorate_class", + "unique_name": "_decorate_class", "qname": "sklearn.utils.deprecation.deprecated._decorate_class", + "unique_qname": "sklearn.utils.deprecation.deprecated._decorate_class", "decorators": [], "parameters": [ { @@ -163270,7 +169184,9 @@ }, { "name": "_decorate_fun", + "unique_name": "_decorate_fun", "qname": "sklearn.utils.deprecation.deprecated._decorate_fun", + "unique_qname": "sklearn.utils.deprecation.deprecated._decorate_fun", "decorators": [], "parameters": [ { @@ -163302,7 +169218,9 @@ }, { "name": "_decorate_property", + "unique_name": "_decorate_property", "qname": "sklearn.utils.deprecation.deprecated._decorate_property", + "unique_qname": "sklearn.utils.deprecation.deprecated._decorate_property", "decorators": [], "parameters": [ { @@ -163334,7 +169252,9 @@ }, { "name": "_update_doc", + "unique_name": "_update_doc", "qname": "sklearn.utils.deprecation.deprecated._update_doc", + "unique_qname": "sklearn.utils.deprecation.deprecated._update_doc", "decorators": [], "parameters": [ { @@ -163366,7 +169286,9 @@ }, { "name": "__array__", + "unique_name": "__array__", "qname": "sklearn.utils.estimator_checks._NotAnArray.__array__", + "unique_qname": "sklearn.utils.estimator_checks._NotAnArray.__array__", "decorators": [], "parameters": [ { @@ -163398,7 +169320,9 @@ }, { "name": "__array_function__", + "unique_name": "__array_function__", "qname": "sklearn.utils.estimator_checks._NotAnArray.__array_function__", + "unique_qname": "sklearn.utils.estimator_checks._NotAnArray.__array_function__", "decorators": [], "parameters": [ { @@ -163460,7 +169384,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.utils.estimator_checks._NotAnArray.__init__", + "unique_qname": "sklearn.utils.estimator_checks._NotAnArray.__init__", "decorators": [], "parameters": [ { @@ -163492,7 +169418,9 @@ }, { "name": "_apply_on_subsets", + "unique_name": "_apply_on_subsets", "qname": "sklearn.utils.estimator_checks._apply_on_subsets", + "unique_qname": "sklearn.utils.estimator_checks._apply_on_subsets", "decorators": [], "parameters": [ { @@ -163524,7 +169452,9 @@ }, { "name": "_check_transformer", + "unique_name": "_check_transformer", "qname": "sklearn.utils.estimator_checks._check_transformer", + "unique_qname": "sklearn.utils.estimator_checks._check_transformer", "decorators": [], "parameters": [ { @@ -163576,7 +169506,9 @@ }, { "name": "_choose_check_classifiers_labels", + "unique_name": "_choose_check_classifiers_labels", "qname": "sklearn.utils.estimator_checks._choose_check_classifiers_labels", + "unique_qname": "sklearn.utils.estimator_checks._choose_check_classifiers_labels", "decorators": [], "parameters": [ { @@ -163618,7 +169550,9 @@ }, { "name": "_construct_instance", + "unique_name": "_construct_instance", "qname": "sklearn.utils.estimator_checks._construct_instance", + "unique_qname": "sklearn.utils.estimator_checks._construct_instance", "decorators": [], "parameters": [ { @@ -163640,7 +169574,9 @@ }, { "name": "_enforce_estimator_tags_x", + "unique_name": "_enforce_estimator_tags_x", "qname": "sklearn.utils.estimator_checks._enforce_estimator_tags_x", + "unique_qname": "sklearn.utils.estimator_checks._enforce_estimator_tags_x", "decorators": [], "parameters": [ { @@ -163672,7 +169608,9 @@ }, { "name": "_enforce_estimator_tags_y", + "unique_name": "_enforce_estimator_tags_y", "qname": "sklearn.utils.estimator_checks._enforce_estimator_tags_y", + "unique_qname": "sklearn.utils.estimator_checks._enforce_estimator_tags_y", "decorators": [], "parameters": [ { @@ -163704,7 +169642,9 @@ }, { "name": "_generate_sparse_matrix", + "unique_name": "_generate_sparse_matrix", "qname": "sklearn.utils.estimator_checks._generate_sparse_matrix", + "unique_qname": "sklearn.utils.estimator_checks._generate_sparse_matrix", "decorators": [], "parameters": [ { @@ -163726,7 +169666,9 @@ }, { "name": "_get_check_estimator_ids", + "unique_name": "_get_check_estimator_ids", "qname": "sklearn.utils.estimator_checks._get_check_estimator_ids", + "unique_qname": "sklearn.utils.estimator_checks._get_check_estimator_ids", "decorators": [], "parameters": [ { @@ -163748,7 +169690,9 @@ }, { "name": "_is_pairwise_metric", + "unique_name": "_is_pairwise_metric", "qname": "sklearn.utils.estimator_checks._is_pairwise_metric", + "unique_qname": "sklearn.utils.estimator_checks._is_pairwise_metric", "decorators": [], "parameters": [ { @@ -163770,7 +169714,9 @@ }, { "name": "_is_public_parameter", + "unique_name": "_is_public_parameter", "qname": "sklearn.utils.estimator_checks._is_public_parameter", + "unique_qname": "sklearn.utils.estimator_checks._is_public_parameter", "decorators": [], "parameters": [ { @@ -163792,7 +169738,9 @@ }, { "name": "_maybe_mark_xfail", + "unique_name": "_maybe_mark_xfail", "qname": "sklearn.utils.estimator_checks._maybe_mark_xfail", + "unique_qname": "sklearn.utils.estimator_checks._maybe_mark_xfail", "decorators": [], "parameters": [ { @@ -163834,7 +169782,9 @@ }, { "name": "_maybe_skip", + "unique_name": "_maybe_skip", "qname": "sklearn.utils.estimator_checks._maybe_skip", + "unique_qname": "sklearn.utils.estimator_checks._maybe_skip", "decorators": [], "parameters": [ { @@ -163866,7 +169816,9 @@ }, { "name": "_pairwise_estimator_convert_X", + "unique_name": "_pairwise_estimator_convert_X", "qname": "sklearn.utils.estimator_checks._pairwise_estimator_convert_X", + "unique_qname": "sklearn.utils.estimator_checks._pairwise_estimator_convert_X", "decorators": [], "parameters": [ { @@ -163908,7 +169860,9 @@ }, { "name": "_regression_dataset", + "unique_name": "_regression_dataset", "qname": "sklearn.utils.estimator_checks._regression_dataset", + "unique_qname": "sklearn.utils.estimator_checks._regression_dataset", "decorators": [], "parameters": [], "results": [], @@ -163919,7 +169873,9 @@ }, { "name": "_set_checking_parameters", + "unique_name": "_set_checking_parameters", "qname": "sklearn.utils.estimator_checks._set_checking_parameters", + "unique_qname": "sklearn.utils.estimator_checks._set_checking_parameters", "decorators": [], "parameters": [ { @@ -163941,7 +169897,9 @@ }, { "name": "_should_be_skipped_or_marked", + "unique_name": "_should_be_skipped_or_marked", "qname": "sklearn.utils.estimator_checks._should_be_skipped_or_marked", + "unique_qname": "sklearn.utils.estimator_checks._should_be_skipped_or_marked", "decorators": [], "parameters": [ { @@ -163973,7 +169931,9 @@ }, { "name": "_yield_all_checks", + "unique_name": "_yield_all_checks", "qname": "sklearn.utils.estimator_checks._yield_all_checks", + "unique_qname": "sklearn.utils.estimator_checks._yield_all_checks", "decorators": [], "parameters": [ { @@ -163995,7 +169955,9 @@ }, { "name": "_yield_checks", + "unique_name": "_yield_checks", "qname": "sklearn.utils.estimator_checks._yield_checks", + "unique_qname": "sklearn.utils.estimator_checks._yield_checks", "decorators": [], "parameters": [ { @@ -164017,7 +169979,9 @@ }, { "name": "_yield_classifier_checks", + "unique_name": "_yield_classifier_checks", "qname": "sklearn.utils.estimator_checks._yield_classifier_checks", + "unique_qname": "sklearn.utils.estimator_checks._yield_classifier_checks", "decorators": [], "parameters": [ { @@ -164039,7 +170003,9 @@ }, { "name": "_yield_clustering_checks", + "unique_name": "_yield_clustering_checks", "qname": "sklearn.utils.estimator_checks._yield_clustering_checks", + "unique_qname": "sklearn.utils.estimator_checks._yield_clustering_checks", "decorators": [], "parameters": [ { @@ -164061,7 +170027,9 @@ }, { "name": "_yield_outliers_checks", + "unique_name": "_yield_outliers_checks", "qname": "sklearn.utils.estimator_checks._yield_outliers_checks", + "unique_qname": "sklearn.utils.estimator_checks._yield_outliers_checks", "decorators": [], "parameters": [ { @@ -164083,7 +170051,9 @@ }, { "name": "_yield_regressor_checks", + "unique_name": "_yield_regressor_checks", "qname": "sklearn.utils.estimator_checks._yield_regressor_checks", + "unique_qname": "sklearn.utils.estimator_checks._yield_regressor_checks", "decorators": [], "parameters": [ { @@ -164105,7 +170075,9 @@ }, { "name": "_yield_transformer_checks", + "unique_name": "_yield_transformer_checks", "qname": "sklearn.utils.estimator_checks._yield_transformer_checks", + "unique_qname": "sklearn.utils.estimator_checks._yield_transformer_checks", "decorators": [], "parameters": [ { @@ -164127,7 +170099,9 @@ }, { "name": "check_class_weight_balanced_classifiers", + "unique_name": "check_class_weight_balanced_classifiers", "qname": "sklearn.utils.estimator_checks.check_class_weight_balanced_classifiers", + "unique_qname": "sklearn.utils.estimator_checks.check_class_weight_balanced_classifiers", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -164209,7 +170183,9 @@ }, { "name": "check_class_weight_balanced_linear_classifier", + "unique_name": "check_class_weight_balanced_linear_classifier", "qname": "sklearn.utils.estimator_checks.check_class_weight_balanced_linear_classifier", + "unique_qname": "sklearn.utils.estimator_checks.check_class_weight_balanced_linear_classifier", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -164241,7 +170217,9 @@ }, { "name": "check_class_weight_classifiers", + "unique_name": "check_class_weight_classifiers", "qname": "sklearn.utils.estimator_checks.check_class_weight_classifiers", + "unique_qname": "sklearn.utils.estimator_checks.check_class_weight_classifiers", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -164273,7 +170251,9 @@ }, { "name": "check_classifier_data_not_an_array", + "unique_name": "check_classifier_data_not_an_array", "qname": "sklearn.utils.estimator_checks.check_classifier_data_not_an_array", + "unique_qname": "sklearn.utils.estimator_checks.check_classifier_data_not_an_array", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -164305,7 +170285,9 @@ }, { "name": "check_classifier_multioutput", + "unique_name": "check_classifier_multioutput", "qname": "sklearn.utils.estimator_checks.check_classifier_multioutput", + "unique_qname": "sklearn.utils.estimator_checks.check_classifier_multioutput", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -164337,7 +170319,9 @@ }, { "name": "check_classifiers_classes", + "unique_name": "check_classifiers_classes", "qname": "sklearn.utils.estimator_checks.check_classifiers_classes", + "unique_qname": "sklearn.utils.estimator_checks.check_classifiers_classes", "decorators": [], "parameters": [ { @@ -164369,7 +170353,9 @@ }, { "name": "check_classifiers_multilabel_output_format_decision_function", + "unique_name": "check_classifiers_multilabel_output_format_decision_function", "qname": "sklearn.utils.estimator_checks.check_classifiers_multilabel_output_format_decision_function", + "unique_qname": "sklearn.utils.estimator_checks.check_classifiers_multilabel_output_format_decision_function", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -164401,7 +170387,9 @@ }, { "name": "check_classifiers_multilabel_output_format_predict", + "unique_name": "check_classifiers_multilabel_output_format_predict", "qname": "sklearn.utils.estimator_checks.check_classifiers_multilabel_output_format_predict", + "unique_qname": "sklearn.utils.estimator_checks.check_classifiers_multilabel_output_format_predict", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -164433,7 +170421,9 @@ }, { "name": "check_classifiers_multilabel_output_format_predict_proba", + "unique_name": "check_classifiers_multilabel_output_format_predict_proba", "qname": "sklearn.utils.estimator_checks.check_classifiers_multilabel_output_format_predict_proba", + "unique_qname": "sklearn.utils.estimator_checks.check_classifiers_multilabel_output_format_predict_proba", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -164465,7 +170455,9 @@ }, { "name": "check_classifiers_multilabel_representation_invariance", + "unique_name": "check_classifiers_multilabel_representation_invariance", "qname": "sklearn.utils.estimator_checks.check_classifiers_multilabel_representation_invariance", + "unique_qname": "sklearn.utils.estimator_checks.check_classifiers_multilabel_representation_invariance", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -164497,7 +170489,9 @@ }, { "name": "check_classifiers_one_label", + "unique_name": "check_classifiers_one_label", "qname": "sklearn.utils.estimator_checks.check_classifiers_one_label", + "unique_qname": "sklearn.utils.estimator_checks.check_classifiers_one_label", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -164529,7 +170523,9 @@ }, { "name": "check_classifiers_predictions", + "unique_name": "check_classifiers_predictions", "qname": "sklearn.utils.estimator_checks.check_classifiers_predictions", + "unique_qname": "sklearn.utils.estimator_checks.check_classifiers_predictions", "decorators": ["ignore_warnings"], "parameters": [ { @@ -164581,7 +170577,9 @@ }, { "name": "check_classifiers_regression_target", + "unique_name": "check_classifiers_regression_target", "qname": "sklearn.utils.estimator_checks.check_classifiers_regression_target", + "unique_qname": "sklearn.utils.estimator_checks.check_classifiers_regression_target", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -164613,7 +170611,9 @@ }, { "name": "check_classifiers_train", + "unique_name": "check_classifiers_train", "qname": "sklearn.utils.estimator_checks.check_classifiers_train", + "unique_qname": "sklearn.utils.estimator_checks.check_classifiers_train", "decorators": ["ignore_warnings"], "parameters": [ { @@ -164665,7 +170665,9 @@ }, { "name": "check_clusterer_compute_labels_predict", + "unique_name": "check_clusterer_compute_labels_predict", "qname": "sklearn.utils.estimator_checks.check_clusterer_compute_labels_predict", + "unique_qname": "sklearn.utils.estimator_checks.check_clusterer_compute_labels_predict", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -164697,7 +170699,9 @@ }, { "name": "check_clustering", + "unique_name": "check_clustering", "qname": "sklearn.utils.estimator_checks.check_clustering", + "unique_qname": "sklearn.utils.estimator_checks.check_clustering", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -164739,7 +170743,9 @@ }, { "name": "check_complex_data", + "unique_name": "check_complex_data", "qname": "sklearn.utils.estimator_checks.check_complex_data", + "unique_qname": "sklearn.utils.estimator_checks.check_complex_data", "decorators": [], "parameters": [ { @@ -164771,7 +170777,9 @@ }, { "name": "check_dataframe_column_names_consistency", + "unique_name": "check_dataframe_column_names_consistency", "qname": "sklearn.utils.estimator_checks.check_dataframe_column_names_consistency", + "unique_qname": "sklearn.utils.estimator_checks.check_dataframe_column_names_consistency", "decorators": [], "parameters": [ { @@ -164799,11 +170807,13 @@ "is_public": true, "description": "", "docstring": "", - "source_code": "\ndef check_dataframe_column_names_consistency(name, estimator_orig):\n try:\n import pandas as pd\n except ImportError:\n raise SkipTest('pandas is not installed: not checking column name consistency for pandas')\n tags = _safe_tags(estimator_orig)\n is_supported_X_types = '2darray' in tags['X_types'] or 'categorical' in tags['X_types']\n if not is_supported_X_types or tags['no_validation']:\n return\n rng = np.random.RandomState(0)\n estimator = clone(estimator_orig)\n set_random_state(estimator)\n X_orig = rng.normal(size=(150, 8))\n X_orig -= X_orig.min() + 0.5\n X_orig = _enforce_estimator_tags_x(estimator, X_orig)\n X_orig = _pairwise_estimator_convert_X(X_orig, estimator)\n (n_samples, n_features) = X_orig.shape\n names = np.array([f'col_{i}' for i in range(n_features)])\n X = pd.DataFrame(X_orig, columns=names)\n if is_regressor(estimator):\n y = rng.normal(size=n_samples)\n else:\n y = rng.randint(low=0, high=2, size=n_samples)\n y = _enforce_estimator_tags_y(estimator, y)\n estimator.fit(X, y)\n if not hasattr(estimator, 'feature_names_in_'):\n raise ValueError('Estimator does not have a feature_names_in_ attribute after fitting with a dataframe')\n assert isinstance(estimator.feature_names_in_, np.ndarray)\n assert estimator.feature_names_in_.dtype == object\n assert_array_equal(estimator.feature_names_in_, names)\n module_name = estimator_orig.__module__\n if module_name.startswith('sklearn.') and not ('test_' in module_name or module_name.endswith('_testing')) and 'feature_names_in_' not in estimator_orig.__doc__:\n raise ValueError(f'Estimator {name} does not document its feature_names_in_ attribute')\n check_methods = []\n for method in ('predict', 'transform', 'decision_function', 'predict_proba', 'score', 'score_samples', 'predict_log_proba'):\n if not hasattr(estimator, method):\n continue\n callable_method = getattr(estimator, method)\n if method == 'score':\n callable_method = partial(callable_method, y=y)\n check_methods.append((method, callable_method))\n for (_, method) in check_methods:\n method(X)\n invalid_names = [(names[::-1], 'Feature names must be in the same order as they were in fit.'), ([f'another_prefix_{i}' for i in range(n_features)], 'Feature names unseen at fit time:\\n- another_prefix_0\\n- another_prefix_1\\n'), (names[:3], f'Feature names seen at fit time, yet now missing:\\n- {min(names[3:])}\\n')]\n for (invalid_name, additional_message) in invalid_names:\n X_bad = pd.DataFrame(X, columns=invalid_name)\n expected_msg = re.escape(f'The feature names should match those that were passed during fit. Starting version 1.2, an error will be raised.\\n{additional_message}')\n for (name, method) in check_methods:\n with warnings.catch_warnings():\n warnings.filterwarnings('error', category=FutureWarning, module='sklearn')\n with raises(FutureWarning, match=expected_msg, err_msg=f'{name} did not raise'):\n method(X_bad)\n if not hasattr(estimator, 'partial_fit'):\n continue\n estimator = clone(estimator_orig)\n if is_classifier(estimator):\n classes = np.unique(y)\n estimator.partial_fit(X, y, classes=classes)\n else:\n estimator.partial_fit(X, y)\n with warnings.catch_warnings():\n warnings.filterwarnings('error', category=FutureWarning, module='sklearn')\n with raises(FutureWarning, match=expected_msg):\n estimator.partial_fit(X_bad, y)" + "source_code": "\ndef check_dataframe_column_names_consistency(name, estimator_orig):\n try:\n import pandas as pd\n except ImportError:\n raise SkipTest('pandas is not installed: not checking column name consistency for pandas')\n tags = _safe_tags(estimator_orig)\n is_supported_X_types = '2darray' in tags['X_types'] or 'categorical' in tags['X_types']\n if not is_supported_X_types or tags['no_validation']:\n return\n rng = np.random.RandomState(0)\n estimator = clone(estimator_orig)\n set_random_state(estimator)\n X_orig = rng.normal(size=(150, 8))\n X_orig -= X_orig.min() + 0.5\n X_orig = _enforce_estimator_tags_x(estimator, X_orig)\n X_orig = _pairwise_estimator_convert_X(X_orig, estimator)\n (n_samples, n_features) = X_orig.shape\n names = np.array([f'col_{i}' for i in range(n_features)])\n X = pd.DataFrame(X_orig, columns=names)\n if is_regressor(estimator):\n y = rng.normal(size=n_samples)\n else:\n y = rng.randint(low=0, high=2, size=n_samples)\n y = _enforce_estimator_tags_y(estimator, y)\n estimator.fit(X, y)\n if not hasattr(estimator, 'feature_names_in_'):\n raise ValueError('Estimator does not have a feature_names_in_ attribute after fitting with a dataframe')\n assert isinstance(estimator.feature_names_in_, np.ndarray)\n assert estimator.feature_names_in_.dtype == object\n assert_array_equal(estimator.feature_names_in_, names)\n module_name = estimator_orig.__module__\n if module_name.startswith('sklearn.') and not ('test_' in module_name or module_name.endswith('_testing')) and 'feature_names_in_' not in estimator_orig.__doc__:\n raise ValueError(f'Estimator {name} does not document its feature_names_in_ attribute')\n check_methods = []\n for method in ('predict', 'transform', 'decision_function', 'predict_proba', 'score', 'score_samples', 'predict_log_proba'):\n if not hasattr(estimator, method):\n continue\n callable_method = getattr(estimator, method)\n if method == 'score':\n callable_method = partial(callable_method, y=y)\n check_methods.append((method, callable_method))\n for (_, method) in check_methods:\n with warnings.catch_warnings():\n warnings.filterwarnings('error', message='X does not have valid feature names', category=UserWarning, module='sklearn')\n method(X)\n invalid_names = [(names[::-1], 'Feature names must be in the same order as they were in fit.'), ([f'another_prefix_{i}' for i in range(n_features)], 'Feature names unseen at fit time:\\n- another_prefix_0\\n- another_prefix_1\\n'), (names[:3], f'Feature names seen at fit time, yet now missing:\\n- {min(names[3:])}\\n')]\n for (invalid_name, additional_message) in invalid_names:\n X_bad = pd.DataFrame(X, columns=invalid_name)\n expected_msg = re.escape(f'The feature names should match those that were passed during fit. Starting version 1.2, an error will be raised.\\n{additional_message}')\n for (name, method) in check_methods:\n with warnings.catch_warnings():\n warnings.filterwarnings('error', category=FutureWarning, module='sklearn')\n with raises(FutureWarning, match=expected_msg, err_msg=f'{name} did not raise'):\n method(X_bad)\n if not hasattr(estimator, 'partial_fit'):\n continue\n estimator = clone(estimator_orig)\n if is_classifier(estimator):\n classes = np.unique(y)\n estimator.partial_fit(X, y, classes=classes)\n else:\n estimator.partial_fit(X, y)\n with warnings.catch_warnings():\n warnings.filterwarnings('error', category=FutureWarning, module='sklearn')\n with raises(FutureWarning, match=expected_msg):\n estimator.partial_fit(X_bad, y)" }, { "name": "check_decision_proba_consistency", + "unique_name": "check_decision_proba_consistency", "qname": "sklearn.utils.estimator_checks.check_decision_proba_consistency", + "unique_qname": "sklearn.utils.estimator_checks.check_decision_proba_consistency", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -164835,7 +170845,9 @@ }, { "name": "check_dict_unchanged", + "unique_name": "check_dict_unchanged", "qname": "sklearn.utils.estimator_checks.check_dict_unchanged", + "unique_qname": "sklearn.utils.estimator_checks.check_dict_unchanged", "decorators": ["ignore_warnings"], "parameters": [ { @@ -164867,7 +170879,9 @@ }, { "name": "check_dont_overwrite_parameters", + "unique_name": "check_dont_overwrite_parameters", "qname": "sklearn.utils.estimator_checks.check_dont_overwrite_parameters", + "unique_qname": "sklearn.utils.estimator_checks.check_dont_overwrite_parameters", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -164899,7 +170913,9 @@ }, { "name": "check_dtype_object", + "unique_name": "check_dtype_object", "qname": "sklearn.utils.estimator_checks.check_dtype_object", + "unique_qname": "sklearn.utils.estimator_checks.check_dtype_object", "decorators": [ "ignore_warnings(category=(FutureWarning, UserWarning))" ], @@ -164933,7 +170949,9 @@ }, { "name": "check_estimator", + "unique_name": "check_estimator", "qname": "sklearn.utils.estimator_checks.check_estimator", + "unique_qname": "sklearn.utils.estimator_checks.check_estimator", "decorators": [], "parameters": [ { @@ -164960,12 +170978,14 @@ "results": [], "is_public": true, "description": "Check if estimator adheres to scikit-learn conventions.\n\nThis estimator will run an extensive test-suite for input validation, shapes, etc, making sure that the estimator complies with `scikit-learn` conventions as detailed in :ref:`rolling_your_own_estimator`. Additional tests for classifiers, regressors, clustering or transformers will be run if the Estimator class inherits from the corresponding mixin from sklearn.base. Setting `generate_only=True` returns a generator that yields (estimator, check) tuples where the check can be called independently from each other, i.e. `check(estimator)`. This allows all checks to be run independently and report the checks that are failing. scikit-learn provides a pytest specific decorator, :func:`~sklearn.utils.parametrize_with_checks`, making it easier to test multiple estimators.", - "docstring": "Check if estimator adheres to scikit-learn conventions.\n\nThis estimator will run an extensive test-suite for input validation,\nshapes, etc, making sure that the estimator complies with `scikit-learn`\nconventions as detailed in :ref:`rolling_your_own_estimator`.\nAdditional tests for classifiers, regressors, clustering or transformers\nwill be run if the Estimator class inherits from the corresponding mixin\nfrom sklearn.base.\n\nSetting `generate_only=True` returns a generator that yields (estimator,\ncheck) tuples where the check can be called independently from each\nother, i.e. `check(estimator)`. This allows all checks to be run\nindependently and report the checks that are failing.\n\nscikit-learn provides a pytest specific decorator,\n:func:`~sklearn.utils.parametrize_with_checks`, making it easier to test\nmultiple estimators.\n\nParameters\n----------\nEstimator : estimator object\n Estimator instance to check.\n\n .. versionchanged:: 0.24\n Passing a class was deprecated in version 0.23, and support for\n classes was removed in 0.24.\n\ngenerate_only : bool, default=False\n When `False`, checks are evaluated when `check_estimator` is called.\n When `True`, `check_estimator` returns a generator that yields\n (estimator, check) tuples. The check is run by calling\n `check(estimator)`.\n\n .. versionadded:: 0.22\n\nReturns\n-------\nchecks_generator : generator\n Generator that yields (estimator, check) tuples. Returned when\n `generate_only=True`.", - "source_code": "\ndef check_estimator(Estimator, generate_only=False):\n \"\"\"Check if estimator adheres to scikit-learn conventions.\n\n This estimator will run an extensive test-suite for input validation,\n shapes, etc, making sure that the estimator complies with `scikit-learn`\n conventions as detailed in :ref:`rolling_your_own_estimator`.\n Additional tests for classifiers, regressors, clustering or transformers\n will be run if the Estimator class inherits from the corresponding mixin\n from sklearn.base.\n\n Setting `generate_only=True` returns a generator that yields (estimator,\n check) tuples where the check can be called independently from each\n other, i.e. `check(estimator)`. This allows all checks to be run\n independently and report the checks that are failing.\n\n scikit-learn provides a pytest specific decorator,\n :func:`~sklearn.utils.parametrize_with_checks`, making it easier to test\n multiple estimators.\n\n Parameters\n ----------\n Estimator : estimator object\n Estimator instance to check.\n\n .. versionchanged:: 0.24\n Passing a class was deprecated in version 0.23, and support for\n classes was removed in 0.24.\n\n generate_only : bool, default=False\n When `False`, checks are evaluated when `check_estimator` is called.\n When `True`, `check_estimator` returns a generator that yields\n (estimator, check) tuples. The check is run by calling\n `check(estimator)`.\n\n .. versionadded:: 0.22\n\n Returns\n -------\n checks_generator : generator\n Generator that yields (estimator, check) tuples. Returned when\n `generate_only=True`.\n \"\"\"\n if isinstance(Estimator, type):\n msg = \"Passing a class was deprecated in version 0.23 and isn't supported anymore from 0.24.Please pass an instance instead.\"\n raise TypeError(msg)\n estimator = Estimator\n name = type(estimator).__name__\n \n def checks_generator():\n for check in _yield_all_checks(estimator):\n check = _maybe_skip(estimator, check)\n yield (estimator, partial(check, name))\n if generate_only:\n return checks_generator()\n for (estimator, check) in checks_generator():\n try:\n check(estimator)\n except SkipTest as exception:\n warnings.warn(str(exception), SkipTestWarning)" + "docstring": "Check if estimator adheres to scikit-learn conventions.\n\nThis estimator will run an extensive test-suite for input validation,\nshapes, etc, making sure that the estimator complies with `scikit-learn`\nconventions as detailed in :ref:`rolling_your_own_estimator`.\nAdditional tests for classifiers, regressors, clustering or transformers\nwill be run if the Estimator class inherits from the corresponding mixin\nfrom sklearn.base.\n\nSetting `generate_only=True` returns a generator that yields (estimator,\ncheck) tuples where the check can be called independently from each\nother, i.e. `check(estimator)`. This allows all checks to be run\nindependently and report the checks that are failing.\n\nscikit-learn provides a pytest specific decorator,\n:func:`~sklearn.utils.parametrize_with_checks`, making it easier to test\nmultiple estimators.\n\nParameters\n----------\nEstimator : estimator object\n Estimator instance to check.\n\n .. versionchanged:: 0.24\n Passing a class was deprecated in version 0.23, and support for\n classes was removed in 0.24.\n\ngenerate_only : bool, default=False\n When `False`, checks are evaluated when `check_estimator` is called.\n When `True`, `check_estimator` returns a generator that yields\n (estimator, check) tuples. The check is run by calling\n `check(estimator)`.\n\n .. versionadded:: 0.22\n\nReturns\n-------\nchecks_generator : generator\n Generator that yields (estimator, check) tuples. Returned when\n `generate_only=True`.\n\nSee Also\n--------\nparametrize_with_checks : Pytest specific decorator for parametrizing estimator\n checks.", + "source_code": "\ndef check_estimator(Estimator, generate_only=False):\n \"\"\"Check if estimator adheres to scikit-learn conventions.\n\n This estimator will run an extensive test-suite for input validation,\n shapes, etc, making sure that the estimator complies with `scikit-learn`\n conventions as detailed in :ref:`rolling_your_own_estimator`.\n Additional tests for classifiers, regressors, clustering or transformers\n will be run if the Estimator class inherits from the corresponding mixin\n from sklearn.base.\n\n Setting `generate_only=True` returns a generator that yields (estimator,\n check) tuples where the check can be called independently from each\n other, i.e. `check(estimator)`. This allows all checks to be run\n independently and report the checks that are failing.\n\n scikit-learn provides a pytest specific decorator,\n :func:`~sklearn.utils.parametrize_with_checks`, making it easier to test\n multiple estimators.\n\n Parameters\n ----------\n Estimator : estimator object\n Estimator instance to check.\n\n .. versionchanged:: 0.24\n Passing a class was deprecated in version 0.23, and support for\n classes was removed in 0.24.\n\n generate_only : bool, default=False\n When `False`, checks are evaluated when `check_estimator` is called.\n When `True`, `check_estimator` returns a generator that yields\n (estimator, check) tuples. The check is run by calling\n `check(estimator)`.\n\n .. versionadded:: 0.22\n\n Returns\n -------\n checks_generator : generator\n Generator that yields (estimator, check) tuples. Returned when\n `generate_only=True`.\n\n See Also\n --------\n parametrize_with_checks : Pytest specific decorator for parametrizing estimator\n checks.\n \"\"\"\n if isinstance(Estimator, type):\n msg = \"Passing a class was deprecated in version 0.23 and isn't supported anymore from 0.24.Please pass an instance instead.\"\n raise TypeError(msg)\n estimator = Estimator\n name = type(estimator).__name__\n \n def checks_generator():\n for check in _yield_all_checks(estimator):\n check = _maybe_skip(estimator, check)\n yield (estimator, partial(check, name))\n if generate_only:\n return checks_generator()\n for (estimator, check) in checks_generator():\n try:\n check(estimator)\n except SkipTest as exception:\n warnings.warn(str(exception), SkipTestWarning)" }, { "name": "check_estimator_get_tags_default_keys", + "unique_name": "check_estimator_get_tags_default_keys", "qname": "sklearn.utils.estimator_checks.check_estimator_get_tags_default_keys", + "unique_qname": "sklearn.utils.estimator_checks.check_estimator_get_tags_default_keys", "decorators": [], "parameters": [ { @@ -164997,7 +171017,9 @@ }, { "name": "check_estimator_sparse_data", + "unique_name": "check_estimator_sparse_data", "qname": "sklearn.utils.estimator_checks.check_estimator_sparse_data", + "unique_qname": "sklearn.utils.estimator_checks.check_estimator_sparse_data", "decorators": [], "parameters": [ { @@ -165029,7 +171051,9 @@ }, { "name": "check_estimators_data_not_an_array", + "unique_name": "check_estimators_data_not_an_array", "qname": "sklearn.utils.estimator_checks.check_estimators_data_not_an_array", + "unique_qname": "sklearn.utils.estimator_checks.check_estimators_data_not_an_array", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -165091,7 +171115,9 @@ }, { "name": "check_estimators_dtypes", + "unique_name": "check_estimators_dtypes", "qname": "sklearn.utils.estimator_checks.check_estimators_dtypes", + "unique_qname": "sklearn.utils.estimator_checks.check_estimators_dtypes", "decorators": ["ignore_warnings"], "parameters": [ { @@ -165123,7 +171149,9 @@ }, { "name": "check_estimators_empty_data_messages", + "unique_name": "check_estimators_empty_data_messages", "qname": "sklearn.utils.estimator_checks.check_estimators_empty_data_messages", + "unique_qname": "sklearn.utils.estimator_checks.check_estimators_empty_data_messages", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -165155,7 +171183,9 @@ }, { "name": "check_estimators_fit_returns_self", + "unique_name": "check_estimators_fit_returns_self", "qname": "sklearn.utils.estimator_checks.check_estimators_fit_returns_self", + "unique_qname": "sklearn.utils.estimator_checks.check_estimators_fit_returns_self", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -165197,7 +171227,9 @@ }, { "name": "check_estimators_nan_inf", + "unique_name": "check_estimators_nan_inf", "qname": "sklearn.utils.estimator_checks.check_estimators_nan_inf", + "unique_qname": "sklearn.utils.estimator_checks.check_estimators_nan_inf", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -165229,7 +171261,9 @@ }, { "name": "check_estimators_overwrite_params", + "unique_name": "check_estimators_overwrite_params", "qname": "sklearn.utils.estimator_checks.check_estimators_overwrite_params", + "unique_qname": "sklearn.utils.estimator_checks.check_estimators_overwrite_params", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -165261,7 +171295,9 @@ }, { "name": "check_estimators_partial_fit_n_features", + "unique_name": "check_estimators_partial_fit_n_features", "qname": "sklearn.utils.estimator_checks.check_estimators_partial_fit_n_features", + "unique_qname": "sklearn.utils.estimator_checks.check_estimators_partial_fit_n_features", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -165293,7 +171329,9 @@ }, { "name": "check_estimators_pickle", + "unique_name": "check_estimators_pickle", "qname": "sklearn.utils.estimator_checks.check_estimators_pickle", + "unique_qname": "sklearn.utils.estimator_checks.check_estimators_pickle", "decorators": ["ignore_warnings"], "parameters": [ { @@ -165325,7 +171363,9 @@ }, { "name": "check_estimators_unfitted", + "unique_name": "check_estimators_unfitted", "qname": "sklearn.utils.estimator_checks.check_estimators_unfitted", + "unique_qname": "sklearn.utils.estimator_checks.check_estimators_unfitted", "decorators": ["ignore_warnings"], "parameters": [ { @@ -165357,7 +171397,9 @@ }, { "name": "check_fit1d", + "unique_name": "check_fit1d", "qname": "sklearn.utils.estimator_checks.check_fit1d", + "unique_qname": "sklearn.utils.estimator_checks.check_fit1d", "decorators": ["ignore_warnings"], "parameters": [ { @@ -165389,7 +171431,9 @@ }, { "name": "check_fit2d_1feature", + "unique_name": "check_fit2d_1feature", "qname": "sklearn.utils.estimator_checks.check_fit2d_1feature", + "unique_qname": "sklearn.utils.estimator_checks.check_fit2d_1feature", "decorators": ["ignore_warnings"], "parameters": [ { @@ -165421,7 +171465,9 @@ }, { "name": "check_fit2d_1sample", + "unique_name": "check_fit2d_1sample", "qname": "sklearn.utils.estimator_checks.check_fit2d_1sample", + "unique_qname": "sklearn.utils.estimator_checks.check_fit2d_1sample", "decorators": ["ignore_warnings"], "parameters": [ { @@ -165453,7 +171499,9 @@ }, { "name": "check_fit2d_predict1d", + "unique_name": "check_fit2d_predict1d", "qname": "sklearn.utils.estimator_checks.check_fit2d_predict1d", + "unique_qname": "sklearn.utils.estimator_checks.check_fit2d_predict1d", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -165485,7 +171533,9 @@ }, { "name": "check_fit_check_is_fitted", + "unique_name": "check_fit_check_is_fitted", "qname": "sklearn.utils.estimator_checks.check_fit_check_is_fitted", + "unique_qname": "sklearn.utils.estimator_checks.check_fit_check_is_fitted", "decorators": [], "parameters": [ { @@ -165517,7 +171567,9 @@ }, { "name": "check_fit_idempotent", + "unique_name": "check_fit_idempotent", "qname": "sklearn.utils.estimator_checks.check_fit_idempotent", + "unique_qname": "sklearn.utils.estimator_checks.check_fit_idempotent", "decorators": [], "parameters": [ { @@ -165549,7 +171601,9 @@ }, { "name": "check_fit_non_negative", + "unique_name": "check_fit_non_negative", "qname": "sklearn.utils.estimator_checks.check_fit_non_negative", + "unique_qname": "sklearn.utils.estimator_checks.check_fit_non_negative", "decorators": [], "parameters": [ { @@ -165581,7 +171635,9 @@ }, { "name": "check_fit_score_takes_y", + "unique_name": "check_fit_score_takes_y", "qname": "sklearn.utils.estimator_checks.check_fit_score_takes_y", + "unique_qname": "sklearn.utils.estimator_checks.check_fit_score_takes_y", "decorators": ["ignore_warnings"], "parameters": [ { @@ -165613,7 +171669,9 @@ }, { "name": "check_get_params_invariance", + "unique_name": "check_get_params_invariance", "qname": "sklearn.utils.estimator_checks.check_get_params_invariance", + "unique_qname": "sklearn.utils.estimator_checks.check_get_params_invariance", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -165645,7 +171703,9 @@ }, { "name": "check_methods_sample_order_invariance", + "unique_name": "check_methods_sample_order_invariance", "qname": "sklearn.utils.estimator_checks.check_methods_sample_order_invariance", + "unique_qname": "sklearn.utils.estimator_checks.check_methods_sample_order_invariance", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -165677,7 +171737,9 @@ }, { "name": "check_methods_subset_invariance", + "unique_name": "check_methods_subset_invariance", "qname": "sklearn.utils.estimator_checks.check_methods_subset_invariance", + "unique_qname": "sklearn.utils.estimator_checks.check_methods_subset_invariance", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -165709,7 +171771,9 @@ }, { "name": "check_n_features_in", + "unique_name": "check_n_features_in", "qname": "sklearn.utils.estimator_checks.check_n_features_in", + "unique_qname": "sklearn.utils.estimator_checks.check_n_features_in", "decorators": [], "parameters": [ { @@ -165741,7 +171805,9 @@ }, { "name": "check_n_features_in_after_fitting", + "unique_name": "check_n_features_in_after_fitting", "qname": "sklearn.utils.estimator_checks.check_n_features_in_after_fitting", + "unique_qname": "sklearn.utils.estimator_checks.check_n_features_in_after_fitting", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -165773,7 +171839,9 @@ }, { "name": "check_no_attributes_set_in_init", + "unique_name": "check_no_attributes_set_in_init", "qname": "sklearn.utils.estimator_checks.check_no_attributes_set_in_init", + "unique_qname": "sklearn.utils.estimator_checks.check_no_attributes_set_in_init", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -165805,7 +171873,9 @@ }, { "name": "check_non_transformer_estimators_n_iter", + "unique_name": "check_non_transformer_estimators_n_iter", "qname": "sklearn.utils.estimator_checks.check_non_transformer_estimators_n_iter", + "unique_qname": "sklearn.utils.estimator_checks.check_non_transformer_estimators_n_iter", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -165837,7 +171907,9 @@ }, { "name": "check_nonsquare_error", + "unique_name": "check_nonsquare_error", "qname": "sklearn.utils.estimator_checks.check_nonsquare_error", + "unique_qname": "sklearn.utils.estimator_checks.check_nonsquare_error", "decorators": ["ignore_warnings"], "parameters": [ { @@ -165869,7 +171941,9 @@ }, { "name": "check_outlier_corruption", + "unique_name": "check_outlier_corruption", "qname": "sklearn.utils.estimator_checks.check_outlier_corruption", + "unique_qname": "sklearn.utils.estimator_checks.check_outlier_corruption", "decorators": [], "parameters": [ { @@ -165911,7 +171985,9 @@ }, { "name": "check_outliers_fit_predict", + "unique_name": "check_outliers_fit_predict", "qname": "sklearn.utils.estimator_checks.check_outliers_fit_predict", + "unique_qname": "sklearn.utils.estimator_checks.check_outliers_fit_predict", "decorators": [], "parameters": [ { @@ -165943,7 +172019,9 @@ }, { "name": "check_outliers_train", + "unique_name": "check_outliers_train", "qname": "sklearn.utils.estimator_checks.check_outliers_train", + "unique_qname": "sklearn.utils.estimator_checks.check_outliers_train", "decorators": [], "parameters": [ { @@ -165985,7 +172063,9 @@ }, { "name": "check_parameters_default_constructible", + "unique_name": "check_parameters_default_constructible", "qname": "sklearn.utils.estimator_checks.check_parameters_default_constructible", + "unique_qname": "sklearn.utils.estimator_checks.check_parameters_default_constructible", "decorators": [], "parameters": [ { @@ -166017,7 +172097,9 @@ }, { "name": "check_pipeline_consistency", + "unique_name": "check_pipeline_consistency", "qname": "sklearn.utils.estimator_checks.check_pipeline_consistency", + "unique_qname": "sklearn.utils.estimator_checks.check_pipeline_consistency", "decorators": ["ignore_warnings"], "parameters": [ { @@ -166049,7 +172131,9 @@ }, { "name": "check_regressor_data_not_an_array", + "unique_name": "check_regressor_data_not_an_array", "qname": "sklearn.utils.estimator_checks.check_regressor_data_not_an_array", + "unique_qname": "sklearn.utils.estimator_checks.check_regressor_data_not_an_array", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -166081,7 +172165,9 @@ }, { "name": "check_regressor_multioutput", + "unique_name": "check_regressor_multioutput", "qname": "sklearn.utils.estimator_checks.check_regressor_multioutput", + "unique_qname": "sklearn.utils.estimator_checks.check_regressor_multioutput", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -166113,7 +172199,9 @@ }, { "name": "check_regressors_int", + "unique_name": "check_regressors_int", "qname": "sklearn.utils.estimator_checks.check_regressors_int", + "unique_qname": "sklearn.utils.estimator_checks.check_regressors_int", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -166145,7 +172233,9 @@ }, { "name": "check_regressors_no_decision_function", + "unique_name": "check_regressors_no_decision_function", "qname": "sklearn.utils.estimator_checks.check_regressors_no_decision_function", + "unique_qname": "sklearn.utils.estimator_checks.check_regressors_no_decision_function", "decorators": ["ignore_warnings"], "parameters": [ { @@ -166177,7 +172267,9 @@ }, { "name": "check_regressors_train", + "unique_name": "check_regressors_train", "qname": "sklearn.utils.estimator_checks.check_regressors_train", + "unique_qname": "sklearn.utils.estimator_checks.check_regressors_train", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -166229,7 +172321,9 @@ }, { "name": "check_requires_y_none", + "unique_name": "check_requires_y_none", "qname": "sklearn.utils.estimator_checks.check_requires_y_none", + "unique_qname": "sklearn.utils.estimator_checks.check_requires_y_none", "decorators": [], "parameters": [ { @@ -166261,7 +172355,9 @@ }, { "name": "check_sample_weights_invariance", + "unique_name": "check_sample_weights_invariance", "qname": "sklearn.utils.estimator_checks.check_sample_weights_invariance", + "unique_qname": "sklearn.utils.estimator_checks.check_sample_weights_invariance", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -166303,7 +172399,9 @@ }, { "name": "check_sample_weights_list", + "unique_name": "check_sample_weights_list", "qname": "sklearn.utils.estimator_checks.check_sample_weights_list", + "unique_qname": "sklearn.utils.estimator_checks.check_sample_weights_list", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -166335,7 +172433,9 @@ }, { "name": "check_sample_weights_not_an_array", + "unique_name": "check_sample_weights_not_an_array", "qname": "sklearn.utils.estimator_checks.check_sample_weights_not_an_array", + "unique_qname": "sklearn.utils.estimator_checks.check_sample_weights_not_an_array", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -166367,7 +172467,9 @@ }, { "name": "check_sample_weights_not_overwritten", + "unique_name": "check_sample_weights_not_overwritten", "qname": "sklearn.utils.estimator_checks.check_sample_weights_not_overwritten", + "unique_qname": "sklearn.utils.estimator_checks.check_sample_weights_not_overwritten", "decorators": [], "parameters": [ { @@ -166399,7 +172501,9 @@ }, { "name": "check_sample_weights_pandas_series", + "unique_name": "check_sample_weights_pandas_series", "qname": "sklearn.utils.estimator_checks.check_sample_weights_pandas_series", + "unique_qname": "sklearn.utils.estimator_checks.check_sample_weights_pandas_series", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -166431,7 +172535,9 @@ }, { "name": "check_sample_weights_shape", + "unique_name": "check_sample_weights_shape", "qname": "sklearn.utils.estimator_checks.check_sample_weights_shape", + "unique_qname": "sklearn.utils.estimator_checks.check_sample_weights_shape", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -166463,7 +172569,9 @@ }, { "name": "check_set_params", + "unique_name": "check_set_params", "qname": "sklearn.utils.estimator_checks.check_set_params", + "unique_qname": "sklearn.utils.estimator_checks.check_set_params", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -166495,7 +172603,9 @@ }, { "name": "check_sparsify_coefficients", + "unique_name": "check_sparsify_coefficients", "qname": "sklearn.utils.estimator_checks.check_sparsify_coefficients", + "unique_qname": "sklearn.utils.estimator_checks.check_sparsify_coefficients", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -166527,7 +172637,9 @@ }, { "name": "check_supervised_y_2d", + "unique_name": "check_supervised_y_2d", "qname": "sklearn.utils.estimator_checks.check_supervised_y_2d", + "unique_qname": "sklearn.utils.estimator_checks.check_supervised_y_2d", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -166559,7 +172671,9 @@ }, { "name": "check_supervised_y_no_nan", + "unique_name": "check_supervised_y_no_nan", "qname": "sklearn.utils.estimator_checks.check_supervised_y_no_nan", + "unique_qname": "sklearn.utils.estimator_checks.check_supervised_y_no_nan", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -166591,7 +172705,9 @@ }, { "name": "check_transformer_data_not_an_array", + "unique_name": "check_transformer_data_not_an_array", "qname": "sklearn.utils.estimator_checks.check_transformer_data_not_an_array", + "unique_qname": "sklearn.utils.estimator_checks.check_transformer_data_not_an_array", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -166623,7 +172739,9 @@ }, { "name": "check_transformer_general", + "unique_name": "check_transformer_general", "qname": "sklearn.utils.estimator_checks.check_transformer_general", + "unique_qname": "sklearn.utils.estimator_checks.check_transformer_general", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -166665,7 +172783,9 @@ }, { "name": "check_transformer_get_feature_names_out", + "unique_name": "check_transformer_get_feature_names_out", "qname": "sklearn.utils.estimator_checks.check_transformer_get_feature_names_out", + "unique_qname": "sklearn.utils.estimator_checks.check_transformer_get_feature_names_out", "decorators": [], "parameters": [ { @@ -166697,7 +172817,9 @@ }, { "name": "check_transformer_get_feature_names_out_pandas", + "unique_name": "check_transformer_get_feature_names_out_pandas", "qname": "sklearn.utils.estimator_checks.check_transformer_get_feature_names_out_pandas", + "unique_qname": "sklearn.utils.estimator_checks.check_transformer_get_feature_names_out_pandas", "decorators": [], "parameters": [ { @@ -166729,7 +172851,9 @@ }, { "name": "check_transformer_n_iter", + "unique_name": "check_transformer_n_iter", "qname": "sklearn.utils.estimator_checks.check_transformer_n_iter", + "unique_qname": "sklearn.utils.estimator_checks.check_transformer_n_iter", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -166761,7 +172885,9 @@ }, { "name": "check_transformer_preserve_dtypes", + "unique_name": "check_transformer_preserve_dtypes", "qname": "sklearn.utils.estimator_checks.check_transformer_preserve_dtypes", + "unique_qname": "sklearn.utils.estimator_checks.check_transformer_preserve_dtypes", "decorators": [], "parameters": [ { @@ -166793,7 +172919,9 @@ }, { "name": "check_transformers_unfitted", + "unique_name": "check_transformers_unfitted", "qname": "sklearn.utils.estimator_checks.check_transformers_unfitted", + "unique_qname": "sklearn.utils.estimator_checks.check_transformers_unfitted", "decorators": ["ignore_warnings(category=FutureWarning)"], "parameters": [ { @@ -166825,7 +172953,9 @@ }, { "name": "parametrize_with_checks", + "unique_name": "parametrize_with_checks", "qname": "sklearn.utils.estimator_checks.parametrize_with_checks", + "unique_qname": "sklearn.utils.estimator_checks.parametrize_with_checks", "decorators": [], "parameters": [ { @@ -166842,12 +172972,14 @@ "results": [], "is_public": true, "description": "Pytest specific decorator for parametrizing estimator checks.\n\nThe `id` of each check is set to be a pprint version of the estimator and the name of the check with its keyword arguments. This allows to use `pytest -k` to specify which tests to run:: pytest test_check_estimators.py -k check_estimators_fit_returns_self", - "docstring": "Pytest specific decorator for parametrizing estimator checks.\n\nThe `id` of each check is set to be a pprint version of the estimator\nand the name of the check with its keyword arguments.\nThis allows to use `pytest -k` to specify which tests to run::\n\n pytest test_check_estimators.py -k check_estimators_fit_returns_self\n\nParameters\n----------\nestimators : list of estimators instances\n Estimators to generated checks for.\n\n .. versionchanged:: 0.24\n Passing a class was deprecated in version 0.23, and support for\n classes was removed in 0.24. Pass an instance instead.\n\n .. versionadded:: 0.24\n\nReturns\n-------\ndecorator : `pytest.mark.parametrize`\n\nExamples\n--------\n>>> from sklearn.utils.estimator_checks import parametrize_with_checks\n>>> from sklearn.linear_model import LogisticRegression\n>>> from sklearn.tree import DecisionTreeRegressor\n\n>>> @parametrize_with_checks([LogisticRegression(),\n... DecisionTreeRegressor()])\n... def test_sklearn_compatible_estimator(estimator, check):\n... check(estimator)", - "source_code": "\ndef parametrize_with_checks(estimators):\n \"\"\"Pytest specific decorator for parametrizing estimator checks.\n\n The `id` of each check is set to be a pprint version of the estimator\n and the name of the check with its keyword arguments.\n This allows to use `pytest -k` to specify which tests to run::\n\n pytest test_check_estimators.py -k check_estimators_fit_returns_self\n\n Parameters\n ----------\n estimators : list of estimators instances\n Estimators to generated checks for.\n\n .. versionchanged:: 0.24\n Passing a class was deprecated in version 0.23, and support for\n classes was removed in 0.24. Pass an instance instead.\n\n .. versionadded:: 0.24\n\n Returns\n -------\n decorator : `pytest.mark.parametrize`\n\n Examples\n --------\n >>> from sklearn.utils.estimator_checks import parametrize_with_checks\n >>> from sklearn.linear_model import LogisticRegression\n >>> from sklearn.tree import DecisionTreeRegressor\n\n >>> @parametrize_with_checks([LogisticRegression(),\n ... DecisionTreeRegressor()])\n ... def test_sklearn_compatible_estimator(estimator, check):\n ... check(estimator)\n\n \"\"\"\n import pytest\n if any((isinstance(est, type) for est in estimators)):\n msg = \"Passing a class was deprecated in version 0.23 and isn't supported anymore from 0.24.Please pass an instance instead.\"\n raise TypeError(msg)\n \n def checks_generator():\n for estimator in estimators:\n name = type(estimator).__name__\n for check in _yield_all_checks(estimator):\n check = partial(check, name)\n yield _maybe_mark_xfail(estimator, check, pytest)\n return pytest.mark.parametrize('estimator, check', checks_generator(), ids=_get_check_estimator_ids)" + "docstring": "Pytest specific decorator for parametrizing estimator checks.\n\nThe `id` of each check is set to be a pprint version of the estimator\nand the name of the check with its keyword arguments.\nThis allows to use `pytest -k` to specify which tests to run::\n\n pytest test_check_estimators.py -k check_estimators_fit_returns_self\n\nParameters\n----------\nestimators : list of estimators instances\n Estimators to generated checks for.\n\n .. versionchanged:: 0.24\n Passing a class was deprecated in version 0.23, and support for\n classes was removed in 0.24. Pass an instance instead.\n\n .. versionadded:: 0.24\n\nReturns\n-------\ndecorator : `pytest.mark.parametrize`\n\nSee Also\n--------\ncheck_estimator : Check if estimator adheres to scikit-learn conventions.\n\nExamples\n--------\n>>> from sklearn.utils.estimator_checks import parametrize_with_checks\n>>> from sklearn.linear_model import LogisticRegression\n>>> from sklearn.tree import DecisionTreeRegressor\n\n>>> @parametrize_with_checks([LogisticRegression(),\n... DecisionTreeRegressor()])\n... def test_sklearn_compatible_estimator(estimator, check):\n... check(estimator)", + "source_code": "\ndef parametrize_with_checks(estimators):\n \"\"\"Pytest specific decorator for parametrizing estimator checks.\n\n The `id` of each check is set to be a pprint version of the estimator\n and the name of the check with its keyword arguments.\n This allows to use `pytest -k` to specify which tests to run::\n\n pytest test_check_estimators.py -k check_estimators_fit_returns_self\n\n Parameters\n ----------\n estimators : list of estimators instances\n Estimators to generated checks for.\n\n .. versionchanged:: 0.24\n Passing a class was deprecated in version 0.23, and support for\n classes was removed in 0.24. Pass an instance instead.\n\n .. versionadded:: 0.24\n\n Returns\n -------\n decorator : `pytest.mark.parametrize`\n\n See Also\n --------\n check_estimator : Check if estimator adheres to scikit-learn conventions.\n\n Examples\n --------\n >>> from sklearn.utils.estimator_checks import parametrize_with_checks\n >>> from sklearn.linear_model import LogisticRegression\n >>> from sklearn.tree import DecisionTreeRegressor\n\n >>> @parametrize_with_checks([LogisticRegression(),\n ... DecisionTreeRegressor()])\n ... def test_sklearn_compatible_estimator(estimator, check):\n ... check(estimator)\n\n \"\"\"\n import pytest\n if any((isinstance(est, type) for est in estimators)):\n msg = \"Passing a class was deprecated in version 0.23 and isn't supported anymore from 0.24.Please pass an instance instead.\"\n raise TypeError(msg)\n \n def checks_generator():\n for estimator in estimators:\n name = type(estimator).__name__\n for check in _yield_all_checks(estimator):\n check = partial(check, name)\n yield _maybe_mark_xfail(estimator, check, pytest)\n return pytest.mark.parametrize('estimator, check', checks_generator(), ids=_get_check_estimator_ids)" }, { "name": "_deterministic_vector_sign_flip", + "unique_name": "_deterministic_vector_sign_flip", "qname": "sklearn.utils.extmath._deterministic_vector_sign_flip", + "unique_qname": "sklearn.utils.extmath._deterministic_vector_sign_flip", "decorators": [], "parameters": [ { @@ -166869,7 +173001,9 @@ }, { "name": "_incremental_mean_and_var", + "unique_name": "_incremental_mean_and_var", "qname": "sklearn.utils.extmath._incremental_mean_and_var", + "unique_qname": "sklearn.utils.extmath._incremental_mean_and_var", "decorators": [], "parameters": [ { @@ -166931,7 +173065,9 @@ }, { "name": "_randomized_eigsh", + "unique_name": "_randomized_eigsh", "qname": "sklearn.utils.extmath._randomized_eigsh", + "unique_qname": "sklearn.utils.extmath._randomized_eigsh", "decorators": [], "parameters": [ { @@ -167013,7 +173149,9 @@ }, { "name": "_safe_accumulator_op", + "unique_name": "_safe_accumulator_op", "qname": "sklearn.utils.extmath._safe_accumulator_op", + "unique_qname": "sklearn.utils.extmath._safe_accumulator_op", "decorators": [], "parameters": [ { @@ -167045,7 +173183,9 @@ }, { "name": "cartesian", + "unique_name": "cartesian", "qname": "sklearn.utils.extmath.cartesian", + "unique_qname": "sklearn.utils.extmath.cartesian", "decorators": [], "parameters": [ { @@ -167072,12 +173212,14 @@ "results": [], "is_public": true, "description": "Generate a cartesian product of input arrays.", - "docstring": "Generate a cartesian product of input arrays.\n\nParameters\n----------\narrays : list of array-like\n 1-D arrays to form the cartesian product of.\nout : ndarray, default=None\n Array to place the cartesian product in.\n\nReturns\n-------\nout : ndarray\n 2-D array of shape (M, len(arrays)) containing cartesian products\n formed of input arrays.\n\nExamples\n--------\n>>> cartesian(([1, 2, 3], [4, 5], [6, 7]))\narray([[1, 4, 6],\n [1, 4, 7],\n [1, 5, 6],\n [1, 5, 7],\n [2, 4, 6],\n [2, 4, 7],\n [2, 5, 6],\n [2, 5, 7],\n [3, 4, 6],\n [3, 4, 7],\n [3, 5, 6],\n [3, 5, 7]])\n\nNotes\n-----\nThis function may not be used on more than 32 arrays\nbecause the underlying numpy functions do not support it.", - "source_code": "\ndef cartesian(arrays, out=None):\n \"\"\"Generate a cartesian product of input arrays.\n\n Parameters\n ----------\n arrays : list of array-like\n 1-D arrays to form the cartesian product of.\n out : ndarray, default=None\n Array to place the cartesian product in.\n\n Returns\n -------\n out : ndarray\n 2-D array of shape (M, len(arrays)) containing cartesian products\n formed of input arrays.\n\n Examples\n --------\n >>> cartesian(([1, 2, 3], [4, 5], [6, 7]))\n array([[1, 4, 6],\n [1, 4, 7],\n [1, 5, 6],\n [1, 5, 7],\n [2, 4, 6],\n [2, 4, 7],\n [2, 5, 6],\n [2, 5, 7],\n [3, 4, 6],\n [3, 4, 7],\n [3, 5, 6],\n [3, 5, 7]])\n\n Notes\n -----\n This function may not be used on more than 32 arrays\n because the underlying numpy functions do not support it.\n \"\"\"\n arrays = [np.asarray(x) for x in arrays]\n shape = (len(x) for x in arrays)\n dtype = arrays[0].dtype\n ix = np.indices(shape)\n ix = ix.reshape(len(arrays), -1).T\n if out is None:\n out = np.empty_like(ix, dtype=dtype)\n for (n, arr) in enumerate(arrays):\n out[:, n] = arrays[n][ix[:, n]]\n return out" + "docstring": "Generate a cartesian product of input arrays.\n\nParameters\n----------\narrays : list of array-like\n 1-D arrays to form the cartesian product of.\nout : ndarray, default=None\n Array to place the cartesian product in.\n\nReturns\n-------\nout : ndarray\n 2-D array of shape (M, len(arrays)) containing cartesian products\n formed of input arrays.\n\nExamples\n--------\n>>> from sklearn.utils.extmath import cartesian\n>>> cartesian(([1, 2, 3], [4, 5], [6, 7]))\narray([[1, 4, 6],\n [1, 4, 7],\n [1, 5, 6],\n [1, 5, 7],\n [2, 4, 6],\n [2, 4, 7],\n [2, 5, 6],\n [2, 5, 7],\n [3, 4, 6],\n [3, 4, 7],\n [3, 5, 6],\n [3, 5, 7]])\n\nNotes\n-----\nThis function may not be used on more than 32 arrays\nbecause the underlying numpy functions do not support it.", + "source_code": "\ndef cartesian(arrays, out=None):\n \"\"\"Generate a cartesian product of input arrays.\n\n Parameters\n ----------\n arrays : list of array-like\n 1-D arrays to form the cartesian product of.\n out : ndarray, default=None\n Array to place the cartesian product in.\n\n Returns\n -------\n out : ndarray\n 2-D array of shape (M, len(arrays)) containing cartesian products\n formed of input arrays.\n\n Examples\n --------\n >>> from sklearn.utils.extmath import cartesian\n >>> cartesian(([1, 2, 3], [4, 5], [6, 7]))\n array([[1, 4, 6],\n [1, 4, 7],\n [1, 5, 6],\n [1, 5, 7],\n [2, 4, 6],\n [2, 4, 7],\n [2, 5, 6],\n [2, 5, 7],\n [3, 4, 6],\n [3, 4, 7],\n [3, 5, 6],\n [3, 5, 7]])\n\n Notes\n -----\n This function may not be used on more than 32 arrays\n because the underlying numpy functions do not support it.\n \"\"\"\n arrays = [np.asarray(x) for x in arrays]\n shape = (len(x) for x in arrays)\n dtype = arrays[0].dtype\n ix = np.indices(shape)\n ix = ix.reshape(len(arrays), -1).T\n if out is None:\n out = np.empty_like(ix, dtype=dtype)\n for (n, arr) in enumerate(arrays):\n out[:, n] = arrays[n][ix[:, n]]\n return out" }, { "name": "density", + "unique_name": "density", "qname": "sklearn.utils.extmath.density", + "unique_qname": "sklearn.utils.extmath.density", "decorators": [], "parameters": [ { @@ -167099,7 +173241,9 @@ }, { "name": "fast_logdet", + "unique_name": "fast_logdet", "qname": "sklearn.utils.extmath.fast_logdet", + "unique_qname": "sklearn.utils.extmath.fast_logdet", "decorators": [], "parameters": [ { @@ -167121,7 +173265,9 @@ }, { "name": "log_logistic", + "unique_name": "log_logistic", "qname": "sklearn.utils.extmath.log_logistic", + "unique_qname": "sklearn.utils.extmath.log_logistic", "decorators": [], "parameters": [ { @@ -167153,7 +173299,9 @@ }, { "name": "make_nonnegative", + "unique_name": "make_nonnegative", "qname": "sklearn.utils.extmath.make_nonnegative", + "unique_qname": "sklearn.utils.extmath.make_nonnegative", "decorators": [], "parameters": [ { @@ -167185,7 +173333,9 @@ }, { "name": "randomized_range_finder", + "unique_name": "randomized_range_finder", "qname": "sklearn.utils.extmath.randomized_range_finder", + "unique_qname": "sklearn.utils.extmath.randomized_range_finder", "decorators": [], "parameters": [ { @@ -167247,7 +173397,9 @@ }, { "name": "randomized_svd", + "unique_name": "randomized_svd", "qname": "sklearn.utils.extmath.randomized_svd", + "unique_qname": "sklearn.utils.extmath.randomized_svd", "decorators": [], "parameters": [ { @@ -167339,7 +173491,9 @@ }, { "name": "row_norms", + "unique_name": "row_norms", "qname": "sklearn.utils.extmath.row_norms", + "unique_qname": "sklearn.utils.extmath.row_norms", "decorators": [], "parameters": [ { @@ -167371,7 +173525,9 @@ }, { "name": "safe_sparse_dot", + "unique_name": "safe_sparse_dot", "qname": "sklearn.utils.extmath.safe_sparse_dot", + "unique_qname": "sklearn.utils.extmath.safe_sparse_dot", "decorators": [], "parameters": [ { @@ -167413,7 +173569,9 @@ }, { "name": "softmax", + "unique_name": "softmax", "qname": "sklearn.utils.extmath.softmax", + "unique_qname": "sklearn.utils.extmath.softmax", "decorators": [], "parameters": [ { @@ -167445,7 +173603,9 @@ }, { "name": "squared_norm", + "unique_name": "squared_norm", "qname": "sklearn.utils.extmath.squared_norm", + "unique_qname": "sklearn.utils.extmath.squared_norm", "decorators": [], "parameters": [ { @@ -167467,7 +173627,9 @@ }, { "name": "stable_cumsum", + "unique_name": "stable_cumsum", "qname": "sklearn.utils.extmath.stable_cumsum", + "unique_qname": "sklearn.utils.extmath.stable_cumsum", "decorators": [], "parameters": [ { @@ -167519,7 +173681,9 @@ }, { "name": "svd_flip", + "unique_name": "svd_flip", "qname": "sklearn.utils.extmath.svd_flip", + "unique_qname": "sklearn.utils.extmath.svd_flip", "decorators": [], "parameters": [ { @@ -167561,7 +173725,9 @@ }, { "name": "weighted_mode", + "unique_name": "weighted_mode", "qname": "sklearn.utils.extmath.weighted_mode", + "unique_qname": "sklearn.utils.extmath.weighted_mode", "decorators": [], "parameters": [ { @@ -167603,7 +173769,9 @@ }, { "name": "__call__", + "unique_name": "__call__", "qname": "sklearn.utils.fixes._FuncWrapper.__call__", + "unique_qname": "sklearn.utils.fixes._FuncWrapper.__call__", "decorators": [], "parameters": [ { @@ -167625,7 +173793,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.utils.fixes._FuncWrapper.__init__", + "unique_qname": "sklearn.utils.fixes._FuncWrapper.__init__", "decorators": [], "parameters": [ { @@ -167657,7 +173827,9 @@ }, { "name": "_astype_copy_false", + "unique_name": "_astype_copy_false", "qname": "sklearn.utils.fixes._astype_copy_false", + "unique_qname": "sklearn.utils.fixes._astype_copy_false", "decorators": [], "parameters": [ { @@ -167677,9 +173849,24 @@ "docstring": "Returns the copy=False parameter for\n{ndarray, csr_matrix, csc_matrix}.astype when possible,\notherwise don't specify", "source_code": "\ndef _astype_copy_false(X):\n \"\"\"Returns the copy=False parameter for\n {ndarray, csr_matrix, csc_matrix}.astype when possible,\n otherwise don't specify\n \"\"\"\n if sp_version >= parse_version('1.1') or not sp.issparse(X):\n return {'copy': False}\n else:\n return {}" }, + { + "name": "_get_threadpool_controller", + "unique_name": "_get_threadpool_controller", + "qname": "sklearn.utils.fixes._get_threadpool_controller", + "unique_qname": "sklearn.utils.fixes._get_threadpool_controller", + "decorators": [], + "parameters": [], + "results": [], + "is_public": false, + "description": "", + "docstring": "", + "source_code": "\ndef _get_threadpool_controller():\n if not hasattr(threadpoolctl, 'ThreadpoolController'):\n return None\n if not hasattr(sklearn, '_sklearn_threadpool_controller'):\n sklearn._sklearn_threadpool_controller = threadpoolctl.ThreadpoolController()\n return sklearn._sklearn_threadpool_controller" + }, { "name": "_joblib_parallel_args", + "unique_name": "_joblib_parallel_args", "qname": "sklearn.utils.fixes._joblib_parallel_args", + "unique_qname": "sklearn.utils.fixes._joblib_parallel_args", "decorators": [], "parameters": [], "results": [], @@ -167690,7 +173877,9 @@ }, { "name": "_object_dtype_isnan", + "unique_name": "_object_dtype_isnan", "qname": "sklearn.utils.fixes._object_dtype_isnan", + "unique_qname": "sklearn.utils.fixes._object_dtype_isnan", "decorators": [], "parameters": [ { @@ -167712,7 +173901,9 @@ }, { "name": "_take_along_axis", + "unique_name": "_take_along_axis", "qname": "sklearn.utils.fixes._take_along_axis", + "unique_qname": "sklearn.utils.fixes._take_along_axis", "decorators": [], "parameters": [ { @@ -167754,7 +173945,9 @@ }, { "name": "delayed", + "unique_name": "delayed", "qname": "sklearn.utils.fixes.delayed", + "unique_qname": "sklearn.utils.fixes.delayed", "decorators": [], "parameters": [ { @@ -167776,7 +173969,9 @@ }, { "name": "linspace", + "unique_name": "linspace", "qname": "sklearn.utils.fixes.linspace", + "unique_qname": "sklearn.utils.fixes.linspace", "decorators": [], "parameters": [ { @@ -167856,9 +174051,58 @@ "docstring": "Implements a simplified linspace function as of numpy version >= 1.16.\n\nAs of numpy 1.16, the arguments start and stop can be array-like and\nthere is an optional argument `axis`.\nFor simplicity, we only allow 1d array-like to be passed to start and stop.\nSee: https://github.com/numpy/numpy/pull/12388 and numpy 1.16 release\nnotes about start and stop arrays for linspace logspace and geomspace.\n\nReturns\n-------\nout : ndarray of shape (num, n_start) or (num,)\n The output array with `n_start=start.shape[0]` columns.", "source_code": "\ndef linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0):\n \"\"\"Implements a simplified linspace function as of numpy version >= 1.16.\n\n As of numpy 1.16, the arguments start and stop can be array-like and\n there is an optional argument `axis`.\n For simplicity, we only allow 1d array-like to be passed to start and stop.\n See: https://github.com/numpy/numpy/pull/12388 and numpy 1.16 release\n notes about start and stop arrays for linspace logspace and geomspace.\n\n Returns\n -------\n out : ndarray of shape (num, n_start) or (num,)\n The output array with `n_start=start.shape[0]` columns.\n \"\"\"\n if np_version < parse_version('1.16'):\n start = np.asanyarray(start) * 1.0\n stop = np.asanyarray(stop) * 1.0\n dt = np.result_type(start, stop, float(num))\n if dtype is None:\n dtype = dt\n if start.ndim == 0 == stop.ndim:\n return np.linspace(start=start, stop=stop, num=num, endpoint=endpoint, retstep=retstep, dtype=dtype)\n if start.ndim != 1 or stop.ndim != 1 or start.shape != stop.shape:\n raise ValueError('start and stop must be 1d array-like of same shape.')\n n_start = start.shape[0]\n out = np.empty((num, n_start), dtype=dtype)\n step = np.empty(n_start, dtype=np.float)\n for i in range(n_start):\n (out[:, i], step[i]) = np.linspace(start=start[i], stop=stop[i], num=num, endpoint=endpoint, retstep=True, dtype=dtype)\n if axis != 0:\n out = np.moveaxis(out, 0, axis)\n if retstep:\n return out, step\n else:\n return out\n else:\n return np.linspace(start=start, stop=stop, num=num, endpoint=endpoint, retstep=retstep, dtype=dtype, axis=axis)" }, + { + "name": "threadpool_info", + "unique_name": "threadpool_info", + "qname": "sklearn.utils.fixes.threadpool_info", + "unique_qname": "sklearn.utils.fixes.threadpool_info", + "decorators": [], + "parameters": [], + "results": [], + "is_public": true, + "description": "", + "docstring": "", + "source_code": "\ndef threadpool_info():\n controller = _get_threadpool_controller()\n if controller is not None:\n return controller.info()\n else:\n return threadpoolctl.threadpool_info()" + }, + { + "name": "threadpool_limits", + "unique_name": "threadpool_limits", + "qname": "sklearn.utils.fixes.threadpool_limits", + "unique_qname": "sklearn.utils.fixes.threadpool_limits", + "decorators": [], + "parameters": [ + { + "name": "limits", + "default_value": "None", + "is_public": true, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "", + "description": "" + } + }, + { + "name": "user_api", + "default_value": "None", + "is_public": true, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "", + "description": "" + } + } + ], + "results": [], + "is_public": true, + "description": "", + "docstring": "", + "source_code": "\ndef threadpool_limits(limits=None, user_api=None):\n controller = _get_threadpool_controller()\n if controller is not None:\n return controller.limit(limits=limits, user_api=user_api)\n else:\n return threadpoolctl.threadpool_limits(limits=limits, user_api=user_api)" + }, { "name": "gen_batches", + "unique_name": "gen_batches", "qname": "sklearn.utils.gen_batches", + "unique_qname": "sklearn.utils.gen_batches", "decorators": [], "parameters": [ { @@ -167900,7 +174144,9 @@ }, { "name": "gen_even_slices", + "unique_name": "gen_even_slices", "qname": "sklearn.utils.gen_even_slices", + "unique_qname": "sklearn.utils.gen_even_slices", "decorators": [], "parameters": [ { @@ -167942,7 +174188,9 @@ }, { "name": "get_chunk_n_rows", + "unique_name": "get_chunk_n_rows", "qname": "sklearn.utils.get_chunk_n_rows", + "unique_qname": "sklearn.utils.get_chunk_n_rows", "decorators": [], "parameters": [ { @@ -167984,7 +174232,9 @@ }, { "name": "_fix_connected_components", + "unique_name": "_fix_connected_components", "qname": "sklearn.utils.graph._fix_connected_components", + "unique_qname": "sklearn.utils.graph._fix_connected_components", "decorators": [], "parameters": [ { @@ -168056,7 +174306,9 @@ }, { "name": "graph_shortest_path", + "unique_name": "graph_shortest_path", "qname": "sklearn.utils.graph.graph_shortest_path", + "unique_qname": "sklearn.utils.graph.graph_shortest_path", "decorators": [ "deprecated('`graph_shortest_path` is deprecated in 1.0 (renaming of 0.25) and will be removed in 1.2. Use `scipy.sparse.csgraph.shortest_path` instead.')" ], @@ -168087,7 +174339,7 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "string ['auto'|'FW'|'D']", + "type": "{'auto', 'FW', 'D'}, default='auto'", "description": "method to use. Options are\n'auto' : attempt to choose the best method for the current problem\n'FW' : Floyd-Warshall algorithm. O[N^3]\n'D' : Dijkstra's algorithm with Fibonacci stacks. O[(k+log(N))N^2]" } } @@ -168095,12 +174347,14 @@ "results": [], "is_public": true, "description": "Shortest-path graph search on a positive directed or undirected graph.", - "docstring": "Shortest-path graph search on a positive directed or undirected graph.\n\nParameters\n----------\ndist_matrix : arraylike or sparse matrix, shape = (N,N)\n Array of positive distances.\n If vertex i is connected to vertex j, then dist_matrix[i,j] gives\n the distance between the vertices.\n If vertex i is not connected to vertex j, then dist_matrix[i,j] = 0\n\ndirected : boolean\n if True, then find the shortest path on a directed graph: only\n progress from a point to its neighbors, not the other way around.\n if False, then find the shortest path on an undirected graph: the\n algorithm can progress from a point to its neighbors and vice versa.\n\nmethod : string ['auto'|'FW'|'D']\n method to use. Options are\n 'auto' : attempt to choose the best method for the current problem\n 'FW' : Floyd-Warshall algorithm. O[N^3]\n 'D' : Dijkstra's algorithm with Fibonacci stacks. O[(k+log(N))N^2]\n\nReturns\n-------\nG : np.ndarray, float, shape = [N,N]\n G[i,j] gives the shortest distance from point i to point j\n along the graph.\n\nNotes\n-----\nAs currently implemented, Dijkstra's algorithm does not work for\ngraphs with direction-dependent distances when directed == False.\ni.e., if dist_matrix[i,j] and dist_matrix[j,i] are not equal and\nboth are nonzero, method='D' will not necessarily yield the correct\nresult.\nAlso, these routines have not been tested for graphs with negative\ndistances. Negative distances can lead to infinite cycles that must\nbe handled by specialized algorithms.", - "source_code": "\n@deprecated('`graph_shortest_path` is deprecated in 1.0 (renaming of 0.25) and will be removed in 1.2. Use `scipy.sparse.csgraph.shortest_path` instead.')\ndef graph_shortest_path(dist_matrix, directed=True, method='auto'):\n \"\"\"Shortest-path graph search on a positive directed or undirected graph.\n\n Parameters\n ----------\n dist_matrix : arraylike or sparse matrix, shape = (N,N)\n Array of positive distances.\n If vertex i is connected to vertex j, then dist_matrix[i,j] gives\n the distance between the vertices.\n If vertex i is not connected to vertex j, then dist_matrix[i,j] = 0\n\n directed : boolean\n if True, then find the shortest path on a directed graph: only\n progress from a point to its neighbors, not the other way around.\n if False, then find the shortest path on an undirected graph: the\n algorithm can progress from a point to its neighbors and vice versa.\n\n method : string ['auto'|'FW'|'D']\n method to use. Options are\n 'auto' : attempt to choose the best method for the current problem\n 'FW' : Floyd-Warshall algorithm. O[N^3]\n 'D' : Dijkstra's algorithm with Fibonacci stacks. O[(k+log(N))N^2]\n\n Returns\n -------\n G : np.ndarray, float, shape = [N,N]\n G[i,j] gives the shortest distance from point i to point j\n along the graph.\n\n Notes\n -----\n As currently implemented, Dijkstra's algorithm does not work for\n graphs with direction-dependent distances when directed == False.\n i.e., if dist_matrix[i,j] and dist_matrix[j,i] are not equal and\n both are nonzero, method='D' will not necessarily yield the correct\n result.\n Also, these routines have not been tested for graphs with negative\n distances. Negative distances can lead to infinite cycles that must\n be handled by specialized algorithms.\n \"\"\"\n return sparse.csgraph.shortest_path(dist_matrix, method=method, directed=directed)" + "docstring": "Shortest-path graph search on a positive directed or undirected graph.\n\nParameters\n----------\ndist_matrix : arraylike or sparse matrix, shape = (N,N)\n Array of positive distances.\n If vertex i is connected to vertex j, then dist_matrix[i,j] gives\n the distance between the vertices.\n If vertex i is not connected to vertex j, then dist_matrix[i,j] = 0\n\ndirected : boolean\n if True, then find the shortest path on a directed graph: only\n progress from a point to its neighbors, not the other way around.\n if False, then find the shortest path on an undirected graph: the\n algorithm can progress from a point to its neighbors and vice versa.\n\nmethod : {'auto', 'FW', 'D'}, default='auto'\n method to use. Options are\n 'auto' : attempt to choose the best method for the current problem\n 'FW' : Floyd-Warshall algorithm. O[N^3]\n 'D' : Dijkstra's algorithm with Fibonacci stacks. O[(k+log(N))N^2]\n\nReturns\n-------\nG : np.ndarray, float, shape = [N,N]\n G[i,j] gives the shortest distance from point i to point j\n along the graph.\n\nNotes\n-----\nAs currently implemented, Dijkstra's algorithm does not work for\ngraphs with direction-dependent distances when directed == False.\ni.e., if dist_matrix[i,j] and dist_matrix[j,i] are not equal and\nboth are nonzero, method='D' will not necessarily yield the correct\nresult.\nAlso, these routines have not been tested for graphs with negative\ndistances. Negative distances can lead to infinite cycles that must\nbe handled by specialized algorithms.", + "source_code": "\n@deprecated('`graph_shortest_path` is deprecated in 1.0 (renaming of 0.25) and will be removed in 1.2. Use `scipy.sparse.csgraph.shortest_path` instead.')\ndef graph_shortest_path(dist_matrix, directed=True, method='auto'):\n \"\"\"Shortest-path graph search on a positive directed or undirected graph.\n\n Parameters\n ----------\n dist_matrix : arraylike or sparse matrix, shape = (N,N)\n Array of positive distances.\n If vertex i is connected to vertex j, then dist_matrix[i,j] gives\n the distance between the vertices.\n If vertex i is not connected to vertex j, then dist_matrix[i,j] = 0\n\n directed : boolean\n if True, then find the shortest path on a directed graph: only\n progress from a point to its neighbors, not the other way around.\n if False, then find the shortest path on an undirected graph: the\n algorithm can progress from a point to its neighbors and vice versa.\n\n method : {'auto', 'FW', 'D'}, default='auto'\n method to use. Options are\n 'auto' : attempt to choose the best method for the current problem\n 'FW' : Floyd-Warshall algorithm. O[N^3]\n 'D' : Dijkstra's algorithm with Fibonacci stacks. O[(k+log(N))N^2]\n\n Returns\n -------\n G : np.ndarray, float, shape = [N,N]\n G[i,j] gives the shortest distance from point i to point j\n along the graph.\n\n Notes\n -----\n As currently implemented, Dijkstra's algorithm does not work for\n graphs with direction-dependent distances when directed == False.\n i.e., if dist_matrix[i,j] and dist_matrix[j,i] are not equal and\n both are nonzero, method='D' will not necessarily yield the correct\n result.\n Also, these routines have not been tested for graphs with negative\n distances. Negative distances can lead to infinite cycles that must\n be handled by specialized algorithms.\n \"\"\"\n return sparse.csgraph.shortest_path(dist_matrix, method=method, directed=directed)" }, { "name": "single_source_shortest_path_length", + "unique_name": "single_source_shortest_path_length", "qname": "sklearn.utils.graph.single_source_shortest_path_length", + "unique_qname": "sklearn.utils.graph.single_source_shortest_path_length", "decorators": [], "parameters": [ { @@ -168142,7 +174396,9 @@ }, { "name": "indices_to_mask", + "unique_name": "indices_to_mask", "qname": "sklearn.utils.indices_to_mask", + "unique_qname": "sklearn.utils.indices_to_mask", "decorators": [], "parameters": [ { @@ -168174,7 +174430,9 @@ }, { "name": "is_scalar_nan", + "unique_name": "is_scalar_nan", "qname": "sklearn.utils.is_scalar_nan", + "unique_qname": "sklearn.utils.is_scalar_nan", "decorators": [], "parameters": [ { @@ -168191,12 +174449,14 @@ "results": [], "is_public": true, "description": "Tests if x is NaN.\n\nThis function is meant to overcome the issue that np.isnan does not allow non-numerical types as input, and that np.nan is not float('nan').", - "docstring": "Tests if x is NaN.\n\nThis function is meant to overcome the issue that np.isnan does not allow\nnon-numerical types as input, and that np.nan is not float('nan').\n\nParameters\n----------\nx : any type\n\nReturns\n-------\nboolean\n\nExamples\n--------\n>>> is_scalar_nan(np.nan)\nTrue\n>>> is_scalar_nan(float(\"nan\"))\nTrue\n>>> is_scalar_nan(None)\nFalse\n>>> is_scalar_nan(\"\")\nFalse\n>>> is_scalar_nan([np.nan])\nFalse", - "source_code": "\ndef is_scalar_nan(x):\n \"\"\"Tests if x is NaN.\n\n This function is meant to overcome the issue that np.isnan does not allow\n non-numerical types as input, and that np.nan is not float('nan').\n\n Parameters\n ----------\n x : any type\n\n Returns\n -------\n boolean\n\n Examples\n --------\n >>> is_scalar_nan(np.nan)\n True\n >>> is_scalar_nan(float(\"nan\"))\n True\n >>> is_scalar_nan(None)\n False\n >>> is_scalar_nan(\"\")\n False\n >>> is_scalar_nan([np.nan])\n False\n \"\"\"\n return isinstance(x, numbers.Real) and math.isnan(x)" + "docstring": "Tests if x is NaN.\n\nThis function is meant to overcome the issue that np.isnan does not allow\nnon-numerical types as input, and that np.nan is not float('nan').\n\nParameters\n----------\nx : any type\n\nReturns\n-------\nboolean\n\nExamples\n--------\n>>> import numpy as np\n>>> from sklearn.utils import is_scalar_nan\n>>> is_scalar_nan(np.nan)\nTrue\n>>> is_scalar_nan(float(\"nan\"))\nTrue\n>>> is_scalar_nan(None)\nFalse\n>>> is_scalar_nan(\"\")\nFalse\n>>> is_scalar_nan([np.nan])\nFalse", + "source_code": "\ndef is_scalar_nan(x):\n \"\"\"Tests if x is NaN.\n\n This function is meant to overcome the issue that np.isnan does not allow\n non-numerical types as input, and that np.nan is not float('nan').\n\n Parameters\n ----------\n x : any type\n\n Returns\n -------\n boolean\n\n Examples\n --------\n >>> import numpy as np\n >>> from sklearn.utils import is_scalar_nan\n >>> is_scalar_nan(np.nan)\n True\n >>> is_scalar_nan(float(\"nan\"))\n True\n >>> is_scalar_nan(None)\n False\n >>> is_scalar_nan(\"\")\n False\n >>> is_scalar_nan([np.nan])\n False\n \"\"\"\n return isinstance(x, numbers.Real) and math.isnan(x)" }, { "name": "__get__", + "unique_name": "__get__", "qname": "sklearn.utils.metaestimators._AvailableIfDescriptor.__get__", + "unique_qname": "sklearn.utils.metaestimators._AvailableIfDescriptor.__get__", "decorators": [], "parameters": [ { @@ -168238,7 +174498,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.utils.metaestimators._AvailableIfDescriptor.__init__", + "unique_qname": "sklearn.utils.metaestimators._AvailableIfDescriptor.__init__", "decorators": [], "parameters": [ { @@ -168290,7 +174552,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.utils.metaestimators._BaseComposition.__init__", + "unique_qname": "sklearn.utils.metaestimators._BaseComposition.__init__", "decorators": ["abstractmethod"], "parameters": [ { @@ -168312,7 +174576,9 @@ }, { "name": "_get_params", + "unique_name": "_get_params", "qname": "sklearn.utils.metaestimators._BaseComposition._get_params", + "unique_qname": "sklearn.utils.metaestimators._BaseComposition._get_params", "decorators": [], "parameters": [ { @@ -168354,7 +174620,9 @@ }, { "name": "_replace_estimator", + "unique_name": "_replace_estimator", "qname": "sklearn.utils.metaestimators._BaseComposition._replace_estimator", + "unique_qname": "sklearn.utils.metaestimators._BaseComposition._replace_estimator", "decorators": [], "parameters": [ { @@ -168406,7 +174674,9 @@ }, { "name": "_set_params", + "unique_name": "_set_params", "qname": "sklearn.utils.metaestimators._BaseComposition._set_params", + "unique_qname": "sklearn.utils.metaestimators._BaseComposition._set_params", "decorators": [], "parameters": [ { @@ -168438,7 +174708,9 @@ }, { "name": "_validate_names", + "unique_name": "_validate_names", "qname": "sklearn.utils.metaestimators._BaseComposition._validate_names", + "unique_qname": "sklearn.utils.metaestimators._BaseComposition._validate_names", "decorators": [], "parameters": [ { @@ -168470,7 +174742,9 @@ }, { "name": "__init__", + "unique_name": "__init__", "qname": "sklearn.utils.metaestimators._IffHasAttrDescriptor.__init__", + "unique_qname": "sklearn.utils.metaestimators._IffHasAttrDescriptor.__init__", "decorators": [], "parameters": [ { @@ -168522,7 +174796,9 @@ }, { "name": "_check", + "unique_name": "_check", "qname": "sklearn.utils.metaestimators._IffHasAttrDescriptor._check", + "unique_qname": "sklearn.utils.metaestimators._IffHasAttrDescriptor._check", "decorators": [], "parameters": [ { @@ -168550,11 +174826,13 @@ "is_public": false, "description": "", "docstring": "", - "source_code": "\ndef _check(self, obj):\n delegate = None\n for delegate_name in self.delegate_names:\n try:\n delegate = attrgetter(delegate_name)(obj)\n break\n except AttributeError:\n continue\n if delegate is None:\n return False\n return getattr(delegate, self.attribute_name) or True" + "source_code": "\ndef _check(self, obj):\n delegate = None\n for delegate_name in self.delegate_names:\n try:\n delegate = attrgetter(delegate_name)(obj)\n break\n except AttributeError:\n continue\n if delegate is None:\n return False\n getattr(delegate, self.attribute_name)\n return True" }, { "name": "_safe_split", + "unique_name": "_safe_split", "qname": "sklearn.utils.metaestimators._safe_split", + "unique_qname": "sklearn.utils.metaestimators._safe_split", "decorators": [], "parameters": [ { @@ -168616,7 +174894,9 @@ }, { "name": "available_if", + "unique_name": "available_if", "qname": "sklearn.utils.metaestimators.available_if", + "unique_qname": "sklearn.utils.metaestimators.available_if", "decorators": [], "parameters": [ { @@ -168638,7 +174918,9 @@ }, { "name": "if_delegate_has_method", + "unique_name": "if_delegate_has_method", "qname": "sklearn.utils.metaestimators.if_delegate_has_method", + "unique_qname": "sklearn.utils.metaestimators.if_delegate_has_method", "decorators": [], "parameters": [ { @@ -168647,7 +174929,7 @@ "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { - "type": "string, list of strings or tuple of strings", + "type": "str, list of str or tuple of str", "description": "Name of the sub-estimator that can be accessed as an attribute of the\nbase object. If a list or a tuple of names are provided, the first\nsub-estimator that is an attribute of the base object will be used." } } @@ -168655,12 +174937,14 @@ "results": [], "is_public": true, "description": "Create a decorator for methods that are delegated to a sub-estimator\n\nThis enables ducktyping by hasattr returning True according to the sub-estimator.", - "docstring": "Create a decorator for methods that are delegated to a sub-estimator\n\nThis enables ducktyping by hasattr returning True according to the\nsub-estimator.\n\nParameters\n----------\ndelegate : string, list of strings or tuple of strings\n Name of the sub-estimator that can be accessed as an attribute of the\n base object. If a list or a tuple of names are provided, the first\n sub-estimator that is an attribute of the base object will be used.", - "source_code": "\ndef if_delegate_has_method(delegate):\n \"\"\"Create a decorator for methods that are delegated to a sub-estimator\n\n This enables ducktyping by hasattr returning True according to the\n sub-estimator.\n\n Parameters\n ----------\n delegate : string, list of strings or tuple of strings\n Name of the sub-estimator that can be accessed as an attribute of the\n base object. If a list or a tuple of names are provided, the first\n sub-estimator that is an attribute of the base object will be used.\n\n \"\"\"\n if isinstance(delegate, list):\n delegate = tuple(delegate)\n if not isinstance(delegate, tuple):\n delegate = (delegate, )\n return lambda fn: _IffHasAttrDescriptor(fn, delegate, attribute_name=fn.__name__)" + "docstring": "Create a decorator for methods that are delegated to a sub-estimator\n\nThis enables ducktyping by hasattr returning True according to the\nsub-estimator.\n\nParameters\n----------\ndelegate : str, list of str or tuple of str\n Name of the sub-estimator that can be accessed as an attribute of the\n base object. If a list or a tuple of names are provided, the first\n sub-estimator that is an attribute of the base object will be used.", + "source_code": "\ndef if_delegate_has_method(delegate):\n \"\"\"Create a decorator for methods that are delegated to a sub-estimator\n\n This enables ducktyping by hasattr returning True according to the\n sub-estimator.\n\n Parameters\n ----------\n delegate : str, list of str or tuple of str\n Name of the sub-estimator that can be accessed as an attribute of the\n base object. If a list or a tuple of names are provided, the first\n sub-estimator that is an attribute of the base object will be used.\n\n \"\"\"\n if isinstance(delegate, list):\n delegate = tuple(delegate)\n if not isinstance(delegate, tuple):\n delegate = (delegate, )\n return lambda fn: _IffHasAttrDescriptor(fn, delegate, attribute_name=fn.__name__)" }, { "name": "_check_partial_fit_first_call", + "unique_name": "_check_partial_fit_first_call", "qname": "sklearn.utils.multiclass._check_partial_fit_first_call", + "unique_qname": "sklearn.utils.multiclass._check_partial_fit_first_call", "decorators": [], "parameters": [ { @@ -168692,7 +174976,9 @@ }, { "name": "_is_integral_float", + "unique_name": "_is_integral_float", "qname": "sklearn.utils.multiclass._is_integral_float", + "unique_qname": "sklearn.utils.multiclass._is_integral_float", "decorators": [], "parameters": [ { @@ -168714,7 +175000,9 @@ }, { "name": "_ovr_decision_function", + "unique_name": "_ovr_decision_function", "qname": "sklearn.utils.multiclass._ovr_decision_function", + "unique_qname": "sklearn.utils.multiclass._ovr_decision_function", "decorators": [], "parameters": [ { @@ -168756,7 +175044,9 @@ }, { "name": "_unique_indicator", + "unique_name": "_unique_indicator", "qname": "sklearn.utils.multiclass._unique_indicator", + "unique_qname": "sklearn.utils.multiclass._unique_indicator", "decorators": [], "parameters": [ { @@ -168778,7 +175068,9 @@ }, { "name": "_unique_multiclass", + "unique_name": "_unique_multiclass", "qname": "sklearn.utils.multiclass._unique_multiclass", + "unique_qname": "sklearn.utils.multiclass._unique_multiclass", "decorators": [], "parameters": [ { @@ -168800,7 +175092,9 @@ }, { "name": "check_classification_targets", + "unique_name": "check_classification_targets", "qname": "sklearn.utils.multiclass.check_classification_targets", + "unique_qname": "sklearn.utils.multiclass.check_classification_targets", "decorators": [], "parameters": [ { @@ -168822,7 +175116,9 @@ }, { "name": "class_distribution", + "unique_name": "class_distribution", "qname": "sklearn.utils.multiclass.class_distribution", + "unique_qname": "sklearn.utils.multiclass.class_distribution", "decorators": [], "parameters": [ { @@ -168854,7 +175150,9 @@ }, { "name": "is_multilabel", + "unique_name": "is_multilabel", "qname": "sklearn.utils.multiclass.is_multilabel", + "unique_qname": "sklearn.utils.multiclass.is_multilabel", "decorators": [], "parameters": [ { @@ -168876,7 +175174,9 @@ }, { "name": "type_of_target", + "unique_name": "type_of_target", "qname": "sklearn.utils.multiclass.type_of_target", + "unique_qname": "sklearn.utils.multiclass.type_of_target", "decorators": [], "parameters": [ { @@ -168893,12 +175193,14 @@ "results": [], "is_public": true, "description": "Determine the type of data indicated by the target.\n\nNote that this type is the most specific type that can be inferred. For example: * ``binary`` is more specific but compatible with ``multiclass``. * ``multiclass`` of integers is more specific but compatible with ``continuous``. * ``multilabel-indicator`` is more specific but compatible with ``multiclass-multioutput``.", - "docstring": "Determine the type of data indicated by the target.\n\nNote that this type is the most specific type that can be inferred.\nFor example:\n\n * ``binary`` is more specific but compatible with ``multiclass``.\n * ``multiclass`` of integers is more specific but compatible with\n ``continuous``.\n * ``multilabel-indicator`` is more specific but compatible with\n ``multiclass-multioutput``.\n\nParameters\n----------\ny : array-like\n\nReturns\n-------\ntarget_type : str\n One of:\n\n * 'continuous': `y` is an array-like of floats that are not all\n integers, and is 1d or a column vector.\n * 'continuous-multioutput': `y` is a 2d array of floats that are\n not all integers, and both dimensions are of size > 1.\n * 'binary': `y` contains <= 2 discrete values and is 1d or a column\n vector.\n * 'multiclass': `y` contains more than two discrete values, is not a\n sequence of sequences, and is 1d or a column vector.\n * 'multiclass-multioutput': `y` is a 2d array that contains more\n than two discrete values, is not a sequence of sequences, and both\n dimensions are of size > 1.\n * 'multilabel-indicator': `y` is a label indicator matrix, an array\n of two dimensions with at least two columns, and at most 2 unique\n values.\n * 'unknown': `y` is array-like but none of the above, such as a 3d\n array, sequence of sequences, or an array of non-sequence objects.\n\nExamples\n--------\n>>> import numpy as np\n>>> type_of_target([0.1, 0.6])\n'continuous'\n>>> type_of_target([1, -1, -1, 1])\n'binary'\n>>> type_of_target(['a', 'b', 'a'])\n'binary'\n>>> type_of_target([1.0, 2.0])\n'binary'\n>>> type_of_target([1, 0, 2])\n'multiclass'\n>>> type_of_target([1.0, 0.0, 3.0])\n'multiclass'\n>>> type_of_target(['a', 'b', 'c'])\n'multiclass'\n>>> type_of_target(np.array([[1, 2], [3, 1]]))\n'multiclass-multioutput'\n>>> type_of_target([[1, 2]])\n'multilabel-indicator'\n>>> type_of_target(np.array([[1.5, 2.0], [3.0, 1.6]]))\n'continuous-multioutput'\n>>> type_of_target(np.array([[0, 1], [1, 1]]))\n'multilabel-indicator'", - "source_code": "\ndef type_of_target(y):\n \"\"\"Determine the type of data indicated by the target.\n\n Note that this type is the most specific type that can be inferred.\n For example:\n\n * ``binary`` is more specific but compatible with ``multiclass``.\n * ``multiclass`` of integers is more specific but compatible with\n ``continuous``.\n * ``multilabel-indicator`` is more specific but compatible with\n ``multiclass-multioutput``.\n\n Parameters\n ----------\n y : array-like\n\n Returns\n -------\n target_type : str\n One of:\n\n * 'continuous': `y` is an array-like of floats that are not all\n integers, and is 1d or a column vector.\n * 'continuous-multioutput': `y` is a 2d array of floats that are\n not all integers, and both dimensions are of size > 1.\n * 'binary': `y` contains <= 2 discrete values and is 1d or a column\n vector.\n * 'multiclass': `y` contains more than two discrete values, is not a\n sequence of sequences, and is 1d or a column vector.\n * 'multiclass-multioutput': `y` is a 2d array that contains more\n than two discrete values, is not a sequence of sequences, and both\n dimensions are of size > 1.\n * 'multilabel-indicator': `y` is a label indicator matrix, an array\n of two dimensions with at least two columns, and at most 2 unique\n values.\n * 'unknown': `y` is array-like but none of the above, such as a 3d\n array, sequence of sequences, or an array of non-sequence objects.\n\n Examples\n --------\n >>> import numpy as np\n >>> type_of_target([0.1, 0.6])\n 'continuous'\n >>> type_of_target([1, -1, -1, 1])\n 'binary'\n >>> type_of_target(['a', 'b', 'a'])\n 'binary'\n >>> type_of_target([1.0, 2.0])\n 'binary'\n >>> type_of_target([1, 0, 2])\n 'multiclass'\n >>> type_of_target([1.0, 0.0, 3.0])\n 'multiclass'\n >>> type_of_target(['a', 'b', 'c'])\n 'multiclass'\n >>> type_of_target(np.array([[1, 2], [3, 1]]))\n 'multiclass-multioutput'\n >>> type_of_target([[1, 2]])\n 'multilabel-indicator'\n >>> type_of_target(np.array([[1.5, 2.0], [3.0, 1.6]]))\n 'continuous-multioutput'\n >>> type_of_target(np.array([[0, 1], [1, 1]]))\n 'multilabel-indicator'\n \"\"\"\n valid = (isinstance(y, (Sequence, spmatrix)) or hasattr(y, '__array__')) and not isinstance(y, str)\n if not valid:\n raise ValueError('Expected array-like (array or non-string sequence), got %r' % y)\n sparse_pandas = y.__class__.__name__ in ['SparseSeries', 'SparseArray']\n if sparse_pandas:\n raise ValueError(\"y cannot be class 'SparseSeries' or 'SparseArray'\")\n if is_multilabel(y):\n return 'multilabel-indicator'\n with warnings.catch_warnings():\n warnings.simplefilter('error', np.VisibleDeprecationWarning)\n try:\n y = np.asarray(y)\n except np.VisibleDeprecationWarning:\n y = np.asarray(y, dtype=object)\n try:\n if not hasattr(y[0], '__array__') and isinstance(y[0], Sequence) and not isinstance(y[0], str):\n raise ValueError('You appear to be using a legacy multi-label data representation. Sequence of sequences are no longer supported; use a binary array or sparse matrix instead - the MultiLabelBinarizer transformer can convert to this format.')\n except IndexError:\n pass\n if y.ndim > 2 or y.dtype == object and len(y) and not isinstance(y.flat[0], str):\n return 'unknown'\n if y.ndim == 2 and y.shape[1] == 0:\n return 'unknown'\n if y.ndim == 2 and y.shape[1] > 1:\n suffix = '-multioutput'\n else:\n suffix = ''\n if y.dtype.kind == 'f' and np.any(y != y.astype(int)):\n _assert_all_finite(y)\n return 'continuous' + suffix\n if len(np.unique(y)) > 2 or y.ndim >= 2 and len(y[0]) > 1:\n return 'multiclass' + suffix\n else:\n return 'binary'" + "docstring": "Determine the type of data indicated by the target.\n\nNote that this type is the most specific type that can be inferred.\nFor example:\n\n * ``binary`` is more specific but compatible with ``multiclass``.\n * ``multiclass`` of integers is more specific but compatible with\n ``continuous``.\n * ``multilabel-indicator`` is more specific but compatible with\n ``multiclass-multioutput``.\n\nParameters\n----------\ny : array-like\n\nReturns\n-------\ntarget_type : str\n One of:\n\n * 'continuous': `y` is an array-like of floats that are not all\n integers, and is 1d or a column vector.\n * 'continuous-multioutput': `y` is a 2d array of floats that are\n not all integers, and both dimensions are of size > 1.\n * 'binary': `y` contains <= 2 discrete values and is 1d or a column\n vector.\n * 'multiclass': `y` contains more than two discrete values, is not a\n sequence of sequences, and is 1d or a column vector.\n * 'multiclass-multioutput': `y` is a 2d array that contains more\n than two discrete values, is not a sequence of sequences, and both\n dimensions are of size > 1.\n * 'multilabel-indicator': `y` is a label indicator matrix, an array\n of two dimensions with at least two columns, and at most 2 unique\n values.\n * 'unknown': `y` is array-like but none of the above, such as a 3d\n array, sequence of sequences, or an array of non-sequence objects.\n\nExamples\n--------\n>>> from sklearn.utils.multiclass import type_of_target\n>>> import numpy as np\n>>> type_of_target([0.1, 0.6])\n'continuous'\n>>> type_of_target([1, -1, -1, 1])\n'binary'\n>>> type_of_target(['a', 'b', 'a'])\n'binary'\n>>> type_of_target([1.0, 2.0])\n'binary'\n>>> type_of_target([1, 0, 2])\n'multiclass'\n>>> type_of_target([1.0, 0.0, 3.0])\n'multiclass'\n>>> type_of_target(['a', 'b', 'c'])\n'multiclass'\n>>> type_of_target(np.array([[1, 2], [3, 1]]))\n'multiclass-multioutput'\n>>> type_of_target([[1, 2]])\n'multilabel-indicator'\n>>> type_of_target(np.array([[1.5, 2.0], [3.0, 1.6]]))\n'continuous-multioutput'\n>>> type_of_target(np.array([[0, 1], [1, 1]]))\n'multilabel-indicator'", + "source_code": "\ndef type_of_target(y):\n \"\"\"Determine the type of data indicated by the target.\n\n Note that this type is the most specific type that can be inferred.\n For example:\n\n * ``binary`` is more specific but compatible with ``multiclass``.\n * ``multiclass`` of integers is more specific but compatible with\n ``continuous``.\n * ``multilabel-indicator`` is more specific but compatible with\n ``multiclass-multioutput``.\n\n Parameters\n ----------\n y : array-like\n\n Returns\n -------\n target_type : str\n One of:\n\n * 'continuous': `y` is an array-like of floats that are not all\n integers, and is 1d or a column vector.\n * 'continuous-multioutput': `y` is a 2d array of floats that are\n not all integers, and both dimensions are of size > 1.\n * 'binary': `y` contains <= 2 discrete values and is 1d or a column\n vector.\n * 'multiclass': `y` contains more than two discrete values, is not a\n sequence of sequences, and is 1d or a column vector.\n * 'multiclass-multioutput': `y` is a 2d array that contains more\n than two discrete values, is not a sequence of sequences, and both\n dimensions are of size > 1.\n * 'multilabel-indicator': `y` is a label indicator matrix, an array\n of two dimensions with at least two columns, and at most 2 unique\n values.\n * 'unknown': `y` is array-like but none of the above, such as a 3d\n array, sequence of sequences, or an array of non-sequence objects.\n\n Examples\n --------\n >>> from sklearn.utils.multiclass import type_of_target\n >>> import numpy as np\n >>> type_of_target([0.1, 0.6])\n 'continuous'\n >>> type_of_target([1, -1, -1, 1])\n 'binary'\n >>> type_of_target(['a', 'b', 'a'])\n 'binary'\n >>> type_of_target([1.0, 2.0])\n 'binary'\n >>> type_of_target([1, 0, 2])\n 'multiclass'\n >>> type_of_target([1.0, 0.0, 3.0])\n 'multiclass'\n >>> type_of_target(['a', 'b', 'c'])\n 'multiclass'\n >>> type_of_target(np.array([[1, 2], [3, 1]]))\n 'multiclass-multioutput'\n >>> type_of_target([[1, 2]])\n 'multilabel-indicator'\n >>> type_of_target(np.array([[1.5, 2.0], [3.0, 1.6]]))\n 'continuous-multioutput'\n >>> type_of_target(np.array([[0, 1], [1, 1]]))\n 'multilabel-indicator'\n \"\"\"\n valid = (isinstance(y, (Sequence, spmatrix)) or hasattr(y, '__array__')) and not isinstance(y, str)\n if not valid:\n raise ValueError('Expected array-like (array or non-string sequence), got %r' % y)\n sparse_pandas = y.__class__.__name__ in ['SparseSeries', 'SparseArray']\n if sparse_pandas:\n raise ValueError(\"y cannot be class 'SparseSeries' or 'SparseArray'\")\n if is_multilabel(y):\n return 'multilabel-indicator'\n with warnings.catch_warnings():\n warnings.simplefilter('error', np.VisibleDeprecationWarning)\n try:\n y = np.asarray(y)\n except np.VisibleDeprecationWarning:\n y = np.asarray(y, dtype=object)\n try:\n if not hasattr(y[0], '__array__') and isinstance(y[0], Sequence) and not isinstance(y[0], str):\n raise ValueError('You appear to be using a legacy multi-label data representation. Sequence of sequences are no longer supported; use a binary array or sparse matrix instead - the MultiLabelBinarizer transformer can convert to this format.')\n except IndexError:\n pass\n if y.ndim > 2 or y.dtype == object and len(y) and not isinstance(y.flat[0], str):\n return 'unknown'\n if y.ndim == 2 and y.shape[1] == 0:\n return 'unknown'\n if y.ndim == 2 and y.shape[1] > 1:\n suffix = '-multioutput'\n else:\n suffix = ''\n if y.dtype.kind == 'f' and np.any(y != y.astype(int)):\n _assert_all_finite(y)\n return 'continuous' + suffix\n if len(np.unique(y)) > 2 or y.ndim >= 2 and len(y[0]) > 1:\n return 'multiclass' + suffix\n else:\n return 'binary'" }, { "name": "unique_labels", + "unique_name": "unique_labels", "qname": "sklearn.utils.multiclass.unique_labels", + "unique_qname": "sklearn.utils.multiclass.unique_labels", "decorators": [], "parameters": [], "results": [], @@ -168909,7 +175211,9 @@ }, { "name": "_cg", + "unique_name": "_cg", "qname": "sklearn.utils.optimize._cg", + "unique_qname": "sklearn.utils.optimize._cg", "decorators": [], "parameters": [ { @@ -168961,7 +175265,9 @@ }, { "name": "_check_optimize_result", + "unique_name": "_check_optimize_result", "qname": "sklearn.utils.optimize._check_optimize_result", + "unique_qname": "sklearn.utils.optimize._check_optimize_result", "decorators": [], "parameters": [ { @@ -169013,7 +175319,9 @@ }, { "name": "_line_search_wolfe12", + "unique_name": "_line_search_wolfe12", "qname": "sklearn.utils.optimize._line_search_wolfe12", + "unique_qname": "sklearn.utils.optimize._line_search_wolfe12", "decorators": [], "parameters": [ { @@ -169095,7 +175403,9 @@ }, { "name": "_newton_cg", + "unique_name": "_newton_cg", "qname": "sklearn.utils.optimize._newton_cg", + "unique_qname": "sklearn.utils.optimize._newton_cg", "decorators": [], "parameters": [ { @@ -169207,7 +175517,9 @@ }, { "name": "_random_choice_csc", + "unique_name": "_random_choice_csc", "qname": "sklearn.utils.random._random_choice_csc", + "unique_qname": "sklearn.utils.random._random_choice_csc", "decorators": [], "parameters": [ { @@ -169259,7 +175571,9 @@ }, { "name": "resample", + "unique_name": "resample", "qname": "sklearn.utils.resample", + "unique_qname": "sklearn.utils.resample", "decorators": [], "parameters": [ { @@ -169306,12 +175620,14 @@ "results": [], "is_public": true, "description": "Resample arrays or sparse matrices in a consistent way.\n\nThe default strategy implements one step of the bootstrapping procedure.", - "docstring": "Resample arrays or sparse matrices in a consistent way.\n\nThe default strategy implements one step of the bootstrapping\nprocedure.\n\nParameters\n----------\n*arrays : sequence of array-like of shape (n_samples,) or (n_samples, n_outputs)\n Indexable data-structures can be arrays, lists, dataframes or scipy\n sparse matrices with consistent first dimension.\n\nreplace : bool, default=True\n Implements resampling with replacement. If False, this will implement\n (sliced) random permutations.\n\nn_samples : int, default=None\n Number of samples to generate. If left to None this is\n automatically set to the first dimension of the arrays.\n If replace is False it should not be larger than the length of\n arrays.\n\nrandom_state : int, RandomState instance or None, default=None\n Determines random number generation for shuffling\n the data.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\nstratify : array-like of shape (n_samples,) or (n_samples, n_outputs), default=None\n If not None, data is split in a stratified fashion, using this as\n the class labels.\n\nReturns\n-------\nresampled_arrays : sequence of array-like of shape (n_samples,) or (n_samples, n_outputs)\n Sequence of resampled copies of the collections. The original arrays\n are not impacted.\n\nExamples\n--------\nIt is possible to mix sparse and dense arrays in the same run::\n\n >>> X = np.array([[1., 0.], [2., 1.], [0., 0.]])\n >>> y = np.array([0, 1, 2])\n\n >>> from scipy.sparse import coo_matrix\n >>> X_sparse = coo_matrix(X)\n\n >>> from sklearn.utils import resample\n >>> X, X_sparse, y = resample(X, X_sparse, y, random_state=0)\n >>> X\n array([[1., 0.],\n [2., 1.],\n [1., 0.]])\n\n >>> X_sparse\n <3x2 sparse matrix of type '<... 'numpy.float64'>'\n with 4 stored elements in Compressed Sparse Row format>\n\n >>> X_sparse.toarray()\n array([[1., 0.],\n [2., 1.],\n [1., 0.]])\n\n >>> y\n array([0, 1, 0])\n\n >>> resample(y, n_samples=2, random_state=0)\n array([0, 1])\n\nExample using stratification::\n\n >>> y = [0, 0, 1, 1, 1, 1, 1, 1, 1]\n >>> resample(y, n_samples=5, replace=False, stratify=y,\n ... random_state=0)\n [1, 1, 1, 0, 1]\n\nSee Also\n--------\nshuffle", - "source_code": "\ndef resample(*arrays, replace=True, n_samples=None, random_state=None, stratify=None):\n \"\"\"Resample arrays or sparse matrices in a consistent way.\n\n The default strategy implements one step of the bootstrapping\n procedure.\n\n Parameters\n ----------\n *arrays : sequence of array-like of shape (n_samples,) or (n_samples, n_outputs)\n Indexable data-structures can be arrays, lists, dataframes or scipy\n sparse matrices with consistent first dimension.\n\n replace : bool, default=True\n Implements resampling with replacement. If False, this will implement\n (sliced) random permutations.\n\n n_samples : int, default=None\n Number of samples to generate. If left to None this is\n automatically set to the first dimension of the arrays.\n If replace is False it should not be larger than the length of\n arrays.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation for shuffling\n the data.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n stratify : array-like of shape (n_samples,) or (n_samples, n_outputs), default=None\n If not None, data is split in a stratified fashion, using this as\n the class labels.\n\n Returns\n -------\n resampled_arrays : sequence of array-like of shape (n_samples,) or (n_samples, n_outputs)\n Sequence of resampled copies of the collections. The original arrays\n are not impacted.\n\n Examples\n --------\n It is possible to mix sparse and dense arrays in the same run::\n\n >>> X = np.array([[1., 0.], [2., 1.], [0., 0.]])\n >>> y = np.array([0, 1, 2])\n\n >>> from scipy.sparse import coo_matrix\n >>> X_sparse = coo_matrix(X)\n\n >>> from sklearn.utils import resample\n >>> X, X_sparse, y = resample(X, X_sparse, y, random_state=0)\n >>> X\n array([[1., 0.],\n [2., 1.],\n [1., 0.]])\n\n >>> X_sparse\n <3x2 sparse matrix of type '<... 'numpy.float64'>'\n with 4 stored elements in Compressed Sparse Row format>\n\n >>> X_sparse.toarray()\n array([[1., 0.],\n [2., 1.],\n [1., 0.]])\n\n >>> y\n array([0, 1, 0])\n\n >>> resample(y, n_samples=2, random_state=0)\n array([0, 1])\n\n Example using stratification::\n\n >>> y = [0, 0, 1, 1, 1, 1, 1, 1, 1]\n >>> resample(y, n_samples=5, replace=False, stratify=y,\n ... random_state=0)\n [1, 1, 1, 0, 1]\n\n See Also\n --------\n shuffle\n \"\"\"\n max_n_samples = n_samples\n random_state = check_random_state(random_state)\n if len(arrays) == 0:\n return None\n first = arrays[0]\n n_samples = first.shape[0] if hasattr(first, 'shape') else len(first)\n if max_n_samples is None:\n max_n_samples = n_samples\n elif max_n_samples > n_samples and not replace:\n raise ValueError('Cannot sample %d out of arrays with dim %d when replace is False' % (max_n_samples, n_samples))\n check_consistent_length(*arrays)\n if stratify is None:\n if replace:\n indices = random_state.randint(0, n_samples, size=(max_n_samples, ))\n else:\n indices = np.arange(n_samples)\n random_state.shuffle(indices)\n indices = indices[:max_n_samples]\n else:\n y = check_array(stratify, ensure_2d=False, dtype=None)\n if y.ndim == 2:\n y = np.array([' '.join(row.astype('str')) for row in y])\n (classes, y_indices) = np.unique(y, return_inverse=True)\n n_classes = classes.shape[0]\n class_counts = np.bincount(y_indices)\n class_indices = np.split(np.argsort(y_indices, kind='mergesort'), np.cumsum(class_counts)[:-1])\n n_i = _approximate_mode(class_counts, max_n_samples, random_state)\n indices = []\n for i in range(n_classes):\n indices_i = random_state.choice(class_indices[i], n_i[i], replace=replace)\n indices.extend(indices_i)\n indices = random_state.permutation(indices)\n arrays = [a.tocsr() if issparse(a) else a for a in arrays]\n resampled_arrays = [_safe_indexing(a, indices) for a in arrays]\n if len(resampled_arrays) == 1:\n return resampled_arrays[0]\n else:\n return resampled_arrays" + "docstring": "Resample arrays or sparse matrices in a consistent way.\n\nThe default strategy implements one step of the bootstrapping\nprocedure.\n\nParameters\n----------\n*arrays : sequence of array-like of shape (n_samples,) or (n_samples, n_outputs)\n Indexable data-structures can be arrays, lists, dataframes or scipy\n sparse matrices with consistent first dimension.\n\nreplace : bool, default=True\n Implements resampling with replacement. If False, this will implement\n (sliced) random permutations.\n\nn_samples : int, default=None\n Number of samples to generate. If left to None this is\n automatically set to the first dimension of the arrays.\n If replace is False it should not be larger than the length of\n arrays.\n\nrandom_state : int, RandomState instance or None, default=None\n Determines random number generation for shuffling\n the data.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\nstratify : array-like of shape (n_samples,) or (n_samples, n_outputs), default=None\n If not None, data is split in a stratified fashion, using this as\n the class labels.\n\nReturns\n-------\nresampled_arrays : sequence of array-like of shape (n_samples,) or (n_samples, n_outputs)\n Sequence of resampled copies of the collections. The original arrays\n are not impacted.\n\nExamples\n--------\nIt is possible to mix sparse and dense arrays in the same run::\n\n >>> import numpy as np\n >>> X = np.array([[1., 0.], [2., 1.], [0., 0.]])\n >>> y = np.array([0, 1, 2])\n\n >>> from scipy.sparse import coo_matrix\n >>> X_sparse = coo_matrix(X)\n\n >>> from sklearn.utils import resample\n >>> X, X_sparse, y = resample(X, X_sparse, y, random_state=0)\n >>> X\n array([[1., 0.],\n [2., 1.],\n [1., 0.]])\n\n >>> X_sparse\n <3x2 sparse matrix of type '<... 'numpy.float64'>'\n with 4 stored elements in Compressed Sparse Row format>\n\n >>> X_sparse.toarray()\n array([[1., 0.],\n [2., 1.],\n [1., 0.]])\n\n >>> y\n array([0, 1, 0])\n\n >>> resample(y, n_samples=2, random_state=0)\n array([0, 1])\n\nExample using stratification::\n\n >>> y = [0, 0, 1, 1, 1, 1, 1, 1, 1]\n >>> resample(y, n_samples=5, replace=False, stratify=y,\n ... random_state=0)\n [1, 1, 1, 0, 1]\n\nSee Also\n--------\nshuffle", + "source_code": "\ndef resample(*arrays, replace=True, n_samples=None, random_state=None, stratify=None):\n \"\"\"Resample arrays or sparse matrices in a consistent way.\n\n The default strategy implements one step of the bootstrapping\n procedure.\n\n Parameters\n ----------\n *arrays : sequence of array-like of shape (n_samples,) or (n_samples, n_outputs)\n Indexable data-structures can be arrays, lists, dataframes or scipy\n sparse matrices with consistent first dimension.\n\n replace : bool, default=True\n Implements resampling with replacement. If False, this will implement\n (sliced) random permutations.\n\n n_samples : int, default=None\n Number of samples to generate. If left to None this is\n automatically set to the first dimension of the arrays.\n If replace is False it should not be larger than the length of\n arrays.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation for shuffling\n the data.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n stratify : array-like of shape (n_samples,) or (n_samples, n_outputs), default=None\n If not None, data is split in a stratified fashion, using this as\n the class labels.\n\n Returns\n -------\n resampled_arrays : sequence of array-like of shape (n_samples,) or (n_samples, n_outputs)\n Sequence of resampled copies of the collections. The original arrays\n are not impacted.\n\n Examples\n --------\n It is possible to mix sparse and dense arrays in the same run::\n\n >>> import numpy as np\n >>> X = np.array([[1., 0.], [2., 1.], [0., 0.]])\n >>> y = np.array([0, 1, 2])\n\n >>> from scipy.sparse import coo_matrix\n >>> X_sparse = coo_matrix(X)\n\n >>> from sklearn.utils import resample\n >>> X, X_sparse, y = resample(X, X_sparse, y, random_state=0)\n >>> X\n array([[1., 0.],\n [2., 1.],\n [1., 0.]])\n\n >>> X_sparse\n <3x2 sparse matrix of type '<... 'numpy.float64'>'\n with 4 stored elements in Compressed Sparse Row format>\n\n >>> X_sparse.toarray()\n array([[1., 0.],\n [2., 1.],\n [1., 0.]])\n\n >>> y\n array([0, 1, 0])\n\n >>> resample(y, n_samples=2, random_state=0)\n array([0, 1])\n\n Example using stratification::\n\n >>> y = [0, 0, 1, 1, 1, 1, 1, 1, 1]\n >>> resample(y, n_samples=5, replace=False, stratify=y,\n ... random_state=0)\n [1, 1, 1, 0, 1]\n\n See Also\n --------\n shuffle\n \"\"\"\n max_n_samples = n_samples\n random_state = check_random_state(random_state)\n if len(arrays) == 0:\n return None\n first = arrays[0]\n n_samples = first.shape[0] if hasattr(first, 'shape') else len(first)\n if max_n_samples is None:\n max_n_samples = n_samples\n elif max_n_samples > n_samples and not replace:\n raise ValueError('Cannot sample %d out of arrays with dim %d when replace is False' % (max_n_samples, n_samples))\n check_consistent_length(*arrays)\n if stratify is None:\n if replace:\n indices = random_state.randint(0, n_samples, size=(max_n_samples, ))\n else:\n indices = np.arange(n_samples)\n random_state.shuffle(indices)\n indices = indices[:max_n_samples]\n else:\n y = check_array(stratify, ensure_2d=False, dtype=None)\n if y.ndim == 2:\n y = np.array([' '.join(row.astype('str')) for row in y])\n (classes, y_indices) = np.unique(y, return_inverse=True)\n n_classes = classes.shape[0]\n class_counts = np.bincount(y_indices)\n class_indices = np.split(np.argsort(y_indices, kind='mergesort'), np.cumsum(class_counts)[:-1])\n n_i = _approximate_mode(class_counts, max_n_samples, random_state)\n indices = []\n for i in range(n_classes):\n indices_i = random_state.choice(class_indices[i], n_i[i], replace=replace)\n indices.extend(indices_i)\n indices = random_state.permutation(indices)\n arrays = [a.tocsr() if issparse(a) else a for a in arrays]\n resampled_arrays = [_safe_indexing(a, indices) for a in arrays]\n if len(resampled_arrays) == 1:\n return resampled_arrays[0]\n else:\n return resampled_arrays" }, { "name": "safe_mask", + "unique_name": "safe_mask", "qname": "sklearn.utils.safe_mask", + "unique_qname": "sklearn.utils.safe_mask", "decorators": [], "parameters": [ { @@ -169343,7 +175659,9 @@ }, { "name": "safe_sqr", + "unique_name": "safe_sqr", "qname": "sklearn.utils.safe_sqr", + "unique_qname": "sklearn.utils.safe_sqr", "decorators": [], "parameters": [ { @@ -169375,7 +175693,9 @@ }, { "name": "configuration", + "unique_name": "configuration", "qname": "sklearn.utils.setup.configuration", + "unique_qname": "sklearn.utils.setup.configuration", "decorators": [], "parameters": [ { @@ -169407,7 +175727,9 @@ }, { "name": "shuffle", + "unique_name": "shuffle", "qname": "sklearn.utils.shuffle", + "unique_qname": "sklearn.utils.shuffle", "decorators": [], "parameters": [ { @@ -169434,12 +175756,14 @@ "results": [], "is_public": true, "description": "Shuffle arrays or sparse matrices in a consistent way.\n\nThis is a convenience alias to ``resample(*arrays, replace=False)`` to do random permutations of the collections.", - "docstring": "Shuffle arrays or sparse matrices in a consistent way.\n\nThis is a convenience alias to ``resample(*arrays, replace=False)`` to do\nrandom permutations of the collections.\n\nParameters\n----------\n*arrays : sequence of indexable data-structures\n Indexable data-structures can be arrays, lists, dataframes or scipy\n sparse matrices with consistent first dimension.\n\nrandom_state : int, RandomState instance or None, default=None\n Determines random number generation for shuffling\n the data.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\nn_samples : int, default=None\n Number of samples to generate. If left to None this is\n automatically set to the first dimension of the arrays. It should\n not be larger than the length of arrays.\n\nReturns\n-------\nshuffled_arrays : sequence of indexable data-structures\n Sequence of shuffled copies of the collections. The original arrays\n are not impacted.\n\nExamples\n--------\nIt is possible to mix sparse and dense arrays in the same run::\n\n >>> X = np.array([[1., 0.], [2., 1.], [0., 0.]])\n >>> y = np.array([0, 1, 2])\n\n >>> from scipy.sparse import coo_matrix\n >>> X_sparse = coo_matrix(X)\n\n >>> from sklearn.utils import shuffle\n >>> X, X_sparse, y = shuffle(X, X_sparse, y, random_state=0)\n >>> X\n array([[0., 0.],\n [2., 1.],\n [1., 0.]])\n\n >>> X_sparse\n <3x2 sparse matrix of type '<... 'numpy.float64'>'\n with 3 stored elements in Compressed Sparse Row format>\n\n >>> X_sparse.toarray()\n array([[0., 0.],\n [2., 1.],\n [1., 0.]])\n\n >>> y\n array([2, 1, 0])\n\n >>> shuffle(y, n_samples=2, random_state=0)\n array([0, 1])\n\nSee Also\n--------\nresample", - "source_code": "\ndef shuffle(*arrays, random_state=None, n_samples=None):\n \"\"\"Shuffle arrays or sparse matrices in a consistent way.\n\n This is a convenience alias to ``resample(*arrays, replace=False)`` to do\n random permutations of the collections.\n\n Parameters\n ----------\n *arrays : sequence of indexable data-structures\n Indexable data-structures can be arrays, lists, dataframes or scipy\n sparse matrices with consistent first dimension.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation for shuffling\n the data.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n n_samples : int, default=None\n Number of samples to generate. If left to None this is\n automatically set to the first dimension of the arrays. It should\n not be larger than the length of arrays.\n\n Returns\n -------\n shuffled_arrays : sequence of indexable data-structures\n Sequence of shuffled copies of the collections. The original arrays\n are not impacted.\n\n Examples\n --------\n It is possible to mix sparse and dense arrays in the same run::\n\n >>> X = np.array([[1., 0.], [2., 1.], [0., 0.]])\n >>> y = np.array([0, 1, 2])\n\n >>> from scipy.sparse import coo_matrix\n >>> X_sparse = coo_matrix(X)\n\n >>> from sklearn.utils import shuffle\n >>> X, X_sparse, y = shuffle(X, X_sparse, y, random_state=0)\n >>> X\n array([[0., 0.],\n [2., 1.],\n [1., 0.]])\n\n >>> X_sparse\n <3x2 sparse matrix of type '<... 'numpy.float64'>'\n with 3 stored elements in Compressed Sparse Row format>\n\n >>> X_sparse.toarray()\n array([[0., 0.],\n [2., 1.],\n [1., 0.]])\n\n >>> y\n array([2, 1, 0])\n\n >>> shuffle(y, n_samples=2, random_state=0)\n array([0, 1])\n\n See Also\n --------\n resample\n \"\"\"\n return resample(*arrays, replace=False, n_samples=n_samples, random_state=random_state)" + "docstring": "Shuffle arrays or sparse matrices in a consistent way.\n\nThis is a convenience alias to ``resample(*arrays, replace=False)`` to do\nrandom permutations of the collections.\n\nParameters\n----------\n*arrays : sequence of indexable data-structures\n Indexable data-structures can be arrays, lists, dataframes or scipy\n sparse matrices with consistent first dimension.\n\nrandom_state : int, RandomState instance or None, default=None\n Determines random number generation for shuffling\n the data.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\nn_samples : int, default=None\n Number of samples to generate. If left to None this is\n automatically set to the first dimension of the arrays. It should\n not be larger than the length of arrays.\n\nReturns\n-------\nshuffled_arrays : sequence of indexable data-structures\n Sequence of shuffled copies of the collections. The original arrays\n are not impacted.\n\nExamples\n--------\nIt is possible to mix sparse and dense arrays in the same run::\n\n >>> import numpy as np\n >>> X = np.array([[1., 0.], [2., 1.], [0., 0.]])\n >>> y = np.array([0, 1, 2])\n\n >>> from scipy.sparse import coo_matrix\n >>> X_sparse = coo_matrix(X)\n\n >>> from sklearn.utils import shuffle\n >>> X, X_sparse, y = shuffle(X, X_sparse, y, random_state=0)\n >>> X\n array([[0., 0.],\n [2., 1.],\n [1., 0.]])\n\n >>> X_sparse\n <3x2 sparse matrix of type '<... 'numpy.float64'>'\n with 3 stored elements in Compressed Sparse Row format>\n\n >>> X_sparse.toarray()\n array([[0., 0.],\n [2., 1.],\n [1., 0.]])\n\n >>> y\n array([2, 1, 0])\n\n >>> shuffle(y, n_samples=2, random_state=0)\n array([0, 1])\n\nSee Also\n--------\nresample", + "source_code": "\ndef shuffle(*arrays, random_state=None, n_samples=None):\n \"\"\"Shuffle arrays or sparse matrices in a consistent way.\n\n This is a convenience alias to ``resample(*arrays, replace=False)`` to do\n random permutations of the collections.\n\n Parameters\n ----------\n *arrays : sequence of indexable data-structures\n Indexable data-structures can be arrays, lists, dataframes or scipy\n sparse matrices with consistent first dimension.\n\n random_state : int, RandomState instance or None, default=None\n Determines random number generation for shuffling\n the data.\n Pass an int for reproducible results across multiple function calls.\n See :term:`Glossary `.\n\n n_samples : int, default=None\n Number of samples to generate. If left to None this is\n automatically set to the first dimension of the arrays. It should\n not be larger than the length of arrays.\n\n Returns\n -------\n shuffled_arrays : sequence of indexable data-structures\n Sequence of shuffled copies of the collections. The original arrays\n are not impacted.\n\n Examples\n --------\n It is possible to mix sparse and dense arrays in the same run::\n\n >>> import numpy as np\n >>> X = np.array([[1., 0.], [2., 1.], [0., 0.]])\n >>> y = np.array([0, 1, 2])\n\n >>> from scipy.sparse import coo_matrix\n >>> X_sparse = coo_matrix(X)\n\n >>> from sklearn.utils import shuffle\n >>> X, X_sparse, y = shuffle(X, X_sparse, y, random_state=0)\n >>> X\n array([[0., 0.],\n [2., 1.],\n [1., 0.]])\n\n >>> X_sparse\n <3x2 sparse matrix of type '<... 'numpy.float64'>'\n with 3 stored elements in Compressed Sparse Row format>\n\n >>> X_sparse.toarray()\n array([[0., 0.],\n [2., 1.],\n [1., 0.]])\n\n >>> y\n array([2, 1, 0])\n\n >>> shuffle(y, n_samples=2, random_state=0)\n array([0, 1])\n\n See Also\n --------\n resample\n \"\"\"\n return resample(*arrays, replace=False, n_samples=n_samples, random_state=random_state)" }, { "name": "_get_elem_at_rank", + "unique_name": "_get_elem_at_rank", "qname": "sklearn.utils.sparsefuncs._get_elem_at_rank", + "unique_qname": "sklearn.utils.sparsefuncs._get_elem_at_rank", "decorators": [], "parameters": [ { @@ -169491,7 +175815,9 @@ }, { "name": "_get_median", + "unique_name": "_get_median", "qname": "sklearn.utils.sparsefuncs._get_median", + "unique_qname": "sklearn.utils.sparsefuncs._get_median", "decorators": [], "parameters": [ { @@ -169523,7 +175849,9 @@ }, { "name": "_min_or_max_axis", + "unique_name": "_min_or_max_axis", "qname": "sklearn.utils.sparsefuncs._min_or_max_axis", + "unique_qname": "sklearn.utils.sparsefuncs._min_or_max_axis", "decorators": [], "parameters": [ { @@ -169565,7 +175893,9 @@ }, { "name": "_minor_reduce", + "unique_name": "_minor_reduce", "qname": "sklearn.utils.sparsefuncs._minor_reduce", + "unique_qname": "sklearn.utils.sparsefuncs._minor_reduce", "decorators": [], "parameters": [ { @@ -169597,7 +175927,9 @@ }, { "name": "_raise_error_wrong_axis", + "unique_name": "_raise_error_wrong_axis", "qname": "sklearn.utils.sparsefuncs._raise_error_wrong_axis", + "unique_qname": "sklearn.utils.sparsefuncs._raise_error_wrong_axis", "decorators": [], "parameters": [ { @@ -169619,7 +175951,9 @@ }, { "name": "_raise_typeerror", + "unique_name": "_raise_typeerror", "qname": "sklearn.utils.sparsefuncs._raise_typeerror", + "unique_qname": "sklearn.utils.sparsefuncs._raise_typeerror", "decorators": [], "parameters": [ { @@ -169641,7 +175975,9 @@ }, { "name": "_sparse_min_max", + "unique_name": "_sparse_min_max", "qname": "sklearn.utils.sparsefuncs._sparse_min_max", + "unique_qname": "sklearn.utils.sparsefuncs._sparse_min_max", "decorators": [], "parameters": [ { @@ -169673,7 +176009,9 @@ }, { "name": "_sparse_min_or_max", + "unique_name": "_sparse_min_or_max", "qname": "sklearn.utils.sparsefuncs._sparse_min_or_max", + "unique_qname": "sklearn.utils.sparsefuncs._sparse_min_or_max", "decorators": [], "parameters": [ { @@ -169715,7 +176053,9 @@ }, { "name": "_sparse_nan_min_max", + "unique_name": "_sparse_nan_min_max", "qname": "sklearn.utils.sparsefuncs._sparse_nan_min_max", + "unique_qname": "sklearn.utils.sparsefuncs._sparse_nan_min_max", "decorators": [], "parameters": [ { @@ -169747,7 +176087,9 @@ }, { "name": "count_nonzero", + "unique_name": "count_nonzero", "qname": "sklearn.utils.sparsefuncs.count_nonzero", + "unique_qname": "sklearn.utils.sparsefuncs.count_nonzero", "decorators": [], "parameters": [ { @@ -169789,7 +176131,9 @@ }, { "name": "csc_median_axis_0", + "unique_name": "csc_median_axis_0", "qname": "sklearn.utils.sparsefuncs.csc_median_axis_0", + "unique_qname": "sklearn.utils.sparsefuncs.csc_median_axis_0", "decorators": [], "parameters": [ { @@ -169811,7 +176155,9 @@ }, { "name": "incr_mean_variance_axis", + "unique_name": "incr_mean_variance_axis", "qname": "sklearn.utils.sparsefuncs.incr_mean_variance_axis", + "unique_qname": "sklearn.utils.sparsefuncs.incr_mean_variance_axis", "decorators": [], "parameters": [ { @@ -169883,7 +176229,9 @@ }, { "name": "inplace_column_scale", + "unique_name": "inplace_column_scale", "qname": "sklearn.utils.sparsefuncs.inplace_column_scale", + "unique_qname": "sklearn.utils.sparsefuncs.inplace_column_scale", "decorators": [], "parameters": [ { @@ -169915,7 +176263,9 @@ }, { "name": "inplace_csr_column_scale", + "unique_name": "inplace_csr_column_scale", "qname": "sklearn.utils.sparsefuncs.inplace_csr_column_scale", + "unique_qname": "sklearn.utils.sparsefuncs.inplace_csr_column_scale", "decorators": [], "parameters": [ { @@ -169947,7 +176297,9 @@ }, { "name": "inplace_csr_row_scale", + "unique_name": "inplace_csr_row_scale", "qname": "sklearn.utils.sparsefuncs.inplace_csr_row_scale", + "unique_qname": "sklearn.utils.sparsefuncs.inplace_csr_row_scale", "decorators": [], "parameters": [ { @@ -169979,7 +176331,9 @@ }, { "name": "inplace_row_scale", + "unique_name": "inplace_row_scale", "qname": "sklearn.utils.sparsefuncs.inplace_row_scale", + "unique_qname": "sklearn.utils.sparsefuncs.inplace_row_scale", "decorators": [], "parameters": [ { @@ -170011,7 +176365,9 @@ }, { "name": "inplace_swap_column", + "unique_name": "inplace_swap_column", "qname": "sklearn.utils.sparsefuncs.inplace_swap_column", + "unique_qname": "sklearn.utils.sparsefuncs.inplace_swap_column", "decorators": [], "parameters": [ { @@ -170053,7 +176409,9 @@ }, { "name": "inplace_swap_row", + "unique_name": "inplace_swap_row", "qname": "sklearn.utils.sparsefuncs.inplace_swap_row", + "unique_qname": "sklearn.utils.sparsefuncs.inplace_swap_row", "decorators": [], "parameters": [ { @@ -170095,7 +176453,9 @@ }, { "name": "inplace_swap_row_csc", + "unique_name": "inplace_swap_row_csc", "qname": "sklearn.utils.sparsefuncs.inplace_swap_row_csc", + "unique_qname": "sklearn.utils.sparsefuncs.inplace_swap_row_csc", "decorators": [], "parameters": [ { @@ -170137,7 +176497,9 @@ }, { "name": "inplace_swap_row_csr", + "unique_name": "inplace_swap_row_csr", "qname": "sklearn.utils.sparsefuncs.inplace_swap_row_csr", + "unique_qname": "sklearn.utils.sparsefuncs.inplace_swap_row_csr", "decorators": [], "parameters": [ { @@ -170179,7 +176541,9 @@ }, { "name": "mean_variance_axis", + "unique_name": "mean_variance_axis", "qname": "sklearn.utils.sparsefuncs.mean_variance_axis", + "unique_qname": "sklearn.utils.sparsefuncs.mean_variance_axis", "decorators": [], "parameters": [ { @@ -170231,7 +176595,9 @@ }, { "name": "min_max_axis", + "unique_name": "min_max_axis", "qname": "sklearn.utils.sparsefuncs.min_max_axis", + "unique_qname": "sklearn.utils.sparsefuncs.min_max_axis", "decorators": [], "parameters": [ { @@ -170273,7 +176639,9 @@ }, { "name": "_weighted_percentile", + "unique_name": "_weighted_percentile", "qname": "sklearn.utils.stats._weighted_percentile", + "unique_qname": "sklearn.utils.stats._weighted_percentile", "decorators": [], "parameters": [ { @@ -170315,7 +176683,9 @@ }, { "name": "tosequence", + "unique_name": "tosequence", "qname": "sklearn.utils.tosequence", + "unique_qname": "sklearn.utils.tosequence", "decorators": [], "parameters": [ { @@ -170337,7 +176707,9 @@ }, { "name": "_allclose_dense_sparse", + "unique_name": "_allclose_dense_sparse", "qname": "sklearn.utils.validation._allclose_dense_sparse", + "unique_qname": "sklearn.utils.validation._allclose_dense_sparse", "decorators": [], "parameters": [ { @@ -170389,7 +176761,9 @@ }, { "name": "_assert_all_finite", + "unique_name": "_assert_all_finite", "qname": "sklearn.utils.validation._assert_all_finite", + "unique_qname": "sklearn.utils.validation._assert_all_finite", "decorators": [], "parameters": [ { @@ -170431,7 +176805,9 @@ }, { "name": "_check_feature_names_in", + "unique_name": "_check_feature_names_in", "qname": "sklearn.utils.validation._check_feature_names_in", + "unique_qname": "sklearn.utils.validation._check_feature_names_in", "decorators": [], "parameters": [ { @@ -170463,7 +176839,9 @@ }, { "name": "_check_fit_params", + "unique_name": "_check_fit_params", "qname": "sklearn.utils.validation._check_fit_params", + "unique_qname": "sklearn.utils.validation._check_fit_params", "decorators": [], "parameters": [ { @@ -170505,7 +176883,9 @@ }, { "name": "_check_large_sparse", + "unique_name": "_check_large_sparse", "qname": "sklearn.utils.validation._check_large_sparse", + "unique_qname": "sklearn.utils.validation._check_large_sparse", "decorators": [], "parameters": [ { @@ -170537,7 +176917,9 @@ }, { "name": "_check_psd_eigenvalues", + "unique_name": "_check_psd_eigenvalues", "qname": "sklearn.utils.validation._check_psd_eigenvalues", + "unique_qname": "sklearn.utils.validation._check_psd_eigenvalues", "decorators": [], "parameters": [ { @@ -170564,12 +176946,14 @@ "results": [], "is_public": false, "description": "Check the eigenvalues of a positive semidefinite (PSD) matrix.\n\nChecks the provided array of PSD matrix eigenvalues for numerical or conditioning issues and returns a fixed validated version. This method should typically be used if the PSD matrix is user-provided (e.g. a Gram matrix) or computed using a user-provided dissimilarity metric (e.g. kernel function), or if the decomposition process uses approximation methods (randomized SVD, etc.). It checks for three things: - that there are no significant imaginary parts in eigenvalues (more than 1e-5 times the maximum real part). If this check fails, it raises a ``ValueError``. Otherwise all non-significant imaginary parts that may remain are set to zero. This operation is traced with a ``PositiveSpectrumWarning`` when ``enable_warnings=True``. - that eigenvalues are not all negative. If this check fails, it raises a ``ValueError`` - that there are no significant negative eigenvalues with absolute value more than 1e-10 (1e-6) and more than 1e-5 (5e-3) times the largest positive eigenvalue in double (simple) precision. If this check fails, it raises a ``ValueError``. Otherwise all negative eigenvalues that may remain are set to zero. This operation is traced with a ``PositiveSpectrumWarning`` when ``enable_warnings=True``. Finally, all the positive eigenvalues that are too small (with a value smaller than the maximum eigenvalue multiplied by 1e-12 (2e-7)) are set to zero. This operation is traced with a ``PositiveSpectrumWarning`` when ``enable_warnings=True``.", - "docstring": "Check the eigenvalues of a positive semidefinite (PSD) matrix.\n\nChecks the provided array of PSD matrix eigenvalues for numerical or\nconditioning issues and returns a fixed validated version. This method\nshould typically be used if the PSD matrix is user-provided (e.g. a\nGram matrix) or computed using a user-provided dissimilarity metric\n(e.g. kernel function), or if the decomposition process uses approximation\nmethods (randomized SVD, etc.).\n\nIt checks for three things:\n\n- that there are no significant imaginary parts in eigenvalues (more than\n 1e-5 times the maximum real part). If this check fails, it raises a\n ``ValueError``. Otherwise all non-significant imaginary parts that may\n remain are set to zero. This operation is traced with a\n ``PositiveSpectrumWarning`` when ``enable_warnings=True``.\n\n- that eigenvalues are not all negative. If this check fails, it raises a\n ``ValueError``\n\n- that there are no significant negative eigenvalues with absolute value\n more than 1e-10 (1e-6) and more than 1e-5 (5e-3) times the largest\n positive eigenvalue in double (simple) precision. If this check fails,\n it raises a ``ValueError``. Otherwise all negative eigenvalues that may\n remain are set to zero. This operation is traced with a\n ``PositiveSpectrumWarning`` when ``enable_warnings=True``.\n\nFinally, all the positive eigenvalues that are too small (with a value\nsmaller than the maximum eigenvalue multiplied by 1e-12 (2e-7)) are set to\nzero. This operation is traced with a ``PositiveSpectrumWarning`` when\n``enable_warnings=True``.\n\nParameters\n----------\nlambdas : array-like of shape (n_eigenvalues,)\n Array of eigenvalues to check / fix.\n\nenable_warnings : bool, default=False\n When this is set to ``True``, a ``PositiveSpectrumWarning`` will be\n raised when there are imaginary parts, negative eigenvalues, or\n extremely small non-zero eigenvalues. Otherwise no warning will be\n raised. In both cases, imaginary parts, negative eigenvalues, and\n extremely small non-zero eigenvalues will be set to zero.\n\nReturns\n-------\nlambdas_fixed : ndarray of shape (n_eigenvalues,)\n A fixed validated copy of the array of eigenvalues.\n\nExamples\n--------\n>>> _check_psd_eigenvalues([1, 2]) # nominal case\narray([1, 2])\n>>> _check_psd_eigenvalues([5, 5j]) # significant imag part\nTraceback (most recent call last):\n ...\nValueError: There are significant imaginary parts in eigenvalues (1\n of the maximum real part). Either the matrix is not PSD, or there was\n an issue while computing the eigendecomposition of the matrix.\n>>> _check_psd_eigenvalues([5, 5e-5j]) # insignificant imag part\narray([5., 0.])\n>>> _check_psd_eigenvalues([-5, -1]) # all negative\nTraceback (most recent call last):\n ...\nValueError: All eigenvalues are negative (maximum is -1). Either the\n matrix is not PSD, or there was an issue while computing the\n eigendecomposition of the matrix.\n>>> _check_psd_eigenvalues([5, -1]) # significant negative\nTraceback (most recent call last):\n ...\nValueError: There are significant negative eigenvalues (0.2 of the\n maximum positive). Either the matrix is not PSD, or there was an issue\n while computing the eigendecomposition of the matrix.\n>>> _check_psd_eigenvalues([5, -5e-5]) # insignificant negative\narray([5., 0.])\n>>> _check_psd_eigenvalues([5, 4e-12]) # bad conditioning (too small)\narray([5., 0.])", - "source_code": "\ndef _check_psd_eigenvalues(lambdas, enable_warnings=False):\n \"\"\"Check the eigenvalues of a positive semidefinite (PSD) matrix.\n\n Checks the provided array of PSD matrix eigenvalues for numerical or\n conditioning issues and returns a fixed validated version. This method\n should typically be used if the PSD matrix is user-provided (e.g. a\n Gram matrix) or computed using a user-provided dissimilarity metric\n (e.g. kernel function), or if the decomposition process uses approximation\n methods (randomized SVD, etc.).\n\n It checks for three things:\n\n - that there are no significant imaginary parts in eigenvalues (more than\n 1e-5 times the maximum real part). If this check fails, it raises a\n ``ValueError``. Otherwise all non-significant imaginary parts that may\n remain are set to zero. This operation is traced with a\n ``PositiveSpectrumWarning`` when ``enable_warnings=True``.\n\n - that eigenvalues are not all negative. If this check fails, it raises a\n ``ValueError``\n\n - that there are no significant negative eigenvalues with absolute value\n more than 1e-10 (1e-6) and more than 1e-5 (5e-3) times the largest\n positive eigenvalue in double (simple) precision. If this check fails,\n it raises a ``ValueError``. Otherwise all negative eigenvalues that may\n remain are set to zero. This operation is traced with a\n ``PositiveSpectrumWarning`` when ``enable_warnings=True``.\n\n Finally, all the positive eigenvalues that are too small (with a value\n smaller than the maximum eigenvalue multiplied by 1e-12 (2e-7)) are set to\n zero. This operation is traced with a ``PositiveSpectrumWarning`` when\n ``enable_warnings=True``.\n\n Parameters\n ----------\n lambdas : array-like of shape (n_eigenvalues,)\n Array of eigenvalues to check / fix.\n\n enable_warnings : bool, default=False\n When this is set to ``True``, a ``PositiveSpectrumWarning`` will be\n raised when there are imaginary parts, negative eigenvalues, or\n extremely small non-zero eigenvalues. Otherwise no warning will be\n raised. In both cases, imaginary parts, negative eigenvalues, and\n extremely small non-zero eigenvalues will be set to zero.\n\n Returns\n -------\n lambdas_fixed : ndarray of shape (n_eigenvalues,)\n A fixed validated copy of the array of eigenvalues.\n\n Examples\n --------\n >>> _check_psd_eigenvalues([1, 2]) # nominal case\n array([1, 2])\n >>> _check_psd_eigenvalues([5, 5j]) # significant imag part\n Traceback (most recent call last):\n ...\n ValueError: There are significant imaginary parts in eigenvalues (1\n of the maximum real part). Either the matrix is not PSD, or there was\n an issue while computing the eigendecomposition of the matrix.\n >>> _check_psd_eigenvalues([5, 5e-5j]) # insignificant imag part\n array([5., 0.])\n >>> _check_psd_eigenvalues([-5, -1]) # all negative\n Traceback (most recent call last):\n ...\n ValueError: All eigenvalues are negative (maximum is -1). Either the\n matrix is not PSD, or there was an issue while computing the\n eigendecomposition of the matrix.\n >>> _check_psd_eigenvalues([5, -1]) # significant negative\n Traceback (most recent call last):\n ...\n ValueError: There are significant negative eigenvalues (0.2 of the\n maximum positive). Either the matrix is not PSD, or there was an issue\n while computing the eigendecomposition of the matrix.\n >>> _check_psd_eigenvalues([5, -5e-5]) # insignificant negative\n array([5., 0.])\n >>> _check_psd_eigenvalues([5, 4e-12]) # bad conditioning (too small)\n array([5., 0.])\n\n \"\"\"\n lambdas = np.array(lambdas)\n is_double_precision = lambdas.dtype == np.float64\n significant_imag_ratio = 1e-05\n significant_neg_ratio = 1e-05 if is_double_precision else 0.005\n significant_neg_value = 1e-10 if is_double_precision else 1e-06\n small_pos_ratio = 1e-12 if is_double_precision else 2e-07\n if not np.isreal(lambdas).all():\n max_imag_abs = np.abs(np.imag(lambdas)).max()\n max_real_abs = np.abs(np.real(lambdas)).max()\n if max_imag_abs > significant_imag_ratio * max_real_abs:\n raise ValueError('There are significant imaginary parts in eigenvalues (%g of the maximum real part). Either the matrix is not PSD, or there was an issue while computing the eigendecomposition of the matrix.' % (max_imag_abs / max_real_abs))\n if enable_warnings:\n warnings.warn('There are imaginary parts in eigenvalues (%g of the maximum real part). Either the matrix is not PSD, or there was an issue while computing the eigendecomposition of the matrix. Only the real parts will be kept.' % (max_imag_abs / max_real_abs), PositiveSpectrumWarning)\n lambdas = np.real(lambdas)\n max_eig = lambdas.max()\n if max_eig < 0:\n raise ValueError('All eigenvalues are negative (maximum is %g). Either the matrix is not PSD, or there was an issue while computing the eigendecomposition of the matrix.' % max_eig)\n else:\n min_eig = lambdas.min()\n if min_eig < -significant_neg_ratio * max_eig and min_eig < -significant_neg_value:\n raise ValueError('There are significant negative eigenvalues (%g of the maximum positive). Either the matrix is not PSD, or there was an issue while computing the eigendecomposition of the matrix.' % (-min_eig / max_eig))\n elif min_eig < 0:\n if enable_warnings:\n warnings.warn('There are negative eigenvalues (%g of the maximum positive). Either the matrix is not PSD, or there was an issue while computing the eigendecomposition of the matrix. Negative eigenvalues will be replaced with 0.' % (-min_eig / max_eig), PositiveSpectrumWarning)\n lambdas[lambdas < 0] = 0\n too_small_lambdas = (0 < lambdas) & (lambdas < small_pos_ratio * max_eig)\n if too_small_lambdas.any():\n if enable_warnings:\n warnings.warn('Badly conditioned PSD matrix spectrum: the largest eigenvalue is more than %g times the smallest. Small eigenvalues will be replaced with 0.' % (1 / small_pos_ratio), PositiveSpectrumWarning)\n lambdas[too_small_lambdas] = 0\n return lambdas" + "docstring": "Check the eigenvalues of a positive semidefinite (PSD) matrix.\n\nChecks the provided array of PSD matrix eigenvalues for numerical or\nconditioning issues and returns a fixed validated version. This method\nshould typically be used if the PSD matrix is user-provided (e.g. a\nGram matrix) or computed using a user-provided dissimilarity metric\n(e.g. kernel function), or if the decomposition process uses approximation\nmethods (randomized SVD, etc.).\n\nIt checks for three things:\n\n- that there are no significant imaginary parts in eigenvalues (more than\n 1e-5 times the maximum real part). If this check fails, it raises a\n ``ValueError``. Otherwise all non-significant imaginary parts that may\n remain are set to zero. This operation is traced with a\n ``PositiveSpectrumWarning`` when ``enable_warnings=True``.\n\n- that eigenvalues are not all negative. If this check fails, it raises a\n ``ValueError``\n\n- that there are no significant negative eigenvalues with absolute value\n more than 1e-10 (1e-6) and more than 1e-5 (5e-3) times the largest\n positive eigenvalue in double (simple) precision. If this check fails,\n it raises a ``ValueError``. Otherwise all negative eigenvalues that may\n remain are set to zero. This operation is traced with a\n ``PositiveSpectrumWarning`` when ``enable_warnings=True``.\n\nFinally, all the positive eigenvalues that are too small (with a value\nsmaller than the maximum eigenvalue multiplied by 1e-12 (2e-7)) are set to\nzero. This operation is traced with a ``PositiveSpectrumWarning`` when\n``enable_warnings=True``.\n\nParameters\n----------\nlambdas : array-like of shape (n_eigenvalues,)\n Array of eigenvalues to check / fix.\n\nenable_warnings : bool, default=False\n When this is set to ``True``, a ``PositiveSpectrumWarning`` will be\n raised when there are imaginary parts, negative eigenvalues, or\n extremely small non-zero eigenvalues. Otherwise no warning will be\n raised. In both cases, imaginary parts, negative eigenvalues, and\n extremely small non-zero eigenvalues will be set to zero.\n\nReturns\n-------\nlambdas_fixed : ndarray of shape (n_eigenvalues,)\n A fixed validated copy of the array of eigenvalues.\n\nExamples\n--------\n>>> from sklearn.utils.validation import _check_psd_eigenvalues\n>>> _check_psd_eigenvalues([1, 2]) # nominal case\narray([1, 2])\n>>> _check_psd_eigenvalues([5, 5j]) # significant imag part\nTraceback (most recent call last):\n ...\nValueError: There are significant imaginary parts in eigenvalues (1\n of the maximum real part). Either the matrix is not PSD, or there was\n an issue while computing the eigendecomposition of the matrix.\n>>> _check_psd_eigenvalues([5, 5e-5j]) # insignificant imag part\narray([5., 0.])\n>>> _check_psd_eigenvalues([-5, -1]) # all negative\nTraceback (most recent call last):\n ...\nValueError: All eigenvalues are negative (maximum is -1). Either the\n matrix is not PSD, or there was an issue while computing the\n eigendecomposition of the matrix.\n>>> _check_psd_eigenvalues([5, -1]) # significant negative\nTraceback (most recent call last):\n ...\nValueError: There are significant negative eigenvalues (0.2 of the\n maximum positive). Either the matrix is not PSD, or there was an issue\n while computing the eigendecomposition of the matrix.\n>>> _check_psd_eigenvalues([5, -5e-5]) # insignificant negative\narray([5., 0.])\n>>> _check_psd_eigenvalues([5, 4e-12]) # bad conditioning (too small)\narray([5., 0.])", + "source_code": "\ndef _check_psd_eigenvalues(lambdas, enable_warnings=False):\n \"\"\"Check the eigenvalues of a positive semidefinite (PSD) matrix.\n\n Checks the provided array of PSD matrix eigenvalues for numerical or\n conditioning issues and returns a fixed validated version. This method\n should typically be used if the PSD matrix is user-provided (e.g. a\n Gram matrix) or computed using a user-provided dissimilarity metric\n (e.g. kernel function), or if the decomposition process uses approximation\n methods (randomized SVD, etc.).\n\n It checks for three things:\n\n - that there are no significant imaginary parts in eigenvalues (more than\n 1e-5 times the maximum real part). If this check fails, it raises a\n ``ValueError``. Otherwise all non-significant imaginary parts that may\n remain are set to zero. This operation is traced with a\n ``PositiveSpectrumWarning`` when ``enable_warnings=True``.\n\n - that eigenvalues are not all negative. If this check fails, it raises a\n ``ValueError``\n\n - that there are no significant negative eigenvalues with absolute value\n more than 1e-10 (1e-6) and more than 1e-5 (5e-3) times the largest\n positive eigenvalue in double (simple) precision. If this check fails,\n it raises a ``ValueError``. Otherwise all negative eigenvalues that may\n remain are set to zero. This operation is traced with a\n ``PositiveSpectrumWarning`` when ``enable_warnings=True``.\n\n Finally, all the positive eigenvalues that are too small (with a value\n smaller than the maximum eigenvalue multiplied by 1e-12 (2e-7)) are set to\n zero. This operation is traced with a ``PositiveSpectrumWarning`` when\n ``enable_warnings=True``.\n\n Parameters\n ----------\n lambdas : array-like of shape (n_eigenvalues,)\n Array of eigenvalues to check / fix.\n\n enable_warnings : bool, default=False\n When this is set to ``True``, a ``PositiveSpectrumWarning`` will be\n raised when there are imaginary parts, negative eigenvalues, or\n extremely small non-zero eigenvalues. Otherwise no warning will be\n raised. In both cases, imaginary parts, negative eigenvalues, and\n extremely small non-zero eigenvalues will be set to zero.\n\n Returns\n -------\n lambdas_fixed : ndarray of shape (n_eigenvalues,)\n A fixed validated copy of the array of eigenvalues.\n\n Examples\n --------\n >>> from sklearn.utils.validation import _check_psd_eigenvalues\n >>> _check_psd_eigenvalues([1, 2]) # nominal case\n array([1, 2])\n >>> _check_psd_eigenvalues([5, 5j]) # significant imag part\n Traceback (most recent call last):\n ...\n ValueError: There are significant imaginary parts in eigenvalues (1\n of the maximum real part). Either the matrix is not PSD, or there was\n an issue while computing the eigendecomposition of the matrix.\n >>> _check_psd_eigenvalues([5, 5e-5j]) # insignificant imag part\n array([5., 0.])\n >>> _check_psd_eigenvalues([-5, -1]) # all negative\n Traceback (most recent call last):\n ...\n ValueError: All eigenvalues are negative (maximum is -1). Either the\n matrix is not PSD, or there was an issue while computing the\n eigendecomposition of the matrix.\n >>> _check_psd_eigenvalues([5, -1]) # significant negative\n Traceback (most recent call last):\n ...\n ValueError: There are significant negative eigenvalues (0.2 of the\n maximum positive). Either the matrix is not PSD, or there was an issue\n while computing the eigendecomposition of the matrix.\n >>> _check_psd_eigenvalues([5, -5e-5]) # insignificant negative\n array([5., 0.])\n >>> _check_psd_eigenvalues([5, 4e-12]) # bad conditioning (too small)\n array([5., 0.])\n\n \"\"\"\n lambdas = np.array(lambdas)\n is_double_precision = lambdas.dtype == np.float64\n significant_imag_ratio = 1e-05\n significant_neg_ratio = 1e-05 if is_double_precision else 0.005\n significant_neg_value = 1e-10 if is_double_precision else 1e-06\n small_pos_ratio = 1e-12 if is_double_precision else 2e-07\n if not np.isreal(lambdas).all():\n max_imag_abs = np.abs(np.imag(lambdas)).max()\n max_real_abs = np.abs(np.real(lambdas)).max()\n if max_imag_abs > significant_imag_ratio * max_real_abs:\n raise ValueError('There are significant imaginary parts in eigenvalues (%g of the maximum real part). Either the matrix is not PSD, or there was an issue while computing the eigendecomposition of the matrix.' % (max_imag_abs / max_real_abs))\n if enable_warnings:\n warnings.warn('There are imaginary parts in eigenvalues (%g of the maximum real part). Either the matrix is not PSD, or there was an issue while computing the eigendecomposition of the matrix. Only the real parts will be kept.' % (max_imag_abs / max_real_abs), PositiveSpectrumWarning)\n lambdas = np.real(lambdas)\n max_eig = lambdas.max()\n if max_eig < 0:\n raise ValueError('All eigenvalues are negative (maximum is %g). Either the matrix is not PSD, or there was an issue while computing the eigendecomposition of the matrix.' % max_eig)\n else:\n min_eig = lambdas.min()\n if min_eig < -significant_neg_ratio * max_eig and min_eig < -significant_neg_value:\n raise ValueError('There are significant negative eigenvalues (%g of the maximum positive). Either the matrix is not PSD, or there was an issue while computing the eigendecomposition of the matrix.' % (-min_eig / max_eig))\n elif min_eig < 0:\n if enable_warnings:\n warnings.warn('There are negative eigenvalues (%g of the maximum positive). Either the matrix is not PSD, or there was an issue while computing the eigendecomposition of the matrix. Negative eigenvalues will be replaced with 0.' % (-min_eig / max_eig), PositiveSpectrumWarning)\n lambdas[lambdas < 0] = 0\n too_small_lambdas = (0 < lambdas) & (lambdas < small_pos_ratio * max_eig)\n if too_small_lambdas.any():\n if enable_warnings:\n warnings.warn('Badly conditioned PSD matrix spectrum: the largest eigenvalue is more than %g times the smallest. Small eigenvalues will be replaced with 0.' % (1 / small_pos_ratio), PositiveSpectrumWarning)\n lambdas[too_small_lambdas] = 0\n return lambdas" }, { "name": "_check_sample_weight", + "unique_name": "_check_sample_weight", "qname": "sklearn.utils.validation._check_sample_weight", + "unique_qname": "sklearn.utils.validation._check_sample_weight", "decorators": [], "parameters": [ { @@ -170621,7 +177005,9 @@ }, { "name": "_check_y", + "unique_name": "_check_y", "qname": "sklearn.utils.validation._check_y", + "unique_qname": "sklearn.utils.validation._check_y", "decorators": [], "parameters": [ { @@ -170663,7 +177049,9 @@ }, { "name": "_deprecate_positional_args", + "unique_name": "_deprecate_positional_args", "qname": "sklearn.utils.validation._deprecate_positional_args", + "unique_qname": "sklearn.utils.validation._deprecate_positional_args", "decorators": [], "parameters": [ { @@ -170695,7 +177083,9 @@ }, { "name": "_ensure_no_complex_data", + "unique_name": "_ensure_no_complex_data", "qname": "sklearn.utils.validation._ensure_no_complex_data", + "unique_qname": "sklearn.utils.validation._ensure_no_complex_data", "decorators": [], "parameters": [ { @@ -170717,7 +177107,9 @@ }, { "name": "_ensure_sparse_format", + "unique_name": "_ensure_sparse_format", "qname": "sklearn.utils.validation._ensure_sparse_format", + "unique_qname": "sklearn.utils.validation._ensure_sparse_format", "decorators": [], "parameters": [ { @@ -170789,7 +177181,9 @@ }, { "name": "_get_feature_names", + "unique_name": "_get_feature_names", "qname": "sklearn.utils.validation._get_feature_names", + "unique_qname": "sklearn.utils.validation._get_feature_names", "decorators": [], "parameters": [ { @@ -170811,7 +177205,9 @@ }, { "name": "_is_arraylike", + "unique_name": "_is_arraylike", "qname": "sklearn.utils.validation._is_arraylike", + "unique_qname": "sklearn.utils.validation._is_arraylike", "decorators": [], "parameters": [ { @@ -170833,7 +177229,9 @@ }, { "name": "_make_indexable", + "unique_name": "_make_indexable", "qname": "sklearn.utils.validation._make_indexable", + "unique_qname": "sklearn.utils.validation._make_indexable", "decorators": [], "parameters": [ { @@ -170855,7 +177253,9 @@ }, { "name": "_num_features", + "unique_name": "_num_features", "qname": "sklearn.utils.validation._num_features", + "unique_qname": "sklearn.utils.validation._num_features", "decorators": [], "parameters": [ { @@ -170877,7 +177277,9 @@ }, { "name": "_num_samples", + "unique_name": "_num_samples", "qname": "sklearn.utils.validation._num_samples", + "unique_qname": "sklearn.utils.validation._num_samples", "decorators": [], "parameters": [ { @@ -170899,7 +177301,9 @@ }, { "name": "as_float_array", + "unique_name": "as_float_array", "qname": "sklearn.utils.validation.as_float_array", + "unique_qname": "sklearn.utils.validation.as_float_array", "decorators": [], "parameters": [ { @@ -170941,7 +177345,9 @@ }, { "name": "assert_all_finite", + "unique_name": "assert_all_finite", "qname": "sklearn.utils.validation.assert_all_finite", + "unique_qname": "sklearn.utils.validation.assert_all_finite", "decorators": [], "parameters": [ { @@ -170973,7 +177379,9 @@ }, { "name": "check_X_y", + "unique_name": "check_X_y", "qname": "sklearn.utils.validation.check_X_y", + "unique_qname": "sklearn.utils.validation.check_X_y", "decorators": [], "parameters": [ { @@ -171135,7 +177543,9 @@ }, { "name": "check_array", + "unique_name": "check_array", "qname": "sklearn.utils.validation.check_array", + "unique_qname": "sklearn.utils.validation.check_array", "decorators": [], "parameters": [ { @@ -171267,7 +177677,9 @@ }, { "name": "check_consistent_length", + "unique_name": "check_consistent_length", "qname": "sklearn.utils.validation.check_consistent_length", + "unique_qname": "sklearn.utils.validation.check_consistent_length", "decorators": [], "parameters": [], "results": [], @@ -171278,7 +177690,9 @@ }, { "name": "check_is_fitted", + "unique_name": "check_is_fitted", "qname": "sklearn.utils.validation.check_is_fitted", + "unique_qname": "sklearn.utils.validation.check_is_fitted", "decorators": [], "parameters": [ { @@ -171330,7 +177744,9 @@ }, { "name": "check_memory", + "unique_name": "check_memory", "qname": "sklearn.utils.validation.check_memory", + "unique_qname": "sklearn.utils.validation.check_memory", "decorators": [], "parameters": [ { @@ -171352,7 +177768,9 @@ }, { "name": "check_non_negative", + "unique_name": "check_non_negative", "qname": "sklearn.utils.validation.check_non_negative", + "unique_qname": "sklearn.utils.validation.check_non_negative", "decorators": [], "parameters": [ { @@ -171384,7 +177802,9 @@ }, { "name": "check_random_state", + "unique_name": "check_random_state", "qname": "sklearn.utils.validation.check_random_state", + "unique_qname": "sklearn.utils.validation.check_random_state", "decorators": [], "parameters": [ { @@ -171406,7 +177826,9 @@ }, { "name": "check_scalar", + "unique_name": "check_scalar", "qname": "sklearn.utils.validation.check_scalar", + "unique_qname": "sklearn.utils.validation.check_scalar", "decorators": [], "parameters": [ { @@ -171478,7 +177900,9 @@ }, { "name": "check_symmetric", + "unique_name": "check_symmetric", "qname": "sklearn.utils.validation.check_symmetric", + "unique_qname": "sklearn.utils.validation.check_symmetric", "decorators": [], "parameters": [ { @@ -171530,7 +177954,9 @@ }, { "name": "column_or_1d", + "unique_name": "column_or_1d", "qname": "sklearn.utils.validation.column_or_1d", + "unique_qname": "sklearn.utils.validation.column_or_1d", "decorators": [], "parameters": [ { @@ -171562,7 +177988,9 @@ }, { "name": "has_fit_parameter", + "unique_name": "has_fit_parameter", "qname": "sklearn.utils.validation.has_fit_parameter", + "unique_qname": "sklearn.utils.validation.has_fit_parameter", "decorators": [], "parameters": [ { @@ -171589,12 +178017,14 @@ "results": [], "is_public": true, "description": "Checks whether the estimator's fit method supports the given parameter.", - "docstring": "Checks whether the estimator's fit method supports the given parameter.\n\nParameters\n----------\nestimator : object\n An estimator to inspect.\n\nparameter : str\n The searched parameter.\n\nReturns\n-------\nis_parameter: bool\n Whether the parameter was found to be a named parameter of the\n estimator's fit method.\n\nExamples\n--------\n>>> from sklearn.svm import SVC\n>>> has_fit_parameter(SVC(), \"sample_weight\")\nTrue", - "source_code": "\ndef has_fit_parameter(estimator, parameter):\n \"\"\"Checks whether the estimator's fit method supports the given parameter.\n\n Parameters\n ----------\n estimator : object\n An estimator to inspect.\n\n parameter : str\n The searched parameter.\n\n Returns\n -------\n is_parameter: bool\n Whether the parameter was found to be a named parameter of the\n estimator's fit method.\n\n Examples\n --------\n >>> from sklearn.svm import SVC\n >>> has_fit_parameter(SVC(), \"sample_weight\")\n True\n\n \"\"\"\n return parameter in signature(estimator.fit).parameters" + "docstring": "Checks whether the estimator's fit method supports the given parameter.\n\nParameters\n----------\nestimator : object\n An estimator to inspect.\n\nparameter : str\n The searched parameter.\n\nReturns\n-------\nis_parameter: bool\n Whether the parameter was found to be a named parameter of the\n estimator's fit method.\n\nExamples\n--------\n>>> from sklearn.svm import SVC\n>>> from sklearn.utils.validation import has_fit_parameter\n>>> has_fit_parameter(SVC(), \"sample_weight\")\nTrue", + "source_code": "\ndef has_fit_parameter(estimator, parameter):\n \"\"\"Checks whether the estimator's fit method supports the given parameter.\n\n Parameters\n ----------\n estimator : object\n An estimator to inspect.\n\n parameter : str\n The searched parameter.\n\n Returns\n -------\n is_parameter: bool\n Whether the parameter was found to be a named parameter of the\n estimator's fit method.\n\n Examples\n --------\n >>> from sklearn.svm import SVC\n >>> from sklearn.utils.validation import has_fit_parameter\n >>> has_fit_parameter(SVC(), \"sample_weight\")\n True\n\n \"\"\"\n return parameter in signature(estimator.fit).parameters" }, { "name": "indexable", + "unique_name": "indexable", "qname": "sklearn.utils.validation.indexable", + "unique_qname": "sklearn.utils.validation.indexable", "decorators": [], "parameters": [], "results": [],