Get the App
SLTechnology News&Howtos  ›  Development  › 

How to understand and master Python logical regression

Shulou Source: shulou.com Published: 2022-06-02 18:24:27 10月03日 Update

This article mainly explains "how to understand and master Python logical regression". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to understand and master Python logical regression".

Def sigmoid (x): define the sigmoid function

Return 1 / (1+np.exp (- x))

Parameter setting and iteration for logical regression

Def weights: # initialization parameter mline n = x_train.shapetheta = np.random.rand (n) # Parameter cnt = "iterations max_iter = 5000" start iteration while cnt < max_iter:cnt + = 1diff = np.full (nMagol 0) for i in range (m): diff = (y [I]-sigmoid (theta.T @ x [I]) * x [I] theta = theta + alpha * diffif (abs (diff) 0.5:return 1else:return 0)

Call function

X_train = np.array ([1Power2.697 minus 6.254], [1mine1.872 pr 2.014], [1je 2.312 pr 0.812], [lde 1.932 pr 3.920], [1Me 1.321 mei 5.583], [1 mei 2.215 mei 1.560], [1mel 1.659pr 2.932], [1mel 0.85 pr 7.362], [1mel 1.685pr 4.763], [1mel 1.786je 2.523]) y_train = np.array ([1remiere 1.685 meme 4.763]) y_train = np.array 1]) alpha = 0.001 # Learning rate thershold = 0.01# specify a threshold Used to check twice error print (weights) thank you for reading, above is the content of "how to understand and master Python logical regression". After the study of this article, I believe you have a deeper understanding of how to understand and master Python logical regression, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Logic learning functions parameters iterations content that is ideas situations articles more times knowledge knowledge points articles errors follow problems thresholds practice Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Redmi Docker Linux Xiaomi