本文整理汇总了Python中soccersimulator.KeyboardStrategy.read方法的典型用法代码示例。如果您正苦于以下问题:Python KeyboardStrategy.read方法的具体用法?Python KeyboardStrategy.read怎么用?Python KeyboardStrategy.read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类soccersimulator.KeyboardStrategy
的用法示例。
在下文中一共展示了KeyboardStrategy.read方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_apprentissage
# 需要导入模块: from soccersimulator import KeyboardStrategy [as 别名]
# 或者: from soccersimulator.KeyboardStrategy import read [as 别名]
def build_apprentissage(fn,generator):
ex_raw = KeyboardStrategy.read(fn)
exemples = []
labels = []
for x in ex_raw:
exemples.append(generator(x[1],x[0][0],x[0][1]))
labels.append(x[0][2])
return exemples,labels
示例2: build_apprentissage
# 需要导入模块: from soccersimulator import KeyboardStrategy [as 别名]
# 或者: from soccersimulator.KeyboardStrategy import read [as 别名]
#gen_features.names = ["ball_dist","distance ball my goal","distance ball his goal","hisgoal_dist","mygoal_dist","dist adv le plus proche","nb adv autour"]
def build_apprentissage(fn,generator):
ex_raw = KeyboardStrategy.read(fn)
exemples = []
labels = []
for x in ex_raw:
exemples.append(generator(x[1],x[0][0],x[0][1]))
labels.append(x[0][2])
return exemples,labels
def apprendre_arbre(train,labels,depth=5,min_samples_leaf=2,min_samples_split=2):
tree= DecisionTreeClassifier(max_depth=depth,min_samples_leaf=min_samples_leaf,min_samples_split=min_samples_split)
tree.fit(train,labels)
return tree
## Match d'entrainement et apprentissage de l'arbre
if True:
#match = SoccerMatch(team_noob,team_bad,1000)
#show(match)
## Sauvegarde des exemples, mettre False a True si concatenation des fichiers
#strat.write("test.tree",True)
## Lecture du fichier cree
exemples = KeyboardStrategy.read("./training.exp")
## constitution de la base d'entrainement et des labels
train,labels = build_apprentissage("./training.exp",gen_features)
## apprentissage de l'arbre
tree = apprendre_arbre(train,labels)
## sauvegarde de l'arbre
cPickle.dump(tree,file("tree.pkl","w"))
示例3: aux
# 需要导入模块: from soccersimulator import KeyboardStrategy [as 别名]
# 或者: from soccersimulator.KeyboardStrategy import read [as 别名]
long = 10
sep1="|"+"-"*(long-1)
sepl="|"+" "*(long-1)
sepr=" "*long
def aux(node,sep):
if tree.tree_.children_left[node]<0:
ls ="(%s)" % (", ".join( "%s: %d" %(tree.classes_[i],int(x)) for i,x in enumerate(tree.tree_.value[node].flat)))
return sep+sep1+"%s\n" % (ls,)
return (sep+sep1+"X%d<=%0.2f\n"+"%s"+sep+sep1+"X%d>%0.2f\n"+"%s" )% \
(tree.tree_.feature[node],tree.tree_.threshold[node],aux(tree.tree_.children_left[node],sep+sepl),
tree.tree_.feature[node],tree.tree_.threshold[node],aux(tree.tree_.children_right[node],sep+sepr))
return aux(0,"")
exemples = KeyboardStrategy.read("./monfichier.exp")
train,labels = build_apprentissage("./monfichier.exp",gen_features)
tree = apprendre_arbre(train,labels)
print(affiche_arbre(tree))
if __name__=="__main__":
prefix = "./test"
if len(sys.argv)>1:
prefix = sys.argv[1]
## constitution de la base d'entrainement et des labels
train,labels = build_apprentissage(prefix+".exp",gen_features)
## apprentissage de l'arbre