Question

Using Python Estimate the 5th and the 2nd degree polynomial regressions for this data: Age Salary...

Using Python Estimate the 5th and the 2nd degree polynomial regressions for this data:

Age  Salary
25  135000
55  260000
27  105000
35  220000
60  240000
65  265000
45  270000
40  300000
50  265000
30  105000

Please show the coding used.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#CODE

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

data = pd.read_csv('AgeSalary.csv')
print(data)

X = np.array(data['Age']).reshape(1,-1).T
Y = data['Salary'].values

## Without any polynomial transforming

from sklearn.linear_model import LinearRegression
reg = LinearRegression()
reg.fit(X,Y)

#plot the actual and predicted
plt.scatter(X,Y,color='red')
plt.plot(X,reg.predict(X),color='blue')
plt.xlabel('Age')
plt.ylabel("Salary")

## Using 5th degree polynomial

from sklearn.preprocessing import PolynomialFeatures
poly5 = PolynomialFeatures(degree = 5)
X_poly = poly5.fit_transform(X)
poly5.fit(X_poly,Y)
lin_poly5_reg = LinearRegression()
lin_poly5_reg.fit(X_poly,Y)

plt.scatter(X, Y, color = 'blue')
plt.plot(X, lin_poly5_reg.predict(X_poly), color = 'red')
plt.xlabel('Age')
plt.ylabel('Salary')

## Using 2nd degree polynomial

poly2 = PolynomialFeatures(degree = 2)
X_poly = poly2.fit_transform(X)
poly2.fit(X_poly,Y)
lin_poly2_reg = LinearRegression()
lin_poly2_reg.fit(X_poly,Y)

plt.scatter(X, Y, color = 'blue')
plt.plot(X, lin_poly2_reg.predict(X_poly), color = 'red')
plt.xlabel('Age')
plt.ylabel('Salary')

#OUTPUT

Add a comment
Know the answer?
Add Answer to:
Using Python Estimate the 5th and the 2nd degree polynomial regressions for this data: Age Salary...
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
  • From the data in the table below, estimate two regression models using a calculator or MS...

    From the data in the table below, estimate two regression models using a calculator or MS Excel (calculations only) to solve this. At a very minimum, please attempt one using a calculator. Show your work in a table Model 1: Weekly Disposable IncomeAge+ Model 2: Weekly Per Capita Consumption Age+ Age (years) Income (S Weekly Disposable Weekly Consumption per capita (S 30 35 40 45 50 500 550 600 500 900 1000 1000 1200 1500 50 60 60 50 70...

  • The research team would like to estimate the average gender difference in age. Compute a 90%...

    The research team would like to estimate the average gender difference in age. Compute a 90% estimate and confidence interval for the difference in the average age of Female and Male employees. What is the margin of error of the confidence interval ? (Use 3 decimals) Employee Number1 Annual Salary Gender Age (years) Experience (years) Training Level 1 $     32,368 F 42 3 B 2 $     53,174 M 54 10 B 3 $     52,722 M 47 10 A 4 $     53,423 M 47 1...

  • JDD Corporation provides the following to its employee, Ahmed (age 50): Salary $ 339,000 Health insurance...

    JDD Corporation provides the following to its employee, Ahmed (age 50): Salary $ 339,000 Health insurance 14,700 Dental insurance 2,100 Life insurance 3,900 Dependent care 4,200 Professional dues 1,310 Personal use of company jet 259,000 Assume the life insurance is a group-term life insurance policy that provides $294,000 of coverage for Ahmed. (Use EXHIBIT 12-8.) Assuming Ahmed is subject to a marginal tax rate of 32 percent, what is his after-tax benefit of receiving each of these benefits? (Enter all...

  • The accompanying table provides data for the sex, age, and weight of bears. For sex, let...

    The accompanying table provides data for the sex, age, and weight of bears. For sex, let 0 represent female and let 1 represent male. Letting the response (y) varieble represent weight, use the dummy variable of sex and the variable of age and to find the multiple regression equation, Use the equation to find the predicted weight of a bear with the characteristics given below. Does sex appear to have much of an effect on the weight of a bear?...

  • Question 1 30 pts Jessie, age 53, is a single taxpayer. She earns a salary of...

    Question 1 30 pts Jessie, age 53, is a single taxpayer. She earns a salary of $90,000. Her employer puts $5,000 into a qualified pension plan on her behalf and Jessie puts $7,000 in her pension plan. Her employer provides all employees with group-term life insurance equal to their salary ($90,000). Jessie put $2,000 in her flexible benefits plan. Her allowable deductions for AGI total $4,200 and she has $10,100 of allowable itemized deductions. In addition, Jessie received interest income...

  • ntroduce your scenario and data set. Provide a brief overview of the scenario you are given...

    ntroduce your scenario and data set. Provide a brief overview of the scenario you are given above and the data set that you will be analyzing. Classify the variables in your data set. Which variables are quantitative/qualitative? Which variables are discrete/continuous? Describe the level of measurement for each variable included in your data set. Discuss the importance of the Measures of Center and the Measures of Variation. What are the measures of center and why are they important? What are...

  • In Python Question 3 (13 points): Purpose: To practice your ability to modify lists and compute...

    In Python Question 3 (13 points): Purpose: To practice your ability to modify lists and compute with lists of lists Degree of Difficulty: Moderate For this question, you are given some population estimates, by age group, from Statistics Canada for some provinces. Starter File a5q3 starter.py is a file that contains a list of lists, to which the variable Pop-data refers, which represents 2020 population numbers. The first item in Pop_data is a list whose first item is the string...

  • Infinite Spiral of Numbers (due 17 Feb 2020) HELLO, WE ARE USING PYTHON 3 TO COMPLETE...

    Infinite Spiral of Numbers (due 17 Feb 2020) HELLO, WE ARE USING PYTHON 3 TO COMPLETE THIS PROJECT!! PLEASE FOLLOW CODE SKELETON AS GIVEN AT THE END. THIS IS DUE 17TH FEB 2020, ANY AND ALL HELP WOULD BE GREATLY APPRECIATED, THANK YOU! Consider the natural numbers laid out in a square spiral, with 1 occupying the center of the spiral. The central 11 x 11 subset of that spiral is shown in the table below. 111 112 113 114...

  • In this exercise, you will investigate the relationship between a worker's age and earnings. (Generally, older...

    In this exercise, you will investigate the relationship between a worker's age and earnings. (Generally, older workers have more job experience, leading to higher productivity and earnings.) The following table contains data for full-time, full-years workers, age 25-34, with a high school diploma or B.A./B.S. as their highest degree. Download the data from the table by clicking the download table icon 0 . A detailed description of the variables used in the data set is available here Use a statistical...

  • Python Pandas, Series and DataFrame Question (NO Loops, No If Statements, No List Comprehensions) The file...

    Python Pandas, Series and DataFrame Question (NO Loops, No If Statements, No List Comprehensions) The file bank.csv contains data about bank customers. The last column ('Personal Loan') indicates whether or not the customer was approved for a personal loan or not. Write a function named loan_by_zip that accepts 3 parameters: a file name, a minimum number of records, and a percentage approval rate. The function should return a DataFrame of those zip codes for which we meet the minimum number...

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
ADVERTISEMENT