Nov-26-2018, 08:00 AM
Hi
import pandas as pd
import quandl, math
import numpy as np
import sys
from sklearn import preprocessing, model_selection, svm # model_selection replaces cross_validation
from sklearn.linear_model import LinearRegression
sys.path.insert(0, 'C:\Program Files\Scripts')
df = quandl.get('FINRA/FORF_TLLTD')
df['PCT']= df['ShortVolume']/df['TotalVolume']*100
df = df[['ShortVolume','TotalVolume', 'PCT']]
forecast_col = 'ShortVolume'
df.fillna(-99999, inplace= True)
forecast_out = int(math.ceil(0.01*len(df)))
df['label'] = df[forecast_col].shift(-forecast_out)
df.dropna(inplace=True)
X = np.array(df.drop(['label'], 1))
y = np.array(df['label'])
X= preprocessing.scale(X)
X= X[:-forecast_out+1]
y = np.array(df['label'])
X_train,X_test,y_train,y_test= model_selection.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)Error:Traceback (most recent call last):
File "C:/Program Files/PycharmProjects/code examples/code practice.py", line 39, in <module>
X_train,X_test,y_train,y_test= model_selection.train_test_split(X, y, test_size=0.2)
File "C:\Users\Ayaz\AppData\Roaming\Python\Python37\site-packages\sklearn\model_selection\_split.py", line 2184, in train_test_split
arrays = indexable(*arrays)
File "C:\Users\Ayaz\AppData\Roaming\Python\Python37\site-packages\sklearn\utils\validation.py", line 260, in indexable
check_consistent_length(*result)
File "C:\Users\Ayaz\AppData\Roaming\Python\Python37\site-packages\sklearn\utils\validation.py", line 235, in check_consistent_length
" samples: %r" % [int(l) for l in lengths])
ValueError: Found input variables with inconsistent numbers of samples: [0, 3]
