日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

sklearn:sklearn.preprocessing的MinMaxScaler简介、使用方法之详细攻略

發(fā)布時(shí)間:2025/3/21 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 sklearn:sklearn.preprocessing的MinMaxScaler简介、使用方法之详细攻略 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

sklearn:sklearn.preprocessing的MinMaxScaler簡介、使用方法之詳細(xì)攻略

?

目錄

MinMaxScaler簡介

MinMaxScaler函數(shù)解釋

MinMaxScaler底層代碼

MinMaxScaler的使用方法

1、基礎(chǔ)案例


?

?

MinMaxScaler簡介

MinMaxScaler函數(shù)解釋

????"""Transforms features by scaling each feature to a given range.
????
????This estimator scales and translates each feature individually such that it is in the given range on the training set, i.e. between zero and one.
????
????The transformation is given by::
????
????X_std = (X - X.min(axis=0)) / (X.max(axis=0) - X.min(axis=0))
????X_scaled = X_std * (max - min) + min
????
????where min, max = feature_range.
????
????This transformation is often used as an alternative to zero mean, unit variance scaling.
????
????Read more in the :ref:`User Guide <preprocessing_scaler>`.
“”通過將每個特性縮放到給定范圍來轉(zhuǎn)換特性。

這個估計(jì)量對每個特征進(jìn)行了縮放和單獨(dú)轉(zhuǎn)換,使其位于訓(xùn)練集的給定范圍內(nèi),即在0和1之間

變換由::

????X_std = (X - X.min(axis=0)) / (X.max(axis=0) - X.min(axis=0))
????X_scaled = X_std * (max - min) + min

其中,min, max = feature_range。

這種轉(zhuǎn)換經(jīng)常被用來替代零均值,單位方差縮放。

請參閱:ref: ' User Guide ?'。</preprocessing_scaler>
? ? Parameters
? ? ----------
? ? feature_range : tuple (min, max), default=(0, 1)
? ? Desired range of transformed data.
? ??
? ? copy : boolean, optional, default True
? ? Set to False to perform inplace row normalization and avoid a copy (if the input is already a numpy array).
參數(shù)

feature_range: tuple (min, max),默認(rèn)值=(0,1)
所需的轉(zhuǎn)換數(shù)據(jù)范圍。

復(fù)制:布爾值,可選,默認(rèn)為真
設(shè)置為False執(zhí)行插入行規(guī)范化并避免復(fù)制(如果輸入已經(jīng)是numpy數(shù)組)。
? ? Attributes
? ? ----------
? ? min_ : ndarray, shape (n_features,)
? ? Per feature adjustment for minimum.
? ??
? ? scale_ : ndarray, shape (n_features,)
? ? Per feature relative scaling of the data.
? ??
? ? .. versionadded:: 0.17
? ? *scale_* attribute.
? ??
? ? data_min_ : ndarray, shape (n_features,)
? ? Per feature minimum seen in the data
? ??
? ? .. versionadded:: 0.17
? ? *data_min_*
? ??
? ? data_max_ : ndarray, shape (n_features,)
? ? Per feature maximum seen in the data
? ??
? ? .. versionadded:: 0.17
? ? *data_max_*
? ??
? ? data_range_ : ndarray, shape (n_features,)
? ? Per feature range ``(data_max_ - data_min_)`` seen in the data
? ??
? ? .. versionadded:: 0.17
? ? *data_range_*

屬性
?----------
min_: ndarray, shape (n_features,)
每個功能調(diào)整為最小。

scale_: ndarray, shape (n_features,)
每個特征數(shù)據(jù)的相對縮放。

. .versionadded:: 0.17
* scale_ *屬性。

data_min_: ndarray, shape (n_features,)
每個特征在數(shù)據(jù)中出現(xiàn)的最小值

. .versionadded:: 0.17
* data_min_ *

data_max_: ndarray, shape (n_features,)
每個特征在數(shù)據(jù)中出現(xiàn)的最大值


. .versionadded:: 0.17
* data_max_ *
data_range_: ndarray, shape (n_features,)
在數(shù)據(jù)中看到的每個特性范圍' ' (data_max_ - data_min_) ' '


. .versionadded:: 0.17
* data_range_ *

?

MinMaxScaler底層代碼

class MinMaxScaler Found at: sklearn.preprocessing.dataclass MinMaxScaler(BaseEstimator, TransformerMixin):def __init__(self, feature_range=(0, 1), copy=True):self.feature_range = feature_rangeself.copy = copydef _reset(self):"""Reset internal data-dependent state of the scaler, if necessary.__init__ parameters are not touched."""# Checking one attribute is enough, becase they are all set together# in partial_fitif hasattr(self, 'scale_'):del self.scale_del self.min_del self.n_samples_seen_del self.data_min_del self.data_max_del self.data_range_def fit(self, X, y=None):"""Compute the minimum and maximum to be used for later scaling.Parameters----------X : array-like, shape [n_samples, n_features]The data used to compute the per-feature minimum and maximumused for later scaling along the features axis."""# Reset internal state before fittingself._reset()return self.partial_fit(X, y)def partial_fit(self, X, y=None):"""Online computation of min and max on X for later scaling.All of X is processed as a single batch. This is intended for caseswhen `fit` is not feasible due to very large number of `n_samples`or because X is read from a continuous stream.Parameters----------X : array-like, shape [n_samples, n_features]The data used to compute the mean and standard deviationused for later scaling along the features axis.y : Passthrough for ``Pipeline`` compatibility."""feature_range = self.feature_rangeif feature_range[0] >= feature_range[1]:raise ValueError("Minimum of desired feature range must be smaller"" than maximum. Got %s." % str(feature_range))if sparse.issparse(X):raise TypeError("MinMaxScaler does no support sparse input. ""You may consider to use MaxAbsScaler instead.")X = check_array(X, copy=self.copy, warn_on_dtype=True, estimator=self, dtype=FLOAT_DTYPES)data_min = np.min(X, axis=0)data_max = np.max(X, axis=0)# First passif not hasattr(self, 'n_samples_seen_'):self.n_samples_seen_ = X.shape[0]else:data_min = np.minimum(self.data_min_, data_min)data_max = np.maximum(self.data_max_, data_max)self.n_samples_seen_ += X.shape[0] # Next stepsdata_range = data_max - data_minself.scale_ = (feature_range[1] - feature_range[0]) / _handle_zeros_in_scale(data_range)self.min_ = feature_range[0] - data_min * self.scale_self.data_min_ = data_minself.data_max_ = data_maxself.data_range_ = data_rangereturn selfdef transform(self, X):"""Scaling features of X according to feature_range.Parameters----------X : array-like, shape [n_samples, n_features]Input data that will be transformed."""check_is_fitted(self, 'scale_')X = check_array(X, copy=self.copy, dtype=FLOAT_DTYPES)X *= self.scale_X += self.min_return Xdef inverse_transform(self, X):"""Undo the scaling of X according to feature_range.Parameters----------X : array-like, shape [n_samples, n_features]Input data that will be transformed. It cannot be sparse."""check_is_fitted(self, 'scale_')X = check_array(X, copy=self.copy, dtype=FLOAT_DTYPES)X -= self.min_X /= self.scale_return X

?

MinMaxScaler的使用方法

1、基礎(chǔ)案例

>>> from sklearn.preprocessing import MinMaxScaler>>>>>> data = [[-1, 2], [-0.5, 6], [0, 10], [1, 18]]>>> scaler = MinMaxScaler()>>> print(scaler.fit(data))MinMaxScaler(copy=True, feature_range=(0, 1))>>> print(scaler.data_max_)[ 1. 18.]>>> print(scaler.transform(data))[[ 0. 0. ][ 0.25 0.25][ 0.5 0.5 ][ 1. 1. ]]>>> print(scaler.transform([[2, 2]]))[[ 1.5 0. ]]

?

?

?

?

?

?

?

?

?

?

?

總結(jié)

以上是生活随笔為你收集整理的sklearn:sklearn.preprocessing的MinMaxScaler简介、使用方法之详细攻略的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。