如何避免收集错误 Python Numpy

How to avoid Collection Error Python Numpy

我正在尝试训练一个线性回归限定符来继续一个 grap。 我的 csv 文件中有几千行数据,我将它们导入到 numpy 数组中。这是我的代码:

import pandas as pd 
import numpy as np 
from matplotlib import pyplot as plt 
import csv
import math
from sklearn import preprocessing, svm
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression

def predict():
    sample_data = pd.read_csv("includes\csv.csv")
    x = np.array(sample_data["day"])
    y = np.array(sample_data["balance"])

    for x in x:
        x = x.reshape(1, -1)
        #lol

    for y in y:
        y.reshape(1, -1)
        #lol

    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)

当我运行这个的时候,错误是:

TypeError: Singleton array 6014651 cannot be considered a valid collection.

知道为什么会这样吗?

经过评论讨论:

import pandas as pd 
import numpy as np 
from matplotlib import pyplot as plt 
import csv
import math
from sklearn import preprocessing, svm
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression

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)

    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)

X_train,X_test要大写,python变量区分大小写