Giter VIP home page Giter VIP logo

Comments (4)

awei-lwj avatar awei-lwj commented on June 1, 2024

可能时间有点久了,这里提供一下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:
3 B9

原因以及Debug的方法
https://discuss.pytorch.org/t/creating-tensor-typeerror-cant-convert-np-ndarray-of-type-numpy-object/125741

3 C0

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

from dive-into-dl-pytorch.

Mr47121836 avatar Mr47121836 commented on June 1, 2024

from dive-into-dl-pytorch.

awei-lwj avatar awei-lwj commented on June 1, 2024

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)

from dive-into-dl-pytorch.

Mr47121836 avatar Mr47121836 commented on June 1, 2024

谢谢

from dive-into-dl-pytorch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.