本文整理匯總了Python中sklearn.preprocessing.MaxAbsScaler方法的典型用法代碼示例。如果您正苦於以下問題:Python preprocessing.MaxAbsScaler方法的具體用法?Python preprocessing.MaxAbsScaler怎麽用?Python preprocessing.MaxAbsScaler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sklearn.preprocessing
的用法示例。
在下文中一共展示了preprocessing.MaxAbsScaler方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_01_xgb_classifier
# 需要導入模塊: from sklearn import preprocessing [as 別名]
# 或者: from sklearn.preprocessing import MaxAbsScaler [as 別名]
def test_01_xgb_classifier(self):
print("\ntest 01 (xgb classifier with preprocessing) [multi-class]\n")
model = XGBClassifier()
pipeline_obj = Pipeline([
('scaler',MaxAbsScaler()),
("model", model)
])
pipeline_obj.fit(self.X,self.Y)
file_name = "test01xgboost.pmml"
xgboost_to_pmml(pipeline_obj, self.features, 'Species', file_name)
model_name = self.adapa_utility.upload_to_zserver(file_name)
predictions, probabilities = self.adapa_utility.score_in_zserver(model_name, self.test_file)
model_pred = pipeline_obj.predict(self.X)
model_prob = pipeline_obj.predict_proba(self.X)
self.assertEqual(self.adapa_utility.compare_predictions(predictions, model_pred), True)
self.assertEqual(self.adapa_utility.compare_probability(probabilities, model_prob), True)
示例2: test_02_lgbm_classifier
# 需要導入模塊: from sklearn import preprocessing [as 別名]
# 或者: from sklearn.preprocessing import MaxAbsScaler [as 別名]
def test_02_lgbm_classifier(self):
print("\ntest 02 (lgbm classifier with preprocessing) [multi-class]\n")
model = LGBMClassifier()
pipeline_obj = Pipeline([
('scaler',MaxAbsScaler()),
("model", model)
])
pipeline_obj.fit(self.X,self.Y)
file_name = "test02lgbm.pmml"
lgb_to_pmml(pipeline_obj, self.features, 'Species', file_name)
model_name = self.adapa_utility.upload_to_zserver(file_name)
predictions, probabilities = self.adapa_utility.score_in_zserver(model_name, self.test_file)
model_pred = pipeline_obj.predict(self.X)
model_prob = pipeline_obj.predict_proba(self.X)
self.assertEqual(self.adapa_utility.compare_predictions(predictions, model_pred), True)
self.assertEqual(self.adapa_utility.compare_probability(probabilities, model_prob), True)
示例3: train_model
# 需要導入模塊: from sklearn import preprocessing [as 別名]
# 或者: from sklearn.preprocessing import MaxAbsScaler [as 別名]
def train_model(self, train_file_path, model_path):
print("==> Load the data ...")
X_train, Y_train = self.load_file(train_file_path)
print(train_file_path, shape(X_train))
print("==> Train the model ...")
min_max_scaler = preprocessing.MaxAbsScaler()
X_train_minmax = min_max_scaler.fit_transform(X_train)
clf = RandomForestRegressor(n_estimators=self.n_estimators)
clf.fit(X_train_minmax.toarray(), Y_train)
print("==> Save the model ...")
pickle.dump(clf, open(model_path, 'wb'))
scaler_path = model_path.replace('.pkl', '.scaler.pkl')
pickle.dump(min_max_scaler, open(scaler_path, 'wb'))
return clf
示例4: normalize_cv
# 需要導入模塊: from sklearn import preprocessing [as 別名]
# 或者: from sklearn.preprocessing import MaxAbsScaler [as 別名]
def normalize_cv(X, y, i, norm="zero_score"):
X_test = X[i]
y_test = y[i]
X_train = pd.concat(X[:i] + X[i+1:])
y_train = pd.concat(y[:i] + y[i+1:])
if norm == "min_max":
scaler = preprocessing.MinMaxScaler()
elif norm == "max_abs":
scaler = preprocessing.MaxAbsScaler()
else:
scaler = preprocessing.StandardScaler()
X_train = pd.DataFrame(scaler.fit_transform(X_train),
index=y_train.index.values)
X_train.columns = X[i].columns.values
X_test = pd.DataFrame(scaler.transform(X_test), index=y_test.index.values)
X_test.columns = X[i].columns.values
return X_train, X_test, y_train, y_test
示例5: transform
# 需要導入模塊: from sklearn import preprocessing [as 別名]
# 或者: from sklearn.preprocessing import MaxAbsScaler [as 別名]
def transform(self, X):
"""Scale the data.
Parameters
----------
X : array-like, shape = (n_samples, n_timestamps)
Data to scale.
Returns
-------
X_new : array-like, shape = (n_samples, n_timestamps)
Scaled data.
"""
X = check_array(X, dtype='float64')
scaler = SklearnMaxAbsScaler()
X_new = scaler.fit_transform(X.T).T
return X_new
示例6: test_objectmapper
# 需要導入模塊: from sklearn import preprocessing [as 別名]
# 或者: from sklearn.preprocessing import MaxAbsScaler [as 別名]
def test_objectmapper(self):
df = pdml.ModelFrame([])
self.assertIs(df.preprocessing.Binarizer, pp.Binarizer)
self.assertIs(df.preprocessing.FunctionTransformer,
pp.FunctionTransformer)
self.assertIs(df.preprocessing.Imputer, pp.Imputer)
self.assertIs(df.preprocessing.KernelCenterer, pp.KernelCenterer)
self.assertIs(df.preprocessing.LabelBinarizer, pp.LabelBinarizer)
self.assertIs(df.preprocessing.LabelEncoder, pp.LabelEncoder)
self.assertIs(df.preprocessing.MultiLabelBinarizer, pp.MultiLabelBinarizer)
self.assertIs(df.preprocessing.MaxAbsScaler, pp.MaxAbsScaler)
self.assertIs(df.preprocessing.MinMaxScaler, pp.MinMaxScaler)
self.assertIs(df.preprocessing.Normalizer, pp.Normalizer)
self.assertIs(df.preprocessing.OneHotEncoder, pp.OneHotEncoder)
self.assertIs(df.preprocessing.PolynomialFeatures, pp.PolynomialFeatures)
self.assertIs(df.preprocessing.RobustScaler, pp.RobustScaler)
self.assertIs(df.preprocessing.StandardScaler, pp.StandardScaler)
示例7: load_data
# 需要導入模塊: from sklearn import preprocessing [as 別名]
# 或者: from sklearn.preprocessing import MaxAbsScaler [as 別名]
def load_data():
data_path = args['in']
df = (pd.read_csv(data_path,skiprows=1).values).astype('float32')
df_y = df[:,0].astype('float32')
df_x = df[:, 1:PL].astype(np.float32)
# scaler = MaxAbsScaler()
scaler = StandardScaler()
df_x = scaler.fit_transform(df_x)
X_train, X_test, Y_train, Y_test = train_test_split(df_x, df_y, test_size= 0.20, random_state=42)
print('x_train shape:', X_train.shape)
print('x_test shape:', X_test.shape)
return X_train, Y_train, X_test, Y_test
示例8: sparse_normalize_dataset
# 需要導入模塊: from sklearn import preprocessing [as 別名]
# 或者: from sklearn.preprocessing import MaxAbsScaler [as 別名]
def sparse_normalize_dataset(dataset):
""" Normaliza dataset without removing the sparseness structure of the data """
#Remove mean of dataset
dataset = dataset - np.mean(dataset)
#Truncate to +/-3 standard deviations and scale to -1 to 1
std_dev = 3 * np.std(dataset)
dataset = np.maximum(np.minimum(dataset, std_dev), -std_dev) / std_dev
#Rescale from [-1, 1] to [0.1, 0.9]
dataset = (dataset + 1) * 0.4 + 0.1
#dataset = (dataset-np.amin(dataset))/(np.amax(dataset)-np.amin(dataset))
return dataset
#return preprocessing.MaxAbsScaler().fit_transform(dataset)
示例9: scale_by_max_value
# 需要導入模塊: from sklearn import preprocessing [as 別名]
# 或者: from sklearn.preprocessing import MaxAbsScaler [as 別名]
def scale_by_max_value(X):
"""
Scale each feature by its abs maximum value.
Keyword arguments:
X -- The feature vectors
"""
if verbose:
print '\nScaling to the range [-1,1] ...'
max_abs_scaler = preprocessing.MaxAbsScaler()
return max_abs_scaler.fit_transform(X)
示例10: normalize
# 需要導入模塊: from sklearn import preprocessing [as 別名]
# 或者: from sklearn.preprocessing import MaxAbsScaler [as 別名]
def normalize(data, norm="zero_score", scaler=None):
"""Normalize pandas Dataframe.
@param data: Input dataframe
@param norm: normalization method [default: zero_score standardization],
alternatives: 'min_max', 'max_abs'
@return datascaled: normalized dataframe
"""
if scaler is not None:
datascaled = pd.DataFrame(scaler.transform(data),
index=data.index.values)
datascaled.columns = data.columns.values
else:
if norm == "min_max":
scaler = preprocessing.MinMaxScaler()
elif norm == "max_abs":
scaler = preprocessing.MaxAbsScaler()
else:
scaler = preprocessing.StandardScaler()
datascaled = pd.DataFrame(scaler.fit_transform(data),
index=data.index.values)
datascaled.columns = data.columns.values
return datascaled, scaler
# deprecated - use sklearn.model_selection.train_test_split instead
示例11: _get_feature_scaler
# 需要導入模塊: from sklearn import preprocessing [as 別名]
# 或者: from sklearn.preprocessing import MaxAbsScaler [as 別名]
def _get_feature_scaler(self):
"""Get a feature value scaler based on the model settings"""
if self.config.model_settings is None:
scale_type = None
else:
scale_type = self.config.model_settings.get("feature_scaler")
scaler = {
"std-dev": StandardScaler(with_mean=False),
"max-abs": MaxAbsScaler(),
}.get(scale_type)
return scaler
示例12: _get_feature_scaler
# 需要導入模塊: from sklearn import preprocessing [as 別名]
# 或者: from sklearn.preprocessing import MaxAbsScaler [as 別名]
def _get_feature_scaler(scale_type):
"""Get a feature value scaler based on the model settings"""
scaler = {
"std-dev": StandardScaler(with_mean=False),
"max-abs": MaxAbsScaler(),
}.get(scale_type)
return scaler
示例13: scale
# 需要導入模塊: from sklearn import preprocessing [as 別名]
# 或者: from sklearn.preprocessing import MaxAbsScaler [as 別名]
def scale(df, scaling=None):
"""Scale data included in pandas dataframe.
Parameters
----------
df : pandas dataframe
dataframe to scale
scaling : 'maxabs', 'minmax', 'std', or None, optional (default 'std')
type of scaling to apply
"""
if scaling is None or scaling.lower() == 'none':
return df
df = df.dropna(axis=1, how='any')
# Scaling data
if scaling == 'maxabs':
# Normalizing -1 to 1
scaler = MaxAbsScaler()
elif scaling == 'minmax':
# Scaling to [0,1]
scaler = MinMaxScaler()
else:
# Standard normalization
scaler = StandardScaler()
mat = df.as_matrix()
mat = scaler.fit_transform(mat)
df = pd.DataFrame(mat, columns=df.columns)
return df
示例14: impute_and_scale
# 需要導入模塊: from sklearn import preprocessing [as 別名]
# 或者: from sklearn.preprocessing import MaxAbsScaler [as 別名]
def impute_and_scale(df, scaling='std'):
"""Impute missing values with mean and scale data included in pandas dataframe.
Parameters
----------
df : pandas dataframe
dataframe to impute and scale
scaling : 'maxabs' [-1,1], 'minmax' [0,1], 'std', or None, optional (default 'std')
type of scaling to apply
"""
df = df.dropna(axis=1, how='all')
#imputer = Imputer(strategy='mean', axis=0)
imputer = Imputer(strategy='mean')
mat = imputer.fit_transform(df)
if scaling is None or scaling.lower() == 'none':
return pd.DataFrame(mat, columns=df.columns)
if scaling == 'maxabs':
scaler = MaxAbsScaler()
elif scaling == 'minmax':
scaler = MinMaxScaler()
else:
scaler = StandardScaler()
mat = scaler.fit_transform(mat)
df = pd.DataFrame(mat, columns=df.columns)
return df
示例15: impute_and_scale
# 需要導入模塊: from sklearn import preprocessing [as 別名]
# 或者: from sklearn.preprocessing import MaxAbsScaler [as 別名]
def impute_and_scale(df, scaling='std'):
"""Impute missing values with mean and scale data included in pandas dataframe.
Parameters
----------
df : pandas dataframe
dataframe to impute and scale
scaling : 'maxabs' [-1,1], 'minmax' [0,1], 'std', or None, optional (default 'std')
type of scaling to apply
"""
df = df.dropna(axis=1, how='all')
imputer = Imputer(strategy='mean')
mat = imputer.fit_transform(df)
if scaling is None or scaling.lower() == 'none':
return pd.DataFrame(mat, columns=df.columns)
if scaling == 'maxabs':
scaler = MaxAbsScaler()
elif scaling == 'minmax':
scaler = MinMaxScaler()
else:
scaler = StandardScaler()
mat = scaler.fit_transform(mat)
df = pd.DataFrame(mat, columns=df.columns)
return df