博客
关于我
逻辑回归_训练多元分类器
阅读量:378 次
发布时间:2019-03-05

本文共 1576 字,大约阅读时间需要 5 分钟。

逻辑回归_训练多元分类器

一对多

# 训练多元分类器from sklearn.linear_model import LogisticRegressionfrom sklearn import datasetsfrom sklearn.preprocessing import StandardScaler# 加载数据iris = datasets.load_iris()features = iris.datatarget = iris.target​scaler = StandardScaler()features_standardized = scaler.fit_transform(features)# multi_class="ovr"   表示一对多的逻辑回归    另外一种是MLR 多元逻辑回归logistic_regression = LogisticRegression(random_state=0, multi_class="ovr")#logistic_regression_MNL = LogisticRegression(random_state=0, multi_class="multinomial")# 训练模型model = logistic_regression.fit(features_standardized, target)DiscussionOn their own, logistic regressions are only binary classifiers, meaning they cannot handle target vectors with more than two classes. However, two clever extensions to logistic regression do just that. First, in one-vs-rest logistic regression (OVR) a separate model is trained for each class predicted whether an observation is that class or not (thus making it a binary classification problem). It assumes that each observation problem (e.g. class 0 or not) is independentAlternatively in multinomial logistic regression (MLR) the logistic function we saw in Recipe 15.1 is replaced with a softmax function:P(yI=k|X)=eβkxi∑Kj=1eβjxiP(yI=k|X)=eβkxi∑j=1Keβjxi where  P(yi=k|X)P(yi=k|X)  is the probability of the ith observation's target value,  yiyi , is class k, and K is the total number of classes. One practical advantage of the MLR is that its predicted probabilities using predict_proba method are more reliableWe can switch to an MNL by setting multi_class='multinomial'

转载地址:http://xprg.baihongyu.com/

你可能感兴趣的文章
MySQL 是怎样运行的 - InnoDB数据页结构
查看>>
mysql 更新子表_mysql 在update中实现子查询的方式
查看>>
MySQL 有什么优点?
查看>>
mysql 权限整理记录
查看>>
mysql 权限登录问题:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
查看>>
MYSQL 查看最大连接数和修改最大连接数
查看>>
MySQL 查看有哪些表
查看>>
mysql 查看锁_阿里/美团/字节面试官必问的Mysql锁机制,你真的明白吗
查看>>
MySql 查询以逗号分隔的字符串的方法(正则)
查看>>
MySQL 查询优化:提速查询效率的13大秘籍(避免使用SELECT 、分页查询的优化、合理使用连接、子查询的优化)(上)
查看>>
mysql 查询数据库所有表的字段信息
查看>>
【Java基础】什么是面向对象?
查看>>
mysql 查询,正数降序排序,负数升序排序
查看>>
MySQL 树形结构 根据指定节点 获取其下属的所有子节点(包含路径上的枝干节点和叶子节点)...
查看>>
mysql 死锁 Deadlock found when trying to get lock; try restarting transaction
查看>>
mysql 死锁(先delete 后insert)日志分析
查看>>
MySQL 死锁了,怎么办?
查看>>
MySQL 深度分页性能急剧下降,该如何优化?
查看>>
MySQL 深度分页性能急剧下降,该如何优化?
查看>>
MySQL 添加列,修改列,删除列
查看>>