0Pricing
Data Science Academy · บทเรียน

สร้างคุณลักษณะจากวันที่และข้อความ

ดึงสัญญาณจากฟิลด์ดิบ

สร้างคุณลักษณะจากวันที่และข้อความ เป็นบทเรียน Data Science Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Data Science Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Data Science Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Raw Fields Hide Signal

A timestamp or a free-text note holds rich clues a model cannot read directly. Feature engineering pulls that signal into usable columns. 🔍

Parse the Date First

Before mining a date, convert the string with to_datetime. Only a real datetime exposes the handy parts you want to extract.

df['ts'] = pd.to_datetime(df['ts'])

The dt Accessor

The dt accessor unlocks date parts on a datetime column. Reach for it to grab year, month, day, and more in one line.

df['year'] = df['ts'].dt.year
df['month'] = df['ts'].dt.month

Day of Week

Pull dayofweek to capture weekly rhythm, where Monday is 0 and Sunday is 6. Behavior often shifts a lot by weekday.

df['weekday'] = df['ts'].dt.dayofweek

Weekend Flag

Turn the weekday into a simple boolean: is this a weekend? Such yes-or-no flags are easy for models to learn from.

df['is_weekend'] = df['ts'].dt.dayofweek >= 5

Cyclical Time

Hour 23 sits right next to hour 0, yet the numbers look far apart. Cyclical encoding with sine and cosine fixes that wrap-around.

Text: Length and Counts

Start simple with text. The character length of a review or its word count is often a surprisingly strong feature.

df['len'] = df['review'].str.len()
df['words'] = df['review'].str.split().str.len()

Contains a Keyword

Flag whether text holds a key term using str.contains. A column for words like refund can capture clear intent.

df['has_refund'] = df['review'].str.contains('refund')

Bag of Words

To use words themselves, count them. A bag-of-words turns text into one column per term holding how often it appears.

from sklearn.feature_extraction.text import CountVectorizer
X = CountVectorizer().fit_transform(df['review'])

TF-IDF Weighs Words

Plain counts overrate common words. TF-IDF rewards terms that are frequent in one row yet rare overall, so the distinctive words stand out.

from sklearn.feature_extraction.text import TfidfVectorizer
X = TfidfVectorizer().fit_transform(df['review'])

Avoid Leaky Features

Never build a feature from information unavailable at prediction time. A leaky column inflates scores in testing, then fails in the real world.

Quick Check

You have a datetime column and want the weekday number. What do you use?

Recap: Date and Text Features

You mined raw fields into signal: parse dates then use dt for parts and flags, and turn text into lengths, keyword flags, or word counts. 🎉

คำถามที่พบบ่อย

บทเรียน “สร้างคุณลักษณะจากวันที่และข้อความ” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “สร้างคุณลักษณะจากวันที่และข้อความ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Data Science Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Data Science Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “สร้างคุณลักษณะจากวันที่และข้อความ”

ดึงสัญญาณจากฟิลด์ดิบ คุณปฏิบัติ Data Science Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Data Science Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Data Science Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “สร้างคุณลักษณะจากวันที่และข้อความ” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Data Science Academy นี้ได้ไหม

ได้ บทเรียน Data Science Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. แบ่งตัวเลขเป็นหมวดหมู่
  2. เข้ารหัสคอลัมน์เชิงหมวดหมู่
  3. ปรับสเกลและทำตัวเลขให้เป็นมาตรฐาน
  4. สร้างคุณลักษณะจากวันที่และข้อความ
← กลับไปที่ Data Science Academy