Machine Learning Algorithm- Linear Regression| Simple

There are two parts of machine learning-

  1. Supervised Learning: The output will consider from the given input. The Supervised learning process start from-

Trained the data on the basis of past output -> Classify the trained data –> Apply Algorithm -> Predicted the data using an algorithm

Some important process happens in Supervised Learning- Input & Output available.

2. Unsupervised Learning: Unsupervised learning does not use any data for taking training.

  • It includes only inputs
  • Classify the data inputs
  • Behalf of input collection, Clustering the data

Example of Unsupervised Learning : K-Means Algorithm

Machine Learning used some algorithm for prediction

  • Linear Regression
  • Logistic Regression
  • Decision Tree
  • SVM
  • Naive Bayes
  • KNN
  • K-Means
  • Random Forest

Linear Regression :

Code :

#For Mathematical calculation
import numpy as np

#For handling datasets
import pandas as pd

#For plotting graphs
from matplotlib import pyplot as plt

#import the sklearn library for linear regression
from sklearn.linear_model import LinearRegression

#import the csv file from dataset, which is located in Drive C path has been given 

#prints the top 5 rows

#prepare the traning set
x_train=df['Father'].values[:,np.newaxis]  #newaxis sperate values
#x_train=[[65.0],[63.3],[ 65.0],[ 65.8],[ 61.1]]
#y_train=[[59.8],[63.2],[ 63.3],[ 62.8],[ 64.3]]

lm=LinearRegression()     #lm is object of linearRegression

#Train the Model,y_train)  # Fit() is fubction (independent varable x,y)

#Prepare the test data
x_test=[[72.8],[61.1],[67.4],[70.2],[75.6],[60.2],[59.2]]       #new value to find out son height if father's height given

#Test the model


#plot the traning data

#plot the best fit line using predicted values
plt.xlabel("Father height in inches")
plt.ylabel('Son height in inches')

Output :

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top