Building and training ML models with Vertex AI
Summary
TLDRビデオの要約では、Priyanka VergadiaがAI Simplifiedというシリーズで、データセットの管理からモデルの構築・トレーニング、評価、展開、予測までをカバーするVertex AIというプラットフォームを紹介しています。このエピソードでは、AutoMLとカスタムモデルトレーニングの選択肢と、それぞれの適用状況について解説しています。また、信用カード詐欺検出モデルの構築手順を紹介し、データセットのアップロード、モデルのトレーニングオプションの設定、そしてモデルの評価指標を解説しています。さらに、AutoMLモデルのトレーニング方法と、モデルのデプロイとテスト方法についても説明しています。最後に、カスタムモデルの構築に焦点を当てた次のエピソードへの期待をかき立てています。
Takeaways
- 📈 Vertex AIは、機械学習のワークフローの各ステップに必要なツールを提供するプラットフォームです。
- 🔍 Vertex AIは、画像、テーブル、テキスト、ビデオデータを扱うマネージドデータセットをサポートしています。
- 🤖 AutoMLは、最小限の労力で高品質なカスタムモデルを作成できる機能です。
- 💡 カスタマーコードを使用すると、クラウド上でカスタムトレーニングアプリケーションを実行できます。
- 📚 AutoMLは、画像分類、ビデオ分類、テキスト分類など、特定のユースケースに適しています。
- 🔧 カスタムモデルは、モデルのアーキテクチャやフレームワークに特定の要件がある場合に適しています。
- 👥 チームの機械学習の専門知識が限られている場合は、AutoMLが最適な選択です。
- 🚀 小規模なデータサイエンスチームは、AutoMLを通じて迅速な初期モデルを開発することが推奨されます。
- 🛠️ カスタマーモデルを使用すると、既存の基準を改善したり、ヒューリスティクスをテストしたりできます。
- 📊 Vertex AIを使用してAutoMLモデルを構築・トレーニングする手順は、データセットの作成から開始されます。
- 📝 モデルの評価指標として、混同行列と特徴重要性が重要です。
- 🔬 Vertex AIでは、個々の予測だけでなく、バッチ全体の特徴重要性を取得できます。
- 🌐 モデルのデプロイメント後、エンドポイントを作成し、トラフィックを分割して複数のエンドポイントに配布できます。
- 📘 UIとAPIの両方を使って、デプロイされたモデルから予測を得ることができます。
Q & A
AutoMLとは何ですか?
-AutoMLは、最小限の労力と機械学習の専門知識で高品質のカスタムモデルを作成できるツールです。AutoMLは、画像、ビデオの分類、テキストの分類、エンティティ抽出、センチメント分析、テーブル形式の回帰や分類などのユースケースに適しています。
カスタムモデルトレーニングコードとは何ですか?
-カスタムモデルトレーニングコードとは、クラウド上で事前に構築されたコンテナを使用して、独自のトレーニングアプリケーションを実行できるオプションです。これは、モデルのアーキテクチャやフレームワーク、出力モデルアセットについて制御する必要がある場合に適しています。
AutoMLを選択するべき状況は何ですか?
-AutoMLは、サポートされているAutoMLオファリングに適合するユースケースの場合、またはチームが機械学習の専門知識が限られている場合、また小規模なデータサイエンスチームで素早く初期モデルを開発する必要がある場合に適しています。
カスタムモデルを使用するべき状況は何ですか?
-カスタムモデルは、AutoMLがサポートしていないユースケースに適しています。また、モデルが混合型の入力タイプをとる場合や、モデルの背後にある要件に特定の制御が必要な場合にも適しています。
データセットの管理とは何ですか?
-データセットの管理とは、Vertex AIが提供する機能で、画像、テーブル、テキスト、ビデオデータのデータセットを管理することができます。管理されたデータセットは、モデルの構築とトレーニングに直接フィードされます。
モデルのトレーニング時に、AutoMLとカスタムトレーニングのどちらを選ぶべきですか?
-モデルのトレーニング時に使用するオプションは、ユースケースやチームの専門知識、チームの規模、そしてモデルの要件によって決まります。AutoMLは、専門知識が限られている場合や素早く初期モデルを開発する必要がある場合に適しています。一方、カスタムトレーニングは、より高度な制御が必要で、より専門的な知識を持つチームに適しています。
モデルの評価指標として、コンフュージョンマトリクスとは何ですか?
-コンフュージョンマトリクスは、テストセットの各クラスの例について、モデルが正しく予測した割合を示す指標です。これは、データセットが極端に偏っている場合に、全体の精度よりもモデルのパフォーマンスを測定するのに適した方法です。
特徴量の重要性とは何ですか?
-特徴量の重要性は、モデルが予測を行っているときに最も大きな信号を提供する特徴を示す指標です。これは、説明可能なAIのフィールドの一部であり、モデルが予測を行っている仕組みをより深く理解するのに役立ちます。
モデルのデプロイメントとは何ですか?
-モデルのデプロイメントとは、トレーニングされたモデルをエンドポイントに展開し、それから予測を得られるようにすることです。Vertex AIでは、モデルリソースに複数のエンドポイントを関連付け、エンドポイント間のトラフィックを分割することができます。
Vertex AIのUIとAPIのどちらを使用してモデルの予測を得ることができますか?
-Vertex AIでは、UIとAPIの両方を使ってモデルの予測を得ることができます。UIは、デプロイされたエンドポイントが期待通りに動作していることを確認するのに便利です。一方、APIは、プログラムから動的に予測を得るために使用されます。
トレーニングデータが偏っている場合、モデルのパフォーマンスを向上させるために何を試すことができますか?
-トレーニングデータが偏っている場合、モデルのパフォーマンスを向上させるためには、より多くのコンピュート時間をトレーニングに使用したり、より多くのトレーニングデータを収集することができます。また、特徴量の重要性を分析して、最も重要な特徴を特定し、モデルの性能を改善するのに役立てることができます。
Vertex AIを使用してモデルをトレーニングした後、次に何をすべきですか?
-Vertex AIを使用してモデルをトレーニングした後、次のステップはエンドポイントの作成です。その後、UIやAPIを通じてモデルの予測を得ることができます。また、モデルの評価指標を分析し、特徴量の重要性に基づいてモデルを改善することができます。
Outlines
📚 AI Simplifiedの紹介と機械学習ワークフローの概要
Priyanka Vergadiaがホストを務めるAI Simplifiedは、データの活用方法を学ぶ番組です。节目中で架空の企業が機械学習のワークフローを構築し、AIイノベーションを促進するためにVertex AIを活用しています。Vertex AIは、データセットの管理からモデルのトレーニング、評価、展開、予測まで、機械学習の各ステップに必要なツールを提供します。前回のエピソードでは、MLプロジェクトの最初のデータセットについて触れましたが、今回はMLワークフローの次のステップであるモデルの構築とトレーニングについて話します。
🤖 AutoMLとカスタムモデルトレーニングの選択基準
AutoMLを使用すると、最小限の労力で高品質なカスタムモデルを作成できますが、必要に応じてカスタムモデルのトレーニングコードを書くこともできます。AutoMLは、画像やビデオの分類、テキストの分類、エンティティ抽出、センチメント分析、テーブル回帰、クラスタリングなどのサポートされているユースケースに適しています。一方、カスタムモデルは、モデルのアーキテクチャやフレームワーク、出力モデルアセットに対する制御が必要、または混合型の入力タイプを持つ場合に適しています。また、チームの機械学習の経験やチームサイズも選択の際に考慮すべき要素です。
🔍 Vertex AIを使用したAutoMLモデルの構築とトレーニング
Vertex AIでAutoMLモデルを構築し、トレーニングする方法について学びます。BigQueryの公開データセットを使用して、クレジットカード詐欺検出モデルを作成します。データセットをアップロードし、トレーニングとテストの分割、モデルの名前付け、目的の定義を行います。また、データが極端に偏っているため、AUC PRCオプションを選択して、稀なクラスの正確さを最大化します。トレーニングのオプションでは、コンピュート時間の予算と早い停止を設定し、トレーニングジョブが完了するまで待ちます。その後、モデルの評価メトリックを確認し、混同行列と特徴の重要性を分析します。
🚀 モデルの展開と予測の取得
トレーニングが完了した後、Vertex AIでエンドポイントを作成し、モデルを展開します。エンドポイントに名前を付け、トラフィックの分割設定を行い、マシンタイプを選択して展開します。その後、UIからテスト予測を行ったり、APIを通じて動的な予測を取得することができます。ノートブックを使用して、Vertex AI SDKをインストールし、エンドポイントオブジェクトを作成してから、予測リクエストを行います。最後に、AutoMLとカスタムトレーニングの選択肢とその使用時、そしてVertex AIでMLモデルを構築しトレーニングする方法について学び、次のエピソードではカスタムモデルの構築とトレーニングに焦点を当てます。
Mindmap
Keywords
💡AutoML
💡カスタムモデル
💡
💡データセット
💡機械学習ワークフロー
💡TensorFlow
💡PyTorch
💡予測
💡モデル評価
💡混同行列
💡特徴量の重要性
💡エンドポイント
Highlights
Vertex AI provides tools for every step of the machine learning workflow, from managing datasets to training, evaluating, deploying, and making predictions.
Vertex AI supports managed datasets for image, tabular, text, and video data.
There are two options to train models in Vertex AI: AutoML and custom model training code.
AutoML allows creating high quality custom models with minimal effort and ML expertise for supported use cases like image/video classification, text classification, and tabular regression/classification.
Custom model training is suitable when use case doesn't fit AutoML offerings, requires control over model architecture/framework, or needs specific input types.
Factors to consider when choosing between AutoML and custom model training include use case, technical requirements, team expertise/experience, and team size.
AutoML is a good starting point for teams with limited ML expertise and smaller teams, while custom models allow more flexibility for experienced teams.
For quick initial models or proofs of concept, AutoML is recommended. Custom models can be used to improve upon baselines.
The credit card fraud detection model example uses a heavily imbalanced dataset from BigQuery public datasets.
When training AutoML models, you can specify the training objective, target column, and advanced options like train/test split and evaluation metrics.
For imbalanced datasets, precision-recall metrics like AUC PRC are more informative than overall accuracy.
AutoML model training starts with 1 compute hour to assess feature-label relationships, with options to train longer to improve performance.
Model evaluation metrics to focus on include the confusion matrix for class-specific accuracy and feature importance for understanding model predictions.
Feature importance provides insights into which input features most influence model predictions and can inform model improvements.
After training, you can deploy the model to an endpoint in Vertex AI to get predictions via UI or API.
Endpoints can have multiple versions/variants with traffic splitting, allowing A/B testing and gradual rollouts.
The UI allows quick testing of deployed models with random or custom input data to verify predictions.
REST API calls can dynamically retrieve predictions from deployed models for integration into applications.
The Vertex AI SDK can be used in notebooks to make prediction requests to deployed endpoints and retrieve results.
In summary, Vertex AI offers AutoML and custom training options with comprehensive tools for end-to-end ML workflows, from data management to deployment and prediction.
Transcripts
PRIYANKA VERGADIA: Hi, I'm Priyanka Vergadia.
And this is AI Simplified, where we
learn to make our data useful.
We're helping an imaginary company
that is in the process of building their machine learning
workflow.
And to accelerate AI innovation, they
are looking at Vertex AI, which provides
tools for every step of the machine learning workflow,
from managing data sets, to different ways of training
the model, evaluating, deploying,
and making predictions.
In the previous episode, we started
by looking at the first part of any ML project, the data sets.
Vertex AI supports managed data sets for image, tabular, text,
and video data.
In this episode, let's move further in the ML workflow
and talk about building and training the models.
The managed data sets we created earlier feed directly
into the model building and training.
Although you can bring external data sets
while building the model, managed data sets
bring some added benefits as I laid out
in the previous episode.
We have two options to train the model.
We can use AutoML which allows us to create high quality
custom models with minimal effort and machine learning
expertise.
And the second option is to write custom model training
code, where you can run custom training
applications in the cloud using pre-built containers
of your own.
Now when should you write your own model code and then
should you choose AutoML?
It depends.
So let's see.
If your use case fits a supported AutoML offering,
then starting with AutoML is a great choice.
And these use cases include cases where you have images,
or video classification, or object
detection, text classification, entity extraction
from the text, sentiment analysis of text,
tabular regression, and classification.
But if it does not fit any of those categories,
or your model takes some mixed input type, such
as you have images and then the metadata
is in the form of text, then it makes sense
to use custom model.
The other technical factor could be
that you have specific requirements for the underlying
model if you need control over your model's
architecture, framework, or the exported model assets.
For example, maybe your model needs
to be built in TensorFlow or PyTorch.
Then you use custom model.
Otherwise, for the basic use cases, just use AutoML.
The next factor could be how experienced
is your team with ML and AI.
If you have a team with limited machine learning expertise
in building custom models, then exploring AutoML
makes sense before looking into the custom model code
because it is the lowest barrier to entry.
Another deciding factor could be your team size.
Now if you have a small data science team and less machine
learning expertise in that team, it perhaps
makes more sense to work with AutoML because custom model
code would require more time and maintenance.
And use AutoML if you want to develop a quick initial model
to be used as a baseline or a proof of concept,
which could eventually end up being your production model.
But if you are looking to improve on your existing
baseline, or heuristics, then you
might want to write your own custom model
to test out the possibilities.
Hopefully, these factors have clarified
which path to take when it comes to building the models.
Now let's see how to build and train the AutoML model
using Vertex AI.
With that, onto the Google Cloud console.
We learned how to create data sets in the previous episode.
But for the sake of completeness,
let's create a data set.
In this example, we're using credit card fraud
detection data set available on BigQuery
public data sets to create a credit card fraud
detection model.
I have included the link to this data set below if you
would like to follow along.
Once the data is uploaded, we can analyze our data
in the rows and columns.
Right from the data set details page,
we can select Train New Model, define our objective,
which is classification here since we are labeling examples
as either fraudulent or non fraudulent.
This is where you decide whether you
want to use AutoML or custom training.
In this video, we're focusing on AutoML.
So we will select that.
Stay tuned for the next episode, where
I will cover a custom model.
Next, we give our model a name.
Under the Target column, we select Class.
This is an integer indicating whether or not
a particular transaction was fraudulent, zero for non fraud,
and one for fraud.
In the advanced options, you can specify a specific train test
split if you don't want Vertex AI to handle that automatically
for you.
In this case, we're using the random assignment.
But you can also specify this manually
when you upload a CSV of your data.
Or you can have the data split chronologically
if it has a time column.
In the Choose Training Options section,
we will go to the Advanced option.
And since this data is heavily imbalanced, less than 1%
of the data here contains fraudulent transactions,
we will choose the AUC PRC option,
which will maximize precision recall for the less
common class.
In this case, we care more about ensuring our model
can classify fraudulent transactions correctly.
Now the last step is compute and pricing.
Here we enter one as the number of compute hours for our budget
and leave early stopping enabled.
Training your AutoML model for one compute hour
is typically a good start for understanding whether there
is a relationship between the features and labels you've
selected.
From there, you can modify your features
and train for more time to improve model performance.
Then we are ready to start training.
From here, we can leave the UI and will get an email when
our training job completes.
All right.
So our model is ready.
Let's explore the model evaluation metrics.
We head to our Model tab and evaluate
the model we just trained.
There are many evaluation metrics here.
We will focus on two, the confusion matrix, and feature
importance.
A confusion matrix tells us the percentage of examples
from each class in our test set that our model predicted
correctly.
In the case of an imbalanced data
set like the one we're dealing with here,
this is a better measure of our model's performance
than overall accuracy.
Remember that less than 1% of the examples in our data set
were fraudulent transactions.
So if our model accuracy is 99%, there is a good chance
that it's just randomly guessing the non fraudulent class 99%
of the time.
That's why looking at our model's accuracy for each class
is a better metric here.
The confusion matrix shows that our initial model
is able to classify 85% of the fraudulent examples
in our test set correctly.
This is pretty good, especially considering
our significant data set imbalance.
Next, we could try training our model for more compute hours,
or gathering more training data to see if we can improve that
from this 85%.
Now this shows us the features that
provided the biggest signal to our model
when making predictions.
The feature importance is one type
of explainable AI, a field that includes various methods
for getting more insight into how animal model is making
predictions.
The feature importance chart is calculated as an aggregate
by looking at all of our model's predictions on our test set.
It shows us the most important features
across a batch of examples.
This chart would be more exciting
if most of the features in our data set were not obscured.
We might learn, for example, that the type of transaction,
transfer, deposit, et cetera can be the biggest
indicators of fraud.
In a real world scenario, these feature importance values
could be used to help us improve our model
and to have more confidence in its prediction.
We might decide to remove the least important features
next time we train a model, or to combine
two of our more significant features into a feature cross
to see if this improves our model's performance.
We are looking at feature importance across a batch here.
But we can also get feature importance
for individual predictions in Vertex AI.
And we'll see how to do that once we've deployed our model.
Now that we have trained model, the next step
is to create an endpoint in Vertex AI.
A model resource in Vertex AI can have multiple endpoints
associated with it.
And you can split traffic between endpoints.
On our model page, there is Deploy and Test tab.
There we click Deploy To Endpoint.
Give your endpoint a name like fraud version one or two.
And then leave the traffic splitting settings as is.
And then select a machine type for your model deployment.
We used an n1-highcpu-2 here but you
can choose whichever machine type you would like,
including one with GPUs.
Then select Done and click Continue.
Leave the selected location settings as is
and then click Deploy.
Your endpoint will take a few minutes to deploy.
When it is completed, you will see a green checkmark
next to it just like my version one here.
Now we are ready to get predictions
on our deployed model.
There are a few options for getting model predictions,
the UI and the API.
Let's check out both one by one.
On your model page where your endpoint is shown,
scroll down to the Test Your Model section.
Here, Vertex AI has chosen random values
for each of our model's features that we can
use to get a test prediction.
You're welcome to change these values if you like
and then scroll down to the bottom of the page
and select Predict.
In the prediction results section,
you should see your models predicted percentage
for each class.
A confidence score of 0.99 for class zero for example
means that our model thinks this example is 99% non fraudulent.
The UI is a great way to make sure the deployed endpoint is
working as expected.
But chances are that you will want
to get prediction dynamically via a REST API call.
To show you how to get model predictions here,
let's set up a notebook.
For that, we navigate to Notebooks option
and select TensorFlow Without GPUs.
Once created, open the notebook instance.
And then we open Python 3 notebook form the launcher.
In the notebook, we run the command in a cell
to install the Vertex AI SDK.
And below that, we add and run a new cell and the example
from our test set.
Next, we need to create the endpoint object
and then change the endpoint ID and project number
to your specific endpoint.
You can get the endpoint from the URL and the project ID
from the project dashboard.
We use that to make a prediction request to our endpoint.
And we see our prediction around 0.99 for the zero class,
which means the model thinks there
is a 99% chance this transaction is non fraudulent.
With that, we've learned about the two options
to train our models in Vertex AI, AutoML and custom training,
and when to use which one.
Then we went into the console and trained an ML model
from scratch.
In the next episode of AI Simplified,
we will look at building and training a custom model.
In the meantime, let's continue our discussion
in the comments below.
And don't forget to like and subscribe
to catch that next episode.
Browse More Related Video
RAG Evaluation (Answer Correctness) | LangSmith Evaluations - Part 12
YOLOv9 Tutorial: Train Model on Custom Dataset | How to Deploy YOLOv9
How to Fine Tune Google PaliGemma, a Vision Language Model?
Advent Of Cyber: Day 15 - Building Email Spam Detector with ML
Why Evals Matter | LangSmith Evaluations - Part 1
日本一わかりやすいStableDiffusion WebUI AUTOMATIC1111(ローカル版)のインストール方法と基本的な使い方
5.0 / 5 (0 votes)