Python uses the MinMaxScaler, StandardScaler, and RobustScaler functions of Feature engine for data standardization
Preparation work:
Firstly, it is necessary to ensure that Python has been installed and the relevant environment has been configured.
2. Install the Feature engine library: You can install it by running 'pip install feature engine' from the command line.
Dependent class libraries:
1. Feature engine: A library for data preprocessing.
Here is an example to illustrate how to use the MinMaxScaler, StandardScaler, and RobustScaler functions in the Feature engine library to standardize data.
Data sample:
Suppose we have a dataset containing numerical features, which have three features: 'Age', 'Height', and 'Weight'.
The complete Python code is as follows:
python
import pandas as pd
from sklearn.datasets import load_boston
from sklearn.model_selection import train_test_split
from feature_engine import transformation as vt
#Load Dataset
data = load_boston()
df = pd.DataFrame(data.data, columns=data.feature_names)
#Divide the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(df, data.target, test_size=0.2, random_state=42)
#Standardize data using the MinMaxScaler function in the Feature engine library
scaler = vt.MinMaxScaler(variables=['Age', 'Height', 'Weight'])
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)
#Standardize data using the StandardScaler function in the Feature engine library
scaler = vt.StandardScaler(variables=['Age', 'Height', 'Weight'])
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)
#Standardize data using the RobustScaler function in the Feature engine library
scaler = vt.RobustScaler(variables=['Age', 'Height', 'Weight'])
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)
Summary:
Firstly, we need to load the dataset and divide it into training and testing sets.
Then, we use the MinMaxScaler, StandardScaler, and RobustScaler functions in the Feature engine library to standardize the data.
For each standardized function, we need to specify the features that need to be standardized.
4. Finally, we can use fit_ The transform method is used to fit and transform the training set, and the transform method is used to transform the test set.
By using the standardization function of the Feature engine library, data can be easily standardized to improve the performance of machine learning models.