Scikit-Learn Exporter Module

def any_in(seq_a, seq_b)[source]

Checks for common elements in two given sequence elements

Parameters:
  • seq_a (list) – A list of items
  • seq_b (list) – A list of items
Returns:

Return type:

Returns a boolean value if any item of seq_a belongs to seq_b or visa versa

def avgPathLength(n)[source]

Generates average path length for Isolation forest models

Parameters:n (int) – Number of samples
Returns:
Return type:The average path length
def get_PMML_kwargs(model, derived_col_names, col_names, target_name, mining_imp_val, categoric_values, model_name)[source]

It returns all the pmml elements.

Parameters:
  • model (Scikit-learn model object) – An instance of Scikit-learn model.
  • derived_col_names (List) – Contains column names after preprocessing
  • col_names (List) – Contains list of feature/column names.
  • target_name (String) – Name of the target column .
  • mining_imp_val (tuple) – Contains the mining_attributes,mining_strategy, mining_impute_value
  • categoric_values (tuple) – Contains Categorical attribute names and its values
  • model_name (string) – Name of the model
Returns:

algo_kwargs – Get the PMML model argument based on scikit learn model object

Return type:

Dictionary

def get_anomaly_detection_output(model)[source]

Generates output for anomaly detection models

Parameters:model – Scikit-learn’s model object
Returns:Returns Nyoka’s Output object
Return type:output_fields
def get_anomalydetection_model(model, derived_col_names, col_names, target_name, mining_imp_val, categoric_values, model_name)[source]

Creates xml elements for anomaly detction models

Parameters:
  • model – An instance of Scikit-learn model.
  • derived_col_names (List) – Contains column names after preprocessing
  • col_names (List) – Contains list of feature/column names.
  • target_name (String) – Name of the Target column.
  • mining_imp_val (tuple) – Contains the mining_attributes,mining_strategy, mining_impute_value
  • categoric_values (tuple) – Contains Categorical attribute names and its values
  • model_name (string) – Name of the model
Returns:

anomaly_detection_model – Returns Nyoka’s AnomalyDetectionModel object

Return type:

List

def get_bayes_inputs(model, derived_col_names)[source]

It returns the Bayes Input element of the naive bayes model .

Parameters:
  • model – An instance of Scikit-learn model.
  • derived_col_names (List) – Contains column names after preprocessing.
Returns:

Returns Nyoka’s BayesInput object.

Return type:

bayes_inputs

def get_bayes_output(model, target_name)[source]

It returns the Bayes Output element of the model

Parameters:
  • model – An instance of Scikit-learn model.
  • target_name (String) – Name of the Target column.
Returns:

Returns Nyoka’s BayesOutput object

Return type:

BayesOutput

def get_classificationMethod(model)[source]

It returns the Classification method name for SVM models.

Parameters:model – A Scikit-learn model instance.
Returns:
Return type:Returns the classification method of the SVM model
def get_cluster_num(model)[source]

Returns number of cluster for clustering models

Parameters:model – An instance of Scikit-learn model.
Returns:model.n_clusters – Returns the number of clusters
Return type:Integer
def get_cluster_vals(model, counts)[source]

Generates cluster information for clustering models

Parameters:model – An instance of Scikit-learn model.
Returns:cluster_flds – Returns Nyoka’s Cluster object
Return type:List
def get_clustering_flds(col_names)[source]

Generates cluster fields for clustering models

Parameters:col_names – Contains list of feature/column names.
Returns:clustering_flds – Returns Nyoka’s ClusteringField object
Return type:List
def get_clustering_model(model, derived_col_names, col_names, target_name, mining_imp_val, categoric_values, model_name)[source]

Generates PMML elements for clustering models

Parameters:
  • model – An instance of Scikit-learn model.
  • derived_col_names (List) – Contains column names after preprocessing
  • col_names (List) – Contains list of feature/column names.
  • target_name (String) – Name of the Target column.
  • mining_imp_val (tuple) – Contains the mining_attributes,mining_strategy, mining_impute_value
  • categoric_values (tuple) – Contains Categorical attribute names and its values
  • model_name (string) – Name of the model
Returns:

clustering_models – Returns Nyoka’s ClusteringModel object

Return type:

List

def get_comp_measure()[source]

Generates comparison measure information for clustering models

Returns:
Return type:Returns Nyoka’s ComparisonMeasure object
def get_comparison_measure(model)[source]

It return the Comparison measure element for nearest neighbour model.

Parameters:model – An instance of Scikit-learn model.
Returns:Returns Nyoka’s ComparisonMeasure object.
Return type:comp_measure
def get_data_dictionary(model, feature_names, target_name, categoric_values)[source]

It returns the Data Dictionary element.

Parameters:
  • model – A Scikit-learn model instance.
  • feature_names (List) – Contains the list of feature/column name.
  • target_name (List) – Name of the Target column.
  • categoric_values (tuple) – Contains Categorical attribute names and its values
Returns:

Returns Nyoka’s DataDictionary object

Return type:

data_dict

def get_dtype(feat_value)[source]

It return the data type of the value.

Parameters:feat_value – Contains a value for finding the its data type.
Returns:
Return type:Returns the respective data type of that value.
def get_ensemble_models(model, derived_col_names, col_names, target_name, mining_imp_val, categoric_values, model_name)[source]

Generates PMML elemenets for ensemble models

Parameters:
  • model – An instance of Scikit-learn model.
  • derived_col_names (List) – Contains column names after preprocessing.
  • col_names (List) – Contains list of feature/column names.
  • target_name (String) – Name of the Target column.
  • mining_imp_val (tuple) – Contains the mining_attributes,mining_strategy, mining_impute_value.
  • categoric_values (tuple) – Contains Categorical attribute names and its values
  • model_name (string) – Name of the model
Returns:

mining_models – Returns Nyoka’s MiningModel object

Return type:

List

def get_funct(sk_model)[source]

It returns the activation fucntion for a neural network model.

Parameters:model – A Scikit-learn model instance.
Returns:a_fn – Returns the activation function.
Return type:String
def get_header(description)[source]

It returns the Header element of the pmml.

header :
Returns Nyoka’s Header object.
def get_inline_table(model)[source]

It Returns the Inline Table element of the model.

Parameters:model – An instance of Scikit-learn model.
Returns:Returns Nyoka’s InlineTable object
Return type:InlineTable
def get_inner_segments(model, derived_col_names, col_names, index)[source]

It returns the segments of a Segmentation.

Parameters:
  • model – A Scikit-learn model instance.
  • derived_col_names (List) – Contains column names after preprocessing.
  • col_names (List) – Contains list of feature/column names.
  • index (Integer) – The index of the estimator for the model
Returns:

segments – Nyoka’s Segment object

Return type:

List

def get_instance_fields(derived_col_names, target_name)[source]

It returns the Instance field element.

Parameters:
  • derived_col_names (List) – Contains column names after preprocessing.
  • target_name (String) – Name of the Target column.
Returns:

Returns Nyoka’s InstanceFields object

Return type:

InstanceFields

def get_kernel_type(model)[source]

It returns the kernel type element.

Parameters:model – A Scikit-learn model instance.
Returns:kernel_kwargs – Get the respective kernel type of the SVM model.
Return type:Dictionary
def get_knn_inputs(col_names)[source]

It returns the KNN Inputs element.

Parameters:col_names (List) – Contains list of feature/column names.
Returns:Returns Nyoka’s KNNInputs object.
Return type:KNNInputs
def get_mining_func(model)[source]

It returns the name of the mining function of the model.

Parameters:model – A Scikit-learn model instance.
Returns:func_name – Returns the function name of the model
Return type:String
def get_mining_schema(model, feature_names, target_name, mining_imp_val, categoric_values)[source]

It returns the Mining Schema of the model.

Parameters:
  • model – A Scikit-learn model instance.
  • feature_names (List) – Contains the list of feature/column name.
  • target_name (String) – Name of the Target column.
  • mining_imp_val (tuple) – Contains the mining_attributes,mining_strategy, mining_impute_value.
  • categoric_values (tuple) – Contains Categorical attribute names and its values
Returns:

Nyoka’s MiningSchema object

Return type:

MiningSchema

def get_model_kwargs(model, col_names, target_name, mining_imp_val, categoric_values)[source]

It returns all the model element for a specific model.

Parameters:
  • model – An instance of Scikit-learn model.
  • col_names (List) – Contains list of feature/column names.
  • target_name (String) – Name of the Target column.
  • mining_imp_val (tuple) – Contains the mining_attributes,mining_strategy, mining_impute_value
  • categoric_values (tuple) – Contains Categorical attribute names and its values
Returns:

model_kwargs – Returns function name, MiningSchema and Output of the sk_model object

Return type:

Dictionary

def get_multiple_model_method(model)[source]

It returns the type of multiple model method for MiningModels.

Parameters:model – A Scikit-learn model instance
Returns:
Return type:The multiple model method for a MiningModel.
def get_naiveBayesModel(model, derived_col_names, col_names, target_name, mining_imp_val, categoric_values, model_name)[source]

Generates PMML elements for naive bayes models

Parameters:
  • model – An instance of Scikit-learn model.
  • derived_col_names (List) – Contains column names after preprocessing.
  • col_names (List) – Contains list of feature/column names.
  • target_name (String) – Name of the Target column.
  • mining_imp_val (tuple) – Contains the mining_attributes,mining_strategy, mining_impute_value
  • categoric_values (tuple) – Contains Categorical attribute names and its values
  • model_name (string) – Name of the model
Returns:

naive_bayes_model – Returns Nyoka’s NaiveBayesModel

Return type:

List

def get_nearestNeighbour_model(model, derived_col_names, col_names, target_name, mining_imp_val, categoric_values, model_name)[source]

Generates PMML elements for nearest neighbour model

Parameters:
  • model – An instance of Scikit-learn model.
  • derived_col_names (List) – Contains column names after preprocessing
  • col_names (List) – Contains list of feature/column names.
  • target_name (String) – Name of the Target column.
  • mining_imp_val (tuple) – Contains the mining_attributes,mining_strategy, mining_impute_value
  • categoric_values (tuple) – Contains Categorical attribute names and its values
  • model_name (string) – Name of the model
Returns:

Returns Nyoka’s NearestNeighborModel object

Return type:

nearest_neighbour_model

def get_neural_layer(model, feature_names, target_name)[source]

It returns the Neural Layer and Neural Ouptput element.

Parameters:
  • model – A Scikit-learn model instance.
  • feature_names (List) – Contains the list of feature/column name.
  • target_name (String) – Name of the Target column.
Returns:

  • all_neuron_layer (List) – Nyoka’s NeuralLayer object
  • neural_output_element – Nyoka’s NeuralOutput object

def get_neural_models(model, derived_col_names, col_names, target_name, mining_imp_val, categoric_values, model_name)[source]

Generates PMML elements for neural network models

Parameters:
  • model – A Scikit-learn model instance.
  • derived_col_names (List) – Contains column names after preprocessing.
  • col_names (List) – Contains list of feature/column names.
  • target_name (String) – Name of the Target column.
  • mining_imp_val (tuple) – Contains the mining_attributes,mining_strategy, mining_impute_value.
  • categoric_values (tuple) – Contains Categorical attribute names and its values
  • model_name (string) – Name of the model
Returns:

neural_model – Nyoka’s NeuralNetwork object

Return type:

List

def get_neuron_input(feature_names)[source]

It returns the Neural Input element.

Parameters:feature_names (List) – Contains the list of feature/column name.
Returns:Returns Nyoka’s NeuralInput object
Return type:neural_input_element
def get_node(model, features_names, main_model=None)[source]

It return the Node element of the model.

Parameters:
  • model – An instance of the estimator of the tree object.
  • features_names (List) – Contains the list of feature/column name.
  • main_model – A Scikit-learn model instance.
Returns:

Return type:

Get all the underlying Nodes.

def get_outer_segmentation(model, derived_col_names, col_names, target_name, mining_imp_val, categoric_values, model_name)[source]

It returns the Segmentation element of a MiningModel.

Parameters:
  • model – A Scikit-learn model instance.
  • derived_col_names (List) – Contains column names after preprocessing.
  • col_names (List) – Contains list of feature/column names.
  • target_name (String) – Name of the Target column.
  • mining_imp_val (tuple) – Contains the mining_attributes,mining_strategy, mining_impute_value
  • categoric_values (tuple) – Contains Categorical attribute names and its values
Returns:

Nyoka’s Segmentation object

Return type:

segmentation

def get_output(model, target_name)[source]

It returns the output element of the model.

Parameters:
  • model – A Scikit-learn model instance.
  • target_name (String) – Name of the Target column.
Returns:

Nyoka’s Output object

Return type:

Output

def get_output_for_clustering(values)[source]

Generates output for clustering models

Parameters:model – An instance of Scikit-learn model.
Returns:output_fields – Returns Nyoka’s Output object
Return type:List
def get_reg_mining_models(model, derived_col_names, col_names, target_name, mining_imp_val, categoric_values, model_name)[source]

Creates xml elements for multi-class linear models

Parameters:
  • model – An instance of Scikit-learn model.
  • derived_col_names (List) – Contains column names after preprocessing
  • col_names (List) – Contains list of feature/column names.
  • target_name (String) – Name of the Target column.
  • mining_imp_val (tuple) – Contains the mining_attributes,mining_strategy, mining_impute_value
  • categoric_values (tuple) – Contains Categorical attribute names and its values
  • model_name (string) – Name of the model
Returns:

mining_model – Returns a Nyoka’s MiningModel object

Return type:

List

def get_reg_tab_for_reg_mining_model(model, col_names, index, categorical_values)[source]

Generates Regression Table for multi-class linear models

Parameters:
  • model – An instance of Scikit-learn model.
  • col_names (List) – Contains list of feature/column names.
  • index (int) –
  • categoric_values (tuple) – Contains Categorical attribute names and its values
Returns:

Return type:

Returns Nyoka’s RegressionTable object

def get_regrs_models(model, derived_col_names, col_names, target_name, mining_imp_val, categoric_values, model_name)[source]

Generates PMML elements for linear models

Parameters:
  • model – A Scikit-learn model instance.
  • derived_col_names (List) – Contains column names after preprocessing.
  • col_names (List) – Contains list of feature/column names.
  • target_name (String) – Name of the Target column.
  • mining_imp_val (tuple) – Contains the mining_attributes,mining_strategy, mining_impute_value
  • categoric_values (tuple) – Contains Categorical attribute names and its values
  • model_name (string) – Name of the model
Returns:

regrs_models – Nyoka’s RegressionModel object

Return type:

List

def get_regrs_tabl(model, feature_names, target_name, categoric_values)[source]

It returns the Regression Table element of the model.

Parameters:
  • model – A Scikit-learn model instance.
  • derived_col_names (List) – Contains column names after preprocessing.
  • target_name (String) – Name of the Target column.
  • categoric_values (tuple) – Contains Categorical attribute names and its values
Returns:

merge – Nyoka’s RegressionTable object

Return type:

List

def get_segments(model, derived_col_names, col_names, target_name, mining_imp_val, categoric_values, model_name)[source]

It returns the Segment element of a Segmentation.

Parameters:
  • model – A Scikit-learn model instance.
  • derived_col_names (List) – Contains column names after preprocessing.
  • col_names (List) – Contains list of feature/column names.
  • target_name (String) – Name of the Target column.
  • mining_imp_val (tuple) – Contains the mining_attributes,mining_strategy, mining_impute_value
  • categoric_values (tuple) – Contains Categorical attribute names and its values
Returns:

Nyoka’s Segment object

Return type:

segments

def get_segments_for_gbc(model, derived_col_names, col_names, target_name, mining_imp_val, categoric_values, model_name)[source]

It returns list of Segments element of a Segmentation.

Parameters:
  • model – A Scikit-learn model instance.
  • derived_col_names (List) – Contains column names after preprocessing.
  • col_names (List) – Contains list of feature/column names.
  • target_name (String) – Name of the Target column.
  • mining_imp_val (tuple) – Contains the mining_attributes,mining_strategy, mining_impute_value
  • categoric_values (tuple) – Contains Categorical attribute names and its values
Returns:

segments – Nyoka’s Segment object

Return type:

List

def get_super_cls_names(model_inst)[source]

It returns the set of Super class of the model.

Parameters:model_inst – Instance of the scikit-learn model
Returns:parents – Returns all the parent class of the model instance.
Return type:Set
def get_supportVectorMachine(model)[source]

Generates PMML elements for support vector machine models

Parameters:model – A Scikit-learn model instance.
Returns:support_vector_machines – Nyoka’s SupportVectorMachineModel object
Return type:List
def get_supportVectorMachine_models(model, derived_col_names, col_names, target_names, mining_imp_val, categoric_values, model_name)[source]

Generates PMML elements for support vector machine models

Parameters:
  • model – An instance of Scikit-learn model.
  • derived_col_names (List) – Contains column names after preprocessing.
  • col_names (List) – Contains list of feature/column names.
  • target_names (String) – Name of the Target column.
  • mining_imp_val (tuple) – Contains the mining_attributes,mining_strategy, mining_impute_value
  • categoric_values (tuple) – Contains Categorical attribute names and its values
  • model_name (string) – Name of the model
Returns:

supportVector_models – Returns Nyoka’s SupportVectorMachineModel object

Return type:

List

def get_targets(model, target_name)[source]

It returns the Target element of the model.

Parameters:
  • model – A Scikit-learn model instance.
  • target_name (String) – Name of the Target column.
Returns:

Returns Nyoka’s Target object

Return type:

targets

def get_threshold()[source]

It returns the Threshold value for Naive Bayes models.

Returns:
Return type:Returns the Threshold value
def get_training_instances(model, derived_col_names, target_name)[source]

It returns the Training Instance element.

Parameters:
  • model – An instance of Scikit-learn model.
  • derived_col_names (List) – Contains column names after preprocessing
  • target_name (String) – Name of the Target column.
Returns:

Returns Nyoka’s TrainingInstances object

Return type:

TrainingInstances

def get_tree_models(model, derived_col_names, col_names, target_name, mining_imp_val, categoric_values, model_name)[source]

Generates PMML elements for tree models

Parameters:
  • model – A Scikit-learn model instance.
  • derived_col_names – Contains column names after preprocessing.
  • col_names (List) – Contains list of feature/column names.
  • target_name (String) – Name of the Target column.
  • mining_imp_val (tuple) – Contains the mining_attributes,mining_strategy, mining_impute_value
  • categoric_values (tuple) – Contains Categorical attribute names and its values
  • model_name (string) – Name of the model
Returns:

tree_models – Nyoka’s TreeModel object

Return type:

List

def get_vectorDictionary(model, derived_col_names, categoric_values)[source]

It return the Vector Dictionary element.

Parameters:
  • model – A Scikit-learn model instance.
  • derived_col_names (List) – Contains column names after preprocessing.
  • categoric_values (tuple) – Contains Categorical attribute names and its values
Returns:

Nyoka’s VectorDictionary object

Return type:

VectorDictionary

def has_target(model)[source]

Checks whether a given model has target or not

Parameters:model – Scikit-learn’s model object
Returns:
Return type:Boolean value
def skl_to_pmml(pipeline, col_names, target_name='target', pmml_f_name='from_sklearn.pmml', model_name=None, description=None)[source]

Exports scikit-learn pipeline object into pmml

Parameters:
  • pipeline – Contains an instance of Pipeline with preprocessing and final estimator
  • col_names (List) – Contains list of feature/column names.
  • target_name (String) – Name of the target column. (Default=’target’)
  • pmml_f_name (String) – Name of the pmml file. (Default=’from_sklearn.pmml’)
  • model_name (string (optional)) – Name of the model
  • description (string (optional)) – Description of the model
Returns:

Return type:

Generates a PMML object and exports it to pmml_f_name