39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
import pandas as pd
|
|
import tensorflow as tf
|
|
from sklearn.preprocessing import StandardScaler, OneHotEncoder
|
|
import numpy as np
|
|
|
|
categorical_cols = ['bacteria', 'viruses']
|
|
encoder = OneHotEncoder(sparse=False, handle_unknown='ignore')
|
|
|
|
data_test = pd.read_csv('dane/water_test.csv')
|
|
|
|
X_test = data_test.drop('is_safe', axis=1)
|
|
y_test = data_test['is_safe']
|
|
X_test_encoded = pd.DataFrame(encoder.fit_transform(X_test[categorical_cols]))
|
|
X_test_processed = pd.concat([X_test.drop(categorical_cols, axis=1), X_test_encoded], axis=1)
|
|
X_test_processed.columns = X_test_processed.columns.astype(str)
|
|
|
|
scaler = StandardScaler()
|
|
X_test_scaled = scaler.fit_transform(X_test_processed)
|
|
|
|
model = tf.keras.models.load_model('savedmodel')
|
|
|
|
predictions = model.predict(X_test_scaled)
|
|
print(predictions)
|
|
prediction_classes = [1 if prob > 0.5 else 0 for prob in np.ravel(predictions)]
|
|
print(prediction_classes[:30])
|
|
|
|
with open("predictionsResults.txt", mode='w', newline='') as f:
|
|
f.write(str(f'Results:))
|
|
for pred in predictions:
|
|
f.write(str(f'{pred[0]}'))
|
|
f.write("\n")
|
|
|
|
loss, accuracy, precision, recall = model.evaluate(X_test_scaled, y_test)
|
|
|
|
from sklearn.metrics import accuracy_score, precision_score, recall_score
|
|
|
|
print(f'Accuracy: {accuracy_score(y_test, prediction_classes):.2f}')
|
|
print(f'Precision: {precision_score(y_test, prediction_classes):.2f}')
|
|
print(f'Recall: {recall_score(y_test, prediction_classes):.2f}') |