Câu hỏi của tôi là làm thế nào để tạo biểu đồ phân phối bình thường từ khung dữ liệu trong Python. Tôi có thể tìm thấy nhiều thông tin để tạo biểu đồ như vậy từ các số ngẫu nhiên, nhưng tôi không biết làm thế nào để làm từ khung dữ liệu.
Đầu tiên, tôi tạo ra các số ngẫu nhiên và tạo một khung dữ liệu.
import numpy as np
import pandas
from pandas import DataFrame
cv1 = np.random.normal[50, 3, 1000]
source = {"Genotype": ["CV1"]*1000, "AGW": cv1}
Cultivar_1=DataFrame[source]
Sau đó, tôi đã cố gắng thực hiện một biểu đồ phân phối bình thường.
sns.kdeplot[data = Cultivar_1['AGW']]
plt.xlim[[30,70]]
plt.xlabel["Grain weight [mg]", size=12]
plt.ylabel["Frequency", size=12]
plt.grid[True, alpha=0.3, linestyle="--"]
plt.show[]
Tuy nhiên, đây là biểu đồ mật độ, không phải là biểu đồ phân phối bình thường được tính toán bằng độ lệch trung bình và độ lệch chuẩn.mean and standard deviation.
Bạn có thể cho tôi biết tôi cần sử dụng mã nào để tạo biểu đồ phân phối bình thường không?
Thanks!!
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Prerequisites:
- Đọc
- Bàn luận
- Matplotlib
- Numpy
Scipy is a probability function used in statistics that tells about how the data values are distributed. It is the most important probability distribution function used in statistics because of its advantages in real case scenarios. For example, the height of the population, shoe size, IQ level, rolling a die, and many more.
Số liệu thống kê
Phân phối bình thường là một hàm xác suất được sử dụng trong các số liệu thống kê cho biết cách phân phối giá trị dữ liệu. Đây là chức năng phân phối xác suất quan trọng nhất được sử dụng trong số liệu thống kê vì lợi thế của nó trong trường hợp thực tế. Ví dụ, chiều cao của dân số, kích thước giày, mức IQ, lăn một cái chết, và nhiều hơn nữa. & NBSP;
Hàm mật độ xác suất của phân phối bình thường hoặc Gaussian được đưa ra bởi:
Hàm mật độ xác suất
- Ở đâu, x là biến, MU là giá trị trung bình và độ lệch chuẩn Sigmais python’s data visualization library which is widely used for the purpose of data visualization.
- Các mô -đun cần thiết is a general-purpose array-processing package. It provides a high-performance multidimensional array object, and tools for working with these arrays. It is the fundamental package for scientific computing with Python.
- Matplotlib là thư viện trực quan hóa dữ liệu Python, được sử dụng rộng rãi cho mục đích trực quan hóa dữ liệu.is a python library that is useful in solving many mathematical equations and algorithms.
- Numpyis một gói xử lý mảng đa năng. Nó cung cấp một đối tượng mảng đa chiều hiệu suất cao và các công cụ để làm việc với các mảng này. Đây là gói cơ bản để điện toán khoa học với Python.module provides functions for calculating mathematical statistics of numeric data.
Scipy là một thư viện Python hữu ích trong việc giải nhiều phương trình toán học và thuật toán.
- Mô -đun thống kê cung cấp các chức năng để tính toán số liệu thống kê toán học của dữ liệu số.
Syntax:
mean[data]
- Các chức năng được sử dụng
Syntax:
stdev[data]
- Để tính toán trung bình của dữ liệu
Syntax:
Để tính toán độ lệch chuẩn của dữ liệu
Để tính toán mật độ xác suất bình thường của định mức dữ liệu.pdf được sử dụng, nó đề cập đến hàm mật độ xác suất bình thường là mô -đun trong thư viện SCIPY sử dụng hàm mật độ xác suất trên để tính toán giá trị.
Norm.pdf [dữ liệu, LỘC, tỷ lệ]
- Ở đây, tham số LỘC còn được gọi là giá trị trung bình và tham số tỷ lệ còn được gọi là độ lệch chuẩn.
- Cách tiếp cận
- Nhập mô -đun
- Tạo dữ liệu
- Tính toán trung bình và độ lệch
- Hiển thị cốt truyện
Dưới đây là việc thực hiện.
Python3
import
numpy as np
import
matplotlib.pyplot as plt
from
scipy.stats
import
sns.kdeplot[data = Cultivar_1['AGW']]
plt.xlim[[30,70]]
plt.xlabel["Grain weight [mg]", size=12]
plt.ylabel["Frequency", size=12]
plt.grid[True, alpha=0.3, linestyle="--"]
plt.show[]
1import
sns.kdeplot[data = Cultivar_1['AGW']]
plt.xlim[[30,70]]
plt.xlabel["Grain weight [mg]", size=12]
plt.ylabel["Frequency", size=12]
plt.grid[True, alpha=0.3, linestyle="--"]
plt.show[]
3sns.kdeplot[data = Cultivar_1['AGW']]
plt.xlim[[30,70]]
plt.xlabel["Grain weight [mg]", size=12]
plt.ylabel["Frequency", size=12]
plt.grid[True, alpha=0.3, linestyle="--"]
plt.show[]
4sns.kdeplot[data = Cultivar_1['AGW']]
plt.xlim[[30,70]]
plt.xlabel["Grain weight [mg]", size=12]
plt.ylabel["Frequency", size=12]
plt.grid[True, alpha=0.3, linestyle="--"]
plt.show[]
5 sns.kdeplot[data = Cultivar_1['AGW']]
plt.xlim[[30,70]]
plt.xlabel["Grain weight [mg]", size=12]
plt.ylabel["Frequency", size=12]
plt.grid[True, alpha=0.3, linestyle="--"]
plt.show[]
6sns.kdeplot[data = Cultivar_1['AGW']]
plt.xlim[[30,70]]
plt.xlabel["Grain weight [mg]", size=12]
plt.ylabel["Frequency", size=12]
plt.grid[True, alpha=0.3, linestyle="--"]
plt.show[]
7sns.kdeplot[data = Cultivar_1['AGW']]
plt.xlim[[30,70]]
plt.xlabel["Grain weight [mg]", size=12]
plt.ylabel["Frequency", size=12]
plt.grid[True, alpha=0.3, linestyle="--"]
plt.show[]
8sns.kdeplot[data = Cultivar_1['AGW']]
plt.xlim[[30,70]]
plt.xlabel["Grain weight [mg]", size=12]
plt.ylabel["Frequency", size=12]
plt.grid[True, alpha=0.3, linestyle="--"]
plt.show[]
9sns.kdeplot[data = Cultivar_1['AGW']]
plt.xlim[[30,70]]
plt.xlabel["Grain weight [mg]", size=12]
plt.ylabel["Frequency", size=12]
plt.grid[True, alpha=0.3, linestyle="--"]
plt.show[]
8sns.kdeplot[data = Cultivar_1['AGW']]
plt.xlim[[30,70]]
plt.xlabel["Grain weight [mg]", size=12]
plt.ylabel["Frequency", size=12]
plt.grid[True, alpha=0.3, linestyle="--"]
plt.show[]
9mean[data]2223
mean[data]4
sns.kdeplot[data = Cultivar_1['AGW']]
plt.xlim[[30,70]]
plt.xlabel["Grain weight [mg]", size=12]
plt.ylabel["Frequency", size=12]
plt.grid[True, alpha=0.3, linestyle="--"]
plt.show[]
5 mean[data]6
mean[data]7
sns.kdeplot[data = Cultivar_1['AGW']]
plt.xlim[[30,70]]
plt.xlabel["Grain weight [mg]", size=12]
plt.ylabel["Frequency", size=12]
plt.grid[True, alpha=0.3, linestyle="--"]
plt.show[]
5 mean[data]9
stdev[data]0
stdev[data]1
Output:
Đầu ra của mã trên