DynamicSuperb/Covid19CoughAudioClassification_CoughVid
Viewer • Updated • 972 • 44
How to use greenarcade/cough-classification-model with Keras:
# Available backend options are: "jax", "torch", "tensorflow".
import os
os.environ["KERAS_BACKEND"] = "jax"
import keras
model = keras.saving.load_model("hf://greenarcade/cough-classification-model")
This Random Forest model classifies cough audio recordings into three categories: COVID-19, healthy, and symptomatic.
This model is intended for research purposes only and should not be used for medical diagnosis. It demonstrates how machine learning can identify patterns in cough audio that might correlate with health status.
| Class | Precision | Recall | F1-Score | Support |
|---|---|---|---|---|
| COVID-19 | 0.82 | 0.75 | 0.78 | 20 |
| healthy | 0.79 | 0.85 | 0.82 | 20 |
| symptomatic | 0.70 | 0.70 | 0.70 | 20 |
| accuracy | 0.77 | 60 | ||
| macro avg | 0.77 | 0.77 | 0.77 | 60 |
| weighted avg | 0.77 | 0.77 | 0.77 | 60 |
Top 5 features identified by the model:
The model achieves 77% overall accuracy, with slightly better performance on healthy coughs compared to COVID-19 and symptomatic coughs.
import pickle
from librosa import load
import pandas as pd
import numpy as np
# Function to extract features (see source code for implementation)
def extract_all_features(audio_path):
# Implementation here - refer to original code
pass
# Load model components
with open('cough_classification_model.pkl', 'rb') as f:
components = pickle.load(f)
model = components['model']
scaler = components['scaler']
label_encoder = components['label_encoder']
feature_names = components['feature_names']
# Extract features from a new audio file
features = extract_all_features('path/to/cough_recording.wav')
# Prepare features
features_df = pd.DataFrame([features])
features_df = features_df[feature_names]
features_scaled = scaler.transform(features_df)
# Make prediction
prediction_idx = model.predict(features_scaled)[0]
prediction = label_encoder.inverse_transform([prediction_idx])[0]
probabilities = model.predict_proba(features_scaled)[0]
print(f"Predicted status: {prediction}")
print("Class probabilities:")
for idx, prob in enumerate(probabilities):
class_name = label_encoder.inverse_transform([idx])[0]
print(f" {class_name}: {prob:.4f}")
Base model
google/hear-pytorch