【问题标题】:Upsample timeseries with weather data in a correct way以正确的方式使用天气数据对时间序列进行上采样
【发布时间】:2021-10-27 23:59:05
【问题描述】:

我有一个数据集,其中包含从每月 1 日到 20 日的每个月的天气数据,以及一天中的每个小时抛出一年和每个月的最后 10 天(包括小时)。

天气数据为: (温度 - 湿度 - 风速 - 能见度 - 露水温度 - 太阳能辐射 - 降雨 - 降雪)

我想将数据集上采样为时间序列,以填补当天缺失的数据,但由于气候变化,我也面临许多问题。

这是目前为止尝试过的内容

def get_hour_month_mean(data,date,hour,max_id):
    return { 'ID':max_id,
            
            'temperature':data['temperature'].mean(),
                'humidity':data['humidity'].mean(),
                'date':date,
                'hour':hour,
                'wind_speed':data['wind_speed'].mean(),
                'visibility':data['visibility'].mean(),
                'dew_temperature':data['dew_temperature'].mean(),
                'solar_radiation':data['solar_radiation'].mean(),
                'rainfall':data['rainfall'].mean(),
                'count':data['count'].mean() if str(date.date()) not in seoul_not_func else 0,
                'snowfall':data['snowfall'].mean(),
                'season':data['season'].mode()[0],
                'is_holiday':'No Holiday' if str(date.date()) not in seoul_p_holidays_17_18 else 'Holiday' ,
                'functional_day':'Yes' if str(date.date()) not in seoul_not_func else 'No' ,
            }

def upsample_data_with_missing_dates(data):
    data_range = pd.date_range(
    start="2017-12-20", end="2018-11-30", freq='D')
    missing_range=data_range.difference(df['date'])
    hour_range=range(0,24)
    max_id=data['ID'].max()
    data_copy=data.copy()
    for date in missing_range:
        for hour in hour_range:
            max_id+=1
            year=data_copy.year
            month=date.month
            if date.month==11:
                year-=1
                month=12
            else:
                month+=1
            month_mask=((data_copy['year'] == year) &
                        (data_copy['month'] == month) &
                        (data_copy['hour'] == hour) &(data_copy['day'].isin([1,2])))
            data_filter=data_copy[month_mask]
            dict_row=get_hour_month_mean(data_filter,date,hour,max_id)
            data = data.append(dict_row, ignore_index=True)
    return data

如果我有前 20 天和后 20 天的数据,那么获取缺失天数的最佳方法是什么?

【问题讨论】:

    标签: python pandas machine-learning time-series data-science


    【解决方案1】:

    其实处理缺失时间序列值的方式有很多。

    您已经尝试过传统方法,即用平均值估算数据。但是这种方法的缺点是数据上的值太多造成的偏差。

    您可以尝试使用遗传算法 (GA)、支持向量机 (SVR)、自回归 (AR) 和移动平均 (MA) 来进行时间序列插补和建模。为了克服传统方法(均值)带来的偏差问题,这些方法用于预测或/和估算时间序列。

    (假设您有一个多元时间序列)

    这里有一些你可以使用的资源:

    A Survey on Deep Learning Approaches

    time.series.missing-values-in-time-series-in-python

    Interpolation in Python to fill Missing Values

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-28
      • 1970-01-01
      • 2017-11-18
      • 2021-01-19
      • 2019-01-26
      • 2014-12-15
      • 2019-03-02
      • 1970-01-01
      相关资源
      最近更新 更多