python - 如何在 Python Numpy 中使用 train_test_split 修复值错误

标签 python pandas numpy sklearn-pandas

我正在将 sklearn 与 numpy 数组一起使用。 我有 2 个数组 (x, y),它们应该是:

test_size=0.2
train_size=0.8

这是我当前的代码:

def predict():

    sample_data = pd.read_csv("includes\\csv.csv")

    x = np.array(sample_data["day"])
    y = np.array(sample_data["balance"])


    x = x.reshape(1, -1)



    y = y.reshape(1, -1)




    print(x)
    print(y)



    X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.2)



    clf = LinearRegression()
    clf.fit(x_train, y_train)

    clf.score(x_test, y_test)

错误是:

ValueError: With n_samples=1, test_size=0.2 and train_size=None, the resulting train set will be empty. Adjust any of the aforementioned parameters.

,它出现在行中:

X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.2)

有什么想法为什么会出现吗?

最佳答案

我也遇到过这个问题。检查库“scikit-learn”。 sklearn在0.20.0+版本的scikt-learn上有问题,尝试这样做:

Windows:pip uninstall scikit-learn
Linux:sudo python36 -m pip uninstall scikit-learn

并安装:

Windows:pip install scikit-learn==0.19.1
Linux:sudo python36 -m pip install scikit-learn==0.19.1

关于python - 如何在 Python Numpy 中使用 train_test_split 修复值错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56396950/

相关文章:

numpy - 步幅如何帮助遍历 numpy 中的数组?

python - 如何拆分 numpy 数组,保留之前拆分的一些元素?

Python:从列表创建数据框,其中每个新行都从特定的列表索引开始

python - 如何在 Ray 中使用 python 日志记录?

python - tensorflow-serving-apis - 找不到 python 文档

python - Pandas:如何根据列表从数据框中删除行?

python - 向列添加前导零

python - 如何在 python 中将可变长度列表打印为列?

python - 加载带有五十一的数据集时排除某些类

python - pandas 中的 SQL 风格条件连接