Fuzzy machine learning algorithms implementing the scikit-learn interface.
https://github.com/sorend/fylearn.git
fylearn is a fuzzy machine learning library, built on top of SciKit-Learn.
SciKit-Learn contains many common machine learning algorithms, and is a good place to start if you want to play or program anything related to machine learning in Python. fylearn is not intended to be a replacement for SciKit-Learn (in fact fylearn depends on SciKit-Learn), but to provide an extra set of machine learning algorithms from the fuzzy logic community.
Machine learning algorithms
Fuzzy pattern classifiers are classifiers that describe data using fuzzy sets and fuzzy aggregation functions.
Several fuzzy pattern classifiers are implemented in the library:
A type of classifier that uses GA to optimize rules
Installation
pip install fylearn
You can use the classifiers as any other SciKit-Learn classifier:
from fylearn.nfpc import FuzzyPatternClassifier from fylearn.garules import MultimodalEvolutionaryClassifier from fylearn.fpt import FuzzyPatternTreeTopDownClassifier
C = (FuzzyPatternClassifier(), MultimodalEvolutionaryClassifier(), FuzzyPatternTreeTopDownClassifier())
for c in C: print c.fit(X, y).predict([1, 2, 3, 4])
Heuristic search methods
import numpy as np from fylearn.ga import UnitIntervalGeneticAlgorithm, helperfitness, helpern_generations from fylearn.localsearch import LocalUnimodalSamplingOptimizer, helpernum_runs from fylearn.tlbo import TeachingLearningBasedOptimizer from fylearn.jaya import JayaOptimizer
def fitness(x): # defined for a single chromosome, so we need helper_fitness for GA return np.sum(x**2)
ga = UnitIntervalGeneticAlgorithm(fitnessfunction=helperfitness(fitness), nchromosomes=100, ngenes=10) ga = helperngenerations(ga, 100) bestchromosomes, bestfitness = ga.best(1) print "GA solution", bestchromosomes[0], "fitness", bestfitness[0]
lowerbounds, upperbounds = np.ones(10) -10., np.ones(10) 10. lus = LocalUnimodalSamplingOptimizer(fitness, lowerbounds, upperbounds) bestsolution, bestfitness = helpernumruns(lus, 100) print "LUS solution", bestsolution, "fitness", bestfitness
tlbo = TeachingLearningBasedOptimizer(fitness, lowerbounds, upperbounds) tlbo = helperngenerations(tlbo, 100) bestsolution, bestfitness = tlbo.best() print "TLBO solution", bestsolution, "fitness", bestfitness
jaya = JayaOptimizer(fitness, lowerbounds, upperbounds) jaya = helperngenerations(jaya, 100) bestsolution, bestfitness = jaya.best() print "Jaya solution", bestsolution, "fitness", bestfitness
A tiny fuzzy logic library
import numpy as np from fylearn.fuzzylogic import TriangularSet t = TriangularSet(1.0, 4.0, 5.0) print t(3) # use with singletons print t(np.array([[1, 2, 3], [4, 5, 6]])) # use with arrays
Here focus has been on providing aggregation functions that support aggregation along a specified axis for 2-dimensional matrices.
Example use:
import numpy as np from fylearn.fuzzylogic import meowa, OWA a = OWA([1.0, 0.0, 0.0]) # pure AND in OWA X = np.random.rand(5, 3) print a(X) # AND row-wise a = meowa(5, 0.2) # OR, andness = 0.2 print a(X.T) # works column-wise, so apply to transposed X
To Do
Contributions: