This project implements a machine learning model in Go, focusing on data preprocessing, training, and evaluation. The model handles binary classification tasks and includes functions for splitting data, calculating probabilities, and saving/loading model parameters.
-
Clone the repository:
git clone https://github.com/Saurav-Navdhare/BayesianClassifier.git cd BayesianClassifier
-
Install dependencies:
go mod tidy
-
Data Preprocessing: Convert raw data into a format suitable for training.
import "BayesianClassifier/utils" data := [][]string{ {"Yes", "No", "Male"}, {"No", "Yes", "Female"}, } headers := []string{"Feature1", "Feature2", "Gender"} binaryData := utils.BinaryLabelling(data) df := utils.ConvertToDF(binaryData, headers)
-
Train-Test Split: Split the data into training and test sets.
import "BayesianClassifier/model" trainSet, testSet := model.TrainTestSplit(df, 0.2)
-
Model Training: Train the model using the training set.
classProbabilities, featureStats := model.CalculateProbabilities(trainSet)
-
Save Model: Save the trained model to a file.
model := model.Model{ ClassProbabilities: classProbabilities, FeatureStats: featureStats, } model.SaveModel("model.json", model)
-
Load Model: Load the model from a file and print the parameters.
loadedModel, err := model.LoadModel("model.json") if err != nil { log.Fatal(err) }
BinaryLabelling
: Converts categorical data into binary labels.ConvertToDF
: Converts a 2D slice of integers into a DataFrame-like map.
TrainTestSplit
: Splits the dataset into training and test sets.CalculateProbabilities
: Calculates class probabilities and feature statistics.
SaveModel
: Saves the model parameters to a JSON file.LoadModel
: Loads the model parameters from a JSON file and prints them.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
This project is licensed under the MIT License. See the LICENSE
file for details.