Fix explorer.md python codeblocks (#18471)

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
This commit is contained in:
Glenn Jocher 2025-01-02 21:11:17 +01:00 committed by GitHub
parent 26ff8b5914
commit 126867e355
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -53,9 +53,7 @@ Pip install `ultralytics` and [dependencies](https://github.com/ultralytics/ultr
```bash
%pip install ultralytics[explorer] openai
import ultralytics
ultralytics.checks()
yolo checks
```
## Similarity Search
@ -88,11 +86,9 @@ You can use the also plot the similar samples directly using the `plot_similar`
```python
exp.plot_similar(idx=6500, limit=20)
# exp.plot_similar(idx=[100,101], limit=10) # Can also pass list of idxs or imgs
exp.plot_similar(idx=[100, 101], limit=10) # Can also pass list of idxs or imgs
exp.plot_similar(
img="https://ultralytics.com/images/bus.jpg", limit=10, labels=False
) # Can also pass any external images
exp.plot_similar(img="https://ultralytics.com/images/bus.jpg", limit=10, labels=False) # Can also pass external images
```
![Similarity search image 2](https://github.com/ultralytics/docs/releases/download/0/similarity-search-image-2.avif)
@ -149,7 +145,7 @@ exp.plot_sql_query("WHERE labels LIKE '%person, person%' AND labels LIKE '%dog%'
```python
table = exp.sql_query("WHERE labels LIKE '%person, person%' AND labels LIKE '%dog%' LIMIT 10")
table
print(table)
```
Just like similarity search, you also get a util to directly plot the sql queries using `exp.plot_sql_query`
@ -166,7 +162,7 @@ Explorer works on [LanceDB](https://lancedb.github.io/lancedb/) tables internall
```python
table = exp.table
table.schema
print(table.schema)
```
### Run raw queries¶
@ -213,12 +209,8 @@ One of the preliminary steps in analysing embeddings is by plotting them in 2D s
![Scatterplot Example](https://github.com/ultralytics/docs/releases/download/0/scatterplot-sql-queries.avif)
```python
pip install scikit-learn
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from sklearn.decomposition import PCA
from sklearn.decomposition import PCA # pip install scikit-learn
# Reduce dimensions using PCA to 3 components for visualization in 3D
pca = PCA(n_components=3)