Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am implementing a sentiment analysis project and I now need to implement the last stage (SVM) the classifier.

What I have tried:

I understand SVM in theoretical part but now I want to start implementing it and I don't know how I can go about that
Posted
Updated 3-Oct-20 22:19pm
Comments
Richard MacCutchan 4-Oct-20 3:38am    
You will need to provide far more detail about your problem if you want a sensible response.
ShaggyPo 4-Oct-20 3:42am    
I am doing sentiment analysis and I have done it to feature extraction where I used TF-IDF to obtain weights and now I need to implement SVM classifier
Richard MacCutchan 4-Oct-20 3:57am    
Sorry but that does not explain anything. If you have a problem in your code then please provide the details.
ShaggyPo 4-Oct-20 4:04am    
Thank you Richard for showing support. I don't mind showing you and explaining what I have done. To explain it more in details I think it is better we call on google meet up or hangout here (shaggyzee@gmail.com) because putting my code here and explaining is a lot

1 solution

Look at the section 'Evaluation of the performance on the test set' at the following url: Working With Text Data — scikit-learn 0.23.2 documentation[^]

High level, example code would look like:
Python
feature_extraction = TfidfVectorizer()
X = feature_extraction.fit_transform(data["sentiments"].values)

X_train = X[:num_training]
X_test = X[num_training:]
y_train = data["Label"].values[:num_training]
y_test = data["Label"].values[num_training:]

# train classifier
clf = SVC(probability=True, kernel='rbf')
clf.fit(X_train, y_train)

# predict and evaluate predictions
predictions = clf.predict_proba(X_test)


Now, in case you want to re-invent wheel and have your own implementation of SVM, would suggest you star from here: scikit-learn/_classes.py at master · scikit-learn/scikit-learn · GitHub[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900