0% found this document useful (0 votes)
2 views2 pages

Regression Workflow Python Notes

The document outlines a machine learning workflow for regression problems using Python, detailing steps from importing libraries to model evaluation. It includes dataset loading, exploration, preprocessing, univariate and bivariate EDA, train-test splitting, training various regression models, and evaluating their performance. The final step involves comparing models based on R² scores and error metrics to select the best-performing model.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Regression Workflow Python Notes

The document outlines a machine learning workflow for regression problems using Python, detailing steps from importing libraries to model evaluation. It includes dataset loading, exploration, preprocessing, univariate and bivariate EDA, train-test splitting, training various regression models, and evaluating their performance. The final step involves comparing models based on R² scores and error metrics to select the best-performing model.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Machine Learning Workflow for Regression

Problems (Python)
1. Import Libraries
import pandas as pd
import numpy as np
import [Link] as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from [Link] import LabelEncoder, StandardScaler
from [Link] import mean_absolute_error, mean_squared_error, r2_score

Observation: Required libraries imported successfully.

2. Load Dataset
df=pd.read_csv('[Link]')
[Link]()

Observation: Verify dataset loaded correctly.

3. Dataset Exploration
[Link]()
[Link]
[Link]()
[Link]().sum()
[Link]().sum()
[Link]

Inference: Understand structure, data types, missing values and duplicates.

4. Preprocessing
df=df.drop_duplicates()
[Link]([Link](numeric_only=True), inplace=True)
for col in df.select_dtypes(include='object'):
df[col]=LabelEncoder().fit_transform(df[col])
X=[Link]('Price',axis=1)
y=df['Price']
X=StandardScaler().fit_transform(X)

Inference: Data is cleaned, encoded and standardized.

5. Univariate EDA
[Link](figsize=(12,10))
[Link](data=df)
[Link](df['Price'],kde=True)

Observation: Examine distributions and outliers.

6. Bivariate EDA
[Link]([Link](),annot=True,cmap='coolwarm')
[Link](x='Feature1',y='Price',data=df)
[Link](df)

Inference: Identify feature relationships.

7. Train-Test Split
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=42)

Observation: 80% training and 20% testing.


8. Regression Algorithms
LinearRegression()
DecisionTreeRegressor()
RandomForestRegressor()
SVR()
KNeighborsRegressor()

Observation: Train multiple regression models.

9. Evaluation
mae=mean_absolute_error(y_test,y_pred)
mse=mean_squared_error(y_test,y_pred)
rmse=[Link](mse)
r2=r2_score(y_test,y_pred)

Inference: Lower MAE/MSE/RMSE and higher R² indicate better performance.

10. Actual vs Predicted


[Link](y_test,y_pred)
[Link]('Actual')
[Link]('Predicted')

Observation: Points close to the diagonal indicate good predictions.

11. Model Comparison


Store R² scores in a DataFrame and plot a bar chart.

Observation: Select the model with the highest R² and lowest errors.

You might also like