periodical data 在机器学习中的feature engineering

如果数据中出现显著的周期性,比如 月,日 (年倒是例外吧)或者 角度之类的
应该处理成循环的数据类型. (也不一定总work)

  • 利用 between_time 之类的function
  • 借助sin/cos 函数,变成wave 形状的函数
Result

丢弃date这个变量,RMSE 65.75
加入month, day 变量,RMSE 降到49.38
如果将month, day 变成周期性变量, convert_period RMSE 反而上升了 54.02

代码如下

def convert_period(time):
    return np.sin((time-min(time))/(max(time)-min(time)+1) * 2 * np.pi)

def dataIO(datafile):
    input_file = datafile

    # comma delimited is the default
    df = pd.read_csv(input_file, header = 0)

    # put the original column names in a python list
    original_headers = list(df.columns.values)

    day = df['day'].str.split('/')

    year = np.array([int(i[0]) for i in day])
    month = np.array([int(i[1]) for i in day])
    day = np.array([int(i[2]) for i in day])

    ## if you consider periodical feature

    month = convert_period(month)
    day = convert_period(day)

    ## remove the non-numeric columns
    df = df._get_numeric_data()
    data = df.as_matrix()

    day = np.vstack((month, day)).T
    data = np.hstack((day,data))

    # put the numeric column names in a python list
    numeric_headers = list(df.columns.values)

    # create a numpy array with the numeric values for input into scikit-learn
    return original_headers, data
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值