Aug-18-2020, 12:26 AM
Hello am working on a personal project to practice what I ahve learnt. The title of the project is 'Fake news detection using machine learning'. I'm having a problem in deploying to web app using flask.
Please I will be glad to receive help here.
The error am having is that: ImportError: cannot import name 'joblib' from 'sklearn.externals'
Relevant code files are attached.
the flask code
feature.py
Traceback (most recent call last):
File "app.py", line 2, in <module>
from sklearn.externals import joblib
ImportError: cannot import name 'joblib' from 'sklearn.externals'
Please I will be glad to receive help here.
The error am having is that: ImportError: cannot import name 'joblib' from 'sklearn.externals'
Relevant code files are attached.
the flask code
from flask import Flask, abort, jsonify, request, render_template from sklearn.externals import joblib from feature import * import json pipeline = joblib.load('pipeline.sav') app = Flask(__name__) @app.route('/') def home(): return render_template('index.html') @app.route('/api',methods=['POST']) def get_delay(): result=request.form query_title = result['title'] query_author = result['author'] query_text = result['maintext'] print(query_text) query = get_all_query(query_title, query_author, query_text) user_input = {'query':query} pred = pipeline.predict(query) print(pred) dic = {1:'real',0:'fake'} return f'<html><body><h1>{dic[pred[0]]}</h1> <form action="/"> <button type="submit">back </button> </form></body></html>' if __name__ == '__main__': app.run(port=8080, debug=True)..........................
feature.py
import numpy as np # linear algebra import pandas as pd #data processing import os import re import nltk def get_all_query(title, author, text): total= title + author + text total = [total] return total def remove_punctuation_stopwords_lemma(sentence): filter_sentence = '' lemmatizer=WordNetLemmatizer() sentence = re.sub(r'[^\w\s]','',s) words = nltk.word_tokenize(sentence) #tokenization words = [w for w in words if not w in stop_words] for word in words: filter_sentence = filter_sentence + ' ' + str(lemmatizer.lemmatize(word)).lower() return filter_sentenceStackTrace
Traceback (most recent call last):
File "app.py", line 2, in <module>
from sklearn.externals import joblib
ImportError: cannot import name 'joblib' from 'sklearn.externals'