-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In this example, we will use a data set of Iris flowers to create a flower species classifier based on their characteristics.
- Loading branch information
1 parent
b9b5700
commit cdae4a6
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from sklearn.datasets import load_iris | ||
from sklearn.model_selection import train_test_split | ||
from sklearn.neighbors import KNeighborsClassifier | ||
from sklearn.metrics import accuracy_score | ||
|
||
# Paso 1: Cargar el conjunto de datos | ||
iris = load_iris() | ||
X = iris.data | ||
y = iris.target | ||
|
||
# Paso 2: Dividir el conjunto de datos en conjuntos de entrenamiento y prueba | ||
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) | ||
|
||
# Paso 3: Crear y entrenar el modelo | ||
clf = KNeighborsClassifier(n_neighbors=3) | ||
clf.fit(X_train, y_train) | ||
|
||
# Paso 4: Realizar predicciones | ||
y_pred = clf.predict(X_test) | ||
|
||
# Paso 5: Evaluar el rendimiento del modelo | ||
precision = accuracy_score(y_test, y_pred) | ||
print("Precisión del modelo:", precision) | ||
|
||
# Paso 6: Utilizar el modelo para hacer predicciones nuevas | ||
nuevas_caracteristicas = [[5.1, 3.5, 1.4, 0.2]] # Nuevas características de una flor | ||
prediccion = clf.predict(nuevas_caracteristicas) | ||
print("Predicción:", iris.target_names[prediccion]) |