Quick Start Guide#
Installation#
The easiest way to install pychemauth is with pip:
1pip install git+https://github.com/mahynski/pychemauth@main
Sometimes errors related to the inability to find numpy can occur during installation; to solve this run pip install numpy before install installing pychemauth. For example:
1pip install numpy && pip install git+https://github.com/mahynski/pychemauth@main
You can also download the repository and install it from there. Check for the most recent version, or whichever is desired, and replace “X.X.X” below.
1git clone https://github.com/mahynski/pychemauth.git --branch vX.X.X --depth 1
2cd pychemauth
3pip install .
4python -m pytest # Optional, but recommended to run unittests
Note that there are warnings raised by theses tests which indicate certain default checks, used to determine if a class is compatible with sklearn’s estimator api, have been skipped. This is expected as certain checks have been disabled intentionally; it does not indicate a problem with the code or its installation.
Usage#
Simply import the package to begin using it.
1import pychemauth
Some example psuedocode might look like this:
1from pychemauth.classifier.plsda import PLSDA
2X_train, X_test, y_train, y_test = load_data(...)
3model = PLSDA(n_components=10, style='soft')
4model.fit(X_train.values, y_train.values)
5pred = model.predict(X_test.values)
6df, I, CSNS, CSPS, CEFF, TSNS, TSPS, TEFF = model.figures_of_merit(pred, y_test.values)
Deploying on Colab#
You can use pychemauth in the cloud for free by using Google Colab. Click the link and follow the instructions to set up an account if you do not already have one. Start by creating a new notebook directly from inside your Google Drive account and proceed as follows.
How can you upload your data so you can access it from Colab? There are 2 options. The first involves uploading the file(s) directly to this particular runtime instance. If you are concerned about controlling where this data goes, consider the second option of mounting your Drive from the notebook. In that case you can upload your data to your Drive and simply access it from there.
1# 1. Upload your data as a .csv file (enter this code and click "Choose Files")
2from google.colab import files
3my_file = files.upload() # Currently there are some issues with this on Firefox
4
5for fn in my_file.keys():
6print('User uploaded file "{name}" with length {length} bytes'.format(
7 name=fn, length=len(my_file[fn]))
8)
9
10# Read your csv data into a Pandas DataFrame
11import pandas as pd
12df = pd.read_csv(list(uploaded.keys())[0])
1# 2. Put the file in your Google Drive and access it from there
2from google.colab import drive
3drive.mount('/content/drive')
4
5# Your Drive is mounted here
6%ls drive/MyDrive/
7
8# Read your csv data into a Pandas DataFrame
9import pandas as pd
10df = pd.read_csv("/drive/MyDrive/my_file.csv")
You can then install pychemauth and begin your analysis.
1# 3. Install PyChemAuth
2!pip install git+https://github.com/mahynski/pychemauth@main
Note that you may be prompted to restart the runtime after installing pychemauth, which is normal. You can restart from the top menu (Runtime > Restart runtime) or use the python code below.
1import os
2os.kill(os.getpid(), 9)
1import pychemauth
2
3# Perform analysis ...