<jupyter_start><jupyter_text>Linear regressionIn this activity, we will use a regression plot to visualize the linear relationships.<jupyter_code>%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
mydata = pd.read_csv("anage_data.csv")
mydata.head()<jupyter_output><empty_output><jupyter_text>The given dataset is not complete. Filter the data so you end up with samples containing a body mass and a maximum longevity. Only consider samples for the class Mammalia and a body mass below 200,000.<jupyter_code>longevity = 'Maximum longevity (yrs)'
mass = 'Body mass (g)'
data = mydata[mydata['Class'] == 'Mammalia']
data = data[np.isfinite(data[longevity]) & np.isfinite(data[mass]) & (data[mass] < 200000)]<jupyter_output><empty_output><jupyter_text>Create a regression plot to visualize the linear relationship of the variables.<jupyter_code># Create figure
sns.set()
plt.figure(figsize=(10, 6), dpi=300)
# Create scatter plot
sns.regplot(mass, longevity, data=data)
# Show plot
plt.show()<jupyter_output>C:\Users\bhaveshb\AppData\Local\Continuum\anaconda3\lib\site-packages\scipy\stats\stats.py:1713: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval
{'fraction_non_alphanumeric': 0.10505319148936171, 'fraction_numerical': 0.015292553191489361, 'mean_word_length': 6.377450980392157, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '404956', 'license': 'MIT', 'n_tokens_mistral': 513, 'n_tokens_neox': 472, 'n_words': 154, 'path': 'Lesson04/Activity25/activity25_solution.ipynb', 'repo_name': 'webobite/Data-Visualization-with-Python', 'size': '1504'}