reduced_X_train = X_train.dropna(axis = 1)
reduced_X_valid = X_valid.dropna(axis = 1)
axis = 1是丢掉列,axis = 0是丢掉行。
Imputation就是用每一列的均值/中位数/最大频率的数等去补充缺失值。值得注意的是对于valid的数据而言,fit的时候仍然要用train的数据。strategy也可以修改为其他的方法。
from sklearn.impute import SimpleImputer
imp_mean = SimpleImputer(strategy='mean')
imputed_X_train = pd.DataFrame(imp_mean.fit_transform(X_train))
imputed_X_valid = pd.DataFrame(imp_mean.transform(X_valid))
imputed_X_train.columns = X_train.columns
imputed_X_valid.columns = X_valid.columns
以上方法来自与kaggle的机器学习课程