O’ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA KOMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI
Muhammad Al-Xorazmiy nomidagi Toshkent axborot texnologiyalari universiteti Samarqand filiali
AMALIY ISHI_5
Mavzu: Iris gulini turlar bo’yicha tadqiq etish
Bajardi : Avalov Azizbek
Tekshirdi : Axrorov M.
Samarqand -2022
Mavzu: Iris gulini turlar bo’yicha tadqiq etish
fishertable= readtable('fisheriris.csv') funksiyasini matlab oynasiga kiritib olamiz va enter tugmasini bosamiz
Ko’rib turganingizdek bizda quyidagi 150x5 matritsa hosil jadvali hosil bo’ladi.Bu jadvalda “Iris” gulining 3 ta tur bo’yicha sinflanishi keltirilgan bular “setosa” “virginica” va “versicolor”
Endi APPS bo’limiga o’tib Classification Leaner ni tanlaymiz
From workpace ni bosib qiymatlarni chaqirib olamiz va hosil bo’lgan oynadan Start Session ni bosamiz
Ko’rib turganingizdek bizda Iris gulining 3ta turi 96.7% aniqlikda sinflarga ajratildi
Confusion Matrixni bosamiz quyidagi jadval vujudga keladi bunda Setosa 48%, Versicolor 43%, Virginica 44% aniqlikda sinflangan
Parellel kordinatalar Grafigi ko’rinishi
Dasturning kodi:
function [trainedClassifier, validationAccuracy] = trainClassifier(trainingData)
% [trainedClassifier, validationAccuracy] = trainClassifier(trainingData)
% Returns a trained classifier and its accuracy. This code recreates the
% classification model trained in Classification Learner app. Use the
% generated code to automate training the same model with new data, or to
% learn how to programmatically train models.
%
% Input:
% trainingData: A table containing the same predictor and response
% columns as those imported into the app.
%
% Output:
% trainedClassifier: A struct containing the trained classifier. The
% struct contains various fields with information about the trained
% classifier.
%
% trainedClassifier.predictFcn: A function to make predictions on new
% data.
%
% validationAccuracy: A double containing the accuracy as a
% percentage. In the app, the Models pane displays this overall
% accuracy score for each model.
%
% Use the code to train the model with new data. To retrain your
% classifier, call the function from the command line with your original
% data or new data as the input argument trainingData.
%
% For example, to retrain a classifier trained with the original data set
% T, enter:
% [trainedClassifier, validationAccuracy] = trainClassifier(T)
%
% To make predictions with the returned 'trainedClassifier' on new data T2,
% use
% yfit = trainedClassifier.predictFcn(T2)
%
% T2 must be a table containing at least the same predictor columns as used
% during training. For details, enter:
% trainedClassifier.HowToPredict
% Auto-generated by MATLAB on 18-May-2022 10:50:53
% Extract predictors and response
% This code processes the data into the right shape for training the
% model.
inputTable = trainingData;
predictorNames = {'SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth'};
predictors = inputTable(:, predictorNames);
response = inputTable.Species;
isCategoricalPredictor = [false, false, false, false];
% Train a classifier
% This code specifies all the classifier options and trains the classifier.
classificationTree = fitctree(...
predictors, ...
response, ...
'SplitCriterion', 'gdi', ...
'MaxNumSplits', 100, ...
'Surrogate', 'off', ...
'ClassNames', {'setosa'; 'versicolor'; 'virginica'});
% Create the result struct with predict function
predictorExtractionFcn = @(t) t(:, predictorNames);
treePredictFcn = @(x) predict(classificationTree, x);
trainedClassifier.predictFcn = @(x) treePredictFcn(predictorExtractionFcn(x));
% Add additional fields to the result struct
trainedClassifier.RequiredVariables = {'PetalLength', 'PetalWidth', 'SepalLength', 'SepalWidth'};
trainedClassifier.ClassificationTree = classificationTree;
trainedClassifier.About = 'This struct is a trained model exported from Classification Learner R2022a.';
trainedClassifier.HowToPredict = sprintf('To make predictions on a new table, T, use: \n yfit = c.predictFcn(T) \nreplacing ''c'' with the name of the variable that is this struct, e.g. ''trainedModel''. \n \nThe table, T, must contain the variables returned by: \n c.RequiredVariables \nVariable formats (e.g. matrix/vector, datatype) must match the original training data. \nAdditional variables are ignored. \n \nFor more information, see How to predict using an exported model.');
% Extract predictors and response
% This code processes the data into the right shape for training the
% model.
inputTable = trainingData;
predictorNames = {'SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth'};
predictors = inputTable(:, predictorNames);
response = inputTable.Species;
isCategoricalPredictor = [false, false, false, false];
% Perform cross-validation
Dostları ilə paylaş: |