Skip to main content

290 posts tagged with "Python"

Python Programming Language

View All Tags

How to Choose the Columns of a pandas DataFrame with reindex

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

Tables often have more columns than you need, in an order you didn't choose. pandas picks columns by name in two ways: frame[[...]], which needs every name to exist, and reindex(columns=[...]), which adds an empty column for a name that doesn't. This guide picks columns both ways from a small table of test scores, including one column that isn't there, with real output from pandas 3.1.1.

How to Rename Columns in a pandas DataFrame

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

Column names that come from a file or another program are often longer or clumsier than you want, such as price_usd where price would do. pandas renames columns with one call, rename, and a dictionary from old names to new ones. This guide renames two columns, shows that the original table is untouched, and makes a misspelled name raise an error instead of passing silently, with real output from pandas 3.1.1.

MLflow Tutorial for Machine Learning in Python — Part 3: Log Artifacts and Datasets

· 30 min read
Jagdish Kumawat
Founder @ Dewiride

Part 2's runs record numbers: scores at every step and the computer's load. Two questions those numbers can't answer: which data did this run learn from, and what did it produce besides scores? In this part every run records its training, validation and test data as MLflow datasets, and saves three files with itself: which features the forest relies on, every setting it used, and every prediction it got wrong.

How to Read a JSON or Text Artifact from MLflow in Python

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

When code needs a value from a file another run logged, such as a setting from its configuration, downloading the file first is a detour. mlflow.artifacts.load_dict() returns a JSON or YAML file as a Python dictionary, and load_text() returns any text file as a string, in one call each. This guide reads a run's settings back both ways, with real output from MLflow 3.18.0.

How to Download Artifacts from an MLflow Run

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

The files a run logged live on the tracking server, but sooner or later you need them on your own disk: to open a CSV in a spreadsheet, to compare reports, or to feed a file to another program. MLflow gives you three ways, a Python function, a terminal command and a button in the UI. This guide lists a run's files and downloads a folder of them, with real output from MLflow 3.18.0.

How to Log a Folder of Files to MLflow with log_artifacts

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

When a step of your code writes several files, such as a set of reports or charts, logging them one by one gets tedious. mlflow.log_artifacts() uploads a whole folder to the run in one call, subfolders included. One detail decides where the files end up: artifact_path. This guide logs a folder of two reports, with real output from MLflow 3.18.0.

How to Log a File to MLflow with log_artifact

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

Anything your code writes to disk can travel with the run that produced it: a CSV of predictions, a saved chart, a report, the data file itself. mlflow.log_artifact() uploads one file to the run, where it can be previewed and downloaded from the MLflow UI. This guide logs a CSV file twice, once at the top level and once in a folder, with real output from MLflow 3.18.0.

How to Log Text to a File in MLflow with log_text

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

Notes about a run, a text report, a summary someone else will read: when the content is already a string, mlflow.log_text() saves it with the run as a file in one call, without creating anything on your disk. This guide logs a Markdown note and a plain text file and looks at both in the MLflow UI, with real output from MLflow 3.18.0.

How to Log a Dictionary to MLflow as a JSON or YAML File

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

A run's settings, a model's full configuration or a summary of results often already sit in a Python dictionary. mlflow.log_dict() saves one with the run as a JSON or YAML file in a single line, without writing anything to disk yourself. This guide logs the same dictionary in both formats and compares the files, with real output from MLflow 3.18.0.

How to Load a Logged Table from MLflow with load_table

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

A table logged with mlflow.log_table() can be read straight back into a pandas DataFrame with mlflow.load_table(). Its best trick is reading the same table from many runs at once, stacked into one DataFrame with a column that says which run each row came from. This guide loads a predictions table from two runs, with real output from MLflow 3.18.0.