#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

#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()
  • $\begingroup$ Hi @Manan Nawal, thank you for the post. However, we are struggling to understand what it is you are exactly asking and the context behind the issue you are experiencing. Could you edit your post accordingly so then we can help you? $\endgroup$ – shepan6 Jul 7 '20 at 9:11
  • $\begingroup$ Hi, and welcome to the stackexchange network. To learn more on how to ask a good question, which is likely to be answered, please visit the site tour (datascience.stackexchange.com/tour), especially the "how to ask" part (datascience.stackexchange.com/help/how-to-ask). $\endgroup$ – Itamar Mushkin Jul 7 '20 at 10:34

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().
The variable 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()?


Not the answer you're looking for? Browse other questions tagged or ask your own question.