當前位置: 首頁>>代碼示例>>Python>>正文


Python KNNClassifierRegion.KNNClassifierRegion類代碼示例

本文整理匯總了Python中KNNClassifierRegion.KNNClassifierRegion的典型用法代碼示例。如果您正苦於以下問題:Python KNNClassifierRegion類的具體用法?Python KNNClassifierRegion怎麽用?Python KNNClassifierRegion使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了KNNClassifierRegion類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

  def __init__(self,
               trainRecords,
               anomalyThreshold,
               cacheSize,
               classificationVectorType=1,
               activeColumnCount=40,
               classificationMaxDist=0.30,
               **classifierArgs):

    # Internal Region Values
    self._maxLabelOutputs = 16
    self._activeColumnCount = activeColumnCount
    self._prevPredictedColumns = numpy.array([])
    self._anomalyVectorLength = None
    self._classificationMaxDist = classificationMaxDist
    self._iteration = 0

    # Set to create deterministic classifier
    classifierArgs['SVDDimCount'] = None

    # Parameters
    self.trainRecords = trainRecords
    self.anomalyThreshold = anomalyThreshold
    self.cacheSize = cacheSize
    self.classificationVectorType = classificationVectorType

    self._knnclassifierArgs = classifierArgs
    self._knnclassifier = KNNClassifierRegion(**self._knnclassifierArgs)
    self.labelResults = []
    self.saved_categories = []
    self._recordsCache = []

    self._version = KNNAnomalyClassifierRegion.__VERSION__
開發者ID:GeraldLoeffler,項目名稱:nupic,代碼行數:33,代碼來源:KNNAnomalyClassifierRegion.py

示例2: __setstate__

  def __setstate__(self, state):
    """
    Set the state of ourself from a serialized state.
    """
    if '_version' not in state or state['_version'] == 1:

      knnclassifierProps = state.pop('_knnclassifierProps')

      self.__dict__.update(state)
      self._knnclassifier = KNNClassifierRegion(**self._knnclassifierArgs)
      self._knnclassifier.__setstate__(knnclassifierProps)

      self._version = KNNAnomalyClassifierRegion.__VERSION__
    else:
      raise Exception("Invalid KNNAnomalyClassifierRegion version. Current "
          "version: %s" % (KNNAnomalyClassifierRegion.__VERSION__))
開發者ID:GeraldLoeffler,項目名稱:nupic,代碼行數:16,代碼來源:KNNAnomalyClassifierRegion.py

示例3: __setstate__

  def __setstate__(self, state):
    """
    Set the state of ourself from a serialized state.
    """
    if '_version' not in state or state['_version'] == 1:

      knnclassifierProps = state.pop('_knnclassifierProps')

      self.__dict__.update(state)
      self._knnclassifier = KNNClassifierRegion(**self._knnclassifierArgs)
      self._knnclassifier.__setstate__(knnclassifierProps)

      self._version = KNNAnomalyClassifierRegion.__VERSION__
    else:
      raise Exception("Invalid KNNAnomalyClassifierRegion version. Current "
          "version: %s" % (KNNAnomalyClassifierRegion.__VERSION__))


    # --------------------------------------------------------------------------
    # Migrate from when Anomaly was separated to stand-alone class
    if not hasattr(self, "_anomaly"):
      self._anomaly = Anomaly()
開發者ID:pjpan,項目名稱:nupic,代碼行數:22,代碼來源:KNNAnomalyClassifierRegion.py

示例4: getSpec


#.........這裏部分代碼省略.........
            isDefaultInput=True,
            requireSplitterMap=False),

          tpLrnActiveStateT=dict(
            description="""Active cells in the learn state at time T from TP.
                        This is used to classify on.""",
            dataType='Real32',
            count=0,
            required=True,
            regionLevel=False,
            isDefaultInput=True,
            requireSplitterMap=False)
        ),

        outputs=dict(
        ),

        parameters=dict(
          trainRecords=dict(
            description='Number of records to wait for training',
            dataType='UInt32',
            count=1,
            constraints='',
            defaultValue=0,
            accessMode='Create'),

          anomalyThreshold=dict(
            description='Threshold used to classify anomalies.',
            dataType='Real32',
            count=1,
            constraints='',
            defaultValue=0,
            accessMode='Create'),

          cacheSize=dict(
            description='Number of records to store in cache.',
            dataType='UInt32',
            count=1,
            constraints='',
            defaultValue=0,
            accessMode='Create'),

          classificationVectorType=dict(
            description="""Vector type to use when classifying.
              1 - Vector Column with Difference (TP and SP)
            """,
            dataType='UInt32',
            count=1,
            constraints='',
            defaultValue=1,
            accessMode='ReadWrite'),

          activeColumnCount=dict(
            description="""Number of active columns in a given step. Typically
            equivalent to SP.numActivePerInhArea""",
            dataType='UInt32',
            count=1,
            constraints='',
            defaultValue=40,
            accessMode='ReadWrite'),

          classificationMaxDist=dict(
            description="""Maximum distance a sample can be from an anomaly
            in the classifier to be labeled as an anomaly.

            Ex: With rawOverlap distance, a value of 0.65 means that the points
            must be at most a distance 0.65 apart from each other. This
            translates to they must be at least 35% similar.""",
            dataType='Real32',
            count=1,
            constraints='',
            defaultValue=0.65,
            accessMode='Create'
            )
        ),
        commands=dict(
          getLabels=dict(description=
            "Returns a list of label dicts with properties ROWID and labels."
            "ROWID corresponds to the records id and labels is a list of "
            "strings representing the records labels.  Takes additional "
            "integer properties start and end representing the range that "
            "will be returned."),

          addLabel=dict(description=
            "Takes parameters start, end and labelName. Adds the label "
            "labelName to the records from start to end. This will recalculate "
            "labels from end to the most recent record."),

          removeLabels=dict(description=
            "Takes additional parameters start, end, labelFilter.  Start and "
            "end correspond to range to remove the label. Remove labels from "
            "each record with record ROWID in range from start to end, "
            "noninclusive of end. Removes all records if labelFilter is None, "
            "otherwise only removes the labels eqaul to labelFilter.")
        )
      )

    ns['parameters'].update(KNNClassifierRegion.getSpec()['parameters'])

    return ns
開發者ID:pjpan,項目名稱:nupic,代碼行數:101,代碼來源:KNNAnomalyClassifierRegion.py

示例5: KNNAnomalyClassifierRegion

class KNNAnomalyClassifierRegion(PyRegion):
  """
  KNNAnomalyClassifierRegion wraps the KNNClassifierRegion to classify clamodel
  state.  It allows for individual records to be classified as anomalies and
  supports anomaly detection even after the model has learned the anomalous
  sequence.

  Methods:
    compute() - called by clamodel during record processing
    getLabels() - return points with classification records
    addLabel() - add a set label to a given set of points
    removeLabels() - remove labels from a given set of points

  Parameters:
    trainRecords - number of records to skip before classification
    anomalyThreshold - threshold on anomaly score to automatically classify
                       record as an anomaly
    cacheSize - number of records to keep in cache. Can only recalculate
                records kept in cache when setting the trainRecords.

  """

  @classmethod
  def getSpec(cls):
    ns = dict(
        description=KNNAnomalyClassifierRegion.__doc__,
        singleNodeOnly=True,
        inputs=dict(
          spBottomUpOut=dict(
            description="""The output signal generated from the bottom-up inputs
                            from lower levels.""",
            dataType='Real32',
            count=0,
            required=True,
            regionLevel=False,
            isDefaultInput=True,
            requireSplitterMap=False),

          tpTopDownOut=dict(
            description="""The top-down inputsignal, generated from
                          feedback from upper levels""",
            dataType='Real32',
            count=0,
            required=True,
            regionLevel=False,
            isDefaultInput=True,
            requireSplitterMap=False),

          tpLrnActiveStateT=dict(
            description="""Active cells in the learn state at time T from TP.
                        This is used to classify on.""",
            dataType='Real32',
            count=0,
            required=True,
            regionLevel=False,
            isDefaultInput=True,
            requireSplitterMap=False)
        ),

        outputs=dict(
        ),

        parameters=dict(
          trainRecords=dict(
            description='Number of records to wait for training',
            dataType='UInt32',
            count=1,
            constraints='',
            defaultValue=0,
            accessMode='Create'),

          anomalyThreshold=dict(
            description='Threshold used to classify anomalies.',
            dataType='Real32',
            count=1,
            constraints='',
            defaultValue=0,
            accessMode='Create'),

          cacheSize=dict(
            description='Number of records to store in cache.',
            dataType='UInt32',
            count=1,
            constraints='',
            defaultValue=0,
            accessMode='Create'),

          classificationVectorType=dict(
            description="""Vector type to use when classifying.
              1 - Vector Column with Difference (TP and SP)
            """,
            dataType='UInt32',
            count=1,
            constraints='',
            defaultValue=1,
            accessMode='ReadWrite'),

          activeColumnCount=dict(
            description="""Number of active columns in a given step. Typically
            equivalent to SP.numActivePerInhArea""",
#.........這裏部分代碼省略.........
開發者ID:pjpan,項目名稱:nupic,代碼行數:101,代碼來源:KNNAnomalyClassifierRegion.py


注:本文中的KNNClassifierRegion.KNNClassifierRegion類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。