Skip to main content

375 posts tagged with "Python"

Python Programming Language

View All Tags

How to Find the Best Run in MLflow

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

After a batch of training runs, the next question is always the same: which one did best? MLflow answers it with one search: sort the experiment's runs by the metric that measures quality, ask for just one run, and take it. This guide finds the run with the lowest error among three, with real output from MLflow 3.18.0.

How to Search MLflow Runs in Python with search_runs

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

mlflow.search_runs() is the Python way to look through an experiment's runs: one call returns them as a pandas DataFrame, one row per run, with a column for every metric, parameter and tag. You can filter, sort and limit the result on the server. This guide searches three small runs, reads the columns MLflow returns, and narrows them to the best runs, with real output from MLflow 3.18.0.

How to Write a Search Filter for MLflow Runs

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

MLflow finds runs with a filter string, a short condition such as metrics.loss < 0.35. The same string works in the UI's search box and in Python's mlflow.search_runs(). It looks like the WHERE part of SQL, with a few rules of its own: which comparisons each kind of value allows, what needs quotes, and no OR. This guide gives the general form, runs five filters on three small runs, and lists the exact errors MLflow 3.18.0 gives when a rule is broken.

How to Accept Only Positive Integers in argparse

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

type=int makes an argparse option a whole number, but it happily accepts 0 and -5, which make no sense for a count. A small function passed as type does the conversion and the check in one place, and argparse turns its complaint into a proper error message. This guide builds a script that repeats a word a positive number of times, with real output from Python 3.15.2.

How to Print a pandas DataFrame Without the Index

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

print() on a pandas DataFrame adds a column of row numbers on the left, the index, which is noise when you only want to show the data, for example in a command-line tool's output. to_string(index=False) turns the table into text without it, and float_format rounds its numbers while you're at it. This guide prints a small price list three ways, with real output from pandas 3.1.1.

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.