#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jan  7 01:05:43 2019

@author: subham
"""

# Natural Language Processing

# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# Importing the dataset
dataset1 = pd.read_csv('training_queries.csv')
dataset2 = pd.read_csv('training_queries_labels.csv')

# 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, 1808):
    review = re.sub('[^a-zA-Z]', ' ', dataset1['query'][i])
    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 = ' '.join(review)
    corpus.append(review)

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

# Decision Tree Classification


# 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 = 500/1808)


# Fitting Decision Tree Classification to the Training set
from sklearn.tree import DecisionTreeClassifier
classifier = DecisionTreeClassifier(criterion = 'entropy')
classifier.fit(X_train, y_train)

# Predicting the Test set results
y_pred = classifier.predict(X_test)

# Making the Confusion Matrix
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)

#this model have approximately 75-80% of accuracy which might be according to me is also the value of precision recall and hence F1 score
e1efe327dcabdd5eb7283410139387bfc9439263
<mask token>

<mask token>
nltk.download('stopwords')
<mask token>
for i in range(0, 1808):
    review = re.sub('[^a-zA-Z]', ' ', dataset1['query'][i])
    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 = ' '.join(review)
    corpus.append(review)
<mask token>
classifier.fit(X_train, y_train)
<mask token>

<mask token>
dataset1 = pd.read_csv('training_queries.csv')
dataset2 = pd.read_csv('training_queries_labels.csv')
<mask token>
nltk.download('stopwords')
<mask token>
corpus = []
for i in range(0, 1808):
    review = re.sub('[^a-zA-Z]', ' ', dataset1['query'][i])
    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 = ' '.join(review)
    corpus.append(review)
<mask token>
cv = CountVectorizer()
X = cv.fit_transform(corpus).toarray()
y = dataset2.iloc[:, 1].values
<mask token>
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=500 / 1808)
<mask token>
classifier = DecisionTreeClassifier(criterion='entropy')
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)
<mask token>
cm = confusion_matrix(y_test, y_pred)

<mask token>
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
dataset1 = pd.read_csv('training_queries.csv')
dataset2 = pd.read_csv('training_queries_labels.csv')
import re
import nltk
nltk.download('stopwords')
from nltk.corpus import stopwords
from nltk.stem.porter import PorterStemmer
corpus = []
for i in range(0, 1808):
    review = re.sub('[^a-zA-Z]', ' ', dataset1['query'][i])
    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 = ' '.join(review)
    corpus.append(review)
from sklearn.feature_extraction.text import CountVectorizer
cv = CountVectorizer()
X = cv.fit_transform(corpus).toarray()
y = dataset2.iloc[:, 1].values
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=500 / 1808)
from sklearn.tree import DecisionTreeClassifier
classifier = DecisionTreeClassifier(criterion='entropy')
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jan  7 01:05:43 2019

@author: subham
"""

# Natural Language Processing

# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# Importing the dataset
dataset1 = pd.read_csv('training_queries.csv')
dataset2 = pd.read_csv('training_queries_labels.csv')

# 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, 1808):
    review = re.sub('[^a-zA-Z]', ' ', dataset1['query'][i])
    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 = ' '.join(review)
    corpus.append(review)

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

# Decision Tree Classification


# 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 = 500/1808)


# Fitting Decision Tree Classification to the Training set
from sklearn.tree import DecisionTreeClassifier
classifier = DecisionTreeClassifier(criterion = 'entropy')
classifier.fit(X_train, y_train)

# Predicting the Test set results
y_pred = classifier.predict(X_test)

# Making the Confusion Matrix
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)

#this model have approximately 75-80% of accuracy which might be according to me is also the value of precision recall and hence F1 score