Non-Linear Models to Data
显示 更早的评论
I have made a Linear model for my data using this code, I can't figure out how to create a non linear regression model which predicts the compressive strength of concrete based on its composition and age, how do I do this?:
% Load data from the file
data = readmatrix('Concrete_Data.xls');
% Define predictor variables and response variable
predictors = data(:, 1:end-1);
response = data(:, end);
% Create a random partition of the data into 70% training data and 30% testing data
rng(1); % Set the random number generator seed for reproducibility
cv = cvpartition(length(data), 'HoldOut', 0.3);
% Split the data into training and testing sets using the partition indices
training_data = data(cv.training,:);
testing_data = data(cv.test,:);
% Create a linear regression model using the training data
model = fitlm(training_data(:,1:end-1), training_data(:,end));
disp(model)
% Displaying of the graph
figure;
plot(model)
% Calculate the R-squared score of the model using the testing data
y_pred = predict(model, testing_data(:,1:end-1));
R2 = 1 - sum((testing_data(:,end) - y_pred).^2) / sum((testing_data(:,end) - mean(testing_data(:,end))).^2);
% Output the results to the command window
fprintf('R-squared score obtained with the linear model using %d variables: %.2f\n', size(predictors, 2), R2);
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Linear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!