'Predict the labels (1 inlier, -1 outlier) of X according to LOF.
If X is None, returns the same as fit_predict(X_train).
This method allows to generalize prediction to new observations (not
in the training set). As LOF originally does not deal with new data,
this method is kept private.
Parameters
X : array-like, shape (n_samples, n_features), default=None
The query sample or samples to compute the Local Outlier Factor
w.r.t. to the training samples. If None, makes prediction on the
training data without considering them as their own neighbors.
Returns
is_inlier : array, shape (n_samples,)
Returns -1 for anomalies/outliers and +1 for inliers.'

def _predict(self, X=None):

    check_is_fitted(self, ['threshold_', 'negative_outlier_factor_', 'n_neighbors_', '_distances_fit_X_'])
    if (X is not None):
        X = check_array(X, accept_sparse='csr')
        is_inlier = np.ones(X.shape[0], dtype=int)
        is_inlier[(self._decision_function(X) <= self.threshold_)] = (-1)
    else:
        is_inlier = np.ones(self._fit_X.shape[0], dtype=int)
        is_inlier[(self.negative_outlier_factor_ <= self.threshold_)] = (-1)
    return is_inlier
