<jupyter_start><jupyter_text>Logistic Regression---This notebook uses Cirrus to run logistic regression on the Criteo dataset.  Setup---<jupyter_code># To ease development, each time a cell is run, all modules will be reloaded.
%load_ext autoreload
%autoreload 2
import logging
import sys
import atexit
import local_ps
# Cirrus produces logs, but they will not show unless we add a handler that prints.
from cirrus import utilities
utilities.set_logging_handler()
from cirrus import instance, parameter_server, automate, lr, aws_resources<jupyter_output><empty_output><jupyter_text>Instance, server, and task--- First, we start an EC2 instance.<jupyter_code>instance.resources = aws_resources.get_resource()
automate.resources = aws_resources.get_resource()

inst = instance.Instance(
    name="lr_example_instance",
    disk_size=32,
    typ="t3.micro",
    username="ubuntu",
    ami_owner_name=("self", "cirrus_server_image")
)
inst.start()<jupyter_output><empty_output><jupyter_text>Second, we create a parameter server to run on our instance.<jupyter_code>""""
# Enable this if running on EC2
server = parameter_server.ParameterServer(
    instance=inst,
    ps_port=1337,
    error_port=1338,
    num_workers=64
)
"""
# Running the ParameterServer locally on compute22.
server = local_ps.LocalParameterServer(
    public_ip="192.168.3.11",
    port=1337)<jupyter_output><empty_output><jupyter_text>Third, we define our machine learning task.<jupyter_code>task = lr.LogisticRegression(
    n_workers=16,
    n_ps=1,
    dataset="criteo-kaggle-19b",
    learning_rate=0.0001,
    epsilon=0.0001,
    progress_callback=None,
    train_set=(0, 19),
    test_set=(20, 30),
    minibatch_size=5,
    #train_set=(0, 799),
    #test_set=(800, 850),
    #minibatch_size=200,
    model_bits=19,
    ps=server,
    opt_method="adagrad",
    timeout=60,
    lambda_size=192
)<jupyter_output><empty_output><jupyter_text>Run--- Next, we run our machine learning task.<jupyter_code>task.run()<jupyter_output><empty_output><jupyter_text>Run this cell to see the present accuracy of the model.<jupyter_code>for line in server.ps_output().split(b'\n')[-10:]:
    print(line)

for line in server.error_output().split(b'\n')[-10:]:
    print(line)
#    if b'Accuracy' in line:
#        print(line)<jupyter_output><empty_output><jupyter_text>Cleanup--- When we're satisfied with the results, we kill our task.<jupyter_code>task.kill()<jupyter_output><empty_output><jupyter_text>We also need to terminate our instance in order to avoid continuing charges.<jupyter_code>inst.cleanup()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11320754716981132, 'fraction_numerical': 0.030034655371582595, 'mean_word_length': 5.4148148148148145, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '25957', 'license': 'Apache-2.0', 'n_tokens_mistral': 938, 'n_tokens_neox': 880, 'n_words': 203, 'path': 'python/frontend/cirrus/examples/logistic_regression.ipynb', 'repo_name': 'yuju-huang/cirrus', 'size': '2598'}