SlideShare a Scribd company logo
Machine Learning in Agriculture
Module 3
Presented By
Dr. Prasenjit Dey,
Assistant Professor,
Coochbehar Government Engineering College,
West Bengal, India
Linear Regression
 Definition
 Linear regression is a linear model, e.g., a model that assumes a linear relationship
between the input variable (x) and the output variable (y)
 f(x) = w1x1 + w2x2 + w3x3 + … + wnxn + C
 F(TLL,SD) = w1TLL + w2SD + C
 In higher dimension, when we have more than one input(x), the line becomes
plane or hyperplane
Linear Regression Measurements
 Mean Absolute Error (MAE)
 It is the sum of the absolute differences between predictions and actual values. It gives an idea of how wrong the predictions
were
 MAE = |y_predict –y_desired|
 Mean Squared Error (MSE)
 It is the sum of squared differences between predictions and actual values
 MSE = (y_predict –y_desired)2
 Root Mean Squared Error (RMSE)
 It is the squared root of the MSE, converts the units back to the original units of the output variable
 𝑅𝑀𝑆𝐸 = √(y_predict –y_desired)2
 R2 Metric
 It is an indicator of the goodness of a set of predictions to the actual values, lies between 0 and 1 for non-fit and perfect-fit
respectively
 R2 = 1 -
𝑆𝑢𝑚 𝑜𝑓 𝑠𝑞𝑢𝑎𝑟𝑒𝑑 𝑟𝑒𝑔𝑟𝑒𝑠𝑠𝑜𝑟 𝑒𝑟𝑟𝑜𝑟
𝑠𝑢𝑚 𝑠𝑞𝑢𝑎𝑟𝑒𝑑 𝑜𝑓 𝑡𝑜𝑡𝑎𝑙 𝑒𝑟𝑟𝑜𝑟
Using Python Notebook for Machine
Learning
 https://colab.research.google.com/notebooks/welcome.ipynb
 Go to file and upload your notebook(code file)
 Setting Up Google Python NoteBook
Coding
# conventional way to import pandas
 import pandas as pd
# read CSV file directly from a URL and save the results
 #data = pd.read_csv('https://raw.githubusercontent.com/Prasenjit123/ML-
Training/main/crop_yield.csv')
 data = pd.read_csv('https://raw.githubusercontent.com/Prasenjit123/ML-
Training/main/crop_data.csv')
# display the first 5 rows
 data.head()
Coding
# create a Python list of feature names
 feature_cols = ['TLL', 'SD']
# use the list to select a subset of the original DataFrame
 X = data[feature_cols]
# print the first 5 rows
 print(X.head())
# select a Series from the DataFrame
 y = data[Yield']
# print the first 5 values
 print(y.head())
Coding
# import model
 from sklearn.linear_model import LinearRegression
 from sklearn. model_selection import train_test_split
 from sklearn import datasets, linear_model
 X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.10, random_state=1)
# instantiate
 linreg = LinearRegression(normalize=True)
# fit the model to the training data (learn the coefficients)
 linreg.fit(X_train, y_train)
Coding
 from sklearn import metrics
 import numpy as np
# make predictions on the testing set
 y_pred = linreg.predict(X_test)
 for mp, av in zip(y_pred, y_test):
 print ('Model Predicted Value ={}, Known Value = {}, difference = {}'.format(round(mp,2),roun
d(av,2),round(abs(mp-av),2)))
Coding
 from sklearn import metrics
 print ('Mean Absolute Error = ', metrics.mean_absolute_error(y_test, y_pred))
 print ('Mean Squared Error = ',metrics.mean_squared_error(y_test, y_pred))
 print ('Root Mean Squared Error = ', np.sqrt(metrics.mean_squared_error(y_test, y_pred)))
 print ('R2 score = ', metrics.r2_score(y_test, y_pred))
Coding
 from sklearn. model_selection import train_test_split
 from sklearn import datasets, linear_model
 from sklearn. model_selection import cross_val_score
 lm = linear_model.LinearRegression()
 scores = cross_val_score(lm, X, y, cv=10, scoring='r2')
 print("n", scores)
 print ("The mean of r2 is", scores.mean())
 scores = cross_val_score(lm, X, y, cv=10, scoring='neg_mean_absolute_error')
 print("n",scores)
 print ("The mean of absolute error is", scores.mean())
Coding
# read CSV file
 df = pd.read_csv('https://raw.githubusercontent.com/Prasenjit123/ML-
Training/main/crop_data.csv')
 print(df)
# create a Python list of feature names
 feature_cols = ['TLL', 'SD']
# use the list to select a subset of the original DataFrame
 input_data = df[feature_cols]
# make predictions on the testing set
 y_pred = linreg.predict(input_data)
Thank You

More Related Content

What's hot

2
22
Matlab Tutorial
Matlab TutorialMatlab Tutorial
Matlab Tutorial
Ahmad Siddiq
 
Data analysis on bank data
Data analysis on bank dataData analysis on bank data
Data analysis on bank data
ANISH BHANUSHALI
 
Bisection and fixed point method
Bisection and fixed point methodBisection and fixed point method
Bisection and fixed point method
Jazz Michele Pasaribu
 
10 array
10 array10 array
Statistics Assignment Help
Statistics Assignment HelpStatistics Assignment Help
Statistics Assignment Help
Statistics Assignment Help
 
Arithmetic operators
Arithmetic operatorsArithmetic operators
Arithmetic operators
sidneyodingo
 
Understanding variable importances in forests of randomized trees
Understanding variable importances in forests of randomized treesUnderstanding variable importances in forests of randomized trees
Understanding variable importances in forests of randomized trees
Gilles Louppe
 
Matlab Files
Matlab FilesMatlab Files
Matlab Files
Saloni Singhal
 
AP Calculus January 9, 2009
AP Calculus January 9, 2009AP Calculus January 9, 2009
AP Calculus January 9, 2009
Darren Kuropatwa
 
Conference poster 6
Conference poster 6Conference poster 6
Conference poster 6
NTNU
 
Matrix operations in MATLAB
Matrix operations in MATLABMatrix operations in MATLAB
Matrix operations in MATLAB
Saloni Singhal
 
Numerical Method Analysis: Algebraic and Transcendental Equations (Non-Linear)
Numerical Method Analysis: Algebraic and Transcendental Equations (Non-Linear)Numerical Method Analysis: Algebraic and Transcendental Equations (Non-Linear)
Numerical Method Analysis: Algebraic and Transcendental Equations (Non-Linear)
Minhas Kamal
 
Applications of numerical methods
Applications of numerical methodsApplications of numerical methods
Applications of numerical methods
Tarun Gehlot
 
Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Kyiv 2017, Day 1
Psychtoolbox (PTB) practical course  by Volodymyr B. Bogdanov, Kyiv 2017, Day 1Psychtoolbox (PTB) practical course  by Volodymyr B. Bogdanov, Kyiv 2017, Day 1
Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Kyiv 2017, Day 1
Volodymyr Bogdanov
 
Unit 7.2
Unit 7.2Unit 7.2
Unit 7.2
Mark Ryder
 
Interpolation and its applications
Interpolation and its applicationsInterpolation and its applications
Interpolation and its applications
RinkuMonani
 
2. data types, variables and operators
2. data types, variables and operators2. data types, variables and operators
2. data types, variables and operators
PhD Research Scholar
 
358 33 powerpoint-slides_5-arrays_chapter-5
358 33 powerpoint-slides_5-arrays_chapter-5358 33 powerpoint-slides_5-arrays_chapter-5
358 33 powerpoint-slides_5-arrays_chapter-5
sumitbardhan
 
Bisection
BisectionBisection
Bisection
Shipon Sarder
 

What's hot (20)

2
22
2
 
Matlab Tutorial
Matlab TutorialMatlab Tutorial
Matlab Tutorial
 
Data analysis on bank data
Data analysis on bank dataData analysis on bank data
Data analysis on bank data
 
Bisection and fixed point method
Bisection and fixed point methodBisection and fixed point method
Bisection and fixed point method
 
10 array
10 array10 array
10 array
 
Statistics Assignment Help
Statistics Assignment HelpStatistics Assignment Help
Statistics Assignment Help
 
Arithmetic operators
Arithmetic operatorsArithmetic operators
Arithmetic operators
 
Understanding variable importances in forests of randomized trees
Understanding variable importances in forests of randomized treesUnderstanding variable importances in forests of randomized trees
Understanding variable importances in forests of randomized trees
 
Matlab Files
Matlab FilesMatlab Files
Matlab Files
 
AP Calculus January 9, 2009
AP Calculus January 9, 2009AP Calculus January 9, 2009
AP Calculus January 9, 2009
 
Conference poster 6
Conference poster 6Conference poster 6
Conference poster 6
 
Matrix operations in MATLAB
Matrix operations in MATLABMatrix operations in MATLAB
Matrix operations in MATLAB
 
Numerical Method Analysis: Algebraic and Transcendental Equations (Non-Linear)
Numerical Method Analysis: Algebraic and Transcendental Equations (Non-Linear)Numerical Method Analysis: Algebraic and Transcendental Equations (Non-Linear)
Numerical Method Analysis: Algebraic and Transcendental Equations (Non-Linear)
 
Applications of numerical methods
Applications of numerical methodsApplications of numerical methods
Applications of numerical methods
 
Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Kyiv 2017, Day 1
Psychtoolbox (PTB) practical course  by Volodymyr B. Bogdanov, Kyiv 2017, Day 1Psychtoolbox (PTB) practical course  by Volodymyr B. Bogdanov, Kyiv 2017, Day 1
Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Kyiv 2017, Day 1
 
Unit 7.2
Unit 7.2Unit 7.2
Unit 7.2
 
Interpolation and its applications
Interpolation and its applicationsInterpolation and its applications
Interpolation and its applications
 
2. data types, variables and operators
2. data types, variables and operators2. data types, variables and operators
2. data types, variables and operators
 
358 33 powerpoint-slides_5-arrays_chapter-5
358 33 powerpoint-slides_5-arrays_chapter-5358 33 powerpoint-slides_5-arrays_chapter-5
358 33 powerpoint-slides_5-arrays_chapter-5
 
Bisection
BisectionBisection
Bisection
 

Similar to Machine Learning in Agriculture Module 3: linear regression

X01 Supervised learning problem linear regression one feature theorie
X01 Supervised learning problem linear regression one feature theorieX01 Supervised learning problem linear regression one feature theorie
X01 Supervised learning problem linear regression one feature theorie
Marco Moldenhauer
 
working with python
working with pythonworking with python
working with python
bhavesh lande
 
Understanding Blackbox Prediction via Influence Functions
Understanding Blackbox Prediction via Influence FunctionsUnderstanding Blackbox Prediction via Influence Functions
Understanding Blackbox Prediction via Influence Functions
SEMINARGROOT
 
3 Data Structure in R
3 Data Structure in R3 Data Structure in R
3 Data Structure in R
Dr Nisha Arora
 
Naïve Bayes.pptx
Naïve Bayes.pptxNaïve Bayes.pptx
Naïve Bayes.pptx
Dr. Amanpreet Kaur
 
maXbox starter69 Machine Learning VII
maXbox starter69 Machine Learning VIImaXbox starter69 Machine Learning VII
maXbox starter69 Machine Learning VII
Max Kleiner
 
simple linear regression
simple linear regressionsimple linear regression
simple linear regression
Akhilesh Joshi
 
decision tree regression
decision tree regressiondecision tree regression
decision tree regression
Akhilesh Joshi
 
Deep Learning: Introduction & Chapter 5 Machine Learning Basics
Deep Learning: Introduction & Chapter 5 Machine Learning BasicsDeep Learning: Introduction & Chapter 5 Machine Learning Basics
Deep Learning: Introduction & Chapter 5 Machine Learning Basics
Jason Tsai
 
Basic R Data Manipulation
Basic R Data ManipulationBasic R Data Manipulation
Basic R Data Manipulation
Chu An
 
Array,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN CArray,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN C
naveed jamali
 
R for Statistical Computing
R for Statistical ComputingR for Statistical Computing
R for Statistical Computing
Mohammed El Rafie Tarabay
 
Regression
RegressionRegression
Regression
ramyaranjith
 
E10
E10E10
E10
lksoo
 
Csci101 lect08b matlab_programs
Csci101 lect08b matlab_programsCsci101 lect08b matlab_programs
Csci101 lect08b matlab_programs
Elsayed Hemayed
 
Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine Learning
Big_Data_Ukraine
 
knn classification
knn classificationknn classification
knn classification
Akhilesh Joshi
 
Computational Intelligence Assisted Engineering Design Optimization (using MA...
Computational Intelligence Assisted Engineering Design Optimization (using MA...Computational Intelligence Assisted Engineering Design Optimization (using MA...
Computational Intelligence Assisted Engineering Design Optimization (using MA...
AmirParnianifard1
 
Linear Regression (Machine Learning)
Linear Regression (Machine Learning)Linear Regression (Machine Learning)
Linear Regression (Machine Learning)
Omkar Rane
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
BilawalBaloch1
 

Similar to Machine Learning in Agriculture Module 3: linear regression (20)

X01 Supervised learning problem linear regression one feature theorie
X01 Supervised learning problem linear regression one feature theorieX01 Supervised learning problem linear regression one feature theorie
X01 Supervised learning problem linear regression one feature theorie
 
working with python
working with pythonworking with python
working with python
 
Understanding Blackbox Prediction via Influence Functions
Understanding Blackbox Prediction via Influence FunctionsUnderstanding Blackbox Prediction via Influence Functions
Understanding Blackbox Prediction via Influence Functions
 
3 Data Structure in R
3 Data Structure in R3 Data Structure in R
3 Data Structure in R
 
Naïve Bayes.pptx
Naïve Bayes.pptxNaïve Bayes.pptx
Naïve Bayes.pptx
 
maXbox starter69 Machine Learning VII
maXbox starter69 Machine Learning VIImaXbox starter69 Machine Learning VII
maXbox starter69 Machine Learning VII
 
simple linear regression
simple linear regressionsimple linear regression
simple linear regression
 
decision tree regression
decision tree regressiondecision tree regression
decision tree regression
 
Deep Learning: Introduction & Chapter 5 Machine Learning Basics
Deep Learning: Introduction & Chapter 5 Machine Learning BasicsDeep Learning: Introduction & Chapter 5 Machine Learning Basics
Deep Learning: Introduction & Chapter 5 Machine Learning Basics
 
Basic R Data Manipulation
Basic R Data ManipulationBasic R Data Manipulation
Basic R Data Manipulation
 
Array,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN CArray,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN C
 
R for Statistical Computing
R for Statistical ComputingR for Statistical Computing
R for Statistical Computing
 
Regression
RegressionRegression
Regression
 
E10
E10E10
E10
 
Csci101 lect08b matlab_programs
Csci101 lect08b matlab_programsCsci101 lect08b matlab_programs
Csci101 lect08b matlab_programs
 
Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine Learning
 
knn classification
knn classificationknn classification
knn classification
 
Computational Intelligence Assisted Engineering Design Optimization (using MA...
Computational Intelligence Assisted Engineering Design Optimization (using MA...Computational Intelligence Assisted Engineering Design Optimization (using MA...
Computational Intelligence Assisted Engineering Design Optimization (using MA...
 
Linear Regression (Machine Learning)
Linear Regression (Machine Learning)Linear Regression (Machine Learning)
Linear Regression (Machine Learning)
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 

More from Prasenjit Dey

Dynamic interconnection networks
Dynamic interconnection networksDynamic interconnection networks
Dynamic interconnection networks
Prasenjit Dey
 
Machine Learning in Agriculture Module 6: classification
Machine Learning in Agriculture Module 6: classificationMachine Learning in Agriculture Module 6: classification
Machine Learning in Agriculture Module 6: classification
Prasenjit Dey
 
Machine learning in agriculture module 2
Machine learning in agriculture module 2Machine learning in agriculture module 2
Machine learning in agriculture module 2
Prasenjit Dey
 
Machine Learning in Agriculture Module 1
Machine Learning in Agriculture Module 1Machine Learning in Agriculture Module 1
Machine Learning in Agriculture Module 1
Prasenjit Dey
 
Support vector machine
Support vector machineSupport vector machine
Support vector machine
Prasenjit Dey
 
Numerical on general pipelines
Numerical on general pipelinesNumerical on general pipelines
Numerical on general pipelines
Prasenjit Dey
 
General pipeline concepts
General pipeline conceptsGeneral pipeline concepts
General pipeline concepts
Prasenjit Dey
 
Evaluation of computer performance
Evaluation of computer performanceEvaluation of computer performance
Evaluation of computer performance
Prasenjit Dey
 
Instruction Set Architecture: MIPS
Instruction Set Architecture: MIPSInstruction Set Architecture: MIPS
Instruction Set Architecture: MIPS
Prasenjit Dey
 
Page replacement and thrashing
Page replacement and thrashingPage replacement and thrashing
Page replacement and thrashing
Prasenjit Dey
 
Addressing mode
Addressing modeAddressing mode
Addressing mode
Prasenjit Dey
 
Register transfer and microoperations part 2
Register transfer and microoperations part 2Register transfer and microoperations part 2
Register transfer and microoperations part 2
Prasenjit Dey
 
Instruction set (prasenjit dey)
Instruction set (prasenjit dey)Instruction set (prasenjit dey)
Instruction set (prasenjit dey)
Prasenjit Dey
 
Register transfer and microoperations part 1
Register transfer and microoperations part 1Register transfer and microoperations part 1
Register transfer and microoperations part 1
Prasenjit Dey
 
Different types of memory and hardware designs of RAM and ROM
Different types of memory and hardware designs of RAM and ROMDifferent types of memory and hardware designs of RAM and ROM
Different types of memory and hardware designs of RAM and ROM
Prasenjit Dey
 
Cache memory
Cache  memoryCache  memory
Cache memory
Prasenjit Dey
 
Carry look ahead adder
Carry look ahead adder Carry look ahead adder
Carry look ahead adder
Prasenjit Dey
 
Binary division restoration and non restoration algorithm
Binary division restoration and non restoration algorithmBinary division restoration and non restoration algorithm
Binary division restoration and non restoration algorithm
Prasenjit Dey
 
Booth's algorithm
Booth's algorithm Booth's algorithm
Booth's algorithm
Prasenjit Dey
 
Computer organization basics and number systems
Computer organization basics and number systemsComputer organization basics and number systems
Computer organization basics and number systems
Prasenjit Dey
 

More from Prasenjit Dey (20)

Dynamic interconnection networks
Dynamic interconnection networksDynamic interconnection networks
Dynamic interconnection networks
 
Machine Learning in Agriculture Module 6: classification
Machine Learning in Agriculture Module 6: classificationMachine Learning in Agriculture Module 6: classification
Machine Learning in Agriculture Module 6: classification
 
Machine learning in agriculture module 2
Machine learning in agriculture module 2Machine learning in agriculture module 2
Machine learning in agriculture module 2
 
Machine Learning in Agriculture Module 1
Machine Learning in Agriculture Module 1Machine Learning in Agriculture Module 1
Machine Learning in Agriculture Module 1
 
Support vector machine
Support vector machineSupport vector machine
Support vector machine
 
Numerical on general pipelines
Numerical on general pipelinesNumerical on general pipelines
Numerical on general pipelines
 
General pipeline concepts
General pipeline conceptsGeneral pipeline concepts
General pipeline concepts
 
Evaluation of computer performance
Evaluation of computer performanceEvaluation of computer performance
Evaluation of computer performance
 
Instruction Set Architecture: MIPS
Instruction Set Architecture: MIPSInstruction Set Architecture: MIPS
Instruction Set Architecture: MIPS
 
Page replacement and thrashing
Page replacement and thrashingPage replacement and thrashing
Page replacement and thrashing
 
Addressing mode
Addressing modeAddressing mode
Addressing mode
 
Register transfer and microoperations part 2
Register transfer and microoperations part 2Register transfer and microoperations part 2
Register transfer and microoperations part 2
 
Instruction set (prasenjit dey)
Instruction set (prasenjit dey)Instruction set (prasenjit dey)
Instruction set (prasenjit dey)
 
Register transfer and microoperations part 1
Register transfer and microoperations part 1Register transfer and microoperations part 1
Register transfer and microoperations part 1
 
Different types of memory and hardware designs of RAM and ROM
Different types of memory and hardware designs of RAM and ROMDifferent types of memory and hardware designs of RAM and ROM
Different types of memory and hardware designs of RAM and ROM
 
Cache memory
Cache  memoryCache  memory
Cache memory
 
Carry look ahead adder
Carry look ahead adder Carry look ahead adder
Carry look ahead adder
 
Binary division restoration and non restoration algorithm
Binary division restoration and non restoration algorithmBinary division restoration and non restoration algorithm
Binary division restoration and non restoration algorithm
 
Booth's algorithm
Booth's algorithm Booth's algorithm
Booth's algorithm
 
Computer organization basics and number systems
Computer organization basics and number systemsComputer organization basics and number systems
Computer organization basics and number systems
 

Recently uploaded

办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
apvysm8
 
Global Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headedGlobal Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headed
vikram sood
 
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdfUnleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
Enterprise Wired
 
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
g4dpvqap0
 
Learn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queriesLearn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queries
manishkhaire30
 
My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.
rwarrenll
 
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
74nqk8xf
 
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
sameer shah
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
Timothy Spann
 
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
nuttdpt
 
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
nuttdpt
 
Challenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more importantChallenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more important
Sm321
 
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
mzpolocfi
 
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
ahzuo
 
Analysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performanceAnalysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performance
roli9797
 
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
oz8q3jxlp
 
The Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series DatabaseThe Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series Database
javier ramirez
 
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
nyfuhyz
 
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdfEnhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
GetInData
 
Everything you wanted to know about LIHTC
Everything you wanted to know about LIHTCEverything you wanted to know about LIHTC
Everything you wanted to know about LIHTC
Roger Valdez
 

Recently uploaded (20)

办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
 
Global Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headedGlobal Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headed
 
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdfUnleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
 
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
 
Learn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queriesLearn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queries
 
My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.
 
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
 
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
 
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
 
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
 
Challenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more importantChallenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more important
 
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
 
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
 
Analysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performanceAnalysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performance
 
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
 
The Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series DatabaseThe Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series Database
 
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
 
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdfEnhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
 
Everything you wanted to know about LIHTC
Everything you wanted to know about LIHTCEverything you wanted to know about LIHTC
Everything you wanted to know about LIHTC
 

Machine Learning in Agriculture Module 3: linear regression

  • 1. Machine Learning in Agriculture Module 3 Presented By Dr. Prasenjit Dey, Assistant Professor, Coochbehar Government Engineering College, West Bengal, India
  • 2. Linear Regression  Definition  Linear regression is a linear model, e.g., a model that assumes a linear relationship between the input variable (x) and the output variable (y)  f(x) = w1x1 + w2x2 + w3x3 + … + wnxn + C  F(TLL,SD) = w1TLL + w2SD + C  In higher dimension, when we have more than one input(x), the line becomes plane or hyperplane
  • 3. Linear Regression Measurements  Mean Absolute Error (MAE)  It is the sum of the absolute differences between predictions and actual values. It gives an idea of how wrong the predictions were  MAE = |y_predict –y_desired|  Mean Squared Error (MSE)  It is the sum of squared differences between predictions and actual values  MSE = (y_predict –y_desired)2  Root Mean Squared Error (RMSE)  It is the squared root of the MSE, converts the units back to the original units of the output variable  𝑅𝑀𝑆𝐸 = √(y_predict –y_desired)2  R2 Metric  It is an indicator of the goodness of a set of predictions to the actual values, lies between 0 and 1 for non-fit and perfect-fit respectively  R2 = 1 - 𝑆𝑢𝑚 𝑜𝑓 𝑠𝑞𝑢𝑎𝑟𝑒𝑑 𝑟𝑒𝑔𝑟𝑒𝑠𝑠𝑜𝑟 𝑒𝑟𝑟𝑜𝑟 𝑠𝑢𝑚 𝑠𝑞𝑢𝑎𝑟𝑒𝑑 𝑜𝑓 𝑡𝑜𝑡𝑎𝑙 𝑒𝑟𝑟𝑜𝑟
  • 4. Using Python Notebook for Machine Learning  https://colab.research.google.com/notebooks/welcome.ipynb  Go to file and upload your notebook(code file)  Setting Up Google Python NoteBook
  • 5. Coding # conventional way to import pandas  import pandas as pd # read CSV file directly from a URL and save the results  #data = pd.read_csv('https://raw.githubusercontent.com/Prasenjit123/ML- Training/main/crop_yield.csv')  data = pd.read_csv('https://raw.githubusercontent.com/Prasenjit123/ML- Training/main/crop_data.csv') # display the first 5 rows  data.head()
  • 6. Coding # create a Python list of feature names  feature_cols = ['TLL', 'SD'] # use the list to select a subset of the original DataFrame  X = data[feature_cols] # print the first 5 rows  print(X.head()) # select a Series from the DataFrame  y = data[Yield'] # print the first 5 values  print(y.head())
  • 7. Coding # import model  from sklearn.linear_model import LinearRegression  from sklearn. model_selection import train_test_split  from sklearn import datasets, linear_model  X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.10, random_state=1) # instantiate  linreg = LinearRegression(normalize=True) # fit the model to the training data (learn the coefficients)  linreg.fit(X_train, y_train)
  • 8. Coding  from sklearn import metrics  import numpy as np # make predictions on the testing set  y_pred = linreg.predict(X_test)  for mp, av in zip(y_pred, y_test):  print ('Model Predicted Value ={}, Known Value = {}, difference = {}'.format(round(mp,2),roun d(av,2),round(abs(mp-av),2)))
  • 9. Coding  from sklearn import metrics  print ('Mean Absolute Error = ', metrics.mean_absolute_error(y_test, y_pred))  print ('Mean Squared Error = ',metrics.mean_squared_error(y_test, y_pred))  print ('Root Mean Squared Error = ', np.sqrt(metrics.mean_squared_error(y_test, y_pred)))  print ('R2 score = ', metrics.r2_score(y_test, y_pred))
  • 10. Coding  from sklearn. model_selection import train_test_split  from sklearn import datasets, linear_model  from sklearn. model_selection import cross_val_score  lm = linear_model.LinearRegression()  scores = cross_val_score(lm, X, y, cv=10, scoring='r2')  print("n", scores)  print ("The mean of r2 is", scores.mean())  scores = cross_val_score(lm, X, y, cv=10, scoring='neg_mean_absolute_error')  print("n",scores)  print ("The mean of absolute error is", scores.mean())
  • 11. Coding # read CSV file  df = pd.read_csv('https://raw.githubusercontent.com/Prasenjit123/ML- Training/main/crop_data.csv')  print(df) # create a Python list of feature names  feature_cols = ['TLL', 'SD'] # use the list to select a subset of the original DataFrame  input_data = df[feature_cols] # make predictions on the testing set  y_pred = linreg.predict(input_data)