Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created January 12, 2026 08:00
Show Gist options
  • Select an option

  • Save thinkphp/208def99c58db2e679bd596dd5926b71 to your computer and use it in GitHub Desktop.

Select an option

Save thinkphp/208def99c58db2e679bd596dd5926b71 to your computer and use it in GitHub Desktop.
IRIS
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
from sklearn.cluster import KMeans
#1. incarcarea setului de date Iris
iris = load_iris()
#2. Afisarea descrierii bazei de date
print("="*50)
print(iris.DESCR)
print("="*50)
#afisarea denumirii caracteristicilor
print("="*50)
print(iris.feature_names)
print("="*50)
#3 extragerea matricei datelor si afisarea dimensiunilor
X = iris.data
print("="*50)
print(f"Forma matricei: {X.shape}")
print(f"Numar de samples (linii): {X.shape[0]}")
print(f"Numar de features (coloane): {X.shape[1]}")
print("="*50)
#4 extragerea vectorului target
y = iris.target
etichete_unice = np.unique(y)
print("="*50)
print("ETICHETE in vectorul TARGET")
print("="*50)
print(f"Etichete unice: {etichete_unice}")
#Trebuie să obțineți: 0, 1, 2. 0 reprezintă Iris-Setosa, 1-Iris-Versicolor, 2-Iris-Verginica
#5 afisarea numarului de samples pe fiecare clasa
print("="*50)
for eticheta in etichete_unice:
count = np.sum(y == eticheta)
print(f"Clasa {eticheta}({iris.target_names[eticheta]}): {count} samples")
print("="*50)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment