An warware: tazarar amincewar makirci matplotlib

Matplotlib babban ษ—akin karatu ne mai ฦ™irฦ™ira da ake amfani da shi a cikin yaren shirye-shiryen Python. Yana ba da API mai dacewa da abu don shigar da makirci cikin aikace-aikacen da ke amfani da kayan aikin GUI na gaba ษ—aya kamar Tkinter, wxPython, ko Qt. ฦŠaya daga cikin mahimman kayan aikin da Matplotlib ke bayarwa shine ikon ฦ™irฦ™irar makircin tazarar amincewa.

Tazarar amincewa, a matsayin kalmar ฦ™ididdiga, tana nufin matakin tabbaci a hanyar samfur. Matsayin amincewa yana gaya muku yadda tabbacin za ku iya zama, an bayyana shi azaman kashi. Misali, matakin amincewa da kashi 99% yana nuna cewa kowane ฦ™ididdigan yuwuwar ku yana iya zama daidai 99% na lokaci.

ฦ˜irฦ™irar Tazarar Tazarar Tattalin Arziฦ™i Ta Amfani da Matplotlib

ฦ˜irฦ™irar makircin tazarar amincewa a Matplotlib ya ฦ™unshi matakai da yawa. Bari mu shiga cikin bayanin madaidaicin lambar Python don cim ma waษ—annan matakan:

Da farko, dole ne mu shigo da dakunan karatu masu mahimmanci:

import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import sem, t
from scipy import mean

Yanzu, za mu iya ฦ™ididdige tazarar amincewa ta bin waษ—annan matakan.

1. ฦ˜ayyade saitin bayanan bazuwar wanda za mu lissafta tazarar amincewa.
2. ฦ˜ididdige kuskuren ma'ana da daidaitattun bayanai.
3. ฦ˜ayyade gefen kuskure don tazarar amincewa.
4. A ฦ™arshe, ฦ™ididdige kewayon tazarar amincewa.

Anan ga lambar Python daidai da waษ—annan matakan.

confidence = 0.95
data = np.random.rand(100)
n = len(data)
m = mean(data)
std_err = sem(data)
h = std_err * t.ppf((1 + confidence) / 2, n - 1)

start = m - h
end = m + h

Madaidaicin 'kwarin gwiwa' shine matakin amincewa da aka bayyana azaman kaso, kuma 'bayanai' ya ฦ™unshi bayanan bazuwar. Ana lissafta ma'ana da daidaitaccen kuskure ta hanyar 'ma'ana' da 'sem' aikin ษ—akin karatu na SciPy bi da bi. An ฦ™ayyade gefen kuskuren 'h' ta hanyar ninka daidaitaccen kuskure ta hanyar t-score, wanda muka samo daga t-rarraba ta amfani da aikin 'ppf'. A ฦ™arshe, muna ฦ™ididdige kewayon tazarar amincewa.

ฦ˜irฦ™irar Tazarar Amincewa a Matplotlib

A cikin wannan sashin ฦ™arshe na lambar, muna amfani da Matplotlib don ganin tazarar amincewa.

plt.figure(figsize=(9,6))
plt.bar(np.arange(len(data)), data)
plt.fill_between(np.arange(len(data)), start, end, color='b', alpha=0.1)
plt.title('Confidence Interval')
plt.show()

Yana amfani da makircin mashaya don nuna bayanan da hanyar 'fill_between' don wakiltar tazarar amincewa. Aikin 'siffa' yana fara sabon adadi kuma aikin 'nuna' yana gabatar da makircin.

ฦ˜irฦ™irar makircin tazarar amincewa a cikin Matplotlib hanya ce mai dacewa don nazarin bayanan ku na gani, musamman ma bayanan da suka ฦ™unshi ฦ™ididdigar ฦ™ididdiga. Wannan kayan aiki mai ฦ™arfi yana bayarwa hanya mai sauฦ™i da fahimta don gabatar da hadaddun bayanai a cikin wani nau'i wanda za'a iya fassara shi cikin sauฦ™i, yana mai da shi kayan aiki mai mahimmanci ga kowane manazarcin bayanan python ko masanin kimiyya. Ta hanyar fahimtar yadda ake sarrafa da amfani da wannan, za mu iya sa tsarin fassarar bayanai ya fi dacewa kuma daidai.

Shafi posts:

Leave a Comment