XGBoost modelini çapraz doğrulama
Bu egzersizde, oluşturduğun pipeline'ı kullanarak modelini hem ön işlemek hem de çapraz doğrulamak için bir adım daha ileri gideceksin.
Bu egzersiz
XGBoost ile Aşırı Gradyan Artırma
kursunun bir parçasıdırEgzersiz talimatları
stepskullanarakxgb_pipelineadında bir pipeline oluştur.cross_val_score()ile 10 katlı çapraz doğrulama yap. Pipeline'ı,X'i (sözlük olarak,.to_dict("records")kullanarak),y'yi, kullanmak istediğin kat sayısını vescoring'i ("neg_mean_squared_error") iletmen gerekecek.- 10 katlı RMSE'yi yazdır.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
# Import necessary modules
from sklearn.feature_extraction import DictVectorizer
from sklearn.pipeline import Pipeline
from sklearn.model_selection import cross_val_score
# Fill LotFrontage missing values with 0
X.LotFrontage = ____
# Setup the pipeline steps: steps
steps = [("ohe_onestep", DictVectorizer(sparse=False)),
("xgb_model", xgb.XGBRegressor(max_depth=2, objective="reg:squarederror"))]
# Create the pipeline: xgb_pipeline
xgb_pipeline = ____
# Cross-validate the model
cross_val_scores = ____
# Print the 10-fold RMSE
print("10-fold RMSE: ", np.mean(np.sqrt(np.abs(____))))