Permalink
Browse files

Added PyML

  • Loading branch information...
pranjalv123 committed Jan 11, 2012
1 parent f0d6be9 commit d767c9f2bfa8cce523201f104f3de5ad296f7db9
Showing 1,038 changed files with 508,552 additions and 0 deletions.
View
Binary file not shown.
View
Binary file not shown.
View
@@ -0,0 +1,19 @@
+
+PyML -- a machine learning library in python.
+
+Copyright (C) 2004-2011 Asa Ben-Hur
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
View
@@ -0,0 +1,10 @@
+Metadata-Version: 1.0
+Name: PyML
+Version: 0.7.9
+Summary: PyML - a Python machine learning package
+Home-page: http://pyml.sourceforge.net
+Author: Asa Ben-Hur
+Author-email: myfirstname@cs.colostate.edu
+License: GPL
+Description: UNKNOWN
+Platform: UNKNOWN
Binary file not shown.
@@ -0,0 +1,8 @@
+
+__version__ = '0.7.9'
+
+from PyML.containers import *
+from PyML.classifiers import *
+from PyML.preproc import *
+from PyML.demo import *
+from PyML.feature_selection import *
Binary file not shown.
@@ -0,0 +1,2 @@
+
+#PyMLobject = __import__('base.pymlObject').pymlObject.PyMLobject
@@ -0,0 +1,19 @@
+
+class PyMLobject (object) :
+
+ def __init__(self, arg=None, **args) :
+ """
+ Takes care of keyword arguments that are defined in the attributes
+ class attribute
+ """
+ if not hasattr(self, 'attributes') : return
+ if self.__class__ == arg.__class__ :
+ for attribute in self.attributes :
+ setattr(self, attribute, getattr(arg, attribute))
+ else :
+ for attribute in self.attributes :
+ if attribute in args :
+ setattr(self, attribute, args[attribute])
+ else :
+ setattr(self, attribute, self.attributes[attribute])
+
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,6 @@
+
+SVM = __import__('PyML.classifiers.svm', fromlist=['']).SVM
+KNN = __import__('PyML.classifiers.knn', fromlist=['']).KNN
+RidgeRegression = __import__('PyML.classifiers.ridgeRegression', fromlist=['']).RidgeRegression
+import modelSelection
+
@@ -0,0 +1,153 @@
+import numpy
+import time
+import copy
+
+from PyML.evaluators import assess,resultsObjects
+from PyML.utils import misc
+from PyML.base.pymlObject import PyMLobject
+
+"""base class for for PyML classifiers"""
+
+__docformat__ = "restructuredtext en"
+
+containersRequiringProjection = ['VectorDataSet']
+
+class Classifier (PyMLobject) :
+
+ """base class for PyML classifiers, specifying the classifier api"""
+
+ type = 'classifier'
+ deepcopy = False
+
+ # the type of Results object returned by testing a classifier:
+ resultsObject = resultsObjects.ClassificationResults
+
+ test = assess.test
+ cv = assess.cv
+ stratifiedCV = assess.stratifiedCV
+ loo = assess.loo
+ trainTest = assess.trainTest
+ nCV = assess.nCV
+
+ def __init__(self, arg = None, **args) :
+
+ PyMLobject.__init__(self, arg, **args)
+ if type(arg) == type('') :
+ self.load(arg)
+ self.log = misc.Container()
+
+ def logger(self) :
+
+ pass
+
+ def __repr__(self) :
+
+ return '<' + self.__class__.__name__ + ' instance>\n'
+
+ def verifyData(self, data) :
+ """
+ verify that for a VectorDataSet the test examples refer to the same
+ features used in training.
+ """
+
+ if data.__class__.__name__ != 'VectorDataSet' :
+ return
+ if len(misc.intersect(self.featureID, data.featureID)) != len(self.featureID) :
+ raise ValueError, 'missing features in test data'
+
+
+ def save(self, fileHandle) :
+
+ raise NotImplementedError, 'your classifier does not implement this function'
+
+ def train(self, data, **args) :
+
+ # store the current cpu time:
+ self._clock = time.clock()
+
+ if not data.labels.numericLabels :
+ # check if there is a class that is not represented in the training data:
+ if min(data.labels.classSize) == 0 :
+ raise ValueError, 'there is a class with no data'
+
+ # store just as much about the labels as is needed:
+ self.labels = misc.Container()
+ self.labels.addAttributes(data.labels, ['numClasses', 'classLabels'])
+ # if dealing with a VectorDataSet test data needs to have the same features
+ if data.__class__.__name__ == 'VectorDataSet' :
+ self.featureID = data.featureID[:]
+
+ data.train(**args)
+ # if there is some testing done on the data, it requires the training data:
+ if data.testingFunc is not None :
+ self.trainingData = data
+
+ def trainFinalize(self) :
+
+ self.log.trainingTime = self.getTrainingTime()
+
+ def getTrainingTime(self) :
+
+ return time.clock() - self._clock
+
+ def classify(self, data, i) :
+
+ raise NotImplementedError
+
+ def twoClassClassify(self, data, i) :
+
+ val = self.decisionFunc(data, i)
+ if val > 0 :
+ return (1, val)
+ else:
+ return (0, val)
+
+class IteratorClassifier (Classifier) :
+
+ def __iter__(self) :
+
+ self._classifierIdx = -1
+ return self
+
+ def getClassifier(self) :
+
+ if self._classifierIdx < 0 :
+ return None
+ return self.classifiers[self._classifierIdx]
+
+ def next(self) :
+
+ self._classifierIdx += 1
+ if self._classifierIdx == len(self.classifiers) :
+ raise StopIteration
+ func = getattr(self.classifiers[self._classifierIdx], self._method)
+
+ return func(self._data, **self._args)
+
+ def test(self, data, **args) :
+
+ self._method = 'test'
+ self._data = data
+ self._args = args
+ return iter(self)
+
+ def cv(self, data, **args) :
+
+ self._method = 'cv'
+ self._data = data
+ self._args = args
+ return iter(self)
+
+ def stratifiedCV(self, data, **args) :
+
+ self._method = 'stratifiedCV'
+ self._data = data
+ self._args = args
+ return iter(self)
+
+ def loo(self, data, **args) :
+
+ self._method = 'loo'
+ self._data = data
+ self._args = args
+ return iter(self)
Oops, something went wrong.

0 comments on commit d767c9f

Please sign in to comment.