import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
# Load the dataset
dataset = pd.read_csv('maintenance_data.csv')
# Split the dataset into features (X) and target variable (y)
X = dataset.drop('failure', axis=1)
y = dataset['failure']
# Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Create a Random Forest Classifier
model = RandomForestClassifier()
# Train the model
model.fit(X_train, y_train)
# Make predictions on the test set
y_pred = model.predict(X_test)
# Evaluate the model's accuracy
accuracy = accuracy_score(y_test, y_pred)
print('Accuracy:', accuracy)
In this code snippet:
The dataset is loaded using pd.read_csv() from a CSV file named maintenance_data.csv. This dataset should contain historical data related to equipment, including features and the target variable indicating whether a failure occurred or not.
The dataset is split into features (X) and the target variable (y).
The data is further split into training and testing sets using train_test_split() from sklearn.model_selection. Adjust the test_size parameter as needed.
A Random Forest Classifier is created using RandomForestClassifier() from sklearn.ensemble.
The model is trained using the training data with model.fit(X_train, y_train).
Predictions are made on the test set using model.predict(X_test).
The accuracy of the model is evaluated by comparing the predicted values (y_pred) with the actual values (y_test) using accuracy_score() from sklearn.metrics.
Note that this is a basic example using a Random Forest Classifier. Depending on your specific requirements, you might need to explore other ML algorithms, perform feature engineering, hyperparameter tuning, or handle imbalanced data to improve the accuracy of the predictive maintenance model.
Ensure that you have a suitable dataset containing relevant features and the target variable indicating failures or maintenance needs for your equipment. Adjust the code accordingly to fit your dataset and consider additional preprocessing steps or model enhancements based on your specific use case.
the sample data for this is as below
temperature,humidity,vibration,failure
30,60,0.2,0
28,55,0.3,0
32,58,0.5,1
26,50,0.4,0
34,65,0.6,1
No comments:
Post a Comment