参考:https:
from sklearn.feature_selection import SelectFromModel
from sklearn.linear_model import LogisticRegression
from sklearn.feature_selection import RFE
from sklearn.feature_selection import chi2
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import VarianceThreshold
from sklearn.preprocessing import FunctionTransformer
from numpy import log1p
from sklearn.preprocessing import PolynomialFeatures
from sklearn.impute import SimpleImputer as Imputer
from numpy import vstack, array, nan
from sklearn.preprocessing import OneHotEncoder
from sklearn.preprocessing import Binarizer
from sklearn.preprocessing import Normalizer
from sklearn.preprocessing import MinMaxScaler
from sklearn.preprocessing import StandardScaler
from sklearn.datasets import load_iris
iris = load_iris()
iris.data
iris.target
print("original")
print(iris.data)
print("---------------------")
iris1 = StandardScaler().fit_transform(iris.data)
print("after standardlize")
print(iris1)
print("---------------------")
iris2 = MinMaxScaler().fit_transform(iris.data)
print("0-1")
print(iris2)
print("---------------------")
iris3 = Normalizer().fit_transform(iris.data)
print("after normalized")
print(iris3)
print("---------------------")
iris4 = Binarizer(threshold=3).fit_transform(iris.data)
print("after binarized")
print(iris4)
print("---------------------")
iris5 = OneHotEncoder().fit_transform(iris.target.reshape((-1, 1)))
print("after oneHot")
print(iris5)
print("---------------------")
iris6 = vstack((array([nan, nan, nan, nan]), iris.data))
print("add nan nan nan nan to the data:")
print(iris6)
print("---------------------")
iris7 = Imputer().fit_transform(
vstack((array([nan, nan, nan, nan]), iris.data)))
print("after fill the nan with mean:")
print(iris7)
print("---------------------")
iris8 = PolynomialFeatures().fit_transform(iris.data)
print("after PolynomialFeatures:")
print(iris8)
print("---------------------")
iris9 = FunctionTransformer(log1p).fit_transform(iris.data)
print("after FunctionTransformer:")
print(iris9)
print("---------------------")
iris10 = VarianceThreshold(threshold=3).fit_transform(iris.data)
print("VarianceThreshold:")
print(iris10)
print("---------------------")
iris11 = SelectKBest(chi2, k=2).fit_transform(iris.data, iris.target)
print("SelectKBest:")
print(iris11)
print("---------------------")
iris12 = RFE(estimator=LogisticRegression(), n_features_to_select=2).fit_transform(
iris.data, iris.target)
print("features_to_select:")
print(iris12)
print("---------------------")