Example 1: logistic regression sklearn
from sklearn.linear_model import LogisticRegression
LR = LogisticRegression(random_state=0).fit(X, y)
LR.predict(X[:2, :])
LR.score(X, y)
from sklearn.metrics import mean_absolute_error
mean_absolute_error(y_true, y_pred)
from sklearn.metrics import mean_squared_error
mean_squared_error(y_true, p_pred)
from sklearn.metrics import r2_score
r2_score(y_true, y_pred)
Example 2: logistic regression algorithm in python
from sklearn.linear_model import LogisticRegression
logreg = LogisticRegression()
logreg.fit(X_train,y_train)
y_pred=logreg.predict(X_test)
Example 3: multinomial regression scikit learn
model1 = LogisticRegression(random_state=0, multi_class='multinomial', penalty='none', solver='newton-cg').fit(X_train, y_train)
preds = model1.predict(X_test)
params = model1.get_params()
print(params)
{'C': 1.0, 'class_weight': None, 'dual': False, 'fit_intercept': True, 'intercept_scaling': 1, 'l1_ratio': None, 'max_iter': 100, 'multi_class': 'multinomial', 'n_jobs': None, 'penalty': 'none', 'random_state': 0, 'solver': 'newton-cg', 'tol': 0.0001, 'verbose': 0, 'warm_start': False}
Example 4: importing logistic regression
sklearn.linear_model.LogisticRegression
Example 5: logistic regression algorithm in python
print("Accuracy:",metrics.accuracy_score(y_test, y_pred))
print("Precision:",metrics.precision_score(y_test, y_pred))
print("Recall:",metrics.recall_score(y_test, y_pred))
Example 6: logistic regression algorithm in python
from sklearn import metrics
cnf_matrix = metrics.confusion_matrix(y_test, y_pred)
cnf_matrix