Question

In: Computer Science

Machine Learning do using python on jupyter notebook 1. Linear Regression Dataset used: Diabetes from sklearn...

Machine Learning

do using python on jupyter notebook
1. Linear Regression
Dataset used: Diabetes from sklearn
You are asked to solve a regression problem in the Diabetes dataset. Please review the Diabetes dataset used before creating a program to decide which attributes will be used in the regression process.
please use the cross-validation step to produce the best evaluation of the model.
All you have to do is
• Perform linear regression using the OLS (Ordinary Least Square) method (sklearn.linear_model.LinearRegression)
• Also do linear regression using additional regularization. (Lasso)
• Also do linear regression by doing gradient descent algorithm training (func: sklearn.linear_model.SGDRegressor)
• In Sklearn there are several other regression methods that can be tried for use in Diabetes problems.

Solutions

Expert Solution

import pandas as pd
import numpy as np
from sklearn.datasets import load_diabetes

data=load_diabetes()

data1 = pd.DataFrame(data= np.c_[data['data'], data['target']],
columns= data['feature_names'] + ['target'])

print(data1.head)

y=data1['target']
X=data1
X.drop(['target'], axis=1,inplace=True)

from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test=train_test_split(X,y)

#LinearRegression

from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
reg = LinearRegression().fit(X_train,y_train)
pred1=reg.predict(X_train)
pred2=reg.predict(X_test)
train_mse=mean_squared_error(pred1,y_train)
test_mse=mean_squared_error(pred2,y_test)

print('train mean_squared_error :',train_mse)
print('test mean_squared_error :',test_mse)

#Lasso

from sklearn import linear_model
from sklearn.metrics import mean_squared_error
reg = linear_model.Lasso()
reg.fit(X_train,y_train)
pred1=reg.predict(X_train)
pred2=reg.predict(X_test)
train_mse=mean_squared_error(pred1,y_train)
test_mse=mean_squared_error(pred2,y_test)

print('train mean_squared_error :',train_mse)
print('test mean_squared_error :',test_mse)

#SGDRegressor

from sklearn import linear_model
from sklearn.metrics import mean_squared_error
reg = linear_model.SGDRegressor()
reg.fit(X_train,y_train)
pred1=reg.predict(X_train)
pred2=reg.predict(X_test)
train_mse=mean_squared_error(pred1,y_train)
test_mse=mean_squared_error(pred2,y_test)

print('train mean_squared_error :',train_mse)
print('test mean_squared_error :',test_mse)

#Bayesian Ridge

from sklearn import linear_model
from sklearn.metrics import mean_squared_error
reg = linear_model.BayesianRidge()
reg.fit(X_train,y_train)
pred1=reg.predict(X_train)
pred2=reg.predict(X_test)
train_mse=mean_squared_error(pred1,y_train)
test_mse=mean_squared_error(pred2,y_test)

print('train mean_squared_error :',train_mse)
print('test mean_squared_error :',test_mse)


Related Solutions

Python: Using Jupyter Notebook 1. Write code to generate Fibonacci series. Fibonacci numbers – 1, 1,...
Python: Using Jupyter Notebook 1. Write code to generate Fibonacci series. Fibonacci numbers – 1, 1, 2, 3, 5, 8, … 2. Check if a number is an Armstrong number A positive integer is called an Armstrong number of order n if abcd... = a^n + b^n + c^n + d^n + ... In case of an Armstrong number of 3 digits, the sum of cubes of each digits is equal to the number itself. For example: 153 = 1*1*1...
Focuses on the design, development, implementation, and testing of a Python program using Jupyter Notebook only...
Focuses on the design, development, implementation, and testing of a Python program using Jupyter Notebook only to solve the problem described below. You will write a program that simulates an Automatic Teller Machine (ATM). For this program, your code can have of user-defined functions only. However, the program must not call on any external functions or modules to handle any of the input, computational, and output requirements. Note, the program can be completed without the use of user-defined functions. Requirements:...
Linear Regression Linear regression is used to predict the value of one variable from another variable....
Linear Regression Linear regression is used to predict the value of one variable from another variable. Since it is based on correlation, it cannot provide causation. In addition, the strength of the relationship between the two variables affects the ability to predict one variable from the other variable; that is, the stronger the relationship between the two variables, the better the ability to do prediction. What is one instance where you think linear regression would be useful to you in...
Using the data from boston_housing.xls (accessible online) a.) do the appropriate multiple linear regression model procedures...
Using the data from boston_housing.xls (accessible online) a.) do the appropriate multiple linear regression model procedures to obtain a final model
1. A multiple linear regression model should not be used if: A The variables are all...
1. A multiple linear regression model should not be used if: A The variables are all statistically significant. B The coefficient of determination R2 is large. C Both of the above. D Neither of the above. 2. Consider a multiple linear regression model where the output variable is a company's revenue for different months, and the purpose is to investigate how the revenue depends upon the company's advertising budget. The input variables can be time-lagged so that the first input...
Linear regression is used to predict the value of one variable from another variable. Since it...
Linear regression is used to predict the value of one variable from another variable. Since it is based on correlation, it cannot provide causation. In addition, the strength of the relationship between the two variables affects the ability to predict one variable from the other variable; that is, the stronger the relationship between the two variables, the better the ability to do prediction. What is one instance where you think linear regression would be useful to you in your workplace...
1)      Do linear regression (includes line, r-coefficient) for data taken from a thermocouple during calibration for:...
1)      Do linear regression (includes line, r-coefficient) for data taken from a thermocouple during calibration for: Voltage (Volts) Temperature (ºC) 0.032 0 0.063 10 0.16 25 0.29 50 0.36 63 0.51 75 0.63 100
How do you create a linear regression model with any intercept using Matrix operations. The following...
How do you create a linear regression model with any intercept using Matrix operations. The following points are: (x0, x1, x2, y): (1, 2, 3, 15), (1, 4, 5, 23), (1, 1, 2, 8), and (1, 3, 5, 21).
(1) For linear regression with multiple variables, why do we need to do feature scaling? (2)...
(1) For linear regression with multiple variables, why do we need to do feature scaling? (2) How does the learning rate alpha influence the gradient descent algorithm?
1.Develop a multiple linear regression model to predict the price of a house using the square...
1.Develop a multiple linear regression model to predict the price of a house using the square feet of living area, number of bedrooms, and number of bathrooms as the predictor variables     Write the reqression equation.      Discuss the statistical significance of the model as a whole using the appropriate regression statistic at a 95% level of confidence. Discuss the statistical significance of the coefficient for each independent variable using the appropriate regression statistics at a 95% level of confidence....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT