Support Vector Machines
Support Vector Machines using If
Example 1
Summary: Runs a Support Vector Machines analysis in JMP Pro, specifying the response variable and predictors, and extracting model summary tables.
Code:
If( JMP Product Name() == "Pro",
dt2 = Open("data_table.jmp");
SVM_LDF1 = dt2 << Support Vector Machines(
Y( :Survived ),
X( :Age, :Cabin ),
Fit(
Kernel Function( "Radial Basis Function" ),
Gamma( 0.5 ),
Cost( 1 ),
Validation Method( "None" ),
Response Profile Plot( 0 ),
Plot Actual by Predicted( 0 ),
Confusion Matrix( 0.98857734377105 )
)
);
SVMTable = Report( SVM_LDF1 )[Outline Box( "Support Vector Machine" )][Outline Box( "Support Vector Machine Model 1" )][
Outline Box( "Model Summary" )][Table Box( 2 )] << Make Into Data Table;
vals = SVMTable << Get as matrix;
SVM_LDF1 << Local Data Filter(
Add Filter( columns( :Passenger Class, :Sex ), Where( :Passenger Class == 2 ), Where( :Sex == "female" ) )
);
text1 = (Report( SVM_LDF1 ) << Parent)[Outline Box( 1 )][Text Box( 1 )] << Get Text;
Close( dt2, nosave );
Close( SVMTable, nosave );
);
Code Explanation:
- Check if JMP is Pro.
- Open data table;
- Run Support Vector Machines analysis.
- Specify response variable: Survived.
- Specify predictors: Age, Cabin.
- Set kernel function to Radial Basis Function.
- Set gamma to 0.5.
- Set cost to 1.
- Disable validation method.
- Disable plots and confusion matrix.
- Extract model summary table.
- Convert table to data table.
- Get table values as matrix.
- Add local data filter for Passenger Class 2 and Sex female.
- Retrieve text from report.
- Close datasets without saving.
Example 2
Summary: Executes a Support Vector Machines model in JMP Pro, utilizing the Radial Basis Function kernel and retrieving fit measures.
Code:
If( Contains( JMP Product Name(), "Pro" ) > 0,
dt = Open("data_table.jmp");
obj = dt << Support Vector Machines(
Y( :Y Binary ),
X( :Age, :Gender, :BMI, :BP, :Total Cholesterol, :LDL, :HDL, :TCH, :LTG ),
Validation( :Validation ),
Kernel Function( "Radial Basis Function" ),
Fit
);
actualmeasures = obj << (Fit[1] << Get Measures);
Close( dt, no save );
);
Code Explanation:
- Check if JMP Pro.
- Open data table;
- Run Support Vector Machines.
- Set Y variable.
- Set X variables.
- Use Validation column.
- Select Radial Basis Function.
- Perform model fit.
- Retrieve fit measures.
- Close dataset without saving.
Example 3
Summary: Process of training a Support Vector Machines model in JMP Pro, generating predicted probabilities and saving probability formulas.
Code:
If( Contains( JMP Product Name(), "Pro" ) > 0,
dt = Open("data_table.jmp");
obj = dt << Support Vector Machines(
Y( :BAD ),
X( :LOAN, :MORTDUE, :VALUE, :REASON, :JOB, :YOJ, :DEROG, :DELINQ, :CLAGE, :NINQ, :CLNO, :DEBTINC ),
Fit( Kernel Function( "Radial Basis Function" ), Gamma( 0.0833333333333333 ), Cost( 1 ), Validation Method( "None" ) )
);
rpt = obj << Report();
obj << (fit[1] << Save Probabilities);
obj << (fit[1] << Save Probability Formula);
probcols = dt[0, 15 :: 16];
mostlikelycol = dt[0, 17];
decisionvalform = dt[0, 18];
probforms = dt[0, 19 :: 20];
mostlikelyform = dt[0, 21];
threshpredform = dt[0, 22];
reportthreshprob = rpt[Outline Box( "Set Probability Threshold" )][Number Edit Box( 1 )] << get;
dt << New Column( "Threshold Check", Numeric, Nominal, Formula( If( :"Probability( BAD=Good Risk )"n > reportthreshprob, 0, 1 ) ) );
:Threshold Check << Value Labels( {0 = "Good Risk", 1 = "Bad Risk"} );
threshcheck = dt[0, 23];
index = Loc Nonmissing( probforms );
jindex = Loc Nonmissing( probcols );
obj << (fit[1] << Save Predicteds);
obj << (fit[1] << Save Prediction Formula);
predicteds = dt[0, 24];
predforms = dt[0, 25];
:Threshold Predicted BAD << Use Value Labels( 0 );
threshpredformnolabels = dt[0, 22];
decisiondatatype = dt:Decision Value << Get Data Type;
decisionmodeltype = dt:Decision Value << Get Modeling Type;
Close( dt, no save );
);
Code Explanation:
- Check if JMP Pro is installed.
- Open data table;
- Run Support Vector Machines model.
- Specify response and predictor variables.
- Set kernel function and parameters.
- Generate model report.
- Save predicted probabilities.
- Save probability formula.
- Identify probability columns.
- Close dataset without saving.
Summary: Runs Support Vector Machines analysis on a data table, generating a report with model comparison results and extracting key parameters.
Code:
dt = Open("data_table.jmp");
obj = dt << Support Vector Machines(
Y( :Species ),
X( :Sepal length, :Sepal width, :Petal length, :Petal width ),
Fit( Kernel Function( "Radial Basis Function" ), Gamma( -0.25 ), Cost( -1 ), Validation Method( "None" ) ),
Fit( Kernel Function( "Radial Basis Function" ), Gamma( . ), Cost( . ), Validation Method( "None" ) ),
Fit( Kernel Function( "Radial Basis Function" ), Gamma( -1 ), Cost( -2 ), Validation Method( "None" ) )
);
rpt = obj << Report();
actualMethod = rpt[Outline Box( "Model Comparison" )][String Col Box( "Method" )] << get;
actualKernel = rpt[Outline Box( "Model Comparison" )][String Col Box( "Kernel Function" )] << get;
actualCost = rpt[Outline Box( "Model Comparison" )][Number Col Box( "Cost" )] << get as matrix;
actualGamma = rpt[Outline Box( "Model Comparison" )][Number Col Box( "Gamma" )] << get as matrix;
actualNumofSVs = rpt[Outline Box( "Model Comparison" )][Number Col Box( "# SV" )] << get as matrix;
actualMisclassRate = rpt[Outline Box( "Model Comparison" )][Number Col Box( "Training Misclassification Rate" )] << get as matrix;
actualBest = rpt[Outline Box( "Model Comparison" )][String Col Box( "Best" )] << get;
Code Explanation:
- Open data table;
- Run Support Vector Machines analysis.
- Set first model parameters.
- Set second model parameters.
- Set third model parameters.
- Generate report from results.
- Extract method name.
- Extract kernel function.
- Extract cost values.
- Extract gamma values.