2017-09-09 6 views
0

私のコードを実行しようとすると、私は次のエラーとValueError:サンプルの一貫性のない数字で見つかり入力変数:[4、3255]、のpython3

ValueErrorを取得:サンプルの一貫性のない数字で見つかり入力変数:[4を、 3255]、Python3

私はそれが何らかのフォーマットエラーであることを理解していますが、解決方法はわかりません。

import pandas as pd 
import quandl, math 
import numpy as np 
from sklearn import preprocessing, svm, cross_validation 
from sklearn.linear_model import LinearRegression 

df = quandl.get('WIKI/GOOGL') 
df = df [['Adj. Open','Adj. High','Adj. Low','Adj. Close','Adj. Volume',]] 
df['HL_PCT'] = (df['Adj. High'] - df['Adj. Open'])/df['Adj. Open'] * 100 
df['PCT_change'] = (df['Adj. Close'] - df['Adj. Open'])/df['Adj. Open'] * 100 

df = df[['Adj. Close','HL_PCT','PCT_change','Adj. Volume']] 

forecast_col = 'Adj. Close' 
df.fillna(-99999, inplace=True) 

forecast_out = int(math.ceil(0.01*len(df))) 

df['label'] = df[forecast_col].shift(-forecast_out) 


x = np.array(df.drop(['label'],1)) 
x = preprocessing.scale(x) 
x = x[-forecast_out] 
x_lately = x[-forecast_out:] 


df.dropna(inplace=True) 
y = np.array(df['label']) 
y = np.array(df['label']) 



x_train, x_test, y_train, y_test = cross_validation.train_test_split(x, y, test_size=0.2) 

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

accuracy = clf.score(x_test, y_test) 

print(accuracy) 

トレースバック:

Traceback (most recent call last): 
    File "main.py", line 33, in <module> 
    x_train, x_test, y_train, y_test = cross_validation.train_test_split(x, y, test_size=0.2) 
    File "C:\Users\User\Python\lib\site-packages\sklearn\cross_validation.py", line 2059, in train_test_split 
    arrays = indexable(*arrays) 
    File "C:\Users\User\Python\lib\site-packages\sklearn\utils\validation.py", line 198, in indexable 
    check_consistent_length(*result) 
    File "C:\Users\User\Python\lib\site-packages\sklearn\utils\validation.py", line 173, in check_consistent_length 
    " samples: %r" % [int(l) for l in lengths]) 
ValueError: Found input variables with inconsistent numbers of samples: [4, 3255] 
+0

示しすることはできますか? – RedEyed

+0

私はこれにはかなり新しく、トレースバックを表示する方法を知らない – Oscar

+0

トレースバックは、このエラーメッセージが表示された場所からの出力です:ValueError:サンプルの数が一致しない入力変数が見つかりました:[4,3255] – RedEyed

答えて

0

私は問題を発見しました。これは、それが動作するためのコードをフォーマットする方法である:

X = np.array(df.drop([ 'ラベル']、1))

X = preprocessing.scale(X)

X_lately = X [-forecast_out:]

X = X [: - forecast_out:]あなたはトレースバックを

関連する問題