Question

This is an open-ended lab. Using Python, run a linear regression analysis on data you have...

This is an open-ended lab. Using Python, run a linear regression analysis on data you have collected from public domain.
   
Recommended packages:
• scikit-learn
• numpy
• matplotlib
• pandas   
Deliverables:
1. python code [.py file(s)]
2. Explanation of work

Create an original how-to document with step by step instructions you have followed to create your program. Your document should be used as an adequate tutorial for someone to reproduce your work by following the steps/instructions.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

STEP 1. IMPORT ALL THE LIBRARIES REQUIRED FOR THE ANALYSIS

STEP 2. IMPORT THE DATA FOR THE ANALYSIS FROM A URL AND SHOW SOME ENTRIES

STEP 3. VISUALIZING THE DATA USING A REGPLOT

STEP 4. SPLITTING THE DATASET INTO TWO PARTS: TRAINING PART AND TESTING PART

TRAINING PART HELPS IN TRAINING THE LINER REGRESSION MODEL.

TESTING PART HELPS IN MEASURING THE PERFORMANCE OF OUR TRAINED MODEL

STEP 5. IMPORTING THE LINEAR REGRESSION MODEL FROM THE SCiKIT-LEARN LIBRARY AND FITTING THE MODEL TO TRAINING DATASET.

STEP 6. VISUALIZING THE REGRESSION LINE OVER THE DATASET

STEP 7. CALCULATING THE SCORE FOR THE TRAINED MODEL USING TESTING DATASET

CODE:

STEP 1.

%matplotlib inline

# Imports

import matplotlib.pyplot as plt

import matplotlib as mpl

import pandas as pd

import seaborn as sns

import sklearn

import numpy as np

STEP 2.

url = "https://raw.githubusercontent.com/ludobouan/linear-regression-sklearn/master/challenge_dataset.txt"

df = pd.read_csv(url, names=['X','Y'])

df.head()

STEP 3.

sns.regplot(x='X', y='Y', data=df, fit_reg=False)

plt.show()

STEP 4.

from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = np.asarray(train_test_split(df['X'], df['Y'], test_size=0.1))

STEP 5.

from sklearn.linear_model import LinearRegression

reg = LinearRegression()

reg.fit(X_train.values.reshape(-1,1), y_train.values.reshape(-1,1))

STEP 6.

x_line = np.arange(5,25).reshape(-1,1)

sns.regplot(x=df['X'], y=df['Y'], data=df, fit_reg=False)

plt.plot(x_line, reg.predict(x_line))

plt.show()

STEP 7.

print('Score: ', reg.score(X_test.values.reshape(-1,1), y_test.values.reshape(-1,1)))

THANK YOU!

(NOTE SOMETIMES IF YOU TRY TO COPY THE PYTHON CODE IT SHOWS IDENTATION DUE TO ZERO WIDTH SPACE PROBLEM SO IF POSSIBLE WRITE DOWN THE ABOVE CODE)

Add a comment
Know the answer?
Add Answer to:
This is an open-ended lab. Using Python, run a linear regression analysis on data you have...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Lab 10C - Creating a new class This assignment assumes that you have read and understood...

    Lab 10C - Creating a new class This assignment assumes that you have read and understood the following documents: http://www.annedawson.net/Python3_Intro_OOP.pdf http://www.annedawson.net/Python3_Prog_OOP.pdf and that you're familiar with the following example programs: http://www.annedawson.net/python3programs.html 13-01.py, 13-02.py, 13-03.py, 13-04.py Instructions: Complete as much as you can in the time allowed. Write a Python class named "Car" that has the following data attributes (please create your own variable names for these attributes using the recommended naming conventions): - year (for the car's year of manufacture)...

  • Using Python, Can someone please assist in the following: These are the hints: Summary This week's lab is to create a simple multiplication table using nested loops and if statements. Prompt the...

    Using Python, Can someone please assist in the following: These are the hints: Summary This week's lab is to create a simple multiplication table using nested loops and if statements. Prompt the user for the size of the multiplication table (from 2x2 to 10x10). Use a validation loop to display a warning if the number is less than 2 or greater than 10 and prompt the user to enter the data again until they enter a valid number Put a...

  • 23.4 Project 4: Using Pandas for data analysis and practice with error handling Python Please! 23.4...

    23.4 Project 4: Using Pandas for data analysis and practice with error handling Python Please! 23.4 PROJECT 4: Using Pandas for data analysis and practice with error handling Overview In this project, you will use the Pandas module to analyze some data about some 20th century car models, country of origin, miles per gallon, model year, etc. Provided Input Files An input file with nearly 200 rows of data about automobiles. The input file has the following format (the same...

  • Please show all work and answer all parts using python, thanks! Instructions You will need to...

    Please show all work and answer all parts using python, thanks! Instructions You will need to create four files: • Shape2D.py - file containing a class definition containing properties all Shapes could possibly have. • Circle.py - file containing a class definition of a Circle that inherits from the Shape2D class. Square.py - file containing a class definition of a Square that inherits from the Shape2D class. • testFile.py - file containing pytest functions testing the Shape2D, Circle, and Square...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT