Skip to content

Instantly share code, notes, and snippets.

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

Lakshay lakshay-arora

🇮🇳
  • Walmart
  • Bengaluru
View GitHub Profile
# importing pandas to read the CSV file
import pandas as pd
# read the data
data_classification = pd.read_csv('datasets/loan_train_data.csv')
# view the top rows of the data
data_classification.head()
# start flask
app = Flask(__name__)
# render default webpage
@app.route('/')
def home():
return render_template('home.html')
# when the post method detect, then redirect to success function
@app.route('/', methods=['POST', 'GET'])
# importing the required libraries
from flask import Flask, render_template, request, redirect, url_for
from joblib import load
from get_tweets import get_related_tweets
# load the pipeline object
pipeline = load("text_classification.joblib")
# function to get results for a particular text query
def requestResults(name):
def get_related_tweets(text_query):
# list to store tweets
tweets_list = []
# no of tweets
count = 50
try:
# Pulling individual tweets from query
for tweet in api.search(q=text_query, count=count):
print(tweet.text)
# Adding to list that contains all tweets
# import required libraries
import tweepy
import time
import pandas as pd
pd.set_option('display.max_colwidth', 1000)
# api key
api_key = "Enter API Key Here"
# api secret key
api_secret_key = "Enter API Secret Key Here."
# import joblib
from joblib import load
# sample tweet text
text = ["Virat Kohli, AB de Villiers set to auction their 'Green Day' kits from 2016 IPL match to raise funds"]
# load the saved pipleine model
pipeline = load("text_classification.joblib")
# predict on the sample tweet text
# import joblib
from joblib import dump
# dump the pipeline model
dump(pipeline, filename="text_classification.joblib")
# sample tweet
text = ["Virat Kohli, AB de Villiers set to auction their 'Green Day' kits from 2016 IPL match to raise funds"]
# predict the label using the pipeline
pipeline.predict(text)
## >> array([0])
# define the stages of the pipeline
pipeline = Pipeline(steps= [('tfidf', TfidfVectorizer(lowercase=True,
max_features=1000,
stop_words= ENGLISH_STOP_WORDS)),
('model', LogisticRegression())])
# fit the pipeline model with the training data
pipeline.fit(train.tweet, train.label)
# create the object of LinearRegression Model
model_LR = LogisticRegression()
# fit the model with the training data
model_LR.fit(train_idf, train.label)
# predict the label on the traning data
predict_train = model_LR.predict(train_idf)
# predict the model on the test data