##Bai 1:

# Sinh 500 giá trị từ phân phối chuẩn N(50, 225)
set.seed(123)  # Để kết quả có thể lặp lại
data <- rnorm(n = 500, mean = 50, sd = sqrt(225))

# Kiểm định Shapiro-Wilk
shapiro_test <- shapiro.test(data)

# In kết quả kiểm định
print(shapiro_test)
## 
##  Shapiro-Wilk normality test
## 
## data:  data
## W = 0.99812, p-value = 0.8639
# Đánh giá kết quả
alpha <- 0.05
if (shapiro_test$p.value > alpha) {
  print("Không thể bác bỏ giả thuyết H0: Dữ liệu có phân phối chuẩn.")
} else {
  print("Bác bỏ giả thuyết H0: Dữ liệu không có phân phối chuẩn.")
}
## [1] "Không thể bác bỏ giả thuyết H0: Dữ liệu có phân phối chuẩn."

##Bai 2:

#install.packages("reticulate")
library("reticulate")
use_python("D:/HocTapp/Anacondaaa/python.exe", required = TRUE)  # Thay bằng đường dẫn Python của bạn
# Import thư viện
import pandas as pd
import seaborn as sns

# Đọc tập dữ liệu Iris từ seaborn
df = sns.load_dataset("iris")

# Hiển thị 5 dòng đầu tiên
df.head()
##    sepal_length  sepal_width  petal_length  petal_width species
## 0           5.1          3.5           1.4          0.2  setosa
## 1           4.9          3.0           1.4          0.2  setosa
## 2           4.7          3.2           1.3          0.2  setosa
## 3           4.6          3.1           1.5          0.2  setosa
## 4           5.0          3.6           1.4          0.2  setosa
# Tính phương sai của từng cột số
variances = df.var(numeric_only=True)

# Hiển thị kết quả
variances
## sepal_length    0.685694
## sepal_width     0.189979
## petal_length    3.116278
## petal_width     0.581006
## dtype: float64
import matplotlib.pyplot as plt
import seaborn as sns

# Vẽ biểu đồ scatter
plt.figure(figsize=(8, 5))
sns.scatterplot(data=df, x="sepal_length", y="sepal_width", hue="species", palette="viridis")
plt.title("Biểu đồ Scatter giữa Sepal.Length và Sepal.Width")
plt.xlabel("Chiều dài đài hoa (Sepal.Length)")
plt.ylabel("Chiều rộng đài hoa (Sepal.Width)")
plt.show()