- Deep Learning By Example
- Ahmed Menshawy
- 128字
- 2021-06-24 18:52:45
Factorizing
This approach is used to create a numerical categorical feature from any other feature. In pandas, the factorize() function does that. This type of transformation is useful if your feature is an alphanumeric categorical variable. In the Titanic data samples, we can transform the Cabin feature into a categorical feature, representing the letter of the cabin:
# the cabin number is a sequence of of alphanumerical digits, so we are going to create some features
# from the alphabetical part of it
df_titanic_data['CabinLetter'] = df_titanic_data['Cabin'].map(lambda l: get_cabin_letter(l))
df_titanic_data['CabinLetter'] = pd.factorize(df_titanic_data['CabinLetter'])[0]
def get_cabin_letter(cabin_value):
# searching for the letters in the cabin alphanumerical value
letter_match = re.compile("([a-zA-Z]+)").search(cabin_value)
if letter_match:
return letter_match.group()
else:
return 'U'
We can also apply transformations to quantitative features by using one of the following approaches.
推薦閱讀
- Mastering Mesos
- Deep Learning Quick Reference
- Ansible Quick Start Guide
- Spark編程基礎(Scala版)
- 商戰數據挖掘:你需要了解的數據科學與分析思維
- 樂高機器人EV3設計指南:創造者的搭建邏輯
- ROS機器人編程與SLAM算法解析指南
- 工業機器人現場編程(FANUC)
- 四向穿梭式自動化密集倉儲系統的設計與控制
- 基于企業網站的顧客感知服務質量評價理論模型與實證研究
- 一步步寫嵌入式操作系統
- 電動汽車驅動與控制技術
- Microsoft Dynamics CRM 2013 Marketing Automation
- 穿越計算機的迷霧
- 貫通Java Web輕量級應用開發