Interactive web-based machine learning demos showcasing linear regression and binary classification using TensorFlow.js. Built with Materialize CSS framework for a clean, modern interface.
- Linear Regression Demo: Predicts house prices using the King County housing dataset
- Binary Classification Demo: COVID-19 case prediction using US counties data
- Real-time Visualization: Interactive plots using TensorFlow Vis
- In-Browser Training: All ML models train directly in the browser using TensorFlow.js
- Modern UI: Clean interface built with Materialize CSS
- Framework: TensorFlow.js 2.0+
- Visualization: TensorFlow Vis for interactive charts
- Frontend: HTML5, Vanilla JavaScript
- Styling: Materialize CSS, Bootstrap
- Server: HTTP-server for local development
- Node.js 14+ and npm
- Clone the repository:
git clone https://github.com/CodeBalch25/Machine-Learning-Tensorflow.js.git
cd Machine-Learning-Tensorflow.js- Install dependencies:
npm install- Start the development server:
npm start- Open your browser and navigate to:
- Linear Regression:
http://localhost:8080/linearregression.html - Binary Classification:
http://localhost:8080/binaryclassification.html
- Linear Regression:
Machine-Learning-Tensorflow.js/
├── linearregression.html # House price prediction demo
├── binaryclassification.html # COVID-19 case classification
├── kc_house_data.csv # King County housing dataset
├── us-counties.csv # US counties COVID data
├── package.json # Node dependencies
└── README.md # Documentation
Dataset: King County Housing Data
- Features: Square footage, bedrooms, bathrooms, year built, etc.
- Target: House sale prices
- Techniques: Feature normalization, gradient descent optimization
Key Features:
- Interactive scatter plots showing prediction accuracy
- Real-time training loss visualization
- Multiple feature exploration
- Model performance metrics
Dataset: US Counties Data
- Features: Population, demographics, geographic data
- Target: Binary classification (High/Low risk)
- Techniques: Logistic regression, sigmoid activation
Key Features:
- Decision boundary visualization
- Confusion matrix display
- Precision and recall metrics
- ROC curve analysis
- Load and normalize housing data
- Create TensorFlow.js sequential model
- Define loss function (Mean Squared Error)
- Train using Adam optimizer
- Visualize predictions vs actual values
- Evaluate model performance
- Load and preprocess county data
- Build neural network with sigmoid output
- Binary cross-entropy loss function
- Train with mini-batch gradient descent
- Plot decision boundaries
- Calculate accuracy and F1 score
const model = tf.sequential();
model.add(tf.layers.dense({
inputShape: [1],
units: 1
}));
model.compile({
optimizer: tf.train.adam(),
loss: 'meanSquaredError'
});await model.fit(trainX, trainY, {
epochs: 100,
callbacks: {
onEpochEnd: (epoch, logs) => {
console.log(`Epoch ${epoch}: loss = ${logs.loss}`);
}
}
});{
"@tensorflow/tfjs": "^2.0.1",
"@tensorflow/tfjs-node": "^2.0.1",
"@tensorflow/tfjs-vis": "latest",
"http-server": "^0.12.3"
}- Training Speed: Optimized for browser execution using WebGL
- Model Size: Lightweight models (~100KB)
- Inference Time: Real-time predictions (<10ms)
- Browser Support: Chrome, Firefox, Safari, Edge (modern versions)
- Records: 21,000+ home sales
- Features: 19 numerical and categorical variables
- Time Period: 2014-2015
- Source: Public county records
- Records: 3,000+ US counties
- Features: Population, cases, deaths, geographic data
- Updated: Real-time (dependent on source)
- Add CNN for image classification
- Implement transfer learning demos
- Add NLP sentiment analysis example
- Mobile-responsive design improvements
- Save/load trained models
- Add more datasets and examples
This project demonstrates:
- TensorFlow.js fundamentals
- Model training in the browser
- Data preprocessing techniques
- Visualization best practices
- Gradient descent optimization
- Evaluation metrics
- Chrome 80+
- Firefox 75+
- Safari 13+
- Edge 80+
This project is open source and available under the MIT License.
Timothy Balch - @CodeBalch25
- TensorFlow.js team for the amazing framework
- Materialize CSS for the UI components
- Google Developers for TensorFlow Vis
tensorflow-js machine-learning web-ml javascript linear-regression classification data-science browser-ml interactive-visualization