Presentasi sedang didownload. Silahkan tunggu

Presentasi sedang didownload. Silahkan tunggu

Data Statistika diPYTHON

Presentasi serupa


Presentasi berjudul: "Data Statistika diPYTHON"— Transcript presentasi:

1 Data Statistika diPYTHON
Ridho Rahman Hariadi, S.Kom, M.Sc

2 Numpy NumPy (pronounced /ˈnʌmpaɪ/ (NUM-py) or sometimes /ˈnʌmpi/ (NUM-pee)) is a library for the Python programming language, adding support for large, multi- dimensional arrays and matrices, along with a large collection of high- level mathematical functions to operate on these arrays. Numpy memiliki kegunaan untuk operasi vektor dan matriks. Fiturnya hampir sama dengan MATLAB dalam mengelola array dan array multidimensi. Numpy merupakan salah satu library yang digunakan oleh library lain seperti SciPy untuk keperluan analisis data.

3 Contoh Numpy >>> x = np.array([[1, 2, 3], [4, 5, 6]], np.int32) >>> type(x) <type 'numpy.ndarray'> >>> x.shape (2, 3) >>> x.dtype dtype('int32')

4 Pandas Pandas is a software library written for the Python programming language for data manipulation and analysis. In particular, it offers data structures and operations for manipulating numerical tables and time series. Dengan menggunakan sistem dataframe, kamu dapat memuat sebuah file ke dalam tabel virtual ala spreadsheet dengan menggunakan Pandas. Dengan menggunakan Pandas, kamu dapat mengolah suatu data dan mengolahnya seperti join, distinct, group by, agregasi, dan teknik seperti pada SQL. Hanya saja dilakukan pada tabel yang dimuat dari file ke RAM. Pandas juga dapat membaca file dari berbagai format seperti .txt, .csv, .tsv, dan lainnya. Anggap saja Pandas adalah spreadsheet namun tidak memiliki GUI dan punya fitur seperti SQL.

5 Contoh Pandas >>> import pandas as pd
>>> pd.set_option('display.mpl_style', 'default') # Make the graphs a bit prettier >>> figsize(15, 5) >>> broken_df = pd.read_csv('../data/bikes.csv') # Look at the first 3 rows >>> broken_df[:3]

6 Scipy SciPy (pronounced /ˈsaɪpaɪ'/ "Sigh Pie") is a free and open-source Python library used for scientific computing and technical computing. SciPy contains modules for optimization, linear algebra, integration, interpolation, special functions, FFT, signal and image processing, ODE solvers and other tasks common in science and engineering. SciPy builds on the NumPy array object and is part of the NumPy stack which includes tools like Matplotlib, pandas and SymPy, and an expanding set of scientific computing libraries. This NumPy stack has similar users to other applications such as MATLAB, GNU Octave, and Scilab. The NumPy stack is also sometimes referred to as the SciPy stack.

7 Scipy Kegunaanya adalah untuk menangani operasi aljabar dan matriks serta operasi matematika lainya. Disini kamu dapat menangani sejumlah operasi matematika yang lebih kompleks daripada menggunakan library math bawaan Python. Ada juga beberapa fungsi statistika dasar yang dimiliki oleh Scipy.

8 Contoh Scipy >>> import numpy as np
>>> from scipy import linalg >>> A = np.array([[1,2],[3,4]]) >>> A array([[1, 2], [3, 4]]) >>> linalg.inv(A) array([[-2. , 1. ], [ 1.5, -0.5]])

9 Contoh Scipy >>> b = np.array([[5,6]]) #2D array
>>> b.T array([[5], [6]])

10 Contoh Scipy >>> A*b #not matrix multiplication!
array([[ 5, 12], [15, 24]]) >>> A.dot(b.T) #matrix multiplication array([[17], [39]])

11 Contoh Scipy >>> b = np.array([5,6]) #1D array >>> b
>>> b.T #not matrix transpose! >>> A.dot(b) #does not matter for multiplication array([17, 39])

12 Latihan Numpy >>> import numpy as np
L = np.random.random(100) (L) L = np.random.random(100) Latihan Numpy >>> import numpy as np >>> L = np.random.random(100) >>> sum(L) >>> np.sum(L)

13 Latihan Numpy >>> import numpy as np
L = np.random.random(100) (L) L = np.random.random(100) Latihan Numpy >>> import numpy as np >>> big_array = np.random.rand( ) >>> sum(big_array) >>> np.sum(big_array)

14 Latihan Pandas >>> import pandas as pd
>>> data = pd.read_csv(' nsumption_by_country.csv') >>> data >>> df = data[0:10] >>> df

15 Latihan Scipy(1) >>> import numpy as np
>>> from scipy import linalg >>> A = np.array([[1,2],[3,4]]) >>> A array([[1, 2], [3, 4]]) >>> linalg.inv(A) array([[-2. , 1. ], [ 1.5, -0.5]])

16 Latihan Scipy(2) >>> b = np.array([[5,6]]) #2D array
>>> b.T array([[5], [6]])

17 Latihan Scipy(3) >>> A*b #not matrix multiplication!
array([[ 5, 12], [15, 24]]) >>> A.dot(b.T) #matrix multiplication array([[17], [39]])

18 Latihan Scipy(4) >>> b = np.array([5,6]) #1D array
>>> b.T #not matrix transpose because of 1D array! >>> A.dot(b) #does not matter for multiplication array([17, 39])

19 Latihan(1) import pandas as pd import numpy as np import scipy
data = pd.read_csv(' nsumption_by_country.csv') df = data[0:10]

20 Latihan(2) mean = np.mean(data['alcohol'])
st_dev = np.std(data['alcohol']) print("The mean is",mean) print("The standard deviation is",st_dev)

21 Latihan(3) median = np.median(data['alcohol'])
maximum = np.max(data['alcohol']) minimum = np.min(data['alcohol']) print("The median is",median) print("The maximum is",maximum) print("The minimum is",minimum)

22 Tugas di Kelas Cari file CSV apapun yang dapat digunakan sebagai file input Gunakan pandas untuk meload file tersebut Hitung mean, median, max, min, dan standar deviasi dari data tersebut Ambil 10 data teratas dari CSV tersebut (ignore sisanya) Hitung mean, median, max, min, dan standar deviasi dari 10 data tersebut

23 Tugas di Kelas Buat matrix A yang berisi sebuah matrix 2x2
Buat matrix B yang merupakan transpose dari matrix A Buat matrix C yang merupakan inverse dari matrix A Lakukan matrix multiplication antara matrix A dan B


Download ppt "Data Statistika diPYTHON"

Presentasi serupa


Iklan oleh Google