Posts

Showing posts with the label python

How to perform two-sample one-tailed t-test in Python

Image
In python, we can use ttest_ind   to perform two-sample one-tailed test. Assuming that our hypothesis are: Ho(Null Hypothesis): P1 >= P2 Ha(Alternative Hypothesis): P1< P2 In this case, we know that we have 1st normal distribution with mean equal to 3 and variance equal to 2 with 400 data points. The 2nd normal distribution has the mean equal to 6 but the same sigma and size as 1st normal distribution.  How can we interpret the results? According the  Stat Trek , when the null hypothesis is: 6>=3, the t score should be equal to 21.2 with degree freedom equal to 798 and SE equal to 0.1414. Stat Trek Calculator gives use the p-value equal to 1. You might notice that no matter whether or not we write  ttest_ind(P1,P2)   or  ttest_ind(P2,P1)  , the t-statistics changes but the p-value does not change. Why? By default, Python Scipy library does not give an option for us to perform one-tailed two sample test. The p-value is compu...

Data tells you the secrets of extramarital affairs

Image
Recently I found this interesting dataset about extramarital affair of women in 1974. The dataset was built under a survey and now is available to download via Pandas package in Python. Some interesting facts are discovered after pure data visualization. If you are interested in interactive dashboard, please click here . 

What's the probability of forming a triangle by breaking a stick twice?

Questions: Supposed that you have 2 chances to break a stick with length of 1 into 3 pieces. What is the probability that the 3 pieces form a triangle? Code in Python: [in:] n=100 y>0 z>0 success = 0 fail = 0 n=1500 for i in range (0,1500):     x = rd.random()     y = rd.random()     if (y>0.5 and x<0.5 and y-x<0.5) or (x>0.5 and y<0.5 and x-y<0.5):         success = success+1              else :         fail = fail+1 probability = success/n print (probability)

Data Visualization with Seaborn in Python: FANG Stock Correlation Analysis

Image
FANG, known as Facebook, Amazon, Netflix, and Google in the stock market, are considered very good investment in 2015. Thanks to the Python package Pandas and Seaborn, I am able to gather the adjusted close price and the volume on each day of last year of FANG stocks. 1. Volume and Adjusted Closing Price pattern of FANG in 2015 Amazon and Google has 3 significant peak volume in 2015. It's so interesting to see that the pattern of adjusted closing price of Google and Amazon are almost the same in 2015. It seems the Wall Street investors became confident in both Google and Amazon at the same time. 

Automatically stream and download the Yahoo! Finance stock price using Python

Image
Attention: Yahoo! Finance deprecated the API in late 2017. Please refer to this article and learn how to use Google Finance as an alternative.  Thanks to the Pandas package in Python, now we can stream the stock price from Yahoo! automatically within 1 second. And of course, it's free!  I am going to show you the example of downloading stock price of US Oil, Facebook, Best Buy, and Expedia from Jan 1st, 2014 to Dec 1st, 2015 and saving the data into a CSV file on your local drive.  ======== Code Start ========   import pandas.io.data as pdweb import datetime #import the library you need from pandas stockprice = pdweb.get_data_yahoo([ 'USO',' FB','BBY','EXPE' ],start = datetime.datetime(2014,1,1), en d=datetime.datetime(2015,12,1) )['Adj Close'] #set the stocks you would like to download and the time frame stockprice.to_csv(' stockprice.csv ') #save it to your local drive. It's in the same folder where yo...

3 Books for Data Scientist Interviews

Image
Recently I made an infograph to show my classmates' current companies. I graduated with a M.S. in Business Analytics in 2014. A lot of my classmates pursued their careers in Data Science. 5 years ago, business analytics or data science were not considered as a major at college. It's a emerging subject that calls programming and statistics together to find the story of big data.  (To see the high resolution of the graph or know more about the story, please click here .)  1. Data Science Interview Exposed     Purchase at Amazon.com      Authors: Jane You, Iris Wang, Yanping Huang, Ian Gao, Feng Gao      Reasons:      1) The book includes a lot of sample question with a variety topics covered as well as ANSWERS, no matter case study of data modeling, coding with Python, probability of fair coins, machine learning, and etc.       2) The book compares similar roles of Data Engineer, BI E...

How to get approximate value of pi with Python

Goal: The goal of the project is to estimate pi value without using the function math.pi. Theory:  Assuming that you throw 18,000 balls into a square of 2 feet by 2 feet. The radius of the largest circle inside the square is equal to 1. Assuming that 18,000 balls has the same probability to fall into inside the circle or outside the circle within the square. At the end, we are going to calculate number of balls inside the circle divided by 18,000 to get the approximate value of pi.

Use Pascal Function to Get Approximate P-value of A/B Testing

Image
If you are looking for script that allows you to get approximate p-value for your A/B testing, this is the place for you. Or if you are looking for reference to calculate p-value and z-value due to the limited available maths methods in SQL, the python script can be translated in SQL user define function.