IUM_06
This commit is contained in:
parent
f5f69a488b
commit
4e825aa649
@ -4,15 +4,16 @@ import tensorflow as tf
|
|||||||
|
|
||||||
test_data = pd.read_csv('./beer_reviews_test.csv')
|
test_data = pd.read_csv('./beer_reviews_test.csv')
|
||||||
X_test = test_data[['review_aroma', 'review_appearance', 'review_palate', 'review_taste']]
|
X_test = test_data[['review_aroma', 'review_appearance', 'review_palate', 'review_taste']]
|
||||||
|
y_test = test_data['review_overall']
|
||||||
|
|
||||||
model = tf.keras.models.load_model('beer_review_sentiment_model.h5')
|
model = tf.keras.models.load_model('beer_review_sentiment_model.h5')
|
||||||
|
|
||||||
tokenizer = tf.keras.preprocessing.text.Tokenizer(num_words=10000)
|
tokenizer = tf.keras.preprocessing.text.Tokenizer(num_words=10000)
|
||||||
|
tokenizer.fit_on_texts(X_test)
|
||||||
|
|
||||||
X_test_seq = tokenizer.texts_to_sequences(X_test)
|
X_test_seq = tokenizer.texts_to_sequences(X_test)
|
||||||
X_test_pad = tf.keras.preprocessing.sequence.pad_sequences(X_test_seq, maxlen=100)
|
X_test_pad = tf.keras.preprocessing.sequence.pad_sequences(X_test_seq, maxlen=100)
|
||||||
|
|
||||||
predictions = model.predict(X_test_pad)
|
predictions = model.predict(X_test_pad)
|
||||||
|
|
||||||
np.savetxt('beer_review_sentiment_predictions.csv', predictions, delimiter=',', fmt='%.10f')
|
results = pd.DataFrame({'Predictions': predictions.flatten(), 'Actual': y_test})
|
||||||
|
results.to_csv('beer_review_sentiment_predictions.csv', index=False)
|
@ -1,19 +1,19 @@
|
|||||||
from sklearn.metrics import confusion_matrix
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import sys
|
from sklearn.metrics import accuracy_score, precision_recall_fscore_support, mean_squared_error
|
||||||
|
from math import sqrt
|
||||||
|
|
||||||
|
# Load the predictions data
|
||||||
|
data = pd.read_csv('beer_review_sentiment_predictions.csv')
|
||||||
|
y_pred = data['Predictions']
|
||||||
|
y_test = data['Actual']
|
||||||
|
|
||||||
def main():
|
# Calculate metrics
|
||||||
y_test = pd.read_csv("beer_reviews_test.csv")
|
accuracy = accuracy_score(y_test, y_pred.round())
|
||||||
y_pred = pd.read_csv("beer_review_sentiment_predictions.csv", header=None)
|
precision, recall, f1, _ = precision_recall_fscore_support(y_test, y_pred.round(), average='micro')
|
||||||
build_number = sys.argv[1]
|
rmse = sqrt(mean_squared_error(y_test, y_pred))
|
||||||
|
|
||||||
cm = confusion_matrix(y_test, y_pred)
|
print(f'Accuracy: {accuracy}')
|
||||||
accuracy = cm[1, 1] / (cm[1, 0] + cm[1, 1])
|
print(f'Micro-avg Precision: {precision}')
|
||||||
|
print(f'Micro-avg Recall: {recall}')
|
||||||
with open(r"beer_metrics.txt", "a") as f:
|
print(f'F1 Score: {f1}')
|
||||||
f.write(f"{accuracy},{build_number}\n")
|
print(f'RMSE: {rmse}')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
Loading…
Reference in New Issue
Block a user