class_docstr: Meta-transformer for selecting features based on importance weights.
  
  .. versionadded:: 0.17
  
  Read more in the :ref:`User Guide <select_from_model>`.
  
  Parameters
  ----------
  estimator : object
      The base estimator from which the transformer is built.
      This can be both a fitted (if ``prefit`` is set to True)
      or a non-fitted estimator. The estimator should have a
      ``feature_importances_`` or ``coef_`` attribute after fitting.
      Otherwise, the ``importance_getter`` parameter should be used.
  
  threshold : str or float, default=None
      The threshold value to use for feature selection. Features whose
      absolute importance value is greater or equal are kept while the others
      are discarded. If "median" (resp. "mean"), then the ``threshold`` value
      is the median (resp. the mean) of the feature importances. A scaling
      factor (e.g., "1.25*mean") may also be used. If None and if the
      estimator has a parameter penalty set to l1, either explicitly
      or implicitly (e.g, Lasso), the threshold used is 1e-5.
      Otherwise, "mean" is used by default.
  
  prefit : bool, default=False
      Whether a prefit model is expected to be passed into the constructor
      directly or not.
      If `True`, `estimator` must be a fitted estimator.
      If `False`, `estimator` is fitted and updated by calling
      `fit` and `partial_fit`, respectively.
  
  norm_order : non-zero int, inf, -inf, default=1
      Order of the norm used to filter the vectors of coefficients below
      ``threshold`` in the case where the ``coef_`` attribute of the
      estimator is of dimension 2.
  
  max_features : int, callable, default=None
      The maximum number of features to select.
  
      - If an integer, then it specifies the maximum number of features to
        allow.
      - If a callable, then it specifies how to calculate the maximum number of
        features allowed by using the output of `max_features(X)`.
      - If `None`, then all features are kept.
  
      To only select based on ``max_features``, set ``threshold=-np.inf``.
  
      .. versionadded:: 0.20
      .. versionchanged:: 1.1
         `max_features` accepts a callable.
  
  importance_getter : str or callable, default='auto'
      If 'auto', uses the feature importance either through a ``coef_``
      attribute or ``feature_importances_`` attribute of estimator.
  
      Also accepts a string that specifies an attribute name/path
      for extracting feature importance (implemented with `attrgetter`).
      For example, give `regressor_.coef_` in case of
      :class:`~sklearn.compose.TransformedTargetRegressor`  or
      `named_steps.clf.feature_importances_` in case of
      :class:`~sklearn.pipeline.Pipeline` with its last step named `clf`.
  
      If `callable`, overrides the default feature importance getter.
      The callable is passed with the fitted estimator and it should
      return importance for each feature.
  
      .. versionadded:: 0.24
  
  Attributes
  ----------
  estimator_ : estimator
      The base estimator from which the transformer is built. This attribute
      exist only when `fit` has been called.
  
      - If `prefit=True`, it is a deep copy of `estimator`.
      - If `prefit=False`, it is a clone of `estimator` and fit on the data
        passed to `fit` or `partial_fit`.
  
  n_features_in_ : int
      Number of features seen during :term:`fit`. Only defined if the
      underlying estimator exposes such an attribute when fit.
  
      .. versionadded:: 0.24
  
  max_features_ : int
      Maximum number of features calculated during :term:`fit`. Only defined
      if the ``max_features`` is not `None`.
  
      - If `max_features` is an `int`, then `max_features_ = max_features`.
      - If `max_features` is a callable, then `max_features_ = max_features(X)`.
  
      .. versionadded:: 1.1
  
  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
  
  threshold_ : float
      The threshold value used for feature selection.
  
  See Also
  --------
  RFE : Recursive feature elimination based on importance weights.
  RFECV : Recursive feature elimination with built-in cross-validated
      selection of the best number of features.
  SequentialFeatureSelector : Sequential cross-validation based feature
      selection. Does not rely on importance weights.
  
  Notes
  -----
  Allows NaN/Inf in the input if the underlying estimator does as well.
  
  Examples
  --------
  >>> from sklearn.feature_selection import SelectFromModel
  >>> from sklearn.linear_model import LogisticRegression
  >>> X = [[ 0.87, -1.34,  0.31 ],
  ...      [-2.79, -0.02, -0.85 ],
  ...      [-1.34, -0.48, -2.55 ],
  ...      [ 1.92,  1.48,  0.65 ]]
  >>> y = [0, 1, 0, 1]
  >>> selector = SelectFromModel(estimator=LogisticRegression()).fit(X, y)
  >>> selector.estimator_.coef_
  array([[-0.3252...,  0.8345...,  0.4976...]])
  >>> selector.threshold_
  0.55249...
  >>> selector.get_support()
  array([False,  True, False])
  >>> selector.transform(X)
  array([[-1.34],
         [-0.02],
         [-0.48],
         [ 1.48]])
  
  Using a callable to create a selector that can use no more than half
  of the input features.
  
  >>> def half_callable(X):
  ...     return round(len(X[0]) / 2)
  >>> half_selector = SelectFromModel(estimator=LogisticRegression(),
  ...                                 max_features=half_callable)
  >>> _ = half_selector.fit(X, y)
  >>> half_selector.max_features_
  2
class_docstr_tok: ["Meta-transformer","for","selecting","features","based","on","importance","weights",".","..","versionadded",":",":","0.17","Read","more","in","the",":","ref",":","`","User","Guide","<","select_from_model",">","`",".","Parameters","--","--","--","--","--","estimator",":","object","The","base","estimator","from","which","the","transformer","is","built",".","This","can","be","both","a","fitted","(","if","``","prefit","``","is","set","to","True",")","or","a","non-fitted","estimator",".","The","estimator","should","have","a","``","feature_importances_","``","or","``","coef_","``","attribute","after","fitting",".","Otherwise",",","the","``","importance_getter","``","parameter","should","be","used",".","threshold",":","str","or","float",",","default=None","The","threshold","value","to","use","for","feature","selection",".","Features","whose","absolute","importance","value","is","greater","or","equal","are","kept","while","the","others","are","discarded",".","If","``","median","''","(","resp",".","``","mean","''",")",",","then","the","``","threshold","``","value","is","the","median","(","resp",".","the","mean",")","of","the","feature","importances",".","A","scaling","factor","(","e.g.",",","``","1.25","*","mean","''",")","may","also","be","used",".","If","None","and","if","the","estimator","has","a","parameter","penalty","set","to","l1",",","either","explicitly","or","implicitly","(","e.g",",","Lasso",")",",","the","threshold","used","is","1e-5",".","Otherwise",",","``","mean","''","is","used","by","default",".","prefit",":","bool",",","default=False","Whether","a","prefit","model","is","expected","to","be","passed","into","the","constructor","directly","or","not",".","If","`","True","`",",","`","estimator","`","must","be","a","fitted","estimator",".","If","`","False","`",",","`","estimator","`","is","fitted","and","updated","by","calling","`","fit","`","and","`","partial_fit","`",",","respectively",".","norm_order",":","non-zero","int",",","inf",",","-inf",",","default=1","Order","of","the","norm","used","to","filter","the","vectors","of","coefficients","below","``","threshold","``","in","the","case","where","the","``","coef_","``","attribute","of","the","estimator","is","of","dimension","2.","max_features",":","int",",","callable",",","default=None","The","maximum","number","of","features","to","select",".","-","If","an","integer",",","then","it","specifies","the","maximum","number","of","features","to","allow",".","-","If","a","callable",",","then","it","specifies","how","to","calculate","the","maximum","number","of","features","allowed","by","using","the","output","of","`","max_features","(","X",")","`",".","-","If","`","None","`",",","then","all","features","are","kept",".","To","only","select","based","on","``","max_features","``",",","set","``","threshold=-np.inf","``",".","..","versionadded",":",":","0.20","..","versionchanged",":",":","1.1","`","max_features","`","accepts","a","callable",".","importance_getter",":","str","or","callable",",","default='auto'","If","'auto","'",",","uses","the","feature","importance","either","through","a","``","coef_","``","attribute","or","``","feature_importances_","``","attribute","of","estimator",".","Also","accepts","a","string","that","specifies","an","attribute","name\/path","for","extracting","feature","importance","(","implemented","with","`","attrgetter","`",")",".","For","example",",","give","`","regressor_.coef_","`","in","case","of",":","class",":","`","~sklearn.compose.TransformedTargetRegressor","`","or","`","named_steps.clf.feature_importances_","`","in","case","of",":","class",":","`","~sklearn.pipeline.Pipeline","`","with","its","last","step","named","`","clf","`",".","If","`","callable","`",",","overrides","the","default","feature","importance","getter",".","The","callable","is","passed","with","the","fitted","estimator","and","it","should","return","importance","for","each","feature",".","..","versionadded",":",":","0.24","Attributes","--","--","--","--","--","estimator_",":","estimator","The","base","estimator","from","which","the","transformer","is","built",".","This","attribute","exist","only","when","`","fit","`","has","been","called",".","-","If","`","prefit=True","`",",","it","is","a","deep","copy","of","`","estimator","`",".","-","If","`","prefit=False","`",",","it","is","a","clone","of","`","estimator","`","and","fit","on","the","data","passed","to","`","fit","`","or","`","partial_fit","`",".","n_features_in_",":","int","Number","of","features","seen","during",":","term",":","`","fit","`",".","Only","defined","if","the","underlying","estimator","exposes","such","an","attribute","when","fit",".","..","versionadded",":",":","0.24","max_features_",":","int","Maximum","number","of","features","calculated","during",":","term",":","`","fit","`",".","Only","defined","if","the","``","max_features","``","is","not","`","None","`",".","-","If","`","max_features","`","is","an","`","int","`",",","then","`","max_features_","=","max_features","`",".","-","If","`","max_features","`","is","a","callable",",","then","`","max_features_","=","max_features","(","X",")","`",".","..","versionadded",":",":","1.1","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","threshold_",":","float","The","threshold","value","used","for","feature","selection",".","See","Also","--","--","--","--","RFE",":","Recursive","feature","elimination","based","on","importance","weights",".","RFECV",":","Recursive","feature","elimination","with","built-in","cross-validated","selection","of","the","best","number","of","features",".","SequentialFeatureSelector",":","Sequential","cross-validation","based","feature","selection",".","Does","not","rely","on","importance","weights",".","Notes","--","--","-","Allows","NaN\/Inf","in","the","input","if","the","underlying","estimator","does","as","well",".","Examples","--","--","--","--",">",">",">","from","sklearn.feature_selection","import","SelectFromModel",">",">",">","from","sklearn.linear_model","import","LogisticRegression",">",">",">","X","=","[","[","0.87",",","-1.34",",","0.31","]",",","...","[","-2.79",",","-0.02",",","-0.85","]",",","...","[","-1.34",",","-0.48",",","-2.55","]",",","...","[","1.92",",","1.48",",","0.65","]","]",">",">",">","y","=","[","0",",","1",",","0",",","1","]",">",">",">","selector","=","SelectFromModel","(","estimator=LogisticRegression","(",")",")",".fit","(","X",",","y",")",">",">",">","selector.estimator_.coef_","array","(","[","[","-0.3252","...",",","0.8345","...",",","0.4976","...","]","]",")",">",">",">","selector.threshold_","0.55249","...",">",">",">","selector.get_support","(",")","array","(","[","False",",","True",",","False","]",")",">",">",">","selector.transform","(","X",")","array","(","[","[","-1.34","]",",","[","-0.02","]",",","[","-0.48","]",",","[","1.48","]","]",")","Using","a","callable","to","create","a","selector","that","can","use","no","more","than","half","of","the","input","features",".",">",">",">","def","half_callable","(","X",")",":","...","return","round","(","len","(","X","[","0","]",")","\/","2",")",">",">",">","half_selector","=","SelectFromModel","(","estimator=LogisticRegression","(",")",",","...","max_features=half_callable",")",">",">",">","_","=","half_selector.fit","(","X",",","y",")",">",">",">","half_selector.max_features_","2"]
code: def _check_max_features(self, X):
      if self.max_features is not None:
          n_features = _num_features(X)
  
          if callable(self.max_features):
              max_features = self.max_features(X)
          else:  # int
              max_features = self.max_features
  
          check_scalar(
              max_features,
              "max_features",
              Integral,
              min_val=0,
              max_val=n_features,
          )
          self.max_features_ = max_features
  
imports: from copy import deepcopy
  from numbers import Integral, Real
  import numpy
  from ..base import BaseEstimator, MetaEstimatorMixin, _fit_context, clone
  from ..exceptions import NotFittedError
  from ..utils._param_validation import HasMethods, Interval, Options
  from ..utils._tags import _safe_tags
  from ..utils.metadata_routing import MetadataRouter, MethodMapping, _routing_enabled, process_routing
  from ..utils.metaestimators import available_if
  from ..utils.validation import _num_features, check_is_fitted, check_scalar
  from ._base import SelectorMixin, _get_feature_importances
label_desc: Use image node_id 3 for calling the SelectFromModel obj's underlying member method code with example usage: obj._check_max_features(X) without return types