Skip to content

Instantly share code, notes, and snippets.

Avatar

Lakshay lakshay-arora

View GitHub Profile
View pycaret_1.py
# 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()
View flask_14.py
# 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'])
View flask_13.py
# 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):
View flask_12.py
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
View flask_11.py
# 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."
View flask_10.py
# 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
View flask_9.py
# import joblib
from joblib import dump
# dump the pipeline model
dump(pipeline, filename="text_classification.joblib")
View flask_8.py
# 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])
View flask_7.py
# 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)
View flask_6.py
# 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
You can’t perform that action at this time.