Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Case

Case Python Experiment

Rating
-
Sold
-
Pages
9
Grade
A+
Uploaded on
25-12-2023
Written in
2023/2024

Design and implement a data analysis project to calculate and predict electricity bills, Using a dataset containing monthly electricity consumption data for a group of residential customers. This is full of practical experiment and projects

Show more Read less
Institution
Course

Content preview

19MS279- Data science with Python

1. Design and implement a data analysis project to calculate and predict electricity bills, Using a
dataset containing monthly electricity consumption data for a group of residential customers.

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
import matplotlib.pyplot as plt

# Let's create a sample dataset
np.random.seed(42)

# Generating random data for demonstration
months = pd.date_range(start='2023-01-01', end='2023-12-31', freq='M')
consumption = np.random.randint(100, 500, size=len(months))
dataset = pd.DataFrame({'Month': months, 'Consumption': consumption})

# Display the first few rows of the dataset
print(dataset.head())




Generated data

Month Consumption
0 2023-01-31 202
1 2023-02-28 448
2 2023-03-31 370
3 2023-04-30 206
4 2023-05-31 171

, # Plot the consumption trend over time
plt.figure(figsize=(10, 6))
plt.plot(dataset['Month'], dataset['Consumption'])
plt.title('Monthly Electricity Consumption Over Time')
plt.xlabel('Month')
plt.ylabel('Consumption (kWh)')
plt.show()

# Extract features from the date
dataset['Year'] = dataset['Month'].dt.year
dataset['MonthNumber'] = dataset['Month'].dt.month

# Display the modified dataset
print(dataset.head())

# Make predictions on the test set
y_pred = model.predict(X_test)

# Evaluate the model
mse = mean_squared_error(y_test, y_pred)
print(f'Mean Squared Error: {mse}')

# Visualize the predictions
plt.figure(figsize=(10, 6))
plt.scatter(X_test['MonthNumber'], y_test, color='black', label='Actual Consumption')
plt.plot(X_test['MonthNumber'], y_pred, color='blue', linewidth=3, label='Predicted Consumption')
plt.title('Actual vs Predicted Electricity Consumption')
plt.xlabel('Month')
plt.ylabel('Consumption (kWh)')
plt.legend()
plt.show()

Written for

Course

Document information

Uploaded on
December 25, 2023
Number of pages
9
Written in
2023/2024
Type
CASE
Professor(s)
Sanjay d
Grade
A+

Subjects

Available practice questions

$26.39
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
Techn028

Also available in package deal

Get to know the seller

Seller avatar
Techn028 Saveetha Engineering College
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
20
Last sold
-
Future Leaders

Don't Depend on Others....

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions