pub struct PyStandardScaler { /* private fields */ }Expand description
Standardize features by removing the mean and scaling to unit variance.
The standard score of a sample x is calculated as:
z = (x - u) / swhere u is the mean of the training samples or zero if with_mean=False,
and s is the standard deviation of the training samples or one if
with_std=False.
Centering and scaling happen independently on each feature by computing
the relevant statistics on the samples in the training set. Mean and
standard deviation are then stored to be used on later data using
:meth:transform.
Standardization of a dataset is a common requirement for many machine learning estimators: they might behave badly if the individual features do not more or less look like standard normally distributed data (e.g. Gaussian with 0 mean and unit variance).
§Parameters
copy : bool, default=True If False, try to avoid a copy and do inplace scaling instead. This is not guaranteed to always work inplace; e.g. if the data is not a NumPy array or scipy.sparse CSR matrix, a copy may still be returned.
with_mean : bool, default=True If True, center the data before scaling. This does not work (and will raise an exception) when attempted on sparse matrices, because centering them entails building a dense matrix which in common use cases is likely to be too large to fit in memory.
with_std : bool, default=True If True, scale the data to unit variance (or equivalently, unit standard deviation).
§Attributes
scale_ : ndarray of shape (n_features,) or None
Per feature relative scaling of the data to achieve zero mean and unit
variance. Generally this is calculated using np.sqrt(var_). If a
variance is zero, we can’t achieve unit variance, and the data is left
as-is, giving a scaling factor of 1. scale_ is equal to None
when with_std=False.
mean_ : ndarray of shape (n_features,) or None
The mean value for each feature in the training set.
Equal to None when with_mean=False.
var_ : ndarray of shape (n_features,) or None
The variance for each feature in the training set. Used to compute
scale_. Equal to None when with_std=False.
n_features_in_ : int
Number of features seen during :term:fit.
n_samples_seen_ : int
The number of samples processed by the estimator.
It will be reset on new calls to fit, but increments across
partial_fit calls.
§Examples
from sklears_python import StandardScaler import numpy as np data = [[0, 0], [0, 0], [1, 1], [1, 1]] scaler = StandardScaler() scaler.fit(data) StandardScaler() print(scaler.mean_) [0.5 0.5] print(scaler.transform(data)) [[-1. -1.] [-1. -1.] [ 1. 1.] [ 1. 1.]] print(scaler.transform([[2, 2]])) [[3. 3.]]
Trait Implementations§
impl DerefToPyAny for PyStandardScaler
impl ExtractPyClassWithClone for PyStandardScaler
Source§impl<'py> IntoPyObject<'py> for PyStandardScaler
impl<'py> IntoPyObject<'py> for PyStandardScaler
Source§type Target = PyStandardScaler
type Target = PyStandardScaler
Source§type Output = Bound<'py, <PyStandardScaler as IntoPyObject<'py>>::Target>
type Output = Bound<'py, <PyStandardScaler as IntoPyObject<'py>>::Target>
Source§fn into_pyobject(
self,
py: Python<'py>,
) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
Source§impl PyClass for PyStandardScaler
impl PyClass for PyStandardScaler
Source§impl PyClassImpl for PyStandardScaler
impl PyClassImpl for PyStandardScaler
Source§const MODULE: Option<&str> = ::core::option::Option::None
const MODULE: Option<&str> = ::core::option::Option::None
Source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§const IS_IMMUTABLE_TYPE: bool = false
const IS_IMMUTABLE_TYPE: bool = false
Source§const RAW_DOC: &'static CStr = /// Standardize features by removing the mean and scaling to unit variance.
///
/// The standard score of a sample `x` is calculated as:
///
/// ```text
/// z = (x - u) / s
/// ```
///
/// where `u` is the mean of the training samples or zero if `with_mean=False`,
/// and `s` is the standard deviation of the training samples or one if
/// `with_std=False`.
///
/// Centering and scaling happen independently on each feature by computing
/// the relevant statistics on the samples in the training set. Mean and
/// standard deviation are then stored to be used on later data using
/// :meth:`transform`.
///
/// Standardization of a dataset is a common requirement for many
/// machine learning estimators: they might behave badly if the
/// individual features do not more or less look like standard normally
/// distributed data (e.g. Gaussian with 0 mean and unit variance).
///
/// Parameters
/// ----------
/// copy : bool, default=True
/// If False, try to avoid a copy and do inplace scaling instead.
/// This is not guaranteed to always work inplace; e.g. if the data is
/// not a NumPy array or scipy.sparse CSR matrix, a copy may still be
/// returned.
///
/// with_mean : bool, default=True
/// If True, center the data before scaling.
/// This does not work (and will raise an exception) when attempted on
/// sparse matrices, because centering them entails building a dense
/// matrix which in common use cases is likely to be too large to fit in
/// memory.
///
/// with_std : bool, default=True
/// If True, scale the data to unit variance (or equivalently,
/// unit standard deviation).
///
/// Attributes
/// ----------
/// scale_ : ndarray of shape (n_features,) or None
/// Per feature relative scaling of the data to achieve zero mean and unit
/// variance. Generally this is calculated using `np.sqrt(var_)`. If a
/// variance is zero, we can't achieve unit variance, and the data is left
/// as-is, giving a scaling factor of 1. `scale_` is equal to `None`
/// when `with_std=False`.
///
/// mean_ : ndarray of shape (n_features,) or None
/// The mean value for each feature in the training set.
/// Equal to ``None`` when ``with_mean=False``.
///
/// var_ : ndarray of shape (n_features,) or None
/// The variance for each feature in the training set. Used to compute
/// `scale_`. Equal to ``None`` when ``with_std=False``.
///
/// n_features_in_ : int
/// Number of features seen during :term:`fit`.
///
/// n_samples_seen_ : int
/// The number of samples processed by the estimator.
/// It will be reset on new calls to fit, but increments across
/// ``partial_fit`` calls.
///
/// Examples
/// --------
/// >>> from sklears_python import StandardScaler
/// >>> import numpy as np
/// >>> data = [[0, 0], [0, 0], [1, 1], [1, 1]]
/// >>> scaler = StandardScaler()
/// >>> scaler.fit(data)
/// StandardScaler()
/// >>> print(scaler.mean_)
/// [0.5 0.5]
/// >>> print(scaler.transform(data))
/// [[-1. -1.]
/// [-1. -1.]
/// [ 1. 1.]
/// [ 1. 1.]]
/// >>> print(scaler.transform([[2, 2]]))
/// [[3. 3.]]
const RAW_DOC: &'static CStr = /// Standardize features by removing the mean and scaling to unit variance. /// /// The standard score of a sample `x` is calculated as: /// /// ```text /// z = (x - u) / s /// ``` /// /// where `u` is the mean of the training samples or zero if `with_mean=False`, /// and `s` is the standard deviation of the training samples or one if /// `with_std=False`. /// /// Centering and scaling happen independently on each feature by computing /// the relevant statistics on the samples in the training set. Mean and /// standard deviation are then stored to be used on later data using /// :meth:`transform`. /// /// Standardization of a dataset is a common requirement for many /// machine learning estimators: they might behave badly if the /// individual features do not more or less look like standard normally /// distributed data (e.g. Gaussian with 0 mean and unit variance). /// /// Parameters /// ---------- /// copy : bool, default=True /// If False, try to avoid a copy and do inplace scaling instead. /// This is not guaranteed to always work inplace; e.g. if the data is /// not a NumPy array or scipy.sparse CSR matrix, a copy may still be /// returned. /// /// with_mean : bool, default=True /// If True, center the data before scaling. /// This does not work (and will raise an exception) when attempted on /// sparse matrices, because centering them entails building a dense /// matrix which in common use cases is likely to be too large to fit in /// memory. /// /// with_std : bool, default=True /// If True, scale the data to unit variance (or equivalently, /// unit standard deviation). /// /// Attributes /// ---------- /// scale_ : ndarray of shape (n_features,) or None /// Per feature relative scaling of the data to achieve zero mean and unit /// variance. Generally this is calculated using `np.sqrt(var_)`. If a /// variance is zero, we can't achieve unit variance, and the data is left /// as-is, giving a scaling factor of 1. `scale_` is equal to `None` /// when `with_std=False`. /// /// mean_ : ndarray of shape (n_features,) or None /// The mean value for each feature in the training set. /// Equal to ``None`` when ``with_mean=False``. /// /// var_ : ndarray of shape (n_features,) or None /// The variance for each feature in the training set. Used to compute /// `scale_`. Equal to ``None`` when ``with_std=False``. /// /// n_features_in_ : int /// Number of features seen during :term:`fit`. /// /// n_samples_seen_ : int /// The number of samples processed by the estimator. /// It will be reset on new calls to fit, but increments across /// ``partial_fit`` calls. /// /// Examples /// -------- /// >>> from sklears_python import StandardScaler /// >>> import numpy as np /// >>> data = [[0, 0], [0, 0], [1, 1], [1, 1]] /// >>> scaler = StandardScaler() /// >>> scaler.fit(data) /// StandardScaler() /// >>> print(scaler.mean_) /// [0.5 0.5] /// >>> print(scaler.transform(data)) /// [[-1. -1.] /// [-1. -1.] /// [ 1. 1.] /// [ 1. 1.]] /// >>> print(scaler.transform([[2, 2]])) /// [[3. 3.]]
Source§const DOC: &'static CStr
const DOC: &'static CStr
text_signature if a constructor is defined. Read moreSource§type Layout = <<PyStandardScaler as PyClassImpl>::BaseNativeType as PyClassBaseType>::Layout<PyStandardScaler>
type Layout = <<PyStandardScaler as PyClassImpl>::BaseNativeType as PyClassBaseType>::Layout<PyStandardScaler>
Source§type ThreadChecker = NoopThreadChecker
type ThreadChecker = NoopThreadChecker
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny by default, and when you declare
#[pyclass(extends=PyDict)], it’s PyDict.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
Source§fn dict_offset() -> Option<PyObjectOffset>
fn dict_offset() -> Option<PyObjectOffset>
Source§fn weaklist_offset() -> Option<PyObjectOffset>
fn weaklist_offset() -> Option<PyObjectOffset>
Source§impl PyClassNewTextSignature for PyStandardScaler
impl PyClassNewTextSignature for PyStandardScaler
const TEXT_SIGNATURE: &'static str = "(copy=True, with_mean=True, with_std=True)"
Source§impl PyMethods<PyStandardScaler> for PyClassImplCollector<PyStandardScaler>
impl PyMethods<PyStandardScaler> for PyClassImplCollector<PyStandardScaler>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for PyStandardScaler
impl PyTypeInfo for PyStandardScaler
Source§const NAME: &str = <Self as ::pyo3::PyClass>::NAME
const NAME: &str = <Self as ::pyo3::PyClass>::NAME
prefer using ::type_object(py).name() to get the correct runtime value
Source§const MODULE: Option<&str> = <Self as ::pyo3::impl_::pyclass::PyClassImpl>::MODULE
const MODULE: Option<&str> = <Self as ::pyo3::impl_::pyclass::PyClassImpl>::MODULE
prefer using ::type_object(py).module() to get the correct runtime value
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
Source§fn type_object(py: Python<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
Auto Trait Implementations§
impl Freeze for PyStandardScaler
impl RefUnwindSafe for PyStandardScaler
impl Send for PyStandardScaler
impl Sync for PyStandardScaler
impl Unpin for PyStandardScaler
impl UnsafeUnpin for PyStandardScaler
impl UnwindSafe for PyStandardScaler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
Source§fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
self into an owned Python object, dropping type information.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PyErrArguments for T
impl<T> PyErrArguments for T
Source§impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.