How Python programming can discriminate between linear

Source: Internet
Author: User
This article is mainly to share with you about how Python programming to distinguish the linearity, the need for small partners to look at.

"" "Author:victoriacreated on:2017.9.15 11:45" "" Import pandas as Pdimport NumPy as Npimport matplotlib.pyplot as Pltdef L    DA (X0, X1): "" "Get the optimal params of LDA model given training data. Input:X0:np.array with shape [N1, d] X1:np.array with shape [N2, d] Return:omega:np.array wit h shape [1, d].    Optimal params of LDA. "" "#shape [1, d] mean0 = Np.mean (X0, axis=0, keepdims=true) mean1 = Np.mean (X1, axis=0, keepdims=true) Sw = ( X0-MEAN0). T.dot (X0-mean0) + (X1-MEAN1). T.dot (x1-mean1) Omega = Np.linalg.inv (Sw). dot (mean0-mean1). T) return omegaif __name__== "__main__": #read data from xls Work_book = Pd.read_csv (".. /data/watermelon_3a.csv ", header=none) Positive_data = work_book.values[work_book.values[:,-1] = = 1.0,:] Negative_ data = work_book.values[work_book.values[:,-1] = = 0.0,:] Print (positive_data) #LDA Omega = LDA (negative_data[: , 1:-1], positive_data[:, 1:-1]) #plot Plt.plot (positive_data[:, 1], positive_data[:, 2], "Bo") Plt.plot (negative_data[:, 1], negative_data[:, 2], "r+") lda_left = 0 Lda_right =-(omega[0]*0.9)/omega[1] Plt.plot ([0, 0.9], [Lda_left, Lda_right], ' G ') plt.xlabel (' Density ') plt.ylabel (' s Ugar rate ') plt.title ("LDA") plt.show ()


Related recommendations:

A concise introductory guide to linear discriminant analysis

Linear discriminant Analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.