-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
454ff9e
commit 58c8e53
Showing
9 changed files
with
22,759 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from flask import Flask,render_template,url_for,request | ||
import pandas as pd | ||
import pickle | ||
from sklearn.feature_extraction.text import CountVectorizer | ||
from sklearn.naive_bayes import MultinomialNB | ||
from sklearn.externals import joblib | ||
|
||
|
||
app = Flask(__name__) | ||
|
||
@app.route('/') | ||
def home(): | ||
return render_template('home.html') | ||
|
||
@app.route('/predict',methods=['POST']) | ||
def predict(): | ||
df= pd.read_csv("twitterdataset.csv", encoding="latin-1") | ||
|
||
# Features and Labels | ||
df['label'] = df['class'].map({'Non-Bullying': 0, 'Bullying': 1}) | ||
X = df['message'] | ||
y = df['label'] | ||
|
||
# Extract Feature With CountVectorizer | ||
cv = CountVectorizer() | ||
X = cv.fit_transform(X) # Fit the Data | ||
from sklearn.model_selection import train_test_split | ||
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42) | ||
#Naive Bayes Classifier | ||
from sklearn.naive_bayes import MultinomialNB | ||
|
||
clf = MultinomialNB() | ||
clf.fit(X_train,y_train) | ||
clf.score(X_test,y_test) | ||
#Alternative Usage of Saved Model | ||
# joblib.dump(clf, 'NB_spam_model.pkl') | ||
# NB_spam_model = open('NB_spam_model.pkl','rb') | ||
# clf = joblib.load(NB_spam_model) | ||
|
||
if request.method == 'POST': | ||
message = request.form['message'] | ||
data = [message] | ||
vect = cv.transform(data).toarray() | ||
my_prediction = clf.predict(vect) | ||
return render_template('result.html',prediction = my_prediction) | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
app.run(debug=True) |
Oops, something went wrong.