開始使用免費開始

處理非定態性

在這個練習中,你會再次視覺化模型分數的變動,但這次面對的是隨時間改變統計特性的資料。

model 中已經存有一個 Linear regression 模型物件,cv 是交叉驗證物件,資料則在 Xy

本練習屬於課程

Python 的時間序列資料機器學習

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Pre-initialize window sizes
window_sizes = [25, 50, 75, 100]

# Create an empty DataFrame to collect the stores
all_scores = ____(index=times_scores)

# Generate scores for each split to see how the model performs over time
for window in window_sizes:
    # Create cross-validation object using a limited lookback window
    cv = ____(n_splits=100, max_train_size=window)
    
    # Calculate scores across all CV splits and collect them in a DataFrame
    this_scores = ____(____, ____, ____, cv=cv, scoring=my_pearsonr)
    all_scores['Length {}'.format(window)] = this_scores
編輯並執行程式碼