⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dtreegui.m

📁 具有图形操作界面的支持向量机多类分类实验系统.全部用Matlab实现,可以实现多种分类识别. 这是本人的毕业设计的附属程序
💻 M
字号:
function varargout = DtreeGUI(varargin)
% DTREEGUI M-file for DtreeGUI.fig
%      DTREEGUI, by itself, creates a new DTREEGUI or raises the existing
%      singleton*.
%
%      H = DTREEGUI returns the handle to a new DTREEGUI or the handle to
%      the existing singleton*.
%
%      DTREEGUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in DTREEGUI.M with the given input arguments.
%
%      DTREEGUI('Property','Value',...) creates a new DTREEGUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before DtreeGUI_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to DtreeGUI_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Copyright 2002-2003 The MathWorks, Inc.

% Edit the above text to modify the response to help DtreeGUI

% Last Modified by GUIDE v2.5 11-Jun-2005 17:33:41

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @DtreeGUI_OpeningFcn, ...
                   'gui_OutputFcn',  @DtreeGUI_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before DtreeGUI is made visible.
function DtreeGUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to DtreeGUI (see VARARGIN)

% Choose default command line output for DtreeGUI
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes DtreeGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = DtreeGUI_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;



function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double


% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
helpwin(mfilename)


% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
cla;
DetreeExp1_8;

global Text1 Text2 Text
T1='plot(ntermnodes,cost,''b-'', ntermnodes,resubcost,''r--'')'
T2='figure(gcf);'
T3='[mincost,minloc] = min(cost)'
T4='cutoff = mincost + secost(minloc)'
T5='plot(ntermnodes(bestlevel+1), cost(bestlevel+1), ''mo'')'
Text1 = strvcat(T1,T2,T3,T4,T5);
set(handles.edit2,'String',Text1);

T6='cost用直线表示 resucost用续线表示'
T7='显示离散值'
T8='  把min(cost) 得出cost列变量中的最小值赋给mincost变量,cost列变量中的最小值的索引号赋给minloc变量'
T9='cutoff为截止值'
T10='最佳叶结点数用圆圈圈出'
Text2 = strvcat(T6,T7,T8,T9,T10);
set(handles.edit1,'String',Text2);
Text= strvcat(Text1,Text2) ;
set(handles.edit3,'String','最佳叶结点数=5');

% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
cla;
DetreeExp1_4;

global Text1 Text2 Text3;
T1='tree = treefit(meas(:,1:2), species)'
T2='[dtnum,dtnode,dtclass] = treeval(tree, meas(:,1:2))'
T3='bad_d = ~strcmp(dtclass,species);'
T4='sum(bad_d) / numobs'
T5='gscatter(x,y,grpname,''grb'',''sod'')'
T0='plot(meas(bad_d,1), meas(bad_d,2), ''kx'')'
Text1 = strvcat(T1,T2,T3,T4,T5,T0);
set(handles.edit2,'String',Text1);

T6='Treefit函数能为数据集找到适合的决策树。'
T7='treeval计算决策树的代价'
T8='计算决策树分类误差'
T9='ans=0.1333'
T10='创建含有x轴,y轴的栅格图来显示决策树分类区域'
T11='错误分类的样本用x表示'
Text2 = strvcat(T6,T7,T8,T9,T10,T11);
set(handles.edit1,'String',Text2);

T12='决策树分类'
T13='错误比例=13.3%'
Text3=strvcat(T12,T13);
set(handles.edit3,'String',Text3);

% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
DetreeExp1_6;
global Text1 Text2 Text
T1='treedisp(tree,''name'',{''萼片长度'' ''萼片宽度''})'
set(handles.edit2,'String',T1);

T2='用树状结构显示决策树分类'
set(handles.edit1,'String',T2);

% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
cla;
DetreeExp1_7;

global Text1 Text2 Text
T1='resubcost = treetest(tree,''resub'')'
T2='[cost,secost,ntermnodes,bestlevel] = treetest(tree,''cross'',meas(:,1:2),species);'
T3='plot(ntermnodes,cost,''b-'', ntermnodes,resubcost,''r--'');'
T4='figure(gcf)'
Text1 = strvcat(T1,T2,T3,T4);
set(handles.edit2,'String',Text1);

T6='运用回代方法计算代价。'
T7='返回secost变量'

T8='secost变量含有每个代价的标准误差'
T9='其中cost变量为交叉确认得到的代价'

T10='cost用直线表示 resucost用虚线表示'
T11='显示离散值'
Text2 = strvcat(T6,T7,T8,T9,T10,T11);
set(handles.edit1,'String',Text2);
Text= strvcat(Text1,Text2) ;

% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

DetreeExp1_9;

global Text1 Text2 Text
T1='prunedtree = treeprune(tree,bestlevel);'
T3='treedisp(prunedtree,''name'',{''萼片长度'', ''萼片宽度''})'
Text1= strvcat(T1,T3);
set(handles.edit2,'String',Text1);

T2='对原始决策树进行剪枝,剪枝以后的树结构赋给prunedtree变量。因为bestlevel=4所以得到四层的决策树'
T4='用决策树显示器显示剪枝以后的树'
Text2=strvcat(T2,T4);
T5='5'
set(handles.edit1,'String',Text2);
set(handles.edit3,'String',T5);


% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)

global  Text5
axes(handles.axes1);
popup_sel_index1 = get(handles.popupmenu1, 'Value');
switch popup_sel_index1 
    case 1 %         axis on    ;
        Text5='axis on ';
    case 2 %         axis off ;
        Text5='axis off ';
    case 3 %         axis ij;   
       Text5='axis ij '; 
    case 4 %         axis xy;  
       Text5='axis xy';  
end
eval(Text5);
set(handles.edit2,'String',Text5);

% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end




% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
close(gcf);





function edit3_Callback(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit3 as text
%        str2double(get(hObject,'String')) returns contents of edit3 as a double


% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end




% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -