Scikit-Learn库已经实现了所有基本机器学习的算法,可以直接调用里面库进行模型构建。

一、逻辑回归

大多数情况下被用来解决分类问题(二元分类),但多类的分类(所谓的一对多方法)也适用。这个算法的优点是对于每一个输出的对象都有一个对应类别的概率。

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))

二、朴素贝叶斯

它也是最有名的机器学习的算法之一,它的主要任务是恢复训练样本的数据分布密度。这个方法通常在多类的分类问题上表现的很好。

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))

三、k-最近邻

kNN(k-最近邻)方法通常用于一个更复杂分类算法的一部分。例如,我们可以用它的估计值做为一个对象的特征。有时候,一个简单的kNN算法在良好选择的特征上会有很出色的表现。当参数(主要是metrics)被设置得当,这个算法在回归问题中通常表现出最好的质量。

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))

四、决策树

分类和回归树(CART)经常被用于这么一类问题,在这类问题中对象有可分类的特征且被用于回归和分类问题。决策树很适用于多类分类。

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))

五、支持向量机

SVM(支持向量机)是最流行的机器学习算法之一,它主要用于分类问题。同样也用于逻辑回归,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))

除了分类和回归问题,Scikit-Learn还有海量的更复杂的算法,包括了聚类, 以及建立混合算法的实现技术,如Bagging和Boosting。

最新文章

  1. C\C++中声明与定义的区别
  2. 不用写Windows服务实现定时器功能(FluentScheduler )
  3. slice,substr和substring的区别
  4. VSS - 版本管理起的学习 AND 使用
  5. 通过RDB还原用户误删除的邮件
  6. POJ 3281 Dining 网络流最大流
  7. Objective C 四舍五入,float处理
  8. 【HDOJ】1088 Write a simple HTML Browser
  9. Filter与Servlet的区别和联系
  10. ssh: connect to host github.com port 22: Connection refused
  11. 运行和控制Nginx
  12. C#封装的websocket协议类
  13. java线程阻塞唤醒的四种方式
  14. UVA1471-Copying Books(二分答案)
  15. TypeScript作业
  16. Linux进程间通信机制
  17. IQ调制原理
  18. 6、tcp_wrapper
  19. how2j网站前端项目——天猫前端(第一次)学习笔记6
  20. 如何用SQL脚本在SQL Server Replication中创建合并复制,以及怎么创建分区合并复制

热门文章

  1. 【APS.NET Core】- 应用程序Startup类介绍
  2. 【Linux】- Ubuntu安装redis,并开启远程访问
  3. 第三部分shell编程3(shell脚本2)
  4. JavaScript中setInterval常见的问题(setInterval第一个参数加引号与不加引号区别)
  5. get computer system mac info in javascript
  6. ajax 请求 后台返回的文件流
  7. 【bzoj2259】[Oibh]新型计算机 堆优化Dijkstra
  8. 【题解】Atcoder AGC#16 E-Poor Turkeys
  9. 洛谷 P2906 [USACO08OPEN]牛的街区Cow Neighborhoods | Set+并查集
  10. 洛谷 P1653 猴子 解题报告