<jupyter_start><jupyter_text>Simple Linear Regression<jupyter_code># Simple Linear Regression

# Import Libraries

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# Import  Dataset

dataset = pd.read_csv('../../data/datasets/Part 2 - Regression/Section 4 - Simple Linear Regression/Salary_Data.csv')
# Matrix
X = dataset.iloc[:, :-1].values
# Vector
y = dataset.iloc[:, 1].values


# Divide the data set into training set and test set

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 1/3, random_state = 0)


# Variable scaling
"""
from sklearn.preprocessing import StandardScaler
sc_X = StandardScaler()
X_train = sc_X.fit_transform(X_train)
X_test = sc_X.transform(X_test)
"""
# Create Simple Linear Regression model with training set

from sklearn.linear_model import LinearRegression
regression = LinearRegression()
regression.fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>Predict the test set<jupyter_code>y_pred = regression.predict(X_test)
print(y_pred)<jupyter_output>[ 40835.10590871 123079.39940819  65134.55626083  63265.36777221
 115602.64545369 108125.8914992  116537.23969801  64199.96201652
  76349.68719258 100649.1375447 ]<jupyter_text>View training results<jupyter_code># Train
plt.scatter(X_train, y_train, color = "red")
plt.plot(X_train, regression.predict(X_train), color = "blue")
plt.title("Sueldo vs Años de Experiencia (Conjunto de Entrenamiento)")
plt.xlabel("Años de Experiencia")
plt.ylabel("Sueldo (en $)")
plt.show()
# Test
plt.scatter(X_test, y_test, color = "red")
plt.plot(X_train, regression.predict(X_train), color = "blue")
plt.title("Sueldo vs Años de Experiencia (Conjunto de Testing)")
plt.xlabel("Años de Experiencia")
plt.ylabel("Sueldo (en $)")
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1143011917659805, 'fraction_numerical': 0.07583965330444203, 'mean_word_length': 6.300395256916996, 'pattern_counts': {'":': 0, '<': 12, '<?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': '64979', 'license': 'MIT', 'n_tokens_mistral': 788, 'n_tokens_neox': 666, 'n_words': 154, 'path': 'notebooks/Module2-Regression/Simple-Linear-Regression.ipynb', 'repo_name': 'jesussantana/Machine-Learning-from-A-to-Z', 'size': '1846'}