线性回归:鸢尾花数据iris
# encoding: utf-8
from sklearn.linear_model import LogisticRegression
import numpy as np
from sklearn import model_selection
import matplotlib.pyplot as plt
import matplotlib as mpl
from matplotlib import colors
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline
from sklearn.datasets import load_iris #加载数据
data=load_iris()
X ,y=data['data'],data['target']
x=X[:,0:2]
x_train,x_test,y_train,y_test=model_selection.train_test_split(x,y,random_state=1,test_size=0.3) #模型训练
classifier=Pipeline([('sc',StandardScaler()),('clf',LogisticRegression())])
classifier.fit(x_train,y_train.ravel()) #绘图
x1_min, x1_max = x[:, 0].min(), x[:, 0].max()
x2_min, x2_max = x[:, 1].min(), x[:, 1].max()
x1, x2 = np.mgrid[x1_min:x1_max:200j, x2_min:x2_max:200j]
grid_test = np.stack((x1.flat, x2.flat), axis=1)
grid_hat = classifier.predict(grid_test)
grid_hat = grid_hat.reshape(x1.shape) mpl.rcParams['font.sans-serif'] = [u'SimHei']
mpl.rcParams['axes.unicode_minus'] = False
cm_light = mpl.colors.ListedColormap(['#A0FFA0', '#FFA0A0', '#A0A0FF'])
cm_dark = mpl.colors.ListedColormap(['g', 'r', 'b'])
alpha=0.5 plt.pcolormesh(x1, x2, grid_hat, cmap=cm_light)
plt.plot(x[:, 0], x[:, 1], 'o', alpha=alpha, color='blue', markeredgecolor='k')
plt.scatter(x_test[:, 0], x_test[:, 1], s=120, facecolors='none', zorder=10)
plt.xlabel(u'length', fontsize=13)
plt.ylabel(u'width', fontsize=13)
plt.xlim(x1_min, x1_max)
plt.ylim(x2_min, x2_max)
plt.title(u'iris', fontsize=15)
plt.grid()
plt.show()

线性回归:鸢尾花数据iris的更多相关文章
- [机器学习 ]PCA降维--两种实现 : SVD或EVD. 强力总结. 在鸢尾花数据集(iris)实做
PCA降维--两种实现 : SVD或EVD. 强力总结. 在鸢尾花数据集(iris)实做 今天自己实现PCA,从网上看文章的时候,发现有的文章没有搞清楚把SVD(奇异值分解)实现和EVD(特征值分解) ...
- EM 算法-对鸢尾花数据进行聚类
公号:码农充电站pro 主页:https://codeshellme.github.io 之前介绍过K 均值算法,它是一种聚类算法.今天介绍EM 算法,它也是聚类算法,但比K 均值算法更加灵活强大. ...
- 鸢尾花数据集-iris.data
iris.data 5.1,3.5,1.4,0.2,Iris-setosa 4.9,3.0,1.4,0.2,Iris-setosa 4.7,3.2,1.3,0.2,Iris-setosa 4.6,3. ...
- 基于鸢尾花数据的PCA降维处理
- 通俗地说逻辑回归【Logistic regression】算法(二)sklearn逻辑回归实战
前情提要: 通俗地说逻辑回归[Logistic regression]算法(一) 逻辑回归模型原理介绍 上一篇主要介绍了逻辑回归中,相对理论化的知识,这次主要是对上篇做一点点补充,以及介绍sklear ...
- 机器学习实战 | SKLearn最全应用指南
作者:韩信子@ShowMeAI 教程地址:http://www.showmeai.tech/tutorials/41 本文地址:http://www.showmeai.tech/article-det ...
- 主成分分析 —PCA
一.定义 主成分分析(principal components analysis)是一种无监督的降维算法,一般在应用其他算法前使用,广泛应用于数据预处理中.其在保证损失少量信息的前提下,把多个指标转化 ...
- 【R笔记】apply函数族
(1) apply apply函数通过对数组,矩阵,或非空维数值的数据框的“边缘”(margin)即行或列运用函数.返回值为向量,数组或列表. 函数形式 apply(X, MARGIN, ...
- 05-01 seaborn
1.Seaborn 在上节中我们学习了matplotlib,这节课我们来看看另一个可视化的模块seaborn,它是基于matplotlib的更高级的开源库,主要用作于数据可视化,解决了matplotl ...
随机推荐
- 错误信息: Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
这个错误主要原因是:数据库的配置出问题,比如写错库名什么的,仔细检查下.
- Tensorflow细节-P174-真正的图像预处理
注意这里的读取image_raw_data = tf.gfile.FastGFile("./datasets/cat.jpg", "rb").read(),写入 ...
- 【CSP游记S】
简略:初三小蒟蒻本想体验一下提高,结果尝到了省选的滋味.fclose没有打,目前不知道会不会有影响,很伤心. day 1 大早上的6:30起床天好黑啊~,想起这次没有面包吃,到华生园买了包熊博士(毕竟 ...
- 六.搭建基本的Web服务
1.安装httpd软件包 ]# yum -y install httpd 2.重起httpd服务 ]# systemctl restart httpd ]# systemctl enable http ...
- shell编程题(一)
求2个数之和 #!/bin/bash function add { )); then echo "The arg in't correct" else +$)) echo $sum ...
- Pytest权威教程18-插件编写
[TOC] 返回: Pytest权威教程 插件编写 很容易为你自己的项目实现[本地conftest插件或可以在许多项目中使用的可[安装的插件,包括第三方项目.如果你只想使用但不能编写插件,请参阅[安装 ...
- java如何实现多线程?线程的状态有哪些?
java实现多线程有两种方法 1.继承Thread类 2.实现Runnable接口 这两种方法的共同点: 不论用哪种方法,都必须用Thread(如果是Thead子类就用它本身) ...
- Java SpringBoot Scheduled定时任务
package task.demo.controller; import org.springframework.beans.factory.annotation.Autowired; import ...
- Nginx+Tomcat多实例及负载均衡配置
Nginx+Tomcat多实例及负载均衡配置 采用nginx的反向代理负载均衡功能,配合后端的tomcat多实例来实现tomcat WEB服务的负载均衡 01 安装nginx服务 安装所需的pcre库 ...
- docker run 参数含义
-a stdin: 指定标准输入输出内容类型,可选 STDIN/STDOUT/STDERR 三项: -d: 后台运行容器,并返回容器ID: -i: 以交互模式运行容器,通常与 -t 同时使用: ...