【问题标题】:python normalize weird behaviourpython规范化奇怪的行为
【发布时间】:2018-05-29 02:46:54
【问题描述】:

我正在尝试根据一组声音样本进行训练。我想通过对正样本进行归一化来使负样本更广泛。

这是我的代码:

for sound in dogbarks:
    expandedsound = audio_to_metadata(sound)
    preprocessed_dogbarks.append(expandedsound)
for sound in noisesounds:
    expandedsound = audio_to_metadata(sound)
    preprocessed_noisesounds.append(expandedsound)

labels = [0]*len(preprocessed_noisesounds) + 
[1]*len(preprocessed_dogbarks)
assert len(labels) == len(preprocessed_noisesounds) + 
len(preprocessed_dogbarks)
allsounds = preprocessed_noisesounds + preprocessed_dogbarks

allsounds_normalized = normalize(allsounds)

当代码尝试规范化数组集并且在我的案例 48 中达到一定数量的成员时,它返回错误:

~/.local/lib/python3.5/site-packages/sklearn/utils/validation.py in 
check_array(array, accept_sparse, dtype, order, copy, 
force_all_finite, ensure_2d, allow_nd, ensure_min_samples, 
ensure_min_features, warn_on_dtype, estimator)
    431                                       force_all_finite)
    432     else:
--> 433         array = np.array(array, dtype=dtype, order=order, copy=copy)
    434 
    435         if ensure_2d:
ValueError: setting an array element with a sequence.

但是,如果我只运行 48 号会员,它就可以正常工作。谁能给我一个线索?如果您愿意,我可以提供数据。

谢谢。

【问题讨论】:

  • 请提供一些有关您正在尝试做什么的上下文并提供代码。
  • 更新了@pault。如果您需要更多信息,请告诉我。谢谢
  • 你在使用sklean.preprocessing.normalize吗? allsounds的类型和维度是什么?
  • 是的,我使用 sklean.preprocessing.normalize,allsounds 的维度是 2,它们是浮点数。
  • 你有什么见解@pault 吗?谢谢

标签: python machine-learning scipy


【解决方案1】:

因为我的问题没有简单的解决方案。我正在采取另一种方式,将其循环并一一规范化并将其放回数组。

for sound in allsounds :
    allsounds_normalized.append(normalize([sound])[0])

如果你们有更好的解决方案,请告诉我,但现在,这就是解决方案。谢谢

【讨论】:

    猜你喜欢
    • 2019-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-05
    • 2022-10-24
    • 2020-03-24
    • 1970-01-01
    相关资源
    最近更新 更多