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 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() |
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
# 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']) |
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 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): |
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
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 |
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
# 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." |
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
# 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 |
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
# import joblib | |
from joblib import dump | |
# dump the pipeline model | |
dump(pipeline, filename="text_classification.joblib") |
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
# 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]) |
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 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) |
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 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 |