GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (4082)

Orange/clustering/kmeans.py (11 issues)

1
import numpy as np
0 ignored issues
show
The import numpy could not be resolved.

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.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

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.

Loading history...
2
import sklearn.cluster as skl_cluster
0 ignored issues
show
The import sklearn.cluster could not be resolved.

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.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

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.

Loading history...
3
from sklearn.metrics import silhouette_score
0 ignored issues
show
The import sklearn.metrics could not be resolved.

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.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

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.

Loading history...
4
5
from Orange.data import Table, DiscreteVariable, Domain, Instance
6
from Orange.projection import SklProjector, Projection
7
from Orange.distance import Euclidean
8
9
10
__all__ = ["KMeans"]
11
12
13
class KMeans(SklProjector):
14
    __wraps__ = skl_cluster.KMeans
15
16
    def __init__(self, n_clusters=8, init='k-means++', n_init=10, max_iter=300,
0 ignored issues
show
The argument init seems to be unused.
Loading history...
The argument n_init seems to be unused.
Loading history...
The argument max_iter seems to be unused.
Loading history...
The argument n_clusters seems to be unused.
Loading history...
17
                 tol=0.0001, random_state=None, preprocessors=None):
0 ignored issues
show
The argument random_state seems to be unused.
Loading history...
The argument tol seems to be unused.
Loading history...
18
        super().__init__(preprocessors=preprocessors)
19
        self.params = vars()
20
21
    def fit(self, X, Y=None):
22
        proj = skl_cluster.KMeans(**self.params)
23
        if isinstance(X, Table):
24
            proj = proj.fit(X.X, Y)
25
            proj.silhouette = silhouette_score(X.X, proj.labels_)
26
        else:
27
            proj = proj.fit(X, Y)
28
            proj.silhouette = silhouette_score(X, proj.labels_)
29
        proj.inertia = proj.inertia_ / len(X)
30
        cluster_dist = Euclidean(proj.cluster_centers_)
31
        proj.inter_cluster = np.mean(cluster_dist[np.triu_indices_from(cluster_dist, 1)])
32
        return KMeansModel(proj, self.preprocessors)
33
34
35
class KMeansModel(Projection):
36
    def __init__(self, proj, preprocessors=None):
0 ignored issues
show
The argument preprocessors seems to be unused.
Loading history...
37
        super().__init__(proj=proj)
38
        self.k = self.proj.get_params()["n_clusters"]
39
        self.centroids = self.proj.cluster_centers_
40
41
    def __call__(self, data):
42
        if isinstance(data, Table):
43
            if data.domain is not self.pre_domain:
44
                data = Table(self.pre_domain, data)
45
            c = DiscreteVariable(name='Cluster id', values=range(self.k))
46
            domain = Domain([c])
47
            return Table(
48
                domain,
49
                self.proj.predict(data.X).astype(int).reshape((len(data), 1)))
50
        elif isinstance(data, Instance):
51
            if data.domain is not self.pre_domain:
52
                data = Instance(self.pre_domain, data)
53
            c = DiscreteVariable(name='Cluster id', values=range(self.k))
54
            domain = Domain([c])
55
            return Table(
56
                domain,
57
                np.atleast_2d(self.proj.predict(data._x)).astype(int))
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _x was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
58
        else:
59
            return self.proj.predict(data).reshape((len(data), 1))
60