This file contains hidden or 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
| line-bot-sdk | |
| flask | |
| requests |
This file contains hidden or 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
| from flask import Flask, request, abort | |
| from linebot import ( | |
| LineBotApi, WebhookHandler | |
| ) | |
| from linebot.exceptions import ( | |
| InvalidSignatureError | |
| ) | |
| from linebot.models import * | |
| #tambahkan ini######################### |
This file contains hidden or 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 handle_message(event): | |
| msg_from_user = event.message.text | |
| if msg_from_user == 'Data-covid': | |
| message = TextSendMessage("Data COVID-19 " + negara + "\nPositif: " + positif + "\nSembuh: " + sembuh + "\nMeninggal: " + meninggal) | |
| line_bot_api.reply_message(event.reply_token, message) |
This file contains hidden or 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
| from linebot.models import * | |
| #tambahkan ini######################### | |
| import requests | |
| import json | |
| url = "https://api.kawalcorona.com/indonesia/" | |
| response = requests.get(url) | |
| parsed = response.json()[0] | |
| negara = parsed["name"] | |
| positif = parsed["positif"] | |
| sembuh = parsed["sembuh"] |
This file contains hidden or 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
| # Channel Access Token | |
| line_bot_api = LineBotApi('YOUR_CHANNEL_ACCESS_TOKEN') | |
| # Channel Secret | |
| handler = WebhookHandler('YOUR_CHANNEL_SECRET') |
This file contains hidden or 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
| print("Confusion Matrix Test") | |
| df_cm = pd.DataFrame(cm, index = (0, 1), columns = (0, 1)) | |
| plt.figure(figsize = (10,7)) | |
| sn.set(font_scale=1.4) | |
| sn.heatmap(df_cm, annot=True, fmt='g') | |
| print("Confusion Matrix Train") | |
| df_cm_train = pd.DataFrame(cm_train, index = (0, 1), columns = (0, 1)) | |
| plt.figure(figsize = (10,7)) | |
| sn.set(font_scale=1.4) | |
| sn.heatmap(df_cm_train, annot=True, fmt='g') |
This file contains hidden or 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
| ## EXTRA: Confusion Matrix | |
| cm = confusion_matrix(y_test, y_pred) # rows = truth, cols = prediction | |
| cm_train = confusion_matrix(y_train, y_pred_train) | |
| print("Test Data Accuracy: %0.4f" % accuracy_score(y_test, y_pred)) | |
| print(cm) | |
| print("Train Data Accuracy: %0.4f" % accuracy_score(y_train, y_pred_train)) | |
| print(cm_train) |
This file contains hidden or 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
| #Let's see how our model performed | |
| print("Hasil Test") | |
| print(classification_report(y_test, y_pred)) |
This file contains hidden or 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
| # Predict | |
| y_pred = classifier.predict(X_test) | |
| y_pred = (y_pred > 0.5) | |
| score = classifier.evaluate(X_test, y_test) | |
| print("Score test", score) | |
| y_pred_train = classifier.predict(X_train) | |
| y_pred_train = (y_pred_train > 0.5) | |
| score_pred_train = classifier.evaluate(X_train, y_train) | |
| print("Score train", score_pred_train) |
This file contains hidden or 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
| # list all data in history | |
| print(history.history.keys()) | |
| # summarize history for accuracy | |
| plt.plot(history.history['acc']) | |
| plt.plot(history.history['val_acc']) | |
| plt.title('model accuracy') | |
| plt.ylabel('accuracy') | |
| plt.xlabel('epoch') | |
| plt.legend(['train', 'test'], loc='upper left') | |
| plt.show() |
NewerOlder