Using kernels for nonlinear SVR
Recall from our discussion at the beginning of this chapter that we can use a kernel function to fit a nonlinear epsilon-insensitive tube. In this section, we will run a nonlinear SVR with the land temperatures data that we worked with in the previous chapter. But first, we will construct a linear SVR with the same data for comparison.
We will model the average temperature for weather stations as a function of latitude and elevation. Follow these steps:
- We will begin by loading the familiar libraries. The only new class is
SVR
from scikit-learn:import pandas as pd import numpy as np from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler from sklearn.svm import LinearSVR, SVR from scipy.stats import uniform from sklearn.impute import SimpleImputer from sklearn.pipeline import make_pipeline from sklearn.compose import TransformedTargetRegressor from sklearn.impute import KNNImputer from sklearn...