Giter Site home page Giter Site logo

autosmart's Introduction

Alt text
license

The introduction of AutoSmart

The 1st place solution for KDD Cup 2019 AutoML Track

How to install

Requirements: Cython with C compiler.

clone or download autosmart package, run

python setup.py install 

How to use

import auto_smart

info = auto_smart.read_info("data")
train_data,train_label = auto_smart.read_train("data",info)
test_data = auto_smart.read_test("data",info)
auto_smart.train_and_predict(train_data,train_label,info,test_data)

Data Sample

Data

This page describes the datasets that our system can deal with.

Components

Each dataset is split into two subsets, namely the training set and the testing set.

Both sets have:

  • a main table file that stores the main table (label excluded);
  • multiple related table files that store the related tables;
  • an info dictionary that contains important information about the dataset, including table relations;
  • The training set has an additional label file that stores labels associated with the main table.

Table files

Each table file is a CSV file that stores a table (main or related), with '\t' as the delimiter. The first row indicates the names of features, a.k.a 'schema', and the following rows are the records.

The type of each feature can be found in the info dictionary that will be introduced soon.

There are 4 types of features, indicated by "cat", "num", "multi-cat", and "time", respectively:

  • cat: categorical feature, an integer
  • num: numerical Feature, a real value.
  • multi-cat: multi-value categorical Feature: a set of integers, split by the comma. The size of the set is not fixed and can be different for each instance. For example, topics of an article, words in a title, items bought by a user and so on.
  • time: time feature, an integer that indicates the timestamp.

Label file

The label file is associated only with the main table in the training set. It is a CSV file that contains only one column, with the first row as the header and the remaining indicating labels associated with instances in the main table.

info dictionary

Important information about each dataset is stored in a python dictionary structure named as info, which acts as an input of this system. Generally,you need to manually generate the dictionary information info.json file. Here we give details about info.

Alt text

Descriptions of the keys in info:

  • time_budget: time budget for this dataset (sec).

  • time_col: the column name of the primary timestamp; Each dataset has one unique time_col; time_col is definitely contained in the main table, but not necessarily in a related table;

  • start_time: DEPRECATED.

  • tables: a dictionary that stores information about tables. Each key indicates a table, and its corresponding value is a dictionary that indicates the type of each column in this table. Two kinds of keys are contained in tables:

    • main: the main table;
    • table_{i}: the i-th related table.
    • There are 4 types of features, indicated by "cat", "num", "multi-cat", and "time", respectively:
      • cat: categorical feature, an integer
      • num: numerical Feature, a real value.
      • multi-cat: multi-value categorical Feature: a set of integers, split by the comma. The size of the set is not fixed and can be different for each instance. For example, topics of an article, words in a title, items bought by a user and so on.
      • time: time feature, an integer that indicates the timestamp.
  • relations: a list that stores table relations in the dataset. Each relation can be represented as an ordered table pair (table_A, table_B), a key column key that appears in both tables and acts as the pivot of table joining, and a relation type type. Different relation types will be introduced shortly.

Relations Between Tables

Four table relations are considered in this system:

  • one-to-one (1-1): the key columns in both table_A and table_B have no duplicated values;
  • one-to-many (1-M): the key column in table_A has no duplicated values, but that in table_B may have duplicated values;
  • many-to-one (M-1): the key column in table_A may have duplicated values, but that in table_B has no duplicated values;
  • many-to-many (M-M): the key columns in both table_A and table_B may have duplicated values.

Contact Us

DeepBlueAI: [email protected]

autosmart's People

Contributors

aister2020 avatar deepsmartai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

autosmart's Issues

is 'importances.csv' the only output ?

Hello ! I would like to know if the 'importances.csv' file which contains the features and their importances is the only output after running the program.
Is there a way to get the actual model, its metrics and other informations.
Thank you so much !

[BUG] 'DefaultFeatPipeline' object has no attribute 'keys_order3s'

Dataset from following kaggle challenge:
https://www.kaggle.com/c/acquire-valued-shoppers-challenge
Note that is enough to reproduce error using single table:

import pandas as pd
import auto_smart
import os.path
import time
import datetime


PREPROC = True
NROWS = None
TARGET = 'repeater'
DATE = 'offerdate'

if PREPROC:
    #train & target
    df_tr = pd.read_csv(os.path.join('data', 'train', 'trainHistory.csv'), nrows=NROWS)
    
    df_tr_lbl = df_tr[[TARGET]]
    df_tr_lbl[TARGET] = df_tr_lbl[TARGET].map({'f': 0, 't': 1}) 
    df_tr_lbl = df_tr_lbl.rename(columns={TARGET: 'label'})
    df_tr_lbl.to_csv(os.path.join('data', 'train', 'main_train.solution'), index=False)
    
    df_tr = df_tr[df_tr.columns.difference([TARGET])]
    df_tr = df_tr.drop(['repeattrips'], axis=1)
    df_tr[DATE] = df_tr[DATE].apply(lambda s: time.mktime(datetime.datetime.strptime(s, '%Y-%m-%d').timetuple()))
    df_tr.to_csv(os.path.join('data', 'train', 'main_train.data'), index=False, sep='\t')

    # #offer:
    # df_of = pd.read_csv(os.path.join('data', 'train', 'offers.csv'), nrows=NROWS)
    # df_of.to_csv(os.path.join('data', 'train', 'offers.data'), index=False, sep='\t')

    #transactions
    # df_txs = pd.read_csv(os.path.join('data', 'train', 'transactions.csv'), nrows=NROWS)
    # df_txs['date'] = df_txs['date'].apply(lambda s: time.mktime(datetime.datetime.strptime(s, '%Y-%m-%d').timetuple()))
    # df_txs.to_csv(os.path.join('data', 'train', 'transactions.data'), index=False, sep='\t')

    #test:
    df_te = pd.read_csv(os.path.join('data', 'test', 'testHistory.csv'), nrows=NROWS)
    df_te[DATE] = df_te[DATE].apply(lambda s: time.mktime(datetime.datetime.strptime(s, '%Y-%m-%d').timetuple()))
    df_te.to_csv(os.path.join('data', 'test', 'main_test.data'), index=False, sep='\t')


print('info...')
info = auto_smart.read_info('data')

print('train...')
train_data, train_label = auto_smart.read_train('data', info)

print('test...')
test_data = auto_smart.read_test('data', info)

print('model...')
prd = auto_smart.train_and_predict(train_data, train_label, info, test_data)
    
print('finalizing...')
prd_df = pd.read_csv('sampleSubmission.csv')
prd_df['repeatProbability'] = prd
prd_df.to_csv('predictions.csv', index=False)

with following json configuration:

{
 "time_budget": 300,
 "time_col": "offerdate",
 "start_time": 1550654179,
 "tables": {
  "main": {
    "id": "cat",
    "chain": "cat",
    "offer": "cat",
    "market": "cat",
    "offerdate": "time"
  }
 },
 "relations": []
}

I got following error:

  'New categorical_feature is {}'.format(sorted(list(categorical_feature))))
--------------------total feat num:22, drop feat num:0
----------------End   [LGBFeatureSelectionWait.fit]. Time elapsed: 0.56 sec.
----------------End time: 2020-02-11 06:21:35

----------------Start [LGBFeatureSelectionWait.transform]:
----------------Start time: 2020-02-11 06:21:35
----------------End   [LGBFeatureSelectionWait.transform]. Time elapsed: 0.00 sec.
----------------End time: 2020-02-11 06:21:35
------------End   [LGBFeatureSelectionWait.fit_transform]. Time elapsed: 0.56 sec.
------------End time: 2020-02-11 06:21:35
--------End   [FeatEngine.fit_transform_keys_order2]. Time elapsed: 0.56 sec.
--------End time: 2020-02-11 06:21:35

--------Start [FeatEngine.fit_transform_keys_order3]:
--------Start time: 2020-02-11 06:21:35
Traceback (most recent call last):

  File "/home/mglowacki/Desktop/AVR_kaggle/autosmart_avr.py", line 61, in <module>
    prd = auto_smart.train_and_predict(train_data, train_label, info, test_data)

  File "/home/mglowacki/anaconda3/envs/py37/lib/python3.7/site-packages/auto_smart/__init__.py", line 71, in train_and_predict
    return cmodel.predict(test_data)

  File "/home/mglowacki/anaconda3/envs/py37/lib/python3.7/site-packages/auto_smart/util.py", line 38, in timed
    result = method(*args, **kw)

  File "/home/mglowacki/anaconda3/envs/py37/lib/python3.7/site-packages/auto_smart/model.py", line 358, in predict
    self.my_fit(self.Xs, self.y, X_test)

  File "/home/mglowacki/anaconda3/envs/py37/lib/python3.7/site-packages/auto_smart/util.py", line 38, in timed
    result = method(*args, **kw)

  File "/home/mglowacki/anaconda3/envs/py37/lib/python3.7/site-packages/auto_smart/model.py", line 156, in my_fit
    feat_engine.fit_transform_keys_order3(main_table,y)

  File "/home/mglowacki/anaconda3/envs/py37/lib/python3.7/site-packages/auto_smart/util.py", line 38, in timed
    result = method(*args, **kw)

  File "/home/mglowacki/anaconda3/envs/py37/lib/python3.7/site-packages/auto_smart/feat_engine.py", line 143, in fit_transform_keys_order3
    for feat_cls in self.feat_pipeline.keys_order3s:

AttributeError: 'DefaultFeatPipeline' object has no attribute 'keys_order3s'

It is auto_smart issue, I've check file auto_smart/feat/feat_pipeline.py and there is no self.keys_order3s = ....
"Stop-error solution" for single table is set self.keys_order3s to self.keys_order2s, but different error appears when you add offers table (about signature mismatch) also it doesn't look right to me. Additional error could be related to this "stop-error solution" or completly independent thing.

Problem when run demo.py

Hi all,
I got this problem:
"lightgbm.basic.LightGBMError: Do not support special JSON characters in feature name."
How should i do now :(

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.