Skip to main content

290 posts tagged with "Python"

Python Programming Language

View All Tags

How to Log a Table in MLflow with log_table

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

Some results of a run are tables: predictions next to the real values, scores per group, the importance of each feature. mlflow.log_table() saves a pandas DataFrame or a dictionary with the run as a table that the MLflow UI shows as rows and columns and can compare across runs. This guide logs a small predictions table from two models, with real output from MLflow 3.18.0.

How to Make an MLflow Dataset Digest Cover Every Row

· 8 min read
Jagdish Kumawat
Founder @ Dewiride

An MLflow dataset's digest is meant to tell you when data changes, but for a pandas DataFrame it only looks at part of it: the first 10,000 rows, and only the columns that hold text or numbers. Change a value further down, or a date anywhere, and the digest stays the same. This guide shows both gaps happening, finds the reason in MLflow's code, and passes a digest of every row and column instead, with real output from MLflow 3.18.0.

How to Check Whether Two MLflow Runs Used the Same Data

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

When two runs give different results, the first question is whether they learned from the same data. If both logged their data with mlflow.log_input(), MLflow already knows: each dataset has a digest, a short fingerprint of its contents, and equal digests mean equal data. This guide compares three runs in the UI and in Python, with real screens and output from MLflow 3.18.0.

How to See Which Datasets an MLflow Run Used

· 9 min read
Jagdish Kumawat
Founder @ Dewiride

When a run logs its data with mlflow.log_input(), MLflow keeps each dataset's name, digest, source, schema and row count with the run. You can find them in the MLflow UI, from the command line and from Python. This guide looks at one run that used a training set and a test set, in all four places, with real screens and output from MLflow 3.18.0.

How to Log a Dataset in MLflow

· 8 min read
Jagdish Kumawat
Founder @ Dewiride

A model is only as good as the data it learned from, so a run should record which data that was. MLflow does it in two calls: mlflow.data.from_pandas() describes a pandas DataFrame as a dataset, and mlflow.log_input() attaches that description to the run. This guide logs a small CSV file of houses, with real output from MLflow 3.18.0.

How to See Every Setting of a scikit-learn Model with get_params

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

You usually set two or three of a model's settings and leave the rest at their defaults, so the code doesn't show the full picture. get_params() does: it returns every setting of a scikit-learn model, chosen or default, as a dictionary you can print, check or save. This guide lists all 18 settings of a random forest, with real output from scikit-learn 1.9.1.

How to Get Feature Importances from a Random Forest in scikit-learn

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

A trained random forest can tell you which inputs it leaned on most. feature_importances_ holds one number per input, and feature_names_in_ holds the inputs' names in the same order. This guide trains a forest on scikit-learn's California Housing data, reads both, and turns them into a sorted table, with real output from scikit-learn 1.9.1.

How to Save a pandas DataFrame to a CSV File

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

A CSV file is the simplest way to hand a table to someone else: Excel, Google Sheets and nearly every tool can open it. DataFrame.to_csv writes one in a single call, but its default adds the table's row numbers as an extra, nameless first column. This guide writes the same table twice, with and without them, and shows both files, with real output from pandas 3.1.1.

How to Sort a pandas DataFrame by a Column

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

Sorting a table by one column is how you find its top or bottom rows: the most expensive houses, or the predictions a model got most wrong. DataFrame.sort_values does it in one call, and two of its options cover cases that trip people up: sorting by size regardless of sign, and renumbering the rows afterwards. This guide sorts a small table of prediction errors, with real output from pandas 3.1.1.

How to Join a pandas Series to a DataFrame by Index

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

When a table's columns and one more column live apart, such as the inputs of a model and the value it should predict, DataFrame.join puts them back together. It matches rows by their labels, not their position, so the right value lands on the right row even when the two are in a different order. This guide joins a price column to a table of houses, with real output from pandas 3.1.1.