I just saw an article called Announcing PyCaret 1.0.0. .. Since it was an interesting library, this article will explain how to actually use PyCaret. ** PyCaret is a Python library that allows you to perform data preprocessing, visualization, and model development in machine learning model development with just a few lines of code. ** **
PyCaret is a Python wrapper for some of the major machine learning libraries (scikit-learn, XGBoost, LightGBM, etc.). It can handle classification, regression, clustering, anomaly detection, and natural language processing. So to speak, PyCaret is like a free version of DataRobot.
Basically, it seems that you can do everything from preprocessing, modeling, performance evaluation, tuning, and visualization. In addition, stacking can be done. (Some evaluation indexes such as time series analysis and log loss are provided.) PyCaret/Github
Also, the target audience has already introduced a series of machine learning using scikit-learn! Is the one who says. (If you are a beginner in machine learning, you may not understand the contents. Let's spend some time for the time being .. I think it ends with the feeling. I'm sorry for the in-house service, but [AI Academy](https: // aiacademy. Try to get started with machine learning programming using jp /) etc.)
There is also an explanation video of kaggle's Credit Card Fraud Detection using PyCaret, so please take a look.
First, install PyCaret.
When installing from a terminal or command prompt, you can install with the following command.
pip install pycaret
In Jupyter Notebook and Google Colab, you can install it with the following command with a! At the beginning.
!pip install pycaret
This time, I will try multi-class classification using the iris dataset. First, load the required code.
import warnings
#I'll erase unnecessary warnings
warnings.filterwarnings("ignore")
#The leading role this time! Load PyCaret.
from pycaret.classification import *
#Load the Iris dataset.
from sklearn.datasets import load_iris
#Since it handles data frames, it also reads Pandas.
import pandas as pd
Next, prepare the data.
iris = load_iris()
X = pd.DataFrame(iris.data, columns=iris.feature_names)
y = pd.DataFrame(iris.target, columns=["target"])
df = pd.concat([X,y], axis=1)
The first 5 items are displayed.
df.head()
Now! Preprocessing.
Use ** setup () ** to handle missing values, split data, etc.
Pass the objective variable to target.
exp1 = setup(df, target = 'target')
To compare models, just use ** compare_models () **.
compare_models()
Enter the name of the algorithm used for learning by referring to https://pycaret.org/create-model/. This time, we will use the "Quadratic Discriminant Analysis" and the decision tree, which have the highest accuracy rate. For Quadratic Discriminant Analysis, you can enter'qda', so enter qda this time.
qda = create_model('qda')
Let's also try the decision tree.
tree = create_model('dt')
Let's tune the decision tree.
tuned_tree = tune_model('dt')
tuned_tree.get_params
plot_model(tuned_qda)
plot_model(tuned_tree)
lgbm = create_model('lightgbm')
xgboost = create_model('xgboost')
ensemble = blend_models([lgbm, xgboost])
stack = stack_models(estimator_list = [xgboost], meta_model = lgbm)
pred = predict_model(qda)
Yes, convenient.
In just a few lines, I was able to complete it. .. I think I'll use it little by little from now on.
This is an article that I used as a reference. Please refer to it in addition to this article.
Reference article 1 Reference article 2 [Reference article 3](https://techtech-sorae.com/%E6%A9%9F%E6%A2%B0%E5%AD%A6%E7%BF%92%E3%81%AE%E8%87 % AA% E5% 8B% 95% E5% 8C% 96% E3% 83% A9% E3% 82% A4% E3% 83% 96% E3% 83% A9% E3% 83% AA% E3% 80% 8Cpycaret % E3% 80% 8D% E3% 82% 92% E4% BD% BF% E3% 81% A3% E3% 81% A6% E3% 81% BF% E3% 81% 9F /
Cyber Brain Co., Ltd. CEO Kazunori Tani We look forward to your follow-up! Twitter Facebook We also run an AI community with more than 5,000 participants. We provide information about AI every day, so we look forward to your participation! Artificial Intelligence Research Community AI Academy
Recommended Posts