• 1000
Потеря сети:
def LosScore2(x_pred, x_test):
mse = []
for i in range(len(x_test)):
mse.append(mean_squared_error(pd.DataFrame(x_pred[i]), pd.DataFrame(x_test[i])))
return mse
Генерация поддельных данных:
#Generate sample data, the shape of expected input
# X: ND-Array containing fixed-length segments of shape (1,100,4)
X = np.random.randn(2000, 1, 100, 4)
a,b,c = np.repeat(0, 700), np.repeat(1, 700), np.repeat(2, 600)
y = np.hstack((a,b,c))
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_state=7)
LABELS= list(set(np.ndarray.flatten(y_train)))
Обучить сеть:
models = []
for i in range(len(LABELS)):
print(LABELS[i])
sub_train = x_train[y_train == i]
sub_test = x_test[y_test == i]
autoencoder = SingleEncoder(sub_train, sub_test)
autoencoder = autoencoder.buildModel()
models.append(autoencoder)
Этот MWE
работает отлично, но когда Я пытаюсь оценить тестовый набор. Я обнаружил ошибку из-за формы ввода, как показано ниже:
print("Evaluating on test set -> ")
x_pred = []
# for each model
# predition
for e in range(len(models)):
x_pred.append(models[e].predict(x_test))
scored0 = (LosScore2(x_pred[0], x_test))
scored1 = (LosScore2(x_pred[1], x_test))
scored2 = (LosScore2(x_pred[2], x_test))
Вот и ошибка:
Evaluating on test set ->
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-11-989c507cfd63> in <module>()
9 #scored0 = (LosScore2(x_pred[0][np.newaxis], x_test))
10
---> 11 scored0 = (LosScore2(x_pred[0], x_test))
12 scored1 = (LosScore2(x_pred[1], x_test))
13 scored2 = (LosScore2(x_pred[2], x_test))
3 frames
<ipython-input-9-356737ea1f97> in LosScore2(x_pred, x_test)
2 mse = []
3 for i in range(len(x_test)):
----> 4 mse.append(mean_squared_error(pd.DataFrame(x_pred[i]), pd.DataFrame(x_test[i])))
5 return mse
/usr/local/lib/python3.6/dist-packages/pandas/core/frame.py in __init__(self, data, index, columns, dtype, copy)
462 mgr = init_dict({data.name: data}, index, columns, dtype=dtype)
463 else:
--> 464 mgr = init_ndarray(data, index, columns, dtype=dtype, copy=copy)
465
466 # For data is list-like, or Iterable (will consume into list)
/usr/local/lib/python3.6/dist-packages/pandas/core/internals/construction.py in init_ndarray(values, index, columns, dtype, copy)
167 # by definition an array here
168 # the dtypes will be coerced to a single dtype
--> 169 values = prep_ndarray(values, copy=copy)
170
171 if dtype is not None:
/usr/local/lib/python3.6/dist-packages/pandas/core/internals/construction.py in prep_ndarray(values, copy)
293 values = values.reshape((values.shape[0], 1))
294 elif values.ndim != 2:
--> 295 raise ValueError("Must pass 2-d input")
296
297 return values
ValueError: Must pass 2-d input
Я понимаю, что это связано с тестом формы данных, но я не могу понять, как это исправить.