python/머신러닝A.I
x and y can be no greater than 2-D, but have shapes (2,) and (2, 1, 1)
맑은안개
2021. 3. 2. 15:18
plt.scatter(train_input, train_target)
plt.plot([15, 50], [15*lr.coef_+lr.intercept_, 50*lr.coef_+lr.intercept_])
plt.scatter(50, 1241.8, marker='^')
plt.xlabel('length')
plt.ylabel('weight')
plt.show()
위 구문에서 다음과 같은 오류 발생
~\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\axes\_base.py in _plot_args(self, tup, kwargs)
343 f"have shapes {x.shape} and {y.shape}")
344 if x.ndim > 2 or y.ndim > 2:
--> 345 raise ValueError(f"x and y can be no greater than 2-D, but have "
346 f"shapes {x.shape} and {y.shape}")
347 if x.ndim == 1:
ValueError: x and y can be no greater than 2-D, but have shapes (2,) and (2, 1, 1)
회귀선이 그려지는 로직을 다음과 같이 수정한다.
# Before
plt.plot([15, 50], [15*lr.coef_+lr.intercept_, 50*lr.coef_+lr.intercept_])
# After
plt.plot([15, 50], [float(15*lr.coef_+lr.intercept_), float(50*lr.coef_+lr.intercept_)], 'r-')
반응형