-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comet Logging #1
base: master
Are you sure you want to change the base?
Changes from 11 commits
5cd12f5
02d4859
4297eb0
3a86340
2fa5d05
5a20397
12e9c8e
587b83e
dbe276e
f55f085
e6e9aa5
2e83b1c
b9af5f7
718ac7d
b504789
6346632
a04fc14
af961d8
90d8df4
1ba8738
39e583b
764af3d
6a8dd6c
ef4532a
0468c39
d93843e
4c2a882
7bcfa2d
a113fcb
a44717e
c54b2c8
af5c024
5a22544
ca4459a
2a2c58d
a6fca92
7da170f
a45d6a1
9b76c5c
0e271e6
84f5bb6
3b40f7e
32cb44d
b0d0070
03c8a66
7602824
443c517
34c495d
c969895
1696d79
2f90500
a616455
2f4a893
5fd0946
e841ca9
b827002
f68bcc2
26b55a2
9c12913
53aac9e
0aff0b6
d39d7d6
02ccc09
0f5c23a
3547901
91544b9
ca7d76c
609b35a
a6c2d06
2e59b6f
06b54da
6e387ec
f39ffc4
406a114
408ed47
566de57
b23976c
d2fd30c
f236b07
da5b5a8
c8dd28d
6bcc205
4838cf9
6902074
f9ecc80
2bfaf9d
18d60b0
6acdbd4
c7c2829
bd3dec8
85ac526
f98c706
2aad2ab
eeed821
d5099a4
cb30144
6602fd1
3aed933
06423b8
246da52
f597701
b506391
b6c9e15
668e4cd
670fca0
b7aa8e6
9ab54aa
c29cc90
860453c
d50c6ec
737cf5d
f250d70
43e001f
69d83a3
0c16e27
ac9262b
e7a89b2
1ebd1dc
94ac64a
9c3ea61
25bbb6b
79da22e
1bd4181
17338ee
1bd13ed
91d8485
ea9bf6b
b366f94
04067c6
7d3b0d2
9b934b0
ad5e044
62eab2d
9ba00ea
1a2c212
d7399ef
520e2d1
de40537
b47a896
6752958
aad6482
b3492eb
4a0a2c0
e960260
5fc1f85
2cee973
bbc9f90
8fb2455
5001f9a
3bc356e
3c62ee6
0971884
05955f5
51843a6
41c4a1e
3e04460
4cccf76
2c2e79d
eda49b0
b53e46a
a1a4dfb
a094fbc
b395a4e
1e23448
ba6a930
df339d6
83152b5
bb0a145
b84e0fe
4b44b07
d7e5295
3ebe175
3c02f5e
aa512cc
eb6aca6
3f4b5bb
127ac76
15a1147
bee3787
e8a43cd
aa8ffcd
f691927
7c5208a
ca4b00c
53b9317
3d524e4
c298497
c91e274
b9b59d4
d2ff3d0
dae5037
314b6b1
bfb1080
0369a39
fb8ddde
c40f5fb
3841800
2704229
a6805bb
0a19724
ea9fcd6
fc23bf5
ef75c5a
4dcafba
80df135
bc80a3f
09d2f40
ef12067
d38b90c
cf3d0d0
8e8e7ce
d3b0ce9
cfc1ef3
4bf7452
2813a1a
e522a9d
4e697ef
3ef7d8a
59727da
347c9fe
4b1db3c
cd1ec13
ce4c703
e2951c0
39c1b24
70c1024
8705360
cea8c19
dae68f1
213eb02
b4cf58a
bc303e3
b84c649
7cd6134
867db6d
38ddba9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from pycaret.loggers.base_logger import BaseLogger | ||
from pathlib import Path | ||
import uuid | ||
from copy import deepcopy | ||
import joblib | ||
|
||
try: | ||
import comet_ml | ||
except ImportError: | ||
comet_ml = None | ||
|
||
class CometLogger(BaseLogger): | ||
def __init__(self) -> None: | ||
if comet_ml is None: | ||
raise ImportError( | ||
"CometLogger requires Comet. Install using `pip install comet_ml`" | ||
) | ||
super().__init__() | ||
self.run = None | ||
|
||
def init_experiment(self, exp_name_log, full_name=None, **kwargs): | ||
self.run = comet_ml.Experiment(project_name=exp_name_log, **kwargs) | ||
self.run.set_name(full_name) | ||
self.run.log_other('Created from', 'pycaret') | ||
return self.run | ||
|
||
def log_params(self, params, model_name=None): | ||
sherpan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.run.log_parameters(params, prefix=model_name) | ||
|
||
def set_tags(self, source, experiment_custom_tags, runtime): | ||
tags = [source, runtime] | ||
self.run.add_tags(tags) | ||
self.run.log_others(experiment_custom_tags) | ||
|
||
def log_sklearn_pipeline(self, experiment, prep_pipe, model, path=None): | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to remove explicit dependency on def __init__(self, pipline_dumper):
self._pipeline_dumper = pipeline_dumper # user can pass joblib.dump or any other suitable function the price to pay is that it's not part of the standard API |
||
pipeline = deepcopy(prep_pipe) | ||
pipeline.steps.append(["trained_model", model]) | ||
joblib.dump(pipeline, 'pipeline.pkl') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better use a |
||
self.run.log_model(name='model', file_or_folder='pipeline.pkl') | ||
|
||
def log_model_comparison(self, model_result, source): | ||
result_copy = deepcopy(model_result) | ||
if "Object" in result_copy: | ||
result_copy["Object"] = result_copy["Object"].apply( | ||
lambda obj: str(type(obj).__name__) | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this transforamtion should be extracted to another function with a meaningful name, so we understand why it is needed |
||
self.run.log_metrics({source: result_copy}) | ||
|
||
def log_metrics(self, metrics, source=None): | ||
self.run.log_metrics(metrics) | ||
|
||
def log_plot(self, plot, title): | ||
self.run.log_figure(figure=plot, figure_name=title) | ||
|
||
def log_hpram_grid(self, html_file, title="hpram_grid"): | ||
self.run.log_html(html_file) | ||
|
||
def log_artifact(self, file, type="artifact"): | ||
file_name, extension = None, "" | ||
file_pathlib = Path(file) | ||
file_name = file_pathlib.stem.replace(" ", "_") + str(uuid.uuid1())[:8] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. too much going on in one line. better do this sanitized_step = Path(file).stem.replace(" ", "_")
short_uiud = str(uuid.uuid1())[:8]
nicer to use "{stem}_{uuid}".format(stem=sanitized_stem, short_uuid) |
||
artifact = comet_ml.Artifact(name=file_name, artifact_type=type) | ||
artifact.add(file) | ||
self.run.log_artifact(artifact) | ||
|
||
def finish_experiment(self): | ||
sherpan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if self.run: | ||
self.run.end() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason to call it "run" and not "experiment"?
does it have to be public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run is what they used for other loggers and they have made it public. so just am following the maintainer's format