1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 探索:爬取双色球开奖历史数据 高准确度预测下一期开奖号码。

探索:爬取双色球开奖历史数据 高准确度预测下一期开奖号码。

时间:2020-08-12 14:39:56

相关推荐

探索:爬取双色球开奖历史数据 高准确度预测下一期开奖号码。

最近在学习ML,本人偶尔喜欢买点彩票,经常觉得选号码是件困难的事,而且总是不中奖,那么有没有捷径,让计算机帮我去选号码,或者帮我选择中奖率高的号码。

一、让计算机帮我选取号码,随机选取。python代码如下:

import randomdef ball():ball_list=[]while 1:a=random.randint(1,33)if a not in ball_list:ball_list.append(a)if len(ball_list)==6:breakball_list.sort()ball_list.append(random.randint(1,16))print(ball_list)ball()

这是运行效果:

缺点:中奖率特别低,自己试过,经常是一个号码都不中,哈哈哈哈。

二、爬取双色球开奖历史数据,使用一些算法预测下一期中奖号码,希望能提升中奖率,但是能不能中奖就不清楚了。

先爬取数据保存在ssq.csv文件中,然后看看统计效果。

# coding=utf-8import requests,csvimport pandas as pdimport matplotlib.pyplot as pltimport seaborn as snfrom lxml import etree #lxml最新版本没有etree功能,3.7.2有,使用:pip install lxml==3.7.2def csv_w(filename,content):'用于csv格式文件,写入数据。数据用列表形式。'#打开文件,追加afile = open(filename,'a',newline="")#设定写入模式csv_write = csv.writer(file,dialect='excel')#写入具体内容csv_write.writerow(content)file.close()print ("write over")def ssq(filename): #爬取双色球历史数据,写入到ssq.csv文件中url = "/ssq/history/newinc/history.php?start=00001&end=18081" #数据来源response = requests.get(url)response = response.textselector = etree.HTML(response)for i in selector.xpath('//tr[@class="t_tr1"]'):datetime = i.xpath('td/text()')[0]red = i.xpath('td/text()')[1:7]blue = i.xpath('td/text()')[7]need=[]need.append(datetime)for j in red:need.append(j)need.append(blue)csv_w(filename, need)if __name__=='__main__':one=['id','red_one','red_two','red_three','red_four','red_five','red_six','blue'] #制作好表头。csv_w("ssq.csv",one) #写入表头ssq('ssq.csv')data=pd.read_csv("ssq.csv") #pandas读取csv格式文件数据。print(data.info()) #查看每列的大致信息sn.countplot(data.blue) #统计蓝色球情况plt.show() #显示出直方图。

运行效果:

可以看出,在蓝球中,12号的中奖概率是最高的。

算法预测部分待研究···············

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。