% === Load Leukemia Dataset === data = readtable('leukemia.xlsx'); X = table2array(data(:, 1:end-1)); y = table2array(data(:, end)); % === Normalize Features === X = normalize(X); % === Binarize Labels for Multi-Class ROC === classes = unique(y); nClasses = length(classes); y_bin = zeros(length(y), nClasses); for i = 1:nClasses y_bin(:, i) = (y == classes(i)); end % === Split into Train/Test === cv = cvpartition(y, 'HoldOut', 0.3); X_train = X(training(cv), :); X_test = X(test(cv), :); y_train = y(training(cv)); y_test = y(test(cv)); y_bin_test = y_bin(test(cv), :); % === Train SVM Model === svmModel = fitcecoc(X_train, y_train, ... 'Learners', templateSVM('KernelFunction','rbf','Standardize',true), ... 'Coding','onevsall'); % === Predict and Score === [y_pred, scores] = predict(svmModel, X_test); % === F1 Score (Weighted) === f1 = f1score(y_test, y_pred); % Custom function below fprintf('Leukemia Dataset - F1 Score: %.2f\n', f1); % === ROC and AUC Plot === colors = {'r', 'b', 'g'}; figure; hold on; for i = 1:nClasses [Xroc, Yroc, ~, AUC] = perfcurve(y_bin_test(:, i), scores(:, i), 1); plot(Xroc, Yroc, 'Color', colors{i}, 'LineWidth', 2, ... 'DisplayName', sprintf('Class %d (AUC = %.2f)', i-1, AUC)); end % === Plot Formatting === plot([0 1], [0 1], 'k--', 'LineWidth', 1); legend('Location', 'southeast', 'FontSize', 14); xlabel('False Positive Rate', 'FontSize', 12); ylabel('True Positive Rate', 'FontSize', 12); title(sprintf('AUC analysis for Proposed model (F1 = %.2f)', f1), 'FontSize', 14); axis([0 1 0 1.05]); grid on; saveas(gcf, 'AUC_Leukemia_Proposed.png'); function f1 = f1score(y_true, y_pred) classes = unique(y_true); f1s = zeros(length(classes),1); for i = 1:length(classes) c = classes(i); tp = sum((y_pred == c) & (y_true == c)); fp = sum((y_pred == c) & (y_true ~= c)); fn = sum((y_pred ~= c) & (y_true == c)); precision = tp / (tp + fp + eps); recall = tp / (tp + fn + eps); f1s(i) = 2 * (precision * recall) / (precision + recall + eps); end support = histcounts(y_true, [classes; max(classes)+1]); f1 = sum(f1s .* support') / sum(support); end
An Error occurred while handling another error:
yii\web\HeadersAlreadySentException: Headers already sent in  on line 0. in /var/www/html/prof-homepages/vendor/yiisoft/yii2/web/Response.php:366
Stack trace:
#0 /var/www/html/prof-homepages/vendor/yiisoft/yii2/web/Response.php(339): yii\web\Response->sendHeaders()
#1 /var/www/html/prof-homepages/vendor/yiisoft/yii2/web/ErrorHandler.php(136): yii\web\Response->send()
#2 /var/www/html/prof-homepages/vendor/yiisoft/yii2/base/ErrorHandler.php(135): yii\web\ErrorHandler->renderException()
#3 [internal function]: yii\base\ErrorHandler->handleException()
#4 {main}
Previous exception:
yii\web\HeadersAlreadySentException: Headers already sent in  on line 0. in /var/www/html/prof-homepages/vendor/yiisoft/yii2/web/Response.php:366
Stack trace:
#0 /var/www/html/prof-homepages/vendor/yiisoft/yii2/web/Response.php(339): yii\web\Response->sendHeaders()
#1 /var/www/html/prof-homepages/vendor/yiisoft/yii2/base/Application.php(656): yii\web\Response->send()
#2 /var/www/html/prof-homepages/vendor/faravaghi/yii2-filemanager/models/Files.php(696): yii\base\Application->end()
#3 /var/www/html/prof-homepages/vendor/faravaghi/yii2-filemanager/controllers/FilesController.php(484): faravaghi\filemanager\models\Files->getFile()
#4 [internal function]: faravaghi\filemanager\controllers\FilesController->actionGetFile()
#5 /var/www/html/prof-homepages/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#6 /var/www/html/prof-homepages/vendor/yiisoft/yii2/base/Controller.php(180): yii\base\InlineAction->runWithParams()
#7 /var/www/html/prof-homepages/vendor/yiisoft/yii2/base/Module.php(528): yii\base\Controller->runAction()
#8 /var/www/html/prof-homepages/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction()
#9 /var/www/html/prof-homepages/vendor/yiisoft/yii2/base/Application.php(386): yii\web\Application->handleRequest()
#10 /var/www/html/prof-homepages/backend/web/index.php(16): yii\base\Application->run()
#11 {main}