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

23 views
Skip to first unread message

정재민

unread,
Jan 11, 2023, 3:45:06 AM1/11/23
to 머신러닝/딥러닝 도서 Q&A
3장 다중회귀 164페이지

train_score = []
test_score = []
alpha_list = [0.001, 0.01, 0.1, 1, 10, 100]
for alpha in alpha_list:
  lasso = Lasso(alpha=alpha, max_iter=10000)
  lasso.fit(train_scaled, train_target)
  train_score.append(lasso.score(train_scaled, train_target))
  train_score.append(lasso.score(test_scaled, test_target))

plt.plot(np.log10(alpha_list), train_score)
plt.plot(np.log10(alpha_list), test_score)
plt.xlabel('alpha')
plt.ylabel('R^2')
plt.show()

코드를 실행하였는데, 빨간색 부분에서
/usr/local/lib/python3.8/dist-packages/matplotlib/axes/_base.py in _plot_args(self, tup, kwargs) 340 341 if x.shape[0] != y.shape[0]: --> 342 raise ValueError(f"x and y must have same first dimension, but " 343 f"have shapes {x.shape} and {y.shape}") 344 if x.ndim > 2 or y.ndim > 2: ValueError: x and y must have same first dimension, but have shapes (6,) and (12,)

이라는 오류 메세지가 뜹니다. train_score 가 12개라는데 이유를 모르겠어요.

Haesun Park

unread,
Jan 13, 2023, 6:48:19 PM1/13/23
to 정재민, 머신러닝/딥러닝 도서 Q&A
안녕하세요. 박해선입니다.
저도 무슨 이유인지 알기 어렵네요.
코랩에서 노트북을 실행해 보시고 작성하신 코드와 비교해 보시면 좋을 것 같습니다.
감사합니다!

2023년 1월 11일 (수) 오후 5:45, 정재민 <zcd...@gmail.com>님이 작성:
--
이 메일은 Google 그룹스 '머신러닝/딥러닝 도서 Q&A' 그룹에 가입한 분들에게 전송되는 메시지입니다.
이 그룹에서 탈퇴하고 더 이상 이메일을 받지 않으려면 ml-dl-book-qn...@googlegroups.com에 이메일을 보내세요.
웹에서 이 토론을 보려면 https://groups.google.com/d/msgid/ml-dl-book-qna/6e955f3f-26cc-4d7f-8d86-4dbb6938f703n%40googlegroups.com을(를) 방문하세요.
Reply all
Reply to author
Forward
0 new messages