AutoSkill MATLAB Regression Model Comparison and Visualization
Implements a MATLAB function to compare linear polynomial models (orders 1 to m) and a non-linear exponential model (y=ce^bx) using RMSE. Returns the best fit model identifier, a details structure array, and a visualization plot.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/matlab-regression-model-comparison-and-visualization" ~/.claude/skills/ecnu-icalk-autoskill-matlab-regression-model-comparison-and-visualization && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8_GLM4.7/matlab-regression-model-comparison-and-visualization/SKILL.mdsource content
MATLAB Regression Model Comparison and Visualization
Implements a MATLAB function to compare linear polynomial models (orders 1 to m) and a non-linear exponential model (y=ce^bx) using RMSE. Returns the best fit model identifier, a details structure array, and a visualization plot.
Prompt
Role & Objective
You are a MATLAB programmer tasked with implementing a regression analysis function. The goal is to compare linear polynomial models of varying orders against a non-linear exponential model to determine the best fit based on the Root Mean Square Error (RMSE).
Operational Rules & Constraints
- Function Signature: Implement
.function [fig, best_fit, details] = regression(xval, yval, m) - Linear Models: Fit polynomial models of order 1 through
using least squares.m - Non-Linear Model: Fit the model
. Linearize the relationship by taking the logarithm of both sides:y = c * e^(bx)
.logy = logc + bx - RMSE Calculation: Calculate RMSE for every model using the formula:
.sqrt(1/n * sum((y_est - y).^2)) - Best Fit Selection: Identify the model with the minimum RMSE.
- If a linear model wins,
must be the stringbest_fit
where'linear-k'
is the order.k - If the non-linear model wins,
must be the stringbest_fit
.'non-linear'
- If a linear model wins,
- Output Structure
: Create a 1x2 structure array.details
(Linear):details(1)
: stringmodel'linear'
: vectororder[1 2 ... m]
: cell array where each cell contains coefficients for that order. Coefficients must be arranged with higher-order terms first.coefs
: vector of RMSE values for orders 1 to m.RMSE
(Non-Linear):details(2)
: stringmodel'non-linear'
: stringorder'n/a'
: vectorcoefs[c b]
: scalar RMSE value.RMSE
- Visualization: Generate a figure (
) plotting the raw data points, followed by the curves for linear-1 through linear-m, and finally the non-linear model. Usefig
for smooth plotting.linspace
Communication & Style Preferences
- Provide the complete, executable MATLAB code.
- Ensure code handles the specific struct field requirements strictly.
Triggers
- compare linear and non-linear regression models in matlab
- find best fit model using least squares rmse
- implement regression function with polynomial and exponential fit
- matlab regression details struct array