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的更多相关文章

  1. sklearn 标准化数据的方法

    Sklearn 标准化数据 from __future__ import print_function from sklearn import preprocessing import numpy a ...

  2. sklearn.preprocessing.LabelEncoder_标准化标签,将标签值统一转换成range(标签值个数-1)范围内

    . LabelEncode(),标签值编码用在将一些类别型的列进行编码,方便用于训练

  3. sklearn标准化-【老鱼学sklearn】

    在前面的一篇博文中关于计算房价中我们也大致提到了标准化的概念,也就是比如对于影响房价的参数中有面积和户型,面积的取值范围可以很广,它可以从0-500平米,而户型一般也就1-5. 标准化就是要把这两种参 ...

  4. 机器学习入门-线性判别分析(LDA)1.LabelEncoder(进行标签的数字映射) 2.LinearDiscriminantAnalysis (sklearn的LDA模块)

    1.from sklearn.processing import LabelEncoder 进行标签的代码编译 首先需要通过model.fit 进行预编译,然后使用transform进行实际编译 2. ...

  5. 利用sklearn的LabelEncoder对标签进行数字化编码

    from sklearn.preprocessing import LabelEncoder def gen_label_encoder(): labels = ['BB', 'CC'] le = L ...

  6. python标签值标准化到[0-(#class-1)]

    python 处理标签常常需要将一组标签映射到一组数字,数字还要求连续. 比如 ['a', 'b', 'c', 'a', 'a', 'b', 'c'] ==(a->0, b->1, c-& ...

  7. 11.sklearn.preprocessing.LabelEncoder的作用

    In [5]: from sklearn import preprocessing ...: le =preprocessing.LabelEncoder() ...: le.fit(["p ...

  8. OneHotEncoder独热编码和 LabelEncoder标签编码

    学习sklearn和kagggle时遇到的问题,什么是独热编码?为什么要用独热编码?什么情况下可以用独热编码?以及和其他几种编码方式的区别. 首先了解机器学习中的特征类别:连续型特征和离散型特征 拿到 ...

  9. 使用sklearn进行数据挖掘-房价预测(4)—数据预处理

    在使用机器算法之前,我们先把数据做下预处理,先把特征和标签拆分出来 housing = strat_train_set.drop("median_house_value",axis ...

随机推荐

  1. redis日常使用汇总--持续更新

    redis日常使用汇总--持续更新 工作中有较多用到redis的场景,尤其是触及性能优化的方面,传统的缓存策略在处理持久化和多服务间数据共享的问题总是不尽人意,此时引入redis,但redis是单线程 ...

  2. docker 搭建简易仓库registry

    下载仓库镜像: docker pull  registry:2 运行仓库库镜像: docker run -d  -p 5000:5000  -v /usr/local/registry:/var/li ...

  3. python 模块之-shelve

    shelve模块比pickle模块简单,只有一个open函数,返回类似字典的对象,可读可写;key必须为字符串,而值可以是python所支持的数据类型 import shelve f = shelve ...

  4. MySQL数据库实现分页查询的SQL语句写法!

    一:分页需求: 客户端通过传递start(页码),limit(每页显示的条数)两个参数去分页查询数据库表中的数据,那我们知道MySql数据库提供了分页的函数limit m,n,但是该函数的用法和我们的 ...

  5. 【XSY1476】平凡之路 斜率优化DP

    题目大意 有\(n\)个格子,一开始你在\(1\)号格子.每次你只能往编号更大的格子走.从第\(i\)个格子走到第\(j\)个格子的代价是\(a_i+a_j\times(j-i)\times m\) ...

  6. 【XSY1591】卡片游戏 DP

    题目描述 有标有数字为\(1\)~\(9\)的卡片各\(a_1,a_2\cdots a_9\)张,还有标有乘号的卡片\(m\)张.从中取出\(n\)张按任意顺序排列,取出两个乘号相邻和乘法在边界上的非 ...

  7. python学习日记(数据结构习题)

    元素分类 有如下值li= [11,22,33,44,55,66,77,88,99,90],将所有大于 66 的值保存至字典的第一个key中,将小于 66 的值保存至第二个key的值中.即: {'k1' ...

  8. CentOS 7 Shell脚本编程第九讲 read命令简单介绍

    测试代码 sqlSessionFactory.openSession(false).getMapper(StudentMapper.class).findStudentById(id)核心方法:org ...

  9. 【BZOJ4891】[TJOI2017]龙舟(Pollard_rho)

    [BZOJ4891][TJOI2017]龙舟(Pollard_rho) 题面 BZOJ 洛谷 题解 看了半天题....就是让你求\(\frac{b}{a}\)在模\(M\)意义下的值... 首先把\( ...

  10. VC++2010组件安装失败解决办法

    安装SQLSERVER时,安装不上,总是报错说 VC++2010组件安装错误. 单独安装时,也会报出严重错误无法安装.就是下面这两个 最后到网上找到一个办法解决了:如下: 下载这个软件 Microso ...