scikit-learn学习笔记
参考资料:
python机器学习库scikit-learn简明教程之:随机森林
http://nbviewer.jupyter.org/github/donnemartin/data-science-ipython-notebooks/blob/master/kaggle/titanic.ipynb
scikit-learn sklearn 0.18 官方文档中文版
https://github.com/jakevdp/sklearn_pycon2015
官网:http://scikit-learn.org/stable/
Scikit-learn (sklearn) 优雅地学会机器学习 (莫烦 Python 教程)
python机器学习库scikit-learn简明教程之:AdaBoost算法
http://www.docin.com/p-1775095945.html
https://www.bilibili.com/video/av22530538/?p=6
https://github.com/Fdevmsy/Image_Classification_with_5_methods
https://github.com/huangchuchuan/SVM-HOG-images-classifier
https://blog.csdn.net/always2015/article/details/47100713
DBScan https://www.cnblogs.com/pinard/p/6208966.html
1.KNN的使用
carto@cartoPC:~$ python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> from sklearn import datasets
>>> from sklearn.cross_validation import train_test_split
/usr/local/lib/python2.7/dist-packages/sklearn/cross_validation.py:41: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.
"This module will be removed in 0.20.", DeprecationWarning)
>>> from sklearn.neighbors import KNeighborsClassifier
>>> iris=datasets.load_iris()
>>> iris_X=iris.data
>>> iris_y=iris.target
>>> print(iris_X[:2,:])
[[ 5.1 3.5 1.4 0.2]
[ 4.9 3. 1.4 0.2]]
>>> print(iris_y)
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2]
>>> X_train,X_test,y_train,y_test=train_test_split(iris_X,iris_y,test_size=0.3)
>>> print(y_train)
[2 1 0 0 0 2 0 0 1 1 2 2 1 1 2 2 2 0 1 0 2 2 1 1 1 1 1 0 1 1 0 2 1 0 0 2 2
0 0 2 1 0 0 2 1 2 1 2 1 1 1 2 1 2 0 2 0 1 1 2 1 0 1 2 2 0 2 2 1 0 1 1 2 2
1 0 1 1 2 0 0 1 0 1 0 2 0 1 1 0 2 1 2 0 2 0 2 0 2 1 0 2 0 2 2]
>>> knn=KNeighborsClassifier()
>>> knn.fit()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: fit() takes exactly 3 arguments (1 given)
>>> knn.fit(X_train,y_train)
KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='minkowski',
metric_params=None, n_jobs=1, n_neighbors=5, p=2,
weights='uniform')
>>> print(knn.predict(X_test))
[1 1 2 0 1 1 1 1 2 0 0 2 0 1 0 0 0 1 2 2 2 2 0 1 2 0 1 2 2 0 1 2 0 0 1 0 0
0 0 1 0 1 1 2 0]
>>> print(y_test)
[1 1 2 0 1 1 1 1 2 0 0 2 0 1 0 0 0 1 2 2 2 2 0 1 2 0 1 2 2 0 2 2 0 0 2 0 0
0 0 1 0 1 1 2 0]
>>>
2.SVC的使用
import pandas as pd
import numpy as np
from sklearn import datasets
from sklearn import svm
from sklearn.model_selection import train_test_split
def load_data():
iris=datasets.load_iris()
X_train,X_test,y_train,y_test=train_test_split(
iris.data,iris.target,test_size=0.10,random_state=0)
return X_train,X_test,y_train,y_test def test_LinearSVC(X_train,X_test,y_train,y_test):
cls=svm.LinearSVC()
cls.fit(X_train,y_train)
print('Coefficients:%s, intercept %s'%(cls.coef_,cls.intercept_))
print('Score: %.2f' %cls.score(X_test,y_test)) if __name__=="__main__":
X_train,X_test,y_train,y_test=load_data()
test_LinearSVC(X_train,X_test,y_train,y_test)
调用
carto@cartoPC:~/python_ws$ python svmtest2.py
Coefficients:[[ 0.18424504 0.45123335 -0.80794237 -0.45071267]
[-0.13381099 -0.75235247 0.57223898 -1.11494325]
[-0.7943601 -0.95801711 1.31465593 1.8169808 ]], intercept [ 0.10956304 1.86593164 -1.72576407]
Score: 1.00
scikit-learn学习笔记的更多相关文章
- 机器学习-scikit learn学习笔记
scikit-learn官网:http://scikit-learn.org/stable/ 通常情况下,一个学习问题会包含一组学习样本数据,计算机通过对样本数据的学习,尝试对未知数据进行预测. 学习 ...
- Learning How to Learn学习笔记(转)
add by zhj: 工作中提高自己水平的最重要的一点是——快速的学习能力.这篇文章就是探讨这个问题的,掌握了快速学习能力的规律,你自然就有了快速学习能力了. 原文:Learning How to ...
- The Road to learn React书籍学习笔记(第二章)
The Road to learn React书籍学习笔记(第二章) 组件的内部状态 组件的内部状态也称为局部状态,允许保存.修改和删除在组件内部的属性,使用ES6类组件可以在构造函数中初始化组件的状 ...
- The Road to learn React书籍学习笔记(第三章)
The Road to learn React书籍学习笔记(第三章) 代码详情 声明周期方法 通过之前的学习,可以了解到ES6 类组件中的生命周期方法 constructor() 和 render() ...
- (原创)(三)机器学习笔记之Scikit Learn的线性回归模型初探
一.Scikit Learn中使用estimator三部曲 1. 构造estimator 2. 训练模型:fit 3. 利用模型进行预测:predict 二.模型评价 模型训练好后,度量模型拟合效果的 ...
- (原创)(四)机器学习笔记之Scikit Learn的Logistic回归初探
目录 5.3 使用LogisticRegressionCV进行正则化的 Logistic Regression 参数调优 一.Scikit Learn中有关logistics回归函数的介绍 1. 交叉 ...
- 学习笔记之Model selection and evaluation
学习笔记之scikit-learn - 浩然119 - 博客园 https://www.cnblogs.com/pegasus923/p/9997485.html 3. Model selection ...
- Sublime3学习笔记
学习笔记: 学习内容:sublime 3 学习时间:2015-10-20 预计学习时长:1 hour/3 day 学习工具&资料: 官网:http://www.sublimetext.com/ ...
- Android学习笔记(十七)——数据库操作(下)
//此系列博文是<第一行Android代码>的学习笔记,如有错漏,欢迎指正! 这一次我们来试一试升级数据库,并进行数据库的CRUD操作,其中, C 代表添加(Create) ,R 代表查询 ...
- Coursera台大机器学习基础课程学习笔记1 -- 机器学习定义及PLA算法
最近在跟台大的这个课程,觉得不错,想把学习笔记发出来跟大家分享下,有错误希望大家指正. 一机器学习是什么? 感觉和 Tom M. Mitchell的定义几乎一致, A computer program ...
随机推荐
- oc调用swift的打包.a / framework 不成功?!
https://www.jianshu.com/p/734341f7c242 虽说是Swift和OC混编SDK,但目前只支持项目中使用了Swift调用OC的工程,暂不支持OC调用Swift的工程 ...
- ThinkPHP5配置redis缓存
thinkphp采用cache类提供缓存功能支持,采用驱动方式,在使用缓存之前需要进行初始化操作.支持的缓存类型包括file.memcache.wincache.sqlite.redis和xcache ...
- pandas设置值-【老鱼学pandas】
本节主要讲述如何根据上篇博客中选择出相应的数据之后,对其中的数据进行修改. 对某个值进行修改 例如,我们想对数据集中第2行第2列的数据进行修改: import pandas as pd import ...
- Scala模式匹配| 隐式转换
1. 模式匹配 Scala中的模式匹配类似于Java中的switch语法,但是更加强大.模式匹配语法中,采用match关键字声明,每个分支采用case关键字进行声明,当需要匹配时,会从第一个case分 ...
- pyqt pyside 窗口自动调整大小
pyqt pyside 窗口自动调整大小 在QTimer中一直调整 def initTimer(self): self.resizeTimer = QtCore.QTimer(self) self.r ...
- 此处为当前页,设置此处的href点后没有效果
<%--此处当前页不能点,设置href为没有动作Javascript:void(0); --%> 如果javaScript:void(0);写错了,那就很尴尬(某些浏览器忽略该错误如:谷歌 ...
- Round#534 div.2-B Game with string
唔,第一次参加,掉了好多分. http://codeforces.com/contest/1104/problem/B 不用考虑太多,string真的好厉害. #include<stdio.h& ...
- 2018-2019-1 20189201 《LInux内核原理与分析》第五周作业
甜死人的图片 一.书本第四章知识总结[系统调用的三层机制(上)] 无参数系统调用 依次通过c语言和内嵌汇编的c语言实现time()函数中封装的系统调用. 用户态.内核态和中断 用户态:在低的执行级别下 ...
- Linux 定时任务的配置
通常我们会需要定时启动一些shell脚本,类似Windows中的Task Scheduler, 下面是在AWS EMR Cluster 主几点上配置的步骤: 1. 先创建一个shell脚本,将需要执行 ...
- Linux 内核参数 arp_ignore & arp_announce 详解
arp_ignore定义了对目标地址为本机IP的ARP询问的不同应答模式. arp_announce对网络接口(网卡)上发出的ARP请求包中的源IP地址作出相应的限制:主机会根据这个参数值的不同选择使 ...