现实中的数据,总是不理想的,比如说数据中有的列会存在缺失值。
缺失值太多的样本本身没有太多的信息,对训练模型就没有作用。同时,缺失值会影响模型,特别是使用度量相关的模型。如KNN和SVM。
### 统计数据每列的缺失数量
ListData.isnull().sum()
Out[11]:
id 0
name 1
host_id 0
host_name 0
neighbourhood_group 28452
neighbourhood 0
latitude 0
longitude 0
room_type 0
price 0
minimum_nights 0
number_of_reviews 0
last_review 11158
reviews_per_month 11158
calculated_host_listings_count 0
availability_365 0
dtype: int64
我们看的是缺失的占比,所以在这个的基础之上,我们可以在除一个样本数
ListData.isnull().sum()/ListData.shape[0]
Out[19]:
id 0.000000
name 0.000035
host_id 0.000000
host_name 0.000000
neighbourhood_group 1.000000
neighbourhood 0.000000
latitude 0.000000
longitude 0.000000
room_type 0.000000
price 0.000000
minimum_nights 0.000000
number_of_reviews 0.000000
last_review 0.392169
reviews_per_month 0.392169
calculated_host_listings_count 0.000000
availability_365 0.000000
dtype: float64