程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[AI practice] pandas obtains the time characteristics of machine learning model

編輯:Python

pandas Get the time characteristics of the machine learning model

Environmental Science

  • Ubuntu 18.04
  • python 3.6.9
  • pandas 1.1.5

Get time characteristics


df = pd.read_csv(data_path, low_memory=False)
# Time characteristics 
df['date'] = pd.to_datetime(df['date'])
# year 
df['year'] = df['date'].map(lambda x: (x.year))
# month 
df['month'] = df['date'].map(lambda x: (x.month))
# Japan 
df['day'] = df['date'].map(lambda x: (x.day))
# Hours 
df['hour'] = df['date'].map(lambda x: (x.hour))
# minute 
df['minute'] = df['date'].map(lambda x: (x.minute))
# What day 
df['dayofweek'] = df['date'].map(lambda x: (x.dayofweek+1))

The above time characteristics are numerical

Hot coding alone one-hot Time characteristics

Search Baidu by yourself one-hot

  • problem
    one-hot The applicable features should be classified features , And there is no difference in the distance between different categories , For example, red, yellow and blue , Chinese characters, etc one-hot The expression is very good . But for time series ,5 Point and 6 Point tracking 18 The distance between points is obviously different , So use one-hot To measure , A lot of information will be lost .

Change a time variable into a point on the circumference of a two-dimensional plane

As shown above , Change a time variable into a point on the circumference of a two-dimensional plane . In this way, we can solve the cyclical factors .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved