本文整理汇总了Python中sklearn.manifold方法的典型用法代码示例。如果您正苦于以下问题:Python sklearn.manifold方法的具体用法?Python sklearn.manifold怎么用?Python sklearn.manifold使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn
的用法示例。
在下文中一共展示了sklearn.manifold方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: learn_tsne
# 需要导入模块: import sklearn [as 别名]
# 或者: from sklearn import manifold [as 别名]
def learn_tsne(data, **kwargs):
"""
Calculates TSNE transformation for given matrix features.
Parameters
--------
data: np.array
Array of features.
kwargs: optional
Parameters for ``sklearn.manifold.TSNE()``
Returns
-------
Calculated TSNE transform
Return type
-------
np.ndarray
"""
_tsne_filter = TSNE.get_params(TSNE)
kwargs = {i: j for i, j in kwargs.items() if i in _tsne_filter}
res = TSNE(random_state=0, **kwargs).fit_transform(data.values)
return pd.DataFrame(res, index=data.index.values)
示例2: get_manifold
# 需要导入模块: import sklearn [as 别名]
# 或者: from sklearn import manifold [as 别名]
def get_manifold(data, manifold_type, **kwargs):
"""
Reduces number of dimensions.
Parameters
---------
data: pd.DataFrame
Dataframe with features for clustering indexed as in ``retention_config.index_col``
manifold_type: str
Name dimensionality reduction method from ``sklearn.decomposition`` and ``sklearn.manifold``
kwargs: optional
Parameters for ``sklearn.decomposition`` and ``sklearn.manifold`` methods.
Returns
--------
pd.DataFrame with reduced dimensions.
Return type
--------
pd.DataFrame
"""
if hasattr(decomposition, manifold_type):
man = getattr(decomposition, manifold_type)
elif hasattr(manifold, manifold_type):
man = getattr(manifold, manifold_type)
else:
raise ValueError(f'There is not such manifold {manifold_type}')
tsvd = man(**{i: j for i, j in kwargs.items() if i in man.get_params(man)})
res = tsvd.fit_transform(data)
return pd.DataFrame(res, index=data.index)
示例3: merge_features
# 需要导入模块: import sklearn [as 别名]
# 或者: from sklearn import manifold [as 别名]
def merge_features(features, metadata, meta_index_col=None, manifold_type=None, fillna=None, drop=False, **kwargs):
"""
Adds metadata to TFIDF of trajectories. Eeduced if ``manifold_type`` is not ``None``.
Parameters
--------
features: pd.DataFrame
Dataframe with users` metadata.
metadata: pd.DataFrame
Dataframe with user or session properties or any other information you would like to extract as features (e.g. user properties, LTV values, etc.). Default: ``None``
meta_index_col: str, optional
Used when metadata is not ``None``. Name of column in ``metadata`` dataframe that contains the same ID as in ``index_col``, or if not defined, same as in retention_config (e.g ID of users or sessions). If ``None``, then index of metadata dataframe is used instead. Default: ``None``
manifold_type: str, optional
Name dimensionality reduction method from ``sklearn.decomposition`` and ``sklearn.manifold``. Default: ``None``
fillna: optional
Value for filling missing metadata for any ``index_col`` value. Default: ``None``
drop: bool, optional
If ``True``, then drops users which do not exist in ``metadata`` dataframe. Default: ``False``
kwargs: optional
Keyword arguments for ``sklearn.decomposition`` and ``sklearn.manifold`` methods.
Returns
-------
Dataframe with trajectory features (possibly reduced) and users metadata.
Return type
-------
pd.DataFrame
"""
if manifold_type is not None:
features = get_manifold(features, manifold_type, **kwargs)
if meta_index_col is not None:
metadata.index = metadata[meta_index_col].values
metadata = metadata.drop(meta_index_col, 1)
res = features.join(metadata, rsuffix='_meta',)
if drop and (fillna is None):
res = res[res.isnull().sum(1) == 0].copy()
if fillna is not None:
res = res.fillna(fillna)
return res