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

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)

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
乘风的头像乘风管理团队
上一篇 2022年5月11日
下一篇 2022年5月13日

相关推荐