安装
关于安装scikit-learn,建议通过使用anaconda来进行安装,不用担心各种配置和环境问题。当然也可以直接pip来安装:
pip install scikit-learn
数据集生成
sklearn内置了一些优秀的数据集,比如:Iris数据、房价数据、泰坦尼克数据等。
import pandas as pd import numpy as np import sklearn from sklearn import datasets # 导入数据集
分类数据-iris数据
# iris数据 iris = datasets.load_iris() type(iris) sklearn.utils.Bunch
iris数据到底是什么样子?每个内置的数据都存在很多的信息
![06.Scikit-Learn教程](https://caovan.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
![06.Scikit-Learn教程](https://caovan.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
![06.Scikit-Learn教程](https://caovan.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
![06.Scikit-Learn教程](https://caovan.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
可以将上面的数据生成我们想看到的DataFrame,还可以添加因变量:
![06.Scikit-Learn教程](https://caovan.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
![06.Scikit-Learn教程](https://caovan.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
原创文章,作者:朋远方,如若转载,请注明出处:https://caovan.com/06-scikit-learnjiaocheng/.html