📄 dtreegui2.m
字号:
function varargout = DtreeGUI2(varargin)
% DTREEGUI2 M-file for DtreeGUI2.fig
% DTREEGUI2, by itself, creates a new DTREEGUI2 or raises the existing
% singleton*.
%
% H = DTREEGUI2 returns the handle to a new DTREEGUI2 or the handle to
% the existing singleton*.
%
% DTREEGUI2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in DTREEGUI2.M with the given input arguments.
%
% DTREEGUI2('Property','Value',...) creates a new DTREEGUI2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before DtreeGUI2_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to DtreeGUI2_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 DtreeGUI2
% Last Modified by GUIDE v2.5 23-May-2006 15:15:00
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @DtreeGUI2_OpeningFcn, ...
'gui_OutputFcn', @DtreeGUI2_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 DtreeGUI2 is made visible.
function DtreeGUI2_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 DtreeGUI2 (see VARARGIN)
% Choose default command line output for DtreeGUI2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes DtreeGUI2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = DtreeGUI2_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;
DetreeExp2_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','最佳叶结点数=7');
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
cla;
DetreeExp2_4
global Text1 Text2 Text
T1='tree = treefit(WM(:,1:2), species)'
T2='[dtnum,dtnode,dtclass] = treeval(tree, WM(:,1:2))'
T3='bad_d = ~strcmp(dtclass,species);'
T4='sum(bad_d) / numobs'
T5='gscatter(x,y,grpname,''grb'',''sod'')'
T0='plot(WM(bad_d,1), WM(bad_d,2), ''kx'')'
Text1 = strvcat(T1,T2,T3,T4,T5,T0);
set(handles.edit2,'String',Text1);
T6='Treefit函数能为数据集找到适合的决策树。'
T7='treeval计算决策树的代价'
T8='计算决策树分类误差ans=0.09'
T9='可见分类误差仅有9%'
T10='创建含有x轴,y轴的栅格图来显示决策树分类区域'
T11='错误分类的样本用x表示'
Text2 = strvcat(T6,T7,T8,T9,T10,T11);
set(handles.edit1,'String',Text2);
Text= strvcat(Text1,Text2) ;
T12='决策树分类'
T13='错误比例=9%'
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)
DetreeExp2_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;
DetreeExp2_7;
global Text1 Text2 Text
T1='resubcost = treetest(tree,''resub'')'
T2='[cost,secost,ntermnodes,bestlevel] = treetest(tree,''cross'',WM(:,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)
DetreeExp2_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=7所以得到有七个叶结点的决策树'
T4='用决策树显示器显示剪枝以后的树'
Text2=strvcat(T2,T4);
set(handles.edit1,'String',Text2);
% --- 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -