关键代码
import numpy as np
import matplotlib.pyplot as plt
from xgboost import XGBRegressor
#pip install xgboost -i https://pypi.tuna.tsinghua.edu.cn/simple
import pandas as pd
import joblib#处理中文字体
plt.rcParams['font.family'] = ['sans-serif']
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus']=False#读取数据
csv_data = pd.read_csv('dataset.csv')
datas = csv_data.values #转换为numpytrain_num=240 #前240行为训练集
Xtrain = datas[:train_num, 1:10] #训练集X
Ytrain = datas[:train_num, 0:1] #训练集Y# 训练集
plt.figure(1)
plt.plot(Ytrain, c='b', label='实际值',marker="*")
plt.plot(Ytrainpred, c='r', label='测试值',marker="o")
plt.legend()
plt.title("训练集对比")
plt.show()# 测试集
plt.figure(2)
plt.plot(Ytest, c='b', label='实际值',marker="*")
plt.plot(Ytestpred, c='k', label='测试值',marker="o")
plt.legend()
plt.title("测试集对比")
plt.show()
#完整代码 公众号回复关键字获取