gpt4 book ai didi

python - Python 中的随机选择机器学习代码

转载 作者:行者123 更新时间:2023-11-30 09:57:15 24 4
gpt4 key购买 nike

我是 Python 新手,正在使用示例乐透绘图软件。我已经创建了一个结果字典,我的代码从中选择一组最常出现、最不常出现的数字,或者三个随机组合的建议。现在,我有兴趣让我的软件学习根据彩票抽奖的真实结果做出更好的选择。我还需要将这些结果添加到我的字典中。有什么想法吗?

我的目标不是成为百万富翁(尽管这很有趣),只是为了看看如何实现这样的学习代码。感谢您的时间。这是我的代码:

from random import choice

# Data created on 06.12.2013
LottoNumbers = {'1':336,'2':339,'3':383,'4':346,'5':369,'6':347,'7':364,'8':329,
'9':342,'10':345,'11':344,'12':336,'13':340,'14':330,'15':345,
'16':370,'17':376,'18':334,'19':343,'20':353,'21':334,'22':329,
'23':349,'24':351,'25':359,'26':378,'27':357,'28':347,'29':347,
'30':352,'31':365,'32':354,'33':310,'34':343,'35':341,'36':362,
'37':356,'38':361,'39':389,'40':351,'41':344,'42':385,'43':399,
'44':378,'45':357}

# Copy of Lotto Numbers in order not to accidentally damage or change it
LNC = LottoNumbers

#get a list of tuples, with value in 1st position, key second
li = [(value, key) for key, value in LNC.items()]

#sort the list
li.sort()

# needed number of items
m = 6

# grab the m highest values, from the end of the list
li_high_keys = [k for v, k in li[-m:]]

# grab the m lowest values from the beginning of the list
li_low_keys = [k for v, k in li[0:m]]

# add two lists together:
mixed_list = li_high_keys + li_low_keys

# create a list with 6 random items:
def ranList(list):
ranList = []
for i in range(0, 6):
item = choice(list)
if item in ranList:
item = choice(list)
ranList.append(item)
return ranList

# Get random choice from both lists:
ranList1 = sorted(ranList(mixed_list))
ranList2 = sorted(ranList(mixed_list))
ranList3 = sorted(ranList(mixed_list))

print "Numbers with highest frequency: "
print ', '.join(str(p) for p in li_high_keys)

print "Numbers with lowest frequency: "
print ', '.join(str(p) for p in li_low_keys)

print "Random mix of both lists: "
print ', '.join(str(p) for p in ranList1)
print ', '.join(str(p) for p in ranList2)
print ', '.join(str(p) for p in ranList3)

最佳答案

没有技术可以预测随机彩票的数字,因为随机的定义是没有算法可以预测它。

但是,如果彩票有偏差,一种原始的机器学习方法是计算每个号码在彩票中出现的次数,并对其进行加权:仅在该号码之前添加一个与彩票抽奖次数相加的常数每次遇到该数字时计数器都会发生。常数越高,旧彩票抽奖的权重越小。

关于python - Python 中的随机选择机器学习代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20404208/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com