如何在Python Numpy中使用train_test_split修复Value Error

时间:2019-05-31 14:27:36

标签: 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)

为什么会出现任何想法?

1 个答案:

答案 0 :(得分:1)

我有这个问题。检查库“ scikit-learn”。 sklearn与scikt-learn的0.20.0+版本有关,请尝试这样做:

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