Skip to main content

153 posts tagged with "Python"

Python Programming Language

View All Tags

How to Get the History of a Metric in MLflow

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

When a run logs a metric many times, such as a loss after every round of training, MLflow keeps every value. The run's summary shows only the latest one, though. MlflowClient.get_metric_history returns them all, each with its step and the moment it was logged. This guide reads a short curve back and finds its best step, with real output from MLflow 3.18.0.

How to Add Command-Line Options to a Python Script with argparse

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

A script that reads its settings from the command line can be run in many ways without editing it. argparse, part of Python's standard library, turns a few lines of description into options, type checks, error messages and a --help page. This guide builds a small greeting script with an argument, an option and a flag, with real output from Python 3.15.2.

How to Use warm_start to Add Trees to a Random Forest in scikit-learn

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

A random forest normally grows all its trees in one call to fit. With warm_start=True, it keeps the trees it already has, and the next fit adds only the ones you asked for on top. That lets you score the forest at 25, 50, 75 and 100 trees without starting over each time. This guide shows how, with real output from scikit-learn 1.9.1.

How to Split Data into Training, Validation and Test Sets with scikit-learn

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

A test set tells you how good a finished model is, but only if you never use it while building the model. To check the model while you build it, you need a third part of the data, a validation set. scikit-learn has no single function for that, so you call train_test_split twice. This guide shows how, with real output from scikit-learn 1.9.1.

Fixed: scikit-learn Random Forest Predictions Change Slightly Between Calls with n_jobs=-1

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

A check that two random forests predict the same values printed False, although both forests had exactly the same trees. Even one forest, asked twice for the same predictions, gave values that differed in the 15th decimal place. With n_jobs=-1, scikit-learn adds up the trees' predictions in whatever order its threads finish, and decimal rounding makes the order show. Compare predictions with np.allclose, or predict with n_jobs=1 when you need identical numbers.

MLflow Tutorial for Machine Learning in Python — Part 1: Install MLflow and Track Your First Experiment

· 42 min read
Jagdish Kumawat
Founder @ Dewiride

Every time you train a model, you change something: the number of trees, a setting, the data. A week later nobody remembers which change gave the best result. MLflow remembers it for you. In this first part you install MLflow, start your own tracking server, and log your first machine learning experiment from Python.

How to Plot Predicted vs Actual Values with Matplotlib

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

A single error score tells you how much a regression model misses on average. A predicted vs actual chart shows where it misses: which values it gets right, which it underestimates, and where the data itself is odd. This guide draws the chart with Matplotlib, saves it as a PNG, and reads a real one from a scikit-learn model.

How to Calculate MAE, RMSE and R² in scikit-learn

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

A regression model predicts numbers, so you measure it by how far its numbers are from the real ones. Three scores do most of the work: MAE, RMSE and R². This guide calculates all three with scikit-learn for a real house price model, compares them against a model that always guesses the average, and explains what each number says in plain words.