NDVI时间序列的线性趋势
我想提取我的NDVI时间序列的线性趋势。当我在Python中使用这段代码进行线性回归时:
from sklearn.linear_model import LinearRegression
import pandas as pd
data_orig = pd.read_csv('NDVI.csv')
N_values = data_orig['N'].values.reshape(-1, 1)
NDVI_values = data_orig['NDVI'].values
model = LinearRegression()
model.fit(N_values, NDVI_values)
slope = model.coef_[0]
intercept = model.intercept_
print("Linear trend equation: NDVI = {:.4f} * N + {:.4f}".format(slope, intercept))
这段代码的输出是 线性趋势方程:NDVI = 0.0000 * N + 0.0485
。
我觉得这个方程不对,因为时间序列中的植被明显是随着时间在增加的。
我还尝试了LOESS方法,使用了这段代码:
import matplotlib.pyplot as plt
import pandas
from pandas.plotting import register_matplotlib_converters
data_orig = pandas.read_csv('NDVI.csv')
from statsmodels.tsa.seasonal import STL
res = STL(data_orig['NDVI'], period=46, trend_jump=460).fit()
从中我得到了一个明显且显著的上升趋势。不过,我想知道把 trend_jump
设置为460(这是我的时间序列值的数量)是否合适。
1 个回答
0
print("Linear trend equation: NDVI = {:.4f} * N + {:.4f}".format(slope, intercept))
这段代码在打印之前会把斜率四舍五入到小数点后四位。根据这个图,看起来在460步的过程中,斜率大约上升了0.015。
这意味着斜率大约是0.015 / 460 = 0.000032。四舍五入到小数点后四位,就是0.0000。
所以,我觉得线性回归可能确实在检测斜率——但经过四舍五入后,这个斜率变成了零。
我认为这样做可能有效:
print("Linear trend equation: NDVI = {:.8f} * N + {:.4f}".format(slope, intercept))