- Deep Learning By Example
- Ahmed Menshawy
- 139字
- 2021-06-24 18:52:45
Assigning an average value
This is also one of the common approaches because of its simplicity. In the case of a numerical feature, you can just replace the missing values with the mean or median. You can also use this approach in the case of categorical variables by assigning the mode (the value that has the highest occurrence) to the missing values.
The following code assigns the median of the non-missing values of the Fare feature to the missing values:
# handling the missing values by replacing it with the median fare
df_titanic_data['Fare'][np.isnan(df_titanic_data['Fare'])] = df_titanic_data['Fare'].median()
Or, you can use the following code to find the value that has the highest occurrence in the Embarked feature and assign it to the missing values:
# replacing the missing values with the most common value in the variable
df_titanic_data.Embarked[df_titanic_data.Embarked.isnull()] = df_titanic_data.Embarked.dropna().mode().values
推薦閱讀
- 零起步輕松學單片機技術(第2版)
- Canvas LMS Course Design
- Hands-On Cybersecurity with Blockchain
- 網站前臺設計綜合實訓
- 網絡管理工具實用詳解
- PLC與變頻技術應用
- Creating ELearning Games with Unity
- ADuC系列ARM器件應用技術
- 菜鳥起飛電腦組裝·維護與故障排查
- Machine Learning in Java
- PostgreSQL High Performance Cookbook
- 工業(yè)機器人應用系統(tǒng)三維建模
- 實戰(zhàn)突擊
- Hands-On Artificial Intelligence for Beginners
- iLike就業(yè)SQL多功能教材