import pandas as pd
from [Link] import IsolationForest
# Load the dataset from Excel file
data = pd.read_excel('cyclone_data.xlsx')
# Select the relevant columns for anomaly detection
selected_columns = ['Cyclone_Inlet_Gas_Temp', 'Cyclone_Gas_Outlet_Temp',
'Cyclone_Outlet_Gas_draft', 'Cyclone_cone_draft',
'Cyclone_Inlet_Draft', 'Cyclone_Material_Temp']
X = data[selected_columns]
# Initialize and fit the Isolation Forest model
model = IsolationForest(contamination='auto', random_state=42)
[Link](X)
# Predict the anomalies
predictions = [Link](X)
# Add the anomaly predictions as a new column in the original dataset
data['Anomaly'] = predictions
# Filter the dataset to show only the anomalous records
anomalies = data[data['Anomaly'] == -1]
# Identify the time periods with abnormal operations
abnormal_periods = []
current_period = []
for index, row in [Link]():
if len(current_period) == 0:
current_period.append(index)
elif index == current_period[-1] + 1:
current_period.append(index)
else:
abnormal_periods.append(current_period)
current_period = [index]
# Print the time periods with abnormal operations
for period in abnormal_periods:
start_time = [Link][period[0], 'Timestamp']
end_time = [Link][period[-1], 'Timestamp']
print(f"Abnormal period: {start_time} to {end_time}")