RuntimeError: Can't call numpy() on Tensor that requires grad. Use
tensor.detach().numpy() instead.
이 텐서를 넘파이 배열로 변환하려면
detach
()
메서드를 호출해야 합니다. 이렇게 하면 그래
프를 벗어나게 되므로 자동으로 그레이디언트를 계산하지 못합니다. 이것이 매우 유용할 수 있
지만 텐서의
detach
()
메서드를 호출하면 자동으로 그레이디언트를 계산하지 못하게 된다는
점을 유념하세요.
참고
•파이토치 자동미분 튜토리얼(
https
://
oreil
.
ly
/
mOWSw
)
21.2
신경망을 위해 데이터 전처리하기
과제
신경망에 사용할 데이터를 전처리하고 싶습니다.
해결
사이킷런의
StandardScaler
를 사용해 특성을 표준화합니다.
# 라이브러리를임포트합니다.
fromsklearnimportpreprocessing
importnumpyasnp
# 특성을만듭니다.
features=np.array([[-100.1,3240.1],
[-200.2,-234.1],
[5000.5,150.1],
[6000.6,-125.1],
[9000.9,-673.1]])
# 스케일링객체를만듭니다.
scaler=preprocessing ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.
O’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
I wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
I’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
I'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.