Downloads · 30 days
0
studentscolab/iris_keras
iris_keras is a tabular classification model from studentscolab. Use it for the tabular classification task on the model card, and read the license before you ship it in a product. It is set up for tensorflow. The card lists the license as mit.
This repository contains a simple multiclass classifier for the classic Iris dataset, implemented as a small MLP (Multi-Layer Perceptron) in TensorFlow / Keras. The model predicts one of three classes based on four nu…
Downloads · 30 days
0
Access
Public
Updated Mar 3, 2026
Repo size
—
Likes
0
Public
Click a slice to open those files.
.keras33.7 KB · 88%
From the Hugging Face model README
This repository contains a simple multiclass classifier for the classic Iris dataset, implemented as a small MLP (Multi-Layer Perceptron) in TensorFlow / Keras.
The model predicts one of three classes based on four numerical features.
Tabular multiclass classification
Given the 4 iris measurements, predict the class:
0 → setosa1 → versicolor2 → virginicaIris dataset (from sklearn.datasets.load_iris)
The model expects 4 float features in this exact order:
sepal length (cm)sepal width (cm)petal length (cm)petal width (cm)y ∈ {0,1,2}sparse_categorical_crossentropy)A small feed-forward network with built-in feature normalization:
Normalization layer?The tf.keras.layers.Normalization layer learns feature-wise mean and variance from the training set via adapt(...).
This makes inference easier and safer: the same scaling used during training is embedded inside the saved model.
learning_rate=1e-3)sparse_categorical_crossentropystratify=y, random_state=42)validation_split=0.2)tf.random.set_seed(42)np.random.seed(42)Note: Exact accuracy may vary slightly across environments due to numerical differences and nondeterminism in some TF ops.
The model was trained using the following core logic (simplified):
normalizer = tf.keras.layers.Normalization(axis=-1)
normalizer.adapt(X_train.to_numpy())
model = tf.keras.Sequential([
tf.keras.Input(shape=(4,)),
normalizer,
tf.keras.layers.Dense(16, activation="relu"),
tf.keras.layers.Dense(16, activation="relu"),
tf.keras.layers.Dense(3, activation="softmax"),
])
model.compile(
optimizer=tf.keras.optimizers.Adam(learning_rate=1e-3),
loss="sparse_categorical_crossentropy",
metrics=["accuracy"]
)
model.fit(
X_train.to_numpy(), y_train.to_numpy(),
validation_split=0.2,
epochs=100,
batch_size=16,
verbose=0
)
import numpy as np
import pandas as pd
import tensorflow as tf
from huggingface_hub import hf_hub_download
filename = "iris_mlp.keras"
repo_id = "studentscolab/iris_keras"
model_path = hf_hub_download(repo_id=repo_id, filename=filename)
model = tf.keras.models.load_model(model_path)
x_new = pd.DataFrame([{
"sepal length (cm)": 5.1,
"sepal width (cm)": 3.5,
"petal length (cm)": 1.4,
"petal width (cm)": 0.2,
}])
proba = model.predict(x_new.to_numpy(), verbose=0)[0] # shape: (3,)
pred = int(np.argmax(proba))
print("Probabilities:", proba)
print("Predicted class:", pred)