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§
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 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§type ThreadChecker = SendablePyClass<PyStandardScaler>
type ThreadChecker = SendablePyClass<PyStandardScaler>
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>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
Source§impl PyClassNewTextSignature<PyStandardScaler> for PyClassImplCollector<PyStandardScaler>
impl PyClassNewTextSignature<PyStandardScaler> for PyClassImplCollector<PyStandardScaler>
fn new_text_signature(self) -> Option<&'static str>
Source§impl<'a, 'py> PyFunctionArgument<'a, 'py, false> for &'a PyStandardScaler
impl<'a, 'py> PyFunctionArgument<'a, 'py, false> for &'a PyStandardScaler
Source§impl<'a, 'py> PyFunctionArgument<'a, 'py, false> for &'a mut PyStandardScaler
impl<'a, 'py> PyFunctionArgument<'a, 'py, false> for &'a mut PyStandardScaler
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§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>
impl DerefToPyAny for PyStandardScaler
Auto Trait Implementations§
impl Freeze for PyStandardScaler
impl RefUnwindSafe for PyStandardScaler
impl Send for PyStandardScaler
impl Sync for PyStandardScaler
impl Unpin 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
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.