def rescale(data, _min, _max, start=0.0, end=1.0, axis=0):
"""Rescale features of a dataset
args:
data (np.array): feature matrix.
_min (np.array): list of minimum values per feature.
_max (np.array): list of maximum values per feature.
start (float = 0.): lowest value for norm.
end (float = 1.): highest value for norm.
axis (int = 0): axis to normalize across
returns:
(np.array): normalized features, the same shape as data
"""
new_data = (data - _min) / (_max - _min)
# check if feature is constant, will be nan in new_data
np.place(new_data, np.isnan(new_data), 1)
new_data = (end - start) * new_data + start
return new_data
评论列表
文章目录