Skip to content

Repository files navigation

Weight Calculation for Semi-Supervised Learning

This package provides tools for calculating weights for test data based on training data using nearest neighbors and various distance measures. The implementation leverages scikit-learn, scipy, and joblib for efficient computation.

https://pypi.org/project/db-weights/

Features

  • Calculate weights using Nearest Neighbors
  • Calculate weights using different distance measures
  • Supports various distance metrics including Euclidean, Mahalanobis, Cosine, etc.
  • Parallel processing for faster computation

Installation

You can install the package using pip:

pip install db-weights

Usage

Importing the package

importnumpyasnpfromdb_weightsimportWeightCalculator

Creating a WeightCalculator instance

weight_calculator=WeightCalculator(n_neighbors=3, algorithm='auto', n_jobs=-1)

Calculating weights using Nearest Neighbors

x_train=np.random.rand(100, 5) # Training datax_test=np.random.rand(20, 5) # Test dataweights_nn=weight_calculator.calculate_weights_nn(x_train, x_test, weight=1)
print(weights_nn)

Calculating weights using distance measures

weights_dist=weight_calculator.calculate_weights_dist(x_train, x_test, weight=1, measure_type='euclidean')
print(weights_dist)

Getting available distance measures

measurements=weight_calculator.get_measurements()
print(measurements)

Make WHL

pipinstallsetuptoolswheelpythonsetup.pysdistbdist_wheel

Dependencies

  • numpy
  • scikit-learn
  • scipy
  • joblib

Contributing

Contributions are welcome. Please fork the repository and submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

distance based wighting to calculate weights of training records, considering the distance from test set

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages