Naive Bayes
Example 1
Summary: Generates a Naive Bayes analysis to predict the 'Success' outcome based on patient variables, utilizing a profiler with initial conditions and term values.
Code:
Open("data_table.jmp") << Naive Bayes(
Y( :Success 1 ),
X(
Column Group( "Patient Variables" ),
:Family Present,
:Support Present,
:Counselor Present,
:Device Assisted,
:Shift,
:Expert RN,
:Mean Active Minutes,
:Mean Nurse Exp,
:Mean Nurse Comp,
:Mean Difficulty,
:Mean Cooperative,
:Mean Distress,
:Minutes 1,
:Nurse Exp 1,
:Nurse Comp 1,
:Difficulty 1,
:Cooperative 1,
:Distress 1
),
Profiler(
1,
Term Value(
Age( 5.262, Lock( 0 ), Show( 1 ) ),
Gender( 1, Lock( 0 ), Show( 1 ) ),
Weight( 24.75, Lock( 0 ), Show( 1 ) ),
Previous IV( 0, Lock( 0 ), Show( 1 ) ),
Lost IV( "0", Lock( 0 ), Show( 1 ) ),
Dehydrated( "No/Unknown", Lock( 0 ), Show( 1 ) ),
Family Present( 0, Lock( 0 ), Show( 1 ) ),
Support Present( 0, Lock( 0 ), Show( 1 ) ),
Counselor Present( 0, Lock( 0 ), Show( 1 ) ),
Device Assisted( 0.8446, Lock( 0 ), Show( 1 ) ),
Shift( 1, Lock( 0 ), Show( 1 ) ),
Expert RN( 0.0557, Lock( 0 ), Show( 1 ) ),
Mean Active Minutes( 5.706, Lock( 0 ), Show( 1 ) ),
Mean Nurse Exp( 5.585, Lock( 0 ), Show( 1 ) ),
Mean Nurse Comp( 3.1058, Lock( 0 ), Show( 1 ) ),
Mean Difficulty( 0.6416, Lock( 0 ), Show( 1 ) ),
Mean Cooperative( 0.5241, Lock( 0 ), Show( 1 ) ),
Mean Distress( 5.062, Lock( 0 ), Show( 1 ) ),
Minutes 1( 5.75, Lock( 0 ), Show( 1 ) ),
Nurse Exp 1( 2.2566, Lock( 0 ), Show( 1 ) ),
Nurse Comp 1( 2.9069, Lock( 0 ), Show( 1 ) ),
Difficulty 1( 0.3022, Lock( 0 ), Show( 1 ) ),
Cooperative 1( 0.5332, Lock( 0 ), Show( 1 ) ),
Distress 1( 5.115, Lock( 0 ), Show( 1 ) )
)
)
);
Code Explanation:
- Open data table;
- Run Naive Bayes analysis.
- Set response variable.
- Define predictor variables.
- Create profiler.
- Set initial conditions.
- Configure term values.
- Display all terms.
- Unlock all terms.
- Show all terms.
Example 2
Summary: Generates a Naive Bayes analysis to predict Thread Wear based on Method, Size of Load, Sand blasted?, and Starch Content variables, with Profiler settings configured for Alpha Amalyze method.
Code:
Open("data_table.jmp") << Naive Bayes(
Y( :Thread Wear ),
X( :Method, :"Size of Load (lbs)"n, :Sand blasted?, :"Starch Content (%)"n ),
Profiler(
1,
Term Value(
Method( "Alpha Amalyze",
Lock( 0 ),
Show( 1 )
),
"Size of Load (lbs)"n( 182.26, Lock( 0 ), Show( 1 ) ),
Sand blasted?( "no", Lock( 0 ), Show( 1 ) ),
"Starch Content (%)"n( 25.517, Lock( 0 ), Show( 1 ) )
)
)
);
Code Explanation:
- Open data_table data
- Run Naive Bayes analysis.
- Set Y variable: Thread Wear.
- Set X variables: Method, Size of Load, Sand blasted?, Starch Content.
- Launch Profiler.
- Configure Profiler settings.
- Set Method to Alpha Amalyze.
- Unlock Method parameter.
- Display Method parameter.
- Set Size of Load to 182.26 lbs.
Example 3
Summary: Generates a Naive Bayes analysis on the provided data table, specifying predictor variables and configuring Profiler settings to analyze the relationship between Age, Gender, BMI, BP, Total Cholesterol, LDL, HDL, TCH, LTG, and Glucose.
Code:
dt = Open("data_table.jmp");
obj = dt << Naive Bayes(
Y( :Y Binary ),
X( :Age, :Gender, :BMI, :BP, :Total Cholesterol, :LDL, :HDL, :TCH, :LTG, :Glucose ),
Profiler(
1,
Term Value(
Age( 48.518, Lock( 0 ), Show( 1 ) ),
Gender( 1, Lock( 0 ), Show( 1 ) ),
BMI( 30.75, Lock( 0 ), Show( 1 ) ),
BP( 94.647, Lock( 0 ), Show( 1 ) ),
Total Cholesterol( 257.5, Lock( 0 ), Show( 1 ) ),
LDL( 115.44, Lock( 0 ), Show( 1 ) ),
HDL( 49.788, Lock( 0 ), Show( 1 ) ),
TCH( 4.0702, Lock( 0 ), Show( 1 ) ),
LTG( 4.6414, Lock( 0 ), Show( 1 ) ),
Glucose( 91.26, Lock( 0 ), Show( 1 ) )
)
)
);
Code Explanation:
- Open data table;
- Run Naive Bayes analysis.
- Set response variable.
- Specify predictor variables.
- Enable Profiler.
- Configure Profiler settings.
- Set Age term value.
- Set Gender term value.
- Set BMI term value.
- Set BP term value.
Example 4
Summary: Generates a Naive Bayes model to predict the 'BAD' response variable using multiple predictors from an open data table, with profiler configuration and term value specification.
Code:
Open("data_table.jmp") << Naive Bayes(
Validation( :Validation ),
Y( :BAD ),
X( :LOAN, :MORTDUE, :VALUE, :REASON, :JOB, :YOJ, :DEROG, :DELINQ, :CLAGE, :NINQ, :CLNO ),
Profiler(
1,
Term Value(
LOAN( 18608, Lock( 0 ), Show( 1 ) ),
MORTDUE( 73760, Lock( 0 ), Show( 1 ) ),
VALUE( 101780, Lock( 0 ), Show( 1 ) ),
REASON( "DebtCon", Lock( 0 ), Show( 1 ) ),
JOB( "Mgr", Lock( 0 ), Show( 1 ) ),
YOJ( 8.922, Lock( 0 ), Show( 1 ) ),
DEROG( 0.255, Lock( 0 ), Show( 1 ) ),
DELINQ( 0.449, Lock( 0 ), Show( 1 ) ),
CLAGE( 179.8, Lock( 0 ), Show( 1 ) ),
NINQ( 1.186, Lock( 0 ), Show( 1 ) ),
CLNO( 21.296, Lock( 0 ), Show( 1 ) )
)
)
);
Code Explanation:
- Open data table;
- Apply Naive Bayes model.
- Use "Validation" column for validation.
- Set "BAD" as response variable.
- Include multiple predictors: "LOAN", "MORTDUE", "VALUE", "REASON", "JOB", "YOJ", "DEROG", "DELINQ", "CLAGE", "NINQ", "CLNO".
- Enable Profiler.
- Set Profiler configuration to 1.
- Specify term values for each predictor.
- Lock all terms for prediction.
- Display all terms in the profiler.
Example 5
Summary: Generates a Naive Bayes analysis to predict country based on size and type, with profiler enabled and ROC curve disabled, saving the probability formula.
Code:
dt = Open("data_table.jmp");
obj = dt << Naive Bayes(
Y( :country ),
X( :size, :type ),
Profiler( 1, Term Value( size( "Large", Lock( 0 ), Show( 1 ) ), Type( "Family", Lock( 0 ), Show( 1 ) ) ) ),
ROC Curve( 0 )
);
obj << Save Probability Formula;
Code Explanation:
- Open data table.
- Run Naive Bayes analysis.
- Set response variable.
- Specify predictor variables.
- Enable profiler.
- Configure term values.
- Disable ROC curve.
- Save probability formula.
Example 6
Summary: Runs the fitting and testing of a Naive Bayes model to predict country based on size and type variables, with interactive profiling capabilities.
Code:
dt = Open("data_table.jmp");
obj = dt << Naive Bayes(
Y( :country ),
X( :size, :type ),
Profiler( 1, Term Value( size( "Large", Lock( 0 ), Show( 1 ) ), Type( "Family", Lock( 0 ), Show( 1 ) ) ) ),
ROC Curve( 0 )
);
obj << Save Probability Formula;
obj << Test YFullFormula;
Code Explanation:
- Open data table;
- Fit Naive Bayes model.
- Set response variable: country.
- Set predictor variables: size, type.
- Enable Profiler.
- Lock size term at "Large".
- Show size term in Profiler.
- Lock type term at "Family".
- Show type term in Profiler.
- Disable ROC Curve.
- Save probability formula.
- Test YFullFormula.
Example 7
Summary: Generates a Naive Bayes analysis on the Titanic dataset, using multiple X variables and configuring the Profiler to visualize term values.
Code:
Open("data_table.jmp") << Naive Bayes(
Y( :Survived ),
X( :Passenger Class, :Sex, :Age, :Siblings and Spouses, :Parents and Children, :Fare, :Port, :Lifeboat ),
Profiler(
1,
Term Value(
Passenger Class( 1, Lock( 0 ), Show( 1 ) ),
Sex( "female", Lock( 0 ), Show( 1 ) ),
Age( 29.881, Lock( 0 ), Show( 1 ) ),
Siblings and Spouses( 0.4989, Lock( 0 ), Show( 1 ) ),
Parents and Children( 0.385, Lock( 0 ), Show( 1 ) ),
Fare( 121, Lock( 0 ), Show( 1 ) ),
Port( "C", Lock( 0 ), Show( 1 ) ),
Lifeboat( "A", Lock( 0 ), Show( 1 ) )
)
)
);
Code Explanation:
- Open data table;
- Apply Naive Bayes model.
- Set Y variable to Survived.
- Include multiple X variables.
- Enable Profiler.
- Set Profiler configuration.
- Define term values for each X variable.
- Lock terms for Passenger Class.
- Lock terms for Sex.
- Lock terms for Age.
Example 8
Summary: Fits a Naive Bayes model to predict sex based on transformed height and weight data, with interactive profiling capabilities.
Code:
dt = Open("data_table.jmp");
obj = Naive Bayes(
Y( :sex ),
X( Transform Column( "Log[height]", Formula( Log( :height ) ) ), :weight ),
Profiler( 1, Term Value( "Log[height]"n( 4.13363, Lock( 0 ), Show( 1 ) ), weight( 105, Lock( 0 ), Show( 1 ) ) ) )
);
Code Explanation:
- Open data table.
- Create Log[height] column.
- Fit Naive Bayes model.
- Use sex as response.
- Include transformed height and weight.
- Enable Profiler.
- Set Log[height] term value.
- Unlock Log[height] term.
- Display Log[height] term.
- Set weight term value.
Naive Bayes using Set Property
Example 1
Summary: Generates a Naive Bayes analysis to predict the BAD variable in the data table, utilizing informative missing values for REASON, JOB, DEROG, and DELINQ.
Code:
dt = Open("data_table.jmp");
dt:REASON << Set Property( "Informative Missing", 1 );
dt:JOB << Set Property( "Informative Missing", 1 );
dt:DEROG << Set Property( "Informative Missing", 1 );
dt:DELINQ << Set Property( "Informative Missing", 1 );
dt << Naive Bayes(
Validation( :Validation ),
Y( :BAD ),
X( :LOAN, :MORTDUE, :VALUE, :REASON, :JOB, :YOJ, :DEROG, :DELINQ, :CLAGE, :NINQ, :CLNO ),
Profiler(
1,
Term Value(
LOAN( 18608, Lock( 0 ), Show( 1 ) ),
MORTDUE( 73760, Lock( 0 ), Show( 1 ) ),
VALUE( 101780, Lock( 0 ), Show( 1 ) ),
REASON( "", Lock( 0 ), Show( 1 ) ),
JOB( "Mgr", Lock( 0 ), Show( 1 ) ),
YOJ( 8.92, Lock( 0 ), Show( 1 ) ),
DEROG( 0.26, Lock( 0 ), Show( 1 ) ),
DELINQ( 0.45, Lock( 0 ), Show( 1 ) ),
CLAGE( 180, Lock( 0 ), Show( 1 ) ),
NINQ( 1.2, Lock( 0 ), Show( 1 ) ),
CLNO( 21.3, Lock( 0 ), Show( 1 ) )
)
)
);
Code Explanation:
- Open data table;
- Set Informative Missing for REASON.
- Set Informative Missing for JOB.
- Set Informative Missing for DEROG.
- Set Informative Missing for DELINQ.
- Run Naive Bayes analysis.
- Use Validation column.
- Predict BAD variable.
- Include all specified X variables.
- Launch Profiler with given settings.
Example 2
Summary: Generates a Naive Bayes analysis to predict the likelihood of 'BAD' outcomes based on the 'REASON' column, with informative missing values set for the 'REASON' column.
Code:
dt = Open("data_table.jmp");
dt:REASON << Set Property( "Informative Missing", 1 );
dt << Naive Bayes( Validation( :Validation ), Y( :BAD ), X( :REASON ), Profiler( 1, Term Value( REASON( "", Lock( 0 ), Show( 1 ) ) ) ) );
Code Explanation:
- Open data table.
- Set "Informative Missing" property for REASON column.
- Run Naive Bayes analysis.
- Specify Validation column.
- Set BAD as response variable.
- Use REASON as predictor.
- Enable Profiler.
- Configure REASON term in Profiler.
- Lock REASON term at default value.
- Display REASON term in Profiler.
Naive Bayes using If
Summary: Fits a Naive Bayes model to a data table, saving probability formulas, and retrieving values in JMP Pro.
Code:
If( Contains( JMP Product Name(), "Pro" ),
dt = Open("data_table.jmp");
obj1 = dt << Naive Bayes( Validation( :Validation ), Y( :BAD ), X( :REASON, JOB ), Profiler( 1 ) );
obj1 << save probability formula;
formula1 = (dt:Naive Score Good Risk << get values);
dt:REASON << Set Property( "Informative Missing", 1 );
obj2 = dt << Naive Bayes( Validation( :Validation ), Y( :BAD ), X( :REASON, :JOB ), Profiler() );
obj2 << save probability formula;
formula2 = (dt:Naive Score Good Risk 2 << get values);
Close( dt, no save );
);
Code Explanation:
- Check for JMP Pro version.
- Open data table;
- Fit Naive Bayes model.
- Save probability formula.
- Retrieve probability values.
- Set "Informative Missing" property.
- Refit Naive Bayes model.
- Save second probability formula.
- Retrieve second set of values.
- Close dataset without saving.