sklearn-數據可視化(第4講)

數據繪圖   2020/5/27
=====================================================================================
#1.繪製直線
import numpy as np
import 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()
=======================================================================================

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章