teradataml 17.20.0.6__py3-none-any.whl → 20.0.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of teradataml might be problematic. Click here for more details.
- teradataml/LICENSE-3RD-PARTY.pdf +0 -0
- teradataml/LICENSE.pdf +0 -0
- teradataml/README.md +238 -1
- teradataml/__init__.py +13 -3
- teradataml/_version.py +1 -1
- teradataml/analytics/Transformations.py +4 -4
- teradataml/analytics/__init__.py +0 -2
- teradataml/analytics/analytic_function_executor.py +3 -0
- teradataml/analytics/json_parser/utils.py +13 -12
- teradataml/analytics/sqle/DecisionTreePredict.py +15 -30
- teradataml/analytics/sqle/NaiveBayesPredict.py +11 -20
- teradataml/analytics/sqle/__init__.py +0 -13
- teradataml/analytics/utils.py +1 -0
- teradataml/analytics/valib.py +3 -0
- teradataml/automl/__init__.py +1628 -0
- teradataml/automl/custom_json_utils.py +1270 -0
- teradataml/automl/data_preparation.py +993 -0
- teradataml/automl/data_transformation.py +727 -0
- teradataml/automl/feature_engineering.py +1648 -0
- teradataml/automl/feature_exploration.py +547 -0
- teradataml/automl/model_evaluation.py +163 -0
- teradataml/automl/model_training.py +887 -0
- teradataml/catalog/__init__.py +0 -2
- teradataml/catalog/byom.py +49 -6
- teradataml/catalog/function_argument_mapper.py +0 -2
- teradataml/catalog/model_cataloging_utils.py +2 -1021
- teradataml/common/aed_utils.py +6 -2
- teradataml/common/constants.py +50 -58
- teradataml/common/deprecations.py +160 -0
- teradataml/common/garbagecollector.py +61 -104
- teradataml/common/messagecodes.py +27 -36
- teradataml/common/messages.py +11 -15
- teradataml/common/utils.py +205 -287
- teradataml/common/wrapper_utils.py +1 -110
- teradataml/context/context.py +150 -78
- teradataml/data/bank_churn.csv +10001 -0
- teradataml/data/bmi.csv +501 -0
- teradataml/data/docs/sqle/docs_17_10/BincodeFit.py +3 -3
- teradataml/data/docs/sqle/docs_17_10/BincodeTransform.py +6 -5
- teradataml/data/docs/sqle/docs_17_10/Fit.py +1 -1
- teradataml/data/docs/sqle/docs_17_10/OneHotEncodingTransform.py +1 -1
- teradataml/data/docs/sqle/docs_17_10/OutlierFilterTransform.py +1 -1
- teradataml/data/docs/sqle/docs_17_10/PolynomialFeaturesTransform.py +2 -2
- teradataml/data/docs/sqle/docs_17_10/RowNormalizeTransform.py +2 -1
- teradataml/data/docs/sqle/docs_17_10/ScaleTransform.py +1 -0
- teradataml/data/docs/sqle/docs_17_10/SimpleImputeTransform.py +1 -1
- teradataml/data/docs/sqle/docs_17_10/Transform.py +2 -1
- teradataml/data/docs/sqle/docs_17_20/BincodeFit.py +3 -3
- teradataml/data/docs/sqle/docs_17_20/BincodeTransform.py +6 -5
- teradataml/data/docs/sqle/docs_17_20/Fit.py +1 -1
- teradataml/data/docs/sqle/docs_17_20/GLM.py +1 -1
- teradataml/data/docs/sqle/docs_17_20/GLMPredictPerSegment.py +9 -10
- teradataml/data/docs/sqle/docs_17_20/KMeansPredict.py +3 -2
- teradataml/data/docs/sqle/docs_17_20/NaiveBayesTextClassifierPredict.py +16 -15
- teradataml/data/docs/sqle/docs_17_20/NaiveBayesTextClassifierTrainer.py +2 -2
- teradataml/data/docs/sqle/docs_17_20/NonLinearCombineFit.py +2 -2
- teradataml/data/docs/sqle/docs_17_20/NonLinearCombineTransform.py +8 -8
- teradataml/data/docs/sqle/docs_17_20/OneClassSVMPredict.py +21 -20
- teradataml/data/docs/sqle/docs_17_20/OneHotEncodingTransform.py +1 -1
- teradataml/data/docs/sqle/docs_17_20/OutlierFilterTransform.py +8 -3
- teradataml/data/docs/sqle/docs_17_20/PolynomialFeaturesTransform.py +6 -5
- teradataml/data/docs/sqle/docs_17_20/RandomProjectionTransform.py +6 -6
- teradataml/data/docs/sqle/docs_17_20/RowNormalizeTransform.py +2 -1
- teradataml/data/docs/sqle/docs_17_20/SVM.py +1 -1
- teradataml/data/docs/sqle/docs_17_20/SVMPredict.py +16 -16
- teradataml/data/docs/sqle/docs_17_20/ScaleTransform.py +1 -0
- teradataml/data/docs/sqle/docs_17_20/SimpleImputeTransform.py +3 -2
- teradataml/data/docs/sqle/docs_17_20/TDDecisionForestPredict.py +4 -4
- teradataml/data/docs/sqle/docs_17_20/TDGLMPredict.py +19 -19
- teradataml/data/docs/sqle/docs_17_20/TargetEncodingTransform.py +5 -4
- teradataml/data/docs/sqle/docs_17_20/Transform.py +2 -2
- teradataml/data/docs/sqle/docs_17_20/XGBoostPredict.py +9 -9
- teradataml/data/fish.csv +160 -0
- teradataml/data/glass_types.csv +215 -0
- teradataml/data/insurance.csv +1 -1
- teradataml/data/iris_data.csv +151 -0
- teradataml/data/jsons/sqle/17.10/TD_FunctionTransform.json +1 -0
- teradataml/data/jsons/sqle/17.10/TD_OneHotEncodingTransform.json +1 -0
- teradataml/data/jsons/sqle/17.10/TD_OutlierFilterTransform.json +1 -0
- teradataml/data/jsons/sqle/17.10/TD_PolynomialFeaturesTransform.json +1 -0
- teradataml/data/jsons/sqle/17.10/TD_RowNormalizeTransform.json +1 -0
- teradataml/data/jsons/sqle/17.10/TD_ScaleTransform.json +1 -0
- teradataml/data/jsons/sqle/17.10/TD_SimpleImputeTransform.json +1 -0
- teradataml/data/load_example_data.py +3 -0
- teradataml/data/multi_model_classification.csv +401 -0
- teradataml/data/multi_model_regression.csv +401 -0
- teradataml/data/openml_example.json +63 -0
- teradataml/data/scripts/deploy_script.py +65 -0
- teradataml/data/scripts/mapper.R +20 -0
- teradataml/data/scripts/sklearn/__init__.py +0 -0
- teradataml/data/scripts/sklearn/sklearn_fit.py +175 -0
- teradataml/data/scripts/sklearn/sklearn_fit_predict.py +135 -0
- teradataml/data/scripts/sklearn/sklearn_function.template +113 -0
- teradataml/data/scripts/sklearn/sklearn_model_selection_split.py +158 -0
- teradataml/data/scripts/sklearn/sklearn_neighbors.py +152 -0
- teradataml/data/scripts/sklearn/sklearn_score.py +128 -0
- teradataml/data/scripts/sklearn/sklearn_transform.py +179 -0
- teradataml/data/templates/open_source_ml.json +9 -0
- teradataml/data/teradataml_example.json +73 -1
- teradataml/data/test_classification.csv +101 -0
- teradataml/data/test_prediction.csv +101 -0
- teradataml/data/test_regression.csv +101 -0
- teradataml/data/train_multiclass.csv +101 -0
- teradataml/data/train_regression.csv +101 -0
- teradataml/data/train_regression_multiple_labels.csv +101 -0
- teradataml/data/wine_data.csv +1600 -0
- teradataml/dataframe/copy_to.py +79 -13
- teradataml/dataframe/data_transfer.py +8 -0
- teradataml/dataframe/dataframe.py +910 -311
- teradataml/dataframe/dataframe_utils.py +102 -5
- teradataml/dataframe/fastload.py +11 -3
- teradataml/dataframe/setop.py +15 -2
- teradataml/dataframe/sql.py +3735 -77
- teradataml/dataframe/sql_function_parameters.py +56 -5
- teradataml/dataframe/vantage_function_types.py +45 -1
- teradataml/dataframe/window.py +30 -29
- teradataml/dbutils/dbutils.py +18 -1
- teradataml/geospatial/geodataframe.py +18 -7
- teradataml/geospatial/geodataframecolumn.py +5 -0
- teradataml/hyperparameter_tuner/optimizer.py +910 -120
- teradataml/hyperparameter_tuner/utils.py +131 -37
- teradataml/lib/aed_0_1.dll +0 -0
- teradataml/lib/libaed_0_1.dylib +0 -0
- teradataml/lib/libaed_0_1.so +0 -0
- teradataml/libaed_0_1.dylib +0 -0
- teradataml/libaed_0_1.so +0 -0
- teradataml/opensource/__init__.py +1 -0
- teradataml/opensource/sklearn/__init__.py +1 -0
- teradataml/opensource/sklearn/_class.py +255 -0
- teradataml/opensource/sklearn/_sklearn_wrapper.py +1668 -0
- teradataml/opensource/sklearn/_wrapper_utils.py +268 -0
- teradataml/opensource/sklearn/constants.py +54 -0
- teradataml/options/__init__.py +3 -6
- teradataml/options/configure.py +21 -20
- teradataml/scriptmgmt/UserEnv.py +61 -5
- teradataml/scriptmgmt/lls_utils.py +135 -53
- teradataml/table_operators/Apply.py +38 -6
- teradataml/table_operators/Script.py +45 -308
- teradataml/table_operators/TableOperator.py +182 -591
- teradataml/table_operators/__init__.py +0 -1
- teradataml/table_operators/table_operator_util.py +32 -40
- teradataml/utils/validators.py +127 -3
- {teradataml-17.20.0.6.dist-info → teradataml-20.0.0.0.dist-info}/METADATA +243 -3
- {teradataml-17.20.0.6.dist-info → teradataml-20.0.0.0.dist-info}/RECORD +147 -391
- teradataml/analytics/mle/AdaBoost.py +0 -651
- teradataml/analytics/mle/AdaBoostPredict.py +0 -564
- teradataml/analytics/mle/Antiselect.py +0 -342
- teradataml/analytics/mle/Arima.py +0 -641
- teradataml/analytics/mle/ArimaPredict.py +0 -477
- teradataml/analytics/mle/Attribution.py +0 -1070
- teradataml/analytics/mle/Betweenness.py +0 -658
- teradataml/analytics/mle/Burst.py +0 -711
- teradataml/analytics/mle/CCM.py +0 -600
- teradataml/analytics/mle/CCMPrepare.py +0 -324
- teradataml/analytics/mle/CFilter.py +0 -460
- teradataml/analytics/mle/ChangePointDetection.py +0 -572
- teradataml/analytics/mle/ChangePointDetectionRT.py +0 -477
- teradataml/analytics/mle/Closeness.py +0 -737
- teradataml/analytics/mle/ConfusionMatrix.py +0 -420
- teradataml/analytics/mle/Correlation.py +0 -477
- teradataml/analytics/mle/Correlation2.py +0 -573
- teradataml/analytics/mle/CoxHazardRatio.py +0 -679
- teradataml/analytics/mle/CoxPH.py +0 -556
- teradataml/analytics/mle/CoxSurvival.py +0 -478
- teradataml/analytics/mle/CumulativeMovAvg.py +0 -363
- teradataml/analytics/mle/DTW.py +0 -623
- teradataml/analytics/mle/DWT.py +0 -564
- teradataml/analytics/mle/DWT2D.py +0 -599
- teradataml/analytics/mle/DecisionForest.py +0 -716
- teradataml/analytics/mle/DecisionForestEvaluator.py +0 -363
- teradataml/analytics/mle/DecisionForestPredict.py +0 -561
- teradataml/analytics/mle/DecisionTree.py +0 -830
- teradataml/analytics/mle/DecisionTreePredict.py +0 -528
- teradataml/analytics/mle/ExponentialMovAvg.py +0 -418
- teradataml/analytics/mle/FMeasure.py +0 -402
- teradataml/analytics/mle/FPGrowth.py +0 -734
- teradataml/analytics/mle/FrequentPaths.py +0 -695
- teradataml/analytics/mle/GLM.py +0 -558
- teradataml/analytics/mle/GLML1L2.py +0 -547
- teradataml/analytics/mle/GLML1L2Predict.py +0 -519
- teradataml/analytics/mle/GLMPredict.py +0 -529
- teradataml/analytics/mle/HMMDecoder.py +0 -945
- teradataml/analytics/mle/HMMEvaluator.py +0 -901
- teradataml/analytics/mle/HMMSupervised.py +0 -521
- teradataml/analytics/mle/HMMUnsupervised.py +0 -572
- teradataml/analytics/mle/Histogram.py +0 -561
- teradataml/analytics/mle/IDWT.py +0 -476
- teradataml/analytics/mle/IDWT2D.py +0 -493
- teradataml/analytics/mle/IdentityMatch.py +0 -763
- teradataml/analytics/mle/Interpolator.py +0 -918
- teradataml/analytics/mle/KMeans.py +0 -485
- teradataml/analytics/mle/KNN.py +0 -627
- teradataml/analytics/mle/KNNRecommender.py +0 -488
- teradataml/analytics/mle/KNNRecommenderPredict.py +0 -581
- teradataml/analytics/mle/LAR.py +0 -439
- teradataml/analytics/mle/LARPredict.py +0 -478
- teradataml/analytics/mle/LDA.py +0 -548
- teradataml/analytics/mle/LDAInference.py +0 -492
- teradataml/analytics/mle/LDATopicSummary.py +0 -464
- teradataml/analytics/mle/LevenshteinDistance.py +0 -450
- teradataml/analytics/mle/LinReg.py +0 -433
- teradataml/analytics/mle/LinRegPredict.py +0 -438
- teradataml/analytics/mle/MinHash.py +0 -544
- teradataml/analytics/mle/Modularity.py +0 -587
- teradataml/analytics/mle/NEREvaluator.py +0 -410
- teradataml/analytics/mle/NERExtractor.py +0 -595
- teradataml/analytics/mle/NERTrainer.py +0 -458
- teradataml/analytics/mle/NGrams.py +0 -570
- teradataml/analytics/mle/NPath.py +0 -634
- teradataml/analytics/mle/NTree.py +0 -549
- teradataml/analytics/mle/NaiveBayes.py +0 -462
- teradataml/analytics/mle/NaiveBayesPredict.py +0 -513
- teradataml/analytics/mle/NaiveBayesTextClassifier.py +0 -607
- teradataml/analytics/mle/NaiveBayesTextClassifier2.py +0 -531
- teradataml/analytics/mle/NaiveBayesTextClassifierPredict.py +0 -799
- teradataml/analytics/mle/NamedEntityFinder.py +0 -529
- teradataml/analytics/mle/NamedEntityFinderEvaluator.py +0 -414
- teradataml/analytics/mle/NamedEntityFinderTrainer.py +0 -396
- teradataml/analytics/mle/POSTagger.py +0 -417
- teradataml/analytics/mle/Pack.py +0 -411
- teradataml/analytics/mle/PageRank.py +0 -535
- teradataml/analytics/mle/PathAnalyzer.py +0 -426
- teradataml/analytics/mle/PathGenerator.py +0 -367
- teradataml/analytics/mle/PathStart.py +0 -464
- teradataml/analytics/mle/PathSummarizer.py +0 -470
- teradataml/analytics/mle/Pivot.py +0 -471
- teradataml/analytics/mle/ROC.py +0 -425
- teradataml/analytics/mle/RandomSample.py +0 -637
- teradataml/analytics/mle/RandomWalkSample.py +0 -490
- teradataml/analytics/mle/SAX.py +0 -779
- teradataml/analytics/mle/SVMDense.py +0 -677
- teradataml/analytics/mle/SVMDensePredict.py +0 -536
- teradataml/analytics/mle/SVMDenseSummary.py +0 -437
- teradataml/analytics/mle/SVMSparse.py +0 -557
- teradataml/analytics/mle/SVMSparsePredict.py +0 -553
- teradataml/analytics/mle/SVMSparseSummary.py +0 -435
- teradataml/analytics/mle/Sampling.py +0 -549
- teradataml/analytics/mle/Scale.py +0 -565
- teradataml/analytics/mle/ScaleByPartition.py +0 -496
- teradataml/analytics/mle/ScaleMap.py +0 -378
- teradataml/analytics/mle/ScaleSummary.py +0 -320
- teradataml/analytics/mle/SentenceExtractor.py +0 -363
- teradataml/analytics/mle/SentimentEvaluator.py +0 -432
- teradataml/analytics/mle/SentimentExtractor.py +0 -578
- teradataml/analytics/mle/SentimentTrainer.py +0 -405
- teradataml/analytics/mle/SeriesSplitter.py +0 -641
- teradataml/analytics/mle/Sessionize.py +0 -475
- teradataml/analytics/mle/SimpleMovAvg.py +0 -397
- teradataml/analytics/mle/StringSimilarity.py +0 -425
- teradataml/analytics/mle/TF.py +0 -389
- teradataml/analytics/mle/TFIDF.py +0 -504
- teradataml/analytics/mle/TextChunker.py +0 -414
- teradataml/analytics/mle/TextClassifier.py +0 -399
- teradataml/analytics/mle/TextClassifierEvaluator.py +0 -413
- teradataml/analytics/mle/TextClassifierTrainer.py +0 -565
- teradataml/analytics/mle/TextMorph.py +0 -494
- teradataml/analytics/mle/TextParser.py +0 -623
- teradataml/analytics/mle/TextTagger.py +0 -530
- teradataml/analytics/mle/TextTokenizer.py +0 -502
- teradataml/analytics/mle/UnivariateStatistics.py +0 -488
- teradataml/analytics/mle/Unpack.py +0 -526
- teradataml/analytics/mle/Unpivot.py +0 -438
- teradataml/analytics/mle/VarMax.py +0 -776
- teradataml/analytics/mle/VectorDistance.py +0 -762
- teradataml/analytics/mle/WeightedMovAvg.py +0 -400
- teradataml/analytics/mle/XGBoost.py +0 -842
- teradataml/analytics/mle/XGBoostPredict.py +0 -627
- teradataml/analytics/mle/__init__.py +0 -123
- teradataml/analytics/mle/json/adaboost_mle.json +0 -135
- teradataml/analytics/mle/json/adaboostpredict_mle.json +0 -85
- teradataml/analytics/mle/json/antiselect_mle.json +0 -34
- teradataml/analytics/mle/json/antiselect_mle_mle.json +0 -34
- teradataml/analytics/mle/json/arima_mle.json +0 -172
- teradataml/analytics/mle/json/arimapredict_mle.json +0 -52
- teradataml/analytics/mle/json/attribution_mle_mle.json +0 -143
- teradataml/analytics/mle/json/betweenness_mle.json +0 -97
- teradataml/analytics/mle/json/burst_mle.json +0 -140
- teradataml/analytics/mle/json/ccm_mle.json +0 -124
- teradataml/analytics/mle/json/ccmprepare_mle.json +0 -14
- teradataml/analytics/mle/json/cfilter_mle.json +0 -93
- teradataml/analytics/mle/json/changepointdetection_mle.json +0 -92
- teradataml/analytics/mle/json/changepointdetectionrt_mle.json +0 -78
- teradataml/analytics/mle/json/closeness_mle.json +0 -104
- teradataml/analytics/mle/json/confusionmatrix_mle.json +0 -79
- teradataml/analytics/mle/json/correlation_mle.json +0 -86
- teradataml/analytics/mle/json/correlationreduce_mle.json +0 -49
- teradataml/analytics/mle/json/coxhazardratio_mle.json +0 -89
- teradataml/analytics/mle/json/coxph_mle.json +0 -98
- teradataml/analytics/mle/json/coxsurvival_mle.json +0 -79
- teradataml/analytics/mle/json/cumulativemovavg_mle.json +0 -34
- teradataml/analytics/mle/json/decisionforest_mle.json +0 -167
- teradataml/analytics/mle/json/decisionforestevaluator_mle.json +0 -33
- teradataml/analytics/mle/json/decisionforestpredict_mle_mle.json +0 -74
- teradataml/analytics/mle/json/decisiontree_mle.json +0 -194
- teradataml/analytics/mle/json/decisiontreepredict_mle_mle.json +0 -86
- teradataml/analytics/mle/json/dtw_mle.json +0 -97
- teradataml/analytics/mle/json/dwt2d_mle.json +0 -116
- teradataml/analytics/mle/json/dwt_mle.json +0 -101
- teradataml/analytics/mle/json/exponentialmovavg_mle.json +0 -55
- teradataml/analytics/mle/json/fmeasure_mle.json +0 -58
- teradataml/analytics/mle/json/fpgrowth_mle.json +0 -159
- teradataml/analytics/mle/json/frequentpaths_mle.json +0 -129
- teradataml/analytics/mle/json/glm_mle.json +0 -111
- teradataml/analytics/mle/json/glml1l2_mle.json +0 -106
- teradataml/analytics/mle/json/glml1l2predict_mle.json +0 -57
- teradataml/analytics/mle/json/glmpredict_mle_mle.json +0 -74
- teradataml/analytics/mle/json/histogram_mle.json +0 -100
- teradataml/analytics/mle/json/hmmdecoder_mle.json +0 -192
- teradataml/analytics/mle/json/hmmevaluator_mle.json +0 -206
- teradataml/analytics/mle/json/hmmsupervised_mle.json +0 -91
- teradataml/analytics/mle/json/hmmunsupervised_mle.json +0 -114
- teradataml/analytics/mle/json/identitymatch_mle.json +0 -88
- teradataml/analytics/mle/json/idwt2d_mle.json +0 -73
- teradataml/analytics/mle/json/idwt_mle.json +0 -66
- teradataml/analytics/mle/json/interpolator_mle.json +0 -151
- teradataml/analytics/mle/json/kmeans_mle.json +0 -97
- teradataml/analytics/mle/json/knn_mle.json +0 -141
- teradataml/analytics/mle/json/knnrecommender_mle.json +0 -111
- teradataml/analytics/mle/json/knnrecommenderpredict_mle.json +0 -75
- teradataml/analytics/mle/json/lar_mle.json +0 -78
- teradataml/analytics/mle/json/larpredict_mle.json +0 -69
- teradataml/analytics/mle/json/lda_mle.json +0 -130
- teradataml/analytics/mle/json/ldainference_mle.json +0 -78
- teradataml/analytics/mle/json/ldatopicsummary_mle.json +0 -64
- teradataml/analytics/mle/json/levenshteindistance_mle.json +0 -92
- teradataml/analytics/mle/json/linreg_mle.json +0 -42
- teradataml/analytics/mle/json/linregpredict_mle.json +0 -56
- teradataml/analytics/mle/json/minhash_mle.json +0 -113
- teradataml/analytics/mle/json/modularity_mle.json +0 -91
- teradataml/analytics/mle/json/naivebayespredict_mle_mle.json +0 -85
- teradataml/analytics/mle/json/naivebayesreduce_mle.json +0 -52
- teradataml/analytics/mle/json/naivebayestextclassifierpredict_mle_mle.json +0 -147
- teradataml/analytics/mle/json/naivebayestextclassifiertrainer2_mle.json +0 -108
- teradataml/analytics/mle/json/naivebayestextclassifiertrainer_mle.json +0 -102
- teradataml/analytics/mle/json/namedentityfinder_mle.json +0 -84
- teradataml/analytics/mle/json/namedentityfinderevaluatorreduce_mle.json +0 -43
- teradataml/analytics/mle/json/namedentityfindertrainer_mle.json +0 -64
- teradataml/analytics/mle/json/nerevaluator_mle.json +0 -54
- teradataml/analytics/mle/json/nerextractor_mle.json +0 -87
- teradataml/analytics/mle/json/nertrainer_mle.json +0 -89
- teradataml/analytics/mle/json/ngrams_mle.json +0 -137
- teradataml/analytics/mle/json/ngramsplitter_mle_mle.json +0 -137
- teradataml/analytics/mle/json/npath@coprocessor_mle.json +0 -73
- teradataml/analytics/mle/json/ntree@coprocessor_mle.json +0 -123
- teradataml/analytics/mle/json/pack_mle.json +0 -58
- teradataml/analytics/mle/json/pack_mle_mle.json +0 -58
- teradataml/analytics/mle/json/pagerank_mle.json +0 -81
- teradataml/analytics/mle/json/pathanalyzer_mle.json +0 -63
- teradataml/analytics/mle/json/pathgenerator_mle.json +0 -40
- teradataml/analytics/mle/json/pathstart_mle.json +0 -62
- teradataml/analytics/mle/json/pathsummarizer_mle.json +0 -72
- teradataml/analytics/mle/json/pivoting_mle.json +0 -71
- teradataml/analytics/mle/json/postagger_mle.json +0 -51
- teradataml/analytics/mle/json/randomsample_mle.json +0 -131
- teradataml/analytics/mle/json/randomwalksample_mle.json +0 -85
- teradataml/analytics/mle/json/roc_mle.json +0 -73
- teradataml/analytics/mle/json/sampling_mle.json +0 -75
- teradataml/analytics/mle/json/sax_mle.json +0 -154
- teradataml/analytics/mle/json/scale_mle.json +0 -93
- teradataml/analytics/mle/json/scalebypartition_mle.json +0 -89
- teradataml/analytics/mle/json/scalemap_mle.json +0 -44
- teradataml/analytics/mle/json/scalesummary_mle.json +0 -14
- teradataml/analytics/mle/json/sentenceextractor_mle.json +0 -41
- teradataml/analytics/mle/json/sentimentevaluator_mle.json +0 -43
- teradataml/analytics/mle/json/sentimentextractor_mle.json +0 -100
- teradataml/analytics/mle/json/sentimenttrainer_mle.json +0 -68
- teradataml/analytics/mle/json/seriessplitter_mle.json +0 -133
- teradataml/analytics/mle/json/sessionize_mle_mle.json +0 -62
- teradataml/analytics/mle/json/simplemovavg_mle.json +0 -48
- teradataml/analytics/mle/json/stringsimilarity_mle.json +0 -50
- teradataml/analytics/mle/json/stringsimilarity_mle_mle.json +0 -50
- teradataml/analytics/mle/json/svmdense_mle.json +0 -165
- teradataml/analytics/mle/json/svmdensepredict_mle.json +0 -95
- teradataml/analytics/mle/json/svmdensesummary_mle.json +0 -58
- teradataml/analytics/mle/json/svmsparse_mle.json +0 -148
- teradataml/analytics/mle/json/svmsparsepredict_mle_mle.json +0 -103
- teradataml/analytics/mle/json/svmsparsesummary_mle.json +0 -57
- teradataml/analytics/mle/json/textchunker_mle.json +0 -40
- teradataml/analytics/mle/json/textclassifier_mle.json +0 -51
- teradataml/analytics/mle/json/textclassifierevaluator_mle.json +0 -43
- teradataml/analytics/mle/json/textclassifiertrainer_mle.json +0 -103
- teradataml/analytics/mle/json/textmorph_mle.json +0 -63
- teradataml/analytics/mle/json/textparser_mle.json +0 -166
- teradataml/analytics/mle/json/texttagger_mle.json +0 -81
- teradataml/analytics/mle/json/texttokenizer_mle.json +0 -91
- teradataml/analytics/mle/json/tf_mle.json +0 -33
- teradataml/analytics/mle/json/tfidf_mle.json +0 -34
- teradataml/analytics/mle/json/univariatestatistics_mle.json +0 -81
- teradataml/analytics/mle/json/unpack_mle.json +0 -91
- teradataml/analytics/mle/json/unpack_mle_mle.json +0 -91
- teradataml/analytics/mle/json/unpivoting_mle.json +0 -63
- teradataml/analytics/mle/json/varmax_mle.json +0 -176
- teradataml/analytics/mle/json/vectordistance_mle.json +0 -179
- teradataml/analytics/mle/json/weightedmovavg_mle.json +0 -48
- teradataml/analytics/mle/json/xgboost_mle.json +0 -178
- teradataml/analytics/mle/json/xgboostpredict_mle.json +0 -104
- teradataml/analytics/sqle/Antiselect.py +0 -321
- teradataml/analytics/sqle/Attribution.py +0 -603
- teradataml/analytics/sqle/DecisionForestPredict.py +0 -408
- teradataml/analytics/sqle/GLMPredict.py +0 -430
- teradataml/analytics/sqle/MovingAverage.py +0 -543
- teradataml/analytics/sqle/NGramSplitter.py +0 -548
- teradataml/analytics/sqle/NPath.py +0 -632
- teradataml/analytics/sqle/NaiveBayesTextClassifierPredict.py +0 -515
- teradataml/analytics/sqle/Pack.py +0 -388
- teradataml/analytics/sqle/SVMSparsePredict.py +0 -464
- teradataml/analytics/sqle/Sessionize.py +0 -390
- teradataml/analytics/sqle/StringSimilarity.py +0 -400
- teradataml/analytics/sqle/Unpack.py +0 -503
- teradataml/analytics/sqle/json/antiselect_sqle.json +0 -21
- teradataml/analytics/sqle/json/attribution_sqle.json +0 -92
- teradataml/analytics/sqle/json/decisionforestpredict_sqle.json +0 -48
- teradataml/analytics/sqle/json/glmpredict_sqle.json +0 -48
- teradataml/analytics/sqle/json/h2opredict_sqle.json +0 -63
- teradataml/analytics/sqle/json/movingaverage_sqle.json +0 -58
- teradataml/analytics/sqle/json/naivebayestextclassifierpredict_sqle.json +0 -76
- teradataml/analytics/sqle/json/ngramsplitter_sqle.json +0 -126
- teradataml/analytics/sqle/json/npath_sqle.json +0 -67
- teradataml/analytics/sqle/json/pack_sqle.json +0 -47
- teradataml/analytics/sqle/json/pmmlpredict_sqle.json +0 -55
- teradataml/analytics/sqle/json/sessionize_sqle.json +0 -43
- teradataml/analytics/sqle/json/stringsimilarity_sqle.json +0 -39
- teradataml/analytics/sqle/json/svmsparsepredict_sqle.json +0 -74
- teradataml/analytics/sqle/json/unpack_sqle.json +0 -80
- teradataml/catalog/model_cataloging.py +0 -980
- teradataml/config/mlengine_alias_definitions_v1.0 +0 -118
- teradataml/config/mlengine_alias_definitions_v1.1 +0 -127
- teradataml/config/mlengine_alias_definitions_v1.3 +0 -129
- teradataml/table_operators/sandbox_container_util.py +0 -643
- {teradataml-17.20.0.6.dist-info → teradataml-20.0.0.0.dist-info}/WHEEL +0 -0
- {teradataml-17.20.0.6.dist-info → teradataml-20.0.0.0.dist-info}/top_level.txt +0 -0
- {teradataml-17.20.0.6.dist-info → teradataml-20.0.0.0.dist-info}/zip-safe +0 -0
|
@@ -1,980 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""
|
|
3
|
-
Unpublished work.
|
|
4
|
-
Copyright (c) 2020 by Teradata Corporation. All rights reserved.
|
|
5
|
-
TERADATA CORPORATION CONFIDENTIAL AND TRADE SECRET
|
|
6
|
-
|
|
7
|
-
Primary Owner: Rohit.Khurd@teradata.com
|
|
8
|
-
Secondary Owner:
|
|
9
|
-
|
|
10
|
-
teradataml Model Cataloging
|
|
11
|
-
-------------------------------
|
|
12
|
-
teradataml Model Cataloging functions provide interface to manage user created models
|
|
13
|
-
generated by teradataml Analytic functions, and retrieve saved models to use with teradataml.
|
|
14
|
-
"""
|
|
15
|
-
|
|
16
|
-
import pandas as pd
|
|
17
|
-
import json
|
|
18
|
-
import warnings
|
|
19
|
-
|
|
20
|
-
from teradataml.common.constants import ModelCatalogingConstants as mac
|
|
21
|
-
from collections import OrderedDict
|
|
22
|
-
from teradataml.common.exceptions import TeradataMlException
|
|
23
|
-
from teradataml.common.garbagecollector import GarbageCollector
|
|
24
|
-
from teradataml.common.messagecodes import MessageCodes
|
|
25
|
-
from teradataml.common.messages import Messages
|
|
26
|
-
from teradataml.context.context import get_connection
|
|
27
|
-
from teradataml.common.utils import UtilFuncs, function_deprecation
|
|
28
|
-
from teradataml.dbutils.dbutils import _execute_transaction
|
|
29
|
-
from teradataml.options.display import *
|
|
30
|
-
from teradataml.utils.validators import _Validators
|
|
31
|
-
from teradataml.catalog.function_argument_mapper import _argument_mapper
|
|
32
|
-
from teradatasql import OperationalError as SqlOperationalError
|
|
33
|
-
from teradataml.dataframe.dataframe import DataFrame, in_schema
|
|
34
|
-
|
|
35
|
-
from teradataml.catalog.model_cataloging_utils import __check_if_model_cataloging_tables_exists,\
|
|
36
|
-
__check_if_model_exists, __get_model_engine, __get_current_user, __get_model_inputs_outputs,\
|
|
37
|
-
__get_model_parameters, __get_like_filter_expression_on_col, __retrieve_model_client_engine_algorithm,\
|
|
38
|
-
__retrieve_model_attributes, __retrieve_model_outputs, __get_tables_for_model, __delete_model_tableview,\
|
|
39
|
-
__retrieve_argument_and_output_map, __get_wrapper_class, __get_model_access, __retrieve_model_inputs
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
__awu = _Validators()
|
|
43
|
-
__gc = GarbageCollector()
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
# TODO: Support for type argument in all MC API's.
|
|
47
|
-
# This should be done when DLEngine support is added.
|
|
48
|
-
# type - Required Argument. Indicates the type of the model. ML Engine or DL Engine.
|
|
49
|
-
|
|
50
|
-
# TODO: Notes for save_model()
|
|
51
|
-
# 1. TODO: Add support for overwrite = True
|
|
52
|
-
#
|
|
53
|
-
@function_deprecation("future")
|
|
54
|
-
def save_model(model,
|
|
55
|
-
name,
|
|
56
|
-
description,
|
|
57
|
-
model_project=None,
|
|
58
|
-
entity_target=None,
|
|
59
|
-
performance_metrics=None):
|
|
60
|
-
"""
|
|
61
|
-
DESCRIPTION:
|
|
62
|
-
Function to save a teradataml Analytic Function model in Teradata Vantage.
|
|
63
|
-
|
|
64
|
-
PARAMETERS:
|
|
65
|
-
model:
|
|
66
|
-
Required Argument.
|
|
67
|
-
Specifies the teradataml analytic function model to be saved.
|
|
68
|
-
Types: teradataml analytic function object.
|
|
69
|
-
|
|
70
|
-
name:
|
|
71
|
-
Required Argument.
|
|
72
|
-
Specifies the unique name to identify the saved model.
|
|
73
|
-
The maximum length of the name is 128 characters.
|
|
74
|
-
Types: str
|
|
75
|
-
|
|
76
|
-
description:
|
|
77
|
-
Required Argument.
|
|
78
|
-
Specifies a note describing the model to be saved.
|
|
79
|
-
The maximum length of the description is 1024 characters.
|
|
80
|
-
Types: str
|
|
81
|
-
|
|
82
|
-
model_project:
|
|
83
|
-
Optional Argument.
|
|
84
|
-
Specifies the project that the model is associated with.
|
|
85
|
-
The maximum length of the model_project is 128 characters.
|
|
86
|
-
Types: str
|
|
87
|
-
Default Value: None
|
|
88
|
-
|
|
89
|
-
entity_target:
|
|
90
|
-
Optional Argument.
|
|
91
|
-
Specifies a group or team that the model is associated with.
|
|
92
|
-
The maximum length of the entity_target is 128 characters.
|
|
93
|
-
Types: str
|
|
94
|
-
Default Value: None
|
|
95
|
-
|
|
96
|
-
performance_metrics:
|
|
97
|
-
Optional Argument.
|
|
98
|
-
Specifies the performance metrics for the model.
|
|
99
|
-
performance_metrics must be a dictionary of the following form:
|
|
100
|
-
{ "<metric>" : { "measure" : <value> }, ... }
|
|
101
|
-
For example:
|
|
102
|
-
{ "AUC" : { "measure" : 0.5 }, ... }
|
|
103
|
-
The value should be of type float.
|
|
104
|
-
Types: dict
|
|
105
|
-
Default Value: None
|
|
106
|
-
|
|
107
|
-
RETURNS:
|
|
108
|
-
None.
|
|
109
|
-
|
|
110
|
-
RAISES:
|
|
111
|
-
TeradataMlException, TypeError, ValueError
|
|
112
|
-
|
|
113
|
-
EXAMPLES:
|
|
114
|
-
# Load the data to run the example
|
|
115
|
-
load_example_data("decisionforest", ["housing_train"])
|
|
116
|
-
|
|
117
|
-
# Create teradataml DataFrame objects.
|
|
118
|
-
housing_train = DataFrame.from_table("housing_train")
|
|
119
|
-
|
|
120
|
-
# This example uses home sales data to create a
|
|
121
|
-
# classification tree that predicts home style, which can be input
|
|
122
|
-
# to the DecisionForestPredict.
|
|
123
|
-
formula = "homestyle ~ driveway + recroom + fullbase + gashw + airco + prefarea + price + lotsize + bedrooms + bathrms + stories + garagepl"
|
|
124
|
-
rft_model = DecisionForest(data=housing_train,
|
|
125
|
-
formula = formula,
|
|
126
|
-
tree_type="classification",
|
|
127
|
-
ntree=50,
|
|
128
|
-
tree_size=100,
|
|
129
|
-
nodesize=1,
|
|
130
|
-
variance=0.0,
|
|
131
|
-
max_depth=12,
|
|
132
|
-
maxnum_categorical=20,
|
|
133
|
-
mtry=3,
|
|
134
|
-
mtry_seed=100,
|
|
135
|
-
seed=100
|
|
136
|
-
)
|
|
137
|
-
|
|
138
|
-
# Let's save this generated model.
|
|
139
|
-
save_model(model=rft_model, name="decision_forest_model", description="Decision Forest test")
|
|
140
|
-
|
|
141
|
-
"""
|
|
142
|
-
# Perform required validations for the API.
|
|
143
|
-
# Check whether Model Cataloging tables exist or not.
|
|
144
|
-
__check_if_model_cataloging_tables_exists()
|
|
145
|
-
|
|
146
|
-
# Let's perform argument validations.
|
|
147
|
-
# Create argument information matrix to do parameter checking
|
|
148
|
-
__arg_info_matrix = []
|
|
149
|
-
__arg_info_matrix.append(["name", name, False, (str), True])
|
|
150
|
-
__arg_info_matrix.append(["description", description, False, (str), True])
|
|
151
|
-
__arg_info_matrix.append(["model_project", model_project, True, (str), True])
|
|
152
|
-
__arg_info_matrix.append(["entity_target", entity_target, True, (str), True])
|
|
153
|
-
__arg_info_matrix.append(["performance_metrics", performance_metrics, True, (dict)])
|
|
154
|
-
|
|
155
|
-
# Make sure that a correct type of values has been supplied to the arguments.
|
|
156
|
-
__awu._validate_function_arguments(__arg_info_matrix)
|
|
157
|
-
|
|
158
|
-
# Check length of the model name provided by user.
|
|
159
|
-
__awu._validate_str_arg_length('name', name, 'LE', 128)
|
|
160
|
-
# Check length of the model description provided by user.
|
|
161
|
-
__awu._validate_str_arg_length('description', description, 'LE', 1024)
|
|
162
|
-
# Check length of the model project name provided by user, if not None.
|
|
163
|
-
if model_project:
|
|
164
|
-
__awu._validate_str_arg_length('model_project', model_project, 'LE', 128)
|
|
165
|
-
# Check length of the model entity target name provided by user, if not None.
|
|
166
|
-
if entity_target:
|
|
167
|
-
__awu._validate_str_arg_length('entity_target', entity_target, 'LE', 128)
|
|
168
|
-
|
|
169
|
-
# Check type of model argument. If it's not MLE or SQLE model, raise the error.
|
|
170
|
-
if not ("teradataml.analytics.mle." in str(type(model)) or "teradataml.analytics.sqle." in str(type(model))):
|
|
171
|
-
raise TypeError(Messages.get_message(MessageCodes.UNSUPPORTED_DATATYPE, ["model"],
|
|
172
|
-
["teradataml Analytic Function Object"]))
|
|
173
|
-
|
|
174
|
-
# Check if model._sql_specific_attributes is None
|
|
175
|
-
if model._get_sql_specific_attributes() is None:
|
|
176
|
-
# This means that the model is a retrieved model, and we should raise an exception here
|
|
177
|
-
raise TeradataMlException(Messages.get_message(MessageCodes.CANNOT_SAVE_RETRIEVED_MODEL),
|
|
178
|
-
MessageCodes.CANNOT_SAVE_RETRIEVED_MODEL)
|
|
179
|
-
|
|
180
|
-
# Check if model with same name exists or not, raise error if it exists.
|
|
181
|
-
__check_if_model_exists(name, raise_error_if_exists=True)
|
|
182
|
-
|
|
183
|
-
# Validations are complete. Let's move forward with model saving.
|
|
184
|
-
# We first gather the model related information.
|
|
185
|
-
generating_engine = __get_model_engine(model)
|
|
186
|
-
generating_client = mac.MODEL_TDML.value
|
|
187
|
-
algorithm = model._get_algorithm_name().lower()
|
|
188
|
-
build_time = model.get_build_time()
|
|
189
|
-
|
|
190
|
-
# Get the current user name.
|
|
191
|
-
conn = get_connection()
|
|
192
|
-
created_by = __get_current_user(conn)
|
|
193
|
-
status = mac.DEFAULT_SAVE_STATUS.value
|
|
194
|
-
access = mac.DEFAULT_SAVE_ACCESS.value
|
|
195
|
-
location = mac.MODEL_ENGINE_ADVSQL.value
|
|
196
|
-
|
|
197
|
-
# Let's get the attributes, input and output related information.
|
|
198
|
-
function_arg_map = _argument_mapper._get_function_map(engine=generating_engine,
|
|
199
|
-
function_name=algorithm)
|
|
200
|
-
vantage_version = _argument_mapper._vantage_version
|
|
201
|
-
|
|
202
|
-
training_data, training_objects, remove_tables_entries_from_gc = __get_model_inputs_outputs(model,
|
|
203
|
-
function_arg_map)
|
|
204
|
-
training_data = json.dumps(training_data)
|
|
205
|
-
training_objects = json.dumps(training_objects)
|
|
206
|
-
|
|
207
|
-
algorithm_parameters = json.dumps(__get_model_parameters(model, function_arg_map))
|
|
208
|
-
# Escape single quotes in values
|
|
209
|
-
algorithm_parameters = algorithm_parameters.replace("'", "''")
|
|
210
|
-
|
|
211
|
-
target_column = model.get_target_column()
|
|
212
|
-
prediction_type = model.get_prediction_type()
|
|
213
|
-
|
|
214
|
-
if performance_metrics:
|
|
215
|
-
performance_metrics = json.dumps(performance_metrics)
|
|
216
|
-
else:
|
|
217
|
-
performance_metrics = None
|
|
218
|
-
|
|
219
|
-
# Save the model based on the new details provided.
|
|
220
|
-
# Call the Stored Procedure to save the model.
|
|
221
|
-
# But first, find the transaction mode of the session to decide which Stored Procedure to call
|
|
222
|
-
save_sp = '{}{}'.format(mac.SAVE_MODEL.value, 'T')
|
|
223
|
-
transaction_mode = conn.dialect.get_transaction_mode(conn)
|
|
224
|
-
if transaction_mode and transaction_mode.lower() == 'a':
|
|
225
|
-
save_sp = '{}{}'.format(mac.SAVE_MODEL.value, 'A')
|
|
226
|
-
|
|
227
|
-
# Form the stored procedure call
|
|
228
|
-
sp_call = "CALL {0}('{1}',{2},'{3}',{4},'{5}'," \
|
|
229
|
-
"'{6}','{7}','{8}','{9}',{10}," \
|
|
230
|
-
"'{11}','{12}','{13}','{14}','{15}'," \
|
|
231
|
-
"'{16}','{17}','{18}',{19},{20}, SaveStatus)".format(save_sp,
|
|
232
|
-
name,
|
|
233
|
-
"'{}'".format(model_project)
|
|
234
|
-
if model_project else 'NULL',
|
|
235
|
-
description,
|
|
236
|
-
"'{}'".format(target_column)
|
|
237
|
-
if target_column else 'NULL',
|
|
238
|
-
prediction_type,
|
|
239
|
-
generating_engine,
|
|
240
|
-
generating_client,
|
|
241
|
-
vantage_version,
|
|
242
|
-
algorithm,
|
|
243
|
-
"'{}'".format(entity_target)
|
|
244
|
-
if entity_target else 'NULL',
|
|
245
|
-
build_time,
|
|
246
|
-
created_by,
|
|
247
|
-
status,
|
|
248
|
-
access,
|
|
249
|
-
location,
|
|
250
|
-
training_objects,
|
|
251
|
-
algorithm_parameters,
|
|
252
|
-
training_data,
|
|
253
|
-
"'{}'".format(performance_metrics)
|
|
254
|
-
if performance_metrics else 'NULL',
|
|
255
|
-
'NULL')
|
|
256
|
-
|
|
257
|
-
# Call the Stored Procedure
|
|
258
|
-
try:
|
|
259
|
-
_execute_transaction(sp_call)
|
|
260
|
-
except SqlOperationalError:
|
|
261
|
-
raise
|
|
262
|
-
except Exception as err:
|
|
263
|
-
raise TeradataMlException(
|
|
264
|
-
Messages.get_message(MessageCodes.MODEL_CATALOGING_OPERATION_FAILED,
|
|
265
|
-
"save",
|
|
266
|
-
"Stored Procedure call failed."),
|
|
267
|
-
MessageCodes.MODEL_CATALOGING_OPERATION_FAILED) from err
|
|
268
|
-
|
|
269
|
-
# Update Garbage collection, to remove temp table info from the garbage collector.
|
|
270
|
-
# Print the information for the user experience.
|
|
271
|
-
print("Persisting model information.")
|
|
272
|
-
# Let's remove entry for each table from Garbage Collector
|
|
273
|
-
for table_name in remove_tables_entries_from_gc:
|
|
274
|
-
dbname = UtilFuncs._teradata_unquote_arg(UtilFuncs._extract_db_name(table_name), "\"")
|
|
275
|
-
tablename = UtilFuncs._teradata_unquote_arg(UtilFuncs._extract_table_name(table_name), "\"")
|
|
276
|
-
__gc._delete_object_entry("\"{0}\".\"{1}\"".format(dbname, tablename),
|
|
277
|
-
remove_entry_from_gc_list=True)
|
|
278
|
-
|
|
279
|
-
print("Persisted table: {}".format(table_name))
|
|
280
|
-
|
|
281
|
-
# Now that we have removed entry from GC, we can safely say that model table has been persisted.
|
|
282
|
-
print("Successfully persisted model.")
|
|
283
|
-
|
|
284
|
-
@function_deprecation("future")
|
|
285
|
-
def list_models(name=None,
|
|
286
|
-
algorithm_name=None,
|
|
287
|
-
engine=None,
|
|
288
|
-
accessible=True,
|
|
289
|
-
public=False):
|
|
290
|
-
"""
|
|
291
|
-
DESCRIPTION:
|
|
292
|
-
Function to list models accessible to the user and optionally only models created by the user.
|
|
293
|
-
|
|
294
|
-
PARAMETERS:
|
|
295
|
-
name:
|
|
296
|
-
Optional Argument.
|
|
297
|
-
Specifies the search string for model name. When this argument is used,
|
|
298
|
-
all models matching the name are listed.
|
|
299
|
-
Types: str
|
|
300
|
-
|
|
301
|
-
algorithm_name:
|
|
302
|
-
Optional Argument.
|
|
303
|
-
Specifies the search string for the analytic function name. When this argument is used,
|
|
304
|
-
all models matching the algorithm_name are listed.
|
|
305
|
-
Types: str
|
|
306
|
-
|
|
307
|
-
engine:
|
|
308
|
-
Optional Argument.
|
|
309
|
-
Specifies the model generating engine as a filter.
|
|
310
|
-
Types: str
|
|
311
|
-
Permitted Values: ['ML Engine', 'Advanced SQL Engine']
|
|
312
|
-
|
|
313
|
-
accessible:
|
|
314
|
-
Optional Argument.
|
|
315
|
-
Specifies whether to list all models that the user has access to, or only the models that the user created.
|
|
316
|
-
When True, all models to which the user has access are listed.
|
|
317
|
-
When False, all models created by the user are listed.
|
|
318
|
-
Types: bool
|
|
319
|
-
Default Value: True
|
|
320
|
-
|
|
321
|
-
public:
|
|
322
|
-
Optional Argument.
|
|
323
|
-
Specifies whether to filter only those models that have public access.
|
|
324
|
-
Types: bool
|
|
325
|
-
Default Value: False
|
|
326
|
-
|
|
327
|
-
RETURNS:
|
|
328
|
-
None.
|
|
329
|
-
|
|
330
|
-
RAISES:
|
|
331
|
-
TeradataMlException, TypeError, ValueError
|
|
332
|
-
|
|
333
|
-
EXAMPLES:
|
|
334
|
-
# Load the data to run the example
|
|
335
|
-
load_example_data("decisionforest", ["housing_train"])
|
|
336
|
-
|
|
337
|
-
# Create teradataml DataFrame objects.
|
|
338
|
-
housing_train = DataFrame.from_table("housing_train")
|
|
339
|
-
|
|
340
|
-
# The examples use home sales data to create a
|
|
341
|
-
# classification tree that predicts home style, which can be input
|
|
342
|
-
# to the DecisionForestPredict.
|
|
343
|
-
formula = "homestyle ~ driveway + recroom + fullbase + gashw + airco + prefarea + price + lotsize + bedrooms + bathrms + stories + garagepl"
|
|
344
|
-
rft_model = DecisionForest(data=housing_train,
|
|
345
|
-
formula = formula,
|
|
346
|
-
tree_type="classification",
|
|
347
|
-
ntree=50,
|
|
348
|
-
tree_size=100,
|
|
349
|
-
nodesize=1,
|
|
350
|
-
variance=0.0,
|
|
351
|
-
max_depth=12,
|
|
352
|
-
maxnum_categorical=20,
|
|
353
|
-
mtry=3,
|
|
354
|
-
mtry_seed=100,
|
|
355
|
-
seed=100
|
|
356
|
-
)
|
|
357
|
-
|
|
358
|
-
# Let's save this generated model.
|
|
359
|
-
save_model(model=rft_model, name="decision_forest_model", description="Decision Forest test")
|
|
360
|
-
|
|
361
|
-
# Let's view the saved models accessible to the user
|
|
362
|
-
# Example 1 - List all models saved and accessible to the current user.
|
|
363
|
-
list_models()
|
|
364
|
-
|
|
365
|
-
# Example 2 - List models accessible to the user with name = 'decision_forest_model'
|
|
366
|
-
list_models(name = "decision_forest_model")
|
|
367
|
-
|
|
368
|
-
# Example 3 - List all models accessible to the user with algorithm name 'DecisionForest'
|
|
369
|
-
list_models(algorithm_name = "DecisionForest")
|
|
370
|
-
|
|
371
|
-
# Example 4 - List all models accessible to user with algorithm name 'DecisionForest' and model name
|
|
372
|
-
# containing string 'forest'.
|
|
373
|
-
list_models(name = "forest", algorithm_name = "DecisionForest")
|
|
374
|
-
|
|
375
|
-
# Example 5 - List all models accessible to user with algorithm name 'DecisionForest' and model generated using
|
|
376
|
-
# 'ML Engine'.
|
|
377
|
-
list_models(name = "forest", algorithm_name = "DecisionForest", engine = "ML Engine")
|
|
378
|
-
|
|
379
|
-
# Example 6 - List all models created by the user with algorithm name 'DecisionForest' and model generated using
|
|
380
|
-
# 'ML Engine' and access not set to Public.
|
|
381
|
-
list_models(name = "forest", algorithm_name = "DecisionForest", engine = "ML Engine",
|
|
382
|
-
accessible = False, public = False)
|
|
383
|
-
|
|
384
|
-
"""
|
|
385
|
-
# Perform required validations for the API.
|
|
386
|
-
# Check whether Model Cataloging tables exist or not.
|
|
387
|
-
__check_if_model_cataloging_tables_exists()
|
|
388
|
-
|
|
389
|
-
# Let's perform argument validations.
|
|
390
|
-
# Create argument information matrix to do parameter checking
|
|
391
|
-
__arg_info_matrix = []
|
|
392
|
-
__arg_info_matrix.append(["name", name, True, (str), True])
|
|
393
|
-
__arg_info_matrix.append(["algorithm_name", algorithm_name, True, (str), True])
|
|
394
|
-
__arg_info_matrix.append(["engine", engine, True, (str), True, [mac.MODEL_ENGINE_ML.value,
|
|
395
|
-
mac.MODEL_ENGINE_ADVSQL.value]])
|
|
396
|
-
__arg_info_matrix.append(["public", public, True, (bool)])
|
|
397
|
-
__arg_info_matrix.append(["accessible", accessible, True, (bool)])
|
|
398
|
-
|
|
399
|
-
# Make sure that a correct type of values has been supplied to the arguments.
|
|
400
|
-
__awu._validate_function_arguments(__arg_info_matrix)
|
|
401
|
-
|
|
402
|
-
public = False if not public else True
|
|
403
|
-
accessible = False if not accessible else True
|
|
404
|
-
|
|
405
|
-
# Let's get the required details to list down the models.
|
|
406
|
-
model_details = DataFrame(in_schema(mac.MODEL_CATALOG_DB.value, mac.MODELS_DETAILSX.value))
|
|
407
|
-
|
|
408
|
-
filter_condition = None
|
|
409
|
-
if not accessible:
|
|
410
|
-
# We shall show only models created by current user.
|
|
411
|
-
conn = get_connection()
|
|
412
|
-
current_user = __get_current_user(conn)
|
|
413
|
-
filter_condition = model_details[mac.CREATED_BY.value].str.lower() == current_user.lower()
|
|
414
|
-
|
|
415
|
-
if public:
|
|
416
|
-
# Additional filter to filter out models with PUBLIC access.
|
|
417
|
-
filter_expression = model_details[mac.MODEL_ACCESS.value] == mac.PUBLIC_ACCESS.value
|
|
418
|
-
if filter_condition:
|
|
419
|
-
filter_condition = filter_condition & filter_expression
|
|
420
|
-
else:
|
|
421
|
-
filter_condition = filter_expression
|
|
422
|
-
|
|
423
|
-
if name:
|
|
424
|
-
# Filter Expression on ModeName column.
|
|
425
|
-
# We are looking to find all rows with ModelName matching with 'name' string.
|
|
426
|
-
# This is case-insensitive look-up.
|
|
427
|
-
filter_expression = __get_like_filter_expression_on_col(model_details._metaexpr,
|
|
428
|
-
mac.MODEL_DERIVED_NAME.value, name)
|
|
429
|
-
if filter_condition:
|
|
430
|
-
filter_condition = filter_condition & filter_expression
|
|
431
|
-
else:
|
|
432
|
-
filter_condition = filter_expression
|
|
433
|
-
|
|
434
|
-
if algorithm_name:
|
|
435
|
-
# Filter Expression on ModeAlgorithm column.
|
|
436
|
-
# We are looking to find all rows with ModeAlgorithm matching with 'algorithm_name' string.
|
|
437
|
-
# This is case-insensitive look-up.
|
|
438
|
-
filter_expression = __get_like_filter_expression_on_col(model_details._metaexpr,
|
|
439
|
-
mac.MODEL_DERIVED_ALGORITHM.value,
|
|
440
|
-
algorithm_name)
|
|
441
|
-
if filter_condition:
|
|
442
|
-
filter_condition = filter_condition & filter_expression
|
|
443
|
-
else:
|
|
444
|
-
filter_condition = filter_expression
|
|
445
|
-
|
|
446
|
-
if engine is not None:
|
|
447
|
-
# Filter Expression on ModelGeneratingEngine column.
|
|
448
|
-
# We are looking to find all rows with ModelGeneratingEngine matching with 'engine' string.
|
|
449
|
-
# This is case-insensitive look-up.
|
|
450
|
-
filter_expression = __get_like_filter_expression_on_col(model_details._metaexpr,
|
|
451
|
-
mac.MODEL_DERIVED_GENENG.value,
|
|
452
|
-
engine)
|
|
453
|
-
if filter_condition:
|
|
454
|
-
filter_condition = filter_condition & filter_expression
|
|
455
|
-
else:
|
|
456
|
-
filter_condition = filter_expression
|
|
457
|
-
|
|
458
|
-
if filter_condition:
|
|
459
|
-
model_details = model_details[filter_condition]
|
|
460
|
-
|
|
461
|
-
display_df = model_details.select(mac.MODEL_LIST_LIST.value)
|
|
462
|
-
if display_df.shape[0] != 0:
|
|
463
|
-
orig_max_rows_num = display.max_rows
|
|
464
|
-
try:
|
|
465
|
-
display.max_rows = 99999
|
|
466
|
-
print(display_df)
|
|
467
|
-
except Exception:
|
|
468
|
-
raise
|
|
469
|
-
finally:
|
|
470
|
-
display.max_rows = orig_max_rows_num
|
|
471
|
-
else:
|
|
472
|
-
# If any of the non-default search-criterion were provided.
|
|
473
|
-
if name is not None or algorithm_name is not None or engine is not None \
|
|
474
|
-
or not accessible or public:
|
|
475
|
-
# MODEL_WITH_SEARCH_CRITERION_NOT_FOUND
|
|
476
|
-
raise TeradataMlException(
|
|
477
|
-
Messages.get_message(MessageCodes.MODEL_WITH_SEARCH_CRITERION_NOT_FOUND),
|
|
478
|
-
MessageCodes.MODEL_WITH_SEARCH_CRITERION_NOT_FOUND)
|
|
479
|
-
else:
|
|
480
|
-
# Since no search-criterion were provided by the user,
|
|
481
|
-
# we print a simple message.
|
|
482
|
-
print("No models found.")
|
|
483
|
-
|
|
484
|
-
@function_deprecation("future")
|
|
485
|
-
def describe_model(name):
|
|
486
|
-
"""
|
|
487
|
-
DESCRIPTION:
|
|
488
|
-
List details of the model, if accessible to the user.
|
|
489
|
-
|
|
490
|
-
PARAMETERS:
|
|
491
|
-
name:
|
|
492
|
-
Required Argument.
|
|
493
|
-
Specifies the name of the model to list the details for.
|
|
494
|
-
Types: str
|
|
495
|
-
|
|
496
|
-
RETURNS:
|
|
497
|
-
None.
|
|
498
|
-
|
|
499
|
-
RAISES:
|
|
500
|
-
TeradataMlException, TypeError, ValueError
|
|
501
|
-
|
|
502
|
-
EXAMPLES:
|
|
503
|
-
# Load the data to run the example
|
|
504
|
-
load_example_data("decisionforest", ["housing_train"])
|
|
505
|
-
|
|
506
|
-
# Create teradataml DataFrame objects.
|
|
507
|
-
housing_train = DataFrame.from_table("housing_train")
|
|
508
|
-
|
|
509
|
-
# This example uses home sales data to create a
|
|
510
|
-
# classification tree that predicts home style, which can be input
|
|
511
|
-
# to the DecisionForestPredict.
|
|
512
|
-
formula = "homestyle ~ driveway + recroom + fullbase + gashw + airco + prefarea + price + lotsize + bedrooms + bathrms + stories + garagepl"
|
|
513
|
-
rft_model = DecisionForest(data=housing_train,
|
|
514
|
-
formula = formula,
|
|
515
|
-
tree_type="classification",
|
|
516
|
-
ntree=50,
|
|
517
|
-
tree_size=100,
|
|
518
|
-
nodesize=1,
|
|
519
|
-
variance=0.0,
|
|
520
|
-
max_depth=12,
|
|
521
|
-
maxnum_categorical=20,
|
|
522
|
-
mtry=3,
|
|
523
|
-
mtry_seed=100,
|
|
524
|
-
seed=100
|
|
525
|
-
)
|
|
526
|
-
|
|
527
|
-
# Let's save this generated model.
|
|
528
|
-
save_model(model=rft_model, name="decision_forest_model", description="Decision Forest test")
|
|
529
|
-
|
|
530
|
-
# List all details of recently saved model 'decision_forest_model'.
|
|
531
|
-
describe_model(name="decision_forest_model")
|
|
532
|
-
|
|
533
|
-
"""
|
|
534
|
-
# Perform required validations for the API.
|
|
535
|
-
# Check whether Model Cataloging tables exist or not.
|
|
536
|
-
__check_if_model_cataloging_tables_exists()
|
|
537
|
-
|
|
538
|
-
# Let's perform argument validations.
|
|
539
|
-
# Create argument information matrix to do parameter checking
|
|
540
|
-
__arg_info_matrix = []
|
|
541
|
-
__arg_info_matrix.append(["name", name, False, (str), True])
|
|
542
|
-
|
|
543
|
-
# Make sure that a correct type of values has been supplied to the arguments.
|
|
544
|
-
__awu._validate_function_arguments(__arg_info_matrix)
|
|
545
|
-
|
|
546
|
-
# Let's get the required details to list down the models.
|
|
547
|
-
# We shall show only model accessible by current user.
|
|
548
|
-
__check_if_model_exists(name, accessible=True, raise_error_if_model_not_found=True)
|
|
549
|
-
|
|
550
|
-
df_info_mapper = OrderedDict({mac.MODELS_DETAILS.value: "Model Details",
|
|
551
|
-
mac.MODELS_ATTRS.value: "Model Attributes",
|
|
552
|
-
mac.MODELS_INPUTSX.value: "Model Training Data",
|
|
553
|
-
mac.MODELS_OBJECTS.value: "Model Training Objects",
|
|
554
|
-
mac.MODELS_PERF.value: "Model Performance Metrics",
|
|
555
|
-
mac.MODELS_LOC.value: "Model Location Based Information"
|
|
556
|
-
})
|
|
557
|
-
|
|
558
|
-
for info_table, description in df_info_mapper.items():
|
|
559
|
-
display_df = None
|
|
560
|
-
if info_table in [mac.MODELS_OBJECTS.value, mac.MODELS_ATTRS.value, mac.MODELS_INPUTSX.value]:
|
|
561
|
-
model_client, model_engine, model_algorithm = __retrieve_model_client_engine_algorithm(name)
|
|
562
|
-
function_arg_map = _argument_mapper._get_function_map(engine=model_engine,
|
|
563
|
-
function_name=model_algorithm.lower())
|
|
564
|
-
if info_table == mac.MODELS_OBJECTS.value:
|
|
565
|
-
# Output Information.
|
|
566
|
-
# We wish to display teradataml relevant information, so we get that using this function call
|
|
567
|
-
# instead of directly reading the underlying view.
|
|
568
|
-
display_df = __retrieve_model_outputs(name, model_client, function_arg_map)
|
|
569
|
-
elif info_table == mac.MODELS_ATTRS.value:
|
|
570
|
-
# Attribute Information.
|
|
571
|
-
# We wish to display teradataml relevant information, so we get that using this function call
|
|
572
|
-
# instead of directly reading the underlying view.
|
|
573
|
-
model_parameters = __retrieve_model_attributes(name, model_client, function_arg_map)[0]
|
|
574
|
-
attr_name = [key for key in model_parameters.keys()]
|
|
575
|
-
attr_value = [model_parameters[key] for key in attr_name]
|
|
576
|
-
display_df = pd.DataFrame({'AttrName': attr_name, 'AttrValue': attr_value})
|
|
577
|
-
else:
|
|
578
|
-
# Input data Information.
|
|
579
|
-
# We wish to display teradataml relevant information, so we get that using this function call
|
|
580
|
-
# instead of directly reading the underlying view.
|
|
581
|
-
model_inputs = __retrieve_model_inputs(name, model_client, function_arg_map)
|
|
582
|
-
input_name = [key for key in model_inputs.keys()]
|
|
583
|
-
table_name = [model_inputs[key][mac.MODEL_OBJ_TABLE_NAME.value] for key in input_name]
|
|
584
|
-
nrows = [model_inputs[key][mac.MODEL_INPUT_NROWS.value] for key in input_name]
|
|
585
|
-
ncols = [model_inputs[key][mac.MODEL_INPUT_NCOLS.value] for key in input_name]
|
|
586
|
-
display_df = pd.DataFrame({'InputName': input_name,
|
|
587
|
-
'InputTableName': table_name,
|
|
588
|
-
'NRows': nrows,
|
|
589
|
-
'NCols': ncols})
|
|
590
|
-
else:
|
|
591
|
-
display_df = DataFrame(in_schema(mac.MODEL_CATALOG_DB.value, info_table))
|
|
592
|
-
display_df = display_df[display_df[mac.MODEL_DERIVED_NAME.value] == name].to_pandas()
|
|
593
|
-
|
|
594
|
-
if info_table == mac.MODELS_DETAILS.value:
|
|
595
|
-
# We do a transpose of the Model Details to provide better readability of
|
|
596
|
-
# the ouptut since it is one record with multiple columns.
|
|
597
|
-
display_df = display_df.set_index(mac.MODEL_DERIVED_NAME.value).transpose()
|
|
598
|
-
else:
|
|
599
|
-
# Otherwise, we remove the 'ModelName' column from the
|
|
600
|
-
# projection which is redundant.
|
|
601
|
-
cols = display_df.columns.tolist()
|
|
602
|
-
cols.remove(mac.MODEL_DERIVED_NAME.value)
|
|
603
|
-
display_df = display_df[cols]
|
|
604
|
-
|
|
605
|
-
if display_df.shape[0] > 0:
|
|
606
|
-
# Set the max_rows parameter to a fairly high value
|
|
607
|
-
orig_max_rows_num = display.max_rows
|
|
608
|
-
try:
|
|
609
|
-
display.max_rows = 99999
|
|
610
|
-
|
|
611
|
-
# Print the relevant information for the model
|
|
612
|
-
print("\n\n*** '{}': {} ***".format(name, description))
|
|
613
|
-
print(display_df)
|
|
614
|
-
except Exception:
|
|
615
|
-
raise
|
|
616
|
-
finally:
|
|
617
|
-
# Reset the max_rows parameter to it's original value
|
|
618
|
-
display.max_rows = orig_max_rows_num
|
|
619
|
-
|
|
620
|
-
@function_deprecation("future")
|
|
621
|
-
def delete_model(name, delete_objects=False):
|
|
622
|
-
"""
|
|
623
|
-
DESCRIPTION:
|
|
624
|
-
Delete a model, and optionally delete the model objects.
|
|
625
|
-
A model can be deleted only by the creator of the model.
|
|
626
|
-
|
|
627
|
-
PARAMETERS:
|
|
628
|
-
name:
|
|
629
|
-
Required Argument.
|
|
630
|
-
Specifies the name of the model to be deleted.
|
|
631
|
-
Types: str
|
|
632
|
-
|
|
633
|
-
delete_objects:
|
|
634
|
-
Optional Argument.
|
|
635
|
-
Specifies whether to drop the model objects also.
|
|
636
|
-
When True, the model objects related to the model are deleted/dropped.
|
|
637
|
-
Types: bool
|
|
638
|
-
Default Value: False
|
|
639
|
-
|
|
640
|
-
RETURNS:
|
|
641
|
-
None.
|
|
642
|
-
|
|
643
|
-
RAISES:
|
|
644
|
-
TeradataMlException, TypeError, ValueError
|
|
645
|
-
|
|
646
|
-
EXAMPLES:
|
|
647
|
-
# Load the data to run the example
|
|
648
|
-
load_example_data("decisionforest", ["housing_train"])
|
|
649
|
-
|
|
650
|
-
# Create teradataml DataFrame objects.
|
|
651
|
-
housing_train = DataFrame.from_table("housing_train")
|
|
652
|
-
|
|
653
|
-
# The examples use home sales data to create a
|
|
654
|
-
# classification tree that predicts home style, which can be input
|
|
655
|
-
# to the DecisionForestPredict.
|
|
656
|
-
formula = "homestyle ~ driveway + recroom + fullbase + gashw + airco + prefarea + price + lotsize + bedrooms + bathrms + stories + garagepl"
|
|
657
|
-
rft_model = DecisionForest(data=housing_train,
|
|
658
|
-
formula = formula,
|
|
659
|
-
tree_type="classification",
|
|
660
|
-
ntree=50,
|
|
661
|
-
tree_size=100,
|
|
662
|
-
nodesize=1,
|
|
663
|
-
variance=0.0,
|
|
664
|
-
max_depth=12,
|
|
665
|
-
maxnum_categorical=20,
|
|
666
|
-
mtry=3,
|
|
667
|
-
mtry_seed=100,
|
|
668
|
-
seed=100
|
|
669
|
-
)
|
|
670
|
-
|
|
671
|
-
# Let's save this generated model.
|
|
672
|
-
save_model(model=rft_model, name="decision_forest_model", description="Decision Forest test")
|
|
673
|
-
|
|
674
|
-
# Example 1 - Only delete model information from the Model Catalog.
|
|
675
|
-
delete_model('decision_forest_model')
|
|
676
|
-
|
|
677
|
-
# Example 2 - Delete model information from the Model Catalog and drop model objects as well.
|
|
678
|
-
delete_model('decision_forest_model', True)
|
|
679
|
-
"""
|
|
680
|
-
# Perform required validations for the API.
|
|
681
|
-
# Check whether Model Cataloging tables exist or not.
|
|
682
|
-
__check_if_model_cataloging_tables_exists()
|
|
683
|
-
|
|
684
|
-
# Let's perform argument validations.
|
|
685
|
-
# Create argument information matrix to do parameter checking
|
|
686
|
-
__arg_info_matrix = []
|
|
687
|
-
__arg_info_matrix.append(["name", name, False, (str), True])
|
|
688
|
-
__arg_info_matrix.append(["delete_objects", delete_objects, True, (bool)])
|
|
689
|
-
|
|
690
|
-
# Make sure that a correct type of values has been supplied to the arguments.
|
|
691
|
-
__awu._validate_function_arguments(__arg_info_matrix)
|
|
692
|
-
|
|
693
|
-
# Let's check if the user created the model since only the creator can delete it
|
|
694
|
-
__check_if_model_exists(name, created=True, raise_error_if_model_not_found=True)
|
|
695
|
-
|
|
696
|
-
conn = get_connection()
|
|
697
|
-
current_user = __get_current_user(conn)
|
|
698
|
-
|
|
699
|
-
# Get the models tables for the given model
|
|
700
|
-
model_tables = __get_tables_for_model(name, current_user)
|
|
701
|
-
|
|
702
|
-
# First, find the transaction mode of the session to decide which Stored Procedure to call
|
|
703
|
-
delete_sp = '{}{}'.format(mac.DELETE_MODEL.value, 'T')
|
|
704
|
-
transaction_mode = conn.dialect.get_transaction_mode(conn)
|
|
705
|
-
if transaction_mode and transaction_mode.lower() == 'a':
|
|
706
|
-
delete_sp = '{}{}'.format(mac.DELETE_MODEL.value, 'A')
|
|
707
|
-
|
|
708
|
-
# Form the stored procedure call
|
|
709
|
-
sp_call = "CALL {0}('{1}', DeleteStatus)".format(delete_sp, name)
|
|
710
|
-
|
|
711
|
-
# Call the stored Procedure after any grant statements and only if they were successful
|
|
712
|
-
try:
|
|
713
|
-
# Call the Stored Procedure
|
|
714
|
-
_execute_transaction(sp_call)
|
|
715
|
-
except SqlOperationalError:
|
|
716
|
-
raise
|
|
717
|
-
except Exception as ex:
|
|
718
|
-
raise TeradataMlException(
|
|
719
|
-
Messages.get_message(MessageCodes.MODEL_CATALOGING_OPERATION_FAILED,
|
|
720
|
-
"delete",
|
|
721
|
-
"Stored Procedure call failed."),
|
|
722
|
-
MessageCodes.MODEL_CATALOGING_OPERATION_FAILED) from ex
|
|
723
|
-
|
|
724
|
-
print("Deleted model '{}' successfully.".format(name))
|
|
725
|
-
|
|
726
|
-
if delete_objects:
|
|
727
|
-
failed_to_drop = []
|
|
728
|
-
for table_name in model_tables:
|
|
729
|
-
if not __delete_model_tableview(table_name):
|
|
730
|
-
failed_to_drop.append(table_name)
|
|
731
|
-
if len(failed_to_drop) > 0:
|
|
732
|
-
warnings.warn('Failed to drop the following Model Objects: {}.'.format(failed_to_drop))
|
|
733
|
-
else:
|
|
734
|
-
print("Model Objects dropped successfully.")
|
|
735
|
-
else:
|
|
736
|
-
print('Model Objects that can be dropped: {}.'.format(model_tables))
|
|
737
|
-
|
|
738
|
-
@function_deprecation("future")
|
|
739
|
-
def retrieve_model(name):
|
|
740
|
-
"""
|
|
741
|
-
DESCRIPTION:
|
|
742
|
-
Function to retrieve a saved model accessible to the current user.
|
|
743
|
-
|
|
744
|
-
PARAMETERS:
|
|
745
|
-
name:
|
|
746
|
-
Required Argument.
|
|
747
|
-
Specifies the name of the model to retrieve.
|
|
748
|
-
Types: str
|
|
749
|
-
|
|
750
|
-
RETURNS:
|
|
751
|
-
The Analytic function object corresponding to the model retrieved.
|
|
752
|
-
|
|
753
|
-
RAISES:
|
|
754
|
-
TeradataMlException, TypeError, ValueError
|
|
755
|
-
|
|
756
|
-
EXAMPLES:
|
|
757
|
-
# Load the data to run the example
|
|
758
|
-
load_example_data("decisionforestpredict", ["housing_train","housing_test"])
|
|
759
|
-
|
|
760
|
-
# Create teradataml DataFrame objects.
|
|
761
|
-
housing_train = DataFrame.from_table("housing_train")
|
|
762
|
-
housing_test = DataFrame.from_table("housing_test")
|
|
763
|
-
|
|
764
|
-
# This example uses home sales data to create a
|
|
765
|
-
# classification tree that predicts home style, which can be input
|
|
766
|
-
# to the DecisionForestPredict.
|
|
767
|
-
formula = "homestyle ~ driveway + recroom + fullbase + gashw + airco + prefarea + price + lotsize + bedrooms + bathrms + stories + garagepl"
|
|
768
|
-
rft_model = DecisionForest(data=housing_train,
|
|
769
|
-
formula = formula,
|
|
770
|
-
tree_type="classification",
|
|
771
|
-
ntree=50,
|
|
772
|
-
tree_size=100,
|
|
773
|
-
nodesize=1,
|
|
774
|
-
variance=0.0,
|
|
775
|
-
max_depth=12,
|
|
776
|
-
maxnum_categorical=20,
|
|
777
|
-
mtry=3,
|
|
778
|
-
mtry_seed=100,
|
|
779
|
-
seed=100
|
|
780
|
-
)
|
|
781
|
-
|
|
782
|
-
# Let's save this generated model.
|
|
783
|
-
save_model(model=rft_model, name="decision_forest_model", description="Decision Forest test")
|
|
784
|
-
|
|
785
|
-
# Retrieve the saved model.
|
|
786
|
-
retrieved_rft_model = retrieve_model("decision_forest_model")
|
|
787
|
-
|
|
788
|
-
# Use the retrieved model in predict.
|
|
789
|
-
decision_forest_predict_out = DecisionForestPredict(object = retrieved_rft_model,
|
|
790
|
-
newdata = housing_test,
|
|
791
|
-
id_column = "sn",
|
|
792
|
-
detailed = False,
|
|
793
|
-
terms = ["homestyle"],
|
|
794
|
-
newdata_order_column=['sn', 'price'],
|
|
795
|
-
object_order_column=['worker_ip', 'task_index']
|
|
796
|
-
)
|
|
797
|
-
|
|
798
|
-
# Print the results.
|
|
799
|
-
decision_forest_predict_out.result
|
|
800
|
-
"""
|
|
801
|
-
# Perform required validations for the API.
|
|
802
|
-
# Check whether Model Cataloging tables exist or not.
|
|
803
|
-
__check_if_model_cataloging_tables_exists()
|
|
804
|
-
|
|
805
|
-
# Let's perform argument validations.
|
|
806
|
-
# Create argument information matrix to do parameter checking
|
|
807
|
-
__arg_info_matrix = []
|
|
808
|
-
__arg_info_matrix.append(["name", name, False, (str), True])
|
|
809
|
-
|
|
810
|
-
# Make sure that a correct type of values has been supplied to the arguments.
|
|
811
|
-
__awu._validate_function_arguments(__arg_info_matrix)
|
|
812
|
-
|
|
813
|
-
# We shall show only retrieve models accessible by current user.
|
|
814
|
-
# Let's first make sure, whether such model with name exists or not.
|
|
815
|
-
__check_if_model_exists(name, accessible=True, raise_error_if_model_not_found=True)
|
|
816
|
-
|
|
817
|
-
# Let's read model attributes and their values/output tables.
|
|
818
|
-
model_class, model_engine, attr_and_output_dictionary = __retrieve_argument_and_output_map(name)
|
|
819
|
-
|
|
820
|
-
# Get wrapper class for which model is to be instantiated. We shall later use the same to instantiate the
|
|
821
|
-
# wrapper.
|
|
822
|
-
class_ = __get_wrapper_class(model_engine, model_class)
|
|
823
|
-
|
|
824
|
-
# Let's instantiate model class and return the model of CLASS model_class.
|
|
825
|
-
# But first we make sure the keys are strings
|
|
826
|
-
new_dict = {}
|
|
827
|
-
for key in attr_and_output_dictionary:
|
|
828
|
-
val = attr_and_output_dictionary[key]
|
|
829
|
-
if not isinstance(key, str):
|
|
830
|
-
key = str(key)
|
|
831
|
-
|
|
832
|
-
new_dict[key] = val
|
|
833
|
-
|
|
834
|
-
return class_._from_model_catalog(**new_dict)
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
# TODO: For publish model
|
|
838
|
-
# 1. Should have a way to issue GRANTs/REVOKEs
|
|
839
|
-
# 2. Should also have a way to undo the publish operation (revoke access) and set access to Private
|
|
840
|
-
# or a different role/user.
|
|
841
|
-
# Need to get a list of users who already have access to it
|
|
842
|
-
@function_deprecation("future")
|
|
843
|
-
def publish_model(name, grantee=None, status=None):
|
|
844
|
-
"""
|
|
845
|
-
DESCRIPTION:
|
|
846
|
-
Function to publish a model.
|
|
847
|
-
It can be used to update the access level from PRIVATE to PUBLIC or TEAM.
|
|
848
|
-
It can also be used to update the status of the model to one of the expected values.
|
|
849
|
-
A model can be published only by the creator of the model.
|
|
850
|
-
|
|
851
|
-
PARAMETERS:
|
|
852
|
-
name:
|
|
853
|
-
Required Argument.
|
|
854
|
-
Specifies the name of the model to be published.
|
|
855
|
-
Types: str
|
|
856
|
-
|
|
857
|
-
grantee:
|
|
858
|
-
Optional Argument. Must be specified when status is not specified.
|
|
859
|
-
Specifies a user or role (including PUBLIC) to update the model's access level to.
|
|
860
|
-
Types: str
|
|
861
|
-
|
|
862
|
-
status:
|
|
863
|
-
Optional Argument. Must be specified when grantee is not specified.
|
|
864
|
-
Specify a string to set the status of the model to.
|
|
865
|
-
Types: str
|
|
866
|
-
Permitted Values: ['ACTIVE', 'RETIRED', 'CANDIDATE', 'PRODUCTION', 'IN-DEVELOPMENT']
|
|
867
|
-
|
|
868
|
-
RETURNS:
|
|
869
|
-
None.
|
|
870
|
-
|
|
871
|
-
RAISES:
|
|
872
|
-
TeradataMlException, TypeError, ValueError
|
|
873
|
-
|
|
874
|
-
EXAMPLES:
|
|
875
|
-
# Load the data to run the example
|
|
876
|
-
load_example_data("decisionforest", ["housing_train"])
|
|
877
|
-
|
|
878
|
-
# Create teradataml DataFrame objects.
|
|
879
|
-
housing_train = DataFrame.from_table("housing_train")
|
|
880
|
-
|
|
881
|
-
# The examples use home sales data to create a
|
|
882
|
-
# classification tree that predicts home style, which can be input
|
|
883
|
-
# to the DecisionForestPredict.
|
|
884
|
-
formula = "homestyle ~ driveway + recroom + fullbase + gashw + airco + prefarea + price + lotsize + bedrooms + bathrms + stories + garagepl"
|
|
885
|
-
rft_model = DecisionForest(data=housing_train,
|
|
886
|
-
formula = formula,
|
|
887
|
-
tree_type="classification",
|
|
888
|
-
ntree=50,
|
|
889
|
-
tree_size=100,
|
|
890
|
-
nodesize=1,
|
|
891
|
-
variance=0.0,
|
|
892
|
-
max_depth=12,
|
|
893
|
-
maxnum_categorical=20,
|
|
894
|
-
mtry=3,
|
|
895
|
-
mtry_seed=100,
|
|
896
|
-
seed=100
|
|
897
|
-
)
|
|
898
|
-
|
|
899
|
-
# Let's save this generated model.
|
|
900
|
-
save_model(model=rft_model, name="decision_forest_model", description="Decision Forest test")
|
|
901
|
-
|
|
902
|
-
# Example 1 - Update only the access.
|
|
903
|
-
publish_model('decision_forest_model', grantee='john')
|
|
904
|
-
|
|
905
|
-
# Example 2 - Update only the status.
|
|
906
|
-
publish_model('decision_forest_model', status='Active')
|
|
907
|
-
|
|
908
|
-
# Example 3 - Update both the access and status.
|
|
909
|
-
publish_model('decision_forest_model', grantee='PUBLIC', status='Production')
|
|
910
|
-
"""
|
|
911
|
-
# Perform required validations for the API.
|
|
912
|
-
# Check whether Model Cataloging tables exist or not.
|
|
913
|
-
__check_if_model_cataloging_tables_exists()
|
|
914
|
-
|
|
915
|
-
# Let's perform argument validations.
|
|
916
|
-
# Create argument information matrix to do parameter checking
|
|
917
|
-
__arg_info_matrix = []
|
|
918
|
-
__arg_info_matrix.append(["name", name, False, (str), True])
|
|
919
|
-
__arg_info_matrix.append(["grantee", grantee, True, (str), True])
|
|
920
|
-
__arg_info_matrix.append(["status", status, True, (str), True, mac.MODEL_VALID_STATUS.value])
|
|
921
|
-
|
|
922
|
-
# Make sure that a correct type of values has been supplied to the arguments.
|
|
923
|
-
__awu._validate_function_arguments(__arg_info_matrix)
|
|
924
|
-
|
|
925
|
-
# Both grantee and status cannot be null
|
|
926
|
-
if grantee is None and status is None:
|
|
927
|
-
raise TeradataMlException(Messages.get_message(MessageCodes.EITHER_THIS_OR_THAT_ARGUMENT, "grantee", "status"),
|
|
928
|
-
MessageCodes.EITHER_THIS_OR_THAT_ARGUMENT)
|
|
929
|
-
|
|
930
|
-
# Let's check if the user created the model since only the creator can publish it
|
|
931
|
-
__check_if_model_exists(name, created=True, raise_error_if_model_not_found=True)
|
|
932
|
-
|
|
933
|
-
conn = get_connection()
|
|
934
|
-
|
|
935
|
-
# First, find the transaction mode of the session to decide which Stored Procedure to call
|
|
936
|
-
publish_sp = '{}{}'.format(mac.PUBLISH_MODEL.value, 'T')
|
|
937
|
-
transaction_mode = conn.dialect.get_transaction_mode(conn)
|
|
938
|
-
if transaction_mode and transaction_mode.lower() == 'a':
|
|
939
|
-
publish_sp = '{}{}'.format(mac.PUBLISH_MODEL.value, 'A')
|
|
940
|
-
|
|
941
|
-
print_message = None
|
|
942
|
-
current_user = __get_current_user(conn)
|
|
943
|
-
old_access = __get_model_access(name)
|
|
944
|
-
# Update the access only when we have a grantee that is not the same as the current user or 'private',
|
|
945
|
-
# and when the current access level is PRIVATE.
|
|
946
|
-
if grantee is not None and grantee.lower() != current_user.lower() \
|
|
947
|
-
and grantee.lower() != 'private' and old_access.lower() == 'private':
|
|
948
|
-
grant_list = __get_tables_for_model(name, current_user)
|
|
949
|
-
|
|
950
|
-
print_message = "Please execute the following GRANT statements:\n{}".format(
|
|
951
|
-
'\n'.join('GRANT SELECT ON {} to {};'.format(obj, grantee) for obj in grant_list))
|
|
952
|
-
elif grantee is not None:
|
|
953
|
-
warnings.warn("'grantee' must not be equal '{0}' or the current user's name,"
|
|
954
|
-
" and the earlier access level must be '{0}'.".format(mac.DEFAULT_SAVE_ACCESS.value))
|
|
955
|
-
# Set grantee to None so that it is not passed in stored procedure
|
|
956
|
-
grantee = None
|
|
957
|
-
|
|
958
|
-
# Call the stored procedure after any grant statements and only if they were successful
|
|
959
|
-
# Form the stored procedure call
|
|
960
|
-
sp_call = "CALL {0}('{1}',{2},{3}, PublishStatus)".format(publish_sp,
|
|
961
|
-
name,
|
|
962
|
-
"'{}'".format(grantee) if grantee else 'NULL',
|
|
963
|
-
"'{}'".format(status) if status else 'NULL'
|
|
964
|
-
)
|
|
965
|
-
|
|
966
|
-
try:
|
|
967
|
-
# Call the Stored Procedure
|
|
968
|
-
_execute_transaction(sp_call)
|
|
969
|
-
except SqlOperationalError:
|
|
970
|
-
raise
|
|
971
|
-
except Exception as ex:
|
|
972
|
-
raise TeradataMlException(
|
|
973
|
-
Messages.get_message(MessageCodes.MODEL_CATALOGING_OPERATION_FAILED,
|
|
974
|
-
"publish",
|
|
975
|
-
"Stored Procedure call failed."),
|
|
976
|
-
MessageCodes.MODEL_CATALOGING_OPERATION_FAILED) from ex
|
|
977
|
-
|
|
978
|
-
print("Model published successfully!")
|
|
979
|
-
if print_message:
|
|
980
|
-
print(print_message)
|