Here's a summarized breakdown of the Splunk Machine Learning Toolkit (MLTK) commands along with practical examples:
fit CommandSyntax:
spl
fit <algorithm> [option_name]=[option_value]... <response-field> from <explanatory-field> [into <model_name>]
Examples:
spl
... | fit LinearRegression errors from _time
errors_over_time:
spl
... | fit LinearRegression errors from _time into errors_over_time
spl
... | fit LogisticRegression species from petal_length petal_width sepal_length sepal_width
apply CommandSyntax:
spl
apply <model_name> [as <output_field>]
Examples:
spl
... | apply errors_over_time
predicted_errors:
spl
... | apply errors_over_time as predicted_errors
summary CommandSyntax:
spl
summary <model_name>
Examples:
LinearRegression model:
spl
| summary errors_over_time
listmodels Commandfit command.Syntax:
spl
listmodels
Example:
spl
| listmodels
deletemodel CommandSyntax:
spl
deletemodel <model_name>
Examples:
errors_over_time:
spl
| deletemodel errors_over_time
sample CommandSyntax:
spl
sample [ratio=<float>] [count=<int>] [proportional=<field>] [partitions=<int>] [seed=<number>]
Examples:
spl
... | sample ratio=0.01
spl
... | sample count=20
spl
... | sample count=20 by host
spl
... | sample partitions=7 fieldname="partition_number"
score CommandSyntax:
spl
score <scoring-method-name> <field1> against <field2>
Examples:
spl
... | score confusion_matrix true="species" pred="predicted(species)"
fit, apply, and score CommandsTrain a Linear Regression Model:
spl
index=your_index
| fit LinearRegression sales from advertising_budget temperature into sales_model
Apply the Model to Make Predictions:
sales_model to predict sales:
spl
index=your_index
| apply sales_model as predicted_sales
Evaluate the Model's Performance:
spl
index=your_index
| apply sales_model as predicted_sales
| eval residual = sales - predicted_sales
| eval residual_squared = residual * residual
| stats avg(abs(residual)) as MAE, avg(residual_squared) as MSE
Validate the Model (Classification):
spl
... | score confusion_matrix true="actual_field" pred="predicted_field"
fit: Use to train models.apply: Use to apply models for predictions.summary: Get the details of a trained model (e.g., coefficients).listmodels: List all trained models.deletemodel: Delete a specific model.sample: Randomly sample or partition data for training/testing.score: Validate model outcomes with statistical tests.These commands provide powerful tools for integrating machine learning into Splunk searches, allowing you to apply predictive analytics and statistical models to your data directly within the Splunk environment.