Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ValueError:找到样本数不一致的输入变量:[4,103]_Python_Scikit Learn - Fatal编程技术网

Python ValueError:找到样本数不一致的输入变量:[4,103]

Python ValueError:找到样本数不一致的输入变量:[4,103],python,scikit-learn,Python,Scikit Learn,我一直在尝试从一本书中自学机器学习,这是我第一次尝试“非常规”算法。准备好数据后,我使用导入的split函数,然后尝试进行一些预测。但是,即使在手动验证每个功能的#数量相同后,我也会得到一个错误声明: Traceback (most recent call last): File "main.py", line 89, in <module> xTrain, xTest, yTrain, yTest = tts(new_data, netGood, random_stat

我一直在尝试从一本书中自学机器学习,这是我第一次尝试“非常规”算法。准备好数据后,我使用导入的split函数,然后尝试进行一些预测。但是,即使在手动验证每个功能的#数量相同后,我也会得到一个错误声明:

Traceback (most recent call last):
  File "main.py", line 89, in <module>
    xTrain, xTest, yTrain, yTest = tts(new_data, netGood, random_state=0)
  File "/home/runner/.local/lib/python3.6/site-packages/sklearn/model_selection/_split.py", line 2096, in train_test_split
    arrays = indexable(*arrays)
  File "/home/runner/.local/lib/python3.6/site-packages/sklearn/utils/validation.py", line 230, in indexable
    check_consistent_length(*result)
  File "/home/runner/.local/lib/python3.6/site-packages/sklearn/utils/validation.py", line 205, in check_consistent_length
    " samples: %r" % [int(l) for l in lengths])
ValueError: Found input variables with inconsistent numbers of samples: [4, 103]

你需要有新的数据,这是一个观察数组。现在,您拥有一系列功能。只需将其转置即可修复:

import numpy as np
new_data = np.transpose(new_data)
103
103
103
103
103
---------------------------
import numpy as np
new_data = np.transpose(new_data)