机器学习模型总结(机器学习模型五花八门不知道怎么选)(1)

来源:授权自AI科技大本营(ID:rgznai100)

本文约4900字,建议阅读10分钟。

本文我们将探讨不同的机器学习模型,以及每个模型合理的使用场景。

机器学习模型总结(机器学习模型五花八门不知道怎么选)(2)

[ 导读 ] 一般来说,基于树形结构的模型在Kaggle竞赛中是表现最好的,而其它的模型可以用于融合模型。对于计算机视觉领域的挑战,CNNs (Convolutional Neural Network, 卷积神经网络)是最适合不过的。而对于NLP(Natural Language Processing,自然语言处理),LSTMs或GRUs是最好的选择。下面是一个不完全模型细目清单,同时列出了每个模型的一些优缺点。

1. 回归 — 预测连续值

A. 线性回归(Linear Regression)

B. 回归树(Regression Trees)

C. 深度学习(Deep Learning)

D. 基于距离的K近邻算法(K Nearest Neighbors – Distance Based)

2. 分类 — 预测一个或多个类别的概率

A. 逻辑回归算法(logistic Regression)

B. 基于距离的支持向量机算法(Support Vector Machines – Distance based)

C. 基于概率的朴素贝叶斯算法(Naive Bayes — Probability based)

D. 基于距离的K近邻算法( K Nearest Neighbors — Distance Based)

E. 分类树(Classification Tree)

F. 深度学习(Deep Learning)

3. 聚类 — 将数据分类以便最大化相似性

A. DBSCAN聚类算法(Density-Based Spatial Clustering of Applications with Noise)

B. Kmeans算法

4. Misc — 本文中未包含的模型

融合模型

融合模型是一种非常强大的技术,有助于减少过度拟合,并通过组合来自不同模型的输出以做出更稳定的预测。融合模型是赢得Kaggle竞赛的一个重要工具,在选择模型进行融合时,我们希望选择不同类型的模型,以确保它们具有不同的优势和劣势,从而在数据集中获取不同的模式。这种更明显的多样性特点使得偏差降低。我们还希望确保它们的性能是可以对比的,这样就能确保预测的稳定性。

我们在这里可以看到,这些模型的融合实际上比任何单一的模型生成的损失都要低得多。部分的原因是,尽管所有的这些模型都非常擅长预测,但它们都能得到不同的正确预测结果,通过把它们组合在一起,我们能够根据它们所有不同的优势组合成一个超级模型。

机器学习模型总结(机器学习模型五花八门不知道怎么选)(3)

# in order to make the final predictions more robust to overfittingdef blended_predictions(X): return ((0.1 * ridge_model_full_data.predict(X)) \\ (0.2 * svr_model_full_data.predict(X)) \\ (0.1 * gbr_model_full_data.predict(X)) \\ (0.1 * xgb_model_full_data.predict(X)) \\ (0.1 * lgb_model_full_data.predict(X)) \\ (0.05 * rf_model_full_data.predict(X)) \\ (0.35 * stack_gen_model.predict(np.array(X))))

融合模型分为四种类型(包括混合型):

模型对比

权重和偏差让我们可以用一行代码来跟踪和比较模型的性能表现。选择要测试的模型后,对其进行训练并添加wandb.log({‘score’: cv_score})来记录模型的运行状态。完成训练之后,你就可以在一个简单的控制台中对比模型的性能了!

# WandBimport wandbimport tensorflow.kerasfrom wandb.keras import WandbCallbackfrom sklearn.model_selection import cross_val_score# Import models (Step 1: add your models here)from sklearn import svmfrom sklearn.linear_model import Ridge, RidgeCVfrom xgboost import XGBRegressor# Model 1# Initialize wandb run# You can change your project name here. For more config options, see https://docs.wandb.com/docs/init.htmlwandb.init(anonymous='allow', project="pick-a-model")# Initialize model (Step 2: add your classifier here)clf = svm.SVR(C= 20, epsilon= 0.008, gamma=0.0003)# Get CV scorescv_scores = cross_val_score(clf, X_train, train_labels, cv=5)# Log scoresfor cv_score in cv_scores: wandb.log({'score': cv_score})# Model 2# Initialize wandb run# You can change your project name here. For more config options, see https://docs.wandb.com/docs/init.htmlwandb.init(anonymous='allow', project="pick-a-model")# Initialize model (Step 2: add your classifier here)clf = XGBRegressor(learning_rate=0.01, n_estimators=6000, max_depth=4, min_child_weight=0, gamma=0.6, subsample=0.7, colsample_bytree=0.7, objective='reg:linear', nthread=-1, scale_pos_weight=1, seed=27, reg_alpha=0.00006, random_state=42)# Get CV scorescv_scores = cross_val_score(clf, X_train, train_labels, cv=5)# Log scoresfor cv_score in cv_scores: wandb.log({'score': cv_score})# Model 3# Initialize wandb run# You can change your project name here. For more config options, see https://docs.wandb.com/docs/init.htmlwandb.init(anonymous='allow', project="pick-a-model")# Initialize model (Step 2: add your classifier here)ridge_alphas = [1e-15, 1e-10, 1e-8, 9e-4, 7e-4, 5e-4, 3e-4, 1e-4, 1e-3, 5e-2, 1e-2, 0.1, 0.3, 1, 3, 5, 10, 15, 18, 20, 30, 50, 75, 100]clf = Ridge(alphas=ridge_alphas)# Get CV scorescv_scores = cross_val_score(clf, X_train, train_labels, cv=5)# Log scoresfor cv_score in cv_scores: wandb.log({'score': cv_score})

就这样,在有了所有的工具和算法之后,就可以为你的问题选择正确的模型了!

模型的选择可能是非常复杂的,但我希望本指南能给你带来一些启发,让你找到模型选择的好方法。

原文链接:

https://lavanya.ai/2019/09/18/part-ii-whirlwind-tour-of-machine-learning-models/

编辑:于腾凯

校对:林亦霖

—完—

关注清华-青岛数据科学研究院官方微信公众平台“ THU数据派 ”及姊妹号“ 数据派THU ”获取更多讲座福利及优质内容。

,