Y
考虑关于的线性回归X
,其中(xi, yi) = (2, 7), (0, 2), (5, 14) for i = 1, 2, 3
。解决方案是(a, b) = (2.395, 2.079)
,使用手持计算器上的回归函数获得。
我想使用该pykalman
模块计算线性拟合的斜率和截距。我越来越
ValueError: The shape of all parameters is not consistent. Please re-check their values.
如果有人能帮助我,我将不胜感激。
这是我的代码:
from pykalman import KalmanFilter
import numpy as np
measurements = np.asarray([[7], [2], [14]])
initial_state_matrix = [[1], [1]]
transition_matrix = [[1, 0], [0, 1]]
observation_covariance_matrix = [[1, 0],[0, 1]]
observation_matrix = [[2, 1], [0, 1], [5, 1]]
kf1 = KalmanFilter(n_dim_state=2, n_dim_obs=6,
transition_matrices=transition_matrix,
observation_matrices=observation_matrix,
initial_state_mean=initial_state_matrix,
observation_covariance=observation_covariance_matrix)
kf1 = kf1.em(measurements, n_iter=0)
(smoothed_state_means, smoothed_state_covariances) = kf1.smooth(measurements)
print smoothed_state_means