In Python machine learning, how do I store results in a database?

In Python machine learning, storing results in a database can be accomplished using various libraries such as SQLite, MySQL, or PostgreSQL. This allows you to maintain a permanent record of your machine learning outputs, making it easier to access and analyze data later.

Here's a simple example of how to store machine learning results in a SQLite database:

import sqlite3 import pandas as pd # Sample DataFrame with machine learning results results = pd.DataFrame({ 'model_name': ['Model A', 'Model B'], 'accuracy': [0.95, 0.92], 'timestamp': pd.Timestamp.now() }) # Connect to SQLite database (or create it if it doesn't exist) conn = sqlite3.connect('ml_results.db') # Save the DataFrame to the database results.to_sql('results', conn, if_exists='replace', index=False) # Close the database connection conn.close()

Python Machine Learning Database SQLite MySQL PostgreSQL Store Results