# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

# Input data files are available in the read-only "../input/" directory
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory

import os
for dirname, _, filenames in os.walk('/kaggle/input'):
    for filename in filenames:
        print(os.path.join(dirname, filename))

# You can write up to 5GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All" 
# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session
/kaggle/input/sentiment-labelled-sentences-data-set/sentiment labelled sentences/imdb_labelled.txt
/kaggle/input/sentiment-labelled-sentences-data-set/sentiment labelled sentences/yelp_labelled.csv
/kaggle/input/sentiment-labelled-sentences-data-set/sentiment labelled sentences/imdb_labelled.csv
/kaggle/input/sentiment-labelled-sentences-data-set/sentiment labelled sentences/amazon_cells_labelled.csv
/kaggle/input/sentiment-labelled-sentences-data-set/sentiment labelled sentences/amazon_cells_labelled.txt
/kaggle/input/sentiment-labelled-sentences-data-set/sentiment labelled sentences/yelp_labelled.txt
/kaggle/input/sentiment-labelled-sentences-data-set/sentiment labelled sentences/readme.txt
/kaggle/input/sentiment-labelled-sentences-data-set/sentiment labelled sentences/sentiment labelled sentences/imdb_labelled.txt
/kaggle/input/sentiment-labelled-sentences-data-set/sentiment labelled sentences/sentiment labelled sentences/yelp_labelled.csv
/kaggle/input/sentiment-labelled-sentences-data-set/sentiment labelled sentences/sentiment labelled sentences/imdb_labelled.csv
/kaggle/input/sentiment-labelled-sentences-data-set/sentiment labelled sentences/sentiment labelled sentences/amazon_cells_labelled.csv
/kaggle/input/sentiment-labelled-sentences-data-set/sentiment labelled sentences/sentiment labelled sentences/amazon_cells_labelled.txt
/kaggle/input/sentiment-labelled-sentences-data-set/sentiment labelled sentences/sentiment labelled sentences/yelp_labelled.txt
/kaggle/input/sentiment-labelled-sentences-data-set/sentiment labelled sentences/sentiment labelled sentences/readme.txt
file_path_dict = {'yelp':   '../input/sentiment-labelled-sentences-data-set/sentiment labelled sentences/yelp_labelled.txt',
                 'amazon': '../input/sentiment-labelled-sentences-data-set/sentiment labelled sentences/amazon_cells_labelled.txt',
                 'imdb':   '../input/sentiment-labelled-sentences-data-set/sentiment labelled sentences/imdb_labelled.txt'}

def readAndConcatAllFiles(dict): 
    df_list = []
    for source, filepath in dict.items():
        df = pd.read_csv(filepath, names=['sentence', 'sentiment'], sep='\t')
        df['source'] = source
        df_list.append(df)
    return pd.concat(df_list)

df = readAndConcatAllFiles(file_path_dict)
from sklearn.feature_extraction.text import CountVectorizer
vectorizer = CountVectorizer()
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score


sentences = df['sentence'].values
y = df['sentiment'].values

sentences_train, sentences_test, y_train, y_test = train_test_split(sentences, y, test_size=0.25, random_state=1000)
vectorizer.fit(sentences_train)

X_train = vectorizer.transform(sentences_train)
X_test  = vectorizer.transform(sentences_test)

classifier = LogisticRegression()
classifier.fit(X_train, y_train)

print("accuracy_score : ",accuracy_score(y_test,classifier.predict(X_test)))
accuracy_score :  0.8195050946142649
from sklearn.tree import DecisionTreeClassifier
sentences_model = DecisionTreeClassifier(random_state=1)
sentences_model.fit(X_train,y_train)

print("accuracy_score : ",accuracy_score(y_test,sentences_model.predict(X_test)))
accuracy_score :  0.7540029112081513
from sklearn.ensemble import RandomForestClassifier
sentences_model = RandomForestClassifier(random_state=1)
sentences_model.fit(X_train,y_train)

print("accuracy_score : ",accuracy_score(y_test,sentences_model.predict(X_test)))
accuracy_score :  0.8122270742358079