0Pricing
NLP Academy · レッスン

複数の特徴量タイプを組み合わせる

テキスト特徴量と数値特徴量を連結する

「複数の特徴量タイプを組み合わせる」はCoddyKit上の無料NLP Academyレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはNLP Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 NLP Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

One Type Is Rarely Enough

TF-IDF captures words, your hand-built numbers capture style. The best models often combine several feature types into one input.

Text and Numbers Together

Imagine a review's TF-IDF vector plus its length and star rating. Stacking these gives the model both word and numeric signal at once.

The Shape Problem

TF-IDF outputs a sparse matrix, while your custom features are a small dense array. You must join them along the same rows.

Side by Side, Not Stacked

We glue features as new columns for the same documents, not new rows. This horizontal join is called concatenation.

Stacking Sparse Matrices

SciPy offers hstack to place matrices side by side efficiently. It keeps everything sparse, so memory stays under control.

from scipy.sparse import hstack
combined = hstack([tfidf_matrix, numeric_features])

ColumnTransformer to the Rescue

scikit-learn's ColumnTransformer applies different steps to different columns. It is the clean way to route text and numbers through one pipeline.

Wiring It Up

You give ColumnTransformer a list of named transformers and the columns each one handles. It builds a single feature matrix for you.

from sklearn.compose import ColumnTransformer
ct = ColumnTransformer([("text", TfidfVectorizer(), "review"), ("num", "passthrough", ["length"])])

FeatureUnion for Parallel Steps

When several transformers read the same input, FeatureUnion runs them in parallel and joins the outputs. It is built for combining feature extractors.

Mind the Scales

Raw word counts and a 0-to-1000 length live on very different ranges. Mixing them often calls for scaling so no feature dominates.

Let Data Decide

Adding feature types should be a measured experiment. Compare a validation score before and after to confirm the combo actually helps.

More Is Not Always Better

Throwing in every feature can add noise and slow training. Aim for a small, well-chosen mix over a giant kitchen sink. 🧹

Quick Check

How should TF-IDF and numeric features be merged?

Recap

Strong models combine text and numeric features by concatenating columns. Use hstack, ColumnTransformer, or FeatureUnion, and scale before mixing. ✅

よくある質問

「複数の特徴量タイプを組み合わせる」レッスンは無料ですか?

はい。「複数の特徴量タイプを組み合わせる」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、NLP Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 NLP Academyコースには全4レッスンが含まれています。

「複数の特徴量タイプを組み合わせる」で何を学びますか?

テキスト特徴量と数値特徴量を連結する ブラウザで直接実行するハンズオンコードでNLP Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

NLP Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのNLP Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。

「複数の特徴量タイプを組み合わせる」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このNLP Academyレッスンでコードを書いて実行できますか?

はい。すべてのNLP Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. Bag-of-Words の先へ
  2. 頑健性のための文字 N-Gram
  3. 複数の特徴量タイプを組み合わせる
  4. 特徴量をスケーリングして選択する
← NLP Academyに戻る