Notice
Recent Posts
Recent Comments
Link
JY Tech
y must have at least two dimensions for multi-output regression but has only one. 오류 본문
Programming/Error Solution
y must have at least two dimensions for multi-output regression but has only one. 오류
J.Dragon 2023. 2. 16. 17:34LG Aimers 2기 Phase2 과제 진행 중 기본모델인 Randomforest를 xgboost로 바꾸려고 했다.
xgb = MultiOutputRegressor(xgb.XGBRegressor(파라미터 입력) ).fit(train_x, train_y)
위와 같이 모델을 설정하고 피팅을 했는데..
아래와 같이
y must have at least two dimensions for multi-output regression but has only one.
이런 오류가 발생한다..

해결방법은 의외로 간단하다
y는 최소 2차원이어야 하는데 1차원인 데이터를 가지고 실행해서 발생한 오류이다
y.reshape(-1, 1)
을 추가하여 차원을 늘려주면 해결된다
참고로 pandas series는 reshape를 지원하지 않아 values를 추가로 사용해야 한다
y = y.values.reshape(-1, 1)
과 같이 reshape 해주면 된다
여담이지만 나 같은 경우는Classification으로 학습시켜야 하는 것을 Regression으로 시키다 보니 위의 오류 해결 후에도 결과값이 이상하게 나와서 reshape한 부분을 지우고 xgb중 classification으로 바꿔서 해결했다...
classification과 regression의 차이는 다음시간에 알아보자
결론: 인공지능 학습 중 차원오류 발생 시 reshape를 사용하여 차원을 늘려주자
'Programming > Error Solution' 카테고리의 다른 글
[파이썬] raise KeyError(key) from err (1) | 2023.11.27 |
---|---|
[파이썬]xlrd.biffh.XLRDError(xlrd오류) (1) | 2023.11.10 |
[C#/윈폼]"도구상자 항목 '###'을(를) 로드하지 못했습니다. 해당 항목은 도구상자에서 제거됩니다. (0) | 2023.04.30 |
[파이썬,sqlite] incorrect number of bindings supplied. the current statement uses 1 and there are 3 supplied (0) | 2023.04.21 |
파이썬 TypeError: can only concatenate str (not "list") to str (0) | 2023.04.04 |