Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
targets = self.get_clusters(plot_type=None, **kwargs)
elif plot_type == 'targets':
targets = self._tsne_targets
else:
return self._tsne
if proj_type == '3d':
plot.tsne_3d(
self._obj,
clustering.aggregate_cl(targets, 7) if kwargs.get('method') == 'dbscan' else targets,
old_targs,
**kwargs
)
else:
plot.cluster_tsne(
self._obj,
clustering.aggregate_cl(targets, 7) if kwargs.get('method') == 'dbscan' else targets,
targets,
**kwargs
)
return self._tsne
Parameters for ``sklearn.decomposition()`` and ``sklearn.manifold()`` methods. Keyword arguments for clusterers. For more information, please, see ``sklearn.cluster.KMeans()``, ``sklearn.cluster.DBSCAN()``, ``sklearn.mixture.GaussianMixture()`` docs.
Returns
-------
Array of clusters
Return type
-------
np.array
"""
if hasattr(self, 'datatype') and self.datatype == 'features':
features = self._obj.copy()
else:
features = self.extract_features(**kwargs)
if not hasattr(self, 'clusters') or refit_cluster:
clusterer = getattr(clustering, method)
self.clusters, self._metrics = clusterer(features, **kwargs)
self._create_cluster_mapping(features.index.values)
if hasattr(self, 'datatype') and self.datatype == 'features':
target = kwargs.pop('target')
else:
target = self.get_positive_users(**kwargs)
target = features.index.isin(target)
self._metrics['homogen'] = clustering.homogeneity_score(target, self.clusters)
if hasattr(self, '_tsne'):
features.retention._tsne = self._tsne
if plot_type:
func = getattr(plot, plot_type)
res = func(
features,
clustering.aggregate_cl(self.clusters, 7) if method == 'dbscan' else self.clusters,