<jupyter_start><jupyter_text>Test Train Split<jupyter_code>train = df.query('Year < 2008')
test = df.query('Year >=2008')
X_train = train[features]
y_train = train[target]
X_test = test[features]
y_test = test[target]

X_train.shape, y_train.shape, X_test.shape, y_test.shape
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
y_pred
y_test
mean_absolute_error(y_test, y_pred)<jupyter_output><empty_output><jupyter_text>Leave-One-Out Cross-Validation<jupyter_code>from sklearn.linear_model import LinearRegression
print('Leave-One-Out Cross-Validation, Do-It-Yourself implemnetation')

maes =[]

for year in df['Year']: 
    print(f'Fit Linear Regression on all years except {year}')
    
    #Choose model hyperparmeters by instantiating this class
    model = LinearRegression()
    
    #Arrange data into X features matrix and y target 
    train = df[df['Year'] !=year]
    test = df[df['Year'] == year]
    X_train = train[features]
    y_train = train[target]
    X_test = test[features]
    y_test = test[target]
    
    #Fit the model to your data by calling
    model.fit(X_train, y_train)
    
    #Apply the model to new data: predict labels for unknown data using predict() method
    y_pred = model.predict(X_test)
    
    mae= mean_absolute_error(y_test, y_pred)
    maes.append(mae)
    print(f'Absolute Error on prediction for {year} = {mae}')
    
    
#Leave-One-Out Cross-Validation Mean Absolute Error
pd.Series(maes).mean()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup