Knowledge Graph — Coursera NotesAcademic disciplinesInformation Technology / Computer ScienceArtificial IntelligenceMachine Learning & Data

Data preprocessing

concept · part of Machine Learning & Data

The step of transforming raw data into a format suitable for machine learning, including scaling and encoding.

Feature values are scaled to a range between 0 and 1 using MinMaxScaler to ensure optimal neural network performance. The dataset is split into 80% training and 20% testing sets.

Missing values can be handled by imputation, e.g., filling with median for numerical columns. Duplicate entries should be removed to ensure data consistency.

for column in df.select_dtypes(include=['float64', 'int64']).columns:
 df[column].fillna(df[column].median(), inplace=True)
df.drop_duplicates(inplace=True)

Standardization scales numerical features to have zero mean and unit variance using StandardScaler from scikit-learn. This prevents any single feature from dominating the model.

scaler = StandardScaler()
numeric_features = df.select_dtypes(include=['float64', 'int64']).columns
df[numeric_features] = scaler.fit_transform(df[numeric_features])

Categorical features are converted into numerical format using one-hot encoding via pd.get_dummies(df, drop_first=True). This ensures compatibility with machine learning algorithms.

df = pd.get_dummies(df, drop_first=True)

Outliers can be detected using Z-score analysis. Data points with Z-score >= 3 are considered outliers and removed to maintain dataset integrity.

z_scores = np.abs(stats.zscore(df.select_dtypes(include=['float64', 'int64'])))
df = df[(z_scores < 3).all(axis=1)]

Logarithmic transformation (e.g., np.log1p) is applied to reduce skewness in skewed features, making the data more suitable for modeling.

df['income_log'] = np.log1p(df['income'])

The dataset is split into training and testing sets using train_test_split from scikit-learn, typically with test_size=0.2 and random_state=42 for reproducibility. This ensures unbiased evaluation of model performance.

X = df.drop('target', axis=1)
y = df['target']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

Inside Data preprocessing (10)

Connections

This is the text view of an interactive 3D knowledge graph — open this page with JavaScript enabled to explore it visually.

🧠 Knowledge Graph

Select a node

The owner's editing tools — shown here so you can see how the graph is grown, but read-only.

Click a bubble to drill in · click again to collapse · drag to move around