Main Content

이 번역 페이지는 최신 내용을 담고 있지 않습니다. 최신 내용을 영문으로 보려면 여기를 클릭하십시오.

곡선 피팅 값 구하기

이 예제에서는 곡선 피팅을 다루는 방법을 보여줍니다.

데이터를 불러와서 다항식 곡선 피팅하기

load census
curvefit = fit(cdate,pop,'poly3','normalize','on')
curvefit = 
     Linear model Poly3:
     curvefit(x) = p1*x^3 + p2*x^2 + p3*x + p4
       where x is normalized by mean 1890 and std 62.05
     Coefficients (with 95% confidence bounds):
       p1 =       0.921  (-0.9743, 2.816)
       p2 =       25.18  (23.57, 26.79)
       p3 =       73.86  (70.33, 77.39)
       p4 =       61.74  (59.69, 63.8)

출력에는 피팅된 모델 방정식, 피팅된 계수, 피팅된 계수에 대한 신뢰한계가 표시됩니다.

피팅, 데이터, 잔차, 예측한계 플로팅하기

plot(curvefit,cdate,pop)

Figure contains an axes object. The axes object with xlabel x, ylabel y contains 2 objects of type line. One or more of the lines displays its values using only markers These objects represent data, fitted curve.

잔차 피팅을 플로팅합니다.

plot(curvefit,cdate,pop,'Residuals')

Figure contains an axes object. The axes object with xlabel x contains 2 objects of type line. One or more of the lines displays its values using only markers These objects represent data, zero line.

피팅에 대한 예측한계를 플로팅합니다.

plot(curvefit,cdate,pop,'predfunc')

Figure contains an axes object. The axes object with xlabel x, ylabel y contains 4 objects of type line. One or more of the lines displays its values using only markers These objects represent data, fitted curve, prediction bounds.

지정된 점에서 피팅 값 구하기

y = fittedmodel(x) 형식으로 x 에 대한 값을 지정하여 특정 점에서 피팅 값을 구합니다.

curvefit(1991)
ans = 252.6690

여러 점에서 피팅 값 구하기

값으로 구성된 벡터에서 모델을 실행하여 2050년까지 외삽합니다.

xi = (2000:10:2050).';
curvefit(xi)
ans = 6×1

  276.9632
  305.4420
  335.5066
  367.1802
  400.4859
  435.4468

해당 값에 대한 예측한계를 구합니다.

ci = predint(curvefit,xi)
ci = 6×2

  267.8589  286.0674
  294.3070  316.5770
  321.5924  349.4208
  349.7275  384.6329
  378.7255  422.2462
  408.5919  462.3017

외삽된 피팅 범위에 대해 피팅 및 예측 구간을 플로팅합니다. 피팅은 기본적으로 데이터 범위에 대해 플로팅됩니다. 피팅에서 외삽된 값을 보려면 피팅을 플로팅하기 전에 좌표축의 x 상한을 2050으로 설정하십시오. 예측 구간을 플로팅하려면 플롯 유형으로 predobs 또는 predfun을 사용하십시오.

plot(cdate,pop,'o')
xlim([1900,2050])
hold on
plot(curvefit,'predobs')
hold off

Figure contains an axes object. The axes object with xlabel x, ylabel y contains 4 objects of type line. One or more of the lines displays its values using only markers These objects represent fitted curve, prediction bounds.

모델 방정식 가져오기

피팅 이름을 입력하여 모델 방정식, 피팅된 계수, 피팅된 계수에 대한 신뢰한계를 표시합니다.

curvefit
curvefit = 
     Linear model Poly3:
     curvefit(x) = p1*x^3 + p2*x^2 + p3*x + p4
       where x is normalized by mean 1890 and std 62.05
     Coefficients (with 95% confidence bounds):
       p1 =       0.921  (-0.9743, 2.816)
       p2 =       25.18  (23.57, 26.79)
       p3 =       73.86  (70.33, 77.39)
       p4 =       61.74  (59.69, 63.8)

모델 방정식만 구하려면 formula를 사용하십시오.

formula(curvefit)
ans = 
'p1*x^3 + p2*x^2 + p3*x + p4'

계수 이름과 값 가져오기

계수를 이름으로 지정합니다.

p1 = curvefit.p1
p1 = 0.9210
p2 = curvefit.p2
p2 = 25.1834

모든 계수 이름을 가져옵니다. 피팅 방정식(예: f(x) = p1*x^3+...)을 살펴보며 각 계수에 대한 모델 항을 확인합니다.

coeffnames(curvefit)
ans = 4x1 cell
    {'p1'}
    {'p2'}
    {'p3'}
    {'p4'}

모든 계수 값을 가져옵니다.

coeffvalues(curvefit)
ans = 1×4

    0.9210   25.1834   73.8598   61.7444

계수에 대한 신뢰한계 가져오기

계수에 대한 신뢰한계를 사용하여 피팅을 계산하고 비교할 수 있습니다. 계수에 대한 신뢰한계는 계수의 정확도를 결정합니다. 서로 멀리 떨어진 한계는 불확실성을 나타냅니다. 선형 계수에 대해 한계가 영점을 교차하는 경우, 이는 해당 계수가 0과 다르다는 사실을 확신할 수 없음을 의미합니다. 일부 모델 항이 0인 계수를 가진다면 이는 피팅에 도움이 되지 않습니다.

confint(curvefit)
ans = 2×4

   -0.9743   23.5736   70.3308   59.6907
    2.8163   26.7931   77.3888   63.7981

적합도 통계량 검토하기

명령줄에서 적합도 통계량을 가져오기 위해 다음 중 하나를 수행할 수 있습니다.

  • 곡선 피팅기 앱을 엽니다. 곡선 피팅기 탭의 내보내기 섹션에서 내보내기를 클릭하고 작업 공간으로 내보내기를 선택하여 피팅과 피팅의 적합도를 작업 공간으로 내보냅니다.

  • fit 함수를 사용하여 gof 출력 인수를 지정합니다.

gof와 출력 인수를 지정하여 피팅을 다시 생성해 적합도 통계량과 피팅 알고리즘 정보를 가져옵니다.

[curvefit,gof,output] = fit(cdate,pop,'poly3','normalize','on')
curvefit = 
     Linear model Poly3:
     curvefit(x) = p1*x^3 + p2*x^2 + p3*x + p4
       where x is normalized by mean 1890 and std 62.05
     Coefficients (with 95% confidence bounds):
       p1 =       0.921  (-0.9743, 2.816)
       p2 =       25.18  (23.57, 26.79)
       p3 =       73.86  (70.33, 77.39)
       p4 =       61.74  (59.69, 63.8)
gof = struct with fields:
           sse: 149.7687
       rsquare: 0.9988
           dfe: 17
    adjrsquare: 0.9986
          rmse: 2.9682

output = struct with fields:
        numobs: 21
      numparam: 4
     residuals: [21x1 double]
      Jacobian: [21x4 double]
      exitflag: 1
     algorithm: 'QR factorization and solve'
    iterations: 1

잔차의 히스토그램을 플로팅하여 대략적으로 정규분포를 따르는지 확인합니다.

histogram(output.residuals,10)

Figure contains an axes object. The axes object contains an object of type histogram.

피팅, 데이터 및 잔차 플로팅하기

plot(curvefit,cdate,pop,'fit','residuals')
legend Location SouthWest
subplot(2,1,1)
legend Location NorthWest

Figure contains 2 axes objects. Axes object 1 with xlabel x, ylabel y contains 2 objects of type line. One or more of the lines displays its values using only markers These objects represent data, fitted curve. Axes object 2 with xlabel x contains 2 objects of type line. One or more of the lines displays its values using only markers These objects represent data, zero line.

방법 찾기

피팅에서 사용할 수 있는 모든 방법을 나열합니다.

methods(curvefit)
Methods for class cfit:

argnames       category       cfit           coeffnames     coeffvalues    confint        dependnames    differentiate  feval          fitoptions     formula        indepnames     integrate      islinear       numargs        numcoeffs      plot           predint        probnames      probvalues     setoptions     type           

피팅 방법 사용에 대한 자세한 내용은 cfit 항목을 참조하십시오.

참고 항목

| | |