def scale_data(X, scaler=None):
""" Scale X with robust scaling.
Args:
X (np.array): feature matrix indexed by binID.
scaler (RobustScaler): pre-trained scaler. Default is None
Returns:
np.array: normalized feature matrix.
RobustScaler: robust scaler fitted with training data,
only returned when there is no pre-trained scaler.
"""
if scaler is not None:
return scaler.transform(X)
else:
scaler = RobustScaler(copy=False)
scaler.fit(X)
return scaler.transform(X), scaler
评论列表
文章目录