Skip to content

Commit

Permalink
Merge pull request #2 from lucasoldaini/master
Browse files Browse the repository at this point in the history
Fixed compatibility issues with Python 3
  • Loading branch information
jma127 committed Oct 15, 2016
2 parents c8ed9ff + 7c892f3 commit 5065509
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 32 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Compiler/Interpreter Output #
###############################
*.py[cod]
__pycache__/

# Folders #
###########
Expand All @@ -9,9 +10,14 @@ build/
dist/
local/
*.egg-info/
.idea/

# Junk #
########
.DS_Store*
.*.swp
*.swp

# Installation Files #
######################
files.txt
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ validation set for early stopping and trimming::
verbose=1,
)

model.fit(TX, ty, Tqids, monitor=monitor)
model.fit(TX, Ty, Tqids, monitor=monitor)

Evaluate model on test data::

Epred = model.predict(Ex)
Epred = model.predict(EX)
print 'Random ranking:', metric.calc_mean_random(Eqids, Ey)
print 'Our model:', metric.calc_mean(Eqids, Ey, Epred)

Expand Down
8 changes: 4 additions & 4 deletions pyltr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

import data
import metrics
import models
import util
from . import data
from . import metrics
from . import models
from . import util
2 changes: 1 addition & 1 deletion pyltr/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"""

import letor
from . import letor
14 changes: 7 additions & 7 deletions pyltr/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"""

from _metrics import *
from ap import AP
from dcg import DCG, NDCG
from err import ERR
from kendall import KendallTau
from roc import AUCROC
import gains
from ._metrics import *
from .ap import AP
from .dcg import DCG, NDCG
from .err import ERR
from .kendall import KendallTau
from .roc import AUCROC
from . import gains
7 changes: 3 additions & 4 deletions pyltr/metrics/dcg.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
import numpy as np
from . import gains, Metric
from overrides import overrides
from sklearn.externals.six.moves import range

from sklearn.externals.six import moves

_EPS = np.finfo(np.float64).eps

range = moves.range

class DCG(Metric):
def __init__(self, k=10, gain_type='exp2'):
Expand Down Expand Up @@ -54,7 +53,7 @@ def calc_random_ev(self, qid, targets):

@classmethod
def _make_discounts(self, n):
return np.array([1.0 / np.log2(i + 2.0) for i in xrange(n)])
return np.array([1.0 / np.log2(i + 2.0) for i in range(n)])

def _get_discount(self, i):
if i >= self.k:
Expand Down
4 changes: 2 additions & 2 deletions pyltr/metrics/err.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import numpy as np
from . import gains, Metric
from overrides import overrides
from sklearn.externals.six.moves import range

from sklearn.externals.six import moves

range = moves.range
_EPS = np.finfo(np.float64).eps


Expand Down
Empty file added pyltr/metrics/tests/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion pyltr/metrics/tests/test_ap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

import helpers
from . import helpers
import itertools
import numpy as np
import pyltr
Expand Down
2 changes: 1 addition & 1 deletion pyltr/metrics/tests/test_dcg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

import helpers
from . import helpers
import itertools
import numpy as np
import pyltr
Expand Down
2 changes: 1 addition & 1 deletion pyltr/metrics/tests/test_err.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

import helpers
from . import helpers
import itertools
import numpy as np
import pyltr
Expand Down
2 changes: 1 addition & 1 deletion pyltr/metrics/tests/test_kendall.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

import helpers
from . import helpers
import itertools
import numpy as np
import pyltr
Expand Down
2 changes: 1 addition & 1 deletion pyltr/metrics/tests/test_roc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

import helpers
from . import helpers
import itertools
import numpy as np
import pyltr
Expand Down
6 changes: 3 additions & 3 deletions pyltr/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"""

from _models import *
from lambdamart import LambdaMART
import monitors
from ._models import *
from .lambdamart import LambdaMART
from . import monitors
2 changes: 1 addition & 1 deletion pyltr/models/lambdamart.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def init(self, est, begin_at_stage=0):
def update(self, j, est, monitor_output):
"""Update reporter with new iteration. """
if monitor_output is True:
print 'Early termination at iteration', j
print('Early termination at iteration ', j)
return
do_query_oob = est.query_subsample < 1
# we need to take into account if we fit additional estimators.
Expand Down
4 changes: 2 additions & 2 deletions pyltr/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"""

import group
import sort
from . import group
from . import sort
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'numpy',
'overrides',
'scipy',
'sklearn',
'scikit-learn',
],
zip_safe=True
)

0 comments on commit 5065509

Please sign in to comment.