Wine Cultivar Classifiers

k-NN, decision tree, and random forest classifiers for the UCI Wine dataset.

Try the demo

Results

Model Training CV accuracy Test accuracy
k-NN 0.9719 100.00%
Decision tree 0.9022 94.44%
Random forest 0.9791 100.00%

142 training samples and 36 test samples; stratified split with seed 42. Scaling is fitted within training cross-validation. The default classifier is selected by five-fold training CV. Results are from this small benchmark, not new wine sources.

K-means silhouette analysis is recorded separately in metrics.json. The highest score is 0.3102 at k = 3. Silhouette measures cluster separation, not classification accuracy.

Use the models

Use Python 3.12 and download this repository's files.

python -m pip install -r requirements.txt
import json
import joblib

models = joblib.load("models.joblib")
metrics = json.load(open("metrics.json"))
model = models[metrics["selected_by_training_cv"]]
sample = [[13.2, 2.0, 2.3, 19.0, 100, 2.2, 2.0, 0.3, 1.5, 5.0, 1.0, 2.7, 750]]
print(model.predict(sample))
print(model.predict_proba(sample))

Use the feature order listed in metrics.json. The output is cultivar class 1, 2, or 3. Load joblib files only from sources you trust.

To retrain:

python train.py

These models were retrained for the project update; the original notebook's saved scores are not reused. The original notebook version and current project home are recorded in source-manifest.json.

Data: Aeberhard & Forina (1992), UCI Wine, CC BY 4.0. Code and data retain their existing terms.

Downloads last month
-
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Space using iankamar/wine-cultivar-classifiers 1