<jupyter_start><jupyter_text>Regression Analysis:  1. Form of predictive modelling technique which investigates the relationship between a dependent (target) and independent variable (predictor).2. Used for forecasting, time series modelling, finding the casual effect of road accidents by a driver3. Important tool for modelling and analyzing data. 4. Goal is to fit a curve/line to the data points in a manner that the differences between the distance of data points from the curve or line is minimized.5. Benefits:    a. Indicates the significant relationships between dep and indep var        b. Indicates the strength of impact of multiple indep var on dep var        c. Compares the effecs of variables measured on different scales  Linear Regression:  1. Establishes the relationship between dep and indep var using a best fit straight line - Regression Line2. Represented by an equation : Y = (m*X)+c+e -> Y = dep, X = indep, m = slope, c = intercept, e = error term  Import statements for python:<jupyter_code>import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline 
#Allows the plots to appear directly in this notebook<jupyter_output><empty_output><jupyter_text>Example: Advertising Data<jupyter_code>url = "http://faculty.marshall.usc.edu/gareth-james/ISL/Advertising.csv"
df = pd.read_csv(url,index_col = 0)
df.head()<jupyter_output><empty_output><jupyter_text>1. Features: TV, radio, Newspaper2. Response: Sales  Q1. Shape of DataFrame:<jupyter_code>df.shape<jupyter_output><empty_output><jupyter_text>Q2. Visualize the relationship between the features and the response using scatterplots:  Step 1<jupyter_code>fig,axis = plt.subplots(1,3,sharey = True) #Sharing the y axis for the 3 plots
print(fig)
print(axis)<jupyter_output>Figure(432x288)
[<matplotlib.axes._subplots.AxesSubplot object at 0x0000012F1F6D6BE0>
 <matplotlib.axes._subplots.AxesSubplot object at 0x0000012F1F979CC0>
 <matplotlib.axes._subplots.AxesSubplot object at 0x0000012F1F9AB128>]<jupyter_text>Step 2<jupyter_code>df.plot(kind = "scatter", x = "TV", y = "sales", ax = axis[0], figsize = (16,8))
df.plot(kind = "scatter", x = "radio", y = "sales", ax = axis[1])
df.plot(kind = "scatter", x = "newspaper", y = "sales", ax = axis[2])<jupyter_output><empty_output><jupyter_text>Step 3<jupyter_code>fig,axis = plt.subplots(1,3,sharey = True) #Sharing the y axis for the 3 plots
df.plot(kind = "scatter", x = "TV", y = "sales", ax = axis[0], figsize = (16,8))
df.plot(kind = "scatter", x = "radio", y = "sales", ax = axis[1])
df.plot(kind = "scatter", x = "newspaper", y = "sales", ax = axis[2])<jupyter_output><empty_output><jupyter_text>Simple Linear Regression:  1. Approach for predicting a quantitative response using a single feature2. Y = b0 + b1X -> Y = response, X = feature, b0 = intercept, b1 = coefficient of X    b0 and b1 are model coefficients  Estimating ( "Learning") Model Coefficients  Coefficients are estimated using the:Least Squared Criterion - mathematically speaking we find the line to minimize the Sum of Squared Residuals/Errors  Least Squared Method:<jupyter_code>from IPython.display import Image
Image(filename="C:/Users/MAHE/Desktop/Data Science/Images/img1.PNG",width=300,height=300)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10357583230579531, 'fraction_numerical': 0.02836004932182491, 'mean_word_length': 5.568825910931174, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 33, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '391479', 'license': 'MIT', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1048, 'n_words': 346, 'path': 'Data-Science-HYD-2k19/Topic-Wise/MACHINE LEARNING/.ipynb_checkpoints/2. Linear Regression-checkpoint.ipynb', 'repo_name': 'Sanjay9921/Python', 'size': '3244'}