How to use MindsDB - 10 common examples

To help you get started, we’ve selected a few MindsDB examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mindsdb / mindsdb / integration_testing / run_tests.py View on Github external
except:
        logger.error(f'Failed to create mindsdb Predictor')
        exit(1)


    try:
        mdb.learn(from_data=train_file_name, to_predict=label_headers)
        logger.info(f'--------------- Learning ran succesfully ---------------')
    except:
        print(traceback.format_exc())
        logger.error(f'Failed during the training !')
        exit(1)

    # Predict
    try:
        mdb = mindsdb.Predictor(name='test_one_label_prediction')
        logger.debug(f'Succesfully create mindsdb Predictor')
    except:
        print(traceback.format_exc())
        logger.error(f'Failed to create mindsdb Predictor')
        exit(1)

    try:
        results = mdb.predict(when_data=test_file_name)
        for row in results:
            expect_columns = [label_headers[0] ,label_headers[0] + '_confidence']
            for col in expect_columns:
                if col not in row:
                    logger.error(f'Prediction failed to return expected column: {col}')
                    logger.debug('Got row: {}'.format(row))
                    exit(1)
github mindsdb / mindsdb / integration_testing / run_tests.py View on Github external
columns_train.extend(list(map(lambda col: col[1:int(len(col)*3/4)], labels)))
        columns_to_file(columns_train, train_file_name, separator, headers=[*feature_headers,*label_headers])

        # Create the testing dataset and save it to a file
        columns_test = list(map(lambda col: col[int(len(col)*3/4):], features))
        columns_to_file(columns_test, test_file_name, separator, headers=feature_headers)
        logger.debug(f'Multilabel datasets generate and saved to files successfully')
    except:
        print(traceback.format_exc())
        logger.error(f'Failed to generate datasets !')
        exit(1)

    # Train
    mdb = None
    try:
        mdb = mindsdb.Predictor(name='test_multilabel_prediction')
        logger.debug(f'Succesfully create mindsdb Predictor')
    except:
        logger.error(f'Failed to create mindsdb Predictor')
        exit(1)


    try:
        mdb.learn(from_data=train_file_name, to_predict=label_headers)
        logger.info(f'--------------- Learning ran succesfully ---------------')
    except:
        print(traceback.format_exc())
        logger.error(f'Failed during the training !')
        exit(1)

    # Predict
    try:
github mindsdb / mindsdb / integration_testing / run_tests.py View on Github external
except:
        logger.error(f'Failed to create mindsdb Predictor')
        exit(1)


    try:
        mdb.learn(from_data=train_file_name, to_predict=label_headers)
        logger.info(f'--------------- Learning ran succesfully ---------------')
    except:
        print(traceback.format_exc())
        logger.error(f'Failed during the training !')
        exit(1)

    # Predict
    try:
        mdb = mindsdb.Predictor(name='test_multilabel_prediction')
        logger.debug(f'Succesfully create mindsdb Predictor')
    except:
        print(traceback.format_exc())
        logger.error(f'Failed to create mindsdb Predictor')
        exit(1)

    try:
        results = mdb.predict(when_data=test_file_name)
        for i in range(len(results)):
            row = results[i]
            expect_columns = [label_headers[0] ,label_headers[0] + '_confidence']
            for col in expect_columns:
                print(row[col])
                if col not in row:
                    logger.error(f'Prediction failed to return expected column: {col}')
                    logger.debug('Got row: {}'.format(row))
github mindsdb / mindsdb / tests / functional_testing / data_sources / data_from_mysql.py View on Github external
import MySQLdb

from mindsdb import Predictor, MySqlDS


con = MySQLdb.connect("localhost", "root", "", "mysql")
cur = con.cursor()

cur.execute('DROP TABLE IF EXISTS test_mindsdb')
cur.execute('CREATE TABLE test_mindsdb(col_1 Text, col_2 BIGINT, col_3 BOOL)')
for i in range(0,5000):
    cur.execute(f'INSERT INTO test_mindsdb VALUES ("This is tring number {i}", {i}, {i % 2 == 0})')
con.commit()
con.close()

mdb = Predictor(name='analyse_dataset_test_predictor')
mysql_ds = MySqlDS(query="SELECT * FROM test_mindsdb")
assert(len(mysql_ds._df) == 5000)
mdb.analyse_dataset(from_data=mysql_ds)
github mindsdb / mindsdb / tests / integration_tests / generated_data_tests.py View on Github external
columns_train.extend(list(map(lambda col: col[1:int(len(col)*3/4)], labels)))
        columns_to_file(columns_train, train_file_name, separator, headers=[*feature_headers,*label_headers])

        # Create the testing dataset and save it to a file
        columns_test = list(map(lambda col: col[int(len(col)*3/4):], features))
        columns_to_file(columns_test, test_file_name, separator, headers=feature_headers)
        logger.debug(f'Datasets generate and saved to files successfully')
    except:
        print(traceback.format_exc())
        logger.error(f'Failed to generate datasets !')
        exit(1)

    # Train
    mdb = None
    try:
        mdb = mindsdb.Predictor(name='test_one_label_prediction')
        logger.debug(f'Succesfully create mindsdb Predictor')
    except:
        logger.error(f'Failed to create mindsdb Predictor')
        exit(1)


    try:
        mdb.learn(from_data=train_file_name, to_predict=label_headers, backend=backend)
        logger.info(f'--------------- Learning ran succesfully ---------------')
    except:
        print(traceback.format_exc())
        logger.error(f'Failed during the training !')
        exit(1)

    # Predict
    try:
github mindsdb / mindsdb / tests / integration_tests / generated_data_tests.py View on Github external
except:
        logger.error(f'Failed to create mindsdb Predictor')
        exit(1)


    try:
        mdb.learn(from_data=train_file_name, to_predict=label_headers, backend=backend)
        logger.info(f'--------------- Learning ran succesfully ---------------')
    except:
        print(traceback.format_exc())
        logger.error(f'Failed during the training !')
        exit(1)

    # Predict
    try:
        mdb = mindsdb.Predictor(name='test_multilabel_prediction')
        logger.debug(f'Succesfully create mindsdb Predictor')
    except:
        print(traceback.format_exc())
        logger.error(f'Failed to create mindsdb Predictor')
        exit(1)

    try:
        results = mdb.predict(when_data=test_file_name)
        models = mdb.get_models()
        mdb.get_model_data(models[0]['name'])
        for i in range(len(results)):
            row = results[i]
            expect_columns = [label_headers[0] ,label_headers[0] + '_confidence']
            for col in expect_columns:
                print(row[col])
                if col not in row:
github mindsdb / mindsdb / tests / integration_tests / generated_data_tests.py View on Github external
columns_train.extend(list(map(lambda col: col[1:int(len(col)*3/4)], labels)))
        columns_to_file(columns_train, train_file_name, separator, headers=[*feature_headers,*label_headers])

        # Create the testing dataset and save it to a file
        columns_test = list(map(lambda col: col[int(len(col)*3/4):], features))
        columns_to_file(columns_test, test_file_name, separator, headers=feature_headers)
        logger.debug(f'Multilabel datasets generate and saved to files successfully')
    except:
        print(traceback.format_exc())
        logger.error(f'Failed to generate datasets !')
        exit(1)

    # Train
    mdb = None
    try:
        mdb = mindsdb.Predictor(name='test_multilabel_prediction')
        logger.debug(f'Succesfully create mindsdb Predictor')
    except:
        logger.error(f'Failed to create mindsdb Predictor')
        exit(1)


    try:
        mdb.learn(from_data=train_file_name, to_predict=label_headers, backend=backend)
        logger.info(f'--------------- Learning ran succesfully ---------------')
    except:
        print(traceback.format_exc())
        logger.error(f'Failed during the training !')
        exit(1)

    # Predict
    try:
github mindsdb / mindsdb / integration_testing / run_a_file.py View on Github external
from mindsdb import Predictor


mdb = Predictor(name='suicide_model')
mdb.learn(from_data="integration_testing/suicide.csv", to_predict='suicides_no')

# use the model to make predictions
result = Predictor(name='suicide_rates').predict(when={'country':'Greece','year':1981,'sex':'male','age':'35-54','population':300000})

# you can now print the results
print(result)
github mindsdb / mindsdb / tests / functional_testing / analyse_dataset.py View on Github external
from mindsdb import Predictor


mdb = Predictor(name='analyse_dataset_test_predictor')
results = mdb.analyse_dataset(from_data="https://s3.eu-west-2.amazonaws.com/mindsdb-example-data/home_rentals.csv")
print('\n\n\n\n========================\n\n')
print(results)
github mindsdb / mindsdb / mindsdb / proxies / mysql / data_types / mysql_datum.py View on Github external
def test():


    import pprint

    log.basicConfig(level=10)
    u = Datum('int<8>',DEFAULT_CAPABILITIES >> 16)
    pprint.pprint(u.toStringPacket())