first commit
This commit is contained in:
commit
77eb99cbf5
31
Model.py
Normal file
31
Model.py
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
import pandas as pd
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
# Make numpy values easier to read.
|
||||||
|
np.set_printoptions(precision=3, suppress=True)
|
||||||
|
|
||||||
|
import tensorflow as tf
|
||||||
|
from tensorflow.keras import layers
|
||||||
|
|
||||||
|
ecvalve = pd.read_csv(
|
||||||
|
"/home/fferreira/Documents/teste_ecvalve.csv",
|
||||||
|
names=[ "frequency", "state", "pressure", "capacity"])
|
||||||
|
print("Data shape:", ecvalve.shape)
|
||||||
|
print("Columns:", ecvalve.columns)
|
||||||
|
|
||||||
|
ecvalve.head()
|
||||||
|
ecvalve_features = ecvalve.copy()
|
||||||
|
ecvalve_labels = ecvalve_features.pop('state')
|
||||||
|
|
||||||
|
ecvalve_features = np.array(ecvalve_features)
|
||||||
|
|
||||||
|
ecvalve_model = tf.keras.Sequential([
|
||||||
|
layers.Dense(64, activation='relu', input_shape=(ecvalve_features.shape[1],)),
|
||||||
|
layers.Dense(32, activation='relu'), # Add another layer
|
||||||
|
layers.Dense(1, activation='sigmoid') # Sigmoid for binary classification
|
||||||
|
])
|
||||||
|
ecvalve_model.compile(loss=tf.keras.losses.BinaryCrossentropy(), optimizer=tf.keras.optimizers.Adam(), metrics=['accuracy'])
|
||||||
|
|
||||||
|
ecvalve_model.fit(ecvalve_features, ecvalve_labels, epochs=20)
|
||||||
|
|
||||||
|
ecvalve_model.save('EcValve_1.h5')
|
||||||
14
Predict.py
Normal file
14
Predict.py
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
import tensorflow as tf
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
import tensorflow as tf
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
model = tf.keras.models.load_model('EcValve_1.h5')
|
||||||
|
|
||||||
|
input_data = np.array([[-0.029184604, 7, 60]], dtype=np.float32) # Shape: (1, 3)
|
||||||
|
|
||||||
|
prediction = model.predict(input_data)
|
||||||
|
|
||||||
|
print("Prediction (probability of leak):", prediction)
|
||||||
|
print("Leak detected" if prediction[0] > 0.5 else "No leak")
|
||||||
42
graph.py
Normal file
42
graph.py
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
import pandas as pd
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import seaborn as sns
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
# Set seaborn style for better visuals
|
||||||
|
sns.set(style="whitegrid")
|
||||||
|
|
||||||
|
# Load CSV
|
||||||
|
ecvalve = pd.read_csv(
|
||||||
|
"/home/fferreira/Documents/teste_ecvalve.csv",
|
||||||
|
names=["frequency", "state", "pressure", "capacity"])
|
||||||
|
print("Data shape:", ecvalve.shape)
|
||||||
|
print("Label distribution:", ecvalve['state'].value_counts())
|
||||||
|
|
||||||
|
# Group by frequency and get unique states
|
||||||
|
freq_states = ecvalve.groupby('frequency')['state'].unique().reset_index()
|
||||||
|
freq_states['category'] = freq_states['state'].apply(
|
||||||
|
lambda x: '0' if len(x) == 1 and x[0] == 0 else '1' if len(x) == 1 and x[0] == 1 else 'Both'
|
||||||
|
)
|
||||||
|
|
||||||
|
print("\nFrequencies and their state categories:")
|
||||||
|
print(freq_states[['frequency', 'category']].sort_values('frequency'))
|
||||||
|
|
||||||
|
# Create scatter plot
|
||||||
|
plt.figure(figsize=(10, 6))
|
||||||
|
sns.scatterplot(
|
||||||
|
x='frequency',
|
||||||
|
y='category',
|
||||||
|
hue='category',
|
||||||
|
style='category',
|
||||||
|
data=freq_states,
|
||||||
|
palette={'0': '#36A2EB', '1': '#FF6384', 'Both': '#FFCE56'},
|
||||||
|
s=100
|
||||||
|
)
|
||||||
|
plt.title('Frequencies by State Category (0 = No Leak, 1 = Leak, Both = Mixed)')
|
||||||
|
plt.xlabel('Frequency (Hz)')
|
||||||
|
plt.ylabel('State Category')
|
||||||
|
plt.savefig('/home/fferreira/Documents/HarvardX/teste/frequency_state_categories.png')
|
||||||
|
plt.close()
|
||||||
|
|
||||||
|
print("Graph saved: /home/fferreira/Documents/HarvardX/teste/frequency_state_categories.png")
|
||||||
Loading…
Reference in New Issue
Block a user