diff --git a/lib/sequentia/classifiers/hmm/hmm_classifier.py b/lib/sequentia/classifiers/hmm/hmm_classifier.py index 08f2cfa3..96d1a6c8 100644 --- a/lib/sequentia/classifiers/hmm/hmm_classifier.py +++ b/lib/sequentia/classifiers/hmm/hmm_classifier.py @@ -45,7 +45,7 @@ def fit(self, models): self._encoder = LabelEncoder() self._encoder.fit([model.label for model in models]) - def predict(self, X, prior='frequency', verbose=True, return_scores=False, original_labels=True, n_jobs=1): + def predict(self, X, prior='frequency', return_scores=False, original_labels=True, verbose=True, n_jobs=1): """Predicts the label for an observation sequence (or multiple sequences) according to maximum likelihood or posterior scores. Parameters @@ -62,6 +62,12 @@ def predict(self, X, prior='frequency', verbose=True, return_scores=False, origi Alternatively, class prior probabilities can be specified in an iterable of floats, e.g. `[0.1, 0.3, 0.6]`. + return_scores: bool + Whether to return the scores of each model on the observation sequence(s). + + original_labels: bool + Whether to inverse-transform the labels to their original encoding. + verbose: bool Whether to display a progress bar or not. @@ -70,12 +76,6 @@ def predict(self, X, prior='frequency', verbose=True, return_scores=False, origi are always displayed in the console, regardless of where you are running this function from (e.g. a Jupyter notebook). - return_scores: bool - Whether to return the scores of each model on the observation sequence(s). - - original_labels: bool - Whether to inverse-transform the labels to their original encoding. - n_jobs: int > 0 or -1 | The number of jobs to run in parallel. | Setting this to -1 will use all available CPU cores. @@ -105,9 +105,9 @@ def predict(self, X, prior='frequency', verbose=True, return_scores=False, origi assert np.isclose(sum(prior), 1.), 'Class priors must form a probability distribution by summing to one' else: self._val.one_of(prior, ['frequency', 'uniform'], desc='prior') - self._val.boolean(verbose, desc='verbose') self._val.boolean(return_scores, desc='return_scores') self._val.boolean(original_labels, desc='original_labels') + self._val.boolean(verbose, desc='verbose') self._val.restricted_integer(n_jobs, lambda x: x == -1 or x > 0, 'number of jobs', '-1 or greater than zero') # Create look-up for prior probabilities diff --git a/lib/sequentia/classifiers/knn/knn_classifier.py b/lib/sequentia/classifiers/knn/knn_classifier.py index 7ac38e2b..882eace1 100644 --- a/lib/sequentia/classifiers/knn/knn_classifier.py +++ b/lib/sequentia/classifiers/knn/knn_classifier.py @@ -137,7 +137,7 @@ def fit(self, X, y): self._X, self._y = X, self._encoder.transform(y) self._n_features = X[0].shape[1] - def predict(self, X, verbose=True, original_labels=True, n_jobs=1): + def predict(self, X, original_labels=True, verbose=True, n_jobs=1): """Predicts the label for an observation sequence (or multiple sequences). Parameters @@ -145,6 +145,9 @@ def predict(self, X, verbose=True, original_labels=True, n_jobs=1): X: numpy.ndarray (float) or list of numpy.ndarray (float) An individual observation sequence or a list of multiple observation sequences. + original_labels: bool + Whether to inverse-transform the labels to their original encoding. + verbose: bool Whether to display a progress bar or not. @@ -153,9 +156,6 @@ def predict(self, X, verbose=True, original_labels=True, n_jobs=1): are always displayed in the console, regardless of where you are running this function from (e.g. a Jupyter notebook). - original_labels: bool - Whether to inverse-transform the labels to their original encoding. - n_jobs: int > 0 or -1 | The number of jobs to run in parallel. | Setting this to -1 will use all available CPU cores. @@ -174,8 +174,8 @@ def predict(self, X, verbose=True, original_labels=True, n_jobs=1): raise RuntimeError('The classifier needs to be fitted before predictions are made') X = self._val.observation_sequences(X, allow_single=True) - self._val.boolean(verbose, desc='verbose') self._val.boolean(original_labels, desc='original_labels') + self._val.boolean(verbose, desc='verbose') self._val.restricted_integer(n_jobs, lambda x: x == -1 or x > 0, 'number of jobs', '-1 or greater than zero') if isinstance(X, np.ndarray): @@ -215,7 +215,7 @@ def evaluate(self, X, y, verbose=True, n_jobs=1): """ X, y = self._val.observation_sequences_and_labels(X, y) self._val.boolean(verbose, desc='verbose') - predictions = self.predict(X, verbose=verbose, original_labels=False, n_jobs=n_jobs) + predictions = self.predict(X, original_labels=False, verbose=verbose, n_jobs=n_jobs) cm = confusion_matrix(self._encoder.transform(y), predictions, labels=self._encoder.transform(self._encoder.classes_)) return np.sum(np.diag(cm)) / np.sum(cm), cm