<jupyter_start><jupyter_text>Linear regression attempts to model the relationship between two variables by fitting a linear equation to observed data. One variable is considered to be an explanatory variable, and the other is considered to be a dependent variable.<jupyter_code>import numpy as np
import pandas as pd

# to visualization purposes
import matplotlib.pyplot as plt

# to build linear model
from sklearn.linear_model import LinearRegression
# load dataset
data = pd.read_csv('Book.csv')
data
# view data points
plt.scatter(data.videos, data.views, color='red')
plt.xlabel('Number of Videos')
plt.ylabel('Total Views')
# see single columns from dataset as a pandas series
data.videos
# or we can use "data['videos']"
data['views']
# divide dataset into x and y
x = np.array(data.videos.values)
y = np.array(data.views.values)
# build and train ML model
model = LinearRegression()
model.fit(x.reshape((-1,1)), y)
#Note: In here, we don't use training and testing set. 
# assign a value to predict from our model
new_x = np.array([45]).reshape((-1,1))
new_x
# predict from model
pred = model.predict(new_x)
pred
# visualize our linear model
plt.scatter(data.videos, data.views, color='red')
m, c = np.polyfit(x, y, 1)
plt.plot(x, m*x+c)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10588235294117647, 'fraction_numerical': 0.005490196078431373, 'mean_word_length': 5.285714285714286, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '253470', 'license': 'MIT', 'n_tokens_mistral': 427, 'n_tokens_neox': 402, 'n_words': 151, 'path': 'ML2/linear_regression/LR.ipynb', 'repo_name': 'CySecWee/ML', 'size': '1275'}