当前位置:网站首页>sklearn 特征工程(总结)
sklearn 特征工程(总结)
2022-06-28 05:23:00 【bingbangx】
1、特征工程
字典特征抽取
from sklearn.feature_extraction import DictVectorizer # 特征抽取的包

文本特征抽取和jieba分词
文本的特征抽取,比如说文档分类、垃圾邮件分类和新闻分类。文本分类是通过词是否存在、以及词的概率(重要性)来表示。

如果想要统计中文某些词出现的次数,就要先对中文进行分词。jieba
tf-idf文本抽取
是一种用于信息检索与文本挖掘的常用的加权技术,这种统计方法,用以评估一字一词在一份文件中的重要程度。
from sklearn.feature_extraction.text import TfidfVectorizer
特征工程~归一化
归一化
X=(x-min)/(max-min)
其中,max和min分别是某列的最大值和最小值,x为归一化之前的值。
from sklearn.preprocessing import MinMaxScaler
from sklearn.preprocessing import MinMaxScaler
scaler =MinMaxScaler()
data =[
[180,75,35],[175,80,17],[159,50,46],[149,79,45]
]
result =scaler.fit_transform(data)
print(result)

标准化
from sklearn.preprocessing import StandardScaler #标准化
scaler=StandardScaler()
result=scaler.fit_transform(data)
print(result)

特征工程-数据降维
主成分分析
主成分分析,是一种统计统计方法。通过正交变换将一组可能存在相关性变量的变量转换为一组线性不相关的变量,转换后的这组变量叫主成分。
主成分需要记住两点:
降维后的特征之间协方差为0,表示各个特征关系是独立的,每个特征都不会随着其他特征变化而有规律的变化。
每个特征的方差应尽可能大。
from sklearn.decomposition import PCA
def pca_decomposition():
pca=PCA(n_components=2)#1、0~1之间的,维度的比例-1;2、整形:具体的维度,必须为min(n_samples,n_features)以内
result =pca.fit_transform(
[
[4,2,76,9],
[1,192,1,56],
[34,5,20,90]
])
print(result)
pca_decomposition()

边栏推荐
- 拉萨手风琴
- MySQL export database dictionary to excel file
- Qcom LCD commissioning
- Biovendor sRAGE protein solution
- 【JVM】——JVM中內存劃分
- OpenSSL client programming: SSL session failure caused by an obscure function
- Voltage mode and current mode control of switching power supply
- 如何做好水库大坝安全监测工作
- Shutter nestedscrollview sliding folding head pull-down refresh effect
- Unity out ref params
猜你喜欢

独立站卖家都在用的五大电子邮件营销技巧,你知道吗?

To batch add background pictures and color changing effects to videos

jq图片放大器

Gee learning notes 3- export table data

Wedding studio portal applet based on wechat applet

二级造价工程师证书含金量到底有多高?看这些就知道了

北斗三号短报文终端在大坝安全监测方案的应用

Create NFS based storageclass on kubernetes

MySQL export database dictionary to excel file

如何做好水库大坝安全监测工作
随机推荐
Sqlmap tool user manual
The short video local life section has become popular. How to grasp the new opportunities?
A guide to P2P network penetration (stun) for metartc5.0 programming
Leecode question brushing-ii
[JVM series] JVM tuning
Unity out ref params
Interpretation of cloud native microservice technology trend
線條動畫
Why does the company choose cloud database? What is its charm!
metaRTC5.0编程之p2p网络穿透(stun)指南
Steve Jobs' speech at Stanford University -- follow your heart
Keil C51的Data Overlaying机制导致的函数重入问题
Rxswift -- (1) create a project
Camera Basics
二级造价工程师证书含金量到底有多高?看这些就知道了
【LeetCode】12、整数转罗马数字
Organize the online cake mall project
Shutter nestedscrollview sliding folding head pull-down refresh effect
MySQL export database dictionary to excel file
Reactive dye research: lumiprobe af594 NHS ester, 5-isomer