<jupyter_start><jupyter_text>![data%20max%20logo.png](attachment:data%20max%20logo.png)  Linear Regression with Python<jupyter_code>!pip3 install pandas
!pip3 install numpy
!pip3 install seaborn
!pip3 install matplotlib
!pip3 install scikit-learn
import pandas as pd 
import numpy as np
import seaborn as sns 
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
import numpy as np

X = 2 * np.random.rand(100, 1)
y = 4 + 3 * X + np.random.randn(100, 1)
plt.plot(X, y, "b.")
plt.xlabel("$x_1$", fontsize=18)
plt.ylabel("$y$", rotation=0, fontsize=18)
plt.axis([0, 2, 0, 15])
plt.show()
lin_reg = LinearRegression()
lin_reg.fit(X, y)
lin_reg.intercept_, lin_reg.coef_
wine_data = pd.read_csv('../data/winequality-red.csv')
wine_data.head(100)
wine_data.describe()
correlation = wine_data.corr()
fig = plt.subplots(figsize=(10,10))
sns.heatmap(correlation,vmax=1,square=True,annot=True,cmap='Blues')
X = wine_data.drop('quality', axis=1)
y = wine_data['quality']
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=101, train_size=0.8)
regressor = LinearRegression()
regressor.fit(X_train,y_train)
from sklearn.metrics import mean_absolute_error, mean_squared_error
y_pred = regressor.predict(X_test)
mse = mean_squared_error(y_test, y_pred)
rmse = np.sqrt(mse)
print(mse)
print(rmse)
mae = mean_absolute_error(y_test, y_pred)
print(mae)
y_pred_round = np.round(y_pred, 1)
mse = mean_squared_error(y_pred_round, y_test)
mse
np.sqrt(mse)
import pickle
with open ('../docker/model.pkl', 'wb') as file:
    pickle.dump(regressor, file)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13485851896447923, 'fraction_numerical': 0.030102347983142687, 'mean_word_length': 6.914285714285715, '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': '494663', 'license': 'Apache-2.0', 'n_tokens_mistral': 718, 'n_tokens_neox': 655, 'n_words': 137, 'path': 'Presentations/.ipynb_checkpoints/Linear Regression - Wine Quality-checkpoint.ipynb', 'repo_name': 'data-max-hq/workshop-epoka', 'size': '1661'}