nodes: 0, module; 1, function_definition; 2, function_name:generate_X_grid; 3, parameters; 4, block; 5, identifier:self; 6, identifier:term; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, if_statement; 11, comment:# cant do Intercept; 12, if_statement; 13, comment:# process each subterm in a TensorTerm; 14, if_statement; 15, identifier:n; 16, integer:100; 17, identifier:meshgrid; 18, False; 19, comment:"""create a nice grid of X data
  
          array is sorted by feature and uniformly spaced,
          so the marginal and joint distributions are likely wrong
  
          if term is >= 0, we generate n samples per feature,
          which results in n^deg samples,
          where deg is the degree of the interaction of the term
  
          Parameters
          ----------
          term : int,
              Which term to process.
  
          n : int, optional
              number of data points to create
  
          meshgrid : bool, optional
              Whether to return a meshgrid (useful for 3d plotting)
              or a feature matrix (useful for inference like partial predictions)
  
          Returns
          -------
          if meshgrid is False:
              np.array of shape (n, n_features)
              where m is the number of
              (sub)terms in the requested (tensor)term.
          else:
              tuple of len m,
              where m is the number of (sub)terms in the requested
              (tensor)term.
  
              each element in the tuple contains a np.ndarray of size (n)^m
  
          Raises
          ------
          ValueError :
              If the term requested is an intercept
              since it does not make sense to process the intercept term.
          """; 20, not_operator; 21, block; 22, attribute; 23, block; 24, attribute; 25, block; 26, comment:# all other Terms; 27, elif_clause; 28, comment:# dont know what to do here; 29, else_clause; 30, attribute; 31, raise_statement; 32, subscript; 33, identifier:isintercept; 34, raise_statement; 35, subscript; 36, identifier:istensor; 37, expression_statement; 38, for_statement; 39, expression_statement; 40, if_statement; 41, call; 42, block; 43, block; 44, identifier:self; 45, identifier:_is_fitted; 46, call; 47, attribute; 48, identifier:term; 49, call; 50, attribute; 51, identifier:term; 52, assignment; 53, identifier:term_; 54, subscript; 55, block; 56, assignment; 57, identifier:meshgrid; 58, block; 59, else_clause; 60, identifier:hasattr; 61, argument_list; 62, expression_statement; 63, if_statement; 64, comment:# fill in feature matrix with only relevant features for this term; 65, expression_statement; 66, expression_statement; 67, if_statement; 68, return_statement; 69, raise_statement; 70, identifier:AttributeError; 71, argument_list; 72, identifier:self; 73, identifier:terms; 74, identifier:ValueError; 75, argument_list; 76, identifier:self; 77, identifier:terms; 78, identifier:Xs; 79, list; 80, attribute; 81, identifier:term; 82, expression_statement; 83, identifier:Xs; 84, call; 85, return_statement; 86, block; 87, subscript; 88, string; 89, assignment; 90, identifier:meshgrid; 91, block; 92, assignment; 93, assignment; 94, comparison_operator:getattr(self.terms[term], 'by', None) is not None; 95, block; 96, identifier:X; 97, call; 98, string; 99, string; 100, identifier:self; 101, identifier:terms; 102, call; 103, attribute; 104, argument_list; 105, call; 106, return_statement; 107, attribute; 108, identifier:term; 109, string_content:edge_knots_; 110, identifier:x; 111, call; 112, return_statement; 113, identifier:X; 114, call; 115, subscript; 116, identifier:x; 117, call; 118, None; 119, expression_statement; 120, identifier:TypeError; 121, argument_list; 122, string_content:GAM has not been fitted. Call fit first.; 123, string_content:cannot create grid for intercept term; 124, attribute; 125, argument_list; 126, identifier:np; 127, identifier:meshgrid; 128, list_splat; 129, keyword_argument; 130, identifier:tuple; 131, argument_list; 132, call; 133, identifier:self; 134, identifier:terms; 135, attribute; 136, argument_list; 137, tuple; 138, attribute; 139, argument_list; 140, identifier:X; 141, slice; 142, attribute; 143, identifier:getattr; 144, argument_list; 145, assignment; 146, call; 147, identifier:Xs; 148, identifier:append; 149, call; 150, identifier:Xs; 151, identifier:indexing; 152, string; 153, identifier:Xs; 154, attribute; 155, argument_list; 156, identifier:np; 157, identifier:linspace; 158, subscript; 159, subscript; 160, keyword_argument; 161, identifier:x; 162, identifier:np; 163, identifier:zeros; 164, tuple; 165, subscript; 166, identifier:feature; 167, subscript; 168, string; 169, None; 170, subscript; 171, float:1.; 172, attribute; 173, argument_list; 174, attribute; 175, argument_list; 176, string_content:ij; 177, identifier:self; 178, identifier:_flatten_mesh; 179, identifier:Xs; 180, keyword_argument; 181, attribute; 182, integer:0; 183, attribute; 184, integer:1; 185, identifier:num; 186, identifier:n; 187, identifier:n; 188, subscript; 189, attribute; 190, identifier:term; 191, attribute; 192, identifier:term; 193, string_content:by; 194, identifier:X; 195, slice; 196, attribute; 197, string; 198, identifier:format; 199, subscript; 200, identifier:np; 201, identifier:linspace; 202, subscript; 203, subscript; 204, keyword_argument; 205, identifier:term; 206, identifier:term; 207, subscript; 208, identifier:edge_knots_; 209, subscript; 210, identifier:edge_knots_; 211, attribute; 212, string; 213, identifier:self; 214, identifier:terms; 215, identifier:self; 216, identifier:terms; 217, subscript; 218, identifier:by; 219, string_content:Unexpected term type: {}; 220, attribute; 221, identifier:term; 222, attribute; 223, integer:0; 224, attribute; 225, integer:1; 226, identifier:num; 227, identifier:n; 228, attribute; 229, identifier:term; 230, attribute; 231, identifier:term; 232, identifier:self; 233, identifier:statistics_; 234, string_content:m_features; 235, attribute; 236, identifier:term; 237, identifier:self; 238, identifier:terms; 239, identifier:term_; 240, identifier:edge_knots_; 241, identifier:term_; 242, identifier:edge_knots_; 243, identifier:self; 244, identifier:terms; 245, identifier:self; 246, identifier:terms; 247, identifier:self; 248, identifier:terms
code: def generate_X_grid(self, term, n=100, meshgrid=False):
          """create a nice grid of X data
  
          array is sorted by feature and uniformly spaced,
          so the marginal and joint distributions are likely wrong
  
          if term is >= 0, we generate n samples per feature,
          which results in n^deg samples,
          where deg is the degree of the interaction of the term
  
          Parameters
          ----------
          term : int,
              Which term to process.
  
          n : int, optional
              number of data points to create
  
          meshgrid : bool, optional
              Whether to return a meshgrid (useful for 3d plotting)
              or a feature matrix (useful for inference like partial predictions)
  
          Returns
          -------
          if meshgrid is False:
              np.array of shape (n, n_features)
              where m is the number of
              (sub)terms in the requested (tensor)term.
          else:
              tuple of len m,
              where m is the number of (sub)terms in the requested
              (tensor)term.
  
              each element in the tuple contains a np.ndarray of size (n)^m
  
          Raises
          ------
          ValueError :
              If the term requested is an intercept
              since it does not make sense to process the intercept term.
          """
          if not self._is_fitted:
              raise AttributeError('GAM has not been fitted. Call fit first.')
  
          # cant do Intercept
          if self.terms[term].isintercept:
              raise ValueError('cannot create grid for intercept term')
  
          # process each subterm in a TensorTerm
          if self.terms[term].istensor:
              Xs = []
              for term_ in self.terms[term]:
                  Xs.append(np.linspace(term_.edge_knots_[0],
                                        term_.edge_knots_[1],
                                        num=n))
  
              Xs = np.meshgrid(*Xs, indexing='ij')
              if meshgrid:
                  return tuple(Xs)
              else:
                  return self._flatten_mesh(Xs, term=term)
  
          # all other Terms
          elif hasattr(self.terms[term], 'edge_knots_'):
              x = np.linspace(self.terms[term].edge_knots_[0],
                              self.terms[term].edge_knots_[1],
                              num=n)
  
              if meshgrid:
                  return (x,)
  
              # fill in feature matrix with only relevant features for this term
              X = np.zeros((n, self.statistics_['m_features']))
              X[:, self.terms[term].feature] = x
              if getattr(self.terms[term], 'by', None) is not None:
                  X[:, self.terms[term].by] = 1.
  
              return X
  
          # dont know what to do here
          else:
              raise TypeError('Unexpected term type: {}'.format(self.terms[term]))