项目作者: Vopaaz

项目描述 :
Assist small-scale machine learning.
高级语言: Python
项目地址: git://github.com/Vopaaz/learning-utility.git
创建时间: 2019-08-01T13:51:44Z
项目社区:https://github.com/Vopaaz/learning-utility

开源协议:GNU General Public License v3.0

下载


Unmaintained

This project is unmaintained and the checkpoint functionality has been ported to the checkpointing project.

learning-utility

Assist small-scale machine learning.

learning-utility is a package of utilities for small-scale machine
learning tasks with scikit-learn.

image
image
PyPI - Python Version
Downloads
PyPI

Installation

  1. pip install Lutil

Key Features

Cache Intermediate Results

InlineCheckpoint can cache the computation result in the first call.
Since then, if nothing has changed, it retrieves the cache and skips
computation.

Suppose you have such a .py file.

  1. from Lutil.checkpoints import InlineCheckpoint
  2. a, b = 1, 2
  3. with InlineCheckpoint(watch=["a", "b"], produce=["c"]):
  4. print("Heavy computation.")
  5. c = a + b
  6. print(c)

Run the script, you will get:

  1. Heavy computation.
  2. 3

Run this script again, the with-statement will be skipped. You will get:

  1. 3

Once a value among watch changes or the code inside the with-statement
changes, re-calculation takes place to ensure the correct output.

Save Prediction Result According to the Given Format

Lots of machine learning competitions require a .csv file in a given format.
Most of them provide an example file.

In example.csv:

  1. id, pred
  2. 1, 0.25
  3. 2, 0.45
  4. 3, 0.56

Run:

  1. >>> import numpy as np
  2. >>> from Lutil.dataIO import AutoSaver
  3. >>> result = np.array([0.2, 0.4, 0.1, 0.5])
  4. # Typical output of a scikit-learn predictor
  5. >>> ac = AutoSaver(save_dir="somedir", example_path="path/to/example.csv")
  6. >>> ac.save(result, "some_name.csv")

Then in your somedir/some_name.csv:

  1. id, pred
  2. 1, 0.2
  3. 2, 0.4
  4. 3, 0.1
  5. 4, 0.5

It also works if the result is a pandas DataFrame, Series, 2-dim numpy array, etc.
Also, the encoding, seperator, header, index of the example.csv will all be recognized.