Saturday, 13 August 2022

Fix error ''Expected 2D array, got 1D array instead'' on a scaler

I am testing an .ipynb file with code to perform data augmentation using autoencoders. You can find the file in the following link: Autoencoder Data Augmentation Example

Dataset used: wine.csv

The first error I encountered was a variable that did not exist and was renamed:

# D_in = data_set.x.shape[1]
D_in = traindata_set.x.shape[1]
H = 50
H2 = 12
model = Autoencoder(D_in, H, H2).to(device)
optimizer = optim.Adam(model.parameters(), lr=1e-3)

Later, I get another error derived from the following code:

scaler = trainloader.dataset.standardizer
recon_row = scaler.inverse_transform(recon_batch[0].cpu().numpy())
real_row = scaler.inverse_transform(testloader.dataset.x[0].cpu().numpy())

I get the following error that I can't solve:

ValueError: Expected 2D array, got 1D array instead:
array=[-1.1050762   0.59396696 -0.40257156  0.5084665  -0.3387986   0.5908352
  0.6442218   0.7660801  -0.36749032  0.2818777  -0.06692128  0.49236417
  0.7825899   0.8493577 ].
Reshape your data either using array.reshape(-1, 1) 
if your data has a single feature or array.reshape(1, -1) if it contains a single sample.

I hope you can help me to detect it.



from Fix error ''Expected 2D array, got 1D array instead'' on a scaler

No comments:

Post a Comment