MACHINE LEARNING MODEL FOR MECHANICAL ENGG. APPLICATIONS                            (KNN ALGORITHM)

MACHINE LEARNING MODEL FOR MECHANICAL ENGG. APPLICATIONS (KNN ALGORITHM)


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.

  • Vibration Analysis: Mechanical systems often generate vibrational signals during operation. KNN can classify these signals into normal and faulty categories by comparing the patterns of new data against a historical dataset of vibration patterns. This classification helps in diagnosing faults early and accurately.
  • Temperature Monitoring: In systems where temperature is a critical parameter, such as engines or turbines, KNN can predict abnormal temperature behaviors that indicate potential failures. By analyzing temperature data over time, the algorithm can identify when a component is operating outside its expected range.

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.

  • Composite Materials: For complex materials like composites, which are widely used in aerospace and automotive industries, KNN can classify material samples into categories based on their composite makeup and properties. This classification aids in selecting the right materials for specific engineering applications.
  • Metallurgy: In metallurgy, KNN can classify alloys and predict their mechanical properties based on historical data. This application is crucial for selecting the appropriate materials for manufacturing processes and ensuring product reliability.

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.

  • Defect Detection: By comparing real-time production data with known defect patterns, KNN can classify products as defective or non-defective. This application is particularly useful in high-speed manufacturing environments where manual inspection is impractical.
  • Process Optimization: KNN can also assist in optimizing manufacturing processes. By analyzing past production data, the algorithm can predict the optimal settings for machinery to produce the highest quality products with minimal waste.

4. Performance Prediction

Predicting the performance of mechanical systems under different conditions is another critical application of KNN.

  • Engine Performance: KNN can be used to predict engine performance parameters such as fuel consumption, power output, and emission levels based on operational data. This prediction helps in optimizing engine settings for efficiency and regulatory compliance.
  • Structural Load Prediction: For structures subject to varying loads, KNN can predict the load-bearing capacity and identify potential points of failure. This application is vital in civil engineering projects, such as bridges and buildings, ensuring safety and reliability.

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.

  • CAD Integration: KNN can be integrated with Computer-Aided Design (CAD) tools to classify design features and suggest improvements. For example, in automotive design, KNN can predict the aerodynamic properties of new car models based on the shapes and configurations of previous designs.
  • Prototype Testing: During prototype testing, KNN can classify test results to identify whether the prototype meets the desired performance criteria. This classification aids in refining designs before mass production.

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.

  • HVAC Systems: KNN can predict the energy usage of HVAC systems based on various environmental factors and operational settings. This prediction helps in adjusting the systems for optimal energy efficiency and comfort.
  • Manufacturing Energy Use: By analyzing historical energy consumption data, KNN can classify production processes into high and low energy usage categories. This classification aids in identifying energy-saving opportunities in manufacturing operations.

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.

?


Aditya Narendra

Senior Data Analyst | Data Enthusiast | Kaggle Contributor | Planning Analyst | Senior PMO | Change Management | PMO Trainer

8 个月

Wonderfully narrated. Thought provoking

要查看或添加评论,请登录

Dr.Nadakatti Mahantesh的更多文章

社区洞察

其他会员也浏览了