Metadata-Version: 2.1
Name: predictnow-api
Version: 2.0.0
Summary: A restful client library, designed to access predictnow restful API.
Home-page: https://github.com/PredictNowAI/predictnow-api
Author: PredictNow.ai
Author-email: tech@predictnow.ai
License: UNKNOWN
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
Requires-Dist: aiohttp (==3.7.4.post0)
Requires-Dist: aiohttp-cors (==0.7.0)
Requires-Dist: aioredis (==1.3.1)
Requires-Dist: alembic (==1.6.5)
Requires-Dist: amqp (==5.0.6)
Requires-Dist: astunparse (==1.6.3)
Requires-Dist: async-timeout (==3.0.1)
Requires-Dist: attrs (==21.2.0)
Requires-Dist: beautifulsoup4 (==4.9.3)
Requires-Dist: billiard (==3.6.4.0)
Requires-Dist: blessings (==1.7)
Requires-Dist: blinker (==1.4)
Requires-Dist: boto3 (==1.17.30)
Requires-Dist: botocore (==1.20.91)
Requires-Dist: CacheControl (==0.12.6)
Requires-Dist: cachetools (==4.2.2)
Requires-Dist: category-encoders (==2.2.2)
Requires-Dist: celery (==5.1.2)
Requires-Dist: certifi (==2021.5.30)
Requires-Dist: cffi (==1.14.5)
Requires-Dist: chardet (==3.0.4)
Requires-Dist: click (==7.1.2)
Requires-Dist: click-didyoumean (==0.0.3)
Requires-Dist: click-plugins (==1.1.1)
Requires-Dist: click-repl (==0.2.0)
Requires-Dist: colorama (==0.4.4)
Requires-Dist: colorful (==0.5.4)
Requires-Dist: cryptography (==3.4.7)
Requires-Dist: cycler (==0.10.0)
Requires-Dist: dnspython (==2.1.0)
Requires-Dist: dominate (==2.6.0)
Requires-Dist: email-validator (==1.1.2)
Requires-Dist: et-xmlfile (==1.1.0)
Requires-Dist: filelock (==3.0.12)
Requires-Dist: firebase-admin (==4.4.0)
Requires-Dist: Flask (==1.1.2)
Requires-Dist: Flask-Bootstrap (==3.3.7.1)
Requires-Dist: Flask-Bootstrap4 (==4.0.2)
Requires-Dist: Flask-Login (==0.5.0)
Requires-Dist: Flask-Mail (==0.9.1)
Requires-Dist: Flask-Migrate (==3.0.1)
Requires-Dist: Flask-SQLAlchemy (==2.5.1)
Requires-Dist: Flask-WTF (==0.15.1)
Requires-Dist: future (==0.18.2)
Requires-Dist: google (==3.0.0)
Requires-Dist: google-api-core (==1.30.0)
Requires-Dist: google-api-python-client (==2.8.0)
Requires-Dist: google-auth (==1.30.2)
Requires-Dist: google-auth-httplib2 (==0.1.0)
Requires-Dist: google-cloud-core (==1.6.0)
Requires-Dist: google-cloud-firestore (==2.1.1)
Requires-Dist: google-cloud-storage (==1.38.0)
Requires-Dist: google-crc32c (==1.1.2)
Requires-Dist: google-resumable-media (==1.3.0)
Requires-Dist: googleapis-common-protos (==1.53.0)
Requires-Dist: gpustat (==0.6.0)
Requires-Dist: greenlet (==1.1.0)
Requires-Dist: grpcio (==1.38.0)
Requires-Dist: gunicorn (==20.0.4)
Requires-Dist: hiredis (==2.0.0)
Requires-Dist: honeycomb-beeline (==2.13.1)
Requires-Dist: httplib2 (==0.19.1)
Requires-Dist: idna (==2.10)
Requires-Dist: itsdangerous (==2.0.1)
Requires-Dist: jdcal (==1.4.1)
Requires-Dist: jedi (==0.17.0)
Requires-Dist: Jinja2 (==2.11.2)
Requires-Dist: jmespath (==0.10.0)
Requires-Dist: joblib (==0.17.0)
Requires-Dist: jsons (==1.3.0)
Requires-Dist: jsonschema (==3.2.0)
Requires-Dist: kiwisolver (==1.3.1)
Requires-Dist: kombu (==5.1.0)
Requires-Dist: libhoney (==1.10.0)
Requires-Dist: lightgbm (==2.3.0)
Requires-Dist: Mako (==1.1.4)
Requires-Dist: MarkupSafe (==2.0.1)
Requires-Dist: matplotlib (==3.3.2)
Requires-Dist: msgpack (==1.0.2)
Requires-Dist: multidict (==5.1.0)
Requires-Dist: numpy (==1.19.2)
Requires-Dist: nvidia-ml-py3 (==7.352.0)
Requires-Dist: opencensus (==0.7.13)
Requires-Dist: opencensus-context (==0.1.2)
Requires-Dist: openpyxl (==3.0.5)
Requires-Dist: packaging (==20.9)
Requires-Dist: pandas (==1.1.3)
Requires-Dist: patsy (==0.5.1)
Requires-Dist: paypalrestsdk (==1.13.1)
Requires-Dist: Pillow (==8.2.0)
Requires-Dist: predictnow-client (==0.0.9)
Requires-Dist: prometheus-client (==0.11.0)
Requires-Dist: proto-plus (==1.18.1)
Requires-Dist: protobuf (==3.17.3)
Requires-Dist: psutil (==5.8.0)
Requires-Dist: py-spy (==0.3.7)
Requires-Dist: pyarrow (==2.0.0)
Requires-Dist: pyasn1 (==0.4.8)
Requires-Dist: pyasn1-modules (==0.2.8)
Requires-Dist: pycparser (==2.20)
Requires-Dist: pyfcm (==1.4.7)
Requires-Dist: pyflowchart (==0.1.4)
Requires-Dist: PyJWT (==1.7.1)
Requires-Dist: PyMySQL (==1.0.2)
Requires-Dist: pyOpenSSL (==20.0.1)
Requires-Dist: pyparsing (==2.4.7)
Requires-Dist: pyrsistent (==0.17.3)
Requires-Dist: python-editor (==1.0.4)
Requires-Dist: pytimeparse (==1.1.8)
Requires-Dist: pytz (==2021.1)
Requires-Dist: PyYAML (==5.4.1)
Requires-Dist: pyzmq (==20.0.0)
Requires-Dist: ray (==1.0.0)
Requires-Dist: redis (==3.4.1)
Requires-Dist: requests (==2.24.0)
Requires-Dist: rsa (==4.7.2)
Requires-Dist: s3transfer (==0.3.7)
Requires-Dist: scikit-learn (==0.23.2)
Requires-Dist: scipy (==1.6.3)
Requires-Dist: shap (==0.33.0)
Requires-Dist: six (==1.16.0)
Requires-Dist: soupsieve (==2.2.1)
Requires-Dist: SQLAlchemy (==1.4.17)
Requires-Dist: statsd (==3.3.0)
Requires-Dist: statsmodels (==0.12.0)
Requires-Dist: stripe (==2.55.1)
Requires-Dist: threadpoolctl (==2.1.0)
Requires-Dist: tqdm (==4.50.2)
Requires-Dist: typing-extensions (==3.10.0.0)
Requires-Dist: typish (==1.9.2)
Requires-Dist: uritemplate (==3.0.1)
Requires-Dist: urllib3 (==1.25.11)
Requires-Dist: vine (==5.0.0)
Requires-Dist: visitor (==0.1.3)
Requires-Dist: Werkzeug (==1.0.1)
Requires-Dist: wrapt (==1.12.1)
Requires-Dist: WTForms (==2.3.3)
Requires-Dist: xlrd (==1.2.0)
Requires-Dist: yarl (==1.6.3)

# TO BEGIN ANY WORK WITH PREDICTNOW.AI CLIENT, WE START BY IMPORTING AND CREATING A CLASS INSTANCE
from predictnow.pdapi import PredictNowClient
import pandas as pd

api_key = "KeyProvidedToEachOfOurSubscriber"   
api_host = "http://%VMIP%"  

# Initial variables
username = "user1"  
email = "xxxx@gmail.com"
client = PredictNowClient(api_host,api_key)

# YOU WILL NEED TO EDIT THIS INPUT DATASET FILE PATH, LABELNAME AND MODELNAME!
file_path = 'my_amazing_features.xlsx'  # ********************
labelname = 'futreturn' #might need to change this name accordingly *******************************
modelname = 'model1' # *********************************************
import os

# NOW YOUR PREDICTNOW.AI CLIENT HAS BEEN SETUP.

# For classification problem
params = {"timeseries": "yes", "weights": "no", "prob_calib": "no", "eda": "no", "type": "classification", "feature_selection": "shap", "analysis": "small", "boost": "gbdt", "mode": "train", "testsize": "1"}

# For regression problems
params = {"timeseries": "yes", "weights": "no", "prob_calib": "no", "eda": "no", "type": "regression", "feature_selection": "shap", "analysis": "small", "boost": "gbdt", "mode": "train", "testsize": "1"}

print("THE PARAMS", params)


# LET'S CREATE THE MODEL BY SENDING THE PARAMETERS TO PREDICTNOW.AI

response = client.create_model(
    username=username, # only letters, numbers, or underscores
    model_name=modelname,
    params=params,
)

print(response)


# LET'S LOAD UP THE FILE TO PANDAS IN THE LOCAL ENVIRONMENT

from pandas import read_csv  # If you have the Excel file, replace read_csv with read_excel
from pandas import read_excel
df = read_excel(file_path)  # Same here
df.name = "testdataframe"  # Optional, but recommended

print(df)

# START TRAINING MODEL
# NOTE: THIS MAY TAKE UP TO several minutes
response = client.train(
    model_name=modelname,
    input_df=df,
    label=labelname,

    username=username,
    email=email,
    return_output=False
)

print("THE CLIENT HAS SENT THE DATASET TO THE SERVER AND TRIGGERED THE TRAINING MODEL TASK")
print(response)

# CHECK THE STATUS OF THE MODEL
status = client.getstatus(
    username=username,
    train_id=response["train_id"]
)

print("Current status:")
print(status)

#  NOW WE WILL DOWNLOAD FILES
if status["state"] == "COMPLETED":

    response = client.getresult(
        model_name=modelname,
        username=username,
    )

    import pandas as pd
    predicted_prob_cv = pd.read_json(response.predicted_prob_cv)
    print("predicted_prob_cv")
    print(predicted_prob_cv)

    predicted_prob_test = pd.read_json(response.predicted_prob_test)
    print("predicted_prob_test")
    print(predicted_prob_test)


    predicted_targets_cv = pd.read_json(response.predicted_targets_cv)
    print("predicted_targets_cv")
    print(predicted_targets_cv)

# START PREDICTING USING THE TRAINED MODEL
if status["state"] == "COMPLETED":

    df = read_excel("example_input_live_latest.xlsx")
    df.name = "myfirstpredictname"  # optional, but recommended

    # Predict demo
    response = client.predict(
        model_name=modelname,
        input_df=df,
        username=username,
        eda=params["eda"],
        prob_calib=params["prob_calib"]
    )


