Linear regression is a fundamental machine learning algorithm that helps in understanding the relationship between independent and dependent variables. It is widely used in various fields for predicting numerical outcomes based on one or more input features. To practice and learn about linear regression, it is essential to have access to good quality datasets. In this blog, we have compiled a list of 17 datasets suitable for training linear regression models, available in CSV or easily convertible to CSV (Excel) format. I have also provided a sample Python code you can use to train using these datasets.
The following is a list of 15 dataset which you can use to train linear regression models for learning purpose:
The following is a sample Python code snippet demonstrating how to train a linear regression model using the Boston Housing Dataset. The following Python code snippet imports the necessary libraries, loads the Boston Housing Dataset, splits the data into training and testing sets, trains a linear regression model, makes predictions on the test set, and calculates the performance metrics (Mean Squared Error, Root Mean Squared Error, and R-squared) to evaluate the model’s performance.
The above code can be used as it is to read CSV files from URL and train the linear regression models. However, if the file is downloaded to your local drive, you may try with the following Python code:
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score
# Load the Boston Housing Dataset
url = "https://raw.githubusercontent.com/selva86/datasets/master/BostonHousing.csv"
df = pd.read_csv(url)
# Separate the features (X) and target (y)
X = df.drop('medv', axis=1)
y = df['medv']
# Split the dataset into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Train the linear regression model
lr = LinearRegression()
lr.fit(X_train, y_train)
# Make predictions on the test set
y_pred = lr.predict(X_test)
# Calculate the performance metrics
mse = mean_squared_error(y_test, y_pred)
rmse = np.sqrt(mse)
r2 = r2_score(y_test, y_pred)
# Print the performance metrics
print(f"Mean Squared Error: {mse:.2f}")
print(f"Root Mean Squared Error: {rmse:.2f}")
print(f"R-squared: {r2:.2f}")
# Load the dataset from local drive
file_path = "path/to/your/csv_file.csv"
df = pd.read_csv(file_path)
# Replace 'feature_columns' and 'target_column' with appropriate column names
feature_columns = ['feature1', 'feature2', 'feature3']
target_column = 'target'
# Separate the features (X) and target (y)
X = df[feature_columns]
y = df[target_column]
In this blog post, we compiled a diverse list of 17 datasets (CSV, Excel) suitable for training and practicing linear regression models. These datasets cover a broad range of topics, from predicting house prices to forecasting energy consumption. Using these datasets, you can not only gain hands-on experience with linear regression but also explore various aspects of the machine learning process, such as data preprocessing, feature selection, model evaluation, and improvement.
By working with these datasets, you’ll deepen your understanding of the assumptions and limitations of linear regression models and learn how to apply this fundamental algorithm effectively. Additionally, you’ll develop the skills necessary to tackle real-world problems using linear regression, paving the way for you to explore more complex machine learning techniques.
In recent years, artificial intelligence (AI) has evolved to include more sophisticated and capable agents,…
Adaptive learning helps in tailoring learning experiences to fit the unique needs of each student.…
With the increasing demand for more powerful machine learning (ML) systems that can handle diverse…
Anxiety is a common mental health condition that affects millions of people around the world.…
In machine learning, confounder features or variables can significantly affect the accuracy and validity of…
Last updated: 26 Sept, 2024 Credit card fraud detection is a major concern for credit…