datenum给不同的值相同的日期时间?

时间:2018-08-06 14:28:13

标签: matlab

当我将给定的日期数字“ 2011-01-06 0:45”转换为

def evaluate_arima_model(X, arima_order, s_arima_order):
    scores = []
    train_steps = [36, 48, 60, 72, 84]
    for i in train_steps:
        Train = X[0:i]
        Test = X[i:i + 12]
        model = SARIMAX(Train, order=arima_order, seasonal_order=s_arima_order)
        model_fit = model.fit(trend='nc', disp=0)
        yhat = model_fit.forecast(12)
        rmse = sqrt(mean_squared_error(numpy.exp(Test), numpy.exp(yhat)))
        scores.append(rmse)
    print(scores)
    return scores

我明白了

def evaluate_models(dataset, p_values, d_values, q_values, sp_values, sd_values, sq_values, s_values):
dataset = dataset.astype('float32')
best_score, best_cfg, best_cfg2 = float("inf"), None, None 
for p in p_values:
    for d in d_values:
        for q in q_values:
            order = (p,d,q)
            for sp in sp_values:
                for sd in sd_values:
                    for sq in sq_values:
                        for s in s_values:
                            sorder = (sp,sd,sq,s)
                            try:
                                rmse = evaluate_arima_model(dataset, order, sorder)
                                if rmse < best_score:
                                    best_score, best_cfg, best_cfg2 = rmse, order, sorder
                                print('ARIMA%s SARIMA%s RMSE=%.3f' % (order,sorder,rmse))
                            except:
                                continue
print('\n','Best ARIMA%s SARIMA%s RMSE=%.3f' % (best_cfg, best_cfg2, best_score))


series = read_csv('dataset.csv', header=None, index_col=0, parse_dates=True, squeeze=True)
series = numpy.log(series)

# Evaluate parameters
p_values = range(0, 2)
d_values = range(0, 2)
q_values = range(0, 2)

# Evaluate seasonal parameters
sp_values = range(0, 2)
sd_values = range(0, 2)
sq_values = range(0, 2)

#Set seasonality
s_values = [12]

#Call grid loop
evaluate_models(series, p_values, d_values, q_values, sp_values, sd_values, sq_values, s_values)

作为日期编号。

但是当我使用

生成日期数字向量时
def evaluate_arima_model(X, arima_order, s_arima_order):
scores = []
train_steps = [36, 48, 60, 72, 84]
for i in train_steps:
    Train = X[0:i]
    Test = X[i:i + 12]
    model = SARIMAX(Train, order=arima_order, seasonal_order=s_arima_order)
    model_fit = model.fit(trend='nc', disp=0)
    yhat = model_fit.forecast(12)
    rmse = None
    rmse = sqrt(mean_squared_error(numpy.exp(Test), numpy.exp(yhat)))
    scores.append(rmse)
    print(scores)
print(scores)
return scores

向量'full_data_time_steps'中的第四个日期数字是

datenum('2011-01-06 0:45','yyyy-mm-dd HH:MM')

但是它对应于相同的日期时间“ 2011-01-06 0:45”。我不确定为什么会这样以及如何解决呢?任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:2)

确定要正确查看它们吗?当我这样做

format long g % to make sure we see all the decimals 

datenum('2011-01-06 0:45','yyyy-mm-dd HH:MM')

ans =

              734509.03125

begin_date_time=datenum('2011-01-06 00:00:00','yyyy-mm-dd HH:MM:SS');
str_next_date=strcat('2011-01-06',32,'00:15:00');
next_date_time=datenum(str_next_date,'yyyy-mm-dd HH:MM:SS');
interval=next_date_time-begin_date_time;
end_date_time=datenum('2011-12-31 00:00:00','yyyy-mm-dd HH:MM:SS');
full_data_time_steps=begin_date_time:interval:end_date_time;
full_data_time_steps(4)

ans =

              734509.03125

我也一样。