本文整理汇总了Python中KNNClassifierRegion.KNNClassifierRegion.__setstate__方法的典型用法代码示例。如果您正苦于以下问题:Python KNNClassifierRegion.__setstate__方法的具体用法?Python KNNClassifierRegion.__setstate__怎么用?Python KNNClassifierRegion.__setstate__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KNNClassifierRegion.KNNClassifierRegion
的用法示例。
在下文中一共展示了KNNClassifierRegion.__setstate__方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: KNNAnomalyClassifierRegion
# 需要导入模块: from KNNClassifierRegion import KNNClassifierRegion [as 别名]
# 或者: from KNNClassifierRegion.KNNClassifierRegion import __setstate__ [as 别名]
#.........这里部分代码省略.........
self._deleteRecordsFromKNN(recordsToDelete)
# Remove records not in cache
self._deleteRangeFromKNN(start, end)
# Recompute [clippedEnd, ...)
for state in self._recordsCache[clippedEnd:]:
self.classifyState(state)
#############################################################################
#
# Methods to support serialization
#
#############################################################################
#############################################################################
def __getstate__(self):
"""
Return serializable state. This function will return a version of the
__dict__ with all "ephemeral" members stripped out. "Ephemeral" members
are defined as those that do not need to be (nor should be) stored
in any kind of persistent file (e.g., NuPIC network XML file.)
"""
state = self.__dict__.copy()
# Save knnclassifier properties
state['_knnclassifierProps'] = state['_knnclassifier'].__getstate__()
state.pop('_knnclassifier')
return state
#############################################################################
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()
def diff(self, knnRegion2):
diff = []
toCheck = [((), self.__getstate__(), knnRegion2.__getstate__())]
while toCheck:
keys, a, b = toCheck.pop()
if type(a) != type(b):
diff.append((keys, a, b))
elif 'saved_categories' in keys:
cats1 = set(a)