This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# transform the train and test data | |
train_idf = tfidf_vectorizer.transform(train.tweet) | |
test_idf = tfidf_vectorizer.transform(test.tweet) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create a TF-IDF vectorizer object | |
tfidf_vectorizer = TfidfVectorizer(lowercase= True, max_features=1000, stop_words=ENGLISH_STOP_WORDS) | |
# fit the object with the training data tweets | |
tfidf_vectorizer.fit(train.tweet) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# train test split | |
train, test = train_test_split(data, test_size = 0.2, stratify = data['label'], random_state=21) | |
# get the shape of train and test split. | |
train.shape, test.shape | |
## >> ((25569, 3), (6393, 3)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# read the dataset | |
data = pd.read_csv('dataset/twitter_sentiments.csv') | |
# view the top rows | |
data.head() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# importing required libraries | |
import pandas as pd | |
from sklearn.feature_extraction.text import ENGLISH_STOP_WORDS, TfidfVectorizer | |
from sklearn.linear_model import LogisticRegression | |
from sklearn.pipeline import Pipeline | |
from sklearn.metrics import f1_score | |
from sklearn.model_selection import train_test_split |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# define a function to divide two numbers | |
def division(a, b): | |
# use the try statement where error may occur | |
try: | |
print(a/b) | |
# if the error occurs, handle it !! | |
except ZeroDivisionError: | |
print("Cannot divide by Zero!!") | |
else: | |
print("No Error occured!!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# define a function to divide two numbers | |
def division(a, b): | |
# use the try statement where error may occur | |
try: | |
print(a/b) | |
# if the error occurs, handle it !! | |
except ZeroDivisionError: | |
print("Cannot divide by Zero!!") | |
# if no error occurs | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# define a function to divide two numbers | |
def division(a, b): | |
# use the try statement where error may occur | |
try: | |
return a/b | |
# if the error occurs, handle it !! | |
except ZeroDivisionError: | |
print("Cannot divide by Zero!!") | |
division(10,5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# function to divide two numbers | |
def division(a, b): | |
return a/b | |
# function works fine when you try to divide the number by a non-zero number | |
division(10, 2) | |
# >> 5.0 | |
division(10,-3) | |
# >> -3.333333334 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pandas.io.parsers import ParserError | |
# create a list to store the dataframes | |
dataframe_list = [] | |
file = open('log_file.txt', 'a+') | |
# iterate through the folders 1 to 34 | |
for folder in range(1, 35): |