Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9c85f87

Browse files
committed
Lined up DataSet params with the documented fields. Documented extra param. Fixed .sanitize() to replace with None (the old code no longer did quite what was documented).
1 parent c788734 commit 9c85f87

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

learning.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ class DataSet:
2525
Normally, you call the constructor and you're done; then you just
2626
access fields like d.examples and d.target and d.inputs."""
2727

28-
def __init__(self, examples=None, attrs=None, target=-1, values=None,
29-
attrnames=None, name='', source='',
30-
inputs=None, exclude=(), doc=''):
31-
"""Accepts any of DataSet's fields. Examples can
32-
also be a string or file from which to parse examples using parse_csv.
28+
def __init__(self, examples=None, attrs=None, attrnames=None, target=-1,
29+
inputs=None, values=None, name='', source='', exclude=()):
30+
"""Accepts any of DataSet's fields. Examples can also be a
31+
string or file from which to parse examples using parse_csv.
32+
Optional parameter: exclude, as documented in .setproblem().
3333
>>> DataSet(examples='1, 2, 3')
3434
<DataSet(): 1 examples, 3 attributes>
3535
"""
@@ -92,8 +92,9 @@ def attrnum(self, attr):
9292
return attr
9393

9494
def sanitize(self, example):
95-
"Return a copy of example, with non-input attributes replaced by 0."
96-
return [i in self.inputs and example[i] for i in range(len(example))]
95+
"Return a copy of example, with non-input attributes replaced by None."
96+
return [attr_i if i in self.inputs else None
97+
for i, attr_i in enumerate(example)]
9798

9899
def __repr__(self):
99100
return '<DataSet(%s): %d examples, %d attributes>' % (

0 commit comments

Comments
 (0)