Skip to main content


Project description


Sample Usage

>>> import KNN_TextClassifier
        #load random Data,Labels
>>> dataMatrix,labels = KNN_TextClassifier.loadData(feature_num = 4,rows = 10)
        #norm Data reduce influence of high ranges
>>> normDataSet = KNN_TextClassifier.norm(dataMatrix)

        #predict K should be odd to avoid voting result like {('A',2),('B',2)} difficult choice.
        #Parameter format classify(testData,TrainData,TrainData_Labels,K)
                testData and TrainData should be 2-D list. row represents a text data. Columns represent feature values.
                TrainData_Labels should be a list like ['A','B','C'] an element represents a row of TrainData's class.
                K should be odd as I said before.
>>> print KNN_TextClassifier.classify([[1,2,3,4],[2],[3]], dataMatrix, labels, K=3)
        ['C', 'C', 'C']

>>> print KNN_TextClassifier.classify([['天气好','2','3','4'],['2'],['3']], dataMatrix, labels, K=3)
        ['C', 'A', 'C']

        #get transformed vector
>>> vector,vocabList = KNN_TextClassifier.word2VectorMatrix([['1','2','3','4'],['2'],['3']])
>>> print vector
        [[ 1.  1.  1.  1.]
        [ 0.  0.  1.  0.]
        [ 0.  1.  0.  0.]]

        #get transformed vocabList
>>> print vocabList
        ['1', '3', '2', '4']


$ pip install KNN_TextClassifier

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for KNN_TextClassifier, version 0.0.0
Filename, size File type Python version Upload date Hashes
Filename, size KNN_TextClassifier-0.0.0.tar.gz (2.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page