필터 지우기
필터 지우기

extract predictor and reponse as an array format from ML App.

조회 수: 1 (최근 30일)
amr sayed
amr sayed 2024년 1월 22일
편집: Drew 2024년 1월 22일
Dear all,
i am new in ML apllication. i used Linear regression app to traim my model. after running the app. it give me the following image.
my problem is how to extract the output figure as an array (x,y) or (record number, response) .
I tried to save the output in workspace but i found it as structure format with a lot of data (TrainedModel)

채택된 답변

Drew
Drew 2024년 1월 22일
편집: Drew 2024년 1월 22일
The Response Plot data can be extracted as an array by using the Regression Learner toolstrip option "Export Plot to Figure", and then using handle graphics to obtain the array.
Steps:
(1) With the response plot in focus, choose "Export Plot to Figure"
(2) With the exported "Response Plot" figure in focus, run "h = gca;" at the MATLAB command line.
(3) At this point the data is available in the children of the axes, as in the example below.
Here is an example using fisher iris data:
%% These steps were run earlier, to create the handle to axes
% (1) t=readtable("fisheriris.csv")
% (2) Start regressionLearner
% (3) Create New session with SepalLength as the response. Use other
% variables as predictors. Accept the default 5-fold cross validation
% (4) Build model or models of your choice.
% (5) Put a Response Plot in focus. From the toolstrip, choose "Export Plot to Figure"
% (6) Next, run "h = gca;" to get a handle to the current axes,
% which should be the Response Plot figure
% Instead of h = gca, load a handle "h" from the attached .mat file. This
% handle "h" was obtained from a response plot that was exported from
% Regression Learner using the procedure listed above
load handle_to_response_plot.mat
% Take a look at the names
h.Children
ans =
2×1 Line array: Line (MLearnAppTracePlotPredictionsTrace) Line (MLearnAppTracePlotTrainingDataTrace)
% Just FYI these are the data locations
h.Children(1).XData; % record numbers
h.Children(1).YData; % Predictions
h.Children(2).XData; % record numbers
h.Children(2).YData; % True values (same as training data)
% Recreate the Response Plot
% Plot the "True" data
scatter(h.Children(2).XData,h.Children(2).YData,[],h.Children(2).Color,'filled')
% Make the axes limits of the re-created graph the same as in the original
% exported from Regression Learner
hlocal=gca;
set(hlocal,"XLim",h.XLim);
set(hlocal,"YLim",h.YLim);
% Plot the "Predictions"
hold on;
scatter(h.Children(1).XData,h.Children(1).YData,[],h.Children(1).Color,'filled')
legend('True','Predictions')
legend('Location','northeastoutside');
If this answer helps you, please remember to accept the answer.
For more about exporting from Regression Learner, including exporting models and exporting a function to re-create models with new data, https://www.mathworks.com/help/stats/export-regression-model-to-predict-new-data.html

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by