MATLAB Answers

Prediction response of single data points

2 views (last 30 days)
Eugen Romanenkov
Eugen Romanenkov on 14 Nov 2019
Answered: Shrinidhi KR on 5 May 2020
I trained four different machine learning models. The discriminant analysis, decision tree, svm and the kNN-model. When I predict my data packagewise its prediction response is correct but when I'm predicting them data point by data point it only responses noise class.
Is there a reason why I cannot predict the class of each datapoint pointwise?

  0 Comments

Sign in to comment.

Answers (1)

Shrinidhi KR
Shrinidhi KR on 5 May 2020
You can predict the the class of individual datapoints.
I would suggest to look into Classification Learner and how to export the trained model to MATLAB workspace which can be used to make predictions on new data. This following documentation highlights how it can be done: https://www.mathworks.com/help/stats/export-classification-model-for-use-with-new-data.html
The important point to remember here is to keep in mind the way you pass the new datapoint to the model for prediction. Again as mentioned in the documentation link, the new sent of poinst should have same feature names, datatypes and also need to be passed in the same format as it was passed during training the model.
For example, if the dataset is loaded for a CSV file and imported into a table for traning the model, then individual datapoints are also to be put into table and passed in the same format. Below is an example of iris data and how it can be done using table to show predictions for individual datapoint:
sepallength = [5.1];
sepalwidth = [3.5];
petallength = [1.4];
petalwidth = [0.2];
T = table(sepallength,sepalwidth,petallength,petalwidth);
prediction = trainedModel.predictFcn(T);
This documentation links gives deatils about how to create tables and use them: https://www.mathworks.com/help/matlab/matlab_prog/create-a-table.html
You can also loop through the dataset and pass individual datapoints for prediction as per the required format for the model.
I hope this works for you.

  0 Comments

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!