Hello all ! I'm trying to incorporate plotly visualizations in my mlflow. I've created a simple function:
def make_plotly(): import plotly.express as px df = px.data.iris() fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species", size='petal_length', hover_data=['petal_width']) fig.show() return figAnd created a pipeline where the output of the associated node is stored in the catalog
plotly_fig: type: kedro_mlflow.io.artifacts.MlflowArtifactDataset dataset: type: plotly.PlotlyDataset filepath: data/08_reporting/plotly.json plotly_args: type: scatter
@Philippe Martin, I tried using plotly.HTMLDataset instead of plotly.JSONDataset and it worked
shuttle_passenger_capacity_plot_go:
type: kedro_mlflow.io.artifacts.MlflowArtifactDataset dataset: type: plotly.HTMLDataset filepath: data/08_reporting/shuttle_passenger_capacity_plot_go.html
hey @Philippe Martin it seems like MLflow provides mlflow.log_artifact
. it is stored in the artifact repository associated with the current MLflow run. These artifacts can then be viewed and downloaded from the MLflow UI. Perhaps this can help to visualise your plotly in MLFlow?
https://mlflow.org/docs/latest/traditional-ml/hyperparameter-tuning-with-child-runs/notebooks/logging-plots-in-mlflow.html
Unfortunatly no.. the artifacts is well saved as a json file in the artificat repository, but it doesn't show as a plotly figure in the MLflow UI, it shows as a json file. Maybe the error comes from how I stored the figure in the catalog ?
plotly_fig: type: kedro_mlflow.io.artifacts.MlflowArtifactDataset dataset: type: plotly.PlotlyDataset filepath: data/08_reporting/plotly.json plotly_args: type: scatterThank you for your help
I also tried chaning to type plotly.JSONDataset instead of plotly.PlotlyDataset, but same issue ..
Hi @Philippe Martin
It is possible to log plotly figure with mlflow so that they show in mlflow UI. The artifact needs to be stored as HTML.
Look into mlflow.log_figure. If I recall properly, it should be called that way:
mlflow.log_figure(figure=figure, artifact_file=f"{name}.html")
The plotly dataset in kedro-datasets returns a figure object, which works well with Kedro-Viz. However, MLflow doesn't support this json format. A great idea would be to create an plotly.MLFlowDataset
dataset that would return the html as you said. We are already have a plotly.HTMLDataset
@Philippe Martin, I tried using plotly.HTMLDataset instead of plotly.JSONDataset and it worked
shuttle_passenger_capacity_plot_go:
type: kedro_mlflow.io.artifacts.MlflowArtifactDataset dataset: type: plotly.HTMLDataset filepath: data/08_reporting/shuttle_passenger_capacity_plot_go.html