Guest User

Untitled

a guest
May 24th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. import pandas as pd
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. import time
  5. import csv
  6. import string
  7. from sklearn.cross_validation import train_test_split
  8. from sklearn.feature_extraction.text import CountVectorizer
  9. from sklearn.naive_bayes import MultinomialNB
  10.  
  11. # Importing dataset
  12. data = pd.read_csv("test.csv", quotechar='"', delimiter=',',quoting=csv.QUOTE_ALL, skipinitialspace=True,error_bad_lines=False)
  13. df2 = data.set_index("name", drop = False)
  14.  
  15.  
  16.  
  17. df2['sentiment'] = df2['rating'].apply(lambda rating : +1 if rating > 3 else -1)
  18.  
  19.  
  20. train, test = train_test_split(df2, test_size=0.2)
  21.  
  22.  
  23. count_vect = CountVectorizer()
  24. X_train_counts = count_vect.fit_transform(train)
  25. test_matrix = count_vect.transform(test)
  26.  
  27. clf = MultinomialNB().fit(X_train_tfidf, twenty_train.target)
  28.  
  29. clf = MultinomialNB().fit(X_train_tfidf, twenty_train.target)
  30.  
  31. X : {array-like, sparse matrix}, shape = [n_samples, n_features]
  32. Training vectors, where n_samples is the number of samples and n_features is
  33. the number of features.
  34.  
  35. y : array-like, shape = [n_samples]
  36. Target values.
Add Comment
Please, Sign In to add comment