■ poly1d 클래스를 사용해 1차 방정식을 생성하는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import matplotlib.pyplot as pp import numpy as np xNDArray = np.arange(0, 10, 0.01) yNDArray = 3 * xNDArray + 5 yNoiseNDArray = yNDArray + np.random.randn(len(yNDArray)) sourcePolyfitNDArray = np.polyfit(xNDArray, yNoiseNDArray, 1) # 1차식 sourcePoly1d = np.poly1d(sourcePolyfitNDArray) # pp.figure(figsize = (12, 8)) pp.plot(xNDArray, yNoiseNDArray, label = "noise", color = "y") pp.plot(xNDArray, yNDArray, ls = "dashed", lw = 3, color = "b", label = "original") pp.plot(xNDArray, sourcePoly1d(xNDArray), lw = 2, color = "r", label = "polyfit") pp.show(); |