Supercharge Your Data Insights With Neural Networks - Here's A Powerful, Easy-To-Use Suite Of Tools
I've spent the last few weeks developing an easy to use set of scripts and html pages for training neural networks and visualizing the results
Check out this video explainer for the project:
Main Code Base:
neural_network_trainer.py
ffnn_model.py
modelToJSON.py
Model Training Example Scripts:
nNetTrainerRunner2D.py
nNetTrainerRunner3D.py
nNetTrainerRunner2DAndCategs.py
Equation Samplers (For Generating Data To Test Model Training):
create2DDatasetForRegressionTraining.html
create3DDatasetForRegressionTraining.html
createCategoricalDatasetForRegressionTraining.html
Prediction Visualizers (For Visualizing Model Predictions Fit To Actual Data):
ModelPredictionViewer.html
ModelPredictionViewer3D.html
ModelPredictionViewer2DWithCategs.html
simplifyMLResultsDatasetCSV.py
simplifyMLResultsDatasetCSV_WithCategs.py
Make Predictions From Saved Model Example Scripts:
makePredictionsRunner2D.py
makePredictionsRunner3D.py
makePredictionsRunner2DAndCategs.py
Assorted:
printCategoryEmbeddingsForModel.py
Main Code Base:
neural_network_trainer.py - The most important class, responsible for loading up data from a csv and training a model, either from scratch or loaded from a saved file, and saving the new trained model to a file. The NeuralNetworkTrainer class provides a comprehensive framework for training and managing a neural network model, supporting features like model initialization, data normalization, training, saving, and making predictions.
Example Usage, Training From Scratch:
trainer = NeuralNetworkTrainer(
csv_path='C:\path\to\my\csvFile.csv',
numerical_features=['x', 'y'],
categorical_features=[{"categoryTitle": 'color', "classes": ['Red', 'Green', 'Blue'], "embedDims":2}],
target='z',
config={
'hidden_sizes': [1000],
'dropout': 0,
'activation': 'ReLU'
},
save_model_path='C:\path\to\save\theModel.pth'
)
trainer.run_training(num_runs=1, epochs=100000, learning_rate=0.01)
Example Usage, Training From Saved Model:
trainer = NeuralNetworkTrainer(
csv_path='C:\path\to\my\csvFile.csv',
load_model_path='C:\path\to\save\theModel.pth',
numerical_features=['x', 'y'],
categorical_features=[{"categoryTitle": 'color', "classes": ['Red', 'Green', 'Blue'], "embedDims":2}],
target='z',
save_model_path='C:\path\to\save\theNewUpdatedModel.pth'
)
trainer.run_training(num_runs=1, epochs=100000, learning_rate=0.01)
Included Training Example Scripts:
nNetTrainerRunner.py - This script shows how to train a neural network model with 1 input numerical feature and 1 target numerical feature. The default code shows how to load the model from scratch using an included csv file (you can make more CSVs to train models using create2DDatasetForRegressionTraining.html). Once you've trained your first model, you can comment out the first part of the code and uncomment the second part of the code to then train your saved model further (just make sure you update the path to the model to match it's location). You can use ModelPredictionViewer.html to visualize the performance of the model in chart format. You can quickly make predictions with your trained models with makePredictionsRunner2D.py
nNetTrainerRunner3D.py - This script shows how to train a neural network model with 2 input numerical features and 1 target numerical feature. You can make more CSVs to train models using create3DDatasetForRegressionTraining.html. Once you've trained your first model, you can comment out the first part of the code and uncomment the second part of the code to then train your saved model further (just make sure you update the path to the model to match it's location). You can use ModelPredictionViewer3D.html to visualize the performance of the model in chart format. You can quickly make predictions with your trained models with makePredictionsRunner3D.py
nNetTrainerRunner2DAndCategs.py - This script shows how to train a neural network model with 1 input numerical feature, 1 category feature and 1 target numerical feature. You can make more CSVs to train models using createCategoricalDatasetForRegressionTraining.html. Once you've trained your first model, you can comment out the first part of the code and uncomment the second part of the code to then train your saved model further (just make sure you update the path to the model to match it's location). You can use ModelPredictionViewer2DWithCategs.html to visualize the performance of the model in chart format. You can quickly make predictions with your trained models with makePredictionsRunner2DAndCategs.py
NeuralNetworkTrainer Parameters
csv_path (str): Path to the CSV file containing the dataset to use for training
numerical_features (list): List of numerical feature names.
categorical_features (list): List of categorical feature dictionaries, each with 'categoryTitle' and 'embedDims'.
target (str): Name of the target column. This is the value the model trains to predict
load_model_path (str): Path to a pre-trained model to load
config (dict): Configuration dictionary for the neural network model when making the model from scratch - not needed if load_model_path is set
save_model_path (str): Path to save the trained model.
save_weights_bias_json (bool): Flag to save the model's weights and biases to a JSON file (defaults to true)
save_predictions_csv (bool): Flag to save predictions to a CSV file (defaults to true)
device (torch.device): Device on which to run the model (CPU or GPU) (defaults to best available)
Other Useful Scripts:
If you want to reduce the number of datapoints after training for an optimal viewing experience in your browser:
Use simplifyMLResultsDatasetCSV.py if you made the data with create2DDatasetForRegressionTraining.html or create3DDatasetForRegressionTraining.html (or using the sample csv)
Or use simplifyMLResultsDatasetCSV_WithCategs.py if you made the data with createCategoricalDatasetForRegressionTraining.html (or using the sample csv with categories)