logistic-regression

Finding coefficients for logistic regression in python

牧云@^-^@ 提交于 2021-01-21 10:25:07
问题 I'm working on a classification problem and need the coefficients of the logistic regression equation. I can find the coefficients in R but I need to submit the project in python. I couldn't find the code for learning coefficients of logistic regression in python. How to get the coefficient values in python? 回答1: sklearn.linear_model.LogisticRegression is for you. See this example: from sklearn.linear_model import LogisticRegression from sklearn.datasets import load_iris X, y = load_iris

Regularized logistic regression code in matlab

本小妞迷上赌 提交于 2021-01-20 14:42:39
问题 I'm trying my hand at regularized LR, simple with this formulas in matlab: The cost function: J(theta) = 1/m*sum((-y_i)*log(h(x_i)-(1-y_i)*log(1-h(x_i))))+(lambda/2*m)*sum(theta_j) The gradient: ∂J(theta)/∂theta_0 = [(1/m)*(sum((h(x_i)-y_i)*x_j)] if j=0 ∂j(theta)/∂theta_n = [(1/m)*(sum((h(x_i)-y_i)*x_j)]+(lambda/m)*(theta_j) if j>1 This is not matlab code is just the formula. So far I've done this: function [J, grad] = costFunctionReg(theta, X, y, lambda) J = 0; grad = zeros(size(theta));

Regularized logistic regresion with vectorization

谁说我不能喝 提交于 2021-01-07 02:41:45
问题 I'm trying to implement a vectorized version of the regularised logistic regression. I have found a post that explains the regularised version but I don't understand it. To make it easy I will copy the code below: hx = sigmoid(X * theta); m = length(X); J = (sum(-y' * log(hx) - (1 - y') * log(1 - hx)) / m) + lambda * sum(theta(2:end).^2) / (2*m); grad =((hx - y)' * X / m)' + lambda .* theta .* [0; ones(length(theta)-1, 1)] ./ m ; I understand the first part of the Cost equation, If I'm

Oversampling after splitting the dataset - Text classification

本秂侑毒 提交于 2021-01-01 13:33:30
问题 I am having some issues with the steps to follow for over-sampling a dataset. What I have done is the following: # Separate input features and target y_up = df.Label X_up = df.drop(columns=['Date','Links', 'Paths'], axis=1) # setting up testing and training sets X_train_up, X_test_up, y_train_up, y_test_up = train_test_split(X_up, y_up, test_size=0.30, random_state=27) class_0 = X_train_up[X_train_up.Label==0] class_1 = X_train_up[X_train_up.Label==1] # upsample minority class_1_upsampled =

ConvergenceWarning: lbfgs failed to converge (status=1): STOP: TOTAL NO. of ITERATIONS REACHED LIMIT

巧了我就是萌 提交于 2020-12-03 07:26:12
问题 I have a dataset consisting of both numeric and categorical data and I want to predict adverse outcomes for patients based on their medical characteristics. I defined a prediction pipeline for my dataset like so: X = dataset.drop(columns=['target']) y = dataset['target'] # define categorical and numeric transformers numeric_transformer = Pipeline(steps=[ ('knnImputer', KNNImputer(n_neighbors=2, weights="uniform")), ('scaler', StandardScaler())]) categorical_transformer = Pipeline(steps=[ (