当前位置:网站首页>Data processing of deep learning
Data processing of deep learning
2022-07-07 00:42:00 【Peng Xiang】
Data manipulation
- data type , The most commonly used one is array
Creating an array requires
- shape : A few lines and columns
- Element type :int still float
- Element value
Array access method :
Code :
This mechanism works as follows : First , Extend one or two arrays by copying elements appropriately , So that after the conversion , Two tensors have the same shape . secondly , Perform a per element operation on the generated array .
because a and b And matrix , If you add them together , Their shapes don't match . We broadcast two matrices into a larger matrix , As shown below : matrix a Columns will be copied , matrix b The row will be copied , Then add by element .
Data preprocessing
Create files and write data
import os
os.makedirs(os.path.join('.', 'data'), exist_ok=True)# Create in current directory data Folder
data_file = os.path.join('.', 'data', 'house_tiny.csv')# stay data Create under folder house_tiny.csv
print(data_file)
with open(data_file, 'w') as f:
f.write('NumRooms,Alley,Price\n') # Name
f.write('NA,Pave,127500\n') # Each row represents a data sample
f.write('2,NA,106000\n')
f.write('4,NA,178100\n')
f.write('NA,NA,140000\n')
Read the file , about csv Document multipurpose pandas This library
import pandas as pd
data=pd.read_csv(data_file)
print(data)
Data processing missing values and conversions
For missing values , We can use two methods: insertion method and deletion method , Insertion is the value we give , Deletion is a direct deletion, which is no longer considered , Here we use the method of taking the mean value of the missing value
inputs,outputs = data.iloc[:, 0:2], data.iloc[:, 2]# Read data in file format , Read columns 1 to 2
inputs = inputs.fillna(inputs.mean())# For the missing value, we usually take the mean value of other values
inputs = pd.get_dummies(inputs, dummy_na=True)# about string Type we see Alley The value is only Pave and NaN, So we can put Pave Write it down as 1,NaN Write it down as 0
print(inputs)
Transform our data into tensors
import torch
x,y=torch.tensor(inputs.values),torch.tensor(outputs.values)
print(x,y)
Come here , We will convert the data into tensor Tensor , This is processable for computers
Complete code :
import os
os.makedirs(os.path.join('.', 'data'), exist_ok=True)
data_file = os.path.join('.', 'data', 'house_tiny.csv')
print(data_file)
with open(data_file, 'w') as f:
f.write('NumRooms,Alley,Price\n') # Name
f.write('NA,Pave,127500\n') # Each row represents a data sample
f.write('2,NA,106000\n')
f.write('4,NA,178100\n')
f.write('NA,NA,140000\n')
import pandas as pd
data=pd.read_csv(data_file)
print(data)
inputs,outputs = data.iloc[:, 0:2], data.iloc[:, 2]# Read data in file format , Read columns 1 to 2
inputs = inputs.fillna(inputs.mean())# For the missing value, we usually take the mean value of other values
inputs = pd.get_dummies(inputs, dummy_na=True)
print(inputs)
import torch
x,y=torch.tensor(inputs.values),torch.tensor(outputs.values)
print(x,y)
边栏推荐
- Model-Free Prediction
- Leecode brushes questions to record interview questions 17.16 massagist
- Interesting wine culture
- 2021 SASE integration strategic roadmap (I)
- Leecode brush questions record sword finger offer 44 A digit in a sequence of numbers
- Article management system based on SSM framework
- Zynq transplant ucosiii
- 沉浸式投影在线下展示中的三大应用特点
- JWT signature does not match locally computed signature. JWT validity cannot be asserted and should
- dynamic programming
猜你喜欢
@TableId can‘t more than one in Class: “com.example.CloseContactSearcher.entity.Activity“.
37页数字乡村振兴智慧农业整体规划建设方案
AI超清修复出黄家驹眼里的光、LeCun大佬《深度学习》课程生还报告、绝美画作只需一行代码、AI最新论文 | ShowMeAI资讯日报 #07.06
Lombok 同时使⽤ @Data 和 @Builder 的坑,你中招没?
【软件逆向-求解flag】内存获取、逆变换操作、线性变换、约束求解
【YoloV5 6.0|6.1 部署 TensorRT到torchserve】环境搭建|模型转换|engine模型部署(详细的packet文件编写方法)
If the college entrance examination goes well, I'm already graying out at the construction site at the moment
Designed for decision tree, the National University of Singapore and Tsinghua University jointly proposed a fast and safe federal learning system
The way of intelligent operation and maintenance application, bid farewell to the crisis of enterprise digital transformation
JWT signature does not match locally computed signature. JWT validity cannot be asserted and should
随机推荐
How engineers treat open source -- the heartfelt words of an old engineer
rancher集成ldap,实现统一账号登录
Service asynchronous communication
@TableId can‘t more than one in Class: “com.example.CloseContactSearcher.entity.Activity“.
2021 SASE integration strategic roadmap (I)
2022年PMP项目管理考试敏捷知识点(9)
uniapp实现从本地上传头像并显示,同时将头像转化为base64格式存储在mysql数据库中
Leecode brush questions record interview questions 32 - I. print binary tree from top to bottom
uniapp中redirectTo和navigateTo的区别
equals()与hashCode()
什么是时间
Liuyongxin report | microbiome data analysis and science communication (7:30 p.m.)
JWT signature does not match locally computed signature. JWT validity cannot be asserted and should
A way of writing SQL, update when matching, or insert
Policy Gradient Methods
基于GO语言实现的X.509证书
@TableId can‘t more than one in Class: “com.example.CloseContactSearcher.entity.Activity“.
JWT signature does not match locally computed signature. JWT validity cannot be asserted and should
浅谈测试开发怎么入门,如何提升?
js导入excel&导出excel