An advanced Support Vector Machine (SVM) package implementing multiple kernel types and solvers. This package includes Nyström approximation, LaSVM, NySVM, and CoreSVM solvers to support a variety of SVM applications, including online learning and efficient kernel approximations. It supports various kernel functions and allows flexible kernel chaining through a tree structure for enhanced performance.
- Multiple Kernel Options: Support for Linear, Polynomial, RBF, Chi-squared, and other specialized kernels.
- Kernel Chaining: Flexible tree-based structure allowing combinations of multiple kernels.
- Nyström Approximation: Efficiently handles large datasets by approximating kernel matrices.
- Multiple Solvers: CoreSVM, NySVM, and LaSVM solvers with options for online learning.
- Customization: Allows custom kernel functions and multiple sampling strategies.
-
Clone the repository:
git clone https://github.com/Koaha/multiple_kernel.git cd multiple_kernel -
Install dependencies:
pip install -r requirements.txt
-
Set up the environment (optional, recommended for development):
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts�ctivate`
Here’s how to use the package for training and predicting with different SVM solvers.
-
Initialize
SVMWrapper:from svm_wrapper import SVMWrapper # Load toy data X_train, Y_train = ... # Training data and labels X_test = ... # Test data # Initialize SVM with CoreSVM solver svm = SVMWrapper(solver_type='coresvm', C=1.0, kernel='linear') svm.fit(X_train, Y_train) predictions = svm.predict(X_test)
-
Use Nyström Approximation:
# Define custom kernel function def rbf_kernel(x, y, gamma=0.5): return np.exp(-gamma * np.linalg.norm(x - y) ** 2) # Configure Nyström parameters nystrom_params = { 'X': X_train, 'kernel': rbf_kernel, 'sample_size': 100, 'sampling_method': 'kmeans' } # Initialize SVM with NySVM solver and Nyström approximation svm = SVMWrapper(solver_type='nysvm', use_nystrom=True, nystrom_params=nystrom_params, C=1.0) svm.fit(X_train, Y_train) predictions = svm.predict(X_test)
-
Online Learning with LaSVM:
# Initialize SVM with LaSVM solver lasvm = SVMWrapper(solver_type='lasvm', C=1.0, tau=0.1, kernel='rbf') lasvm.fit(X_train, Y_train) predictions = lasvm.predict(X_test)
- Linear Kernel
- Polynomial Kernel
- RBF (Gaussian) Kernel
- Chi-squared Kernel
- Laplacian Kernel
- Histogram Intersection Kernel
- Generalized Min Kernel
- Custom Kernel Support: Define your own kernel function to use in any solver.
- CoreSVM: Standard SVM using SMO with multiple kernel options.
- NySVM: SVM with Nyström approximation for handling large datasets.
- LaSVM: Online learning SVM that can dynamically update support vectors.
To run tests and check code coverage:
-
Run tests:
make test -
Generate a coverage report:
make coverage
Ensure code quality and style consistency by running:
make lintContributions are welcome! To contribute:
- Fork the repository.
- Create a new branch for your feature (
git checkout -b feature-name). - Commit your changes (
git commit -m 'Add new feature'). - Push the branch (
git push origin feature-name). - Open a pull request.
Feel free to reach out if you encounter issues or have suggestions for improvement.