Python中的文件查找问题
我尝试使用Python编写J48 parseTree算法 然而,我遇到了一个奇怪的问题:Python中的文件查找问题,python,Python,我尝试使用Python编写J48 parseTree算法 然而,我遇到了一个奇怪的问题: def parseTree(f1): line = f1.readline() while not line.startswith("attribute"): f2.write(line); save = f1.tell(); line = f1.readline() print f1.tell() print f1.readline() f1.seek(1
def parseTree(f1):
line = f1.readline()
while not line.startswith("attribute"):
f2.write(line);
save = f1.tell();
line = f1.readline()
print f1.tell()
print f1.readline()
f1.seek(1518)
print f1.readline()
结果是:
1518
attribute22 > 0
te14 = Y
我不明白为什么这两个f1.readline()不一样
这是J48树的一部分:
=== Run information ===
Scheme:weka.classifiers.trees.J48 -C 0.25 -M 2
Relation: cls-weka.filters.unsupervised.attribute.Remove-R1,25-27,48-56
Instances: 60818
Attributes: 43
cert_category
attribute1
attribute2
attribute3
attribute4
attribute5
attribute6
attribute7
attribute8
attribute9
attribute10
attribute11
attribute12
attribute13
attribute14
attribute15
attribute16
attribute17
attribute18
attribute19
attribute20
attribute21
attribute22
attribute26
attribute27
attribute28
attribute29
attribute23_days
attribute24_days
attribute25_days
attribute30
attribute31
attribute32
attribute33
attribute34
attribute35
attribute36
attribute37
attribute38
attribute39
attribute40
attribute41
attribute42_num
Test mode:10-fold cross-validation
=== Classifier model (full training set) ===
J48 pruned tree
------------------
attribute22 <= 0: 4 (406.0)
attribute22 > 0
| attribute23_days <= 1
| | attribute14 = Y
| | | attribute37 = Y: 0 (60.0/2.0)
| | | attribute37 = N: 5 (17.0/1.0)
| | | attribute37 = A: 0 (0.0)
| | attribute14 = N
| | | attribute23_days <= 0: 5 (45.0)
| | | attribute23_days > 0
| | | | attribute2 <= 26: 5 (20.0)
| | | | attribute2 > 26
| | | | | attribute3 = Y: 5 (13.0)
| | | | | at
==运行信息===
方案:weka.classifiers.trees.J48-c0.25-m2
关系:cls weka.filters.unsupervised.attribute.Remove-R1,25-27,48-56
实例:60818
属性:43
证书类别
属性1
属性2
属性3
属性4
属性5
属性6
属性7
属性8
属性9
属性10
属性11
属性12
属性13
属性14
属性15
属性16
属性17
属性18
属性19
属性20
属性21
属性22
属性26
属性27
属性28
属性29
属性23天
属性24天
属性25天
属性30
属性31
属性32
属性33
属性34
属性35
属性36
属性37
属性38
属性39
属性40
属性41
属性42_num
测试模式:10倍交叉验证
==分类器模型(完整训练集)===
J48修剪树
------------------
属性22 0
|属性23天您可以演示如何打开文件吗?(text,binary,r,a,a+)?你能试着用二进制模式打开它吗:open('j48.txt','rb')?有时,如果文件不是以二进制模式打开的,则seek函数会出现问题,因为会有结束行标记