SlideShare a Scribd company logo
1 of 4
Assignment 2
Linear Regression
Predicting Car MPG
The goal of this assignment is to help you understand the
concepts of regression through having hands-on
experience with training and applying regression models.
You are given a dataset of car attributes and their gas
consumption in MPG (Mile Per Gallon). Your task is to build
a regression model that can predict a car’s MPG given its
attributes.
Car MPG dataset:
The dataset consists of 393 car models, their attributes and their
MPG. The columns in the data set are as follows:
1. Car Model Name
2. MPG - Miles Per Gallon. This is the value that we want to
predict
3. Number of cylinders
4. Engine Displacement
5. Engine Horse Power
6. Car Weight
7. Acceleration (time needed to reach a speed of 60 miles/hour)
8. Model Year
9. Origin
Tasks:
following in python:
1. Load the data from the csv file using Pandas
2. Preview/print the top 10 rows of the data
3. Create the Features matrix (columns 3-9 above – i.e. exclude
the model_name and the mpg
columns)
4. Create the Labels vector (the mpg column)
5. Plot the relationship between each of the features and the
label mpg on a scatter chart. This will
be a total of 7 charts.
6. Normalize the features using the StandardScaler class of the
sklearn.preprocessing package
7. Split the data into training and test data using the
cross_validation class of sklearn
8. Train a regression model on the training subset using the
SGDRegressor class of the
sklearn.linear_models package. Set the number of iterations of
the learner to be 500 iterations.
Perform the training as follows:
a model using the cylinders
feature only, then train a model using the displacement feature
only, and so on.
9. For each of the models trained in step 8, apply the model to
the test subset and then compute
the r2_score, the mean_squared_error, and the
mean_absolute_error scores for the predictions
of each model trained above.
10. Train a model using all features for 500 iterations while
setting the regularization type (penalty)
to ‘l1’ instead of the default ‘l2’. Apply the model to the test
data and compute the evaluation
metrics as in step 9.
11. Train a model using all features for 500 iterations with ‘l2’
regularization and an initial learning
rate (eta0) set to 10.0. Compute the evaluation metrics as in
step 9.
What to submit
1. Submit the Jupyter Notebook that shows all your work
exactly as described above. Your notebook should
include section headers and descriptive text that explains what
you are doing at each step (follow the
style of the notebooks we develop at class.)
Submit your jyputer notebook both in *.ipynb format and also
HTML format. To produce the
HTML format: File > Download AS > HTML (.html).
2. Submit a document in PDF format that shows the results of
the experiments you ran in steps 8 to 11
above. The results should be shown in one table similar to the
following:
Features Used Non-default params R2 score Mean Squared
Error Mean Absolute Error
Cylinders Iter = 500
Displacement Iter = 500
Horsepower Iter = 500
Weight Iter = 500
Acceleration Iter = 500
Year Iter = 500
Origin Iter = 500
All Features Iter = 500
All Features
Iter = 500, penalty =
l1
All Features Iter = 500, eta0 = 10

More Related Content

Similar to Assignment 2 linear regression predicting car mpg

Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxBroncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxcurwenmichaela
 
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxBroncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxhartrobert670
 
A machine learning model for average fuel consumption in heavy vehicles
A machine learning model for average fuel consumption in heavy vehiclesA machine learning model for average fuel consumption in heavy vehicles
A machine learning model for average fuel consumption in heavy vehiclesVenkat Projects
 
GDE Lab 1 – Traffic Light Pg. 1 Lab 1 Traffic L.docx
GDE Lab 1 – Traffic Light  Pg. 1     Lab 1 Traffic L.docxGDE Lab 1 – Traffic Light  Pg. 1     Lab 1 Traffic L.docx
GDE Lab 1 – Traffic Light Pg. 1 Lab 1 Traffic L.docxbudbarber38650
 
Cmis 102 Effective Communication / snaptutorial.com
Cmis 102  Effective Communication / snaptutorial.comCmis 102  Effective Communication / snaptutorial.com
Cmis 102 Effective Communication / snaptutorial.comHarrisGeorg12
 
Augustus Overview Open Source Analytics
Augustus Overview  Open Source AnalyticsAugustus Overview  Open Source Analytics
Augustus Overview Open Source Analyticsjtrussell
 
Object-oriented Modeling with OptimJ
Object-oriented Modeling with OptimJObject-oriented Modeling with OptimJ
Object-oriented Modeling with OptimJPatrick Viry
 
Key projects Data Science and Engineering
Key projects Data Science and EngineeringKey projects Data Science and Engineering
Key projects Data Science and EngineeringVijayananda Mohire
 
Key projects Data Science and Engineering
Key projects Data Science and EngineeringKey projects Data Science and Engineering
Key projects Data Science and EngineeringVijayananda Mohire
 
IBM Cognos 10 Framework Manager Metadata Modeling: Tips and Tricks
IBM Cognos 10 Framework Manager Metadata Modeling: Tips and TricksIBM Cognos 10 Framework Manager Metadata Modeling: Tips and Tricks
IBM Cognos 10 Framework Manager Metadata Modeling: Tips and TricksSenturus
 
ENGR 131 Elementary Computer ProgrammingTeam IN – Instructor
ENGR 131  Elementary Computer ProgrammingTeam IN – InstructorENGR 131  Elementary Computer ProgrammingTeam IN – Instructor
ENGR 131 Elementary Computer ProgrammingTeam IN – InstructorTanaMaeskm
 
Unsupervised Aspect Based Sentiment Analysis at Scale
Unsupervised Aspect Based Sentiment Analysis at ScaleUnsupervised Aspect Based Sentiment Analysis at Scale
Unsupervised Aspect Based Sentiment Analysis at ScaleAaron (Ari) Bornstein
 
Cmis 102 Enthusiastic Study / snaptutorial.com
Cmis 102 Enthusiastic Study / snaptutorial.comCmis 102 Enthusiastic Study / snaptutorial.com
Cmis 102 Enthusiastic Study / snaptutorial.comStephenson22
 
Cmis 102 Success Begins / snaptutorial.com
Cmis 102 Success Begins / snaptutorial.comCmis 102 Success Begins / snaptutorial.com
Cmis 102 Success Begins / snaptutorial.comWilliamsTaylorza48
 
BTE 320-498 Summer 2017 Take Home Exam (200 poi.docx
BTE 320-498 Summer 2017 Take Home Exam (200 poi.docxBTE 320-498 Summer 2017 Take Home Exam (200 poi.docx
BTE 320-498 Summer 2017 Take Home Exam (200 poi.docxAASTHA76
 
Angular2 with TypeScript
Angular2 with TypeScript Angular2 with TypeScript
Angular2 with TypeScript Rohit Bishnoi
 
School of Computing, Science & EngineeringAssessment Briefin.docx
School of Computing, Science & EngineeringAssessment Briefin.docxSchool of Computing, Science & EngineeringAssessment Briefin.docx
School of Computing, Science & EngineeringAssessment Briefin.docxanhlodge
 

Similar to Assignment 2 linear regression predicting car mpg (20)

Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxBroncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
 
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxBroncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
 
A machine learning model for average fuel consumption in heavy vehicles
A machine learning model for average fuel consumption in heavy vehiclesA machine learning model for average fuel consumption in heavy vehicles
A machine learning model for average fuel consumption in heavy vehicles
 
GDE Lab 1 – Traffic Light Pg. 1 Lab 1 Traffic L.docx
GDE Lab 1 – Traffic Light  Pg. 1     Lab 1 Traffic L.docxGDE Lab 1 – Traffic Light  Pg. 1     Lab 1 Traffic L.docx
GDE Lab 1 – Traffic Light Pg. 1 Lab 1 Traffic L.docx
 
projectreport
projectreportprojectreport
projectreport
 
Cmis 102 Effective Communication / snaptutorial.com
Cmis 102  Effective Communication / snaptutorial.comCmis 102  Effective Communication / snaptutorial.com
Cmis 102 Effective Communication / snaptutorial.com
 
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORYGE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
 
Augustus Overview Open Source Analytics
Augustus Overview  Open Source AnalyticsAugustus Overview  Open Source Analytics
Augustus Overview Open Source Analytics
 
Object-oriented Modeling with OptimJ
Object-oriented Modeling with OptimJObject-oriented Modeling with OptimJ
Object-oriented Modeling with OptimJ
 
Key projects Data Science and Engineering
Key projects Data Science and EngineeringKey projects Data Science and Engineering
Key projects Data Science and Engineering
 
Key projects Data Science and Engineering
Key projects Data Science and EngineeringKey projects Data Science and Engineering
Key projects Data Science and Engineering
 
IBM Cognos 10 Framework Manager Metadata Modeling: Tips and Tricks
IBM Cognos 10 Framework Manager Metadata Modeling: Tips and TricksIBM Cognos 10 Framework Manager Metadata Modeling: Tips and Tricks
IBM Cognos 10 Framework Manager Metadata Modeling: Tips and Tricks
 
ENGR 131 Elementary Computer ProgrammingTeam IN – Instructor
ENGR 131  Elementary Computer ProgrammingTeam IN – InstructorENGR 131  Elementary Computer ProgrammingTeam IN – Instructor
ENGR 131 Elementary Computer ProgrammingTeam IN – Instructor
 
Unsupervised Aspect Based Sentiment Analysis at Scale
Unsupervised Aspect Based Sentiment Analysis at ScaleUnsupervised Aspect Based Sentiment Analysis at Scale
Unsupervised Aspect Based Sentiment Analysis at Scale
 
Cmis 102 Enthusiastic Study / snaptutorial.com
Cmis 102 Enthusiastic Study / snaptutorial.comCmis 102 Enthusiastic Study / snaptutorial.com
Cmis 102 Enthusiastic Study / snaptutorial.com
 
Cmis 102 Success Begins / snaptutorial.com
Cmis 102 Success Begins / snaptutorial.comCmis 102 Success Begins / snaptutorial.com
Cmis 102 Success Begins / snaptutorial.com
 
BTE 320-498 Summer 2017 Take Home Exam (200 poi.docx
BTE 320-498 Summer 2017 Take Home Exam (200 poi.docxBTE 320-498 Summer 2017 Take Home Exam (200 poi.docx
BTE 320-498 Summer 2017 Take Home Exam (200 poi.docx
 
Mini Project- Stepper Motor Control
Mini Project- Stepper Motor ControlMini Project- Stepper Motor Control
Mini Project- Stepper Motor Control
 
Angular2 with TypeScript
Angular2 with TypeScript Angular2 with TypeScript
Angular2 with TypeScript
 
School of Computing, Science & EngineeringAssessment Briefin.docx
School of Computing, Science & EngineeringAssessment Briefin.docxSchool of Computing, Science & EngineeringAssessment Briefin.docx
School of Computing, Science & EngineeringAssessment Briefin.docx
 

More from ssuserf9c51d

Muslims in the Golden Age is the theme for the research project. You.docx
Muslims in the Golden Age is the theme for the research project. You.docxMuslims in the Golden Age is the theme for the research project. You.docx
Muslims in the Golden Age is the theme for the research project. You.docxssuserf9c51d
 
Multiple Sources of MediaExamine the impact of multiple sour.docx
Multiple Sources of MediaExamine the impact of multiple sour.docxMultiple Sources of MediaExamine the impact of multiple sour.docx
Multiple Sources of MediaExamine the impact of multiple sour.docxssuserf9c51d
 
Multicultural Event WrittenPlease choose and research a cult.docx
Multicultural Event WrittenPlease choose and research a cult.docxMulticultural Event WrittenPlease choose and research a cult.docx
Multicultural Event WrittenPlease choose and research a cult.docxssuserf9c51d
 
Multi-Party NegotiationFor this Essay, you will explore the co.docx
Multi-Party NegotiationFor this Essay, you will explore the co.docxMulti-Party NegotiationFor this Essay, you will explore the co.docx
Multi-Party NegotiationFor this Essay, you will explore the co.docxssuserf9c51d
 
Music has long been used by movements seeking social change.  In the.docx
Music has long been used by movements seeking social change.  In the.docxMusic has long been used by movements seeking social change.  In the.docx
Music has long been used by movements seeking social change.  In the.docxssuserf9c51d
 
MSW Advanced Clinical Concentration -Student Learning AgreementW.docx
MSW Advanced Clinical Concentration -Student Learning AgreementW.docxMSW Advanced Clinical Concentration -Student Learning AgreementW.docx
MSW Advanced Clinical Concentration -Student Learning AgreementW.docxssuserf9c51d
 
Multimedia Instructional MaterialsStaying current on technolog.docx
Multimedia Instructional MaterialsStaying current on technolog.docxMultimedia Instructional MaterialsStaying current on technolog.docx
Multimedia Instructional MaterialsStaying current on technolog.docxssuserf9c51d
 
Murray Bowen is one of the most respected family theorists in th.docx
Murray Bowen is one of the most respected family theorists in th.docxMurray Bowen is one of the most respected family theorists in th.docx
Murray Bowen is one of the most respected family theorists in th.docxssuserf9c51d
 
Mrs. Thomas is a 54, year old African American widow, mother and gra.docx
Mrs. Thomas is a 54, year old African American widow, mother and gra.docxMrs. Thomas is a 54, year old African American widow, mother and gra.docx
Mrs. Thomas is a 54, year old African American widow, mother and gra.docxssuserf9c51d
 
Multiple Source Essay, Speculating about CausesProposing a Solution.docx
Multiple Source Essay, Speculating about CausesProposing a Solution.docxMultiple Source Essay, Speculating about CausesProposing a Solution.docx
Multiple Source Essay, Speculating about CausesProposing a Solution.docxssuserf9c51d
 
Multiyear Plans Please respond to the followingDo you.docx
Multiyear Plans Please respond to the followingDo you.docxMultiyear Plans Please respond to the followingDo you.docx
Multiyear Plans Please respond to the followingDo you.docxssuserf9c51d
 
Multinational Financial ManagementDetermine key reasons wh.docx
Multinational Financial ManagementDetermine key reasons wh.docxMultinational Financial ManagementDetermine key reasons wh.docx
Multinational Financial ManagementDetermine key reasons wh.docxssuserf9c51d
 
Murder CasePreambleAn organization system administrator .docx
Murder CasePreambleAn organization system administrator .docxMurder CasePreambleAn organization system administrator .docx
Murder CasePreambleAn organization system administrator .docxssuserf9c51d
 
Multimodal Personal Narrative – Develop a multimodal document to bot.docx
Multimodal Personal Narrative – Develop a multimodal document to bot.docxMultimodal Personal Narrative – Develop a multimodal document to bot.docx
Multimodal Personal Narrative – Develop a multimodal document to bot.docxssuserf9c51d
 
Multigenre ProjectEN101O Fall 2019 Dr. WalterA Multigenre Pr.docx
Multigenre ProjectEN101O Fall 2019 Dr. WalterA Multigenre Pr.docxMultigenre ProjectEN101O Fall 2019 Dr. WalterA Multigenre Pr.docx
Multigenre ProjectEN101O Fall 2019 Dr. WalterA Multigenre Pr.docxssuserf9c51d
 
Multimedia activity Business OrganizationVisit the Choose Your .docx
Multimedia activity Business OrganizationVisit the Choose Your .docxMultimedia activity Business OrganizationVisit the Choose Your .docx
Multimedia activity Business OrganizationVisit the Choose Your .docxssuserf9c51d
 
Multicultural PerspectiveToday’s classrooms are diverse and .docx
Multicultural PerspectiveToday’s classrooms are diverse and .docxMulticultural PerspectiveToday’s classrooms are diverse and .docx
Multicultural PerspectiveToday’s classrooms are diverse and .docxssuserf9c51d
 
Muhammad Ali, how did his refusal to go into the army affect his.docx
Muhammad Ali, how did his refusal to go into the army affect his.docxMuhammad Ali, how did his refusal to go into the army affect his.docx
Muhammad Ali, how did his refusal to go into the army affect his.docxssuserf9c51d
 
MS 113 Some key concepts that you need to know to navigate th.docx
MS 113 Some key concepts that you need to know to navigate th.docxMS 113 Some key concepts that you need to know to navigate th.docx
MS 113 Some key concepts that you need to know to navigate th.docxssuserf9c51d
 
Much has been made of the new Web 2.0 phenomenon, including social n.docx
Much has been made of the new Web 2.0 phenomenon, including social n.docxMuch has been made of the new Web 2.0 phenomenon, including social n.docx
Much has been made of the new Web 2.0 phenomenon, including social n.docxssuserf9c51d
 

More from ssuserf9c51d (20)

Muslims in the Golden Age is the theme for the research project. You.docx
Muslims in the Golden Age is the theme for the research project. You.docxMuslims in the Golden Age is the theme for the research project. You.docx
Muslims in the Golden Age is the theme for the research project. You.docx
 
Multiple Sources of MediaExamine the impact of multiple sour.docx
Multiple Sources of MediaExamine the impact of multiple sour.docxMultiple Sources of MediaExamine the impact of multiple sour.docx
Multiple Sources of MediaExamine the impact of multiple sour.docx
 
Multicultural Event WrittenPlease choose and research a cult.docx
Multicultural Event WrittenPlease choose and research a cult.docxMulticultural Event WrittenPlease choose and research a cult.docx
Multicultural Event WrittenPlease choose and research a cult.docx
 
Multi-Party NegotiationFor this Essay, you will explore the co.docx
Multi-Party NegotiationFor this Essay, you will explore the co.docxMulti-Party NegotiationFor this Essay, you will explore the co.docx
Multi-Party NegotiationFor this Essay, you will explore the co.docx
 
Music has long been used by movements seeking social change.  In the.docx
Music has long been used by movements seeking social change.  In the.docxMusic has long been used by movements seeking social change.  In the.docx
Music has long been used by movements seeking social change.  In the.docx
 
MSW Advanced Clinical Concentration -Student Learning AgreementW.docx
MSW Advanced Clinical Concentration -Student Learning AgreementW.docxMSW Advanced Clinical Concentration -Student Learning AgreementW.docx
MSW Advanced Clinical Concentration -Student Learning AgreementW.docx
 
Multimedia Instructional MaterialsStaying current on technolog.docx
Multimedia Instructional MaterialsStaying current on technolog.docxMultimedia Instructional MaterialsStaying current on technolog.docx
Multimedia Instructional MaterialsStaying current on technolog.docx
 
Murray Bowen is one of the most respected family theorists in th.docx
Murray Bowen is one of the most respected family theorists in th.docxMurray Bowen is one of the most respected family theorists in th.docx
Murray Bowen is one of the most respected family theorists in th.docx
 
Mrs. Thomas is a 54, year old African American widow, mother and gra.docx
Mrs. Thomas is a 54, year old African American widow, mother and gra.docxMrs. Thomas is a 54, year old African American widow, mother and gra.docx
Mrs. Thomas is a 54, year old African American widow, mother and gra.docx
 
Multiple Source Essay, Speculating about CausesProposing a Solution.docx
Multiple Source Essay, Speculating about CausesProposing a Solution.docxMultiple Source Essay, Speculating about CausesProposing a Solution.docx
Multiple Source Essay, Speculating about CausesProposing a Solution.docx
 
Multiyear Plans Please respond to the followingDo you.docx
Multiyear Plans Please respond to the followingDo you.docxMultiyear Plans Please respond to the followingDo you.docx
Multiyear Plans Please respond to the followingDo you.docx
 
Multinational Financial ManagementDetermine key reasons wh.docx
Multinational Financial ManagementDetermine key reasons wh.docxMultinational Financial ManagementDetermine key reasons wh.docx
Multinational Financial ManagementDetermine key reasons wh.docx
 
Murder CasePreambleAn organization system administrator .docx
Murder CasePreambleAn organization system administrator .docxMurder CasePreambleAn organization system administrator .docx
Murder CasePreambleAn organization system administrator .docx
 
Multimodal Personal Narrative – Develop a multimodal document to bot.docx
Multimodal Personal Narrative – Develop a multimodal document to bot.docxMultimodal Personal Narrative – Develop a multimodal document to bot.docx
Multimodal Personal Narrative – Develop a multimodal document to bot.docx
 
Multigenre ProjectEN101O Fall 2019 Dr. WalterA Multigenre Pr.docx
Multigenre ProjectEN101O Fall 2019 Dr. WalterA Multigenre Pr.docxMultigenre ProjectEN101O Fall 2019 Dr. WalterA Multigenre Pr.docx
Multigenre ProjectEN101O Fall 2019 Dr. WalterA Multigenre Pr.docx
 
Multimedia activity Business OrganizationVisit the Choose Your .docx
Multimedia activity Business OrganizationVisit the Choose Your .docxMultimedia activity Business OrganizationVisit the Choose Your .docx
Multimedia activity Business OrganizationVisit the Choose Your .docx
 
Multicultural PerspectiveToday’s classrooms are diverse and .docx
Multicultural PerspectiveToday’s classrooms are diverse and .docxMulticultural PerspectiveToday’s classrooms are diverse and .docx
Multicultural PerspectiveToday’s classrooms are diverse and .docx
 
Muhammad Ali, how did his refusal to go into the army affect his.docx
Muhammad Ali, how did his refusal to go into the army affect his.docxMuhammad Ali, how did his refusal to go into the army affect his.docx
Muhammad Ali, how did his refusal to go into the army affect his.docx
 
MS 113 Some key concepts that you need to know to navigate th.docx
MS 113 Some key concepts that you need to know to navigate th.docxMS 113 Some key concepts that you need to know to navigate th.docx
MS 113 Some key concepts that you need to know to navigate th.docx
 
Much has been made of the new Web 2.0 phenomenon, including social n.docx
Much has been made of the new Web 2.0 phenomenon, including social n.docxMuch has been made of the new Web 2.0 phenomenon, including social n.docx
Much has been made of the new Web 2.0 phenomenon, including social n.docx
 

Recently uploaded

Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 

Recently uploaded (20)

Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 

Assignment 2 linear regression predicting car mpg

  • 1. Assignment 2 Linear Regression Predicting Car MPG The goal of this assignment is to help you understand the concepts of regression through having hands-on experience with training and applying regression models. You are given a dataset of car attributes and their gas consumption in MPG (Mile Per Gallon). Your task is to build a regression model that can predict a car’s MPG given its attributes. Car MPG dataset: The dataset consists of 393 car models, their attributes and their MPG. The columns in the data set are as follows: 1. Car Model Name 2. MPG - Miles Per Gallon. This is the value that we want to predict 3. Number of cylinders 4. Engine Displacement 5. Engine Horse Power 6. Car Weight 7. Acceleration (time needed to reach a speed of 60 miles/hour) 8. Model Year 9. Origin
  • 2. Tasks: following in python: 1. Load the data from the csv file using Pandas 2. Preview/print the top 10 rows of the data 3. Create the Features matrix (columns 3-9 above – i.e. exclude the model_name and the mpg columns) 4. Create the Labels vector (the mpg column) 5. Plot the relationship between each of the features and the label mpg on a scatter chart. This will be a total of 7 charts. 6. Normalize the features using the StandardScaler class of the sklearn.preprocessing package 7. Split the data into training and test data using the cross_validation class of sklearn 8. Train a regression model on the training subset using the SGDRegressor class of the sklearn.linear_models package. Set the number of iterations of the learner to be 500 iterations. Perform the training as follows: a model using the cylinders feature only, then train a model using the displacement feature only, and so on. 9. For each of the models trained in step 8, apply the model to the test subset and then compute the r2_score, the mean_squared_error, and the
  • 3. mean_absolute_error scores for the predictions of each model trained above. 10. Train a model using all features for 500 iterations while setting the regularization type (penalty) to ‘l1’ instead of the default ‘l2’. Apply the model to the test data and compute the evaluation metrics as in step 9. 11. Train a model using all features for 500 iterations with ‘l2’ regularization and an initial learning rate (eta0) set to 10.0. Compute the evaluation metrics as in step 9. What to submit 1. Submit the Jupyter Notebook that shows all your work exactly as described above. Your notebook should include section headers and descriptive text that explains what you are doing at each step (follow the style of the notebooks we develop at class.) Submit your jyputer notebook both in *.ipynb format and also HTML format. To produce the HTML format: File > Download AS > HTML (.html). 2. Submit a document in PDF format that shows the results of the experiments you ran in steps 8 to 11 above. The results should be shown in one table similar to the following: Features Used Non-default params R2 score Mean Squared Error Mean Absolute Error
  • 4. Cylinders Iter = 500 Displacement Iter = 500 Horsepower Iter = 500 Weight Iter = 500 Acceleration Iter = 500 Year Iter = 500 Origin Iter = 500 All Features Iter = 500 All Features Iter = 500, penalty = l1 All Features Iter = 500, eta0 = 10