Skip to content

wietsesas/PowerML

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PowerML

This module is designed to harness the capabilities of Microsoft's machine learning framework ML.Net directly from within your PowerShell scripts and automation tasks.

Version info

  • Version: 1.0.0.1
  • Compatible PowerShell edition: Core
  • PowerShell version: 7.3.8

On this page

Installation

This PowerShell module has been published to the PowerShell Gallery. Use the following command to install the module on your local machine:

Install-Module PowerML

You can also download the latest release from this github repository.

Usage

MLContext

The common context for all ML.NET operations. It provides a way to create components for data preparation, feature engineering, training, prediction, and model evaluation. It also allows logging, execution control, and the ability to set repeatable random numbers.

A context is automatically created and cached on the first operation that requires a context. This means you don't have to create a context or pass it to the cmdlets.

However, if you want the MLContext environment to become deterministic, you have to provide a fixed seed. In this case you can create your own context before calling another cmdlet that needs a context.

New-MLContext -Seed 1234567

If you want to work with multiple contexts at once, you can choose to not cache the context and pass the correct context to the subsequent cmdlets.

$context1 = New-MLContext -NoCache
$context2 = New-MLContext -Seed 1234567 -NoCache
# ...
$data1 = Import-MLData -Type '<type_name>' -Path '<path_to_data>' -Context $context1
$data2 = Import-MLData -Type '<type_name>' -Path '<path_to_data>' -Context $context2

Types

ML input and output data is typed. You can use the cmdlet Register-MLType to register a new custom type.
You can pass the type definition as a Hashtable.

Register-MLType -Definition @{
  Name = 'SentimentData'
  Properties = @{
    SentimentText = @{ Type = 'string'; LoadColumn = 0 }
    Sentiment = @{ Type = 'bool'; LoadColumn = 1; ColumnName = 'Label' }
  }
}

Or you can load the type from a json file containing the type definition.

Register-MLType -Path '<path_to_json_file>'

You can get the registered types with the cmdlet Get-MLType.

# Get all registered types
Get-MLType
# Get a specific registered type
Get-MLType -Type '<type_name>'

You can create an object of a registered type with the cmdlet New-MLObject.

@{
  Property1 = 1
  Property2 = 'Value2'
} | New-MLObject -Type '<type_name>'

Examples

Examples are taken from the original Microsoft tutorials.

Cmdlets

MLContext

Name Description
Get-MLContext Get the current (cached) MLContext.
New-MLContext Create a new MLContext.
Set-MLContext Set the current (cached) MLContext.

Custom types

Name Description
Get-MLType Get a registered type.
New-MLObject Create a new object of the specified registered type with the specified properties.
Register-MLType Register a custom type from a type definition.

Data

Name Description
ConvertTo-Enumerable Convert an IDataView to an enumerable list.
Get-BootstrapSample Take an approximate bootstrap sample of the input data.
Import-MLData Get data from memory, files or database.
Measure-EntireAnomalyBySrCnn Detect timeseries anomalies for entire input using SRCNN algorithm.
Measure-Seasonality Detects this predictable interval (or period) by adopting techniques of fourier analysis.
Select-MLData Select a subset of data in a DataView.
Split-MLData Split the dataset into a train and test set or into cross-validation folds of train and test sets.

Model

Name Description
Build-MLModel Train a machine learning model (Fit).
Export-MLModel Export a machine learning model.
Import-MLModel Import a machine learning model.
Import-TensorFlowModel Load TensorFlow model into memory.
Invoke-MLModel Transform data using a machine learning model.
Test-MLModel Evaluate a machine learning model.

Transforms

Name Description
Add-ApplyOnnxModelTransform Transform the input data with an imported ONNX model.
Add-ApplyWordEmbeddingTransform Convert vectors of text tokens into sentence vectors using a pre-trained model.
Add-ApproximatedKernelMapTransform Map each input vector onto a lower dimensional feature space, where inner products approximate a kernel function, so that the features can be used as inputs to the linear algorithms.
Add-CacheCheckpoint Append a caching checkpoint to an estimator chain.
Add-CalculateFeatureContribution Calculate contribution scores for each element of a feature vector.
Add-ConcatenateTransform Concatenate one or more input columns into a new output column.
Add-ConvertToGrayscaleTransform Convert an image to grayscale.
Add-ConvertToImageTransform Convert a vector of pixels to ImageDataViewType.
Add-ConvertTypeTransform Convert the type of an input column to a new type.
Add-CopyColumnsTransform Copy and rename one or more input columns.
Add-DetectAnomalyBySrCnnTransform Detect anomalies in the input time series data using the Spectral Residual (SR) algorithm.
Add-DetectChangePointBySsaTransform Detect change points in time series data using singular spectrum analysis (SSA).
Add-DetectIidChangePointTransform Detect change points in independent and identically distributed (IID) time series data using adaptive kernel density estimations and martingale scores.
Add-DetectIidSpikeTransform Detect spikes in independent and identically distributed (IID) time series data using adaptive kernel density estimations and martingale scores.
Add-DetectSpikeBySsaTransform Detect spikes in time series data using singular spectrum analysis (SSA).
Add-DnnFeaturizeImageTransform Applies a pre-trained deep neural network (DNN) model to transform an input image into a feature vector.
Add-DropColumnsTransform Drop one or more input columns.
Add-ExpressionTransform Apply an expression to transform columns into new ones.
Add-ExtractPixelsTransform Convert pixels from input image into a vector of numbers.
Add-FeaturizeTextTransform Transform a text column into a float array of normalized ngrams and char-grams counts.
Add-ForecastBySsaTransform Singular Spectrum Analysis (SSA) model for univariate time-series forecasting.
Add-HashTransform Hash the value in the input column.
Add-IndicateMissingValuesTransform Create a new boolean output column, the value of which is true when the value in the input column is missing.
Add-IsotonicTransform Transforms a binary classifier raw score into a class probability by assigning scores to bins, where the position of boundaries and the size of bins are estimated using the training data.
Add-LatentDirichletAllocationTransform Transform a document (represented as a vector of floats) into a vector of floats over a set of topics.
Add-LoadImagesTransform Load images from a folder into memory.
Add-LoadRawImageBytesTransform Loads images of raw bytes into a new column.
Add-MapKeyToBinaryVectorTransform Convert keys back to a binary vector of original values.
Add-MapKeyToValueTransform Convert keys back to their original values.
Add-MapKeyToVectorTransform Convert keys back to vectors of original values.
Add-MapValueToKeyTransform Map values to keys (categories) by creating the mapping from the input data.
Add-MapValueTransform Map values to keys (categories) based on the supplied dictionary of mappings.
Add-NaiveTransform Transforms a binary classifier raw score into a class probability by assigning scores to bins, and calculating the probability based on the distribution among the bins.
Add-NormalizeBinningTransform Assign the input value to a bin index and divide by the number of bins to produce a float value between 0 and 1. The bin boundaries are calculated to evenly distribute the training data across bins.
Add-NormalizeGlobalContrastTransform Scale each value in a row by subtracting the mean of the row data and divide by either the standard deviation or l2-norm (of the row data), and multiply by a configurable scale factor (default 2).
Add-NormalizeLogMeanVarianceTransform Normalize based on the logarithm of the training data.
Add-NormalizeLpNormTransform Scale input vectors by their lp-norm, where p is 1, 2 or infinity. Defaults to the l2 (Euclidean distance) norm.
Add-NormalizeMeanVarianceTransform Subtract the mean (of the training data) and divide by the variance (of the training data).
Add-NormalizeMinMaxTransform Scale the input by the difference between the minimum and maximum values in the training data.
Add-NormalizeRobustScalingTransform Scale each value using statistics that are robust to outliers that will center the data around 0 and scales the data according to the quantile range.
Add-NormalizeSupervisedBinningTransform Assign the input value to a bin based on its correlation with label column.
Add-NormalizeTextTransform Change case, remove diacritical marks, punctuation marks, and numbers.
Add-OneHotEncodingTransform Convert one or more text columns into one-hot encoded vectors.
Add-OneHotHashEncodingTransform Convert one or more text columns into hash-based one-hot encoded vectors.
Add-PlattTransform Transforms a binary classifier raw score into a class probability using logistic regression with fixed parameters or parameters estimated using the training data.
Add-ProduceHashedNgramsTransform Transform text column into a vector of hashed ngram counts.
Add-ProduceHashedWordBagsTransform Transform text column into a bag of hashed ngram counts.
Add-ProduceNgramsTransform Transform text column into a bag of counts of ngrams (sequences of consecutive words).
Add-ProduceWordBagsTransform Transform text column into a bag of counts of ngrams vector.
Add-ProjectToPrincipalComponentsTransform Reduce the dimensions of the input feature vector by applying the Principal Component Analysis algorithm.
Add-RemoveStopWordsTransform Remove default (for the specified language) or specified stop words from input columns.
Add-ReplaceMissingValuesTransform Create a new output column, the value of which is set to a default value if the value is missing from the input column, and the input value otherwise.
Add-ResizeImagesTransform Resize images.
Add-ScoreTensorFlowModelTransform Scores a dataset using a pre-trained TensorFlow model.
Add-SelectColumnsTransform Select one or more columns to keep from the input data.
Add-SelectFeaturesBasedOnCountTransform Select features whose non-default values are greater than a threshold.
Add-SelectFeaturesBasedOnMutualInformationTransform Select the features on which the data in the label column is most dependent.
Add-TokenizeIntoCharactersAsKeysTransform Split one or more text columns into individual characters floats over a set of topics.
Add-TokenizeIntoWordsTransform Split one or more text columns into individual words.

Trainers

Name Description
Add-AveragedPerceptronTrainer Predict a target using a linear binary classification model trained with the averaged perceptron.
Add-FastForestBinaryTrainer Train a decision tree binary classification model using Fast Forest.
Add-FastForestRegressionTrainer Train a decision tree regression model using Fast Forest.
Add-FastTreeBinaryTrainer Train a decision tree binary classification model using FastTree.
Add-FastTreeRankingTrainer Train a decision tree ranking model using FastTree.
Add-FastTreeRegressionTrainer Train a decision tree regression model using FastTree.
Add-FastTreeTweedieTrainer Train a decision tree regression model using Tweedie loss function. This trainer is a generalization of Poisson, compound Poisson, and gamma regression.
Add-FieldAwareFactorizationMachineTrainer Predict a target using a field-aware factorization machine model trained using a stochastic gradient method.
Add-GamBinaryTrainer Train a binary classification model with generalized additive models (GAM).
Add-GamRegressionTrainer Train a regression model with generalized additive models (GAM).
Add-ImageClassificationTrainer Train a Deep Neural Network (DNN) to classify images.
Add-KMeansTrainer Train a KMeans cluster.
Add-LbfgsLogisticRegressionBinaryTrainer Predict a target using a linear logistic regression model trained with L-BFGS method.
Add-LbfgsMaximumEntropyMulticlassTrainer Predict a target using a maximum entropy multiclass classifier trained with L-BFGS method.
Add-LbfgsPoissonRegressionTrainer Train a Poisson regression model.
Add-LdSvmTrainer Predict a target using a non-linear binary classification model trained with Local Deep SVM.
Add-LightGbmBinaryTrainer Train a boosted decision tree binary classification model using LightGBM.
Add-LightGbmMulticlassTrainer Train a boosted decision tree multi-class classification model using LightGBM.
Add-LightGbmRankingTrainer Train a boosted decision tree ranking model using LightGBM.
Add-LightGbmRegressionTrainer Train a boosted decision tree regression model using LightGBM.
Add-LinearSvmTrainer Predict a target using a linear binary classification model trained with Linear SVM.
Add-MatrixFactorizationTrainer Predict elements in a matrix using matrix factorization (also known as a type of collaborative filtering).
Add-NaiveBayesMulticlassTrainer Predicts a multiclass target using a Naive Bayes model that supports binary feature values.
Add-OlsTrainer Train a linear regression model using ordinary least squares (OLS) for estimating the parameters of the linear regression model.
Add-OnlineGradientDescentTrainer Train a linear regression model using Online Gradient Descent (OGD) for estimating the parameters of the linear regression model.
Add-PriorTrainer Predicting a target using a binary classification model.
Add-RandomizedPcaTrainer Train an approximate PCA using Randomized SVD algorithm.
Add-SdcaLogisticRegressionBinaryTrainer Train a binary logistic regression classification model using the stochastic dual coordinate ascent method. The trained model is calibrated and can produce probability by feeding the output value of the linear function to a PlattCalibrator.
Add-SdcaMaximumEntropyMulticlassTrainer Predict a target using a maximum entropy multiclass classifier. The trained model MaximumEntropyModelParameters produces probabilities of classes.
Add-SdcaNonCalibratedBinaryTrainer Train a binary logistic regression classification model using the stochastic dual coordinate ascent method.
Add-SdcaNonCalibratedMulticlassTrainer Predict a target using a linear multiclass classifier. The trained model LinearMulticlassModelParameters produces probabilities of classes.
Add-SdcaRegressionTrainer Training a regression model using the stochastic dual coordinate ascent method.
Add-SgdCalibratedBinaryTrainer Train logistic regression using a parallel stochastic gradient method. The trained model is calibrated and can produce probability by feeding the output value of the linear function to a PlattCalibrator.
Add-SgdNonCalibratedBinaryTrainer Train logistic regression using a parallel stochastic gradient method.
Add-SymbolicSgdLogisticRegressionBinaryTrainer Train logistic regression using a parallel stochastic gradient method.

Contributors

Feel free to send pull requests or fill out issues when you encounter them.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages