sklearn-数据可视化(第4讲)
发布日期:2021-06-29 14:44:30 浏览次数:4 分类:技术文章

本文共 1920 字,大约阅读时间需要 6 分钟。

数据绘图   2020/5/27=====================================================================================#1.绘制直线import numpy as npimport matplotlib.pyplot as plt# X represents the features of our training data, the diameters of the pizzas.# A scikit-learn convention is to name the matrix of feature vectors X.# Uppercase letters indicate matrices, and lowercase letters indicate vectors.X = np.array([[6], [8], [10], [14], [18]])# y is a vector representing the prices of the pizzas.y = [7, 9, 13, 17.5, 18]plt.figure()plt.title('data')plt.xlabel('x axis')plt.ylabel('y axis')plt.plot(X, y, 'k.')# plt.axis([0, 25, 0, 25])plt.grid(True)plt.show()======================================================================================import matplotlib.pyplot as plt,pandas as pd,numpy as np#2.箱线图-查看数据分布filename = 'pima_data.csv'names = ['preg', 'plas', 'pres', 'skin', 'test', 'mass', 'pedi', 'age', 'class']data = pd.read_csv(filename, names=names)data.plot(kind='box', subplots=True, layout=(3,3), sharex=False)plt.show()======================================================================================#3.相关矩阵图 显示不同属性相互影响的程度correlations = data.corr()fig = plt.figure()ax = fig.add_subplot(111)cax = ax.matshow(correlations, vmin=-1, vmax=1)fig.colorbar(cax)ticks = np.arange(0, 9, 1)ax.set_xticks(ticks)ax.set_yticks(ticks)ax.set_xticklabels(names)ax.set_yticklabels(names)plt.show()======================================================================================#4.密度图-连续变量 数据的分布data.plot(kind='density', subplots=True, layout=(3,3), sharex=False)plt.show()======================================================================================#5.直方图-查看数据分布data.hist()plt.show()======================================================================================#6.散点图-变量随自变量的变化趋势pd.plotting.scatter_matrix(data)plt.show()=======================================================================================

 

转载地址:https://chunyou.blog.csdn.net/article/details/106389089 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:pandas.DataFrame按行列值/名称排序
下一篇:sklearn-查看数据(第2讲)

发表评论

最新留言

很好
[***.229.124.182]2024年04月22日 03时51分24秒