Feature engineering

Python में Machine Learning के साथ CTR प्रेडिक्शन

Kevin Huo

Instructor

तिथियों से निपटना

print(df.hour.head(1))
14102101
df['hour'] = pd.to_datetime(
  df['hour'], format = '%y%m%d%H')
df['hour_of_day'] = df['hour'].dt.hour
print(df.hour.head(1))
2014-10-21 01:00:0
print(df.groupby('hour_of_day')
      ['click'].sum())
             click
hour_of_day       
1             1092
2             6546
Python में Machine Learning के साथ CTR प्रेडिक्शन

Hashing से categorical variables बदलना

  • Categorical फीचर को numerical फ़ॉर्मेट में बदलना होता है

  • Hash फंक्शन: किसी भी input को integer output में मैप करता है, एक ही input पर हमेशा वही output देता है

  • Lambda फंक्शन: lambda x: f(x)

  • f(x) = hash(x) से hash फंक्शन ऐसे लागू करें:

df['site_id'] = df['site_id'].apply(lambda x: hash(x))
83a0ad1a -> -9161053084583616050
85f751fd-> 818242008494177460
Python में Machine Learning के साथ CTR प्रेडिक्शन

फीचर्स को करीब से देखें

  • count() और nunique() के उदाहरण:
df['ad_type'].count()
50000
df['ad_type'].nunique()
31

किसी categorical कॉलम के वितरण का उदाहरण

Python में Machine Learning के साथ CTR प्रेडिक्शन

फीचर्स बनाना

  • ज़्यादातर variables categorical हैं
  • ज़्यादा फीचर जोड़ने से predictive power बेहतर होती है

  • नए फीचर का उदाहरण: device_id (user) और search_engine_type पर impressions:

df['device_id_count'] = df.groupby('device_id')['click'].transform("count")
df['search_engine_type_count'] = df.groupby('search_engine_type')['click'].transform("count")
print(df.head(1))
...  device_id_count  search_engine_type_count
...            40862                     47710
Python में Machine Learning के साथ CTR प्रेडिक्शन

अभ्यास करते हैं!

Python में Machine Learning के साथ CTR प्रेडिक्शन

Preparing Video For Download...