Sort by

recency

|

5 Discussions

|

  • + 0 comments
    from sklearn.feature_extraction.text import CountVectorizer
    from sklearn.feature_extraction.text import TfidfTransformer,TfidfVectorizer
    from sklearn.pipeline import Pipeline
    from sklearn.linear_model import SGDClassifier
    from sklearn.svm import LinearSVC
    import re
    import numpy as np
    
    x_train=[]
    y_train=[]
    
    def words(text):
        return re.findall(r'(?:[a-zA-Z]+[a-zA-Z\'\-]?[a-zA-Z]|[a-zA-Z]+)',text)
    
    count=0
    with open('training.txt', 'r') as f:
        for line in f:
            count+=1
            if count==1:
                continue
            x=[a for a in line.rstrip().split("\t")]
            sen=" ".join(word for word in words(x[0]))
            x_train.append(sen)
            y_train.append(x[1])
    
    x=np.array(x_train)
    y=np.array(y_train)
    text_clf=Pipeline([('vect',CountVectorizer()),
                       ('tfidf',TfidfTransformer()),
                       ('clf', LinearSVC())])
    text_clf.fit(x,y)
    
    test=[]
    for i in range(int(input())): 
        x=input()
        sen=" ".join(word for word in words(x))
        test.append(x)
    predicted=text_clf.predict(np.array(test))
    for i in predicted:
        print(i)
    
  • + 0 comments

    I am unable to use Wordnet lemmatize function. It says below error: [nltk_data] Error loading wordnet:

    Any suggestions?

  • + 0 comments

    For help, you can follow up the link:

    https://github.com/nishant-sethi/HackerRank/

  • + 0 comments

    I saw the 30.00 points scorer's solution. I laughed! :-P

  • + 0 comments

    I copied and pasted code from @gshguru and got 25.97 score while he has a score of 26.90. How's that possible?

No more comments