Predicting Employee Attrition & Performance using MindsDB Cloud
Published: 2022-10-15 10:43:07


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2b7lhpypuouf7wp25wq9.jpg)



## Introduction
With MindsDB, we can begin predicting in SQL right now. In order to predict the Target feature on the basis of the options, we will fetch our dataset and create a model instantly.

This tutorial will teach you how to train a model to predict Employee Attrition based on many variables, such as Age, Attrition , DailyRate, Education, etc. From Kaggle, we will use a  IBM Employee Attrition dataset.

Then we will log in to MindsDB Cloud, connect it to our data, train a model based on the dataset in our data, and attempt to predict Employee Attrition & Performance.

## Importing Data to MindsDB Cloud

Download the dataset from [Kaggle] (https://www.kaggle.com/datasets/pavansubhasht/ibm-hr-analytics-attrition-dataset) and then merely extract it and save the CSV file for later use.
Now allow us to start with our MindsDB Cloud account to require things additional.

**Step 1:** Login to your existing MindsDB Cloud account or signup for a brand new one here.


![Image description](https://community.ops.io/remoteimages/uploads/articles/rw31k30hwipf5qo1tv8d.png)

**Step 2:** Once you've got signed up or logged in to your MindsDB cloud account, you'll be able to realize the MindsDB Cloud Editor displayed for you.
The top panel is for writing the question, all-time low panel is for displaying the results and therefore the right panel lists out a number of the training hub resources to form things easier for the new users.


![Image description](https://community.ops.io/remoteimages/uploads/articles/kyqcme3pbtuwb142zl43.png)

**Step 3:** Click on Add Data from the highest right and on consequent screen that seems, turn to Files rather than Databases and so click on Import File.


![Image description](https://community.ops.io/remoteimages/uploads/articles/h6488yctbpwuca2yb9r8.png)

Step 4: Currently on the Import File dashboard, browse the dataset file from your pc, set a name for the Table and then hit the Save and Continue button. this could simply transfer the dataset file for you and build a Table with the name you provided.



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bse1j34cbks5prn319c2.png)



**Step 5:** Now the GUI returns back to the Editor screen where you can find two generic queries mentioned to either list the tables or query the data in the table that you just uploaded. Let's run both of these queries and check through the results.



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lb12kk7ljh7yjjvzmge3.png)



We are now ready to create a Predictor model using our attrition table that we just uploaded.

## Training a Predictor Model
MindsDB makes it extremely easy to define a Predictor model and train it by using a simple SQL syntax.

**Step 1:** We will now use the CREATE PREDICTOR syntax to create the Predictor. The syntax will be like this.

``` sql
CREATE PREDICTOR mindsdb.predictor_name (Your Predictor Name)
FROM database_name                      (Your Database Name)
(SELECT * FROM table_name LIMIT 10000)  (Your Table Name)
PREDICT target_parameter;               (Your Target Parameter)
```

The query get's executed and return successful in the terminal.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jyt64r6qntxy8c7vr8iz.png)


**Step 2:** The model should take a little while to get created and trained. We can check the status of the model using the syntax below. If the query returns Complete, then the model is ready to use or else wait if it returns Training status.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tmce80t8szjukxr32415.png)



## Describing the Predictor Model
MindsDB provides a DESCRIBE statement that we can use to gain some insights into the Predictor Model. We can find more details about the model in the following three ways.

- By Features
- By Model
- By Model Ensemble

## By Features

``` sql
DESCRIBE mindsdb.predictor_model_name.features;
```

This statement is used to find out the type of encoders used on each column to train the model and the role of each of the columns for the model. A sample output for our model is posted below.



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wj5o13f1xogvtpy9pc2e.png)



## By Model

``` sql
DESCRIBE mindsdb.predictor_model_name.model;
```

MindsDB uses multiple models internally to train the data and then select the most optimized one for the model to do the predictions. This statement simply lists out all the candidate models used to train the data along with other details. The model with 1 in its selected column is the one that is the most optimized and accurate.



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hazighcopl6goo3yo49o.png)



## By Model Ensemble

``` sql
DESCRIBE mindsdb.predictor_model_name.ensemble;
```

With the above statement, we can simply query out a JSON object that lists out the multiple attributes used to select the best candidate model to do the predictions.



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/003vsh9p5em18ncjw5lv.png)



## Querying the Model

Now that we have a tendency to square measure prepared with our Predictor Model, we will merely execute some straightforward SQL question statements to predict the target Attrition supported by the feature parameters.

We will start by predicting that only 1 feature parameter is supported by ibmAttrition and therefore the question statement should look like this.


``` sql

SELECT Attrition
FROM mindsdb.ibmAttrition
WHERE BusinessTravel ='Travel_Frequently';
;
```

This should return the expected Attrition having BusinessTravel value as Travel_Frequently.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fywin6mc6veo97eclwtx.png)



Let's now try predicting the Attrition based on multiple feature parameters.

``` sql
SELECT Attrition
FROM mindsdb.ibm
WHERE Department='Sales' AND Education = 2;;
```

This should return the expected Attrition having Department values as Sales and Education value as 2;


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9vv6ku8wxurn7b29ebw3.png)



## Conclusion

It's time to wrap up the tutorial. As part of this tutorial, we created a MindsDB Cloud account, uploaded a dataset to the cloud interface, trained a predictor model with the dataset, and predicted the IBM Attrition.

Using MindsDB, you can coach your own predictive models using datasets available on the market online. Don't be afraid to give it a try if you want to make all the predictions you want.

As a final note, please LIKE this page if you learn something new and interesting today and feel free to share your feedback below.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jpauxlpqlth7advnt1rh.jpg)