TutorMe homepage
Subjects
PRICING
COURSES
SIGN IN
Start Free Trial
Vinay S.
Research student at IIIT-Hyderabad, India
Tutor Satisfaction Guarantee
Python Programming
TutorMe
Question:

Create a model to do sentiment analysis of the text sentences given. Use SVM, Decision tree and Naive Bayes models. Program this solution in Python.

Vinay S.
Answer:

# Baseline code without using any special features. from sklearn.feature_extraction.text import CountVectorizer from sklearn.naive_bayes import MultinomialNB from sklearn.feature_extraction.text import TfidfTransformer from sklearn.tree import DecisionTreeClassifier from sklearn.metrics import classification_report import numpy as np from sklearn.pipeline import Pipeline from sklearn.linear_model import SGDClassifier data_X = [] data_Y = [] with open('data_file_name') as f: for line in f: line = line.strip('\n').split('\t') data_Y.append(line[1]) data_X.append(line[0]) train = int(len(data_X)*0.8) train_X = data_X[:train] train_Y = data_Y[:train] test_X = data_X[train:] test_Y = data_Y[train:] test = len(data_X)-train print train, test print len(data_X), len(data_Y) print len(train_X), len(train_Y) print len(test_X), len(test_Y) target_names = ['NAME_OF_TAGS'] # NB text_clf = Pipeline([('vect', CountVectorizer()), ('tfidf', TfidfTransformer()),('clf', MultinomialNB()),]) text_clf = text_clf.fit(train_X, train_Y) predicted = text_clf.predict(test_X) print np.mean(predicted == test_Y) print(classification_report(test_Y, predicted, target_names=target_names)) # SVM text_clf_svm = Pipeline([('vect', CountVectorizer()), ('tfidf', TfidfTransformer()), ('clf-svm', SGDClassifier(loss='hinge', penalty='l2', alpha=1e-3, n_iter=5, random_state=42)), ]) text_clf_svm = text_clf_svm.fit(train_X, train_Y) predicted_svm = text_clf_svm.predict(test_X) print np.mean(predicted_svm == test_Y) print(classification_report(test_Y, predicted_svm, target_names=target_names)) # Decision Tree text_clf_dt = Pipeline([('vect', CountVectorizer()), ('tfidf', TfidfTransformer()),('clf-dt', DecisionTreeClassifier()), ]) text_clf_dt = text_clf_dt.fit(train_X, train_Y) predict_dt = text_clf_dt.predict(test_X) print np.mean(predict_dt==test_Y) print(classification_report(test_Y, predict_dt, target_names=target_names)) ------------------------------------------------------------------------------------------------------------------------------ The above code gives the accuracies of the three models as well as the report i.r recall, precision and f-score for all the label in the training and testing data-set. This will help us to compare between the three models and see which one will be more suitable for our use.

C++ Programming
TutorMe
Question:

Finding if a given array contains a number 'P' such that there are exactly "P" numbers in the array 'greater' than 'P'. If Yes: return 1 else : -1 eg: Array = [1 2 3 3 5 6 7] this will return "1" as we have 3 elements greater that "3". (5, 6, 7)

Vinay S.
Answer:

So the approach to solve the above problem is: 1. Sort the given array 2. Iterate on each element: if A[i] < A[i-1] && A[i] == size_of_array - i - 1: return 1; 3. return -1; we have to take care of cases of array with all negative numbers and 0 in the array if that is the case just check: if A[size_of_array-1]==0: return 1; This solves our problem.

Artificial Intelligence
TutorMe
Question:

What is the best use of Artificial Intelligence that we all are one way or the other waiting to be true?

Vinay S.
Answer:

Well In my perspective the one basic thing that each and every person wants from Artificial Intelligence is that to make the life of a human better in respect of health and life span, and I guess with the help of AI we are moving towards era of medicine and research in the medical fields that are finding cures and vaccines of some problems/diseases which were thought unsolvable. Apart from this AI will make many more impacts in human life like lower their load of work but this basic feature of AI will be for each and every human on planet.

Send a message explaining your
needs and Vinay will reply soon.
Contact Vinay
Ready now? Request a lesson.
Start Session
FAQs
What is a lesson?
A lesson is virtual lesson space on our platform where you and a tutor can communicate. You'll have the option to communicate using video/audio as well as text chat. You can also upload documents, edit papers in real time and use our cutting-edge virtual whiteboard.
How do I begin a lesson?
If the tutor is currently online, you can click the "Start Session" button above. If they are offline, you can always send them a message to schedule a lesson.
Who are TutorMe tutors?
Many of our tutors are current college students or recent graduates of top-tier universities like MIT, Harvard and USC. TutorMe has thousands of top-quality tutors available to work with you.