Skip to content

Commit dcd08e1

Browse files
committed
Merge branch 'release/1.1.1' into stable
2 parents a13c141 + 0b6c489 commit dcd08e1

File tree

7 files changed

+66
-33
lines changed

7 files changed

+66
-33
lines changed

doc/run_experiment.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,12 @@ example, if you wanted to collapse the labels ``beagle`` and ``dachsund`` into a
381381
382382
Any labels not included in the dictionary will be left untouched.
383383

384-
.. _cv_folds:
384+
.. _num_cv_folds:
385385

386-
cv_folds *(Optional)*
386+
num_cv_folds *(Optional)*
387387
""""""""""""""""""""""
388388

389-
The number of folds to use for cross-validation. Defaults to 10.
389+
The number of folds to use for cross validation. Defaults to 10.
390390

391391
.. _random_folds:
392392

skll/config.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,14 @@ def validate(self):
194194
incorrectly_specified_options]))
195195

196196

197-
def _locate_file(file_path, config_path):
197+
def _locate_file(file_path, config_dir):
198198
if not file_path:
199199
return ''
200-
path_to_check = file_path if isabs(file_path) else normpath(join(dirname(config_path), file_path))
200+
path_to_check = file_path if isabs(file_path) else normpath(join(config_dir,
201+
file_path))
201202
ans = exists(path_to_check)
202203
if not ans:
203-
raise IOError(errno.ENOENT, "File does not exist",
204-
path_to_check)
204+
raise IOError(errno.ENOENT, "File does not exist", path_to_check)
205205
else:
206206
return path_to_check
207207

@@ -234,6 +234,7 @@ def _parse_config_file(config_path):
234234

235235
# compute the absolute path for the config file
236236
config_path = realpath(config_path)
237+
config_dir = dirname(config_path)
237238

238239
# set up a config parser with the above default values
239240
config = _setup_config_parser(config_path)
@@ -419,10 +420,10 @@ def _parse_config_file(config_path):
419420
featuresets[0][0] += '_test_{}'.format(basename(test_file))
420421

421422
# make sure all the specified paths/files exist
422-
train_path = _locate_file(train_path, config_path)
423-
test_path = _locate_file(test_path, config_path)
424-
train_file = _locate_file(train_file, config_path)
425-
test_file = _locate_file(test_file, config_path)
423+
train_path = _locate_file(train_path, config_dir)
424+
test_path = _locate_file(test_path, config_dir)
425+
train_file = _locate_file(train_file, config_dir)
426+
test_file = _locate_file(test_file, config_dir)
426427

427428
# Get class mapping dictionary if specified
428429
class_map_string = config.get("Input", "class_map")
@@ -443,27 +444,31 @@ def _parse_config_file(config_path):
443444

444445
# do we want to keep the predictions?
445446
prediction_dir = config.get("Output", "predictions")
446-
if prediction_dir and not exists(prediction_dir):
447-
prediction_dir = join(dirname(config_path), prediction_dir)
448-
os.makedirs(prediction_dir)
447+
if prediction_dir:
448+
prediction_dir = join(config_dir, prediction_dir)
449+
if not exists(prediction_dir):
450+
os.makedirs(prediction_dir)
449451

450452
# make sure log path exists
451453
log_path = config.get("Output", "log")
452-
if log_path and not exists(log_path):
453-
log_path = join(dirname(config_path), log_path)
454-
os.makedirs(log_path)
454+
if log_path:
455+
log_path = join(config_dir, log_path)
456+
if not exists(log_path):
457+
os.makedirs(log_path)
455458

456459
# make sure model path exists
457460
model_path = config.get("Output", "models")
458-
if model_path and not exists(model_path):
459-
model_path = join(dirname(config_path), model_path)
460-
os.makedirs(model_path)
461+
if model_path:
462+
model_path = join(config_dir, model_path)
463+
if not exists(model_path):
464+
os.makedirs(model_path)
461465

462466
# make sure results path exists
463467
results_path = config.get("Output", "results")
464-
if results_path and not exists(results_path):
465-
results_path = join(dirname(config_path), results_path)
466-
os.makedirs(results_path)
468+
if results_path:
469+
results_path = join(config_dir, results_path)
470+
if not exists(results_path):
471+
os.makedirs(results_path)
467472

468473
# 4. Tuning
469474
# do we need to run a grid search for the hyperparameters or are we just

skll/data/readers.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def read(self):
183183
ids = []
184184
labels = []
185185
with open(self.path_or_list, 'r' if PY3 else 'rb') as f:
186-
for ex_num, (id_, class_, _) in enumerate(self._sub_read(f)):
186+
for ex_num, (id_, class_, _) in enumerate(self._sub_read(f), start=1):
187187
# Update lists of IDs, clases, and features
188188
if self.ids_to_floats:
189189
try:
@@ -212,9 +212,8 @@ def feat_dict_generator():
212212
for ex_num, (_, _, feat_dict) in enumerate(self._sub_read(f)):
213213
yield feat_dict
214214
if ex_num % 100 == 0:
215-
self._print_progress('{:.8}%'.format(100 * ((ex_num +
216-
1) /
217-
total)))
215+
self._print_progress('{:.8}%'.format(100 * ((ex_num /
216+
total))))
218217
self._print_progress("100%")
219218

220219
# Convert everything to numpy arrays

skll/learner.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,9 @@ def model_params(self):
709709
if coef[idx]:
710710
res['{}\t{}'.format(label, feat)] = coef[idx]
711711

712-
intercept = dict(zip(label_list, self.model.intercept_))
712+
if self.model.intercept_:
713+
intercept = dict(zip(label_list, self.model.intercept_))
714+
713715
else:
714716
# not supported
715717
raise ValueError(("{} is not supported by" +

skll/utilities/print_model_weights.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import sys
1515

1616
from six import iteritems
17+
import numpy as np
1718

1819
from skll import Learner
1920
from skll.version import __version__
@@ -63,7 +64,12 @@ def main(argv=None):
6364
if intercept is not None:
6465
# subclass of LinearModel
6566
if '_intercept_' in intercept:
66-
print("intercept = {:.12f}".format(intercept['_intercept_']))
67+
# Some learners (e.g. LinearSVR) may return a list of intercepts
68+
if isinstance(intercept['_intercept_'], np.ndarray):
69+
intercept_list = ["%.12f" % i for i in intercept['_intercept_']]
70+
print("intercept = {}".format(intercept_list))
71+
else:
72+
print("intercept = {:.12f}".format(intercept['_intercept_']))
6773
else:
6874
print("== intercept values ==")
6975
for (label, val) in intercept.items():

skll/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
:organization: ETS
88
"""
99

10-
__version__ = '1.1.0'
10+
__version__ = '1.1.1'
1111
VERSION = tuple(int(x) for x in __version__.split('.'))

tests/test_utilities.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from __future__ import (absolute_import, division, print_function,
1010
unicode_literals)
11+
import ast
1112

1213
import copy
1314
import itertools
@@ -27,7 +28,7 @@
2728
from mock import create_autospec, patch
2829

2930
from nose.tools import eq_, assert_almost_equal, raises, assert_raises
30-
from numpy.testing import assert_array_equal, assert_allclose
31+
from numpy.testing import assert_array_equal, assert_allclose, assert_array_almost_equal
3132

3233
import skll
3334
import skll.utilities.compute_eval_from_predictions as cefp
@@ -377,9 +378,12 @@ def check_print_model_weights(task='classification'):
377378
if task == 'classification':
378379
learner = Learner('LogisticRegression')
379380
learner.train(train_fs)
380-
else:
381+
elif task == 'regression':
381382
learner = Learner('LinearRegression')
382383
learner.train(train_fs, grid_objective='pearson')
384+
else:
385+
learner = Learner('LinearSVR')
386+
learner.train(train_fs, grid_objective='pearson')
383387

384388
# now save the model to disk
385389
model_file = join(_my_dir, 'output',
@@ -414,7 +418,7 @@ def check_print_model_weights(task='classification'):
414418
feature_values = [t[1] for t in sorted(feature_values)]
415419
assert_almost_equal(intercept, learner.model.intercept_[0])
416420
assert_allclose(learner.model.coef_[0], feature_values)
417-
else:
421+
elif task == 'regression':
418422
lines_to_parse = [l for l in out.split('\n') if l]
419423
intercept = safe_float(lines_to_parse[0].split('=')[1])
420424
feature_values = []
@@ -424,11 +428,28 @@ def check_print_model_weights(task='classification'):
424428
feature_values = [t[1] for t in sorted(feature_values)]
425429
assert_almost_equal(intercept, learner.model.intercept_)
426430
assert_allclose(learner.model.coef_, feature_values)
431+
else:
432+
lines_to_parse = [l for l in out.split('\n') if l]
433+
434+
intercept_list = ast.literal_eval(lines_to_parse[0].split('=')[1].strip())
435+
intercept = []
436+
for intercept_string in intercept_list:
437+
intercept.append(safe_float(intercept_string))
438+
439+
feature_values = []
440+
for ltp in lines_to_parse[1:]:
441+
fields = ltp.split('\t')
442+
feature_values.append((fields[1], safe_float(fields[0])))
443+
feature_values = [t[1] for t in sorted(feature_values)]
444+
445+
assert_array_almost_equal(intercept, learner.model.intercept_)
446+
assert_allclose(learner.model.coef_, feature_values)
427447

428448

429449
def test_print_model_weights():
430450
yield check_print_model_weights, 'classification'
431451
yield check_print_model_weights, 'regression'
452+
yield check_print_model_weights, 'regression_linearSVR'
432453

433454

434455
def check_summarize_results_argparse(use_ablation=False):

0 commit comments

Comments
 (0)