Question

In: Computer Science

Use the multi-layer perceptron algorithm to learn a model that classifies IRIS flower dataset. Split the...

Use the multi-layer perceptron algorithm to learn a model that classifies IRIS flower dataset.

Split the dataset into a train set to train the algorithm and test set to test the algorithm. Calculate the accuracy.

Use Scikit-Learn

Solutions

Expert Solution

#Python3 code

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

from sklearn.neural_network import MLPClassifier # neural network

from sklearn.model_selection import train_test_split

from sklearn import metrics

from sklearn.datasets import load_iris

iris = load_iris() #load iris dataset

X=iris.data #input variable

y=iris.target #output variable

X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.5) #spilting of the data into train and test

clf = MLPClassifier(solver='lbfgs', alpha=1e-5, hidden_layer_sizes=(3, 3), random_state=1)

clf.fit(X_train,y_train) #training the MLP classifier on the training data to create the model

prediction = clf.predict(X_test) #model validation on test data

print("Predicted Class Label:\n")

print(prediction)

print("Actual Class Label:\n")

print(y_test)

print('The accuracy of the Multi-layer Perceptron is:',metrics.accuracy_score(prediction,y_test)) #calculate the model accuracy.

#OUTPUT

Predicted Class Label:

[2 1 0 0 0 0 2 1 1 2 0 1 2 0 0 1 2 1 0 2 0 0 2 1 0 0 0 2 1 0 1 2 2 2 2 2 1
0 2 2 1 2 1 1 0 0 1 2 0 0 0 1 0 2 2 1 2 2 2 0 2 2 2 2 0 0 1 2 0 0 1 1 2 2
0]
Actual Class Label:

[2 1 0 0 0 0 2 1 1 2 0 1 2 0 0 1 2 1 0 1 0 0 2 1 0 0 0 2 1 0 1 2 2 2 2 2 1
0 2 2 1 2 1 1 0 0 1 2 0 0 0 1 0 2 2 1 1 2 2 0 2 2 1 2 0 0 1 2 0 0 1 1 2 2
0]
The accuracy of the Multi-layer Perceptron is: 0.96






Related Solutions

1. Use the R command X <- iris to assign Fishers’ iris dataset to the data...
1. Use the R command X <- iris to assign Fishers’ iris dataset to the data matrix X. Using the head(X) command summarize what each column of the dataset is measuring and represents. Assign Y as a new matrix of dimension 150 by 4 which has the values of X without the species label. 2. Compute and interpret (in summary English) each of the summary statistics X,S,R using R. 3. Visualize the dataset by making a scatterplot of Sepal Length...
For this problem, use the e1-p1.csv dataset. Using the decision tree algorithm that we discussed in...
For this problem, use the e1-p1.csv dataset. Using the decision tree algorithm that we discussed in the class, determine which attribute is the best attribute at the root level. You should not use Weka, JMP Pro, or any other data mining/machine learning software. You must show all intermediate results and calculations. For this problem, use the e1-p1.csv dataset. Using the decision tree algorithm that we discussed in the class, determine which attribute is the best attribute at the root level....
From the reading this week, you will learn about the basic model that we use to...
From the reading this week, you will learn about the basic model that we use to explain the entire economy, aggregate demand-aggregate supply. All of the macroeconomic material is related to this model: GDP, inflation, unemployment. In chapter 12, you’ll read about how fiscal policy can affect the economy. The fiscal policy tools that you read about in this chapter are meant to adjust the aggregate demand side of the economy. But there is a debate about whether this is...
Let’s continue to use the Toluca.txt dataset. We now assume a normal error model: Yi =...
Let’s continue to use the Toluca.txt dataset. We now assume a normal error model: Yi = β0 + β1xi + i (i = 1, . . . , n), i ∼ N (0, σ2 ), where xi = lotSize and Yi = workHrs. a. Obtain an estimate for σ 2 . Let’s call this estimator ˆσ 2 . You can either calculate this using the formula directly or obtain this from the R output using lm. b. Construct a 90%...
How can and why might we want to change consumer attitudes?   Use the multi-attribute attitude model...
How can and why might we want to change consumer attitudes?   Use the multi-attribute attitude model to demonstrate how you could change consumer attitudes for your IMC client.
We will use the dataset **Auto{ISLR}** to develop a binomial classification model to predict the likelihood of automobiles having high gas mileage.
code in R: We will use the dataset **Auto{ISLR}** to develop a binomial classification model to predict the likelihood of automobiles having high gas mileage. So, first load the **{ISLR}** library. Since we don't have a dummy variable to classify high vs. low gas mileage vehicles, let's use the quantitative value of miles per gallon **mpg** to create a binary variable called **mpg.hi** if a vehicle has higher **mpg** than the **median mpg**. Let's first calculate the **median mpg** value...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT