Posts

Tensorflow.js, Epoch, Batch and Learning Rate

In Tensorflow.js , training a model involves configuring three critical hyperparameters: Epochs, Batch Size, and Learning Rate. These determine how often the model updates, how many samples it sees at once, and how much it adjusts its internal parameters during training. Epochs An epoch is one complete pass of the entire training dataset through the model. Function: It defines the duration of the training process. Purpose: Training for multiple epochs allows the model to see the data repeatedly, which is necessary for the weights to converge to an optimal state. Usage: It is defined in the model.fit() or model.fitDataset() configuration. Risk: Too few epochs lead to underfitting (the model hasn't learned enough), while too many can lead to overfitting (the model memorizes the training data but fails on new data). Batch Size The batch size is the number of samples processed before the model updates its internal weights. Efficiency: I...

Powerball (Lottery) prediction using TensorFlow.js LSTM model - Grok Generated

Using Tensorflow.js to build an LSTM model for Powerball (Lottery) prediction is an interesting exercise, but it’s important to note that Powerball numbers are drawn randomly, and no model can reliably predict future outcomes due to the inherent randomness and lack of temporal dependencies in lottery draws. However, Tensorflow.js LSTM model can be used to predict the next set of Powerball numbers based on historical data, treating it as a time series problem for illustrative purposes. The model will attempt to learn patterns in the sequence of past draws, though its predictive power is limited by the random nature of the lottery. Approach Data : Powerball draws consist of 5 main numbers (1–69) and 1 Powerball number (1–26). We’ll treat each draw as a time step with 6 features (5 main numbers + 1 Powerball). Preprocessing : Normalize the numbers (e.g., scale to [0,1] by dividing main numbers by 69 and Powerball by 26). Create sequences of past draws (e.g., 10 draws) to p...

LSTM for Time Series in TensorFlow.js - Grok Generated

Tensorflow.js is a JavaScript library for training and deploying machine learning models in the browser or Node.js . It supports Long Short-Term Memory (LSTM) networks, a type of recurrent neural network (RNN) well-suited for time series data due to their ability to capture long-term dependencies and handle sequential data effectively. ### Key Concepts of LSTM for Time Series in Tensorflow.js **Time Series Data** : Time series data consists of sequences of data points ordered by time (e.g., stock prices, temperature readings, or sensor data). For LSTM modeling, the data is typically formatted as a sequence of observations over fixed time steps, often in the shape `[samples, timeSteps, features]`. samples : Number of sequences (or batches). timeSteps : Number of time steps in each sequence (e.g., 10 days of data). features : Number of variables at each time step (e.g., temperature, humidity). **LSTM A...

Powerball (Lottery) prediction using TensorFlow.js LSTM Time Series - ChatGPT Generated

If you're looking to build a Tensorflow.js LSTM model to predict the Powerball numbers (or any lottery game based on time series data), it's important to note a few things upfront: Lottery Numbers Are Random : The numbers in Powerball are drawn randomly. Predicting random numbers is inherently unreliable because there is no underlying pattern. However, for educational purposes, you could treat Powerball draws as a time series problem, even though the model won't have any real predictive power. In practice, this exercise could be useful for learning time series prediction techniques. Data Structure : Powerball numbers consist of 5 white balls (with numbers from 1 to 69) and a Powerball (with numbers from 1 to 26). Each draw can be treated as a sequence of 6 numbers (5 white balls + 1 Powerball). In a time series context, this means you're predicting sequences of numbers over time. Model Setup : The model will learn from historical data to predict the next Pow...

TensorFlow.js LSTM Time Series - ChatGPT Generated

Creating an LSTM ( Long Short-Term Memory ) model for time series prediction in Tensorflow.js involves several steps. this will guide you through the process, starting from data preparation to model training and prediction. Prerequisites: Install Tensorflow.js in your project: npm install @tensorflow/tfjs Import Tensorflow.js into your code: import * as tf from '@tensorflow/tfjs'; Step-by-Step Example for LSTM Time Series Prediction in Tensorflow.js Let’s assume you have a time series dataset for a univariate problem (e.g., stock prices, temperature, etc.). Step 1: Prepare the Data You’ll need to process your data into a format suitable for time series forecasting. This usually involves: Normalizing the data. Converting the data into sequences that the LSTM can learn from. For example, given a sequence of time steps, you can create sequences of input features (X) and output labels (y). function prepareData(data, lookback) { const X =...

Powerball (Lottery) “Forecasting” with Tensorflow.js and LSTM - CoPilot Generated

Adapting the stock‐forecasting pipeline to ingest historical Powerball draws, train an LSTM on sequences of past draws, and “predict” the next draw. Note that Powerball is random—this is purely experimental and not a reliable method for winning. Prerequisites Initialize Node.js project and isntall: mkdir tfjs-powerball cd tfjs-powerball npm init ‑y npm install @tensorflow/tfjs-node csv-parser csv-writer Package Purpose @tensorflow/tfjs-node Run Tensorflow.js models in Node csv-parser Parse historical Powerball CSV files csv-writer Export results for plotting/analysis Obtain Historical Data Download a CSV of past Powerball results, with columns like: Draw Date White Ball 1 White Ball 2 White Ball 3 White Ball 4 White Ball 5 Red Ball 2025-07-30 4 15 35 50 64 8 ..... ..... ..... .....

Full Pipeline: Stock Price Forecasting with Tensorflow.js and LSTM - CoPilot Generated

🧪 Project Workflow This project walks through: Fetching stock data via Alpha Vantage Computing Simple Moving Average (SMA) to smooth the data Training an LSTM model using Tensorflow.js Predicting future prices and comparing them to actual values 📦 Dataset Source: Alpha Vantage API You can fetch historical stock prices using the Alpha Vantage API, which provides: Daily or weekly adjusted closing prices Open, high, low, close, volume Up to 20 years of historical data Time Series Forecasting with Tensorflow.js 🛠️ How to Use the Alpha Vantage API Sign up at Alpha Vantage Get your free API key Use this endpoint to fetch daily prices: https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=MSFT&apikey=YOUR_API_KEY 🧠 LSTM Model in Tensorflow.js Here’s a simplified version of the model setup: const model = tf.sequential(); model.add(tf.layers.lstm({ units: 64, inputShape: [sequenceLength, 1], ...

Stock Price Forecasting using Tensorflow.js and LSTM, based on a well-documented project: - CoPilot Generated

Project Example: Stock Price Forecasting with Tensorflow.js A GitHub project by jinglescode demonstrates how to: Pull stock prices using the Alpha Vantage API Preprocess data using Simple Moving Average Train an LSTM neural network in Tensorflow.js Predict future stock prices and compare them to actual values Why LSTM for Time Series? LSTM (Long Short-Term Memory) networks are ideal for time series because they: Capture long-term dependencies Handle non-linear relationships Work with variable-length sequences Automatically learn relevant features from raw data 🛠️ Tensorflow.js Implementation Tips To build your own LSTM time series model in TensorFlow.js: Prepare your data: Normalize and shape it into sequences. Define the model: const model = tf.sequential(); model.add(tf.layers.lstm({ units: 50, returnSequences: false, inputShape: [sequenceLength, numFeatures] })); model.add(tf.layers.dense({ units: 1 })); model.c...

Tensorflow.js LSTM Time Series - Gemini Generated

Implementing time series forecasting with TensorFlow.js and LSTMs Tensorflow.js enables you to build and train machine learning models, including Long Short-Term Memory (LSTM) networks, directly within a web browser using JavaScript. LSTMs are particularly well-suited for time series forecasting due to their ability to capture long-term dependencies and patterns within sequential data. Here's a breakdown of the key steps involved: Data acquisition and preparation Gather Time Series Data: Obtain your time series data, for example stock prices from an online API like Alpha Vantage. Feature Engineering (Optional): Extract relevant features, like a simple moving average (SMA), from the raw data. Create Training and Validation Sets: Split your data into training and validation sets to evaluate model performance on unseen data. Format for LSTM: Structure your data into sequences (e.g., using a sliding window) where each input sequence (X) ...

The juice is not worth the squeeze

That is not an original quote or thought. I heard it while streaming live my daily go-to source of news and current affairs - C-SPAN . For whatever reason the quote stuck in my sub-conscious and triggered a deep dive self-reflection mentally on the full meaning and import of the quote - "The Juice is not worth the squeeze - the end game is not commesurate with the load up front". It then led me to ponder the real purpose of life? That is a million dollar question whose answer or response depends on the respondent. Personally though, I think the purpose of life is a sum zero game in the sense that - if you look at it really critically, it is all for nothing - it is all vanity. I am not sure the Earth - nay the universe - is adversely affected one way or the other if we were alive or dead. We are given birth to (or conceived in a petri dish and nutured to full term outside of the womb) , we strive to become somebody or something in life - we strive for success and if s...

Just for Laffs

Why did the developer go broke? - Because he used up all his cache!!! Maybe he can find some money deeper in the stack. Now he is in the food shelf queue. Last night, he got arrested for an access violation, breaking into a closed grocery store. Looking for Eggs?! He just wanted a few bytes. I think he wanted an Apple. He got a virus when he left his Windows open. This guy was a real hacker; he didn't have a valid license. What are we talking about? It's technical. Oh.. its bad pun day. The boss found his cookies, and they are now gone. Lost in the stack. Overflow? These azure are puns. What did the server say to the cloud? “You lift me up!” I won't have to put up with these puns for much longer. I can see my retirement on the horizon. What would the Terminator be called after retirement? - The Exterminator. Ex-terminator? - ARNOLD Why don't drummers come out of retirement? - Too many repercussion...

Random Musings

Way back when I just set out in the IT world, I attended an interview for an open position as a Programmer/Analyst (I hardly see any opening bearing that title anymore). The Interviewer asked me, amongst others, to explain my understanding of the concept of "Portability" in relation to software development. To be frank - I did not know the answer but I thought I could pull a fast one by just explaining it within the concept of the gramatical meaning. So, I replied that it was when a piece of software code was "small" and "compact". The Interviewer kept nodging me on as if I was on the right track. To my surprise -I did not get the job but of course, my response was way wrong but the interviewer gave me false hope with his body language. Moral of the story - don't try to adjudge the outcome of an interview based on the body language of the Interviewer - it could just be a red herring. Why do interviewers always ask - "where do you see your...

Artificial Intelligence, Oxymoron and Natural Intelligence

Image
I posted this question to a couple of online AI engines and to my surprise, none came up with the correct anwser. This is the question - "Two Americans were crossing a bridge on a bright summer morning, one was the father of the other and the other wasn't the son. So, what was their relationship?" This is a classic IQ question - supposedly, employed by Microsoft in the easrly 90s in the recruitment of top talent for its work pool. Essentially, this is a mis-direction fixation challenge. On the surface - it is a fairly straight forward question with the requisite hint at solving it. For whatever reason, most people asked this question are always fixated on the "father and son" narative, which in reality - is the hint to solving the question, but always end up getting it wrong. My point really is - the so called AI engines got the answer to the question wrong as well. The real poser is - should we still be referring to the encompassing ecosystem...

Mythical Man Month, Project Failures and the Knight in Shining Armor

Mythical Man Month is the title of a collection of essays in software engineering  and project management - covering the  good and bad practices in the IT sector. It was first written in the 70s and later updated in the 80s and 90s subsequently. One of the chapters in the book that caught my fancy then was the one aptly titled - "The second time effect" . Basically, the chapter is a treatise about the desire to tend to over do things when given the chance to upgrade or rewrite an existing application - so called version 2.0 There is always the tendency attempting to fix all the so called real and imaginary flaws found in version 1 and more often than not - you'll end up with a revised edition that is unduly bulky and overtly prone to more errors than version 1. I had a first hand experience in a similar situation and I'll be sharing my observations and hopefully, this could serve as a panacea to avoid a similar pitfall. Essentially, I became the honcho man supervisin...

Tensorflow.js load latest API and find/display the version

Working on Tensorflow.js API and wanted to find out how to accomplish the following: Load the latest Tensorflow.js API without recourse to the version number. Find out or print out the version of the library loaded. On the surface - these tasks look pretty simple and should not be any biggies but as usual, the Devil is in the details. Unfurtunately, I could not find any easy reference to accomplish them. Anyway, without much ado - following these steps would get you to El Dorado: <script src=" https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-vis@1.0.2/dist/tfjs-vis.umd.min.js "> </script> Add an event listener at the bottom of your htlm page, extract the version and spew it out to a place holder. <div id="version"> </div> <script> window.addEventListener('load', (event) => { ...

C# - Making Multiple instances from a STATIC class

STATIC classes are basically meant to be like global references in an application - created once and used for the lifetime of the application.  The primary advantage of this - apart from the obvious small footprint, is the fact that you don't need to instantiate a new instance of the class whenever you want to reference any of its members.  One of the requirements for using a STATIC class is that all the publicly accessible members must also be qualified with the STATIC reserved word.  Essentially, it means only one copy of the method is maintained throughout the life cycle of the application. In order to ensure some level of sanity, it is recommended that one does not pass parameters by reference to STATIC methods but rather, pass in your parameters by values, perform any processed needed and return any value - if needed, by value as well.  Sometimes though, you want to leverage on the simplicity offered by the STATIC class usage in terms of no instance - new clas...