Use F# and ML.NET to predict New York taxi fares

Mark Farragher
7 min readJul 21, 2020

Building machine learning apps has never been easier!

Because we have ML.NET, Microsoft’s new machine learning library. It can run linear regression, logistic classification, clustering, deep learning, and many other machine learning algorithms.

But did you know that the F# language is the perfect choice for developing machine learning applications with ML.NET?

The F# language is just perfect for machine learning. It’s a 100% pure functional programming language based on OCaml and inspired by Python, Haskell, Scala, and Erlang. It has a powerful syntax and lots of built-in classes and functions for processing data.

Check out the following F# code fragment that trains a machine learning model to predict taxi fares in New York city, and then uses the fully-trained model to predict a single trip for a passenger paying with a credit card.

Look how compact the syntax is. F# machine learning code is elegant, concise, and beautiful:

A nice feature of F# is that it supports Duck Typing. In many cases you can leave out class names or generic type names and the compiler will just figure them out on its own. You can see an example of that in the screenshot where I initialize taxiTripSample without having to specify a class name.

--

--