Skip to content

Commit fecc606

Browse files
committed
Improve linting
1 parent 2432b51 commit fecc606

13 files changed

+485
-485
lines changed

libact/base/interfaces.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def update(self, entry_id, label):
3636
label : float
3737
The label of the queried sample.
3838
"""
39-
pass
4039

4140
def _get_scores(self):
4241
"""Return the score used for making query, the larger the better. Read-only.
@@ -48,7 +47,6 @@ def _get_scores(self):
4847
(ask_id, scores): list of tuple (int, float)
4948
The index of the next unlabeled sample to be queried and the score assigned.
5049
"""
51-
pass
5250

5351
@abstractmethod
5452
def make_query(self):
@@ -61,7 +59,6 @@ def make_query(self):
6159
ask_id : int
6260
The index of the next unlabeled sample to be queried and labeled.
6361
"""
64-
pass
6562

6663

6764
class Labeler(with_metaclass(ABCMeta, object)):
@@ -84,7 +81,6 @@ def label(self, feature):
8481
label : int
8582
The class label of the queried feature.
8683
"""
87-
pass
8884

8985

9086
class Model(with_metaclass(ABCMeta, object)):
@@ -108,7 +104,6 @@ def train(self, dataset, *args, **kwargs):
108104
self : object
109105
Returns self.
110106
"""
111-
pass
112107

113108
@abstractmethod
114109
def predict(self, feature, *args, **kwargs):
@@ -124,7 +119,6 @@ def predict(self, feature, *args, **kwargs):
124119
y_pred : array-like, shape (n_samples,)
125120
The class labels for samples in the feature array.
126121
"""
127-
pass
128122

129123
@abstractmethod
130124
def score(self, testing_dataset, *args, **kwargs):
@@ -141,7 +135,6 @@ def score(self, testing_dataset, *args, **kwargs):
141135
score : float
142136
Mean accuracy of self.predict(X) wrt. y.
143137
"""
144-
pass
145138

146139

147140
class MultilabelModel(Model):
@@ -150,7 +143,6 @@ class MultilabelModel(Model):
150143
A Model returns a multilabel-predicting function for future samples after
151144
trained on a training dataset.
152145
"""
153-
pass
154146

155147

156148
class ContinuousModel(Model):
@@ -183,7 +175,6 @@ def predict_real(self, feature, *args, **kwargs):
183175
Each entry is the confidence scores per (sample, class)
184176
combination.
185177
"""
186-
pass
187178

188179

189180
class ProbabilisticModel(ContinuousModel):
@@ -210,4 +201,3 @@ def predict_proba(self, feature, *args, **kwargs):
210201
X : array-like, shape (n_samples, n_classes)
211202
Each entry is the prabablity estimate for each class.
212203
"""
213-
pass

libact/labelers/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
from .ideal_labeler import IdealLabeler
66
try:
77
from .interactive_labeler import InteractiveLabeler
8-
except ImportError:
8+
except ImportError as import_error:
99
raise ImportError("Error importing matplotlib."
10-
"InteractiveLabeler not supported.")
10+
"InteractiveLabeler not supported.") from import_error

libact/labelers/ideal_labeler.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class IdealLabeler(Labeler):
2020
2121
"""
2222

23-
def __init__(self, dataset, **kwargs):
23+
def __init__(self, dataset):
24+
super().__init__()
2425
X, y = dataset.get_entries()
2526
# make sure the input dataset is fully labeled
2627
assert (np.array(y) != np.array(None)).all()
@@ -29,7 +30,7 @@ def __init__(self, dataset, **kwargs):
2930

3031
@inherit_docstring_from(Labeler)
3132
def label(self, feature):
32-
yy = self.y[np.where([np.array_equal(x, feature)
33-
for x in self.X])[0]]
34-
ind = np.arange(len(yy))
35-
return yy[np.random.choice(ind, 1)[0]]
33+
labels = self.y[np.where([np.array_equal(x, feature)
34+
for x in self.X])[0]]
35+
ind = np.arange(len(labels))
36+
return labels[np.random.choice(ind, 1)[0]]

libact/labelers/interactive_labeler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class InteractiveLabeler(Labeler):
2626
"""
2727

2828
def __init__(self, **kwargs):
29+
super().__init__()
2930
self.label_name = kwargs.pop('label_name', None)
3031

3132
@inherit_docstring_from(Labeler)

libact/models/logistic_regression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class LogisticRegression(ProbabilisticModel):
1818
"""
1919

2020
def __init__(self, *args, **kwargs):
21+
super().__init__()
2122
self.model = sklearn.linear_model.LogisticRegression(*args, **kwargs)
2223

2324
def train(self, dataset, *args, **kwargs):
@@ -38,4 +39,3 @@ def predict_real(self, feature, *args, **kwargs):
3839

3940
def predict_proba(self, feature, *args, **kwargs):
4041
return self.model.predict_proba(feature, *args, **kwargs)
41-

libact/models/perceptron.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Perceptron(Model):
1616
"""
1717

1818
def __init__(self, *args, **kwargs):
19+
super().__init__()
1920
self.model = sklearn.linear_model.Perceptron(*args, **kwargs)
2021

2122
def train(self, dataset, *args, **kwargs):

libact/models/sklearn_adapter.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""scikit-learn classifier adapter
22
"""
33
from sklearn.base import clone
4-
from libact.base.interfaces import Model, ContinuousModel, ProbabilisticModel
4+
from libact.base.interfaces import Model, ProbabilisticModel
55

66

77
class SklearnAdapter(Model):
@@ -37,6 +37,7 @@ class SklearnAdapter(Model):
3737
"""
3838

3939
def __init__(self, clf):
40+
super().__init__()
4041
self._model = clf
4142

4243
def train(self, dataset, *args, **kwargs):
@@ -50,6 +51,8 @@ def score(self, testing_dataset, *args, **kwargs):
5051
**kwargs)
5152

5253
def clone(self):
54+
"""Constructs a new untrained model with the same parameters.
55+
"""
5356
return SklearnProbaAdapter(clone(self._model))
5457

5558

@@ -108,4 +111,6 @@ def predict_proba(self, feature, *args, **kwargs):
108111
return self._model.predict_proba(feature, *args, **kwargs)
109112

110113
def clone(self):
114+
"""Constructs a new untrained model with the same parameters.
115+
"""
111116
return SklearnProbaAdapter(clone(self._model))

libact/models/svm.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
An interface for scikit-learn's C-Support Vector Classifier model.
44
"""
55
import logging
6-
LOGGER = logging.getLogger(__name__)
76

87
import numpy as np
98
import sklearn.svm
@@ -12,6 +11,9 @@
1211
from libact.base.interfaces import ContinuousModel
1312

1413

14+
LOGGER = logging.getLogger(__name__)
15+
16+
1517
class SVM(ContinuousModel):
1618

1719
"""C-Support Vector Machine Classifier
@@ -46,8 +48,8 @@ def predict_real(self, feature, *args, **kwargs):
4648
dvalue = self.model.decision_function(feature, *args, **kwargs)
4749
if len(np.shape(dvalue)) == 1: # n_classes == 2
4850
return np.vstack((-dvalue, dvalue)).T
49-
else:
50-
if self.decision_function_shape != 'ovr':
51-
LOGGER.warn("SVM model support only 'ovr' for multiclass"
52-
"predict_real.")
53-
return dvalue
51+
52+
if self.decision_function_shape != 'ovr':
53+
LOGGER.warning("SVM model support only 'ovr' for multiclass"
54+
"predict_real.")
55+
return dvalue

libact/query_strategies/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"""
44
from __future__ import absolute_import
55

6+
# pylint: disable=wrong-import-position
7+
68
import os
79
ON_RTD = os.environ.get('READTHEDOCS', None) == 'True'
810
import logging

libact/query_strategies/density_weighted_uncertainty_sampling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def make_query(self):
154154
return unlabeled_entry_ids[ask_id]
155155

156156
class DensityWeightedLogisticRegression(object):
157-
"""Density Weighted Logistic Regression
157+
r"""Density Weighted Logistic Regression
158158
159159
Density Weighted Logistice Regression is used in DWUS to estimate the
160160
probability of representing which label for each cluster.

0 commit comments

Comments
 (0)