TfidfVectorizer transform not found

Viewed 111

I created a class in python to train a model NLP through TfidfVectorizer for preprocessing, the training goes well and I save on model TFIDF on my google Drive, except that when I retrieve the link of the file in another prediction function, it shows me the error that transform is not found. Here is my code:

def train_model(self,text_,label):
      x_train, x_test, y_train,y_test = train_test_split(text_,label,test_size = 0.25, random_state = 42)

      tfidf_vectorizer=TfidfVectorizer(stop_words='english', max_df=0.7)
    
      tfidf_train=tfidf_vectorizer.fit_transform(x_train.values.astype('U')) 
      tfidf_test=tfidf_vectorizer.transform(x_test.values.astype('U')) 
      dump(tfidf_train,'/content/drive/MyDrive/Fake_news_detector_model/vectorizer_.plk') 

the prediction function

 def prediction(self,text):
    vectorizer_ = load('/content/drive/MyDrive/Fake_news_detector_model/vectorizer_.plk')
    test_ = vectorizer_.transform([text])
    return test_

And I get this error

AttributeError                            Traceback (most recent call last) <ipython-input-24-cfbc0ad58472> in <module>()
      1 pr = "In a bid to end their winless streaks, SC East Bengal and Mumbai City FC clash in the 52nd match of the Indian Super League (ISL) 2021-22 on Friday, January 7. The Kolkata team has had a miserable campaign so far, not winning any of their nine games so far. Head coach Jose Manuel Diaz was given the marching orders before the match against Bengaluru FC, Renedy Singh was appointed as the interim coach. The team put up a spirited performance against the Blues, however, for SCEB, the match ended in a 1-1 draw, making it two in a row for the red and gold brigade. "
----> 2 Re.prediction(pr)

1 frames /usr/local/lib/python3.7/dist-packages/scipy/sparse/base.py in __getattr__(self, attr)
    689             return self.getnnz()
    690         else:
--> 691             raise AttributeError(attr + " not found")
    692 
    693     def transpose(self, axes=None, copy=False):

AttributeError: transform not found

It's for an end of year project, I hope to have your help. Thanks

0 Answers
Related