Skip to main content

Algorithm SDK for TencentCloud TIONE

Project description

Algorithm SDK for TencentCloud TIONE

License


install

pip3 install --upgrade tialgo

example

import os
import sys
import pandas as pd
from sklearn.preprocessing import LabelEncoder
from sklearn.ensemble import RandomForestClassifier
from tialgo import TableDataModel

class Model(TableDataModel):
    def __init__(self):
        super(Model, self).__init__()

    def train(self, df):
        super().train(df)

        #字符串索引化
        for col in ["term","grade","home_ownership","verification_status"]:
            # 需要保存的对象
            encoder = LabelEncoder()
            df[col] = encoder.fit_transform(df[col])
            self.put_model(encoder)

        feature = [col for col in df.columns if col not in ["loan_status"]]
        X,y = df[feature], df["loan_status"]

        #随机森林分类
        model = RandomForestClassifier(max_depth = 7, n_estimators = 20,)
        model.fit(X, y)
        self.put_model(model)

        print('自动保存模型:')
        self.print_model()

    def predict(self, df):
        super().predict(df)

        feature = [col for col in df.columns if col not in ["loan_status"]]
        df = df[feature]

        #字符串索引化 贷款期限 贷款信用评级 贷款客户房屋所有权状况 收入认证状态
        for col in ["term","grade","home_ownership","verification_status"]:
            # 需要保存的对象
            encoder = self.get_model()
            df[col] = encoder.transform(df[col])

        #分类
        model = self.get_model()
        y_pred_proba = model.predict_proba(df)
        return pd.DataFrame(y_pred_proba)

    def load_train_data(self):
        return {'data': df, 'label': 'loan_status'}


run_mode = os.environ.get('run_mode') or 'train'
print('run_mode:', run_mode)

if run_mode=='train':
    df = pd.read_csv("demo.csv")

model = Model()
model.run(run_mode)

model.run('predict_online')

test data

save as demo.csv

loan_amnt,term,int_rate,grade,emp_length,home_ownership,annual_inc,verification_status,dti,delinq_2yrs,inq_last_6mths,chargeoff_within_12_mths,loan_status
15000.0, 60 months,25.82,E,0.0,OWN,25000.0,Source Verified,2.26,0.0,0.0,0.0,0
20000.0, 36 months,6.11,A,4.0,MORTGAGE,95000.0,Not Verified,15.32,1.0,2.0,0.0,1
15000.0, 36 months,10.91,B,0.0,RENT,38000.0,Not Verified,23.63,0.0,1.0,0.0,1
4800.0, 36 months,12.62,C,3.0,RENT,100000.0,Source Verified,10.31,0.0,0.0,0.0,0
16000.0, 60 months,19.42,D,6.0,MORTGAGE,60000.0,Verified,22.68,0.0,0.0,0.0,1
40000.0, 60 months,7.21,A,3.0,MORTGAGE,130000.0,Source Verified,18.0,0.0,0.0,0.0,1
4000.0, 36 months,29.69,F,2.0,RENT,47000.0,Source Verified,25.97,0.0,1.0,0.0,0
30000.0, 60 months,12.73,B,11.0,RENT,102000.0,Source Verified,21.11,0.0,0.0,0.0,1
5000.0, 36 months,10.08,B,0.0,OWN,46000.0,Source Verified,30.42,0.0,0.0,0.0,1
16000.0, 36 months,8.08,A,5.0,RENT,30000.0,Source Verified,25.08,0.0,0.0,0.0,0
8000.0, 36 months,9.92,B,11.0,RENT,105000.0,Not Verified,11.28,0.0,1.0,0.0,1
10000.0, 36 months,15.05,C,4.0,RENT,50000.0,Source Verified,14.12,0.0,0.0,0.0,0
22000.0, 60 months,15.02,C,0.0,RENT,80000.0,Not Verified,36.51,0.0,0.0,0.0,1

test the online service

curl http://127.0.0.1:8501 -X POST --data-binary @demo.csv

more

Homepage: https://cloud.tencent.com

Project details


Download files

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

Source Distribution

tialgo-0.0.2.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tialgo-0.0.2-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file tialgo-0.0.2.tar.gz.

File metadata

  • Download URL: tialgo-0.0.2.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.5.2

File hashes

Hashes for tialgo-0.0.2.tar.gz
Algorithm Hash digest
SHA256 cedc32a23f04c4745d9ada589d9a580ffee3502065984946ec0123e1b85e8787
MD5 57c84242ea2a2bbbaebfc5e83e2d5c5b
BLAKE2b-256 b0251aa5bd35a9630e373c1e0caee23bd71d0bde51c90d58298035377e5791e1

See more details on using hashes here.

File details

Details for the file tialgo-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: tialgo-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.5.2

File hashes

Hashes for tialgo-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 492b824db2cbfae2ee685f09ee3579c642efc938afe1ed7905902f4501c79665
MD5 fe9dca8d17d7a88d245ec025937642ee
BLAKE2b-256 8d0bf2c66008707a2564a3636d92e2e6951b48d9d173c2b001b886304fed8d60

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page