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.