这里是画图部分,具体的就不多讲了,不懂的可以私信我
#encoding:utf-8
# 导入相应的包
from pylab import *
import numpy as np
import matplotlib.pyplot as plt
class drawing():
def Line_chart(self, train_erro, test_erro):
#这里要将训练和预测的部分都画得一块,看起来可能有点费劲
M = np.arange(train_erro.shape[1])# 选取横坐标的值
L = np.arange(test_erro.shape[1])
# figure()
# subplot(111)
# plt.figure(1)
plt.plot(M, train_erro[0], color='blue', linewidth=1.5, linestyle="-", label="train")
plt.plot(L, test_erro[0], color='red', linewidth=1.5, linestyle="-", label="test")
plt.xlabel('numbert of pc')
plt.ylabel('train and test erro')
plt.title('The mse for each PC')
plt.legend()
plt.show()
# 这里是画散点图
def Distribution(self, pc, Y, turn_Y, y, turn_y):
for j in range(pc):
plot(y, turn_y[:, [j]],'bo',label="test")
plt.plot(Y, turn_Y[:, [j]],'ro',label="train")
plt.plot(Y,Y)
plt.xlabel('numbert of pc')
plt.ylabel('train and test ')
plt.title('The mse for each PC')
plt.legend(loc='upper left')
plt.show()