<jupyter_start><jupyter_text>1. Scikit-learn   1. One of the most popular open source ML libraries for Python2. Provides algos for ML including classification, regression, dimensionally reduction and clustering.3. Provides modules for extracting features, processing data and evaluating models.<jupyter_code>import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline 
#Allows the plots to appear directly in this notebook

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>Step1<jupyter_code>#Create x and y

feature_cols = ["TV"] 
x = df[feature_cols] #DataFrame
y = df.sales         #Series<jupyter_output><empty_output><jupyter_text>Step2<jupyter_code>from sklearn.linear_model import LinearRegression<jupyter_output><empty_output><jupyter_text>Step3<jupyter_code>lm = LinearRegression()
lm.fit(x,y)<jupyter_output><empty_output><jupyter_text>Step4<jupyter_code>m = lm.coef_
c = lm.intercept_
print("Slope is: ",m)
print("Intercept is: ",c)<jupyter_output>Slope is:  [0.04753664]
Intercept is:  7.032593549127693<jupyter_text>Q1. Predict the sales in the market if the amount spent for TV advertising was $50000    1. Using y = b0+b1X<jupyter_code>x = 50 
y_predict = c+(m*x)
print("Predicted sales is: ",y_predict)<jupyter_output>Predicted sales is:  [9.40942557]<jupyter_text>Thus we would predict the sales of 9409 widgets in that market  2. Using sklearn<jupyter_code>lm.predict([[50]])<jupyter_output><empty_output><jupyter_text>2. Plotting the Least Squares Line  1. Make the predictions for the smallest and largest observed values of x2. Use the predicted values to plot the least squared line<jupyter_code>tv_min = df.TV.min()
tv_max = df.TV.max()

df2 = pd.DataFrame({"TV":[tv_min,tv_max]})
df2
y_predict = lm.predict(df2)
y_predict
#Plot the data

df.plot(kind = "scatter", x = "TV", y = "sales")

plt.plot(df2, y_predict, c = "red", linewidth = 2)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1111111111111111, 'fraction_numerical': 0.03422619047619048, 'mean_word_length': 6.361313868613139, 'pattern_counts': {'":': 1, '<': 31, '<?xml version=': 0, '>': 31, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '89616', 'license': 'MIT', 'n_tokens_mistral': 791, 'n_tokens_neox': 740, 'n_words': 184, 'path': 'Data-Science-HYD-2k19/Topic-Wise/MACHINE LEARNING/2. Linear Regression/2b. Least Squares Method.ipynb', 'repo_name': 'Sanjay9921/Python', 'size': '2016'}