ValueError: Expected 2D array, got 1D array instead

ValueError: Expected 2D array, got 1D array instead,第1张

Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.

翻译过来就是:

如果数据具有单个特征,请使用 array.reshape(-1, 1) 重塑数据,如果数据包含单个样本,则使用 array.reshape(1, -1) 来重塑数据。

 从feature_file提取的为list类型的数据,首先需变成二维数组,然后经过.reshape(1,-1)进行转换变换即可正常输入模型分类测试:

注:我这里用的是模型测试阶段(只有一个样本,包含若干个特征)

    import numpy as np
    name = input('请输入文件路径:')
    #开始特征提取
    fea = feature_file(name)
    print("fea",fea)

    fea = np.array(fea).reshape(1,-1)  #重点在这行

    #开始分类
    Classify(fea)

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/943562.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-18
下一篇 2022-05-18

发表评论

登录后才能评论

评论列表(0条)

保存