In [1]:
from journal import WorkJournal

from sklearn.linear_model import LogisticRegression
from sklearn.linear_model import LinearRegression
from sklearn.linear_model import Ridge
log_reg_params = {
                    'C' : [0.1, 0.2],
                    'B' : [1, 2]
                 }
lin_reg_params = {
                    'a' : [5, 6, 3],
                    'k' : [8, 6, 3, 15],
                    't' : ['a', 'b', 'c']
                 }
ridge_params = {
                    'loss' : ['k', 'l', 0.3, 5],
                    'pam' : [[1, 2, 3], 5, 27]
               }

In [2]:
# Creating the journal

wj = WorkJournal(filename='wj1_test.wj')

In [3]:
# Adding new work
# Let task be the following cortage: (Model, dict of params)
# And work is one or few tasks
# It allows to add new work it in different ways and they are equal
# But if task has already in journal then it will not allow to add another one

task1 = (LogisticRegression, log_reg_params)
task2 = (LinearRegression, lin_reg_params)
task3 = (Ridge, ridge_params)

# Method 1 : Put few tasks
wj.add_work(task1, task2, task3)


Task in work already exist:LogisticRegression#{'C': [0.1, 0.2], 'B': [1, 2]}
Task in work already exist:LinearRegression#{'a': [5, 6, 3], 'k': [8, 6, 3, 15], 't': ['a', 'b', 'c']}
Task in work already exist:Ridge#{'loss': ['k', 'l', 0.3, 5], 'pam': [[1, 2, 3], 5, 27]}

In [4]:
# Method 2.1 : Put cortage of tasks
wj.add_work((task1, task2, task3))


Task in work already exist:LogisticRegression#{'C': [0.1, 0.2], 'B': [1, 2]}
Task in work already exist:LinearRegression#{'a': [5, 6, 3], 'k': [8, 6, 3, 15], 't': ['a', 'b', 'c']}
Task in work already exist:Ridge#{'loss': ['k', 'l', 0.3, 5], 'pam': [[1, 2, 3], 5, 27]}

In [5]:
# Method 2.2 : Put list of tasks
wj.add_work([task1, task2, task3])


Task in work already exist:LogisticRegression#{'C': [0.1, 0.2], 'B': [1, 2]}
Task in work already exist:LinearRegression#{'a': [5, 6, 3], 'k': [8, 6, 3, 15], 't': ['a', 'b', 'c']}
Task in work already exist:Ridge#{'loss': ['k', 'l', 0.3, 5], 'pam': [[1, 2, 3], 5, 27]}

In [6]:
# Method 3.1 : put dict of tasks as a key word argument
wj.add_work(work={LogisticRegression : log_reg_params, LinearRegression : lin_reg_params, Ridge : ridge_params})


Task in work already exist:Ridge#{'loss': ['k', 'l', 0.3, 5], 'pam': [[1, 2, 3], 5, 27]}
Task in work already exist:LogisticRegression#{'C': [0.1, 0.2], 'B': [1, 2]}
Task in work already exist:LinearRegression#{'a': [5, 6, 3], 'k': [8, 6, 3, 15], 't': ['a', 'b', 'c']}

In [7]:
# Method 3.2 : put cortage of tasks as a key word argument
wj.add_work(work=(task1, task2, task3))


Task in work already exist:LogisticRegression#{'C': [0.1, 0.2], 'B': [1, 2]}
Task in work already exist:LinearRegression#{'a': [5, 6, 3], 'k': [8, 6, 3, 15], 't': ['a', 'b', 'c']}
Task in work already exist:Ridge#{'loss': ['k', 'l', 0.3, 5], 'pam': [[1, 2, 3], 5, 27]}

In [8]:
# Method 3.3 : put list of tasks as a key word argument
wj.add_work(work=[task1, task2, task3])


Task in work already exist:LogisticRegression#{'C': [0.1, 0.2], 'B': [1, 2]}
Task in work already exist:LinearRegression#{'a': [5, 6, 3], 'k': [8, 6, 3, 15], 't': ['a', 'b', 'c']}
Task in work already exist:Ridge#{'loss': ['k', 'l', 0.3, 5], 'pam': [[1, 2, 3], 5, 27]}

In [9]:
# Iterating through the tasks
# You can use 'for each' loop but you have to call task_done() method after making some stuff
# or you will get the same task

for task in wj:
    print(task)
    wj.task_done(task)


(<class 'sklearn.linear_model.logistic.LogisticRegression'>, {'C': [0.1, 0.2], 'B': [1, 2]})
(<class 'sklearn.linear_model.base.LinearRegression'>, {'a': [5, 6, 3], 'k': [8, 6, 3, 15], 't': ['a', 'b', 'c']})
(<class 'sklearn.linear_model.ridge.Ridge'>, {'loss': ['k', 'l', 0.3, 5], 'pam': [[1, 2, 3], 5, 27]})

In [ ]: