Hello Everyone! My name is Andrew Fung, in this video, I will be showing you how to create a Wine Quality Prediction Project as a part of the Machine Learning series. I will be walking you through different processes and steps to take to slowly train and enhance the performance of your models, such as data preprocessing, features selection, feature correlation , classification and hyper parameters tuning. Hope you enjoy this tutorial ;)
#python #linearregression #machinelearning #traintestsplit
Installation and Setup!
Installing Jupyter Notebook: https://jupyter.readthedocs.io/en/lat...
Sklearn linear regression doc: https://scikit-learn.org/stable/modul...
Check out my Github!
https://github.com/Andrew-FungKinHo
Timestamps
0:00 | Introduction
0:32 | Train Test Data Split
3:55 | Linear Regression Plot
14:31 | Out tro
Full code:
———————————————————————————————
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import r2_score
import matplotlib.pyplot as plt
use the train test split submodule in scikit-learn to split the data in train.csv, with 80% for training and 20% for validation.
X_train, X_valid, y_train, y_valid = train_test_split(df_train.iloc[:,:10],
df_train.iloc[:,10:],
train_size=0.8,
random_state=69)
For each specified x attribute, create a linear regression model against DENSITY and compute the r2 scores
columns_concerned = ['fixed acidity', 'residual sugar', 'chlorides', 'free sulfur dioxide', 'total sulfur dioxide', 'alcohol']
y_density = df_train.loc[:,df_train.columns == 'density']
for i in range(len(columns_concerned)):
x_lin = df_train.loc[:,df_train.columns== columns_concerned[I]]
X_train, X_valid, y_train, y_valid = train_test_split(x_lin,
y_density,
test_size= 0.2,
random_state=69)
create a linear Regression model
model_1 = LinearRegression()
model_1.fit(X_train,y_train)
y_predict = model_1.predict(X_valid)
r2 = r2_score(y_valid,y_predict)
print(f'{columns_concerned[i]} : {r2}')
Plot the linear regression graphs
plt.figure(figsize=(12,10))
plt.subplot(3,2,i+1)
plt.title(f'Desnsity vs {columns_concerned[i]} \n (R^2 = {r2})')
plt.scatter(X_valid,y_valid,color='black')
plt.plot(X_valid,y_predict,color='red',linewidth=3)
plt.tight_layout()
plt.show()
———————————————————————————————
Feel free to drop a like and comment if you enjoy and video and let me know if you want me to do other types of programming videos ;) !!!