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

Regression Analysis Simple Regression

Regression Analysis is a statistical method for modeling the relationship between a dependent variable and one or more independent variables, primarily used for prediction and understanding relationships. Key terms include dependent variable, independent variable, intercept, coefficient, and residual, with applications in forecasting, risk analysis, and consumer behavior. An example illustrates predicting exam scores based on study hours using simple linear regression, demonstrating a positive relationship between study time and performance.

Uploaded by

BOT MAYANK
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 views10 pages

Regression Analysis Simple Regression

Regression Analysis is a statistical method for modeling the relationship between a dependent variable and one or more independent variables, primarily used for prediction and understanding relationships. Key terms include dependent variable, independent variable, intercept, coefficient, and residual, with applications in forecasting, risk analysis, and consumer behavior. An example illustrates predicting exam scores based on study hours using simple linear regression, demonstrating a positive relationship between study time and performance.

Uploaded by

BOT MAYANK
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
You are on page 1/ 10

Regression Analysis

Regression Analysis is a statistical technique used to model and analyze the


relationship between a dependent variable and one or more independent
variables. Its main goal is to predict outcomes and understand the strength
and nature of relationships among variables.

Types of Regression Analysis:

Key Terms:
 Dependent Variable (Y): The variable we want to predict.
 Independent Variable (X): The variable(s) used to make the prediction.
 Intercept (a): Value of Y when X = 0.
 Coefficient (b): Measures the change in Y for a one-unit change in X.
 Residual/Error (ε): Difference between actual and predicted values.
Applications:
 Forecasting sales, prices, or trends.
 Risk analysis in finance.
 Estimating real estate values.
 Understanding consumer behavior.

Example Question: A researcher wants to study the relationship between


hours studied and exam scores of students.

QUESTION: Using simple linear regression, predict the exam score if a student
studies for 7 hours.

Solution Steps:
Solution for the give problem
Table with Summation Row

Step 3: Calculate the Intercept (a)


Regression Equation

Step 4: Predict the Exam Score for 7 Hours Studied

Final Answer:
If a student studies for 7 hours, the predicted exam score is 81.75.
Interpretation:

 Intercept (55.5): This is the predicted score for a student who


studied 0 hours. While this may not have practical meaning, it
helps anchor the line.

 Slope (3.75): For each additional hour studied, the exam score
is expected to increase by 3.75 points.

 The model shows a positive linear relationship between study


time and exam performance.
What is a Regression Line / Graph?

Purpose of the Regression Line:


 Predict values of the dependent variable (Y) for given inputs
(X).
 Visualize the trend or pattern in data.
 Show direction (positive or negative) and strength of the
relationship.
Graph Example:
#Python codes
import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression

# Step 1: Prepare the data


data = {
'Hours_Studied': [2, 4, 6, 8, 10],
'Exam_Score': [65, 70, 75, 85, 95]
}

df = pd.DataFrame(data)

# Step 2: Define X and Y


X = df[['Hours_Studied']] # 2D array
y = df['Exam_Score'] # 1D array

# Step 3: Fit the Linear Regression model


model = LinearRegression()
model.fit(X, y)

# Step 4: Get the intercept and coefficient


intercept = model.intercept_
slope = model.coef_[0]
print(f"Regression Equation: Y = {intercept:.2f} + {slope:.2f}X")

# Step 5: Predict the score for 7 hours of study


predicted_score = model.predict([[7]])
print(f"Predicted Exam Score for 7 hours of study:
{predicted_score[0]:.2f}")

#Output
#Plotting
import matplotlib.pyplot as plt
import numpy as np

# Regression equation: Y = 55.5 + 3.75X


def regression_line(x):
return 55.5 + 3.75 * x

# Generate X values (e.g., from 0 to 12)


x_values = np.linspace(0, 12, 100)
y_values = regression_line(x_values)

# Plot the line


plt.figure(figsize=(8, 5))
plt.plot(x_values, y_values, color='red', label='Y = 55.5 + 3.75X')

# Optional: add original data points


x_data = [2, 4, 6, 8, 10]
y_data = [65, 70, 75, 85, 95]
plt.scatter(x_data, y_data, color='blue', label='Original Data')

# Optional: add prediction for 7 hours


x_pred = 7
y_pred = regression_line(x_pred)
plt.scatter(x_pred, y_pred, color='green', marker='x', s=100,
label=f'Prediction (X={x_pred})')

# Labels and title


plt.title('Graph of Regression Equation')
plt.xlabel('Hours Studied (X)')
plt.ylabel('Exam Score (Y)')
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()

#Output

You might also like