Как избежать ошибки коллекции Python Numpy - PullRequest
0 голосов
/ 31 мая 2019

Я пытаюсь обучить классификатору линейной регрессии, чтобы продолжить захват.У меня есть несколько тысяч строк данных в моем CSV-файле, которые я импортирую в массивы.Вот мой код:

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.

Есть идеи, почему это так?

Ответы [ 2 ]

0 голосов
/ 31 мая 2019

X_train, X_test должен быть прописным, переменные python чувствительны к регистру

0 голосов
/ 31 мая 2019

После обсуждения в комментариях:

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)
...