prrao87 / fine-grained-sentiment-app Goto Github PK
View Code? Open in Web Editor NEWA Flask LIME explainer app for fine-grained sentiment classification.
License: MIT License
A Flask LIME explainer app for fine-grained sentiment classification.
License: MIT License
is it possible to convert the lime explainer output to json? or suggest any method to predict the final output without using lime framework
Hi I have create ML web app for taking input from user and show result to web app.User will fill my form on web app page and then flask will use model to predicted and then model will send result to web app page.Text result working but graph doesn't. Now i want to show explainer using LIME but when i save LIME graph it return empty graph,I already checked my error log.There are no error details
`model = pickle.load(open("./model/hr.pkl", "rb"))
app = flask.Flask(__name__, template_folder='templates')
@app.route('/', methods=['GET', 'POST'])
def main():
if flask.request.method == 'GET':
# Just render the initial form, to get input
return (flask.render_template('main.html'))
if flask.request.method == 'POST':
# Extract the input
TotalWorkingYears = flask.request.form['TotalWorkingYears']
OverTime_code = flask.request.form['OverTime_code']
JobInvolvement = flask.request.form['JobInvolvement']
JobRole_code = flask.request.form['JobRole_code']
Age = flask.request.form['Age']
WorkLifeBalance = flask.request.form['WorkLifeBalance']
Gender_code = flask.request.form['Gender_code']
DistanceFromHome = flask.request.form['DistanceFromHome']
MaritalStatus_code = flask.request.form['MaritalStatus_code']
YearsSinceLastPromotion = flask.request.form['YearsSinceLastPromotion']
Education = flask.request.form['Education']
PercentSalaryHike = flask.request.form['PercentSalaryHike']
TrainingTimesLastYear = flask.request.form['TrainingTimesLastYear']
JobLevel = flask.request.form['JobLevel']
YearsAtCompany = flask.request.form['YearsAtCompany']
DailyRate = flask.request.form['DailyRate']
YearsWithCurrManager = flask.request.form['YearsWithCurrManager']
MonthlyIncome = flask.request.form['MonthlyIncome']
JobSatisfaction = flask.request.form['JobSatisfaction']
EducationField_code = flask.request.form['EducationField_code']
RelationshipSatisfaction = flask.request.form['RelationshipSatisfaction']
MonthlyRate = flask.request.form['MonthlyRate']
BusinessTravel_code = flask.request.form['BusinessTravel_code']
# Make DataFrame for model
input_variables = pd.DataFrame([[TotalWorkingYears, OverTime_code, JobInvolvement,JobRole_code, Age, WorkLifeBalance,
Gender_code, DistanceFromHome, MaritalStatus_code, YearsSinceLastPromotion,
Education,PercentSalaryHike, TrainingTimesLastYear, JobLevel, YearsAtCompany, DailyRate,
YearsWithCurrManager, MonthlyIncome, JobSatisfaction, EducationField_code,
RelationshipSatisfaction, MonthlyRate, BusinessTravel_code]],
columns=['TotalWorkingYears', 'OverTime_code', 'JobInvolvement', 'JobRole_code',
'Age','WorkLifeBalance', 'Gender_code', 'DistanceFromHome','MaritalStatus_code',
'YearsSinceLastPromotion','Education','PercentSalaryHike','TrainingTimesLastYear','JobLevel',
'YearsAtCompany','DailyRate','YearsWithCurrManager','MonthlyIncome','JobSatisfaction',
'EducationField_code','RelationshipSatisfaction','MonthlyRate','BusinessTravel_code'],
dtype=float,
index=['input'])
# Get the model's prediction
prediction = model.predict(input_variables)[0]
prediction_percentage = model.predict_proba(input_variables)[:,1]
row_to_show = 1
data_for_prediction = input_variables.iloc[1] # use 1 row of data here. Could use multiple rows if desired
data_for_prediction_array = data_for_prediction.values.reshape(1, -1)
model.predict_proba(data_for_prediction_array)
X_featurenames = input_variables.columns
categorical_features = np.argwhere(np.array([len(set(input_variables.values[0]))]))
predict_fn = lambda x: model.predict_proba(x).astype(float)
explainer = lime.lime_tabular.LimeTabularExplainer(input_variables.values,
feature_names=X_featurenames,
class_names=['Yes','No'],
categorical_features=categorical_features,
verbose=True, mode='classification')
exp = explainer.explain_instance(input_variables.values[0], predict_fn, num_features=5)
fig = exp.as_pyplot_figure()
if os.path.isfile("/home/Domemakarov2013/smart_hr/static/images/shap_graph/graph.svg"):
os.remove("/home/Domemakarov2013/smart_hr/static/images/shap_graph/graph.svg")
plt.savefig("/home/Domemakarov2013/smart_hr/static/images/shap_graph/graph.svg",
dpi = 150,
bbox_inches = 'tight')
# plt.savefig('/home/Domemakarov2013/smart_hr/static/images/shap_graph/graph.svg')
else:
# plt.savefig('/home/Domemakarov2013/smart_hr/static/images/shap_graph/graph.svg')
plt.savefig("/home/Domemakarov2013/smart_hr/static/images/shap_graph/graph.svg",
dpi = 150,
bbox_inches = 'tight')`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.