Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

หาค่าประมาณเชิงพยากรณ์น้อยที่สุด (Least squares fit) ของอนุกรมเฮอร์ไมท์กับข้อมูลใน Python

เมธอด hermite.hermfit() หา係ณอนุกรมเฮอร์ไมท์ที่เหมาะสมที่สุดกับข้อมูลตัวอย่าง (x, y) โดยวิธี Least squares

พารามิเตอร์สำคัญ:

  • x, y: พิกัดข้อมูลตัวอย่าง
  • deg: ดีกรีของพหุนามที่ปรับให้เหมาะสม
  • rcond: เงื่อนไขสัมพัทธ์ของการปรับ
  • full: หาก True จะคืนค่าข้อมูลวินิจฉัยเพิ่มเติม
  • w: น้ำหนักของแต่ละจุดข้อมูล

ขั้นตอน

import numpy as np
from numpy.polynomial import hermite as H

x = np.linspace(-1, 1, 51)
y = x**3 - x + np.random.randn(len(x))
c, stats = H.hermfit(x, y, 3, full=True)
print("X Co-ordinate...\n", x)
print("\nY Co-ordinate...\n", y)
print("\nResult...\n", c)
print("\nResult...\n", stats)

ตัวอย่างโค้ดสมบูรณ์

import numpy as np
from numpy.polynomial import hermite as H

x = np.linspace(-1, 1, 51)
y = x**3 - x + np.random.randn(len(x))
c, stats = H.hermfit(x, y, 3, full=True)
print("X Co-ordinate...\n", x)
print("\nY Co-ordinate...\n", y)
print("\nResult...\n", c)
print("\nResult...\n", stats)

ผลลัพธ์

ผลลัพธ์จะเปลี่ยนแปลงไปตามข้อมูลสุ่ม (ดูรายละเอียดในโค้ดต้นฉบับ)