TVP

# 机器学习算法的使用以及实践到应用

scikit-learn实现了机器学习的大部分基础算法，让我们快速了解一下。

1.逻辑回归大多数问题都可以归结为二元分类问题。这个算法的优点是可以给出数据所在类别的概

from sklearn import metrics

from sklearn.linear_model import LogisticRegression model = LogisticRegression()

model.fit(X, y)

print(model)

# make predictions

expected = y

predicted = model.predict(X)

# summarize the fit of the model

print(metrics.classification_report(expected, predicted)) print(metrics.confusion_matrix(expected, predicted))

2.朴素贝叶斯这也是著名的机器学习算法，该方法的任务是还原训练样本数据的分布密度，其在多类

from sklearn import metrics

from sklearn.naive_bayes import GaussianNB

model = GaussianNB()

model.fit(X, y)

print(model)

# make predictions

expected = y

predicted = model.predict(X)

# summarize the fit of the model print(metrics.classification_report(expected, predicted)) print(metrics.confusion_matrix(expected, predicted))

3.k近邻

k近邻算法常常被用作是分类算法一部分，比如可以用它来评估特征，在特征选择上我

from sklearn import metrics

from sklearn.neighbors import KNeighborsClassifier

# fit a k-nearest neighbor model to the data

model = KNeighborsClassifier()

model.fit(X, y)

print(model)

# make predictions

expected = y

predicted = model.predict(X)

# summarize the fit of the model print(metrics.classification_report(expected, predicted)) print(metrics.confusion_matrix(expected, predicted))

4.决策树

from sklearn import metrics

from sklearn.tree import DecisionTreeClassifier

# fit a CART model to the data

model = DecisionTreeClassifier()

model.fit(X, y)

print(model)

# make predictions

expected = y

predicted = model.predict(X)

# summarize the fit of the model print(metrics.classification_report(expected, predicted)) print(metrics.confusion_matrix(expected, predicted))

5.支持向量机

SVM是非常流行的机器学习算法，主要用于分类问题，如同逻辑回归问题，它可以使用

from sklearn import metrics

from sklearn.svm import SVC

# fit a SVM model to the data

model = SVC()

model.fit(X, y)

print(model)

# make predictions

expected = y

predicted = model.predict(X)

# summarize the fit of the model print(metrics.classification_report(expected, predicted)) print(metrics.confusion_matrix(expected, predicted))

• 发表于:
• 原文链接https://kuaibao.qq.com/s/20180620G122E300?refer=cp_1026
• 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号（企鹅号）传播渠道之一，根据《腾讯内容开放平台服务协议》转载发布内容。
• 如有侵权，请联系 cloudcommunity@tencent.com 删除。

2021-05-21

2023-07-16

2018-07-16

2018-01-27

2018-05-06

2018-02-19

2021-11-24

2018-03-08

2018-02-09

2019-02-08

2018-06-11

2019-01-30

2023-11-04

2018-12-20

2023-05-03

2018-08-09

2018-07-09

2018-10-23

2018-06-13

2024-01-25