필터 지우기
필터 지우기

how to do cross-validation without built-in function in excel data

조회 수: 2 (최근 30일)
Chandini Govind
Chandini Govind 2019년 9월 19일
댓글: Saket Chirania 2020년 6월 3일
i am studying about different classifires and i like to know how to do cross-validation without built-in function.i am using iris dataset for practise?
  댓글 수: 1
Saket Chirania
Saket Chirania 2020년 6월 3일
There is inbuild function named, crossvalind, which helps to perform diffrent cross validation methods such as Kfold, HoldOut, etc.
However, you can import your data to the MATLAB workspace using readmatrix function from the excel data.
Consider, you want to perform 5 cross folds.
  • 1st fold : 1 2 for test, 3:10 for train
  • 2nd fold : 3 4 for test, 1 2 5:10 for train
  • 3rd fold : 5 6 for test, 1:4 7:10 for train
  • 4th fold : 7 8 for test, 1:6 9:10 for train
  • 5th fold : 9 10 for test, 1:8 for train
Following code is an example for this process:
data = readmatrix('IrisData.xls');
dataRowNumber = size(data,1);
labels= rand(dataRowNumber,1) > 0.5;
randomColumn = rand(dataRowNumber,1);
X = [ randomColumn data labels];
SortedData = sort(X,1);
crossValidationFolds = 5;
numberOfRowsPerFold = dataRowNumber / crossValidationFolds;
crossValidationTrainData = [];
crossValidationTestData = [];
for startOfRow = 1:numberOfRowsPerFold:dataRowNumber
testRows = startOfRow:startOfRow+numberOfRowsPerFold-1;
if (startOfRow == 1)
trainRows = [max(testRows)+1:dataRowNumber];
else
trainRows = [1:startOfRow-1 max(testRows)+1:dataRowNumber];
end
crossValidationTrainData = [crossValidationTrainData ; SortedData(trainRows ,:)];
crossValidationTestData = [crossValidationTestData ;SortedData(testRows ,:)];
end

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by