Machine Learning with One Line of Code!

Introducing MindsDb Platform

Ali Masri
Ali Masri
Jun 27 · 3 min read
Photo by Adi Goldstein on Unsplash

Intro

Machine Learning libraries are getting easier and easier to work with. Their objective is to hide complex mathematical operations and offer simple APIs. Recently, I stumbled upon MindsDb. A new platform that enables users to train models with only one line of code! I know it sounds a little bit exaggerated but follow me and you will see.

What is MindsDb?

MindsDB is an automated machine learning platform that allows anyone to gain powerful insights from their data. With MindsDB, users can get fast, accurate, and interpretable answers to any of their data questions within minutes — Official MindsDb website.

Installation

The installation process is very easy, if you have a Python environment, just run:

pip3 install mindsdb –-user

Otherwise, refer to the installation instructions on the official website.

Coding Example

Let us use MindsDb to predict home rental prices [download data from here].

This dataset contains 8 columns:

  • Number of rooms
  • Number of bathrooms
  • Size in square feet
  • Location
  • Days on market
  • Neighborhood
  • Rental price

Here is a snapshot of the data: (Notice the mix of numerical and categorical columns).

We start by importing mindsdb and defining a Predictor by giving it any name we want.

import mindsdbpredictor = mindsdb.Predictor(name='home_rental_predictor')

Now, it is time for training. Training is done by calling the learn method while passing two parameters:

  1. the data (file path, URL or a pandas Dataframe)
  2. and the name of the column to predict
predictor.learn(from_data='home_rentals.csv', to_predict='rental_price')

Done! Yes do not be surprised. Thats it, no need to preprocess the features, specify the algorithm, choose hyperparameters or any other complex details. MindsDb does it all under the hood. For more information about the magic behind this step refer to the official documentation.

To use the trained model, you access the predict method and pass it the a dictionary of the features’ values. Note that you don’t even have to pass all the values.

prediction = predictor.predict(when={'number_of_rooms': 3,'number_of_bathrooms': 2, 'sqft': 2000})print(prediction.data['rental_price'])

For the full code feel free to refer to the official code on Google Colab.

More Information?

MindsDb is not only for numeric and categorical data. It could be used for images, time series and many others. For advanced use cases feel free to check the advanced section in the official documentation.

Final Thoughts

There is a lot of attention nowadays to facilitate the access to machine learning and data science. With libraries such as MindsDb, users are given the key to experience with this domain and find its potential. Personally, I prefer tuning my own model and applying my own data transformations. But, it is always a pleasure to investigate and experiment new technologies.

If you enjoyed this article, I would appreciate it if you hit the clap button 👏 so it could be spread to others. You can also follow me on Twitter, Facebook, email me directly or find me on LinkedIn.

The Startup

Medium's largest active publication, followed by +479K people. Follow to join our community.

Ali Masri

Written by

Ali Masri

Lead Data Scientist at Cognitus France. https://alimasri.github.io

The Startup

Medium's largest active publication, followed by +479K people. Follow to join our community.