Skip to content

Commit 495649a

Browse files
authored
Merge pull request #1036 from dayhaha/grep_error
add python version evaluate function
2 parents f83add2 + 3f3a9ff commit 495649a

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

demo/recommendation/evaluate.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/python
2+
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
import sys
16+
import re
17+
import math
18+
19+
20+
def get_best_pass(log_filename):
21+
with open(log_filename, 'r') as f:
22+
text = f.read()
23+
pattern = re.compile('Test.*? cost=([0-9]+\.[0-9]+).*?pass-([0-9]+)',
24+
re.S)
25+
results = re.findall(pattern, text)
26+
sorted_results = sorted(results, key=lambda result: float(result[0]))
27+
return sorted_results[0]
28+
29+
30+
log_filename = sys.argv[1]
31+
log = get_best_pass(log_filename)
32+
predict_error = math.sqrt(float(log[0])) / 2
33+
print 'Best pass is %s, error is %s, which means predict get error as %f' % (
34+
log[1], log[0], predict_error)
35+
36+
evaluate_pass = "output/pass-%s" % log[1]
37+
print "evaluating from pass %s" % evaluate_pass

0 commit comments

Comments
 (0)