Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
8 views
Final Code
Uploaded by
Vineet Jaiswal
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download now
Download
Save final Code For Later
Download
Save
Save final Code For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
8 views
Final Code
Uploaded by
Vineet Jaiswal
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download now
Download
Save final Code For Later
Carousel Previous
Carousel Next
Save
Save final Code For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 3
Search
Fullscreen
% Load necessary packages
import matlab.io.*
import matlab.internal.math.*
% Read the data from Excel file
data = readtable('C:\\Users\\Vineet Jaiswal\\Desktop\\G6\\MATLAB\\Concrete Mix
Design- Workbook complete.xlsx', 'Sheet', 1, 'Range', 'A2:AJ5000');
% Extract the feature matrix (X) and target variables (y)
X = data(:, 1:33);
ls1 = data(:, 34);
ls2 = data(:, 35);
ls3 = data(:, 36);
% Convert tables to arrays
X = table2array(X);
ls1 = table2array(ls1);
ls2 = table2array(ls2);
ls3 = table2array(ls3);
% Replace NaN values with mean of respective columns
X = fillmissing(X, 'constant', mean(X, 'omitnan'));
ls1 = fillmissing(ls1, 'constant', mean(ls1, 'omitnan'));
ls2 = fillmissing(ls2, 'constant', mean(ls2, 'omitnan'));
ls3 = fillmissing(ls3, 'constant', mean(ls3, 'omitnan'));
% Split the data into training and testing sets
[trainIdx1, testIdx1] = crossvalind('HoldOut', ls1, 0.2);
[trainIdx2, testIdx2] = crossvalind('HoldOut', ls2, 0.2);
[trainIdx3, testIdx3] = crossvalind('HoldOut', ls3, 0.2);
X1_train = X(trainIdx1, :); ls1_train = ls1(trainIdx1);
X1_test = X(testIdx1, :); ls1_test = ls1(testIdx1);
[X1_val, ls1_val, X1_test, ls1_test] = splitTestData(X1_test, ls1_test);
X2_train = X(trainIdx2, :); ls2_train = ls2(trainIdx2);
X2_test = X(testIdx2, :); ls2_test = ls2(testIdx2);
[X2_val, ls2_val, X2_test, ls2_test] = splitTestData(X2_test, ls2_test);
X3_train = X(trainIdx3, :); ls3_train = ls3(trainIdx3);
X3_test = X(testIdx3, :); ls3_test = ls3(testIdx3);
[X3_val, ls3_val, X3_test, ls3_test] = splitTestData(X3_test, ls3_test);
% Function to split test data into validation and test sets
function [X_val, y_val, X_test, y_test] = splitTestData(X_test, y_test)
numTest = length(y_test);
valSize = floor(numTest / 2);
valIdx = randperm(numTest, valSize);
testIdx = setdiff(1:numTest, valIdx);
X_val = X_test(valIdx, :); y_val = y_test(valIdx);
X_test = X_test(testIdx, :); y_test = y_test(testIdx);
end
% Apply Lasso regression
start_time = tic;
[B1, FitInfo1] = lasso(X1_train, ls1_train, 'Alpha', 0.1);
[B2, FitInfo2] = lasso(X2_train, ls2_train, 'Alpha', 0.1);
[B3, FitInfo3] = lasso(X3_train, ls3_train, 'Alpha', 0.1);
elapsed_time = toc(start_time);
% Predict on the testing data
ls1_pred = X1_test * B1 + FitInfo1.Intercept;
ls2_pred = X2_test * B2 + FitInfo2.Intercept;
ls3_pred = X3_test * B3 + FitInfo3.Intercept;
% Predict on the validation set
ls1_val_pred = X1_val * B1 + FitInfo1.Intercept;
ls2_val_pred = X2_val * B2 + FitInfo2.Intercept;
ls3_val_pred = X3_val * B3 + FitInfo3.Intercept;
% Evaluate the model on the validation set
mse_val1 = mean((ls1_val - ls1_val_pred).^2);
r2_val1 = 1 - sum((ls1_val - ls1_val_pred).^2) / sum((ls1_val - mean(ls1_val)).^2);
fprintf('Validation Mean Squared Error: %.4f\n', mse_val1);
fprintf('Validation R-squared Score: %.4f\n', r2_val1);
mse_val2 = mean((ls2_val - ls2_val_pred).^2);
r2_val2 = 1 - sum((ls2_val - ls2_val_pred).^2) / sum((ls2_val - mean(ls2_val)).^2);
fprintf('Validation Mean Squared Error: %.4f\n', mse_val2);
fprintf('Validation R-squared Score: %.4f\n', r2_val2);
mse_val3 = mean((ls3_val - ls3_val_pred).^2);
r2_val3 = 1 - sum((ls3_val - ls3_val_pred).^2) / sum((ls3_val - mean(ls3_val)).^2);
fprintf('Validation Mean Squared Error: %.4f\n', mse_val3);
fprintf('Validation R-squared Score: %.4f\n', r2_val3);
% Save predictions and actuals to Excel
filename = 'out.xlsx';
writetable(array2table(ls1_pred), filename, 'Sheet', 'prediction1',
'WriteVariableNames', false);
writetable(array2table(ls1_test), filename, 'Sheet', 'actuals1',
'WriteVariableNames', false);
writetable(array2table(ls2_pred), filename, 'Sheet', 'prediction2',
'WriteVariableNames', false);
writetable(array2table(ls2_test), filename, 'Sheet', 'actuals2',
'WriteVariableNames', false);
writetable(array2table(ls3_pred), filename, 'Sheet', 'prediction3',
'WriteVariableNames', false);
writetable(array2table(ls3_test), filename, 'Sheet', 'actuals3',
'WriteVariableNames', false);
% Evaluate the model
mse1 = mean((ls1_test - ls1_pred).^2);
r21 = 1 - sum((ls1_test - ls1_pred).^2) / sum((ls1_test - mean(ls1_test)).^2);
fprintf('Mean Squared Error: %.4f\n', mse1);
fprintf('R-squared Score: %.4f\n', r21);
fprintf('Time elapsed: %.4f seconds\n', elapsed_time);
mse2 = mean((ls2_test - ls2_pred).^2);
r22 = 1 - sum((ls2_test - ls2_pred).^2) / sum((ls2_test - mean(ls2_test)).^2);
fprintf('Mean Squared Error: %.4f\n', mse2);
fprintf('R-squared Score: %.4f\n', r22);
fprintf('Time elapsed: %.4f seconds\n', elapsed_time);
mse3 = mean((ls3_test - ls3_pred).^2);
r23 = 1 - sum((ls3_test - ls3_pred).^2) / sum((ls3_test - mean(ls3_test)).^2);
fprintf('Mean Squared Error: %.4f\n', mse3);
fprintf('R-squared Score: %.4f\n', r23);
fprintf('Time elapsed: %.4f seconds\n', elapsed_time);
% Save coefficients to Excel
writetable(array2table(B1), filename, 'Sheet', 'coefficients1',
'WriteVariableNames', false);
writetable(array2table(B2), filename, 'Sheet', 'coefficients2',
'WriteVariableNames', false);
writetable(array2table(B3), filename, 'Sheet', 'coefficients3',
'WriteVariableNames', false);
disp('all done');
You might also like
Download Study Guide for 1Z0 071 Oracle Database 12c SQL Oracle Certification Prep 1st Edition Matthew Morris ebook All Chapters PDF
PDF
100% (1)
Download Study Guide for 1Z0 071 Oracle Database 12c SQL Oracle Certification Prep 1st Edition Matthew Morris ebook All Chapters PDF
55 pages
Statistics, Data Analysis, and Decision Modeling, 5th Edition
PDF
100% (5)
Statistics, Data Analysis, and Decision Modeling, 5th Edition
556 pages
Using INF Files To Edit The Window Registry
PDF
No ratings yet
Using INF Files To Edit The Window Registry
5 pages
Hologram Dream Sequence Manual
PDF
No ratings yet
Hologram Dream Sequence Manual
21 pages
Selected Solutions To Munkres's Topology, 2nd Ed.: Takumi Murayama December 20, 2014
PDF
100% (1)
Selected Solutions To Munkres's Topology, 2nd Ed.: Takumi Murayama December 20, 2014
54 pages
Briefly Explain The Trade-Offs Associated Between The Model Variance Versus Bias-Squared To Inform Model Selection
PDF
No ratings yet
Briefly Explain The Trade-Offs Associated Between The Model Variance Versus Bias-Squared To Inform Model Selection
7 pages
Naive Bayes
PDF
No ratings yet
Naive Bayes
58 pages
Datos: %entrenamiento %validación %test
PDF
No ratings yet
Datos: %entrenamiento %validación %test
16 pages
2 Linear Regression
PDF
No ratings yet
2 Linear Regression
5 pages
Exp 5-6-7-8
PDF
No ratings yet
Exp 5-6-7-8
8 pages
DA_Programs
PDF
No ratings yet
DA_Programs
44 pages
Cl-Vii Ass2 4301063
PDF
No ratings yet
Cl-Vii Ass2 4301063
5 pages
21brs1474 ML Lab 2
PDF
No ratings yet
21brs1474 ML Lab 2
25 pages
Assignment 1
PDF
No ratings yet
Assignment 1
16 pages
ML Lab Prgms Split
PDF
No ratings yet
ML Lab Prgms Split
3 pages
Data Mining Practicals
PDF
No ratings yet
Data Mining Practicals
22 pages
BL.SC.U4AIE24125[SHEET-6,7,8][1]
PDF
No ratings yet
BL.SC.U4AIE24125[SHEET-6,7,8][1]
41 pages
New Text Document
PDF
No ratings yet
New Text Document
7 pages
CASOS
PDF
No ratings yet
CASOS
12 pages
Applied Linear Regression
PDF
No ratings yet
Applied Linear Regression
13 pages
R
PDF
No ratings yet
R
4 pages
ML2
PDF
No ratings yet
ML2
7 pages
Multiple Linear Regression
PDF
100% (1)
Multiple Linear Regression
14 pages
MACHINE PROBLEM 9
PDF
No ratings yet
MACHINE PROBLEM 9
6 pages
Bi Pract 9
PDF
No ratings yet
Bi Pract 9
8 pages
Stat Lab
PDF
No ratings yet
Stat Lab
24 pages
Cost Practical
PDF
No ratings yet
Cost Practical
13 pages
Labrecord
PDF
No ratings yet
Labrecord
39 pages
paper
PDF
No ratings yet
paper
7 pages
20BCE1205 Lab3
PDF
No ratings yet
20BCE1205 Lab3
9 pages
7406HW02-1
PDF
No ratings yet
7406HW02-1
3 pages
Stukas ML Loop Rev.r
PDF
No ratings yet
Stukas ML Loop Rev.r
8 pages
EE 5020 Spring 2024 Project 2
PDF
No ratings yet
EE 5020 Spring 2024 Project 2
3 pages
T8-Least Squares Regression
PDF
No ratings yet
T8-Least Squares Regression
9 pages
Appendix
PDF
No ratings yet
Appendix
12 pages
Matlab Homework Experts 2
PDF
No ratings yet
Matlab Homework Experts 2
10 pages
Model Summaru Output
PDF
No ratings yet
Model Summaru Output
12 pages
Zerox Ready
PDF
No ratings yet
Zerox Ready
21 pages
Department of Metallurgical Engineering and Materials Science, IIT Bombay
PDF
No ratings yet
Department of Metallurgical Engineering and Materials Science, IIT Bombay
5 pages
Cappstone
PDF
No ratings yet
Cappstone
2 pages
20mia1032 A Sri Karthik - Lab - Assessment
PDF
No ratings yet
20mia1032 A Sri Karthik - Lab - Assessment
6 pages
Lab 7 - Bias and Variance
PDF
No ratings yet
Lab 7 - Bias and Variance
5 pages
Matlab Prject
PDF
No ratings yet
Matlab Prject
10 pages
ml_all_projectpdf_removed
PDF
No ratings yet
ml_all_projectpdf_removed
41 pages
Cran.r2021-Linear Regression and Logistic Regression With Missing Covariates
PDF
No ratings yet
Cran.r2021-Linear Regression and Logistic Regression With Missing Covariates
10 pages
Labtask1: Generatedataset
PDF
No ratings yet
Labtask1: Generatedataset
12 pages
A028 GLM-SC3
PDF
No ratings yet
A028 GLM-SC3
137 pages
ML Record Print
PDF
No ratings yet
ML Record Print
20 pages
Lab4 Ch22b023 CTC
PDF
No ratings yet
Lab4 Ch22b023 CTC
15 pages
MAE 502 Prob Set 3
PDF
No ratings yet
MAE 502 Prob Set 3
8 pages
Data Science Manual
PDF
No ratings yet
Data Science Manual
16 pages
Data Mining Lab Manual
PDF
No ratings yet
Data Mining Lab Manual
7 pages
Taf 6002505
PDF
No ratings yet
Taf 6002505
24 pages
HW11數學規劃
PDF
No ratings yet
HW11數學規劃
14 pages
Regression Model
PDF
No ratings yet
Regression Model
6 pages
Statistics, Statistical Modelling and Data analytics_practicalfile_sj
PDF
No ratings yet
Statistics, Statistical Modelling and Data analytics_practicalfile_sj
23 pages
Lab 8
PDF
No ratings yet
Lab 8
13 pages
1 - Standard Linear Regression: Numpy NP Pandas
PDF
No ratings yet
1 - Standard Linear Regression: Numpy NP Pandas
4 pages
Chandigarh Group of Colleges College of Engineering Landran, Mohali
PDF
No ratings yet
Chandigarh Group of Colleges College of Engineering Landran, Mohali
47 pages
Unit 2 Regression Analysis
PDF
No ratings yet
Unit 2 Regression Analysis
16 pages
Complete PSLP
PDF
No ratings yet
Complete PSLP
17 pages
Rallfun v37
PDF
No ratings yet
Rallfun v37
1,294 pages
vertopal.com_Lab_Linear_Regression
PDF
No ratings yet
vertopal.com_Lab_Linear_Regression
21 pages
Computer Engineering Laboratory Solution Primer
From Everand
Computer Engineering Laboratory Solution Primer
Karan Bhandari
No ratings yet
The Essential R Reference
From Everand
The Essential R Reference
Mark Gardener
No ratings yet
Si tts520 10mhz To 520mhz Transmitter Test Set Amm B Automatic Modulation
PDF
No ratings yet
Si tts520 10mhz To 520mhz Transmitter Test Set Amm B Automatic Modulation
108 pages
The Effect of Psychological Empowerment On Job Satisfaction
PDF
No ratings yet
The Effect of Psychological Empowerment On Job Satisfaction
10 pages
KORG Collection: Owner's Manual
PDF
No ratings yet
KORG Collection: Owner's Manual
65 pages
Minor II V I
PDF
No ratings yet
Minor II V I
3 pages
Be Chemical Engineering Second Year Se Semester 3 Rev 2019 C Scheme
PDF
No ratings yet
Be Chemical Engineering Second Year Se Semester 3 Rev 2019 C Scheme
64 pages
CMD Line
PDF
No ratings yet
CMD Line
394 pages
Dig Assist 4.0 OBW Operator
PDF
No ratings yet
Dig Assist 4.0 OBW Operator
54 pages
MC-1612 Datasheet v0.95
PDF
No ratings yet
MC-1612 Datasheet v0.95
13 pages
CLASS 5TH Syllabus and Date sheet
PDF
No ratings yet
CLASS 5TH Syllabus and Date sheet
2 pages
Cat Syllabus PDF 2025
PDF
100% (1)
Cat Syllabus PDF 2025
31 pages
B - Inductance Profile
PDF
No ratings yet
B - Inductance Profile
4 pages
Beam Reinforced Shell Structure Using Offsets
PDF
No ratings yet
Beam Reinforced Shell Structure Using Offsets
12 pages
L9 Vectors in Space
PDF
No ratings yet
L9 Vectors in Space
4 pages
What Is A Tree?
PDF
No ratings yet
What Is A Tree?
10 pages
Programmable Logic Controller (PLC)
PDF
No ratings yet
Programmable Logic Controller (PLC)
43 pages
Prod. Ucts Det. Ails
PDF
No ratings yet
Prod. Ucts Det. Ails
15 pages
Assignment Highway Engg For 2013
PDF
No ratings yet
Assignment Highway Engg For 2013
5 pages
Nandika Sampath Tennakoon
PDF
No ratings yet
Nandika Sampath Tennakoon
13 pages
STATISTICS-LESSON-14 3rd Quarter
PDF
No ratings yet
STATISTICS-LESSON-14 3rd Quarter
23 pages
UAS TM-4030, 29-11-2021: Waktu 2 Jam: No Pernyataan B S
PDF
No ratings yet
UAS TM-4030, 29-11-2021: Waktu 2 Jam: No Pernyataan B S
5 pages
Grimm Edm 180
PDF
No ratings yet
Grimm Edm 180
12 pages
SAP HANA XS JavaScript Reference
PDF
No ratings yet
SAP HANA XS JavaScript Reference
130 pages
Chapter 8 Transport in Humans_Student_S3_completed version
PDF
No ratings yet
Chapter 8 Transport in Humans_Student_S3_completed version
19 pages
EHP-5 Pneumatics and Hydraulics COURSE 2-1441-1442 New Update
PDF
100% (1)
EHP-5 Pneumatics and Hydraulics COURSE 2-1441-1442 New Update
255 pages
First Draft 100L STATISTICS First Semester 2024
PDF
No ratings yet
First Draft 100L STATISTICS First Semester 2024
1 page