{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [ { "data": { "text/plain": "0.0" }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import scipy.stats as st\n", "\n", "# ortalamsı 0, std.spaması 10 olan bir rastegle değişken tanımlayalım\n", "n = st.norm(0, 10)\n", "\n", "n.mean()" ] }, { "cell_type": "code", "execution_count": 3, "outputs": [ { "data": { "text/plain": "10.0" }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "n.std()" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 4, "outputs": [ { "data": { "text/plain": "30000.0" }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "n.moment(4)" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 6, "outputs": [ { "data": { "text/plain": "0.03989422804014327" }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# rvs : random variates\n", "# pdf : probability density function\n", "# cdf : cumulative distribution func\n", "# sf : survival func (1 - cdf)\n", "# ppf : percent point func (inverse of sf)\n", "# isf : inverse survival func\n", "\n", "n.pdf(0)" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 7, "outputs": [ { "data": { "text/plain": "0.5" }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "n.cdf(0)" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 8, "outputs": [ { "data": { "text/plain": "array([14.47370202, -3.16015903, 10.71787186, 5.92254866, -0.93282238,\n -0.27714311, -8.24859593, -1.01334594, 3.70286296, 11.99284959])" }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Rastgele örneklem oluşturalım. Bu örneklemin ortalaması 0, std. sapması 10 olacaktır\n", "n.rvs(10)" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 17, "outputs": [ { "data": { "text/plain": "(0.0, 0.0, 100.0)" }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "n.mean(), n.median(), n.var()" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 32, "outputs": [ { "data": { "text/plain": "ShapiroResult(statistic=0.9902140498161316, pvalue=0.6819034218788147)" }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Shapiro-Wilks testi, verilerin normal bir dağılımdan alındığına dair yokluk hipotezini test eder\n", "\n", "st.shapiro(n.rvs(100))" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 2, "outputs": [], "source": [ "from sympy import stats, sqrt,exp, pi\n", "\n", "X = stats.Normal('x', 0, 10)" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 3, "outputs": [ { "data": { "text/plain": "sqrt(2)*exp(-x**2/200)/(20*sqrt(pi))", "text/latex": "$\\displaystyle \\frac{\\sqrt{2} e^{- \\frac{x^{2}}{200}}}{20 \\sqrt{\\pi}}$" }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# X rastgele değişkeninin olasılık yoğunluk fonksiyonu\n", "from sympy.abc import x\n", "stats.density(X)(x)" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 4, "outputs": [ { "data": { "text/plain": "1/2", "text/latex": "$\\displaystyle \\frac{1}{2}$" }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Toplam dağılım fonksiyonun bir noktadaki değeri\n", "stats.cdf(X)(0)" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 5, "outputs": [ { "data": { "text/plain": "1/2", "text/latex": "$\\displaystyle \\frac{1}{2}$" }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Standart olasılık sorularını cevaplamak için sezgisel yol kullanımı\n", "stats.P(X>0)" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": null, "outputs": [], "source": [ "# Standart olasılık sorularını cevaplamak için sezgisel yol kullanımı\n", "stats.P(X>0)" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": null, "outputs": [], "source": [ "# Beklenen değerler\n", "stats.E(abs(X) ** (1 / 2)).evalf()" ], "metadata": { "collapsed": false } }, { "cell_type": "markdown", "source": [ "Diğer python istatistik modülleri\n", "* Seaborn: Keşifçi veri analizi (EDA Explatory Data Analysis) için kullanılır\n", "* Statsmodel: Çok çeşitli istiksel modeller için tanımlayıcı istatistikler, tahminler ve çıkarımlar ile SciPy'ı tamamlamak üzere tasarlanmıştır. Statsmodel ayrıca ekonometrik veri ve problemlere vurgu yaparak zaman serisi analizi için yöntemler ve genelleştirilmiş doğrusal modeller de içerir." ], "metadata": { "collapsed": false } } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 0 }