To normalize features in Python, you can use the MinMaxScaler
class from the sklearn.preprocessing
module. Here's an example of how to do it:
main.py268 chars13 lines
Output:
main.py34 chars4 lines
In this example, the MinMaxScaler
scales the features to a specified range (by default, between 0 and 1). The fit_transform()
method is used to fit the scaler to the data and then transform it. The resulting normalized_data
variable contains the normalized features.
Note that the MinMaxScaler
can also be used on a single feature or a single column of data.
gistlibby LogSnag