#Text Representation from sklearn.feature_extraction.text import TfidfVectorizer tfidf = TfidfVectorizer(sublinear_tf=True, min_df=2,max_df= 0.3, norm='l2', encoding='latin-1', ngram_range=(1, 2), stop_words='english') features = tfidf.fit_transform(df.ContextualText).toarray() labels = df.category_id features.shape #Running Linear SVC from sklearn.model_selection import train_test_split model = LinearSVC() X_train, X_test, y_train, y_test, indices_train, indices_test = train_test_split(features, labels, df.index, test_size=0.2, random_state=0) model.fit(X_train, y_train) y_pred = model.predict(X_test) #Predictions based on model vectorized_text = features.transform("Heathcare is good").toarray()
Your question leaves a lot unexplained, but the error you're receiving probably came from the last line
vectorized_text = features.transform("Heathcare is good").toarray().
features is itself an array (it came from
features = ... .toarray()).
I'm assuming you meant to replace it with
vectorized_text = tfidf.transform("Heathcare is good").toarray()?