1
|
|
|
import sklearn.manifold as skl_manifold |
|
|
|
|
2
|
|
|
|
3
|
|
|
from Orange.distance import SklDistance, SpearmanDistance, PearsonDistance |
4
|
|
|
from Orange.projection import SklProjector |
5
|
|
|
|
6
|
|
|
__all__ = ["MDS", "Isomap", "LocallyLinearEmbedding"] |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
class MDS(SklProjector): |
10
|
|
|
__wraps__ = skl_manifold.MDS |
11
|
|
|
name = 'mds' |
12
|
|
|
|
13
|
|
|
def __init__(self, n_components=2, metric=True, n_init=4, max_iter=300, |
|
|
|
|
14
|
|
|
eps=0.001, n_jobs=1, random_state=None, |
|
|
|
|
15
|
|
|
dissimilarity='euclidean', |
16
|
|
|
preprocessors=None): |
17
|
|
|
super().__init__(preprocessors=preprocessors) |
18
|
|
|
self.params = vars() |
19
|
|
|
self._metric = dissimilarity |
20
|
|
|
|
21
|
|
|
def __call__(self, data): |
22
|
|
|
distances = SklDistance, SpearmanDistance, PearsonDistance |
23
|
|
|
if isinstance(self._metric, distances): |
24
|
|
|
data = self.preprocess(data) |
25
|
|
|
X, Y, domain = data.X, data.Y, data.domain |
26
|
|
|
dist_matrix = self._metric(X) |
27
|
|
|
self.params['dissimilarity'] = 'precomputed' |
28
|
|
|
clf = self.fit(dist_matrix, Y=Y) |
29
|
|
|
elif self._metric is 'precomputed': |
30
|
|
|
dist_matrix, Y, domain = data, None, None |
31
|
|
|
clf = self.fit(dist_matrix, Y=Y) |
32
|
|
|
else: |
33
|
|
|
data = self.preprocess(data) |
34
|
|
|
X, Y, domain = data.X, data.Y, data.domain |
35
|
|
|
clf = self.fit(X, Y=Y) |
36
|
|
|
clf.domain = domain |
37
|
|
|
return clf |
38
|
|
|
|
39
|
|
|
def fit(self, X, init=None, Y=None): |
|
|
|
|
40
|
|
|
proj = self.__wraps__(**self.params) |
41
|
|
|
return proj.fit(X, init=init, y=Y) |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
class Isomap(SklProjector): |
45
|
|
|
__wraps__ = skl_manifold.Isomap |
46
|
|
|
name = 'isomap' |
47
|
|
|
|
48
|
|
|
def __init__(self, n_neighbors=5, n_components=2, eigen_solver='auto', |
|
|
|
|
49
|
|
|
max_iter=None, path_method='auto', |
|
|
|
|
50
|
|
|
neighbors_algorithm='auto', preprocessors=None): |
|
|
|
|
51
|
|
|
super().__init__(preprocessors=preprocessors) |
52
|
|
|
self.params = vars() |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
class LocallyLinearEmbedding(SklProjector): |
56
|
|
|
__wraps__ = skl_manifold.LocallyLinearEmbedding |
57
|
|
|
name = 'lle' |
58
|
|
|
|
59
|
|
|
def __init__(self, n_neighbors=5, n_components=2, reg=0.001, |
|
|
|
|
60
|
|
|
eigen_solver='auto', tol=1e-06 , max_iter=100, |
|
|
|
|
61
|
|
|
method='standard', hessian_tol=0.0001, |
|
|
|
|
62
|
|
|
modified_tol=1e-12, neighbors_algorithm='auto', |
|
|
|
|
63
|
|
|
random_state=None, preprocessors=None): |
|
|
|
|
64
|
|
|
super().__init__(preprocessors=preprocessors) |
65
|
|
|
self.params = vars() |
66
|
|
|
|
This can be caused by one of the following:
1. Missing Dependencies
This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.
2. Missing __init__.py files
This error could also result from missing
__init__.py
files in your module folders. Make sure that you place one file in each sub-folder.