시작하기무료로 시작하기

범주형 열

항공편 데이터에는 carrierorg라는 두 개의 범주형 데이터 열이 있습니다. 이 열들을 숫자 인덱스 값으로 변환해야 합니다.

이 연습은 강의의 일부입니다

PySpark로 하는 Machine Learning

강의 보기

연습 안내

  • 적절한 클래스를 가져온 후, carrier 열을 문자열에서 숫자 인덱스로 변환할 인덱서 객체를 생성하세요.
  • 항공편 데이터에 인덱서 객체를 학습시키세요.
  • 학습된 인덱서를 사용해 숫자 인덱스 열을 생성하세요.
  • org 열에도 동일한 과정을 반복하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

from pyspark.ml.feature import ____

# Create an indexer
indexer = ____(inputCol=____, outputCol='carrier_idx')

# Indexer identifies categories in the data
indexer_model = indexer.____(flights)

# Indexer creates a new column with numeric index values
flights_indexed = ____.____(____)

# Repeat the process for the other categorical feature
flights_indexed = ____(inputCol=____, outputCol='org_idx').____(____).____(____)
flights_indexed.show(5)
코드 편집 및 실행