3.P1 Loading Data and Splitting x, y
[video] /api/lesson-media/videos/9b417aa2-5e9f-4ae3-a9db-2a3b7f03f372-1794878469169-4e7bec584a48f8e8.mp4
[markdown] content available only on the platform
[markdown] content available only on the platform
Flashcards · 3.P1 Loading Data and Splitting x, y
pandas (pd) — A Python library for working with structured data such as CSV, Excel and JSON; usually imported as pd.
import pandas as pd
pd.read_csv() — Reads a CSV file into a pandas DataFrame.
data = pd.read_csv('diabetes.csv')
DataFrame — A pandas table with labelled rows and columns.
data has 768 rows x 9 columns.
Outcome — The label column of diabetes.csv: 1 = has diabetes, 0 = does not.
y = data['Outcome']
Feature matrix x — The table of input columns the model uses to make predictions.
x = data.drop('Outcome', axis=1) -> 8 columns
Label y — The target column the model learns to predict.
y.shape -> (768,)
axis parameter — In drop, axis=0 removes rows and axis=1 removes columns.
data.drop('Outcome', axis=1)
data.shape — A DataFrame attribute giving (number of rows, number of columns).
(768, 9)
value_counts() — Counts how many times each value appears in a column; useful to check class balance.
y.value_counts()
