<jupyter_start><jupyter_text>Publish Model to Data Catalog<jupyter_code># First, let's verify that the sparktk libraries are installed
import sparktk
print "sparktk installation path = %s" % (sparktk.__path__)
# This notebook assumes you have already created a credentials file.
# Enter the path here to connect to ATK
from sparktk import TkContext
tc = TkContext()
# Create a new frame by uploading rows
data = [ [4.9,1.4,0], 
        [4.7,1.3,0], 
        [4.6,1.5,0], 
        [6.3,4.9,1],
        [6.1,4.7,1], 
        [6.4,4.3,1], 
        [6.6,4.4,1], 
        [7.2,6.0,2],
        [7.2,5.8,2], 
        [7.4,6.1,2], 
        [7.9,6.4,2]]

schema = [('Sepal_Length', float),
          ('Petal_Length', float),
          ('Class', int)]
frame = tc.frame.create(data, schema)
# Consider the following frame containing three columns.
frame.inspect()
# Create a new model and train it
model = tc.models.classification.naive_bayes.train(frame, ['Sepal_Length', 'Petal_Length'], 'Class')
# Export the trained model to MAR format
model.export_to_mar("hdfs://nameservice1/user/hadoop/example_naive_bayes_model.mar")
# Import Data Catalog client module from tap_catalog
from tap_catalog import DataCatalog
# Create an instance of Data Catalog
## data_catalog = DataCatalog('TAP_DOMAIN_URI', 'TAP_USERNAME', 'TAP_PASSWORD') # For Scripting purposes
data_catalog = DataCatalog()
# Add an entry to Data Catalog
data_catalog.add("/user/hadoop/example_naive_bayes_model.mar")
# Inspect HDFS directly using hdfsclient

import hdfsclient
from hdfsclient import ls, mkdir, rm, mv
ls("/user/hadoop/example_naive_bayes_model.mar")
# Cleanup the file from HDFS
## (This does not delete from data catalog. Remember to delete it from the Data Catalog UI)
rm("/user/hadoop/example_naive_bayes_model.mar")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12383048981838195, 'fraction_numerical': 0.030820033021463952, 'mean_word_length': 4.05, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '272859', 'license': 'Apache-2.0', 'n_tokens_mistral': 646, 'n_tokens_neox': 622, 'n_words': 173, 'path': 'jupyter-default-notebooks/notebooks/examples/tklibs/sparktk/data-catalog-example.ipynb', 'repo_name': 'trustedanalytics/clear-jupyter', 'size': '1817'}