Welcome to the Binary Classifier Models repository. This library provides two simple, easy-to-understand implementations of fundamental machine learning algorithms for binary classification tasks, built with pure Python and NumPy.
- Decision Tree (
dt.py): A depth-limited decision tree that splits features based on thresholding at 0.5. - Perceptron (
main.py): A classic single-layer perceptron suitable for linearly separable data.
- Clone the repository:
git clone https://github.com/myrodar/AI_cookbook.git cd your-repo - (Optional) Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate - Install dependencies:
pip install -r requirements.txt
Coming soon!
-
DT(opts: dict)
Initialize with options:opts['maxDepth']: Maximum depth of the tree.
-
train(X: np.ndarray, Y: Sequence[int])
Build the decision tree from the data. -
predict(x: np.ndarray) -> int
Predict the label (-1or1) for a single sample. -
__repr__()/displayTree()
Print a human-readable representation of the tree.
This folder contains two scripts.
This folder contains two scripts:
-
main.pyis the main script for the raw perceptron. It contains the Perceptron class and its main function to instantiate, train, and predict based on the data you provide. -
test.pyuses the Perceptron implementation frommain.pyand generates a visual representation of the decision boundary, allowing you to see how the single neuron learns. -
Challenge: Try swapping the generated dataset for the Iris dataset. Be sure to use only two classes from the Iris dataset, as a perceptron can only perform binary classification.
Contributions are welcome. To contribute: Contributions are welcome. To contribute:
- Fork the repository.
- Create a new branch:
git checkout -b feature/your-feature. - Commit your changes and push your branch.
- Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.