Skip to content

Instantly share code, notes, and snippets.

@Razor-Sec
Last active October 7, 2021 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Razor-Sec/fafffad16551ee6a14ebe3d34d475bd3 to your computer and use it in GitHub Desktop.
Save Razor-Sec/fafffad16551ee6a14ebe3d34d475bd3 to your computer and use it in GitHub Desktop.
# solving statistika karna mager ngitung :D
# done dong wkwkwk
import math
import statistics
from collections import Counter
import numpy as np
from scipy.stats import kurtosis, skew
places = []
count = 0
gede = float('-inf')
kecil = float('inf')
jangkauan = 0
def logcallculator(jumlah):
realnumberbanyakkelas = math.log10(jumlah) * 3.3 + 1
return realnumberbanyakkelas
def inti():
with open('file.txt', 'r') as filehandle:
global places,count,gede,kecil,banyakkelas
filecontents = filehandle.readlines()
for lines in filecontents:
places.append(float(lines))
count += 1
number = float(lines)
if gede < number:
gede = number
if kecil > number:
kecil = number
print("Nilai : \n",places)
print("Nilai terbesar\t: ",gede)
print("Nilai terkecil\t: ",kecil)
print("banyak variable\t: ",count)
def panjangkelas():
global realnumberbanyakkelas,jangkauan
jangkauan = float(gede) - float(kecil)
jangkauan = jangkauan / realnumberbanyakkelas
jangkauan = round(jangkauan)
def table(kecil,jangkauan,banyakkelas,freqtot):
b1 = kecil
b2 = 0
interval = jangkauan
frekuensi = 0
count = 0
places2 = []
line = 0
totalfrekuensi = 0
print("-"*41)
print("|\tNilai\t\t|\tFreq\t|")
temp = b1
for i in range(banyakkelas):
print("-"*41)
b2 = temp+interval - 1
while(line <= freqtot -1):
if places[line] >= temp and places[line] <= b2 :
places2.append(places[line])
count +=1
line +=1
if count == 0:
places2 = ["Kosong"]
print("|\t",temp,"-",b2,"\t|\t",count,"\t|"," nilai :",places2)
totalfrekuensi += count
temp = b2 + 1
count = 0
line = 0
places2 = []
print("-"*41)
print("Total jumlah : ",totalfrekuensi)
def average(places):
count = 0
text = ""
for i in range(len(places)):
count += places[i]
text += str(places[i]) + " + "
print("[+] Average: \n")
print(text, " = " ,count , " / " , len(places) , " = ", count / len(places) , " \n--> " , round(count / len(places)))
return count / len(places)
def median(places):
places = sorted(places)
print("\n[+] Median: \n")
median = len(places)
print("Sorted : \n",places,"\n")
if(median %2 == 0):
median_rate = median // 2
median = (places[median_rate - 1] + places[median_rate]) / 2
print(places[median_rate-1] , " + " , places[median_rate] , "/ 2 = ", median )
else:
print("-->",places[median // 2])
def mode(places):
mode = Counter(iter(places)).most_common(1)
print("\n[+] Mode \n-->" , mode[0][0], "Sebanyak : ",mode[0][1], " kali")
def variance(places, xbar=None):
print("\n[+] Variance \n")
variance = statistics.variance(places)
print("Caranya panjang sumpah gw mager mending langsung pake module aja biar langsung bener")
print("-->",variance)
def standard_deviation(places):
standard_deviation = statistics.pstdev(places)
print("\n[+] Standard Deviation\n","--> ",standard_deviation)
return standard_deviation
def minimum(places):
print("\n[+] Minimum\n","--> ",min(places))
return min(places)
def maximum(places):
print("\n[+] Maximum\n","--> ",max(places))
return max(places)
def rangee(places):
print("\n[+] Range\n","--> ", max(places) - min(places))
def quartil(places):
quartil = sorted(places)
print("\n[+] Lower Quartil\n","--> ",np.quantile(quartil, .25, interpolation='midpoint'))
print("\n[+] High Quartil\n","--> ",np.quantile(quartil, .75, interpolation='midpoint'))
print("\n[+] InterQuartil\n","--> ",np.quantile(quartil, .75, interpolation='midpoint') - np.quantile(quartil, .25, interpolation='midpoint'))
def scipyy(places):
print("\n[+] Skewness\n","--> ",skew(places))
print("\n[+] Kurtosis\n","--> ",kurtosis(places))
def CoefficientVariation(places):
standard_deviation = statistics.pstdev(places)
mean = statistics.mean(places)
print("\n[+] Coefficient Variation\n","Standard Deviation = ",standard_deviation,"\n Average = ",mean,"\n--> ",standard_deviation , " / ",mean," = ",standard_deviation / mean)
inti()
realnumberbanyakkelas = logcallculator(count)
banyakkelas = round(realnumberbanyakkelas)
panjangkelas()
print("Banyak Baris \t: ",banyakkelas)
print("Panjang Baris\t: ",jangkauan)
table(kecil, jangkauan, banyakkelas,count)
average(places)
median(places)
mode(places)
variance(places)
standard_deviation(places)
minimum(places)
maximum(places)
rangee(places)
quartil(places)
scipyy(places)
CoefficientVariation(places)
35
46
27
45
78
73
43
37
42
24
87
39
23
43
65
54
34
63
86
21
54
74
84
43
65
53
48
65
77
46
75
24
23
27
76
28
34
93
43
54
54
23
34
75
65
54
35
45
76
65
52
81
88
76
64
89
└─$ python3 app.py
Nilai :
[35.0, 46.0, 27.0, 45.0, 78.0, 73.0, 43.0, 37.0, 42.0, 24.0, 87.0, 39.0, 23.0, 43.0, 65.0, 54.0, 34.0, 63.0, 86.0, 21.0, 54.0, 74.0, 84.0, 43.0, 65.0, 53.0, 48.0, 65.0, 77.0, 46.0, 75.0, 24.0, 23.0, 27.0, 76.0, 28.0, 34.0, 93.0, 43.0, 54.0, 54.0, 23.0, 34.0, 75.0, 65.0, 54.0, 35.0, 45.0, 76.0, 65.0, 52.0, 81.0, 88.0, 76.0, 64.0, 89.0]
Nilai terbesar : 93.0
Nilai terkecil : 21.0
banyak variable : 56
Banyak Baris : 7
Panjang Baris : 11
-----------------------------------------
| Nilai | Freq |
-----------------------------------------
| 21.0 - 31.0 | 9 | nilai : [27.0, 24.0, 23.0, 21.0, 24.0, 23.0, 27.0, 28.0, 23.0]
-----------------------------------------
| 32.0 - 42.0 | 8 | nilai : [35.0, 37.0, 42.0, 39.0, 34.0, 34.0, 34.0, 35.0]
-----------------------------------------
| 43.0 - 53.0 | 11 | nilai : [46.0, 45.0, 43.0, 43.0, 43.0, 53.0, 48.0, 46.0, 43.0, 45.0, 52.0]
-----------------------------------------
| 54.0 - 64.0 | 7 | nilai : [54.0, 63.0, 54.0, 54.0, 54.0, 54.0, 64.0]
-----------------------------------------
| 65.0 - 75.0 | 9 | nilai : [73.0, 65.0, 74.0, 65.0, 65.0, 75.0, 75.0, 65.0, 65.0]
-----------------------------------------
| 76.0 - 86.0 | 8 | nilai : [78.0, 86.0, 84.0, 77.0, 76.0, 76.0, 81.0, 76.0]
-----------------------------------------
| 87.0 - 97.0 | 4 | nilai : [87.0, 93.0, 88.0, 89.0]
-----------------------------------------
Total jumlah : 56
[+] Average:
35.0 + 46.0 + 27.0 + 45.0 + 78.0 + 73.0 + 43.0 + 37.0 + 42.0 + 24.0 + 87.0 + 39.0 + 23.0 + 43.0 + 65.0 + 54.0 + 34.0 + 63.0 + 86.0 + 21.0 + 54.0 + 74.0 + 84.0 + 43.0 + 65.0 + 53.0 + 48.0 + 65.0 + 77.0 + 46.0 + 75.0 + 24.0 + 23.0 + 27.0 + 76.0 + 28.0 + 34.0 + 93.0 + 43.0 + 54.0 + 54.0 + 23.0 + 34.0 + 75.0 + 65.0 + 54.0 + 35.0 + 45.0 + 76.0 + 65.0 + 52.0 + 81.0 + 88.0 + 76.0 + 64.0 + 89.0 + = 3027.0 / 56 = 54.05357142857143
--> 54
[+] Median:
Sorted :
[21.0, 23.0, 23.0, 23.0, 24.0, 24.0, 27.0, 27.0, 28.0, 34.0, 34.0, 34.0, 35.0, 35.0, 37.0, 39.0, 42.0, 43.0, 43.0, 43.0, 43.0, 45.0, 45.0, 46.0, 46.0, 48.0, 52.0, 53.0, 54.0, 54.0, 54.0, 54.0, 54.0, 63.0, 64.0, 65.0, 65.0, 65.0, 65.0, 65.0, 73.0, 74.0, 75.0, 75.0, 76.0, 76.0, 76.0, 77.0, 78.0, 81.0, 84.0, 86.0, 87.0, 88.0, 89.0, 93.0]
53.0 + 54.0 / 2 = 53.5
[+] Mode
--> 65.0 Sebanyak : 5 kali
[+] Variance
Caranya panjang sumpah gw mager mending langsung pake module aja biar langsung bener
--> 435.1061688311688
[+] Standard Deviation
--> 20.672116868292093
[+] Minimum
--> 21.0
[+] Maximum
--> 93.0
[+] Range
--> 72.0
[+] Lower Quartil
--> 36.0
[+] High Quartil
--> 74.5
[+] InterQuartil
--> 38.5
[+] Skewness
--> 0.12274677144181328
[+] Kurtosis
--> -1.1548553618848114
[+] Coefficient Variation
Standard Deviation = 20.672116868292093
Average = 54.05357142857143
--> 20.672116868292093 / 54.05357142857143 = 0.38243757668462414
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment