在油氣行業中,輸送管道是至關重要的設備,它們負責將油氣從生產地運送到儲存或加工地點。監測這些管道的健康狀態可以幫助預防漏油、泄漏等意外事件,保障生產運營的安全和效率
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, classification_report
# 創建一個虛擬的輸送管道健康監測數據集
data = {'Pressure': [150, 155, 140, 160, 158, 152],
'FlowRate': [500, 520, 480, 510, 515, 505],
'Temperature': [35, 34, 36, 33, 37, 34],
'Status': [0, 0, 1, 0, 1, 1]} # 0 表示正常,1 表示異常
df = pd.DataFrame(data)
# 提取特徵和目標變量
X = df[['Pressure', 'FlowRate', 'Temperature']]
y = df['Status']
# 將數據集劃分為訓練集和測試集
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# 初始化隨機森林分類器
rf_model = RandomForestClassifier()
# 訓練模型
rf_model.fit(X_train, y_train)
# 預測管道狀態
y_pred = rf_model.predict(X_test)
# 計算準確度
accuracy = accuracy_score(y_test, y_pred)
print(f"準確度: {accuracy}")
print(classification_report(y_test, y_pred))