Skip to main content

KNN_TextClassifier

KNN_TextClassifier

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']

        #predict
>>> 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']

Installation

$ pip install KNN_TextClassifier

Metadata

Release files for KNN_TextClassifier 0.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for KNN_TextClassifier 0.0.0
File Size Uploaded
KNN_TextClassifier-0.0.0.tar.gz 2.6 kB Details

Release files / KNN_TextClassifier-0.0.0.tar.gz

Download URL KNN_TextClassifier-0.0.0.tar.gz
Size 2.6 kB
Tags Source
SHA-256 checksum
How to use checksums
963f04c49f7e5f560a6225ef524d295cba2829922d0f713abef3c30447307930
BLAKE2b-256 checksum
How to use checksums
1347c3b59f905f265d7f8b6c59888446a4095ab88fb27b1cb1a87904c6a02e2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.0.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page