How to Split test and training set

30 ビュー (過去 30 日間)
UTHOWAIPRU CHOWDHURY BAICHING
UTHOWAIPRU CHOWDHURY BAICHING 2022 年 6 月 22 日
I am stuck on how split train and test data correctly.
XTrain = readtable("urbanGB.csv");
YTrain = readtable("urbanGB.labels.csv");

採用された回答

Garmit Pant
Garmit Pant 2022 年 6 月 23 日
Hello Uthowaipru
It is my understanding that you have data in the form of CSV files that you wish to load and split into train and test subsets.
You can use the 'cvpartition' function of the Statistics and Machine Learning Toolbox to do the same.
You'll can use the following code snippet to divide your data into training and test subsets.
XTrain = readtable("urbanGB.csv");
YTrain = readtable("urbanGB.labels.csv");
XTrain.Y = table2cell(YTrain); %assuming YTrain to be a single column
rng('default') % For reproducibility
n = length(XTrain.Y);
hpartition = cvpartition(n,'Holdout',0.3); % Nonstratified partition
idxTrain = training(hpartition);
tblTrain = tbl(idxTrain,:);
idxTest = test(hpartition);
tblTest = tbl(idxNew,:);
You can refer to the documentation of cvpartition for more details: cvpartition
  1 件のコメント
UTHOWAIPRU CHOWDHURY BAICHING
UTHOWAIPRU CHOWDHURY BAICHING 2022 年 6 月 26 日
Thank you very much, Garmit

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeModel Building and Assessment についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by