Closed Mr47121836 closed 1 year ago
可能时间有点久了,这里提供一下bug的修复方法 Debug:
这里书上的代码:
n_train = train_data.shape[0]
train_features = torch.tensor(all_features[:n_train].values, dtype=torch.float)
test_features = torch.tensor(all_features[n_train:].values, dtype=torch.float)
train_labels = torch.tensor(train_data.SalePrice.values, dtype=torch.float).view(-1, 1)
会出现bug:
原因以及Debug的方法 https://discuss.pytorch.org/t/creating-tensor-typeerror-cant-convert-np-ndarray-of-type-numpy-object/125741
You won’t be able to directly convert it as the object type contains arbitrary or mixed data. Transform your numpy object to an array first and call torch.from_numpy afterwards.
也就是改成像我这样,先变成numpyarray然后强制类型转化,然后在直接转为tensor
train_features = np.array(all_features[:n_train]).astype(np.float64)
train_features = torch.from_numpy(train_features)
test_features = np.array(all_features[n_train:].values).astype(np.float64)
test_feature
这是来自QQ邮箱的假期自动回复邮件。你好,我最近正在休假中,无法亲自回复你的邮件。我将在假期结束后,尽快给你回复。
train_features = np.array(all_features[:n_train]).astype(np.float64) train_features = torch.from_numpy(train_features)
test_features = np.array(all_features[n_train:].values).astype(np.float64) test_features = torch.from_numpy(test_features)
谢谢
bug描述![image](https://user-images.githubusercontent.com/66686828/234868676-6c91af76-9e9d-4d93-bcb2-8b22a5b0d32e.png)
版本信息 pytorch:1.8.0+cu111 torchvision:0.9.1+cu101 torchtext:0.9.0 ...