管道使用
from sklearn.pipeline import Pipeline from sklearn.preprocessing import StandardScaler from sklearn.ensemble import RandomForestClassifier pipeline = Pipeline([ ('scaler', StandardScaler()), ('classifier', RandomForestClassifier()) ]) pipeline.fit(X_train, y_train)
特征工程
from sklearn.feature_selection import SelectKBest, f_classif from sklearn.preprocessing import PolynomialFeatures # 特征选择 selector = SelectKBest(f_classif, k=10) X_selected = selector.fit_transform(X, y) # 多项式特征 poly = PolynomialFeatures(degree=2) X_poly = poly.fit_transform(X)
转载请注明:周志洋的博客 » Python机器学习-Scikit-learn进阶