[혼자 공부하는 머신러닝+딥러닝]

12 views
Skip to first unread message

김동국

unread,
Jan 9, 2023, 12:53:56 AM1/9/23
to 머신러닝/딥러닝 도서 Q&A
5장 트리 알고리즘 223페이지

----------------
import pandas as pd

from sklearn.model_selection import train_test_split

wine = pd.read_csv('https://bit.ly/wine-date')

#wine.describe()

data = wine[['alcohol', 'sugar', 'pH']].to_numpy()
target = wine['class'].to_numpy

train_input, test_input, train_target, test_target = train_test_split(data, target, test_size=0.2, random_state=42)

print(train_input.shape, test_input.shape)
-------------------------------------------
위의 코드를 실행했는데 아래와 같은 오류 메세지가 나옵니다. 

---------------------------------------
TypeError Traceback (most recent call last) <ipython-input-13-12dce3f42a43> in <module> 10 target = wine['class'].to_numpy 11 ---> 12 train_input, test_input, train_target, test_target = train_test_split(data, target, test_size=0.2, random_state=42) 13 14 print(train_input.shape, test_input.shape)
4 frames
/usr/local/lib/python3.8/dist-packages/sklearn/utils/validation.py in _num_samples(x) 267 if hasattr(x, "shape") and x.shape is not None: 268 if len(x.shape) == 0: --> 269 raise TypeError( 270 "Singleton array %r cannot be considered a valid collection." % x 271 )
---------------------------------------
아무리 봐도 오류 원인을 알 수가 없어서 도움 부탁드립니다.

Haesun Park

unread,
Jan 9, 2023, 1:05:41 AM1/9/23
to 김동국, 머신러닝/딥러닝 도서 Q&A
안녕하세요. 박해선입니다.
어떤 문제 때문에 이런 오류가 발생하는지 제가 알기 어렵네요.
코랩에서 깃허브 코드를 실행하시고 작성하신 내용과 비교해 보시면 좋을 것 같습니다.
감사합니다!

2023년 1월 9일 (월) 오후 2:53, 김동국 <dgki...@gmail.com>님이 작성:
--
이 메일은 Google 그룹스 '머신러닝/딥러닝 도서 Q&A' 그룹에 가입한 분들에게 전송되는 메시지입니다.
이 그룹에서 탈퇴하고 더 이상 이메일을 받지 않으려면 ml-dl-book-qn...@googlegroups.com에 이메일을 보내세요.
웹에서 이 토론을 보려면 https://groups.google.com/d/msgid/ml-dl-book-qna/8ca506ae-ea92-4c41-9223-559c931fa59cn%40googlegroups.com을(를) 방문하세요.
Reply all
Reply to author
Forward
0 new messages