Skip to content
Permalink
Browse files

Model training added

  • Loading branch information
ratan
ratan committed Oct 1, 2018
1 parent a01942a commit 22c14b373d5be71bdcd0577a77f79746e7e5508e
@@ -1,4 +1,12 @@
Tweets
Testing tweet for research
"Let me go, go away"
I am so awesome
"I have a time management video that reveals my secrets on how i'm so productive dropping in 12 hours! For context,… https://t.co/Sp1wUzrBS9"
@dsampaolo @laurentbourelly @PatrickChareyre oui je suis d'accord
"Years ago, I was in a taxi in SE Asia. Outside, a man beat a woman on the street & a crowd watched. 2 children trie… https://t.co/Xp486JhItY"
"RT @iamtrask: Optimizers like SGD, Adam, and Adagrad are very mysterious things. @distillpub has created #interactive #visualizations which…"
"RT @iamtrask: If you are interested in cutting edge #AI #Safety research updates from @DeepMindAI, we just launched an awesome new blog!!…"
@laurentbourelly @PatrickChareyre ça va
@1stSumanDas someday i'd like my own show like that lol yes
@naveen9697navee great suggestion thanks
@MohitWildBeast @AndrewYNg watch my deep learning playlist
Math gives us a glimpse into the vast expanse of possibility that lives inside our own head. This is the human brai… https://t.co/Iey8G0kcs4
Mathematics of Dopamine: https://t.co/eEiW72ouwt via @YouTube
Binary file not shown.
Binary file not shown.
@@ -67,10 +67,11 @@ def fetch_tweets(auth_api, username):
print("List is empty")
sys.exit()

print("Fetched Successfully")
print("Tweets Fetched Successfully")
data = pd.DataFrame({'Tweets': s})
data.to_csv("Recent Tweets.csv", index=False)


except:
print("\nInvalid uesrname or No recent tweet")
sys.exit()
@@ -5,6 +5,13 @@
# Load tweets
tweets = pd.read_csv("Recent Tweets.csv").iloc[:, 0]

# Obtain a model if doesn't exists
import os
if not os.path.exists("model.sav"):
print("\nWait for model training")
import train_model


# Predict tweet
import predict
from predict import predict_tweet
@@ -17,6 +24,6 @@
print("\nYour today emotion is", today_mood)

# Recommend a song
print("Choosing a song for you")
print("\nChoosing a song for you")
from play_song import playSong
playSong(today_mood)
@@ -0,0 +1,61 @@
# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import warnings

warnings.filterwarnings("ignore")
# Importing the dataset
dataset = pd.read_csv('ISEAR.csv', header=None).iloc[:, :2]

# Cleaning the texts
import re
import nltk
# nltk.download('stopwords')
#from nltk.corpus import stopwords
from nltk.stem.porter import PorterStemmer
corpus = []
for i in range(0, 7517):
review = re.sub('[^a-zA-Z]', ' ', dataset.iloc[i, 1])
review = review.lower()
review = review.split()
ps = PorterStemmer()
#review = [ps.stem(word) for word in review if not word in set(stopwords.words('english'))]
review = [ps.stem(word) for word in review]
review = ' '.join(review)
corpus.append(review)

import warnings
warnings.filterwarnings("ignore")

# Creating the Bag of Words model
from sklearn.feature_extraction.text import CountVectorizer
cv = CountVectorizer(max_features=15000)
X = cv.fit_transform(corpus).toarray()
y = dataset.iloc[:, 0].values

# Encoding categorical data
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
labelencoder_y = LabelEncoder()
y = labelencoder_y.fit_transform(y)

# Splitting the dataset into the Training set and Test set
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.20, random_state=0)

# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)

from sklearn.ensemble import RandomForestClassifier
classifier = RandomForestClassifier(
n_estimators=1500, n_jobs=-1, random_state=0)
classifier.fit(X_train, y_train)

# Dump model
import pickle
filename = 'model.sav'
pickle.dump(classifier, open(filename, 'wb'))

0 comments on commit 22c14b3

Please sign in to comment.
You can’t perform that action at this time.