Я пытаюсь использовать машинное обучение / нейронную сеть для изучения акций. Код моего файла regressionModel выглядит следующим образом:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.model_selection import cross_val_score
from sklearn.preprocessing import MinMaxScaler
from sklearn import datasets
from sklearn.neural_network import MLPClassifier
digits = datasets.load_digits()
numhrs = 12
def init(data) :
inx, iny = [data['EMAs'][0], data['SMAs'][0]], data['endPeriodPrices']
#X, Y = data['EMAs'][0], data['endPeriodPrices']
del iny[0:numhrs]
while len(inx) > len(iny) : inx.pop()
while len(inx[0]) > len(iny) : inx[0].pop()
while len(inx[1]) > len(iny) : inx[1].pop()
newX = []
for item in range(len(inx[0])) :
newX.append([inx[0][item], inx[1][item]])
X_tr, X_t, Y_tr, Y_t = train_test_split(newX, iny, test_size=0.3, random_state=0)
X_tr.astype(int)
scaling = MinMaxScaler(feature_range=(-1,1)).fit(X_tr)
X_tr = scaling.transform(X_tr)
X_t = scaling.transform(X_t)
nn = MLPClassifier(hidden_layer_sizes=(512, ), activation = 'relu', solver = 'adam', shuffle = True, tol=1e-4, random_state=1)
cv = cross_val_score(nn, X_tr, Y_tr, cv=10)
test_score = nn.fit(X_tr, Y_tr).score(X_t, Y_t)
print('CV accuracy score: %0.3f' % np.mean(cv))
print('Test accuracy score: %0.3f' % (test_score))
Я получаю следующую ошибку:
warnings.warn("Estimator fit failed. The score on this train-test"
Traceback (most recent call last):
File "mainprogram.py", line 41, in <module>
regressionModel.init(cryptoChoices[desiredCoin])
File "C:\Users\Julian\Documents\CryptoTradeTool\regressionModel.py", line 33, in init
test_score = nn.fit(X_tr, Y_tr).score(X_t, Y_t)
File "C:\Users\Julian\Documents\CryptoTradeTool\.venv\lib\site-packages\sklearn\neural_network\_multilayer_perceptron.py", line 1027, in fit
return self._fit(X, y, incremental=(self.warm_start and
File "C:\Users\Julian\Documents\CryptoTradeTool\.venv\lib\site-packages\sklearn\neural_network\_multilayer_perceptron.py", line 326, in _fit
X, y = self._validate_input(X, y, incremental)
File "C:\Users\Julian\Documents\CryptoTradeTool\.venv\lib\site-packages\sklearn\neural_network\_multilayer_perceptron.py", line 971, in _validate_input
self._label_binarizer.fit(y)
File "C:\Users\Julian\Documents\CryptoTradeTool\.venv\lib\site-packages\sklearn\preprocessing\_label.py", line 437, in fit
self.classes_ = unique_labels(y)
File "C:\Users\Julian\Documents\CryptoTradeTool\.venv\lib\site-packages\sklearn\utils\multiclass.py", line 97, in unique_labels
raise ValueError("Unknown label type: %s" % repr(ys))
ValueError: Unknown label type: (array([9882.37166161, 9233.91408649, 9155.17422894, ..., 9775.32490259,
9437.21027712, 9108.97314461]),)
Не уверен, что я здесь делаю неправильно. Массивы значений X представляют собой списки переменных с плавающей запятой, как и массив значений Y.