Software engineering


from sklearn.linear_model import


Download 341.69 Kb.
bet5/21
Sana20.12.2022
Hajmi341.69 Kb.
#1035265
1   2   3   4   5   6   7   8   9   ...   21
Bog'liq
MASHINA-LEARNING2

from sklearn.linear_model import ElasticNet model = ElasticNet() model.fit(X, Y)
For all the regularized regression, X is the key parameter to tune during grid search in Python. In an elastic net, a can be an additional parameter to tune.
Logistic Regression
Logistic regression is one of the most widely used algorithms for classification. The logistic regression model arises from the desire to model the probabilities of the output classes given a function that is linear in x, at the same time ensuring that output probabilities sum up to one and remain between zero and one as we would expect from probabilities.
If we train a linear regression model on several examples where Y = 0 or 1, we might end up predicting some probabilities that are less than zero or greater than one, which doesn’t make sense. Instead, we use a logistic regression model (or logit model), which is a modification of linear regression that makes sure to output a probability between zero and one by applying the sigmoid function.2
Equation 4-2 shows the equation for a logistic regression model. Similar to linear regression, input values (x) are combined linearly using weights or coefficient values to predict an output value (y). The output coming from Equation 4-2 is a probability that is transformed into a binary value (0 or 1) to get the model prediction.
Equation 4-2. Logistic regression equation
y = exp(P 0 +P 1 x 1 +....+P i x 1 ) 1+exp(P 0 +P 1 x 1 +....+P i x 1 )
Wherey is the predicted output, P 0 is the bias or intercept term and B1 is the coefficient for the single input value (x). Each column in the input data has an associated P coefficient (a constant real value) that must be learned from the training data.
In logistic regression, the cost function is basically a measure of how often we predicted one when the true answer was zero, or vice versa. Training the logistic regression coefficients is done using techniques such as maximum likelihood estimation (MLE) to predict values close to 1 for the default class and close to 0 for the other class.3
A logistic regression model can be constructed using the LogisticRegression class of the sklearn package of Python, as shown in the following code snippet:

Download 341.69 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   ...   21




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling