code: def test_linearmodel():
      """Test LinearModel class for computing filters and patterns."""
      # check categorical target fit in standard linear model
      from sklearn.linear_model import LinearRegression
  
      rng = np.random.RandomState(0)
      clf = LinearModel()
      n, n_features = 20, 3
      X = rng.rand(n, n_features)
      y = np.arange(n) % 2
      clf.fit(X, y)
      assert_equal(clf.filters_.shape, (n_features,))
      assert_equal(clf.patterns_.shape, (n_features,))
      with pytest.raises(ValueError):
          wrong_X = rng.rand(n, n_features, 99)
          clf.fit(wrong_X, y)
  
      # check categorical target fit in standard linear model with GridSearchCV
      from sklearn import svm
      from sklearn.model_selection import GridSearchCV
  
      parameters = {"kernel": ["linear"], "C": [1, 10]}
      clf = LinearModel(
          GridSearchCV(
              svm.SVC(), parameters, cv=2, refit=True, n_jobs=None
          )
      )
      clf.fit(X, y)
      assert_equal(clf.filters_.shape, (n_features,))
      assert_equal(clf.patterns_.shape, (n_features,))
      with pytest.raises(ValueError):
          wrong_X = rng.rand(n, n_features, 99)
          clf.fit(wrong_X, y)
  
      # check continuous target fit in standard linear model with GridSearchCV
      n_targets = 1
      Y = rng.rand(n, n_targets)
      clf = LinearModel(
          GridSearchCV(
              svm.SVR(), parameters, cv=2, refit=True, n_jobs=None
          )
      )
      clf.fit(X, y)
      assert_equal(clf.filters_.shape, (n_features,))
      assert_equal(clf.patterns_.shape, (n_features,))
      with pytest.raises(ValueError):
          wrong_y = rng.rand(n, n_features, 99)
          clf.fit(X, wrong_y)
  
      # check multi-target fit in standard linear model
      n_targets = 5
      Y = rng.rand(n, n_targets)
      clf = LinearModel(LinearRegression())
      clf.fit(X, Y)
      assert_equal(clf.filters_.shape, (n_targets, n_features))
      assert_equal(clf.patterns_.shape, (n_targets, n_features))
      with pytest.raises(ValueError):
          wrong_y = rng.rand(n, n_features, 99)
          clf.fit(X, wrong_y)
  
imports: import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_array_less, assert_equal
  from mne import EpochsArray, create_info
  from mne.decoding import GeneralizingEstimator, Scaler, TransformerMixin, Vectorizer
  from mne.decoding.base import BaseEstimator, LinearModel, _get_inverse_funcs, cross_val_multiscore, get_coef
  from mne.decoding.search_light import SlidingEstimator
label_desc: Use image node_id 6 for calling a global function with example usage: test_linearmodel() without return types