I understand that the task at hand is to classify a given set of 10 (x, y) pairs into one of three categories: linear, parabolic, or exponential. Here is the workflow using MATLAB:
Step 1: Feature Engineering
- Slope Features: Calculate slopes between consecutive points. For linear functions, slopes should be relatively constant; for quadratic functions, they should increase or decrease linearly; for exponential functions, the rate of change will be more variable and potentially higher.
- Y value Ratios: Calculate the ratio of consecutive y values (y[i+1]/y[i]). These ratios might be nearly constant for exponential functions, but not for linear or quadratic functions.
- Curve Fitting errors: Fit each set of (x,y) pairs with linear, parabolic, and exponential models and calculate the fit error (e.g., R2 score, mean squared error). The model with the lowest error indicates the function type. The Curve Fitting Toolbox (cftool) can be used like below for fitting each function type:
[fitLin, gofLin] = fit(x, y, 'poly1'); //Linear fit
[fitQuad, gofQuad] = fit(x, y, 'poly2'); // Parabolic fit
[fitExp, gofExp] = fit(x, y, 'exp1'); // exponential fit
Here, “gofLin”, “gofQuad” and “gofExp” contain goodness-of-fit” statistics, including the R-squared value (“gofLin.rsquare”), which can be used as features.
4. Statistical Features: Calculate statistical features like the mean, variance, skewness, and kurtosis of both x and y values, as they might reveal the distribution and spread of data points indicative of the underlying function, using the Statistics and Machine Learning Toolbox in MATLAB.
Step 2: Model Selection:
MATLAB’s Statistics and Machine Learning Toolbox provides various algorithms for classification. Some of these are:
- “fitctree” for Decision trees
- “TreeBagger” for Random Forests.
- “fitcsvm” for SVM
Step 3: Preparing the Dataset:
- Label each set of (x,y) pairs according to their function type.
- Divide the dataset into training and testing sets. A common split is 80% for training and 20% for testing.
Step 4: Training the model:
Train the model using the chosen model and the training dataset in Steps 2 and 3.
Step 5: Model Evaluation:
The accuracy, F1 score, and confusion matrix (using “confusionmat”) are calculated using MATLAB functions to evaluate the model’s performance.
Step 6: Prediction:
With this trained model, you can now predict the function type of new sets of (x,y) pairs.
You may refer to the following documentation links for more information:
Hope it helps!