Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

PA1-5extra.pdf: Accuracy =( TP +TN)/total. TPR= TP/(TP +FN). PA1-5data.html: Shown below EXTRA INFORMATION: You can use numpy. You can use numpy to conduct dot operation. numpy.dot(a,b) will be dot...

1 answer below »

Write a Python 3 program called pa1.py that implements a three-class linear classifier

using the following method:

Training (using the training data set):

  1. Compute the centroid of each class (e.g. A, B, and C).

  2. Construct a discriminant function between each pair of classes (e.g. A/B, B/C, and

    A/C), halfway between the two centroids and orthogonal to the line connecting the two centroids. This is the “basic linear classifier” that we have discussed.

Answered Same Day Apr 21, 2021

Solution

Pushpendra answered on Apr 22 2021
144 Votes
#!/us
in/env python
# coding: utf-8
# In[89]:
pwd
# In[4]:
import pandas as pd
import numpy as np
# In[6]:
df1=pd.read_excel("training_LDA.xlsx")
df1.head()
# In[8]:
df2=pd.read_excel("testing_LDA.xlsx")
df2.head()
# # Centroid
# In[9]:
from sklearn.cluster import KMeans
from sklearn import metrics
import numpy as np
print("*****Centroid for A******")
x1=df1.iloc[:,0:1].values
K =1
kmeans_model = KMeans(n_clusters=K).fit(x1)
print(kmeans_model.cluster_centers_)
centers = np.a
ay(kmeans_model.cluster_centers_)
# In[10]:
print("*****Centroid for B******")
x2=df1.iloc[:,1:2].values
K =1
kmeans_model = KMeans(n_clusters=K).fit(x2)
print(kmeans_model.cluster_centers_)
centers = np.a
ay(kmeans_model.cluster_centers_)
# In[11]:
print("*****Centroid for C******")
x3=df1.iloc[:,2:3].values
K =1
kmeans_model = KMeans(n_clusters=K).fit(x3)
print(kmeans_model.cluster_centers_)
centers = np.a
ay(kmeans_model.cluster_centers_)
# # Analysis
# In[5]:
X_train=df1.drop(('Y'),axis=1)
X_train
# In[6]:
Y_train=df1.pop('Y')
Y_train
# In[9]:
X_test=df2.drop(('Y'),axis=1)
X_test
# In[10]:
Y_test=df2.pop('Y')
Y_test
# In[11]:
#Import svm model
from sklearn import svm
#Create a svm Classifie
clf = svm.SVC(kernel='linear') # Linear Kernel
#Train the model using the training sets
clf.fit(X_train, Y_train)
#Predict the response for...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here