QuestionQuestion

Question I
Use the Boston data set available in sklearn package. Design a linear regression model using Keras Framework. Obtain the coefficients for the linear regression model and compare it with the coefficients obtained using the sklearn.linear_model.LinearRegression. Use the following code for compiling the keras model:
model.compile(loss: 'mean_squared_error', optimizer: 'rmsprop', metrics :;'mae'1)

Question 2
Use the Iris data set Set up a KNN based classifier and choose an appropriate value for K. Show the confusion matrix. Discuss the difference between KNN and K-means classifier. Set-up a K-means classifier with appropriate cluster size. Perform a few manipulations to obtain the confusion matrix using the output from the K-means classifier' (Hint: K-means is unsupervised learning and hence you need to map the cluster numbers properly in order to generate the confusion matrix.)

Question 3
Use the diamonds dataset Perform exploratory data analysis and construct a SVM based estimator for predicting the diamond price (Use 'rbf kernel). Select a diamond from the website https://t'lllviamesallen.corn. extract the parameters and provide them as input to the SVM estimator. Estimate the price of the selected diamond and compare it with the price in the website. Discuss the reasons for the difference in estimated price and the advertised price.


Question 4
Access the German Traffic Sign dataset using the code listed below. Once you have loaded the dataset in the colab environment, perform exploratory data analysis. Determine the number of traffic signs in the dataset. Prepare the dataset for training a CNN. you are required to use TWO (2) convolutional layers and THREE (3) dense layers. Rate the perfoffnance of your algorithm.

!git clone https:;,.bitLruckct.orqr.iacjslirn,,gerrr_ran-traf'f.lg-sign:
import pickle as pkl
with open (' german -traffi c-sign s/train.p','rb') as f: train_datalkl.load(fl
with open ('german-traffi c-si gns/test.p','rb,) as f: test_data:pkl. load (f;
with open ('german-traffi c-s i gns/val id. p,,'rb') as f: val_data:pkl.load(f)
x_train. y_train : trai n_dataf'fbatures'], train_data['label s'] #3 47 99 trai n data x_test, y_test : test_data['features'], test_data[,labels'] #12630 test data x_val, y_val : val_data['features'], val_data['labels'] #4410 validation data

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

# -*- coding: utf-8 -*-
"""eca.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/188Ft0dntB6e5TrayRnvNxrrMD8QWn9mP

# Question 1

## **Linear Regression using SKLEARN Package**
"""

#Import Libraries and Modules

import pandas as pd
import numpy as np

import seaborn as sns
import matplotlib.pyplot as plt

from sklearn import preprocessing
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split, cross_val_score
from sklearn.metrics import mean_squared_error
from sklearn.metrics import r2_score

#Loading the Boston Dataset

from sklearn.datasets import load_boston
boston = load_boston()

#Fields present along with the data

boston.keys()

#Description about the dataset and its attributes

print(boston.DESCR)

# Shape of the dataset

boston.data.shape

# Target Variable Shape

boston.target.shape

# Features present in the dataset

boston.feature_names

# File path of the dataset

boston.filename

# Loading data into pandas dataframe

df = pd.DataFrame(boston.data)

# Assigning the columns of the dataframe with features present in the dataset

df.columns = boston.feature_names

# Loading Target Data into the dataframe with column name "price"

df['price'] = boston.target

# Final Shape of the dataframe after loading target variable

df.shape

# Head of the dataframe

df.head()

# Random samples from the dataframe

df.sample(5)

# basic information about the dataframe

df.info()

# describing the dataframe

df.describe()

# Checking NULL values and total number of NULL values in each column

df.isnull().sum()

# Datatypes of the columns in the dataframe

df.dtypes

# Plotting correlation matrix

plt.figure(figsize=(12,12))
sns.heatmap(df.corr().round(2), annot = True, cmap = 'coolwarm')

# Distribution Plot and Pair Plot between each variables

sns.pairplot(df, diag_kind="kde")

# Breaking the data features into independent and dependent variables

df_train = df[df.columns.drop(['price']).tolist()]                  
df_target = df['price']

# Scaling the independent data variables

standard_scaler = preprocessing.StandardScaler()
X = standard_scaler.fit_transform(df_train)

# Splitting the dataset into Train and Test Variables

X_train, X_test, Y_train, Y_test = train_test_split(X, df_target, test_size = 0.2, random_state=3)

# Shapes of Train X, Y abd Test X, Y

X_train.shape, X_test.shape, Y_train.shape, Y_test.shape

# Initialize the Linear Regression Model from SKLEARN package and train the model

sklearn_model = LinearRegression().fit(X_train, Y_train)

# Predicting the Test dataset

y_predict = sklearn_model.predict(X_test)

# Finding Performance Metrics of Regression such as Root Mean Squared Erro(RMSE), r2, Mean Squared Erro(MSE)...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$185.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Artificial Intelligence Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats