MACHINE LEARNING MODEL FOR MECHANICAL ENGG. APPLICATIONS (KNN ALGORITHM)
Dr.Nadakatti Mahantesh
Professor, Post-Doc Fellow (Sweden), Ph.D., FIE, MIE, MISTE,Certified VLCI Demonstrator, Professor at Gogte Institute of Technology, Belgaum, India,
Artificial intelligence (AI) is a broad field encompassing any technique that enables machines to mimic human cognitive functions. This includes everything from simple rule-based systems to complex algorithms capable of learning and adapting.
?Machine learning (ML) is a powerful subfield of AI that allows computers to learn from data without explicit programming. By analyzing massive datasets, ML algorithms can identify patterns, make predictions, and improve their performance over time. This makes them invaluable for a wide range of applications, from recommendation systems suggesting products you might like to medical diagnosis tools that can detect diseases with high accuracy.
?
Applications of the K-Nearest Neighbours (KNN) Algorithm in Mechanical Engineering
The K-Nearest Neighbors (KNN) algorithm is a versatile and intuitive machine learning technique widely used across various domains, including mechanical engineering. Its simplicity, ease of implementation, and effectiveness in handling complex datasets make it a valuable tool for engineers looking to incorporate predictive modeling and classification tasks into their workflows. This note explores several key applications of the KNN algorithm in the field of mechanical engineering.
1. Fault Diagnosis and Predictive Maintenance
One of the primary applications of KNN in mechanical engineering is in fault diagnosis and predictive maintenance. Machinery and mechanical systems are prone to wear and tear, leading to potential failures. Predictive maintenance aims to foresee these failures before they occur, allowing for timely intervention and reducing downtime.
2. Material Property Classification
Mechanical engineering frequently deals with materials of various properties and behaviors. KNN can be employed to classify materials based on their characteristics, such as hardness, tensile strength, and elasticity.
3. Quality Control and Manufacturing
Ensuring product quality is essential in manufacturing processes. KNN is valuable for real-time quality control by analyzing data from various stages of the production line.
4. Performance Prediction
Predicting the performance of mechanical systems under different conditions is another critical application of KNN.
5. Design and Prototyping
In the design phase, KNN can help engineers make informed decisions by predicting the outcomes of design changes based on historical data.
6. Energy Consumption Optimization
In industries where energy efficiency is critical, such as HVAC systems and manufacturing plants, KNN can predict energy consumption patterns and suggest optimization strategies.
CONCLUSIONS
The K-Nearest Neighbors (KNN) algorithm offers a wide range of applications in mechanical engineering. Its ability to classify and predict based on historical data makes it a valuable tool for fault diagnosis, material classification, quality control, performance prediction, design optimization, and energy consumption management. As mechanical systems and processes become increasingly complex, the role of KNN and other machine learning algorithms will continue to grow, enabling engineers to enhance efficiency, reliability, and innovation in their work.
Top of Form
Bottom of Form
?
BEARING CONDITION PREDICTION USING MATLAB’S KNN Capabilities.
PART A
Two data sets, imported into MATLAB workspace:
a)???? Training data set, shown on left side screenshot above. : Name of the file “BearingRPMVsTemp.xlsx”
b)???? Testing Data set, shown on the right side screenshot above: Name of the file “TestDataBearingRPMVsTemp.xlsx.”
?
?
Important Notes:
?? Training data set has 4 columns, 3 with format as “Number” and 4th column is a “Straing” format, which is referred to as “Categorical” in MATLAB.
?? Testing data set has 3 columns, exactly same as first 3 columns of Training data set. 4th column is left blank intentionally, as the KNN model should predict the outcomes of the Testing Data, which will be copy-pasted later, in the 4th column, and will be saved as? separate file with suitable name, say as “PredictedBearingCondition”, etc .? Don’t even give the column name in the 4th column. It will be just a 3 column excel file, that’s all! This data is imported from test setups, using which we need to predict the condition of the bearing.
?
?
?
PART B
?
Editor Code: Type the following under “Editor”, “New” and save the file as “*.m*. In the present case, it is saved as “KNNModel23062024V2”.
% Load the dataset
data = readtable('BearingRPMVsTemp.xlsx');
?
% Convert Quality column to categorical
data.Quality = categorical(data.Quality);
?
% Split the data into features and labels
X = table2array(data(:,1:end-1));? % Features
Y = data.Quality;????????????????? % Labels
?
% Split the dataset into training and testing sets (80% training dataset and 20% testing dataset)
split = 0.8;
idx = randperm(size(data, 1));
trainIdx = idx(1:round(split * end));
testIdx = idx(round(split * end) + 1:end);
?
X_train = X(trainIdx, :);
Y_train = Y(trainIdx, :);
X_test = X(testIdx, :);
Y_test = Y(testIdx, :);
?
% Train the KNN model
k = 5;? % Set the number of neighbors
md1 = fitcknn(X_train, Y_train, 'NumNeighbors', k);
?
% Predict on the test set
Y_pred = predict(md1, X_test);
?
% Evaluate the model
accuracy = sum(Y_pred == Y_test) / numel(Y_test);
disp(['Accuracy: ' num2str(accuracy * 100) '%']);
?
% Present Confusion Chart
confusionchart(Y_test, Y_pred);
?
% Now, predict with the new dataset
newData = readtable('TestDataBearingRPMVsTemp.xlsx');
领英推荐
?
% Assuming newData has the same structure as the original features used for training
X_new = table2array(newData);
?
% Verify the number of columns in X_new
expectedColumns = size(X_train, 2);? % Ensure that new data matches the training data structure
if size(X_new, 2) ~= expectedColumns
??? error(['The number of columns in X_new (' num2str(size(X_new, 2)) ') does not match the training data (' num2str(expectedColumns) ').']);
end
?
% Predict on the new dataset using the trained KNN model
Y_new_pred = predict(md1, X_new);
?
% Display the predicted results
disp('Predicted Quality for the new dataset:');
disp(Y_new_pred);
?
?Screenshot of CODE written in MATLAB EDITOR tab, using “NEW” option.
Observations in the Screenshot shown above:
a)? Entire code is written in Editor Window and saved as KNNModel23062024V2.m.
b)? 2 files have been imported into MATLAB workspace, as shown on the right side of the screen
a.???????? BearingRPMVsTemp ---------------------Training Data Set. ??4 Column Excel table (3 columns : Number data, last 4th column: String data, referred to as “Categorial” data in MATLAB.? This is the data regarding various factors which affect the life of a bearing and the condition of the bearing under those conditions,
??? Ex.: a) Bearing age,
????????? ??????b) Bearing RPM,
???????? ?c) Bearing Temperature and
???????? ?d) last column is Bearing Condition.
b.???????? TestDataBearingRPMVsTemp ----------Testing Data Set. This is? a 3 column data, containing information only the factors affecting bearing condition.? 4th column is totally left out. Even column heading also is not mentioned.
c.???????? Make sure that, both files have exactly same structure. Column headings should be identical.
?
?
PART C
?Observations:
Training DataSet
X_train has a dataset of 15 elements. (80% of the given dataset of 19 elements for training purpose)
Y_train has exactly 15 predictions (corresponding to 15 elements of X_train dataset.)
Test DataSet
X_test has a dataset of 4 elements. (20% of the given dataset of 19 elements for training purpose)
Y_train has exactly 4 predictions (corresponding to 4 elements of X_train dataset.)
Model Development and accuracy level: Once all the pre-requisites are met, execute the program.
i.e., 1) Type the entire code.
??????? 2) Import two files in MATLAB workspace.
??????? 3) “Run” the program and check for any errors. Debug them.
??????? 4) MATLAB is PATH SPECIFIC application and special attention should be given for naming MATLAB programs. (No spaces are allowed in the file name. Ex.in the present case, file name is KNNMODEL23062024.M)
Screenshot after executing the program:
?
Accuracy Level is 50% as seen in the screenshot.
Confusion Matrix:
THIS COMPLETES THE MODEL GENERATION AND TRAINING. NEXT STEP IS TO PREDICT THE BEARING CONDITION BASED ON THE KNN MODLE DEVELOPED? AND TEST IT. For this, we have already loaded the test data set, containing bearing information, in the 2nd file. It is also imported in to the MATLAB environment..
Even the code is written to PREDICT THE BEARING condition.
Just execute the program. That’s all.
Observations:
1)??? Bearing condition of the test data set is predicted.
2)??? There are 9 rows of data in Test Data Set, using which, the model should predict the bearing condition.
3)??? Exactly 9 outcomes are generated by the KNN algorithm as can be seen from the above screenshot.
PART D
?Copy these outcomes and paste them in 4th column of Test Data Set and name the file suitably, in the present case, it is saved as PredictedBearingCondition.xlsx. Since the accuracy level is 50%, we need to have more training data.
THAT’S IT. THIS IS HOW THE KNN Machine Learning Model is developed and deployed for Bearing Condition Monitoring. Similar applications could be developed for other mechanical engineering applications and fault diagnosis, by suitably altering the data column headings, file names ?and the code.
Some examples where this could be effectively employed is large data sets containing vibration signatures ( Frequency V/s Amplitude, Pressure V/s Volume, Pressure, Temperature and Resistance, wear rate analysis, etc.)
?
Though this article is written with a Mechanical Engineering perspective, similar logic could be applied for any branch of engineering to develop suitable Machine Learning Models which help in solving complex processes, with relatively less effort, time and with better accuracy levels.
?
For further details send an email to : [email protected]
?
Dr.M.M.Nadakatti,
Professor, Dept. of Mechanical Engineering,
KLS Gogte Institute of Technology,
Belagavi, 590008.
?
?Acknowledgement:
?Author wishes to acknowledge the help with regard to MATLAB code from Mr. Andrews A, from The Mechanical Engineer and his YOUTUBE Video.
?
Senior Data Analyst | Data Enthusiast | Kaggle Contributor | Planning Analyst | Senior PMO | Change Management | PMO Trainer
8 个月Wonderfully narrated. Thought provoking