Regression
Now we have split the datasets and transformed the data, we will show you how to use the scikit-learn library to build up ML models. We will start with regression and show you the following examples:
- Simple linear regression
- Multiple linear regression
- Polynomial/non-linear regression
Simple linear regression
First things first, we need to prepare the dataset:
import numpy as pd import pandas as pd import matplotlib.pyplot as plt dataset = pd.read_csv('Salary_Data.csv') X = dataset.iloc[:,:-1].values y = dataset.iloc[:, -1].values from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split(X, y , test_size = 0.2, random_state = 1)
Now we can start training our regression model. We need to import a class and feed our training data:
from sklearn.linear_model import LinearRegression regressor = LinearRegression() regressor.fit(X_train, y_train)
Next, we are going to predict the results...