sklearn-标准化标签LabelEncoder
python机器学习-乳腺癌细胞挖掘(博主亲自录制视频)
https://study.163.com/course/introduction.htm?courseId=1005269003&utm_campaign=commission&utm_source=cp-400000000398149&utm_medium=share
sklearn.preprocessing.LabelEncoder():标准化标签
standardScaler==features with a mean=0 and variance=1
minMaxScaler==features in a 0 to 1 range
normalizer==feature vector to a euclidean length=1
normalization
bring the values of each feature vector on a common scale
L1-least absolute deviations-sum of absolute values(on each row)=1;it is insensitive to outliers
L2-Least squares-sum of squares(on each row)=1;takes outliers in consideration during traing
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 14 09:09:41 2018 @author:Toby
standardScaler==features with a mean=0 and variance=1
minMaxScaler==features in a 0 to 1 range
normalizer==feature vector to a euclidean length=1 normalization
bring the values of each feature vector on a common scale
L1-least absolute deviations-sum of absolute values(on each row)=1;it is insensitive to outliers
L2-Least squares-sum of squares(on each row)=1;takes outliers in consideration during traing """ from sklearn import preprocessing
import numpy as np data=np.array([[2.2,5.9,-1.8],[5.4,-3.2,-5.1],[-1.9,4.2,3.2]])
bindata=preprocessing.Binarizer(threshold=1.5).transform(data)
print('Binarized data:',bindata) #mean removal
print('Mean(before)=',data.mean(axis=0))
print('standard deviation(before)=',data.std(axis=0)) #features with a mean=0 and variance=1
scaled_data=preprocessing.scale(data)
print('Mean(before)=',scaled_data.mean(axis=0))
print('standard deviation(before)=',scaled_data.std(axis=0))
print('scaled_data:',scaled_data)
'''
scaled_data: [[ 0.10040991 0.91127074 -0.16607709]
[ 1.171449 -1.39221918 -1.1332319 ]
[-1.27185891 0.48094844 1.29930899]]
''' #features in a 0 to 1 range
minmax_scaler=preprocessing.MinMaxScaler(feature_range=(0,1))
data_minmax=minmax_scaler.fit_transform(data)
print('MinMaxScaler applied on the data:',data_minmax)
'''
MinMaxScaler applied on the data: [[ 0.56164384 1. 0.39759036]
[ 1. 0. 0. ]
[ 0. 0.81318681 1. ]]
''' data_l1=preprocessing.normalize(data,norm='l1')
data_l2=preprocessing.normalize(data,norm='l2')
print('l1-normalized data:',data_l1)
'''
[[ 0.22222222 0.5959596 -0.18181818]
[ 0.39416058 -0.23357664 -0.37226277]
[-0.20430108 0.4516129 0.34408602]]
'''
print('l2-normalized data:',data_l2)
'''
[[ 0.3359268 0.90089461 -0.2748492 ]
[ 0.6676851 -0.39566524 -0.63059148]
[-0.33858465 0.74845029 0.57024784]]
'''
https://study.163.com/provider/400000000398149/index.htm?share=2&shareId=400000000398149( 欢迎关注博主主页,学习python视频资源,还有大量免费python经典文章)
QQ:231469242
sklearn-标准化标签LabelEncoder的更多相关文章
- sklearn 标准化数据的方法
Sklearn 标准化数据 from __future__ import print_function from sklearn import preprocessing import numpy a ...
- sklearn.preprocessing.LabelEncoder_标准化标签,将标签值统一转换成range(标签值个数-1)范围内
. LabelEncode(),标签值编码用在将一些类别型的列进行编码,方便用于训练
- sklearn标准化-【老鱼学sklearn】
在前面的一篇博文中关于计算房价中我们也大致提到了标准化的概念,也就是比如对于影响房价的参数中有面积和户型,面积的取值范围可以很广,它可以从0-500平米,而户型一般也就1-5. 标准化就是要把这两种参 ...
- 机器学习入门-线性判别分析(LDA)1.LabelEncoder(进行标签的数字映射) 2.LinearDiscriminantAnalysis (sklearn的LDA模块)
1.from sklearn.processing import LabelEncoder 进行标签的代码编译 首先需要通过model.fit 进行预编译,然后使用transform进行实际编译 2. ...
- 利用sklearn的LabelEncoder对标签进行数字化编码
from sklearn.preprocessing import LabelEncoder def gen_label_encoder(): labels = ['BB', 'CC'] le = L ...
- python标签值标准化到[0-(#class-1)]
python 处理标签常常需要将一组标签映射到一组数字,数字还要求连续. 比如 ['a', 'b', 'c', 'a', 'a', 'b', 'c'] ==(a->0, b->1, c-& ...
- 11.sklearn.preprocessing.LabelEncoder的作用
In [5]: from sklearn import preprocessing ...: le =preprocessing.LabelEncoder() ...: le.fit(["p ...
- OneHotEncoder独热编码和 LabelEncoder标签编码
学习sklearn和kagggle时遇到的问题,什么是独热编码?为什么要用独热编码?什么情况下可以用独热编码?以及和其他几种编码方式的区别. 首先了解机器学习中的特征类别:连续型特征和离散型特征 拿到 ...
- 使用sklearn进行数据挖掘-房价预测(4)—数据预处理
在使用机器算法之前,我们先把数据做下预处理,先把特征和标签拆分出来 housing = strat_train_set.drop("median_house_value",axis ...
随机推荐
- kubernetes 编排详解 挂载
##kube挂载本地磁盘apiVersion: v1 kind: Pod metadata: name: redis spec: containers: - name: redis image: re ...
- .net Json 反序列化时,属性带点
.net Json 反序列化时,属性带点 使用[JsonProperty("xxx.xxx")] static void Main(string[] args) { string ...
- Django ContentType组件
ContentType组件 引入 现在我们有这样一个需求~我们的商城里有很多的商品~~节日要来了~我们要搞活动~~ 那么我们就要设计优惠券~~优惠券都有什么类型呢~~满减的~折扣的~立减的~~ 我们对 ...
- BZOJ4653 [NOI2016] 区间 【线段树】
题目分析: 首先思考一个二分答案的做法.我们可以注意到答案具有单调性,所以可以二分答案. 假设当前二分的答案是$ k $.那么按照大小顺序插入每个区间,同时在末端删除会对答案产生影响的区间.这里不妨用 ...
- 大学实验3指导:利用单链表实现A-B
实验目的:深入理解单链表的建立及操作 实验内容: 1.建立单链表A与B 2.实现主要的函数,查找.插入.删除等 3.实现操作A-B 步骤1:包含必要的函数库,对结构体LNode中的抽象数据类型Elem ...
- [洛谷P1484] 种树
题目类型:堆+贪心 传送门:>Here< 题意:有\(N\)个坑,每个坑可以种树,且获利\(a[i]\)(可以为负).任何相邻两个坑里不能都种树,问在最多种\(K\)棵树的前提下的最大获利 ...
- [SCOI2005] 互不侵犯
传送门:>Here< 解题思路 其实这道题一种很简单的解法是搜索+打表,但是这样很赖皮.这里给出一种状压DP的解法. 很显然利用普通的DP无法解决了,因为针对点来转移是很难的.但看到$N& ...
- 「BZOJ1691」[Usaco2007 Dec] 挑剔的美食家 (Treap)
Description 与很多奶牛一样,Farmer John那群养尊处优的奶牛们对食物越来越挑剔,随便拿堆草就能打发她们午饭的日子自然是一去不返了.现在,Farmer John不得不去牧草专供商那里 ...
- nginx 重定向 说明
一.nginx 两个操作系统的安装见以前的随笔(已安装请跳过) linux上搭建nginx windows上搭建nginx 二.Nginx重定向——直接到项目,而非nginx欢迎页 默认ngin修改n ...
- 【BZOJ5302】[HAOI2018]奇怪的背包(动态规划,容斥原理)
[BZOJ5302][HAOI2018]奇怪的背包(动态规划,容斥原理) 题面 BZOJ 洛谷 题解 为啥泥萌做法和我都不一样啊 一个重量为\(V_i\)的物品,可以放出所有\(gcd(V_i,P)\ ...