class_docstr: Generate polynomial and interaction features.
  
  Generate a new feature matrix consisting of all polynomial combinations
  of the features with degree less than or equal to the specified degree.
  For example, if an input sample is two dimensional and of the form
  [a, b], the degree-2 polynomial features are [1, a, b, a^2, ab, b^2].
  
  Read more in the :ref:`User Guide <polynomial_features>`.
  
  Parameters
  ----------
  degree : int or tuple (min_degree, max_degree), default=2
      If a single int is given, it specifies the maximal degree of the
      polynomial features. If a tuple `(min_degree, max_degree)` is passed,
      then `min_degree` is the minimum and `max_degree` is the maximum
      polynomial degree of the generated features. Note that `min_degree=0`
      and `min_degree=1` are equivalent as outputting the degree zero term is
      determined by `include_bias`.
  
  interaction_only : bool, default=False
      If `True`, only interaction features are produced: features that are
      products of at most `degree` *distinct* input features, i.e. terms with
      power of 2 or higher of the same input feature are excluded:
  
          - included: `x[0]`, `x[1]`, `x[0] * x[1]`, etc.
          - excluded: `x[0] ** 2`, `x[0] ** 2 * x[1]`, etc.
  
  include_bias : bool, default=True
      If `True` (default), then include a bias column, the feature in which
      all polynomial powers are zero (i.e. a column of ones - acts as an
      intercept term in a linear model).
  
  order : {'C', 'F'}, default='C'
      Order of output array in the dense case. `'F'` order is faster to
      compute, but may slow down subsequent estimators.
  
      .. versionadded:: 0.21
  
  Attributes
  ----------
  powers_ : ndarray of shape (`n_output_features_`, `n_features_in_`)
      `powers_[i, j]` is the exponent of the jth input in the ith output.
  
  n_features_in_ : int
      Number of features seen during :term:`fit`.
  
      .. versionadded:: 0.24
  
  feature_names_in_ : ndarray of shape (`n_features_in_`,)
      Names of features seen during :term:`fit`. Defined only when `X`
      has feature names that are all strings.
  
      .. versionadded:: 1.0
  
  n_output_features_ : int
      The total number of polynomial output features. The number of output
      features is computed by iterating over all suitably sized combinations
      of input features.
  
  See Also
  --------
  SplineTransformer : Transformer that generates univariate B-spline bases
      for features.
  
  Notes
  -----
  Be aware that the number of features in the output array scales
  polynomially in the number of features of the input array, and
  exponentially in the degree. High degrees can cause overfitting.
  
  See :ref:`examples/linear_model/plot_polynomial_interpolation.py
  <sphx_glr_auto_examples_linear_model_plot_polynomial_interpolation.py>`
  
  Examples
  --------
  >>> import numpy as np
  >>> from sklearn.preprocessing import PolynomialFeatures
  >>> X = np.arange(6).reshape(3, 2)
  >>> X
  array([[0, 1],
         [2, 3],
         [4, 5]])
  >>> poly = PolynomialFeatures(2)
  >>> poly.fit_transform(X)
  array([[ 1.,  0.,  1.,  0.,  0.,  1.],
         [ 1.,  2.,  3.,  4.,  6.,  9.],
         [ 1.,  4.,  5., 16., 20., 25.]])
  >>> poly = PolynomialFeatures(interaction_only=True)
  >>> poly.fit_transform(X)
  array([[ 1.,  0.,  1.,  0.],
         [ 1.,  2.,  3.,  6.],
         [ 1.,  4.,  5., 20.]])
class_docstr_tok: ["Generate","polynomial","and","interaction","features",".","Generate","a","new","feature","matrix","consisting","of","all","polynomial","combinations","of","the","features","with","degree","less","than","or","equal","to","the","specified","degree",".","For","example",",","if","an","input","sample","is","two","dimensional","and","of","the","form","[","a",",","b","]",",","the","degree-2","polynomial","features","are","[","1",",","a",",","b",",","a^2",",","ab",",","b^2","]",".","Read","more","in","the",":","ref",":","`","User","Guide","<","polynomial_features",">","`",".","Parameters","--","--","--","--","--","degree",":","int","or","tuple","(","min_degree",",","max_degree",")",",","default=2","If","a","single","int","is","given",",","it","specifies","the","maximal","degree","of","the","polynomial","features",".","If","a","tuple","`","(","min_degree",",","max_degree",")","`","is","passed",",","then","`","min_degree","`","is","the","minimum","and","`","max_degree","`","is","the","maximum","polynomial","degree","of","the","generated","features",".","Note","that","`","min_degree=0","`","and","`","min_degree=1","`","are","equivalent","as","outputting","the","degree","zero","term","is","determined","by","`","include_bias","`",".","interaction_only",":","bool",",","default=False","If","`","True","`",",","only","interaction","features","are","produced",":","features","that","are","products","of","at","most","`","degree","`","*","distinct","*","input","features",",","i.e",".","terms","with","power","of","2","or","higher","of","the","same","input","feature","are","excluded",":","-","included",":","`","x","[","0","]","`",",","`","x","[","1","]","`",",","`","x","[","0","]","*","x","[","1","]","`",",","etc",".","-","excluded",":","`","x","[","0","]","*","*","2","`",",","`","x","[","0","]","*","*","2","*","x","[","1","]","`",",","etc",".","include_bias",":","bool",",","default=True","If","`","True","`","(","default",")",",","then","include","a","bias","column",",","the","feature","in","which","all","polynomial","powers","are","zero","(","i.e",".","a","column","of","ones","-","acts","as","an","intercept","term","in","a","linear","model",")",".","order",":","{","'","C","'",",","'","F","'","}",",","default=","'","C'","Order","of","output","array","in","the","dense","case",".","`","'","F","'","`","order","is","faster","to","compute",",","but","may","slow","down","subsequent","estimators",".","..","versionadded",":",":","0.21","Attributes","--","--","--","--","--","powers_",":","ndarray","of","shape","(","`","n_output_features_","`",",","`","n_features_in_","`",")","`","powers_","[","i",",","j","]","`","is","the","exponent","of","the","jth","input","in","the","ith","output",".","n_features_in_",":","int","Number","of","features","seen","during",":","term",":","`","fit","`",".","..","versionadded",":",":","0.24","feature_names_in_",":","ndarray","of","shape","(","`","n_features_in_","`",",",")","Names","of","features","seen","during",":","term",":","`","fit","`",".","Defined","only","when","`","X","`","has","feature","names","that","are","all","strings",".","..","versionadded",":",":","1.0","n_output_features_",":","int","The","total","number","of","polynomial","output","features",".","The","number","of","output","features","is","computed","by","iterating","over","all","suitably","sized","combinations","of","input","features",".","See","Also","--","--","--","--","SplineTransformer",":","Transformer","that","generates","univariate","B-spline","bases","for","features",".","Notes","--","--","-","Be","aware","that","the","number","of","features","in","the","output","array","scales","polynomially","in","the","number","of","features","of","the","input","array",",","and","exponentially","in","the","degree",".","High","degrees","can","cause","overfitting",".","See",":","ref",":","`","examples\/linear_model\/plot_polynomial_interpolation.py","<","sphx_glr_auto_examples_linear_model_plot_polynomial_interpolation.py",">","`","Examples","--","--","--","--",">",">",">","import","numpy","as","np",">",">",">","from","sklearn.preprocessing","import","PolynomialFeatures",">",">",">","X","=","np.arange","(","6",")",".reshape","(","3",",","2",")",">",">",">","X","array","(","[","[","0",",","1","]",",","[","2",",","3","]",",","[","4",",","5","]","]",")",">",">",">","poly","=","PolynomialFeatures","(","2",")",">",">",">","poly.fit_transform","(","X",")","array","(","[","[","1.",",","0.",",","1.",",","0.",",","0.",",","1",".","]",",","[","1.",",","2.",",","3.",",","4.",",","6.",",","9",".","]",",","[","1.",",","4.",",","5.",",","16.",",","20.",",","25",".","]","]",")",">",">",">","poly","=","PolynomialFeatures","(","interaction_only=True",")",">",">",">","poly.fit_transform","(","X",")","array","(","[","[","1.",",","0.",",","1.",",","0",".","]",",","[","1.",",","2.",",","3.",",","6",".","]",",","[","1.",",","4.",",","5.",",","20",".","]","]",")"]
docstr: Calculate number of terms in polynomial expansion
  
  This should be equivalent to counting the number of terms returned by
  _combinations(...) but much faster.
docstr_tok: ["Calculate","number","of","terms","in","polynomial","expansion","This","should","be","equivalent","to","counting","the","number","of","terms","returned","by","_combinations","(","...",")","but","much","faster","."]
code: def _num_combinations(
      n_features, min_degree, max_degree, interaction_only, include_bias
  ):
      """Calculate number of terms in polynomial expansion
  
      This should be equivalent to counting the number of terms returned by
      _combinations(...) but much faster.
      """
  
      if interaction_only:
          combinations = sum(
              [
                  comb(n_features, i, exact=True)
                  for i in range(
                      max(1, min_degree),
                      min(max_degree, n_features) + 1,
                  )
              ]
          )
      else:
          combinations = (
              comb(n_features + max_degree, max_degree, exact=True) - 1
          )
          if min_degree > 0:
              d = min_degree - 1
              combinations -= comb(n_features + d, d, exact=True) - 1
  
      if include_bias:
          combinations += 1
  
      return combinations
  
imports: import collections
  from itertools import chain, combinations
  from itertools import combinations_with_replacement
  from numbers import Integral
  import numpy
  from scipy import sparse
  from scipy.interpolate import BSpline
  from scipy.special import comb
  from ..base import BaseEstimator, TransformerMixin, _fit_context
  from ..utils import check_array
  from ..utils._param_validation import Interval, StrOptions
  from ..utils.fixes import parse_version, sp_version
  from ..utils.stats import _weighted_percentile
  from ..utils.validation import FLOAT_DTYPES, _check_feature_names_in, _check_sample_weight, check_is_fitted
  from ._csr_polynomial_expansion import _calc_expanded_nnz, _calc_total_nnz, _csr_polynomial_expansion
label_desc: Use image node_id 3 for calling the PolynomialFeatures obj's underlying member method code with example usage: obj._num_combinations(n_features, min_degree, max_degree, interaction_only, include_bias) and returns: combinations