Created
April 11, 2020 20:20
-
-
Save rchardptrsn/dc3563124ee5ed85e672cd082ad85a09 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # Import packages | |
| import pandas as pd | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import seaborn as sns | |
| # Indedependent variable - number of chimpanzees in hunting party | |
| x = np.array([1,2,3,4,5,6,7,8]) | |
| # Dependent Variable - percent of successful hunts | |
| y = np.array([30,45,51,57,60,65,70,71]) | |
| df = pd.DataFrame({'Number of Chimpanzees':x,'Percent Successful Hunts':y}) | |
| # Initialize the figure | |
| plt.figure(figsize=(8,5)) | |
| plt.title('Number of Chimpanzees vs Hunt Success - Least Squares Line') | |
| # Scatterplot | |
| sns.scatterplot(x='Number of Chimpanzees',y='Percent Successful Hunts',data=df).get_figure().savefig('Chimpanzee Hunt Sucess with Least Squares Line.png') | |
| # Least Squares Line | |
| x = np.linspace(1,8,100) | |
| y = 5.4405*x+31.6429 | |
| plt.plot(x, y, '-g',label='y=5.4405x+31.6429') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment