周志洋

个人站

持续学习 才能不被淘汰


Python机器学习-Scikit-learn进阶

管道使用

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进阶

打赏一个呗

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦