我正在开发一种使用熊猫进行活动识别的算法。 在某种程度上,我正在这样做
feat = data[['x','y','z']].rolling(wsize, int(wsize/2)).apply(rms).add_suffix('_rms')
但是我收到此错误:
AttributeError Traceback (most recent call last)
<ipython-input-5-95eebeaeb992> in <module>
1 data2 = read_data('all')
----> 2 feats, y = get_features2(data2, 2)
3 X_train, X_test, y_train, y_test = train_test_split(feats, y, test_size=.25,
4 random_state=0, stratify=y)
5 best_model.fit(X_train, y_train)
<ipython-input-4-8175c64d7de8> in get_features2(data, wsize_sec, overlap)
19
20 #mean_mag = pd.rolling_apply((data**2).sum(axis=1), wsize, lambda ts: np.sqrt(ts).mean(), wsize/2)
---> 21 mean_mag = (data**2).sum(axis=1).swifter.rolling(wsize, int(wsize/2)).aplly(lambda ts: np.sqrt(ts).mean())
22
23 mean_mag.name = 'mean_mag'
AttributeError: 'Rolling' object has no attribute 'aplly'
然后我尝试了迅捷
feat = data[['x','y','z']].swifter.rolling(wsize, int(wsize/2)).apply(rms).add_suffix('_rms')
现在错误已更改为:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-10-95eebeaeb992> in <module>
1 data2 = read_data('all')
----> 2 feats, y = get_features2(data2, 2)
3 X_train, X_test, y_train, y_test = train_test_split(feats, y, test_size=.25,
4 random_state=0, stratify=y)
5 best_model.fit(X_train, y_train)
<ipython-input-9-7810ed7c08b3> in get_features2(data, wsize_sec, overlap)
15
16 #feat = pd.rolling_apply(data[['x','y','z']], wsize, rms, wsize/2).add_suffix('_rms')
---> 17 feat = data[['x','y','z']].swifter.rolling(wsize, int(wsize/2)).apply(rms).add_suffix('_rms')
18 feats = feats.join(feat)
19
~/.local/lib/python3.6/site-packages/swifter/swifter.py in apply(self, func, *args, **kwds)
344 # if pandas apply takes too long, use dask
345 if est_apply_duration > self._dask_threshold:
--> 346 return self._dask_apply(func, *args, **kwds)
347 else: # use pandas
348 if self._progress_bar:
~/.local/lib/python3.6/site-packages/swifter/swifter.py in _dask_apply(self, func, *args, **kwds)
329 return self._obj_dd.apply(func, *args, **kwds).compute(scheduler=self._scheduler)
330 else:
--> 331 return self._obj_dd.apply(func, *args, **kwds).compute(scheduler=self._scheduler)
332
333 def apply(self, func, *args, **kwds):
~/.local/lib/python3.6/site-packages/dask/base.py in compute(self, **kwargs)
154 dask.base.compute
155 """
--> 156 (result,) = compute(self, traverse=False, **kwargs)
157 return result
158
~/.local/lib/python3.6/site-packages/dask/base.py in compute(*args, **kwargs)
391 schedule = get_scheduler(scheduler=kwargs.pop('scheduler', None),
392 collections=collections,
--> 393 get=kwargs.pop('get', None))
394
395 dsk = collections_to_dsk(collections, optimize_graph, **kwargs)
~/.local/lib/python3.6/site-packages/dask/base.py in get_scheduler(get, scheduler, collections, cls)
868 elif "Client" in type(scheduler).__name__ and hasattr(scheduler, 'get'):
869 return scheduler.get
--> 870 elif scheduler.lower() in named_schedulers:
871 return named_schedulers[scheduler.lower()]
872 elif scheduler.lower() in ('dask.distributed', 'distributed'):
AttributeError: 'bool' object has no attribute 'lower'
如何解决此错误? 我正在使用python 3.6和pandas 0.24.2。
这是完整的代码: https://github.com/pauloaferreiraa/Thesis/blob/master/analysis_python3.ipynb