案例天池云大赛工业蒸汽预测代码学习

#查看数据信息的代码
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from  scipy import stats
from pandas import Series,DataFrame
import warnings
from sklearn.linear_model import Ridge
from sklearn.metrics import mean_squared_error
warnings.filterwarnings("ignore")
%matplotlib inline

#train_data_file="C:\Users\jyb2334602399\Desktop\python\zhengqi_train.txt"
#test_data_file="C:\Users\jyb2334602399\Desktop\python\zhengqi_test.txt"
train_data=pd.read_csv(r"C:\Users\jyb2334602399\Desktop\python\zhengqi_train.txt",sep='\t',encoding='utf-8')
test_data=pd.read_csv(r"C:\Users\jyb2334602399\Desktop\python\zhengqi_test.txt",sep='\t',encoding='utf-8')
#首先读取测试集和数据集

train_data.info()
test_data.info()#pandas中的info函数可以用于打印dataFrame的简要信息,包括索引的列的数据类型

train_data.describe()
test_data.describe()
#describe()函数用于生成描述性统计信息。 描述性统计数据:数值类型的包括均值,标准差,最大值,最小值,分位数等;类别的包括个数,类别的数目,最高数量的类别及出现次数等;输出将根据提供的内容而有所不同。

info部分运行结果:
<class ‘pandas.core.frame.DataFrame’>
RangeIndex: 2888 entries, 0 to 2887
Data columns (total 39 columns):

Column Non-Null Count Dtype


0 V0 2888 non-null float64
1 V1 2888 non-null float64
表明该数据集中又2888个样本,有v0到v37三十八个变量和一个target变量。
describe()函数部分运行结果:
V0 V1 V2 V3 V4
count 2888.000000 2888.000000 2888.000000 2888.000000 2888.000000
mean 0.123048 0.056068 0.289720 -0.067790 0.012921
std 0.928031 0.941515 0.911236 0.970298 0.888377
min -4.335000 -5.122000 -3.420000 -3.956000 -4.742000
25% -0.297000 -0.226250 -0.313000 -0.652250 -0.385000
50% 0.359000 0.272500 0.386000 -0.044500 0.110000
75% 0.726000 0.599000 0.918250 0.624000 0.550250
max 2.121000 1.918000 2.828000 2.457000 2.689000
展示了数据集的均值,标准差,分位数,最大最小值等内容。

head函数:展示数据集中的前五行。

fig=plt.figure(figsize=(4,6))
sns.boxplot(train_data['V0'],orient="v",width=0.5)#参数orient控制
#视图朝向,v为垂直,h为水平。boxplot函数可以用于绘制一组数据的箱线图
plt.show()
#下面绘制V0~V38的箱线图 
column=train_data.columns.tolist()[:39]#列表头
fig=plt.figure(figsize=(80,60),dpi=75)#指定绘图对象的高度和宽度
for i in range(38):
    plt.subplot(7,8,i+1)
    sns.boxplot(train_data[column[i]],orient="v",width=0.5)
    plt.ylabel(column[i],fontsize=36)
plt.show()

plt.figure()函数,用于可视化一个图像:
figure(num=None, figsize=None, dpi=None, facecolor=None, edgecolor=None, frameon=True)
num:图像编号或名称,数字为编号 ,字符串为名称
figsize:指定figure的宽和高,单位为英寸;
dpi参数指定绘图对象的分辨率,即每英寸多少个像素,缺省值为80 1英寸等于2.5cm,A4纸是 21*30cm的纸张
facecolor:背景颜色
edgecolor:边框颜色
frameon:是否显示边框

train_data.columns-----打印会显示数据的列名称,tolist将其转换为列表

plt.subplot(2,3,1)也可以简写plt.subplot(231)表示把显示界面分割成2*3的网格。其中,第一个参数是行数,第二个参数是列数,第三个参数表示图形的标号。

plt.ylabel(column[i],fontsize=36) 设置y轴标签,第一个参数为标签名字, 第二个参数得字体大小

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值