0% found this document useful (0 votes)
18 views

Code

Uploaded by

naveen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Code

Uploaded by

naveen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

import pandas as pd

from sklearn.ensemble 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)
model.fit(X)

# Predict the anomalies


predictions = model.predict(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 anomalies.iterrows():


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 = data.loc[period[0], 'Timestamp']
end_time = data.loc[period[-1], 'Timestamp']
print(f"Abnormal period: {start_time} to {end_time}")

You might also like