現實中的數據,總是不理想的,比如說數據中有的列會存在缺失值。
缺失值太多的樣本本身沒有太多的信息,對訓練模型就沒有作用。同時,缺失值會影響模型,特別是使用度量相關的模型。如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