import numpy as np
import matplotlib.pyplot as plt
from matplotlib import style
from sklearn.linear_model import LinearRegression
from sklearn import preprocessing, cross_validation, svm
df = pd.read_csv('table.csv')
print (df.head())
df = df[['Price', 'Asset']]
x = np.array(df.Price)
y = np.array(df.Asset)
x_train, x_test, y_train, y_test = cross_validation.train_test_split(
x, y, test_size=0.2)
x_train = np.pad(x, [(0,0)], mode='constant')
x_train.reshape((23,1))
y_train = np.pad(y, [(0,0)], mode ='constant')
y_train.reshape((23,1))
np.reshape(-1, 1)
Fehler:Numpy umformen Ausgaben
runfile('C:/Users/HP/Documents/linear.py', wdir='C:/Users/HP/Documents')
Price Asset
0 87.585859 191
1 87.839996 232
2 87.309998 245
3 88.629997 445
4 88.379997 393
C:\Users\HP\Anaconda3\lib\site-packages\sklearn\utils\validation.py:386:
DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and willraise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.
DeprecationWarning)
Traceback (most recent call last):
File "<ipython-input-124-030ffa933525>", line 1, in <module>
runfile('C:/Users/HP/Documents/linear.py', wdir='C:/Users/HP/Documents')
File "C:\Users\HP\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 714, in runfile
execfile(filename, namespace)
File "C:\Users\HP\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 89, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/HP/Documents/linear.py", line 38, in <module>
clf.fit(x_train, y_train)
File "C:\Users\HP\Anaconda3\lib\site-packages\sklearn\linear_model\base.py", line 427, in fit
y_numeric=True, multi_output=True)
File "C:\Users\HP\Anaconda3\lib\site-packages\sklearn\utils\validation.py", line 520, in check_X_y
check_consistent_length(X, y)
File "C:\Users\HP\Anaconda3\lib\site-packages\sklearn\utils\validation.py", line 176, in check_consistent_length
"%s" % str(uniques))
ValueError: Found arrays with inconsistent numbers of samples: [ 1 23]
Meine Datenrahmen Größe: 23, 2.
ich meine x_train geklotzt und y_train auf [23,1], weil ich diesen ersten Fehler bekam Valueerror: Gefundene Arrays mit inkonsistenter Anzahl von Proben: [1 18]. Meine Fehlermeldung nach Auffüllen: ValueError: Gefundene Arrays mit inkonsistenter Anzahl von Samples: [1 23].
Dann habe ich versucht, es neu zu gestalten und immer noch die Fehlermeldung: ValueError: Gefundene Arrays mit inkonsistenten Anzahl von Proben: [1 23].
Wie behebe ich das?
Was möchten Sie umgestalten? 'np.reshape' weiß nicht, was Sie neu gestalten wollen. Benutze es wie 'array.reshape ((x, y))' '. – Ian
Wie @mwormser sagt, müssen Sie 'reshape' für ein Array-Objekt aufrufen, wie' x_train' und 'y_train' in Ihrem Fall; 'x_train.reshape ((23,1))' – Dartmouth
Versucht, dass immer noch die Fehlermeldung: ValueError: Gefunden Arrays mit inkonsistenten Zahlen von Proben: [1 23] – Bolajio