Skip to content

Instantly share code, notes, and snippets.

View lakshay-arora's full-sized avatar
🇮🇳

Lakshay lakshay-arora

🇮🇳
  • Walmart
  • Bengaluru
View GitHub Profile
# transform the train and test data
train_idf = tfidf_vectorizer.transform(train.tweet)
test_idf = tfidf_vectorizer.transform(test.tweet)
# 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)
# 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))
# read the dataset
data = pd.read_csv('dataset/twitter_sentiments.csv')
# view the top rows
data.head()
# 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
# 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!!")
# 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:
# 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)
# 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
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):