Correlation Analysis in python
Correlation Analysis in python
1. Introduction to Correlation
2. Setting Up Python
Copy code
pip install pandas seaborn matplotlib scipy
Copy code
import pandas as pd # For data handling
import seaborn as sns # For data visualization
import matplotlib.pyplot as plt # For plotting graphs
from scipy.stats import pearsonr # For statistical analysis
Copy code
# Sample data
data = {
'StudyHours': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], # Number of
hours studied
'TestScores': [55, 60, 65, 70, 75, 80, 85, 90, 95, 100] #
Corresponding test scores
}
Explanation:
Copy code
# Create scatter plot
sns.scatterplot(x='StudyHours', y='TestScores', data=df)
plt.title("Scatter Plot of Study Hours vs Test Scores")
plt.xlabel("Study Hours")
plt.ylabel("Test Scores")
plt.show()
Explanation:
Copy code
# Add more variables for demonstration
df['PracticeTests'] = [2, 3, 1, 2, 3, 4, 2, 5, 4, 6] # Number
of practice tests taken
Explanation:
Copy code
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from scipy.stats import pearsonr
# Step 1: Create sample data
data = {
'StudyHours': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
'TestScores': [55, 60, 65, 70, 75, 80, 85, 90, 95, 100],
'PracticeTests': [2, 3, 1, 2, 3, 4, 2, 5, 4, 6]
}