-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: menambahkan statistika rumus statistika entropy adalah `H(X) = -∑p(x)log(p(x))` dengan fungsi yang bisa dilihat pada OpenSeries/statistika.py request documentation: @dherlyar Signed-off-by: slowy07 <[email protected]> * fix: memperbaiki dari codeowners Signed-off-by: slowy07 <[email protected]> * fix: menambahkan requirements.txt pada unitesting Signed-off-by: slowy07 <[email protected]> * fix: memperbaiki dari CODEOWNERS Signed-off-by: slowy07 <[email protected]> * feat: menambahkan fungsi standar deviasi fungsi untuk mengukur penyebaran data terhadap nilai rata-rata dengan rumus `σ = √∑(x - μ)^2 / n` Signed-off-by: slowy07 <[email protected]> * chore: merestruktur folder contoh Signed-off-by: slowy07 <[email protected]> --------- Signed-off-by: slowy07 <[email protected]>
- Loading branch information
Showing
31 changed files
with
253 additions
and
115 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import numpy as np | ||
from typing import Union | ||
from OpenSeries.util import error as pesan_error | ||
|
||
|
||
def entropy(label: list[int], base: int = None) -> Union[float, int, str]: | ||
""" | ||
fungsi menghitung entropy dari suatu fitur pada suatu dataset | ||
parameter: | ||
label (list (int)): label fitur yang akan di hitung entropynya | ||
""" | ||
if not isinstance(label, (list)): | ||
return pesan_error.error_tipe_data(["list"]) | ||
if not label: | ||
return pesan_error.error_format("label tidak boleh kosong") | ||
if not all(isinstance(cek_nilai, int) for cek_nilai in label): | ||
return pesan_error.error_tipe_data(["int"]) | ||
_, count = np.unique(label, return_counts=True) | ||
probabilitas = count / len(label) | ||
probabilitas[probabilitas == 0] = 1 | ||
|
||
log = np.log(probabilitas) if base is None else np.log(probabilitas) / np.log(base) | ||
return np.sum(abs(probabilitas * log)) | ||
|
||
|
||
def standar_deviasi(vektor: np.ndarray) -> Union[float, str]: | ||
""" | ||
fungsi untuk mengukur penyebaran data terhadap nilai rata-ratanya | ||
parameter: | ||
vektor (np.array) | ||
""" | ||
if not isinstance(vektor, np.ndarray): | ||
return pesan_error.error_tipe_data(["numpy array"]) | ||
if len(vektor) == 0: | ||
return pesan_error.error_format("vektor tidak boleh kosong") | ||
|
||
mean_value = np.mean(vektor) | ||
squared_diff = np.square(vektor - mean_value) | ||
variansi = np.mean(squared_diff) | ||
std_deviasi = np.sqrt(variansi) | ||
return std_deviasi |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import OpenSeries.fisika as fisika | ||
|
||
# fungsi menghitung energi kinetik | ||
massa_benda = 14 | ||
kecepatan_benda = 23.4 | ||
print( | ||
f"menghitung energi kinetik pada benda {massa_benda} kg dengan kecepatan {kecepatan_benda} m/s" | ||
) | ||
print( | ||
f"hasilnya adalah : {fisika.energi_kinetik(massa_benda, kecepatan_benda)} joule\n" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import OpenSeries.fisika as fisika | ||
|
||
# menghitung energi potensial | ||
massa_benda_potensial = 12 | ||
gravitasi_bumi = 9.78 | ||
ketinggian_benda = 400 | ||
print("menghitung energi potensial dari suatu benda") | ||
print(f"dengan massa benda adalah: {massa_benda_potensial}") | ||
print(f"gravitasi bumi {gravitasi_bumi}") | ||
print(f"dan ketinggian benda adalah {ketinggian_benda}") | ||
print( | ||
f"hasilnya adalah: {fisika.energi_potensial(massa_benda_potensial, gravitasi_bumi, ketinggian_benda)}\n" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import OpenSeries.fisika as fisika | ||
|
||
# fungsi menghitung glbb | ||
print("hitung glbb (gerak lurus beraturan)") | ||
result_glbb = fisika.gerak_lurus_beraturan(10, 2, 3) | ||
print(f"hasil dari glbb adalah: {result_glbb}\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import OpenSeries.fisika as fisika | ||
|
||
# menghitung hukum arus ohm | ||
kuat_arus = 30 | ||
hambatan = 3 | ||
print("menghitung hukum ohm") | ||
print(f"dengan kuat arus {kuat_arus}") | ||
print(f"hambatan {hambatan}") | ||
print(f"hasilnya adalah: {fisika.hukum_ohm(kuat_arus, hambatan)}\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import OpenSeries.fisika as fisika | ||
|
||
print("hitung kecepatan") | ||
result_kecepatan = fisika.kecepatan(4, 2.3) | ||
print(f"hasil dari kecepatan adalah: {result_kecepatan}\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import OpenSeries.fisika as fisika | ||
|
||
# menghitung masa jenis benda | ||
massa_benda = 14 | ||
volume_benda = 8 | ||
print( | ||
f"menghitung massa jenis benda dengan massa benda {massa_benda} gram, dan volume benda {volume_benda} cm3" | ||
) | ||
print(f"hasilnya adalah : {fisika.masa_jenis(massa_benda, volume_benda)}\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import OpenSeries.fisika as fisika | ||
|
||
print("hitung percepatan") | ||
result_percepatan = fisika.percepatan(4, 2.3) | ||
print(f"hasil dari percepatan adalah: {result_percepatan}\n") |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import OpenSeries.matematika as matematika | ||
|
||
nilai_suku = 5 | ||
suku_pertama = 3 | ||
selisih_suku = 2 | ||
print("menghitung jumlah deret aritmatika") | ||
print(f"dengan nilai suku: {nilai_suku}") | ||
print(f"suku pertama: {suku_pertama}") | ||
print(f"selisih suku: {selisih_suku}") | ||
print( | ||
f"hasilnya adalah: {matematika.hitung_jumlah_deret(nilai_suku, suku_pertama, selisih_suku)}\n" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import OpenSeries.matematika as matematika | ||
|
||
nilai1 = 24 | ||
nilai2 = 40 | ||
print( | ||
f"hitung nilai fpb (faktor persekutuan terbesar) dari nilai {nilai1} dan {nilai2}" | ||
) | ||
print(f"hasilnya adalah : {matematika.fpb(nilai1, nilai2)}\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import OpenSeries.matematika as matematika | ||
|
||
print("hitung jari jari lingkaran") | ||
hasil_jari_lingkaran = matematika.luas_lingkaran(4.5) | ||
print(f"hasil dari hitung jari jari lingkaran: {hasil_jari_lingkaran}\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import OpenSeries.matematika as matematika | ||
|
||
nilai_faktorial = 25 | ||
print(f"menghitung nilai faktorial dari angka {nilai_faktorial}") | ||
print(f"hasilnya adalah : {matematika.faktorial(nilai_faktorial)}\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import OpenSeries.matematika as matematika | ||
|
||
nilai_kombinasi = 15 | ||
print(f"menghitung nilai kombinasi dari {nilai_kombinasi}") | ||
print(f"hasilnya adalah : {matematika.kombinasi(nilai_kombinasi, 3)}\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import OpenSeries.util.constant as konstanta | ||
|
||
print("menampilkan nilai konstan") | ||
print(f"nilai dari pi adalah: {str(konstanta.pi)}\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import OpenSeries.matematika as matematika | ||
|
||
nilai_permutasi = 12 | ||
print(f"menghitung nilai permutasi dari {nilai_permutasi}") | ||
print(f"hasilnya adalah : {matematika.permutasi(nilai_permutasi, 2)}\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import OpenSeries.matematika as matematika | ||
|
||
nilai_rata = [2, 3, 5, 5, 6, 1, 2, 3] | ||
print(f"menghitung nilai rata-rata dari {nilai_rata}") | ||
print(f"hasilnya adalah: {matematika.rata_rata(nilai_rata)}\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import OpenSeries.matematika as matematika | ||
|
||
nilai_A = 5 | ||
nilai_S = 10 | ||
|
||
print("menghitung probabilitas suatu kejadian") | ||
print(f"dengan jumlah hasil yang menguntungkan :{nilai_A}") | ||
print(f"dan dengan ukuran ruang sampel {nilai_S}") | ||
print( | ||
f"probabilitas dari kejadiannya adalah: {matematika.peluang_kejadian(nilai_A, nilai_S)}\n" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import OpenSeries.matematika as matematika | ||
|
||
rentang_nilai = 300 | ||
print( | ||
f"rentang nilai {rentang_nilai} faktor prima adalah {matematika.faktor_prima(rentang_nilai)}\n" | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from OpenSeries import statistika as statistika | ||
|
||
# contoh dari entropy | ||
label = [1, 1, 2, 2, 3, 3] | ||
hasil_base_2 = statistika.entropy(label, base=2) | ||
print(hasil_base_2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import numpy as np | ||
from OpenSeries import statistika as statistika | ||
|
||
# contoh dari standar deviasi | ||
vektor = np.array([1, 2, 3, 4, 5]) | ||
hasil = statistika.standar_deviasi(vektor) | ||
print(hasil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
numpy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.