机械学习预估未来GDP

#!/usr/bin/python
#encoding:utf-8
import numpy
import matplotlib.pyplot as plt
print("本程序中使用机械学习的方法来预估未来值,预测准确性取决于数据和拟合度,未考虑特殊因素")
y=[2719450,
3567320,
4863750,
6133990,
7181360,
7971500,
8519550,
9056440,
10028010,
11086310,
12171740,
13742200,
16184020,
18731890,
21943850,
27009230,
31924460,
34851770,
41211930,
48794020,
53858000,
59296320,
64356310,
68885820,
74639510,
83203590,
91928110,
99086510
]
x=list(range(len(y)))
mymodel = numpy.poly1d(numpy.polyfit(x, y, 3))
myline = numpy.linspace(1, len(y))
plt.scatter(x, y)
plt.plot(myline, mymodel(myline))

from sklearn.metrics import r2_score
print("图像拟合度为:")
print(r2_score(y, mymodel(x)))
wen=int(input("你想预测哪一年的,请输入int类型的数字"))
wen=int(wen-1991)
speed = mymodel(wen)
print("预测值")
print(speed)
plt.savefig('./Drawing of mechanical learning.jpg')
plt.show()
while  True:
   wen=int(input("你想预测哪一年的,请输入int类型的数字"))
   wen=int(wen-1991)
   speed = mymodel(wen)
   print("预测值")
   print(speed)

你可能感兴趣的:(Python,AI,深度学习,机器学习)