Description

The db.models.insertOne() method creates and trains a new model.

Syntax

Here is the syntax:

db.models.insertOne({
     name: "predictor_name",
     predict: "target_column",
     connection: "integration_name",
     select_data_query: "db.collection_name.find({})"
});

On execution, we get:

WriteResult({
    "nInserted" : 1
})

Where:

ExpressionsDescription
nameThe name of the model to be created.
predictThe name of the target column to be predicted.
connectionThe name of the integration created via the db.databases.insertOne() method or file upload.
select_data_queryObject that stores the data collection name to be used for training and validation and additional arguments for filtering the data.

Checking Predictor Status

After running the db.models.insertOne() method, execute the db.models.find() method from the mindsdb.models collection to check the status of the model.

db.models.find({name: "model_name"});

Example

This example shows how you can create and train the home_rentals_model machine learning model to predict the rental prices for real estate properties inside the dataset.

db.models.insertOne({
     name: "home_rentals_model",
     predict: "rental_price",
     connection: "mongo_integration",
     select_data_query: "db.home_rentals.find({})"
});

On execution, we get:

WriteResult({
    "nInserted" : 1
})

To check the predictor status, query the mindsdb.models table using the db.models.find() command.

db.models.find({name: "home_rentals_model"});

On execution, we get:

{
  "name": "home_rentals_model",
  "status": "complete",
  "accuracy": 0.91,
  "predict": "rental_price",
  "update_status": "up_to_date",
  "mindsdb_version": "22.8.3.1",
  "error": null,
  "select_data_query": "",
  "training_options": ""
}