- Hands-On Artificial Intelligence for IoT
- Amita Kapoor
- 273字
- 2021-07-02 14:02:02
NoSQL data
The Not Only Structured Query Language (NoSQL) database is not a relational database; instead, data can be stored in key-value, JSON, document, columnar, or graph formats. They are frequently used in big data and real-time applications. We will learn here how to access NoSQL data using MongoDB, and we assume you have the MongoDB server configured properly and on:
- We will need to establish a connection with the Mongo daemon using the MongoClient object. The following code establishes the connection to the default host, localhost , and port (27017). And it gives us access to the database:
from pymongo import MongoClient
client = MongoClient()
db = client.test
- In this example, we try to load the cancer dataset available in scikit-learn to the Mongo database. So, we first get the breast cancer dataset and convert it to a pandas DataFrame:
from sklearn.datasets import load_breast_cancer
import pandas as pd
cancer = load_breast_cancer()
data = pd.DataFrame(cancer.data, columns=[cancer.feature_names])
data.head()
- Next, we convert this into the JSON format, use the json.loads() function to decode it, and insert the decoded data into the open database:
import json
data_in_json = data.to_json(orient='split')
rows = json.loads(data_in_json)
db.cancer_data.insert(rows)
- This will create a collection named cancer_data that contains the data. We can query the document we just created, using the cursor object:
cursor = db['cancer_data'].find({})
df = pd.DataFrame(list(cursor))
print(df)

When it comes to distributed data on the IoT, Hadoop Distributed File System (HDFS) is another popular method for providing distributed data storage and access in IoT systems. In the next section, we study how to access and store data in HDFS.
推薦閱讀
- 高效能辦公必修課:Word圖文處理
- 群體智能與數據挖掘
- JBoss ESB Beginner’s Guide
- 永磁同步電動機變頻調速系統及其控制(第2版)
- 信息物理系統(CPS)測試與評價技術
- 聊天機器人:入門、進階與實戰
- PVCBOT機器人控制技術入門
- Working with Linux:Quick Hacks for the Command Line
- 空間機器人
- Hands-On Deep Learning with Go
- Getting Started with Tableau 2019.2
- Intel Edison Projects
- 創客機器人實戰:基于Arduino和樹莓派
- Web滲透技術及實戰案例解析
- 軟件需求最佳實踐