Predict Yacht Hydrodynamics using MindsDB
Published: 2022-10-31 15:08:16

---
title: Predict Yacht Hydrodynamics using MindsDB
published: true
description: 
tags: 
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
---

![Yachts](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m485l0b6gczzndx7wqxd.png)



## Ships and resistance
A ship must be designed to move efficiently through the water with a minimum of external force. For thousands of years ship designers and builders of sailing vessels used rules of thumb based on the midship-section area to size the sails for a given vessel. But with the advances in steam power and construction of large iron ships in the mid-19th century, it became clear to ship owners and builders that a more rigorous approach was needed.
![Visual Representation of Residuary resistance](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kedj69bs90wwq7nucnv9.png)
In modern times, for the practical evaluation of ship resistance for normal ship forms, it is usual to group wave-making resistance, form resistance, eddy resistance and frictional form resistance into one force:  _residuary resistance_.

Residuary resistance is formally defined as the sum of the wave-making resistance and eddy resistance that opposes the movement of a vessel through the water. 

## Role of Machine Learning and MindsDB

The measurement of the residuary resistance per unit weight of displacement is a complex complex task. Calculating the value from measurements of ship’s dimensions, which are easier to determine and can be achieved using regression methods. 
When dealing with regression, a machine learning model like an MLP can be used to model the regression better than conventional methods. 
Which is where MindsDB comes into play. It acts as a datastore as well as the selector for the correct ML model to fit and train the data. It's an all in one solution when it comes to getting Machine learning involved in your data workflow. 

The goal here is to use MindsDB to predict the values of the residuary resistance per unit weight of displacement from the variables describing ship’s dimensions.

## Training Data

The data is taken from the UCI Machine Learning Repository [here](https://archive.ics.uci.edu/ml/datasets/yacht+hydrodynamics), created by Ship Hydromechanics Laboratory, Maritime and Transport Technology Department, Technical University of Delft. The Delft data set comprises 308 full-scale experiments, which were performed at the Delft Ship Hydromechanics Laboratory. These experiments include 22 different hull forms, derived from a parent form closely related to the â€˜Standfast 43â€™ 

### Attributes:
Variations concern hull geometry coefficients and the Froude number:

1. Longitudinal position of the center of buoyancy, adimensional.
2. Prismatic coefficient, adimensional.
3. Length-displacement ratio, adimensional.
4. Beam-draught ratio, adimensional.
5. Length-beam ratio, adimensional.
6. Froude number, adimensional.
7. Residuary resistance per unit weight of displacement, adimensional.


## Development Environment
As MindsDB offers a cloud version, we can sign up [here](https://cloud.mindsdb.com/), or we could use it locally via [Pip](https://docs.mindsdb.com/setup/self-hosted/pip/source/) or [Docker](https://docs.mindsdb.com/setup/self-hosted/docker/). In this tutorial, we will be using MindsDB via the cloud to highlight the ease of access. 
Data files are restricted to a maximum size of 10MB.

### Connecting to the datasource

For this tutorial, we connect to our database as a CSV file on the MindsDB cloud. We begin by downloading the [data file here](https://archive.ics.uci.edu/ml/machine-learning-databases/00243/) and uploading the file "yacht_hydrodynamics.csv".  Follow the [guide](https://docs.mindsdb.com/sql/tutorials/customer-churn/) to upload the file to MindsDB and name the table appropriately.

## Training
Once named, create and train a predictor with the following command:

`CREATE PREDICTOR mindsdb.yacht_model FROM files (SELECT * FROM yacht_hydrodynamics) PREDICT residuary_resistance;`

The quantity to predict here is residuary_resistance.

It may take a couple of minutes for the training to complete. You can [monitor the status of your model](https://docs.mindsdb.com/#5-creating-a-predictor-create-predictor) like this:

`
SELECT * FROM mindsdb.predictors WHERE name='yacht_model';`
`

The AutoML will figure out the model, and you can use [DESCRIBE](https://docs.mindsdb.com/sql/api/describe/?h=describe) to see how this model was built. MindsDB will pick the most optimised one as the result model to make the predictions. 

`
DESCRIBE PREDICTOR mindsdb.yacht_model.model;
`
The query lists out the candidate models used to train the data along with other metrics like performance, and accuracy.

![Describe the model](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ofq8mvvsy91y1uj9etcr.png)

The model takes very little time to train due to the low number of training points. 

## Prediction
The `SELECT` statement fetches predictions from the model table. The data is returned on the fly and not saved.
``

`SELECT residuary_resistance, residuary_resistance_explain FROM mindsdb.yacht_model WHERE prismatic_coeff=0.55 AND froude_no=0.181;`


![Predicting a query](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iqd3rlsi4p453aep24d4.png)

## Final thoughts

MindsDB eases the process of using ML to predict an otherwise complex problem. There are few barriers to getting started, making this a good option for novice users.