コード例 #1
0
ファイル: sam_knn.py プロジェクト: lengfab/scikit-multiflow
 def clean_samples(self, samplesCl, labelsCl, onlyLast=False):
     """Removes distance-based all instances from the input samples that contradict those in the STM."""
     if len(self._STMLabels) > self.n_neighbors and samplesCl.shape[0] > 0:
         if onlyLast:
             loopRange = [len(self._STMLabels) - 1]
         else:
             loopRange = range(len(self._STMLabels))
         for i in loopRange:
             if len(labelsCl) == 0:
                 break
             samplesShortened = np.delete(self._STMSamples, i, 0)
             labelsShortened = np.delete(self._STMLabels, i, 0)
             distancesSTM = SAMKNN.get_distances(self._STMSamples[i, :],
                                                 samplesShortened)
             nnIndicesSTM = libNearestNeighbor.nArgMin(
                 self.n_neighbors, distancesSTM)[0]
             distancesLTM = SAMKNN.get_distances(self._STMSamples[i, :],
                                                 samplesCl)
             nnIndicesLTM = libNearestNeighbor.nArgMin(
                 min(len(distancesLTM), self.n_neighbors), distancesLTM)[0]
             correctIndicesSTM = nnIndicesSTM[labelsShortened[nnIndicesSTM]
                                              == self._STMLabels[i]]
             if len(correctIndicesSTM) > 0:
                 distThreshold = np.max(distancesSTM[correctIndicesSTM])
                 wrongIndicesLTM = nnIndicesLTM[
                     labelsCl[nnIndicesLTM] != self._STMLabels[i]]
                 delIndices = np.where(
                     distancesLTM[wrongIndicesLTM] <= distThreshold)[0]
                 samplesCl = np.delete(samplesCl,
                                       wrongIndicesLTM[delIndices], 0)
                 labelsCl = np.delete(labelsCl, wrongIndicesLTM[delIndices],
                                      0)
     return samplesCl, labelsCl
コード例 #2
0
ファイル: sam_knn.py プロジェクト: angelleng/scikit-multiflow
    def get_distance_weighted_label(distances, labels, numNeighbours):
        """Returns the the distance weighted label of the k nearest neighbors."""
        nnIndices = libNearestNeighbor.nArgMin(numNeighbours, distances)
        sqrtDistances = np.sqrt(distances[nnIndices])
        if not isinstance(labels, type(np.array([]))):
            labels = np.asarray(labels, dtype=np.int8)
        else:
            labels = np.int8(labels)

        predLabels = libNearestNeighbor.getLinearWeightedLabels(labels[nnIndices], sqrtDistances)
        return predLabels
コード例 #3
0
ファイル: sam_knn.py プロジェクト: lengfab/scikit-multiflow
    def get_maj_label(distances, labels, numNeighbours):
        """Returns the majority label of the k nearest neighbors."""

        nnIndices = libNearestNeighbor.nArgMin(numNeighbours, distances)

        if not isinstance(labels, type(np.array([]))):
            labels = np.asarray(labels, dtype=np.int8)
        else:
            labels = np.int8(labels)

        predLabels = libNearestNeighbor.mostCommon(labels[nnIndices])

        return predLabels
コード例 #4
0
 def getDistanceWeightedLabel(distances, labels, numNeighbours):
     """Returns the the distance weighted label of the k nearest neighbors."""
     nnIndices = libNearestNeighbor.nArgMin(numNeighbours, distances)
     sqrtDistances = np.sqrt(distances[nnIndices])
     predLabels = libNearestNeighbor.getLinearWeightedLabels(labels[nnIndices], sqrtDistances)
     return predLabels
コード例 #5
0
 def getMajLabel(distances, labels, numNeighbours):
     """Returns the majority label of the k nearest neighbors."""
     nnIndices = libNearestNeighbor.nArgMin(numNeighbours, distances)
     predLabels = libNearestNeighbor.mostCommon(labels[nnIndices])
     return predLabels