Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Python wrappers of Cortana Analytics services

Project Description

This a Python library for using Microsoft Azure Datamarket and Cortana Analytics Services.


To install, use pip:

pip install cortanaanalytics

You can also get the development versions directly from the GitHub repo:

Getting Started

Cortana Analytics has many different packages. Please look at each section for the library you are interested in.

Also, you will need obtain an access key from the Azure Datamarket and subscribe to the service you wish to use.

Text Analytics

from cortanaanalytics.textanalytics import TextAnalytics

key = '1abCdEFGh/ijKlmN/opq234r56st/UvWXYZabCD7EF8='
ta = TextAnalytics(key)

score = ta.get_sentiment("hello world")

scores = ta.get_sentiment_batch([{"Text":"hello world", "Id":0}, {"Text":"hello world again", "Id":2}])


from cortanaanalytics.recommendations import Recommendations

email = ''
key = '1abCdEFGh/ijKlmN/opq234r56st/UvWXYZabCD7EF8='
rs = Recommendations(email, key)

# create model
model_id = rs.create_model('groceries' +'%Y%m%d%H%M%S'))

# import item catalog
catalog_path = os.path.join('app', 'management', 'commands', 'catalog.csv')
rs.import_file(model_id, catalog_path, Uris.import_catalog)

# import usage information
transactions_path = os.path.join('app', 'management', 'commands', 'transactions.csv')
rs.import_file(model_id, transactions_path, Uris.import_usage)

# build model
build_id = rs.build_fbt_model(model_id)
status = rs.wait_for_build(model_id, build_id)

if status != BuildStatus.success:
    print('Unsuccessful in building the model, failing now.')

# update model active build (not needed unless you are rebuilding)
rs.update_model(model_id, None, build_id)

print('Built a model. Model ID:{} Build ID:{}'.format(model_id, build_id))

Anomaly Detection

from cortanaanalytics.anomalydetection import AnomalyDetection

key = '1abCdEFGh/ijKlmN/opq234r56st/UvWXYZabCD7EF8='
ad = AnomalyDetection(key)

data = [
            (datetime(2014, 9, 21, 11, 5, 0), 3),
            (datetime(2014, 9, 21, 11, 10, 0), 9.09),
            (datetime(2014, 9, 21, 11, 15, 0), 0)
result = ad.score(test_data)

or you can also use strings

from cortanaanalytics.anomalydetection import AnomalyDetection

key = '1abCdEFGh/ijKlmN/opq234r56st/UvWXYZabCD7EF8='
ad = AnomalyDetection(key)

data = "9/21/2014 11:05:00 AM=3;9/21/2014 11:10:00 AM=9.09;9/21/2014 11:15:00 AM=0;"
params = "SpikeDetector.TukeyThresh=3; SpikeDetector.ZscoreThresh=3"
result = ad.score_raw(data, params)
Release History

Release History

This version
History Node


History Node


History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date (13.0 kB) Copy SHA256 Checksum SHA256 Source Feb 15, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting