Skip to Content
スパーク定義ガイド
book

スパーク定義ガイド

by Bill Chambers, Matei Zaharia
March 2025
Intermediate to advanced
606 pages
9h
Japanese
O'Reilly Media, Inc.
Content preview from スパーク定義ガイド

第25章 前処理と特徴工学 前処理とフィーチャーエンジニアリング

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

データサイエンティストであれば誰でも、高度なアナリティクスにおける最大の課題(そして時間の浪費)の一つが前処理であることを知っている。特に複雑なプログラミングというわけではなく、扱うデータに関する深い知識と、そのデータをうまく活用するためにモデルに何が必要かを理解することが必要なのだ。この章では、Sparkを使ってどのように前処理とフィーチャーエンジニアリングを行うことができるかを詳しく説明する。MLlibモデルを学習するために必要なコア要件について、データ構造の観点から説明する。そして、このような作業を行うためにSparkが提供する様々なツールについて説明する。

ユースケースに応じてモデルを形式化する

Sparkの様々な高度分析ツールのためにデータを前処理するには、最終的な目的を考慮する必要がある。以下のリストでは、MLlib の各先進分析タスクの入力データ構造の要件を説明する:

  • ほとんどの分類や回帰アルゴリズムの場合、ラベルを表すDouble 型の列と、特徴を表すVector 型の列(密または疎)にデータを入れたい。

  • レコメンデーションの場合、データをユーザの列、アイテム(映画や本など)の列、評価の列に分けたい。

  • 教師なし学習の場合、特徴を表現するためにVector (密または疎)型の列が必要となる。

  • グラフ分析の場合、頂点のDataFrameと辺のDataFrameが必要になる。

これらの形式でデータを取得する最良の方法は、トランスフォーマーを使うことである。トランスフォーマーとは、DataFrameを引数として受け取り、新しいDataFrameをレスポンスとして返す関数のことである。この章では、ありとあらゆるトランスフォーマーを列挙するのではなく、特定のユースケースに関連するトランスフォーマーに焦点を当てる。

Spark は、org.apache.spark.ml.feature パッケージの一部として、多くの変換器を提供している。Pythonの対応するパッケージはpyspark.ml.feature である。Spark MLlib には常に新しいトランスフォーマーが追加されているため、本書で定義することは不可能である。最新の情報はSparkのドキュメントサイトで発見できる。

先に進む前に、いくつかの異なるサンプルデータセットを読み込む。それぞれのデータセットには、この章で操作する異なるプロパティがある:

// in Scala
val sales = spark.read.format("csv")
  .option("header", "true")
  .option("inferSchema", "true")
  .load("/data/retail-data/by-day/*.csv")
  .coalesce(5)
  .where("Description IS NOT NULL")
val fakeIntDF = spark.read.parquet("/data/simple-ml-integers")
var simpleDF = spark.read.json("/data/simple-ml")
val scaleDF = spark.read.parquet("/data/simple-ml-scaling" ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

高性能Spark

高性能Spark

Holden Karau, Rachel Warren
生成AIの可視化

生成AIの可視化

Priyanka Vergadia, Valliappa Lakshmanan
ソフトウェア工学の基礎

ソフトウェア工学の基礎

Nathaniel Schutta, Dan Vega

Publisher Resources

ISBN: 9798341627567