Instructions to use sinxcosx11/honey-sugar-analysis with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use sinxcosx11/honey-sugar-analysis with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://sinxcosx11/honey-sugar-analysis") - Notebooks
- Google Colab
- Kaggle
YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
Honey Sugar Rate Predictor (FTIR-Based)
A hybrid machine learning project for predicting sugar content in honey samples using FTIR (Infrared Spectroscopy) data.
This model combines deep learning with classical chemometrics to remain stable and meaningful even on small datasets. The goal is not just prediction, but chemically sensible prediction.
Project Overview
- Input: Raw FTIR spectra (4000–650 cm⁻¹)
- Target: Sugar rate (%) in honey samples
- Dataset Size: 65 samples
- Special Focus: Robust performance at low sugar concentrations (10–20%), where most models collapse
Architecture
Hybrid Model
The system blends two complementary approaches:
- Triple-Scale 1D CNN
- Captures fine, medium, and broad spectral features
- Especially effective for subtle peak variations
- PLS Regression
- Provides chemically interpretable latent structure
- Stabilizes learning on small datasets
The outputs of both models are fused using an optimized nonlinear calibration function.
Spectral Preprocessing
- Crop to the Golden Region
1366–768 cm⁻¹ - Apply 2nd derivative transformation
- Enhances weak spectral features
- Reduces baseline drift and noise
Smart Calibration (Differential Evolution)
Instead of manually tuning coefficients, Differential Evolution was used to evolve the optimal calibration equation.
Why?
- Avoids arbitrary scaling constants
- Learns nonlinear relationships automatically
- Improves generalization on small datasets
“Brave Mode” Training Strategy
Low sugar concentrations produce weak FTIR signals.
Most models respond by predicting near-zero values.
This project modifies the fitness function to:
- Penalize underestimation in low-signal regions
- Encourage meaningful predictions instead of collapse
Result: significantly better performance in the 10–20% sugar range.
Final Prediction Formula
Base Combination
[ \text{Base} = (-0.1366 \cdot CNN_{raw}) + (0.7579 \cdot PLS_{raw}) ]
Golden Formula
[ y = 29.96 \cdot Base^{0.49} - 32.86 \cdot \ln(Base + 1) - 5.19 ]
Where:
CNN_raw= raw CNN outputPLS_raw= raw PLS outputy= predicted sugar percentage
Performance
| Metric | Value |
|---|---|
| Correlation (R) | 0.9074 |
| MAE | ~5.17% |
| Samples | 65 |
Given the dataset size, performance is strong and trend-following.
Files
honey_regression_model.keras
Trained CNN modelhoney_pls_component.pkl
PLS regression componentinference.py
Lightweight script for running predictions
Usage
- Load raw FTIR spectrum
- Crop to 1366–768 cm⁻¹
- Apply 2nd derivative preprocessing
- Run CNN + PLS inference
- Apply the Golden Formula for final prediction
License
MIT License
Free to use, modify, and build upon.
Author
Developed by a chemistry student
With assistance from some AI tools
- Downloads last month
- 5