Maybe this should go into a if self.kernel != 'linear'. The n_samples, n_features = X.shape is confusing in case of precomputed kernels, too.